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 theoverlappolicy.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; withfill_gapsthe blocks no part claims keep the top-level id. It is cut from thetoplayer’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¶
ROIs placed as siblings overlap too much to be imprecise neighbours. |
|
The ROI layer spec is malformed, or disagrees with the node. |
Classes¶
Functions¶
|
Fetch the node's ROIs, resolve the spec's layers and write them under |
|
Problems between the spec and the node's ROIs; empty if none. |
|
|
|
The regions of every ROI the spec reads, after checking the spec against the |
|
The |
|
The DVID ROIs a layer's segments are, in its priority order, for labelling synapses |
|
|
|
|
|
Label the grid with |
|
|
|
|
|
The layer's |
|
DVID's |
|
Every layer (or those named in |
|
|
|
|
|
|
Module Contents¶
- exception neu_mark.roi_layers.NestedRois¶
Bases:
ValueErrorROIs 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:
ValueErrorThe 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:
shapeblocks from blocklo.- 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 blocklo(zyx).- property hi: numpy.ndarray¶
- lo: numpy.ndarray¶
- mask: numpy.ndarray¶
- property size: int¶
- class neu_mark.roi_layers.Spec¶
-
- 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]¶
- 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 itssegment_properties;<dst>/rois.jsonrecords the ids, the overlaps and the node.dry_runresolves 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.
availablenames the node’s ROIs andsizes({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
SpecErrorlisting every disagreement.
- neu_mark.roi_layers.grid_frame(like: str, grid: Grid)¶
The
neu_lib.Frameof the grid: blocks of 32 voxels oflike’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.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).withinlimits every member to a boolean region of the grid. Returns the labels and the overlapping pairs(earlier, later, blocks). RaisesNestedRoisfor a pair overlapping by more thanmax_overlapof the smaller, andValueErrorfor any overlap underpolicy="error".
- neu_mark.roi_layers.parse_node_url(url: str) dict[str, str]¶
dvid://SERVER/UUIDas a spec forneu_vol.dvid, which addresses a node’s ROIs through any instance name.
- neu_mark.roi_layers.properties(spec: Spec, layer_name: str, labels: numpy.ndarray, block_nm: Sequence[float]) dict¶
The layer’s
segment_propertiesdocument: name, description, tags, volume.
- neu_mark.roi_layers.region_from_ranges(ranges: numpy.ndarray) Region¶
DVID’s
[z, y, x0, x1]ranges (x1inclusive) as aRegion.
- 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.write_layer(dst: str, labels: numpy.ndarray, frame, *, overwrite: bool, tmp: str) dict¶
labelsas a precomputed segmentation atdst, 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¶