code: def _as_meg_type_inst(inst, ch_type="grad", mode="fast"):
      """Compute virtual evoked using interpolated fields in mag/grad channels.
  
      Parameters
      ----------
      inst : instance of mne.Evoked or mne.Epochs
          The evoked or epochs object.
      ch_type : str
          The destination channel type. It can be 'mag' or 'grad'.
      mode : str
          Either `'accurate'` or `'fast'`, determines the quality of the
          Legendre polynomial expansion used. `'fast'` should be sufficient
          for most applications.
  
      Returns
      -------
      inst : instance of mne.EvokedArray or mne.EpochsArray
          The transformed evoked object containing only virtual channels.
      """
      _check_option("ch_type", ch_type, ["mag", "grad"])
  
      # pick the original and destination channels
      pick_from = pick_types(
          inst.info, meg=True, eeg=False, ref_meg=False
      )
      pick_to = pick_types(
          inst.info, meg=ch_type, eeg=False, ref_meg=False
      )
  
      if len(pick_to) == 0:
          raise ValueError(
              "No channels matching the destination channel type"
              " found in info. Please pass an evoked containing"
              "both the original and destination channels. Only the"
              " locations of the destination channels will be used"
              " for interpolation."
          )
  
      info_from = pick_info(inst.info, pick_from)
      info_to = pick_info(inst.info, pick_to)
      # XXX someday we should probably expose the origin
      mapping = _map_meg_or_eeg_channels(
          info_from, info_to, origin=(0.0, 0.0, 0.04), mode=mode
      )
  
      # compute data by multiplying by the 'gain matrix' from
      # original sensors to virtual sensors
      if hasattr(inst, "get_data"):
          kwargs = dict()
          if "copy" in inspect.getfullargspec(inst.get_data).kwonlyargs:
              kwargs["copy"] = False
          data = inst.get_data(**kwargs)
      else:
          data = inst.data
  
      ndim = data.ndim
      if ndim == 2:
          data = data[np.newaxis, :, :]
  
      data_ = np.empty(
          (data.shape[0], len(mapping), data.shape[2]), dtype=data.dtype
      )
      for d, d_ in zip(data, data_):
          d_[:] = np.dot(mapping, d[pick_from])
  
      # keep only the destination channel types
      info = pick_info(inst.info, sel=pick_to, copy=True)
  
      # change channel names to emphasize they contain interpolated data
      for ch in info["chs"]:
          ch["ch_name"] += "_v"
      info._update_redundant()
      info._check_consistency()
      if isinstance(inst, Evoked):
          assert ndim == 2
          data_ = data_[0]  # undo new axis
          inst_ = EvokedArray(
              data_,
              info,
              tmin=inst.times[0],
              comment=inst.comment,
              nave=inst.nave,
          )
      else:
          assert isinstance(inst, BaseEpochs)
          inst_ = EpochsArray(
              data_,
              info,
              tmin=inst.tmin,
              events=inst.events,
              event_id=inst.event_id,
              metadata=inst.metadata,
          )
  
      return inst_
  
imports: import inspect
  from copy import deepcopy
  import numpy
  from scipy.interpolate import interp1d
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import _simplify_info
  from .._fiff.pick import pick_info, pick_types
  from .._fiff.proj import _has_eeg_average_ref_proj, make_projector
  from ..bem import _check_origin
  from ..cov import make_ad_hoc_cov
  from ..epochs import BaseEpochs, EpochsArray
  from ..evoked import Evoked, EvokedArray
  from ..fixes import _safe_svd
  from ..surface import get_head_surf, get_meg_helmet_surf
  from ..transforms import _find_trans, _get_trans, transform_surface_to
  from ..utils import _check_fname, _check_option, _pl, _reg_pinv, logger, verbose
  from ._lead_dots import _do_cross_dots, _do_self_dots, _do_surface_dots, _get_legen_table
  from ._make_forward import _create_eeg_els, _create_meg_coils, _read_coil_defs
label_desc: Use image node_id 6 for calling a global function with example usage: _as_meg_type_inst(inst, ch_type, mode) and returns: inst_