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
Copy Markdown
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

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
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
@C-Achard C-Achard added the lint required Please run pre-commit hooks to ensure your formatting is up-to-date label Mar 30, 2026
juan-cobos and others added 6 commits March 30, 2026 13:41
- 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
@C-Achard C-Achard force-pushed the refactor/predict-multianimal branch from 8d9c33b to ad474c3 Compare March 30, 2026 18:44
@C-Achard
Copy link
Copy Markdown
Collaborator

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.

@C-Achard C-Achard removed the lint required Please run pre-commit hooks to ensure your formatting is up-to-date label Mar 30, 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