Pyramid construction¶
Terms¶
- Metavertex
A vertex of a coarser level that replaces every source vertex in one of its bins, placed at their centroid.
- Coarsen factor
The
coarsen_factorofcoarsen_level(first value of eachbuild_pyramidfactor pair). The target bin shape is the source bin shape times this factor, so factors compound:[(2, 1), (2, 1), (2, 1)]gives bins 2, 4 and 8 times the root’s.- Coarsening method
The function that builds a coarser level, named by
method=. Core providesper_object.- Chunk scale factor
The
chunk_scale_factorofcoarsen_level(each entry ofbuild_pyramid’schunk_scale_factors): a positive integer per axis that multiplies the source level’schunk_shape.
The sparsity factor is defined in Object sparsity; cross-level links in Links.
Introduction¶
Levels 1, 2, … hold coarser copies of level 0. build_pyramid
builds them in sequence; coarsen_level builds one. This page specifies
what the core per_object method writes. For a walk-through, see the
pyramid tutorial.
Technical reference¶
Methods and strategies¶
Core provides the per_object method and the random selection
strategy. Other method= and sparsity_strategy= names are looked up
in implementations registered with
zarr_vectors.building.register_coarsen_strategy or
register_selection_strategy. Importing zarr-vectors-tools registers
the methods polyline and skeleton and the strategies in
Object sparsity. An unregistered name raises ValueError
naming the package to install. options= passes keywords to a
registered method; per_object raises CoarseningError if given any.
What per_object writes¶
Part |
Target level |
|---|---|
Bins |
Source bin shape (root |
Vertices and fragments |
Each metavertex ( |
Object index |
A kept object’s manifest names the fragments of the metavertices its source vertices fall in, in source order, with consecutive repeats removed. Every source id has a row; dropped objects are empty. A source with no object index is coarsened as one object and the target has no object index. |
Object attributes |
Copied for kept objects; a dropped object’s row holds the array’s |
Not written |
|
Level attributes:
Key |
Value |
|---|---|
|
|
|
The source level |
|
|
|
Number of metavertices |
|
|
|
Only when it differs from the root’s |
|
|
|
Source object count when it has an object index, else |
|
|
|
The target bin shape |
|
|
The level gets an entry, {"asset": "<level>"}, in the root
multiscales layout. The root’s
format_capabilities gains shared_fragments, and
preserved_object_ids when the level has an object index.
coarsen_level raises CoarseningError if the target level exists. If
a step fails part way, it removes the target level, any links/+1
family it added to the source level, and the root attributes it set. A
links/+1 family the source level already had (a half-removed pyramid
leaves one) is put back as it was. A registered method gets the same
rollback.
build_pyramid is all or nothing: if any step or the cross-level pass
fails, it removes every level it created and restores the root’s and the
existing levels’ attributes and cross-level link families, then raises.
build_pyramid and coarsen_level¶
def build_pyramid(
store_path,
*,
factors: list[tuple[float, float]],
chunk_scale_factors: list[int | tuple[int, ...]] | None = None,
sparsity_strategy: str = "random",
sparsity_seed: int | None = None,
cross_level_depth: int = 1,
cross_level_storage: str = "explicit",
method: str = "per_object",
options: dict | None = None,
sparsity_attribute: str | None = None,
sparsity_attribute_mode: str = "max",
) -> dict
def coarsen_level(
store_path,
source_level: int,
target_level: int,
*,
coarsen_factor: float = 1.0,
sparsity_factor: float = 1.0,
chunk_scale_factor: int | tuple[int, ...] = 1,
sparsity_strategy: str = "random",
sparsity_seed: int | None = None,
cross_level_storage: str = "none",
method: str = "per_object",
options: dict | None = None,
sparsity_attribute: str | None = None,
sparsity_attribute_mode: str = "max",
) -> dict
Both are in zarr_vectors.multiresolution.coarsen;
zarr_vectors.api.Dataset.build_pyramid calls build_pyramid on an
open dataset, and zarr_vectors.coarsen_methods() lists the method=
names the environment accepts. store_path may also be an open Group.
factors[i] is (coarsen_factor, sparsity_factor) for level i + 1,
built from level i; 1.0 leaves an axis unchanged. build_pyramid
returns levels_created, level_specs (one summary per level),
method, cross_level_depth and cross_level_storage.
sparsity_attribute and sparsity_attribute_mode are described in
Object sparsity.
A level chunked by an attribute keeps its bins when coarsened: the
target has the same leading bin axis and chunk_attribute_* metadata,
and a metavertex aggregates vertices of one bin only.
Per-level chunk grids (chunk_scale_factor)¶
target_chunk_shape = source_chunk_shape × chunk_scale_factor # per axis
A scalar applies to every axis; a tuple has sid_ndim positive
integers, so chunk grids nest. The level’s chunk_shape attribute is
written only when it differs from the root’s. Read a level’s chunk shape
with get_level_chunk_shape(root_meta, level_meta) and its integer
multiple of the root’s with chunk_scale_from_root(root_meta, level_meta) (both in zarr_vectors.core.metadata). Links between
levels with different grids use the
anchor.
Cross-level links¶
|
Deltas written |
|---|---|
|
none, whatever |
|
up to |
|
up to the number of levels minus one |
|
Written |
|---|---|
|
nothing |
|
|
|
|
Each record links a vertex to the metavertex it was merged into (for
N ≥ 2, the metavertex containing that one, N - 1 levels up). Every
vertex with a metavertex at the target level has one record. Families
have link_width: 2 and directed: true; endpoint 0 is the vertex at
the owning level.
coarsen_level writes only its own ±1 families, and only when
cross_level_storage is not "none" (its default). build_pyramid
writes deltas of 2 or more after every level exists. It records
cross_level_depth and cross_level_storage in the root attributes,
and adds multiscale_links to format_capabilities when links are
requested and the store has at least two levels. Example:
07_multiscale_links.ipynb.
Validation¶
Raised by |
Exception |
When |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
an entry of |
|
|
a |
|
|
the target level exists |
|
|
any level has octree chunks |
|
|
the source or target level has octree chunks |
L5 checks that levels are numbered from 0 without gaps and that no level has more vertices than the level before (see Validation overview).