brainbox.singlecell
Computes properties of single-cells, e.g. the autocorrelation and firing rate.
Functions
Compute the auto-correlogram of a neuron. |
|
Event aligned raster for single cluster |
|
Event aligned raster for mutliple clusters |
|
Calcluate peri-event time histograms; return means and standard deviations for each time point across specified clusters |
|
Computes the instantaneous firing rate of a unit over time by computing a histogram of spike counts over a specified window of time, and summing this histogram over a sliding window of specified time over a specified period of total time. |
- acorr(spike_times, bin_size=None, window_size=None)[source]
Compute the auto-correlogram of a neuron.
:param : :type : param spike_times: Spike times in seconds. :param : :type : type spike_times: array-like :param : :type : param bin_size: Size of the bin, in seconds. :param : :type : type bin_size: float :param : :type : param window_size: Size of the window, in seconds. :param : :type : type window_size: float :param Returns an (winsize_samples: :param ) array with the auto-correlogram.:
- bin_spikes(times, align_times, pre_time=0.4, post_time=1, bin_size=0.01, weights=None)[source]
Event aligned raster for single cluster
- Parameters:
times
align_times
pre_time
post_time
bin_size
weights
- Returns:
- bin_spikes2D(spike_times, spike_clusters, cluster_ids, align_times, pre_time=0.4, post_time=1, bin_size=0.01, weights=None)[source]
Event aligned raster for mutliple clusters
- Parameters:
spike_times
spike_clusters
cluster_ids
align_times
pre_time
post_time
bin_size
weights
- Returns:
- calculate_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)[source]
Calcluate peri-event time histograms; return means and standard deviations for each time point across specified clusters
- Parameters:
spike_times (array-like) – spike times (in seconds)
spike_clusters (array-like) – cluster ids corresponding to each event in spikes
cluster_ids (array-like) – subset of cluster ids for calculating peths
align_times (array-like) – times (in seconds) to align peths to
pre_time (float) – time (in seconds) to precede align times in peth
post_time (float) – time (in seconds) to follow align times in peth
bin_size (float) – width of time windows (in seconds) to bin spikes
smoothing (float) – standard deviation (in seconds) of Gaussian kernel for smoothing peths; use smoothing=0 to skip smoothing
return_fr (bool) – True to return (estimated) firing rate, False to return spike counts
- Returns:
peths, binned_spikes
- Return type:
peths: Bunch({‘mean’: peth_means, ‘std’: peth_stds, ‘tscale’: ts, ‘cscale’: ids})
- Return type:
binned_spikes: np.array (n_align_times, n_clusters, n_bins)
- firing_rate(ts, hist_win=0.01, fr_win=0.5)[source]
Computes the instantaneous firing rate of a unit over time by computing a histogram of spike counts over a specified window of time, and summing this histogram over a sliding window of specified time over a specified period of total time.
- Parameters:
ts (ndarray) – The spike timestamps from which to compute the firing rate..
hist_win (float) – The time window (in s) to use for computing spike counts.
fr_win (float) – The time window (in s) to use as a moving slider to compute the instantaneous firing rate.
- Returns:
fr – The instantaneous firing rate over time (in hz).
- Return type:
ndarray
See also
metrics.firing_rate_cv
,metrics.firing_rate_fano_factor
,plot.firing_rate
Examples
- Compute the firing rate for unit 1 from the time of its first to last spike.
>>> import brainbox as bb >>> import alf.io as aio >>> import ibllib.ephys.spikes as e_spks (*Note, if there is no 'alf' directory, make 'alf' directory from 'ks2' output directory): >>> e_spks.ks2_to_alf(path_to_ks_out, path_to_alf_out) # Load a spikes bunch and get the timestamps for unit 1, and calculate the instantaneous # firing rate. >>> spks_b = aio.load_object(path_to_alf_out, 'spikes') >>> unit_idxs = np.where(spks_b['clusters'] == 1)[0] >>> ts = spks_b['times'][unit_idxs] >>> fr = bb.singlecell.firing_rate(ts)