Skip to content

Commit bd401ba

Browse files
committed
ADD: Add unit tests for wsireader
1 parent 3d9c9f5 commit bd401ba

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/test_wsireader.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import glymur
1717
import numpy as np
1818
import pytest
19+
import SimpleITK as sitk # noqa: N813
1920
import zarr
2021
from click.testing import CliRunner
2122
from packaging.version import Version
@@ -2989,7 +2990,7 @@ def test_fsspec_reader_open_pass_empty_json(tmp_path: Path) -> None:
29892990

29902991

29912992
def test_read_rect_transformedreader_svs_baseline(
2992-
sample_svs: Path, remote_sample: Callable
2993+
sample_svs: Path, remote_sample: Callable, tmp_path: Path
29932994
) -> None:
29942995
"""Test TransformedWSIReader.read_rect with an SVS file at baseline."""
29952996
wsi = wsireader.TransformedWSIReader(
@@ -3033,6 +3034,26 @@ def test_read_rect_transformedreader_svs_baseline(
30333034
# We don't expect arrays to be the same, but dimensions should be
30343035
assert im_region.shape == im_region_4.shape
30353036

3037+
# Now test MHA file with correct shape
3038+
transform = remote_sample("reg_disp_mha_example")
3039+
displacement_field = sitk.ReadImage(transform, sitk.sitkVectorFloat64)
3040+
disp_array = sitk.GetArrayFromImage(displacement_field) # (2, H, W)
3041+
disp_array = np.moveaxis(disp_array, 0, -1)
3042+
3043+
# Save it to a new .mha file in tmp_path
3044+
transform_path = tmp_path / "new_disp.mha"
3045+
sitk.WriteImage(disp_array, str(transform_path))
3046+
3047+
wsi5 = wsireader.TransformedWSIReader(
3048+
sample_svs,
3049+
target_img=sample_svs,
3050+
transform=transform_path,
3051+
)
3052+
im_region_5 = wsi5.read_rect(location, size, resolution=0, units="level")
3053+
3054+
# We don't expect arrays to be the same, but dimensions should be
3055+
assert im_region.shape == im_region_5.shape
3056+
30363057
# Test wrong file type
30373058
with pytest.raises(ValueError, match="Unsupported transformation file format"):
30383059
wsireader.TransformedWSIReader(

0 commit comments

Comments
 (0)