Skeletons (connectomekg.skeletons)¶
connectomekg.skeletons
¶
SWC skeleton reading, writing and simplification -- NumPy only.
FlyWire's Codex download carries one navis-written .swc file per neuron
(fafb_v783/sk_lod1_783_healed/<root_id>.swc): a header of # comment
lines, then one row per traced point --
PointNo Label X Y Z Radius Parent, coordinates in nanometres, sharing the
graph's own x/y/z frame. Parent names another row's
PointNo, or -1 for a root; PointNo itself may have gaps and is not
the row index. Files mix CRLF and LF line endings. Label values: 0
undefined, 1 soma, 5 fork point, 6 end point.
This module has no PyVista or Qt import anywhere, so it stays importable with
no extra installed -- :mod:connectomekg.scene builds on it lazily.
Skeleton(root_id, points, radius, labels, parent)
dataclass
¶
One neuron's traced skeleton.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_id
|
int
|
Neuron root id, from the SWC file's stem. |
required |
points
|
ndarray
|
|
required |
radius
|
ndarray
|
|
required |
labels
|
ndarray
|
|
required |
parent
|
ndarray
|
|
required |
load_skeletons(data_dir, root_ids)
¶
Load whichever of root_ids have a skeleton file, reporting the rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
str | Path
|
Root of the skeleton download. |
required |
root_ids
|
Iterable[int]
|
Neuron root ids to load. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[int, Skeleton], list[int]]
|
|
Source code in src/connectomekg/skeletons.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
polylines(skeleton, *, step=1)
¶
Maximal unbranched chains, as index arrays into the skeleton's points.
:func:segments returns each child-to-parent edge on its own, which a
tube filter extrudes into one short cylinder per edge: consecutive
cylinders meet at an angle with nothing joining them, and the drawn
neuron is a heap of faceted stubs. A chain is the run of points between
one branch point (or root) and the next branch point (or tip), so tubing
it produces a single continuous surface with mitred joins. It is also
cheaper: a chain's interior points are shared rather than duplicated once
per edge.
Every edge belongs to exactly one chain, so the drawn geometry is the same
as :func:segments would give -- only joined up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The skeleton to draw. |
required |
step
|
int
|
Simplification stride, as :func: |
1
|
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
One |
Source code in src/connectomekg/skeletons.py
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 | |
read_swc(path)
¶
Parse one SWC file into a :class:Skeleton.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
Skeleton
|
The parsed skeleton. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a row has too few fields, a |
Source code in src/connectomekg/skeletons.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
segments(skeleton, *, step=1)
¶
Child-to-parent line segments, optionally simplified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The skeleton to draw. |
required |
step
|
int
|
|
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in src/connectomekg/skeletons.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
skeleton_path(data_dir, root_id)
¶
The SWC file path for one neuron in the Codex skeleton download.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
str | Path
|
Root of the download (default layout: |
required |
root_id
|
int
|
Neuron root id. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
Source code in src/connectomekg/skeletons.py
346 347 348 349 350 351 352 353 | |
soma(skeleton)
¶
The skeleton's soma point, or a fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The skeleton to inspect. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, bool]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the skeleton has neither a |
Source code in src/connectomekg/skeletons.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
write_swc(skeleton, path)
¶
Write a :class:Skeleton back out as an SWC file, for fixtures and round trips.
PointNo is the 1-based row index; this is only ever read back by
:func:read_swc, which does not assume that, so the choice is arbitrary
but self-consistent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The skeleton to write. |
required |
path
|
str | Path
|
Destination path. |
required |
Source code in src/connectomekg/skeletons.py
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 | |