Skip to content

jnwb

jnwb

Version 0.2.17

Dataset-agnostic Python library for Neurodata Without Borders (NWB 2.0+) electrophysiology: addressing, spikes, LFP, spectral analysis, statistics, population methods, decoding, connectivity, laminar CSD, filtering, QC, and visualization.

Condition codes, task structure, and experimental hypotheses belong in project code. The library operates on NWB files, numeric arrays, and metadata tables.

New to NWB in jnwb? Start with the Tutorials: inspect → events / event_onsets → align spikes/LFP → compose an analysis.

Install

pip install -U jnwb
pip install "jnwb[torch,gpu]"   # optional CuPy / PyTorch

Requires Python 3.12 or newer; CI tests 3.12 and 3.15 on Linux. See Installation.

Example

Welch PSD and canonical-band power on a synthetic oscillation:

import jnwb
import numpy as np

rng = np.random.default_rng(0)
fs = 1000.0
time = np.arange(1000) / fs
signal = np.sin(2 * np.pi * 20.0 * time) + 0.5 * rng.normal(size=1000)

freqs, psd = jnwb.compute_psd(signal, fs=fs)
beta_power = jnwb.band_power(
    signal, fs=fs, freq_range=(14.0, 30.0), normalize=False,
)
print(f"Beta band power: {beta_power:.4f}")

Guides

Figures

Synthetic, deterministic examples generated by scripts/figures/generate_figures.py from public APIs:

Artifact repair Artifact repair Artifact detection and trial repair (repair_lfp_trials) Complex TFR with COI Complex TFR with COI Morlet TFR and cone of influence (complex_tfr)
Directed connectivity Directed connectivity Directed connectivity (granger, phase_slope_index) Onset fitting Onset fitting Exponential onset fit (fit_exponential_onset)
Permutation null Permutation null Sign-flip null (exact_sign_flip, permute_labels) Population decoding Population decoding Nested-CV linear decoding (nested_cv_linear_svm)