Beispiel #1
0
def test_common_reference():
    rec, sort = se.example_datasets.toy_example(duration=10, num_channels=4)

    # no groups
    rec_cmr = common_reference(rec, reference='median')
    rec_car = common_reference(rec, reference='average')
    rec_sin = common_reference(rec, reference='single', ref_channels=0)
    rec_cmr_int16 = common_reference(rec, dtype='int16')

    traces = rec.get_traces()
    assert np.allclose(
        traces,
        rec_cmr.get_traces() + np.median(traces, axis=0, keepdims=True))
    assert np.allclose(
        traces,
        rec_car.get_traces() + np.mean(traces, axis=0, keepdims=True))
    assert not np.all(rec_sin.get_traces()[0])
    assert np.allclose(rec_sin.get_traces()[1], traces[1] - traces[0])
    assert 'int16' in str(rec_cmr_int16.get_dtype())

    # test groups
    groups = [[0, 1], [2, 3]]
    rec_cmr_g = common_reference(rec, reference='median', groups=groups)
    rec_car_g = common_reference(rec, reference='average', groups=groups)
    rec_sin_g = common_reference(rec,
                                 reference='single',
                                 ref_channels=[0, 2],
                                 groups=groups)
    rec_cmr_int16_g = common_reference(rec, groups=groups, dtype='int16')

    traces = rec.get_traces()
    assert np.allclose(
        traces[:2],
        rec_cmr_g.get_traces()[:2] +
        np.median(traces[:2], axis=0, keepdims=True))
    assert np.allclose(
        traces[2:],
        rec_cmr_g.get_traces()[2:] +
        np.median(traces[2:], axis=0, keepdims=True))
    assert np.allclose(
        traces[:2],
        rec_car_g.get_traces()[:2] +
        np.mean(traces[:2], axis=0, keepdims=True))
    assert np.allclose(
        traces[2:],
        rec_car_g.get_traces()[2:] +
        np.mean(traces[2:], axis=0, keepdims=True))
    assert not np.all(rec_sin_g.get_traces()[0])
    assert np.allclose(rec_sin_g.get_traces()[1], traces[1] - traces[0])
    assert not np.all(rec_sin_g.get_traces()[2])
    assert np.allclose(rec_sin_g.get_traces()[3], traces[3] - traces[2])
    assert 'int16' in str(rec_cmr_int16_g.get_dtype())
def test_common_reference():
    rec, sort = se.example_datasets.create_dumpable_extractors(duration=10,
                                                               num_channels=4,
                                                               folder='test')

    # no groups
    rec_cmr = common_reference(rec, reference='median')
    rec_car = common_reference(rec, reference='average')
    rec_sin = common_reference(rec, reference='single', ref_channels=0)
    rec_cmr_int16 = common_reference(rec, dtype='int16')

    traces = rec.get_traces()
    assert np.allclose(traces,
                       rec_cmr.get_traces() +
                       np.median(traces, axis=0, keepdims=True),
                       atol=0.01)
    assert np.allclose(traces,
                       rec_car.get_traces() +
                       np.mean(traces, axis=0, keepdims=True),
                       atol=0.01)
    assert not np.all(rec_sin.get_traces()[0])
    assert np.allclose(rec_sin.get_traces()[1], traces[1] - traces[0])
    assert 'int16' in str(rec_cmr_int16.get_dtype())

    # test groups
    groups = [[0, 1], [2, 3]]
    rec_cmr_g = common_reference(rec, reference='median', groups=groups)
    rec_car_g = common_reference(rec, reference='average', groups=groups)
    rec_sin_g = common_reference(rec,
                                 reference='single',
                                 ref_channels=[0, 2],
                                 groups=groups)
    rec_cmr_int16_g = common_reference(rec, groups=groups, dtype='int16')

    traces = rec.get_traces()
    assert np.allclose(traces[:2],
                       rec_cmr_g.get_traces()[:2] +
                       np.median(traces[:2], axis=0, keepdims=True),
                       atol=0.01)
    assert np.allclose(traces[2:],
                       rec_cmr_g.get_traces()[2:] +
                       np.median(traces[2:], axis=0, keepdims=True),
                       atol=0.01)
    assert np.allclose(traces[:2],
                       rec_car_g.get_traces()[:2] +
                       np.mean(traces[:2], axis=0, keepdims=True),
                       atol=0.01)
    assert np.allclose(traces[2:],
                       rec_car_g.get_traces()[2:] +
                       np.mean(traces[2:], axis=0, keepdims=True),
                       atol=0.01)
    assert not np.all(rec_sin_g.get_traces()[0])
    assert np.allclose(rec_sin_g.get_traces()[1], traces[1] - traces[0])
    assert not np.all(rec_sin_g.get_traces()[2])
    assert np.allclose(rec_sin_g.get_traces()[3], traces[3] - traces[2])
    assert 'int16' in str(rec_cmr_int16_g.get_dtype())

    check_dumping(rec_cmr)
    check_dumping(rec_car)
    check_dumping(rec_sin)
    check_dumping(rec_cmr_int16)
    shutil.rmtree('test')
Beispiel #3
0
def test_common_reference():
    rec, sort = se.example_datasets.toy_example(dump_folder='test', dumpable=True, duration=2, num_channels=4, seed=0)

    # no groups
    rec_cmr = common_reference(rec, reference='median')
    rec_car = common_reference(rec, reference='average')
    rec_sin = common_reference(rec, reference='single', ref_channels=0)
    rec_local_car = common_reference(rec, reference='local', local_radius=(1, 3))
    rec_cmr_int16 = common_reference(rec, dtype='int16')

    traces = rec.get_traces()
    assert np.allclose(traces, rec_cmr.get_traces() + np.median(traces, axis=0, keepdims=True), atol=0.01)
    assert np.allclose(traces, rec_car.get_traces() + np.mean(traces, axis=0, keepdims=True), atol=0.01)
    assert not np.all(rec_sin.get_traces()[0])
    assert np.allclose(rec_sin.get_traces()[1], traces[1] - traces[0])

    assert np.allclose(traces[0], rec_local_car.get_traces()[0] + np.mean(traces[[2, 3]], axis=0, keepdims=True),
                       atol=0.01)
    assert np.allclose(traces[1], rec_local_car.get_traces()[1] + np.mean(traces[[3]], axis=0, keepdims=True),
                       atol=0.01)

    assert 'int16' in str(rec_cmr_int16.get_dtype())

    # test groups
    groups = [[0, 1], [2, 3]]
    rec_cmr_g = common_reference(rec, reference='median', groups=groups)
    rec_car_g = common_reference(rec, reference='average', groups=groups)
    rec_sin_g = common_reference(rec, reference='single', ref_channels=[0, 2], groups=groups)
    rec_cmr_int16_g = common_reference(rec, groups=groups, dtype='int16')

    traces = rec.get_traces()
    assert np.allclose(traces[:2], rec_cmr_g.get_traces()[:2] + np.median(traces[:2], axis=0, keepdims=True), atol=0.01)
    assert np.allclose(traces[2:], rec_cmr_g.get_traces()[2:] + np.median(traces[2:], axis=0, keepdims=True), atol=0.01)
    assert np.allclose(traces[:2], rec_car_g.get_traces()[:2] + np.mean(traces[:2], axis=0, keepdims=True), atol=0.01)
    assert np.allclose(traces[2:], rec_car_g.get_traces()[2:] + np.mean(traces[2:], axis=0, keepdims=True), atol=0.01)

    assert not np.all(rec_sin_g.get_traces()[0])
    assert np.allclose(rec_sin_g.get_traces()[1], traces[1] - traces[0])
    assert not np.all(rec_sin_g.get_traces()[2])
    assert np.allclose(rec_sin_g.get_traces()[3], traces[3] - traces[2])
    assert 'int16' in str(rec_cmr_int16_g.get_dtype())

    check_dumping(rec_cmr)
    check_dumping(rec_car)
    check_dumping(rec_sin)
    check_dumping(rec_cmr_int16)
    check_dumping(rec_local_car)

    # test with channels_ids
    channels_ids = np.arange(0, 2)
    assert np.allclose(traces[channels_ids],
                       rec_car.get_traces(channel_ids=channels_ids) + np.mean(traces, axis=0, keepdims=True), atol=0.01)
    assert np.allclose(traces[channels_ids],
                       rec_cmr_g.get_traces(channel_ids=channels_ids) + np.median(traces[[0, 1]], axis=0,
                                                                                  keepdims=True), atol=0.01)

    # Add test on a higher probes
    rec2, sort = se.example_datasets.toy_example(dump_folder='test', dumpable=True, duration=2, num_channels=8, seed=0)
    rec_local_car2 = common_reference(rec2, reference='local', local_radius=(2, 4))
    traces = rec2.get_traces()
    assert np.allclose(traces[3], rec_local_car2.get_traces()[3] + np.mean(traces[[0, 6, 7]], axis=0, keepdims=True),
                       atol=0.01)

    shutil.rmtree('test')