code: def test_chpi_subtraction_filter_chpi():
      """Test subtraction of cHPI signals."""
      raw = read_raw_fif(
          chpi_fif_fname, allow_maxshield="yes", preload=True
      )
      raw.info["bads"] = ["MEG0111"]
      raw.del_proj()
      raw_orig = raw.copy().crop(0, 16)
      with catch_logging() as log:
          filter_chpi(
              raw, include_line=False, t_window=0.2, verbose=True
          )
      log = log.getvalue()
      assert "No average EEG" not in log
      assert "5 cHPI" in log
      # MaxFilter doesn't do quite as well as our algorithm with the last bit
      raw.crop(0, 16)
      # remove cHPI status chans
      raw_c = read_raw_fif(sss_hpisubt_fname).crop(0, 16).load_data()
      raw_c.pick(["meg", "eeg", "eog", "ecg", "stim", "misc"])
      assert_meg_snr(raw, raw_c, 143, 624)
      # cHPI suppressed but not line freqs (or others)
      assert_suppressed(
          raw, raw_orig, np.arange(83, 324, 60), [30, 60, 150]
      )
      raw = raw_orig.copy()
      with catch_logging() as log:
          filter_chpi(
              raw, include_line=True, t_window=0.2, verbose=True
          )
      log = log.getvalue()
      assert "5 cHPI" in log
      assert "6 line" in log
      # cHPI and line freqs suppressed
      suppressed = np.sort(
          np.concatenate(
              [
                  np.arange(83, 324, 60),
                  np.arange(60, 301, 60),
              ]
          )
      )
      assert_suppressed(raw, raw_orig, suppressed, [30, 150])
  
      # No HPI information
      raw = read_raw_fif(sample_fname, preload=True)
      raw_orig = raw.copy()
      assert raw.info["line_freq"] is None
      with pytest.raises(
          RuntimeError, match="line_freq.*consider setting it"
      ):
          filter_chpi(raw, t_window=0.2)
      with raw.info._unlock():
          raw.info["line_freq"] = 60.0
      with pytest.raises(
          ValueError, match="No appropriate cHPI information"
      ):
          filter_chpi(raw, t_window=0.2)
      # but this is allowed
      with catch_logging() as log:
          filter_chpi(
              raw, t_window="auto", allow_line_only=True, verbose=True
          )
      log = log.getvalue()
      assert "0 cHPI" in log
      assert "1 line" in log
      # Our one line freq suppressed but not others
      assert_suppressed(raw, raw_orig, [60], [30, 45, 75])
  
      # When MaxFliter downsamples, like::
      #     $ maxfilter -nosss -ds 2 -f test_move_anon_raw.fif \
      #           -o test_move_anon_ds2_raw.fif
      # it can strip out some values of info, which we emulate here:
      raw = read_raw_fif(chpi_fif_fname, allow_maxshield="yes")
      raw = raw.crop(0, 1).load_data().resample(600.0, npad="auto")
      with raw.info._unlock():
          raw.info["lowpass"] = 200.0
          del raw.info["maxshield"]
          del raw.info["hpi_results"][0]["moments"]
          del raw.info["hpi_subsystem"]["event_channel"]
      with catch_logging() as log:
          filter_chpi(raw, t_window="auto", verbose=True)
      with pytest.raises(ValueError, match="must be > 0"):
          filter_chpi(raw, t_window=-1)
      assert "2 cHPI" in log.getvalue()
  
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  from scipy.interpolate import interp1d
  from scipy.spatial.distance import cdist
  from mne import pick_info, pick_types
  from mne._fiff.constants import FIFF
  from mne.chpi import _chpi_locs_to_times_dig, _compute_good_distances, _get_hpi_initial_fit, _setup_ext_proj, compute_chpi_amplitudes, compute_chpi_locs, compute_chpi_snr, compute_head_pos, extract_chpi_locs_ctf, extract_chpi_locs_kit, filter_chpi, get_active_chpi, get_chpi_info, head_pos_to_trans_rot_t, read_head_pos, write_head_pos
  from mne.datasets import testing
  from mne.forward._compute_forward import _MAG_FACTOR
  from mne.io import RawArray, read_info, read_raw_artemis123, read_raw_ctf, read_raw_fif, read_raw_kit
  from mne.simulation import add_chpi
  from mne.transforms import _angle_between_quats, rot_to_quat
  from mne.utils import assert_meg_snr, catch_logging, object_diff, verbose
  from mne.viz import plot_head_positions
label_desc: Use image node_id 20 for calling a global function with example usage: test_chpi_subtraction_filter_chpi() without return types