Skip to content

Commit

Permalink
Merge pull request #18 from oesteban/pin/nibabel-master
Browse files Browse the repository at this point in the history
ENH: Use ``obliquity`` directly from nibabel
  • Loading branch information
mgxd authored Oct 18, 2019
2 parents 72a8264 + 9f93415 commit 9dfcfb9
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
4 changes: 2 additions & 2 deletions nitransforms/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
25 changes: 0 additions & 25 deletions nitransforms/patched.py
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/afni/afni/blob/b6a9f7a21c1f3231ff09efbd861f8975ad48e525/src/thd_coords.c#L660-L698>`_.
For further details about *obliquity*, check `AFNI's documentation
<https://sscc.nimh.nih.gov/sscc/dglen/Obliquity>_.
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):
Expand Down
16 changes: 0 additions & 16 deletions nitransforms/tests/test_affines.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9dfcfb9

Please sign in to comment.