load_nwb_units#
- class braintools.file.load_nwb_units(path, *, capacity=None)#
Read the Units table of an NWB file into a
SpikeTrains.- Parameters:
- Returns:
One neuron per row of the Units table, in row order, with times as Quantities in seconds.
t_start/t_stopare the earliest start and the latest end of thebraintools_recordingintervals table written bysave_nwb_units()and of theobs_intervalscolumn, widened if needed to contain every spike. Without either, they are the earliest and latest spike (0 s if there are none).overflowis restored from thebraintools_overflowcolumn written bysave_nwb_units()(False if absent).- Return type:
- Raises:
FileNotFoundError – If
pathdoes not exist.ValueError – If the file has no Units table, or a neuron has more than
capacityspikes.ImportError – If
pynwbis not installed (pip install braintools[nwb]).
See also
save_nwb_unitsWrite a Units table.
braintools.file.from_neoImport spike trains from
neo.
Notes
Host-only (not under
jax.jit/jax.vmap). Unit ids are not returned; read them withpynwbif needed. Times are converted to JAX’s default float dtype (float32 unlessjax_enable_x64is 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)