abczarr.api.config
Describe a Zarr array or group to create.
An ArrayConfig or
GroupConfig is a reusable
description of what to create. It carries the coarse choices, such
as chunking, sharding, compression and the format version, and
lowers them to the exact metadata a driver writes. Pass one to
create to make the array or group it
describes, or spread its fields into a group's create_array as
keyword arguments.
"auto" on a field means that the target version decides. An auto
chunk size fits a byte budget, an auto compressor is the version's
default, and an auto fill value is the dtype's zero. A single config
therefore lowers correctly to either format version.
Classes
ZarrConfig
ZarrConfig(zarr_version: Literal[1, 2, 3] = 3, overwrite: bool | int | str = False, driver: str | bytes | None = None, attributes: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = {})
The choices shared by everything abczarr creates.
ArrayConfig and GroupConfig build on this class. It is not
created on its own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zarr_version
|
int
|
The Zarr format version to write. |
3
|
overwrite
|
bool
|
Replace whatever is already at the target location instead of raising. |
False
|
driver
|
str
|
The name of the driver to create with. |
None
|
attributes
|
mapping
|
User attributes to store on the node. |
{}
|
Attributes
Methods:
GroupConfig
GroupConfig(zarr_version: Literal[1, 2, 3] = 3, overwrite: bool | int | str = False, driver: str | bytes | None = None, attributes: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = {})
Bases: ZarrConfig
A description of a group to create.
A group holds no data of its own, so it adds nothing to ZarrConfig.
Methods:
ArrayConfig
ArrayConfig(zarr_version: Literal[1, 2, 3] = 3, overwrite: bool | int | str = False, driver: str | bytes | None = None, attributes: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = {}, shape: Iterable[Integral | integer | bool] | None = None, dtype: None = None, dimension_names: Iterable[str | bytes | None] | None = None, chunks: Integral | integer | bool | Iterable[Integral | integer | bool | Literal['auto']] | Iterable[tuple[str | bytes | None, Integral | integer | bool | Literal['auto']]] | Mapping[str | bytes | None, Integral | integer | bool | Literal['auto']] | None = 'auto', shards: Integral | integer | bool | Iterable[Integral | integer | bool | Literal['auto']] | Iterable[tuple[str | bytes | None, Integral | integer | bool | Literal['auto']]] | Mapping[str | bytes | None, Integral | integer | bool | Literal['auto']] | None = None, max_chunk_bytes: Integral | integer | bool = 8388608, max_shard_bytes: Integral | integer | bool = 2147483648, compression_ratio: Real | floating | bool = 1.8, compressor: str | bytes | Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] | None = 'auto', compressor_options: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = {}, filters: Iterable[Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any]] = (), fill_value: Number | number | bool | str | bytes | None = 'auto', order: Literal['C', 'F'] = 'C', dimension_separator: str | bytes = 'auto')
Bases: ZarrConfig
A description of an array to create.
Set shape and dtype on the config, or supply them when it is lowered.
The chunking, sharding, and compression fields accept "auto", which is
resolved against the shape, dtype, and format version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple of int
|
The array's shape. Required by the time the config is lowered. |
None
|
dtype
|
numpy dtype
|
The array's data type. Required by the time the config is lowered. |
None
|
dimension_names
|
tuple of str
|
A name for each axis, used by a chunk mapping and written to v3 metadata. |
None
|
chunks
|
(int, auto, None, sequence or mapping)
|
The chunk size per axis. |
'auto'
|
shards
|
(int, auto, sequence, mapping or None)
|
The shard size per axis, or |
None
|
max_chunk_bytes
|
int
|
The target chunk size in bytes when a chunk size is |
8388608
|
max_shard_bytes
|
int
|
The target shard size in bytes when a shard size is |
2147483648
|
compression_ratio
|
float
|
The compression factor the byte budgets assume. |
1.8
|
compressor
|
(str, mapping, auto or None)
|
The compressor. |
'auto'
|
compressor_options
|
mapping
|
Options for a named compressor. |
{}
|
filters
|
tuple of mapping
|
Codecs applied before the main compressor, passed through as specs. |
()
|
fill_value
|
(number, auto or None)
|
The value read where nothing was written. |
'auto'
|
order
|
(C, F)
|
The in-memory layout. This field is stored in Zarr v2
metadata. On v3 it is a runtime memory-layout preference and
is not written to |
"C"
|
dimension_separator
|
('/', '.', auto)
|
The separator between chunk indices in a key. |
"/"
|
Attributes
dimension_names
class-attribute
instance-attribute
dimension_names: tuple[str | None, ...] | None = None
compressor_options
class-attribute
instance-attribute
dimension_separator
class-attribute
instance-attribute
dimension_separator: DimensionSeparator | str = 'auto'
Methods:
resolve
Return a copy with "auto" chunking and sharding worked out.
The shape and dtype come from overrides first, then from the
config. A missing shape or dtype falls back to data when
data is given, so an override or a config value always
takes precedence over the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Existing data to fall back to for a shape or dtype the config does not already carry. |
None
|
**overrides
|
Any
|
Field values that take precedence over the config's own
values, such as |
{}
|
Returns:
| Type | Description |
|---|---|
ArrayConfig
|
A copy of this config with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If none of |
to_metadata
to_metadata() -> ArrayMetadata
Lower the config to the metadata a driver writes.
This method resolves "auto" fields, builds Zarr v3
metadata, and converts the result to zarr_version if that
version is not 3.
Returns:
| Type | Description |
|---|---|
ArrayMetadata
|
The metadata document describing the array. |
compressor_codecs
compressor_codecs() -> list[JsonDict]
The compressor as a list of zero or one v3 codec specs.
"auto" becomes the version default, zstd. None and
"none" both mean no compressor. A mapping passes through
unchanged.
resolved_fill_value
resolved_fill_value() -> Any
The fill value, with "auto" turned into the dtype's zero.
resolved_separator
resolved_separator() -> str
The chunk-key separator, with "auto" (or None) resolved.
ZarrOptions
Bases: TypedDict
The keyword form of ZarrConfig.
GroupOptions
ArrayOptions
Bases: ZarrOptions
The keyword form of ArrayConfig.
This TypedDict carries every
ArrayConfig field except shape
and dtype. A group's create_array takes those two fields as
positional arguments instead.