code: def _interpolate_bads_meeg(
      inst,
      mode="accurate",
      origin=(0.0, 0.0, 0.04),
      meg=True,
      eeg=True,
      ref_meg=False,
      exclude=(),
      *,
      method=None,
      verbose=None,
  ):
      from ..forward import _map_meg_or_eeg_channels
  
      if method is None:
          method = {"meg": "MNE", "eeg": "MNE"}
      bools = dict(meg=meg, eeg=eeg)
      info = _simplify_info(inst.info)
      for ch_type, do in bools.items():
          if not do:
              continue
          kw = dict(meg=False, eeg=False)
          kw[ch_type] = True
          picks_type = pick_types(
              info, ref_meg=ref_meg, exclude=exclude, **kw
          )
          picks_good = pick_types(
              info, ref_meg=ref_meg, exclude="bads", **kw
          )
          use_ch_names = [inst.info["ch_names"][p] for p in picks_type]
          bads_type = [
              ch for ch in inst.info["bads"] if ch in use_ch_names
          ]
          if len(bads_type) == 0 or len(picks_type) == 0:
              continue
          # select the bad channels to be interpolated
          picks_bad = pick_channels(
              inst.info["ch_names"], bads_type, exclude=[]
          )
  
          # do MNE based interpolation
          if ch_type == "eeg":
              picks_to = picks_type
              bad_sel = np.isin(picks_type, picks_bad)
          else:
              picks_to = picks_bad
              bad_sel = slice(None)
          info_from = pick_info(inst.info, picks_good)
          info_to = pick_info(inst.info, picks_to)
          mapping = _map_meg_or_eeg_channels(
              info_from, info_to, mode=mode, origin=origin
          )
          mapping = mapping[bad_sel]
          _do_interp_dots(inst, mapping, picks_good, picks_bad)
  
imports: import numpy
  from numpy.polynomial.legendre import legval
  from scipy.interpolate import RectBivariateSpline
  from scipy.linalg import pinv
  from scipy.spatial.distance import pdist, squareform
  from .._fiff.meas_info import _simplify_info
  from .._fiff.pick import pick_channels, pick_info, pick_types
  from ..surface import _normalize_vectors
  from ..utils import _validate_type, logger, verbose, warn
label_desc: Use image node_id 9 for calling a global function with example usage: _interpolate_bads_meeg(inst, mode, origin, meg, eeg, ref_meg, exclude) without return types