code: def test_cross_talk(tmp_path):
      """Test Maxwell filter cross-talk cancellation."""
      raw = read_crop(raw_fname, (0.0, 1.0))
      raw.info["bads"] = bads
      sss_ctc = read_crop(sss_ctc_fname)
      with use_coil_def(elekta_def_fname):
          raw_sss = maxwell_filter(
              raw,
              cross_talk=pathlib.Path(ctc_fname),
              origin=mf_head_origin,
              regularize=None,
              bad_condition="ignore",
          )
      assert_meg_snr(raw_sss, sss_ctc, 275.0)
      py_ctc = raw_sss.info["proc_history"][0]["max_info"]["sss_ctc"]
      assert len(py_ctc) > 0
      with pytest.raises(TypeError, match="path-like"):
          maxwell_filter(raw, cross_talk=raw)
      with pytest.raises(ValueError, match="Invalid cross-talk FIF"):
          maxwell_filter(raw, cross_talk=raw_fname)
      mf_ctc = sss_ctc.info["proc_history"][0]["max_info"]["sss_ctc"]
      del mf_ctc["block_id"]  # we don't write this
      assert isinstance(py_ctc["decoupler"], sparse.csc_matrix)
      assert isinstance(mf_ctc["decoupler"], sparse.csc_matrix)
      assert_array_equal(
          py_ctc["decoupler"].toarray(), mf_ctc["decoupler"].toarray()
      )
      # I/O roundtrip
      fname = tmp_path / "test_sss_raw.fif"
      sss_ctc.save(fname)
      sss_ctc_read = read_raw_fif(fname)
      mf_ctc_read = sss_ctc_read.info["proc_history"][0]["max_info"][
          "sss_ctc"
      ]
      assert isinstance(mf_ctc_read["decoupler"], sparse.csc_matrix)
      assert_array_equal(
          mf_ctc_read["decoupler"].toarray(),
          mf_ctc["decoupler"].toarray(),
      )
      assert object_diff(py_ctc, mf_ctc) == ""
      raw_ctf = read_crop(fname_ctf_raw).apply_gradient_compensation(0)
      raw_sss = maxwell_filter(raw_ctf, origin=(0.0, 0.0, 0.04))
      _assert_n_free(raw_sss, 68)
      raw_sss = maxwell_filter(
          raw_ctf, origin=(0.0, 0.0, 0.04), ignore_ref=True
      )
      _assert_n_free(raw_sss, 70)
      raw_missing = (
          raw.copy()
          .crop(0, 0.1)
          .load_data()
          .pick(
              [
                  raw.ch_names[pi]
                  for pi in pick_types(raw.info, meg=True, exclude=())[
                      3:
                  ]
              ]
          )
      )
      with pytest.warns(
          RuntimeWarning, match="Not all cross-talk channels"
      ):
          maxwell_filter(raw_missing, cross_talk=ctc_fname)
      # MEG channels not in cross-talk
      with pytest.raises(RuntimeError, match="Missing MEG channels"):
          maxwell_filter(
              raw_ctf, origin=(0.0, 0.0, 0.04), cross_talk=ctc_fname
          )
  
imports: import pathlib
  import re
  from contextlib import contextmanager
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from scipy import sparse
  from scipy.special import sph_harm
  import mne
  from mne import compute_raw_covariance, concatenate_raws, pick_info, pick_types
  from mne._fiff.constants import FIFF
  from mne.annotations import _annotations_starts_stops
  from mne.chpi import filter_chpi, read_head_pos
  from mne.datasets import testing
  from mne.forward import _prep_meg_channels, use_coil_def
  from mne.io import BaseRaw, read_info, read_raw_bti, read_raw_ctf, read_raw_fif, read_raw_kit
  from mne.preprocessing import annotate_amplitude, annotate_movement, compute_maxwell_basis, find_bad_channels_maxwell, maxwell_filter, maxwell_filter_prepare_emptyroom
  from mne.preprocessing.maxwell import _bases_complex_to_real, _bases_real_to_complex, _get_n_moments, _prep_mf_coils, _sh_complex_to_real, _sh_negate, _sh_real_to_complex, _sss_basis_basic, _trans_sss_basis
  from mne.rank import _compute_rank_int, _get_rank_sss, compute_rank
  from mne.utils import _record_warnings, assert_meg_snr, buggy_mkl_svd, catch_logging, object_diff, use_log_level
label_desc: Use image node_id 16 for calling a global function with example usage: test_cross_talk(tmp_path) without return types