Skip to content

Commit 2ccfdf1

Browse files
JuliusWelzelpre-commit-ci[bot]sappelhoffdrammock
authored
[MRG] Add motion to BIDSPath (#1430)
* [ADD] describing fields in `event.json` file for the REQUIRED onset and duration columns * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix line length <88 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove column position from description * only provide description and onset for the json * refine description of sample * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * satisfy contributing guidelines * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * move author to correct position in CITATION.cff * [ADD] adapt the config file to include motion data type * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [ADD] include tracking_system in ENTITY_VALUE_TYPE and BIDSPath class * fix tests * [FIX] update spelling of 'tracking-system' in test_path.py with corresponding change in 'ALLOWED_PATH_ENTITIES_SHORT' * [ADD] include 'tracking-system' in the list of valid entity values in test_get_entities_from_fname_errors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [FIX] correct spelling of 'tracking-system' to 'tracking_system' in ALLOWED_PATH_ENTITIES and ALLOWED_PATH_ENTITIES_SHORT * [FIX] update entity name from 'tracking-system' to 'tracking_system' and add it to valid entities * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix whats_new.rst * FIX: tracking_system update in BIDSPath class * FIX: correct path reference for BIDSPath initialization in whats_new.rst * FEAT: add tracking_system parameter to _filter_fnames function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix whats_new.rst to ref BIDSPath * fix whats_new.rst to ref BIDSPath --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Stefan Appelhoff <[email protected]> Co-authored-by: Daniel McCloy <[email protected]>
1 parent a478527 commit 2ccfdf1

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ Please also cite one of the following papers to credit BIDS, depending on which
5858
- [EEG-BIDS](https://doi.org/10.1038/s41597-019-0104-8)
5959
- [iEEG-BIDS](https://doi.org/10.1038/s41597-019-0105-7)
6060
- [NIRS-BIDS](https://doi.org/10.31219/osf.io/7nmcp)
61+
- [Motion-BIDS](https://doi.org/10.1038/s41597-024-03559-8)

doc/authors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@
5959
.. _waldie11: https://github.com/waldie11
6060
.. _William Turner: https://bootstrapbill.github.io/
6161
.. _Yorguin Mantilla: https://github.com/yjmantilla
62+
.. _Julius Welzel: https://github.com/JuliusWelzel

doc/whats_new.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ Version 0.18 (unreleased)
1919

2020
The following authors contributed for the first time. Thank you so much! 🤩
2121

22+
* `Julius Welzel`_
2223
* `Alex Lopez Marquez`_
2324

25+
2426
The following authors had contributed before. Thank you for sticking around! 🤘
2527

26-
* TBD
28+
* `Stefan Appelhoff`_
2729

2830

2931
Detailed list of changes
@@ -33,11 +35,12 @@ Detailed list of changes
3335
^^^^^^^^^^^^^^^
3436

3537
- :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`)
38+
- Extended the configuration to recognise `motion` as a valid BIDS datatype by `Julius Welzel`_ (:gh:`1430`)
3639

3740
🧐 API and behavior changes
3841
^^^^^^^^^^^^^^^^^^^^^^^^^^^
3942

40-
- None yet
43+
- `tracksys` accepted as argument in :class:`mne_bids.BIDSPath()` by `Julius Welzel`_ (:gh:`1430`)
4144

4245
🛠 Requirements
4346
^^^^^^^^^^^^^^^

mne_bids/config.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from mne import io
77
from mne.io.constants import FIFF
88

9-
BIDS_VERSION = "1.7.0"
9+
BIDS_VERSION = "1.9.0"
1010

1111
PYBV_VERSION = "0.7.3"
1212
EEGLABIO_VERSION = "0.0.2"
@@ -15,17 +15,19 @@
1515

1616
EPHY_ALLOWED_DATATYPES = ["meg", "eeg", "ieeg", "nirs"]
1717

18-
ALLOWED_DATATYPES = EPHY_ALLOWED_DATATYPES + ["anat", "beh"]
18+
ALLOWED_DATATYPES = EPHY_ALLOWED_DATATYPES + ["anat", "beh", "motion"]
1919

2020
MEG_CONVERT_FORMATS = ["FIF", "auto"]
2121
EEG_CONVERT_FORMATS = ["BrainVision", "auto"]
2222
IEEG_CONVERT_FORMATS = ["BrainVision", "auto"]
2323
NIRS_CONVERT_FORMATS = ["auto"]
24+
MOTION_CONVERT_FORMATS = ["tsv", "auto"]
2425
CONVERT_FORMATS = {
2526
"meg": MEG_CONVERT_FORMATS,
2627
"eeg": EEG_CONVERT_FORMATS,
2728
"ieeg": IEEG_CONVERT_FORMATS,
2829
"nirs": NIRS_CONVERT_FORMATS,
30+
"motion": MOTION_CONVERT_FORMATS,
2931
}
3032

3133
# Orientation of the coordinate system dependent on manufacturer
@@ -147,12 +149,17 @@
147149
".snirf", # SNIRF
148150
]
149151

152+
allowed_extensions_motion = [
153+
".tsv", # Tab-separated values
154+
]
155+
150156
# allowed extensions (data formats) in BIDS spec
151157
ALLOWED_DATATYPE_EXTENSIONS = {
152158
"meg": allowed_extensions_meg,
153159
"eeg": allowed_extensions_eeg,
154160
"ieeg": allowed_extensions_ieeg,
155161
"nirs": allowed_extensions_nirs,
162+
"motion": allowed_extensions_motion,
156163
}
157164

158165
# allow additional extensions that are not BIDS
@@ -190,6 +197,7 @@
190197
"physio",
191198
"stim", # behavioral
192199
"nirs",
200+
"motion", # motion
193201
]
194202

195203
# converts suffix to known path modalities
@@ -227,6 +235,7 @@
227235
"description",
228236
"suffix",
229237
"extension",
238+
"tracking_system",
230239
)
231240
ALLOWED_PATH_ENTITIES_SHORT = {
232241
"sub": "subject",
@@ -239,6 +248,7 @@
239248
"recording": "recording",
240249
"split": "split",
241250
"desc": "description",
251+
"tracksys": "tracking_system",
242252
}
243253

244254
# Annotations to never remove during reading or writing
@@ -316,6 +326,7 @@
316326
ALLOWED_SPACES["ieeg"] = BIDS_SHARED_COORDINATE_FRAMES + BIDS_IEEG_COORDINATE_FRAMES
317327
ALLOWED_SPACES["anat"] = None
318328
ALLOWED_SPACES["beh"] = None
329+
ALLOWED_SPACES["motion"] = None
319330

320331
# See: https://bids-specification.readthedocs.io/en/latest/appendices/entity-table.html#encephalography-eeg-ieeg-and-meg # noqa: E501
321332
ENTITY_VALUE_TYPE = {
@@ -331,6 +342,7 @@
331342
"description": "label",
332343
"suffix": "label",
333344
"extension": "label",
345+
"tracking_system": "label",
334346
}
335347

336348
# mapping from supported BIDs coordinate frames -> MNE

mne_bids/path.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def __init__(
385385
space=None,
386386
split=None,
387387
description=None,
388+
tracking_system=None,
388389
root=None,
389390
suffix=None,
390391
extension=None,
@@ -421,6 +422,7 @@ def __init__(
421422
space=space,
422423
split=split,
423424
description=description,
425+
tracking_system=tracking_system,
424426
root=root,
425427
datatype=datatype,
426428
suffix=suffix,
@@ -442,6 +444,7 @@ def entities(self):
442444
"recording": self.recording,
443445
"split": self.split,
444446
"description": self.description,
447+
"tracking_system": self.tracking_system,
445448
}
446449

447450
@property
@@ -575,6 +578,15 @@ def description(self) -> str | None:
575578
def description(self, value):
576579
self.update(description=value)
577580

581+
@property
582+
def tracking_system(self) -> str | None:
583+
"""The tracking system entity."""
584+
return self._tracking_system
585+
586+
@tracking_system.setter
587+
def tracking_system(self, value):
588+
self.update(tracking_system=value)
589+
578590
@property
579591
def suffix(self) -> str | None:
580592
"""The filename suffix."""
@@ -881,7 +893,9 @@ def fpath(self):
881893
if self.suffix is None or self.suffix in ALLOWED_DATATYPES:
882894
# now only use valid datatype extension
883895
if self.extension is None:
884-
valid_exts = sum(ALLOWED_DATATYPE_EXTENSIONS.values(), [])
896+
valid_exts = ALLOWED_DATATYPE_EXTENSIONS.get(
897+
self.datatype, sum(ALLOWED_DATATYPE_EXTENSIONS.values(), [])
898+
)
885899
else:
886900
valid_exts = [self.extension]
887901
matching_paths = [
@@ -2325,6 +2339,7 @@ def _filter_fnames(
23252339
description=None,
23262340
suffix=None,
23272341
extension=None,
2342+
tracking_system=None,
23282343
):
23292344
"""Filter a list of BIDS filenames / paths based on BIDS entity values.
23302345
@@ -2351,6 +2366,7 @@ def _filter_fnames(
23512366
description = _ensure_tuple(description)
23522367
suffix = _ensure_tuple(suffix)
23532368
extension = _ensure_tuple(extension)
2369+
tracking_system = _ensure_tuple(tracking_system)
23542370

23552371
leading_path_str = r".*\/?" # nothing or something ending with a `/`
23562372
sub_str = r"sub-(" + "|".join(subject) + ")" if subject else r"sub-([^_]+)"
@@ -2375,6 +2391,11 @@ def _filter_fnames(
23752391
)
23762392
suffix_str = r"_(" + "|".join(suffix) + ")" if suffix else r"_([^_]+)"
23772393
ext_str = r"(" + "|".join(extension) + ")$" if extension else r"\.([^_]+)"
2394+
tracksys_str = (
2395+
r"tracksys-(" + "|".join(tracking_system) + ")"
2396+
if tracking_system
2397+
else r"(|tracksys-([^_]+))"
2398+
)
23782399

23792400
regexp = (
23802401
leading_path_str
@@ -2390,6 +2411,7 @@ def _filter_fnames(
23902411
+ desc_str
23912412
+ suffix_str
23922413
+ ext_str
2414+
+ tracksys_str
23932415
)
23942416

23952417
# Convert to str so we can apply the regexp ...

mne_bids/tests/test_path.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ def test_get_entities_from_fname(fname):
500500
"recording",
501501
"split",
502502
"description",
503+
"tracking_system",
503504
]
504505

505506

@@ -537,6 +538,7 @@ def test_get_entities_from_fname_errors(fname):
537538
"recording",
538539
"split",
539540
"description",
541+
"tracking_system",
540542
]
541543

542544
assert params["subject"] == "01"

0 commit comments

Comments
 (0)