Skip to content
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

ENH: Use obliquity directly from nibabel #18

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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