Skip to content

Commit b72c49d

Browse files
committed
RF: rename orientation_affine to inv_ornt_aff
The original name was very confusing. Add deprecation warning attached to old name.
1 parent e5c7ac4 commit b72c49d

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

nibabel/funcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
''' Processor functions for images '''
1111
import numpy as np
1212

13-
from .orientations import (io_orientation, orientation_affine, flip_axis,
13+
from .orientations import (io_orientation, inv_ornt_aff, flip_axis,
1414
apply_orientation, OrientationError)
1515
from .loadsave import load
1616

@@ -189,7 +189,7 @@ def as_closest_canonical(img, enforce_diag=False):
189189
raise OrientationError('Transformed affine is not diagonal')
190190
return img
191191
shape = img.shape
192-
t_aff = orientation_affine(ornt, shape)
192+
t_aff = inv_ornt_aff(ornt, shape)
193193
out_aff = np.dot(aff, t_aff)
194194
# check if we are going to end up with something diagonal
195195
if enforce_diag and not _aff_is_diag(aff):

nibabel/orientations.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def apply_orientation(arr, ornt):
131131
return t_arr
132132

133133

134-
def orientation_affine(ornt, shape):
134+
def inv_ornt_aff(ornt, shape):
135135
''' Affine transform reversing transforms implied in `ornt`
136136
137137
Imagine you have an array ``arr`` of shape `shape`, and you apply the
@@ -155,7 +155,7 @@ def orientation_affine(ornt, shape):
155155
156156
Returns
157157
-------
158-
transformed_affine : (p + 1, p + 1) ndarray
158+
transform_affine : (p + 1, p + 1) ndarray
159159
An array ``arr`` (shape `shape`) might be transformed according to
160160
`ornt`, resulting in a transformed array ``tarr``. `transformed_affine`
161161
is the transform that takes you from array coordinates in ``tarr`` to
@@ -186,6 +186,11 @@ def orientation_affine(ornt, shape):
186186
return np.dot(undo_flip, undo_reorder)
187187

188188

189+
@np.deprecate_with_doc("Please use inv_ornt_aff instead")
190+
def orientation_affine(ornt, shape):
191+
return inv_ornt_aff(ornt, shape)
192+
193+
189194
def flip_axis(arr, axis=0):
190195
''' Flip contents of `axis` in array `arr`
191196

nibabel/tests/test_orientations.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from numpy.testing import assert_array_equal, assert_array_almost_equal
1616

17-
from ..orientations import (io_orientation, orientation_affine, flip_axis,
17+
from ..orientations import (io_orientation, inv_ornt_aff, flip_axis,
1818
apply_orientation, OrientationError, ornt2axcodes,
1919
aff2axcodes)
2020

@@ -152,7 +152,7 @@ def test_io_orientation():
152152
for in_arr, out_ornt in zip(IN_ARRS, OUT_ORNTS):
153153
ornt = io_orientation(in_arr)
154154
assert_array_equal(ornt, out_ornt)
155-
taff = orientation_affine(ornt, shape)
155+
taff = inv_ornt_aff(ornt, shape)
156156
assert_true(same_transform(taff, ornt, shape))
157157
for axno in range(3):
158158
arr = in_arr.copy()
@@ -163,7 +163,7 @@ def test_io_orientation():
163163
ex_ornt[axno, 1] *= -1
164164
ornt = io_orientation(arr)
165165
assert_array_equal(ornt, ex_ornt)
166-
taff = orientation_affine(ornt, shape)
166+
taff = inv_ornt_aff(ornt, shape)
167167
assert_true(same_transform(taff, ornt, shape))
168168
# Test nasty hang for zero columns
169169
rzs = np.c_[np.diag([2, 3, 4, 5]), np.zeros((4,3))]
@@ -217,8 +217,8 @@ def test_aff2axcodes():
217217
('B', 'R', 'U'))
218218

219219

220-
def test_orientation_affine():
221-
# Extra tests for orientation_affine routines (also tested in
220+
def test_inv_ornt_aff():
221+
# Extra tests for inv_ornt_aff routines (also tested in
222222
# io_orientations test)
223-
assert_raises(OrientationError, orientation_affine,
223+
assert_raises(OrientationError, inv_ornt_aff,
224224
[[0, 1], [1, -1], [np.nan, np.nan]], (3, 4, 5))

0 commit comments

Comments
 (0)