Skip to content

Commit

Permalink
MRG, BUG: Fix Xdawn check (#8496)
Browse files Browse the repository at this point in the history
* BUG: Fix Xdawn check

* DOC: Headings

* FIX: Backport maxwell fix

* FIX: Spelling
  • Loading branch information
larsoner authored Nov 15, 2020
1 parent da066d8 commit 49bb34f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
2 changes: 2 additions & 0 deletions doc/changes/0.21.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Bugs

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

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


.. _changes_0_21_1:

Expand Down
2 changes: 1 addition & 1 deletion examples/inverse/plot_label_source_activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
###############################################################################
# Compute inverse solution
# ------------------------
pick_ori = "normal" # Get signed values to see the effect of sign filp
pick_ori = "normal" # Get signed values to see the effect of sign flip
stc = apply_inverse(evoked, inverse_operator, lambda2, method,
pick_ori=pick_ori)

Expand Down
2 changes: 1 addition & 1 deletion mne/channels/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_interpolation_meg():
"""Test interpolation of MEG channels."""
# speed accuracy tradeoff: channel subselection is faster but the
# correlation drops
thresh = 0.7
thresh = 0.68

raw, epochs_meg = _load_data('meg')

Expand Down
29 changes: 9 additions & 20 deletions mne/preprocessing/tests/test_maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
_sh_real_to_complex, _sh_negate, _bases_complex_to_real, _trans_sss_basis,
_bases_real_to_complex, _prep_mf_coils, find_bad_channels_maxwell)
from mne.rank import _get_rank_sss, _compute_rank_int
from mne.utils import (assert_meg_snr, run_tests_if_main, catch_logging,
from mne.utils import (assert_meg_snr, catch_logging,
object_diff, buggy_mkl_svd, use_log_level)

data_path = testing.data_path(download=False)
Expand Down Expand Up @@ -1339,14 +1339,11 @@ def test_find_bad_channels_maxwell(fname, bads, annot, add_ch, ignore_ref,
# Check "flat" scores.
scores_flat = got_scores['scores_flat']
limits_flat = got_scores['limits_flat']
# The following essentially is just this:
# n_segments_below_limit = (scores_flat < limits_flat).sum(-1)
# made to work with NaN's in the scores.
n_segments_below_limit = np.less(
scores_flat, limits_flat,
where=np.equal(np.isnan(scores_flat), False),
out=np.full_like(scores_flat, fill_value=False)).sum(-1)

# Deal with NaN's in the scores (can't use np.less directly because of
# https://github.com/numpy/numpy/issues/17198)
scores_flat[np.isnan(scores_flat)] = np.inf
limits_flat[np.isnan(limits_flat)] = -np.inf
n_segments_below_limit = (scores_flat < limits_flat).sum(-1)
ch_idx = np.where(n_segments_below_limit >=
min(min_count, len(got_scores['bins'])))
flats = set(got_scores['ch_names'][ch_idx])
Expand All @@ -1355,18 +1352,10 @@ def test_find_bad_channels_maxwell(fname, bads, annot, add_ch, ignore_ref,
# Check "noisy" scores.
scores_noisy = got_scores['scores_noisy']
limits_noisy = got_scores['limits_noisy']
# The following essentially is just this:
# n_segments_beyond_limit = (scores_noisy > limits_noisy).sum(-1)
# made to work with NaN's in the scores.
n_segments_beyond_limit = np.greater(
scores_noisy, limits_noisy,
where=np.equal(np.isnan(scores_noisy), False),
out=np.full_like(scores_noisy, fill_value=False)).sum(-1)

scores_noisy[np.isnan(scores_noisy)] = -np.inf
limits_noisy[np.isnan(limits_noisy)] = np.inf
n_segments_beyond_limit = (scores_noisy > limits_noisy).sum(-1)
ch_idx = np.where(n_segments_beyond_limit >=
min(min_count, len(got_scores['bins'])))
bads = set(got_scores['ch_names'][ch_idx])
assert bads == set(want_bads)


run_tests_if_main()
9 changes: 2 additions & 7 deletions mne/preprocessing/tests/test_xdawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
import os.path as op
import sys

from numpy.testing import (assert_array_equal, assert_array_almost_equal,
assert_allclose)
Expand All @@ -16,7 +15,7 @@
create_info, EpochsArray)
from mne.decoding import Vectorizer
from mne.io import read_raw_fif
from mne.utils import requires_sklearn, run_tests_if_main, check_version
from mne.utils import requires_sklearn, check_version
from mne.preprocessing.xdawn import Xdawn, _XdawnTransformer

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


run_tests_if_main()
2 changes: 1 addition & 1 deletion mne/viz/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _plot_ica_properties(pick, ica, inst, psds_mean, freqs, n_trials,
else:
x = np.linspace(ymin, ymax, 50)
kde_ = kde(x)
kde_ /= kde_.max()
kde_ /= kde_.max() or 1.
kde_ *= hist_ax.get_xlim()[-1] * .9
hist_ax.plot(kde_, x, color="k")
hist_ax.set_ylim(ymin, ymax)
Expand Down

0 comments on commit 49bb34f

Please sign in to comment.