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

MRG: Don't store age, sex, handedness for empty-room in participants.tsv #935

Merged
merged 1 commit into from
Dec 30, 2021
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: 3 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Bug fixes

- :func:`mne_bids.make_report` now correctly handles `participant.tsv` files that only contain a `participant_id` column, by `Simon Kern`_ (:gh:`912`)

- :func:`mne_bids.write_raw_bids` doesn't store age, handedness, and sex in `participants.tsv` anymore for empty-room recordings, by `Richard Höchenberger`_ (:gh:`935`)


:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

.. include:: authors.rst
23 changes: 19 additions & 4 deletions mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ def test_write_participants(_bids_validate, tmp_path):
# add fake participants data
raw.set_meas_date(datetime(year=1994, month=1, day=26,
tzinfo=timezone.utc))
raw.info['subject_info'] = {'his_id': subject_id2,
'birthday': (1993, 1, 26),
'sex': 1, 'hand': 2}
raw.info['subject_info'] = {
'his_id': subject_id2,
'birthday': (1993, 1, 26),
'sex': 1,
'hand': 2
}

bids_path = _bids_path.copy().update(root=tmp_path)
write_raw_bids(raw, bids_path)
Expand Down Expand Up @@ -222,7 +225,6 @@ def test_write_participants(_bids_validate, tmp_path):

# if overwrite is False, then nothing should change from the above
with pytest.raises(FileExistsError, match='already exists'):
raw.info['subject_info'] = None
Copy link
Member Author

Choose a reason for hiding this comment

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

I assume this line was some leftover cruft from debugging

write_raw_bids(raw, bids_path, overwrite=False)
data = _from_tsv(participants_tsv)
with open(participants_json_fpath, 'r', encoding='utf-8') as fin:
Expand All @@ -233,6 +235,19 @@ def test_write_participants(_bids_validate, tmp_path):
# in addition assert the original ordering of the new overwritten file
assert list(data.keys()) == orig_key_order

# For empty-room data, all fields except participant_id should be 'n/a'
assert raw.info['subject_info'] # Ensure the following test makes sense!
bids_path_er = bids_path.copy().update(
subject='emptyroom', task='noise',
session=raw.info['meas_date'].strftime('%Y%m%d')
)
write_raw_bids(raw=raw, bids_path=bids_path_er, verbose=False)
participants_tsv = _from_tsv(participants_tsv)
idx = participants_tsv['participant_id'].index('sub-emptyroom')
assert participants_tsv['hand'][idx] == 'n/a'
assert participants_tsv['sex'][idx] == 'n/a'
assert participants_tsv['age'][idx] == 'n/a'


def test_write_correct_inputs():
"""Test that inputs of write_raw_bids is correct."""
Expand Down
13 changes: 7 additions & 6 deletions mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,11 @@ def _participants_tsv(raw, subject_id, fname, overwrite=False):
False, an error will be raised.

"""
subject_id = 'sub-' + subject_id
data = OrderedDict(participant_id=[subject_id])

subject_age = "n/a"
sex = "n/a"
hand = 'n/a'
subject_info = raw.info.get('subject_info', None)
if subject_info is not None:
if subject_id != 'emptyroom' and subject_info is not None:
# add sex
sex = _map_options(what='sex', key=subject_info.get('sex', 0),
fro='mne', to='bids')
Expand All @@ -336,6 +333,8 @@ def _participants_tsv(raw, subject_id, fname, overwrite=False):
else:
subject_age = "n/a"

subject_id = 'sub-' + subject_id
data = OrderedDict(participant_id=[subject_id])
data.update({'age': [subject_age], 'sex': [sex], 'hand': [hand]})

if os.path.exists(fname):
Expand Down Expand Up @@ -1533,8 +1532,10 @@ def write_raw_bids(raw, bids_path, events_data=None, event_id=None,
_readme(bids_path.datatype, readme_fname, False)

# save all participants meta data
_participants_tsv(raw, bids_path.subject, participants_tsv_fname,
overwrite)
_participants_tsv(
raw=raw, subject_id=bids_path.subject, fname=participants_tsv_fname,
overwrite=overwrite
)
_participants_json(participants_json_fname, True)

# for MEG, we only write coordinate system
Expand Down