Test base function for rereferencing.
()
| 84 | |
| 85 | @testing.requires_testing_data |
| 86 | def test_apply_reference(): |
| 87 | """Test base function for rereferencing.""" |
| 88 | raw = read_raw_fif(fif_fname, preload=True) |
| 89 | |
| 90 | # Rereference raw data by creating a copy of original data |
| 91 | reref, ref_data = _apply_reference(raw.copy(), ref_from=["EEG 001", "EEG 002"]) |
| 92 | assert reref.info["custom_ref_applied"] |
| 93 | _test_reference(raw, reref, ref_data, ["EEG 001", "EEG 002"]) |
| 94 | |
| 95 | # The CAR reference projection should have been removed by the function |
| 96 | assert not _has_eeg_average_ref_proj(reref.info) |
| 97 | |
| 98 | # Test that data is modified in place when copy=False |
| 99 | reref, ref_data = _apply_reference(raw, ["EEG 001", "EEG 002"]) |
| 100 | assert raw is reref |
| 101 | |
| 102 | # Test that disabling the reference does not change anything |
| 103 | reref, ref_data = _apply_reference(raw.copy(), []) |
| 104 | assert_array_equal(raw._data, reref._data) |
| 105 | |
| 106 | # Test re-referencing Epochs object |
| 107 | raw = read_raw_fif(fif_fname, preload=False) |
| 108 | events = read_events(eve_fname) |
| 109 | picks_eeg = pick_types(raw.info, meg=False, eeg=True) |
| 110 | epochs = Epochs( |
| 111 | raw, |
| 112 | events=events, |
| 113 | event_id=1, |
| 114 | tmin=-0.2, |
| 115 | tmax=0.5, |
| 116 | picks=picks_eeg, |
| 117 | preload=True, |
| 118 | ) |
| 119 | reref, ref_data = _apply_reference(epochs.copy(), ref_from=["EEG 001", "EEG 002"]) |
| 120 | assert reref.info["custom_ref_applied"] |
| 121 | _test_reference(epochs, reref, ref_data, ["EEG 001", "EEG 002"]) |
| 122 | |
| 123 | # Test re-referencing Evoked object |
| 124 | evoked = epochs.average() |
| 125 | reref, ref_data = _apply_reference(evoked.copy(), ref_from=["EEG 001", "EEG 002"]) |
| 126 | assert reref.info["custom_ref_applied"] |
| 127 | _test_reference(evoked, reref, ref_data, ["EEG 001", "EEG 002"]) |
| 128 | |
| 129 | # Referencing needs data to be preloaded |
| 130 | raw_np = read_raw_fif(fif_fname, preload=False) |
| 131 | pytest.raises(RuntimeError, _apply_reference, raw_np, ["EEG 001"]) |
| 132 | |
| 133 | # Test having inactive SSP projections that deal with channels involved |
| 134 | # during re-referencing |
| 135 | raw = read_raw_fif(fif_fname, preload=True) |
| 136 | raw.add_proj( |
| 137 | Projection( |
| 138 | active=False, |
| 139 | data=dict( |
| 140 | col_names=["EEG 001", "EEG 002"], |
| 141 | row_names=None, |
| 142 | data=np.array([[1, 1]]), |
| 143 | ncol=2, |
nothing calls this directly
no test coverage detected