nstat.extras.interop.neo — Neo bridge
Convert between nstat.nspikeTrain /
nstat.SpikeTrainCollection and the
Neo data model. Neo is
the de-facto interchange object for the Elephant / SpikeInterface /
Brian2 ecosystem, with readers for Spike2, NEX, AlphaOmega, Axon,
Blackrock, Plexon, and TDT formats.
Install
pip install nstat-toolbox[neo]
Pulls neo>=0.13 + quantities>=0.15.
API
Function |
Direction |
Notes |
|---|---|---|
|
nstat → Neo |
Spike times in seconds; preserves |
|
Neo → nstat |
Auto-converts units via |
|
nstat → Neo |
Builds a |
Recipe
from nstat import nspikeTrain, SpikeTrainCollection
from nstat.extras.interop.neo import (
to_neo_spiketrain, from_neo_spiketrain, to_neo_segment,
)
# nstat → Neo
nst = nspikeTrain(
spikeTimes=[0.1, 0.5, 1.2],
name="unit_42",
sampleRate=30_000.0,
minTime=0.0,
maxTime=2.0,
)
neo_st = to_neo_spiketrain(nst)
# Round-trip back (units preserved)
nst_back = from_neo_spiketrain(neo_st)
assert (nst_back.spikeTimes == nst.spikeTimes).all()
# Collection → Neo Segment (one row per train)
coll = SpikeTrainCollection([nst, nst, nst])
segment = to_neo_segment(coll)
assert len(segment.spiketrains) == 3
Gotchas
Units. Neo requires
quantities.Quantityunits. The bridge assumes seconds throughout (matching nstat’sspikeTimesconvention — see CLAUDE.md “Time and units”). If you pass a NeoSpikeTrainwhose times are inms, therescale(pq.s)conversion is automatic.Window.
t_start/t_stopmap tominTime/maxTime. If the source Neo train doesn’t carrysampling_rate, the round-trip defaults to 1000 Hz — passsample_rate=explicitly to override.Segment scope.
to_neo_segmentonly populatessegment.spiketrains— not analog signals or events. nstat’sSpikeTrainCollectiondoesn’t carry the hierarchical metadata Neo’sBlock/Segmenttrack.
End-to-end demo
examples/extras/interop_neo_demo.py
runs the full round-trip + Segment construction with python examples/extras/interop_neo_demo.py.
Upstream references
Neo: https://github.com/NeuralEnsemble/python-neo
License: BSD-3-Clause (GPL-2 compatible)
Used downstream by: Elephant, SpikeInterface, Brian2