Skip to content

TST: add test for fix in PR 500 #502

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 2 commits into from
Jan 12, 2017
Merged
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
25 changes: 22 additions & 3 deletions nibabel/tests/test_orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
flip_axis, apply_orientation, OrientationError,
ornt2axcodes, axcodes2ornt, aff2axcodes)

from ..affines import from_matvec
from ..affines import from_matvec, to_matvec


IN_ARRS = [np.eye(4),
Expand Down Expand Up @@ -188,8 +188,8 @@ def test_io_orientation():
[1, 1],
[2, 1]])
eps = np.finfo(float).eps
# Test that a Y axis appears as we increase the difference between the first
# two columns
# Test that a Y axis appears as we increase the difference between the
# first two columns
for y_val, has_y in ((0, False),
(eps, False),
(eps * 5, False),
Expand All @@ -203,6 +203,25 @@ def test_io_orientation():
assert_array_equal(io_orientation(def_aff, tol=0), pass_tol)
def_aff[1, 1] = eps * 10
assert_array_equal(io_orientation(def_aff, tol=1e-5), fail_tol)
# Test drop of rows, columns
mat, vec = to_matvec(def_aff)
aff_extra_col = np.zeros((4, 5))
aff_extra_col[-1, -1] = 1 # Not strictly necessary, but for completeness
aff_extra_col[:3, :3] = mat
aff_extra_col[:3, -1] = vec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that supposed to be -1 with 5 columns? Or aff_extra_col[:3, 3]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Assuming I understand what's going on...)

For clarity, maybe an easier way to do this would be to have:

base_affine = np.zeros((4,4))
base_affine [:3, :3] = mat
base_affine[:3, -1] = vec

aff_extra_col[:4, :4] = base_affine
aff_extra_row[:4, :4] = base_affine

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both cases I was aiming for a 4th column / row with all zero, with the last column always being the translations, and non-zero. Is that what you thought?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no, I misunderstood. Carry on, then.

assert_array_equal(io_orientation(aff_extra_col, tol=1e-5),
[[0, 1],
[np.nan, np.nan],
[2, 1],
[np.nan, np.nan]])
aff_extra_row = np.zeros((5, 4))
aff_extra_row[-1, -1] = 1 # Not strictly necessary, but for completeness
aff_extra_row[:3, :3] = mat
aff_extra_row[:3, -1] = vec
assert_array_equal(io_orientation(aff_extra_row, tol=1e-5),
[[0, 1],
[np.nan, np.nan],
[2, 1]])


def test_ornt_transform():
Expand Down