MCPcopy
hub / github.com/mne-tools/mne-python / test_annotate_nan

Function test_annotate_nan

mne/preprocessing/tests/test_annotate_nan.py:18–51  ·  view source on GitHub ↗

Tests automatic NaN annotation generation.

(meas_date)

Source from the content-addressed store, hash-verified

16
17@pytest.mark.parametrize("meas_date", (None, "orig"))
18def test_annotate_nan(meas_date):
19 """Tests automatic NaN annotation generation."""
20 # Load data
21 raw = mne.io.read_raw_fif(raw_fname)
22 sfreq = 100
23 raw.resample(sfreq)
24 if meas_date is None:
25 raw.set_meas_date(None)
26
27 # No Nans, annotate returns empty annots
28 assert not np.isnan(raw._data).any()
29 annot_nan = annotate_nan(raw)
30 assert len(annot_nan) == 0
31
32 # but orig_time should be meas_date
33 assert annot_nan.orig_time == raw.info["meas_date"]
34
35 # insert block of NaN from 1s to 3s for one channel
36 nan_ch_idx = 0
37 raw._data[nan_ch_idx, 1 * sfreq : 3 * sfreq] = np.nan
38
39 # annotate_nan accurately finds this
40 annot_nan = annotate_nan(raw)
41 onset = np.array([1.0])
42 if raw.info["meas_date"]:
43 onset += raw.first_time
44 assert_array_equal(annot_nan.onset, onset)
45 assert_array_equal(annot_nan.duration, np.array([2]))
46 assert_array_equal(annot_nan.description, np.array(["BAD_NAN"]))
47 assert len(annot_nan.ch_names) == 1
48 assert annot_nan.ch_names[0] == (raw.ch_names[nan_ch_idx],)
49
50 # Set the NaN annotations to the raw object
51 raw.set_annotations(annot_nan)

Callers

nothing calls this directly

Calls 4

annotate_nanFunction · 0.90
set_meas_dateMethod · 0.80
resampleMethod · 0.45
set_annotationsMethod · 0.45

Tested by

no test coverage detected