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] fix loading without age information / single-column .tsv #912

Merged
merged 19 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -23,6 +23,7 @@ Authors
~~~~~~~

* `Alex Rockhill`_
* `Simon Kern`_
* `Richard Höchenberger`_
* `Mainak Jas`_
* `Adam Li`_
Expand Down Expand Up @@ -83,6 +84,8 @@ Requirements
Bug fixes
^^^^^^^^^

- Fix setting unknown ages if no age parameter is supplied in csv in function :func:`mne_bids.report._summarize_participants_tsv` (:gh:`912`)
skjerns marked this conversation as resolved.
Show resolved Hide resolved

- Fix writing Ricoh/KIT data that comes without an associated ``.mrk``, ``.elp``, or ``.hsp`` file using :func:`mne_bids.write_raw_bids`, by `Richard Höchenberger`_ (:gh:`850`)

- Properly support CTF MEG data with 2nd-order gradient compensation, by `Mainak Jas`_ (:gh:`858`)
Expand Down
3 changes: 2 additions & 1 deletion mne_bids/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def _summarize_participants_tsv(root):
p_ages = participants_tsv.get('age')
min_age, max_age = 'n/a', 'n/a'
mean_age, std_age = 'n/a', 'n/a'
n_age_unknown = len(p_ages)
print(p_ages,participants_tsv)
skjerns marked this conversation as resolved.
Show resolved Hide resolved
n_age_unknown = len(p_ages) if p_ages else len(p_ids)
if p_ages:
# only summarize age if they are numerics
if all([age.isnumeric() for age in p_ages if age != 'n/a']):
Expand Down
38 changes: 38 additions & 0 deletions mne_bids/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Authors: Adam Li <adam2392@gmail.com>
#
# License: BSD-3-Clause
import os
import os.path as op

import mne
Expand Down Expand Up @@ -59,3 +60,40 @@ def test_report(tmp_path):
analysis (2.0 +/- 0.0 were removed from analysis).""" # noqa

assert report == expected_report


@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_report_no_participant_information(tmp_path):
"""
Test that report generated works as intended even when all participant
information such as age, gender, handedness is removed from the tsv file.
"""
skjerns marked this conversation as resolved.
Show resolved Hide resolved
bids_root = str(tmp_path)
skjerns marked this conversation as resolved.
Show resolved Hide resolved
raw = mne.io.read_raw_fif(raw_fname, verbose=False)
raw.info['line_freq'] = 60
bids_path.update(root=bids_root)
skjerns marked this conversation as resolved.
Show resolved Hide resolved
write_raw_bids(raw, bids_path, overwrite=True, verbose=False)

# remove all information and check if report still runs
os.remove(op.join(bids_root, 'participants.json'))
skjerns marked this conversation as resolved.
Show resolved Hide resolved

# overwrite participant information to see if report still runs
with open(op.join(bids_root, 'participants.tsv'), 'w') as f:
f.write('participant_id\nsub-001')
skjerns marked this conversation as resolved.
Show resolved Hide resolved

report = make_report(bids_root)

expected_report = \
f"""This dataset was created by [Unspecified] and conforms to BIDS version {BIDS_VERSION}.
This report was generated with MNE-BIDS (https://doi.org/10.21105/joss.01896).
The dataset consists of 1 participants (sex were all unknown; handedness were
all unknown; ages all unknown) and 1 recording sessions: 01. Data was recorded
using a MEG system (Elekta manufacturer) sampled at 300.31 Hz with line noise at
60.0 Hz. The following software filters were applied during recording:
SpatialCompensation. There was 1 scan in total. Recording durations ranged from
20.0 to 20.0 seconds (mean = 20.0, std = 0.0), for a total of 20.0 seconds of
data recorded over all scans. For each dataset, there were on average 376.0 (std
= 0.0) recording channels per scan, out of which 374.0 (std = 0.0) were used in
analysis (2.0 +/- 0.0 were removed from analysis).""" # noqa

assert report == expected_report