neu_mark.dvid¶
Fetching annotations out of DVID, for a given set of bodies.
Addressing and version resolution come from neu_vol.dvid: a
dvid://server/uuid/instance URL, resolved once to a concrete node that the provenance
record names.
Point annotations are read per body from /label/<body>, which exists only when the
annotation instance is synced to a labelmap; that is checked up front. neuclease’s
fetch_elements_for_bodies is not used, because it cannot return relationships. Bodies
are fetched on a thread pool (the work is I/O bound), each with retry, and a body that
still fails is recorded rather than raised. The default of 8 threads is a courtesy to a
shared server, which answers overload with 503.
fetch_all_points() reads the whole instance by region instead, with each element’s
body from the synced labelmap, so every partner resolves.
Attributes¶
Functions¶
|
Every record in a keyvalue instance, fetched as a series of bounded key ranges. |
|
Every element of the instance, by region, with each one's body from the labelmap. |
|
Fetch the per-body records from a keyvalue instance. |
|
Fetch every element of every body, and join relationships to bodies. |
|
Bodies with at least this many synapses, with their pre/post counts. |
|
Exact |
|
|
|
Consecutive pairs of |
|
Add a |
|
The provenance record for this source, with whatever the caller wants added. |
|
Resolve and validate a body-annotation (keyvalue) source. |
|
Resolve a synapse-count source: a |
|
Resolve and validate a point-annotation source. Call this before anything else. |
|
Resolve the ref, check the instance type, and return the pinned spec. |
|
Boundaries subdividing |
|
The labelmap(s) an annotation instance is synced to, or raise explaining why not. |
|
Point a source at the |
Module Contents¶
- neu_mark.dvid.fetch_all_body_annotations(source: Mapping[str, Any], *, boundaries: Sequence[str] = DEFAULT_KEY_BOUNDARIES) dict[str, Any]¶
Every record in a keyvalue instance, fetched as a series of bounded key ranges.
Never calls
/keys, which on a large instance times out at DVID’s proxy (504). The instance is read askeyrangevaluesover ranges that cover the whole key space, so no total is needed, and values cost little more than keys. A range that fails is split (refine()) up toMAX_SPLIT_DEPTHtimes. Boundary keys arrive twice, since DVID’s bounds are inclusive; a repeat with a different value raises, as the snapshot would not be coherent.
- neu_mark.dvid.fetch_all_points(source: Mapping[str, Any], *, threads: int = DEFAULT_THREADS) dict[str, Any]¶
Every element of the instance, by region, with each one’s body from the labelmap.
The same tables as
fetch_points(), but complete: both ends of every relationship were fetched, so every partner resolves. Elements come fromneuclease.dvid.annotation.fetch_synapses_in_batches(DVID’s/blocks, in boxes,threadsprocesses) and bodies fromfetch_bodies_for_many_pointson the synced labelmap at the same node (supervoxel per point, then DVID’s whole supervoxel->body map). An element on background has body 0, whichconnectionstreats as no body.
- neu_mark.dvid.fetch_body_annotations(source: Mapping[str, Any], bodies: Sequence[int], *, batch_size: int = 10000) dict[str, Any]¶
Fetch the per-body records from a keyvalue instance.
Uses
fetch_keyvaluesrather than neuclease’sfetch_body_annotations, which raises on anystatusoutside a fixed vocabulary; statuses stay plain strings. Bodies with no record are absent from the result and listed inmissing.
- neu_mark.dvid.fetch_points(source: Mapping[str, Any], bodies: Sequence[int], *, threads: int = DEFAULT_THREADS, progress_every: int = 500) dict[str, Any]¶
Fetch every element of every body, and join relationships to bodies.
Returns
{"points", "relationships", "connections", "match", "failures", "elements"}.failuresis{body: message}for bodies that still failed after retries; the run continues without them.
- neu_mark.dvid.fetch_synapse_counts(source: Mapping[str, Any], *, min_total: int = 10, min_pre: int = 0, min_post: int = 0, limit: int | None = None)¶
Bodies with at least this many synapses, with their pre/post counts.
One ranked
thresholdquery onAllSynat the largest of the three minimums (AllSyncounts every type, so it is at least each one), then exact pre and post counts for the bodies it returns.Returns a DataFrame indexed 0..n with
body,pre,post,syn, ranked bysyndescending.
- neu_mark.dvid.fetch_synapse_counts_for(source: Mapping[str, Any], bodies: Sequence[int])¶
Exact
pre/post/synfor specific bodies, ignoring any threshold.fetch_synapse_counts()finds the bodies above a threshold; this counts a given list.
- neu_mark.dvid.fetch_voxel_counts(source: Mapping[str, Any], bodies: Sequence[int], *, batch_size: int = 1000) dict[int, int]¶
{body: voxels}at full resolution, from the labelmap’s own/sizes.Not from
labelsz, whose'Voxels'type returns an empty result, not an error, without a labelvol sync. About a minute for 20,000 bodies.
- neu_mark.dvid.key_ranges(boundaries: Sequence[str] = DEFAULT_KEY_BOUNDARIES) list[tuple[str, str]]¶
Consecutive pairs of
boundariesas(key1, key2)request bounds.DVID’s key ranges are inclusive at both ends, so consecutive ranges overlap by one key where a key equals a boundary (body
3is in both'2'..'3'and'3'..'4'). Collecting into a dict de-duplicates, but summing per-range counts overcounts.
- neu_mark.dvid.label_point_rois(source: Mapping[str, Any], points, rois: Sequence[str], *, on_overlap: str = 'warn', processes: int = 0) dict[str, Any]¶
Add a
roicolumn to a points frame: which neuropil each synapse falls in.Wraps
neuclease.dvid.roi.determine_point_rois, which builds one combined label volume from the ROIs at scale 5 and samples it at each point’s scale-0x/y/zcolumns.Overlapping ROIs: the combined volume is built by writing each ROI in turn, so in an intersection the ROI passed last wins. With
on_overlap="warn"the volume is unpacked again in reverse order (the fetch is not repeated), and the result reports how many synapses would be attributed differently (ambiguous,ambiguous_pairs).on_overlap="error"refuses instead; some datasets have subtracted variants such asINP(-ATL)(L)for a strict partition.
- neu_mark.dvid.node_record(source: Mapping[str, Any], **extra: Any) dict[str, Any]¶
The provenance record for this source, with whatever the caller wants added.
- neu_mark.dvid.open_bodies_source(src: Mapping[str, Any], *, prefer_locked: bool = False) dict[str, Any]¶
Resolve and validate a body-annotation (keyvalue) source.
- neu_mark.dvid.open_counts_source(src: Mapping[str, Any], *, prefer_locked: bool = False) dict[str, Any]¶
Resolve a synapse-count source: a
labelszindex, or the instance it indexes.
- neu_mark.dvid.open_points_source(src: Mapping[str, Any], *, prefer_locked: bool = False) dict[str, Any]¶
Resolve and validate a point-annotation source. Call this before anything else.
- neu_mark.dvid.open_source(spec: Mapping[str, Any], *, expect: str | tuple[str, ...], prefer_locked: bool = False) dict[str, Any]¶
Resolve the ref, check the instance type, and return the pinned spec.
The returned spec carries the concrete uuid, never the ref, so a branch that moves mid-run cannot leave a table half from one node and half from the next.
- neu_mark.dvid.refine(lo: str, hi: str) list[str]¶
Boundaries subdividing
[lo, hi]by appending one digit tolo.'1'..``’2’`` becomes'1', '10', '11', … '19', '2', since decimal-string keys sort lexicographically. A range that times out is split this way rather than retried, because the proxy’s time limit is fixed while the server’s speed varies with load.Candidates outside
(lo, hi)are dropped, so boundaries stay sorted;[lo, hi]is returned unchanged when none falls strictly between them (it cannot be split further).
- neu_mark.dvid.require_sync(source: Mapping[str, Any]) list[str]¶
The labelmap(s) an annotation instance is synced to, or raise explaining why not.
/label/<body>relies on the sync’s index, so without one every per-body fetch would fail.
- neu_mark.dvid.resolve_labelsz(source: Mapping[str, Any]) dict[str, Any]¶
Point a source at the
labelszinstance to query, from whatever was given.Accepts the
labelszinstance itself, or theannotationinstance it indexes (e.g.synapses), found through the labelsz instance’sBase.Syncs.
- neu_mark.dvid.BODY_INSTANCE = 'keyvalue'¶
- neu_mark.dvid.COUNT_INSTANCE = 'labelsz'¶
- neu_mark.dvid.DEFAULT_KEY_BOUNDARIES¶
- neu_mark.dvid.DEFAULT_THREADS = 8¶
- neu_mark.dvid.MAX_SPLIT_DEPTH = 2¶
- neu_mark.dvid.ON_OVERLAP = ('warn', 'error')¶
- neu_mark.dvid.POINT_INSTANCE = 'annotation'¶
- neu_mark.dvid.ROI_UNSPECIFIED = '<unspecified>'¶
- neu_mark.dvid.logger¶