Skip to content

Commit

Permalink
add minimal test for tree_widget_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
AnniekStok committed Sep 16, 2024
1 parent 6add5af commit 26659d9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def graph_2d():
NodeAttr.POS.value: [50, 50],
NodeAttr.TIME.value: 0,
NodeAttr.SEG_ID.value: 1,
NodeAttr.AREA.value: 1245,
},
),
(
Expand All @@ -90,6 +91,7 @@ def graph_2d():
NodeAttr.POS.value: [60, 45],
NodeAttr.TIME.value: 1,
NodeAttr.SEG_ID.value: 2,
NodeAttr.AREA.value: 697,
},
),
]
Expand Down Expand Up @@ -121,6 +123,7 @@ def multi_hypothesis_graph_2d():
NodeAttr.TIME.value: 0,
NodeAttr.SEG_HYPO.value: 0,
NodeAttr.SEG_ID.value: 1,
NodeAttr.AREA.value: 1245,
},
),
(
Expand All @@ -130,6 +133,7 @@ def multi_hypothesis_graph_2d():
NodeAttr.TIME.value: 0,
NodeAttr.SEG_HYPO.value: 1,
NodeAttr.SEG_ID.value: 1,
NodeAttr.AREA.value: 697,
},
),
(
Expand All @@ -139,6 +143,7 @@ def multi_hypothesis_graph_2d():
NodeAttr.TIME.value: 1,
NodeAttr.SEG_HYPO.value: 0,
NodeAttr.SEG_ID.value: 1,
NodeAttr.AREA.value: 305,
},
),
(
Expand All @@ -148,6 +153,7 @@ def multi_hypothesis_graph_2d():
NodeAttr.TIME.value: 1,
NodeAttr.SEG_HYPO.value: 1,
NodeAttr.SEG_ID.value: 1,
NodeAttr.AREA.value: 697,
},
),
(
Expand All @@ -157,6 +163,8 @@ def multi_hypothesis_graph_2d():
NodeAttr.TIME.value: 1,
NodeAttr.SEG_HYPO.value: 0,
NodeAttr.SEG_ID.value: 2,
NodeAttr.AREA.value: 697,
NodeAttr.AREA.value: 1245,
},
),
(
Expand Down
31 changes: 31 additions & 0 deletions tests/motile_plugin/utils/test_tree_widget_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import napari
import pandas as pd
from motile_plugin.core import Tracks
from motile_plugin.utils.tree_widget_utils import extract_sorted_tracks
from motile_toolbox.visualization.napari_utils import assign_tracklet_ids
import networkx as nx
import numpy as np

Tracks.model_rebuild()


def test_track_df(graph_2d):

tracks = Tracks(graph=graph_2d)

assert tracks.get_area("0_1") == 1245
assert tracks.get_area("1_1") is None

tracks.graph, _ = assign_tracklet_ids(tracks.graph)

colormap = napari.utils.colormaps.label_colormap(
49,
seed=0.5,
background_value=0,
)

track_df = extract_sorted_tracks(tracks, colormap)
assert isinstance(track_df, pd.DataFrame)
assert track_df.loc[track_df["node_id"] == "0_1", "area"].values[0] == 1245
assert track_df.loc[track_df["node_id"] == "1_1", "area"].values[0] == 0
assert track_df["area"].notna().all()

0 comments on commit 26659d9

Please sign in to comment.