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 16 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
1 change: 1 addition & 0 deletions doc/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
.. _Clemens Brunner: https://github.com/cbrnr
.. _Kambiz Tavabi: https://github.com/ktavabi
.. _Franziska von Albedyll: https://www.researchgate.net/profile/Franziska-Von-Albedyll
.. _Simon Kern: https://github.com/skjerns
4 changes: 3 additions & 1 deletion doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Authors
~~~~~~~

People who contributed to this release (in alphabetical order):

* `Simon Kern`_
* `Adam Li`_
* `Alex Rockhill`_
* `Alexandre Gramfort`_
Expand Down Expand Up @@ -54,6 +54,8 @@ Bug fixes

- Forcing EDF conversion in :func:`mne_bids.write_raw_bids` properly uses the ``overwrite`` parameter now, by `Adam Li`_ (:gh:`930`)

- Fix loading tsv participant summary information when only subject_id is supplied and all other information (age, gender, handedness) is missing in :func:`mne_bids.make_report` (:gh:`912`)
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved

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

.. include:: authors.rst
2 changes: 1 addition & 1 deletion mne_bids/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ 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)
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
34 changes: 34 additions & 0 deletions mne_bids/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
channel_unit_changed='ignore:The unit for chann*.:RuntimeWarning:mne',
)

bids_path2 = bids_path.copy()
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_report(tmp_path):
Expand All @@ -59,3 +60,36 @@ 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 report with participants.tsv with participant_id column only."""
bids_root = tmp_path
raw = mne.io.read_raw_fif(raw_fname, verbose=False)
raw.info['line_freq'] = 60
bids_path = bids_path2.update(root=bids_root)
write_raw_bids(raw, bids_path, overwrite=True, verbose=False)

# remove all information and check if report still runs
(bids_root / 'participants.json').unlink()

# overwrite participant information to see if report still runs
(bids_root / 'participants.tsv').write_text('participant_id\nsub-001')

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