spiketools.measures.trials.compute_trial_frs

spiketools.measures.trials.compute_trial_frs(trial_spikes, bins, time_range=None, smooth=None)[source]

Compute continuous binned firing rates for a set of epoched spike times.

Parameters:
trial_spikeslist of 1d array

Spike times per trial, in seconds.

binsfloat or 1d array

The binning to apply to the spiking data. If float, the length of each bin. If array, precomputed bin definitions.

time_rangelist of [float, float], optional

Time range, in seconds, to create the binned firing rate across. Only used if bins is a float.

smoothfloat, optional

If provided, the kernel to use to smooth the continuous firing rate.

Returns:
bin_times1d array

Timestamps for the computed time bins.

trial_cfrs2d array

Continuous firing rates per trial, with shape [n_trials, n_time_bins].

Examples

Compute the continuous firing rates across time bins for 3 trials:

>>> trial_spikes = [np.array([0.005, 0.150, 0.250]),
...                 np.array([0.126, 0.275, 0.300, 0.350, 0.600]),
...                 np.array([0.250, 0.350, 0.700, 0.900])]
>>> bins = 0.5
>>> time_range = [0.0, 1.0]
>>> bin_times, trial_cfrs = compute_trial_frs(trial_spikes, bins, time_range)
>>> trial_cfrs
array([[6., 0.],
       [8., 2.],
       [4., 4.]])