or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-data-structures.mddata-utilities.mdfile-io-support.mdindex.mdrawio-access.md
tile.json

tessl/pypi-neo

A comprehensive Python library for representing electrophysiology data with support for reading and writing a wide range of neurophysiology file formats.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/neo@0.14.x

To install, run

npx @tessl/cli install tessl/pypi-neo@0.14.0

index.mddocs/

Neo

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

Package Information

  • Package Name: neo
  • Language: Python
  • Installation: pip install neo
  • Version: 0.14.2
  • Dependencies: NumPy, quantities
  • License: BSD 3-Clause License

Core Imports

import neo

Common imports for working with data structures:

from neo import Block, Segment, AnalogSignal, SpikeTrain, Event, Epoch

Common imports for file I/O:

from neo.io import AxonIO, BlackrockIO, PlexonIO, Spike2IO
from neo.io import get_io  # Auto-detect file format

Common imports for utilities:

from neo.utils import get_events, get_epochs, cut_segment_by_epoch

Basic Usage

import 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}")

Architecture

Neo implements a hierarchical data model organized around the Artist hierarchy:

  • Block: Top-level container for entire experiments or recording sessions
  • Segment: Time-based container for temporally related data (trials, epochs)
  • Group: Logical grouping container for related data objects across segments
  • Data Objects: Core electrophysiology data types (signals, spikes, events)

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.

Capabilities

Core Data Structures

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

Core Data Structures

File I/O Support

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

File I/O Support

Data Manipulation Utilities

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

Data Manipulation Utilities

Low-Level File Access

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

Low-Level File Access

Types

# 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