|
22 | 22 | # |
23 | 23 | """Test images module.""" |
24 | 24 | import time |
| 25 | +from pathlib import Path |
25 | 26 | import numpy as np |
26 | 27 | import nibabel as nb |
27 | 28 | from nipype.pipeline import engine as pe |
@@ -179,3 +180,38 @@ def test_RobustAverage(tmpdir, shape): |
179 | 180 |
|
180 | 181 | assert out_file.shape == (10, 10, 10) |
181 | 182 | 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