geometry¶
Morphology geometry and transformation utilities.
toric_spines_sim.geometry
¶
Morphology geometry and transformation utilities.
SinkGeometry(radius=0.5, length=100.0, n_cylinders=1, connector_length=1.0, axis='x')
dataclass
¶
Straight cylindrical sink (tag 5 body, optional tip tag).
Attributes:
| Name | Type | Description |
|---|---|---|
radius |
float
|
Cylinder radius in the same units as the SWC. |
length |
float
|
Axial length of the sink (excluding |
n_cylinders |
int
|
Number of frusta along the axis. |
connector_length |
float
|
Short segment from the snapped neck node to the first sink node. |
axis |
str or sequence of float
|
|
SpinyDendriteParams(length, trunk_neck_radius, trunk_tip_radius, n_spines, spine_length, spine_neck_radius, spine_head_radius, spine_neck_length_fraction=0.5, max_spines_per_node=1, distribution='even', seed=None, azimuth0=0.0, axis='z', trunk_tag=3, spine_neck_tag=3, spine_head_tag=3)
dataclass
¶
Explicit parameters for building a spiny dendrite (mode A).
ToricSpineMatchParams(spine_length=_DEFAULT_SPINE_LENGTH, spine_neck_radius=_DEFAULT_SPINE_NECK_RADIUS, spine_head_radius=_DEFAULT_SPINE_HEAD_RADIUS, trunk_neck_radius=_DEFAULT_TRUNK_NECK_RADIUS, trunk_tip_radius=_DEFAULT_TRUNK_TIP_RADIUS, spine_neck_length_fraction=0.5, trunk_length_over_spine_length=_DEFAULT_TRUNK_LENGTH_OVER_SPINE_LENGTH, max_spines_per_node=1, distribution='even', seed=None, azimuth0=0.0, axis='z', scale_strategy='relative', trunk_tag=3, spine_neck_tag=3, spine_head_tag=3, sink_tags=(lambda: _DEFAULT_SINK_TAGS)())
dataclass
¶
Template / layout options when matching a toric spine (mode B).
SpinyDendriteMorphology(nodes, az_points, neck_point, trunk_node_ids, spine_head_node_ids, spines_per_attach_node, params, diagnostics=dict())
dataclass
¶
In-memory spiny dendrite subsystem.
SWCNodeRecord(node_id, tag, x, y, z, radius, parent)
dataclass
¶
One SWC data line.
MeshToSwcResult(mesh_path, polylines_path, swc_path)
dataclass
¶
Outputs from :func:mesh_to_swc.
NeckCandidate(centroid, area, n_faces, planarity, mean_signed, mean_align, ray_frac_inside, dendrite_frac, source='cap', rank_score=0.0)
dataclass
¶
One detected neck interface.
NeckpointParams(crop_margin=120.0, align_thr=0.2, align_signed_max=-3.0, signed_thr=-10.0, min_faces=6, planarity_max=0.22, mean_signed_max=-5.0, mean_align_max=0.5, ray_frac_min=0.6, open_score_min=0.75, ray_offsets=(10.0, 25.0, 50.0, 80.0, 120.0), dendrite_radius=150.0, dendrite_far_thr=20.0, dendrite_frac_floor=0.15, dendrite_frac_of_max=0.5, fallback_dist_thr=15.0, fallback_align_thr=0.5, fallback_min_loop_verts=6, attachment_dendrite_dist_max=35.0, attachment_facing_min=0.25, attachment_min_faces=5, attachment_planarity_max=0.3, attachment_ray_offsets=(10.0, 30.0, 60.0, 100.0), max_necks=None)
dataclass
¶
Thresholds for TS-vs-cell neck-cap detection.
scale_one_radius_in_segment_tree_by_coordinates(tree, scale_factor, target_xyz, tolerance=1e-06)
¶
Scale the radius of a specific node in an Arbor segment_tree, identified by its (x, y, z) coordinates.
Every proximal or distal endpoint whose position matches target_xyz (within tolerance) has its radius multiplied by scale_factor.
Source code in toric_spines_sim/geometry/rescale.py
scale_radii_in_segment_tree_by_tag(tree, scale_factor, scale_tag)
¶
Scale the radii of all segments in an Arbor segment_tree with a given tag.
The distal radius of a matching segment is always scaled. The proximal radius is only scaled when the parent segment also carries scale_tag, so that boundary nodes (e.g. a neck node shared with a different-tagged region) are not affected.
Source code in toric_spines_sim/geometry/rescale.py
compute_geodesic_distances(swc_filepath, source_xyz)
¶
Compute geodesic (path-length) distances from a source point to every node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_filepath
|
path - like
|
Path to an SWC file (with optional |
required |
source_xyz
|
(x, y, z)
|
3-D coordinate of the source point. The nearest graph node is used. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, float]
|
Mapping from node ID to shortest-path distance (in the same spatial units as the SWC file, typically µm). Unreachable nodes are omitted. |
Source code in toric_spines_sim/geometry/graph.py
classify_compartments(swc_filepath, source_xyz, target_xyz, mode='path_based', spine_tag=3, sink_tag=5)
¶
Classify every graph node into one of four categories.
Categories
"main_path"
Nodes on the shortest path from source to target.
"branch"
Spine nodes (tag = spine_tag) that are off the main path but
structurally related to it (definition depends on mode).
"lateral"
All other spine nodes.
"sink"
Nodes with tag = sink_tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_filepath
|
path - like
|
Path to an SWC file. |
required |
source_xyz
|
(x, y, z)
|
Coordinates of source and target landmarks. Nearest graph nodes are used. |
required |
target_xyz
|
(x, y, z)
|
Coordinates of source and target landmarks. Nearest graph nodes are used. |
required |
mode
|
``"path_based"`` | ``"distance_based"``
|
How to distinguish branch from lateral:
|
'path_based'
|
spine_tag
|
int
|
Tag value identifying spine compartments (default 3). |
3
|
sink_tag
|
int
|
Tag value identifying sink compartments (default 5). |
5
|
Returns:
| Type | Description |
|---|---|
dict[int, str]
|
Mapping |
Source code in toric_spines_sim/geometry/graph.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
geodesic_distances_from_probe(swc_filepath, record_points, source_probe, target_probes)
¶
Compute geodesic distances from one probe to target probes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_filepath
|
path - like
|
Path to the SWC morphology. |
required |
record_points
|
dict
|
Mapping |
required |
source_probe
|
str
|
Probe label used as source for distance calculation. |
required |
target_probes
|
iterable[str]
|
Probe labels to measure from |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping |
Source code in toric_spines_sim/geometry/graph.py
map_probes_to_nodes(swc_filepath, record_points)
¶
Map simulation probe labels to their nearest graph node IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_filepath
|
path - like
|
Path to an SWC file. |
required |
record_points
|
dict
|
Mapping |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Mapping |
Source code in toric_spines_sim/geometry/graph.py
map_xyz_to_nearest_probes(record_points, xyz_points)
¶
Map named xyz coordinates to nearest recording probe labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record_points
|
dict
|
Mapping |
required |
xyz_points
|
dict
|
Mapping |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping |
Source code in toric_spines_sim/geometry/graph.py
parse_cycle_breaks(swc_path)
¶
Parse # CYCLE_BREAK reconnect i j annotations from an SWC file.
Returns a list of integer pairs [(i, j), ...].
Raises ValueError if any CYCLE_BREAK directive is malformed (e.g. non-integer IDs).
Source code in toric_spines_sim/geometry/swc.py
parse_multi_neck_reconnects(swc_path)
¶
Parse # MULTI_NECK reconnect i j annotations from an SWC header.
Extra necks are electrically tied to the sink start by a gap junction
between node i (sink start) and node j (colocated sink-start copy).
Source code in toric_spines_sim/geometry/swc.py
parse_reconnect_pairs(swc_path)
¶
Return CYCLE_BREAK pairs followed by MULTI_NECK pairs (no duplicates).
Source code in toric_spines_sim/geometry/swc.py
read_swc_points(swc_path)
¶
Return dict id -> (x, y, z, r) from SWC content (ignores non-data lines).
Source code in toric_spines_sim/geometry/swc.py
get_center_coordinates_for_all_segments(swc_filepath, use_radius_weighting=False)
¶
Compute the center coordinate of each SWC segment (parent→child edge).
Returns a dict mapping probe labels like 'probe_seg_0' to (x, y, z) centers.
Source code in toric_spines_sim/geometry/swc.py
arbor_locations_for_swc_nodes(swc_path, morphology, segment_tree, node_ids)
¶
Map SWC sample IDs to Arbor (branch, pos) at that sample's endpoint.
A.load_swc_arbor makes one segment per non-root SWC sample, in file
order. The distal end of segment k is the k-th non-root sample. Using
this mapping (not place_pwlin.closest on XYZ) keeps colocated cycle-break
/ multi-neck copies on different branches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_path
|
path - like
|
SWC used to build |
required |
morphology
|
morphology
|
Morphology corresponding to |
required |
segment_tree
|
segment_tree
|
Tree produced by |
required |
node_ids
|
iterable of int
|
SWC sample IDs to map. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, location]
|
Distal |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sample/segment counts disagree or a node ID is missing. |
Examples:
>>> locs = arbor_locations_for_swc_nodes(path, morph, tree, [12, 13])
>>> locs[12].branch != locs[13].branch # colocated CYCLE_BREAK copies
True
Source code in toric_spines_sim/geometry/swc.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
sink_endpoint_location_from_swc_file(filepath)
¶
Return XYZ of the distal sink sample referenced by end= in the header.
Expects a header line of the form::
# SINK: start=15, end=22, ...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
path - like
|
SWC file with a |
required |
Returns:
| Type | Description |
|---|---|
tuple of float
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
Examples:
Source code in toric_spines_sim/geometry/sink.py
neck_point_from_swc_file(filepath)
¶
Read the neck point coordinates from the SINK header in an SWC file.
Expects a header line of the form::
# SINK: ..., neck_xyz=<x> <y> <z>
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
path - like
|
SWC file with a |
required |
Returns:
| Type | Description |
|---|---|
tuple of float
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no |
Examples:
Source code in toric_spines_sim/geometry/sink.py
optimal_sink_direction(neck_coords, swc, average_multiple=True)
¶
Compute optimal sink direction(s) pointing away from the morphology.
Args: neck_coords: Either a single (x, y, z) tuple, or a path to a file containing one or more neck points (one per line: x y z). swc: SWC file path, SWCModel instance, or dict of node_id -> (x, y, z, r). average_multiple: If True and neck_coords is a file with multiple points, return the average direction. If False, return a list of directions (one per neck point).
Returns: Single (dx, dy, dz) direction tuple if average_multiple=True or single neck point. List of direction tuples if average_multiple=False and multiple neck points.
Source code in toric_spines_sim/geometry/sink.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
append_sink_to_swc(swc_in, swc_out, neck_coords, geom, tag=5, last_segment_tag=None)
¶
Append a cylindrical sink as a new tree and write # SINK: metadata.
The sink starts at the SWC node nearest neck_coords and extends along
geom.axis. A connector frustum of length geom.connector_length
links the neck to the first sink node. When last_segment_tag is set,
the distal tip uses that tag (typically 6 for HH) instead of tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_in
|
path - like
|
Input SWC and destination path. |
required |
swc_out
|
path - like
|
Input SWC and destination path. |
required |
neck_coords
|
path-like or sequence of float
|
Neck XYZ, or a file with |
required |
geom
|
SinkGeometry
|
Cylinder radius, length, axis, and segmentation. |
required |
tag
|
int
|
SWC tag for sink body nodes (default 5). |
5
|
last_segment_tag
|
int
|
Tag for the distal tip node. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
|
Examples:
>>> geom = SinkGeometry(radius=0.5, length=100.0, axis="x")
>>> append_sink_to_swc("TS1.swc", "TS1_wsink.swc", (0, 0, 0), geom)
Source code in toric_spines_sim/geometry/sink.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 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 | |
append_sink_to_swc_multi_neck_points(swc_in, swc_out, neck_points, geom, tag=5, last_segment_tag=None)
¶
Append one sink, then extra-neck copies of the sink start node.
neck_points is a file of x y z rows. The first row is the primary
neck; each later row gets a copy of the sink-start sample parented at that
neck, recorded as # MULTI_NECK reconnect i j.
Source code in toric_spines_sim/geometry/sink.py
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 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
build_spiny_dendrite(params)
¶
Build an in-memory spiny dendrite from explicit parameters (mode A).
Source code in toric_spines_sim/geometry/dendrite.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
build_from_toric_spine(swc_path, az_path, match=None, neck_path=None)
¶
Build a comparable spiny dendrite matched to a toric spine subsystem.
Hard constraints: n_spines == n_AZ and lateral surface area ≈ TS SA
(excluding sink-tagged segments).
Scale strategies (match.scale_strategy):
relative(default): scale a typical-proportion template uniformly so SA matches (preserves relative geometry).absolute_spines: keep literature absolute spine sizes; solve trunk length so SA matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_path
|
path - like
|
Toric-spine SWC (sink tags excluded from SA). |
required |
az_path
|
path - like
|
Active-zone XYZ file; one spine per point. |
required |
match
|
ToricSpineMatchParams
|
Template proportions and scale strategy. |
None
|
neck_path
|
path - like
|
Recorded in diagnostics only (geometry uses a single proximal neck). |
None
|
Returns:
| Type | Description |
|---|---|
SpinyDendriteMorphology
|
Synthetic morphology plus SA/volume diagnostics. |
Examples:
>>> morph = build_from_toric_spine("TS1.swc", "TS1_AZ.txt")
>>> morph.diagnostics["surface_area_rel_error"] < 0.05
True
Source code in toric_spines_sim/geometry/dendrite.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
write_subsystem(morph, swc_path, az_path, neck_path)
¶
Write SWC + AZ + neckpoint files for a subsystem.
Source code in toric_spines_sim/geometry/dendrite.py
write_swc(path, morph, extra_header=None)
¶
Write morphology nodes as an SWC file.
Source code in toric_spines_sim/geometry/dendrite.py
write_xyz_points(path, points)
¶
Write whitespace-delimited XYZ points (%.6f), one per line.
Source code in toric_spines_sim/geometry/dendrite.py
distribute_spine_counts(n_spines, n_attach, max_spines_per_node, distribution='even', seed=None)
¶
Distribute n_spines across n_attach trunk nodes (each ≤ max).
Source code in toric_spines_sim/geometry/dendrite.py
frustum_lateral_area(r1, r2, length)
¶
Lateral surface area of a conical frustum (excluding end caps).
morphology_surface_area(nodes)
¶
Sum lateral frustum areas over parent→child edges.
Source code in toric_spines_sim/geometry/dendrite.py
morphology_volume(nodes)
¶
Sum frustum volumes over parent→child edges.
Source code in toric_spines_sim/geometry/dendrite.py
swc_subsystem_surface_area(swc_path, sink_tags=None)
¶
Lateral SA of an SWC, excluding segments whose child tag is a sink tag.
Source code in toric_spines_sim/geometry/dendrite.py
fit_swc(mesh_path, polylines_path, swc_path, *, max_edge_length_frac=0.08, radius_strategy='equivalent_area', scale_radii=True, basis_optimize=False, basis_optimizer_options=None, scale_metric='surface_area')
¶
Fit a cable SWC to a mesh + skeleton with mascaf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh_path
|
PathLike
|
Mesh file path, or a bare filename under |
required |
polylines_path
|
PathLike
|
Skeleton polylines text file. |
required |
swc_path
|
PathLike
|
Destination SWC path. |
required |
max_edge_length_frac
|
float
|
|
0.08
|
radius_strategy
|
str
|
Radius estimation strategy (default |
'equivalent_area'
|
scale_radii
|
bool
|
If True, call |
True
|
basis_optimize
|
bool
|
If True, enable mascaf |
False
|
basis_optimizer_options
|
Optional[dict[str, Any]]
|
Optional kwargs for |
None
|
scale_metric
|
str
|
Metric for radius scaling (default |
'surface_area'
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written SWC file. |
Source code in toric_spines_sim/geometry/mesh_pipeline.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
list_ts_meshes()
¶
mesh_to_swc(mesh_path, *, polylines_path=None, swc_path=None, skip_skeletonize=False, polylines_only=False, profile='auto', max_edge_length_frac=0.08, radius_strategy='equivalent_area', scale_radii=True, basis_optimize=False, basis_optimizer_options=None, scale_metric='surface_area', **skeletonize_kwargs)
¶
Run mesh → polylines → SWC (or a subset of those steps).
Default outputs are data/skeletons/<spine_id>.polylines.txt and
data/swc/pixels/<spine_id>.swc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh_path
|
path - like
|
Mesh file or spine id ( |
required |
polylines_path
|
path - like
|
Override default output paths. |
None
|
swc_path
|
path - like
|
Override default output paths. |
None
|
skip_skeletonize
|
bool
|
If True, reuse existing polylines (must already exist). |
False
|
polylines_only
|
bool
|
Stop after skeletonization; |
False
|
profile
|
str
|
pymcfs skeletonize profile ( |
'auto'
|
max_edge_length_frac
|
float
|
Forwarded to |
0.08
|
radius_strategy
|
float
|
Forwarded to |
0.08
|
scale_radii
|
float
|
Forwarded to |
0.08
|
basis_optimize
|
float
|
Forwarded to |
0.08
|
skeletonize_kwargs
|
Any
|
Extra kwargs for |
{}
|
Returns:
| Type | Description |
|---|---|
MeshToSwcResult
|
Resolved mesh / polylines / SWC paths. |
Examples:
Source code in toric_spines_sim/geometry/mesh_pipeline.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
resolve_mesh_targets(meshes=None, *, all_meshes=False)
¶
Resolve CLI mesh targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meshes
|
Optional[Sequence[str]]
|
Explicit mesh names or paths. Ignored when |
None
|
all_meshes
|
bool
|
If True, return every |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
FileNotFoundError
|
If a requested mesh cannot be resolved, or if |
Source code in toric_spines_sim/geometry/mesh_pipeline.py
skeletonize_mesh(mesh_path, polylines_path, *, profile='auto', branching='sparse', **skeletonize_kwargs)
¶
Skeletonize a closed triangle mesh with pymcfs and write polylines.
Defaults match pymcfs toric-spine batch settings
(profile="auto", branching="sparse", tip extension on).
See :data:TORIC_SPINES_SKELETONIZE_DEFAULTS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh_path
|
PathLike
|
Mesh file path, or a bare filename under |
required |
polylines_path
|
PathLike
|
Destination |
required |
profile
|
str
|
pymcfs skeletonization profile (default |
'auto'
|
branching
|
str
|
Branching preference when |
'sparse'
|
**skeletonize_kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written polylines file. |
Source code in toric_spines_sim/geometry/mesh_pipeline.py
compute_neck_candidates(ts_mesh, cell_mesh, params=None)
¶
Detect neck interfaces between a spine mesh and the parent cell mesh.
Tries planar cap detection first, then attachment-face and boundary-loop
fallbacks. params.max_necks truncates the ranked list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts_mesh
|
Trimesh objects (spine and local cell). |
required | |
cell_mesh
|
Trimesh objects (spine and local cell). |
required | |
params
|
NeckpointParams
|
Thresholds, crop margin, and |
None
|
Returns:
| Type | Description |
|---|---|
list of NeckCandidate
|
Largest-first after truncation. |
Examples:
>>> cands = compute_neck_candidates(ts, cell, NeckpointParams(max_necks=2))
>>> cands[0].centroid.shape
(3,)
Source code in toric_spines_sim/geometry/neckpoint.py
compute_neck_points(ts_mesh, cell_mesh, params=None)
¶
Return neckpoint XYZ arrays (pixel space), largest-first after max_necks.
Source code in toric_spines_sim/geometry/neckpoint.py
compute_neck_points_all(*, meshes=None, all_meshes=False, cell_mesh_path=None, params=None, write=True, overwrite=True)
¶
Compute neckpoints for one or more TS meshes.
Source code in toric_spines_sim/geometry/neckpoint.py
compute_neck_points_for_spine(spine_id, *, cell_mesh_path=None, params=None, write=True, overwrite=True, output_path=None)
¶
Compute neckpoints for one TS mesh and optionally write the pixel file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spine_id
|
PathLike
|
Mesh spine id, filename, or path (e.g. |
required |
cell_mesh_path
|
Optional[PathLike]
|
Full cell mesh; defaults to |
None
|
params
|
Optional[NeckpointParams]
|
Detection parameters including |
None
|
write
|
bool
|
If True, write |
True
|
overwrite
|
bool
|
If False and the output exists, skip writing and return existing points only when write would be skipped after a successful compute — still recomputes unless you check existence first in the CLI. |
True
|
output_path
|
Optional[PathLike]
|
Override output path. |
None
|
Source code in toric_spines_sim/geometry/neckpoint.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
default_neckpoint_path(spine_id)
¶
Pixel-space neckpoint path for a mesh spine id (e.g. TS1).
append_sink_write(swc_path_pixels, *, neckpoint_path_pixels=None, radius_um=DEFAULT_SINK_RADIUS_UM, connector_length_um=DEFAULT_SINK_CONNECTOR_LENGTH_UM, n_cylinders=DEFAULT_SINK_N_CYLINDERS, um_per_px, output_swc_path_pixels=None, output_swc_path_microns=None, output_neckpoint_path_microns=None, tag=DEFAULT_SINK_TAG, last_segment_tag=DEFAULT_SINK_TIP_TAG)
¶
Append a sink in pixel space, then write both pixel and micron SWCs.
Sink dimensions are specified in microns and converted to pixels for attachment. Outputs:
data/swc/pixels/<spine_id>_wsink_r<R>um.swcdata/swc/microns/<spine_id>_wsink_r<R>um.swc(scaled copy with SINK header fixed)data/pointsets/microns/<spine_id>_neckpoint.txt
Returns (output_swc_path_pixels, output_swc_path_microns).
Source code in toric_spines_sim/geometry/prepare.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
append_sink_write_microns(swc_path_pixels, *, neckpoint_path_pixels=None, radius_um=DEFAULT_SINK_RADIUS_UM, connector_length_um=DEFAULT_SINK_CONNECTOR_LENGTH_UM, n_cylinders=DEFAULT_SINK_N_CYLINDERS, um_per_px, output_swc_path_microns=None, output_neckpoint_path_microns=None, tag=DEFAULT_SINK_TAG, last_segment_tag=DEFAULT_SINK_TIP_TAG, output_swc_path_pixels=None)
¶
Append a sink and write micron (and pixel) SWCs; return the micron path.
Prefer :func:append_sink_write when both output paths are needed.
Source code in toric_spines_sim/geometry/prepare.py
convert_all_nff_active_zones()
¶
Convert every data/nff/*.nff file that has s points to a pixel AZ file.
Source code in toric_spines_sim/geometry/prepare.py
convert_nff_active_zone(nff_path, output_path=None)
¶
Write NFF s points to data/pointsets/pixels/<spine_id>.txt.
If the NFF has no s points, writes an empty file and logs a warning.
Source code in toric_spines_sim/geometry/prepare.py
list_ts_spine_swcs()
¶
Return sorted TS{n}.swc paths under data/swc/pixels (no _wsink_).
resolve_swc_targets(swcs=None, *, all_swcs=False)
¶
Resolve CLI SWC targets under data/swc/pixels.
Source code in toric_spines_sim/geometry/prepare.py
scale_swc_file(swc_in, swc_out, scale)
¶
Scale SWC coordinates and radii, preserving CYCLE_BREAK / SINK headers.
SWCModel.scale keeps header text verbatim, so # SINK: length, radius,
and neck_xyz are rewritten here to match the scaled geometry.
Source code in toric_spines_sim/geometry/prepare.py
write_synpts_microns(swc_path_pixels, az_path_pixels, synpts_path_microns=None, *, um_per_px)
¶
Project pixel AZ points onto the SWC, scale to microns, and write synpts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swc_path_pixels
|
path - like
|
Pixel-space SWC. |
required |
az_path_pixels
|
path - like
|
Pixel-space active-zone points. |
required |
synpts_path_microns
|
path - like
|
Output path. Default |
None
|
um_per_px
|
float
|
Scale factor (typically 0.005). |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Written micron synpts file. |
Examples: