load_nwb_timeseries

load_nwb_timeseries#

class braintools.file.load_nwb_timeseries(path, name)#

Read a regularly sampled NWB TimeSeries by name.

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

  • name (str) – Name of the TimeSeries. The acquisition group is searched first, then the rest of the file (processing modules, stimulus, …).

Return type:

Tuple[Any, Any]

Returns:

  • data (numpy.ndarray or Quantity) – The samples, time on axis 0, with the series’ conversion and offset applied (data * conversion + offset). A Quantity when the NWB unit string is a unit brainunit can parse (NWB spellings such as "volts" are recognised); a plain array for "n/a" and similar, or with a UserWarning for an unknown unit string.

  • dt (Quantity) – Sampling interval in seconds, from the series’ rate, or from uniformly spaced timestamps.

Raises:
  • FileNotFoundError – If path does not exist.

  • KeyError – If no TimeSeries called name exists (the message lists the available names).

  • ValueError – If the series has irregular timestamps (no single dt).

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

See also

save_nwb_timeseries

Write a series.

Notes

Host-only (not under jax.jit/jax.vmap). The data is read fully into memory.

Examples

>>> import os, tempfile
>>> import brainunit as u
>>> import numpy as np
>>> from braintools.file._nwb import save_nwb_timeseries, load_nwb_timeseries
>>> path = os.path.join(tempfile.mkdtemp(), 'i.nwb')
>>> save_nwb_timeseries(path, np.arange(4.), 1e-3, 'counts')
>>> data, dt = load_nwb_timeseries(path, 'counts')
>>> data, dt
(array([0., 1., 2., 3.]), Quantity(0.001, "s"))