Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menu item for deleting instances beyond frame limit #1797

Merged
merged 13 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sleap/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,12 @@ def new_instance_menu_action():
"Delete Predictions beyond Max Instances...",
self.commands.deleteInstanceLimitPredictions,
)
add_menu_item(
labelMenu,
"delete frame limit predictions new item",
"Delete Predictions beyond Frame Limit new item...",
self.commands.deleteFrameLimitPredictions,
)

### Tracks Menu ###

Expand Down
32 changes: 32 additions & 0 deletions sleap/gui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ def deleteInstanceLimitPredictions(self):
"""Gui for deleting instances beyond some number in each frame."""
self.execute(DeleteInstanceLimitPredictions)

def deleteFrameLimitPredictions(self):
"""Gui for deleting instances beyond some frame number."""
self.execute(DeleteFrameLimitPredictions)

Comment on lines +498 to +501
Copy link

Choose a reason for hiding this comment

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

Add method documentation for deleteFrameLimitPredictions.

Consider adding a detailed docstring for the deleteFrameLimitPredictions method to explain its parameters, return type, and any exceptions it might raise. This will enhance code maintainability and readability.

def completeInstanceNodes(self, instance: Instance):
"""Adds missing nodes to given instance."""
self.execute(AddMissingInstanceNodes, instance=instance)
Expand Down Expand Up @@ -2468,6 +2472,34 @@ def ask(cls, context: CommandContext, params: dict) -> bool:
return super().ask(context, params)


class DeleteFrameLimitPredictions(InstanceDeleteCommand):
@staticmethod
def get_frame_instance_list(context: CommandContext, params: Dict):
shrivaths16 marked this conversation as resolved.
Show resolved Hide resolved
predicted_instances = []
# Select the instances to be deleted
for lf in context.labels.find(context.state["video"]):
if lf.frame_idx >= params["frame_idx_threshold"]:
predicted_instances.extend(
[(lf, inst) for inst in lf.predicted_instances]
)
return predicted_instances

@classmethod
def ask(cls, context: CommandContext, params: Dict) -> bool:
current_video = context.state["video"]
frame_idx_thresh, okay = QtWidgets.QInputDialog.getInt(
context.app,
"Delete Instance beyond Frame Number...",
"Frame number after which instances to be deleted:",
1,
1,
len(current_video),
)
if okay:
params["frame_idx_threshold"] = frame_idx_thresh
return super().ask(context, params)

Copy link

Choose a reason for hiding this comment

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

Ensure proper validation and error handling in DeleteFrameLimitPredictions.

-        if okay:
+        if okay and frame_idx_thresh > 0:

It's crucial to validate the frame_idx_threshold to ensure it's a positive integer. This prevents logical errors where a negative frame index could potentially delete all instances.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
class DeleteFrameLimitPredictions(InstanceDeleteCommand):
@staticmethod
def get_frame_instance_list(context: CommandContext, params: Dict):
predicted_instances = []
# Select the instances to be deleted
for lf in context.labels.find(context.state["video"]):
if lf.frame_idx >= params["frame_idx_threshold"]:
predicted_instances.extend(
[(lf, inst) for inst in lf.predicted_instances]
)
return predicted_instances
@classmethod
def ask(cls, context: CommandContext, params: Dict) -> bool:
current_video = context.state["video"]
frame_idx_thresh, okay = QtWidgets.QInputDialog.getInt(
context.app,
"Delete Instance beyond Frame Number...",
"Frame number after which instances to be deleted:",
1,
1,
len(current_video),
)
if okay:
params["frame_idx_threshold"] = frame_idx_thresh
return super().ask(context, params)
class DeleteFrameLimitPredictions(InstanceDeleteCommand):
@staticmethod
def get_frame_instance_list(context: CommandContext, params: Dict):
predicted_instances = []
# Select the instances to be deleted
for lf in context.labels.find(context.state["video"]):
if lf.frame_idx >= params["frame_idx_threshold"]:
predicted_instances.extend(
[(lf, inst) for inst in lf.predicted_instances]
)
return predicted_instances
@classmethod
def ask(cls, context: CommandContext, params: Dict) -> bool:
current_video = context.state["video"]
frame_idx_thresh, okay = QtWidgets.QInputDialog.getInt(
context.app,
"Delete Instance beyond Frame Number...",
"Frame number after which instances to be deleted:",
1,
1,
len(current_video),
)
if okay and frame_idx_thresh > 0:
params["frame_idx_threshold"] = frame_idx_thresh
return super().ask(context, params)


class TransposeInstances(EditCommand):
topics = [UpdateTopic.project_instances, UpdateTopic.tracks]

Expand Down