load_hdf5

Contents

load_hdf5#

class braintools.file.load_hdf5(path)#

Load a tree saved with save_hdf5().

Parameters:

path (str | PathLike) – The HDF5 file to read.

Returns:

The saved tree, with the original container types, keys, dtypes, units and SpikeTrains objects (including their overflow flag). Files written by other programs are read too: groups become dicts and datasets become numpy arrays (strings become str).

Return type:

Any

Raises:

See also

save_hdf5

Write 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')