load_nwb_units

Contents

load_nwb_units#

class braintools.file.load_nwb_units(path, *, capacity=None)#

Read the Units table of an NWB file into a SpikeTrains.

Parameters:
  • path (str | PathLike) – The .nwb file.

  • capacity (int | None) – Padded number of spike slots per neuron. Defaults to the largest spike count (at least 1).

Returns:

One neuron per row of the Units table, in row order, with times as Quantities in seconds. t_start/t_stop are the earliest start and the latest end of the braintools_recording intervals table written by save_nwb_units() and of the obs_intervals column, widened if needed to contain every spike. Without either, they are the earliest and latest spike (0 s if there are none). overflow is restored from the braintools_overflow column written by save_nwb_units() (False if absent).

Return type:

SpikeTrains

Raises:
  • FileNotFoundError – If path does not exist.

  • ValueError – If the file has no Units table, or a neuron has more than capacity spikes.

  • ImportError – If pynwb is not installed (pip install braintools[nwb]).

See also

save_nwb_units

Write a Units table.

braintools.file.from_neo

Import spike trains from neo.

Notes

Host-only (not under jax.jit/jax.vmap). Unit ids are not returned; read them with pynwb if needed. Times are converted to JAX’s default float dtype (float32 unless jax_enable_x64 is on).

Examples

>>> import os, tempfile
>>> import brainunit as u
>>> import jax.numpy as jnp
>>> from braintools.file._nwb import save_nwb_units, load_nwb_units
>>> from braintools.spike import SpikeTrains
>>> st = SpikeTrains.from_dense(jnp.array([[1, 0], [0, 1], [1, 1]]), dt=1. * u.ms)
>>> path = os.path.join(tempfile.mkdtemp(), 'units.nwb')
>>> save_nwb_units(path, st, session_description='demo', identifier='demo-2')
>>> back = load_nwb_units(path)
>>> back.times.to_decimal(u.ms).round(6)
Array([[0., 2.],
       [1., 2.]], dtype=float32)