MCPcopy Index your code
hub / github.com/mne-tools/mne-python / test_cross_talk

Function test_cross_talk

mne/preprocessing/tests/test_maxwell.py:956–1008  ·  view source on GitHub ↗

Test Maxwell filter cross-talk cancellation.

(tmp_path)

Source from the content-addressed store, hash-verified

954@pytest.mark.slowtest
955@testing.requires_testing_data
956def test_cross_talk(tmp_path):
957 """Test Maxwell filter cross-talk cancellation."""
958 raw = read_crop(raw_fname, (0.0, 1.0))
959 raw.info["bads"] = bads
960 sss_ctc = read_crop(sss_ctc_fname)
961 with use_coil_def(elekta_def_fname):
962 raw_sss = maxwell_filter(
963 raw,
964 cross_talk=pathlib.Path(ctc_fname),
965 origin=mf_head_origin,
966 regularize=None,
967 bad_condition="ignore",
968 )
969 assert_meg_snr(raw_sss, sss_ctc, 275.0)
970 py_ctc = raw_sss.info["proc_history"][0]["max_info"]["sss_ctc"]
971 assert len(py_ctc) > 0
972 with pytest.raises(TypeError, match="path-like"):
973 maxwell_filter(raw, cross_talk=raw)
974 with pytest.raises(ValueError, match="Invalid cross-talk FIF"):
975 maxwell_filter(raw, cross_talk=raw_fname)
976 mf_ctc = sss_ctc.info["proc_history"][0]["max_info"]["sss_ctc"]
977 del mf_ctc["block_id"] # we don't write this
978 assert isinstance(py_ctc["decoupler"], sparse.csc_array)
979 assert isinstance(mf_ctc["decoupler"], sparse.csc_array)
980 assert_array_equal(py_ctc["decoupler"].toarray(), mf_ctc["decoupler"].toarray())
981 # I/O roundtrip
982 fname = tmp_path / "test_sss_raw.fif"
983 sss_ctc.save(fname)
984 sss_ctc_read = read_raw_fif(fname)
985 mf_ctc_read = sss_ctc_read.info["proc_history"][0]["max_info"]["sss_ctc"]
986 assert isinstance(mf_ctc_read["decoupler"], sparse.csc_array)
987 assert_array_equal(
988 mf_ctc_read["decoupler"].toarray(), mf_ctc["decoupler"].toarray()
989 )
990 assert object_diff(py_ctc, mf_ctc) == ""
991 raw_ctf = read_crop(fname_ctf_raw).apply_gradient_compensation(0)
992 raw_sss = maxwell_filter(raw_ctf, origin=(0.0, 0.0, 0.04))
993 _assert_n_free(raw_sss, 68)
994 raw_sss = maxwell_filter(raw_ctf, origin=(0.0, 0.0, 0.04), ignore_ref=True)
995 _assert_n_free(raw_sss, 70)
996 raw_missing = (
997 raw.copy()
998 .crop(0, 0.1)
999 .load_data()
1000 .pick(
1001 [raw.ch_names[pi] for pi in pick_types(raw.info, meg=True, exclude=())[3:]]
1002 )
1003 )
1004 with pytest.warns(RuntimeWarning, match="Not all cross-talk channels"):
1005 maxwell_filter(raw_missing, cross_talk=ctc_fname)
1006 # MEG channels not in cross-talk
1007 with pytest.raises(RuntimeError, match="Missing MEG channels"):
1008 maxwell_filter(raw_ctf, origin=(0.0, 0.0, 0.04), cross_talk=ctc_fname)
1009
1010
1011@testing.requires_testing_data

Callers

nothing calls this directly

Calls 14

use_coil_defFunction · 0.90
assert_meg_snrFunction · 0.90
read_raw_fifFunction · 0.90
object_diffFunction · 0.90
pick_typesFunction · 0.90
read_cropFunction · 0.85
maxwell_filterFunction · 0.85
_assert_n_freeFunction · 0.85
saveMethod · 0.45
pickMethod · 0.45
load_dataMethod · 0.45

Tested by

no test coverage detected