code: def test_compensation_apply(tmp_path, preload, pick):
      """Test applying compensation."""
      # make sure that changing the comp doesn't modify the original data
      raw = read_raw_fif(ctf_comp_fname, preload=preload)
      assert raw._comp is None
      raw2 = raw.copy()
      raw2.apply_gradient_compensation(2)
      if pick:
          raw2.pick([0] + list(range(2, len(raw.ch_names))))
          raw.pick([0] + list(range(2, len(raw.ch_names))))
      assert get_current_comp(raw2.info) == 2
      if preload:
          assert raw2._comp is None
      else:
          assert raw2._comp.shape == (len(raw2.ch_names),) * 2
      fname = tmp_path / "ctf-raw.fif"
      raw2.save(fname)
      raw2 = read_raw_fif(fname)
      assert raw2.compensation_grade == 2
      raw2.apply_gradient_compensation(3)
      assert raw2.compensation_grade == 3
      data, _ = raw[:, :]
      data2, _ = raw2[:, :]
      # channels have norm ~1e-12
      assert_allclose(data, data2, rtol=1e-9, atol=1e-18)
      for ch1, ch2 in zip(raw.info["chs"], raw2.info["chs"]):
          assert ch1["coil_type"] == ch2["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 2 for calling a global function with example usage: test_compensation_apply(tmp_path, preload, pick) without return types