def test_returns_discretization_bins(self): start = 2.0 * pq.s stop = 5.0 * pq.s sampling_rate = 2.0 * pq.Hz expected = sp.array([2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]) * pq.s st = create_empty_spike_train(start, stop) _, bins = sigproc.st_convolve( st, sigproc.GaussianKernel(), sampling_rate=sampling_rate) assert_array_almost_equal(expected, bins)
def test_returns_convolved_spike_train(self): st = neo.SpikeTrain(sp.array([1.0, 2.0]) * pq.s, t_stop=3.0 * pq.s) kernel = sigproc.RectangularKernel(0.3 * pq.s) # Because of the low sampling rate the expected result is a bit off # from the analytical result. expected = sp.array( [0.0, 0.0, 0.0, 1.6666666, 1.6666666, 1.6666666, 0.0, 1.6666666, 1.6666666, 1.6666666, 0.0, 0.0]) * pq.Hz actual, _ = sigproc.st_convolve(st, kernel, sampling_rate=4 * pq.Hz) assert_array_almost_equal(expected, actual)
def test_returns_discretization_bins(self): start = 2.0 * pq.s stop = 5.0 * pq.s sampling_rate = 2.0 * pq.Hz expected = sp.array([2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]) * pq.s st = create_empty_spike_train(start, stop) _, bins = sigproc.st_convolve(st, sigproc.GaussianKernel(), sampling_rate=sampling_rate) assert_array_almost_equal(expected, bins)
def test_returns_convolved_spike_train(self): st = neo.SpikeTrain(sp.array([1.0, 2.0]) * pq.s, t_stop=3.0 * pq.s) kernel = sigproc.RectangularKernel(0.3 * pq.s) # Because of the low sampling rate the expected result is a bit off # from the analytical result. expected = sp.array([ 0.0, 0.0, 0.0, 1.6666666, 1.6666666, 1.6666666, 0.0, 1.6666666, 1.6666666, 1.6666666, 0.0, 0.0 ]) * pq.Hz actual, _ = sigproc.st_convolve(st, kernel, sampling_rate=4 * pq.Hz) assert_array_almost_equal(expected, actual)
def test_length_of_returned_array_equals_sampling_rate_times_duration(self): start = 2.0 * pq.s stop = 5.0 * pq.s duration = stop - start sampling_rate = 12 * pq.Hz expected_length = (sampling_rate * duration).simplified st = create_empty_spike_train(start, stop) result, _ = sigproc.st_convolve( st, sigproc.GaussianKernel(), sampling_rate=sampling_rate) self.assertEqual(expected_length, result.size)
def test_length_of_returned_array_equals_sampling_rate_times_duration( self): start = 2.0 * pq.s stop = 5.0 * pq.s duration = stop - start sampling_rate = 12 * pq.Hz expected_length = (sampling_rate * duration).simplified st = create_empty_spike_train(start, stop) result, _ = sigproc.st_convolve(st, sigproc.GaussianKernel(), sampling_rate=sampling_rate) self.assertEqual(expected_length, result.size)
def test_mode_allows_valid_convolution(self): start = 2.0 * pq.s stop = 5.0 * pq.s sampling_rate = 2.0 * pq.Hz kernel = sigproc.RectangularKernel(0.6 * pq.s) st = create_empty_spike_train(start, stop) expected_length = (stop - start) * sampling_rate - 2 expected_bins = sp.array([2.5, 3.0, 3.5, 4.0, 4.5]) * pq.s binned, bins = sigproc.st_convolve( st, kernel, mode='valid', sampling_rate=sampling_rate) self.assertEqual(binned.size, expected_length) assert_array_almost_equal(expected_bins, bins)
def test_mode_allows_valid_convolution(self): start = 2.0 * pq.s stop = 5.0 * pq.s sampling_rate = 2.0 * pq.Hz kernel = sigproc.RectangularKernel(0.6 * pq.s) st = create_empty_spike_train(start, stop) expected_length = (stop - start) * sampling_rate - 2 expected_bins = sp.array([2.5, 3.0, 3.5, 4.0, 4.5]) * pq.s binned, bins = sigproc.st_convolve(st, kernel, mode='valid', sampling_rate=sampling_rate) self.assertEqual(binned.size, expected_length) assert_array_almost_equal(expected_bins, bins)
def test_convolution_with_empty_spike_train_returns_array_of_zeros(self): st = create_empty_spike_train() result, _ = sigproc.st_convolve(st, sigproc.GaussianKernel(), 1 * pq.Hz) self.assertTrue(sp.all(result == 0.0))