NodeStats Modules
Perform Crossing Region Processing and Analysis.
nodeStats
Class containing methods to find and analyse the nodes/crossings within a grain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grain_crop
|
GrainCrop
|
GrainCrop to be analysed. |
required |
n_grain
|
int
|
Grain being processed. |
required |
node_joining_length
|
float
|
The length over which to join skeletal intersections to be counted as one crossing. |
required |
node_joining_length
|
float
|
The distance over which to join nearby odd-branched nodes. |
required |
node_extend_dist
|
float
|
The distance under which to join odd-branched node regions. |
required |
branch_pairing_length
|
float
|
The length from the crossing point to pair and trace, obtaining FWHM's. |
required |
pair_odd_branches
|
bool
|
Whether to try and pair odd-branched nodes. |
required |
Source code in topostats\tracing\nodestats.py
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 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 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 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 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 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 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 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 | |
__init__(grain_crop: GrainCrop, n_grain: int, node_joining_length: float, node_extend_dist: float, branch_pairing_length: float, pair_odd_branches: bool) -> None
Initialise the nodeStats class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grain_crop
|
GrainCrop
|
GrainCrop node statistics are to be calculated for. |
required |
n_grain
|
int
|
Grain being processed. |
required |
node_joining_length
|
float
|
The distance over which to join nearby odd-branched nodes. |
required |
node_extend_dist
|
float
|
The distance under which to join odd-branched node regions. |
required |
branch_pairing_length
|
float
|
The length from the crossing point to pair and trace, obtaining FWHM's. |
required |
pair_odd_branches
|
bool
|
Whether to try and pair odd-branched nodes. |
required |
Source code in topostats\tracing\nodestats.py
above_below_value_idx(array: npt.NDArray, value: float) -> list
staticmethod
Identify indices of the array neighbouring the specified value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray
|
Array of values. |
required |
value
|
float
|
Value to identify indices between. |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of the lower index and higher index around the value. |
Raises:
| Type | Description |
|---|---|
IndexError
|
When the value is in the array. |
Source code in topostats\tracing\nodestats.py
add_branches_to_labelled_image(branch_under_over_order: npt.NDArray[np.int32], matched_branches: dict[int, MatchedBranch], masked_image: dict[int, dict[str, npt.NDArray[np.bool_]]], branch_start_coords: npt.NDArray[np.int32], ordered_branches: list[npt.NDArray[np.int32]], pairs: npt.NDArray[np.int32], average_trace_advised: bool, image_shape: tuple[int, int]) -> tuple[npt.NDArray[np.int32], npt.NDArray[np.int32]]
staticmethod
Add branches to a labelled image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch_under_over_order
|
NDArray[int32]
|
The order of the branches. |
required |
matched_branches
|
dict[int, MatchedBranch]
|
Dictionary of |
required |
masked_image
|
dict[int, dict[str, NDArray[bool_]]]
|
Dictionary where the key is the index of the pair and the value is a dictionary containing the following keys: - "avg_mask" : npt.NDArray[np.bool_]. Average mask of the branches. |
required |
branch_start_coords
|
NDArray[int32]
|
An Nx2 numpy array of the coordinates of the branches connected to the node. |
required |
ordered_branches
|
list[NDArray[int32]]
|
List of numpy arrays of ordered branch coordinates. |
required |
pairs
|
NDArray[int32]
|
Nx2 numpy array of pairs of branches that are matched through a node. |
required |
average_trace_advised
|
bool
|
Flag to determine whether to use the average trace. |
required |
image_shape
|
tuple[int]
|
The shape of the image, to create a mask from. |
required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray[int32], NDArray[int32]]
|
The branch image and the average image. |
Source code in topostats\tracing\nodestats.py
analyse_node_branches(p_to_nm: np.float64, reduced_node_area: npt.NDArray[np.int32], branch_start_coords: npt.NDArray[np.int32], max_length_px: np.float64, reduced_skeleton_graph: nx.classes.graph.Graph, image: npt.NDArray[np.number], average_trace_advised: bool, node_coord: tuple[np.int32, np.int32], pair_odd_branches: bool, filename: str, resolution_threshold: np.float64) -> tuple[npt.NDArray[np.int32], dict[int, MatchedBranch], list[npt.NDArray[np.int32]], dict[int, dict[str, npt.NDArray[np.bool_]]], npt.NDArray[np.int32], np.float64 | None]
staticmethod
Analyse the branches of a single node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_to_nm
|
float64
|
The pixel to nm scaling factor. |
required |
reduced_node_area
|
NDArray[int32]
|
An NxM numpy array of the node in question and the branches connected to it. Node is marked by 3, and branches by 1. |
required |
branch_start_coords
|
NDArray[int32]
|
An Nx2 numpy array of the coordinates of the branches connected to the node. |
required |
max_length_px
|
int32
|
The maximum length in pixels to traverse along while ordering. |
required |
reduced_skeleton_graph
|
Graph
|
The graph representation of the reduced node area. |
required |
image
|
NDArray[number]
|
The full image of the grain. |
required |
average_trace_advised
|
bool
|
Flag to determine whether to use the average trace. |
required |
node_coord
|
tuple[int32, int32]
|
The node coordinates. |
required |
pair_odd_branches
|
bool
|
Whether to try and pair odd-branched nodes. |
required |
filename
|
str
|
The filename of the image. |
required |
resolution_threshold
|
float64
|
The resolution threshold below which to warn the user that the node is difficult to analyse. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pairs |
NDArray[int32]
|
Nx2 numpy array of pairs of branches that are matched through a node. |
matched_branches |
dict[int, MatchedBranch]]
|
Dictionary where the key is the index of the pair and the value is a dictionary containing the following keys: - "ordered_coords" : npt.NDArray[np.int32]. - "heights" : npt.NDArray[np.number]. Heights of the branches. - "distances" : npt.NDArray[np.number]. The accumulating distance along the branch. - "fwhm" : npt.NDArray[np.number]. Full width half maximum of the branches. - "angles" : np.float64. The angle of the branch, added in later steps. |
ordered_branches |
list[NDArray[int32]]
|
List of numpy arrays of ordered branch coordinates. |
masked_image |
dict[int, dict[str, NDArray[bool_]]]
|
Dictionary where the key is the index of the pair and the value is a dictionary containing the following keys: - "avg_mask" : npt.NDArray[np.bool_]. Average mask of the branches. |
branch_under_over_order |
NDArray[int32]
|
The order of the branches based on the FWHM. |
confidence |
float64 | None
|
The confidence of the crossing. Optional. |
Source code in topostats\tracing\nodestats.py
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 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 | |
analyse_nodes(max_branch_length: float = 20) -> None
Obtain the main analyses for the nodes of a single molecule along the 'max_branch_length'(nm) from the node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_branch_length
|
float
|
The side length of the box around the node to analyse (in nm). |
20
|
Source code in topostats\tracing\nodestats.py
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 | |
average_height_trace(img: npt.NDArray, branch_mask: npt.NDArray, branch_coords: npt.NDArray, centre=(0, 0)) -> tuple
staticmethod
Average two side-by-side ordered skeleton distance and height traces.
Dilate the original branch to create two additional side-by-side branches in order to get a more accurate average of the height traces. This function produces the common distances between these 3 branches, and their averaged heights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray
|
An array of numbers pertaining to an image. |
required |
branch_mask
|
NDArray
|
A binary array of the branch, must share the same dimensions as the image. |
required |
branch_coords
|
NDArray
|
Ordered coordinates of the branch mask. |
required |
centre
|
Union[float, None]
|
The coordinates to centre the branch around. |
(0, 0)
|
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple of the averaged heights from the linetrace and their corresponding distances from the crossing. |
Source code in topostats\tracing\nodestats.py
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 | |
best_matches(arr: npt.NDArray, max_weight_matching: bool = True) -> npt.NDArray
staticmethod
Turn a matrix into a graph and calculates the best matching index pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
NDArray
|
Transpose symmetric MxM array where the value of index i, j represents a weight between i and j. |
required |
max_weight_matching
|
bool
|
Whether to obtain best matching pairs via maximum weight, or minimum weight matching. |
True
|
Returns:
| Type | Description |
|---|---|
NDArray
|
Array of pairs of indexes. |
Source code in topostats\tracing\nodestats.py
binary_line(start: npt.NDArray, end: npt.NDArray) -> npt.NDArray
staticmethod
Create a binary path following the straight line between 2 points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
NDArray
|
A coordinate. |
required |
end
|
NDArray
|
Another coordinate. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
An Nx2 coordinate array that the line passes through. |
Source code in topostats\tracing\nodestats.py
calc_angles(vectors: npt.NDArray) -> npt.NDArray[np.float64]
staticmethod
Calculate the angles between vectors in an array.
Uses the formula:
.. code-block:: RST
cos(theta) = |a|•|b|/|a||b|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vectors
|
NDArray
|
Array of 2x1 vectors. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
An array of the cosine of the angles between the vectors. |
Source code in topostats\tracing\nodestats.py
calculate_fwhm(heights: npt.NDArray, distances: npt.NDArray, half_max: float | None = None) -> tuple[np.float64 | list[np.float64] | None]
staticmethod
Calculate the FWHM value.
First identifyies the HM then finding the closest values in the distances array and using linear interpolation to calculate the FWHM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heights
|
NDArray
|
Array of heights. |
required |
distances
|
NDArray
|
Array of distances. |
required |
half_max
|
Union[None, float]
|
The halfmax value to match (if wanting the same HM between curves), by default None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, list, list]
|
The FWHM value, [distance at hm for 1st half of trace, distance at hm for 2nd half of trace, HM value], [index of the highest point, distance at highest point, height at highest point]. |
Source code in topostats\tracing\nodestats.py
compile_metrics() -> None
Add number of crossings, mean and minimum crossing confidence to the grain_crops.stats dictionary.
Source code in topostats\tracing\nodestats.py
connect_close_nodes(conv_skeleton: npt.NDArray, node_width: float = 2.85) -> npt.NDArray
Connect nodes within the 'node_width' boundary distance.
This labels them as part of the same node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conv_skeleton
|
NDArray
|
A labeled skeleton image with skeleton = 1, endpoints = 2, crossing points =3. |
required |
node_width
|
float
|
The width of the dna in the grain, used to connect close nodes. |
2.85
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The skeleton (label=1) with close nodes connected (label=3). |
Source code in topostats\tracing\nodestats.py
connect_extended_nodes_nearest(connected_nodes: npt.NDArray, node_extend_dist: float = -1) -> npt.NDArray[np.int32]
Extend the odd branched nodes to other odd branched nodes within the 'extend_dist' threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connected_nodes
|
NDArray
|
A 2D array representing the network with background = 0, skeleton = 1, endpoints = 2, node_centres = 3. |
required |
node_extend_dist
|
int | float
|
The distance over which to connect odd-branched nodes, by default -1 for no-limit. |
-1
|
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
Connected nodes array with odd-branched nodes connected. |
Source code in topostats\tracing\nodestats.py
coord_dist_rad(coords: npt.NDArray, centre: npt.NDArray, pixel_to_nm_scaling: float = 1) -> npt.NDArray
staticmethod
Calculate the distance from the centre coordinate to a point along the ordered coordinates.
This differs to traversal along the coordinates taken. This also averages any common distance values and makes those in the trace before the node index negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
NDArray
|
Nx2 array of branch coordinates. |
required |
centre
|
NDArray
|
A 1x2 array of the centre coordinates to identify a 0 point for the node. |
required |
pixel_to_nm_scaling
|
float
|
The pixel to nanometer scaling factor to provide real units, by default 1. |
1
|
Returns:
| Type | Description |
|---|---|
NDArray
|
A Nx1 array of the distance from the node centre. |
Source code in topostats\tracing\nodestats.py
create_weighted_graph(matrix: npt.NDArray) -> nx.Graph
staticmethod
Create a bipartite graph connecting i <-> j from a square matrix of weights matrix[i, j].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
NDArray
|
Square array of weights between rows and columns. |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
Bipatrite graph with edge weight i->j matching matrix[i,j]. |
Source code in topostats\tracing\nodestats.py
cross_confidence(pair_combinations: list) -> float
staticmethod
Obtain the average confidence of the combinations using a reciprical function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair_combinations
|
list
|
List of length 2 combinations of FWHM values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The average crossing confidence. |
Source code in topostats\tracing\nodestats.py
crossing_confidence_statistics() -> tuple[None | float]
Calculate crossing statistics (number, mean and minimum confidence).
Returns:
| Type | Description |
|---|---|
tuple[float | None]
|
The arithmetic mean and minimum confidence across all crossings within a grain. |
Source code in topostats\tracing\nodestats.py
fill_holes(mask: npt.NDArray) -> npt.NDArray
staticmethod
Fill all holes within a binary mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
NDArray
|
Binary array of object. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
Binary array of object with any interior holes filled in. |
Source code in topostats\tracing\nodestats.py
find_branch_starts(reduced_node_image: npt.NDArray) -> npt.NDArray
staticmethod
Find the coordinates where the branches connect to the node region through binary dilation of the node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reduced_node_image
|
NDArray
|
A 2D numpy array containing a single node region (=3) and its connected branches (=1). |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
Coordinate array of pixels next to crossing points (=3 in input). |
Source code in topostats\tracing\nodestats.py
gaussian(x: npt.NDArray, h: float, mean: float, sigma: float)
staticmethod
Apply the gaussian function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
X values to be passed into the gaussian. |
required |
h
|
float
|
The peak height of the gaussian. |
required |
mean
|
float
|
The mean of the x values. |
required |
sigma
|
float
|
The standard deviation of the image. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The y-values of the gaussian performed on the x values. |
Source code in topostats\tracing\nodestats.py
get_node_stats() -> dict[int, npt.NDArray]
Run the workflow to obtain the node statistics.
Statistics are added to the Node attribute of GrainCrop.
Returns:
| Type | Description |
|---|---|
dict[int, NDArray]
|
Dictionary of images. |
Source code in topostats\tracing\nodestats.py
get_ordered_branches_and_vectors(reduced_node_area: npt.NDArray[np.int32], branch_start_coords: npt.NDArray[np.int32], max_length_px: np.float64) -> tuple[list[npt.NDArray[np.int32]], list[npt.NDArray[np.int32]]]
staticmethod
Get ordered branches and vectors for a node.
Branches are ordered so they are no longer just a disordered set of coordinates, and vectors are calculated to represent the general direction tendency of the branch, this allows for alignment matching later on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reduced_node_area
|
NDArray[int32]
|
An NxM numpy array of the node in question and the branches connected to it. Node is marked by 3, and branches by 1. |
required |
branch_start_coords
|
NDArray[int32]
|
An Px2 numpy array of coordinates representing the start of branches where P is the number of branches. |
required |
max_length_px
|
int32
|
The maximum length in pixels to traverse along while ordering. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[NDArray[int32]], list[NDArray[int32]]]
|
A tuple containing a list of ordered branches and a list of vectors. |
Source code in topostats\tracing\nodestats.py
get_vector(coords: npt.NDArray, origin: npt.NDArray) -> npt.NDArray
staticmethod
Calculate the normalised vector of the coordinate means in a branch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
NDArray
|
2xN array of x, y coordinates. |
required |
origin
|
NDArray
|
2x1 array of an x, y coordinate. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
Normalised vector from origin to the mean coordinate. |
Source code in topostats\tracing\nodestats.py
graph_to_skeleton_image(g: nx.Graph, im_shape: tuple[int]) -> npt.NDArray
staticmethod
Convert the skeleton graph back to a binary image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Graph with coordinates as node labels. |
required |
im_shape
|
tuple[int]
|
The shape of the image to dump. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
Skeleton binary image from the graph representation. |
Source code in topostats\tracing\nodestats.py
highlight_node_centres(mask: npt.NDArray) -> npt.NDArray
Calculate the node centres based on height and re-plot on the mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
NDArray
|
2D array with background = 0, skeleton = 1, endpoints = 2, node_centres = 3. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
2D array with the highest node coordinate for each node labeled as 3. |
Source code in topostats\tracing\nodestats.py
interpolate_between_yvalue(x: npt.NDArray, y: npt.NDArray, yvalue: float) -> float
staticmethod
Calculate the x value between the two points either side of yvalue in y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
An array of length y. |
required |
y
|
NDArray
|
An array of length x. |
required |
yvalue
|
float
|
A value within the bounds of the y array. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The linearly interpolated x value between the arrays. |
Source code in topostats\tracing\nodestats.py
join_matching_branches_through_node(pairs: npt.NDArray[np.int32], ordered_branches: list[npt.NDArray[np.int32]], reduced_skeleton_graph: nx.classes.graph.Graph, image: npt.NDArray[np.number], average_trace_advised: bool, node_coords: tuple[np.int32, np.int32], filename: str) -> tuple[dict[int, MatchedBranch], dict[int, dict[str, npt.NDArray[np.bool_]]]]
staticmethod
Join branches that are matched through a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pairs
|
NDArray[int32]
|
Nx2 numpy array of pairs of branches that are matched through a node. |
required |
ordered_branches
|
list[NDArray[int32]]
|
List of numpy arrays of ordered branch coordinates. |
required |
reduced_skeleton_graph
|
Graph
|
Graph representation of the skeleton. |
required |
image
|
NDArray[number]
|
The full image of the grain. |
required |
average_trace_advised
|
bool
|
Flag to determine whether to use the average trace. |
required |
node_coords
|
tuple[int32, int32]
|
The node coordinates. |
required |
filename
|
str
|
The filename of the image. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
matched_branches |
dict[int, dict[str, NDArray[number]]]
|
Dictionary where the key is the index of the pair and the value is a dictionary containing the following keys: - "ordered_coords" : npt.NDArray[np.int32]. - "heights" : npt.NDArray[np.number]. Heights of the branches. - "distances" : - "fwhm" : npt.NDArray[np.number]. Full width half maximum of the branches. |
masked_image |
dict[int, dict[str, NDArray[bool_]]]
|
Dictionary where the key is the index of the pair and the value is a dictionary containing the following keys: - "avg_mask" : npt.NDArray[np.bool_]. Average mask of the branches. |
Source code in topostats\tracing\nodestats.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 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 | |
keep_biggest_object(mask: npt.NDArray) -> npt.NDArray
staticmethod
Retain the largest object in a binary mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
NDArray
|
Binary mask. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
A binary mask with only one object. |
Source code in topostats\tracing\nodestats.py
lin_interp(point_1: list, point_2: list, xvalue: float | None = None, yvalue: float | None = None) -> float
staticmethod
Linear interpolation between two points by finding line equation and subbing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_1
|
list
|
|
required |
point_2
|
list
|
|
required |
xvalue
|
float
|
Value at which to interpolate to get a y coordinate, by default None. |
None
|
yvalue
|
float
|
Value at which to interpolate to get an x coordinate, by default None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Value of x or y linear interpolation. |
Source code in topostats\tracing\nodestats.py
mean_uniques(arr1: npt.NDArray, arr2: npt.NDArray) -> tuple
staticmethod
Obtain the unique values of both arrays, and the mean of common values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr1
|
NDArray
|
An array. |
required |
arr2
|
NDArray
|
An array. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
The unique values of both arrays, and the mean of common values. |
Source code in topostats\tracing\nodestats.py
only_centre_branches(node_image: npt.NDArray, node_coordinate: npt.NDArray) -> npt.NDArray[np.int32]
staticmethod
Remove all branches not connected to the current node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_image
|
NDArray
|
An image of the skeletonised area surrounding the node where the background = 0, skeleton = 1, termini = 2, nodes = 3. |
required |
node_coordinate
|
NDArray
|
2x1 coordinate describing the position of a node. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
The initial node image but only with skeletal branches connected to the middle node. |
Source code in topostats\tracing\nodestats.py
order_branches(branch1: npt.NDArray, branch2: npt.NDArray) -> tuple
staticmethod
Order the two ordered arrays based on the closest endpoint coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch1
|
NDArray
|
An Nx2 array describing coordinates. |
required |
branch2
|
NDArray
|
An Nx2 array describing coordinates. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
An tuple with the each coordinate array ordered to follow on from one-another. |
Source code in topostats\tracing\nodestats.py
pair_angles(angles: npt.NDArray) -> list
staticmethod
Pair angles that are 180 degrees to each other and removes them before selecting the next pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angles
|
NDArray
|
Square array (i,j) of angles between i and j. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A list of paired indexes in a list. |
Source code in topostats\tracing\nodestats.py
pair_vectors(vectors: npt.NDArray) -> npt.NDArray[np.int32]
staticmethod
Take a list of vectors and pairs them based on the angle between them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vectors
|
NDArray
|
Array of 2x1 vectors to be paired. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
An array of the matching pair indices. |
Source code in topostats\tracing\nodestats.py
recip(vals: list) -> float
staticmethod
Compute 1 - (max / min) of the two values provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vals
|
list
|
List of 2 values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Result of applying the 1-(min / max) function to the two values. |
Source code in topostats\tracing\nodestats.py
skeleton_image_to_graph(skeleton: npt.NDArray) -> nx.classes.graph.Graph
staticmethod
Convert a skeletonised mask into a Graph representation.
Graphs conserve the coordinates via the node label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
NDArray
|
A binary single-pixel wide mask, or result from conv_skeleton(). |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
A networkX graph connecting the pixels in the skeleton to their neighbours. |
Source code in topostats\tracing\nodestats.py
tidy_branches(connect_node_mask: npt.NDArray, image: npt.NDArray) -> npt.NDArray
Wrangle distant connected nodes back towards the main cluster.
Works by filling and reskeletonising soely the node areas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connect_node_mask
|
NDArray
|
The connected node mask - a skeleton where node regions = 3, endpoints = 2, and skeleton = 1. |
required |
image
|
NDArray
|
The intensity image. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The wrangled connected_node_mask. |
Source code in topostats\tracing\nodestats.py
nodestats_image(topostats_object: TopoStats, node_joining_length: float, node_extend_dist: float, branch_pairing_length: float, pair_odd_branches: float) -> None
Calculate Node Statistics for a single crop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topostats_object
|
TopoStats
|
TopoStats object from which grains are extracted. |
required |
node_joining_length
|
float
|
The length over which to join skeletal intersections to be counted as one crossing. |
required |
node_joining_length
|
float
|
The distance over which to join nearby odd-branched nodes. |
required |
node_extend_dist
|
float
|
The distance under which to join odd-branched node regions. |
required |
branch_pairing_length
|
float
|
The length from the crossing point to pair and trace, obtaining FWHM's. |
required |
pair_odd_branches
|
bool
|
Whether to try and pair odd-branched nodes. |
required |
Source code in topostats\tracing\nodestats.py
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 | |