MNE-BIDS-Pipeline Maxwell filter reference run rank mismatch

Hi,

I received an error when running the Maxwell filter step in the MNE-BIDS-Pipeline, saying that the rank of the data in the reference rune does not match the empty room data rank, see below:

[10:55:33] β”‚ ❌ preprocessing/_02_maxfilter sub-09 run-01 A critical error occurred. The error message was: Reference run data rank 73.0 does not match empty-room data rank 71.0 after Maxwell filtering. This indicates that the data were processed  differently.

Aborting pipeline run. The full traceback is:

Traceback (most recent call last):

  File "/home/ma09/.conda/envs/my_mne1.4_fix/lib/python3.11/site-packages/mne_bids_pipeline/_run.py", line 54, in wrapper
    out = memory.cache(func)(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/ma09/.conda/envs/my_mne1.4_fix/lib/python3.11/site-packages/mne_bids_pipeline/_run.py", line 263, in wrapper
    out_files = memorized_func(*args, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/ma09/.conda/envs/my_mne1.4_fix/lib/python3.11/site-packages/joblib/memory.py", line 594, in __call__
    return self._cached_call(args, kwargs)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/ma09/.conda/envs/my_mne1.4_fix/lib/python3.11/site-packages/joblib/memory.py", line 537, in _cached_call
    out, metadata = self.call(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/ma09/.conda/envs/my_mne1.4_fix/lib/python3.11/site-packages/joblib/memory.py", line 779, in call
    output = self.func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/ma09/.conda/envs/my_mne1.4_fix/lib/python3.11/site-packages/mne_bids_pipeline/steps/preprocessing/_02_maxfilter.py", line 264, in run_maxwell_filter
    raise RuntimeError(msg)

RuntimeError: Reference run data rank 73.0 does not match empty-room data rank 71.0 after Maxwell filtering. This indicates that the data were processed  differently.

This occurred only with a specific subject in the dataset and it has to do with which run I set as reference. If I set mf_reference_run = '03', I get the error, however, if I set mf_reference_run = '01', then the Maxwell filter step runs fine without an error.

I’m not sure why the data rank in run 3 would be different than in run 1? I’m wondering if this has to do with the recently fixed bug about setting the mf_reference_run parameter to anything else than '01'?

Could anyone please help?

Many thanks,
MΓ‘tΓ©

System info:

Platform             Linux-3.10.0-1160.el7.x86_64-x86_64-with-glibc2.17
Python               3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:28:47) [GCC 11.3.0]
Executable           /home/ma09/.conda/envs/my_mne1.4_fix/bin/python
CPU                  x86_64 (32 cores)
Memory               251.4 GB

Core
β”œβ˜‘ mne               1.4.2
β”œβ˜‘ numpy             1.24.3 (OpenBLAS 0.3.23 with 32 threads)
β”œβ˜‘ scipy             1.10.1
β”œβ˜‘ matplotlib        3.7.1 (backend=agg)
β”œβ˜‘ pooch             1.7.0
β””β˜‘ jinja2            3.1.2

Numerical (optional)
β”œβ˜‘ sklearn           1.2.2
β”œβ˜‘ numba             0.57.0
β”œβ˜‘ nibabel           5.1.0
β”œβ˜‘ nilearn           0.10.1
β”œβ˜‘ dipy              1.7.0
β”œβ˜‘ openmeeg          2.5.6
β”œβ˜‘ pandas            2.0.2
β””β˜ unavailable       cupy

Visualization (optional)
β”œβ˜‘ pyvista           0.39.1 (OpenGL unavailable)
β”œβ˜‘ pyvistaqt         0.0.0
β”œβ˜‘ ipyvtklink        0.2.2
β”œβ˜‘ vtk               9.2.5
β”œβ˜‘ qtpy              2.3.1 (None=None)
β”œβ˜‘ pyqtgraph         0.13.3
β”œβ˜‘ mne-qt-browser    0.5.1
β””β˜ unavailable       ipympl

Ecosystem (optional)
β”œβ˜‘ mne-bids          0.13.dev0
β”œβ˜‘ mne-bids-pipeline 1.4.0.dev3+gb0cf4a0
β””β˜ unavailable       mne-nirs, mne-features, mne-connectivity, mne-icalabel

Just following up on this, can anyone please help? Pinging @larsoner @richard @agramfort

MΓ‘tΓ©

This can happen if the set of bad channels differs between the runs. Can you run with --debug then p raw_noise.info['bads'] and then also for the other instance/info and see if this is the case?

1 Like

… we should probably add an option to allow you to ignore this. It’s a kind of expert seeing but this rank issue is only a probably sometimes. It is something that we should fix and I think there might even be a note in the code about it

1 Like

Thanks @larsoner, I’ll look into this very soon and report back.

This is indeed the case:

(Pdb) raw_noise.info['bads']
['MEG0743', 'MEG1613', 'MEG1831', 'MEG1832', 'MEG1833', 'MEG2011', 'MEG2012', 'MEG2013', 'MEG2141']
(Pdb) raw_sss.info['bads']
['EEG002', 'EEG040']
(Pdb) 

Best,
MΓ‘tΓ©

:frowning:

Can you open a MNE-BIDS-Pipeline issue on GitHub about this? We’ll have to think about how to deal with this use case properly

Sure, I opened a new issue here: Error due to mismatch between Maxwell filter reference run and empty room data rank Β· Issue #759 Β· mne-tools/mne-bids-pipeline Β· GitHub

I’m just wondering why this issue doesn’t occur if the reference run is set to β€˜01’? Is it just sheer luck? I mean it is perfectly possible for run-01 to have different channels rejected than the emptyroom recording. Although the empty room recording has been taken just before run-01, so channel noise might be more similar to the empty room recodign in run-01 than in run-03?

fixed by PR #761: BUG: Fix bug with empty room processing by larsoner Β· Pull Request #761 Β· mne-tools/mne-bids-pipeline Β· GitHub