Skip to content

Commit 7fb3ef2

Browse files
authored
BUG: Fix bug with compute_maxwell_basis(..., int_order=0) (mne-tools#11562)
1 parent f628e19 commit 7fb3ef2

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

doc/changes/latest.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Bugs
5454
- All functions accepting paths can now correctly handle :class:`~pathlib.Path` as input. Historically, we expected strings (instead of "proper" path objects), and only added :class:`~pathlib.Path` support in a few select places, leading to inconsistent behavior. (:gh:`11473` and :gh:`11499` by `Mathieu Scheltienne`_)
5555
- Fix visualization dialog compatibility with matplotlib 3.7 (:gh:`11409` by `Daniel McCloy`_ and `Eric Larson`_)
5656
- Expand tilde (user directory) in config keys (:gh:`11537` by `Clemens Brunner`_)
57+
- Fix bug in :func:`mne.preprocessing.compute_maxwell_basis` where using ``int_order=0`` would raise an error (:gh:`11562` by `Eric Larson`_)
5758
- Fix :func:`mne.io.read_raw` for file names containing multiple dots (:gh:`11521` by `Clemens Brunner`_)
5859
5960
API changes

mne/preprocessing/maxwell.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,18 +1978,24 @@ def _regularize_in(int_order, ext_order, S_decomp, mag_or_fine,
19781978
# Pick the components that give at least 98% of max info
19791979
# This is done because the curves can be quite flat, and we err on the
19801980
# side of including rather than excluding components
1981-
max_info = np.max(I_tots)
1982-
lim_idx = np.where(I_tots >= 0.98 * max_info)[0][0]
1983-
in_removes = remove_order[:lim_idx]
1984-
for ii, ri in enumerate(in_removes):
1985-
logger.debug(' Condition %0.3f/%0.3f = %03.1f, '
1986-
'Removing in component %s: l=%s, m=%+0.0f'
1987-
% (tuple(eigs[ii]) + (eigs[ii, 0] / eigs[ii, 1],
1988-
ri, degrees[ri], orders[ri])))
1989-
logger.debug(' Resulting information: %0.1f bits/sample '
1990-
'(%0.1f%% of peak %0.1f)'
1991-
% (I_tots[lim_idx], 100 * I_tots[lim_idx] / max_info,
1992-
max_info))
1981+
if n_in:
1982+
max_info = np.max(I_tots)
1983+
lim_idx = np.where(I_tots >= 0.98 * max_info)[0][0]
1984+
in_removes = remove_order[:lim_idx]
1985+
for ii, ri in enumerate(in_removes):
1986+
eig = eigs[ii]
1987+
logger.debug(
1988+
f' Condition {eig[0]:0.3f} / {eig[1]:0.3f} = '
1989+
f'{eig[0] / eig[1]:03.1f}, Removing in component '
1990+
f'{ri}: l={degrees[ri]}, m={orders[ri]:+0.0f}'
1991+
)
1992+
logger.debug(
1993+
f' Resulting information: {I_tots[lim_idx]:0.1f} '
1994+
f'bits/sample ({100 * I_tots[lim_idx] / max_info:0.1f}% of peak '
1995+
f'{max_info:0.1f})'
1996+
)
1997+
else:
1998+
in_removes = remove_order[:0]
19931999
return in_removes, out_removes
19942000

19952001

mne/preprocessing/tests/test_maxwell.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,19 +1438,21 @@ def test_find_bads_maxwell_flat():
14381438
assert noisy == want_noisy
14391439

14401440

1441-
@pytest.mark.parametrize('regularize, n', [
1442-
(None, 80),
1443-
('in', 71),
1441+
@pytest.mark.parametrize('regularize, n, int_order', [
1442+
(None, 80, 8),
1443+
('in', 71, 8),
1444+
(None, 0, 0),
1445+
('in', 0, 0),
14441446
])
1445-
def test_compute_maxwell_basis(regularize, n):
1447+
def test_compute_maxwell_basis(regularize, n, int_order):
14461448
"""Test compute_maxwell_basis."""
14471449
raw = read_raw_fif(raw_small_fname).crop(0, 2)
14481450
assert raw.info['bads'] == []
14491451
raw.del_proj()
14501452
rank = compute_rank(raw)['meg']
14511453
assert rank == 306
14521454
raw.info['bads'] = ['MEG 2443']
1453-
kwargs = dict(regularize=regularize, verbose=True)
1455+
kwargs = dict(regularize=regularize, int_order=int_order, verbose=True)
14541456
raw_sss = maxwell_filter(raw, **kwargs)
14551457
want = raw_sss.get_data('meg')
14561458
rank = compute_rank(raw_sss)['meg']

mne/tests/test_import_nesting.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
import sys
66
from mne.utils import run_subprocess
77

8+
# To keep `import mne` time down, we nest most imports, including those of
9+
# required dependencies (e.g., pooch, tqdm, matplotlib). SciPy submodules
10+
# (esp. linalg) can take a while to load, so these imports must be nested, too.
11+
# NumPy is the exception -- it can be imported directly at the top of files.
12+
# N.B. that jinja2 is imported directly in mne/html_templates, so all imports
13+
# of mne.html_templates must be nested to achieve the jinja2 import being
14+
# nested during import of mne.
15+
#
16+
# This test ensures that we don't accidentally un-nest any of these imports.
817

918
run_script = """
1019
import sys
@@ -13,8 +22,7 @@
1322
out = set()
1423
1524
# check scipy (Numba imports it to check the version)
16-
ok_scipy_submodules = set(['scipy', 'numpy', # these appear in old scipy
17-
'version'])
25+
ok_scipy_submodules = {'version'}
1826
scipy_submodules = set(x.split('.')[1] for x in sys.modules.keys()
1927
if x.startswith('scipy.') and '__' not in x and
2028
not x.split('.')[1].startswith('_')

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ xlrd
3232
imageio>=2.6.1
3333
imageio-ffmpeg>=0.4.1
3434
traitlets
35-
pyvista>=0.32,!=0.35.2,!=0.38.0,!=0.38.1,!=0.38.2,!=0.38.3
35+
pyvista>=0.32,!=0.35.2,!=0.38.0,!=0.38.1,!=0.38.2,!=0.38.3,!=0.38.4
3636
pyvistaqt>=0.4
3737
mffpy>=0.5.7
3838
ipywidgets

0 commit comments

Comments
 (0)