Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes path handling in predict_multianimal.py by migrating from os.path string manipulation to pathlib.Path objects, improving code readability and maintainability.
Changes:
- Replaced
os.pathoperations withpathlib.Paththroughout both functions - Removed duplicate
pickleimport and unusedosimport - Refactored
AnalyzeMultiAnimalVideoto use early return pattern instead of deep nesting
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
deruyter92
left a comment
There was a problem hiding this comment.
@juan-cobos , great well-scoped PR, thanks!
I checked the code and everything is consistent now with the old behavior (except one print statement, which I think you improved).
Please see my comments.
Also, one minor other suggestion:
Since this function writes many different output files with a similar base, it might be helpful to define all output paths at the beginning in one single go. This makes the output contract obvious in one glance (and could avoids filename typos in future refactors):
basename = f"{video.stem}{DLCscorer}"
paths = {
"h5": destfolder / f"{basename}.h5",
"full_pickle": destfolder / f"{basename}_full.pickle",
"meta_pickle": destfolder / f"{basename}_meta.pickle",
"assemblies_pickle": destfolder / f"{basename}_assemblies.pickle",
"bpt_features_pickle": destfolder / f"{basename}_bpt_features.pickle",
}- Replace os.path string manipulation with pathlib throughout - Drop duplicate import pickle and unused import os - Guard destfolder as Path in both functions - Use VideoWriter(str(video)) to avoid cv2.VideoCapture breakage - Extract full_pickle variable to avoid repeating the _full.pickle path - Early return in AnalyzeMultiAnimalVideo instead of deep else nesting - Inline vid.dimensions in prints; keep nx, ny only where needed - shelf_path ternary; f-string print; drop unused _ assignment
…aths as destfolder with basename instead of splitting based on extension, fix str path compatibility with shelve
8d9c33b to
ad474c3
Compare
|
Rebased as per #3263: please make sure to reset your local branch to track the current remote state if needed. A local backup of the pre-rebase branch was made, if you feel there is an issue with the rebased branch please let us know and we will restore it. |
refactor: modernize path handling in predict_multianimal.py