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

Added CubicSymmetry #2202

Merged
merged 4 commits into from
Dec 16, 2024
Merged

Added CubicSymmetry #2202

merged 4 commits into from
Dec 16, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Dec 16, 2024

Addresses: #2191

Summary by Sourcery

Add the CubicSymmetry transform to apply random cubic symmetry transformations to 3D volumes, update documentation, and include tests to verify transformation uniqueness and shape preservation.

New Features:

  • Introduce the CubicSymmetry transform for 3D volumes, enabling random cubic symmetry transformations with 48 possible symmetries.

Enhancements:

  • Add the transform_cube function to handle the 48 possible transformations for cubic symmetry.

Documentation:

  • Update README to include documentation for the new CubicSymmetry transform.

Tests:

  • Add tests for the CubicSymmetry transform to ensure all 48 transformations are unique and preserve the shape of the input.

Chores:

  • Update pyproject.toml to ignore linting rule PLR2004.

Copy link
Contributor

sourcery-ai bot commented Dec 16, 2024

Reviewer's Guide by Sourcery

This PR implements a new 3D transformation called CubicSymmetry, which extends the concept of D4 symmetry to three dimensions. The implementation includes a new transform class that applies one of 48 possible symmetry operations to 3D volumes, along with the corresponding functional implementation and tests.

Class diagram for the new CubicSymmetry transform

classDiagram
    class CubicSymmetry {
        +float p
        +bool|None always_apply
        +CubicSymmetry(float p=1.0, bool|None always_apply=None)
        +dict get_params_dependent_on_data(dict params, dict data)
        +np.ndarray apply_to_volume(np.ndarray volume, int index, **params)
        +np.ndarray apply_to_mask(np.ndarray mask, int index, **params)
        +tuple get_transform_init_args_names()
    }
    class Transform3D {
        <<abstract>>
    }
    CubicSymmetry --|> Transform3D
    note for CubicSymmetry "Applies a random cubic symmetry transformation to a 3D volume."
Loading

Class diagram for the transform_cube function

classDiagram
    class transform_cube {
        +np.ndarray transform_cube(np.ndarray cube, int index)
    }
    note for transform_cube "Transform cube by index (0-47)"
Loading

File-Level Changes

Change Details Files
Added new CubicSymmetry transform class for 3D volume augmentation
  • Implemented transform class with random selection from 48 possible transformations
  • Added support for both volume and mask3d targets
  • Included comprehensive documentation with mathematical background
  • Added class to all exports
albumentations/augmentations/transforms3d/transforms.py
Implemented core transformation function for cube symmetry operations
  • Created transform_cube function handling 48 unique transformations
  • Implemented reflection and rotation logic
  • Added support for both 3D (D,H,W) and 4D (D,H,W,C) arrays
albumentations/augmentations/transforms3d/functional.py
Added tests and configuration updates
  • Created new test file for functional transforms
  • Added uniqueness tests for both 3D and 4D inputs
  • Updated aug_definitions.py with new transform
  • Added PLR2004 to ignored lint rules
  • Updated README with new transform documentation
tests/transforms3d/test_functions.py
tests/aug_definitions.py
pyproject.toml
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ternaus - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

tests/transforms3d/test_functions.py Outdated Show resolved Hide resolved
tests/transforms3d/test_functions.py Outdated Show resolved Hide resolved
tests/transforms3d/test_functions.py Outdated Show resolved Hide resolved
tests/transforms3d/test_functions.py Outdated Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_functions.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 88.63636% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.23%. Comparing base (b1a79c2) to head (4e0d2a0).
Report is 315 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/augmentations/functional.py 40.00% 3 Missing ⚠️
...entations/augmentations/transforms3d/functional.py 95.45% 1 Missing ⚠️
...entations/augmentations/transforms3d/transforms.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2202       +/-   ##
=========================================
+ Coverage      0   89.23%   +89.23%     
=========================================
  Files         0       50       +50     
  Lines         0     8905     +8905     
=========================================
+ Hits          0     7946     +7946     
- Misses        0      959      +959     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ternaus ternaus merged commit a958c85 into main Dec 16, 2024
16 checks passed
@ternaus ternaus deleted the add_CubicSymmetry branch December 16, 2024 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant