def test_as_coordinate_map(): ijk = CoordinateSystem('ijk') xyz = CoordinateSystem('xyz') A = np.random.standard_normal((4,4)) # bottom row of A is not [0,0,0,1] yield assert_raises, ValueError, AffineTransform, ijk, xyz, A A[-1] = [0,0,0,1] aff = AffineTransform(ijk, xyz, A) _cmapA = _as_coordinate_map(aff) yield assert_true, isinstance(_cmapA, CoordinateMap) yield assert_true, _cmapA.inverse_function != None # a non-invertible one B = A[1:] xy = CoordinateSystem('xy') affB = AffineTransform(ijk, xy, B) _cmapB = _as_coordinate_map(affB) yield assert_true, isinstance(_cmapB, CoordinateMap) yield assert_true, _cmapB.inverse_function == None
def test_shift_origin(): CS = CoordinateSystem A = np.random.standard_normal((5,6)) A[-1] = [0,0,0,0,0,1] aff1 = AffineTransform(CS('ijklm', 'oldorigin'), CS('xyzt'), A) difference = np.random.standard_normal(5) point_in_old_basis = np.random.standard_normal(5) for aff in [aff1, _as_coordinate_map(aff1)]: # The same affine transforation with a different origin for its domain shifted_aff = shifted_domain_origin(aff, difference, 'neworigin') # This is the relation ship between coordinates in old and new origins yield assert_true, np.allclose(shifted_aff(point_in_old_basis), aff(point_in_old_basis+difference)) yield assert_true, np.allclose(shifted_aff(point_in_old_basis-difference), aff(point_in_old_basis)) # OK, now for the range A = np.random.standard_normal((5,6)) A[-1] = [0,0,0,0,0,1] aff2 = AffineTransform(CS('ijklm', 'oldorigin'), CS('xyzt'), A) difference = np.random.standard_normal(4) for aff in [aff2, _as_coordinate_map(aff2)]: # The same affine transforation with a different origin for its domain shifted_aff = shifted_range_origin(aff, difference, 'neworigin') # Let's check that things work point_in_old_basis = np.random.standard_normal(5) # This is the relation ship between coordinates in old and new origins yield assert_true, np.allclose(shifted_aff(point_in_old_basis), aff(point_in_old_basis)-difference) yield assert_true, np.allclose(shifted_aff(point_in_old_basis)+difference, aff(point_in_old_basis))