Geometry types

Read and write functions per geometry type. Each takes a path or URL, a Zarr store or an open group, and the readers return a dict.

zarr_vectors.types is undecided: treat it as internal. Its writers are supported through Building stores. Level.read() in Data API covers its readers, except per-vertex attributes on some geometries.

Point clouds

Point cloud I/O for ZV (Zarr Vectors) stores.

Supports three point cloud variants:

  1. Undifferentiated — no per-point object identity. All points in a chunk form a single fragment. No object_index.

  2. Per-point objects — each point is its own object (e.g. cell centroids). One fragment per point per chunk. Object index maps point ID → (chunk, fragment_index).

  3. Multi-point objects — many points per object (e.g. transcript spots grouped into cells). Points sharing an object_id are stored in one fragment per chunk. Object index maps object → chunks.

zarr_vectors.types.points.read_points(store_path, *, level=0, bbox=None, object_ids=None, group_ids=None, chunks=None, attribute_names=None, attribute_filter=None, backend=None)[source]

Read point cloud data from a ZV store.

Supports filtering by bounding box, object ID, group ID, or chunk whitelist. Filters AND together — every filter that is supplied must accept a point for it to appear in the output.

Parameters:
  • store_path (ReadSource) – URL or path to the ZV store, a pre-built zarr Store, or an already-open Group.

  • level (int) – Resolution level to read (default 0).

  • bbox (BoundingBox | None) – Optional bounding box filter as (min_corner, max_corner).

  • object_ids (list[int] | None) – Optional list of object IDs to read.

  • group_ids (list[int] | None) – Optional list of group IDs — expands to their object IDs.

  • chunks (list[ChunkCoords] | None) – Optional whitelist of chunk coordinate tuples; only data in those chunks is returned. chunks=[] yields an empty result; chunks=None (default) applies no chunk filter.

  • attribute_names (list[str] | None) – Attributes to read. None reads none – the parameter names what to fetch, it does not mean “all”. Level.read() resolves attributes="all" into an explicit list before calling this.

  • attribute_filter (dict[str, Any] | None)

  • backend (str | None)

Returns:

  • positions: (M, D) array of vertex positions

  • vertex_attributes: {name: array} of per-vertex attributes

  • object_ids: (M,) array of object IDs per vertex (if objects exist)

  • vertex_count: total vertices returned

Return type:

Dict with keys

zarr_vectors.types.points.write_points(store_path, positions, *, chunk_shape=None, bin_shape=None, bounds=None, vertex_attributes=None, object_ids=None, object_attributes=None, fragment_attributes=None, groups=None, group_attributes=None, dtype='float32', backend=None, chunk_by_attribute=None, out_of_bounds='raise', compressor=None, shard_shape='inherit', attributes=None)[source]

Write a point cloud to a new ZV store.

Parameters:
  • store_path (WriteTarget) – Path for the new store (must not exist).

  • positions (npt.NDArray[np.floating]) – (N, D) vertex positions.

  • chunk_shape (ChunkShape | None) – Spatial chunk size per dimension. If None, a single chunk containing all points is used.

  • bin_shape (BinShape | None) – Supervoxel bin edge lengths. If None, defaults to chunk_shape (one bin per chunk — backward compatible).

  • vertex_attributes (dict[str, npt.NDArray] | None) – Per-vertex attributes {name: array}. (Spec name; replaces the deprecated attributes kwarg.)

  • object_ids (npt.NDArray[np.integer] | None) – (N,) integer per-point object assignment.

  • object_attributes (dict[str, npt.NDArray] | None) – Per-object attributes {name: array}.

  • fragment_attributes (dict[str, dict[ChunkCoords, npt.NDArray]] | None) – Per-fragment attributes, keyed per chunk: {name: {chunk_coords: ndarray}}. Each per-chunk ndarray has shape (num_fragments_in_chunk,) or (num_fragments_in_chunk, C) and is aligned with the fragment ordering this writer produces for that chunk. Use case (opt-in): materialize per-fragment parent-IDs (e.g. the OID owning each fragment as object_id).

  • groups (dict[int, list[int]] | None) – Group memberships {group_id: [object_id, ...]}.

  • group_attributes (dict[str, npt.NDArray] | None) – Per-group attributes {name: array}.

  • dtype (str) – Numpy dtype string for vertex positions.

  • chunk_by_attribute (str | None) – If set, the named per-vertex categorical attribute (which must appear in vertex_attributes) becomes the leading chunk axis. Chunk keys gain a prefix, e.g. gene_bin.z.y.x. Vertices with mixed values within the same object are split across multiple attribute chunks. v1 supports integer / string dtypes only.

  • out_of_bounds (str) – Policy for vertices outside the store’s current bounds. "raise" (default) rejects the write, "ignore" drops out-of-bounds vertices (and their aligned per-vertex data), "expand" grows the store’s bounds to include all input vertices.

  • bounds (tuple[list[float], list[float]] | None)

  • backend (str | None)

  • compressor (Any)

  • shard_shape (int | tuple[int, ...] | None | Literal['inherit'])

  • attributes (dict[str, npt.NDArray] | None)

Returns:

Summary dict.

Return type:

dict[str, Any]

Lines

Finite line and vector I/O for zarr vectors stores.

A finite line is two endpoints stored as a two-vertex object. Connectivity is implicit sequential (vertex 0 → vertex 1), so no links array is needed.

Lines that cross a chunk boundary are split into two single-vertex fragments in their respective chunks, with the object_index tracking both and a links/0/<offsets>/ record bridging them. Only boundary-crossing lines produce a record: a line wholly inside one chunk needs none, since its two endpoints are already sequential.

zarr_vectors.types.lines.read_lines(store_path, *, level=0, object_ids=None, bbox=None, attribute_filter=None, backend=None)[source]

Read finite lines from a zarr vectors store.

Parameters:
  • store_path (ReadSource) – URL or path to the store, a pre-built zarr Store, or an already-open Group.

  • level (int) – Resolution level.

  • object_ids (list[int] | None) – Optional list of line (object) IDs to read.

  • bbox (BoundingBox | None) – Optional bounding box filter (lines with any endpoint inside the box are returned).

  • attribute_filter (dict[str, Any] | None)

  • backend (str | None)

Returns:

  • endpoints: (M, 2, D) array of line endpoints

  • line_count: number of lines returned

Return type:

Dict with

zarr_vectors.types.lines.write_lines(store_path, endpoints, *, chunk_shape, bin_shape=None, bounds=None, vertex_attributes=None, object_attributes=None, dtype='float32', backend=None, chunk_by_attribute=None, out_of_bounds='raise', compressor=None, shard_shape='inherit', attributes=None, line_attributes=None)[source]

Write finite line segments to a new zarr vectors store.

Parameters:
  • store_path (WriteTarget) – Path for the new store.

  • endpoints (npt.NDArray[np.floating]) – (N, 2, D) array — N lines, each with 2 endpoints of D dimensions.

  • chunk_shape (ChunkShape) – Spatial chunk size per dimension.

  • vertex_attributes (dict[str, npt.NDArray] | None) – Per-vertex attributes as {name: (N, 2) or (N, 2, C)}. Two values per line (one per endpoint). (Spec name; replaces attributes.)

  • object_attributes (dict[str, npt.NDArray] | None) – Per-line (per-object) attributes as {name: (N,) or (N, C)}. (Spec name; replaces line_attributes.)

  • dtype (str) – Numpy dtype string for positions.

  • bin_shape (BinShape | None)

  • bounds (tuple[list[float], list[float]] | None)

  • backend (str | None)

  • chunk_by_attribute (str | None)

  • out_of_bounds (str)

  • compressor (Any)

  • shard_shape (int | tuple[int, ...] | None | Literal['inherit'])

  • attributes (dict[str, npt.NDArray] | None)

  • line_attributes (dict[str, npt.NDArray] | None)

Returns:

Summary dict with line_count, chunk_count, cross_chunk_count.

Return type:

dict[str, Any]

Polylines and streamlines

Polyline and streamline I/O for zarr vectors stores.

A polyline is an ordered sequence of vertices forming a connected path. Streamlines (from tractography) are polylines with additional per-object attributes like termination regions.

Polylines that cross chunk boundaries are split into segments. The object_index stores the ordered segment sequence for each polyline, and a links/0/<offsets>/ record connects the last vertex of one segment to the first vertex of the next. Within each segment, connectivity is implicit sequential (vertex i → vertex i+1), so only the segment-to-segment bridges are ever stored.

zarr_vectors.types.polylines.read_polylines(store_path, *, level=0, object_ids=None, group_ids=None, bbox=None, chunks=None, attribute_filter=None, backend=None)[source]

Read polylines/streamlines from a zarr vectors store.

Parameters:
  • store_path (ReadSource) – URL or path to the store, a pre-built zarr Store, or an already-open Group.

  • level (int) – Resolution level.

  • object_ids (list[int] | None) – Optional list of polyline (object) IDs.

  • group_ids (list[int] | None) – Optional group IDs — expands to their object IDs.

  • bbox (BoundingBox | None) – Optional bounding box filter. Returns polylines that have at least one segment in a matching chunk.

  • chunks (list[ChunkCoords] | None) – Optional whitelist of chunk coordinate tuples. Unlike bbox (which keeps the whole polyline if any segment matches), chunks crops at the segment level: only fragments stored in listed chunks are returned, and each surviving contiguous run becomes its own output polyline. A polyline whose middle segments lie in unlisted chunks may therefore appear in the result as multiple shorter polylines — the output polyline_count can exceed the input object_count. AND-ed with bbox when both are given (the effective whitelist is the intersection of the two chunk sets). chunks=[] yields an empty result; chunks=None (default) applies no chunk filter.

  • attribute_filter (dict[str, Any] | None)

  • backend (str | None)

Returns:

  • polylines: list of lists of arrays. polylines[i] is a list of segment arrays for polyline i (concatenate for full path).

  • object_ids: the source object ID of each returned polyline, same length and order as polylines. In the whole-object modes these are unique. Under chunks (segment-level crop) a single object can yield several output polylines, so IDs repeat — one entry per emitted polyline, not per object. This is what lets a caller re-associate the cropped runs of one object.

  • polyline_count: number of polylines returned.

  • vertex_count: total vertices across all returned polylines.

Return type:

Dict with

zarr_vectors.types.polylines.write_polylines(store_path, polylines, *, chunk_shape, bin_shape=None, bounds=None, vertex_attributes=None, object_attributes=None, fragment_attributes=None, groups=None, group_attributes=None, dtype='float32', geometry_type='streamline', backend=None, chunk_by_attribute=None, out_of_bounds='raise', compressor=None, shard_shape='inherit', manifest_layout=None)[source]

Write polylines/streamlines to a new zarr vectors store.

Parameters:
  • store_path (WriteTarget) – Path for the new store.

  • polylines (list[npt.NDArray[np.floating]]) – List of arrays, each (N_k, D) — one per polyline.

  • chunk_shape (ChunkShape) – Spatial chunk size per dimension.

  • vertex_attributes (dict[str, list[npt.NDArray]] | None) – Per-vertex attributes aligned with polylines. {name: [array_for_polyline_0, array_for_polyline_1, ...]} where each array is (N_k,) or (N_k, C).

  • object_attributes (dict[str, npt.NDArray] | None) – Per-polyline attributes. {name: (O,) or (O, C)} where O = number of polylines.

  • fragment_attributes (dict[str, dict[ChunkCoords, npt.NDArray]] | None) – Per-fragment attributes, keyed per chunk: {name: {chunk_coords: ndarray}}. Each per-chunk ndarray has shape (num_fragments_in_chunk,) or (num_fragments_in_chunk, C) and is aligned with the fragment ordering this writer produces for that chunk.

  • groups (dict[int, list[int]] | None) – Group memberships {group_id: [polyline_indices]}.

  • group_attributes (dict[str, npt.NDArray] | None) – Per-group attributes {name: (G,) or (G,C)}.

  • dtype (str) – Numpy dtype for positions.

  • geometry_type (str) – "streamline" or "polyline".

  • manifest_layout (str | None) – "dense" for a fixed-width object index (see create_store()); only used when this call creates the store.

  • bin_shape (BinShape | None)

  • bounds (tuple[list[float], list[float]] | None)

  • backend (str | None)

  • chunk_by_attribute (str | None)

  • out_of_bounds (str)

  • compressor (Any)

  • shard_shape (int | tuple[int, ...] | None | Literal['inherit'])

Returns:

Summary dict.

Return type:

dict[str, Any]

Graphs and skeletons

Graph and skeleton I/O for zarr vectors stores.

Supports two modes:

  • General graph: arbitrary undirected/directed edges. Every edge is stored explicitly in links/0/<offsets>/ — the all-zero offsets array holds the intra-chunk edges, the rest hold the boundary-crossing ones. links_convention: "explicit".

  • Skeleton (tree): nodes reordered depth-first, parent links mostly sequential. Only branch points (parent ≠ i−1) need an intra-chunk record, but every boundary-crossing edge is still explicit — implicit sequential order does not span chunks. _skeleton_edges() states the read rule. links_convention: "implicit_sequential_with_branches".

Edge attributes (weight, type, etc.) are stored in link_attributes/ mirroring the links/ family cell for cell.

zarr_vectors.types.graphs.read_graph(store_path, *, level=0, object_ids=None, bbox=None, chunks=None, attribute_filter=None, backend=None)[source]

Read a graph or skeleton from a zarr vectors store.

Parameters:
  • store_path (ReadSource) – URL or path to the store, a pre-built zarr Store, or an already-open Group.

  • level (int) – Resolution level.

  • object_ids (list[int] | None) – Optional object ID filter. Reads only the named objects’ vertices (via the object index) and the edges with both ends read; unknown ids are ignored, and a skeleton vertex whose parent was not read comes back as a root.

  • bbox (BoundingBox | None) – Optional bounding box filter.

  • chunks (list[ChunkCoords] | None) – Optional whitelist of chunk coordinate tuples; only nodes (and intra-chunk edges) in those chunks are returned. AND-ed with bbox and object_ids. Edges spanning a listed chunk and an unlisted chunk are dropped. chunks=[] yields an empty result; chunks=None (default) applies no filter.

  • attribute_filter (dict[str, Any] | None)

  • backend (str | None)

Returns:

  • positions: (N, D) node positions

  • edges: (M, 2) edge list (remapped to output indices)

  • node_count, edge_count

  • object_ids: (N,) each node’s object, only with object_ids=; nodes grouped by object in the order asked.

Return type:

Dict with

zarr_vectors.types.graphs.write_graph(store_path, positions, edges, *, chunk_shape, bin_shape=None, bounds=None, kind='graph', vertex_attributes=None, link_attributes=None, object_attributes=None, fragment_attributes=None, object_ids=None, dtype='float32', backend=None, chunk_by_attribute=None, out_of_bounds='raise', compressor=None, shard_shape='inherit', is_tree=None, node_attributes=None, edge_attributes=None)[source]

Write a graph or skeleton to a new zarr vectors store.

Parameters:
  • store_path (WriteTarget) – Path for the new store.

  • positions (npt.NDArray[np.floating]) – (N, D) node positions.

  • edges (npt.NDArray[np.integer]) – (M, 2) edge list (global vertex indices). For a skeleton each row is [child, parent], and a parent of -1 (SWC style) marks the child a root – no edge.

  • chunk_shape (ChunkShape) – Spatial chunk size per dimension.

  • kind (str) – "graph" (default — general graph, explicit links convention) or "skeleton" (depth-first reorder, implicit sequential with branches convention). Replaces the boolean is_tree kwarg.

  • vertex_attributes (dict[str, npt.NDArray] | None) – Per-node attributes {name: (N,) or (N,C)}. (Spec name; replaces node_attributes.)

  • link_attributes (dict[str, npt.NDArray] | None) – Per-edge attributes {name: (M,) or (M,C)}. (Spec name; replaces edge_attributes.) With kind="skeleton" every edge is then stored explicitly.

  • fragment_attributes (dict[str, dict[ChunkCoords, npt.NDArray]] | None) – Per-fragment attributes, keyed per chunk: {name: {chunk_coords: ndarray}}. Each per-chunk ndarray has shape (num_fragments_in_chunk,) or (num_fragments_in_chunk, C) and is aligned with the fragment ordering this writer produces for that chunk.

  • object_ids (npt.NDArray[np.integer] | None) – (N,) array assigning nodes to objects. If None, all nodes belong to object 0.

  • dtype (str) – Numpy dtype for positions.

  • bin_shape (BinShape | None)

  • bounds (tuple[list[float], list[float]] | None)

  • object_attributes (dict[str, npt.NDArray] | None)

  • backend (str | None)

  • chunk_by_attribute (str | None)

  • out_of_bounds (str)

  • compressor (Any)

  • shard_shape (int | tuple[int, ...] | None | Literal['inherit'])

  • is_tree (bool | None)

  • node_attributes (dict[str, npt.NDArray] | None)

  • edge_attributes (dict[str, npt.NDArray] | None)

Returns:

Summary dict.

Return type:

dict[str, Any]

Meshes

Mesh I/O for zarr vectors stores.

Supports two encoding modes:

  • Raw: vertex positions in vertices/, face indices in links/0/<offsets>/ (L=3 for triangles, L=4 for quads). Faces within one chunk land in the all-zero offsets array; faces spanning chunk boundaries land in the array naming the offsets between them.

  • Draco: each fragment is encoded as a Draco bitstream containing both positions and its own intra-chunk faces. Only the boundary- crossing faces remain in links/ — the bitstream is per-chunk and cannot carry them.

zarr_vectors.types.meshes.read_mesh(store_path, *, level=0, bbox=None, object_ids=None, chunks=None, attribute_filter=None, backend=None)[source]

Read a mesh from a zarr vectors store.

Parameters:
  • store_path (ReadSource) – URL or path to the store, a pre-built zarr Store, or an already-open Group.

  • level (int) – Resolution level.

  • bbox (BoundingBox | None) – Optional bounding box filter.

  • object_ids (list[int] | None) – Optional object ID filter. Only the named objects’ vertex fragments are read – found through the object index, not by scanning chunks – and only the faces whose every vertex belongs to one of them. Ids not in the store are ignored. Not available on Draco-encoded stores, where a chunk is one bitstream shared by every object in it.

  • chunks (list[ChunkCoords] | None) – Optional whitelist of chunk coordinate tuples; only data in those chunks is returned. AND-ed with bbox and object_ids. chunks=[] yields an empty result; chunks=None (default) applies no chunk filter.

  • attribute_filter (dict[str, Any] | None)

  • backend (str | None)

Returns:

  • vertices: (V, D) positions

  • faces: (F, L) face indices (remapped to output vertex order)

  • vertex_count, face_count

  • object_ids: (V,) owning object of each vertex – only when object_ids= was given. Vertices come back grouped by object, in the order the ids were asked for.

Return type:

Dict with

The named objects’ vertex rows and the links among their chunks.

Shared by the mesh and graph object reads. The object index names each object’s (chunk, fragment) pairs; links come from the link cells wholly inside the objects’ chunks (link_cells_within()), or also those touching them under touching (read whole, as a skeleton read needs to find roots). scope narrows the chunks read; aligned is the level’s link_fragments_aligned claim.

Returns (positions, owners, link_rows, fragment_starts) – rows grouped by object in the order asked for, each row’s object, links as output rows (-1 for an endpoint not ours), each fragment’s first output row – or None when no fragment is in scope.

Parameters:
Return type:

tuple[NDArray, NDArray[int64], NDArray[int64], NDArray[int64]] | None

zarr_vectors.types.meshes.write_mesh(store_path, vertices, faces, *, chunk_shape, bin_shape=None, bounds=None, encoding='raw', vertex_attributes=None, object_attributes=None, object_ids=None, dtype='float32', draco_quantization_bits=11, backend=None, chunk_by_attribute=None, out_of_bounds='raise', compressor=None, shard_shape='inherit')[source]

Write a mesh to a new zarr vectors store.

Parameters:
  • store_path (WriteTarget) – Path for the new store.

  • vertices (npt.NDArray[np.floating]) – (V, D) vertex positions.

  • faces (npt.NDArray[np.integer]) – (F, L) face index array (L=3 triangles, L=4 quads).

  • chunk_shape (ChunkShape) – Spatial chunk size per dimension.

  • encoding (str) – "raw" or "draco" (3-D triangles only; other vertices are written raw).

  • vertex_attributes (dict[str, npt.NDArray] | None) – Per-vertex attributes {name: (V,) or (V,C)}.

  • object_ids (npt.NDArray[np.integer] | None) – (V,) array assigning vertices to mesh objects. If None, all vertices belong to object 0.

  • dtype (str) – Numpy dtype for positions.

  • draco_quantization_bits (int) – For Draco encoding only.

  • bin_shape (BinShape | None)

  • bounds (tuple[list[float], list[float]] | None)

  • object_attributes (dict[str, npt.NDArray] | None)

  • backend (str | None)

  • chunk_by_attribute (str | None)

  • out_of_bounds (str)

  • compressor (Any)

  • shard_shape (int | tuple[int, ...] | None | Literal['inherit'])

Returns:

Summary dict.

Return type:

dict[str, Any]