Ordered Tracing Modules
Order single pixel skeletons with or without NodeStats Statistics.
OrderedTraceNodestats
Order single pixel thick skeleton coordinates via NodeStats results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grain_crop
|
GrainCrop
|
|
required |
Source code in topostats\tracing\ordered_tracing.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 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 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 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 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 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 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 | |
__init__(grain_crop: GrainCrop) -> None
Initialise the OrderedTraceNodestats class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grain_crop
|
GrainCrop
|
Grain crop post nodestats. |
required |
Source code in topostats\tracing\ordered_tracing.py
check_node_errorless() -> bool
Check if an error has occurred while processing the node dictionary.
Returns:
| Type | Description |
|---|---|
bool
|
Whether the error is present. |
Source code in topostats\tracing\ordered_tracing.py
compile_images(coord_trace: list | None, cross_add: npt.NDArray | None, crossing_coords: list | None, fwhms: list | None) -> None
Obtain all the diagnostic images based on the produced traces, and values.
Crossing coords and fwhms are used as arguments as reversing the minimum confidence can modify these.
If compiling the image failed, i.e. all parameters are None then all images are set to None too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord_trace
|
list
|
List of N molecule objects containing 2xM arrays of X, Y coordinates. |
required |
cross_add
|
NDArray
|
A labelled array with segments of the ordered trace. |
required |
crossing_coords
|
list
|
A list of I nodes objects containing 2xJ arrays of X, Y coordinates for each crossing branch. |
required |
fwhms
|
list
|
A list of I nodes objects containing FWHM values for each crossing branch. |
required |
Source code in topostats\tracing\ordered_tracing.py
compile_trace(reverse_min_conf_crossing: bool = False) -> tuple[list, npt.NDArray]
Obtain the trace and diagnostic crossing trace and molecule trace images.
This function uses the branches and full-width half-maximums (FWHMs) identified in the node_stats dictionary to create a continuous trace of the molecule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reverse_min_conf_crossing
|
bool
|
Whether to reverse the stacking order of the lowest confidence crossing in the trace. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[list, NDArray]
|
A list of each complete path's ordered coordinates, and labeled crossing image array. |
Source code in topostats\tracing\ordered_tracing.py
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 | |
get_mols_img(coord_trace: list, fwhms: list, crossing_coords: list) -> npt.NDArray
Obtain a labelled image according to each molecule traced N=3 -> n=1,2,3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord_trace
|
list
|
Ordered coordinate trace of each molecule. |
required |
fwhms
|
list
|
List of full-width half-maximums (FWHMs) for each crossing in the trace. |
required |
crossing_coords
|
list
|
The crossing coordinates of each branch crossing. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
2D individual 'molecule' labelled image. |
Source code in topostats\tracing\ordered_tracing.py
get_over_under_img(coord_trace: list, fwhms: list, crossing_coords: list) -> npt.NDArray
Obtain a labelled image according to the main trace (=1), under (=2), over (=3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord_trace
|
list
|
Ordered coordinate trace of each molecule. |
required |
fwhms
|
list
|
List of full-width half-maximums (FWHMs) for each crossing in the trace. |
required |
crossing_coords
|
list
|
The crossing coordinates of each branch crossing. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
2D crossing order labelled image. |
Source code in topostats\tracing\ordered_tracing.py
get_topology(nxyz: npt.NDArray) -> list
Obtain a topological classification from ordered XYZ coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nxyz
|
NDArray
|
A 4xN array of the order index (n), x, y and pseudo z coordinates. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Topology(s) of the provided traced coordinates. |
Source code in topostats\tracing\ordered_tracing.py
get_trace_idxs(fwhms: list) -> tuple[list, list]
staticmethod
Split under-passing and over-passing indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fwhms
|
list
|
List of arrays of full-width half-maximum (FWHM) values for each crossing point. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list, list]
|
All the under, and over indices of the for each node FWHMs in the provided FWHM list. |
Source code in topostats\tracing\ordered_tracing.py
get_trace_segment(remaining_img: npt.NDArray, ordered_segment_coords: list, coord_idx: int) -> npt.NDArray
staticmethod
Return an ordered segment at the end of the current one.
Check the branch of given index to see if it contains an endpoint. If it does, the segment coordinates will be returned starting from the endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remaining_img
|
NDArray
|
A 2D array representing an image composed of connected segments of different integers. |
required |
ordered_segment_coords
|
list
|
A list of 2xN coordinates representing each segment. |
required |
coord_idx
|
int
|
The index of the current segment to look at. There is an index mismatch between the remaining_img and ordered_segment_coords by -1. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
2xN array of coordinates representing a skeletonised ordered trace segment. |
Source code in topostats\tracing\ordered_tracing.py
identify_writhes() -> str | dict
Identify the writhe topology at each crossing in the image.
Returns:
| Type | Description |
|---|---|
str | dict
|
A string of the whole grain writhe sign, and a dictionary linking each node to it's sign. |
Source code in topostats\tracing\ordered_tracing.py
order_from_end(last_segment_coord: npt.NDArray, current_segment: npt.NDArray) -> npt.NDArray
staticmethod
Order the current segment to follow from the end of the previous one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_segment_coord
|
NDArray
|
X and Y coordinates of the end of the last segment. |
required |
current_segment
|
NDArray
|
A 2xN array of coordinates of the current segment to order. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The current segment orientated to follow on from the last. |
bool
|
Whether the order has been flipped. |
Source code in topostats\tracing\ordered_tracing.py
reduce_rows(array: npt.NDArray, n: int = 300) -> npt.NDArray
staticmethod
Reduce the number of rows in the array to n, keeping the first and last indexes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray
|
An array to reduce the number of rows in. |
required |
n
|
int
|
The number of indexes in the array to keep, by default 300. |
300
|
Returns:
| Type | Description |
|---|---|
NDArray
|
The |
Source code in topostats\tracing\ordered_tracing.py
remove_common_values(ordered_array: npt.NDArray, common_value_check_array: npt.NDArray, retain: list = ()) -> np.array
staticmethod
Remove common values in common_value_check_array from ordered_array while retaining specified coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ordered_array
|
NDArray
|
Coordinate array to remove / retain values from. Will retain its order. |
required |
common_value_check_array
|
NDArray
|
Coordinate array containing any common values to be removed from ordered_array. |
required |
retain
|
list
|
List of possible coordinates to keep, by default (). |
()
|
Returns:
| Type | Description |
|---|---|
array
|
Unique ordered_array values and retained coordinates. Retains the order of ordered_array. |
Source code in topostats\tracing\ordered_tracing.py
run_nodestats_tracing() -> dict[str, npt.NDArray]
Run the nodestats tracing pipeline.
Returns:
| Type | Description |
|---|---|
tuple[list, dict, dict]
|
A list of each molecules ordered trace coordinates, the ordered_tracing stats, and the images. |
Source code in topostats\tracing\ordered_tracing.py
trace(ordered_segment_coords: list, both_img: npt.NDArray, zs: npt.NDArray, n: int = 100) -> list
Obtain an ordered trace of each complete path.
Here a 'complete path' means following and removing connected segments until there are no more segments to follow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ordered_segment_coords
|
list
|
Ordered coordinates of each labeled segment in 'both_img'. |
required |
both_img
|
NDArray
|
A skeletonised labeled image of each path segment. |
required |
zs
|
NDArray
|
Array of pseudo heights of the traces. -1 is lowest, 0 is skeleton, then ascending integers for levels of overs. |
required |
n
|
int
|
The number of points to use for the simplified traces. |
100
|
Returns:
| Type | Description |
|---|---|
list
|
Ordered trace coordinates of each complete path. |
Source code in topostats\tracing\ordered_tracing.py
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 | |
writhe_direction(first_vector: npt.NDArray, second_vector: npt.NDArray) -> str
staticmethod
Use the cross product of crossing vectors to determine the writhe sign.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first_vector
|
NDArray
|
An x,y component vector of the overlying strand. |
required |
second_vector
|
NDArray
|
An x,y component vector of the underlying strand. |
required |
Returns:
| Type | Description |
|---|---|
str
|
'+', '-' or '0' for positive, negative, or no writhe. |
Source code in topostats\tracing\ordered_tracing.py
OrderedTraceTopostats
Order single pixel thick skeleton coordinates via TopoStats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grain_crop
|
GrainCrop
|
Grain crop to perform ordered tracing on. |
required |
Source code in topostats\tracing\ordered_tracing.py
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 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | |
__init__(grain_crop: GrainCrop) -> None
Initialise the OrderedTraceTopostats class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grain_crop
|
GrainCrop
|
Grain crop to perform ordered tracing on. |
required |
Source code in topostats\tracing\ordered_tracing.py
get_ordered_traces(disordered_trace_coords: npt.NDArray, mol_is_circular: bool) -> list
staticmethod
Obtain ordered traces from disordered traces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
disordered_trace_coords
|
NDArray
|
A Nx2 array of coordinates to order. |
required |
mol_is_circular
|
bool
|
A flag of whether the molecule has at least one coordinate with only one neighbour. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A list of each molecules ordered trace coordinates. |
Source code in topostats\tracing\ordered_tracing.py
run_topostats_tracing() -> tuple[list, dict, dict]
Run the topostats tracing pipeline.
Returns:
| Type | Description |
|---|---|
tuple[list, dict, dict]
|
A list of each molecules ordered trace coordinates, the ordered_traicing stats, and the images. |
Source code in topostats\tracing\ordered_tracing.py
linear_or_circular(traces) -> bool
Determine whether the molecule is circular or linear via >1 points in the local start area.
This function is sensitive to branches from the skeleton because it is based on whether any given point has zero neighbours or not so the traces should be pruned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traces
|
NDArray
|
The array of coordinates to be assessed. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether a molecule is linear or not (True if linear, False otherwise). |
Source code in topostats\tracing\ordered_tracing.py
ordered_trace_mask(ordered_coordinates: npt.NDArray, shape: tuple) -> npt.NDArray
Obtain a mask of the trace coordinates with each trace pixel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ordered_coordinates
|
NDArray
|
Ordered array of coordinates. |
required |
shape
|
tuple
|
The shape of the array bounding the coordinates. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
NxM image with each pixel in the ordered trace labeled in ascending order. |
Source code in topostats\tracing\ordered_tracing.py
ordered_tracing_image(topostats_object: TopoStats, ordering_method: str) -> None
Run ordered tracing for an entire image of >=1 grains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topostats_object
|
TopoStats
|
TopoStats object to have ordered tracing performed on. |
required |
ordering_method
|
str
|
The method to order the trace coordinates - "topostats" or "nodestats". |
required |
Source code in topostats\tracing\ordered_tracing.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 | |