code: def _get_data_as_dict_from_dig(dig, exclude_ref_channel=True):
      """Obtain coordinate data from a Dig.
  
      Parameters
      ----------
      dig : list of dicts
          A container of DigPoints to be added to the info['dig'].
  
      Returns
      -------
      ch_pos : dict
          The container of all relevant channel positions inside dig.
      """
      # Split up the dig points by category
      hsp, hpi, elp = list(), list(), list()
      fids, dig_ch_pos_location = dict(), list()
      dig = [] if dig is None else dig
  
      for d in dig:
          if d["kind"] == FIFF.FIFFV_POINT_CARDINAL:
              fids[_cardinal_ident_mapping[d["ident"]]] = d["r"]
          elif d["kind"] == FIFF.FIFFV_POINT_HPI:
              hpi.append(d["r"])
              elp.append(d["r"])
          elif d["kind"] == FIFF.FIFFV_POINT_EXTRA:
              hsp.append(d["r"])
          elif d["kind"] == FIFF.FIFFV_POINT_EEG:
              if d["ident"] != 0 or not exclude_ref_channel:
                  dig_ch_pos_location.append(d["r"])
  
      dig_coord_frames = set([d["coord_frame"] for d in dig])
      if len(dig_coord_frames) == 0:
          dig_coord_frames = set([FIFF.FIFFV_COORD_HEAD])
      if len(dig_coord_frames) != 1:
          raise RuntimeError(
              "Only single coordinate frame in dig is supported, "
              f"got {dig_coord_frames}"
          )
      dig_ch_pos_location = np.array(dig_ch_pos_location)
      dig_ch_pos_location.shape = (-1, 3)  # empty will be (0, 3)
      return Bunch(
          nasion=fids.get("nasion", None),
          lpa=fids.get("lpa", None),
          rpa=fids.get("rpa", None),
          hsp=np.array(hsp) if len(hsp) else None,
          hpi=np.array(hpi) if len(hpi) else None,
          elp=np.array(elp) if len(elp) else None,
          dig_ch_pos_location=dig_ch_pos_location,
          coord_frame=dig_coord_frames.pop(),
      )
  
imports: import heapq
  from collections import Counter
  import numpy
  from ..utils import Bunch, _check_fname, _validate_type, logger, verbose, warn
  from .constants import FIFF, _coord_frame_named
  from .tag import read_tag
  from .tree import dir_tree_find
  from .write import start_and_end_file, write_dig_points
label_desc: Use image node_id 7 for calling a global function with example usage: _get_data_as_dict_from_dig(dig, exclude_ref_channel) and returns: Bunch