def test_vhdr(): """Test raw_to_bids conversion for BrainVision data.""" output_path = _TempDir() data_path = op.join(base_path, 'brainvision', 'tests', 'data') raw_fname = op.join(data_path, 'test.vhdr') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False, kind='eeg') cmd = ['bids-validator', '--bep006', output_path] run_subprocess(cmd, shell=shell) # create another bids folder with the overwrite command and check # no files are in the folder data_path = make_bids_folders(subject=subject_id, session=session_id, kind='eeg', root=output_path, overwrite=True) assert len([f for f in os.listdir(data_path) if op.isfile(f)]) == 0
def test_bti(): """ Testing the functionality of the raw_to_bids conversion for BTi data. """ output_path = _TempDir() data_path = op.join(base_path, 'bti', 'tests', 'data') raw_fname = op.join(data_path, 'test_pdf_linux') config_fname = op.join(data_path, 'test_config_linux') headshape_fname = op.join(data_path, 'test_hs_linux') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_file=raw_fname, config=config_fname, hsp=headshape_fname, output_path=output_path, acquisition=acq_a, verbose=True, overwrite=True) # run again with a different acquisiton parameter raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_file=raw_fname, config=config_fname, hsp=headshape_fname, output_path=output_path, acquisition=acq_b, verbose=True, overwrite=True) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell)
def test_ctf(): """Test functionality of the raw_to_bids conversion for CTF data.""" output_path = _TempDir() data_path = op.join(testing.data_path(download=False), 'CTF') raw_fname = op.join(data_path, 'testdata_ctf.ds') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell) # test to check that running again with overwrite == False raises an error with pytest.raises(OSError, match="already exists"): raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False) assert op.exists(op.join(output_path, 'participants.tsv'))
def test_kit(): """ Testing the functionality of the raw_to_bids conversion for KIT data. """ output_path = _TempDir() data_path = op.join(base_path, 'kit', 'tests', 'data') raw_fname = op.join(data_path, 'test.sqd') events_fname = op.join(data_path, 'test-eve.txt') hpi_fname = op.join(data_path, 'test_mrk.sqd') electrode_fname = op.join(data_path, 'test_elp.txt') headshape_fname = op.join(data_path, 'test_hsp.txt') event_id = dict(cond=1) raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_file=raw_fname, events_data=events_fname, event_id=event_id, hpi=hpi_fname, electrode=electrode_fname, hsp=headshape_fname, output_path=output_path, overwrite=True) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell)
def test_ctf(): """ Testing the functionality of the raw_to_bids conversion for CTF data. """ output_path = _TempDir() data_path = op.join(testing.data_path(download=False), 'CTF') raw_fname = op.join(data_path, 'testdata_ctf.ds') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_file=raw_fname, output_path=output_path, acquisition=acq_a, overwrite=True) # run again with a different acquisiton parameter raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_file=raw_fname, output_path=output_path, acquisition=acq_b, overwrite=True) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell)
def test_edf(): """Test raw_to_bids conversion for European Data Format data.""" output_path = _TempDir() data_path = op.join(testing.data_path(), 'EDF') raw_fname = op.join(data_path, 'test_reduced.edf') raw = mne.io.read_raw_edf(raw_fname, preload=True) raw.rename_channels({raw.info['ch_names'][0]: 'EOG'}) raw.info['chs'][0]['coil_type'] = FIFF.FIFFV_COIL_EEG_BIPOLAR raw.rename_channels({raw.info['ch_names'][1]: 'EMG'}) raw.set_channel_types({'EMG': 'emg'}) raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw, output_path=output_path, overwrite=False, kind='eeg') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run2, task=task, acquisition=acq, raw_file=raw, output_path=output_path, overwrite=True, kind='eeg') cmd = ['bids-validator', '--bep006', output_path] run_subprocess(cmd, shell=shell) # ensure there is an EMG channel in the channels.tsv: channels_tsv = make_bids_filename(subject=subject_id, session=session_id, task=task, run=run, suffix='channels.tsv', acquisition=acq, prefix=op.join(output_path, 'sub-01/ses-01/eeg')) df = pd.read_csv(channels_tsv, sep='\t') assert 'ElectroMyoGram' in df['description'].values # check that the scans list contains two scans scans_tsv = make_bids_filename(subject=subject_id, session=session_id, suffix='scans.tsv', prefix=op.join(output_path, 'sub-01/ses-01')) df = pd.read_csv(scans_tsv, sep='\t') assert df.shape[0] == 2
def test_fif(): """ Testing the functionality of the raw_to_bids conversion for Neuromag data. """ output_path = _TempDir() data_path = testing.data_path() raw_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw.fif') event_id = { 'Auditory/Left': 1, 'Auditory/Right': 2, 'Visual/Left': 3, 'Visual/Right': 4, 'Smiley': 5, 'Button': 32 } events_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw-eve.fif') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_file=raw_fname, events_data=events_fname, output_path=output_path, event_id=event_id, acquisition=acq_a, overwrite=True) # let's do some modifications to meas_date raw = mne.io.read_raw_fif(raw_fname) raw.anonymize() data_path2 = _TempDir() raw_fname2 = op.join(data_path2, 'sample_audvis_raw.fif') raw.save(raw_fname2) raw_to_bids(subject_id=subject_id, run=run, task=task, session_id=session_id, raw_file=raw_fname2, events_data=events_fname, output_path=output_path, event_id=event_id, acquisition=acq_b, overwrite=True) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell)
def test_ctf(): """ Testing the functionality of the raw_to_bids conversion for CTF data. """ output_path = _TempDir() data_path = op.join(testing.data_path(download=False), 'CTF') raw_fname = op.join(data_path, 'testdata_ctf.ds') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_fname=raw_fname, output_path=output_path, overwrite=True)
def test_cnt(): """Test raw_to_bids conversion for Neuroscan data.""" output_path = _TempDir() data_path = op.join(testing.data_path(), 'CNT') raw_fname = op.join(data_path, 'scan41_short.cnt') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False, kind='eeg') cmd = ['bids-validator', '--bep006', output_path] run_subprocess(cmd, shell=shell)
def test_bdf(): """Test raw_to_bids conversion for Biosemi data.""" output_path = _TempDir() data_path = op.join(base_path, 'edf', 'tests', 'data') raw_fname = op.join(data_path, 'test.bdf') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False, kind='eeg') cmd = ['bids-validator', '--bep006', output_path] run_subprocess(cmd, shell=shell)
def test_bti(): """ Testing the functionality of the raw_to_bids conversion for BTi data. """ output_path = _TempDir() data_path = op.join(base_path, 'bti', 'tests', 'data') raw_fname = op.join(data_path, 'test_pdf_linux') config_fname = op.join(data_path, 'test_config_linux') headshape_fname = op.join(data_path, 'test_hs_linux') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, raw_fname=raw_fname, config=config_fname, hsp=headshape_fname, output_path=output_path, overwrite=True)
def test_bti(): """Test functionality of the raw_to_bids conversion for BTi data.""" output_path = _TempDir() data_path = op.join(base_path, 'bti', 'tests', 'data') raw_fname = op.join(data_path, 'test_pdf_linux') config_fname = op.join(data_path, 'test_config_linux') headshape_fname = op.join(data_path, 'test_hs_linux') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, config=config_fname, hsp=headshape_fname, output_path=output_path, verbose=True, overwrite=False) assert op.exists(op.join(output_path, 'participants.tsv')) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell)
def test_set(): """Test raw_to_bids conversion for EEGLAB data.""" # standalone .set file output_path = _TempDir() data_path = op.join(testing.data_path(), 'EEGLAB') raw_fname = op.join(data_path, 'test_raw_onefile.set') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False, kind='eeg') cmd = ['bids-validator', '--bep006', output_path] run_subprocess(cmd, shell=shell) with pytest.raises(OSError, match="already exists"): raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False, kind='eeg') # .set with associated .fdt output_path = _TempDir() data_path = op.join(testing.data_path(), 'EEGLAB') raw_fname = op.join(data_path, 'test_raw.set') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, output_path=output_path, overwrite=False, kind='eeg') cmd = ['bids-validator', '--bep006', output_path] run_subprocess(cmd, shell=shell)
data_path = sample.data_path() event_id = { 'Auditory/Left': 1, 'Auditory/Right': 2, 'Visual/Left': 3, 'Visual/Right': 4, 'Smiley': 5, 'Button': 32 } raw_file = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif') events_data = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw-eve.fif') output_path = op.join(data_path, '..', 'MNE-sample-data-bids') ############################################################################### # Finally, we specify the raw_file and events_data raw_to_bids(subject_id='01', run='01', session_id='01', task='audiovisual', raw_file=raw_file, events_data=events_data, output_path=output_path, event_id=event_id, overwrite=False) ############################################################################### # Now let's see the structure of the BIDS folder we created. print_dir_tree(output_path)
# Alexandre Gramfort <*****@*****.**> # Teon Brooks <*****@*****.**> # License: BSD (3-clause) ############################################################################### # Let us import mne_bids import os.path as op from mne.datasets import sample from mne_bids import raw_to_bids ############################################################################### # And define the paths and event_id dictionary. data_path = sample.data_path() event_id = {'Auditory/Left': 1, 'Auditory/Right': 2, 'Visual/Left': 3, 'Visual/Right': 4, 'Smiley': 5, 'Button': 32} raw_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif') events_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw-eve.fif') output_path = op.join(data_path, '..', 'MNE-sample-data-bids') ############################################################################### # Finally, we specify the raw_fname and events_fname raw_to_bids(subject_id='01', run='01', session_id='01', task='audiovisual', raw_fname=raw_fname, events_fname=events_fname, output_path=output_path, event_id=event_id, overwrite=True)
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.set_defaults(kind='meg') parser.add_option('--subject_id', dest='subject_id', help=('The subject name in BIDS compatible format', '(01,02, etc.)'), metavar='s') parser.add_option('--task', dest='task', help='Name of the task the data is based on.', metavar='t') parser.add_option('--raw_file', dest='raw_file', help='The path to the raw MEG file.', metavar='r') parser.add_option('--output_path', dest='output_path', help='The path of the BIDS compatible folder.', metavar='o') parser.add_option('--session_id', dest='session_id', help='The session name in BIDS compatible format.', metavar='ses') parser.add_option('--run', dest='run', help='The run number for this dataset.', metavar='run') parser.add_option('--kind', dest='kind', help='The kind of data being converted.', metavar='k') parser.add_option('--events_data', dest='events_data', help='The events file.', metavar='evt') parser.add_option('--event_id', dest='event_id', help='The event id dict.', metavar='eid') parser.add_option('--hpi', dest='hpi', help='The path to the MEG Marker points', metavar='filename') parser.add_option('--electrode', dest='electrode', help='The path to head-native Digitizer points', metavar='elec') parser.add_option('--hsp', dest='hsp', help='The path to headshape points.', metavar='hsp') parser.add_option('--config', dest='config', help='The path to the configuration file', metavar='cfg') parser.add_option('--overwrite', dest='overwrite', help=("Boolean. Whether to overwrite existing data"), metavar='ow') opt, args = parser.parse_args() raw_to_bids(subject_id=opt.subject_id, task=opt.task, raw_file=opt.raw_file, output_path=opt.output_path, session_id=opt.session_id, run=opt.run, kind=opt.kind, events_data=opt.events_data, event_id=opt.event_id, hpi=opt.hpi, electrode=opt.electrode, hsp=opt.hsp, config=opt.config, overwrite=opt.overwrite, verbose=True)
event_id = { 'face/famous/first': 5, 'face/famous/immediate': 6, 'face/famous/long': 7, 'face/unfamiliar/first': 13, 'face/unfamiliar/immediate': 14, 'face/unfamiliar/long': 15, 'scrambled/first': 17, 'scrambled/immediate': 18, 'scrambled/long': 19, } ############################################################################### # Let us loop over the subjects and create BIDS-compatible folder for subject_id in subject_ids: subject = 'sub%03d' % subject_id for run in runs: raw_file = op.join(data_path, repo, subject, 'MEG', 'run_%02d_raw.fif' % run) # Make it BIDS compatible raw_to_bids(subject_id='%02d' % subject_id, session_id='01', run=run, task='VisualFaces', raw_file=raw_file, event_id=event_id, output_path=output_path, overwrite=True)
event_id = { 'face/famous/first': 5, 'face/famous/immediate': 6, 'face/famous/long': 7, 'face/unfamiliar/first': 13, 'face/unfamiliar/immediate': 14, 'face/unfamiliar/long': 15, 'scrambled/first': 17, 'scrambled/immediate': 18, 'scrambled/long': 19, } ############################################################################### # Let us loop over the subjects and create BIDS-compatible folder for subject_id in subject_ids: subject = 'sub%03d' % subject_id for run in runs: raw_fname = op.join(data_path, repo, subject, 'MEG', 'run_%02d_raw.fif' % run) # Make it BIDS compatible raw_to_bids(subject_id='%02d' % subject_id, run=run, task='visual_faces', raw_fname=raw_fname, event_id=event_id, output_path=output_path, overwrite=True)
def test_kit(): """Test functionality of the raw_to_bids conversion for KIT data.""" output_path = _TempDir() data_path = op.join(base_path, 'kit', 'tests', 'data') raw_fname = op.join(data_path, 'test.sqd') events_fname = op.join(data_path, 'test-eve.txt') hpi_fname = op.join(data_path, 'test_mrk.sqd') electrode_fname = op.join(data_path, 'test_elp.txt') headshape_fname = op.join(data_path, 'test_hsp.txt') event_id = dict(cond=1) raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, events_data=events_fname, event_id=event_id, hpi=hpi_fname, electrode=electrode_fname, hsp=headshape_fname, output_path=output_path, overwrite=False) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell) assert op.exists(op.join(output_path, 'participants.tsv')) # ensure the channels file has no STI 014 channel: channels_tsv = make_bids_filename(subject=subject_id, session=session_id, task=task, run=run, suffix='channels.tsv', acquisition=acq, prefix=op.join(output_path, 'sub-01/ses-01/meg')) df = pd.read_csv(channels_tsv, sep='\t') assert not ('STI 014' in df['name'].values) # ensure the marker file is produced in the right place raw_folder = make_bids_filename(subject=subject_id, session=session_id, task=task, run=run, acquisition=acq, suffix='%s' % 'meg') marker_fname = make_bids_filename(subject=subject_id, session=session_id, task=task, run=run, acquisition=acq, suffix='markers.sqd', prefix=os.path.join( output_path, 'sub-01/ses-01/meg', raw_folder)) assert op.exists(marker_fname) # check for error if there are multiple marker coils specified with pytest.raises(ValueError): raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, task=task, acquisition=acq, raw_file=raw_fname, events_data=events_fname, event_id=event_id, hpi=[hpi_fname, hpi_fname], electrode=electrode_fname, hsp=headshape_fname, output_path=output_path, overwrite=True)
############################################################################### # Now we just need to specify a few more EEG details to get something sensible: # First, tell `MNE-BIDS` that it is working with EEG data: kind = 'eeg' # Brief description of the event markers present in the data. This will become # the `trial_type` column in our BIDS `events.tsv`. We know about the event # meaning from the documentation on PhysioBank trial_type = {'rest': 0, 'imagine left fist': 1, 'imagine right fist': 2} # Now convert our data to be in a new BIDS dataset. raw_to_bids(subject_id=subject_id, task=task, raw_file=raw_file, output_path=output_path, kind=kind, event_id=trial_type, overwrite=False) ############################################################################### # What does our fresh BIDS directory look like? print_dir_tree(output_path) ############################################################################### # Looks good so far, let's convert the data for all tasks and subjects. # Start with a clean directory sh.rmtree(output_path) # Some initial information that we found in the PhysioBank documentation
def test_fif(): """Test functionality of the raw_to_bids conversion for Neuromag data.""" output_path = _TempDir() data_path = testing.data_path() raw_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw.fif') event_id = { 'Auditory/Left': 1, 'Auditory/Right': 2, 'Visual/Left': 3, 'Visual/Right': 4, 'Smiley': 5, 'Button': 32 } events_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw-eve.fif') raw_to_bids(subject_id=subject_id, session_id=session_id, run=run, acquisition=acq, task=task, raw_file=raw_fname, events_data=events_fname, output_path=output_path, event_id=event_id, overwrite=False) # give the raw object some fake participant data raw = mne.io.read_raw_fif(raw_fname) raw.anonymize() raw.info['subject_info'] = { 'his_id': subject_id2, 'birthday': (1994, 1, 26), 'sex': 1 } data_path2 = _TempDir() raw_fname2 = op.join(data_path2, 'sample_audvis_raw.fif') raw.save(raw_fname2) raw_to_bids(subject_id=subject_id2, run=run, task=task, acquisition=acq, session_id=session_id, raw_file=raw_fname2, events_data=events_fname, output_path=output_path, event_id=event_id, overwrite=False) # check that the overwrite parameters work correctly for the participant # data # change the gender but don't force overwrite. raw.info['subject_info'] = { 'his_id': subject_id2, 'birthday': (1994, 1, 26), 'sex': 2 } with pytest.raises(OSError, match="already exists"): raw_to_bids(subject_id=subject_id2, run=run, task=task, acquisition=acq, session_id=session_id, raw_file=raw, events_data=events_fname, output_path=output_path, event_id=event_id, overwrite=False) # now force the overwrite raw_to_bids(subject_id=subject_id2, run=run, task=task, acquisition=acq, session_id=session_id, raw_file=raw, events_data=events_fname, output_path=output_path, event_id=event_id, overwrite=True) cmd = ['bids-validator', output_path] run_subprocess(cmd, shell=shell) assert op.exists(op.join(output_path, 'participants.tsv'))