BinnedSpikeTrain (conversion)

This module allows to convert standard data representations (e.g., a spike train stored as Neo SpikeTrain object) into other representations useful to perform calculations on the data. An example is the representation of a spike train as a sequence of 0-1 values (binned spike train).

BinnedSpikeTrain(spiketrains[, bin_size, …]) 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.
BinnedSpikeTrainView(t_start, t_stop, …[, …]) A view of BinnedSpikeTrain.
binarize(spiketrain[, sampling_rate, …]) Return an array indicating if spikes occurred at individual time points.

Examples

>>> import neo
>>> import quantities as pq
>>> from elephant.conversion import BinnedSpikeTrain
>>> spiketrains = [
...   neo.SpikeTrain([0.5, 0.7, 1.2, 3.1, 4.3, 5.5, 6.7], t_stop=9, units='s'),
...   neo.SpikeTrain([0.1, 0.7, 1.2, 2.2, 4.3, 5.5, 8.0], t_stop=9, units='s')
... ]
>>> bst = BinnedSpikeTrain(spiketrains, bin_size=1 * pq.s)
>>> bst
BinnedSpikeTrain(t_start=0.0 s, t_stop=9.0 s, bin_size=1.0 s; shape=(2, 9))
>>> bst.to_array()
array([[2, 1, 0, 1, 1, 1, 1, 0, 0],
       [2, 1, 1, 0, 1, 1, 0, 0, 1]], dtype=int32)

Binarizing the binned matrix.

>>> bst.to_bool_array()
array([[ True,  True, False,  True,  True,  True,  True, False, False],
       [ True,  True,  True, False,  True,  True, False, False,  True]])
>>> bst_binary = bst.binarize()
>>> bst_binary
BinnedSpikeTrainView(t_start=0.0 s, t_stop=9.0 s, bin_size=1.0 s; shape=(2, 9))
>>> bst_binary.to_array()
array([[1, 1, 0, 1, 1, 1, 1, 0, 0],
       [1, 1, 1, 0, 1, 1, 0, 0, 1]], dtype=int32)

Slicing.

>>> bst.time_slice(t_stop=3.5 * pq.s)
BinnedSpikeTrainView(t_start=0.0 s, t_stop=3.0 s, bin_size=1.0 s; shape=(2, 3))
>>> bst[0, 1:-3]
BinnedSpikeTrainView(t_start=1.0 s, t_stop=6.0 s, bin_size=1.0 s; shape=(1, 5))

Generate a realisation of spike trains from the binned version.

>>> bst.to_spike_trains(spikes='center')
[<SpikeTrain(array([0.33333333, 0.66666667, 1.5       , 3.5       , 4.5       ,
       5.5       , 6.5       ]) * s, [0.0 s, 9.0 s])>,
<SpikeTrain(array([0.33333333, 0.66666667, 1.5       , 2.5       , 4.5       ,
       5.5       , 8.5       ]) * s, [0.0 s, 9.0 s])>]

Check the correctness of a spike trains realosation

>>> BinnedSpikeTrain(bst.to_spike_trains(), bin_size=bst.bin_size) == bst
True

Rescale the units of a binned spike train without changing the data.

>>> bst.rescale('ms')
>>> bst
BinnedSpikeTrain(t_start=0.0 ms, t_stop=9000.0 ms, bin_size=1000.0 ms;
shape=(2, 9))