gridcells.analysis.spikes
 spike train analysis¶
Classes¶
PopulationSpikes (n, senders, times) 
Abstraction of a population of spikes. 
TorusPopulationSpikes (senders, times, sheet_size) 
Spikes of a population of neurons on a twisted torus. 
TwistedTorusSpikes (senders, times, sheet_size) 
Spikes arranged on twisted torus. 

class
gridcells.analysis.spikes.
PopulationSpikes
(n, senders, times)[source]¶ Bases:
collections.abc.Sequence
Abstraction of a population of spikes.
Parameters: n : int
Number of neurons in the population
senders : 1D array
Neuron numbers corresponding to the spikes
times : 1D array
Spike times. The shape of this array must be the same as for senders.

PopulationSpikes.
avg_firing_rate
(tstart, tend)[source]¶ Compute and average firing rate for all the neurons between ‘tstart’ and ‘tend’. Return an array of firing rates, one item for each neuron in the population.
Parameters: tstart : float (ms)
Start time.
tend : float (ms)
End time.
Returns: output : numpy array
Firing rate in Hz for each neuron in the population.

PopulationSpikes.
isi
(n=None, reduce_fun=None)[source]¶ Return interspike interval of one or more neurons.
Parameters: n : None, int, or sequence
Neuron numbers. If
n
is None, then compute ISI stats for all neurons in the population. Ifn
is an int, compute ISIs for just neuron indexed byn
. Otherwisen
is expected to be a sequence of neuron indices.reduce_fun : callable or None
A reduction function (callable object) that performs an operation on all the ISIs of the population. If
None
, nothing is done. The callable has to take one input parameter, which is the sequence of ISIs. This allows to cascade data processing without the need for duplicating spike timing data.Returns: output: list
A list of outputs (depending on parameters) for each neuron, even if
n
is an int.

PopulationSpikes.
isi_cv
(n=None, win_len=None)[source]¶ Coefficients of variation of interspike intervals of one or more neurons in the population. For the description of parameters and outputs and their semantics see also
ISI()
.Parameters: win_len : float, list of floats, or
None
Specify the maximal ISI value, i.e. use windowed coefficient of variation. If
None
, use the whole range.

PopulationSpikes.
isi_neuron
(n)[source]¶ Compute all interspike intervals of one neuron with ID
n
. If the number of spikes is less than 2, returns an empty array.Todo
Works on sorted spike trains only!
Note
If you get negative interspike intervals, you will need to sort your spike times (per each neuron).

PopulationSpikes.
n
¶ Number of neurons in the population

PopulationSpikes.
raster_data
(neuron_list=None)[source]¶ Extract the senders and corresponding spike times for a raster plot.
Todo
implement neuron_list
Parameters: neuron_list : list, optional
Extract only neurons given in this list
Returns: output : a tuple
A pair containing (senders, times).

PopulationSpikes.
sliding_firing_rate
(tstart, tend, dt, win_len)[source]¶ Compute a sliding firing rate over the population of spikes, by taking a rectangular window of specified length.
Parameters: tstart : float
Start time of the firing rate analysis.
tend : float
End time of the analysis
dt : float
Firing rate window time step
win_len : float
Lengths of the windowing function (rectangle)
Returns: output : a tuple
A pair (F, t), specifying the vector of firing rates and corresponding times. F is a 2D array of the shape (n, Ntimes), in which n is the number of neurons and Ntimes is the number of time steps. ‘t’ is a vector of times corresponding to the time windows taken.

PopulationSpikes.
spike_train_difference
(idx1, idx2=None, full=True, reduce_fun=None)[source]¶ Compute time differences between pairs of spikes of two neurons or a list of neurons.
Parameters: idx1 : int, or a sequence of ints
Index of the first neuron or a list of neurons for which to compute the correlation histogram.
idx2 : int, or a sequence of ints, or None
Index of the second neuron or a list of indexes for the second set of spike trains.
full : bool, optional
Not fully implemented yet. Must be set to True.
reduce_fun : callable, optional
Any callable object that computes a function over an array of each spike train difference. The function must take one input argument, which will be the array of spike time differences for a pair of neurons. The output of this function will be stored instead of the default output.
Returns: output : A 2D or 1D array
Spike train autocorrelation histograms for all the pairs of neurons.
The computation takes the following steps:
 If
idx1
oridx2
are integers, they will be converted to a list of size 1.  If
idx2
is None, then the result will be a list of lists of pairs of crosscorrelations between the neurons. Even if there is only one neuron. Iffull == True
, the output will be an upper triangular matrix of all the pairs, i.e. it will exclude the duplicated. Otherwise there will be cross correlation histograms between all the pairs.  if
idx2
is not None, thenidx1
andidx2
must be arrays of the same length, specifying the pairs to compute autocorrelation for
 If

PopulationSpikes.
spike_train_xcorr
(idx1, idx2, lag_range, bins=50, **kw)[source]¶ Compute the spike train crosscorrelation function for all pairs of spike trains in the population.
For explanation of how
idx1
andidx2
are treated, seespike_train_difference()
.Parameters: idx1 : int, or a sequence of ints
Index of the first neuron or a list of neurons for which to compute the correlation histogram.
idx2 : int, or a sequence of ints, or None
Index of the second neuron or a list of indexes for the second set of spike trains.
lag_range : (lag_start, lag_end)
Limits of the crosscorrelation function. The bins will always be centered on the values.
bins : int, optional
Number of bins
kw : dict
Keyword arguments passed on to the numpy.histogram function
Returns: output : a 2D or 1D list

PopulationSpikes.
windowed
(tlimits)[source]¶ Return population spikes restricted to tlimits.
Parameters: tlimits : a pair
A tuple (tstart, tend). The spikes in the population must satisfy tstart >= t <= tend.
Returns: output : PopulationSpikes instance
A copy of self with only a subset of spikes, limited by the time window.


class
gridcells.analysis.spikes.
TorusPopulationSpikes
(senders, times, sheet_size)[source]¶ Bases:
gridcells.analysis.spikes.PopulationSpikes
Spikes of a population of neurons on a twisted torus.

dimensions
¶ Dimensions of the torus (X, Y)

nx
¶ Horizontal size of the torus

ny
¶ Vertical size of the torus

population_vector
(tstart, tend, dt, win_len)[source]¶ Compute the population vector on a torus, from the spikes present. Note that this method will have a limited functionality on a twisted torus, but can be used if the population activity translates in the X dimension only.
Parameters: tstart : float
Start time of analysis
tend : float
End time of analysis
dt : float
Time step of the (rectangular) windowing function
win_len : float
Length of the windowing function
Returns: output : tuple
A pair (r, t) in which r is a 2D vector of shape (int((tendtstart)/dt)+1), 2), corresponding to the population vector for each time step of the windowing function, and t is a vector of times, of length the first dimension of r.

sliding_firing_rate
(tstart, tend, dt, win_len)[source]¶ Compute a sliding firing rate over the population of spikes, by taking a rectangular window of specified length. However, unlike the ancestor method (PopulationSpikes.sliding_firing_rate), return a 3D array, a succession of 2D population firing rates in time.
Parameters: tstart : float
Start time of the firing rate analysis.
tend : float
End time of the analysis
dt : float
Firing rate window time step
win_len : float
Lengths of the windowing function (rectangle)
Returns: output : a tuple
A pair (F, t), specifying the vector of firing rates and corresponding times. F is a 3D array of the shape (nx, ny, Ntimes), in which nx/ny are the number of neurons in X and Y dimensions, respectively, and Ntimes is the number of time steps. ‘t’ is a vector of times corresponding to the time windows taken.


class
gridcells.analysis.spikes.
TwistedTorusSpikes
(senders, times, sheet_size)[source]¶ Bases:
gridcells.analysis.spikes.TorusPopulationSpikes
Spikes arranged on twisted torus. The torus is twisted in the X direction.