From ef7bca3210ff850e3a0631c43a967071730703f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Sat, 10 Apr 2021 18:28:10 +0200 Subject: [PATCH 1/7] WIP: Return empty list of SSPs if no ECG, EOG found --- mne/preprocessing/ssp.py | 8 ++++---- mne/preprocessing/tests/test_ssp.py | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/mne/preprocessing/ssp.py b/mne/preprocessing/ssp.py index 373c24488e9..bd49d6bfa4f 100644 --- a/mne/preprocessing/ssp.py +++ b/mne/preprocessing/ssp.py @@ -69,8 +69,8 @@ def _compute_exg_proj(mode, raw, raw_event, tmin, tmax, # Check to make sure we actually got at least one usable event if events.shape[0] < 1: - warn('No %s events found, returning None for projs' % mode) - return (None, events) + (([],) if return_drop_log else ()) + warn(f'No {mode} events found') + return ([], events) + (([],) if return_drop_log else ()) logger.info('Computing projector') my_info = cp.deepcopy(raw.info) @@ -120,8 +120,8 @@ def _compute_exg_proj(mode, raw, raw_event, tmin, tmax, drop_log = epochs.drop_log if epochs.events.shape[0] < 1: - warn('No good epochs found, returning None for projs') - return (None, events) + ((drop_log,) if return_drop_log else ()) + warn('No good epochs found') + return ([], events) + ((drop_log,) if return_drop_log else ()) if average: evoked = epochs.average() diff --git a/mne/preprocessing/tests/test_ssp.py b/mne/preprocessing/tests/test_ssp.py index b16f5190a16..8537795e726 100644 --- a/mne/preprocessing/tests/test_ssp.py +++ b/mne/preprocessing/tests/test_ssp.py @@ -100,7 +100,15 @@ def test_compute_proj_eog(average, short_raw): raw, n_mag=2, n_grad=2, n_eeg=2, average=average, bads=[], avg_ref=True, no_proj=False, l_freq=None, h_freq=None, tmax=dur_use) - assert projs is None + assert projs == [] + + raw._data[raw.ch_names.index('EOG 061'), :] = 1. + with pytest.warns(RuntimeWarning, match='filter.*longer than the signal'): + from mne.preprocessing import find_eog_events + raw.pick_channels(['EOG 061']) + e = find_eog_events(raw, ch_name='EOG 061') + projs, events = compute_proj_eog(raw=raw, tmax=dur_use, + ch_name='EOG 061') @pytest.mark.slowtest # can be slow on OSX From d720215c7df0e3c4ee9ddcac280722a34e54f9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Mon, 12 Apr 2021 11:00:14 +0200 Subject: [PATCH 2/7] Clean up test --- mne/preprocessing/tests/test_ssp.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/mne/preprocessing/tests/test_ssp.py b/mne/preprocessing/tests/test_ssp.py index 8537795e726..b2deb0b4b37 100644 --- a/mne/preprocessing/tests/test_ssp.py +++ b/mne/preprocessing/tests/test_ssp.py @@ -104,9 +104,6 @@ def test_compute_proj_eog(average, short_raw): raw._data[raw.ch_names.index('EOG 061'), :] = 1. with pytest.warns(RuntimeWarning, match='filter.*longer than the signal'): - from mne.preprocessing import find_eog_events - raw.pick_channels(['EOG 061']) - e = find_eog_events(raw, ch_name='EOG 061') projs, events = compute_proj_eog(raw=raw, tmax=dur_use, ch_name='EOG 061') From 6ef3b0d93f792c6d5fa24a6a5325201cd1373843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Mon, 12 Apr 2021 11:04:07 +0200 Subject: [PATCH 3/7] Update changelog --- doc/changes/latest.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index 4553c597e97..988cc2712a8 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -298,3 +298,5 @@ API changes - ``mne.beamformer.tf_dics`` has been deprecated and will be removed in MNE-Python 0.24 (:gh:`9122` by `Britta Westner`_) - Fitting `~mne.preprocessing.ICA` on baseline-corrected `~mne.Epochs`, and / or applying it on baseline-corrected `~mne.Epochs` or `~mne.Evoked` data will now display a warning. Users are advised to only baseline correct their data after cleaning is completed (:gh:`9033` by `Richard Höchenberger`_) + +- `mne.preprocessing.compute_proj_eog` and `mne.preprocessing.compute_proj_ecg` now return empty lists if no EOG or ECG events, repectively, could be found. Previously, we'd return ``None`` in these situations, which does not match the documented behavior of returning a list of projectors (:gh:`9277` by `Richard Höchenberger`_) \ No newline at end of file From 72e73a71b6ceade6424dd0f5029ed1a3dcfa55f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Mon, 12 Apr 2021 11:06:46 +0200 Subject: [PATCH 4/7] Fix typo --- doc/changes/latest.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index 988cc2712a8..65d160512dd 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -299,4 +299,4 @@ API changes - Fitting `~mne.preprocessing.ICA` on baseline-corrected `~mne.Epochs`, and / or applying it on baseline-corrected `~mne.Epochs` or `~mne.Evoked` data will now display a warning. Users are advised to only baseline correct their data after cleaning is completed (:gh:`9033` by `Richard Höchenberger`_) -- `mne.preprocessing.compute_proj_eog` and `mne.preprocessing.compute_proj_ecg` now return empty lists if no EOG or ECG events, repectively, could be found. Previously, we'd return ``None`` in these situations, which does not match the documented behavior of returning a list of projectors (:gh:`9277` by `Richard Höchenberger`_) \ No newline at end of file +- `mne.preprocessing.compute_proj_eog` and `mne.preprocessing.compute_proj_ecg` now return empty lists if no EOG or ECG events, respectively, could be found. Previously, we'd return ``None`` in these situations, which does not match the documented behavior of returning a list of projectors (:gh:`9277` by `Richard Höchenberger`_) \ No newline at end of file From a4e7068b12f5c86681e3706ce4c6ef8b886d9661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Mon, 12 Apr 2021 11:56:01 +0200 Subject: [PATCH 5/7] Add empty line --- doc/changes/latest.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index 65d160512dd..af7f5c869f4 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -299,4 +299,4 @@ API changes - Fitting `~mne.preprocessing.ICA` on baseline-corrected `~mne.Epochs`, and / or applying it on baseline-corrected `~mne.Epochs` or `~mne.Evoked` data will now display a warning. Users are advised to only baseline correct their data after cleaning is completed (:gh:`9033` by `Richard Höchenberger`_) -- `mne.preprocessing.compute_proj_eog` and `mne.preprocessing.compute_proj_ecg` now return empty lists if no EOG or ECG events, respectively, could be found. Previously, we'd return ``None`` in these situations, which does not match the documented behavior of returning a list of projectors (:gh:`9277` by `Richard Höchenberger`_) \ No newline at end of file +- `mne.preprocessing.compute_proj_eog` and `mne.preprocessing.compute_proj_ecg` now return empty lists if no EOG or ECG events, respectively, could be found. Previously, we'd return ``None`` in these situations, which does not match the documented behavior of returning a list of projectors (:gh:`9277` by `Richard Höchenberger`_) From e2ca65d7b6020e26fd4332cc47bab1830074b58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Mon, 12 Apr 2021 14:35:09 +0200 Subject: [PATCH 6/7] Set minimum peak detection threshold in ECG test --- mne/preprocessing/tests/test_ssp.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mne/preprocessing/tests/test_ssp.py b/mne/preprocessing/tests/test_ssp.py index b2deb0b4b37..4307dc9f6ea 100644 --- a/mne/preprocessing/tests/test_ssp.py +++ b/mne/preprocessing/tests/test_ssp.py @@ -63,8 +63,12 @@ def test_compute_proj_ecg(short_raw, average): projs, events, drop_log = compute_proj_ecg( raw, n_mag=2, n_grad=2, n_eeg=2, ch_name='MEG 1531', bads=[], average=average, avg_ref=True, no_proj=True, l_freq=None, - h_freq=None, tmax=dur_use, return_drop_log=True) - assert projs is None + h_freq=None, tmax=dur_use, return_drop_log=True, + # XXX can be removed once + # XXX https://github.com/mne-tools/mne-python/issues/9273 + # XXX has been resolved: + qrs_threshold=1e-15) + assert projs == [] assert len(events) == len(drop_log) From cd24b666662d5506b76d13b643d27658b269c6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20H=C3=B6chenberger?= Date: Mon, 12 Apr 2021 21:13:31 +0200 Subject: [PATCH 7/7] Move to bug section [skip azp][skip github] --- doc/changes/latest.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index af7f5c869f4..40e31e1066a 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -287,6 +287,8 @@ Bugs - :func:`mne.preprocessing.find_ecg_events` now correctly handles situation where no ECG activity could be detected, and correctly returns an empty array of ECG events (:gh:`9236` by `Richard Höchenberger`_) +- `mne.preprocessing.compute_proj_eog` and `mne.preprocessing.compute_proj_ecg` now return empty lists if no EOG or ECG events, respectively, could be found. Previously, we'd return ``None`` in these situations, which does not match the documented behavior of returning a list of projectors (:gh:`9277` by `Richard Höchenberger`_) + API changes ~~~~~~~~~~~ - Introduced new ``'auto'`` settings for ``ICA.max_iter``. The old default ``max_iter=200`` will be removed in MNE-Python 0.24 (:gh:`9099` **by new contributor** |Cora Kim|_) @@ -298,5 +300,3 @@ API changes - ``mne.beamformer.tf_dics`` has been deprecated and will be removed in MNE-Python 0.24 (:gh:`9122` by `Britta Westner`_) - Fitting `~mne.preprocessing.ICA` on baseline-corrected `~mne.Epochs`, and / or applying it on baseline-corrected `~mne.Epochs` or `~mne.Evoked` data will now display a warning. Users are advised to only baseline correct their data after cleaning is completed (:gh:`9033` by `Richard Höchenberger`_) - -- `mne.preprocessing.compute_proj_eog` and `mne.preprocessing.compute_proj_ecg` now return empty lists if no EOG or ECG events, respectively, could be found. Previously, we'd return ``None`` in these situations, which does not match the documented behavior of returning a list of projectors (:gh:`9277` by `Richard Höchenberger`_)