Skip to content

Commit 30dfc5b

Browse files
committed
test: Test TemplateDimensions interface
1 parent 6cca4df commit 30dfc5b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

niworkflows/interfaces/tests/test_images.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#
2323
"""Test images module."""
2424
import time
25+
from pathlib import Path
2526
import numpy as np
2627
import nibabel as nb
2728
from nipype.pipeline import engine as pe
@@ -179,3 +180,38 @@ def test_RobustAverage(tmpdir, shape):
179180

180181
assert out_file.shape == (10, 10, 10)
181182
assert np.allclose(out_file.get_fdata(), 1.0)
183+
184+
185+
def test_TemplateDimensions(tmp_path):
186+
"""Exercise the various types of inputs."""
187+
shapes = [
188+
(10, 10, 10),
189+
(11, 11, 11),
190+
]
191+
zooms = [
192+
(1, 1, 1),
193+
(0.9, 0.9, 0.9),
194+
]
195+
196+
for i, (shape, zoom) in enumerate(zip(shapes, zooms)):
197+
img = nb.Nifti1Image(np.ones(shape, dtype="float32"), np.eye(4))
198+
img.header.set_zooms(zoom)
199+
img.to_filename(tmp_path / f"test{i}.nii")
200+
201+
anat_list = [str(tmp_path / f"test{i}.nii") for i in range(2)]
202+
td = im.TemplateDimensions(anat_list=anat_list)
203+
res = td.run()
204+
205+
report = Path(res.outputs.out_report).read_text()
206+
assert "Input T1w images: 2" in report
207+
assert "Output dimensions: 11x11x11" in report
208+
assert "Output voxel size: 0.9mm x 0.9mm x 0.9mm" in report
209+
assert "Discarded images: 0" in report
210+
211+
assert res.outputs.t1w_valid_list == anat_list
212+
assert res.outputs.anat_valid_list == anat_list
213+
assert np.allclose(res.outputs.target_zooms, (0.9, 0.9, 0.9))
214+
assert res.outputs.target_shape == (11, 11, 11)
215+
216+
with pytest.warns(UserWarning, match="t1w_list .* is deprecated"):
217+
im.TemplateDimensions(t1w_list=anat_list)

0 commit comments

Comments
 (0)