abczarr.metadata.v2.array
Zarr v2 array metadata.
Zarr v2 describes an array with a single numcodecs compressor, an ordered list of numcodecs filters applied before it, and a byte-order-bearing dtype. ArrayMetadata.to_version converts to v1 by keeping only the compressor, since v1 has no filters. It converts to v3 by mapping the filters and compressor onto v3's codec pipeline, folding the dtype's byte order into an explicit serializer codec.
Classes
ArrayMetadata
ArrayMetadata(attributes: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = {}, zarr_format: Literal[2] = 2, node_type: Literal['array'] = 'array', *, shape: Iterable[Integral | integer | bool] = (), chunks: Iterable[Integral | integer | bool] = (), dtype: DTYPELIKE, compressor: Codec | JsonDict | str | None = None, fill_value: Number | number | bool | None = None, order: Literal['C', 'F'] = 'C', filters: Any = (), dimension_separator: Literal['.', '/'] | None = None)
Bases: ArrayMetadataV2
A Zarr v2 array's metadata: shape, dtype, chunking and codecs.
Corresponds to the contents of .zarray. filters run, in
order, before compressor when encoding a chunk, and in reverse
order after it when decoding.
Example
>>> from abczarr.metadata import v2
>>> meta = v2.ArrayMetadata.from_json({
... "zarr_format": 2,
... "shape": [10, 10],
... "chunks": [5, 5],
... "dtype": "<f8",
... "compressor": {"id": "zstd", "level": 3},
... "fill_value": 0,
... "order": "C",
... "filters": [],
... "attributes": {},
... })
>>> [codec.name for codec in meta.to_version(3).codecs]
['bytes', 'zstd']
Attributes
dtype
instance-attribute
dtype: DType
The array's numpy dtype, encoded as a Zarr v2 dtype string or, for a structured dtype, a field list.
compressor
instance-attribute
compressor: Codec | None
The codec applied last on encode and first on decode, or None
for no compression.
fill_value
class-attribute
instance-attribute
The value an unwritten element of the array reads as.
order
instance-attribute
The memory layout of a decoded chunk: "C" for row-major or
"F" for column-major.
filters
class-attribute
instance-attribute
filters: tuple[Filter, ...] = field(converter=_filters_converter)
The codecs applied, in order, before compressor on encode, and
in reverse order after it on decode.
dimension_separator
instance-attribute
The character joining a chunk index into its store key, "."
or "/". None means the default, ".", applies.
Methods:
to_json
to_json() -> JsonDict
Serialize this metadata to the contents of .zarray.
filters is written as null when there are none, rather
than an empty list, matching how the Zarr v2 specification
represents an array with no filters.
Returns:
| Type | Description |
|---|---|
dict
|
The JSON-compatible representation of this metadata. |
to_version
to_version(version: ZarrVersion, policy: ConversionPolicy = 'lossy') -> ArrayMetadata
Convert this array's metadata to another Zarr version.
Converting to v1 keeps only the compressor: v1 has no
filters, so any filters are subject to policy. Converting
to v3 maps each filter and the compressor onto v3's codec
pipeline and, when order is not "C", applies policy
as well, since v3 has no memory-order field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
ZarrVersion
|
The target Zarr format version: 1, 2 or 3. |
required |
policy
|
ConversionPolicy
|
How to treat a field the target version can't hold. |
'lossy'
|
Returns:
| Type | Description |
|---|---|
ArrayMetadata
|
Equivalent metadata for |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
UnsupportedConversion
|
If |