Chunk arrays¶
This page specifies the arrays inside a level group: the per-chunk arrays, one cell per spatial chunk, and the per-object arrays.
Terms¶
- Per-chunk array
A Zarr v3 array of
data_typevariable_length_byteswhose shape is the level’s chunk grid. Each cell holds one chunk’s payload as one byte blob; an empty chunk has no cell file.vertices/,vertex_fragments/,link_fragments/, and the arrays undervertex_attributes/,fragment_attributes/,links/andlink_attributes/are per-chunk arrays.- Chunk grid
The cells a level allocates for the store’s bounds. Along axis
i, withloandhithe rootboundsandcthe chunk shape, the grid’s origin isfloor(lo_i / c_i)and its length isfloor(hi_i / c_i) - origin_i + 1. The chunk at absolute coordinatekis cellk - origin. A level chunked by an attribute adds a leading bin axis to every per-chunk array.- Array metadata
The array’s
zarr_vectorsattribute: an object whosekindnames the array’s role and whose other keys (dtype,nonempty_chunks, …) describe it. The node also registers the convention with"zarr_conventions": [{"uuid": "66268a61-7833-4995-bbcb-233bb417dae5"}]. In Python,zarr_vectors.core.convention.unwrap_array_metaflattens it into the in-memory form, where the role is thezv_arraytag; on disk the key iszarr_vectors.kind.nonempty_chunksA key of the array metadata listing the dotted keys (
"i.j.k", absolute chunk coordinates) of the cells that hold data. When it is absent, the level’s presence is deferred (see Level groups): a reader must list or read the cells, and must not treat the array as empty.
Introduction¶
Each per-chunk quantity is one Zarr array with one cell per chunk, so reading one chunk of it is one object read. Per-object data is in ordinary arrays indexed by object or group. Which arrays each geometry type writes is on Directory structure.
Technical reference¶
Per-chunk array metadata¶
The zarr.json of vertices/ in an unsharded 3-D store with a 3 × 3 × 3
grid:
{
"shape": [3, 3, 3],
"data_type": "variable_length_bytes",
"chunk_grid": {"name": "regular", "configuration": {"chunk_shape": [1, 1, 1]}},
"chunk_key_encoding": {"name": "default", "configuration": {"separator": "/"}},
"fill_value": "",
"codecs": [{"name": "vlen-bytes", "configuration": {}}],
"attributes": {
"zarr_conventions": [{"uuid": "66268a61-7833-4995-bbcb-233bb417dae5"}],
"zarr_vectors": {
"kind": "vertices",
"nonempty_chunks": ["0.0.1", "0.1.1", "1.0.0", ...],
"dtype": "float32",
"encoding": "raw"
}
},
...
}
Every per-chunk array has this form; only the zarr_vectors object
differs.
Feature |
Rule |
|---|---|
Cells |
Cell |
Compression |
None by default. A writer’s |
Sharding |
With a root |
Grid origin |
A non-zero origin is stored as |
Keys of each per-chunk array’s zarr_vectors object, besides
nonempty_chunks and chunk_grid_origin:
Array |
Keys |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The in-memory zv_array tag equals kind except for two arrays: the
tag "attribute" is stored as "vertex_attribute", and
"groupings_attribute" as "group_attribute".
row_shape is the shape of one row after the first axis: [] for one
value per row, [3] for three. A three-column vertex attribute written
without names gets "channel_names": ["ch0", "ch1", "ch2"]. An array
without row_shape (an older store) has len(channel_names) columns,
or one.
A categorical vertex attribute stores integer codes and adds
encoding: "dictionary", categories (the values, indexed by code),
ordered and, optionally, _FillValue (the code read as missing).
Readers return categories[code].
fragment_attributes/object_id, written by
zarr_vectors.building.build_fragment_owner_index, holds the int64 id
of the object that owns each fragment: -1 when no manifest names it,
-2 when several do. It is derived from the manifests and is not
updated when they change.
The groups holding these arrays have empty attributes, except the link
family groups and object_index/ below.
Decoding a cell blob¶
A reader takes the element type from the dtype key of the array’s
zarr_vectors object and the row width from the metadata. Cells have no header except where stated.
Array |
Cell content |
|---|---|
|
|
|
A Draco-compressed mesh; |
|
|
|
One row of shape |
|
One row of shape |
|
Rows of |
Any other |
|
|
One row of shape |
N is not stored: it is the blob length divided by the row size, so use
the stored dtype. For a link array, W = link_width + 1 when has_perm
is true (the extra leading column is perm_idx), and W = link_width
otherwise.
Decoding cell (0, 0, 0) of vertices/ and of the intra-chunk link array
in a 3-D graph store:
import numpy as np
import zarr
level = zarr.open_group("graph.zarrvectors", mode="r")["0"]
verts = level["vertices"]
blob = verts[0:1, 0:1, 0:1].ravel()[0]
dtype = verts.attrs["zarr_vectors"]["dtype"]
positions = np.frombuffer(blob, dtype=dtype).reshape(-1, 3)
links = level["links/0/0.0.0"]
a = links.attrs["zarr_vectors"]
width = a["link_width"] + (1 if a["has_perm"] else 0)
blob = links[0:1, 0:1, 0:1].ravel()[0]
edges = np.frombuffer(blob, dtype=a["dtype"]).reshape(-1, width)
Link arrays¶
links/<delta>/ is a group with one per-chunk array per offsets segment.
<delta> is the level delta (0, +1, -1, …). <offsets> says where a
record’s other endpoints are relative to the cell that holds it: 0.0.0
within the cell, 0.0.+1 one chunk along the last axis, 0.0.0_0.0.0 for
a triangle wholly in the cell. Endpoint vi_0 indexes the cell’s own
vertices/ rows; vi_k indexes the rows of the chunk at the cell plus
offset k. The array’s offsets attribute holds the parsed segment, for
example [[0, 1, 1]] for 0.+1.+1. The grammar, placement rules and
perm_idx are on Links.
The family group’s attributes, from a graph store:
{
"zarr_conventions": [{"uuid": "66268a61-7833-4995-bbcb-233bb417dae5"}],
"zarr_vectors": {
"kind": "links_family",
"level_delta": 0,
"link_width": 2,
"directed": false,
"store": "canonical",
"sid_ndim": 3,
"num_links": 396,
"num_physical_records": 396
}
}
link_width is 2 for edges and 3 for triangles. Cross-level families
(+1, -1) from build_pyramid have "directed": true.
has_perm is true exactly for a non-intra array at delta 0 whose family is
undirected or has store "duplicate". Only the intra-chunk array at
delta 0 has a link_fragments/ sidecar.
link_attributes/<name>/<delta>/ mirrors links/<delta>/ array for array
and cell for cell. Its zarr_vectors object has kind
"link_attribute_family", name, level_delta and num_links.
Per-object arrays¶
These are ordinary arrays indexed by object or group, not by chunk. See Object manifest and Object attributes.
Path |
Shape and type |
|
|---|---|---|
|
— |
|
|
vlen layouts: |
none |
|
dense layout: |
none |
|
dense layout: |
none |
|
|
none |
|
|
|
|
|
|
|
|
|
Validation¶
L1 checks that every per-chunk array in a
level has the rank of vertices/, that every nonempty_chunks key has
that many components, and, on a level chunked by an attribute, that the
leading axis has one entry per chunk_attribute_values label. It warns
when a links/<delta>/ group has no arrays.
L3 checks that every vertices/ cell
decodes to rows of D finite values and that every manifest names an
existing chunk and fragment. For links it applies the checks listed under
Geometry types.