save_nwb_timeseries#
- class braintools.file.save_nwb_timeseries(path, data, dt, name, unit=None, *, description='no description', session_description='braintools time series', identifier=None, session_start_time=None, overwrite=False)#
Write a regularly sampled signal as an NWB
TimeSeriesin a new file.The series is added to the file’s
acquisitiongroup, with time on axis 0, sampling rate1 / dtin Hz and starting time 0 s.- Parameters:
path (
str|PathLike) – Target.nwbfile, written atomically.data (
Any) – Samples with time on axis 0, shape(T, ...).dt (
Any) – Sampling interval. A Quantity must have a time unit; a plain number is in seconds (the NWB time unit).name (
str) – Name of theTimeSeries.unit (
Unit|str|None) – Physical unit to store. Ifdatais a Quantity, it is converted tounit(astris parsed withbrainunit.parse_unit), and the default is the unit ofdata. Ifdatais a plain array,unitis only recorded as its string; the default is"n/a"(no unit).description (
str) – Description of the series.session_description (
str) – Description of the session (required by NWB).identifier (
str|None) – Unique file identifier; a random UUID by default.session_start_time (
datetime|None) – Timezone-aware session start; the current UTC time by default.overwrite (
bool) – Whether to replace an existing file atpath.
- Raises:
FileExistsError – If
pathexists andoverwriteis False.TypeError – If
dthas a non-time unit ordatais a JAX tracer.ValueError – If
dtis not positive, ordatais 0-d.brainunit.UnitMismatchError – If
datacannot be converted tounit.ImportError – If
pynwbis not installed (pip install braintools[nwb]).
- Return type:
See also
load_nwb_timeseriesRead the series back.
save_nwb_unitsWrite spike trains.
Notes
Host-only (not under
jax.jit/jax.vmap). Each call creates a new file holding one series.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(), 'v.nwb') >>> v = np.array([[-65., -64.], [-63., -60.], [-55., -70.]]) * u.mV >>> save_nwb_timeseries(path, v, 0.1 * u.ms, 'membrane_potential') >>> data, dt = load_nwb_timeseries(path, 'membrane_potential') >>> data Quantity([[-65. -64.] [-63. -60.] [-55. -70.]], "mV") >>> dt.to_decimal(u.ms) 0.1