Neo

raw JSON →
0.14.4 verified Mon Apr 27 auth: no python

Neo is a Python package for representing electrophysiology data, with support for reading a wide range of neurophysiology file formats. Current version 0.14.4, requires Python >=3.10. Release cadence is irregular.

pip install neo
error ImportError: cannot import name 'Block' from 'neo'
cause Block and other core classes moved from neo top-level to neo.core in version 0.10.0.
fix
Use 'from neo.core import Block'.
error ValueError: Must supply units for AnalogSignal
cause AnalogSignal requires units parameter as a quantities object.
fix
Add units='mV' or similar using quantities (import quantities as pq).
error TypeError: unsupported operand type(s) for /: 'Quantity' and 'Quantity'
cause Mixing incompatible units in operations.
fix
Convert units to a common base before arithmetic, e.g., signal.rescale('mV').
breaking In version 0.10.0, core classes were moved from neo.core to neo.core, but the top-level imports (e.g., from neo import Block) were removed. Use from neo.core import ...
fix Change 'from neo import Block' to 'from neo.core import Block'.
breaking Units handling changed: quantities become mandatory for signal and spike train objects. Passing plain numbers without units may raise errors or produce unexpected behavior.
fix Always use quantities (e.g., 1.0*pq.s) for time and amplitude values.
deprecated The 'file_io' subpackage is deprecated in favor of 'io'. Importing from neo.file_io will emit a deprecation warning.
fix Use 'from neo.io import ...' instead of 'from neo.file_io import ...'.
gotcha Data arrays for AnalogSignal must be 2D (time x channel) even for single-channel data. If you pass a 1D array, it may automatically reshape but check shape.
fix Ensure signal data is 2D, e.g., np.random.rand(100, 1).

Quickstart: creating a basic hierarchical data structure with Block, Segment, AnalogSignal, and SpikeTrain.

import neo
from neo.core import Block, Segment, AnalogSignal, SpikeTrain
import quantities as pq
import numpy as np

# Create a Block with a Segment
block = Block(name='example')
seg = Segment(name='segment1')
block.segments.append(seg)

# Create an AnalogSignal (1 second of data, 100 Hz)
signal = AnalogSignal(np.random.rand(100), sampling_rate=100*pq.Hz, units='mV', name='test')
seg.analogsignals.append(signal)

# Create a SpikeTrain
st = SpikeTrain([0.1, 0.2, 0.3, 0.5]*pq.s, t_stop=1.0*pq.s, units='s', name='test_spikes')
seg.spiketrains.append(st)

print('Block:', block)
print('Signals:', seg.analogsignals)
print('Spike trains:', seg.spiketrains)