Skip to content

Commit cb05d73

Browse files
committed
integrate suggested changes
1 parent f700ae6 commit cb05d73

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

mne_bids/dig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ def _write_dig_bids(
413413
acpc_aligned : bool
414414
Whether "mri" space is aligned to ACPC.
415415
electrodes_tsv_task : bool
416-
Whether to add the ``task-`` entity to the ``BIDSPath`` of
417-
the ``electrodes.tsv`` file. Defaults to ``False``.
416+
Whether to add the ``task-`` entity to the ``electrodes.tsv`` filename.
417+
Defaults to ``False``.
418418
overwrite : bool
419419
Whether to overwrite the existing file.
420420
Defaults to False.

mne_bids/tests/test_dig.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def test_electrodes_io(tmp_path):
381381

382382

383383
@testing.requires_testing_data
384-
def test_task_specific_channels_sidecar(tmp_path):
384+
def test_task_specific_electrodes_sidecar(tmp_path):
385385
"""Test the optional task- entity in electrodes.tsv."""
386386
raw = _load_raw()
387387
raw.pick(["eeg"])
@@ -433,32 +433,20 @@ def test_task_specific_channels_sidecar(tmp_path):
433433
assert coordpath_foo.name == "sub-01_ses-01_acq-01_space-CapTrak_coordsystem.json"
434434
assert coordpath_bar.name == "sub-01_ses-01_acq-01_space-CapTrak_coordsystem.json"
435435

436-
# Now test for no task- entity in electrodes.tsv
437-
438-
bpath_kwargs = dict(
439-
root=bids_root2,
440-
subject="01",
441-
session="01",
442-
run="01",
443-
acquisition="01",
444-
task="foo",
436+
# make sure we are reading the correct electrodes sidecar
437+
raw_foo_want_pos = raw_foo.get_montage().get_positions()["ch_pos"]["EEG 029"]
438+
raw_foo = mne_bids.read_raw_bids(bpath_foo)
439+
np.testing.assert_allclose(
440+
raw_foo.get_montage().get_positions()["ch_pos"]["EEG 029"], raw_foo_want_pos
445441
)
446442

447-
write_kwargs = dict(
448-
allow_preload=True,
449-
electrodes_tsv_task=False,
450-
format="BrainVision",
451-
)
443+
# Now test for no task- entity in electrodes.tsv
452444

453-
bpath = mne_bids.BIDSPath(**bpath_kwargs)
454-
bpath_foo = mne_bids.write_raw_bids(raw_foo, bpath, **write_kwargs)
445+
bpath_kwargs.update(root=bids_root2)
446+
write_kwargs.update(electrodes_tsv_task=False)
455447

456-
bpath_kwargs.update(task="bar")
457448
bpath = mne_bids.BIDSPath(**bpath_kwargs)
449+
bpath_foo = mne_bids.write_raw_bids(raw_foo, bpath, **write_kwargs)
458450

459-
# without specifying a task, writing a second electrodes.tsv with the same
460-
# filename but different contents fails
461-
with pytest.raises(
462-
RuntimeError, match="Trying to write electrodes.tsv, but it already exists"
463-
):
464-
bpath_bar = mne_bids.write_raw_bids(raw_bar, bpath, **write_kwargs)
451+
elpath_foo = bpath_foo.find_matching_sidecar(suffix="electrodes", extension=".tsv")
452+
assert elpath_foo.name == "sub-01_ses-01_acq-01_space-CapTrak_electrodes.tsv"

mne_bids/write.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,6 @@ def write_raw_bids(
14321432
event_id=None,
14331433
event_metadata=None,
14341434
extra_columns_descriptions=None,
1435-
electrodes_tsv_task=False,
14361435
*,
14371436
anonymize=None,
14381437
format="auto",
@@ -1441,6 +1440,7 @@ def write_raw_bids(
14411440
allow_preload=False,
14421441
montage=None,
14431442
acpc_aligned=False,
1443+
electrodes_tsv_task=False,
14441444
overwrite=False,
14451445
verbose=None,
14461446
):
@@ -1536,9 +1536,6 @@ def write_raw_bids(
15361536
extra_columns_descriptions : dict | None
15371537
A dictionary that maps column names of the ``event_metadata`` to descriptions.
15381538
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``.
15421539
anonymize : dict | None
15431540
If `None` (default), no anonymization is performed.
15441541
If a dictionary, data will be anonymized depending on the dictionary
@@ -1620,6 +1617,9 @@ def write_raw_bids(
16201617
So, this flag is required to be True when the digitization data
16211618
is in "mri" for intracranial data to confirm that the T1 is
16221619
ACPC-aligned.
1620+
electrodes_tsv_task : bool
1621+
Add the ``task-`` entity to the ``electrodes.tsv`` filename.
1622+
Defaults to ``False``.
16231623
overwrite : bool
16241624
Whether to overwrite existing files or data in files.
16251625
Defaults to ``False``.

0 commit comments

Comments
 (0)