code: def test_compensation_mne(tmp_path):
      """Test comensation by comparing with MNE."""
  
      def make_evoked(fname, comp):
          """Make evoked data."""
          raw = read_raw_fif(fname)
          if comp is not None:
              raw.apply_gradient_compensation(comp)
          picks = pick_types(raw.info, meg=True, ref_meg=True)
          events = np.array([[0, 0, 1]], dtype=np.int64)
          evoked = Epochs(
              raw, events, 1, 0, 20e-3, picks=picks, baseline=None
          ).average()
          return evoked
  
      def compensate_mne(fname, comp):
          """Compensate using MNE-C."""
          tmp_fname = "%s-%d-ave.fif" % (fname.stem, comp)
          cmd = [
              "mne_compensate_data",
              "--in",
              str(fname),
              "--out",
              tmp_fname,
              "--grad",
              str(comp),
          ]
          run_subprocess(cmd)
          return read_evokeds(tmp_fname)[0]
  
      # save evoked response with default compensation
      fname_default = tmp_path / "ctf_default-ave.fif"
      make_evoked(ctf_comp_fname, None).save(fname_default)
  
      for comp in [0, 1, 2, 3]:
          evoked_py = make_evoked(ctf_comp_fname, comp)
          evoked_c = compensate_mne(fname_default, comp)
          picks_py = pick_types(evoked_py.info, meg=True, ref_meg=True)
          picks_c = pick_types(evoked_c.info, meg=True, ref_meg=True)
          assert_allclose(
              evoked_py.data[picks_py],
              evoked_c.data[picks_c],
              rtol=1e-3,
              atol=1e-17,
          )
          chs_py = [evoked_py.info["chs"][ii] for ii in picks_py]
          chs_c = [evoked_c.info["chs"][ii] for ii in picks_c]
          for ch_py, ch_c in zip(chs_py, chs_c):
              assert ch_py["coil_type"] == ch_c["coil_type"]
  
file_path: mne-python/mne/_fiff/tests/test_compensator.py
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  from mne import Epochs, pick_types, read_evokeds
  from mne._fiff.compensator import get_current_comp, make_compensator
  from mne.io import read_raw_fif
  from mne.utils import requires_mne, run_subprocess
label_desc: Use image node_id 3 for calling a global function with example usage: test_compensation_mne(tmp_path) and returns: evoked, read_evokeds