Skip to content

Commit 57c3648

Browse files
author
Jakub Kaczmarzyk
committed
add tests for conform and _transform_range
1 parent 49e4ada commit 57c3648

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

nibabel/tests/test_processing.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
import nibabel as nib
2121
from nibabel.processing import (sigma2fwhm, fwhm2sigma, adapt_affine,
22-
resample_from_to, resample_to_output, smooth_image)
22+
resample_from_to, resample_to_output, smooth_image,
23+
_transform_range, conform)
2324
from nibabel.nifti1 import Nifti1Image
2425
from nibabel.nifti2 import Nifti2Image
25-
from nibabel.orientations import flip_axis, inv_ornt_aff
26+
from nibabel.orientations import aff2axcodes, flip_axis, inv_ornt_aff
2627
from nibabel.affines import (AffineError, from_matvec, to_matvec, apply_affine,
2728
voxel_sizes)
2829
from nibabel.eulerangles import euler2mat
@@ -426,3 +427,32 @@ def test_against_spm_resample():
426427
moved2output = resample_to_output(moved_anat, 4, order=1, cval=np.nan)
427428
spm2output = nib.load(pjoin(DATA_DIR, 'reoriented_anat_moved.nii'))
428429
assert_spm_resampling_close(moved_anat, moved2output, spm2output);
430+
431+
432+
def test__transform_range():
433+
assert_array_equal(_transform_range([2, 4, 6], -1, 1), [-1, 0, 1])
434+
assert_array_equal(_transform_range([-1, 0, 1], 2, 6), [2, 4, 6])
435+
assert_array_equal(_transform_range(np.arange(11), 0, 5),
436+
np.arange(0, 5.5, 0.5))
437+
assert_array_equal(_transform_range(np.arange(-100, 101), 0, 200),
438+
np.arange(201))
439+
440+
441+
def test_conform():
442+
anat = nib.load(pjoin(DATA_DIR, 'anatomical.nii'))
443+
444+
c = conform(anat)
445+
assert c.shape == (256, 256, 256)
446+
assert c.header.get_zooms() == (1, 1, 1)
447+
assert c.dataobj.dtype == np.dtype(np.uint8)
448+
assert aff2axcodes(c.affine) == ('R', 'A', 'S')
449+
450+
c = conform(anat, out_shape=(100, 100, 200), voxel_size=(2, 2, 1.5))
451+
assert c.shape == (100, 100, 200)
452+
assert c.header.get_zooms() == (2, 2, 1.5)
453+
assert c.dataobj.dtype == np.dtype(np.uint8)
454+
assert aff2axcodes(c.affine) == ('R', 'A', 'S')
455+
456+
# Error on non-3D images.
457+
func = nib.load(pjoin(DATA_DIR, 'functional.nii'))
458+
assert_raises(ValueError, conform, func)

0 commit comments

Comments
 (0)