From df2c881091dd99c588600bc8f33c9ad056aacb83 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Sun, 30 May 2021 16:20:11 +0200 Subject: [PATCH] FIX : rank computation from info now uses SSS proc history if only grad or mag are present --- doc/changes/latest.inc | 2 ++ mne/rank.py | 2 +- mne/tests/test_rank.py | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index 1509209aff2..39efb7b87bd 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -59,6 +59,8 @@ Bugs - Fix bug when printing a :class:`mne.io.RawArray` in the notebook (:gh:`9404` by `Alex Gramfort`_) +- Fix bug when computing rank from info for SSS data with only gradiometers or magnetometers (:gh:`9435` by `Alex Gramfort`_) + API changes ~~~~~~~~~~~ - Nothing yet diff --git a/mne/rank.py b/mne/rank.py index 04695603f04..05ddf413743 100644 --- a/mne/rank.py +++ b/mne/rank.py @@ -256,7 +256,7 @@ def _get_rank_sss(inst, msg='You should use data-based rank estimate instead', def _info_rank(info, ch_type, picks, rank): - if ch_type == 'meg' and rank != 'full': + if ch_type in ['meg', 'mag', 'grad'] and rank != 'full': try: return _get_rank_sss(info) except ValueError: diff --git a/mne/tests/test_rank.py b/mne/tests/test_rank.py index e3aa0e760db..7ac9b28cb65 100644 --- a/mne/tests/test_rank.py +++ b/mne/tests/test_rank.py @@ -204,7 +204,11 @@ def test_maxfilter_get_rank(n_proj, fname, rank_orig, meg, tol_kind, tol): assert raw.info['projs'] == [] mf = raw.info['proc_history'][0]['max_info'] assert mf['sss_info']['nfree'] == rank_orig - assert _get_rank_sss(raw) == rank_orig + + assert compute_rank(raw, 'info')['meg'] == rank_orig + assert compute_rank(raw.copy().pick('grad'), 'info')['grad'] == rank_orig + assert compute_rank(raw.copy().pick('mag'), 'info')['mag'] == rank_orig + mult = 1 + (meg == 'separate') rank = rank_orig - mult * n_proj if n_proj > 0: