class_docstr: Mixin class for Raw, Evoked, Epochs.
class_docstr_tok: ["Mixin","class","for","Raw",",","Evoked",",","Epochs","."]
docstr: Interpolate bad MEG and EEG channels.
  
  Operates in place.
  
  Parameters
  ----------
  reset_bads : bool
      If True, remove the bads from info.
  mode : str
      Either ``'accurate'`` or ``'fast'``, determines the quality of the
      Legendre polynomial expansion used for interpolation of channels
      using the minimum-norm method.
  origin : array-like, shape (3,) | str
      Origin of the sphere in the head coordinate frame and in meters.
      Can be ``'auto'`` (default), which means a head-digitization-based
      origin fit.
  
      .. versionadded:: 0.17
  method : dict | str | None
      Method to use for each channel type.
  
      - ``"meg"`` channels support ``"MNE"`` (default) and ``"nan"``
      - ``"eeg"`` channels support ``"spline"`` (default), ``"MNE"`` and ``"nan"``
      - ``"fnirs"`` channels support ``"nearest"`` (default) and ``"nan"``
  
      None is an alias for::
  
          method=dict(meg="MNE", eeg="spline", fnirs="nearest")
  
      If a :class:`str` is provided, the method will be applied to all channel
      types supported and available in the instance. The method ``"nan"`` will
      replace the channel data with ``np.nan``.
  
      .. warning::
          Be careful when using ``method="nan"``; the default value
          ``reset_bads=True`` may not be what you want.
  
      .. versionadded:: 0.21
  exclude : list | tuple
      The channels to exclude from interpolation. If excluded a bad
      channel will stay in bads.
  %(verbose)s
  
  Returns
  -------
  inst : instance of Raw, Epochs, or Evoked
      The modified instance.
  
  Notes
  -----
  The ``"MNE"`` method uses minimum-norm projection to a sphere and back.
  
  .. versionadded:: 0.9.0
docstr_tok: ["Interpolate","bad","MEG","and","EEG","channels",".","Operates","in","place",".","Parameters","--","--","--","--","--","reset_bads",":","bool","If","True",",","remove","the","bads","from","info",".","mode",":","str","Either","``","'accurate","'","``","or","``","'fast","'","``",",","determines","the","quality","of","the","Legendre","polynomial","expansion","used","for","interpolation","of","channels","using","the","minimum-norm","method",".","origin",":","array-like",",","shape","(","3",",",")","|","str","Origin","of","the","sphere","in","the","head","coordinate","frame","and","in","meters",".","Can","be","``","'auto","'","``","(","default",")",",","which","means","a","head-digitization-based","origin","fit",".","..","versionadded",":",":","0.17","method",":","dict","|","str","|","None","Method","to","use","for","each","channel","type",".","-","``","``","meg","''","``","channels","support","``","``","MNE","''","``","(","default",")","and","``","``","nan","''","``","-","``","``","eeg","''","``","channels","support","``","``","spline","''","``","(","default",")",",","``","``","MNE","''","``","and","``","``","nan","''","``","-","``","``","fnirs","''","``","channels","support","``","``","nearest","''","``","(","default",")","and","``","``","nan","''","``","None","is","an","alias","for",":",":","method=dict","(","meg=","''","MNE","''",",","eeg=","''","spline","''",",","fnirs=","''","nearest","''",")","If","a",":","class",":","`","str","`","is","provided",",","the","method","will","be","applied","to","all","channel","types","supported","and","available","in","the","instance",".","The","method","``","``","nan","''","``","will","replace","the","channel","data","with","``","np.nan","``",".","..","warning",":",":","Be","careful","when","using","``","method=","''","nan","''","``",";","the","default","value","``","reset_bads=True","``","may","not","be","what","you","want",".","..","versionadded",":",":","0.21","exclude",":","list","|","tuple","The","channels","to","exclude","from","interpolation",".","If","excluded","a","bad","channel","will","stay","in","bads",".","%","(","verbose",")","s","Returns","--","--","--","-","inst",":","instance","of","Raw",",","Epochs",",","or","Evoked","The","modified","instance",".","Notes","--","--","-","The","``","``","MNE","''","``","method","uses","minimum-norm","projection","to","a","sphere","and","back",".","..","versionadded",":",":","0.9.0"]
code: def interpolate_bads(
      self,
      reset_bads=True,
      mode="accurate",
      origin="auto",
      method=None,
      exclude=(),
      verbose=None,
  ):
      """Interpolate bad MEG and EEG channels.
  
      Operates in place.
  
      Parameters
      ----------
      reset_bads : bool
          If True, remove the bads from info.
      mode : str
          Either ``'accurate'`` or ``'fast'``, determines the quality of the
          Legendre polynomial expansion used for interpolation of channels
          using the minimum-norm method.
      origin : array-like, shape (3,) | str
          Origin of the sphere in the head coordinate frame and in meters.
          Can be ``'auto'`` (default), which means a head-digitization-based
          origin fit.
  
          .. versionadded:: 0.17
      method : dict | str | None
          Method to use for each channel type.
  
          - ``"meg"`` channels support ``"MNE"`` (default) and ``"nan"``
          - ``"eeg"`` channels support ``"spline"`` (default), ``"MNE"`` and ``"nan"``
          - ``"fnirs"`` channels support ``"nearest"`` (default) and ``"nan"``
  
          None is an alias for::
  
              method=dict(meg="MNE", eeg="spline", fnirs="nearest")
  
          If a :class:`str` is provided, the method will be applied to all channel
          types supported and available in the instance. The method ``"nan"`` will
          replace the channel data with ``np.nan``.
  
          .. warning::
              Be careful when using ``method="nan"``; the default value
              ``reset_bads=True`` may not be what you want.
  
          .. versionadded:: 0.21
      exclude : list | tuple
          The channels to exclude from interpolation. If excluded a bad
          channel will stay in bads.
      %(verbose)s
  
      Returns
      -------
      inst : instance of Raw, Epochs, or Evoked
          The modified instance.
  
      Notes
      -----
      The ``"MNE"`` method uses minimum-norm projection to a sphere and back.
  
      .. versionadded:: 0.9.0
      """
      from .interpolation import (
          _interpolate_bads_ecog,
          _interpolate_bads_eeg,
          _interpolate_bads_meeg,
          _interpolate_bads_nan,
          _interpolate_bads_nirs,
          _interpolate_bads_seeg,
      )
  
      _check_preload(self, "interpolation")
      _validate_type(method, (dict, str, None), "method")
      method = _handle_default("interpolation_method", method)
      ch_types = self.get_channel_types(unique=True)
      # figure out if we have "mag" for "meg", "hbo" for "fnirs", ... to filter the
      # "method" dictionary and keep only keys that correspond to existing channels.
      for ch_type in ("meg", "fnirs"):
          for sub_ch_type in _second_rules[ch_type][1].values():
              if sub_ch_type in ch_types:
                  ch_types.remove(sub_ch_type)
                  if ch_type not in ch_types:
                      ch_types.append(ch_type)
      keys2delete = set(method) - set(ch_types)
      for key in keys2delete:
          del method[key]
      valids = {
          "eeg": ("spline", "MNE", "nan"),
          "meg": ("MNE", "nan"),
          "fnirs": ("nearest", "nan"),
          "ecog": ("spline", "nan"),
          "seeg": ("spline", "nan"),
      }
      for key in method:
          _check_option("method[key]", key, tuple(valids))
          _check_option(f"method['{key}']", method[key], valids[key])
      logger.info("Setting channel interpolation method to %s.", method)
      idx = _picks_to_idx(
          self.info, list(method), exclude=(), allow_empty=True
      )
      if idx.size == 0 or len(pick_info(self.info, idx)["bads"]) == 0:
          warn("No bad channels to interpolate. Doing nothing...")
          return self
      for ch_type in method.copy():
          idx = _picks_to_idx(
              self.info, ch_type, exclude=(), allow_empty=True
          )
          if len(pick_info(self.info, idx)["bads"]) == 0:
              method.pop(ch_type)
      logger.info("Interpolating bad channels.")
      needs_origin = [
          key != "seeg" and val != "nan" for key, val in method.items()
      ]
      if any(needs_origin):
          origin = _check_origin(origin, self.info)
      for ch_type, interp in method.items():
          if interp == "nan":
              _interpolate_bads_nan(self, ch_type, exclude=exclude)
      if method.get("eeg", "") == "spline":
          _interpolate_bads_eeg(self, origin=origin, exclude=exclude)
      meg_mne = method.get("meg", "") == "MNE"
      eeg_mne = method.get("eeg", "") == "MNE"
      if meg_mne or eeg_mne:
          _interpolate_bads_meeg(
              self,
              mode=mode,
              meg=meg_mne,
              eeg=eeg_mne,
              origin=origin,
              exclude=exclude,
              method=method,
          )
      if method.get("fnirs", "") == "nearest":
          _interpolate_bads_nirs(self, exclude=exclude)
      if method.get("ecog", "") == "spline":
          _interpolate_bads_ecog(self, origin=origin, exclude=exclude)
      if method.get("seeg", "") == "spline":
          _interpolate_bads_seeg(self, exclude=exclude)
  
      if reset_bads is True:
          if "nan" in method.values():
              warn(
                  "interpolate_bads was called with method='nan' and "
                  "reset_bads=True. Consider setting reset_bads=False so that the "
                  "nan-containing channels can be easily excluded from later "
                  "computations."
              )
          self.info["bads"] = [
              ch for ch in self.info["bads"] if ch in exclude
          ]
  
      return self
  
imports: import os.path
  import string
  import sys
  from collections import OrderedDict
  from copy import deepcopy
  from dataclasses import dataclass
  from functools import partial
  from pathlib import Path
  from typing import Union
  import numpy
  from scipy.io import loadmat
  from scipy.sparse import csr_matrix, lil_matrix
  from scipy.spatial import Delaunay
  from scipy.stats import zscore
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import Info, MontageMixin, _merge_info, _rename_comps, _unit2human, create_info
  from .._fiff.pick import _check_excludes_includes, _pick_data_channels, _picks_by_type, _picks_to_idx, _second_rules, channel_indices_by_type, channel_type, pick_channels, pick_info, pick_types
  from .._fiff.proj import setup_proj
  from .._fiff.reference import add_reference_channels, set_eeg_reference
  from .._fiff.tag import _rename_list
  from ..bem import _check_origin
  from ..defaults import HEAD_SIZE_DEFAULT, _handle_default
  from ..utils import _check_dict_keys, _check_fname, _check_option, _check_preload, _get_stim_channel, _on_missing, _validate_type, fill_doc, legacy, logger, verbose, warn
label_desc: Use image node_id 1 for calling the InterpolationMixin obj's underlying member method code with example usage: obj.interpolate_bads(reset_bads, mode, origin, method, exclude, verbose) and returns: self, self