Skip to content

Commit

Permalink
style(pre-commit.ci): auto fixes [...]
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 4, 2023
1 parent fd32f2a commit 4d0b5b3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
2 changes: 2 additions & 0 deletions tests/loaders/test_ctc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_ctc_single_nodes():
# This should raise an error if there are no times for single nodes
TrackingGraph(G)


def test_ctc_with_gap_closing():
data = [
{"Cell_ID": 1, "Start": 0, "End": 1, "Parent_ID": 0},
Expand All @@ -81,6 +82,7 @@ def test_ctc_with_gap_closing():
assert G.has_edge("1_1", "3_3")
assert G.has_edge("2_1", "4_6")


def test_load_data():
test_dir = os.path.abspath(__file__)
data_dir = os.path.abspath(
Expand Down
10 changes: 7 additions & 3 deletions tests/metrics/test_ctc_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from traccuracy.matchers._base import Matched
from traccuracy.matchers._ctc import CTCMatcher
from traccuracy.metrics._ctc import CTCMetrics
from tests.test_utils import get_movie_with_graph, get_gap_close_graphs

from tests.test_utils import get_gap_close_graphs, get_movie_with_graph


def test_compute_mapping():
Expand All @@ -19,9 +20,12 @@ def test_compute_mapping():
assert results["TRA"] == 1
assert results["DET"] == 1


def test_compute_metrics_gap_close():
g_gt, g_pred, mapper = get_gap_close_graphs()
matched = Matched(gt_graph=TrackingGraph(g_gt), pred_graph=TrackingGraph(g_pred), mapping=mapper)
matched = Matched(
gt_graph=TrackingGraph(g_gt), pred_graph=TrackingGraph(g_pred), mapping=mapper
)
results = CTCMetrics().compute(matched)

# check that missing gap closing edge is false negative
Expand All @@ -30,4 +34,4 @@ def test_compute_metrics_gap_close():
assert g_pred.nodes["1_2"][NodeAttr.FALSE_POS]
# check that correct edge is not annotated with errors
for error_attr in [EdgeAttr.FALSE_POS, EdgeAttr.WRONG_SEMANTIC]:
assert not g_pred.edges[("2_6", "4_10")][error_attr]
assert not g_pred.edges[("2_6", "4_10")][error_attr]
28 changes: 23 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ def get_division_graphs():
def get_gap_close_graphs():
"""
G1
3_5 -- 3_6 -- -- -- 5_10
3_5 -- 3_6 -- -- -- 5_10
1_0 -- 1_1 -- -- -- 2_3 -- 2_4 -<
4_5 -- 4_6
G2
2_5 -- 2_6 -- -- -- 4_10
2_5 -- 2_6 -- -- -- 4_10
1_0 -- 1_1 -- 1_2 -- 1_3 -- 1_4 -<
3_5 -- 3_6
"""
Expand Down Expand Up @@ -201,10 +201,21 @@ def get_gap_close_graphs():
nx.set_node_attributes(G2, attrs)

# G1, G2 mapper
mapper = [("1_0", "1_0"), ("1_1", "1_1"), ("2_3", "1_3"), ("2_4", "1_4"), ("3_5", "2_5"), ("3_6", "2_6"), ("5_10", "4_10"), ("4_5", "3_5"), ("4_6", "3_6")]
mapper = [
("1_0", "1_0"),
("1_1", "1_1"),
("2_3", "1_3"),
("2_4", "1_4"),
("3_5", "2_5"),
("3_6", "2_6"),
("5_10", "4_10"),
("4_5", "3_5"),
("4_6", "3_6"),
]

return G1, G2, mapper


def get_division_gap_close_graphs():
"""
G1
Expand Down Expand Up @@ -248,6 +259,13 @@ def get_division_gap_close_graphs():
attrs[node] = {"t": int(node[-1:]), "x": 0, "y": 0}
nx.set_node_attributes(G2, attrs)

mapper = [("1_0", "1_0"), ("1_1", "1_1"), ("2_3", "2_3"), ("2_4", "2_4"), ("3_2", "3_2"), ("3_4", "4_4")]
mapper = [
("1_0", "1_0"),
("1_1", "1_1"),
("2_3", "2_3"),
("2_4", "2_4"),
("3_2", "3_2"),
("3_4", "4_4"),
]

return G1, G2, mapper
return G1, G2, mapper
21 changes: 11 additions & 10 deletions tests/track_errors/test_divisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_get_succ_by_t,
)

from tests.test_utils import get_division_graphs, get_division_gap_close_graphs
from tests.test_utils import get_division_gap_close_graphs, get_division_graphs


@pytest.fixture
Expand Down Expand Up @@ -221,28 +221,29 @@ def test_evaluate_division_events():

assert np.all([isinstance(k, int) for k in results.keys()])


def test_gap_close_divisions():
g_gt, g_pred, mapper = get_division_gap_close_graphs()
matched_data = Matched(TrackingGraph(g_gt), TrackingGraph(g_pred), mapper)
_classify_divisions(matched_data)

# missing gap close div edge so FN DIV
assert g_gt.nodes['1_1'][NodeAttr.FN_DIV]
assert g_gt.nodes["1_1"][NodeAttr.FN_DIV]

# fix division, assert it's identified correctly
g_pred.remove_node('2_2')
g_pred.add_edge('1_1', '2_3')
g_pred.remove_node("2_2")
g_pred.add_edge("1_1", "2_3")
# mapper doesn't need to change as removed node was always missing
matched_data = Matched(TrackingGraph(g_gt), TrackingGraph(g_pred), mapper)
_classify_divisions(matched_data)
assert g_gt.nodes['1_1'][NodeAttr.TP_DIV]
assert g_gt.nodes['1_1'][NodeAttr.TP_DIV]
assert g_gt.nodes["1_1"][NodeAttr.TP_DIV]
assert g_gt.nodes["1_1"][NodeAttr.TP_DIV]

g_gt, g_pred, mapper = get_division_gap_close_graphs()
# remove gt division
g_gt.remove_edge('1_1', '2_3')
g_gt.remove_edge('1_1', '3_2')
g_gt.remove_edge("1_1", "2_3")
g_gt.remove_edge("1_1", "3_2")
matched_data = Matched(TrackingGraph(g_gt), TrackingGraph(g_pred), mapper)
_classify_divisions(matched_data)
# assert fp division classified correctly
assert g_pred.nodes['1_1'][NodeAttr.FP_DIV]
assert g_pred.nodes["1_1"][NodeAttr.FP_DIV]

1 comment on commit 4d0b5b3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Mean (s) BASE ef50a44 Mean (s) HEAD 4d0b5b3 Percent Change
test_load_gt_data 1.39667 1.23952 -11.25
test_load_pred_data 1.16082 1.1634 0.22
test_ctc_matched 2.24662 2.24321 -0.15
test_ctc_metrics 0.5703 0.53332 -6.48
test_ctc_div_metrics 0.28662 0.29397 2.56
test_iou_matched 9.56684 9.66289 1
test_iou_div_metrics 0.27151 0.27685 1.97

Please sign in to comment.