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()- classmethod from_iterable(spec: Sequence) ZarrArrayPath[source]¶
Construct a
ZarrArrayPathspecifier from an iterable, rather than kwargs
- class ZarrJsonDict(*, type: Literal['zarr'], info: dict[str, str], file: str | None = None, path: str | None = None, dtype: str | None = None, value: list | None = None)[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.
- to_array_input() Array | ZarrArrayPath[source]¶
Construct a ZarrArrayPath if file and path are present, otherwise a ZarrArray
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ZarrTyping[source]¶
Static-typing companion for
ZarrInterface.- constructors: ClassVar[tuple[ConstructorSpec, ...]] = (ConstructorSpec(fullname='zarr.creation.zeros', shape_arg=0, dtype_arg='dtype', mode='function'), ConstructorSpec(fullname='zarr.creation.ones', shape_arg=0, dtype_arg='dtype', mode='function'), ConstructorSpec(fullname='zarr.creation.empty', shape_arg=0, dtype_arg='dtype', mode='function'), ConstructorSpec(fullname='zarr.creation.full', shape_arg=0, dtype_arg='dtype', mode='function'))¶
Constructor calls whose return type the mypy plugin should refine.
- 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
- typing¶
alias of
ZarrTyping
- 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 thezarr.core.Array.hexdigest()as aZarrJsonDictIf either the
dump_arrayvalue in the context dictionary isTrueor 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': Trueto the serializationcontextlooks like this:model.model_dump_json(context={'zarr_dump_array': True})