Пример #1
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))
Пример #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))
Пример #3
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))
Пример #4
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))
Пример #5
0
def binning_distance(trains, tau, exponent=2):
    if sp.isinf(tau) or any(tau > st.t_stop - st.t_start for st in trains):
        num_spikes = sp.atleast_2d([st.size for st in trains])
        return sp.absolute(num_spikes.T - num_spikes) ** exponent
    sampling_rate = 1.0 / tau
    binned, dummy = stools.bin_spike_trains({0: trains}, sampling_rate)
    d = sp.empty((len(trains), len(trains)))
    for i in xrange(len(trains)):
        for j in xrange(i, len(trains)):
            d[i, j] = d[j, i] = sp.sum(
                sp.absolute(binned[0][i] - binned[0][j]) ** exponent)
    return d
Пример #6
0
 def test_bins_spike_train_using_its_properties(self):
     a = neo.SpikeTrain(sp.array([1000.0]) * pq.ms,
                        t_start=500.0 * pq.ms,
                        t_stop=1500.0 * pq.ms)
     sampling_rate = 4.0 * pq.Hz
     expected = {0: [sp.array([0, 0, 1, 0])]}
     expectedBins = sp.array([0.5, 0.75, 1.0, 1.25, 1.5]) * 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))
Пример #7
0
 def test_bins_spike_train_using_its_properties(self):
     a = neo.SpikeTrain(
         sp.array([1000.0]) * pq.ms, t_start=500.0 * pq.ms,
         t_stop=1500.0 * pq.ms)
     sampling_rate = 4.0 * pq.Hz
     expected = {0: [sp.array([0, 0, 1, 0])]}
     expectedBins = sp.array([0.5, 0.75, 1.0, 1.25, 1.5]) * 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))