elephant.spike_train_surrogates.dither_spike_train(spiketrain, shift, n_surrogates=1, decimals=None, edges=True)[source]

Generates surrogates of a spike train by spike train shifting.

The surrogates are obtained by shifting the whole spike train by a random amount of time (independent for each surrogate). Thus, ISIs and temporal correlations within the spike train are kept. For small shifts, the firing rate profile is also kept with reasonable accuracy.

The surrogates retain the spiketrain.t_start and spiketrain.t_stop. Spikes moved beyond this range are lost or moved to the range’s ends, depending on the parameter edges.


The spike train from which to generate the surrogates.


Amount of shift. spiketrain is shifted by a random amount uniformly drawn from the range (-shift, +shift).

n_surrogatesint, optional

Number of surrogates to be generated. Default: 1

decimalsint or None, optional

Number of decimal points for every spike time in the surrogates. If None, machine precision is used. Default: None

edgesbool, optional

For surrogate spikes falling outside the range [spiketrain.t_start, spiketrain.t_stop), whether to drop them out (for edges = True) or set them to the range’s closest end (for edges = False). Default: True

list of neo.SpikeTrain

Each surrogate spike train obtained independently from spiketrain by randomly dithering the whole spike train. The time range of the surrogate spike trains is the same as in spiketrain.


>>> import quantities as pq
>>> import neo
>>> st = neo.SpikeTrain([100, 250, 600, 800] * pq.ms, t_stop=1 * pq.s)
>>> print(dither_spike_train(st, shift = 20*pq.ms))  
[<SpikeTrain(array([  96.53801903,  248.57047376,  601.48865767,
 815.67209811]) * ms, [0.0 ms, 1000.0 ms])>]
>>> print(dither_spike_train(st, shift = 20*pq.ms, n_surrogates=2))
[<SpikeTrain(array([  92.89084054,  242.89084054,  592.89084054,
    792.89084054]) * ms, [0.0 ms, 1000.0 ms])>,
 <SpikeTrain(array([  84.61079043,  234.61079043,  584.61079043,
    784.61079043]) * ms, [0.0 ms, 1000.0 ms])>]
>>> print(dither_spike_train(st, shift = 20 * pq.ms,
[<SpikeTrain(array([  82.,  232.,  582.,  782.]) * ms,
    [0.0 ms, 1000.0 ms])>]