elephant.statistics.time_histogram

elephant.statistics.time_histogram(spiketrains, bin_size, t_start=None, t_stop=None, output='counts', binary=False)[source]

Time Histogram of a list of neo.SpikeTrain objects.

Visualization of this function is covered in Viziphant: viziphant.statistics.plot_time_histogram().

Parameters:
spiketrainslist of neo.SpikeTrain

neo.SpikeTrain`s with a common time axis (same `t_start and t_stop)

bin_sizepq.Quantity

Width of the histogram’s time bins.

t_startpq.Quantity, optional

Start time of the histogram. Only events in spiketrains falling between t_start and t_stop (both included) are considered in the histogram. If None, the maximum t_start of all neo.SpikeTrain`s is used as `t_start. Default: None

t_stoppq.Quantity, optional

Stop time of the histogram. Only events in spiketrains falling between t_start and t_stop (both included) are considered in the histogram. If None, the minimum t_stop of all neo.SpikeTrain`s is used as `t_stop. Default: None

output{‘counts’, ‘mean’, ‘rate’}, optional

Normalization of the histogram. Can be one of: * ‘counts’: spike counts at each bin (as integer numbers). * ‘mean’: mean spike counts per spike train. * ‘rate’: mean spike rate per spike train. Like ‘mean’, but the counts are additionally normalized by the bin width.

Default: ‘counts’

binarybool, optional

If True, indicates whether all neo.SpikeTrain objects should first be binned to a binary representation (using the conversion.BinnedSpikeTrain class) and the calculation of the histogram is based on this representation. Note that the output is not binary, but a histogram of the converted, binary representation. Default: False

Returns:
neo.AnalogSignal

A neo.AnalogSignal object containing the histogram values. neo.AnalogSignal[j] is the histogram computed between t_start + j * bin_size and t_start + (j + 1) * bin_size.

Raises:
ValueError

If output is not ‘counts’, ‘mean’ or ‘rate’.

Warns:
UserWarning

If t_start is None and the objects in spiketrains have different t_start values. If t_stop is None and the objects in spiketrains have different t_stop values.

Examples

>>> import neo
>>> import quantities as pq
>>> from elephant import statistics
>>> spiketrains = [
...     neo.SpikeTrain([0.3, 4.5, 6.7, 9.3], t_stop=10, units='s'),
...     neo.SpikeTrain([0.7, 4.3, 8.2], t_stop=10, units='s')
... ]
>>> hist = statistics.time_histogram(spiketrains,
...                                  bin_size=1 * pq.s)
>>> hist
<AnalogSignal(array([[2],
       [0],
       [0],
       [0],
       [2],
       [0],
       [1],
       [0],
       [1],
       [1]]) * dimensionless, [0.0 s, 10.0 s], sampling rate: 1.0 1/s)>
>>> hist.magnitude.flatten()
array([2, 0, 0, 0, 2, 0, 1, 0, 1, 1])