Skeletons¶
A skeleton in Zarr Vectors is a tree-structured graph: every node has at most
one parent. ingest_swc covers the light-microscopy morphology case —
one reconstructed neuron per file, in the standard SWC text format. For
segment skeletons pulled out of an EM volume, see
Skeletons in EM.
SWC — ingest_swc¶
from zarr_vectors_tools.convert.ingest.swc import ingest_swc
summary = ingest_swc(
"neuron.swc",
"neuron.zv",
(50.0, 50.0, 50.0), # chunk_shape in the file's own units
compute_topological_depth=True, # edges from the soma
compute_strahler=True, # branching hierarchy
compute_node_kind=True, # soma / branch / continuation / terminal
preserve_header=True, # default — keep the # comment lines
)
Pure-Python parser, no extra to install. SWC is seven whitespace-separated
columns — ID type X Y Z radius parent_ID — and the ingest reads every
non-comment row with at least seven fields, remaps non-contiguous IDs to
dense indices, and drops edges whose parent is missing from the file
(orphans stay as isolated nodes). parent_ID == -1 marks a root.
Two per-node attributes are always written: radius from column 5, and
compartment from column 2 — the SWC type code, where 1 is soma, 2 axon,
3 basal dendrite, 4 apical dendrite.
What the three tree metrics mean¶
compute_topological_depthNumber of edges from each node back to the root. Path distance in topology, not in micrometres — it is unaffected by how densely the reconstruction was sampled, which makes it the right axis for comparing branch positions across neurons traced by different people.
compute_strahlerStrahler order. Terminal tips are order 1; when two branches of equal order
nmeet, the parent becomesn + 1; when unequal orders meet, the parent takes the larger. So the order at the soma summarises how deeply nested the whole arbor is, and low-order nodes are the fine distal twigs. Filtering tostrahler >= 3is a quick way to strip terminal detail and see the trunk.compute_node_kindA categorical label —
0 = soma,1 = branch(more than one child),2 = continuation(exactly one child),3 = terminal(no children). Most nodes in a dense reconstruction are continuations; selecting on kind gives you the branch and tip point sets directly, without recomputing the degree.
All three are computed in one pass over the parent-index array, so enabling all three costs the same as enabling one.
Note
The metrics are computed from a single root — the first node whose
parent is -1. An SWC holding several disconnected trees will produce
depths measured from only one of them.
preserve_header=True stores the #-prefixed comment lines in an
SWCHeader. Many tools stash coordinate_space and scaling annotations
there, and export needs them to write a file the original toolchain will
still read.
Per-segment metrics — compute_skeleton_metrics¶
One pass over a level’s chunks measures every object and stores the result as object attributes, indexed by object id:
from zarr_vectors_tools.algorithms.skeleton_metrics import compute_skeleton_metrics
df = compute_skeleton_metrics("flywire.zv", level=0) # writes object_attributes/*
df.sort_values("cable_length").tail()
The metrics are cable_length, node_count, leaf_count, branch_count,
component_count, max_strahler and extent (bounding-box size, one column
per axis).
Cross-chunk edges are included, and the boundary vertex igneous duplicates into both chunks counts once.
Strahler order is rooted at the stored root when there is one (SWC), otherwise at the tip with the smallest (x, y, z).
Objects a sparsity level emptied read 0, and NaN for
extent.Pass
metrics=[...]for a subset,write=Falseto only return the frame, andexecutor=to summarise chunks in parallel.
Cable length and counts are per level: a decimated level is shorter and has fewer nodes than level 0.
Note
The attribute sparsity strategy cannot yet pick objects by a stored metric:
no coarsener passes object attribute values through to it.
See also¶
Skeletons in EM — precomputed / CloudVolume sources