elephant.conversion.binarize¶

elephant.conversion.
binarize
(spiketrain, sampling_rate=None, t_start=None, t_stop=None, return_times=False)[source]¶ Return an array indicating if spikes occurred at individual time points.
The array contains boolean values identifying whether at least one spike occurred in the corresponding time bin. Time bins start at t_start and end at t_stop, spaced in 1/sampling_rate intervals.
Accepts either a neo.SpikeTrain, a pq.Quantity array, or a plain np.ndarray. Returns a boolean array with each element indicating the presence or absence of a spike in that time bin.
Optionally also returns an array of time points corresponding to the elements of the boolean array. The units of this array will be the same as the units of the neo.SpikeTrain, if any.
Parameters:  spiketrainneo.SpikeTrain or pq.Quantity or np.ndarray
The spike times. Does not have to be sorted.
 sampling_ratefloat or pq.Quantity, optional
The sampling rate to use for the time points. If not specified, retrieved from the sampling_rate attribute of spiketrain. Default: None
 t_startfloat or pq.Quantity, optional
The start time to use for the time points. If not specified, retrieved from the t_start attribute of spiketrain. If this is not present, defaults to 0. Any element of spiketrain lower than t_start is ignored. Default: None
 t_stopfloat or pq.Quantity, optional
The stop time to use for the time points. If not specified, retrieved from the t_stop attribute of spiketrain. If this is not present, defaults to the maximum value of spiketrain. Any element of spiketrain higher than t_stop is ignored. Default: None
 return_timesbool, optional
If True, also return the corresponding time points. Default: False
Returns:  valuesnp.ndarray of bool
A True value at a particular index indicates the presence of one or more spikes at the corresponding time point.
 timesnp.ndarray or pq.Quantity, optional
The time points. This will have the same units as spiketrain. If spiketrain has no units, this will be an np.ndarray array.
Raises:  TypeError
If spiketrain is an np.ndarray and t_start, t_stop, or sampling_rate is a pq.Quantity.
 ValueError
If sampling_rate is not explicitly defined and not present as an attribute of spiketrain.
Notes
Spike times are placed in the bin of the closest time point, going to the higher bin if exactly between two bins.
So in the case where the bins are 5.5 and 6.5, with the spike time being 6.0, the spike will be placed in the 6.5 bin.
The upper edge of the last bin, equal to t_stop, is inclusive. That is, a spike time exactly equal to t_stop will be included.
If spiketrain is a pq.Quantity or neo.SpikeTrain and t_start, t_stop or sampling_rate is not, then the arguments that are not pq.Quantity will be assumed to have the same units as spiketrain.