Skip to content

Commit 49bb34f

Browse files
authored
MRG, BUG: Fix Xdawn check (#8496)
* BUG: Fix Xdawn check * DOC: Headings * FIX: Backport maxwell fix * FIX: Spelling
1 parent da066d8 commit 49bb34f

File tree

6 files changed

+16
-30
lines changed

6 files changed

+16
-30
lines changed

doc/changes/0.21.inc

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Bugs
2121

2222
- Fix bug in :func:`mne.preprocessing.compute_fine_calibration` where the magnetometer calibration coefficients were computed incorrectly (:gh:`8522` by `Eric Larson`_)
2323

24+
- Fix bug in :class:`mne.preprocessing.Xdawn` tests by `Eric Larson`_ (:gh:`8496`)
25+
2426

2527
.. _changes_0_21_1:
2628

examples/inverse/plot_label_source_activations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
###############################################################################
4242
# Compute inverse solution
4343
# ------------------------
44-
pick_ori = "normal" # Get signed values to see the effect of sign filp
44+
pick_ori = "normal" # Get signed values to see the effect of sign flip
4545
stc = apply_inverse(evoked, inverse_operator, lambda2, method,
4646
pick_ori=pick_ori)
4747

mne/channels/tests/test_interpolation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_interpolation_meg():
157157
"""Test interpolation of MEG channels."""
158158
# speed accuracy tradeoff: channel subselection is faster but the
159159
# correlation drops
160-
thresh = 0.7
160+
thresh = 0.68
161161

162162
raw, epochs_meg = _load_data('meg')
163163

mne/preprocessing/tests/test_maxwell.py

+9-20
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_sh_real_to_complex, _sh_negate, _bases_complex_to_real, _trans_sss_basis,
2929
_bases_real_to_complex, _prep_mf_coils, find_bad_channels_maxwell)
3030
from mne.rank import _get_rank_sss, _compute_rank_int
31-
from mne.utils import (assert_meg_snr, run_tests_if_main, catch_logging,
31+
from mne.utils import (assert_meg_snr, catch_logging,
3232
object_diff, buggy_mkl_svd, use_log_level)
3333

3434
data_path = testing.data_path(download=False)
@@ -1339,14 +1339,11 @@ def test_find_bad_channels_maxwell(fname, bads, annot, add_ch, ignore_ref,
13391339
# Check "flat" scores.
13401340
scores_flat = got_scores['scores_flat']
13411341
limits_flat = got_scores['limits_flat']
1342-
# The following essentially is just this:
1343-
# n_segments_below_limit = (scores_flat < limits_flat).sum(-1)
1344-
# made to work with NaN's in the scores.
1345-
n_segments_below_limit = np.less(
1346-
scores_flat, limits_flat,
1347-
where=np.equal(np.isnan(scores_flat), False),
1348-
out=np.full_like(scores_flat, fill_value=False)).sum(-1)
1349-
1342+
# Deal with NaN's in the scores (can't use np.less directly because of
1343+
# https://github.com/numpy/numpy/issues/17198)
1344+
scores_flat[np.isnan(scores_flat)] = np.inf
1345+
limits_flat[np.isnan(limits_flat)] = -np.inf
1346+
n_segments_below_limit = (scores_flat < limits_flat).sum(-1)
13501347
ch_idx = np.where(n_segments_below_limit >=
13511348
min(min_count, len(got_scores['bins'])))
13521349
flats = set(got_scores['ch_names'][ch_idx])
@@ -1355,18 +1352,10 @@ def test_find_bad_channels_maxwell(fname, bads, annot, add_ch, ignore_ref,
13551352
# Check "noisy" scores.
13561353
scores_noisy = got_scores['scores_noisy']
13571354
limits_noisy = got_scores['limits_noisy']
1358-
# The following essentially is just this:
1359-
# n_segments_beyond_limit = (scores_noisy > limits_noisy).sum(-1)
1360-
# made to work with NaN's in the scores.
1361-
n_segments_beyond_limit = np.greater(
1362-
scores_noisy, limits_noisy,
1363-
where=np.equal(np.isnan(scores_noisy), False),
1364-
out=np.full_like(scores_noisy, fill_value=False)).sum(-1)
1365-
1355+
scores_noisy[np.isnan(scores_noisy)] = -np.inf
1356+
limits_noisy[np.isnan(limits_noisy)] = np.inf
1357+
n_segments_beyond_limit = (scores_noisy > limits_noisy).sum(-1)
13661358
ch_idx = np.where(n_segments_beyond_limit >=
13671359
min(min_count, len(got_scores['bins'])))
13681360
bads = set(got_scores['ch_names'][ch_idx])
13691361
assert bads == set(want_bads)
1370-
1371-
1372-
run_tests_if_main()

mne/preprocessing/tests/test_xdawn.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import numpy as np
77
import os.path as op
8-
import sys
98

109
from numpy.testing import (assert_array_equal, assert_array_almost_equal,
1110
assert_allclose)
@@ -16,7 +15,7 @@
1615
create_info, EpochsArray)
1716
from mne.decoding import Vectorizer
1817
from mne.io import read_raw_fif
19-
from mne.utils import requires_sklearn, run_tests_if_main, check_version
18+
from mne.utils import requires_sklearn, check_version
2019
from mne.preprocessing.xdawn import Xdawn, _XdawnTransformer
2120

2221
base_dir = op.join(op.dirname(__file__), '..', '..', 'io', 'tests', 'data')
@@ -194,8 +193,7 @@ def test_xdawn_regularization():
194193
xd.fit(epochs)
195194
xd = Xdawn(correct_overlap=False, reg='diagonal_fixed')
196195
xd.fit(epochs)
197-
bad_eig = (sys.platform.startswith('win') and
198-
check_version('numpy', '1.16.5')) # some problem with on Win
196+
bad_eig = check_version('numpy', '1.16.5') # some problem with newer NumPy
199197
if bad_eig:
200198
pytest.skip('Unknown MKL+Windows error fails for eig check')
201199
xd = Xdawn(correct_overlap=False, reg=None)
@@ -353,6 +351,3 @@ def test_xdawn_decoding_performance():
353351
for i in range(len(relev_patterns)):
354352
r, _ = stats.pearsonr(relev_patterns[i, :], mixing_mat[0, :])
355353
assert np.abs(r) > 0.99
356-
357-
358-
run_tests_if_main()

mne/viz/ica.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _plot_ica_properties(pick, ica, inst, psds_mean, freqs, n_trials,
190190
else:
191191
x = np.linspace(ymin, ymax, 50)
192192
kde_ = kde(x)
193-
kde_ /= kde_.max()
193+
kde_ /= kde_.max() or 1.
194194
kde_ *= hist_ax.get_xlim()[-1] * .9
195195
hist_ax.plot(kde_, x, color="k")
196196
hist_ax.set_ylim(ymin, ymax)

0 commit comments

Comments
 (0)