zarr_metadata.v3.chunk_grid
zarr_metadata.v3.chunk_grid ¶
Zarr v3 chunk grid metadata types.
Each chunk grid lives in its own submodule:
regular-- core v3 specrectilinear-- zarr-extensions
The <X>ChunkGridMetadata aliases re-exported here are the canonical type
for each grid's permitted JSON shapes. For the underlying
<X>ChunkGridObject, <X>ChunkGridConfiguration, etc., import directly
from the leaf submodule.
See https://zarr-specs.readthedocs.io/en/latest/v3/core/index.html#chunk-grids
zarr_metadata.v3.chunk_grid.regular ¶
Regular chunk grid (Zarr v3 core spec).
See https://zarr-specs.readthedocs.io/en/latest/v3/core/index.html#regular-grids
REGULAR_CHUNK_GRID_NAME
module-attribute
¶
REGULAR_CHUNK_GRID_NAME: Final = 'regular'
The name field value of the regular chunk grid.
RegularChunkGridMetadata
module-attribute
¶
RegularChunkGridMetadata = RegularChunkGridObject
Permitted JSON shape for regular chunk grid metadata.
chunk_shape is required and has no default, so only the object form is
valid; the short-hand-name form is not permitted by the spec for this grid.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L528-L537 ("must be an object with the names name and configuration")
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564
RegularChunkGridName
module-attribute
¶
RegularChunkGridName = Literal['regular']
Literal type of the name field of the regular chunk grid.
__all__
module-attribute
¶
__all__ = [
"REGULAR_CHUNK_GRID_NAME",
"RegularChunkGrid",
"RegularChunkGridConfiguration",
"RegularChunkGridMetadata",
"RegularChunkGridName",
"RegularChunkGridObject",
]
RegularChunkGrid
dataclass
¶
Bases: ChunkGridEntity
The regular chunk grid, coerced from its metadata.
Source code in src/zarr_metadata/v3/chunk_grid/regular.py
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = REGULAR_CHUNK_GRID_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"chunk_shape": (True, sequence_of(is_int))
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
Default: entities are already canonical. Override where two
spellings of a member mean the same -- a rectilinear dimension's
run-length encoding, a typesize that noshuffle ignores -- and
where a contained entity has its own canonical form.
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
grid ¶
problems ¶
problems() -> tuple[ValidationProblem, ...]
Every chunk extent must be at least one element.
A chunk of zero elements along an axis covers nothing, so no finite number of them tiles the axis; a negative one is meaningless. Whether there is one extent per array dimension is a question for the document, and the rules layer asks it.
Source code in src/zarr_metadata/v3/chunk_grid/regular.py
shape_problems ¶
shape_problems(
array_shape: object,
) -> tuple[ValidationProblem, ...]
A regular grid must chunk every array dimension.
Source code in src/zarr_metadata/v3/chunk_grid/regular.py
to_json ¶
to_json() -> RegularChunkGridObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
RegularChunkGridConfiguration ¶
Bases: TypedDict
Configuration for the regular chunk grid.
Source code in src/zarr_metadata/v3/chunk_grid/regular.py
RegularChunkGridObject ¶
Bases: TypedDict
Regular chunk grid metadata in object form.
Source code in src/zarr_metadata/v3/chunk_grid/regular.py
zarr_metadata.v3.chunk_grid.rectilinear ¶
Rectilinear chunk grid (zarr-extensions).
See https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/chunk-grids/rectilinear/README.md
RECTILINEAR_CHUNK_GRID_KIND
module-attribute
¶
RECTILINEAR_CHUNK_GRID_KIND: Final = ('inline',)
The kind values the rectilinear grid defines.
Only inline so far: the extents are written into the metadata. The
member exists so a later kind can put them somewhere else.
RECTILINEAR_CHUNK_GRID_NAME
module-attribute
¶
RECTILINEAR_CHUNK_GRID_NAME: Final = 'rectilinear'
The name field value of the rectilinear chunk grid.
RectilinearChunkGridMetadata
module-attribute
¶
RectilinearChunkGridMetadata = RectilinearChunkGridObject
Permitted JSON shape for rectilinear chunk grid metadata.
kind and chunk_shapes are required, so only the object form is valid;
the short-hand-name form is not permitted by the spec for this grid.
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/chunk-grids/rectilinear/README.md#L59-L62
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564
RectilinearChunkGridName
module-attribute
¶
RectilinearChunkGridName = Literal['rectilinear']
Literal type of the name field of the rectilinear chunk grid.
RectilinearDimSpec
module-attribute
¶
JSON shape for one dimension's rectilinear spec.
Either a bare integer (uniform shorthand for a regular dimension within
a rectilinear grid), or a tuple of integers and/or [value, count] RLE
pairs.
__all__
module-attribute
¶
__all__ = [
"RECTILINEAR_CHUNK_GRID_KIND",
"RECTILINEAR_CHUNK_GRID_NAME",
"RectilinearChunkGrid",
"RectilinearChunkGridConfiguration",
"RectilinearChunkGridMetadata",
"RectilinearChunkGridName",
"RectilinearChunkGridObject",
"RectilinearDimSpec",
"canonical_chunk_shapes",
"canonical_dim_spec",
]
RectilinearChunkGrid
dataclass
¶
Bases: ChunkGridEntity
The rectilinear chunk grid, coerced from its metadata.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = RECTILINEAR_CHUNK_GRID_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"kind": (True, one_of(RECTILINEAR_CHUNK_GRID_KIND)),
"chunk_shapes": (True, _is_dim_specs),
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
__init__ ¶
__init__(
kind: Literal["inline"] = "inline",
chunk_shapes: tuple[RectilinearDimSpec, ...] = (),
*,
must_understand: bool = True,
) -> None
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
Run-length encoded, which is the spelling that does not grow.
Two dimension specs listing the same extents describe the same grid, and the encoded one stays the same size as the array grows.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
grid ¶
The distinct lengths each axis's chunks take.
Plural per axis, which is the point of a rectilinear grid: an
axis of [30, 34] gives {30, 34}, and anything asking about
divisibility has to hold for both.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
Every chunk extent, bare or run-length encoded, must be positive.
A run's count must be positive too: a run of zero chunks is a way of writing nothing at all, and the empty spelling already exists.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
shape_problems ¶
shape_problems(
array_shape: object,
) -> tuple[ValidationProblem, ...]
One spec per dimension, and explicit specs must cover it.
A bare integer is uniform shorthand, so it covers whatever the dimension turns out to be and imposes no sum; an explicit list names every chunk, so the names have to add up.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
to_json ¶
to_json() -> RectilinearChunkGridObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
RectilinearChunkGridConfiguration ¶
Bases: TypedDict
Configuration for the rectilinear chunk grid.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
RectilinearChunkGridObject ¶
Bases: TypedDict
Rectilinear chunk grid metadata in object form.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
canonical_chunk_shapes ¶
canonical_chunk_shapes(
chunk_shapes: tuple[RectilinearDimSpec, ...],
) -> tuple[RectilinearDimSpec, ...]
Every dimension's chunk sizes in their simplest equivalent form.
Source code in src/zarr_metadata/v3/chunk_grid/rectilinear.py
canonical_dim_spec ¶
canonical_dim_spec(
spec: RectilinearDimSpec,
) -> RectilinearDimSpec
One dimension's chunk sizes in their simplest equivalent form.
Runs of equal sizes collapse to [size, count] pairs, because that is
the spelling that does not grow with the number of chunks: a million
equal chunks is two numbers, not a million. A run of one stays a bare
size, and [size, 1] collapses to one, since a pair says nothing extra
there. Adjacent spellings of the same size merge, which is what makes
this idempotent: [[32, 2], 32] and [32, [32, 2]] both become
[[32, 3]].
A dimension-level bare integer is left alone. It is a step that
repeats until it covers the extent, so it is not equivalent to any
fixed list — expanding it would pin a grid that currently adapts, and
the two would diverge the moment the array were resized. For the same
reason a one-element list is never collapsed to a bare integer:
[32] declares exactly one chunk and 32 declares as many as it takes.
Assumes a spec the shape validator has already accepted.