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"""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 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 expected_report = '\n'.join(textwrap.wrap(expected_report, width=80)) assert report == expected_report
def run(): """Run the raw_to_bids command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__, usage="usage: %prog options args", prog_prefix='mne_bids', version=mne_bids.__version__) parser.add_option('--bids_root', dest='bids_root', help='The path of the BIDS compatible folder.') opt, args = parser.parse_args() if len(args) > 0: parser.print_help() parser.error( 'Do not specify arguments without flags. Found: "{}".\n'.format( args)) if not all([opt.bids_root]): parser.print_help() parser.error('Arguments missing. You need to specify the ' '--bids_root parameter.') report = make_report(opt.bids_root) print('-' * 36 + ' REPORT ' + '-' * 36) print(report) assert ' ' not in report
def test_report(): """Test that report generated works as intended.""" bids_root = _TempDir() raw = mne.io.read_raw_fif(raw_fname, verbose=False) raw.info['line_freq'] = 60 bids_path.update(root=bids_root) write_raw_bids(raw, bids_path, overwrite=True, verbose=False) report = make_report(bids_root) print(report) expected_report = \ """This dataset was created with BIDS version 1.4.0 by Please cite MNE-BIDS in your publication before removing this (citations in README). 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 Hz. 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
def test_report(tmpdir): """Test that report generated works as intended.""" bids_root = str(tmpdir) raw = mne.io.read_raw_fif(raw_fname, verbose=False) raw.info['line_freq'] = 60 bids_path.update(root=bids_root) write_raw_bids(raw, bids_path, overwrite=True, verbose=False) 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
# BIDS dataset. bids_root = somato.data_path() ############################################################################### # Explore the dataset contents # ---------------------------- # # We can use MNE-BIDS to print a tree of all # included files and folders. We pass the ``max_depth`` parameter to # `mne_bids.print_dir_tree` to the output to three levels of folders, for # better readability in this example. print_dir_tree(bids_root, max_depth=3) # We can generate a report of the existing dataset print(make_report(bids_root)) ############################################################################### # Update the sidecar JSON dataset contents # ---------------------------------------- # # We can use MNE-BIDS to update all sidecar files for a matching # ``BIDSPath`` object. We then pass in a dictionary (or JSON file) to update # all matching metadata fields within the BIDS dataset. # create a BIDSPath object bids_root = somato.data_path() datatype = 'meg' subject = '01' task = 'somato' suffix = 'meg'
raw = mne.io.read_raw_ctf(raw_fname) #Change this - should be generic for meg vender raw.info['line_freq'] = line_freq sub = "{0:0=4d}".format(idx) ses = '01' task = 'rest' run = '01' bids_path = BIDSPath(subject=sub, session=ses, task=task, run=run, root=output_path) write_raw_bids(raw, bids_path) report = make_report(bids_dir) # def check_inputs(bids_root=None, line_freq=None, meg_data_dir=None, # subjects_dir=None, subjids='all'): # '''Glob all impotant directories and determine the missing inputs''' # if subjids=='all': # print('''Parsing all meg studies can take a long time depending on the # number of datasets in the search''') # all_meg_datasets = glob.glob(meg_glob) # all_mri_datasets = glob.glob(mri_glob)
raw = mne.io.read_raw_edf(raw_fname) raw.info['line_freq'] = 50 # specify power line frequency raw_list.append(raw) bids_path = BIDSPath(subject=f'{subject_id:03}', session='01', task='MotorImagery', run=f'{run_map[run]:02}', root=bids_root) bids_list.append(bids_path) daysback_min, daysback_max = get_anonymization_daysback(raw_list) for raw, bids_path in zip(raw_list, bids_list): # By using the same anonymization `daysback` number we can # preserve the longitudinal structure of multiple sessions for a # single subject and the relation between subjects. Be sure to # change or delete this number before putting code online, you # wouldn't want to inadvertently de-anonymize your data. write_raw_bids(raw, bids_path, event_id=event_id, anonymize=dict(daysback=daysback_min + 2117), overwrite=True) ############################################################################### # Now let's see the structure of the BIDS folder we created. print_dir_tree(bids_root) ############################################################################### # Now let's generate a report on the dataset. dataset_report = make_report(root=bids_root) print(dataset_report)
# root of BIDs dataset root = Path('../data/') # BIDS entities subject = '01' session = 'interictalsleep' run = '01' datatype = 'ieeg' ############################################################################### # show the contents of the BIDS dataset print_dir_tree(root) # Let's summarize the dataset. print(make_report(root, verbose=False)) ############################################################################### # Load the dataset. bids_path = BIDSPath(subject=subject, session=session, run=run, datatype=datatype, root=root, suffix='ieeg', extension='.vhdr') raw = read_raw_bids(bids_path) ############################################################################### # Let's plot the data and see what it looks like # raw.plot()