Skip to content

Commit c92d560

Browse files
committed
enh(tests): add not-oblique test, move tests to test_affines.py
Addressing one of @matthew-brett's comments.
1 parent 3cfff0d commit c92d560

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

nibabel/affines.py

-8
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,6 @@ def obliquity(affine):
306306
This implementation is inspired by `AFNI's implementation
307307
<https://github.com/afni/afni/blob/b6a9f7a21c1f3231ff09efbd861f8975ad48e525/src/thd_coords.c#L660-L698>`_
308308
309-
>>> affine = np.array([
310-
... [2.74999725e+00, -2.74999817e-03, 2.74999954e-03, -7.69847980e+01],
311-
... [2.98603540e-03, 2.73886840e+00, -2.47165887e-01, -8.36692043e+01],
312-
... [-2.49170222e-03, 2.47168626e-01, 2.73886865e+00, -8.34056848e+01],
313-
... [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]])
314-
>>> abs(5.15699 - obliquity(affine)) < 0.0001
315-
True
316-
317309
"""
318310
vs = voxel_sizes(affine)
319311
fig_merit = (affine[:-1, :-1] / vs[np.newaxis, ...]).max(axis=1).min()

nibabel/tests/test_affines.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from ..eulerangles import euler2mat
99
from ..affines import (AffineError, apply_affine, append_diag, to_matvec,
10-
from_matvec, dot_reduce, voxel_sizes)
10+
from_matvec, dot_reduce, voxel_sizes, obliquity)
1111

1212

1313
from nose.tools import assert_equal, assert_raises
@@ -178,3 +178,13 @@ def test_voxel_sizes():
178178
rot_affine[:3, :3] = rotation
179179
full_aff = rot_affine.dot(aff)
180180
assert_almost_equal(voxel_sizes(full_aff), vox_sizes)
181+
182+
183+
def test_obliquity():
184+
"""Check the calculation of inclination of an affine axes."""
185+
aligned = np.diag([2.0, 2.0, 2.3, 1.0])
186+
aligned[:-1, -1] = [-10, -10, -7]
187+
R = from_matvec(euler2mat(x=0.09, y=0.001, z=0.001), [0.0, 0.0, 0.0])
188+
oblique = R.dot(aligned)
189+
assert_almost_equal(obliquity(aligned), 0.0)
190+
assert_almost_equal(obliquity(oblique), 5.1569948883)

0 commit comments

Comments
 (0)