8000 ENH: Add a utility to calculate obliquity of affines by oesteban · Pull Request #815 · nipy/nibabel · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add a utility to calculate obliquity of affines #815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enh(tests): add not-oblique test, move tests to test_affines.py
Addressing one of @matthew-brett's comments.
  • Loading branch information
oesteban committed Sep 20, 2019
commit c92d5609f37ac2ec18f94606b8bb3075759e27ea
8 changes: 0 additions & 8 deletions nibabel/affines.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,6 @@ def obliquity(affine):
This implementation is inspired by `AFNI's implementation
<https://github.com/afni/afni/blob/b6a9f7a21c1f3231ff09efbd861f8975ad48e525/src/thd_coords.c#L660-L698>`_

>>> affine = np.array([
... [2.74999725e+00, -2.74999817e-03, 2.74999954e-03, -7.69847980e+01],
... [2.98603540e-03, 2.73886840e+00, -2.47165887e-01, -8.36692043e+01],
... [-2.49170222e-03, 2.47168626e-01, 2.73886865e+00, -8.34056848e+01],
... [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]])
>>> abs(5.15699 - obliquity(affine)) < 0.0001
True

"""
vs = voxel_sizes(affine)
fig_merit = (affine[:-1, :-1] / vs[np.newaxis, ...]).max(axis=1).min()
Expand Down
12 changes: 11 additions & 1 deletion nibabel/tests/test_affines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..eulerangles import euler2mat
from ..affines import (AffineError, apply_affine, append_diag, to_matvec,
from_matvec, dot_reduce, voxel_sizes)
from_matvec, dot_reduce, voxel_sizes, obliquity)


from nose.tools import assert_equal, assert_raises
Expand Down Expand Up @@ -178,3 +178,13 @@ def test_voxel_sizes():
rot_affine[:3, :3] = rotation
full_aff = rot_affine.dot(aff)
assert_almost_equal(voxel_sizes(full_aff), vox_sizes)


def test_obliquity():
"""Check the calculation of inclination of an affine axes."""
aligned = np.diag([2.0, 2.0, 2.3, 1.0])
aligned[:-1, -1] = [-10, -10, -7]
R = from_matvec(euler2mat(x=0.09, y=0.001, z=0.001), [0.0, 0.0, 0.0])
oblique = R.dot(aligned)
assert_almost_equal(obliquity(aligned), 0.0)
assert_almost_equal(obliquity(oblique), 5.1569948883)
0