Skip to content

Commit

Permalink
Don't store age, sex, handedness for empty-room in participants.tsv (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechenberger committed Dec 30, 2021
1 parent 9463f19 commit a497390
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions doc/whats_new.rst
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
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
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
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

0 comments on commit a497390

Please sign in to comment.