Streamlines, skeletons and surfaces¶
Region selection, filter trees and bundle summaries on streamline stores; metrics on skeleton stores; segment lookup across stores; and parcel summaries on cortical surfaces.
Streamlines¶
Function |
What it does |
Returns |
|---|---|---|
|
Streamlines through a region, reading only the chunks near it. |
sorted object ids |
|
Per group: streamline count, length statistics, mean tortuosity, start and end centroids. |
DataFrame, one row per group |
|
The rows |
DataFrame |
select_streamlines takes exactly one region: mask (a NIfTI path, a nibabel
image, or an array with mask_affine; needs the trk extra) or
box=(min_corner, max_corner) in RAS mm. mode is "path" (any part inside),
"endpoints" (either end) or "both_endpoints". reach is how far past the
region chunks are read (default: one chunk). A segment longer than reach can
jump over the region, so select at a fine level.
bundle_summary needs groups: TRX groups, LINC TRK labels or
zvtools merge --group-by. By default it computes from level 0 and writes
group_attributes/bundle_* to every level; level=N summarises and writes
level N only. Each bundle is flipped to agree along its main axis before
endpoints are averaged; orient_endpoints=False keeps them as stored. The
command zvtools bundles STORE does the same, with --level, --no-write,
--as-stored and --csv FILE.
from zarr_vectors_tools.algorithms import bundle_summary, select_streamlines
ids = select_streamlines("tracts.zv", box=([15, 25, 40], [30, 40, 50]))
bundle_summary("tracts.zv", write=False)[["streamline_count", "length_mean"]]
Filter trees¶
zarr_vectors_tools.filtering evaluates TrackVis-style filters: regions
(Sphere, Box, Slab, Disk, Mask), column comparisons (Column) and
group membership (InGroup), combined with & (and), | (or), ~ (not) and - (and not). A tree has a
JSON form (to_json, from_json). filtering.evaluate tests every segment
and defines the answer; IndexedEngine tests only segments near each region,
gives the same answer, and caches every leaf. The subpackage needs only numpy.
from zarr_vectors_tools.filtering import IndexedEngine, Passes, Sphere, load_tractogram
tracts = load_tractogram("tracts.zv") # level 0, RAS mm
tree = Passes(Sphere((20, 30, 45), 5)) - Passes(Sphere((45, 32, 32), 5))
accepted = IndexedEngine(tracts).evaluate(tree) # bool per streamline
Skeleton metrics¶
compute_skeleton_metrics(store, *, level=0, metrics=None, write=True, object_ids=None, executor=None) measures every object and returns a DataFrame
indexed by object_id. With write=True it stores each metric as
object_attributes/<metric>; object_ids needs write=False.
Metric |
Meaning |
|---|---|
|
sum of edge lengths, in store units |
|
distinct vertices; connected pieces |
|
vertices with at most one neighbour; with three or more |
|
Strahler order at the root (an SWC soma), else at the tip with the smallest (x, y, z) |
|
bounding-box size per axis; |
SegmentLink(stores, *, level=0) matches objects across stores by
object_attributes/segment_id, which skeleton and zvtools synapses stores
have. resolve(segment_id) gives the object id in each store,
link(store_name, object_id) does the same from one store’s object,
attributes(segment_id, {store_name: [names]}) reads attributes, and
resolve_many(ids) returns a DataFrame.
from zarr_vectors_tools.algorithms import SegmentLink, compute_skeleton_metrics
metrics = compute_skeleton_metrics("neurons.zv")
link = SegmentLink({"skeletons": "neurons.zv", "synapses": "synapses.zv"})
link.resolve(1) # {'skeletons': 0, 'synapses': 0}
Cortical surfaces¶
Function |
What it does |
Returns |
|---|---|---|
|
One hemisphere in the source file’s vertex order, with positions from any kept surface ( |
|
|
Per parcel, as FreeSurfer’s |
DataFrame indexed by (hemisphere, parcel): |
|
The parcel of the vertex nearest each point. |
DataFrame: |
from zarr_vectors_tools.algorithms import parcel_summary
parcel_summary("surf.zv", "aparc", metrics=["thickness"])
Converting surfaces: Surfaces.