Geometry Modules
Functions for measuring geometric properties of grains.
bounding_box_cartesian_points_float(points: npt.NDArray[np.number]) -> tuple[np.float64, np.float64, np.float64, np.float64]
Calculate the bounding box from a set of points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray[number]
|
Nx2 numpy array of points. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float64, float64, float64, float64]
|
Tuple of (min_x, min_y, max_x, max_y). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input array is not Nx2. |
Source code in topostats\measure\geometry.py
bounding_box_cartesian_points_integer(points: npt.NDArray[np.number]) -> tuple[np.int32, np.int32, np.int32, np.int32]
Calculate the bounding box from a set of points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray[number]
|
Nx2 numpy array of points. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int32, int32, int32, int32]
|
Tuple of (min_x, min_y, max_x, max_y). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input array is not Nx2. |
Source code in topostats\measure\geometry.py
calculate_shortest_branch_distances(nodes_with_branch_starting_coords: dict[int, list[npt.NDArray[np.int32]]], whole_skeleton_graph: networkx.classes.graph.Graph) -> tuple[npt.NDArray[np.number], npt.NDArray[np.int32], npt.NDArray[np.number]]
Calculate the shortest distances between branches emanating from nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes_with_branch_starting_coords
|
dict[int, list[NDArray[int32]]]
|
Dictionary where the key is the node number and the value is an Nx2 numpy array of the starting coordinates of its branches. |
required |
whole_skeleton_graph
|
Graph
|
Networkx graph representing the whole network. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[NDArray[number], NDArray[int32], NDArray[int32]]
|
|
Source code in topostats\measure\geometry.py
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 | |
connect_best_matches(network_array_representation: npt.NDArray[np.int32], whole_skeleton_graph: networkx.classes.graph.Graph, match_indexes: npt.NDArray[np.int32], shortest_distances_between_nodes: npt.NDArray[np.number], shortest_distances_branch_indexes: npt.NDArray[np.int32], emanating_branch_starts_by_node: dict[int, list[npt.NDArray[np.int32]]], extend_distance: float = -1) -> npt.NDArray[np.int32]
Connect the branches between node pairs that have been deemed to be best matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_array_representation
|
NDArray[int32]
|
2D numpy array representing the network using integers to represent branches, nodes etc. |
required |
whole_skeleton_graph
|
Graph
|
Networkx graph representing the whole network. |
required |
match_indexes
|
NDArray[int32]
|
Nx2 numpy array of indexes of the best matching nodes. Eg: np.array([[1, 0], [2, 3]]) means that the best matching nodes are node 1 and node 0, and node 2 and node 3. |
required |
shortest_distances_between_nodes
|
NDArray[number]
|
NxN numpy array of shortest distances between every node pair. Index positions indicate which node it's referring to, so index 2, 3 will be the shortest distance between nodes 2 and 3. Values on the diagonal will be 0 because the shortest distance between a node and itself is 0. Eg: np.array([[0.0, 6.0], [6.0, 0.0]]) means that the shortest distance between node 0 and node 1 is 6.0. |
required |
shortest_distances_branch_indexes
|
NDArray[int32]
|
NxNx2 numpy array of indexes of the branches to connect between the best matching nodes. Not entirely sure what it does so won't attempt to explain more to avoid confusion. |
required |
emanating_branch_starts_by_node
|
dict[int, list[NDArray[int32]]]
|
Dictionary where the key is the node number and the value is an Nx2 numpy array of the starting coordinates
of the branches emanating from that node. Rather self-explanatory.
Eg:
|
required |
extend_distance
|
float
|
The distance to extend the branches to connect. If the shortest distance between two nodes is less than or equal to this distance, the branches will be connected. If -1, the branches will be connected regardless of distance. |
-1
|
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
2D numpy array representing the network using integers to represent branches, nodes etc. |
Source code in topostats\measure\geometry.py
do_points_in_arrays_touch(points1: npt.NDArray[np.int32], points2: npt.NDArray[np.int32]) -> tuple[bool, npt.NDArray[np.int32] | None, npt.NDArray[np.int32] | None]
Check if any points in two arrays are touching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points1
|
NDArray[int32]
|
Nx2 numpy array of points. |
required |
points2
|
NDArray[int32]
|
Mx2 numpy array of points. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, NDArray[int32] | None, NDArray[int32] | None]
|
True if any points in the two arrays are touching, False otherwise, followed by the first touching point pair that was found. If no points are touching, the second and third elements of the tuple will be None. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input arrays are not Nx2 and Mx2. |
Source code in topostats\measure\geometry.py
find_branches_for_nodes(network_array_representation: npt.NDArray[np.int32], labelled_nodes: npt.NDArray[np.int32], labelled_branches: npt.NDArray[np.int32]) -> dict[int, list[npt.NDArray[np.int32]]]
Locate branch starting positions for each node in a network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_array_representation
|
NDArray[int32]
|
2D numpy array representing the network using integers to represent branches, nodes etc. |
required |
labelled_nodes
|
NDArray[int32]
|
2D numpy array representing the network using integers to represent nodes. |
required |
labelled_branches
|
NDArray[int32]
|
2D numpy array representing the network using integers to represent branches. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, list[NDArray[int32]]]
|
Dictionary where the key is the node number and the value is an Nx2 numpy array of the starting coordinates of the branches emanating from that node. |