Skip to content

Commit 12c3483

Browse files
committed
add optional task- to electrodes.tsv
1 parent 59e61e3 commit 12c3483

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

CITATION.cff

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ authors:
214214
family-names: Ritz
215215
affiliation: 'Princeton Neuroscience Institute, Princeton University, Princeton, USA'
216216
orcid: 'https://orcid.org/0009-0003-1477-4912'
217+
- given-names: Alex
218+
family-names: Lopez Marquez
219+
affiliation: 'Institut Guttmann, Barcelona, Spain'
220+
orcid: 'https://orcid.org/0000-0002-3353-280X'
217221
- given-names: Alexandre
218222
family-names: Gramfort
219223
affiliation: 'Université Paris-Saclay, Inria, CEA, Palaiseau, France'

doc/authors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.. _Aaron Earle-Richardson: https://github.com/Aaronearlerichardson
22
.. _Adam Li: https://github.com/adam2392
3+
.. _Alex Lopez Marquez: https://github.com/alm180
34
.. _Alex Rockhill: https://github.com/alexrockhill
45
.. _Alexandre Gramfort: http://alexandre.gramfort.net
56
.. _Amaia Benitez: https://github.com/AmaiaBA

doc/whats_new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The following authors contributed for the first time. Thank you so much! 🤩
2222
* `Arne Gottwald`_
2323
* `Matthias Dold`_
2424
* `Harrison Ritz`_
25+
* `Alex Lopez Marquez`_
2526

2627
The following authors had contributed before. Thank you for sticking around! 🤘
2728

@@ -44,6 +45,7 @@ Detailed list of changes
4445
- :func:`mne_bids.get_entity_vals()` has a new parameter ``include_match`` to prefilter item matching and ignore non-matched items from begin of directory scan, by `Arne Gottwald` (:gh:`1355`)
4546
- Data from ``events.tsv`` can now be read into an OrderedDict using :func:`mne_bids.events_file_to_annotation_kwargs()`, by `Matthias Dold` (:gh:`1389`)
4647
- Read the optionally present extra columns from ``events.tsv`` and pass them to :class:`mne.Annotations`, by `Pierre Guetschel` (:gh:`1401`)
48+
- :func:`mne_bids.write_raw_bids()` has a new parameter `electrodes_tsv_task` which allows adding the `task` entity to the `electrodes.tsv` filepath, by `Alex Lopez Marquez`_ (:gh:`1424`)
4749

4850

4951
🧐 API and behavior changes

mne_bids/dig.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,14 @@ def _write_coordsystem_json(
385385
_write_json(fname, fid_json, overwrite=True)
386386

387387

388-
def _write_dig_bids(bids_path, raw, montage=None, acpc_aligned=False, overwrite=False):
388+
def _write_dig_bids(
389+
bids_path,
390+
raw,
391+
montage=None,
392+
acpc_aligned=False,
393+
electrodes_tsv_task=False,
394+
overwrite=False,
395+
):
389396
"""Write BIDS formatted DigMontage from Raw instance.
390397
391398
Handles coordsystem.json and electrodes.tsv writing
@@ -405,6 +412,9 @@ def _write_dig_bids(bids_path, raw, montage=None, acpc_aligned=False, overwrite=
405412
must be transformed from the "head" coordinate frame.
406413
acpc_aligned : bool
407414
Whether "mri" space is aligned to ACPC.
415+
electrodes_tsv_task : bool
416+
Whether to add the ``task-`` entity to the ``BIDSPath`` of
417+
the ``electrodes.tsv`` file. Defaults to ``False``.
408418
overwrite : bool
409419
Whether to overwrite the existing file.
410420
Defaults to False.
@@ -500,12 +510,16 @@ def _write_dig_bids(bids_path, raw, montage=None, acpc_aligned=False, overwrite=
500510
"acquisition": bids_path.acquisition,
501511
"space": None if bids_path.datatype == "nirs" else coord_frame,
502512
}
513+
# add `task-` to the electrodes.tsv file if requested
514+
electrode_file_entities = coord_file_entities.copy()
515+
if electrodes_tsv_task and bids_path.task is not None:
516+
electrode_file_entities["task"] = bids_path.task
503517
channels_suffix = "optodes" if bids_path.datatype == "nirs" else "electrodes"
504518
_channels_fun = (
505519
_write_optodes_tsv if bids_path.datatype == "nirs" else _write_electrodes_tsv
506520
)
507521
channels_path = BIDSPath(
508-
**coord_file_entities, suffix=channels_suffix, extension=".tsv"
522+
**electrode_file_entities, suffix=channels_suffix, extension=".tsv"
509523
)
510524
coordsystem_path = BIDSPath(
511525
**coord_file_entities, suffix="coordsystem", extension=".json"

mne_bids/write.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ def write_raw_bids(
14321432
event_id=None,
14331433
event_metadata=None,
14341434
extra_columns_descriptions=None,
1435+
electrodes_tsv_task=False,
14351436
*,
14361437
anonymize=None,
14371438
format="auto",
@@ -1535,6 +1536,9 @@ def write_raw_bids(
15351536
extra_columns_descriptions : dict | None
15361537
A dictionary that maps column names of the ``event_metadata`` to descriptions.
15371538
Each column of ``event_metadata`` must have a corresponding entry in this.
1539+
electrodes_tsv_task : bool
1540+
Add the ``task-`` entity to the ``BIDSPath`` of the
1541+
``electrodes.tsv`` file. Defaults to ``False``.
15381542
anonymize : dict | None
15391543
If `None` (default), no anonymization is performed.
15401544
If a dictionary, data will be anonymized depending on the dictionary
@@ -2050,7 +2054,9 @@ def write_raw_bids(
20502054
# We only write electrodes.tsv and accompanying coordsystem.json
20512055
# if we have an available DigMontage
20522056
if montage is not None or (raw.info["dig"] is not None and raw.info["dig"]):
2053-
_write_dig_bids(bids_path, raw, montage, acpc_aligned, overwrite)
2057+
_write_dig_bids(
2058+
bids_path, raw, montage, acpc_aligned, electrodes_tsv_task, overwrite
2059+
)
20542060
else:
20552061
logger.info(
20562062
f"Writing of electrodes.tsv is not supported "

0 commit comments

Comments
 (0)