neu_mark.roi_layers

DVID ROIs as precomputed segmentation layers, one label per voxel in each.

A DVID roi instance is a set of 32-voxel blocks of the scale-0 grid, and a node’s ROIs overlap: some nest (ME(L) in OL(L)), some are siblings drawn imprecisely (GL21(L) bleeding into VMNP(L)). A segmentation holds one label per voxel, so a spec (load_spec()) sorts them into layers, each written as its own volume with every ROI’s id taken from one id table shared by all layers:

  • rois = [...]: those ROIs, overlaps settled by the overlap policy.

  • tree = "top": the top-level neuropils of the spec’s [neuropils] tree, each the union of its parts and its own ROI where the node has one.

  • tree = "parts": each top-level neuropil’s region divided among its parts; with fill_gaps the blocks no part claims keep the top-level id. It is cut from the top layer’s regions, so the two nest exactly.

  • from = LAYER: the union of another layer as one label.

A one-label layer (from, or rois naming one ROI) may be cleaned up before writing, in this order: open_blocks (an opening, which drops specks and thin spurs), close_blocks (a closing, which bridges gaps and dents) and fill_holes (enclosed cavities filled). Radii are in ROI blocks, by a ball.

overlap = "split" gives a contested block to the ROI it lies deepest inside (a distance transform of each ROI’s own mask, ties to the ROI listed first); "order" to the ROI listed first; "error" refuses. Siblings overlapping by more than max_overlap of the smaller are nested, not imprecise, and are refused under every policy.

Resolution works on DVID’s block ranges and needs no DVID; build() fetches them.

Attributes

Exceptions

NestedRois

ROIs placed as siblings overlap too much to be imprecise neighbours.

SpecError

The ROI layer spec is malformed, or disagrees with the node.

Classes

Grid

The block grid every layer shares: shape blocks from block lo.

Layer

Region

A boolean mask whose element (0, 0, 0) is block lo (zyx).

Spec

Functions

build(src, spec_path, like, dst, *[, layers, ...]) → dict

Fetch the node's ROIs, resolve the spec's layers and write them under dst.

check_against_node(spec, available[, sizes]) → list[str]

Problems between the spec and the node's ROIs; empty if none.

describe(name, names) → str

names' description for an ROI, its side and exclusion suffixes added.

fetch(src, spec, *[, prefer_locked, processes]) → dict

The regions of every ROI the spec reads, after checking the spec against the

grid_frame(like, grid)

The neu_lib.Frame of the grid: blocks of 32 voxels of like's level 0.

layer_rois(spec, name) → list[str]

The DVID ROIs a layer's segments are, in its priority order, for labelling synapses

load_spec(path) → Spec

open_node(src, *[, prefer_locked]) → tuple[dict, dict]

(spec, provenance) for a node URL, its ref resolved to a UUID once.

paint(grid, members, *, policy, max_overlap[, within, ...]) → tuple[numpy.ndarray, list[tuple[str, str, int]]]

Label the grid with members ((name, id, region), in priority order).

parse_node_url(url) → dict[str, str]

dvid://SERVER/UUID as a spec for neu_vol.dvid, which addresses a node's

parse_spec(raw, *[, where]) → Spec

properties(spec, layer_name, labels, block_nm) → dict

The layer's segment_properties document: name, description, tags, volume.

region_from_ranges(ranges) → Region

DVID's [z, y, x0, x1] ranges (x1 inclusive) as a Region.

resolve(spec, regions[, only]) → tuple[Grid, dict[str, dict]]

Every layer (or those named in only, plus what they are built from) as label

top_level(spec) → dict[str, str]

{part: its top-level neuropil}, a top-level neuropil without parts its own.

union(regions) → Region

write_layer(dst, labels, frame, *, overwrite, tmp) → dict

labels as a precomputed segmentation at dst, with a mode pyramid.

Module Contents

exception neu_mark.roi_layers.NestedRois

Bases: ValueError

ROIs placed as siblings overlap too much to be imprecise neighbours.

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

exception neu_mark.roi_layers.SpecError

Bases: ValueError

The ROI layer spec is malformed, or disagrees with the node.

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

class neu_mark.roi_layers.Grid

The block grid every layer shares: shape blocks from block lo.

view(arr: numpy.ndarray, region: Region) → numpy.ndarray
lo: numpy.ndarray
shape: tuple[int, int, int]
class neu_mark.roi_layers.Layer
property cleans: bool
close_blocks: int = 0
fill_gaps: bool = False
fill_holes: bool = False
property kind: str
label: str | None = None
name: str
open_blocks: int = 0
overlap: str = 'split'
rois: tuple[str, ...] = ()
source: str | None = None
tree: str | None = None
class neu_mark.roi_layers.Region

A boolean mask whose element (0, 0, 0) is block lo (zyx).

property hi: numpy.ndarray
lo: numpy.ndarray
mask: numpy.ndarray
property size: int
class neu_mark.roi_layers.Spec
layer(name: str) → Layer
optional_rois() → set[str]

Top-level neuropils with parts: read where the node has them, else built.

used_rois() → set[str]

Every DVID ROI the layers read. A top-level neuropil with parts is optional.

ids: dict[str, int]
ignore: dict[str, str]
layers: tuple[Layer, ...]
max_overlap: float = 0.2
names: dict[str, str]
neuropils: dict[str, tuple[str, ...]]
neu_mark.roi_layers.build(src: str, spec_path: str, like: str, dst: str, *, layers: Sequence[str] | None = None, overwrite: bool = False, dry_run: bool = False, prefer_locked: bool = False) → dict

Fetch the node’s ROIs, resolve the spec’s layers and write them under dst.

Each layer is <dst>/<layer>, a precomputed segmentation linked to its segment_properties; <dst>/rois.json records the ids, the overlaps and the node. dry_run resolves everything and writes nothing.

neu_mark.roi_layers.check_against_node(spec: Spec, available: Sequence[str], sizes: Mapping[str, int] | None = None) → list[str]

Problems between the spec and the node’s ROIs; empty if none.

available names the node’s ROIs and sizes ({name: blocks}) the fetched ones. Every ROI on the node must be used or ignored, so a new one is never dropped unseen.

neu_mark.roi_layers.describe(name: str, names: Mapping[str, str]) → str

names’ description for an ROI, its side and exclusion suffixes added.

neu_mark.roi_layers.fetch(src: str, spec: Spec, *, prefer_locked: bool = False, processes: int = 8) → dict

The regions of every ROI the spec reads, after checking the spec against the node’s list of ROIs. Raises SpecError listing every disagreement.

neu_mark.roi_layers.grid_frame(like: str, grid: Grid)

The neu_lib.Frame of the grid: blocks of 32 voxels of like’s level 0.

neu_mark.roi_layers.layer_rois(spec: Spec, name: str) → list[str]

The DVID ROIs a layer’s segments are, in its priority order, for labelling synapses with the same set (neu-mark points --rois SPEC.toml:LAYER).

neu_mark.roi_layers.load_spec(path: str) → Spec
neu_mark.roi_layers.open_node(src: str, *, prefer_locked: bool = False) → tuple[dict, dict]

(spec, provenance) for a node URL, its ref resolved to a UUID once.

neu_mark.roi_layers.paint(grid: Grid, members: Sequence[tuple[str, int, Region]], *, policy: str, max_overlap: float, within: numpy.ndarray | None = None, what: str = 'layer') → tuple[numpy.ndarray, list[tuple[str, str, int]]]

Label the grid with members ((name, id, region), in priority order).

within limits every member to a boolean region of the grid. Returns the labels and the overlapping pairs (earlier, later, blocks). Raises NestedRois for a pair overlapping by more than max_overlap of the smaller, and ValueError for any overlap under policy="error".

neu_mark.roi_layers.parse_node_url(url: str) → dict[str, str]

dvid://SERVER/UUID as a spec for neu_vol.dvid, which addresses a node’s ROIs through any instance name.

neu_mark.roi_layers.parse_spec(raw: Mapping[str, Any], *, where: str = 'spec') → Spec
neu_mark.roi_layers.properties(spec: Spec, layer_name: str, labels: numpy.ndarray, block_nm: Sequence[float]) → dict

The layer’s segment_properties document: name, description, tags, volume.

neu_mark.roi_layers.region_from_ranges(ranges: numpy.ndarray) → Region

DVID’s [z, y, x0, x1] ranges (x1 inclusive) as a Region.

neu_mark.roi_layers.resolve(spec: Spec, regions: Mapping[str, Region], only: Sequence[str] | None = None) → tuple[Grid, dict[str, dict]]

Every layer (or those named in only, plus what they are built from) as label arrays on one grid. Returns (grid, {layer: {"labels", "overlaps"}}).

neu_mark.roi_layers.top_level(spec: Spec) → dict[str, str]

{part: its top-level neuropil}, a top-level neuropil without parts its own.

neu_mark.roi_layers.union(regions: Sequence[Region]) → Region
neu_mark.roi_layers.write_layer(dst: str, labels: numpy.ndarray, frame, *, overwrite: bool, tmp: str) → dict

labels as a precomputed segmentation at dst, with a mode pyramid.

neu_mark.roi_layers.CHUNK = (64, 64, 64)
neu_mark.roi_layers.DEFAULT_MAX_OVERLAP = 0.2
neu_mark.roi_layers.POLICIES = ('split', 'order', 'error')
neu_mark.roi_layers.logger