예제 #1
0
def test_baseline():

    d = Dataset(micromed_file)
    ev = [ev['start'] for ev in d.read_markers()][1]
    chans = d.header['chan_name'][:2]
    data = d.read_data(events=ev, pre=1, post=1, chan=chans)

    time_interval = (-.5, -.1)
    out = apply_baseline(data, time=time_interval)
    mout = math(select(out, time=time_interval), operator_name='mean', axis='time')
    assert_array_almost_equal(mout(trial=0), array([1, 1]))

    out = apply_baseline(data, time=time_interval, baseline='zscore')
    mout = math(select(out, time=time_interval), operator_name='mean', axis='time')
    assert_array_almost_equal(mout(trial=0), array([0, 0]))

    out = apply_baseline(data, time=time_interval, baseline='percent')
    mout = math(select(out, time=time_interval), operator_name='mean', axis='time')
    assert_array_almost_equal(mout(trial=0), array([0, 0]))

    freq_interval = (10, 15)
    freq = frequency(data)
    out = apply_baseline(freq, freq=freq_interval, baseline='dB')
    mout = math(select(out, freq=freq_interval), operator_name='mean', axis='freq')
    assert_array_almost_equal(mout(trial=0), array([0, 0]))

    out = apply_baseline(freq, freq=freq_interval, baseline='normchange')
    assert out.data[0].max() <= 1
    assert out.data[0].min() >= -1
def test_micromed_header():
    d = Dataset(micromed_file)
    assert d.header['chan_name'][-1] == 'EMG'
    assert d.header['chan_name'][:5] == ['FP1', 'FP2', 'AF7', 'AF3', 'AFz']
    assert d.header['subj_id'] == 'Tp_metrologie Tp_metrologie'

    orig = d.header['orig']
    assert orig['dvideo_begin'] == iinfo('u4').max

    markers = d.read_markers()
    assert len(markers) == 444
    assert markers[0]['name'] == '1'
    assert markers[0]['start'] == markers[0]['end']

    data = d.read_data(chan=('FP1', 'AFz'), begsam=10, endsam=20)
    assert data.data[0][1, 5] == -334.27734375

    data = d.read_data(chan=('FP1', 'AFz'), begsam=-10, endsam=20)
    assert all(isnan(data.data[0][1, :10]))

    data = d.read_data(chan=('FP1', 'AFz'), begsam=900, endsam=1010)
    assert all(isnan(data.data[0][1, -10:]))

    data = d.read_data(chan=('FP1', 'AFz'), begsam=-10, endsam=-2)
    assert all(isnan(data.data[0][1, :]))

    with raises(OSError):
        d.read_videos(10, 20)
예제 #3
0
def test_bci2000_data():
    assert bci2000_file.exists()

    d = Dataset(bci2000_file)
    assert len(d.read_markers()) == 0

    data = d.read_data()
    assert data.data[0][0, 0] == 179.702
예제 #4
0
def test_ioeeg_mobert_end():
    d = Dataset(moberg_file)
    n_smp = d.header['n_samples']
    data = d.read_data(begsam=n_smp - 1, endsam=n_smp + 1)

    assert data(trial=0, chan='Fp1')[0] == -12302.22384929657
    assert isnan(data(trial=0, chan='Fp1')[1])

    assert len(d.read_markers()) == 0
def test_openephys_markers():
    d = Dataset(filename, session=1)
    markers = d.read_markers()

    assert len(markers) == 10
    assert markers[0]['name'] == 'START RECORDING #0'
    assert markers[7]['name'] == 'Network Event'
    assert markers[7]['end'] == 95.402
    assert markers[-1]['name'] == 'END RECORDING #1'
예제 #6
0
def test_dataset_events():
    d = Dataset(micromed_file)
    events = [ev['start'] for ev in d.read_markers()][::30]

    data = d.read_data(events=events)

    assert data.time[0].shape[0] == 512
    assert data.time[0].shape[0] == data.data[0].shape[1]
    assert (data.number_of('time') == 512).all()
def test_brainvision_dataset_01():
    d = Dataset(brainvision_dir / 'test.vhdr')
    data = d.read_data(begtime=1, endtime=2)

    assert data.data[0][0, 0] == -24.0
    assert len(d.read_markers()) == 12

    data = d.read_data(begsam=-1, endsam=5)
    assert isnan(data.data[0][0, 0])
def test_write_read_fieldtrip():
    data = create_data(n_trial=1, n_chan=2)

    data.export(fieldtrip_file, export_format='fieldtrip')
    d = Dataset(fieldtrip_file)
    ftdata = d.read_data()
    assert_array_equal(data.data[0], ftdata.data[0])

    assert len(d.read_markers()) == 0
예제 #9
0
def test_ioeeg_eeglab_hdf5():

    d1 = Dataset(eeglab_hdf5_1_file)
    d2 = Dataset(eeglab_hdf5_2_file)

    data1 = d1.read_data(begsam=100, endsam=200)
    data2 = d2.read_data(begsam=100, endsam=200)

    assert data1.data[0][0, 0] == data2.data[0][0, 0]

    assert len(d1.read_markers()) == 2
예제 #10
0
def test_ioeeg_eeglab():

    d1 = Dataset(eeglab_1_file)
    d2 = Dataset(eeglab_2_file)

    data1 = d1.read_data()
    data2 = d2.read_data()

    assert data1.data[0][0, 0] == data2.data[0][0, 0]

    assert len(d1.read_markers()) == 2
예제 #11
0
def test_openephys_dataset_01():
    d = Dataset(openephys_dir)
    data = d.read_data(begtime=1, endtime=2)

    d = Dataset(openephys_dir)
    data = d.read_data(chan=[
        'CH1',
    ], begsam=10, endsam=1400)
    assert data.data[0][0, 0] == -132.6

    mrk = d.read_markers()
    assert len(mrk) == 0
예제 #12
0
def read_ieeg_block(filename, electrode_file, conditions, minimalduration,
                    output_dir):
    d = Dataset(filename, bids=True)
    markers = d.read_markers()

    electrodes = Electrodes(electrode_file)
    elec_names = [x['name'] for x in electrodes.electrodes.tsv]
    elec_names = [x for x in elec_names if x in d.header['chan_name']
                  ]  # exclude elec location that have no corresponding channel

    all_conditions = [x for v in conditions.values() for x in v]
    clean_labels = _reject_channels(d, elec_names, all_conditions,
                                    minimalduration)

    outputs = []
    for active_baseline, data_conds in conditions.items():
        block_beg = []
        block_end = []

        for mrk in markers:

            if mrk['name'] in data_conds:
                dur = (mrk['end'] - mrk['start'])
                if dur >= minimalduration:
                    block_beg.append(mrk['start'])
                    block_end.append(mrk['end'])

        data = d.read_data(begtime=block_beg,
                           endtime=block_end,
                           chan=clean_labels)

        output_task = Task(filename)
        output_task.extension = '.pkl'
        output_task.task += active_baseline
        output_file = output_dir / output_task.get_filename()
        with output_file.open('wb') as f:
            dump(data, f)
        outputs.append(output_file)

    return outputs
예제 #13
0
def test_blackrock_markers_00():
    d = Dataset(ns2_file)
    markers = d.read_markers()
    assert len(markers) == 176
예제 #14
0
def test_xltek_marker():
    d = Dataset(ktlx_file)
    markers = d.read_markers()
    assert markers[0]['name'] == 'Gain/Filter change (-unknown-)'
    assert markers[-1]['end'] == 1052.1
예제 #15
0
def test_xltek_marker():
    d = Dataset(ktlx_file)
    markers = d.read_markers()
    assert markers[0]['name'] == 'Start Recording (varkha)'
    assert int(markers[-1]['end']) == 1314
예제 #16
0
def test_edf_annot():
    remove_datetime(generated_file)

    generated = Dataset(generated_file)
    markers = generated.read_markers()
    assert len(markers) == 2