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

Function test_find_bads_maxwell_flat

mne/preprocessing/tests/test_maxwell.py:1836–1876  ·  view source on GitHub ↗

Test find_bads_maxwell when there are flat channels.

()

Source from the content-addressed store, hash-verified

1834
1835@pytest.mark.slowtest
1836def test_find_bads_maxwell_flat():
1837 """Test find_bads_maxwell when there are flat channels."""
1838 # See gh-9479
1839 raw = mne.io.read_raw_fif(raw_small_fname).load_data()
1840 assert_allclose(raw.times[-1], 23.97, atol=1e-2)
1841 noisy, flat = find_bad_channels_maxwell(raw, min_count=1)
1842 assert noisy == ["MEG 1032", "MEG 2313", "MEG 2443"]
1843 assert flat == []
1844 n = int(round(raw.info["sfreq"] * 10))
1845 assert (len(raw.times) - n) / raw.info["sfreq"] > 10 # at least 10 s
1846 with catch_logging() as log:
1847 want_noisy, want_flat = find_bad_channels_maxwell(
1848 raw.copy().crop(n / raw.info["sfreq"], None), min_count=1, verbose="debug"
1849 )
1850 log = log.getvalue()
1851 assert "in 2 intervals " in log
1852 assert want_noisy == ["MEG 2313", "MEG 2443"]
1853 assert want_flat == []
1854 raw._data[:, :n] = 0
1855 with pytest.warns(RuntimeWarning, match="All-flat segment detected"):
1856 with catch_logging() as log:
1857 noisy, flat = find_bad_channels_maxwell(raw, min_count=1, verbose="debug")
1858 log = log.getvalue()
1859 assert " in 4 intervals " in log
1860 assert flat == raw.ch_names[:306]
1861 assert noisy == [] # none found because all flat
1862 # now do what we suggest in the warning
1863 annot, _ = annotate_amplitude(raw, flat=0.0, bad_percent=100, min_duration=1.0)
1864 assert_allclose(annot.duration, 10.0, atol=1e-2) # not even divisor sfreq
1865 raw.info["bads"] = []
1866 raw.set_annotations(annot)
1867 data_good = raw.get_data(reject_by_annotation="omit")
1868 assert data_good.shape[1] / raw.info["sfreq"] / 5.0 > 2 # at least 10 s
1869 with catch_logging() as log:
1870 noisy, flat = find_bad_channels_maxwell(
1871 raw, min_count=1, skip_by_annotation="bad_flat", verbose="debug"
1872 )
1873 log = log.getvalue()
1874 assert " in 2 intervals " in log, log
1875 assert flat == want_flat
1876 assert noisy == want_noisy
1877
1878
1879@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 9

catch_loggingClass · 0.90
annotate_amplitudeFunction · 0.90
getvalueMethod · 0.80
load_dataMethod · 0.45
cropMethod · 0.45
copyMethod · 0.45
set_annotationsMethod · 0.45
get_dataMethod · 0.45

Tested by

no test coverage detected