xarray_beam.offsets_to_slices
- xarray_beam.offsets_to_slices(offsets, sizes, base=None)
Convert offsets into slices with an optional base offset.
- Parameters:
offsets (Mapping[str, int]) – integer offsets from the origin along each axis.
sizes (Mapping[str, int]) – dimension sizes for the corresponding chunks.
base (Optional[Mapping[str, int]]) – optional base-offset to subract from this key. This allows for relative indexing, e.g., into a chunk of a larger Dataset.
- Returns:
Slices suitable for indexing with xarray.Dataset.isel().
- Raises:
ValueError – if an offset is specified for a dimension where there is no corresponding size specified.
- Return type:
Dict[str, slice]
Example usage:
>>> offsets_to_slices({'x': 100}, sizes={'x': 10}) {'x': slice(100, 110, 1)} >>> offsets_to_slices({'x': 100}, sizes={'x': 10}, base={'x': 100}) {'x': slice(0, 10, 1)}