Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/funtracks/candidate_graph/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def nodes_from_segmentation(
attrs[NodeAttr.SEG_ID.value] = regionprop.label
centroid = regionprop.centroid # [z,] y, x
attrs[NodeAttr.POS.value] = centroid
if node_id in cand_graph.nodes:
raise ValueError("Duplicate values found among nodes")
cand_graph.add_node(node_id, **attrs)
nodes_in_frame.append(node_id)
if nodes_in_frame:
Expand Down
9 changes: 9 additions & 0 deletions tests/candidate_graph/test_compute_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def test_graph_from_segmentation_3d(segmentation_3d, graph_3d):
assert pytest.approx(cand_graph.edges[edge], abs=0.01) == graph_3d.edges[edge]


def test_graph_from_segmentation_with_duplicate_nodes(segmentation_2d):
segmentation_2d[1][20:25, 20:25] = 1 # add a duplicate label to another time point
with pytest.raises(ValueError, match="Duplicate values found among nodes"):
compute_graph_from_seg(
segmentation=segmentation_2d,
max_edge_distance=100,
)


def test_graph_from_points_list():
points_list = np.array(
[
Expand Down