Skip to content

Description:

  • Thin, pythonic wrapper around HDF5

Resources:

Create a local hdf5 file with a dataset in a context manager, then open it again and read the data back

import h5py
import numpy as np
from pathlib import Path
tmp = Path("/tmp/ganymede_demo")
tmp.mkdir(parents=True, exist_ok=True)
fp = tmp / "geospatial_data.h5"
# Mode "w" creates a new file (and truncates any existing one)
with h5py.File(fp, "w") as f:
dset = f.create_dataset("mydataset", (100,), dtype='i')
dset[:] = np.arange(100)
dset.attrs["units"] = "metres"
print(dset)
# Mode "r" opens the file read-only
with h5py.File(fp, "r") as f:
dset = f["mydataset"]
print(dset.attrs["units"], dset[:10])

ganymede is made by Eugo