Skip to content

abczarr.metadata.v1.array

Zarr v1 array metadata.

Zarr v1 has no groups, so an array is the only node this format defines. Its metadata names a single numcodecs compressor and carries that compressor's options separately. Zarr v2 uses the same model. ArrayMetadata.to_version converts to v2 or v3 by routing through v2's richer representation of the same compressor.

Classes

ArrayMetadata

ArrayMetadata(attributes: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = {}, zarr_format: Literal[1] = 1, node_type: Literal['array'] = 'array', *, shape: Iterable[Integral | integer | bool] = (), chunks: Iterable[Integral | integer | bool] = (), dtype: DTYPELIKE, compression: Literal['blosc', 'bz2', 'gzip', 'lz4', 'lzma', 'pcodec', 'zfpy', 'zlib', 'zstd'] | None = None, compression_opts: CodecOptions | JsonDict | Integral | integer | bool | str | bytes | None = None, fill_value: Number | number | bool | None = None, order: Literal['C', 'F'] = 'C', extra_items: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = FrozenDict({}))

Bases: ArrayMetadataV1

A Zarr v1 array's metadata: shape, dtype, chunking and codec.

Corresponds to the contents of .zarray. compression names the compressor, and compression_opts carries that compressor's options separately. A compression of None means the array is stored uncompressed.

Example

>>> from abczarr.metadata import v1
>>> meta = v1.ArrayMetadata.from_json({
...     "zarr_format": 1,
...     "shape": [10],
...     "chunks": [5],
...     "dtype": "<f8",
...     "compression": "zlib",
...     "compression_opts": {"level": 1},
...     "fill_value": 0,
...     "order": "C",
...     "attributes": {},
... })
>>> meta.to_version(2).compressor
ZlibCodec(id='zlib', level=1)

Attributes

shape instance-attribute
shape: Shape

The array's shape, one entry per dimension.

chunks instance-attribute
chunks: Shape

The shape of one chunk, one entry per dimension.

dtype instance-attribute
dtype: DType

The array's numpy dtype, encoded as a Zarr v1 dtype string.

compression instance-attribute
compression: Codec | None

The numcodecs id of the compressor, such as "zlib" or "blosc", or None for no compression.

compression_opts instance-attribute
compression_opts: CodecOptions | int | str | None

The compressor's options. Most codecs take an options object. A codec with a scalar form, such as an integer compression level, may carry that scalar directly instead. This is None when compression is None.

fill_value class-attribute instance-attribute
fill_value: BuiltinNumber | None = field(eq=eq_safenan)

The value an unwritten element of the array reads as.

order instance-attribute
order: MemoryOrder

The memory layout of a decoded chunk: "C" for row-major or "F" for column-major.

Methods:

to_version
to_version(version: ZarrVersion, policy: ConversionPolicy = 'lossy') -> ArrayMetadata

Convert this array's metadata to another Zarr version.

A v1 array converts to v2 or v3 without loss. V2's compressor model can represent everything the compression and compression_opts pair can express, and v3's codec pipeline can in turn represent v2's. policy is accepted for a signature consistent with other versions, but it is never invoked here, since nothing is dropped.

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 can't hold. Unused here.

'lossy'

Returns:

Type Description
ArrayMetadata

Equivalent metadata for version. Converting to 1 returns this object unchanged.

Raises:

Type Description
ValueError

If version is not 1, 2 or 3.

required_features
required_features() -> FrozenSet[str]

Report the features a driver needs to read or write this array.

Returns:

Type Description
frozenset of str

A single-element set naming the compressor, for example {"v1:codec:zlib"}, or an empty set when the array is stored uncompressed.