nex5file
Rust library for reading, writing, and editing data stored in NeuroExplorer .nex and .nex5 files.
This crate is a port of the Python nex5file package, with a matching feature set and API surface adapted to idiomatic Rust.
Features
- Read and write
.nexand.nex5files (format chosen by file extension) - Variable types: neurons, events, intervals, markers, waveforms, continuous (A/D), population vectors
- Read full files, headers only, or selected variable payloads (all headers always retained)
- Lazy loading via
OpenNexFilewith a cached file handle - Build and modify in-memory
FileDatabefore writing - JSON metadata support in
.nex5files - Optional read validation (layout checks, payload size limits, sequential I/O)
serdeserialization of in-memory file data- Chunked bulk I/O for large recordings
no_stdfeature — read/write via in-memory buffers (read_from_slice,write_to_vec) without the standard library
no_std
Disable default features for embedded or allocator-only environments:
= { = "1", = false, = ["no_std"] }
use ;
let data = new.read_from_slice?;
let out = new.write_to_vec?;
See docs/format.md for a binary format reference.
Installation
[]
= "1.2"
Or from this repository:
= { = "." }
Quick start
use ;
Lazy loading (large files)
use OpenNexFile;
let mut open = open_headers_only?;
println!;
// Load only what you need — file handle stays open
open.load_variables?;
let ad0 = open.data.continuous?;
Zero-copy mmap views (mmap feature)
When using OpenNexFile::open_mmap, decode timestamps and waveform bytes without allocating full vectors:
use OpenNexFile;
let open = open_mmap?;
let ts: = open.mmap_timestamps_view?.iter_seconds.collect;
Selective reads
Reading specific variables loads their payloads but keeps every variable header, so round-tripping a subset is safe as long as all payloads are loaded before write:
use Reader;
let partial = new.read_nex5_file_variables?;
assert!;
// Other variables appear in headers but are not loaded until requested
Read / write options
use ;
let reader = with_options;
let writer = with_options;
Workspace crates
| Crate | crates.io | Role |
|---|---|---|
nex5 |
1.2 |
Umbrella crate + prelude (feature-gated siblings) |
nex5file |
1.2 |
Read/write .nex / .nex5 |
nex5-nwb |
1.2 |
Convert FileData ↔ NWB 2.x |
nex5-analyze |
1.2 |
PSTH, filtering, ISI, raster, cross-correlation |
nex5-sort |
1.2 |
Kilosort-style sorting + Phy/Kilosort .npy I/O |
nex5-med64 |
1.2 |
MED64 .modat → .nex5 |
nex5-cli |
1.2 |
nex5 command: info, export, NWB, sort, PSTH |
# Cargo.toml
= { = "1.2", = ["full"] }
# or pick crates individually:
= "1.2"
= "1.2"
= "1.2"
= "1.2"
= "1.2"
use ;
use ;
let data = read_nwb_file?;
let psth = psth;
write_nwb_file?;
Examples
API mapping (Python → Rust)
| Python | Rust |
|---|---|
Reader().ReadNex5File(path) |
read_nex5_file(path) |
Reader().ReadNexHeadersOnly(path) |
Reader::new().read_nex_headers_only(path) |
Reader().ReadNexFileVariables(path, names) |
reader.read_nex5_file_variables(path, &names) |
Writer().WriteNex5File(data, path) |
write_nex5_file(&data, path) |
data[name] |
data.get_variable(name)? or data["name"] |
data.AddEvent(...) |
data.add_event(...)? |
data.ContinuousNames() |
data.continuous_names() |
MSRV
Rust 1.74 or later.
License
MIT — same as the original nex5file project.