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, :]
def compute_autocorr(self, clust): self.clus_idx = np.where( self.spikes.clusters == self.clust_ids[clust])[0] x_corr = xcorr(self.spikes.times[self.clus_idx], self.spikes.clusters[self.clus_idx], self.autocorr_bin, self.autocorr_window) corr = x_corr[0, 0, :] return self.t_autocorr, corr
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))
def get_autocorr_for_selection(self): data = Bunch() x_corr = xcorr(self.spikes.times[self.spikes.clusters == self.clust_ids[self.clust]], self.spikes.clusters[self.spikes.clusters == self.clust_ids[self.clust]], AUTOCORR_BIN, AUTOCORR_WINDOW) t_corr = np.arange(0, AUTOCORR_WINDOW + AUTOCORR_BIN, AUTOCORR_BIN) - AUTOCORR_WINDOW / 2 data['vals'] = x_corr[0, 0, :] data['time'] = t_corr return data
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))
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))
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, dtype=np.int32), bin_size=bin_size, window_size=window_size) return xc[0, 0, :]