nstat.SpikeTrain
- class nstat.SpikeTrain(spikeTimes, name='', sampleRate=1000.0, minTime=None, maxTime=None, xlabelval='time', xunits='s', yunits='', dataLabels='', makePlots=0, *, binwidth=None)[source]
Bases:
nspikeTrainCanonical spike train type for point-process analyses.
- Parameters:
- __init__(spikeTimes, name='', sampleRate=1000.0, minTime=None, maxTime=None, xlabelval='time', xunits='s', yunits='', dataLabels='', makePlots=0, *, binwidth=None)
Construct a point-process spike train (Matlab
nspikeTrain).- Parameters:
spikeTimes (array_like) – Vector of spike times in seconds. Stored sorted ascending after construction. Required — passing
NoneraisesValueError.name (str, optional) – Neuron / channel label. Used as the y-axis label in plots and the default
dataLabelsentry. Default"".sampleRate (float, optional) – Sampling rate of the bin grid in Hz used when the spike train is converted to a binned
SignalObjrepresentation (sigRep). Default1000.0Hz (1 ms bins), matching the MATLAB toolbox.minTime (float or None, optional) – Observation window in seconds.
None(default) selectsmin(spikeTimes)andmax(spikeTimes)respectively, or0.0whenspikeTimesis empty.maxTime (float or None, optional) – Observation window in seconds.
None(default) selectsmin(spikeTimes)andmax(spikeTimes)respectively, or0.0whenspikeTimesis empty.xlabelval (str, optional) – X-axis label string (default
"time").xunits (str, optional) – X-axis unit string (default
"s"for seconds).yunits (str, optional) – Y-axis unit string (default
"").dataLabels (str or sequence of str or None, optional) – Per-dimension label(s). A single string is broadcast. Default
"".makePlots (int, optional) –
Behaviour of the implicit
computeStatistics()call:0(default) — compute statistics silently.1— compute statistics and plot diagnostics.< 0— skip statistics entirely (fast construction; all burst-statistics attributes are left asNone).
binwidth (float | None)
- Raises:
ValueError – If spikeTimes is
None.- Return type:
None
See also
SignalObjBinned signal representation returned by
getSigRep().SpikeTrainCollectionMulti-neuron collection container.
- clearSigRep()
Invalidate the cached signal representation.
- Return type:
None
- computeStatistics(makePlots=0)
Compute ISI, burst, and regularity statistics (Matlab
computeStatistics).- Parameters:
makePlots (int)
- Return type:
None
- static fromStructure(structure)
Reconstruct an
nspikeTrainfrom a dict.- Parameters:
- Return type:
- getFieldVal(fieldName)
Return the value of attribute fieldName (Matlab
getFieldVal).- Parameters:
fieldName (str)
- getISIs(minTime=None, maxTime=None)
Return inter-spike intervals within the given time window.
- getMaxBinSizeBinary()
Return the largest bin width that keeps the
sigRepbinary.- Return type:
- getMinISI(minTime=None, maxTime=None)
Return the minimum ISI (refractory period estimate).
- getSigRep(binwidth=None, minTime=None, maxTime=None)
Return the binned signal representation, using cache when possible.
The result is a
SignalObjof spike counts on a regular grid with bin width binwidth (default1/sampleRate).
- getSpikeTimes(minTime=None, maxTime=None)
Return spike times within
[minTime, maxTime].
- nstCopy()
Return a deep copy (Matlab
nstCopy).Matlab’s
nstCopybuilds the copy’s sigRep and callscomputeStatistics(0)so the copy has valid burst parameters.Notes
The constructor would otherwise overwrite the copy’s
originalSpikeTimes/originalMinTime/originalMaxTimewith the current (possibly windowed) state ofself. We explicitly carry the source’s “original” fields over after construction so thatcopy.restoreToOriginal()actually restores to the true original state.- Return type:
- partitionNST(windowTimes, normalizeTime=None, lbound=None, ubound=None)
Partition into per-trial spike trains (Matlab
partitionNST).- Parameters:
windowTimes (sequence of float) – Edge times defining trial boundaries (N edges -> N-1 trials).
normalizeTime (bool, optional) – If
True, rescale each trial’s spikes to [0, 1].lbound (float, optional) – Accept only windows whose duration falls in
[lbound, ubound].ubound (float, optional) – Accept only windows whose duration falls in
[lbound, ubound].
- Return type:
- plot(dHeight=1.0, yOffset=0.5, currentHandle=None, handle=None)
Raster plot: vertical tick per spike (Matlab
plot).
- plotExponentialFit(minTime=None, maxTime=None, numBins=None, handle=None)
ISI histogram + exponential prob-plot side by side.
- plotISIHistogram(minTime=None, maxTime=None, numBins=None, handle=None)
Plot ISI histogram (Matlab
plotISIHistogram).- Parameters:
minTime (float, optional) – Time window for ISIs. Defaults to the spike train bounds.
maxTime (float, optional) – Time window for ISIs. Defaults to the spike train bounds.
numBins (int, optional) – Number of histogram bins. When None the bin width defaults to 1 ms (Matlab default behaviour).
handle (matplotlib Axes, optional) – Axes to plot into.
- plotISISpectrumFunction()
Plot ISI vs. time (Matlab
plotISISpectrumFunction).
- plotJointISIHistogram()
Joint ISI scatter plot: ISI(t) vs ISI(t+1) on log-log axes.
- plotProbPlot(minTime=None, maxTime=None, handle=None)
Exponential probability plot of ISIs (Matlab
plotProbPlot).
- resample(sampleRate)
Rebuild the signal representation at sampleRate Hz.
- Parameters:
sampleRate (float)
- Return type:
- restoreToOriginal()
Reset spike times and time bounds to original values.
- Return type:
None
- setMER(MERSig)
Attach a micro-electrode recording signal to this spike train.
- Parameters:
MERSig (SignalObj)
- Return type:
None
- setMaxTime(maxTime)
Set the observation-window end and recompute statistics.
- Parameters:
maxTime (float)
- Return type:
None
- setMinTime(minTime)
Set the observation-window start and recompute statistics.
- Parameters:
minTime (float)
- Return type:
None
- setSigRep(binwidth=None, minTime=None, maxTime=None)
Build the binned signal representation and store it in-place.