Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes trajectory plot coordinate system issues and improves code maintainability by centralizing layer search logic. The trajectory plot now correctly matches napari's coordinate system (Y-axis orientation and coordinate values), applies theme-based styling consistently, and avoids unnecessary updates when hidden.
Changes:
- Fixed trajectory plot Y-axis to match napari viewer coordinates and orientation
- Centralized layer searching with new utility functions (
find_layer,find_layers,find_layers_of_types) - Improved plot performance by skipping updates when canvas is hidden
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/napari_deeplabcut/misc.py |
Added three utility functions for finding layers by type and optional predicate |
src/napari_deeplabcut/_widgets.py |
Replaced manual layer iteration with utility functions; fixed plot axis orientation and theme styling; added force parameter to plot updates |
src/napari_deeplabcut/_tests/test_widgets.py |
Updated test to verify plot doesn't update when hidden unless forced |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Introduced find_layer, find_layers, and find_layers_of_types utilities in misc.py to simplify and standardize layer selection logic throughout _widgets.py. Replaced multiple for-loops and isinstance checks with these new functions, improving code readability and maintainability.
Added a visibility check to KeypointMatplotlibCanvas.update_plot_range to prevent unnecessary updates when the widget is hidden, unless forced. Ensures plot updates only occur when the canvas is visible or explicitly requested, improving performance.
Improves robustness by handling cases where the points layer or its data attribute may be None or empty. Also corrects logical checks for found neighbors and simplifies color scheme updates.
Replaces np.issubdtype with pandas' is_numeric_dtype to more robustly check if image_paths is numeric in read_hdf. This improves compatibility with different pandas index types.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
23b113c to
708a455
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Enhanced the handling of keypoint trajectory extraction in KeypointMatplotlibCanvas to ensure only 1D trajectories are plotted and to skip empty selections. Updated data presence checks in KeypointControls to use .size for better reliability. Improved dtype handling in read_hdf for image_paths, and made shape_type checks more robust for Shapes layers.
Refactored the trajectory plotting code in KeypointMatplotlibCanvas to remove unnecessary checks and conversions, streamlining the extraction and plotting of keypoint data.
A small update to the trajectory plotting utility, mostly for consistency and performance.
Also updated API for finding layers in code, centralizing and ensuring consistency.
Before: light blue track shown on top instead of bottom (flipped Y), incorrect vline color, and inconsistent axis with viewer coordinates.
After: trajectories match viewer coordinates/orientation, and styling correctly matches the current napari theme
Several plotting and UI behaviors are improved for robustness and better integration with napari's theming.
This pull request also refactors the way layers are found and filtered throughout the
napari_deeplabcutcodebase by introducing new utility functions (find_layer,find_layers, andfind_layers_of_types) inmisc.py. These new functions replace repetitive layer-searching code in_widgets.py, resulting in cleaner, more maintainable, and less error-prone logic.The most important changes are:
Layer Selection Refactor:
find_layer,find_layers, andfind_layers_of_typesutility functions tomisc.pyfor robust and reusable layer searching/filtering by type and predicate._widgets.pywith calls to the new utility functions, simplifying code in methods such as_load_dataframe,_update_slider_max,load_superkeypoints_diagram,_map_keypoints,_extract_single_frame,_store_crop_coordinates, and color mode/colormap updates. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]Plotting and UI Improvements:
update_plot_range) now supports aforceparameter to allow updates even when the widget is hidden, improving reliability when toggling the plot canvas. [1] [2]Maintenance and Readability: