nstat.nspikeTrain
- class nstat.nspikeTrain(spikeTimes, name='', sampleRate=1000.0, minTime=None, maxTime=None, xlabelval='time', xunits='s', yunits='', dataLabels='', makePlots=0, *, binwidth=None)[source]
Bases:
objectPoint-process (spike train) object (Matlab
nspikeTrain).Stores an array of event times (spikes) and converts them on demand into a binned
SignalObjsignal representation (sigRep). Burst statistics, ISI analysis, and raster plotting are built in.- Parameters:
spikeTimes (array_like) – Spike times in seconds.
name (str, optional) – Neuron / channel label.
sampleRate (float, optional) – Sampling rate in Hz of the bin grid used for the signal representation (
sigRep). Default1000.0Hz (1 ms bins).minTime (float, optional) – Observation window. Defaults to
min/max(spikeTimes).maxTime (float, optional) – Observation window. Defaults to
min/max(spikeTimes).xlabelval (str, optional) – Axis label and unit strings.
xunits (str, optional) – Axis label and unit strings.
yunits (str, optional) – Axis label and unit strings.
dataLabels (str or sequence of str, optional) – Label(s) for the spike-train dimension.
makePlots (int, optional) –
0— compute statistics silently (default);1— compute and plot;< 0— skip statistics entirely (fast construction).binwidth (float, optional) – Keyword-only, MATLAB-style alternative to
sampleRate: bin width in seconds. When given it overridessampleRatewith1 / binwidth.
See also
SignalObjContinuous time-series container returned by
getSigRep.SpikeTrainCollectionMulti-neuron collection.
- __init__(spikeTimes, name='', sampleRate=1000.0, minTime=None, maxTime=None, xlabelval='time', xunits='s', yunits='', dataLabels='', makePlots=0, *, binwidth=None)[source]
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.
- getLStatistic()[source]
Return the L-statistic (number of unique bin counts in
sigRep).- Return type:
- setMER(MERSig)[source]
Attach a micro-electrode recording signal to this spike train.
- Parameters:
MERSig (SignalObj)
- Return type:
None
- computeStatistics(makePlots=0)[source]
Compute ISI, burst, and regularity statistics (Matlab
computeStatistics).- Parameters:
makePlots (int)
- Return type:
None
- setSigRep(binwidth=None, minTime=None, maxTime=None)[source]
Build the binned signal representation and store it in-place.
- setMinTime(minTime)[source]
Set the observation-window start and recompute statistics.
- Parameters:
minTime (float)
- Return type:
None
- setMaxTime(maxTime)[source]
Set the observation-window end and recompute statistics.
- Parameters:
maxTime (float)
- Return type:
None
- resample(sampleRate)[source]
Rebuild the signal representation at sampleRate Hz.
- Parameters:
sampleRate (float)
- Return type:
- getSigRep(binwidth=None, minTime=None, maxTime=None)[source]
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).
- getMaxBinSizeBinary()[source]
Return the largest bin width that keeps the
sigRepbinary.- Return type:
- getFieldVal(fieldName)[source]
Return the value of attribute fieldName (Matlab
getFieldVal).- Parameters:
fieldName (str)
- plotISIHistogram(minTime=None, maxTime=None, numBins=None, handle=None)[source]
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.
- plotExponentialFit(minTime=None, maxTime=None, numBins=None, handle=None)[source]
ISI histogram + exponential prob-plot side by side.
- plotProbPlot(minTime=None, maxTime=None, handle=None)[source]
Exponential probability plot of ISIs (Matlab
plotProbPlot).
- getISIs(minTime=None, maxTime=None)[source]
Return inter-spike intervals within the given time window.
- partitionNST(windowTimes, normalizeTime=None, lbound=None, ubound=None)[source]
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:
- isSigRepBinary()[source]
Return
Trueif every bin in the defaultsigRephas <= 1 spike.- Return type:
- restoreToOriginal()[source]
Reset spike times and time bounds to original values.
- Return type:
None
- nstCopy()[source]
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:
- plot(dHeight=1.0, yOffset=0.5, currentHandle=None, handle=None)[source]
Raster plot: vertical tick per spike (Matlab
plot).