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

Function test_mf_skips

mne/preprocessing/tests/test_maxwell.py:1569–1612  ·  view source on GitHub ↗

Test processing of data with skips.

()

Source from the content-addressed store, hash-verified

1567@pytest.mark.slowtest
1568@testing.requires_testing_data
1569def test_mf_skips():
1570 """Test processing of data with skips."""
1571 raw = read_raw_fif(skip_fname, preload=True)
1572 raw.fix_mag_coil_types()
1573 raw.pick(raw.ch_names[:50]) # fast and inaccurate
1574 kwargs = dict(st_only=True, coord_frame="meg", int_order=4, ext_order=3)
1575 # smoke test that this runs
1576 maxwell_filter(raw, st_duration=17.0, skip_by_annotation=(), **kwargs)
1577 # and this one, too, which will process some all-zero data
1578 maxwell_filter(raw, st_duration=2.0, skip_by_annotation=(), **kwargs)
1579 with pytest.raises(ValueError, match="duration"):
1580 # skips decrease acceptable duration
1581 maxwell_filter(raw, st_duration=17.0, **kwargs)
1582 onsets, ends = _annotations_starts_stops(raw, ("edge", "bad_acq_skip"), invert=True)
1583 assert (ends - onsets).min() / raw.info["sfreq"] == 2.0
1584 assert (ends - onsets).max() / raw.info["sfreq"] == 3.0
1585 for st_duration in (2.0, 3.0):
1586 raw_sss = maxwell_filter(raw, st_duration=st_duration, **kwargs)
1587 for start, stop in zip(onsets, ends):
1588 orig_data = raw[:, start:stop][0]
1589 new_data = raw_sss[:, start:stop][0]
1590 if (stop - start) / raw.info["sfreq"] >= st_duration:
1591 # Should be modified
1592 assert not np.allclose(new_data, orig_data, atol=1e-20)
1593 else:
1594 # Should not be modified
1595 assert_allclose(new_data, orig_data, atol=1e-20)
1596 # Processing an individual file and concat should be equivalent to
1597 # concat then process
1598 raw.crop(0, 1)
1599 raw_sss = maxwell_filter(raw, st_duration=1.0, **kwargs)
1600 raw_sss_concat = concatenate_raws([raw_sss, raw_sss.copy()])
1601 raw_concat = concatenate_raws([raw.copy(), raw.copy()])
1602 raw_concat_sss = maxwell_filter(raw_concat, st_duration=1.0, **kwargs)
1603 raw_concat_sss_bad = maxwell_filter(
1604 raw_concat, st_duration=1.0, skip_by_annotation=(), **kwargs
1605 )
1606 data_c = raw_concat[:][0]
1607 data_sc = raw_sss_concat[:][0]
1608 data_cs = raw_concat_sss[:][0]
1609 data_csb = raw_concat_sss_bad[:][0]
1610 assert not np.allclose(data_cs, data_c, atol=1e-20)
1611 assert not np.allclose(data_cs, data_csb, atol=1e-20)
1612 assert_allclose(data_sc, data_cs, atol=1e-20)
1613
1614
1615@pytest.mark.slowtest

Callers

nothing calls this directly

Calls 8

read_raw_fifFunction · 0.90
concatenate_rawsFunction · 0.90
maxwell_filterFunction · 0.85
fix_mag_coil_typesMethod · 0.80
pickMethod · 0.45
cropMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected