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
.npzfile.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:
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
.npzfile.- Parameters:
path (str or Path) – Path to the
.npzfile (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"]