neu_mark.tables

The table model: elements and relationships as DataFrames.

Coordinates are always named columns (z, y, x, to_z, …). DVID stores positions as [x, y, z], the suite holds zyx in memory and precomputed stores xyz, and a mix-up mirrors positions through the z=x diagonal with no error. Named columns cannot be transposed silently; positions_zyx() and positions_xyz() are the only places an (N, 3) array is built from a table, and the caller states the order.

A DVID relationship points at a coordinate, not a body ({"Rel": "PostSynTo", "To": [x, y, z]}); the partner body is found by joining that coordinate against the fetched elements, so it resolves only when both ends’ bodies were fetched. match_rate() reports how much resolved: a low rate means the body list is too small, and otherwise looks like a sparse connectome. Relationships are kept one row each, unmodified, and connections() derives the de-duplicated synapse view, using both directions since each is anchored on the body list at one end only.

Attributes

Functions

body_neuropil_fractions(points, *[, top_level, ...]) → pandas.DataFrame

Per body, the share of its synapses in each neuropil, as columns a rule can read.

body_roi_counts(points, *[, kind_column]) → pandas.DataFrame

Per body and kind, how many synapses fall in each ROI. Long form, lossless.

combine(frames) → tuple[pandas.DataFrame, pandas.DataFrame]

Concatenate per-body (points, rels) pairs and resolve partner bodies.

complete_tables(points, rels) → dict[str, Any]

The tables for a WHOLE instance, whose points carry a looked-up body.

connections(rels) → pandas.DataFrame

The oriented, de-duplicated synapse view over the raw relationship table.

elements_to_frames(elements, body) → tuple[pandas.DataFrame, pandas.DataFrame]

One body's /label response -> (points, relationships).

enrich_connections(conns, points[, columns]) → pandas.DataFrame

Bring per-element columns onto a connections table as pre_<col> / post_<col>.

keyvalues_to_frame(values) → pandas.DataFrame

{body_key: json} from a keyvalue instance -> one row per body.

match_rate(conns) → dict[str, Any]

How much of the connectivity the body list actually resolved.

position_index(points) → pandas.Series

(z, y, x) -> body for every fetched element.

positions_xyz(df[, prefix]) → numpy.ndarray

(N, 3) array of positions in xyz order, as DVID and precomputed store them.

positions_zyx(df[, prefix]) → numpy.ndarray

(N, 3) array of positions in zyx order.

resolve_partner_bodies(points, rels) → pandas.DataFrame

Fill to_body by joining each relationship's target against points.

Module Contents

neu_mark.tables.body_neuropil_fractions(points: pandas.DataFrame, *, top_level: Mapping[str, str] | None = None, kind_column: str = 'kind') → pandas.DataFrame

Per body, the share of its synapses in each neuropil, as columns a rule can read.

synapse_neuropils is {"pre": {roi: share}, "post": {...}, "all": {...}}, each share out of all that body’s synapses of that side, so a side’s shares sum to at most 1 and the rest lies in no ROI. With top_level ({roi: top-level neuropil}) a synapse_neuropils_top column groups the same counts by top-level neuropil. Each inner dict runs largest share first.

neu_mark.tables.body_roi_counts(points: pandas.DataFrame, *, kind_column: str = 'kind') → pandas.DataFrame

Per body and kind, how many synapses fall in each ROI. Long form, lossless.

A group-by over points, in the shape a tagging rule wants: where a neuron’s outputs sit often identifies it.

neu_mark.tables.combine(frames: Iterable[tuple[pandas.DataFrame, pandas.DataFrame]]) → tuple[pandas.DataFrame, pandas.DataFrame]

Concatenate per-body (points, rels) pairs and resolve partner bodies.

neu_mark.tables.complete_tables(points: pandas.DataFrame, rels: pandas.DataFrame) → dict[str, Any]

The tables for a WHOLE instance, whose points carry a looked-up body.

Each relationship’s own body comes from its element and its partner’s by the usual position join, which resolves for every partner because every element was fetched. In connections, body 0 (background) becomes null, so no line is indexed under body 0.

neu_mark.tables.connections(rels: pandas.DataFrame) → pandas.DataFrame

The oriented, de-duplicated synapse view over the raw relationship table.

One row per distinct (tbar, psd) coordinate pair, whichever direction it was seen from. Columns pre_z/pre_y/pre_x, post_z/post_y/post_x, pre_body, post_body.

Both relationship directions are used, then de-duplicated. Non-synaptic relationships are ignored here and stay in the raw table.

neu_mark.tables.elements_to_frames(elements: Sequence[Mapping[str, Any]], body: int) → tuple[pandas.DataFrame, pandas.DataFrame]

One body’s /label response -> (points, relationships).

Elements have Pos, Kind, Tags, Prop and Rels; every Prop key becomes a column. (neuclease.load_elements_as_dataframe drops the element’s body.)

neu_mark.tables.enrich_connections(conns: pandas.DataFrame, points: pandas.DataFrame, columns: Sequence[str] = ('conf',)) → pandas.DataFrame

Bring per-element columns onto a connections table as pre_<col> / post_<col>.

Joined from points on the coordinate (confidence, ROI, …). A value for a partner that was not fetched stays NaN rather than 0, which would claim zero confidence; NaN also fails shader comparisons, so a conf < threshold filter keeps such lines.

neu_mark.tables.keyvalues_to_frame(values: Mapping[str, Any]) → pandas.DataFrame

{body_key: json} from a keyvalue instance -> one row per body.

Records are ragged, so columns are the union of keys, with missing fields null. instance is the neuron’s name (CAm(L)), not a DVID data instance; the name is kept to match neuclease and neuprint. The raw record is kept in a json column.

neu_mark.tables.match_rate(conns: pandas.DataFrame) → dict[str, Any]

How much of the connectivity the body list actually resolved.

A low fraction looks the same as a sparse connectome once the tables are written.

neu_mark.tables.position_index(points: pandas.DataFrame) → pandas.Series

(z, y, x) -> body for every fetched element.

Raises if two elements share a position, which would make the partner join ambiguous.

neu_mark.tables.positions_xyz(df: pandas.DataFrame, prefix: str = '') → numpy.ndarray

(N, 3) array of positions in xyz order, as DVID and precomputed store them.

neu_mark.tables.positions_zyx(df: pandas.DataFrame, prefix: str = '') → numpy.ndarray

(N, 3) array of positions in zyx order.

With positions_xyz(), the only place named coordinate columns become an array.

neu_mark.tables.resolve_partner_bodies(points: pandas.DataFrame, rels: pandas.DataFrame) → pandas.DataFrame

Fill to_body by joining each relationship’s target against points.

NA where the target was not fetched. Nullable UInt64, never float, which would round large body ids.

neu_mark.tables.AXES = ('z', 'y', 'x')
neu_mark.tables.BODY_DTYPE
neu_mark.tables.COORD_DTYPE
neu_mark.tables.DVID_AXES = ('x', 'y', 'z')
neu_mark.tables.NO_BODY = 0
neu_mark.tables.SYNAPTIC_RELS