Skip to content

Commit 24c0c42

Browse files
committed
Fix failing unit-test test_wsireader
Conversion of units when the unit if '' caused the test to fail. FAILED tests/test_wsireader.py::TestTiffFile::test_resolution_mpp_0__home_johnsonhj_src_MONAI_tests_testing_data_temp_wsi_generic_tiff_tiff - ValueError: Currently, it only supports length conversion but `` is given. FAILED tests/test_wsireader.py::TestTiffFile::test_resolution_mpp_0__home_johnsonhj_src_MONAI_tests_testing_data_temp_wsi_generic_tiff_tiff - AttributeError: 'ConvertUnits' object has no attribute 'conversion_factor' Signed-off-by: Hans Johnson <[email protected]>
1 parent 3a0c2d5 commit 24c0c42

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

monai/data/wsi_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ def get_mpp(self, wsi, level: int) -> tuple[float, float]:
10981098
unit = wsi.pages[level].tags.get("ResolutionUnit")
10991099
if unit is not None:
11001100
unit = str(unit.value)[8:]
1101-
else:
1101+
if unit is None or len(unit) == 0:
11021102
warnings.warn("The resolution unit is missing. `micrometer` will be used as default.")
11031103
unit = "micrometer"
11041104

monai/utils/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def __init__(self, input_unit: str, target_unit: str) -> None:
814814
"Both input and target units should be from the same quantity. "
815815
f"Input quantity is {input_base} while target quantity is {target_base}"
816816
)
817-
self._calculate_conversion_factor()
817+
self.conversion_factor = self._calculate_conversion_factor()
818818

819819
def _get_valid_unit_and_base(self, unit):
820820
unit = str(unit).lower()
@@ -841,7 +841,7 @@ def _calculate_conversion_factor(self):
841841
return 1.0
842842
input_power = self._get_unit_power(self.input_unit)
843843
target_power = self._get_unit_power(self.target_unit)
844-
self.conversion_factor = 10 ** (input_power - target_power)
844+
return 10 ** (input_power - target_power)
845845

846846
def __call__(self, value: int | float) -> Any:
847847
return float(value) * self.conversion_factor

0 commit comments

Comments
 (0)