> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# H5py

> H5py: Thin, pythonic wrapper around HDF5. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/h5py/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/h5py/h5py.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/geospatial/h5py.ipynb)

Description:
- Thin, pythonic wrapper around HDF5

Resources:
- [GitHub] https://github.com/h5py/h5py
- [Examples] https://github.com/h5py/h5py/tree/master/examples
- [Website] https://www.h5py.org/
- [Docs] https://docs.h5py.org/en/stable/

## Example 1

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

```python
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])
```
