Save & Load

Grids and their associated data can be persisted to disk and restored later. These functions serialise a grid’s structure and, optionally, any solution arrays defined on it, so that expensive grid constructions do not need to be repeated between sessions.

numgrids.save_grid(path: str | Path, grid: Grid, **data: NDArray) None[source]

Save a grid and optional meshed data arrays to a .npz file.

The grid structure (axis types, parameters) is stored as compact JSON metadata. Any additional keyword arguments are stored as named arrays and will be returned by load_grid().

Parameters:
  • path (str or Path) – Destination file path. A .npz suffix is appended automatically by NumPy if not already present.

  • grid (Grid) – The grid to save.

  • **data (NDArray) – Arbitrary meshed arrays to persist alongside the grid. Each array must have shape grid.shape.

Examples

>>> save_grid("my_grid.npz", grid, temperature=T, pressure=P)
numgrids.load_grid(path: str | Path) tuple[Grid, dict[str, NDArray]][source]

Load a grid and any saved data arrays from a .npz file.

Parameters:

path (str or Path) – Path to the .npz file (the suffix may be omitted).

Returns:

  • grid (Grid) – The reconstructed grid.

  • data (dict[str, NDArray]) – Dictionary of data arrays that were saved alongside the grid. Keys match the original keyword names passed to save_grid().

Examples

>>> grid, data = load_grid("my_grid.npz")
>>> T = data["temperature"]