From 4c3e7535f7991012b68e6ff9925c298e7e980ed7 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 12 Jul 2024 07:22:35 -0500 Subject: [PATCH] correctly track anonymization date of empty room recordings when written simultaneously with data (#1270) * add failing test * fix bug * add changelog entry --- doc/whats_new.rst | 3 ++- mne_bids/tests/test_write.py | 5 ++++- mne_bids/write.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 1824c82b8..9fa966250 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -21,6 +21,7 @@ The following authors contributed for the first time. Thank you so much! 🤩 The following authors had contributed before. Thank you for sticking around! 🤘 +* `Daniel McCloy`_ * `Stefan Appelhoff`_ Detailed list of changes @@ -44,7 +45,7 @@ Detailed list of changes 🪲 Bug fixes ^^^^^^^^^^^^ -- nothing yet +- When anonymizing the date of a recording, MNE-BIDS will no longer error during `~mne_bids.write_raw_bids` if passing a `~mne.io.Raw` instance to ``empty_room``. By `Daniel McCloy`_ (:gh:`1270`) ⚕️ Code health ^^^^^^^^^^^^^^ diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py index 680fd2fe3..a586a1d69 100644 --- a/mne_bids/tests/test_write.py +++ b/mne_bids/tests/test_write.py @@ -3151,13 +3151,16 @@ def test_anonymize(subject, dir_name, fname, reader, tmp_path, _bids_validate): # handle different edge cases if subject == "emptyroom": bids_path.update(task="noise", session=raw_date, suffix="meg", datatype="meg") + erm = dict() else: bids_path.update(task="task", suffix="eeg", datatype="eeg") + # make sure anonymization works when also writing empty room file + erm = dict(empty_room=raw.copy()) daysback_min, daysback_max = get_anonymization_daysback(raw) anonymize = dict(daysback=daysback_min + 1) orig_bids_path = bids_path.copy() bids_path = write_raw_bids( - raw, bids_path, overwrite=True, anonymize=anonymize, verbose=False + raw, bids_path, overwrite=True, anonymize=anonymize, verbose=False, **erm ) # emptyroom recordings' session should match the recording date if subject == "emptyroom": diff --git a/mne_bids/write.py b/mne_bids/write.py index c5d95b7dd..eeaf49257 100644 --- a/mne_bids/write.py +++ b/mne_bids/write.py @@ -1814,7 +1814,7 @@ def write_raw_bids( er_bids_path = bids_path.copy().update( subject="emptyroom", session=er_session, task="noise", run=None ) - write_raw_bids( + er_bids_path = write_raw_bids( raw=empty_room, bids_path=er_bids_path, events=None,