Skip to content

Commit

Permalink
add a warning if the segmentation pixel value for the first node coor…
Browse files Browse the repository at this point in the history
…dinates does not match with the provided seg_id from the csv file, as this likely indicates that the wrong pair of files has been selected. Remove the warning about viewing tracks that are not a motile run
  • Loading branch information
AnniekStok committed Nov 29, 2024
1 parent 93bf21b commit e2a6f62
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/motile_plugin/import_export/import_external_tracks_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,39 @@ def _browse_image(self):
if image_file:
self.image_path_line.setText(image_file)

def tracks_valid(self, scale: list[float]) -> bool:
"""Test if the segmentation pixel value for the coordinates of first node corresponds with the provided seg_id as a basic sanity check that the csv file matches with the segmentation file"""

node = list(self.tracks.graph.nodes)[0]
coordinates = self.tracks.get_position(node, incl_time=True)
seg_id = self.tracks.get_seg_id(node)
coordinates = [
int(coord / scale_value)
for coord, scale_value in zip(coordinates, scale, strict=False)
]
value = self.tracks.segmentation[(coordinates[0], 0, *coordinates[1:])]
if value != seg_id:
msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Warning)
msg_box.setWindowTitle("Warning")
msg_box.setText(
f"Pixel value at coordinates {coordinates} ({value}) does NOT match with the seg_id "
f"from the csv file ({seg_id}). Is it possible that you selected the wrong combination "
"of segmentation and csv file? The displayed result may not be correct."
)

# Add custom buttons
go_back_button = msg_box.addButton("Go back", QMessageBox.ActionRole)
msg_box.addButton("Continue anyway", QMessageBox.AcceptRole)

# Display the message box and wait for user response
msg_box.exec_()

# Handle responses
return msg_box.clickedButton() != go_back_button
else:
return True

def _ok_clicked(self):
"""Tries to read the CSV file and optional segmentation image, and apply the attribute to column mapping to construct a Tracks object"""

Expand Down Expand Up @@ -367,6 +400,9 @@ def _ok_clicked(self):
self.tracks = tracks_from_csv(
csv_file, selected_columns, extra_columns, segmentation, scale
)
if self.tracks.segmentation is not None and not self.tracks_valid(scale):
return

except ValueError as e:
QMessageBox.critical(self, "Error", f"Failed to load tracks: {e}")
return
Expand Down
1 change: 0 additions & 1 deletion src/motile_plugin/motile/menus/motile_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def view_run(self, tracks: SolutionTracks) -> None:
self.edit_run_widget.hide()
self.view_run_widget.show()
else:
show_warning("Tried to view a Tracks that is not a MotileRun")
self.view_run_widget.hide()

def edit_run(self, run: MotileRun | None):
Expand Down

0 comments on commit e2a6f62

Please sign in to comment.