Esempio n. 1
0
    def get_autocorr(self, clust_idx):
        idx = np.where(self.spikes['clusters'] == self.clust_id[clust_idx])[0]
        autocorr = xcorr(self.spikes['times'][idx],
                         self.spikes['clusters'][idx], AUTOCORR_BIN_SIZE,
                         AUTOCORR_WIN_SIZE)

        return autocorr[0, 0, :]
Esempio n. 2
0
    def test_xcorr_2(self):
        max_cluster = 10
        spike_times, spike_clusters = _random_data(max_cluster)
        bin_size, winsize_bins = .001, .05

        c = xcorr(spike_times,
                  spike_clusters,
                  bin_size=bin_size,
                  window_size=winsize_bins)

        self.assertEqual(c.shape, (max_cluster, max_cluster, 51))
Esempio n. 3
0
def acorr(spike_times, bin_size=None, window_size=None):
    """Compute the auto-correlogram of a neuron.

    Parameters
    ----------

    :param spike_times: Spike times in seconds.
    :type spike_times: array-like
    :param bin_size: Size of the bin, in seconds.
    :type bin_size: float
    :param window_size: Size of the window, in seconds.
    :type window_size: float

    Returns an `(winsize_samples,)` array with the auto-correlogram.

    """
    xc = xcorr(spike_times, np.zeros_like(spike_times), bin_size=bin_size, window_size=window_size)
    return xc[0, 0, :]
Esempio n. 4
0
    def test_xcorr_0(self):
        # 0: 0, 10
        # 1: 10, 20
        spike_times = np.array([0, 10, 10, 20])
        spike_clusters = np.array([0, 1, 0, 1])
        bin_size = 1
        winsize_bins = 2 * 3 + 1

        c_expected = np.zeros((2, 2, 7), dtype=np.int32)

        c_expected[1, 0, 3] = 1
        c_expected[0, 1, 3] = 1

        c = xcorr(spike_times,
                  spike_clusters,
                  bin_size=bin_size,
                  window_size=winsize_bins)

        self.assertTrue(np.allclose(c, c_expected))
Esempio n. 5
0
    def test_xcorr_1(self):
        # 0: 2, 10, 12, 30
        # 1: 3, 24
        # 2: 20
        spike_times = np.array([2, 3, 10, 12, 20, 24, 30, 40], dtype=np.uint64)
        spike_clusters = np.array([0, 1, 0, 0, 2, 1, 0, 2])
        bin_size = 1
        winsize_bins = 2 * 3 + 1

        c_expected = np.zeros((3, 3, 7), dtype=np.int32)
        c_expected[0, 1, 4] = 1
        c_expected[1, 0, 2] = 1
        c_expected[0, 0, 1] = 1
        c_expected[0, 0, 5] = 1

        c = xcorr(spike_times,
                  spike_clusters,
                  bin_size=bin_size,
                  window_size=winsize_bins)

        self.assertTrue(np.allclose(c, c_expected))