grids.core.GenericGrid.to_hdf5#

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

Save this grid object as / in an HDF5 file.

This method will save all the grid metadata (bbox, dd, etc.) under group_name/attrs and dump the coordinate arrays into individual datasets inside of group_name, each named in accordance with the coordinate axis it represents. See the notes below for a more comprehensive explanation of the resulting file structure.

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.

Notes

The structure of the resulting HDF5 file will look something like the following:

├── [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
│   ├── ghost_zones         → (2, ndim) array       # Ghost zones on each axis
│   └── coordinate_system   → str                   # Class name of the coordinate system
│
│
├── coordinates/            → group                 # Note: names vary with coordinate system.
│   ├── x                   → 1D array              # Coordinate values along 'x' axis
│   ├── y                   → 1D array              # Coordinate values along 'y' axis
│   └── z                   → 1D array              # Coordinate values along 'z' axis (if 3D)
│
├── units/                  → group
│   ├── length              → str (e.g. "cm")       # Unit string for 'length'
│   ├── time                → str (e.g. "s")        # Unit string for 'time'
│   ├── mass                → str (e.g. "g")        # Unit string for 'mass'
│   ├── angle               → str (e.g. "rad")      # Unit string for 'angle'
│   └── ...                                        # Any other base dimensions
│
└── coord_systm/            → group
    └── ...                 → Defined by coordinate system class
                             (symbolic metric, Jacobians, etc.)

See also

from_hdf5

Method that reads the file structure described above.