Skip to content

Commit 81b7f5b

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 01b88fa commit 81b7f5b

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

monai/tests/test_clinical_preprocessing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_ct_preprocessing_pipeline():
2626
assert scale_transform.b_min == 0.0
2727
assert scale_transform.b_max == 1.0
2828
assert scale_transform.clip is True
29-
29+
3030
# Verify LoadImage configuration (as suggested in review)
3131
load_transform = pipeline.transforms[0]
3232
assert load_transform.image_only is True
@@ -44,7 +44,7 @@ def test_mri_preprocessing_pipeline():
4444
# Verify MRI-specific normalization parameter
4545
normalize_transform = pipeline.transforms[2]
4646
assert normalize_transform.nonzero is True
47-
47+
4848
# Verify LoadImage configuration (as suggested in review)
4949
load_transform = pipeline.transforms[0]
5050
assert load_transform.image_only is True
@@ -55,7 +55,7 @@ def test_preprocess_dicom_series_invalid_modality():
5555
# More robust error matching (as suggested in review)
5656
with pytest.raises(UnsupportedModalityError) as exc_info:
5757
preprocess_dicom_series("dummy_path.dcm", "PET")
58-
58+
5959
error_message = str(exc_info.value)
6060
# Check that all supported modalities are mentioned (order doesn't matter)
6161
assert "CT" in error_message
@@ -99,4 +99,4 @@ def test_preprocess_dicom_series_mr(mock_pipeline):
9999

100100
# Test lowercase and "MRI" variant
101101
result2 = preprocess_dicom_series("dummy_path.dcm", "mri")
102-
assert result2 == dummy_output
102+
assert result2 == dummy_output

monai/transforms/clinical_preprocessing.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class UnsupportedModalityError(ValueError):
2121
def get_ct_preprocessing_pipeline() -> Compose:
2222
"""
2323
Create a preprocessing pipeline for CT (Computed Tomography) images.
24-
24+
2525
Returns:
2626
Compose: A transform composition for CT preprocessing.
27-
27+
2828
The pipeline consists of:
2929
1. LoadImage - Load DICOM series
3030
2. EnsureChannelFirst - Add channel dimension
3131
3. ScaleIntensityRange - Scale Hounsfield Units (HU) from [-1000, 400] to [0, 1]
32-
32+
3333
Note:
3434
The HU window [-1000, 400] is a common soft tissue window.
3535
"""
@@ -43,15 +43,15 @@ def get_ct_preprocessing_pipeline() -> Compose:
4343
def get_mri_preprocessing_pipeline() -> Compose:
4444
"""
4545
Create a preprocessing pipeline for MRI (Magnetic Resonance Imaging) images.
46-
46+
4747
Returns:
4848
Compose: A transform composition for MRI preprocessing.
49-
49+
5050
The pipeline consists of:
5151
1. LoadImage - Load DICOM series
5252
2. EnsureChannelFirst - Add channel dimension
5353
3. NormalizeIntensity - Normalize non-zero voxels
54-
54+
5555
Note:
5656
Normalization is applied only to non-zero voxels to avoid bias from background.
5757
"""
@@ -65,30 +65,30 @@ def get_mri_preprocessing_pipeline() -> Compose:
6565
def preprocess_dicom_series(path: str, modality: str) -> Union[dict, None]:
6666
"""
6767
Preprocess a DICOM series based on the imaging modality.
68-
68+
6969
Args:
7070
path: Path to the DICOM series directory or file.
7171
modality: Imaging modality (case-insensitive). Supported values:
7272
"CT", "MR", "MRI" (MRI is treated as synonym for MR).
73-
73+
7474
Returns:
7575
The preprocessed image data.
76-
76+
7777
Raises:
7878
ModalityTypeError: If modality is not a string.
7979
UnsupportedModalityError: If modality is not supported.
8080
"""
8181
# Validate input type
8282
if not isinstance(modality, str):
8383
raise ModalityTypeError(f"modality must be a string, got {type(modality).__name__}")
84-
84+
8585
# Normalize modality string (strip whitespace, convert to uppercase)
8686
modality_clean = modality.strip().upper()
87-
87+
8888
# Map MRI to MR (treat as synonyms)
8989
if modality_clean == "MRI":
9090
modality_clean = "MR"
91-
91+
9292
# Select appropriate preprocessing pipeline
9393
if modality_clean == "CT":
9494
pipeline = get_ct_preprocessing_pipeline()
@@ -99,16 +99,16 @@ def preprocess_dicom_series(path: str, modality: str) -> Union[dict, None]:
9999
raise UnsupportedModalityError(
100100
f"Unsupported modality '{modality}'. Supported modalities: {', '.join(supported)}"
101101
)
102-
102+
103103
# Apply preprocessing pipeline
104104
return pipeline(path)
105105

106106

107107
# Export the public API
108108
__all__ = [
109109
"ModalityTypeError",
110-
"UnsupportedModalityError",
110+
"UnsupportedModalityError",
111111
"get_ct_preprocessing_pipeline",
112112
"get_mri_preprocessing_pipeline",
113113
"preprocess_dicom_series",
114-
]
114+
]

0 commit comments

Comments
 (0)