From 9f93415e063a329b31a006c7aaf9a1bab07b8367 Mon Sep 17 00:00:00 2001 From: oesteban Date: Fri, 18 Oct 2019 11:30:58 -0700 Subject: [PATCH] ENH: Use ``obliquity`` directly from nibabel --- nitransforms/linear.py | 4 ++-- nitransforms/patched.py | 25 ------------------------- nitransforms/tests/test_affines.py | 16 ---------------- setup.cfg | 2 +- 4 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 nitransforms/tests/test_affines.py diff --git a/nitransforms/linear.py b/nitransforms/linear.py index 262b6ca4..b61578ea 100644 --- a/nitransforms/linear.py +++ b/nitransforms/linear.py @@ -13,9 +13,9 @@ from pathlib import Path from nibabel.loadsave import load as loadimg -from nibabel.affines import from_matvec, voxel_sizes +from nibabel.affines import from_matvec, voxel_sizes, obliquity from .base import TransformBase -from .patched import obliquity, shape_zoom_affine +from .patched import shape_zoom_affine LPS = np.diag([-1, -1, 1, 1]) diff --git a/nitransforms/patched.py b/nitransforms/patched.py index 41708b41..6e0b7ecb 100644 --- a/nitransforms/patched.py +++ b/nitransforms/patched.py @@ -1,29 +1,4 @@ import numpy as np -from nibabel.affines import voxel_sizes - - -def obliquity(affine): - r""" - Estimate the *obliquity* an affine's axes represent. - The term *obliquity* is defined here as the rotation of those axes with - respect to the cardinal axes. - This implementation is inspired by `AFNI's implementation - `_. - For further details about *obliquity*, check `AFNI's documentation - _. - Parameters - ---------- - affine : 2D array-like - Affine transformation array. Usually shape (4, 4), but can be any 2D - array. - Returns - ------- - angles : 1D array-like - The *obliquity* of each axis with respect to the cardinal axes, in radians. - """ - vs = voxel_sizes(affine) - best_cosines = np.abs((affine[:-1, :-1] / vs).max(axis=1)) - return np.arccos(best_cosines) def shape_zoom_affine(shape, zooms, x_flip=True, y_flip=False): diff --git a/nitransforms/tests/test_affines.py b/nitransforms/tests/test_affines.py deleted file mode 100644 index de9d77f3..00000000 --- a/nitransforms/tests/test_affines.py +++ /dev/null @@ -1,16 +0,0 @@ -import numpy as np -from nibabel.affines import from_matvec -from nibabel.eulerangles import euler2mat -from ..patched import obliquity - - -def test_obliquity(): - """Check the calculation of inclination of an affine axes.""" - from math import pi - 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) - np.testing.assert_almost_equal(obliquity(aligned), [0.0, 0.0, 0.0]) - np.testing.assert_almost_equal(obliquity(oblique) * 180 / pi, - [0.0810285, 5.1569949, 5.1569376]) diff --git a/setup.cfg b/setup.cfg index 5510e5c8..45b3b5cd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,7 @@ python_requires = >= 3.5 install_requires = numpy scipy - nibabel + nibabel @ git+https://github.com/nipy/nibabel@cd48bf05bc567387afe4504eda1da15324bb616f h5py test_requires = pytest