topostats.tracing.nodestats#
Perform Crossing Region Processing and Analysis.
Attributes#
Classes#
Dictionary containing the node information. |
|
Dictionary containing the matched branches. |
|
Dictionary containing the image information. |
|
Class containing methods to find and analyse the nodes/crossings within a grain. |
Functions#
|
Initialise the nodeStats class. |
Module Contents#
- topostats.tracing.nodestats.LOGGER#
- class topostats.tracing.nodestats.NodeDict[source]#
Bases:
TypedDict
Dictionary containing the node information.
- error: bool#
- pixel_to_nm_scaling: numpy.float64#
- branch_stats: dict[int, MatchedBranch] | None#
- node_coords: numpy.typing.NDArray[numpy.int32] | None#
- confidence: numpy.float64 | None#
- class topostats.tracing.nodestats.MatchedBranch[source]#
Bases:
TypedDict
Dictionary containing the matched branches.
- matched_branches: dict[int, dict[str, npt.NDArray[np.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]. The ordered coordinates of the branch. - “heights” : npt.NDArray[np.number]. Heights of the branch coordinates. - “distances” : npt.NDArray[np.number]. Distances of the branch coordinates. - “fwhm” : npt.NDArray[np.number]. Full width half maximum of the branch. - “angles” : np.float64. The initial direction angle of the branch, added in later steps.
- ordered_coords: numpy.typing.NDArray[numpy.int32]#
- heights: numpy.typing.NDArray[numpy.number]#
- distances: numpy.typing.NDArray[numpy.number]#
- fwhm: dict[str, numpy.float64 | tuple[numpy.float64]]#
- angles: numpy.float64 | None#
- class topostats.tracing.nodestats.ImageDict[source]#
Bases:
TypedDict
Dictionary containing the image information.
- nodes: dict[str, dict[str, numpy.typing.NDArray[numpy.int32]]]#
- grain: dict[str, numpy.typing.NDArray[numpy.int32] | dict[str, numpy.typing.NDArray[numpy.int32]]]#
- class topostats.tracing.nodestats.nodeStats(filename: str, image: numpy.typing.NDArray, mask: numpy.typing.NDArray, smoothed_mask: numpy.typing.NDArray, skeleton: numpy.typing.NDArray, pixel_to_nm_scaling: numpy.float64, n_grain: int, node_joining_length: float, node_extend_dist: float, branch_pairing_length: float, pair_odd_branches: bool)[source]#
Class containing methods to find and analyse the nodes/crossings within a grain.
- Parameters:
filename (str) – The name of the file being processed. For logging purposes.
image (npt.npt.NDArray) – The array of pixels.
mask (npt.npt.NDArray) – The binary segmentation mask.
smoothed_mask (npt.NDArray) – A smoothed version of the bianary segmentation mask.
skeleton (npt.NDArray) – A binary single-pixel wide mask of objects in the ‘image’.
pixel_to_nm_scaling (np.float32) – The pixel to nm scaling factor.
n_grain (int) – The grain number.
node_joining_length (float) – The length over which to join skeletal intersections to be counted as one crossing.
node_joining_length – The distance over which to join nearby odd-branched nodes.
node_extend_dist (float) – The distance under which to join odd-branched node regions.
branch_pairing_length (float) – The length from the crossing point to pair and trace, obtaining FWHM’s.
pair_odd_branches (bool) – Whether to try and pair odd-branched nodes.
- filename#
- image#
- mask#
- smoothed_mask#
- skeleton#
- pixel_to_nm_scaling#
- n_grain#
- node_joining_length#
- node_extend_dist#
- branch_pairing_length#
- pair_odd_branches#
- conv_skelly#
- connected_nodes#
- all_connected_nodes#
- whole_skel_graph: networkx.classes.graph.Graph | None = None#
- node_centre_mask#
- metrics#
- full_dict#
- mol_coords#
- visuals#
- all_visuals_img = None#
- get_node_stats() tuple[dict, dict] [source]#
Run the workflow to obtain the node statistics.
node_dict key structure: <grain_number> └-> <node_number> |-> 'error' └-> 'node_coords' └-> 'branch_stats' └-> <branch_number> |-> 'ordered_coords' |-> 'heights' |-> 'gaussian_fit' |-> 'fwhm' └-> 'angles' image_dict key structure: 'nodes' <node_number> |-> 'node_area_skeleton' |-> 'node_branch_mask' └-> 'node_avg_mask 'grain' |-> 'grain_image' |-> 'grain_mask' └-> 'grain_skeleton'
- Returns:
Dictionaries of the node_information and images.
- Return type:
tuple[dict, dict]
- static skeleton_image_to_graph(skeleton: numpy.typing.NDArray) networkx.classes.graph.Graph [source]#
Convert a skeletonised mask into a Graph representation.
Graphs conserve the coordinates via the node label.
- Parameters:
skeleton (npt.NDArray) – A binary single-pixel wide mask, or result from conv_skelly().
- Returns:
A networkX graph connecting the pixels in the skeleton to their neighbours.
- Return type:
nx.classes.graph.Graph
- static graph_to_skeleton_image(g: networkx.Graph, im_shape: tuple[int]) numpy.typing.NDArray [source]#
Convert the skeleton graph back to a binary image.
- Parameters:
g (nx.Graph) – Graph with coordinates as node labels.
im_shape (tuple[int]) – The shape of the image to dump.
- Returns:
Skeleton binary image from the graph representation.
- Return type:
npt.NDArray
- tidy_branches(connect_node_mask: numpy.typing.NDArray, image: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Wrangle distant connected nodes back towards the main cluster.
Works by filling and reskeletonising soely the node areas.
- Parameters:
connect_node_mask (npt.NDArray) – The connected node mask - a skeleton where node regions = 3, endpoints = 2, and skeleton = 1.
image (npt.NDArray) – The intensity image.
- Returns:
The wrangled connected_node_mask.
- Return type:
npt.NDArray
- static keep_biggest_object(mask: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Retain the largest object in a binary mask.
- Parameters:
mask (npt.NDArray) – Binary mask.
- Returns:
A binary mask with only one object.
- Return type:
npt.NDArray
- connect_close_nodes(conv_skelly: numpy.typing.NDArray, node_width: float = 2.85) numpy.typing.NDArray [source]#
Connect nodes within the ‘node_width’ boundary distance.
This labels them as part of the same node.
- Parameters:
conv_skelly (npt.NDArray) – A labeled skeleton image with skeleton = 1, endpoints = 2, crossing points =3.
node_width (float) – The width of the dna in the grain, used to connect close nodes.
- Returns:
The skeleton (label=1) with close nodes connected (label=3).
- Return type:
np.ndarray
- highlight_node_centres(mask: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Calculate the node centres based on height and re-plot on the mask.
- Parameters:
mask (npt.NDArray) – 2D array with background = 0, skeleton = 1, endpoints = 2, node_centres = 3.
- Returns:
2D array with the highest node coordinate for each node labeled as 3.
- Return type:
npt.NDArray
- connect_extended_nodes_nearest(connected_nodes: numpy.typing.NDArray, node_extend_dist: float = -1) numpy.typing.NDArray[numpy.int32] [source]#
Extend the odd branched nodes to other odd branched nodes within the ‘extend_dist’ threshold.
- Parameters:
connected_nodes (npt.NDArray) – A 2D array representing the network with background = 0, skeleton = 1, endpoints = 2, node_centres = 3.
node_extend_dist (int | float, optional) – The distance over which to connect odd-branched nodes, by default -1 for no-limit.
- Returns:
Connected nodes array with odd-branched nodes connected.
- Return type:
npt.NDArray[np.int32]
- static find_branch_starts(reduced_node_image: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Find the coordinates where the branches connect to the node region through binary dilation of the node.
- Parameters:
reduced_node_image (npt.NDArray) – A 2D numpy array containing a single node region (=3) and its connected branches (=1).
- Returns:
Coordinate array of pixels next to crossing points (=3 in input).
- Return type:
npt.NDArray
- analyse_nodes(max_branch_length: float = 20) None [source]#
Obtain the main analyses for the nodes of a single molecule along the ‘max_branch_length’(nm) from the node.
- Parameters:
max_branch_length (float) – The side length of the box around the node to analyse (in nm).
- static add_branches_to_labelled_image(branch_under_over_order: numpy.typing.NDArray[numpy.int32], matched_branches: dict[int, MatchedBranch], masked_image: dict[int, dict[str, numpy.typing.NDArray[numpy.bool_]]], branch_start_coords: numpy.typing.NDArray[numpy.int32], ordered_branches: list[numpy.typing.NDArray[numpy.int32]], pairs: numpy.typing.NDArray[numpy.int32], average_trace_advised: bool, image_shape: tuple[int, int]) tuple[numpy.typing.NDArray[numpy.int32], numpy.typing.NDArray[numpy.int32]] [source]#
Add branches to a labelled image.
- Parameters:
branch_under_over_order (npt.NDArray[np.int32]) – The order of the branches.
matched_branches (dict[int, dict[str, 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” : - “fwhm” : npt.NDArray[np.number]. Full width half maximum of the branches.
masked_image (dict[int, dict[str, npt.NDArray[np.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_start_coords (npt.NDArray[np.int32]) – An Nx2 numpy array of the coordinates of the branches connected to the node.
ordered_branches (list[npt.NDArray[np.int32]]) – List of numpy arrays of ordered branch coordinates.
pairs (npt.NDArray[np.int32]) – Nx2 numpy array of pairs of branches that are matched through a node.
average_trace_advised (bool) – Flag to determine whether to use the average trace.
image_shape (tuple[int]) – The shape of the image, to create a mask from.
- Returns:
The branch image and the average image.
- Return type:
tuple[npt.NDArray[np.int32], npt.NDArray[np.int32]]
- static analyse_node_branches(p_to_nm: numpy.float64, reduced_node_area: numpy.typing.NDArray[numpy.int32], branch_start_coords: numpy.typing.NDArray[numpy.int32], max_length_px: numpy.float64, reduced_skeleton_graph: networkx.classes.graph.Graph, image: numpy.typing.NDArray[numpy.number], average_trace_advised: bool, node_coord: tuple[numpy.int32, numpy.int32], pair_odd_branches: bool, filename: str, resolution_threshold: numpy.float64) tuple[numpy.typing.NDArray[numpy.int32], dict[int, MatchedBranch], list[numpy.typing.NDArray[numpy.int32]], dict[int, dict[str, numpy.typing.NDArray[numpy.bool_]]], numpy.typing.NDArray[numpy.int32], numpy.float64 | None] [source]#
Analyse the branches of a single node.
- Parameters:
p_to_nm (np.float64) – The pixel to nm scaling factor.
reduced_node_area (npt.NDArray[np.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.
branch_start_coords (npt.NDArray[np.int32]) – An Nx2 numpy array of the coordinates of the branches connected to the node.
max_length_px (np.int32) – The maximum length in pixels to traverse along while ordering.
reduced_skeleton_graph (nx.classes.graph.Graph) – The graph representation of the reduced node area.
image (npt.NDArray[np.number]) – The full image of the grain.
average_trace_advised (bool) – Flag to determine whether to use the average trace.
node_coord (tuple[np.int32, np.int32]) – The node coordinates.
pair_odd_branches (bool) – Whether to try and pair odd-branched nodes.
filename (str) – The filename of the image.
resolution_threshold (np.float64) – The resolution threshold below which to warn the user that the node is difficult to analyse.
- Returns:
pairs (npt.NDArray[np.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[npt.NDArray[np.int32]]) – List of numpy arrays of ordered branch coordinates.
masked_image (dict[int, dict[str, npt.NDArray[np.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 (npt.NDArray[np.int32]) – The order of the branches based on the FWHM.
confidence (np.float64 | None) – The confidence of the crossing. Optional.
- static join_matching_branches_through_node(pairs: numpy.typing.NDArray[numpy.int32], ordered_branches: list[numpy.typing.NDArray[numpy.int32]], reduced_skeleton_graph: networkx.classes.graph.Graph, image: numpy.typing.NDArray[numpy.number], average_trace_advised: bool, node_coords: tuple[numpy.int32, numpy.int32], filename: str) tuple[dict[int, MatchedBranch], dict[int, dict[str, numpy.typing.NDArray[numpy.bool_]]]] [source]#
Join branches that are matched through a node.
- Parameters:
pairs (npt.NDArray[np.int32]) – Nx2 numpy array of pairs of branches that are matched through a node.
ordered_branches (list[npt.NDArray[np.int32]]) – List of numpy arrays of ordered branch coordinates.
reduced_skeleton_graph (nx.classes.graph.Graph) – Graph representation of the skeleton.
image (npt.NDArray[np.number]) – The full image of the grain.
average_trace_advised (bool) – Flag to determine whether to use the average trace.
node_coords (tuple[np.int32, np.int32]) – The node coordinates.
filename (str) – The filename of the image.
- Returns:
matched_branches (dict[int, dict[str, npt.NDArray[np.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, npt.NDArray[np.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.
- static get_ordered_branches_and_vectors(reduced_node_area: numpy.typing.NDArray[numpy.int32], branch_start_coords: numpy.typing.NDArray[numpy.int32], max_length_px: numpy.float64) tuple[list[numpy.typing.NDArray[numpy.int32]], list[numpy.typing.NDArray[numpy.int32]]] [source]#
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:
reduced_node_area (npt.NDArray[np.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.
branch_start_coords (npt.NDArray[np.int32]) – An Px2 numpy array of coordinates representing the start of branches where P is the number of branches.
max_length_px (np.int32) – The maximum length in pixels to traverse along while ordering.
- Returns:
A tuple containing a list of ordered branches and a list of vectors.
- Return type:
tuple[list[npt.NDArray[np.int32]], list[npt.NDArray[np.int32]]]
- static cross_confidence(pair_combinations: list) float [source]#
Obtain the average confidence of the combinations using a reciprical function.
- Parameters:
pair_combinations (list) – List of length 2 combinations of FWHM values.
- Returns:
The average crossing confidence.
- Return type:
float
- static recip(vals: list) float [source]#
Compute 1 - (max / min) of the two values provided.
- Parameters:
vals (list) – List of 2 values.
- Returns:
Result of applying the 1-(min / max) function to the two values.
- Return type:
float
- static get_vector(coords: numpy.typing.NDArray, origin: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Calculate the normalised vector of the coordinate means in a branch.
- Parameters:
coords (npt.NDArray) – 2xN array of x, y coordinates.
origin (npt.NDArray) – 2x1 array of an x, y coordinate.
- Returns:
Normalised vector from origin to the mean coordinate.
- Return type:
npt.NDArray
- static calc_angles(vectors: numpy.typing.NDArray) numpy.typing.NDArray[numpy.float64] [source]#
Calculate the angles between vectors in an array.
Uses the formula:
cos(theta) = |a|•|b|/|a||b|
- Parameters:
vectors (npt.NDArray) – Array of 2x1 vectors.
- Returns:
An array of the cosine of the angles between the vectors.
- Return type:
npt.NDArray
- static pair_vectors(vectors: numpy.typing.NDArray) numpy.typing.NDArray[numpy.int32] [source]#
Take a list of vectors and pairs them based on the angle between them.
- Parameters:
vectors (npt.NDArray) – Array of 2x1 vectors to be paired.
- Returns:
An array of the matching pair indices.
- Return type:
npt.NDArray
- static best_matches(arr: numpy.typing.NDArray, max_weight_matching: bool = True) numpy.typing.NDArray [source]#
Turn a matrix into a graph and calculates the best matching index pairs.
- Parameters:
arr (npt.NDArray) – Transpose symmetric MxM array where the value of index i, j represents a weight between i and j.
max_weight_matching (bool) – Whether to obtain best matching pairs via maximum weight, or minimum weight matching.
- Returns:
Array of pairs of indexes.
- Return type:
npt.NDArray
- static create_weighted_graph(matrix: numpy.typing.NDArray) networkx.Graph [source]#
Create a bipartite graph connecting i <-> j from a square matrix of weights matrix[i, j].
- Parameters:
matrix (npt.NDArray) – Square array of weights between rows and columns.
- Returns:
Bipatrite graph with edge weight i->j matching matrix[i,j].
- Return type:
nx.Graph
- static pair_angles(angles: numpy.typing.NDArray) list [source]#
Pair angles that are 180 degrees to each other and removes them before selecting the next pair.
- Parameters:
angles (npt.NDArray) – Square array (i,j) of angles between i and j.
- Returns:
A list of paired indexes in a list.
- Return type:
list
- static gaussian(x: numpy.typing.NDArray, h: float, mean: float, sigma: float)[source]#
Apply the gaussian function.
- Parameters:
x (npt.NDArray) – X values to be passed into the gaussian.
h (float) – The peak height of the gaussian.
mean (float) – The mean of the x values.
sigma (float) – The standard deviation of the image.
- Returns:
The y-values of the gaussian performed on the x values.
- Return type:
npt.NDArray
- static interpolate_between_yvalue(x: numpy.typing.NDArray, y: numpy.typing.NDArray, yvalue: float) float [source]#
Calculate the x value between the two points either side of yvalue in y.
- Parameters:
x (npt.NDArray) – An array of length y.
y (npt.NDArray) – An array of length x.
yvalue (float) – A value within the bounds of the y array.
- Returns:
The linearly interpolated x value between the arrays.
- Return type:
float
- static calculate_fwhm(heights: numpy.typing.NDArray, distances: numpy.typing.NDArray, hm: float | None = None) dict[str, numpy.float64 | list[numpy.float64 | float | None]] [source]#
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:
heights (npt.NDArray) – Array of heights.
distances (npt.NDArray) – Array of distances.
hm (Union[None, float], optional) – The halfmax value to match (if wanting the same HM between curves), by default None.
- Returns:
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].
- Return type:
tuple[float, list, list]
- static lin_interp(point_1: list, point_2: list, xvalue: float | None = None, yvalue: float | None = None) float [source]#
Linear interp 2 points by finding line equation and subbing.
- Parameters:
point_1 (list) – List of an x and y coordinate.
point_2 (list) – List of an x and y coordinate.
xvalue (Union[float, None], optional) – Value at which to interpolate to get a y coordinate, by default None.
yvalue (Union[float, None], optional) – Value at which to interpolate to get an x coordinate, by default None.
- Returns:
Value of x or y linear interpolation.
- Return type:
float
- static order_branches(branch1: numpy.typing.NDArray, branch2: numpy.typing.NDArray) tuple [source]#
Order the two ordered arrays based on the closest endpoint coordinates.
- Parameters:
branch1 (npt.NDArray) – An Nx2 array describing coordinates.
branch2 (npt.NDArray) – An Nx2 array describing coordinates.
- Returns:
An tuple with the each coordinate array ordered to follow on from one-another.
- Return type:
tuple
- static binary_line(start: numpy.typing.NDArray, end: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Create a binary path following the straight line between 2 points.
- Parameters:
start (npt.NDArray) – A coordinate.
end (npt.NDArray) – Another coordinate.
- Returns:
An Nx2 coordinate array that the line passes through.
- Return type:
npt.NDArray
- static coord_dist_rad(coords: numpy.typing.NDArray, centre: numpy.typing.NDArray, pixel_to_nm_scaling: float = 1) numpy.typing.NDArray [source]#
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:
coords (npt.NDArray) – Nx2 array of branch coordinates.
centre (npt.NDArray) – A 1x2 array of the centre coordinates to identify a 0 point for the node.
pixel_to_nm_scaling (float, optional) – The pixel to nanometer scaling factor to provide real units, by default 1.
- Returns:
A Nx1 array of the distance from the node centre.
- Return type:
npt.NDArray
- static above_below_value_idx(array: numpy.typing.NDArray, value: float) list [source]#
Identify indices of the array neighbouring the specified value.
- Parameters:
array (npt.NDArray) – Array of values.
value (float) – Value to identify indices between.
- Returns:
List of the lower index and higher index around the value.
- Return type:
list
- Raises:
IndexError – When the value is in the array.
- static average_height_trace(img: numpy.typing.NDArray, branch_mask: numpy.typing.NDArray, branch_coords: numpy.typing.NDArray, centre=(0, 0)) tuple [source]#
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:
img (npt.NDArray) – An array of numbers pertaining to an image.
branch_mask (npt.NDArray) – A binary array of the branch, must share the same dimensions as the image.
branch_coords (npt.NDArray) – Ordered coordinates of the branch mask.
centre (Union[float, None]) – The coordinates to centre the branch around.
- Returns:
A tuple of the averaged heights from the linetrace and their corresponding distances from the crossing.
- Return type:
tuple
- static fill_holes(mask: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Fill all holes within a binary mask.
- Parameters:
mask (npt.NDArray) – Binary array of object.
- Returns:
Binary array of object with any interior holes filled in.
- Return type:
npt.NDArray
- static _remove_re_entering_branches(mask: numpy.typing.NDArray, remaining_branches: int = 1) numpy.typing.NDArray [source]#
Remove smallest branches which branches exit and re-enter the viewing area.
Contninues until only <remaining_branches> remain.
- Parameters:
mask (npt.NDArray) – Skeletonised binary mask of an object.
remaining_branches (int, optional) – Number of objects (branches) to keep, by default 1.
- Returns:
Mask with only a single skeletonised branch.
- Return type:
npt.NDArray
- static only_centre_branches(node_image: numpy.typing.NDArray, node_coordinate: numpy.typing.NDArray) numpy.typing.NDArray[numpy.int32] [source]#
Remove all branches not connected to the current node.
- Parameters:
node_image (npt.NDArray) – An image of the skeletonised area surrounding the node where the background = 0, skeleton = 1, termini = 2, nodes = 3.
node_coordinate (npt.NDArray) – 2x1 coordinate describing the position of a node.
- Returns:
The initial node image but only with skeletal branches connected to the middle node.
- Return type:
npt.NDArray[np.int32]
- static average_uniques(arr1: numpy.typing.NDArray, arr2: numpy.typing.NDArray) tuple [source]#
Obtain the unique values of both arrays, and the average of common values.
- Parameters:
arr1 (npt.NDArray) – An array.
arr2 (npt.NDArray) – An array.
- Returns:
The unique values of both arrays, and the averaged common values.
- Return type:
tuple
- static average_crossing_confs(node_dict) None | float [source]#
Return the average crossing confidence of all crossings in the molecule.
- Parameters:
node_dict (dict) – A dictionary containing node statistics and information.
- Returns:
The value of minimum confidence or none if not possible.
- Return type:
Union[None, float]
- static minimum_crossing_confs(node_dict: dict) None | float [source]#
Return the minimum crossing confidence of all crossings in the molecule.
- Parameters:
node_dict (dict) – A dictionary containing node statistics and information.
- Returns:
The value of minimum confidence or none if not possible.
- Return type:
Union[None, float]
- topostats.tracing.nodestats.nodestats_image(image: numpy.typing.NDArray, disordered_tracing_direction_data: dict, filename: str, pixel_to_nm_scaling: float, node_joining_length: float, node_extend_dist: float, branch_pairing_length: float, pair_odd_branches: float, pad_width: int) tuple [source]#
Initialise the nodeStats class.
- Parameters:
image (npt.NDArray) – The array of pixels.
disordered_tracing_direction_data (dict) – The images and bbox coordinates of the pruned skeletons.
filename (str) – The name of the file being processed. For logging purposes.
pixel_to_nm_scaling (float) – The pixel to nm scaling factor.
node_joining_length (float) – The length over which to join skeletal intersections to be counted as one crossing.
node_joining_length – The distance over which to join nearby odd-branched nodes.
node_extend_dist (float) – The distance under which to join odd-branched node regions.
branch_pairing_length (float) – The length from the crossing point to pair and trace, obtaining FWHM’s.
pair_odd_branches (bool) – Whether to try and pair odd-branched nodes.
pad_width (int) – The number of edge pixels to pad the image by.
- Returns:
The nodestats statistics for each crossing, crossing statistics to be added to the grain statistics, an image dictionary of nodestats steps for the entire image, and single grain images.
- Return type:
tuple[dict, pd.DataFrame, dict, dict]