neu_morpho.measure.compartments

Per-body volume split by semantic compartment, from two aligned volumes.

Gives each body its own somatic fraction, for the variant column. Reads the segmentation and semantic blocks over the same voxel indices and counts (body_id, semantic_label) pairs:

  • The grids must coincide (same voxel size and origin at the chosen level, differing only in far-edge padding); checked at open time.

  • Label 0 is counted too, so sum over labels == the body's total is exact, and verify_compartments() checks it against a volume sweep’s totals, which shows whether a block filter lost anything.

non_somatic = total - (nucleus + soma).

Attributes

Functions

joint_counts(seg, sem[, background]) → dict[tuple[int, int], int]

{(body_id, semantic_label): voxels} for one block.

semantic_label_names(semantic_url) → dict[int, str]

{label: name} from the semantic volume's own segment_properties.

somatic_labels(semantic_url[, names]) → list[int]

The label ids for names, raising if any is missing.

sweep_compartments(seg_spec, sem_spec, db_path, *, ...) → dict

Count (body, semantic_label) pairs into db_path's compartment table.

verify_compartments(db_path, *[, tolerance]) → dict

Check each body's per-label sum against the total a volume sweep recorded.

Module Contents

neu_morpho.measure.compartments.joint_counts(seg: numpy.ndarray, sem: numpy.ndarray, background: int = 0) → dict[tuple[int, int], int]

{(body_id, semantic_label): voxels} for one block.

Background segmentation is dropped (no body there); background semantic is kept, because “this body’s tissue carries no compartment label” is an answer.

neu_morpho.measure.compartments.semantic_label_names(semantic_url: str) → dict[int, str]

{label: name} from the semantic volume’s own segment_properties.

neu_morpho.measure.compartments.somatic_labels(semantic_url: str, names: Iterable[str] = SOMATIC_NAMES) → list[int]

The label ids for names, raising if any is missing.

neu_morpho.measure.compartments.sweep_compartments(seg_spec: dict, sem_spec: dict, db_path: str, *, sem_shape: Sequence[int], block: int = DEFAULT_BLOCK, keep: Iterable[int] | None = None, blocks: Iterable[tuple] | None = None, roi: Sequence[int] | str | None = None, background: int = 0, attempts: int = 5, client: Any | None = None, npartitions: int | None = None, resume: bool = True) → dict

Count (body, semantic_label) pairs into db_path’s compartment table.

blocks optionally restricts the work to a set of block indices, such as an occupancy grid from the segmentation’s own coarse level (which, unlike an anatomical ROI, cannot omit a soma). verify_compartments() shows afterwards whether anything was missed.

neu_morpho.measure.compartments.verify_compartments(db_path: str, *, tolerance: int = 0) → dict

Check each body’s per-label sum against the total a volume sweep recorded.

A coarse occupancy grid can drop a block holding data; the volume sweep read every block, so its totals are ground truth, and this names any body that falls short.

neu_morpho.measure.compartments.SOMATIC_NAMES = ('nucleus', 'soma')