elephant.conversion.BinnedSpikeTrain¶
- class elephant.conversion.BinnedSpikeTrain(spiketrains, bin_size=None, n_bins=None, t_start=None, t_stop=None, tolerance=1e-08, sparse_format='csr')[source]¶
Class which calculates a binned spike train and provides methods to transform the binned spike train to a boolean matrix or a matrix with counted time points.
A binned spike train represents the occurrence of spikes in a certain time frame. I.e., a time series like [0.5, 0.7, 1.2, 3.1, 4.3, 5.5, 6.7] is represented as [0, 0, 1, 3, 4, 5, 6]. The outcome is dependent on given parameter such as size of bins, number of bins, start and stop points.
A boolean matrix represents the binned spike train in a binary (True/False) manner. Its rows represent the number of spike trains and the columns represent the binned index position of a spike in a spike train. The calculated matrix entry containing True indicates a spike.
A matrix with counted time points is calculated the same way, but its entries contain the number of spikes that occurred in the given bin of the given spike train.
Note that with most common parameter combinations spike times can end up on bin edges. This makes the binning susceptible to rounding errors which is accounted for by moving spikes which are within tolerance of the next bin edge into the following bin. This can be adjusted using the tolerance parameter and turned off by setting tolerance=None.
- Parameters:
- spiketrainsneo.SpikeTrain or list of neo.SpikeTrain or np.ndarray
Spike train(s) to be binned.
- bin_sizepq.Quantity, optional
Width of a time bin. Default: None
- n_binsint, optional
Number of bins of the binned spike train. Default: None
- t_startpq.Quantity, optional
Time of the left edge of the first bin (left extreme; included). Default: None
- t_stoppq.Quantity, optional
Time of the right edge of the last bin (right extreme; excluded). Default: None
- tolerancefloat, optional
Tolerance for rounding errors in the binning process and in the input data Default: 1e-8
- sparse_format{‘csr’, ‘csc’}, optional
The sparse matrix format. By default, CSR format is used to perform slicing and computations efficiently. Default: ‘csr’
- Raises:
- AttributeError
If less than 3 optional parameters are None.
- TypeError
If spiketrains is an np.ndarray with dimensionality different than NxM or if type of n_bins is not an int or n_bins < 0.
- ValueError
When number of bins calculated from t_start, t_stop and bin_size differs from provided n_bins or if t_stop of any spike train is smaller than any t_start or if any spike train does not cover the full [t_start, t_stop`] range.
- Warns:
- UserWarning
If some spikes fall outside of [t_start, t_stop] range
Notes
There are four minimal configurations of the optional parameters which have to be provided, otherwise a ValueError will be raised:
t_start, n_bins, bin_size
t_start, n_bins, t_stop
t_start, bin_size, t_stop
t_stop, n_bins, bin_size
If spiketrains is a neo.SpikeTrain or a list thereof, it is enough to explicitly provide only one parameter: n_bins or bin_size. The t_start and t_stop will be calculated from given spiketrains (max t_start and min t_stop of neo.SpikeTrain`s). Missing parameter will be calculated automatically. All parameters will be checked for consistency. A corresponding error will be raised, if one of the four parameters does not match the consistency requirements.
- __init__(spiketrains, bin_size=None, n_bins=None, t_start=None, t_stop=None, tolerance=1e-08, sparse_format='csr')[source]¶
Methods
__init__
(spiketrains[, bin_size, n_bins, ...])binarize
([copy])Clip the internal array (no.
copy
()Copies the binned sparse matrix and returns a view.
get_num_of_spikes
([axis])Compute the number of binned spikes.
rescale
(units)Inplace rescaling to the new quantity units.
time_slice
([t_start, t_stop, copy])Returns a view or a copied view of currently binned spike trains with
(t_start, t_stop)
time slice.to_array
([dtype])Returns a dense matrix, calculated from the sparse matrix, with counted time points of spikes.
to_bool_array
()Returns a matrix, in which the rows correspond to the spike trains and the columns correspond to the bins in the BinnedSpikeTrain.
to_sparse_bool_array
()Getter for boolean version of the sparse matrix, calculated from sparse matrix with counted time points.
to_spike_trains
([spikes, as_array, ...])Generate spike trains from the binned spike train object.
Attributes
bin_centers
Returns each center time point of all bins between
t_start
andt_stop
points.bin_edges
Returns all time edges as a quantity array with
n_bins
bins.bin_size
Bin size quantity.
is_binary
Returns True if the sparse matrix contains binary values only.
shape
The shape of the sparse matrix.
sparsity
The sparsity of the sparse matrix computed as the no.
spike_indices
A list of lists for each spike train (i.e., rows of the binned matrix), that in turn contains for each spike the index into the binned matrix where this spike enters.
t_start
t_start quantity; spike times below this value have been ignored.
t_stop
t_stop quantity; spike times above this value have been ignored.