From ca0cebd9afcf8c3bdd931fb0055e1a9edb142153 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Sat, 15 Sep 2018 23:04:36 -0400 Subject: [PATCH 1/5] FIX bug in meg picks during interpolation --- autoreject/utils.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/autoreject/utils.py b/autoreject/utils.py index b3a63098..4d0c6a52 100644 --- a/autoreject/utils.py +++ b/autoreject/utils.py @@ -356,22 +356,20 @@ def _interpolate_bads_meg_fast(inst, picks, mode='accurate', verbose=None): else: picked_info = inst.info.copy() - def get_picks_bad_good(info): - picks_meg = pick_types(info, meg=True, eeg=False, exclude=[], - stim=False) - ch_names = [info['ch_names'][p] for p in picks_meg] - picks_good = pick_types(info, meg=True, eeg=False, exclude='bads', - stim=False) + def get_picks_bad_good(info, picks_meg): + picks_good = [p for p in picks_meg + if info['ch_names'][p] not in info['bads']] # select the bad meg channel to be interpolated if len(info['bads']) == 0: picks_bad = [] else: - picks_bad = pick_channels(ch_names, info['bads'], - exclude=[]) + picks_bad = [p for p in picks_meg + if info['ch_names'][p] in info['bads']] return picks_meg, picks_good, picks_bad - picks_meg, picks_good, picks_bad = get_picks_bad_good(picked_info) + picks_meg, picks_good, picks_bad = get_picks_bad_good( + picked_info, range(picked_info['nchan'])) # return without doing anything if there are no meg channels if len(picks_meg) == 0 or len(picks_bad) == 0: return @@ -386,7 +384,8 @@ def get_picks_bad_good(info): # the unpicked info of the data. # Since we may have picked the info, we need to double map # the indices. - _, picks_good_, picks_bad_orig = get_picks_bad_good(inst.info.copy()) + _, picks_good_, picks_bad_orig = get_picks_bad_good( + inst.info.copy(), picks) ch_names_a = [picked_info['ch_names'][pp] for pp in picks_bad] ch_names_b = [inst.info['ch_names'][pp] for pp in picks_bad_orig] assert ch_names_a == ch_names_b From f76b7ab1f673b678e0c745e840bbcf2dcac44eac Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Sun, 16 Sep 2018 00:21:22 -0400 Subject: [PATCH 2/5] TST add test for interpolate_bads --- autoreject/tests/test_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/autoreject/tests/test_utils.py b/autoreject/tests/test_utils.py index eacddfd0..d8608239 100644 --- a/autoreject/tests/test_utils.py +++ b/autoreject/tests/test_utils.py @@ -63,3 +63,20 @@ def test_utils(): _interpolate_bads_eeg(evoked_ar, picks=None) mne.channels.interpolation._interpolate_bads_eeg(evoked_mne) assert_array_equal(evoked_ar.data, evoked_mne.data) + + +def test_interpolate_bads(): + """Test interpolate bads""" + event_id = None + events = mne.find_events(raw) + tmin, tmax = -0.2, 0.5 + for ii, ch_name in enumerate(raw.info['ch_names'][:14]): + raw.set_channel_types({ch_name: 'bio'}) + raw.rename_channels({ch_name: 'BIO%02d' % ii}) + + picks = mne.pick_types(raw.info, meg='grad', eeg=False, eog=False) + epochs = mne.Epochs(raw, events, event_id, tmin, tmax, + baseline=(None, 0), decim=10, + reject=None, preload=True)[:10] + epochs.info['bads'] = ['MEG 2212'] + interpolate_bads(epochs, picks) From 1000b261975d7cbf594fc4b6901561b13a266841 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Sun, 16 Sep 2018 00:30:27 -0400 Subject: [PATCH 3/5] Flake8 --- autoreject/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoreject/utils.py b/autoreject/utils.py index 4d0c6a52..d96f9f37 100644 --- a/autoreject/utils.py +++ b/autoreject/utils.py @@ -10,7 +10,7 @@ import mne from mne.utils import check_version as version_is_greater_equal -from mne import pick_types, pick_channels, pick_info +from mne import pick_types, pick_info from mne.channels.interpolation import _do_interp_dots from mne.externals import six From a529c0bb79e9fe8ccb6f9f244af46c6a06e5ecb9 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Sun, 16 Sep 2018 19:08:36 -0400 Subject: [PATCH 4/5] Bump up version of packages --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bd544f61..739ddcf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_install: install: - conda create -n testenv --yes pip python=${PYTHON_VERSION} - source activate testenv - - conda install --yes --quiet numpy=1.12 scipy=0.19 scikit-learn=0.18 matplotlib + - conda install --yes --quiet numpy scipy scikit-learn matplotlib - conda install --yes --quiet nose coverage - pip install -q flake8 mne check-manifest - pip install coverage coveralls From 096abba220fddc76198397fd49a34e773774dfdd Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Tue, 18 Sep 2018 13:45:35 -0400 Subject: [PATCH 5/5] DOC Add what's new --- doc/conf.py | 1 + doc/whats_new.rst | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 doc/whats_new.rst diff --git a/doc/conf.py b/doc/conf.py index 21830b47..fb734e16 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -132,6 +132,7 @@ ("Examples", "auto_examples/index"), ("API", "api"), ("FAQ", "faq"), + ("What's new", "whats_new"), ("GitHub", "https://github.com/autoreject/autoreject", True) ], 'bootswatch_theme': "united" diff --git a/doc/whats_new.rst b/doc/whats_new.rst new file mode 100644 index 00000000..312357e3 --- /dev/null +++ b/doc/whats_new.rst @@ -0,0 +1,27 @@ +:orphan: + +.. _whats_new: + +What's new? +=========== + +.. currentmodule:: autoreject + +.. _current: + +Current +------- + +Changelog +~~~~~~~~~ + +Bug +~~~ + +- Fixed bug in picking bad channels during interpolation. This bug only affects users who got an assertion + error when running :class:`autoreject.Autoreject`. Fixed by `Mainak Jas`_ in `#115 `_ + +API +~~~ + +.. _Mainak Jas: https://perso.telecom-paristech.fr/mjas/