Skip to content

IceChunkBackend

Import path: earth2studio.io.IceChunkBackend

View source on GitHub

Documentation

Bases: ZarrBackend

A backend that writes to an Icechunk repository.

Icechunk is a transactional storage engine for Zarr that adds version control (commits, branches, tags) on top of a regular object store. This backend behaves identically to earth2studio.io.ZarrBackend for add_array / write / read, using an Icechunk writable session's store in place of a plain Zarr store. Since Icechunk snapshots are immutable, call commit to persist accumulated writes; uncommitted writes are still visible to this backend but are lost if the process exits before committing (close commits them with a generic message, and a warning is logged if the backend is destroyed with pending writes).

By default, write is non-blocking: the actual store write for a call runs in a background thread so the inference loop can move on to the next step while the previous step's write is still in flight. The payload is copied before write returns, so callers may reuse or release it immediately. flush, read, to_xarray, __getitem__, commit and close all wait for pending writes first, so they always observe the latest data; pass blocking=True to write synchronously instead, e.g. if a commit on every step makes the flush unconditional anyway.

Parameters:

  • storage (Storage | str, default: None ) –

    Icechunk storage backend to open/create the repository with. If a string is provided, it is treated as a path for icechunk.local_filesystem_storage. If None, an in-memory Icechunk repository is created, by default None

  • branch (str, default: 'main' ) –

    Branch to open a writable session on. Created (from the tip of "main") if it does not already exist, by default "main"

  • repo_kwargs (dict[str, Any], default: {} ) –

    Key word arguments passed to icechunk.Repository.open_or_create, by default {}

  • chunks (dict[str, int], default: {'ensemble': 1, 'time': 1, 'lead_time': 1, 'variable': 1} ) –

    An ordered dict of chunks to use with the data passed through data/coords, by default {}

  • backend_kwargs (dict[str, Any], default: {'overwrite': False} ) –

    Key word arguments for zarr.Group root object, by default {"overwrite": False}

  • zarr_codecs (CompressorsLike, default: None ) –

    Compression codec to use when creating any new arrays. Only effects Zarr 3.0. If None, will use no compressor, by default None

  • blocking (bool, default: False ) –

    If False (default), write submits the store write to a background thread and returns immediately instead of waiting for it to complete. If True, write blocks until the store write finishes, by default False

  • pool_size (int, default: 8 ) –

    Number of background threads used for non-blocking writes, ignored if blocking is True, by default 8

Note

For more information about Icechunk see: icechunk.io/en/latest/

Warning

In non-blocking mode, writing overlapping regions of the same array back to back before a flush point (read/__getitem__/commit) races: the background threads may apply in either order. This is not a concern for the typical inference-loop pattern of writing disjoint time/lead_time slices.

add_array

add_array(template: DataArray) -> None

Create the arrays a template describes in the zarr group.

Coordinates are written once, here, together with their attributes. Each stored array lists its auxiliary coordinates in a CF coordinates attribute and carries the template's attributes.

Parameters:

  • template (DataArray) –

    Concrete coordinate signature; field values are never read.

write

write(x: DataArray) -> None

Write a field at the positions its coordinate labels identify.

Parameters:

  • x (DataArray) –

    NumPy-, CuPy- or Torch-backed field. It is never modified.

Examples using earth2studio.io.IceChunkBackend