Skip to content
Snippets Groups Projects
Commit f6111f9f authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

TEST: Fix imports

parent b53db87d
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ import tests ...@@ -20,7 +20,7 @@ import tests
import fsl.utils.image.resample as resample import fsl.utils.image.resample as resample
import fsl.data.atlases as atlases import fsl.data.atlases as atlases
import fsl.data.image as fslimage import fsl.data.image as fslimage
import fsl.transform as transform import fsl.transform.affine as affine
datadir = op.join(op.dirname(__file__), 'testdata') datadir = op.join(op.dirname(__file__), 'testdata')
...@@ -326,7 +326,7 @@ def test_prepareMask(): ...@@ -326,7 +326,7 @@ def test_prepareMask():
np.random.random(list(ashape) + [2])) np.random.random(list(ashape) + [2]))
wrongspace = fslimage.Image( wrongspace = fslimage.Image(
np.random.random((20, 20, 20)), np.random.random((20, 20, 20)),
xform=transform.concat(atlas.voxToWorldMat, np.diag([2, 2, 2, 1]))) xform=affine.concat(atlas.voxToWorldMat, np.diag([2, 2, 2, 1])))
with pytest.raises(atlases.MaskError): with pytest.raises(atlases.MaskError):
atlas.prepareMask(wrongdims) atlas.prepareMask(wrongdims)
......
...@@ -13,7 +13,7 @@ import pytest ...@@ -13,7 +13,7 @@ import pytest
import fsl.data.atlases as fslatlases import fsl.data.atlases as fslatlases
import fsl.data.image as fslimage import fsl.data.image as fslimage
import fsl.transform as transform import fsl.transform.affine as affine
import fsl.utils.image.resample as resample import fsl.utils.image.resample as resample
import fsl.utils.cache as cache import fsl.utils.cache as cache
...@@ -155,7 +155,7 @@ def _gen_coord_voxel_query(atlas, qtype, qin, **kwargs): ...@@ -155,7 +155,7 @@ def _gen_coord_voxel_query(atlas, qtype, qin, **kwargs):
dlo = (0, 0, 0) dlo = (0, 0, 0)
dhi = atlas.shape dhi = atlas.shape
else: else:
dlo, dhi = transform.axisBounds(atlas.shape, atlas.voxToWorldMat) dlo, dhi = affine.axisBounds(atlas.shape, atlas.voxToWorldMat)
dlen = [hi - lo for lo, hi in zip(dlo, dhi)] dlen = [hi - lo for lo, hi in zip(dlo, dhi)]
...@@ -190,7 +190,7 @@ def _gen_coord_voxel_query(atlas, qtype, qin, **kwargs): ...@@ -190,7 +190,7 @@ def _gen_coord_voxel_query(atlas, qtype, qin, **kwargs):
coords = np.array(coords, dtype=dtype) coords = np.array(coords, dtype=dtype)
if not voxel: if not voxel:
coords = transform.transform(coords, atlas.voxToWorldMat) coords = affine.transform(coords, atlas.voxToWorldMat)
return tuple([dtype(c) for c in coords]) return tuple([dtype(c) for c in coords])
...@@ -200,7 +200,7 @@ def _eval_coord_voxel_query(atlas, query, qtype, qin): ...@@ -200,7 +200,7 @@ def _eval_coord_voxel_query(atlas, query, qtype, qin):
voxel = qtype == 'voxel' voxel = qtype == 'voxel'
if voxel: vx, vy, vz = query if voxel: vx, vy, vz = query
else: vx, vy, vz = transform.transform(query, atlas.worldToVoxMat) else: vx, vy, vz = affine.transform(query, atlas.worldToVoxMat)
vx, vy, vz = [int(round(v)) for v in [vx, vy, vz]] vx, vy, vz = [int(round(v)) for v in [vx, vy, vz]]
......
...@@ -19,10 +19,10 @@ import nibabel as nib ...@@ -19,10 +19,10 @@ import nibabel as nib
from nibabel.spatialimages import ImageFileError from nibabel.spatialimages import ImageFileError
import fsl.data.constants as constants import fsl.data.constants as constants
import fsl.data.image as fslimage import fsl.data.image as fslimage
import fsl.utils.path as fslpath import fsl.utils.path as fslpath
import fsl.transform as transform import fsl.transform.affine as affine
from fsl.utils.tempdir import tempdir from fsl.utils.tempdir import tempdir
...@@ -1113,12 +1113,12 @@ def _test_Image_init_xform(imgtype): ...@@ -1113,12 +1113,12 @@ def _test_Image_init_xform(imgtype):
with tempdir() as td: with tempdir() as td:
sform = transform.compose(np.random.random(3), sform = affine.compose(np.random.random(3),
np.random.random(3), np.random.random(3),
np.random.random(3)) np.random.random(3))
qform = transform.compose(np.random.random(3), qform = affine.compose(np.random.random(3),
np.random.random(3), np.random.random(3),
np.random.random(3)) np.random.random(3))
sform_code = 3 sform_code = 3
qform_code = 4 qform_code = 4
...@@ -1169,9 +1169,9 @@ def _test_Image_init_xform(imgtype): ...@@ -1169,9 +1169,9 @@ def _test_Image_init_xform(imgtype):
# to the xform. and its # to the xform. and its
# s/q form codes the same # s/q form codes the same
# as what is in the header # as what is in the header
rxform = transform.compose(np.random.random(3), rxform = affine.compose(np.random.random(3),
np.random.random(3), np.random.random(3),
np.random.random(3)) np.random.random(3))
fimg = fslimage.Image(img.get_data(), fimg = fslimage.Image(img.get_data(),
header=img.header, header=img.header,
xform=rxform) xform=rxform)
...@@ -1281,12 +1281,12 @@ def test_determineAffine(): ...@@ -1281,12 +1281,12 @@ def test_determineAffine():
for sformcode, qformcode, intent, exp in tests: for sformcode, qformcode, intent, exp in tests:
sform = transform.compose(np.random.random(3), sform = affine.compose(np.random.random(3),
np.random.random(3), np.random.random(3),
np.random.random(3)) np.random.random(3))
qform = transform.compose(np.random.random(3), qform = affine.compose(np.random.random(3),
np.random.random(3), np.random.random(3),
np.random.random(3)) np.random.random(3))
pixdims = np.random.randint(1, 10, 3) pixdims = np.random.randint(1, 10, 3)
hdr = nib.Nifti1Header() hdr = nib.Nifti1Header()
...@@ -1306,16 +1306,16 @@ def test_determineAffine(): ...@@ -1306,16 +1306,16 @@ def test_determineAffine():
if exp == 'sform': exp = sform if exp == 'sform': exp = sform
elif exp == 'qform': exp = qform elif exp == 'qform': exp = qform
elif exp == 'scaling': exp = transform.scaleOffsetXform(pixdims, 0) elif exp == 'scaling': exp = affine.scaleOffsetXform(pixdims, 0)
assert np.all(np.isclose(got, exp)) assert np.all(np.isclose(got, exp))
def test_generateAffines(): def test_generateAffines():
v2w = transform.compose(np.random.random(3), v2w = affine.compose(np.random.random(3),
np.random.random(3), np.random.random(3),
np.random.random(3)) np.random.random(3))
shape = (10, 10, 10) shape = (10, 10, 10)
pixdim = (1, 1, 1) pixdim = (1, 1, 1)
...@@ -1331,10 +1331,10 @@ def test_generateAffines(): ...@@ -1331,10 +1331,10 @@ def test_generateAffines():
f2w = v2w f2w = v2w
w2f = w2v w2f = w2v
else: else:
v2f = transform.scaleOffsetXform([-1, 1, 1], [9, 0, 0]) v2f = affine.scaleOffsetXform([-1, 1, 1], [9, 0, 0])
f2v = npla.inv(v2f) f2v = npla.inv(v2f)
f2w = transform.concat(v2w, f2v) f2w = affine.concat(v2w, f2v)
w2f = transform.concat(v2f, w2v) w2f = affine.concat(v2f, w2v)
assert np.all(np.isclose(v2w, got['voxel', 'world'])) assert np.all(np.isclose(v2w, got['voxel', 'world']))
assert np.all(np.isclose(w2v, got['world', 'voxel'])) assert np.all(np.isclose(w2v, got['world', 'voxel']))
......
...@@ -11,8 +11,8 @@ import numpy as np ...@@ -11,8 +11,8 @@ import numpy as np
from unittest import mock from unittest import mock
import pytest import pytest
import fsl.transform as transform import fsl.transform.affine as affine
import fsl.data.mesh as fslmesh import fsl.data.mesh as fslmesh
from . import tempdir from . import tempdir
...@@ -58,7 +58,7 @@ CUBE_CCW_VERTEX_NORMALS = np.zeros((8, 3)) ...@@ -58,7 +58,7 @@ CUBE_CCW_VERTEX_NORMALS = np.zeros((8, 3))
for i in range(8): for i in range(8):
faces = np.where(CUBE_TRIANGLES_CCW == i)[0] faces = np.where(CUBE_TRIANGLES_CCW == i)[0]
CUBE_CCW_VERTEX_NORMALS[i] = CUBE_CCW_FACE_NORMALS[faces].sum(axis=0) CUBE_CCW_VERTEX_NORMALS[i] = CUBE_CCW_FACE_NORMALS[faces].sum(axis=0)
CUBE_CCW_VERTEX_NORMALS = transform.normalise(CUBE_CCW_VERTEX_NORMALS) CUBE_CCW_VERTEX_NORMALS = affine.normalise(CUBE_CCW_VERTEX_NORMALS)
def test_mesh_create(): def test_mesh_create():
......
...@@ -12,10 +12,10 @@ import shutil ...@@ -12,10 +12,10 @@ import shutil
import numpy as np import numpy as np
import nibabel as nib import nibabel as nib
import fsl.utils.tempdir as tempdir import fsl.utils.tempdir as tempdir
import fsl.transform as transform import fsl.transform.affine as affine
import fsl.data.mghimage as fslmgh import fsl.data.mghimage as fslmgh
import fsl.data.image as fslimage import fsl.data.image as fslimage
datadir = op.join(op.abspath(op.dirname(__file__)), 'testdata') datadir = op.join(op.abspath(op.dirname(__file__)), 'testdata')
...@@ -29,14 +29,14 @@ def test_MGHImage(): ...@@ -29,14 +29,14 @@ def test_MGHImage():
img = fslmgh.MGHImage(testfile) img = fslmgh.MGHImage(testfile)
nbimg = nib.load(testfile) nbimg = nib.load(testfile)
v2s = nbimg.header.get_vox2ras_tkr() v2s = nbimg.header.get_vox2ras_tkr()
w2s = transform.concat(v2s, transform.invert(nbimg.affine)) w2s = affine.concat(v2s, affine.invert(nbimg.affine))
assert np.all(np.isclose(img[:], nbimg.get_data())) assert np.all(np.isclose(img[:], nbimg.get_data()))
assert np.all(np.isclose(img.voxToWorldMat, nbimg.affine)) assert np.all(np.isclose(img.voxToWorldMat, nbimg.affine))
assert np.all(np.isclose(img.voxToSurfMat, v2s)) assert np.all(np.isclose(img.voxToSurfMat, v2s))
assert np.all(np.isclose(img.surfToVoxMat, transform.invert(v2s))) assert np.all(np.isclose(img.surfToVoxMat, affine.invert(v2s)))
assert np.all(np.isclose(img.worldToSurfMat, w2s)) assert np.all(np.isclose(img.worldToSurfMat, w2s))
assert np.all(np.isclose(img.surfToWorldMat, transform.invert(w2s))) assert np.all(np.isclose(img.surfToWorldMat, affine.invert(w2s)))
assert img.name == op.basename(testfile) assert img.name == op.basename(testfile)
assert img.dataSource == testfile assert img.dataSource == testfile
......
...@@ -15,7 +15,7 @@ import scipy.ndimage as ndi ...@@ -15,7 +15,7 @@ import scipy.ndimage as ndi
import pytest import pytest
import fsl.transform as transform import fsl.transform.affine as affine
import fsl.data.atlases as fslatlases import fsl.data.atlases as fslatlases
import fsl.utils.image.resample as resample import fsl.utils.image.resample as resample
import fsl.data.image as fslimage import fsl.data.image as fslimage
...@@ -152,7 +152,7 @@ def _gen_coord_voxel_query(atlas, use_label, q_type, q_in, res): ...@@ -152,7 +152,7 @@ def _gen_coord_voxel_query(atlas, use_label, q_type, q_in, res):
dlo = (0, 0, 0) dlo = (0, 0, 0)
dhi = a_img.shape dhi = a_img.shape
else: else:
dlo, dhi = transform.axisBounds(a_img.shape, a_img.voxToWorldMat) dlo, dhi = affine.axisBounds(a_img.shape, a_img.voxToWorldMat)
dlen = [hi - lo for lo, hi in zip(dlo, dhi)] dlen = [hi - lo for lo, hi in zip(dlo, dhi)]
...@@ -187,7 +187,7 @@ def _gen_coord_voxel_query(atlas, use_label, q_type, q_in, res): ...@@ -187,7 +187,7 @@ def _gen_coord_voxel_query(atlas, use_label, q_type, q_in, res):
coords = np.array(coords, dtype=dtype) coords = np.array(coords, dtype=dtype)
if not voxel: if not voxel:
coords = transform.transform(coords, a_img.voxToWorldMat) coords = affine.transform(coords, a_img.voxToWorldMat)
return tuple([dtype(c) for c in coords]) return tuple([dtype(c) for c in coords])
...@@ -453,8 +453,8 @@ def test_bad_mask(seed): ...@@ -453,8 +453,8 @@ def test_bad_mask(seed):
dtype=np.float32)) dtype=np.float32))
wrongspace = fslimage.Image( wrongspace = fslimage.Image(
np.random.random((20, 20, 20)), np.random.random((20, 20, 20)),
xform=transform.concat(atlas.voxToWorldMat, xform=affine.concat(atlas.voxToWorldMat,
np.diag([2, 2, 2, 1]))) np.diag([2, 2, 2, 1])))
print(wrongdims.shape) print(wrongdims.shape)
print(wrongspace.shape) print(wrongspace.shape)
......
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
import numpy as np import numpy as np
import fsl.utils.tempdir as tempdir import fsl.utils.tempdir as tempdir
import fsl.transform as transform import fsl.transform.affine as affine
import fsl.data.image as fslimage import fsl.transform.flirt as flirt
import fsl.transform.x5 as x5
import fsl.data.image as fslimage
import fsl.scripts.fsl_convert_x5 as fsl_convert_x5 import fsl.scripts.fsl_convert_x5 as fsl_convert_x5
...@@ -14,7 +16,7 @@ def random_image(): ...@@ -14,7 +16,7 @@ def random_image():
vx, vy, vz = np.random.randint(10, 50, 3) vx, vy, vz = np.random.randint(10, 50, 3)
dx, dy, dz = np.random.randint( 1, 10, 3) dx, dy, dz = np.random.randint( 1, 10, 3)
data = (np.random.random((vx, vy, vz)) - 0.5) * 10 data = (np.random.random((vx, vy, vz)) - 0.5) * 10
aff = transform.compose( aff = affine.compose(
(dx, dy, dz), (dx, dy, dz),
np.random.randint(1, 100, 3), np.random.randint(1, 100, 3),
np.random.random(3) * np.pi / 2) np.random.random(3) * np.pi / 2)
...@@ -30,7 +32,7 @@ def test_convert_flirt(): ...@@ -30,7 +32,7 @@ def test_convert_flirt():
src.save('src') src.save('src')
ref.save('ref') ref.save('ref')
xform = transform.compose( xform = affine.compose(
np.random.randint(1, 10, 3), np.random.randint(1, 10, 3),
np.random.randint(-100, 100, 3), np.random.randint(-100, 100, 3),
(np.random.random(3) - 0.5) * np.pi) (np.random.random(3) - 0.5) * np.pi)
...@@ -39,11 +41,11 @@ def test_convert_flirt(): ...@@ -39,11 +41,11 @@ def test_convert_flirt():
fsl_convert_x5.main('flirt -s src -r ref ' fsl_convert_x5.main('flirt -s src -r ref '
'src2ref.mat src2ref.x5'.split()) 'src2ref.mat src2ref.x5'.split())
expxform = transform.concat( expxform = affine.concat(
ref.getAffine('fsl', 'world'), ref.getAffine('fsl', 'world'),
xform, xform,
src.getAffine('world', 'fsl')) src.getAffine('world', 'fsl'))
gotxform, gotsrc, gotref = transform.readLinearX5('src2ref.x5') gotxform, gotsrc, gotref = x5.readLinearX5('src2ref.x5')
assert np.all(np.isclose(gotxform, expxform)) assert np.all(np.isclose(gotxform, expxform))
assert src.sameSpace(gotsrc) assert src.sameSpace(gotsrc)
assert ref.sameSpace(gotref) assert ref.sameSpace(gotref)
...@@ -51,5 +53,5 @@ def test_convert_flirt(): ...@@ -51,5 +53,5 @@ def test_convert_flirt():
fsl_convert_x5.main('flirt -s src -r ref src2ref.x5 ' fsl_convert_x5.main('flirt -s src -r ref src2ref.x5 '
'src2ref_copy.mat'.split()) 'src2ref_copy.mat'.split())
gotxform = transform.readFlirt('src2ref_copy.mat') gotxform = flirt.readFlirt('src2ref_copy.mat')
assert np.all(np.isclose(gotxform, xform)) assert np.all(np.isclose(gotxform, xform))
...@@ -19,7 +19,7 @@ import six ...@@ -19,7 +19,7 @@ import six
import pytest import pytest
import fsl.transform as transform import fsl.transform.affine as affine
datadir = op.join(op.dirname(__file__), 'testdata') datadir = op.join(op.dirname(__file__), 'testdata')
...@@ -56,7 +56,7 @@ def test_invert(): ...@@ -56,7 +56,7 @@ def test_invert():
x = testdata[i * 4:i * 4 + 4, 0:4] x = testdata[i * 4:i * 4 + 4, 0:4]
invx = testdata[i * 4:i * 4 + 4, 4:8] invx = testdata[i * 4:i * 4 + 4, 4:8]
result = transform.invert(x) result = affine.invert(x)
assert np.all(np.isclose(invx, result)) assert np.all(np.isclose(invx, result))
...@@ -86,7 +86,7 @@ def test_concat(): ...@@ -86,7 +86,7 @@ def test_concat():
for inputs, expected in tests: for inputs, expected in tests:
result = transform.concat(*inputs) result = affine.concat(*inputs)
assert np.all(np.isclose(result, expected)) assert np.all(np.isclose(result, expected))
...@@ -108,10 +108,10 @@ def test_veclength(seed): ...@@ -108,10 +108,10 @@ def test_veclength(seed):
vtype = random.choice((list, tuple, np.array)) vtype = random.choice((list, tuple, np.array))
v = vtype(v) v = vtype(v)
assert np.isclose(transform.veclength(v), l(v)) assert np.isclose(affine.veclength(v), l(v))
# Multiple vectors in parallel # Multiple vectors in parallel
result = transform.veclength(vectors) result = affine.veclength(vectors)
expected = l(vectors) expected = l(vectors)
assert np.all(np.isclose(result, expected)) assert np.all(np.isclose(result, expected))
...@@ -121,8 +121,8 @@ def test_normalise(seed): ...@@ -121,8 +121,8 @@ def test_normalise(seed):
vectors = -100 + 200 * np.random.random((200, 3)) vectors = -100 + 200 * np.random.random((200, 3))
def parallel(v1, v2): def parallel(v1, v2):
v1 = v1 / transform.veclength(v1) v1 = v1 / affine.veclength(v1)
v2 = v2 / transform.veclength(v2) v2 = v2 / affine.veclength(v2)
return np.isclose(np.dot(v1, v2), 1) return np.isclose(np.dot(v1, v2), 1)
...@@ -130,16 +130,16 @@ def test_normalise(seed): ...@@ -130,16 +130,16 @@ def test_normalise(seed):
vtype = random.choice((list, tuple, np.array)) vtype = random.choice((list, tuple, np.array))
v = vtype(v) v = vtype(v)
vn = transform.normalise(v) vn = affine.normalise(v)
vl = transform.veclength(vn) vl = affine.veclength(vn)
assert np.isclose(vl, 1.0) assert np.isclose(vl, 1.0)
assert parallel(v, vn) assert parallel(v, vn)
# normalise should also be able # normalise should also be able
# to do multiple vectors at once # to do multiple vectors at once
results = transform.normalise(vectors) results = affine.normalise(vectors)
lengths = transform.veclength(results) lengths = affine.veclength(results)
pars = np.zeros(200) pars = np.zeros(200)
for i in range(200): for i in range(200):
...@@ -171,7 +171,7 @@ def test_scaleOffsetXform(): ...@@ -171,7 +171,7 @@ def test_scaleOffsetXform():
expected = [[float(v) for v in l.split()] for l in expected] expected = [[float(v) for v in l.split()] for l in expected]
expected = np.array(expected) expected = np.array(expected)
result = transform.scaleOffsetXform(scales, offsets) result = affine.scaleOffsetXform(scales, offsets)
assert np.all(np.isclose(result, expected)) assert np.all(np.isclose(result, expected))
...@@ -207,11 +207,11 @@ def test_scaleOffsetXform(): ...@@ -207,11 +207,11 @@ def test_scaleOffsetXform():
for (scale, expected) in stests: for (scale, expected) in stests:
expected = np.array(expected).reshape(4, 4) expected = np.array(expected).reshape(4, 4)
result = transform.scaleOffsetXform(scale, 0) result = affine.scaleOffsetXform(scale, 0)
assert np.all(np.isclose(result, expected)) assert np.all(np.isclose(result, expected))
for (offset, expected) in otests: for (offset, expected) in otests:
expected = np.array(expected).reshape(4, 4) expected = np.array(expected).reshape(4, 4)
result = transform.scaleOffsetXform(1, offset) result = affine.scaleOffsetXform(1, offset)
assert np.all(np.isclose(result, expected)) assert np.all(np.isclose(result, expected))
...@@ -226,8 +226,8 @@ def test_compose_and_decompose(): ...@@ -226,8 +226,8 @@ def test_compose_and_decompose():
xform = lines[i * 4: i * 4 + 4] xform = lines[i * 4: i * 4 + 4]
xform = np.genfromtxt(xform) xform = np.genfromtxt(xform)
scales, offsets, rotations = transform.decompose(xform) scales, offsets, rotations = affine.decompose(xform)
result = transform.compose(scales, offsets, rotations) result = affine.compose(scales, offsets, rotations)
assert np.all(np.isclose(xform, result, atol=1e-5)) assert np.all(np.isclose(xform, result, atol=1e-5))
...@@ -235,22 +235,22 @@ def test_compose_and_decompose(): ...@@ -235,22 +235,22 @@ def test_compose_and_decompose():
# different rotation origin, but we test # different rotation origin, but we test
# explicitly passing the origin for # explicitly passing the origin for
# completeness # completeness
scales, offsets, rotations = transform.decompose(xform) scales, offsets, rotations = affine.decompose(xform)
result = transform.compose(scales, offsets, rotations, [0, 0, 0]) result = affine.compose(scales, offsets, rotations, [0, 0, 0])
assert np.all(np.isclose(xform, result, atol=1e-5)) assert np.all(np.isclose(xform, result, atol=1e-5))
# compose should also accept a rotation matrix # compose should also accept a rotation matrix
rots = [np.pi / 5, np.pi / 4, np.pi / 3] rots = [np.pi / 5, np.pi / 4, np.pi / 3]
rmat = transform.axisAnglesToRotMat(*rots) rmat = affine.axisAnglesToRotMat(*rots)
xform = transform.compose([1, 1, 1], [0, 0, 0], rmat) xform = affine.compose([1, 1, 1], [0, 0, 0], rmat)
# And the angles flag should cause decompose # And the angles flag should cause decompose
# to return the rotation matrix, instead of # to return the rotation matrix, instead of
# the axis angls # the axis angls
sc, of, rot = transform.decompose(xform) sc, of, rot = affine.decompose(xform)
scat, ofat, rotat = transform.decompose(xform, angles=True) scat, ofat, rotat = affine.decompose(xform, angles=True)
scaf, ofaf, rotaf = transform.decompose(xform, angles=False) scaf, ofaf, rotaf = affine.decompose(xform, angles=False)
sc, of, rot = np.array(sc), np.array(of), np.array(rot) sc, of, rot = np.array(sc), np.array(of), np.array(rot)
scat, ofat, rotat = np.array(scat), np.array(ofat), np.array(rotat) scat, ofat, rotat = np.array(scat), np.array(ofat), np.array(rotat)
...@@ -269,8 +269,8 @@ def test_compose_and_decompose(): ...@@ -269,8 +269,8 @@ def test_compose_and_decompose():
# decompose should accept a 3x3 # decompose should accept a 3x3
# affine, and return translations of 0 # affine, and return translations of 0
transform.decompose(xform[:3, :3]) affine.decompose(xform[:3, :3])
sc, of, rot = transform.decompose(xform[:3, :3]) sc, of, rot = affine.decompose(xform[:3, :3])
sc, of, rot = np.array(sc), np.array(of), np.array(rot) sc, of, rot = np.array(sc), np.array(of), np.array(rot)
assert np.all(np.isclose(sc, [1, 1, 1])) assert np.all(np.isclose(sc, [1, 1, 1]))
assert np.all(np.isclose(of, [0, 0, 0])) assert np.all(np.isclose(of, [0, 0, 0]))
...@@ -290,8 +290,8 @@ def test_rotMatToAxisAngles(seed): ...@@ -290,8 +290,8 @@ def test_rotMatToAxisAngles(seed):
-pi2 + 2 * pi2 * np.random.random(), -pi2 + 2 * pi2 * np.random.random(),
-pi + 2 * pi * np.random.random()] -pi + 2 * pi * np.random.random()]
rmat = transform.axisAnglesToRotMat(*rots) rmat = affine.axisAnglesToRotMat(*rots)
gotrots = transform.rotMatToAxisAngles(rmat) gotrots = affine.rotMatToAxisAngles(rmat)
assert np.all(np.isclose(rots, gotrots)) assert np.all(np.isclose(rots, gotrots))
...@@ -310,9 +310,9 @@ def test_rotMatToAffine(seed): ...@@ -310,9 +310,9 @@ def test_rotMatToAffine(seed):
if np.random.random() < 0.5: origin = None if np.random.random() < 0.5: origin = None
else: origin = np.random.random(3) else: origin = np.random.random(3)
rmat = transform.axisAnglesToRotMat(*rots) rmat = affine.axisAnglesToRotMat(*rots)
mataff = transform.rotMatToAffine(rmat, origin) mataff = affine.rotMatToAffine(rmat, origin)
rotaff = transform.rotMatToAffine(rots, origin) rotaff = affine.rotMatToAffine(rots, origin)
exp = np.eye(4) exp = np.eye(4)
exp[:3, :3] = rmat exp[:3, :3] = rmat
...@@ -349,7 +349,7 @@ def test_axisBounds(): ...@@ -349,7 +349,7 @@ def test_axisBounds():
shape, origin, boundary, xform, expected = readTest(i) shape, origin, boundary, xform, expected = readTest(i)
for axes in allAxes: for axes in allAxes:
result = transform.axisBounds(shape, result = affine.axisBounds(shape,
xform, xform,
axes=axes, axes=axes,
origin=origin, origin=origin,
...@@ -371,14 +371,14 @@ def test_axisBounds(): ...@@ -371,14 +371,14 @@ def test_axisBounds():
# US-spelling # US-spelling
assert np.all(np.isclose( assert np.all(np.isclose(
expected, expected,
transform.axisBounds( affine.axisBounds(
shape, xform, origin='center', boundary=boundary))) shape, xform, origin='center', boundary=boundary)))
# Bad origin/boundary values # Bad origin/boundary values
with pytest.raises(ValueError): with pytest.raises(ValueError):
transform.axisBounds(shape, xform, origin='Blag', boundary=boundary) affine.axisBounds(shape, xform, origin='Blag', boundary=boundary)
with pytest.raises(ValueError): with pytest.raises(ValueError):
transform.axisBounds(shape, xform, origin=origin, boundary='Blufu') affine.axisBounds(shape, xform, origin=origin, boundary='Blufu')
def test_transform(): def test_transform():
...@@ -412,7 +412,7 @@ def test_transform(): ...@@ -412,7 +412,7 @@ def test_transform():
lines = readlines(testfile) lines = readlines(testfile)
xform = np.genfromtxt(lines[:4]) xform = np.genfromtxt(lines[:4])
expected = np.genfromtxt(lines[ 4:]) expected = np.genfromtxt(lines[ 4:])
result = transform.transform(testcoords, xform) result = affine.transform(testcoords, xform)
assert np.all(np.isclose(expected, result)) assert np.all(np.isclose(expected, result))
...@@ -422,7 +422,7 @@ def test_transform(): ...@@ -422,7 +422,7 @@ def test_transform():
for axes in allAxes: for axes in allAxes:
atestcoords = testcoords[:, axes] atestcoords = testcoords[:, axes]
aexpected = expected[ :, axes] aexpected = expected[ :, axes]
aresult = transform.transform(atestcoords, xform, axes=axes) aresult = affine.transform(atestcoords, xform, axes=axes)
assert np.all(np.isclose(aexpected, aresult)) assert np.all(np.isclose(aexpected, aresult))
...@@ -433,26 +433,26 @@ def test_transform(): ...@@ -433,26 +433,26 @@ def test_transform():
coords = badcoords[:, :3] coords = badcoords[:, :3]
with pytest.raises(IndexError): with pytest.raises(IndexError):
transform.transform(coords, badxform) affine.transform(coords, badxform)
with pytest.raises(ValueError): with pytest.raises(ValueError):
transform.transform(badcoords, xform) affine.transform(badcoords, xform)
with pytest.raises(ValueError): with pytest.raises(ValueError):
transform.transform(badcoords.reshape(5, 2, 4), xform) affine.transform(badcoords.reshape(5, 2, 4), xform)
with pytest.raises(ValueError): with pytest.raises(ValueError):
transform.transform(badcoords.reshape(5, 2, 4), xform, axes=1) affine.transform(badcoords.reshape(5, 2, 4), xform, axes=1)
with pytest.raises(ValueError): with pytest.raises(ValueError):
transform.transform(badcoords[:, (1, 2, 3)], xform, axes=[1, 2]) affine.transform(badcoords[:, (1, 2, 3)], xform, axes=[1, 2])
def test_transform_vector(seed): def test_transform_vector(seed):
# Some transform with a # Some transform with a
# translation component # translation component
xform = transform.compose([1, 2, 3], xform = affine.compose([1, 2, 3],
[5, 10, 15], [5, 10, 15],
[np.pi / 2, np.pi / 2, 0]) [np.pi / 2, np.pi / 2, 0])
...@@ -463,9 +463,9 @@ def test_transform_vector(seed): ...@@ -463,9 +463,9 @@ def test_transform_vector(seed):
vecExpected = np.dot(xform, list(v) + [0])[:3] vecExpected = np.dot(xform, list(v) + [0])[:3]
ptExpected = np.dot(xform, list(v) + [1])[:3] ptExpected = np.dot(xform, list(v) + [1])[:3]
vecResult = transform.transform(v, xform, vector=True) vecResult = affine.transform(v, xform, vector=True)
vec33Result = transform.transform(v, xform[:3, :3], vector=True) vec33Result = affine.transform(v, xform[:3, :3], vector=True)
ptResult = transform.transform(v, xform, vector=False) ptResult = affine.transform(v, xform, vector=False)
assert np.all(np.isclose(vecExpected, vecResult)) assert np.all(np.isclose(vecExpected, vecResult))
assert np.all(np.isclose(vecExpected, vec33Result)) assert np.all(np.isclose(vecExpected, vec33Result))
...@@ -488,13 +488,13 @@ def test_transformNormal(seed): ...@@ -488,13 +488,13 @@ def test_transformNormal(seed):
rotations = -np.pi + np.random.random(3) * 2 * np.pi rotations = -np.pi + np.random.random(3) * 2 * np.pi
origin = -100 + np.random.random(3) * 200 origin = -100 + np.random.random(3) * 200
xform = transform.compose(scales, xform = affine.compose(scales,
offsets, offsets,
rotations, rotations,
origin) origin)
expected = tn(n, xform) expected = tn(n, xform)
result = transform.transformNormal(n, xform) result = affine.transformNormal(n, xform)
assert np.all(np.isclose(expected, result)) assert np.all(np.isclose(expected, result))
...@@ -502,19 +502,19 @@ def test_transformNormal(seed): ...@@ -502,19 +502,19 @@ def test_transformNormal(seed):
def test_rmsdev(): def test_rmsdev():
t1 = np.eye(4) t1 = np.eye(4)
t2 = transform.scaleOffsetXform([1, 1, 1], [2, 0, 0]) t2 = affine.scaleOffsetXform([1, 1, 1], [2, 0, 0])
assert np.isclose(transform.rmsdev(t1, t2), 2) assert np.isclose(affine.rmsdev(t1, t2), 2)
assert np.isclose(transform.rmsdev(t1, t2, R=2), 2) assert np.isclose(affine.rmsdev(t1, t2, R=2), 2)
assert np.isclose(transform.rmsdev(t1, t2, R=2, xc=(1, 1, 1)), 2) assert np.isclose(affine.rmsdev(t1, t2, R=2, xc=(1, 1, 1)), 2)
t1 = np.eye(3) t1 = np.eye(3)
lastdist = 0 lastdist = 0
for i in range(1, 11): for i in range(1, 11):
rot = np.pi * i / 10.0 rot = np.pi * i / 10.0
t2 = transform.axisAnglesToRotMat(rot, 0, 0) t2 = affine.axisAnglesToRotMat(rot, 0, 0)
result = transform.rmsdev(t1, t2) result = affine.rmsdev(t1, t2)
assert result > lastdist assert result > lastdist
...@@ -522,8 +522,8 @@ def test_rmsdev(): ...@@ -522,8 +522,8 @@ def test_rmsdev():
for i in range(11, 20): for i in range(11, 20):
rot = np.pi * i / 10.0 rot = np.pi * i / 10.0
t2 = transform.axisAnglesToRotMat(rot, 0, 0) t2 = affine.axisAnglesToRotMat(rot, 0, 0)
result = transform.rmsdev(t1, t2) result = affine.rmsdev(t1, t2)
assert result < lastdist assert result < lastdist
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment