grids.mixins.chunking.GridChunkingMixin.zeros_like_chunks#

GridChunkingMixin.zeros_like_chunks(chunks: ChunkIndexInput, /, element_shape: int | Sequence[int] = (), axes: AxesInput | None = None, *, include_ghosts: bool = False, halo_offsets: HaloOffsetInput | None = None, oob_behavior: Literal['clip', 'raise'] = 'raise', **kwargs) ndarray[source]#

Return an array of zeros shaped to match a domain-aligned region of the grid.

This is useful for creating initialized scalar/vector/tensor buffers over the grid.

Parameters:
  • element_shape (int or sequence of int, default ()) – Additional trailing shape to append to the grid dimensions.

  • chunks (int, tuple, slice, or sequence of those) –

    Chunk specification per axis. For each axis, you may specify:

    • int: selects a single chunk (i, i+1)

    • (start, stop): a range of chunks

    • slice(start, stop): a Python slice (step is ignored)

    These are converted to global-space data index ranges.

  • axes (str or list of str, optional) –

    The names of the axes to include in the slice. If None, all axes are used. This determines the number of slice objects returned in the output tuple — one slice per selected axis.

    Note

    Regardless of the ordering of axes, the axes are reordered to match canonical ordering as defined by the coordinate system.

  • include_ghosts (bool, optional) – If True, then the slice will include the ghost zones around the boundary of the domain. Otherwise (default), the ghost zones are excluded from the resulting slice.

  • halo_offsets (int, sequence[int], or np.ndarray, optional) –

    Extra padding (in ghost-cell units) to apply on top of the active or ghost-augmented domain.

    This allows you to extend the region further outward beyond ghost zones — for example, to reserve additional halo space for multi-pass stencils.

    Supported formats:

    • int: same padding applied to both sides of all axes

    • sequence of length N: symmetric padding per axis (left = right)

    • array of shape (2, N): explicit left/right padding per axis

    Note

    This is applied after ghost zones (if include_ghosts=True). Total padding = ghost zones + halo.

  • oob_behavior ({"raise", "clip"}, default "raise") –

    Determines what to do if the computed slice (after applying ghost zones and halo padding) would extend beyond the allocated grid buffer (__ghost_dd__).

    Options:
    • ”raise” : Raise an IndexError if any part of the slice is out of bounds.

    • ”clip” : Clamp the slice to stay within the valid grid extent.

    Use “clip” if you’re performing relaxed operations (e.g., visualization or padding-aware reads), and “raise” for strict enforcement during stencil computations or buffer validation.

  • **kwargs – Additional keyword arguments passed to np.zeros.

Returns:

A zero-initialized array of shape (domain_shape, *element_shape).

Return type:

np.ndarray