Skip to content

Commit c273cf7

Browse files
Fix CI compliance: formatting, type hints, line length
Signed-off-by: Hitendrasinh Rathod <Hitendrasinh.data7@gmail.com>
1 parent 5a4fbb5 commit c273cf7

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

monai/tests/test_clinical_preprocessing.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ def test_unsupported_modality():
8181
@patch("monai.transforms.clinical_preprocessing.LoadImage")
8282
def test_modality_case_insensitivity(mock_load):
8383
"""Test case-insensitive modality handling."""
84-
# Mock the LoadImage to avoid actual file I/O
8584
mock_load.return_value = Mock(return_value=Mock())
8685

8786
for modality in ["CT", "ct", "Ct", "CT ", "MR", "mr", "MRI", "mri", " MrI "]:
88-
# Should not raise modality errors
8987
result = preprocess_dicom_series("dummy.dcm", modality)
9088
assert result is not None
9189

@@ -100,13 +98,11 @@ def test_mr_modality_distinct(mock_load):
10098

10199
def test_preprocess_dicom_series_integration(tmp_path):
102100
"""Integration test with dummy NIfTI file."""
103-
# Create a dummy NIfTI file for testing
104101
dummy_data = np.random.randn(64, 64, 64).astype(np.float32)
105102
test_file = tmp_path / "test.nii.gz"
106103

107104
write_nifti(dummy_data, test_file)
108105

109-
# Test with each modality (including both MR and MRI)
110106
for modality in ["CT", "MR", "MRI"]:
111107
result = preprocess_dicom_series(str(test_file), modality)
112108
assert result is not None

monai/transforms/clinical_preprocessing.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
This module provides modality-specific preprocessing pipelines for common medical imaging modalities.
1616
"""
1717

18-
from monai.data import MetaTensor
18+
from typing import Any
19+
1920
from monai.transforms import (
2021
Compose,
2122
EnsureChannelFirst,
@@ -38,9 +39,9 @@ def get_ct_preprocessing_pipeline() -> Compose:
3839
Create a preprocessing pipeline for CT images.
3940
4041
Returns:
41-
Compose: Transform composition for CT preprocessing. Applies HU windowing
42-
[-1000, 400] scaled to [0, 1] with clipping, suitable for soft tissue
43-
and lung visualization.
42+
Compose: Transform composition for CT preprocessing.
43+
Applies Hounsfield Unit (HU) windowing [-1000, 400] scaled to [0, 1].
44+
This range captures lung (-1000 to -400 HU) and soft tissue (0 to 100 HU) contrast.
4445
"""
4546
return Compose(
4647
[
@@ -62,9 +63,9 @@ def get_mri_preprocessing_pipeline() -> Compose:
6263
Create a preprocessing pipeline for MRI images.
6364
6465
Returns:
65-
Compose: Transform composition for MRI preprocessing. Normalizes using
66-
mean/std computed over non-zero voxels only, appropriate for MRI
67-
data with background regions.
66+
Compose: Transform composition for MRI preprocessing.
67+
Normalizes intensities using nonzero voxels only, excluding background regions
68+
typical in MRI acquisitions.
6869
"""
6970
return Compose(
7071
[
@@ -75,22 +76,23 @@ def get_mri_preprocessing_pipeline() -> Compose:
7576
)
7677

7778

78-
def preprocess_dicom_series(path: str, modality: str) -> MetaTensor:
79+
def preprocess_dicom_series(path: str, modality: str) -> Any:
7980
"""Preprocess a DICOM series or file based on imaging modality.
8081
8182
Args:
8283
path: Path to the DICOM file or directory containing a DICOM series.
8384
modality: Imaging modality. Supported values are "CT", "MR", and "MRI" (case-insensitive).
8485
8586
Returns:
86-
MetaTensor: Preprocessed image tensor with metadata.
87+
Any: Preprocessed image data.
8788
8889
Raises:
8990
ModalityTypeError: If modality is not a string.
9091
UnsupportedModalityError: If the provided modality is not supported.
9192
"""
9293
if not isinstance(modality, str):
93-
raise ModalityTypeError("modality must be a string")
94+
error_msg = "modality must be a string"
95+
raise ModalityTypeError(error_msg)
9496

9597
modality_clean = modality.strip().upper()
9698

@@ -99,9 +101,11 @@ def preprocess_dicom_series(path: str, modality: str) -> MetaTensor:
99101
elif modality_clean == "CT":
100102
pipeline = get_ct_preprocessing_pipeline()
101103
else:
102-
raise UnsupportedModalityError(
103-
f"Unsupported modality '{modality}'. Supported modalities: CT, MR, MRI"
104+
error_msg = (
105+
f"Unsupported modality '{modality}'. "
106+
f"Supported modalities: CT, MR, MRI"
104107
)
108+
raise UnsupportedModalityError(error_msg)
105109

106110
return pipeline(path)
107111

0 commit comments

Comments
 (0)