API reference: Streamlines¶
The curvilinear depth axis: a fixed Streamline, the spatially-varying
StreamlineField, and the field builder.
Streamline¶
Streamline ¶
Bases: object
Build a streamline object to determine distances from a curving pia-to-white matter axis
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
nx3 array
|
Set of points making up the streamline |
required |
tform
|
TransformSequence
|
A transform sequence, by default the identity transform. |
None
|
transform_points
|
bool
|
If points are in the pre-transform coordinates use True, if in the post-transform coordinates use False. By default True. |
True
|
anchor
|
3-element array
|
A default anchor point (pre-transform coordinates) for :meth: |
None
|
Source code in standard_transform/streamlines.py
streamline_at ¶
Location of the streamline passing through point xyz0 at depth y1 in the post-transform space (usually microns)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz0
|
3-element array
|
Anchor point through which the streamline passes |
required |
y1
|
float or array
|
Depth or depths at which to find the streamline x and z points. |
required |
return_as_point
|
bool
|
If True, return the x and z points as tuple, if False returns as an xyz point, by default False. |
False
|
Returns:
| Type | Description |
|---|---|
new_x, new_z : float or array
|
X and z coordinate values for the streamline at the given depths. |
Source code in standard_transform/streamlines.py
streamline_points_tform ¶
Returns the original streamline points at a location that passes through the given point in the pre-transform space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz0_raw
|
3-element array
|
Anchor point which the streamline passes through in the pre-transform space. |
required |
Returns:
| Type | Description |
|---|---|
nx3 array
|
Original streamline points transformed to pass through the given point. |
Source code in standard_transform/streamlines.py
radial_distance ¶
radial_distance(
xyz0, xyz1, transform_points=True, return_angle=False
) -> Union[np.ndarray, tuple]
Find the distance between two points along the x-z plane using the streamline as d=0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz0
|
3-element array
|
First point coordinates |
required |
xyz1
|
nx3 element array
|
One or more coordinates to find the radial distance to. |
required |
transform_points
|
bool
|
If points are in the pre-transform coordinates use True, if in the post-transform coordinates use False. By default True. |
True
|
return_angle
|
bool
|
If True, return the angle between the two points, by default False. The angle is in radians and is measured from the x-axis. |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Distance in the x-z plane after accounting for streamline curvature. |
Source code in standard_transform/streamlines.py
radial_points ¶
radial_points(
xyz0,
xyz1,
transform_points=True,
depth_along_streamline=True,
depth_from=0,
delta=0.1,
) -> np.ndarray
Returns points along the streamline at a given distance from an anchor point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz0
|
ndarray
|
3 element point, the anchor of the radial distance measure. |
required |
xyz1
|
ndarray
|
Nx3 array of points to transform. |
required |
transform_points
|
bool
|
Choose whether to transform points before computing radial distances and depths, by default True |
True
|
depth_along_streamline
|
bool
|
If True, use path length along streamline as depth rather than the raw y coordindate, by default True |
True
|
depth_from
|
int
|
Sets the post-transform y coordinate to use for zero depth, by default 0. |
0
|
delta
|
float
|
Sets the resolution of the depth measurement. Smaller values are more accurate, by default 0.1 |
0.1
|
Returns:
| Type | Description |
|---|---|
array
|
Nx3 array of points with the same radial distance relative to xyz0 and depth as the input points. The relative angle of x and z is maintained from the original coordinates. |
Source code in standard_transform/streamlines.py
depth_between ¶
Find the distance between two points along the depth axis using the streamline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz0
|
3-element array
|
First point coordinates |
required |
xyz1
|
3-element array
|
Second point coordinates |
required |
delta
|
float
|
Step size for the integration in post-transform coordinates, by default 0.1. |
0.1
|
transform_points
|
bool
|
If points are in the pre-transform coordinates use True, if in the post-transform coordinates use False. By default True. |
True
|
Returns:
| Type | Description |
|---|---|
float
|
Distance in the y-axis after accounting for streamline curvature. |
Source code in standard_transform/streamlines.py
depth_along ¶
Find the depth from pia along the streamline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz
|
nx3 array
|
Point coordinates |
required |
delta
|
float
|
Step size for the integration in post-transform coordinates, by default 0.1. |
0.1
|
transform_points
|
bool
|
If points are in the pre-transform coordinates use True, if in the post-transform coordinates use False. By default True. |
True
|
Returns:
| Type | Description |
|---|---|
float
|
Distance in the y-axis after accounting for streamline curvature. |
Source code in standard_transform/streamlines.py
transformer ¶
transformer(
anchor=None,
*,
transform_points=True,
depth_along_streamline=True,
depth_from=0,
delta=0.1,
)
Return a single-argument callable that straightens points along this streamline.
The returned function maps an (n, 3) array of points to an (n, 3) array
(via :meth:radial_points) with the anchor bound in. That fits transform
protocols that pass only the point array — e.g. Ossify's Cell.transform — so
no functools.partial/lambda is needed at the call site:
cell.transform(sl.transformer(cell.s.root_location), inplace=True)
For the per-neuron field workflow the anchor is remembered for you:
sl = field.streamline_at_point(soma) # stores soma as the anchor cell.transform(sl.transformer(), inplace=True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anchor
|
3-element array
|
Origin the straightening is measured from (typically a soma/root), in the
same coordinate space as the points passed to the returned function. If
omitted, uses the anchor stored on the streamline (e.g. set by
:meth: |
None
|
transform_points
|
Passed through to :meth: |
True
|
|
depth_along_streamline
|
Passed through to :meth: |
True
|
|
depth_from
|
Passed through to :meth: |
True
|
|
delta
|
Passed through to :meth: |
True
|
Returns:
| Type | Description |
|---|---|
callable
|
|
Source code in standard_transform/streamlines.py
transform_skeleton_vertices ¶
transform_skeleton_vertices(
sk,
root_loc=None,
depth_from=0,
delta=0.1,
inplace=False,
) -> meshparty.skeleton.Skeleton
Transforms skeleton vertices to the post-transform coordinate system via the radial points function.
.. deprecated::
Transforming morphology objects is moving to Ossify
(https://csdashm.com/ossify/), where the transformation is passed to the
object. Use :meth:radial_points on coordinate arrays instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sk
|
Skeleton
|
Skeleton to transform |
required |
root_loc
|
ndarray
|
3 element array of the root location, by default None. If none, selects the skeleton root. |
None
|
depth_from
|
numeric
|
Sets the post-transform y coordinate to use for zero depth, by default 0. |
0
|
delta
|
float
|
Sets the resolution of the depth measurement. Smaller values are more accurate, by default 0.1 |
0.1
|
inplace
|
bool
|
If True, transform the vertices in place, by default False |
False
|
Source code in standard_transform/streamlines.py
transform_meshwork_vertices ¶
transform_meshwork_vertices(
nrn,
root_loc=None,
depth_from=0,
delta=0.1,
inplace=False,
) -> meshparty.meshwork.Meshwork
Transforms meshwork vertices to the post-transform coordinate system.
.. deprecated::
Transforming morphology objects is moving to Ossify
(https://csdashm.com/ossify/), where the transformation is passed to the
object. Use :meth:radial_points on coordinate arrays instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_loc
|
ndarray
|
3 element array of the root location, by default None |
None
|
inplace
|
bool
|
If True, transform the vertices in place, by default False |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Nx3 array of transformed vertices |
Source code in standard_transform/streamlines.py
transform_meshwork_annotations ¶
transform_meshwork_annotations(
nrn,
anno_dict,
root_loc=None,
depth_from=0,
delta=0.1,
inplace=False,
) -> meshparty.meshwork.Meshwork
Transforms meshwork annotations to the post-transform coordinate system via the radial points function.
.. deprecated::
Transforming morphology objects is moving to Ossify
(https://csdashm.com/ossify/), where the transformation is passed to the
object. Use :meth:radial_points on coordinate arrays instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nrn
|
Meshwork
|
File to transform |
required |
anno_dict
|
dict
|
Dictionary whose keys are annotation tables in the meshwork and whose values are the columns to transform (string or list of strings) |
required |
root_loc
|
array - like
|
location of the root for computing radial points, by default None. If None, uses the root of the meshwork skeleton. |
None
|
depth_from
|
int
|
Sets the post-transform y coordinate to use for zero depth, by default 0. |
0
|
delta
|
float
|
Sets the resolution of the depth measurement. Smaller values are more accurate, by default 0.1 |
0.1
|
inplace
|
bool
|
If True, transform the vertices in place, by default False |
False
|
Returns:
| Type | Description |
|---|---|
meshwork
|
Object with transformed annotation positions. |
Source code in standard_transform/streamlines.py
StreamlineField¶
StreamlineField ¶
StreamlineField(
x_grid,
y_grid,
z_grid,
tangents,
confidence=None,
tform=None,
integration_step=None,
)
Bases: Streamline
A spatially-varying streamline defined by a 3D grid of tangent vectors.
Unlike :class:Streamline, which stores a single curve and translates it to
pass through any anchor point, a StreamlineField stores the local direction
of the pia-to-white-matter axis at every location. The streamline through a
point is obtained by integrating that field, so the shape varies across the
volume. A field that is uniform in x and z reproduces a single Streamline.
Grid values and all query points are in the post-transform (oriented micron)
space. The local tangent is stored as (dx/dy, dz/dy): the volume is
parametrized along depth y, so the y-component of the tangent is implicitly 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_grid
|
1d arrays
|
Strictly-ascending grid node coordinates along each axis, in post-transform microns. Each must have length >= 2. |
required |
y_grid
|
1d arrays
|
Strictly-ascending grid node coordinates along each axis, in post-transform microns. Each must have length >= 2. |
required |
z_grid
|
1d arrays
|
Strictly-ascending grid node coordinates along each axis, in post-transform microns. Each must have length >= 2. |
required |
tangents
|
(array, shape(nx, ny, nz, 2))
|
Local tangent |
required |
confidence
|
(array, shape(nx, ny, nz))
|
Per-node confidence, e.g. precision = count / variance, retained as a
coverage signal (see :meth: |
None
|
tform
|
TransformSequence
|
Transform mapping input coordinates into the grid's post-transform space, by default the identity transform. |
None
|
integration_step
|
float
|
Step size in y (microns) used when integrating streamlines through the field. By default None, which uses the grid's own y-spacing (the field is piecewise-linear between nodes, so a finer step adds no accuracy). |
None
|
Source code in standard_transform/streamlines.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |
streamline_at ¶
Location of the streamline through xyz0 at depth y1, integrated through the field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz0
|
3-element array
|
Anchor point (post-transform space) through which the streamline passes. |
required |
y1
|
float or array
|
Depth or depths at which to evaluate the streamline x and z. |
required |
return_as_point
|
bool
|
If True return an nx3 array, else return (new_x, new_z), by default False. |
False
|
Returns:
| Type | Description |
|---|---|
new_x, new_z : float or array
|
X and z coordinate values for the streamline at the given depths. |
Source code in standard_transform/streamlines.py
streamline_points_tform ¶
Streamline points passing through a pre-transform point, in pre-transform space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz0_raw
|
3-element array
|
Anchor point which the streamline passes through in the pre-transform space. |
required |
Returns:
| Type | Description |
|---|---|
nx3 array
|
Streamline points (sampled at the grid depths) in the pre-transform space. |
Source code in standard_transform/streamlines.py
streamline_at_point ¶
Extract the single streamline through a point (e.g. a cell body) as a Streamline.
This is the intended way to work with a neuron: integrate the field once at the
soma, get back an ordinary fixed-shape :class:Streamline, and apply that one
curve across the whole arbor. It deliberately does not re-derive the axis per
vertex — every vertex is measured against the streamline appropriate to its cell
body. That makes no assumption that the arbor's lateral extent follows the field
(it generally does not).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz
|
3-element array
|
Anchor point, typically the soma location. |
required |
transform_points
|
bool
|
If True, transform the anchor into the grid space first, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
Streamline
|
A fixed-shape streamline through the anchor, carrying this field's transform. |
Source code in standard_transform/streamlines.py
coverage_at ¶
Per-node confidence (precision) that informed the field near each query point.
Useful for flagging low-confidence regions (e.g. dataset edges) where the streamline rests on little or noisy data. Higher means better determined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyz
|
nx3 array
|
Query points. |
required |
transform_points
|
bool
|
If True, transform points into the grid space first, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Nearest-node confidence for each query point (zeros if none stored). |
Source code in standard_transform/streamlines.py
to_npz ¶
Save the field grid to a compressed .npz.
The transform itself is not stored (reattach one via :meth:from_npz), but the
transform version the grid was built in is stamped as provenance so a stale
file -- one attached to a different transform frame later -- can be detected on
load. The build method and, for the Laplace methods, the laplace_strength
used are stamped too. By default the transform version is read from the build
transform (self._transform.version).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Output .npz path. |
required |
transform_version
|
str
|
Version label of the transform whose oriented frame this grid lives in. By default read from the attached transform, or omitted if it has no version. |
None
|
method
|
str
|
The regularizer used to build the field (e.g. |
None
|
laplace_strength
|
float
|
The lambda used, for the Laplace methods (e.g. the CV-selected value). |
None
|
Source code in standard_transform/streamlines.py
from_npz
classmethod
¶
Load a field saved by :meth:to_npz, attaching the given transform.
The grid is in post-transform microns and is therefore unit-agnostic: the same
file serves both nm and voxel variants -- only the attached transform differs.
Any stamped provenance is exposed as built_transform_version,
build_method, and build_laplace_strength (None for older, unstamped
files).
Source code in standard_transform/streamlines.py
streamline_field_from_paths¶
streamline_field_from_paths ¶
streamline_field_from_paths(
paths,
weights=None,
tform=None,
transform_points=True,
bin_size=(75.0, 50.0, 75.0),
bounds=None,
depth_band=(150.0, 700.0),
min_dy=0.001,
normalize_per_path=False,
method="laplace-fit",
smoothing_passes=None,
smoothing_strength=0.5,
laplace_strength=0.05,
bc_deep_layers=1,
edge_extrapolation="hold",
integration_step=None,
) -> StreamlineField
Build a :class:StreamlineField from a collection of pia-to-white-matter paths.
Each path (e.g. the principal axis of one neuron, from a skeleton) contributes the
local tangent (dx/dy, dz/dy) of each of its segments to the grid cell containing
that segment's midpoint. Cell tangents are the mean over all contributing segments,
so noise in individual paths averages out. The input is a plain list of point
arrays; how those paths were produced (neuroglancer, skeletons, etc.) is immaterial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
sequence of (n_i x 3) arrays
|
Ordered point arrays, one per path, in the pre-transform coordinate space
(unless |
required |
weights
|
sequence of arrays
|
Per-path weights matching |
None
|
tform
|
TransformSequence
|
Transform into the post-transform oriented-micron space, by default identity. |
None
|
transform_points
|
bool
|
If True, transform each path before binning, by default True. |
True
|
bin_size
|
3 - tuple
|
Grid spacing (x, y, z) in post-transform microns, by default (75, 50, 75). |
(75.0, 50.0, 75.0)
|
bounds
|
((xmin, xmax), (ymin, ymax), (zmin, zmax))
|
Grid extent in post-transform microns. If None, taken from the data (the y
extent is overridden by |
None
|
depth_band
|
(y_lo, y_hi) or None
|
Only segments within this post-transform depth range inform the field, and the
grid spans exactly this range, by default (150, 700). Outside the band the field
holds the edge orientation constant (see :class: |
(150.0, 700.0)
|
min_dy
|
float
|
Segments with |
0.001
|
normalize_per_path
|
bool
|
If True, scale each path's segment weights to sum to 1 so every neuron contributes equally regardless of how many segments (branches) it has. By default False. Combine with a single tall path per cell, or with weights. |
False
|
method
|
(laplace - fit, diffusion, laplace - bc)
|
How the binned per-cell tangents are regularized into a full field, by default
|
"laplace-fit"
|
smoothing_passes
|
int
|
Precision-weighted diffusion passes ( |
None
|
smoothing_strength
|
float
|
Neighbor coupling for the diffusion, by default 0.5. Larger smooths more. |
0.5
|
laplace_strength
|
float
|
Smoothness weight (relative to the median cell precision) for the Laplace methods, by default 0.05. Larger smooths more. |
0.05
|
bc_deep_layers
|
int
|
Number of deep/shallow y-layers used as boundaries for |
1
|
edge_extrapolation
|
(hold, harmonic)
|
Behavior in data-poor cells for |
"hold"
|
integration_step
|
float
|
Passed through to the resulting field. By default None (uses the y bin size). |
None
|
Returns:
| Type | Description |
|---|---|
StreamlineField
|
|
Source code in standard_transform/streamlines.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
Streamline factories¶
minnie_streamline ¶
Streamline for the minnie65 dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str or array - like
|
Units of the points you will pass in: |
'nm'
|
version
|
str
|
Streamline version; by default the latest. See :func: |
None
|
Source code in standard_transform/datasets.py
v1dd_streamline ¶
Streamline for the v1dd dataset.
By default (version=None) returns the latest definition — the data-derived,
spatially-varying tangent field (a :class:StreamlineField, a drop-in for
:class:Streamline). Pass version="1.4" for the original hand-drawn single
streamline. See :func:minnie_streamline for resolution and
:func:available_versions.