Zarr

Interface to zarr arrays

class ZarrArrayPath(file: Path | str, path: str | None = None)[source]

Map to an array within a zarr store.

See zarr.open()

file: Path | str

Location of Zarr store file or directory

path: str | None = None

Path to array within hierarchical zarr store

open(**kwargs: dict) Array[source]

Open the zarr array at the provided path

classmethod from_iterable(spec: Sequence) ZarrArrayPath[source]

Construct a ZarrArrayPath specifier from an iterable, rather than kwargs

pydantic model ZarrJsonDict[source]

Round-trip Json-able version of a Zarr Array

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Fields:
field dtype: str | None = None
field file: str | None = None
field info: dict[str, str] [Required]
field path: str | None = None
field type: Literal['zarr'] [Required]
field value: list | None = None
to_array_input() Array | ZarrArrayPath[source]

Construct a ZarrArrayPath if file and path are present, otherwise a ZarrArray

class ZarrInterface(shape: Tuple[int, ...] | Any = typing.Any, dtype: str | type | Any | generic = typing.Any)[source]

Interface to in-memory or on-disk zarr arrays

return_type

alias of Array

json_model

alias of ZarrJsonDict

classmethod enabled() bool[source]

True if zarr is installed

classmethod check(array: Any) bool[source]

Check if array is in-memory zarr array, a path to a zarr array, or a ZarrArrayPath

before_validation(array: Array | str | Path | ZarrArrayPath | Sequence) Array[source]

Ensure that the zarr array is opened

get_dtype(array: Array) str | type | Any | generic[source]

Override base dtype getter to handle zarr’s string-as-object encoding.

classmethod to_json(array: Array | str | Path | ZarrArrayPath | Sequence, info: SerializationInfo | None = None) list | ZarrJsonDict[source]

Dump a Zarr Array to JSON

If info.round_trip == False, dump the array as a list of lists. This may be a memory-intensive operation.

Otherwise, dump the metadata for an array from zarr.core.Array.info_items() plus the zarr.core.Array.hexdigest() as a ZarrJsonDict

If either the dump_array value in the context dictionary is True or the zarr array is an in-memory array, dump the array as well (since without a persistent array it would be impossible to roundtrip and dumping to JSON would be meaningless)

Passing `dump_array': True to the serialization context looks like this:

model.model_dump_json(context={'zarr_dump_array': True})