Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly track anonymization date of empty room recordings when written simultaneously with data #1270

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
^^^^^^^^^^^^^^
Expand Down
5 changes: 4 additions & 1 deletion mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +3154 to +3163
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified to

if subject == "emptyroom":
    ...
    er_raw=None
else:
    ...
    er_raw = raw.copy()
...
write_raw_bids(..., empty_room=er_raw)

or so

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's a slight improvement I guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this as is though, I think the difference in code here is miniscule. Thanks for the PR and the reviews.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know, why would you create a dict if you don't need it? just to later unpack the only element it contains 🧐

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
# emptyroom recordings' session should match the recording date
if subject == "emptyroom":
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading