X Tutup
Skip to content

Refactor/predict multianimal#3220

Open
juan-cobos wants to merge 6 commits intoDeepLabCut:mainfrom
juan-cobos:refactor/predict-multianimal
Open

Refactor/predict multianimal#3220
juan-cobos wants to merge 6 commits intoDeepLabCut:mainfrom
juan-cobos:refactor/predict-multianimal

Conversation

@juan-cobos
Copy link
Contributor

refactor: modernize path handling in predict_multianimal.py

  • 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

juan-cobos and others added 3 commits February 25, 2026 13:32
- 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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.path operations with pathlib.Path throughout both functions
  • Removed duplicate pickle import and unused os import
  • Refactored AnalyzeMultiAnimalVideo to use early return pattern instead of deep nesting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…aths as destfolder with basename instead of splitting based on extension, fix str path compatibility with shelve
Copy link
Collaborator

@deruyter92 deruyter92 left a comment

Choose a reason for hiding this comment

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

@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",
}

@deruyter92 deruyter92 added the enhancement New feature or request label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup