Splining Modules
Order single pixel skeletons with or without NodeStats Statistics.
splineTrace
Smooth the ordered trace via an average of splines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topostats_object
|
TopoStats
|
TopoStats object with ordered traces calculated for grains and molecules. |
required |
grain
|
int
|
Grain number to process. |
required |
molecule
|
int
|
Molecule number to process. |
required |
spline_step_size
|
float
|
Step length in meters to use a coordinate for splining. |
None
|
spline_linear_smoothing
|
float
|
Amount of linear spline smoothing. |
None
|
spline_circular_smoothing
|
float
|
Amount of circular spline smoothing. |
None
|
spline_degree
|
int
|
Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value. |
None
|
Source code in topostats\tracing\splining.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 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 248 | |
__init__(topostats_object: TopoStats, grain: int, molecule: int, spline_step_size: float | None = None, spline_linear_smoothing: float | None = None, spline_circular_smoothing: float | None = None, spline_degree: int | None = None) -> None
Initialise the splineTrace class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topostats_object
|
TopoStats
|
TopoStats object with ordered traces calculated for grains and molecules. |
required |
grain
|
int
|
Grain number to process. |
required |
molecule
|
int
|
Molecule number to process. |
required |
spline_step_size
|
float
|
Step length in meters to use a coordinate for splining. |
None
|
spline_linear_smoothing
|
float
|
Amount of linear spline smoothing. |
None
|
spline_circular_smoothing
|
float
|
Amount of circular spline smoothing. |
None
|
spline_degree
|
int
|
Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value. |
None
|
Source code in topostats\tracing\splining.py
get_splined_traces(fitted_trace: npt.NDArray) -> npt.NDArray
Get a splined version of the fitted trace - useful for finding the radius of gyration etc.
This function actually calculates the average of several splines which is important for getting a good fit on the lower resolution data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fitted_trace
|
NDArray
|
Numpy array of the fitted trace. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
Splined (smoothed) array of trace. |
Source code in topostats\tracing\splining.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 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 | |
remove_duplicate_consecutive_tuples(tuple_list: list[tuple | npt.NDArray]) -> list[tuple]
staticmethod
Remove duplicate consecutive tuples from a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tuple_list
|
list[tuple | NDArray]
|
List of tuples or numpy ndarrays to remove consecutive duplicates from. |
required |
Returns:
| Type | Description |
|---|---|
list[Tuple]
|
List of tuples with consecutive duplicates removed. |
Examples:
For the list of tuples [(1, 2), (1, 2), (1, 2), (2, 3), (2, 3), (3, 4)], this function will return [(1, 2), (2, 3), (3, 4)]
Source code in topostats\tracing\splining.py
run_spline_trace() -> tuple[npt.NDArray, dict]
Pipeline to run the splining smoothing and obtaining smoothing stats.
Returns:
| Type | Description |
|---|---|
tuple[NDArray, dict]
|
Tuple of Nx2 smoothed trace coordinates, and smoothed trace statistics. |
Source code in topostats\tracing\splining.py
windowTrace
Obtain a smoothed trace of a molecule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topostats_object
|
TopoStats
|
TopoStats object with ordered traces calculated for grains and molecules. |
required |
grain
|
int
|
Grain number to process. |
required |
molecule
|
int
|
Molecule number to process. |
required |
rolling_window_size
|
float64
|
The length of the rolling window too average over, by default 6.0. |
None
|
rolling_window_resampling
|
bool
|
Whether to resample the rolling window, by default False. |
False
|
rolling_window_resample_interval_nm
|
float
|
The regular spatial interval (nm) to resample the rolling window, by default 0.5. |
0.5
|
Source code in topostats\tracing\splining.py
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 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 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 | |
__init__(topostats_object: TopoStats, grain: int, molecule: int, rolling_window_size: float | None = None, rolling_window_resampling: bool = False, rolling_window_resample_interval_nm: float = 0.5) -> None
Initialise the windowTrace class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topostats_object
|
TopoStats
|
TopoStats object with ordered traces calculated for grains and molecules. |
required |
grain
|
int
|
Grain number to process. |
required |
molecule
|
int
|
Molecule number to process. |
required |
rolling_window_size
|
float64
|
The length of the rolling window too average over, by default 6.0. |
None
|
rolling_window_resampling
|
bool
|
Whether to resample the rolling window, by default False. |
False
|
rolling_window_resample_interval_nm
|
float
|
The regular spatial interval (nm) to resample the rolling window, by default 0.5. |
0.5
|
Source code in topostats\tracing\splining.py
pool_trace_circular(molecule: Molecule, rolling_window_size: np.float64 = 6.0, pixel_to_nm_scaling: float = 1) -> npt.NDArray[np.float64]
staticmethod
Smooth a pixelwise ordered trace of circular molecules via a sliding window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
molecule
|
Molecule
|
Molecule object with attribute |
required |
rolling_window_size
|
float64
|
The length of the rolling window too average over, by default 6.0. |
6.0
|
pixel_to_nm_scaling
|
float
|
The pixel to nm scaling factor, by default 1. |
1
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
MxN Smoothed ordered trace coordinates. |
Source code in topostats\tracing\splining.py
pool_trace_linear(molecule: Molecule, rolling_window_size: np.float64 = 6.0, pixel_to_nm_scaling: float = 1) -> npt.NDArray[np.float64]
staticmethod
Smooth a pixelwise ordered trace of linear molecules via a sliding window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
molecule
|
Molecule
|
Molecule object with attribute |
required |
rolling_window_size
|
float64
|
The length of the rolling window too average over, by default 6.0. |
6.0
|
pixel_to_nm_scaling
|
float
|
The pixel to nm scaling factor, by default 1. |
1
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
MxN Smoothed ordered trace coordinates. |
Source code in topostats\tracing\splining.py
run_window_trace() -> tuple[npt.NDArray, dict]
Pipeline to run the rolling window smoothing and obtaining smoothing stats.
Returns:
| Type | Description |
|---|---|
tuple[NDArray, dict]
|
Tuple of Nx2 smoothed trace coordinates, and smoothed trace statistics. |
Source code in topostats\tracing\splining.py
interpolate_between_two_points_distance(point1: npt.NDArray[np.float32], point2: npt.NDArray[np.float32], distance: np.float32) -> npt.NDArray[np.float32]
Interpolate between two points to create a new point at a set distance between the two.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point1
|
NDArray[float32]
|
The first point. |
required |
point2
|
NDArray[float32]
|
The second point. |
required |
distance
|
float32
|
The distance to interpolate between the two points. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float32]
|
The new point at the specified distance between the two points. |
Source code in topostats\tracing\splining.py
measure_contour_length(splined_trace: npt.NDArray, mol_is_circular: bool, pixel_to_nm_scaling: float) -> float
Contour length for each of the splined traces accounting for whether the molecule is circular or linear.
Contour length units are nm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
splined_trace
|
NDArray
|
The splined trace. |
required |
mol_is_circular
|
bool
|
Whether the molecule is circular or not. |
required |
pixel_to_nm_scaling
|
float
|
Scaling factor from pixels to nanometres. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Length of molecule in nanometres (nm). |
Source code in topostats\tracing\splining.py
measure_end_to_end_distance(splined_trace, mol_is_circular, pixel_to_nm_scaling: float)
Euclidean distance between the start and end of linear molecules.
The hypotenuse is calculated between the start ([0,0], [0,1]) and end ([-1,0], [-1,1]) of linear molecules. If the molecule is circular then the distance is set to zero (0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
splined_trace
|
NDArray
|
The splined trace. |
required |
mol_is_circular
|
bool
|
Whether the molecule is circular or not. |
required |
pixel_to_nm_scaling
|
float
|
Scaling factor from pixels to nanometres. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Length of molecule in nanometres (nm). |
Source code in topostats\tracing\splining.py
resample_points_regular_interval(points: npt.NDArray, interval: float, circular: bool) -> npt.NDArray
Resample a set of points to be at regular spatial intervals.
Note: This is NOT intended to be pure interpolation, as interpolated points would not produce uniformly spaced points in cartesian space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray
|
The points to resample. |
required |
interval
|
float
|
The distance that all returned points should be apart. |
required |
circular
|
bool
|
If True, the first and last points will be connected to form a closed loop. If False, the first and last points will not be connected. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The resampled points, evenly spaced at the specified interval. |
Source code in topostats\tracing\splining.py
splining_image(topostats_object: TopoStats, method: str | None = None, rolling_window_size: float | None = None, spline_step_size: float | None = None, spline_linear_smoothing: float | None = None, spline_circular_smoothing: float | None = None, spline_degree: int | None = None, rolling_window_resampling: bool | None = None, rolling_window_resample_regular_spatial_interval: float | None = None) -> None
Obtain smoothed traces of pixel-wise ordered traces for molecules in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topostats_object
|
TopoStats
|
TopoStats object with ordered traces of grain crops to be splined. |
required |
method
|
str
|
Method of trace smoothing, options are 'splining' and 'rolling_window'. |
None
|
rolling_window_size
|
float
|
Length in meters to average coordinates over in the rolling window. |
None
|
spline_step_size
|
float
|
Step length in meters to use a coordinate for splining. |
None
|
spline_linear_smoothing
|
float
|
Amount of linear spline smoothing. |
None
|
spline_circular_smoothing
|
float
|
Amount of circular spline smoothing. |
None
|
spline_degree
|
int
|
Degree of the spline. Cubic splines are recommended. Even values of k should be avoided especially with a small s-value. |
None
|
rolling_window_resampling
|
bool
|
Whether to resample the rolling window, by default False. |
None
|
rolling_window_resample_regular_spatial_interval
|
float
|
The regular spatial interval (nm) to resample the rolling window, by default 0.5. |
None
|
Source code in topostats\tracing\splining.py
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 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 656 657 658 659 660 661 662 | |