def test_uses_min_spike_train_interval(self):
     a = arange_spikes(5 * pq.s)
     b = arange_spikes(3 * pq.s, 15 * pq.s)
     bin_size = 250.0 * pq.ms
     expectedBins = sp.arange(3.0, 4.9, 0.25) * pq.s
     actual, actualBins = re.binned_spike_trains({0: [a, b]}, bin_size)
     assert_array_almost_equal(
         expectedBins, actualBins.rescale(expectedBins.units))
Exemple #2
0
 def test_uses_max_spike_train_interval(self):
     a = arange_spikes(5 * pq.s)
     b = arange_spikes(7 * pq.s, 15 * pq.s)
     sampling_rate = 4.0 * pq.Hz
     expectedBins = sp.arange(0.0, 15.1, 0.25) * pq.s
     actual, actualBins = tools.bin_spike_trains(
         {0: [a, b]}, sampling_rate=sampling_rate)
     assert_array_almost_equal(expectedBins,
                               actualBins.rescale(expectedBins.units))
Exemple #3
0
 def test_allows_to_pass_additional_args(self):
     st_dict = {
         'a': [arange_spikes(5 * pq.s),
               arange_spikes(4 * pq.s)],
         'b': [arange_spikes(7 * pq.s)]
     }
     expected = {'a': [8, 6], 'b': [12]}
     actual = tools.apply_to_dict(self.fn, st_dict, 2)
     self.assertEqual(expected, actual)
Exemple #4
0
 def test_maps_function_to_each_spike_train(self):
     st_dict = {
         'a': [arange_spikes(5 * pq.s),
               arange_spikes(4 * pq.s)],
         'b': [arange_spikes(7 * pq.s)]
     }
     expected = {'a': [4, 3], 'b': [6]}
     actual = tools.apply_to_dict(self.fn, st_dict)
     self.assertEqual(expected, actual)
Exemple #5
0
 def test_uses_max_spike_train_interval(self):
     a = arange_spikes(5 * pq.s)
     b = arange_spikes(7 * pq.s, 15 * pq.s)
     sampling_rate = 4.0 * pq.Hz
     expectedBins = sp.arange(0.0, 15.1, 0.25) * pq.s
     actual, actualBins = tools.bin_spike_trains(
         {0: [a, b]}, sampling_rate=sampling_rate)
     assert_array_almost_equal(
         expectedBins, actualBins.rescale(expectedBins.units))
Exemple #6
0
 def test_handles_bin_size_which_is_not_divisor_of_duration(self):
     a = arange_spikes(5 * pq.s)
     sampling_rate = 1.0 / 1.3 * pq.Hz
     expected = {0: [sp.array([1, 1, 1, 1])]}
     expectedBins = sp.array([0.0, 1.3, 2.6, 3.9, 5.2]) * pq.s
     actual, actualBins = tools.bin_spike_trains({0: [a]}, sampling_rate)
     self.assertEqual(len(expected), len(actual))
     self.assertEqual(len(expected[0]), len(actual[0]))
     assert_array_equal(expected[0][0], actual[0][0])
     assert_array_almost_equal(expectedBins,
                               actualBins.rescale(expectedBins.units))
 def test_handles_bin_size_which_is_not_divisor_of_duration(self):
     a = arange_spikes(5 * pq.s)
     bin_size = 1300.0 * pq.ms
     expected = {0: [sp.array([1, 1, 1])]}
     expectedBins = sp.array([0.0, 1.3, 2.6, 3.9]) * pq.s
     actual, actualBins = re.binned_spike_trains({0: [a]}, bin_size)
     self.assertEqual(len(expected), len(actual))
     self.assertEqual(len(expected[0]), len(actual[0]))
     assert_array_equal(expected[0][0], actual[0][0])
     assert_array_almost_equal(
         expectedBins, actualBins.rescale(expectedBins.units))
Exemple #8
0
 def test_handles_bin_size_which_is_not_divisor_of_duration(self):
     a = arange_spikes(5 * pq.s)
     sampling_rate = 1.0 / 1.3 * pq.Hz
     expected = {0: [sp.array([1, 1, 1, 1])]}
     expectedBins = sp.array([0.0, 1.3, 2.6, 3.9, 5.2]) * pq.s
     actual, actualBins = tools.bin_spike_trains({0: [a]}, sampling_rate)
     self.assertEqual(len(expected), len(actual))
     self.assertEqual(len(expected[0]), len(actual[0]))
     assert_array_equal(expected[0][0], actual[0][0])
     assert_array_almost_equal(
         expectedBins, actualBins.rescale(expectedBins.units))
Exemple #9
0
 def test_t_stop_is_max_of_all_trains(self):
     a = arange_spikes(3.0 * pq.s, 5.0 * pq.s)
     b = arange_spikes(1.0 * pq.s, 6.0 * pq.s)
     expected = 6.0 * pq.s
     actual = tools.concatenate_spike_trains((a, b)).t_stop
     self.assertAlmostEqual(expected, actual)
Exemple #10
0
 def test_concatenates_spike_trains(self):
     a = arange_spikes(3.0 * pq.s)
     b = arange_spikes(2.0 * pq.s, 5.0 * pq.s)
     expected = arange_spikes(5.0 * pq.s)
     actual = tools.concatenate_spike_trains((a, b))
     assert_array_almost_equal(expected, actual)
Exemple #11
0
 def test_allows_to_pass_additional_args(self):
     st_dict = {'a': [arange_spikes(5 * pq.s), arange_spikes(4 * pq.s)],
                'b': [arange_spikes(7 * pq.s)]}
     expected = {'a': [8, 6], 'b': [12]}
     actual = tools.apply_to_dict(self.fn, st_dict, 2)
     self.assertEqual(expected, actual)
Exemple #12
0
 def test_maps_function_to_each_spike_train(self):
     st_dict = {'a': [arange_spikes(5 * pq.s), arange_spikes(4 * pq.s)],
                'b': [arange_spikes(7 * pq.s)]}
     expected = {'a': [4, 3], 'b': [6]}
     actual = tools.apply_to_dict(self.fn, st_dict)
     self.assertEqual(expected, actual)
Exemple #13
0
 def test_t_stop_is_max_of_all_trains(self):
     a = arange_spikes(3.0 * pq.s, 5.0 * pq.s)
     b = arange_spikes(1.0 * pq.s, 6.0 * pq.s)
     expected = 6.0 * pq.s
     actual = tools.concatenate_spike_trains((a, b)).t_stop
     self.assertAlmostEqual(expected, actual)
Exemple #14
0
 def test_concatenates_spike_trains(self):
     a = arange_spikes(3.0 * pq.s)
     b = arange_spikes(2.0 * pq.s, 5.0 * pq.s)
     expected = arange_spikes(5.0 * pq.s)
     actual = tools.concatenate_spike_trains((a, b))
     assert_array_almost_equal(expected, actual)