예제 #1
0
def test_get_anonymization_daysback():
    """Test daysback querying for anonymization."""
    data_path = testing.data_path()
    raw_fname = op.join(data_path, 'MEG', 'sample',
                        'sample_audvis_trunc_raw.fif')
    raw = mne.io.read_raw_fif(raw_fname)
    daysback_min, daysback_max = _get_anonymization_daysback(raw)
    # max_val off by 1 on Windows for some reason
    assert abs(daysback_min - 28461) < 2 and abs(daysback_max - 36880) < 2
    raw2 = raw.copy()
    raw2.info['meas_date'] = (np.int32(1158942080), np.int32(720100))
    raw3 = raw.copy()
    raw3.info['meas_date'] = (np.int32(914992080), np.int32(720100))
    daysback_min, daysback_max = get_anonymization_daysback([raw, raw2, raw3])
    assert abs(daysback_min - 29850) < 2 and abs(daysback_max - 35446) < 2
    raw4 = raw.copy()
    raw4.info['meas_date'] = (np.int32(4992080), np.int32(720100))
    raw5 = raw.copy()
    raw5.info['meas_date'] = None
    daysback_min2, daysback_max2 = get_anonymization_daysback(
        [raw, raw2, raw3, raw5])
    assert daysback_min2 == daysback_min and daysback_max2 == daysback_max
    with pytest.raises(ValueError, match='The dataset spans more time'):
        daysback_min, daysback_max = \
            get_anonymization_daysback([raw, raw2, raw4])
예제 #2
0
def test_ctf(_bids_validate):
    """Test functionality of the write_raw_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 = mne.io.read_raw_ctf(raw_fname)
    with pytest.warns(UserWarning, match='No line frequency'):
        write_raw_bids(raw, bids_basename, output_path=output_path)

    _bids_validate(output_path)
    with pytest.warns(UserWarning, match='Did not find any events'):
        raw = read_raw_bids(bids_basename + '_meg.ds',
                            output_path,
                            extra_params=dict(clean_names=False))

    # test to check that running again with overwrite == False raises an error
    with pytest.raises(FileExistsError, match="already exists"):  # noqa: F821
        write_raw_bids(raw, bids_basename, output_path=output_path)

    assert op.exists(op.join(output_path, 'participants.tsv'))

    # test anonymize
    raw = mne.io.read_raw_ctf(raw_fname)
    with pytest.warns(UserWarning,
                      match='Converting to FIF for anonymization'):
        output_path = _test_anonymize(raw, bids_basename)
    _bids_validate(output_path)

    # XXX: change the next two lines once raw.set_meas_date() is
    # available.
    raw.info['meas_date'] = None
    raw.anonymize()
    with pytest.raises(ValueError, match='All measurement dates are None'):
        get_anonymization_daysback(raw)
예제 #3
0
# BIDS-compatible names that will be used to save the files in BIDS.
raw_list = list()
bids_list = list()
for subject_id in subject_ids:
    for run in runs:
        raw_fname = eegbci.load_data(subject=subject_id, runs=run)[0]
        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)