-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fixed issue #314 (https://github.com/AIM-Harvard/foundation-cancer-im… #316
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes focus on improving the Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@PaulShiLi I'm happy to merge your fix into the master branch once I go through the code and ensure passing tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
fmcib/utils/idc_helper.py (3)
193-208
: Enhance docstring with return value details.The docstring could be more specific about the structure of the returned dictionary.
Add the following to the Returns section:
Returns: dict: A dictionary containing the extracted information, including the image path, patient ID, and centroid coordinates. + Keys: image_path (str), PatientID (str), coordX (float), + coordY (float), coordZ (float) None: If there's no RTSTRUCT or SEG file, or any step fails.
240-244
: Remove unused variable assignment.The
image
variable is assigned but never used.- try: - image = sitk.ReadImage(str(image_path)) - except Exception as e: - logger.error(f"Failed to read image {image_path}: {e}") - return None + # Verify image can be read + try: + sitk.ReadImage(str(image_path)) + except Exception as e: + logger.error(f"Failed to read image {image_path}: {e}") + return None🧰 Tools
🪛 Ruff (0.8.2)
241-241: Local variable
image
is assigned to but never usedRemove assignment to unused variable
image
(F841)
246-257
: Use safer list access for mask files.While the existence check is good, accessing index 0 could still raise an IndexError if the list is empty.
gtv1_masks = list(series_dir.glob("*GTV-1*.nii.gz")) -if not gtv1_masks: +if len(gtv1_masks) == 0: logger.warning(f"No GTV-1 mask found in {series_dir}. Skipping.") return None
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
fmcib/utils/idc_helper.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
fmcib/utils/idc_helper.py
241-241: Local variable image
is assigned to but never used
Remove assignment to unused variable image
(F841)
266-266: Do not use bare except
(E722)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: build (3.11)
- GitHub Check: build (3.10)
- GitHub Check: build (3.9)
🔇 Additional comments (2)
fmcib/utils/idc_helper.py (2)
Line range hint
273-282
: LGTM! Return value structure is clean and complete.The dictionary construction includes all necessary fields with appropriate types.
🧰 Tools
🪛 Ruff (0.8.2)
241-241: Local variable
image
is assigned to but never usedRemove assignment to unused variable
image
(F841)
266-266: Do not use bare
except
(E722)
Line range hint
193-282
: Verify data integrity for medical imaging processing.Given that this function processes medical imaging data, it's crucial to ensure data integrity throughout the pipeline.
Let's verify the integrity of the processing pipeline:
✅ Verification successful
Data integrity measures are properly implemented
The function implements comprehensive error handling, validation, and logging throughout the medical imaging pipeline:
- Validates input files and formats
- Handles errors gracefully with proper logging
- Implements fallback mechanisms for centroid extraction
- Maintains consistent error reporting patterns
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the integrity of medical imaging data processing # Check for any TODO/FIXME comments that might indicate incomplete processing echo "Checking for TODO/FIXME comments in medical imaging processing..." rg -i "TODO|FIXME" --type py # Check for potential error handling patterns in similar medical imaging functions echo "Checking error handling patterns in similar functions..." ast-grep --pattern 'try { $$$ } catch (Exception $e) { $$$ return None }' # Check for consistent logging patterns in medical imaging functions echo "Checking logging patterns..." rg "logger\.(warning|error)" --type pyLength of output: 1946
🧰 Tools
🪛 Ruff (0.8.2)
241-241: Local variable
image
is assigned to but never usedRemove assignment to unused variable
image
(F841)
266-266: Do not use bare
except
(E722)
# Some masks label is 1, others are 255; try 255 first, else 1 | ||
try: | ||
centroid = label_shape_filter.GetCentroid(255) | ||
except: | ||
centroid = label_shape_filter.GetCentroid(1) | ||
try: | ||
centroid = label_shape_filter.GetCentroid(1) | ||
except Exception as e: | ||
logger.warning(f"Could not extract centroid from mask {mask_path}: {e}") | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Replace bare except with specific exception type.
The bare except clause should catch specific exceptions for better error handling.
try:
centroid = label_shape_filter.GetCentroid(255)
- except:
+ except RuntimeError:
try:
centroid = label_shape_filter.GetCentroid(1)
- except Exception as e:
+ except RuntimeError as e:
logger.warning(f"Could not extract centroid from mask {mask_path}: {e}")
return None
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# Some masks label is 1, others are 255; try 255 first, else 1 | |
try: | |
centroid = label_shape_filter.GetCentroid(255) | |
except: | |
centroid = label_shape_filter.GetCentroid(1) | |
try: | |
centroid = label_shape_filter.GetCentroid(1) | |
except Exception as e: | |
logger.warning(f"Could not extract centroid from mask {mask_path}: {e}") | |
return None | |
# Some masks label is 1, others are 255; try 255 first, else 1 | |
try: | |
centroid = label_shape_filter.GetCentroid(255) | |
except RuntimeError: | |
try: | |
centroid = label_shape_filter.GetCentroid(1) | |
except RuntimeError as e: | |
logger.warning(f"Could not extract centroid from mask {mask_path}: {e}") | |
return None |
🧰 Tools
🪛 Ruff (0.8.2)
266-266: Do not use bare except
(E722)
if len(rt_struct_files) != 0: | ||
dcmrtstruct2nii(str(rt_struct_files[0]), str(series_dir), str(series_dir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for RTSTRUCT conversion.
The dcmrtstruct2nii
call should be wrapped in a try-except block to handle potential conversion failures gracefully.
if len(rt_struct_files) != 0:
- dcmrtstruct2nii(str(rt_struct_files[0]), str(series_dir), str(series_dir))
+ try:
+ dcmrtstruct2nii(str(rt_struct_files[0]), str(series_dir), str(series_dir))
+ except Exception as e:
+ logger.error(f"Failed to convert RTSTRUCT to NIfTI: {e}")
+ return None
Committable suggestion skipped: line range outside the PR's diff.
Summary by CodeRabbit
Bug Fixes
Refactor