grids.core.UniformGrid.to_hdf5#

UniformGrid.to_hdf5(filename: str, group_name: str | None = None, overwrite: bool = False, **kwargs)[source]#

Save this grid object to an HDF5 file.

This method serializes the grid metadata, physical domain information, unit definitions, and coordinate system to disk. Unlike GenericGrid, the coordinates are not explicitly saved, since they are analytically defined from the bounding box and resolution.

Parameters:
  • filename (str) – Path to the target HDF5 file. The file will be created if it does not exist.

  • group_name (str, optional) – Name of the HDF5 group to store the grid under. If None, stores directly at the file root.

  • overwrite (bool, default False) – If True, overwrites the existing group or file if it already exists. If False, raises an error if the target exists.

  • **kwargs – Additional keyword arguments for forward compatibility (ignored by default).

Notes

The resulting HDF5 structure resembles:

├── [attrs]
│   ├── axes                → list of str           # Axis names (e.g. ["x", "y", "z"])
│   ├── chunking            → bool                  # Whether chunking is enabled
│   ├── chunk_size          → list[int]             # Size of each chunk (if enabled)
│   ├── grid_shape          → list[int]             # Grid shape (excluding ghost zones)
│   ├── bbox                → (2, ndim) array       # Physical bounding box (without ghosts)
│   ├── ghost_zones         → (2, ndim) array       # Number of ghost cells per axis
│   ├── coordinate_system   → str                   # Name of the coordinate system class
│   └── centered            → bool                  # Whether grid is cell-centered
│
├── units/                  → group
│   └── ...                 → Unit definitions for each base dimension
│
└── coord_systm/            → group
    └── ...                 → Coordinate system-specific symbolic definitions

See also

from_hdf5

Method to load the grid back from an HDF5 file.