def test_isi_violations(): # 1. check value for fixed spike train parameters: train1 = simulated_spike_train(100, 10, 10) fpRate1, num_violations1 = isi_violations(train1, np.max(train1), 0.001) assert np.isclose(fpRate1, 0.4901480247, rtol=0, atol=1e-5) assert num_violations1 == 10 # 2. check that the value doesn't depend on recording duration: train2 = simulated_spike_train(200, 10, 20) fpRate2, num_violations2 = isi_violations(train2, np.max(train2), 0.001) assert np.isclose(fpRate1, fpRate2, rtol=0, atol=1e-5) # 3. check that the value increases with the number of violations: train3 = simulated_spike_train(100, 10, 20) fpRate3, num_violations3 = isi_violations(train3, np.max(train3), 0.001) assert fpRate3 > fpRate1 # 4. check that the value decreases with a longer violation window: fpRate4, num_violations4 = isi_violations(train1, np.max(train1), 0.002) assert fpRate4 < fpRate1 # 5. check that the value decreases with firing rate: train4 = simulated_spike_train(100, 20, 10) fpRate5, num_violations5 = isi_violations(train4, np.max(train4), 0.001) assert fpRate5 < fpRate1
def simulated_spike_times(): max_time = 100 trains = [simulated_spike_train(max_time, 10, 2), simulated_spike_train(max_time, 5, 4), simulated_spike_train(max_time, 5, 10)] labels = [np.ones((len(trains[i]),), dtype='int') * i for i in range(len(trains))] spike_times = np.concatenate(trains) spike_clusters = np.concatenate(labels) order = np.argsort(spike_times) spike_times = spike_times[order] spike_clusters = spike_clusters[order] return {'spike_times': spike_times, 'spike_clusters': spike_clusters}
def test_firing_rate(): # 1. check that the output value is correct: max_time = 100 simulated_firing_rate = 10.0 train = simulated_spike_train(max_time, simulated_firing_rate, 0) assert firing_rate(train, duration=max_time) == simulated_firing_rate # 2. check that widening the boundaries decreases the rate: assert firing_rate(train, duration=100) > firing_rate(train, duration=200)
def test_presence_ratio(overall_duration, expected_value): spike_times = simulated_spike_train(100, 20, 0) assert presence_ratio(spike_times, 0, overall_duration) == expected_value