elephant.spike_train_surrogates.dither_spikes(spiketrain, dither, n_surrogates=1, decimals=None, edges=True, refractory_period=None)[source]

Generates surrogates of a spike train by spike dithering.

The surrogates are obtained by uniformly dithering times around the original position. The dithering is performed independently for each surrogate.

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 dithering. A spike at time t is placed randomly within (t-dither, t+dither).

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 at a millisecond level. 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

refractory_periodpq.Quantity or None, optional

The dither range of each spike is adjusted such that the spike can not fall into the refractory_period of the previous or next spike. To account this, the refractory period is estimated as the smallest ISI of the spike train. The given argument refractory_period here is thus an initial estimation. Note, that with this option a spike cannot “jump” over the previous or next spike as it is normally possible. If set to None, no refractoriness is in dithering. Default: None

list of neo.SpikeTrain

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


>>> import quantities as pq
>>> import neo
>>> st = neo.SpikeTrain([100, 250, 600, 800] * pq.ms, t_stop=1 * pq.s)
>>> print(dither_spikes(st, dither = 20 * pq.ms))  
[<SpikeTrain(array([  96.53801903,  248.57047376,  601.48865767,
 815.67209811]) * ms, [0.0 ms, 1000.0 ms])>]
>>> print(dither_spikes(st, dither = 20 * pq.ms, n_surrogates=2))
[<SpikeTrain(array([ 104.24942044,  246.0317873 ,  584.55938657,
    818.84446913]) * ms, [0.0 ms, 1000.0 ms])>,
 <SpikeTrain(array([ 111.36693058,  235.15750163,  618.87388515,
    786.1807108 ]) * ms, [0.0 ms, 1000.0 ms])>]
>>> print(dither_spikes(st, dither = 20 * pq.ms,
[<SpikeTrain(array([  81.,  242.,  595.,  799.]) * ms,
    [0.0 ms, 1000.0 ms])>]