A comprehensive Python library for representing electrophysiology data with support for reading and writing a wide range of neurophysiology file formats.
npx @tessl/cli install tessl/pypi-neo@0.14.0Neo is a comprehensive Python library for representing electrophysiology data with support for reading and writing a wide range of neurophysiology file formats. It provides a hierarchical data model well-adapted to intracellular and extracellular electrophysiology and EEG data with multi-electrode support, building on NumPy and the quantities package for dimensional consistency and automatic unit conversion.
pip install neoimport neoCommon imports for working with data structures:
from neo import Block, Segment, AnalogSignal, SpikeTrain, Event, EpochCommon imports for file I/O:
from neo.io import AxonIO, BlackrockIO, PlexonIO, Spike2IO
from neo.io import get_io # Auto-detect file formatCommon imports for utilities:
from neo.utils import get_events, get_epochs, cut_segment_by_epochimport neo
from neo import Block, Segment, AnalogSignal, SpikeTrain
from neo.io import AxonIO
import numpy as np
import quantities as pq
# Reading data from files
io = AxonIO('data.abf')
block = io.read_block()
# Or auto-detect format
io = neo.io.get_io('data.abf')
block = io.read_block()
# Creating data structures manually
block = Block(name="Experiment 1")
segment = Segment(name="Trial 1")
block.segments.append(segment)
# Create analog signal data
signal_data = np.random.randn(1000, 4) * pq.mV # 1000 samples, 4 channels
sampling_rate = 10 * pq.kHz
analog_signal = AnalogSignal(
signal_data,
sampling_rate=sampling_rate,
name="LFP recordings"
)
segment.analogsignals.append(analog_signal)
# Create spike train data
spike_times = np.array([0.1, 0.3, 0.7, 1.2, 1.8]) * pq.s
spike_train = SpikeTrain(
spike_times,
t_start=0 * pq.s,
t_stop=2 * pq.s,
name="Neuron 1"
)
segment.spiketrains.append(spike_train)
# Access data
print(f"Block contains {len(block.segments)} segments")
print(f"First segment has {len(segment.analogsignals)} analog signals")
print(f"Signal shape: {analog_signal.shape}")
print(f"Sampling rate: {analog_signal.sampling_rate}")Neo implements a hierarchical data model organized around the Artist hierarchy:
This design enables Neo to serve as the foundational data representation layer for the Python neuroscience ecosystem, providing interoperability between analysis tools like Elephant, visualization tools like SpykeViewer, simulators like PyNN, and spike sorting tools like tridesclous.
Fundamental data containers and objects for representing all types of electrophysiology data, from continuous signals to discrete events and spike trains.
class Block:
def __init__(self, name=None, description=None, **annotations): ...
segments: list # List of Segment objects
groups: list # List of Group objects
class Segment:
def __init__(self, name=None, description=None, **annotations): ...
analogsignals: list # List of AnalogSignal objects
spiketrains: list # List of SpikeTrain objects
events: list # List of Event objects
epochs: list # List of Epoch objects
imagesequences: list # List of ImageSequence objects
class AnalogSignal:
def __init__(self, signal, units=None, dtype=None, copy=None,
t_start=0*pq.s, sampling_rate=None, sampling_period=None,
name=None, file_origin=None, description=None,
array_annotations=None, **annotations): ...
class SpikeTrain:
def __init__(self, times, t_stop, units=None, dtype=None, copy=None,
sampling_rate=1.0*pq.Hz, t_start=0.0*pq.s, waveforms=None,
left_sweep=None, name=None, file_origin=None, description=None,
array_annotations=None, **annotations): ...Comprehensive support for reading and writing electrophysiology data across 50+ file formats from major hardware manufacturers and analysis software.
def get_io(file_or_folder, *args, **kwargs):
"""Return a Neo IO instance, guessing the type based on the filename suffix."""
class AxonIO:
def __init__(self, filename): ...
def read_block(self, **kwargs): ...
def write_block(self, block, **kwargs): ...
class BlackrockIO:
def __init__(self, filename): ...
def read_block(self, **kwargs): ...
class PlexonIO:
def __init__(self, filename): ...
def read_block(self, **kwargs): ...Utility functions for extracting, filtering, and manipulating electrophysiology data objects within the Neo hierarchy.
def get_events(container, **properties):
"""Extract events matching specified criteria."""
def get_epochs(container, **properties):
"""Extract epochs matching specified criteria."""
def cut_segment_by_epoch(segment, epoch):
"""Create new segment containing data within epoch boundaries."""
def download_dataset(name, data_home=None):
"""Download public electrophysiology datasets for testing and examples."""High-performance, memory-efficient access to file data through the RawIO interface, providing direct access to signal chunks without creating full Neo objects.
class AxonRawIO:
def __init__(self, filename): ...
def parse_header(self): ...
def get_signal_size(self, block_index, seg_index, channel_indexes): ...
def get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, channel_indexes): ...
def get_rawio(filename):
"""Auto-detect and return appropriate RawIO class for file format."""# Core quantity types using the quantities package
Signal = np.ndarray * pq.Quantity # Array with physical units
Time = pq.Quantity # Time values with units (s, ms, etc.)
Rate = pq.Quantity # Sampling rates with units (Hz, kHz, etc.)
# Annotation types
Annotations = dict # Arbitrary metadata key-value pairs
# Container relationships
BlockList = list[Block] # List of Block objects
SegmentList = list[Segment] # List of Segment objects
GroupList = list[Group] # List of Group objects