Beispiel #1
0
def test_remove_bad_channels():
    rec, sort = se.example_datasets.toy_example(dump_folder='test', dumpable=True, duration=2, num_channels=4, seed=0)
    rec_rm = remove_bad_channels(rec, bad_channel_ids=[0])
    assert 0 not in rec_rm.get_channel_ids()

    rec_rm = remove_bad_channels(rec, bad_channel_ids=[1, 2])
    assert 1 not in rec_rm.get_channel_ids() and 2 not in rec_rm.get_channel_ids()

    check_dumping(rec_rm)
    shutil.rmtree('test')

    timeseries = np.random.randn(4, 60000)
    timeseries[1] = 10 * timeseries[1]

    rec_np = se.NumpyRecordingExtractor(timeseries=timeseries, sampling_frequency=30000)
    rec_np.set_channel_locations(np.ones((rec_np.get_num_channels(), 2)))
    se.MdaRecordingExtractor.write_recording(rec_np, 'test')
    rec = se.MdaRecordingExtractor('test')
    rec_rm = remove_bad_channels(rec, bad_channel_ids=None, bad_threshold=2)
    assert 1 not in rec_rm.get_channel_ids()
    check_dumping(rec_rm)

    rec_rm = remove_bad_channels(rec, bad_channel_ids=None, bad_threshold=2, seconds=0.1)
    assert 1 not in rec_rm.get_channel_ids()
    check_dumping(rec_rm)

    rec_rm = remove_bad_channels(rec, bad_channel_ids=None, bad_threshold=2, seconds=10)
    assert 1 not in rec_rm.get_channel_ids()
    check_dumping(rec_rm)
    shutil.rmtree('test')
def test_remove_bad_channels():
    rec, sort = se.example_datasets.toy_example(duration=10, num_channels=4)
    rec_rm = remove_bad_channels(rec, bad_channel_ids=[0])
    assert 0 not in rec_rm.get_channel_ids()

    rec_rm = remove_bad_channels(rec, bad_channel_ids=[1, 2])
    assert 1 not in rec_rm.get_channel_ids(
    ) and 2 not in rec_rm.get_channel_ids()

    timeseries = np.random.randn(4, 60000)
    timeseries[1] = 3 * timeseries[1]

    rec_np = se.NumpyRecordingExtractor(timeseries=timeseries,
                                        sampling_frequency=30000)
    rec_rm = remove_bad_channels(rec_np, bad_channel_ids=None, bad_threshold=2)
    assert 1 not in rec_rm.get_channel_ids()

    rec_rm = remove_bad_channels(rec_np,
                                 bad_channel_ids=None,
                                 bad_threshold=2,
                                 seconds=0.1)
    assert 1 not in rec_rm.get_channel_ids()

    rec_rm = remove_bad_channels(rec_np,
                                 bad_channel_ids=None,
                                 bad_threshold=2,
                                 seconds=10)
    assert 1 not in rec_rm.get_channel_ids()
Beispiel #3
0
def test_export_to_phy():
    folder = 'test'
    if os.path.isdir(folder):
        shutil.rmtree(folder)
    rec, sort = se.example_datasets.toy_example(dump_folder=folder,
                                                dumpable=True,
                                                duration=10,
                                                num_channels=8)

    export_to_phy(rec, sort, output_folder='phy')
    rec.set_channel_groups([0, 0, 0, 0, 1, 1, 1, 1])
    export_to_phy(rec,
                  sort,
                  output_folder='phy_group',
                  grouping_property='group',
                  recompute_info=True)
    export_to_phy(rec,
                  sort,
                  output_folder='phy_max_channels',
                  max_channels_per_template=4,
                  recompute_info=True)
    export_to_phy(rec,
                  sort,
                  output_folder='phy_no_feat',
                  grouping_property='group',
                  compute_pc_features=False,
                  recompute_info=True)
    export_to_phy(rec,
                  sort,
                  output_folder='phy_no_amp',
                  compute_amplitudes=False)
    export_to_phy(rec,
                  sort,
                  output_folder='phy_no_amp_feat',
                  compute_amplitudes=False,
                  compute_pc_features=False)
    export_to_phy(rec, sort, output_folder='phy_par', n_jobs=2)

    rec_phy = se.PhyRecordingExtractor('phy')
    rec_phyg = se.PhyRecordingExtractor('phy_group')
    assert np.allclose(rec.get_traces(), rec_phy.get_traces())
    assert np.allclose(rec.get_traces(), rec_phyg.get_traces())
    assert not (Path('phy_no_feat') / 'pc_features.npy').is_file()
    assert not (Path('phy_no_feat') / 'pc_feature_ind.npy').is_file()
    assert not (Path('phy_no_amp') / 'amplitudes.npy').is_file()
    assert not (Path('phy_no_amp_feat') / 'amplitudes.npy').is_file()
    assert not (Path('phy_no_amp_feat') / 'pc_features.npy').is_file()
    assert not (Path('phy_no_amp_feat') / 'pc_feature_ind.npy').is_file()

    sort_phy = se.PhySortingExtractor('phy', load_waveforms=True)
    sort_phyg = se.PhySortingExtractor('phy_group', load_waveforms=True)

    assert np.allclose(sort_phy.get_unit_spike_train(0),
                       sort.get_unit_spike_train(sort.get_unit_ids()[0]))
    assert np.allclose(sort_phyg.get_unit_spike_train(2),
                       sort.get_unit_spike_train(sort.get_unit_ids()[2]))
    assert sort_phy.get_unit_spike_features(1, 'waveforms').shape[1] == 8
    assert sort_phyg.get_unit_spike_features(3, 'waveforms').shape[1] == 4

    rec.set_channel_groups([0, 0, 0, 0, 1, 1, 1, 1])
    recrm = remove_bad_channels(rec, [1, 2, 5])
    export_to_phy(recrm,
                  sort,
                  output_folder='phy_rm',
                  grouping_property='group',
                  recompute_info=True,
                  verbose=True)
    templates_ind = np.load('phy_rm/template_ind.npy')
    assert len(np.where(templates_ind == -1)[0]) > 0  # removed channels are -1

    try:
        shutil.rmtree('test')
        shutil.rmtree('phy')
        shutil.rmtree('phy_group')
        shutil.rmtree('phy_max_channels')
        shutil.rmtree('phy_no_feat')
        shutil.rmtree('phy_no_amp')
        shutil.rmtree('phy_no_amp_feat')
        shutil.rmtree('phy_rm')
        shutil.rmtree('phy_par')
    except:
        print("Could not delete some test folders")