Skip to content

Commit

Permalink
Remove DISTANCE enum from edges
Browse files Browse the repository at this point in the history
Distances are implied by the incident node positions.
  • Loading branch information
funkey committed Apr 25, 2024
1 parent 84bdca2 commit ee26170
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/motile_toolbox/candidate_graph/graph_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ class EdgeAttr(Enum):
implementations of commonly used ones, listed here.
"""

DISTANCE = "distance"
IOU = "iou"
36 changes: 18 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def graph_2d():
),
]
edges = [
("0_1", "1_1", {EdgeAttr.DISTANCE.value: 42.43, EdgeAttr.IOU.value: 0.0}),
("0_1", "1_2", {EdgeAttr.DISTANCE.value: 11.18, EdgeAttr.IOU.value: 0.395}),
("0_1", "1_1", {EdgeAttr.IOU.value: 0.0}),
("0_1", "1_2", {EdgeAttr.IOU.value: 0.395}),
]
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
Expand Down Expand Up @@ -159,25 +159,25 @@ def multi_hypothesis_graph_2d():
]

edges = [
("0_0_1", "1_0_1", {EdgeAttr.DISTANCE.value: 42.426, EdgeAttr.IOU.value: 0.0}),
("0_0_1", "1_1_1", {EdgeAttr.DISTANCE.value: 43.011, EdgeAttr.IOU.value: 0.0}),
("0_0_1", "1_0_1", {EdgeAttr.IOU.value: 0.0}),
("0_0_1", "1_1_1", {EdgeAttr.IOU.value: 0.0}),
(
"0_0_1",
"1_0_2",
{EdgeAttr.DISTANCE.value: 11.180, EdgeAttr.IOU.value: 0.3931},
{EdgeAttr.IOU.value: 0.3931},
),
(
"0_0_1",
"1_1_2",
{EdgeAttr.DISTANCE.value: 11.180, EdgeAttr.IOU.value: 0.4768},
{EdgeAttr.IOU.value: 0.4768},
),
("0_1_1", "1_0_1", {EdgeAttr.DISTANCE.value: 43.011, EdgeAttr.IOU.value: 0.0}),
("0_1_1", "1_1_1", {EdgeAttr.DISTANCE.value: 42.426, EdgeAttr.IOU.value: 0.0}),
("0_1_1", "1_0_2", {EdgeAttr.DISTANCE.value: 15.0, EdgeAttr.IOU.value: 0.2402}),
("0_1_1", "1_0_1", {EdgeAttr.IOU.value: 0.0}),
("0_1_1", "1_1_1", {EdgeAttr.IOU.value: 0.0}),
("0_1_1", "1_0_2", {EdgeAttr.IOU.value: 0.2402}),
(
"0_1_1",
"1_1_2",
{EdgeAttr.DISTANCE.value: 11.180, EdgeAttr.IOU.value: 0.3931},
{EdgeAttr.IOU.value: 0.3931},
),
]
graph.add_nodes_from(nodes)
Expand Down Expand Up @@ -276,9 +276,9 @@ def graph_3d():
]
edges = [
# math.dist([50, 50], [20, 80])
("0_1", "1_1", {EdgeAttr.DISTANCE.value: 42.43}),
("0_1", "1_1"),
# math.dist([50, 50], [60, 45])
("0_1", "1_2", {EdgeAttr.DISTANCE.value: 11.18}),
("0_1", "1_2"),
]
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
Expand Down Expand Up @@ -336,12 +336,12 @@ def multi_hypothesis_graph_3d():
),
]
edges = [
("0_0_1", "1_0_1", {EdgeAttr.DISTANCE.value: 42.4264}),
("0_0_1", "1_0_2", {EdgeAttr.DISTANCE.value: 11.1803}),
("0_1_1", "1_0_1", {EdgeAttr.DISTANCE.value: 35.3553}),
("0_1_1", "1_0_2", {EdgeAttr.DISTANCE.value: 18.0277}),
("0_0_1", "1_1_1", {EdgeAttr.DISTANCE.value: 40.3112}),
("0_1_1", "1_1_1", {EdgeAttr.DISTANCE.value: 33.5410}),
("0_0_1", "1_0_1"),
("0_0_1", "1_0_2"),
("0_1_1", "1_0_1"),
("0_1_1", "1_0_2"),
("0_0_1", "1_1_1"),
("0_1_1", "1_1_1"),
]
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
Expand Down
11 changes: 0 additions & 11 deletions tests/test_candidate_graph/test_compute_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def test_graph_from_segmentation_2d(segmentation_2d, graph_2d):
assert Counter(cand_graph.nodes[node]) == Counter(graph_2d.nodes[node])
for edge in cand_graph.edges:
print(cand_graph.edges[edge])
assert (
pytest.approx(cand_graph.edges[edge][EdgeAttr.DISTANCE.value], abs=0.01)
== graph_2d.edges[edge][EdgeAttr.DISTANCE.value]
)
assert (
pytest.approx(cand_graph.edges[edge][EdgeAttr.IOU.value], abs=0.01)
== graph_2d.edges[edge][EdgeAttr.IOU.value]
Expand All @@ -33,9 +29,6 @@ def test_graph_from_segmentation_2d(segmentation_2d, graph_2d):
)
assert Counter(list(cand_graph.nodes)) == Counter(["0_1", "1_1", "1_2"])
assert Counter(list(cand_graph.edges)) == Counter([("0_1", "1_2")])
assert cand_graph.edges[("0_1", "1_2")][EdgeAttr.DISTANCE.value] == pytest.approx(
11.18, abs=0.01
)


def test_graph_from_segmentation_3d(segmentation_3d, graph_3d):
Expand Down Expand Up @@ -72,10 +65,6 @@ def test_graph_from_multi_segmentation_2d(
multi_hypothesis_graph_2d.nodes[node]
)
for edge in cand_graph.edges:
assert (
pytest.approx(cand_graph.edges[edge][EdgeAttr.DISTANCE.value], abs=0.01)
== multi_hypothesis_graph_2d.edges[edge][EdgeAttr.DISTANCE.value]
)
assert (
pytest.approx(cand_graph.edges[edge][EdgeAttr.IOU.value], abs=0.01)
== multi_hypothesis_graph_2d.edges[edge][EdgeAttr.IOU.value]
Expand Down
7 changes: 0 additions & 7 deletions tests/test_candidate_graph/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,13 @@ def test_add_cand_edges_2d(graph_2d):
cand_graph = nx.create_empty_copy(graph_2d)
add_cand_edges(cand_graph, max_edge_distance=50)
assert Counter(list(cand_graph.edges)) == Counter(list(graph_2d.edges))
for edge in cand_graph.edges:
assert (
pytest.approx(cand_graph.edges[edge][EdgeAttr.DISTANCE.value], abs=0.01)
== graph_2d.edges[edge][EdgeAttr.DISTANCE.value]
)


def test_add_cand_edges_3d(graph_3d):
cand_graph = nx.create_empty_copy(graph_3d)
add_cand_edges(cand_graph, max_edge_distance=15)
graph_3d.remove_edge("0_1", "1_1")
assert Counter(list(cand_graph.edges)) == Counter(list(graph_3d.edges))
for edge in cand_graph.edges:
assert pytest.approx(cand_graph.edges[edge], abs=0.01) == graph_3d.edges[edge]


def test_get_node_id():
Expand Down

0 comments on commit ee26170

Please sign in to comment.