Codec pipeline¶
The Zarr v3 codecs a store’s arrays declare, the compression choices
zarr-vectors-py offers, and Draco, an optional mesh encoding inside
chunk cells.
Terms¶
- Codec
A Zarr v3 transformation applied to chunk data on write and reversed on read, listed in
codecsin an array’szarr.json. The array-to-bytes codec (vlen-bytesorbytes) comes first; a compressor such aszstd,bloscorgzipmay follow.sharding_indexedThe Zarr v3 sharding codec. It packs several cells into one stored object with an index. See Sharding.
- Encoding
The
encodingattribute of averticesarray:"raw"(positions as little-endian values of the array’sdtype) or"draco"(each cell holds a Draco bitstream). It is not a Zarr codec.
Introduction¶
Every array uses only codecs that zarr-python 3 provides (zarr>=3.0,
numcodecs>=0.12), so a generic Zarr reader can decode every cell.
An unwritten cell of a per-chunk array reads as empty bytes; absent rows
of object attributes hold the array’s fill_value (see
Object attributes).
Compression is chosen when an array is created and does not change.
Draco is applied by the mesh writer inside each vertices cell; Zarr
sees the result as ordinary variable-length bytes.
Technical reference¶
Codecs by array kind¶
Array kind |
Array-to-bytes |
Compressor |
|---|---|---|
Per-chunk arrays ( |
|
the writer’s |
Object-index integer arrays (for example |
|
|
Other fixed-size arrays ( |
|
the write session’s compressor |
The compressor argument¶
The type writers and create_store take compressor, resolved by
zarr_vectors.encoding.compression.resolve_compressor:
|
Codecs after |
|---|---|
|
none |
|
|
|
|
a list of codec dicts |
the list as given |
Any other value raises ValueError. Every per-chunk array a call
creates gets the same codecs; there is no per-array choice. zarr_vectors.create() uses
Layout(compression="auto"), which resolves to "zstd", or to the
ZARR_VECTORS_COMPRESSION environment variable when it is set.
import json
import numpy as np
from zarr_vectors.types.points import write_points
rng = np.random.default_rng(0)
positions = rng.uniform(0, 200, (500, 3)).astype(np.float32)
write_points("gzip.zarrvectors", positions,
chunk_shape=(100.0, 100.0, 100.0),
compressor=[{"name": "gzip", "configuration": {"level": 5}}])
print(json.load(open("gzip.zarrvectors/0/vertices/zarr.json"))["codecs"])
[{'name': 'vlen-bytes', 'configuration': {}}, {'name': 'gzip', 'configuration': {'level': 5}}]
With sharding¶
A sharded array has a single sharding_indexed codec. Its
configuration holds the per-cell codecs and an index encoded with
bytes and crc32c. For compressor="zstd" and shard_shape=2 on a
3-D store:
[{"name": "sharding_indexed",
"configuration": {
"chunk_shape": [1, 1, 1],
"codecs": [{"name": "vlen-bytes", "configuration": {}},
{"name": "zstd", "configuration": {"level": 0, "checksum": false}}],
"index_codecs": [{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "crc32c"}],
"index_location": "end"}}]
The array’s chunk_grid then has chunk shape [2, 2, 2]. An octree
store uses the zarr_octree_sharding codec from the zarr-octree
package instead; see Octree chunks.
Draco mesh encoding¶
write_mesh(..., encoding="draco", draco_quantization_bits=11) writes
each chunk’s vertices and intra-chunk faces as one Draco bitstream in
the chunk’s vertices cell, and sets "encoding": "draco". Faces that
cross chunks stay in links/.
Draco applies only to 3-D triangle meshes. A store of another dimensionality is written
"raw"; faces that are not triangles raiseArrayError.Positions are quantised to
draco_quantization_bits(default 11) relative to the chunk’s bounding box, so they are lossy. The Draco compression level is fixed at 7.A chunk is a single fragment shared by all its objects, so
read_mesh(object_ids=...)raisesArrayError.Encoding needs
DracoPy(extrazarr-vectors[draco]) or thedraco_encoderanddraco_decodertools; with neither,DracoErroris raised.
See Mesh.
The vlen-bytes serializer¶
The Zarr v3 specification of variable-length bytes is not final
(zarr-extensions),
and zarr-python emits UnstableSpecificationWarning when it opens such an
array. Importing zarr_vectors silences that warning. Stores may need
re-encoding if the final specification is incompatible.
Validation¶
No level inspects codec lists. Level 3 (validate/consistency.py)
decodes cells, so a cell that cannot be decoded is reported there. See
Validation.