def test_experiment_channels(): with Experiment('myexperiment', dir=DIRPATH) as exp: assert exp.name == 'myexperiment' assert exp.application_data # assert exp.user_data assert exp.application_data.spikedetekt.nchannels == 3 assert exp.application_data.spikedetekt.waveforms_nsamples == 10 assert exp.application_data.spikedetekt.nfeatures == 3 # Channel group. chgrp = exp.channel_groups[0] assert chgrp.name == 'channel_group_0' assert np.array_equal(chgrp.adjacency_graph, [[4, 6], [8, 4]]) assert chgrp.application_data # assert chgrp.user_data # Channels. channels = chgrp.channels assert list(sorted(channels.keys())) == [4, 6, 8] # Channel. ch = channels[4] assert ch.name == 'channel_4' ch.kwd_index ch.ignored assert np.allclose(ch.position, [.4, .6]) ch.voltage_gain ch.display_threshold assert ch.application_data
def test_experiment_setattr(): with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp: chgrp = exp.channel_groups[0] color0 = chgrp.clusters.main[0].application_data.klustaviewa.color # By default, the cluster's color is 1. assert color0 == 1 # Set it to 0. chgrp.clusters.main[0].application_data.klustaviewa.color = 0 # We check that the color has changed in the file. assert chgrp.clusters.main[0].application_data.klustaviewa._f_getAttr('color') == 0 # Close and open the file. with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp: chgrp = exp.channel_groups[0] # Check that the change has been saved on disk. assert chgrp.clusters.main[0].application_data.klustaviewa.color == 0 # Set back the field to its original value. chgrp.clusters.main[0].application_data.klustaviewa.color = color0
def test_experiment_add_cluster(): with Experiment('myexperiment2', dir=DIRPATH, mode='a') as exp: chgrp = exp.channel_groups[0] chgrp.clusters.main.add_cluster(id=27, color=34) assert 27 in chgrp.clusters.main.keys() assert chgrp.clusters.main[27].application_data.klustaviewa.color == 34 assert np.allclose(chgrp.clusters.main.color[:], [1, 34]) chgrp.clusters.main.remove_cluster(id=27) assert 27 not in chgrp.clusters.main.keys()
def test_experiment_add_cluster_group(): with Experiment('myexperiment2', dir=DIRPATH, mode='a') as exp: chgrp = exp.channel_groups[0] chgrp.cluster_groups.main.add_group(id=27, name='boo', color=34) assert 27 in chgrp.cluster_groups.main.keys() assert chgrp.cluster_groups.main[27].name == 'boo' assert chgrp.cluster_groups.main[27].application_data.klustaviewa.color == 34 chgrp.cluster_groups.main.remove_group(id=27) assert 27 not in chgrp.cluster_groups.main.keys()
def test_experiment_cluster_groups(): with Experiment('myexperiment', dir=DIRPATH) as exp: chgrp = exp.channel_groups[0] cluster_group = chgrp.cluster_groups.main[0] assert cluster_group.name == 'Noise' assert cluster_group.application_data # assert cluster_group.user_data assert np.array_equal(chgrp.cluster_groups.main.color[:], [1]) assert np.array_equal(chgrp.clusters.main.group[:], [0])
def test_experiment_repr_nokwd(): kwd = os.path.join(DIRPATH, 'myexperiment.raw.kwd') kwd2 = os.path.join(DIRPATH, 'myexperiment2.raw.kwd') # Move a KWD file and test if Experiment works without KWD. os.rename(kwd, kwd2) info("The following error message is expected (part of the unit test)") with Experiment('myexperiment', dir=DIRPATH) as exp: s = str(exp) os.rename(kwd2, kwd)
def test_experiment_events(): with Experiment('myexperiment', dir=DIRPATH) as exp: evtp = exp.event_types['myevents'] evtp.application_data # evtp.user_data samples = evtp.events.time_samples assert isinstance(samples, tb.EArray) assert samples.dtype == np.uint64 recordings = evtp.events.recording assert isinstance(recordings, tb.EArray) assert recordings.dtype == np.uint16
def test_experiment_recordings(): with Experiment('myexperiment', dir=DIRPATH) as exp: rec = exp.recordings[0] assert rec.name == 'recording_0' assert rec.sample_rate == 20000. assert rec.start_time == 10. assert rec.start_sample == 200000. assert rec.bit_depth == 16 assert rec.band_high == 100. assert rec.band_low == 500. rd = rec.raw assert isinstance(rd, tb.EArray) assert rd.shape == (0, 3) assert rd.dtype == np.int16
def test_experiment_add_spikes_nomasks(): with Experiment('myexperiment_nomasks', dir=DIRPATH, mode='a') as exp: chgrp = exp.channel_groups[0] spikes = chgrp.spikes assert spikes.features_masks.shape == (0, 3) assert isinstance(spikes.features, tb.Array) assert spikes.features.shape == (0, 3) spikes.add(time_samples=1000) spikes.add(time_samples=2000) assert len(spikes) == 2 assert spikes.features_masks.shape == (2, 3) assert isinstance(spikes.features, tb.Array) assert spikes.features.shape == (2, 3)
def test_experiment_features(): """Test the wrapper around features implementing a custom cache.""" with Experiment('myexperiment', dir=DIRPATH) as exp: chgrp = exp.channel_groups[0] spikes = chgrp.spikes assert isinstance(spikes.features_masks, tb.EArray) assert spikes.features_masks.dtype == np.float32 assert spikes.features_masks.ndim == 3 assert isinstance(spikes.waveforms_raw, tb.EArray) assert spikes.waveforms_raw.dtype == np.int16 assert spikes.waveforms_raw.ndim == 3 assert isinstance(spikes.waveforms_filtered, tb.EArray) assert spikes.waveforms_filtered.dtype == np.int16 assert spikes.waveforms_filtered.ndim == 3
def test_experiment_spikes(): with Experiment('myexperiment', dir=DIRPATH) as exp: chgrp = exp.channel_groups[0] spikes = chgrp.spikes assert isinstance(spikes.time_samples, tb.EArray) assert spikes.time_samples.dtype == np.uint64 assert spikes.time_samples.ndim == 1 t = spikes.concatenated_time_samples # assert isinstance(t, np.ndarray) assert t.dtype == np.uint64 assert t.ndim == 1 assert isinstance(spikes.time_fractional, tb.EArray) assert spikes.time_fractional.dtype == np.uint8 assert spikes.time_fractional.ndim == 1 assert isinstance(spikes.recording, tb.EArray) assert spikes.recording.dtype == np.uint16 assert spikes.recording.ndim == 1 assert isinstance(spikes.clusters.main, tb.EArray) assert spikes.clusters.main.dtype == np.uint32 assert spikes.clusters.main.ndim == 1 assert isinstance(spikes.clusters.original, tb.EArray) assert spikes.clusters.original.dtype == np.uint32 assert spikes.clusters.original.ndim == 1 assert isinstance(spikes.features_masks, tb.EArray) assert spikes.features_masks.dtype == np.float32 assert spikes.features_masks.ndim == 3 assert isinstance(spikes.waveforms_raw, tb.EArray) assert spikes.waveforms_raw.dtype == np.int16 assert spikes.waveforms_raw.ndim == 3 assert isinstance(spikes.waveforms_filtered, tb.EArray) assert spikes.waveforms_filtered.dtype == np.int16 assert spikes.waveforms_filtered.ndim == 3
def test_experiment_copy_clusters(): with Experiment('myexperiment', dir=DIRPATH, mode='a') as exp: clusters = exp.channel_groups[0].spikes.clusters # Adding spikes. for i in range(10): exp.channel_groups[0].spikes.add(time_samples=i*1000, cluster=10+i) main = clusters.main[:] original = clusters.original[:] assert len(main) == 10 assert len(original) == 10 assert np.allclose(main, np.arange(10, 20)) assert np.allclose(original, np.zeros(10)) # Change original clusters on disk. clusters.original[1:10:2] = 123 assert np.all(clusters.main[1:10:2] != 123) # Copy clusters from original to main. clusters.copy('original', 'main') assert np.all(clusters.main[1:10:2] == 123)
def test_experiment_repr(): with Experiment('myexperiment', dir=DIRPATH) as exp: s = str(exp)
def test_experiment_clusters(): with Experiment('myexperiment', dir=DIRPATH) as exp: chgrp = exp.channel_groups[0] cluster = chgrp.clusters.main[0]
def test_experiment_vectorizer(): with Experiment('myexperiment', dir=DIRPATH) as exp: clustering = exp.channel_groups[0].clusters.main dv = DictVectorizer(clustering, 'application_data.klustaviewa.color') assert np.array_equal(dv[0], 1) assert np.array_equal(dv[:], [1])
def test_recluster(): with Experiment('myexperiment', dir=DIRPATH) as exp: spikes, clu = run_klustakwik(exp, channel_group=0, clusters=[5, 8]) assert 10 < len(clu) < 990