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

(0) Add camera group data structures #1258

Draft
wants to merge 43 commits into
base: develop
Choose a base branch
from
Draft

Conversation

roomrys
Copy link
Collaborator

@roomrys roomrys commented Apr 4, 2023

Description

  • add sleap-anipose to deps
  • add camera group data structure -- basically pulls in the camera calibration toml file which is generated by sleap-anipose

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

Summary by CodeRabbit

New Features:

  • Added Camcorder and CameraCluster classes to the sleap.io.cameras module for improved camera handling.
  • Introduced a new dependency "sleap-anipose" in requirements.txt.

Improvements:

  • Updated build scripts to handle OpenCV packages more effectively.
  • Enhanced testing environment setup with specific OpenCV version and pytest-xvfb.

Documentation:

  • Updated docs/installation.md with instructions for setting up the development environment using mamba and environment_mac.yml.

Tests:

  • Added tests for the new Camcorder and CameraCluster classes in tests/io/test_cameras.py.
  • Improved GUI testing setup in tests/gui/test_app.py by setting the QT_QPA_PLATFORM_PLUGIN_PATH environment variable.

Copy link
Collaborator Author

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

Self-review no. 1

sleap/io/video.py Outdated Show resolved Hide resolved
sleap/io/video.py Outdated Show resolved Hide resolved
tests/fixtures/cameras.py Outdated Show resolved Hide resolved
tests/io/test_cameras.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #1258 (0230a97) into develop (5c3441c) will increase coverage by 0.03%.
The diff coverage is 91.22%.

@@             Coverage Diff             @@
##           develop    #1258      +/-   ##
===========================================
+ Coverage    73.37%   73.41%   +0.03%     
===========================================
  Files          134      135       +1     
  Lines        23992    24048      +56     
===========================================
+ Hits         17605    17655      +50     
- Misses        6387     6393       +6     
Files Coverage Δ
sleap/io/video.py 92.04% <100.00%> (ø)
sleap/io/cameras.py 91.07% <91.07%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@roomrys roomrys marked this pull request as ready for review April 4, 2023 17:40
@roomrys roomrys requested a review from talmo April 4, 2023 17:40
@roomrys roomrys added the MultiView Stack This PR is part of the MultView stacked PRs. label Apr 20, 2023
@roomrys roomrys changed the title Add camera group data structures (0) Add camera group data structures Jul 6, 2023
from qtpy.QtWidgets import QApplication

from sleap.gui.app import MainWindow
from sleap.gui.commands import *


os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = QLibraryInfo.location(
QLibraryInfo.PluginsPath
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice find!

@roomrys roomrys mentioned this pull request Aug 16, 2023
11 tasks
@roomrys roomrys marked this pull request as draft August 24, 2023 19:43
@roomrys
Copy link
Collaborator Author

roomrys commented Aug 24, 2023

Converted back to draft due to hacky workaround for version of opencv. Final PR should resolve this version conflict.

@roomrys roomrys marked this pull request as ready for review September 26, 2023 14:40
@coderabbitai
Copy link

coderabbitai bot commented Sep 26, 2023

Walkthrough

This pull request introduces changes to the build scripts, dependencies, and testing environment. It also adds new classes for camera handling in the sleap.io.cameras module and updates the corresponding tests. The changes include a workaround for managing OpenCV versions across different platforms.

Changes

File(s) Summary
.conda/bld.bat, .conda/build.sh, .conda_mac/build.sh Added a hack to uninstall all opencv packages and install opencv-contrib-python. This change is untested.
.github/workflows/ci.yml Added a step to reinstall the correct version of OpenCV and modified the test step description.
dev_requirements.txt, requirements.txt Updated dependencies including a specific version constraint for OpenCV and TensorFlow on macOS.
docs/installation.md Added instructions for setting up the development environment with a specific OpenCV version.
sleap/io/cameras.py Introduced two new classes: Camcorder and CameraCluster for improved camera handling.
tests/conftest.py, tests/fixtures/cameras.py, tests/io/test_cameras.py Updated tests to accommodate the new Camcorder and CameraCluster classes.
tests/gui/test_app.py Set the QT_QPA_PLATFORM_PLUGIN_PATH environment variable to the location of the Qt plugins path.

🐇 "In the land of code, where logic intertwines,
A rabbit hops along the lines.
With each leap, a bug takes flight,
Under the moon's soft, silvery light.
In the dance of keys, a tale we weave,
Of cameras, clusters, what we perceive.
Through tests and trials, we find our way,
Celebrating changes, we end the day." 🌙


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

@roomrys
Copy link
Collaborator Author

roomrys commented Sep 26, 2023

Converting this back to a "Ready for Review" PR to get the coderabbitai feedback. It is definitely not ready to be merged due to the opencv hack described above.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 7

Commits Files that changed from the base of the PR and between 4100153 and 587331f.
Files ignored due to filter (3)
  • environment.yml
  • environment_no_cuda.yml
  • tests/data/cameras/minimal_session/calibration.toml
Files selected for processing (13)
  • .conda/bld.bat (1 hunks)
  • .conda/build.sh (1 hunks)
  • .conda_mac/build.sh (1 hunks)
  • .github/workflows/ci.yml (2 hunks)
  • dev_requirements.txt (1 hunks)
  • docs/installation.md (1 hunks)
  • requirements.txt (1 hunks)
  • sleap/io/cameras.py (1 hunks)
  • sleap/io/video.py (2 hunks)
  • tests/conftest.py (1 hunks)
  • tests/fixtures/cameras.py (1 hunks)
  • tests/gui/test_app.py (1 hunks)
  • tests/io/test_cameras.py (1 hunks)
Files skipped from review due to trivial changes (6)
  • dev_requirements.txt
  • docs/installation.md
  • requirements.txt
  • sleap/io/video.py
  • tests/conftest.py
  • tests/io/test_cameras.py
Additional comments (Suppressed): 8
tests/fixtures/cameras.py (1)
  • 1-8: The new hunk introduces a pytest fixture min_session_calibration_toml_path which returns the path to a calibration file. This fixture can be used in tests that require this specific calibration file. The code looks good and follows best practices for creating pytest fixtures.
.conda/build.sh (1)
  • 12-14: The addition of the OpenCV uninstallation and specific version installation is marked as a hack and untested. This could potentially cause issues if other parts of the code rely on features from newer versions of OpenCV or if the specific version has compatibility issues with other dependencies. Please verify that this change does not break any existing functionality.
.conda/bld.bat (1)
  • 12-14: The new code introduces a hack to uninstall all opencv packages and install a specific version of opencv-contrib-python. This is marked as untested. It's crucial to test this change thoroughly, especially in different environments, to ensure it doesn't introduce unexpected behavior or compatibility issues. Also, consider adding a comment explaining why this hack is necessary.
+ @REM HACK(LM): (untested) Uninstall all opencv packages and install opencv-contrib-python
+ for /f "tokens=1" %%a in ('conda list ^| findstr opencv') do pip uninstall %%a -y
+ pip install "opencv-contrib-python<4.7.0"
.conda_mac/build.sh (1)
  • 12-14: The comment indicates that this change is untested. It's important to test such changes before merging them into the main branch, as they could potentially break the build process. Please verify if these changes have been tested and work as expected.
.github/workflows/ci.yml (2)
  • 96-100: The OpenCV reinstallation step is marked as a hack. This could potentially lead to issues if the specific version of opencv-contrib-python being installed is not compatible with other dependencies or parts of the codebase. It's recommended to verify this change and its implications on the overall system.

  • 109-115: The description for the test step has been updated from "Test environment" to "Test the code and the environment". Ensure that this change accurately reflects what the test step is doing. If the tests are now also testing the code, make sure that all necessary test cases have been added and are being executed in this step.

tests/gui/test_app.py (1)
  • 1-14: The new hunk introduces a workaround to ensure that the libraries sleap-anipose, aniposelib, and imgaug use headless OpenCV. This is done by setting the QT_QPA_PLATFORM_PLUGIN_PATH environment variable to the location of the Qt plugins path. While this is a valid solution, it's important to note that this might have implications on other parts of the codebase that rely on these libraries or the QT_QPA_PLATFORM_PLUGIN_PATH environment variable. Please verify that this change doesn't introduce any unexpected behavior elsewhere in the application.
sleap/io/cameras.py (1)
  • 24-30: The equality check for Camcorder objects only checks the attributes of the Camcorder class itself and does not take into account the attributes of the Camera or FisheyeCamera objects stored in the camera attribute. If the camera attribute's properties should be considered in the equality check, you may need to revise this method.

@@ -9,6 +9,9 @@ export PIP_IGNORE_INSTALLED=False
# https://docs.conda.io/projects/conda-build/en/stable/user-guide/wheel-files.html)
pip install --no-cache-dir -r ./requirements.txt

# HACK(LM): (untested) Uninstall all opencv packages and install opencv-contrib-python
conda list | grep opencv | awk '{system("pip uninstall " $1 " -y")}'
Copy link

Choose a reason for hiding this comment

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

Using system() to execute shell commands can be risky due to potential command injection vulnerabilities. Although in this case, the risk is low because the input to system() is not user-controlled, it's still a good practice to avoid using system() when possible. Consider using a safer alternative for executing shell commands.

Comment on lines +13 to +14
conda list | grep opencv | awk '{system("pip uninstall " $1 " -y")}'
pip install "opencv-contrib-python<4.7.0"
Copy link

Choose a reason for hiding this comment

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

The use of conda list | grep opencv | awk '{system("pip uninstall " $1 " -y")}' to uninstall all OpenCV packages is a bit risky. It assumes that all packages with 'opencv' in their name are related to OpenCV and should be uninstalled, which might not always be the case. Also, it's using pip to uninstall packages installed by conda, which could lead to inconsistencies in the environment. Consider using conda uninstall --force opencv instead to ensure only the opencv package is removed and there are no conflicts between conda and pip.

- conda list | grep opencv | awk '{system("pip uninstall " $1 " -y")}'
+ conda uninstall --force opencv

tests/gui/test_app.py Outdated Show resolved Hide resolved
sleap/io/cameras.py Outdated Show resolved Hide resolved
sleap/io/cameras.py Outdated Show resolved Hide resolved
sleap/io/cameras.py Show resolved Hide resolved
sleap/io/cameras.py Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Commits Files that changed from the base of the PR and between 587331f and d16516c.
Files selected for processing (2)
  • sleap/io/cameras.py (1 hunks)
  • tests/gui/test_app.py (1 hunks)
Additional comments (Suppressed): 1
tests/gui/test_app.py (1)
  • 1-14: The environment variable QT_QPA_PLATFORM_PLUGIN_PATH is being set to the location of the Qt plugins path. This is a workaround for an issue with headless OpenCV, as mentioned in the comment. Ensure that this does not interfere with other parts of the application that might be using Qt or OpenCV. Also, consider moving this setup code to a separate function or module to improve modularity and maintainability.

sleap/io/cameras.py Show resolved Hide resolved
sleap/io/cameras.py Show resolved Hide resolved
sleap/io/cameras.py Show resolved Hide resolved
sleap/io/cameras.py Show resolved Hide resolved
@roomrys roomrys marked this pull request as draft September 29, 2023 18:16
@roomrys roomrys self-assigned this Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MultiView Stack This PR is part of the MultView stacked PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants