code: def _prep_meg_channels(
      info,
      accuracy="accurate",
      exclude=(),
      *,
      ignore_ref=False,
      head_frame=True,
      do_es=False,
      verbose=None,
  ):
      """Prepare MEG coil definitions for forward calculation."""
      # Find MEG channels
      ref_meg = True if not ignore_ref else False
      picks = pick_types(
          info, meg=True, ref_meg=ref_meg, exclude=exclude
      )
  
      # Make sure MEG coils exist
      if len(picks) <= 0:
          raise RuntimeError("Could not find any MEG channels")
      info_meg = pick_info(info, picks)
      del picks
  
      # Get channel info and names for MEG channels
      logger.info(f'Read {len(info_meg["chs"])} MEG channels from info')
  
      # Get MEG compensation channels
      compensator = post_picks = None
      ch_names = info_meg["ch_names"]
      if not ignore_ref:
          ref_picks = pick_types(
              info, meg=False, ref_meg=True, exclude=exclude
          )
          ncomp = len(ref_picks)
          if ncomp > 0:
              logger.info(
                  f"Read {ncomp} MEG compensation channels from info"
              )
              # We need to check to make sure these are NOT KIT refs
              if _has_kit_refs(info, ref_picks):
                  raise NotImplementedError(
                      "Cannot create forward solution with KIT reference "
                      'channels. Consider using "ignore_ref=True" in '
                      "calculation"
                  )
              logger.info(
                  f'{len(info["comps"])} compensation data sets in info'
              )
              # Compose a compensation data set if necessary
              # adapted from mne_make_ctf_comp() from mne_ctf_comp.c
              logger.info("Setting up compensation data...")
              comp_num = get_current_comp(info)
              if comp_num is None or comp_num == 0:
                  logger.info(
                      "    No compensation set. Nothing more to do."
                  )
              else:
                  compensator = make_compensator(
                      info_meg, 0, comp_num, exclude_comp_chs=False
                  )
                  logger.info(
                      f"    Desired compensation data ({comp_num}) found."
                  )
                  logger.info("    All compensation channels found.")
                  logger.info("    Preselector created.")
                  logger.info("    Compensation data matrix created.")
                  logger.info("    Postselector created.")
              post_picks = pick_types(
                  info_meg, meg=True, ref_meg=False, exclude=exclude
              )
              ch_names = [ch_names[pick] for pick in post_picks]
  
      # Create coil descriptions with transformation to head or device frame
      templates = _read_coil_defs()
  
      if head_frame:
          _print_coord_trans(info["dev_head_t"])
          transform = info["dev_head_t"]
      else:
          transform = None
  
      megcoils = _create_meg_coils(
          info_meg["chs"], accuracy, transform, templates, do_es=do_es
      )
  
      # Check that coordinate frame is correct and log it
      if head_frame:
          assert megcoils[0]["coord_frame"] == FIFF.FIFFV_COORD_HEAD
          logger.info(
              "MEG coil definitions created in head coordinates."
          )
      else:
          assert megcoils[0]["coord_frame"] == FIFF.FIFFV_COORD_DEVICE
          logger.info(
              "MEG coil definitions created in device coordinate."
          )
  
      return dict(
          defs=megcoils,
          ch_names=ch_names,
          compensator=compensator,
          info=info_meg,
          post_picks=post_picks,
      )
  
imports: import os
  import os.path
  from contextlib import contextmanager
  from copy import deepcopy
  from pathlib import Path
  import numpy
  from .._fiff.compensator import get_current_comp, make_compensator
  from .._fiff.constants import FIFF, FWD
  from .._fiff.meas_info import Info, read_info
  from .._fiff.pick import _has_kit_refs, pick_info, pick_types
  from .._fiff.tag import _loc_to_coil_trans, _loc_to_eeg_loc
  from ..bem import ConductorModel, _bem_find_surface, read_bem_solution
  from ..source_estimate import VolSourceEstimate
  from ..source_space._source_space import _complete_vol_src, _ensure_src, _filter_source_spaces, _make_discrete_source_space
  from ..surface import _CheckInside, _normalize_vectors
  from ..transforms import Transform, _coord_frame_name, _ensure_trans, _get_trans, _print_coord_trans, apply_trans, invert_transform, transform_surface_to
  from ..utils import _check_fname, _pl, _validate_type, logger, verbose, warn
  from ._compute_forward import _compute_forwards
  from .forward import _FWD_ORDER, Forward, _merge_fwds, convert_forward_solution
label_desc: Use image node_id 9 for calling a global function with example usage: _prep_meg_channels(info, accuracy, exclude) and returns: dict