code: def test_interpolation_eeg(offset, avg_proj, ctol, atol, method):
      """Test interpolation of EEG channels."""
      raw, epochs_eeg = _load_data("eeg")
      epochs_eeg = epochs_eeg.copy()
      assert not _has_eeg_average_ref_proj(epochs_eeg.info)
      # Offsetting the coordinate frame should have no effect on the output
      for inst in (raw, epochs_eeg):
          for ch in inst.info["chs"]:
              if ch["kind"] == FIFF.FIFFV_EEG_CH:
                  ch["loc"][:3] += offset
                  ch["loc"][3:6] += offset
          for d in inst.info["dig"]:
              d["r"] += offset
  
      # check that interpolation does nothing if no bads are marked
      epochs_eeg.info["bads"] = []
      evoked_eeg = epochs_eeg.average()
      kw = dict(method=method)
      with pytest.warns(RuntimeWarning, match="Doing nothing"):
          evoked_eeg.interpolate_bads(**kw)
  
      # create good and bad channels for EEG
      epochs_eeg.info["bads"] = []
      goods_idx = np.ones(len(epochs_eeg.ch_names), dtype=bool)
      goods_idx[epochs_eeg.ch_names.index("EEG 012")] = False
      bads_idx = ~goods_idx
      pos = epochs_eeg._get_channel_positions()
  
      evoked_eeg = epochs_eeg.average()
      if avg_proj:
          evoked_eeg.set_eeg_reference(projection=True).apply_proj()
          assert_allclose(evoked_eeg.data.mean(0), 0.0, atol=1e-20)
      ave_before = evoked_eeg.data[bads_idx]
  
      # interpolate bad channels for EEG
      epochs_eeg.info["bads"] = ["EEG 012"]
      evoked_eeg = epochs_eeg.average()
      if avg_proj:
          evoked_eeg.set_eeg_reference(projection=True).apply_proj()
          good_picks = pick_types(evoked_eeg.info, meg=False, eeg=True)
          assert_allclose(
              evoked_eeg.data[good_picks].mean(0), 0.0, atol=1e-20
          )
      evoked_eeg_bad = evoked_eeg.copy()
      bads_picks = pick_channels(
          epochs_eeg.ch_names,
          include=epochs_eeg.info["bads"],
          ordered=True,
      )
      evoked_eeg_bad.data[bads_picks, :] = 1e10
  
      # Test first the exclude parameter
      evoked_eeg_2_bads = evoked_eeg_bad.copy()
      evoked_eeg_2_bads.info["bads"] = ["EEG 004", "EEG 012"]
      evoked_eeg_2_bads.data[
          pick_channels(evoked_eeg_bad.ch_names, ["EEG 004", "EEG 012"])
      ] = 1e10
      evoked_eeg_interp = evoked_eeg_2_bads.interpolate_bads(
          origin=(0.0, 0.0, 0.0), exclude=["EEG 004"], **kw
      )
      assert evoked_eeg_interp.info["bads"] == ["EEG 004"]
      assert np.all(evoked_eeg_interp.get_data("EEG 004") == 1e10)
      assert np.all(evoked_eeg_interp.get_data("EEG 012") != 1e10)
  
      # Now test without exclude parameter
      evoked_eeg_bad.info["bads"] = ["EEG 012"]
      evoked_eeg_interp = evoked_eeg_bad.copy().interpolate_bads(
          origin=(0.0, 0.0, 0.0), **kw
      )
      if avg_proj:
          assert_allclose(
              evoked_eeg_interp.data.mean(0), 0.0, atol=1e-6
          )
      interp_zero = evoked_eeg_interp.data[bads_idx]
      if method is None:  # using
          pos_good = pos[goods_idx]
          pos_bad = pos[bads_idx]
          interpolation = _make_interpolation_matrix(pos_good, pos_bad)
          assert interpolation.shape == (
              1,
              len(epochs_eeg.ch_names) - 1,
          )
          interp_manual = np.dot(
              interpolation, evoked_eeg_bad.data[goods_idx]
          )
          assert_array_equal(interp_manual, interp_zero)
          del interp_manual, interpolation, pos, pos_good, pos_bad
      assert_allclose(ave_before, interp_zero, atol=atol)
      assert (
          ctol[0] < np.corrcoef(ave_before, interp_zero)[0, 1] < ctol[1]
      )
      interp_fit = (
          evoked_eeg_bad.copy().interpolate_bads(**kw).data[bads_idx]
      )
      assert_allclose(ave_before, interp_fit, atol=2.5e-6)
      assert (
          ctol[1] < np.corrcoef(ave_before, interp_fit)[0, 1]
      )  # better
  
      # check that interpolation fails when preload is False
      epochs_eeg.preload = False
      with pytest.raises(
          RuntimeError, match="requires epochs data to be load"
      ):
          epochs_eeg.interpolate_bads(**kw)
      epochs_eeg.preload = True
  
      # check that interpolation changes the data in raw
      raw_eeg = RawArray(data=epochs_eeg._data[0], info=epochs_eeg.info)
      raw_before = raw_eeg._data[bads_idx]
      raw_after = raw_eeg.interpolate_bads(**kw)._data[bads_idx]
      assert not np.all(raw_before == raw_after)
  
      # check that interpolation fails when preload is False
      for inst in [raw, epochs_eeg]:
          assert hasattr(inst, "preload")
          inst.preload = False
          inst.info["bads"] = [inst.ch_names[1]]
          with pytest.raises(
              RuntimeError, match="requires.*data to be loaded"
          ):
              inst.interpolate_bads(**kw)
  
      # check that interpolation works with few channels
      raw_few = raw.copy().crop(0, 0.1).load_data()
      raw_few.pick(raw_few.ch_names[:1] + raw_few.ch_names[3:4])
      assert len(raw_few.ch_names) == 2
      raw_few.del_proj()
      raw_few.info["bads"] = [raw_few.ch_names[-1]]
      orig_data = raw_few[1][0]
      with _record_warnings() as w:
          raw_few.interpolate_bads(reset_bads=False, **kw)
      assert (
          len([ww for ww in w if "more than" not in str(ww.message)])
          == 0
      )
      new_data = raw_few[1][0]
      assert (new_data == 0).mean() < 0.5
      assert np.corrcoef(new_data, orig_data)[0, 1] > 0.2
  
imports: from itertools import compress
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from mne import Epochs, pick_channels, pick_types, read_events
  from mne._fiff.constants import FIFF
  from mne._fiff.proj import _has_eeg_average_ref_proj
  from mne.channels import make_dig_montage
  from mne.channels.interpolation import _make_interpolation_matrix
  from mne.datasets import testing
  from mne.io import RawArray, read_raw_ctf, read_raw_fif, read_raw_nirx
  from mne.preprocessing.nirs import beer_lambert_law, optical_density, scalp_coupling_index
  from mne.utils import _record_warnings
label_desc: Use image node_id 2 for calling a global function with example usage: test_interpolation_eeg(offset, avg_proj, ctol, atol, method) without return types