Skip to content

Commit

Permalink
fix: pattern resolver update (#116)
Browse files Browse the repository at this point in the history
`PatternResolver` in `med-imagetools` updated the input argument from
`pattern_parser` to `pattern_matcher`, updated this to match here.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Chores**
- Updated parameter naming in the `PatternResolver` class for improved
clarity and consistency.
- Modified the `roiNames` parameter format in segmentation loading tests
for better structure and clarity.
- Adjusted expected output labels in segmentation tests to reflect new
naming conventions.
- Reorganized import statements to source functions from a new module,
maintaining accessibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
strixy16 authored Jan 30, 2025
1 parent f3e71a7 commit 39a6d6b
Show file tree
Hide file tree
Showing 7 changed files with 2,246 additions and 1,917 deletions.
4,122 changes: 2,221 additions & 1,901 deletions pixi.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/readii/io/utils/pattern_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, ClassVar, Dict, Tuple

from imgtools.dicom.sort.exceptions import InvalidPatternError # type: ignore
from imgtools.dicom.sort.parser import PatternParser # type: ignore
from imgtools.pattern_parser.parser import PatternParser # type: ignore

from readii.utils import logger

Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self, filename_format: str) -> None:

try:
self.pattern_parser = PatternParser(
self.filename_format, pattern_parser=self.DEFAULT_PATTERN
self.filename_format, pattern_matcher=self.DEFAULT_PATTERN
)
self.formatted_pattern, self.keys = self.parse() # Validate the pattern by parsing it
except InvalidPatternError as e:
Expand Down
10 changes: 5 additions & 5 deletions src/readii/process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
survivalStatusToNumericMapping,
timeOutcomeColumnSetup,
)
from .select import (
dropUpToFeature,
getOnlyPyradiomicsFeatures,
selectByColumnValue,
)
from .split import (
replaceColumnValues,
splitDataByColumnValue,
)
from .subset import (
dropUpToFeature,
getOnlyPyradiomicsFeatures,
selectByColumnValue,
)

__all__ = [
"addOutcomeLabels",
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test_feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def lung4DRTSTRUCTImage():
lung4DRTSTRUCTPath = "tests/4D-Lung/113_HM10395/11-26-1999-NA-p4-13296/1.000000-P4P113S303I10349 Gated 40.0B-47.35/1-1.dcm"
lung4DCTPath = "tests/4D-Lung/113_HM10395/11-26-1999-NA-p4-13296/1.000000-P4P113S303I10349 Gated 40.0B-29543"
segDictionary = loadSegmentation(lung4DRTSTRUCTPath, modality = 'RTSTRUCT',
baseImageDirPath = lung4DCTPath, roiNames = 'Tumor_c.*')
return segDictionary['Tumor_c40']
baseImageDirPath = lung4DCTPath, roiNames = {'GTV':'Tumor_c.*'})
return segDictionary['GTV']

@pytest.fixture
def pyradiomicsParamFilePath():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def lung4DRTSTRUCTImage():
lung4DRTSTRUCTPath = "tests/4D-Lung/113_HM10395/11-26-1999-NA-p4-13296/1.000000-P4P113S303I10349 Gated 40.0B-47.35/1-1.dcm"
lung4DCTPath = "tests/4D-Lung/113_HM10395/11-26-1999-NA-p4-13296/1.000000-P4P113S303I10349 Gated 40.0B-29543"
segDictionary = loadSegmentation(lung4DRTSTRUCTPath, modality = 'RTSTRUCT',
baseImageDirPath = lung4DCTPath, roiNames = 'Tumor_c.*')
return segDictionary['Tumor_c40']
baseImageDirPath = lung4DCTPath, roiNames = {'GTV':'Tumor_c.*'})
return segDictionary['GTV']


def test_flattenImage(nsclcSEGImage):
Expand Down
19 changes: 14 additions & 5 deletions tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,28 @@ def test_loadSegmentationSEG(nsclcSEGPath):
"Wrong origin"


def test_loadSegmentationRTSTRUCT(lung4DRTSTRUCTPath, lung4DCTPath):

@pytest.mark.parametrize(
"roiNames, expected",
[
({"GTV":'Tumor_c.*'}, "GTV"),
('Tumor_c.*', "Tumor_c40"),
(["Tumor_c40"], "Tumor_c40"),
]
)
def test_loadSegmentationRTSTRUCT(lung4DRTSTRUCTPath, lung4DCTPath, roiNames, expected):
"""Test loading a RTSTRUCT file"""
actual = loadSegmentation(segImagePath = lung4DRTSTRUCTPath,
modality = 'RTSTRUCT',
baseImageDirPath = lung4DCTPath,
roiNames = 'Tumor_c.*')
roiNames = roiNames)

assert isinstance(actual, dict), \
"Wrong object type, should be dictionary"
assert list(actual.keys()) == ['Tumor_c40'], \
"Segmentation label is wrong, should be Heart"
assert list(actual.keys()) == [expected], \
f"Segmentation label is wrong, should be GTV, getting {list(actual.keys())}"

actualImage = actual['Tumor_c40']
actualImage = actual[expected]

assert isinstance(actualImage, sitk.Image), \
"Wrong object type"
Expand Down

0 comments on commit 39a6d6b

Please sign in to comment.