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: nspikeTrain

Canonical 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 None raises ValueError.

  • name (str, optional) – Neuron / channel label. Used as the y-axis label in plots and the default dataLabels entry. Default "".

  • sampleRate (float, optional) – Sampling rate of the bin grid in Hz used when the spike train is converted to a binned SignalObj representation (sigRep). Default 1000.0 Hz (1 ms bins), matching the MATLAB toolbox.

  • minTime (float or None, optional) – Observation window in seconds. None (default) selects min(spikeTimes) and max(spikeTimes) respectively, or 0.0 when spikeTimes is empty.

  • maxTime (float or None, optional) – Observation window in seconds. None (default) selects min(spikeTimes) and max(spikeTimes) respectively, or 0.0 when spikeTimes is 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 as None).

  • binwidth (float | None)

Raises:

ValueError – If spikeTimes is None.

Return type:

None

See also

SignalObj

Binned signal representation returned by getSigRep().

SpikeTrainCollection

Multi-neuron collection container.

inter_spike_intervals()[source]
Return type:

ndarray

to_counts(bin_edges)[source]
Parameters:

bin_edges (Sequence[float])

Return type:

ndarray

clearSigRep()

Invalidate the cached signal representation.

Return type:

None

computeRate()

Return firing rate sigRep * sampleRate in spikes/sec.

Return type:

SignalObj

computeStatistics(makePlots=0)

Compute ISI, burst, and regularity statistics (Matlab computeStatistics).

Parameters:

makePlots (int)

Return type:

None

property duration: float

Observation window duration maxTime - minTime in seconds.

property firing_rate_hz: float

Average firing rate (spikes / duration) in Hz.

static fromStructure(structure)

Reconstruct an nspikeTrain from a dict.

Parameters:

structure (dict[str, Any])

Return type:

nspikeTrain

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.

Parameters:
Return type:

ndarray

getLStatistic()

Return the L-statistic (number of unique bin counts in sigRep).

Return type:

float

getMaxBinSizeBinary()

Return the largest bin width that keeps the sigRep binary.

Return type:

float

getMinISI(minTime=None, maxTime=None)

Return the minimum ISI (refractory period estimate).

Parameters:
Return type:

float

getSigRep(binwidth=None, minTime=None, maxTime=None)

Return the binned signal representation, using cache when possible.

The result is a SignalObj of spike counts on a regular grid with bin width binwidth (default 1/sampleRate).

Parameters:
Return type:

SignalObj

getSpikeTimes(minTime=None, maxTime=None)

Return spike times within [minTime, maxTime].

Parameters:
Return type:

ndarray

isSigRepBinary()

Return True if every bin in the default sigRep has <= 1 spike.

Return type:

bool

property n_spikes: int

Number of spikes in the train.

nstCopy()

Return a deep copy (Matlab nstCopy).

Matlab’s nstCopy builds the copy’s sigRep and calls computeStatistics(0) so the copy has valid burst parameters.

Notes

The constructor would otherwise overwrite the copy’s originalSpikeTimes / originalMinTime / originalMaxTime with the current (possibly windowed) state of self. We explicitly carry the source’s “original” fields over after construction so that copy.restoreToOriginal() actually restores to the true original state.

Return type:

nspikeTrain

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:

nstColl

plot(dHeight=1.0, yOffset=0.5, currentHandle=None, handle=None)

Raster plot: vertical tick per spike (Matlab plot).

Parameters:
  • dHeight (float) – Tick height (default 1.0).

  • yOffset (float) – Vertical centre of ticks (default 0.5).

  • currentHandle (matplotlib Axes, optional) – Axes to draw into.

  • handle (matplotlib Axes, optional) – Axes to draw into.

plotExponentialFit(minTime=None, maxTime=None, numBins=None, handle=None)

ISI histogram + exponential prob-plot side by side.

Parameters:
  • minTime (float | None)

  • maxTime (float | None)

  • numBins (int | None)

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).

Parameters:
resample(sampleRate)

Rebuild the signal representation at sampleRate Hz.

Parameters:

sampleRate (float)

Return type:

nspikeTrain

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

setName(name)

Set the neuron / channel name.

Parameters:

name (str)

Return type:

None

setSigRep(binwidth=None, minTime=None, maxTime=None)

Build the binned signal representation and store it in-place.

Parameters:
Return type:

SignalObj

property times: ndarray

Alias for spikeTimes.

toStructure()

Serialize to a plain dict (Matlab toStructure).

Return type:

dict[str, Any]

to_binned_counts(bin_edges)

Histogram spike times into bin_edges and return count vector.

Parameters:

bin_edges (Sequence[float])

Return type:

ndarray