Spike train utility methods.
Utility methods for reading spike train files as well as to analyze spike train matrices and vectors.
See also
SpikePlot for visualization of spike trains.
AUTHORS:
THOMAS MCTAVISH (2010-03-01): initial version
filtering. Refactored as spiketrain instead of spiketrainutil.
For each spike in the reference train, determine the closest spike time in the other train at least within some window.
Parameters: |
|
---|---|
Returns: | A dict where the keys are indices of the reference train and the time difference of the closest spike in the comparing train is the value. |
The coincidence factor between two spike trains is defined as
where are the number of spikes in the reference train,
is the number of spikes in the comparing train,
is the number of coincident spikes within a time window
,
is the expected number of coincident spikes that would be given by chance
if the spikes in the comparing train were generated by a homogeneous
Poisson process with its rate
. This correlation measure has the range
[-1, 1] where 1 is perfectly correlated, 0 is not correlated, and -1 is
perfectly anti-correlated.
Parameters: |
|
---|---|
Returns: | Coincidence factor |
Parameters: |
|
---|---|
Returns: | A vector of length num_intervals that corresponds to coincidence factor values from a shift of -isi/2 to isi/2. |
Get the fraction of coincident spikes between two trains. Coincidence is defined as a spike co-occurring within some time window.
Parameters: |
|
---|---|
Returns: | A vector of length 1 + 2*timewindow/dt. If normalize is True, return a tuple as (normalized_coincidences, coincidences, expected_coincidences, total_spikes). |
Get the correlogram of coincident spikes between two trains. Coincidence is defined as a spike co-occurring within some time window. The number of coincidences is returned as a vector of len(1 + (2*timewindow)). This means that the middle index is the value at lag zero ms.
Parameters: |
|
---|---|
Returns: | A vector of length 1 + 2*timewindow/dt. |
Convolve a 1D spike train with a kernel and return the resulting vector. This is useful for blurring or otherwise smearing spike times with a particular function, like a gaussian, a linear decay.
Parameters: |
|
---|
See also
Parameters: | origin – can be a string or an integer.: |
---|
Parameters: |
|
---|---|
Returns: | A 1D vector of the filtered spikes. |
Perform a cross-correlation between two spike trains after filtering them to be continuous time domain vectors.
Parameters: |
|
---|---|
Returns: | Tuple (raw_val, norm_factor, expected_val) where raw_val is a scalar if mode='valid' or a vector if mode is a different value. norm_factor the value (scalar) of train_a correlated with itself. expected_vaL the value (scalar) of the mean of each correlated with itself. |
Project the spike times from a 2d spike map to an ordered list in one dimension. This is similar to numpy’s flatten() method, but numpy requires a rectangular matrix. In our case, each row of the spikes array can have a variable number of spike times, and even be empty.
Get the mean frequency of a spike train. Assumes time is in ms.
Get the histogram of one or more spike trains. This is a means of quantizing 1D spikes as well.
Parameters: |
|
---|---|
Returns: | A tuple of the form (discrete, bin_edges). |
Given an ordered list of spike times, return its interspike interval vector.
Parameters: | train – 1D list or numpy array of spike times |
---|---|
Returns: | A 1D vector of length len(spikes)-1 of the time differences in spikes. |
numpy.diff
Get the mean interspike interval of a given spike train.
Parameters: | train – 1D list or numpy array of spike times |
---|---|
Returns: | Mean interspike interval. |
Get the median interspike interval of a given spike train.
Parameters: | train – 1D list or numpy array of spike times |
---|---|
Returns: | Median interspike interval. |
With a given spike train, capture its interspike intervals and permute them into a new spike train.
Parameters: |
|
---|
Get the number of corresponding spikes within some time window between two trains across a number of time-shifted trials.
The number of correlated spikes between two trains that are within some time constant of each other is simply the fraction:
where is the fraction with no delay between the trains.
To determine the correlation at some arbitrary delay,
, we
can re-write the equation as:
where is the time one train is shifted relative to the
reference train.
When the trains are spiking fairly regularly and oscillating around a
particular frequency, it is useful to vary over the interval
where median_isi is the median interspike interval of the reference
train. This permits a measure of the relative phase of one spike train
over the other. As varies over this interval, the individual
values of
can be stored in a vector,
.
Parameters: |
|
---|---|
Returns: | The following values:
|
See also
From a 2D array of spike data, retrieve the minimum and maximum spike times.
Get the spikes from the cell with this idx within a time window.
Parameters: |
|
---|---|
Returns: | If idx is a scalar, then this will return the spikes associated with one cell. If idx is a list of indices, then a dict of lists will be returned. |
For two spike trains, return the mask of those spikes that are within some time window of co-occurrence in the other train.
Parameters: |
|
---|---|
Returns: | Two vectors of len(train_a) and len(train_b) where a zero indicates that a spike does not co-occur in the other train, and 1 indicates that a spike co-occurs in the other train within window time. |
For two spike trains, get their masks where they have spikes that occur within window time of each other and the ratio of correlated vs. total spikes in both trains.
Parameters: |
|
---|---|
Returns: | mask_a, mask_b, ratio – the correlated masks and the ratio of correlated vs. total spikes in both trains. |
Convert data from NetCon.record(tvec, idvec) vectors into a dict where the keys of the dict are the ids and the value is a list of timestamps associated with that id.
Parameters: |
|
---|
Example:
# nclist is a list of NetCons
t_vec = nrn.Vector()
id_vec = nrn.Vector()
for i in range(len(nclist)):
nclist[i].record(t_vec, id_vec, i)
simulate()
Returns: | The data in a dict where the key is the cell id and the list of spike times is the data associated with the cell. |
---|
Convert data from NetCon.record(tvec, idvec) vectors into a dict where the keys of the dict are the ids and the value is a list of timestamps associated with that id.
Parameters: |
|
---|
Example:
# nclist is a list of NetCons
t_vec = nrn.Vector()
id_vec = nrn.Vector()
for i in range(len(nclist)):
nclist[i].record(t_vec, id_vec, i)
simulate()
Returns: | The data as a list of lists with each row being the spike times. |
---|
Permute a 1D array.
Parameters: |
|
---|---|
Returns: | A permuted copy of vec. |
Generator function for a Homogeneous Poisson train.
Parameters: |
|
---|---|
Returns: | A relative spike time from t=start_time, in seconds (not ms). |
EXAMPLE:
# Make a list of spikes at 20 Hz for 3 seconds
spikes = [i for i in poisson_train(20, 3)]
EXAMPLE:
# Use dynamically in a program
# Care needs to be taken with this scenario because the generator will
# generate spikes until the program or spike_gen object is terminated.
spike_gen = poisson_train(20, duration=sys.float_info.max)
spike = spike_gen.next()
# Process the spike, to other programmatic things
spike = spike_gen.next() # Get another spike
# etc.
# Terminate the program.
Print the spike times of cell idx within interval window.
Parameters: |
|
---|
Read the spike data formatted from NEURON where each line is a timestamp of spike followed by a cell (or other spike generator) id that gave the spike.
Parameters: |
|
---|---|
Returns: | The data in a dict where the key is the cell id and the list of spike times is the data associated with the cell. |
Read the spike data formatted from NEURON where each line is a timestamp of spike followed by a cell (or other spike generator) id that gave the spike.
Parameters: |
|
---|---|
Returns: | The data in a vector of tuples of the format (time, gid). |
Read the spike data formatted from NEURON where each line is a timestamp of a spike followed by a cell (or other spike generator) id that gave the spike. Echo a new file in the same format, but only of those spike_ids specified in the spike_ids list. :param file_name: Input file to read. :param out_file_name: Output file to write. :param spike_ids: List of spike ids to write out.
Confirm that the origin for this kernel is valid. Raise an exception if not.
Parameters: | origin – can be a string or an integer.: |
---|
Returns: | a valid integer if a string was used. |
---|