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

feat: Add visualization module with environment detection for Jupyter notebooks #223

Draft
wants to merge 28 commits into
base: development
Choose a base branch
from

Conversation

jjjermiah
Copy link
Contributor

@jjjermiah jjjermiah commented Feb 11, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced image visualization with interactive 3D slicing and multi-slice comparison.
    • Added tools to extract, manage, and export 2D slices as animated or static images.
    • Improved environment detection for a more tailored interactive experience.

semantic-release and others added 21 commits February 7, 2025 17:56
In old version, bounding box was a single voxel. Now is expanded to at
least the minimum dimension default.

- **New Features**
- Now, users can optionally specify a desired size when generating image
bounding boxes for enhanced control.
  
- **Chores**
  - Updated the software version from 1.21.1 to 1.22.0.
…method to Scan class for improved string representation
In old version, bounding box was a single voxel. Now is expanded to at
least the minimum dimension default.

- **New Features**
- Now, users can optionally specify a desired size when generating image
bounding boxes for enhanced control.

- **Chores**
  - Updated the software version from 1.21.1 to 1.22.0.
… in an image (#221)

This works the same way as `_adjust_negative_coordinates`, but requires
the image as an addition input and modifies the RegionBox object
directly.

A message is logged in the debugger if a dimension is adjusted.

I also updated the `crop_image` function to call this before applying
the crop.
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request modifies the image visualization module. The __init__.py file now imports additional entities from both utils and visualizer, updating its public interface via the __all__ declaration. In utils.py, an EnvironmentType enum with a detect method is introduced to identify the Python execution environment. In visualizer.py, two new classes, ImageSlices and SliceImage3D, along with the function view_multiple_SliceImage3DObjects, are added to manage 2D slicing and visualization of 3D images.

Changes

File(s) Change Summary
.../vizualize/__init__.py Updated module exports by adding imports for EnvironmentType (from utils) and for ImageSlices, SliceImage3D, and view_multiple_SliceImage3DObjects (from visualizer), with an updated __all__ list.
.../vizualize/utils.py, .../vizualize/visualizer.py Added new public entities: in utils.py, the EnvironmentType enum with a detect method; in visualizer.py, the ImageSlices and SliceImage3D classes and the view_multiple_SliceImage3DObjects function to handle slicing and visualization of 3D images.

Feedback

The changes are clearly segmented, which aids in maintainability. To further enhance readability and long-term maintainability, consider the following:

  • Documentation: Adding detailed docstrings to classes and methods—especially for the slicing functions and the detect method—can help future developers understand expected behaviors and parameter types.
  • Inline Comments: Including inline comments within complex methods (e.g., the slice generation and error handling) could improve code clarity.
  • Consistency: Ensure that logging and error messages follow a consistent format, which will be beneficial if the code is extended further.
  • Testing: Verify that the exposed public entities behave as expected, particularly when integrated into larger systems.

Overall, the modular design and explicit export declarations are positive steps toward making the codebase more maintainable.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jjjermiah jjjermiah marked this pull request as draft February 11, 2025 21:17
Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (7)
src/imgtools/vizualize/visualizer.py (5)

33-34: Consider adding a class-level docstring.

While the methods in ImageSlices are reasonably documented, a brief class-level docstring would improve clarity about its overall purpose.


37-42: Clarify dictionary keys in the from_dict method.

Here, you convert the dict[tuple[int, int], Image.Image] into a sorted list of images, but the significance of the tuple[int, int] keys is not immediately clear from the docstring. A brief explanation would help future maintainers understand their meaning and sorting logic.


73-75: Class docstring references mask overlay color incorrectly.

The docstring says the mask is overlaid in red, but the _generate_slice method actually uses the green channel to display the mask. Please update the docstring or the overlay color to keep them consistent.

- """Generates 2D slices from a 3D SimpleITK image and optionally overlays a mask."""
+ """Generates 2D slices from a 3D SimpleITK image and optionally overlays a green mask."""

185-186: Remove or update reference to metadata text.

The docstring mentions "metadata text in the bottom right corner," but no text is drawn. You might consider removing this statement or implementing the metadata overlay.


343-349: Unused variable sz.

The logic here conditionally assigns sz based on dim, but immediately overwrites it with Size3D(new_size, new_size, new_size) on line 349 without further usage. This might be leftover code.

-    if dim == 0:
-        sz = Size3D(new_size, new_size, 0)
-    elif dim == 1:
-        sz = Size3D(new_size, 0, new_size)
-
     sz = Size3D(new_size, new_size, new_size)
src/imgtools/vizualize/__init__.py (1)

1-14: Add a brief module-level docstring.

A short explanation of the module’s purpose, such as how it ties utils and visualizer together, will enhance readability and maintainability.

src/imgtools/vizualize/utils.py (1)

5-23: Reflect QtConsole detection in enum usage.

The docstring mentions a JUPYTER_QTCONSOLE environment type, but the code does not explicitly differentiate QtConsole from standard Jupyter Notebook. Consider adjusting the detection logic or updating the docstring to avoid confusion.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0234fe0 and f750b41.

⛔ Files ignored due to path filters (2)
  • pixi.lock is excluded by !**/*.lock and included by none
  • pixi.toml is excluded by none and included by none
📒 Files selected for processing (3)
  • src/imgtools/vizualize/__init__.py (1 hunks)
  • src/imgtools/vizualize/utils.py (1 hunks)
  • src/imgtools/vizualize/visualizer.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/**/*.py`: Review the Python code for compliance with PE...

src/**/*.py: Review the Python code for compliance with PEP 8 and PEP 257 (docstring conventions). Ensure the following: - Variables and functions follow meaningful naming conventions. - Docstrings are present, accurate, and align with the implementation. - Code is efficient and avoids redundancy while adhering to DRY principles. - Consider suggestions to enhance readability and maintainability. - Highlight any potential performance issues, edge cases, or logical errors. - Ensure all imported libraries are used and necessary.

  • src/imgtools/vizualize/utils.py
  • src/imgtools/vizualize/__init__.py
  • src/imgtools/vizualize/visualizer.py
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Unit-Tests (windows-latest, py313)
  • GitHub Check: Unit-Tests (windows-latest, py312)
  • GitHub Check: Unit-Tests (windows-latest, py311)
  • GitHub Check: Unit-Tests (windows-latest, py310)
  • GitHub Check: Unit-Tests (macos-13, py313)
  • GitHub Check: Unit-Tests (macos-13, py312)
  • GitHub Check: Unit-Tests (macos-13, py311)
  • GitHub Check: Unit-Tests (macos-13, py310)
  • GitHub Check: Unit-Tests (macos-latest, py310)
  • GitHub Check: Unit-Tests (ubuntu-latest, py313)
  • GitHub Check: Unit-Tests (ubuntu-latest, py312)
  • GitHub Check: Unit-Tests (ubuntu-latest, py311)
  • GitHub Check: Unit-Tests (ubuntu-latest, py310)
🔇 Additional comments (3)
src/imgtools/vizualize/visualizer.py (2)

1-2: Good top-level docstring.

This concise top-level docstring accurately summarizes the file's purpose and functionality.


131-134: Validate the slice dimension to prevent IndexErrors.

While the docstring states the dimension should be 0, 1, or 2, there is no explicit check, so passing invalid values (like 3) would cause out-of-bounds issues. Consider adding a validation check.

+ if dim not in (0, 1, 2):
+     raise ValueError(f"Invalid dimension {dim}. Must be 0, 1, or 2.")
src/imgtools/vizualize/utils.py (1)

5-65: Good coverage of environment detection logic.

The structured approach to detect IPython-related environments and fall back to standard Python is clear and comprehensive. Nicely done!

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.33%. Comparing base (0234fe0) to head (f750b41).

Additional details and impacted files
@@             Coverage Diff              @@
##           development     #223   +/-   ##
============================================
  Coverage        63.33%   63.33%           
============================================
  Files               52       52           
  Lines             3758     3758           
============================================
  Hits              2380     2380           
  Misses            1378     1378           

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

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.

2 participants