Skip to content

Commit 3a493d4

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 34a7aa2 commit 3a493d4

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
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
4949
load_transform = pipeline.transforms[0]
5050
assert load_transform.image_only is True
@@ -54,7 +54,7 @@ def test_preprocess_dicom_series_invalid_modality():
5454
"""Test preprocess_dicom_series raises UnsupportedModalityError for unsupported modality."""
5555
with pytest.raises(UnsupportedModalityError) as exc_info:
5656
preprocess_dicom_series("dummy_path.dcm", "PET")
57-
57+
5858
error_message = str(exc_info.value)
5959
# Check that all required strings are present (separate assertions, no OR operator)
6060
assert "CT" in error_message
@@ -93,4 +93,4 @@ def test_preprocess_dicom_series_mr(mock_pipeline):
9393

9494
# Test lowercase and "MRI" variant
9595
result2 = preprocess_dicom_series("dummy_path.dcm", "mri")
96-
assert result2 == dummy_output
96+
assert result2 == dummy_output

monai/transforms/clinical_preprocessing.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class UnsupportedModalityError(ValueError):
2020
def get_ct_preprocessing_pipeline() -> Compose:
2121
"""
2222
Create a preprocessing pipeline for CT (Computed Tomography) images.
23-
23+
2424
Returns:
2525
Compose: A transform composition for CT preprocessing.
26-
26+
2727
The pipeline consists of:
2828
1. LoadImage - Load DICOM series
2929
2. EnsureChannelFirst - Add channel dimension
3030
3. ScaleIntensityRange - Scale Hounsfield Units (HU) from [-1000, 400] to [0, 1]
31-
31+
3232
Note:
3333
The HU window [-1000, 400] is a common soft tissue window.
3434
"""
@@ -42,15 +42,15 @@ def get_ct_preprocessing_pipeline() -> Compose:
4242
def get_mri_preprocessing_pipeline() -> Compose:
4343
"""
4444
Create a preprocessing pipeline for MRI (Magnetic Resonance Imaging) images.
45-
45+
4646
Returns:
4747
Compose: A transform composition for MRI preprocessing.
48-
48+
4949
The pipeline consists of:
5050
1. LoadImage - Load DICOM series
5151
2. EnsureChannelFirst - Add channel dimension
5252
3. NormalizeIntensity - Normalize non-zero voxels
53-
53+
5454
Note:
5555
Normalization is applied only to non-zero voxels to avoid bias from background.
5656
"""
@@ -64,30 +64,30 @@ def get_mri_preprocessing_pipeline() -> Compose:
6464
def preprocess_dicom_series(path: str, modality: str):
6565
"""
6666
Preprocess a DICOM series based on the imaging modality.
67-
67+
6868
Args:
6969
path: Path to the DICOM series directory or file.
7070
modality: Imaging modality (case-insensitive). Supported values:
7171
"CT", "MR", "MRI" (MRI is treated as synonym for MR).
72-
72+
7373
Returns:
7474
The preprocessed image data.
75-
75+
7676
Raises:
7777
ModalityTypeError: If modality is not a string.
7878
UnsupportedModalityError: If modality is not supported.
7979
"""
8080
# Validate input type
8181
if not isinstance(modality, str):
8282
raise ModalityTypeError(f"modality must be a string, got {type(modality).__name__}")
83-
83+
8484
# Normalize modality string (strip whitespace, convert to uppercase)
8585
modality_clean = modality.strip().upper()
86-
86+
8787
# Map MRI to MR (treat as synonyms)
8888
if modality_clean == "MRI":
8989
modality_clean = "MR"
90-
90+
9191
# Select appropriate preprocessing pipeline
9292
if modality_clean == "CT":
9393
pipeline = get_ct_preprocessing_pipeline()
@@ -98,16 +98,16 @@ def preprocess_dicom_series(path: str, modality: str):
9898
raise UnsupportedModalityError(
9999
f"Unsupported modality '{modality}'. Supported modalities: {', '.join(supported)}"
100100
)
101-
101+
102102
# Apply preprocessing pipeline
103103
return pipeline(path)
104104

105105

106106
# Export the public API
107107
__all__ = [
108108
"ModalityTypeError",
109-
"UnsupportedModalityError",
109+
"UnsupportedModalityError",
110110
"get_ct_preprocessing_pipeline",
111111
"get_mri_preprocessing_pipeline",
112112
"preprocess_dicom_series",
113-
]
113+
]

0 commit comments

Comments
 (0)