-
Notifications
You must be signed in to change notification settings - Fork 92
/
test_report.py
97 lines (77 loc) · 3.94 KB
/
test_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""Testing automatic BIDS report."""
# Authors: The MNE-BIDS developers
# SPDX-License-Identifier: BSD-3-Clause
import os.path as op
import textwrap
import mne
import pytest
from mne.datasets import testing
from mne_bids import BIDSPath, make_report
from mne_bids.config import BIDS_VERSION
from mne_bids.write import write_raw_bids
subject_id = "01"
session_id = "01"
run = "01"
acq = "01"
task = "testing"
_bids_path = BIDSPath(
subject=subject_id, session=session_id, run=run, acquisition=acq, task=task
)
# Get the MNE testing sample data
data_path = testing.data_path(download=False)
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
warning_str = dict(
channel_unit_changed="ignore:The unit for chann*.:RuntimeWarning:mne",
)
@pytest.mark.filterwarnings(warning_str["channel_unit_changed"])
@testing.requires_testing_data
def test_report(tmp_path):
"""Test that report generated works as intended."""
bids_root = str(tmp_path)
raw = mne.io.read_raw_fif(raw_fname, verbose=False)
raw.info["line_freq"] = 60
bids_path = _bids_path.copy().update(root=bids_root)
write_raw_bids(raw, bids_path, overwrite=True, verbose=False)
report = make_report(bids_root)
expected_report = f""" The [Unspecified] dataset was created by [Unspecified1], and [Unspecified2] 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 an MEG system (Elekta) 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: E501
expected_report = "\n".join(textwrap.wrap(expected_report, width=80))
assert report == expected_report
@pytest.mark.filterwarnings(warning_str["channel_unit_changed"])
@testing.requires_testing_data
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_path.copy().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""" The [Unspecified] dataset was created by [Unspecified1], and [Unspecified2] 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 an MEG system (Elekta) 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: E501
expected_report = "\n".join(textwrap.wrap(expected_report, width=80))
assert report == expected_report