-
Notifications
You must be signed in to change notification settings - Fork 4
Fix legacy mpp factor + multiple dcm files #270
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
base: main
Are you sure you want to change the base?
Conversation
|
Claude finished @blanca-pablos's task —— View job Code Review: PR #270 - Fix legacy mpp factor + multiple dcm filesSummaryThis PR addresses two important issues in WSI (Whole Slide Image) processing:
Overall, this is a solid medical imaging fix addressing real-world compatibility issues. However, there are 5 linting issues that must be fixed and missing test coverage for the new functionality. 🔴 BLOCKING ISSUES (Must Fix)1. Linting Failures (5 errors)The following linting issues were found: File: Fix: # Current (line 351):
for file_path, r, c in files_with_dims:
# Should be:
for file_path, _r, _c in files_with_dims:File: Fix for line 67: # Change from instance method to static method:
@staticmethod
def _get_mpp_correction_factor(props: dict[str, Any]) -> float:Fix for line 77: # Change:
_LEGACY_MPP_FACTOR = 1 / 10
# To (define at module level as constant):
LEGACY_MPP_FACTOR = 1 / 10
# Or inline it:
legacy_mpp_factor = 1 / 10Verify fixes: uv run ruff check --fix src/aignostics/application/_service.py src/aignostics/wsi/_openslide_handler.py
make lint2. Missing Test Coverage (CRITICAL for Medical Device Software)The new functionality has zero test coverage:
Required test cases:
Test example: @pytest.mark.unit
def test_filter_dicom_series_files_single_file(tmp_path):
"""Test that single DICOM files are not filtered."""
# Create test DICOM file
ds = pydicom.Dataset()
ds.SeriesInstanceUID = "1.2.3.4.5"
ds.Rows = 1024
ds.Columns = 1024
dcm_file = tmp_path / "test.dcm"
ds.save_as(dcm_file)
excluded = Service._filter_dicom_series_files(tmp_path)
assert len(excluded) == 0
@pytest.mark.unit
def test_mpp_correction_factor_legacy_libvips():
"""Test MPP correction for legacy libvips <8.8.3."""
props = {
"tiff.ImageDescription": """<vips libVips-version="8.7.0" />"""
}
handler = OpenSlideHandler(test_file_path)
factor = handler._get_mpp_correction_factor(props)
assert factor == 0.1 # Legacy correctionWhy this is critical:
🟡 SUGGESTIONS (Non-Blocking)3. Commit Message ConventionCurrent commits: Issue: First commit doesn't follow conventional commits format. Should be: Why it matters: Conventional commits enable automatic changelog generation. 4. PR Description MissingIssue: No PR description provided. For a medical device SDK, this is concerning. Should include:
Example: ## Problem
1. TIFF files exported with libvips <8.8.3 have incorrect MPP values (10x off)
2. Multi-file DICOM series cause duplicate processing of the same image data
## Solution
1. Detect libvips version from TIFF metadata and apply 0.1 correction factor for buggy versions
2. Filter DICOM files by SeriesInstanceUID, keeping only highest resolution file per series
## Testing
- Manual testing with legacy TIFF files from libvips 8.7.0
- Manual testing with multi-file DICOM series
## References
- libvips bug: https://github.com/libvips/libvips/issues/14215. Documentation Updates NeededFile: Should document:
File: Should document:
6. Error Handling in
|
❌ 1 Tests Failed:
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
* Add mpp correction factor for tiffs written using older versions of vips containing a bug that wrote resolution as px / mm instead of cm. * Select only highest resolution file from DICOM series in multiple files.
c504295 to
55c4343
Compare
|
Claude finished @blanca-pablos's task —— View job PR Review: Fix legacy mpp factor + multiple dcm filesComprehensive review of PR #270 for medical device SDK completed. Todo List:
SummaryThis PR addresses two important medical imaging compatibility issues:
Overall Assessment: Good fix for real-world issues, but has 1 CRITICAL bug causing test failure, missing test coverage (regulatory requirement), and several smaller issues. 🔴 BLOCKING ISSUES (Must Fix Before Merge)1. CRITICAL BUG: MPP Correction Applied to DICOM Files ❌Location: Issue: The MPP correction factor is being incorrectly applied to DICOM files, breaking the test and producing wrong MPP values (10x error in medical measurements!). Root Cause: Inconsistent logic between line 164 and line 212.
Evidence:
Fix: # Line 212 should be:
mpp_correction_factor = self._get_mpp_correction_factor(props) if "tiff.XResolution" in props else 1.0Why Critical: In computational pathology, incorrect MPP can lead to:
Verify Fix: uv run pytest tests/aignostics/wsi/cli_test.py::test_inspect_openslide_dicom -v2. Missing Test Coverage (Regulatory Requirement) ❌No tests exist for the new functionality: A.
B.
Required Test Cases: For DICOM filtering ( @pytest.mark.unit
def test_filter_dicom_series_single_file(tmp_path):
"""Single DICOM file should not be filtered."""
@pytest.mark.unit
def test_filter_dicom_series_multiple_files_same_series(tmp_path):
"""Keep highest resolution file from multi-file series."""
@pytest.mark.unit
def test_filter_dicom_series_multiple_series(tmp_path):
"""Filter each series independently."""
@pytest.mark.unit
def test_filter_dicom_series_invalid_files(tmp_path):
"""Files that fail to read should not be excluded."""For MPP correction ( @pytest.mark.unit
def test_mpp_correction_legacy_libvips():
"""libvips <8.8.3 should apply 0.1 correction."""
props = {"tiff.ImageDescription": '<vips libVips-version="8.7.0" />'}
# Assert correction = 0.1
@pytest.mark.unit
def test_mpp_correction_modern_libvips():
"""libvips ≥8.8.3 should apply 1.0 correction."""
props = {"tiff.ImageDescription": '<vips libVips-version="8.8.3" />'}
# Assert correction = 1.0
@pytest.mark.unit
def test_mpp_correction_no_version():
"""Missing version should default to 0.1 (legacy)."""
props = {"tiff.ImageDescription": '<vips />'}
# Assert correction = 0.1
@pytest.mark.unit
def test_mpp_correction_no_tiff_metadata():
"""Non-TIFF files should use 1.0 correction."""
props = {} # No tiff.ImageDescription
# Assert correction = 1.0Why Critical:
Action Required: Add comprehensive unit tests before merge. 3. Quality Gate Failures ❌SonarQube Report:
Action: Address SonarQube findings and add tests to meet 80% coverage threshold. 🟡 IMPORTANT ISSUES (Should Fix)4. Commit Message Convention ViolationCurrent commits: Issues:
Should be: Why it matters: Conventional commits enable automatic changelog generation per Reference: See root 5. Missing PR DescriptionIssue: No PR description provided. For medical device software, this is concerning. Should include:
Example: ## Problem
1. TIFF files exported with libvips <8.8.3 have incorrect MPP values (10x off)
2. Multi-file DICOM series cause duplicate processing of same image data
## Solution
1. Detect libvips version from TIFF metadata, apply 0.1 correction for buggy versions
2. Filter DICOM files by SeriesInstanceUID, keeping highest resolution per series
## Testing
- ✅ Linting passes
- ❌ Need unit tests for new functionality (see review)
- ✅ Manual testing with legacy TIFF files
- ✅ Manual testing with multi-file DICOM series
## References
- libvips bug: https://github.com/libvips/libvips/issues/1421
- DICOM SeriesInstanceUID: DICOM PS3.3 Section C.7.3.16. Documentation Updates NeededFiles to update: A.
B.
Why: The root 🟢 POSITIVE ASPECTS
🏥 MEDICAL DEVICE CONSIDERATIONSSeverity of IssuesMPP accuracy is critical in computational pathology:
The bug at line 212 would cause:
Regulatory ContextPer repository guidelines (
📋 ACTION ITEMSMust Fix Before Merge:
Should Fix (Recommended):
🔍 ARCHITECTURAL REVIEW✅ Modulith principles: Changes within appropriate module boundaries 🎯 VERIFICATION COMMANDSAfter fixing the bug and adding tests: # Fix linting if needed
make lint
# Run specific failing test
uv run pytest tests/aignostics/wsi/cli_test.py::test_inspect_openslide_dicom -v
# Run all WSI tests
uv run pytest tests/aignostics/wsi/ -v
# Run all application tests
uv run pytest tests/aignostics/application/ -v
# Check coverage
uv run pytest --cov=aignostics.application --cov=aignostics.wsi \
--cov-report=term-missing tests/aignostics/application tests/aignostics/wsi
# Full test suite
make test📊 REVIEW SUMMARY
🏁 FINAL VERDICTCannot merge until:
This is excellent work addressing real-world medical imaging issues, but medical device software requires comprehensive testing. The line 212 bug is critical and would cause 10x measurement errors in DICOM files. Recommendation: Fix the bug first, then add tests, then we can discuss documentation improvements in a follow-up. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|




No description provided.