Skip to content

Commit

Permalink
Merge pull request #89 from funkelab/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes - scaling centroid, warn if no tracks found
  • Loading branch information
cmalinmayor authored Oct 20, 2024
2 parents 08bbff7 + 16f0dad commit 8a1d1fb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/motile_plugin/application_menus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .main_app import MainApp # noqa
from .editing_menu import EditingMenu # noqa
from .menu_widget import MenuWidget # noqa
11 changes: 6 additions & 5 deletions src/motile_plugin/data_model/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ def _create_seg_time_to_node(self) -> dict[int, dict[int, Node]]:

for node in self.graph.nodes():
seg_id = self.get_seg_id(node)
if seg_id is None:
time = self.get_time(node)
if seg_id is None or time is None:
continue
if seg_id not in self.seg_time_to_node:
self.seg_time_to_node[seg_id] = {}
time = self.get_time(node)
self.seg_time_to_node[seg_id][time] = node

def _set_node_attr(self, node: Node, attr: NodeAttr, value: Any):
Expand Down Expand Up @@ -733,12 +733,13 @@ def _compute_node_attrs(
pos = None
else:
seg = self.segmentation[time][0] == seg_id
pos_scale = self.scale[1:] if self.scale is not None else None
area = np.sum(seg)
if self.scale is not None:
area *= np.prod(self.scale)
if pos_scale is not None:
area *= np.prod(pos_scale)
# only include the position if the segmentation was actually there
pos = (
measure.centroid(seg, spacing=self.scale)
measure.centroid(seg, spacing=pos_scale)
if area > 0
else np.array(
[
Expand Down
4 changes: 0 additions & 4 deletions src/motile_plugin/data_views/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
from .tree_view.tree_widget import TreeWidget # noqa
from .layers.track_graph import TrackGraph # noqa
from .layers.track_labels import TrackLabels # noqa
from .layers.track_points import TrackPoints # noqa
2 changes: 0 additions & 2 deletions src/motile_plugin/data_views/views_coordinator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from .node_selection_list import NodeSelectionList # noqa
from .tracks_viewer import TracksViewer # noqa
4 changes: 2 additions & 2 deletions src/motile_plugin/motile/backend/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
get_candidate_graph_from_points_list,
graph_to_nx,
)
from motile_toolbox.visualization.napari_utils import assign_tracklet_ids

from .solver_params import SolverParams

Expand Down Expand Up @@ -71,7 +70,8 @@ def solve(

solution_graph = solver.get_selected_subgraph(solution=solution)
solution_nx_graph = graph_to_nx(solution_graph)
solution_nx_graph, _, _ = assign_tracklet_ids(solution_nx_graph)
logger.debug("Solution graph has %d nodes", solution_nx_graph.number_of_nodes())
# solution_nx_graph, _, _ = assign_tracklet_ids(solution_nx_graph)
return solution_nx_graph


Expand Down
9 changes: 7 additions & 2 deletions src/motile_plugin/motile/menus/motile_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,18 @@ def solve_with_motile(self, run: MotileRun) -> MotileRun:
lambda event_data: self._on_solver_event(run, event_data),
scale=run.scale,
)

run._initialize_track_ids()
if run.input_segmentation is not None:
run.segmentation = self.relabel_segmentation(
run.graph, run.input_segmentation
)

run._create_seg_time_to_node()
run._initialize_track_ids()

if run.graph.number_of_nodes() == 0:
show_warning(
"No tracks found - try making your edge selection value more negative"
)
return run

def _on_solver_event(self, run: MotileRun, event_data: dict) -> None:
Expand Down

0 comments on commit 8a1d1fb

Please sign in to comment.