neu_vol.readback

Read a body’s mesh and skeleton out of a published precomputed volume, local or remote.

The writers are in neu-morpho (neu_morpho.precomputed); reading needs no meshing stack, so it is here, where every package that views or measures a volume can use it. Formats: neuroglancer_multilod_draco and neuroglancer_legacy_mesh meshes, neuroglancer_skeletons, each sharded or not.

Coordinates come back in physical nm: each subresource’s info transform is applied. DracoPy (meshes) and osteoid (skeletons) are imported on first use.

Exceptions

UnsupportedSubresource

A mesh or skeleton subresource is in a form this module cannot decode.

Functions

mesh_body_ids(volume[, mesh_dir]) → list[int]

Sorted ids of the bodies with a mesh under volume/mesh_dir; [] for none.

mesh_transform(volume[, mesh_dir])

The mesh info's stored-model to nm transform, as a (3, 4) matrix.

read_body_mesh(volume, body_id[, lod, mesh_dir])

(vertices_xyz_nm, faces, lod) for one LOD, or None if absent.

read_body_skeleton(volume, body_id[, skeleton_dir, ...])

(vertices_xyz_nm, edges, radii_nm) for one body, or None if absent.

skeleton_transform(volume[, skeleton_dir])

The skeleton info's transform, as a (3, 4) matrix.

Module Contents

exception neu_vol.readback.UnsupportedSubresource

Bases: ValueError

A mesh or skeleton subresource is in a form this module cannot decode.

Distinct from a body with no mesh, which is an ordinary None: anything batching reads should let this propagate rather than count it as a missing body.

Initialize self. See help(type(self)) for accurate signature.

neu_vol.readback.mesh_body_ids(volume: str, mesh_dir: str | None = None) → list[int]

Sorted ids of the bodies with a mesh under volume/mesh_dir; [] for none.

mesh_dir defaults to the directory the volume’s info names under mesh, else mesh.

A multi-resolution mesh counts once its <id>.index manifest exists (neu-morpho writes it after the fragment data); a legacy mesh, once its <id>:0 manifest does. One listing of the directory. A sharded mesh raises UnsupportedSubresource: enumerating one means reading every minishard index (about a billion ids and 3.7 GB of index reads for one published fly CNS), so name the bodies explicitly instead.

neu_vol.readback.mesh_transform(volume: str, mesh_dir: str = 'mesh')

The mesh info’s stored-model to nm transform, as a (3, 4) matrix.

Identity included. read_body_mesh() has already applied it; this is for reporting it and recovering stored-model coordinates. Raises when there is no info at the location, since an identity answer to a mistyped path would be believed.

neu_vol.readback.read_body_mesh(volume: str, body_id: int, lod: int | None = None, mesh_dir: str = 'mesh')

(vertices_xyz_nm, faces, lod) for one LOD, or None if absent.

lod defaults to the coarsest present, the cheapest to draw; pass 0 for full detail. The LOD’s octree fragments are concatenated with face indices rebased. Sharded and unsharded meshes are both read, by the sharding key of the mesh info; a sharded read fetches only the requested LOD.

Vertices are always physical nm: stored coordinates go through the mesh info’s transform, with no opt-out. neu-morpho writes identity; a foreign source may not (one published source declares diag(16)). mesh_transform() reports it.

neu_vol.readback.read_body_skeleton(volume: str, body_id: int, skeleton_dir: str = 'skeleton', *, require_radii: bool = True)

(vertices_xyz_nm, edges, radii_nm) for one body, or None if absent.

Vertices come back xyz, the order the format stores, matching read_body_mesh() so the two overlay without a flip; the rest of the suite holds zyx in memory. They are physical nm, mapped through the skeleton info’s transform as the mesh reader maps its own. Sharded and unsharded skeletons are both read.

Raises if the skeleton has no usable radius attribute. With none declared, osteoid returns one -1 per vertex, which passes a length check and renders as an inverted tube, so negative radii are refused. require_radii=False returns radii_nm=None instead, for a source that publishes centrelines only.

neu_vol.readback.skeleton_transform(volume: str, skeleton_dir: str = 'skeleton')

The skeleton info’s transform, as a (3, 4) matrix.

Separate from mesh_transform() because a source declares the two independently.