tumourkit.postprocessing.join_graph_gt.merge_labels
- tumourkit.postprocessing.join_graph_gt.merge_labels(graph: DataFrame, centroids: ndarray) DataFrame
Matches nodes in the graph to centroids and updates their labels.
Given a graph DataFrame and a centroids array, this function finds 1-1 matchings between nodes in the graph and centroids based on their coordinates. It substitutes the labels of the graph nodes with the labels from the centroids. The matching is performed using KD-trees for efficient nearest neighbor search.
- Parameters:
graph (pd.DataFrame) – The graph DataFrame containing nodes with labels.
centroids (np.ndarray) – The centroids array containing coordinates and labels.
- Returns:
The updated graph DataFrame with matched labels.
- Return type:
pd.DataFrame