Skip to content

Commit 65e1aa6

Browse files
Rework how we apply EEG montages (#960)
1 parent 6598017 commit 65e1aa6

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

docs/source/v1.9.md.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
had previously already been marked as bad in the dataset. Resulting entries in the TSV file may now look like:
2626
`"pre-existing (before MNE-BIDS-pipeline was run) & auto-noisy"` (previously: only `"auto-noisy"`). (#930 by @hoechenberger)
2727
- The `ica_ctps_ecg_threshold` has been renamed to [`ica_ecg_threshold`][mne_bids_pipeline._config.ica_ecg_threshold]. (#935 by @hoechenberger)
28+
- We changed the behavior when setting an EEG montage:
29+
- When applying the montage, we now also check for channel aliases (e.g. `M1 -> TP9`).
30+
- If the data contains a channel that is not present in the montage, we now abort with an exception (previously, we emitted a warning).
31+
This is to prevent silent errors. To proceed in this situation, select a different montage, or drop the respective channels via
32+
the [`drop_channels`][mne_bids_pipeline._config.drop_channels] configuration option. (#960 by @hoechenberger)
2833
2934
### :package: Requirements
3035

mne_bids_pipeline/_config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@
346346
You can find an overview of supported template montages at
347347
https://mne.tools/stable/generated/mne.channels.make_standard_montage.html
348348
349+
!!! warning
350+
If the data contains channel names that are not part of the template montage, the
351+
pipeline run will fail with an error message. You must either pick a different
352+
montage or remove those channels via
353+
[`drop_channels`][mne_bids_pipeline._config.drop_channels] to continue.
354+
355+
349356
???+ example "Example"
350357
Do not apply template montage:
351358
```python
@@ -362,7 +369,8 @@
362369
"""
363370
Names of channels to remove from the data. This can be useful, for example,
364371
if you have added a new bipolar channel via `eeg_bipolar_channels` and now wish
365-
to remove the anode, cathode, or both.
372+
to remove the anode, cathode, or both; or if your selected EEG template montage
373+
doesn't contain coordinates for some channels.
366374
367375
???+ example "Example"
368376
Exclude channels `Fp1` and `Cz` from processing:

mne_bids_pipeline/_import_data.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,10 @@ def _set_eeg_montage(
326326
Modifies ``raw`` in-place.
327327
"""
328328
montage = cfg.eeg_template_montage
329-
is_mne_montage = isinstance(montage, mne.channels.montage.DigMontage)
330-
montage_name = "custom_montage" if is_mne_montage else montage
331329
if cfg.datatype == "eeg" and montage:
332330
msg = f"Setting EEG channel locations to template montage: " f"{montage}."
333331
logger.info(**gen_log_kwargs(message=msg))
334-
if not is_mne_montage:
335-
montage = mne.channels.make_standard_montage(montage_name)
336-
raw.set_montage(montage, match_case=False, on_missing="warn")
332+
raw.set_montage(montage, match_case=False, match_alias=True)
337333

338334

339335
def _fix_stim_artifact_func(cfg: SimpleNamespace, raw: mne.io.BaseRaw) -> None:

0 commit comments

Comments
 (0)