Skip to content

Conversation

jjjermiah
Copy link
Contributor

@jjjermiah jjjermiah commented Dec 11, 2024

4D-Lung

combined

Order of operations

  1. negative_control_strategy(image, mask=mask, region=region_strategy)
  2. runs the __call__ on the negative_control_strategy
  3. which runs the __call__ of region(image_array, mask_array)
  4. the result of which is used to figure out what indices of the original image to apply the transform method of the NegativeControlStrategy concrete classes to
  5. only replace the region indices image_array[mask_indices] = transformed_values

Resource on Strategy Pattern: https://refactoring.guru/design-patterns/strategy/python/example

Summary by CodeRabbit

  • New Features

    • Introduced new strategies for negative control and region processing in medical imaging.
    • Added a comprehensive README detailing the Negative Control Process.
    • New entry point for testing and demonstrating negative control strategies.
  • Bug Fixes

    • Updated configuration files to ensure proper inclusion of relevant Python files.
  • Documentation

    • Enhanced documentation in the new README and module-level docstrings.
  • Chores

    • Removed outdated project metadata and dependencies from the configuration files.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces several changes, primarily focusing on the addition of a new path in the ruff.toml configuration file for Python files related to a negative controls refactor. It also removes an outdated old_pyproject.toml file while updating the pyproject.toml file to include new dependencies for type checking. Additionally, new modules related to negative control strategies and region strategies are created, along with their respective classes and methods, enhancing the functionality for image processing.

Changes

File Path Change Summary
config/ruff.toml Updated include list to add "src/readii/negative_controls_refactor/**.py"; removed commented-out select list.
old_pyproject.toml Removed file containing project metadata, dependencies, and build system requirements.
pyproject.toml Added dependencies: mypy and scipy-stubs under [tool.pixi.feature.style.dependencies].
src/readii/negative_controls_refactor/README.md Added detailed explanation of the Negative Control Process and its workflow.
src/readii/negative_controls_refactor/init.py Introduced new module-level docstring and public entities for negative control strategies.
src/readii/negative_controls_refactor/main.py Created a main entry point for testing the module, demonstrating various negative control strategies.
src/readii/negative_controls_refactor/abstract_classes.py Added abstract classes RegionStrategy and NegativeControlStrategy with relevant methods.
src/readii/negative_controls_refactor/manager.py Introduced NegativeControlManager class to manage strategies, including methods for applying and combining strategies.
src/readii/negative_controls_refactor/negative_controls.py Added ShuffledControl, SampledControl, and RandomizedControl classes for manipulating pixel values.
src/readii/negative_controls_refactor/regions.py Introduced classes for region strategies: FullRegion, ROIRegion, NonROIRegion, and NonROIWithBorderRegion.

Possibly related PRs

Suggested reviewers

  • strixy16

🐰 In the fields, I hop with glee,
New paths and classes, oh what a spree!
With strategies fresh and regions anew,
The code now dances, all bright and true.
Let's celebrate changes, both big and small,
For in this refactor, we flourish and sprawl! 🌼✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3bcaa28 and 3edf54e.

⛔ Files ignored due to path filters (1)
  • pixi.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • config/ruff.toml (1 hunks)
  • old_pyproject.toml (0 hunks)
  • pyproject.toml (1 hunks)
  • src/readii/negative_controls_refactor/README.md (1 hunks)
  • src/readii/negative_controls_refactor/__init__.py (1 hunks)
  • src/readii/negative_controls_refactor/__main__.py (1 hunks)
  • src/readii/negative_controls_refactor/abstract_classes.py (1 hunks)
  • src/readii/negative_controls_refactor/manager.py (1 hunks)
  • src/readii/negative_controls_refactor/negative_controls.py (1 hunks)
  • src/readii/negative_controls_refactor/regions.py (1 hunks)

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. (Experiment)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@codecov
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 199 lines in your changes missing coverage. Please review.

Project coverage is 44.51%. Comparing base (3bcaa28) to head (3edf54e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...dii/negative_controls_refactor/abstract_classes.py 0.00% 49 Missing ⚠️
src/readii/negative_controls_refactor/manager.py 0.00% 38 Missing ⚠️
...ii/negative_controls_refactor/negative_controls.py 0.00% 37 Missing ⚠️
src/readii/negative_controls_refactor/regions.py 0.00% 37 Missing ⚠️
src/readii/negative_controls_refactor/__main__.py 0.00% 33 Missing ⚠️
src/readii/negative_controls_refactor/__init__.py 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #81       +/-   ##
===========================================
- Coverage   60.92%   44.51%   -16.41%     
===========================================
  Files          10       16        +6     
  Lines         540      739      +199     
===========================================
  Hits          329      329               
- Misses        211      410      +199     

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

@jjjermiah jjjermiah requested a review from strixy16 December 11, 2024 20:06
@jjjermiah
Copy link
Contributor Author

addressing this comment

image_array isn't actually used in any of the region strategies. Can it be removed?

this is a good catch, when I initially defined the base classes I didnt know how the transformations were done and then I didnt know what other regions might be implemented in the future so I left the image_array parameter.

if we arent looking to implement new regions we can remove the parameter.

some ideas I had for regions that would use the original image would look like :

class ThresholdRegion(RegionStrategy):
	"""
	Region strategy to include only pixels in the image where intensity exceeds a threshold.

	Unlike ROI-based strategies, this strategy does not consider the mask_array.
	"""

	region_name: str = "threshold"

	def __init__(self, threshold: float):
		"""
		Initialize the region strategy with a given intensity threshold.

		Parameters
		----------
		threshold : float
			The intensity threshold for including pixels in the region.
		"""
		self.threshold = threshold

	def __call__(self, image_array: np.ndarray, _: np.ndarray) -> np.ndarray:
		"""
		Apply the threshold-based region mask to the image.

		Parameters
		----------
		image_array : np.ndarray
			The full image array to evaluate pixel intensities.
		_ : np.ndarray
			Ignored in this implementation.

		Returns
		-------
		np.ndarray
			A binary mask including only pixels in the image that exceed the threshold.
		"""
		# Apply the threshold directly to the image array
		region_mask = np.where(image_array > self.threshold, 1, 0)

		# Validate that the resulting mask is not empty
		if not region_mask.any():
			raise ValueError("No pixels in the image exceed the specified intensity threshold.")

		return region_mask

@jjjermiah jjjermiah marked this pull request as ready for review December 11, 2024 21:21
@jjjermiah jjjermiah merged commit c10a568 into main Dec 11, 2024
14 of 17 checks passed
@jjjermiah jjjermiah deleted the jjjermiah/refactor/negative-controls/abstract-and-concrete-classes branch December 13, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants