neu_morpho.precomputed

Write neuroglancer precomputed meshes and skeletons (stage-2 output).

Meshes: write_mesh_info() (the info, once) and write_body_multires() (per-LOD octree fragments), encoded by vol2mesh.multires. Skeletons: the neuroglancer_skeletons format via osteoid’s Skeleton.to_precomputed — write_skeleton_info() and write_body_skeleton().

Axis order. Model space is physical nm, held zyx in memory; both formats store xyz. vol2mesh flips meshes internally and encode_skeleton() flips skeletons; getting it wrong mirrors skeletons through the z=x diagonal relative to their meshes.

Every write goes through neu-vol’s kvstore helpers, never open(), so output_dir may be a local path or an s3:// URL. Hence multires.build_info / encode_multilod_object (a dict and bytes), never write_info / write_object_mesh, which write to the local filesystem.

Attributes

Functions

check_quantization(cfg, chunk_shape_xyz, voxel_size_zyx, *) → None

Fail fast if Draco quantization would collapse triangles at a coarse LOD.

encode_skeleton(skeleton) → bytes

Encode a global-nm zyx skeleton as precomputed xyz bytes.

quantization_step_nm(cfg, chunk_shape_xyz) → float

Position resolution (nm) at the COARSEST LOD — the one that bites.

volume_exists(volume_dir) → bool

True if a precomputed info is present at volume_dir (one request; works on

write_body_multires(output_dir, body_id, mesh, cfg, *, ...) → int

Write one body's multi-resolution mesh; returns fragments written (0 if empty).

write_body_skeleton(output_dir, body_id, skeleton) → int

Write one body's skeleton blob; returns the vertex count (0 if empty).

write_mesh_info(output_dir, cfg, *[, transform, ...]) → None

Write the multi-resolution mesh info (once per output volume).

write_skeleton_info(output_dir, *[, transform, ...]) → None

Write the neuroglancer_skeletons info (once per output volume).

Module Contents

neu_morpho.precomputed.check_quantization(cfg: neu_morpho.config.MeshConfig, chunk_shape_xyz: Sequence[float], voxel_size_zyx: Sequence[float], *, min_ratio: float = 4.0) → None

Fail fast if Draco quantization would collapse triangles at a coarse LOD.

When the coarsest LOD’s step approaches the voxel size, decimated triangles quantize to zero area and Draco rejects the whole body (“All triangles are degenerate”); at 10 bits and scale 2 that was 29% of bodies.

neu_morpho.precomputed.encode_skeleton(skeleton) → bytes

Encode a global-nm zyx skeleton as precomputed xyz bytes.

The vertex attributes are normalized to SKELETON_VERTEX_ATTRIBUTES, so the blob matches the info. Unknown radii stay -1.

neu_morpho.precomputed.quantization_step_nm(cfg: neu_morpho.config.MeshConfig, chunk_shape_xyz: Sequence[float]) → float

Position resolution (nm) at the COARSEST LOD — the one that bites.

Draco spreads 2**bits steps across each octree cell, and a LOD-l cell is chunk * 2**l wide, so the step doubles per LOD.

neu_morpho.precomputed.volume_exists(volume_dir: str) → bool

True if a precomputed info is present at volume_dir (one request; works on object stores, where there is no directory to stat).

neu_morpho.precomputed.write_body_multires(output_dir: str, body_id: int, mesh, cfg: neu_morpho.config.MeshConfig, *, chunk_shape_xyz: Sequence[float], grid_origin_xyz: Sequence[float]) → int

Write one body’s multi-resolution mesh; returns fragments written (0 if empty).

LOD 0 is the assembled mesh; each coarser LOD decimates by cfg.lod_decimation_factor and is octree-partitioned. Writes <body> and <body>.index (unsharded multires). Vertices are nm; the info transform is identity. Cells count from grid_origin_xyz, which must lie below every vertex.

neu_morpho.precomputed.write_body_skeleton(output_dir: str, body_id: int, skeleton) → int

Write one body’s skeleton blob; returns the vertex count (0 if empty).

neu_morpho.precomputed.write_mesh_info(output_dir: str, cfg: neu_morpho.config.MeshConfig, *, transform=None, lod_scale_multiplier: float = 1.0) → None

Write the multi-resolution mesh info (once per output volume).

neu_morpho.precomputed.write_skeleton_info(output_dir: str, *, transform: Sequence[float] | None = None, vertex_attributes: Sequence[dict] | None = None) → None

Write the neuroglancer_skeletons info (once per output volume).

The transform is identity: vertices are already physical nm in the same model space as the meshes, so neuroglancer must not re-scale them.

neu_morpho.precomputed.IDENTITY_TRANSFORM = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]
neu_morpho.precomputed.SKELETON_VERTEX_ATTRIBUTES
neu_morpho.precomputed.VALID_QUANTIZATION_BITS = (10, 16)
neu_morpho.precomputed.WEBGL_SKELETON_ATTRIBUTE_DTYPES
neu_morpho.precomputed.logger