def test_peths_synthetic(self): n_spikes = 20000 n_clusters = 20 n_events = 200 record_length = 1654 cluster_sel = [1, 2, 3, 6, 15, 16] np.random.seed(seed=42) spike_times = np.sort(np.random.rand(n_spikes, ) * record_length) spike_clusters = np.random.randint(0, n_clusters, n_spikes) event_times = np.sort(np.random.rand(n_events, ) * record_length) peth, fr = peths(spike_times, spike_clusters, cluster_ids=cluster_sel, align_times=event_times) self.assertTrue(peth.means.shape[0] == len(cluster_sel)) self.assertTrue(np.all(peth.means.shape == peth.stds.shape)) self.assertTrue(np.all(fr.shape == (n_events, len(cluster_sel), 28))) self.assertTrue(peth.tscale.size == 28)
#ses_path = get_session_path(datasets) ses_path = datasets[ 0].local_path.parent #local path where the data has been downloaded spikes = alf.io.load_object(ses_path, 'spikes') trials = alf.io.load_object(ses_path, 'trials') # check which neurons are responsive #are_neurons_responsive(spike_times,spike_clusters,stimulus_intervals=None,spontaneous_period=None,p_value_threshold=.05): # spontaenous period is just 1 interval! on and off time responsive = are_neurons_responsive( spikes.times, spikes.clusters, np.vstack((trials.stimOn_times, trials.stimOn_times + 0.5)).T, np.array([0, trials.stimOn_times[0] - 1]).reshape(-1), 0.001) #peths(spike_times, spike_clusters, cluster_ids, align_times, pre_time=0.2, # post_time=0.5, bin_size=0.025, smoothing=0.025, return_fr=True): responsive_neuron = np.unique(spikes.clusters)[responsive] peth, bs = peths(spikes.times, spikes.clusters, responsive_neuron, trials.stimOn_times) plt.plot(peth.tscale, peth.means.T) #for m in np.arange(peth.means.shape[0]): # plt.fill_between(peth.tscale, # peth.means[m, :].T - peth.stds[m, :].T / 20, # peth.means[m, :].T + peth.stds[m, :].T / 20, # alpha=0.2, edgecolor='#1B2ACC', facecolor='#089FFF', # linewidth=4, linestyle='dashdot', antialiased=True)
import matplotlib.pyplot as plt import numpy as np import alf.io from brainbox.singlecell import peths from oneibl.one import ONE one = ONE() eid = one.search(subject='KS004', date=['2019-09-25'], task_protocol='ephysChoiceWorld')[0] datasets = one.load(eid, download_only=True) ses_path = datasets[0].local_path.parent spikes = alf.io.load_object(ses_path, 'spikes') trials = alf.io.load_object(ses_path, '_ibl_trials') peth, bs = peths(spikes.times, spikes.clusters, [225, 52], trials.goCue_times) plt.plot(peth.tscale, peth.means.T) for m in np.arange(peth.means.shape[0]): plt.fill_between(peth.tscale, peth.means[m, :].T - peth.stds[m, :].T / 20, peth.means[m, :].T + peth.stds[m, :].T / 20, alpha=0.2, edgecolor='#1B2ACC', facecolor='#089FFF', linewidth=4, linestyle='dashdot', antialiased=True)
for i, align_event in enumerate(align_events): if align_event == 'stimOff': if choice == stim_side: offset = 1.0 else: offset = 2.0 align_times = trials['feedback_times'][trial_ids[d]] + offset elif align_event == 'movement': raise NotImplementedError else: align_times = trials[align_event + '_times'][trial_ids[d]] peth_, bs = peths(spikes['times'], spikes['clusters'], cluster_ids, align_times, pre_time=PRE_TIME, post_time=POST_TIME, bin_size=BIN_SIZE, smoothing=SMOOTH_SIZE) peth_means[d][align_event] = peth_.means peth_stds[d][align_event] = peth_.stds binned[d][align_event] = bs # plot peths for each cluster n_trials, n_clusters, _ = binned[d][align_event].shape n_rows = 4 # clusters per page n_plots = int(np.ceil(n_clusters / n_rows)) # n_plots = 3 # for testing for d in ['l', 'r']: for p in range(n_plots):