load_hdf5#
- class braintools.file.load_hdf5(path)#
Load a tree saved with
save_hdf5().- Parameters:
- Returns:
The saved tree, with the original container types, keys, dtypes, units and
SpikeTrainsobjects (including theiroverflowflag). Files written by other programs are read too: groups become dicts and datasets become numpy arrays (strings becomestr).- Return type:
- Raises:
FileNotFoundError – If
pathdoes not exist.ImportError – If
h5pyis not installed (pip install braintools[hdf5]).
See also
save_hdf5Write a tree.
Notes
Everything is read into memory. Host-side only (not under
jax.jit).Examples
>>> import os, tempfile >>> import brainunit as u >>> import jax.numpy as jnp >>> from braintools.file._hdf5 import save_hdf5, load_hdf5 >>> from braintools.spike import SpikeTrains >>> path = os.path.join(tempfile.mkdtemp(), 'spikes.h5') >>> st = SpikeTrains.from_dense(jnp.array([[1, 0], [0, 0], [1, 0]]), dt=1. * u.ms) >>> save_hdf5(path, {'trains': st, 'labels': ('exc', 'inh')}) >>> out = load_hdf5(path) >>> out['trains'].times Quantity([[ 0. 2.] [inf inf]], "ms") >>> out['labels'] ('exc', 'inh')