nstat.extras.interop.pynapple

pynapple ↔ nstat converters (Tier-B interop).

pynapple (https://github.com/pynapple-org/pynapple) is the modern systems-neuroscience time-series library — its Ts / Tsd / TsdFrame containers plus IntervalSet epoch math are exactly the kind of trial-window operations users repeatedly hand-roll on top of nstat’s Trial. This module exposes the conversion so users can keep epoch math in pynapple and do MATLAB-style GLM / point-process analysis in nstat.

Install:

pip install nstat-toolbox[pynapple]

Functions

from_pynapple_ts(ts, *[, name, sample_rate, ...])

Convert a pynapple.Ts to an nstat.nspikeTrain.

to_pynapple_ts(nst)

Convert an nstat.nspikeTrain to a pynapple.Ts.

to_pynapple_tsgroup(spike_collection)

Convert a nstat.SpikeTrainCollection to a pynapple.TsGroup.

to_pynapple_with_support(nst)

Convert an nstat.nspikeTrain plus its recording window.

nstat.extras.interop.pynapple.to_pynapple_ts(nst)[source]

Convert an nstat.nspikeTrain to a pynapple.Ts.

The resulting Ts carries timestamps in seconds (pynapple’s canonical unit, matching nstat’s convention). The pynapple Ts has no notion of minTime / maxTime outside its own timestamps, so use to_pynapple_with_support() if you need to preserve nstat’s recording-window bounds.

Parameters:

nst (nspikeTrain) – nstat spike train.

Return type:

pynapple.Ts

nstat.extras.interop.pynapple.to_pynapple_with_support(nst)[source]

Convert an nstat.nspikeTrain plus its recording window.

Returns a (Ts, IntervalSet) pair so the downstream pynapple workflow knows the full recording window — important for tuning curves, perievent histograms, and rate calculations that need to know “how much time was observed” (not just when spikes happened).

Returns:

  • ts (pynapple.Ts)

  • support (pynapple.IntervalSet) – Single-interval set [nst.minTime, nst.maxTime].

Parameters:

nst (nspikeTrain)

Return type:

tuple[nap.Ts, nap.IntervalSet]

nstat.extras.interop.pynapple.from_pynapple_ts(ts, *, name='', sample_rate=1000.0, support=None)[source]

Convert a pynapple.Ts to an nstat.nspikeTrain.

Parameters:
  • ts (nap.Ts) – pynapple timestamps (seconds).

  • name (str) – nstat spike-train name.

  • sample_rate (float) – Recording sample rate in Hz. Default 1000 Hz to match nstat’s default; override to match your acquisition.

  • support (nap.IntervalSet | None) – Optional pynapple IntervalSet providing the recording window. If provided, its [start, end] is used for minTime / maxTime. If absent, the window defaults to the [min, max] of the timestamps (no padding).

Return type:

nspikeTrain

nstat.extras.interop.pynapple.to_pynapple_tsgroup(spike_collection)[source]

Convert a nstat.SpikeTrainCollection to a pynapple.TsGroup.

A pynapple TsGroup is the natural container for a per-neuron population (the same role nstat’s SpikeTrainCollection plays).

Parameters:

spike_collection (SpikeTrainCollection)

Return type:

nap.TsGroup