Skip to content

Commit cbeeb98

Browse files
SophieHerbstpre-commit-ci[bot]larsoner
authored
change default for info to use for inverse #905 (#919)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Larson <[email protected]>
1 parent 6288770 commit cbeeb98

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

docs/source/v1.9.md.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
### :warning: Behavior changes
1010

11+
- Changed default for `source_info_path_update` to `None`. In `_04_make_forward.py`
12+
and `_05_make_inverse.py`, we retrieve the info from the file from which
13+
the `noise_cov` is computed (#919 by @SophieHerbst)
1114
- The [`depth`][mne_bids_pipeline._config.depth] parameter doesn't accept `None`
1215
anymore. Please use `0` instead. (#915 by @hoechenberger)
1316

mne_bids_pipeline/_config.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,22 +2098,35 @@ def noise_cov(bids_path):
20982098
of `mne.compute_covariance` for details.
20992099
"""
21002100

2101-
source_info_path_update: dict[str, str] | None = dict(suffix="ave")
2101+
source_info_path_update: dict[str, str] | None = None
21022102
"""
2103-
When computing the forward and inverse solutions, by default the pipeline
2104-
retrieves the `mne.Info` object from the cleaned evoked data. However, in
2105-
certain situations you may wish to use a different `Info`.
2106-
2103+
When computing the forward and inverse solutions, it is important to
2104+
provide the `mne.Info` object from the data on which the noise covariance was
2105+
computed, to avoid problems resulting from mismatching ranks.
21072106
This parameter allows you to explicitly specify from which file to retrieve the
21082107
`mne.Info` object. Use this parameter to supply a dictionary to
21092108
`BIDSPath.update()` during the forward and inverse processing steps.
2109+
If set to `None` (default), the info will be retrieved either from the raw
2110+
file specified in `noise_cov`, or the cleaned evoked
2111+
(if `noise_cov` is None or `ad-hoc`).
21102112
21112113
???+ example "Example"
21122114
Use the `Info` object stored in the cleaned epochs:
21132115
```python
21142116
source_info_path_update = {'processing': 'clean',
21152117
'suffix': 'epo'}
21162118
```
2119+
2120+
Use the `Info` object stored in a raw file (e.g. resting state):
2121+
```python
2122+
source_info_path_update = {'processing': 'clean',
2123+
'suffix': 'raw',
2124+
'task': 'rest'}
2125+
```
2126+
If you set `noise_cov = 'rest'` and `source_path_info = None`,
2127+
then the behavior is identical to that above
2128+
(it will automatically use the resting state data).
2129+
21172130
"""
21182131

21192132
inverse_targets: list[Literal["evoked"]] = ["evoked"]

mne_bids_pipeline/_config_import.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ def _default_factory(key, val):
344344
allowlist = [
345345
{"n_mag": 1, "n_grad": 1, "n_eeg": 1}, # n_proj_*
346346
{"custom": (8, 24.0, 40)}, # decoding_csp_freqs
347-
{"suffix": "ave"}, # source_info_path_update
348347
["evoked"], # inverse_targets
349348
[4, 8, 16], # autoreject_n_interpolate
350349
]

mne_bids_pipeline/steps/source/_04_make_forward.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from ..._logging import gen_log_kwargs, logger
2424
from ..._parallel import get_parallel_backend, parallel_func
2525
from ..._report import _open_report, _render_bem
26-
from ..._run import _prep_out_files, failsafe_run, save_logs
26+
from ..._run import _prep_out_files, _sanitize_callable, failsafe_run, save_logs
2727

2828

2929
def _prepare_trans_template(
@@ -102,7 +102,18 @@ def get_input_fnames_forward(*, cfg, subject, session):
102102
check=False,
103103
)
104104
in_files = dict()
105-
in_files["info"] = bids_path.copy().update(**cfg.source_info_path_update)
105+
# for consistency with 05_make_inverse, read the info from the
106+
# data used for the noise_cov
107+
if cfg.source_info_path_update is None:
108+
if cfg.noise_cov in ("rest", "noise"):
109+
source_info_path_update = dict(
110+
processing="clean", suffix="raw", task=cfg.noise_cov
111+
)
112+
else:
113+
source_info_path_update = dict(suffix="ave")
114+
else:
115+
source_info_path_update = cfg.source_info_path_update
116+
in_files["info"] = bids_path.copy().update(**source_info_path_update)
106117
bem_path = cfg.fs_subjects_dir / cfg.fs_subject / "bem"
107118
_, tag = _get_bem_conductivity(cfg)
108119
in_files["bem"] = bem_path / f"{cfg.fs_subject}-{tag}-bem-sol.fif"
@@ -242,6 +253,7 @@ def get_config(
242253
use_template_mri=config.use_template_mri,
243254
adjust_coreg=config.adjust_coreg,
244255
source_info_path_update=config.source_info_path_update,
256+
noise_cov=_sanitize_callable(config.noise_cov),
245257
ch_types=config.ch_types,
246258
fs_subject=get_fs_subject(config=config, subject=subject),
247259
fs_subjects_dir=get_fs_subjects_dir(config),

mne_bids_pipeline/steps/source/_05_make_inverse.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,19 @@ def get_input_fnames_inverse(
4848
check=False,
4949
)
5050
in_files = dict()
51-
in_files["info"] = bids_path.copy().update(**cfg.source_info_path_update)
51+
# make sure the info matches the data from which the noise cov
52+
# is computed to avoid rank-mismatch
53+
if cfg.source_info_path_update is None:
54+
if cfg.noise_cov in ("rest", "noise"):
55+
source_info_path_update = dict(
56+
processing="clean", suffix="raw", task=cfg.noise_cov
57+
)
58+
else:
59+
source_info_path_update = dict(suffix="ave")
60+
# XXX is this the right solution also for noise_cov = 'ad-hoc'?
61+
else:
62+
source_info_path_update = cfg.source_info_path_update
63+
in_files["info"] = bids_path.copy().update(**source_info_path_update)
5264
in_files["forward"] = bids_path.copy().update(suffix="fwd")
5365
if cfg.noise_cov != "ad-hoc":
5466
in_files["cov"] = get_noise_cov_bids_path(

0 commit comments

Comments
 (0)