Algorithms¶
Streaming algorithms for graphs (and skeletons, which are graphs with a
tree convention), triangle meshes, streamline bundles and cortical
surfaces. They all read directly from a chunked Zarr Vectors store — no
full materialisation — and a subset write their results back to the same
store: per-vertex results via
zarr_vectors_tools._attributes.write_vertex_attribute, bundle summaries
as group attributes.
Matrix¶
Function |
Domain |
Returns |
|
|
Constraints |
|---|---|---|---|---|---|
|
graph |
distances, predecessors |
– |
– |
– |
|
graph |
path, cost, visited |
– |
– |
edge weights via attribute name |
|
graph |
labels, sizes |
✓ → |
– |
undirected |
|
graph |
coreness, sizes |
– |
– |
– |
|
graph |
labels, sizes |
– |
– |
– |
|
graph |
labels, modularity |
– |
– |
edge weights via attribute name |
|
mesh |
area, volume, Euler χ |
– |
✓ → per-object dicts |
triangle meshes ( |
|
mesh |
normals |
✓ → |
– |
triangle meshes |
|
mesh |
curvature |
✓ → |
– |
triangle meshes |
|
mesh |
hit position, chunk, face |
– |
– |
triangle meshes |
|
mesh |
hit t, position, chunk, face |
– |
– |
triangle meshes |
|
skeleton |
per-object cable length, node / leaf / branch / component counts, Strahler order, extent |
✓ → |
– |
EM and SWC-style skeleton stores |
|
streamlines |
object ids through a NIfTI mask or box, or ending in it |
– |
– |
reads only the chunks the region touches |
|
streamlines |
per-group table (count, length stats, tortuosity, endpoint centroids) |
✓ → |
– |
object groups required |
|
surface mesh |
per-parcel vertex count, surface area, map mean / std |
– |
– |
matches FreeSurfer |
|
surface mesh |
parcel of the vertex nearest each point |
– |
– |
surface stores |
|
surface mesh |
vertices in source order, faces, attributes, any kept surface |
– |
– |
surface stores (GIFTI / FreeSurfer ingest) |
|
any store with segment ids |
each store’s object id for a segment, the match for a picked object, each store’s object attributes |
– |
– |
|
Calling convention¶
All algorithms take a store path as the first argument and accept
level=0 (the resolution level to operate on) as a keyword:
from zarr_vectors_tools.algorithms import (
compute_connected_components,
compute_mesh_summary,
shortest_path,
)
cc = compute_connected_components("graph.zv", write_back=True)
summary = compute_mesh_summary("mesh.zv", per_object=True)
path = shortest_path("graph.zv", source=0, target=42, weight="cost")
Domain pages¶
Graph search —
bfs_distances,shortest_pathGraph components —
compute_connected_componentsGraph clustering —
compute_k_core,compute_label_propagation,compute_louvainMesh summary —
compute_mesh_summaryMesh attributes —
compute_vertex_normals,compute_mean_curvatureMesh queries —
closest_point,cast_ray
Cross-chunk handling¶
At format 0.9.0, connectivity is one family per level: every record
lives under links/<delta>/<offsets>/, and an intra-chunk record is
simply one whose offsets are all zero. There is no separate
cross_chunk_links/ group to read — a record that spans chunks is
distinguished by its offsets, not by its location.
Warning
The double-count trap. Before the links merge, read_links meant
intra-chunk only and had a sibling read_cross_chunk_links, so the
idiom was “loop read_chunk_links over every chunk, then add
read_cross_chunk_links”. read_links now returns the whole family,
so that idiom unions every intra-chunk edge twice — silently doubling
every degree, with no error and no exception. Code ported from the
pre-0.9 shape must do exactly one of:
call
read_links(level_group, delta=0)alone and drop the per-chunk loop; orkeep the per-chunk
read_chunk_linksloop and addread_cross_links(level_group, delta=0)— never bareread_links.
The supported filters live in zarr_vectors_tools.algorithms._links:
Helper |
Returns |
Use for |
|---|---|---|
|
Every record under |
Pairing with a per-chunk |
|
|
Batching reads before a whole-family decode |
|
Chunk tuples of every populated cross-chunk cell |
Bucketing cells to target chunks without decoding records ( |
read_cross_links is the sole definition of the cross filter — that
is why the module does not re-export a bare read_links. It filters on
decoded chunk identity rather than on the offsets segment name, because
store="duplicate" and perm_idx make the segment-to-record mapping
non-obvious, and read_links is the only public reader that reverses
perm_idx back to input order.
Note
links/<delta> is a group, not an array — its children are one array
per offsets segment. Naming the group where an array is expected fails
silently: list_chunks returns [] for it and the batch reader skips
any prefetch entry that is not an array, so every read falls back to a
serial GET with no warning. That is what link_prefetch_plan exists for:
it enumerates the segments so the plan names arrays and prefetch actually
happens.
How each algorithm resolves this:
Graph search, components, clustering: one whole-family
read_linksand no per-chunk loop. Weights come fromread_link_attributes(level_group, weight, delta=0), which enumerates in the same(segment, cell)order asread_links— that shared order is the only thing aligning row i to record i, so a length mismatch is treated as a partial or stale write and the weights are dropped back to unit.Mesh summary: per-chunk
read_chunk_linksfor the area / volume / edge accumulation, thenread_cross_linksfor the boundary records. Cross-chunk face records (arity ≥ 3) contribute their consecutive endpoint pairs to the Euler-characteristic dedup set, but their per-face area / volume is excluded;excluded_cross_face_edgesquantifies the gap.Mesh attributes (normals, curvature): per-chunk faces drive the computation, and
read_cross_linksidentifies boundary vertices, which are counted inincomplete_boundary_vertices. Their values are computed from intra-chunk faces only.Mesh queries (
closest_point,cast_ray): per-chunkread_chunk_linksonly — cross-chunk faces are not tested. For typical meshes this is a negligible minority.
See also¶
Multiresolution — building the levels these algorithms read.
Cross-level links — the
delta != 0families in the same layout.zarr_vectors_tools._attributes.write_vertex_attribute— the write-back surface used by the four functions above.