9
9
10
10
from .. import load as top_load
11
11
from ..parrec import load
12
+ from ..affines import voxel_sizes
12
13
13
14
from .nibabel_data import get_nibabel_data , needs_nibabel_data
14
15
19
20
from numpy .testing import assert_almost_equal
20
21
21
22
BALLS = pjoin (get_nibabel_data (), 'nitest-balls1' )
23
+ OBLIQUE = pjoin (get_nibabel_data (), 'parrec_oblique' )
22
24
23
25
# Amount by which affine translation differs from NIFTI conversion
24
- AFF_OFF = [- 0.93644031 , - 0.95572686 , 0.03288748 ]
26
+ AFF_OFF = [- 0.93575081 , - 0.95657335 , 0.03264122 ]
25
27
26
28
27
29
@needs_nibabel_data ('nitest-balls1' )
@@ -45,8 +47,8 @@ def test_loading():
45
47
aff_off = pimg .affine [:3 , 3 ] - nimg .affine [:3 , 3 ]
46
48
assert_almost_equal (aff_off , AFF_OFF , 4 )
47
49
# The difference is max in the order of 0.5 voxel
48
- vox_sizes = np . sqrt (( nimg .affine [: 3 , : 3 ] ** 2 ). sum ( axis = 0 ) )
49
- assert_true (np .all (np .abs (aff_off / vox_sizes ) <= 0.5 ))
50
+ vox_sizes = voxel_sizes ( nimg .affine )
51
+ assert_true (np .all (np .abs (aff_off / vox_sizes ) <= 0.501 ))
50
52
# The data is very close, unless it's the fieldmap
51
53
if par_root != 'fieldmap' :
52
54
assert_true (np .allclose (pimg .dataobj , nimg .dataobj ))
@@ -63,3 +65,25 @@ def test_fieldmap():
63
65
load (fieldmap_par )
64
66
top_load (fieldmap_nii )
65
67
raise SkipTest ('Fieldmap remains puzzling' )
68
+
69
+
70
+ @needs_nibabel_data ('parrec_oblique' )
71
+ def test_oblique_loading ():
72
+ # Test loading of oblique parrec files
73
+ for par in glob (pjoin (OBLIQUE , 'PARREC' , '*.PAR' )):
74
+ par_root , ext = splitext (basename (par ))
75
+ # Check we can load the image
76
+ pimg = load (par )
77
+ assert_equal (pimg .shape , (560 , 560 , 1 ))
78
+ # Compare against NIFTI if present
79
+ nifti_fname = pjoin (OBLIQUE , 'NIFTI' , par_root + '.nii' )
80
+ nimg = top_load (nifti_fname )
81
+ assert_almost_equal (nimg .affine [:3 , :3 ], pimg .affine [:3 , :3 ], 3 )
82
+ # The translation part is always off
83
+ # The ammount differs by rotation
84
+ aff_off = pimg .affine [:3 , 3 ] - nimg .affine [:3 , 3 ]
85
+ # The difference is max in the order of 0.5 voxel
86
+ vox_sizes = voxel_sizes (nimg .affine )
87
+ assert_true (np .all (np .abs (aff_off / vox_sizes ) <= 0.5 ))
88
+ # The data is very close
89
+ assert_true (np .allclose (pimg .dataobj , nimg .dataobj ))
0 commit comments