当前位置: 首页>>代码示例>>Python>>正文


Python AffineTransform.from_params方法代码示例

本文整理汇总了Python中nipy.core.reference.coordinate_map.AffineTransform.from_params方法的典型用法代码示例。如果您正苦于以下问题:Python AffineTransform.from_params方法的具体用法?Python AffineTransform.from_params怎么用?Python AffineTransform.from_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nipy.core.reference.coordinate_map.AffineTransform的用法示例。


在下文中一共展示了AffineTransform.from_params方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_compose

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_compose():
    value = np.array([[1.0, 2.0, 3.0]]).T
    aa = compose(E.a, E.a)
    yield assert_true, aa.inverse() is None
    yield assert_true, np.allclose(aa(value), 4 * value)
    ab = compose(E.a, E.b)
    yield assert_true, ab.inverse() is None
    assert_true, np.allclose(ab(value), 4 * value)
    ac = compose(E.a, E.c)
    yield assert_true, ac.inverse() is None
    yield assert_true, np.allclose(ac(value), value)
    bb = compose(E.b, E.b)
    #    yield assert_true, bb.inverse() is not None
    aff1 = np.diag([1, 2, 3, 1])
    affine1 = AffineTransform.from_params("ijk", "xyz", aff1)
    aff2 = np.diag([4, 5, 6, 1])
    affine2 = AffineTransform.from_params("xyz", "abc", aff2)
    # compose mapping from 'ijk' to 'abc'
    compcm = compose(affine2, affine1)
    yield assert_equal, compcm.function_domain.coord_names, ("i", "j", "k")
    yield assert_equal, compcm.function_range.coord_names, ("a", "b", "c")
    yield assert_equal, compcm.affine, np.dot(aff2, aff1)
    # check invalid coordinate mappings
    yield assert_raises, ValueError, compose, affine1, affine2

    yield assert_raises, ValueError, compose, affine1, "foo"

    cm1 = CoordinateMap(CoordinateSystem("ijk"), CoordinateSystem("xyz"), np.log)
    cm2 = CoordinateMap(CoordinateSystem("xyz"), CoordinateSystem("abc"), np.exp)
    yield assert_raises, ValueError, compose, cm1, cm2
开发者ID:jonathan-taylor,项目名称:nipy,代码行数:32,代码来源:test_coordinate_map.py

示例2: test_drop_io_dim

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_drop_io_dim():
    # test ordinary case of 4d to 3d
    cm4d = AffineTransform.from_params('ijkl', 'xyzt', np.diag([1,2,3,4,1]))
    cm3d = drop_io_dim(cm4d, 't')
    yield assert_array_equal(cm3d.affine, np.diag([1, 2, 3, 1]))
    # 3d to 2d
    cm3d = AffineTransform.from_params('ijk', 'xyz', np.diag([1,2,3,1]))
    cm2d = drop_io_dim(cm3d, 'z')
    yield assert_array_equal(cm2d.affine, np.diag([1, 2, 1]))
    # test zero scaling for dropped dimension
    cm3d = AffineTransform.from_params('ijk', 'xyz', np.diag([1, 2, 0, 1]))
    cm2d = drop_io_dim(cm3d, 'z')
    yield assert_array_equal(cm2d.affine, np.diag([1, 2, 1]))
    # test not diagonal but orthogonal
    aff = np.array([[1, 0, 0, 0],
                    [0, 0, 2, 0],
                    [0, 3, 0, 0],
                    [0, 0, 0, 1]])
    cm3d = AffineTransform.from_params('ijk', 'xyz', aff)
    cm2d = drop_io_dim(cm3d, 'z')
    yield assert_array_equal(cm2d.affine, np.diag([1, 2, 1]))
    cm2d = drop_io_dim(cm3d, 'k')
    yield assert_array_equal(cm2d.affine, np.diag([1, 3, 1]))
    # and with zeros scaling for orthogonal dropped dimension
    aff[2] = 0
    cm3d = AffineTransform.from_params('ijk', 'xyz', aff)
    cm2d = drop_io_dim(cm3d, 'z')
    yield assert_array_equal(cm2d.affine, np.diag([1, 2, 1]))
开发者ID:Garyfallidis,项目名称:nipy,代码行数:30,代码来源:test_coordinate_map.py

示例3: test_compose

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_compose():
    value = np.array([[1., 2., 3.]]).T
    aa = compose(E.a, E.a)
    yield assert_true, aa.inverse() is None
    yield assert_true, np.allclose(aa(value), 4*value)
    ab = compose(E.a,E.b)
    yield assert_true, ab.inverse() is None
    assert_true, np.allclose(ab(value), 4*value)
    ac = compose(E.a,E.c)
    yield assert_true, ac.inverse() is None
    yield assert_true, np.allclose(ac(value), value)
    bb = compose(E.b,E.b)
    #    yield assert_true, bb.inverse() is not None
    aff1 = np.diag([1,2,3,1])
    affine1 = AffineTransform.from_params('ijk', 'xyz', aff1)
    aff2 = np.diag([4,5,6,1])
    affine2 = AffineTransform.from_params('xyz', 'abc', aff2)
    # compose mapping from 'ijk' to 'abc'
    compcm = compose(affine2, affine1)
    yield assert_equal, compcm.function_domain.coord_names, ('i', 'j', 'k')
    yield assert_equal, compcm.function_range.coord_names, ('a', 'b', 'c')
    yield assert_equal, compcm.affine, np.dot(aff2, aff1)
    # check invalid coordinate mappings
    yield assert_raises, ValueError, compose, affine1, affine2

    yield assert_raises, ValueError, compose, affine1, 'foo'

    cm1 = CoordinateMap(CoordinateSystem('ijk'),
                        CoordinateSystem('xyz'), np.log)
    cm2 = CoordinateMap(CoordinateSystem('xyz'),
                        CoordinateSystem('abc'), np.exp)
    yield assert_raises, ValueError, compose, cm1, cm2
开发者ID:Garyfallidis,项目名称:nipy,代码行数:34,代码来源:test_coordinate_map.py

示例4: test_synchronized_order

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_synchronized_order():

    data = np.random.standard_normal((3,4,7,5))
    im = Image(data, AffineTransform.from_params('ijkl', 'xyzt', np.diag([1,2,3,4,1])))

    im_scrambled = im.reordered_axes('iljk').reordered_reference('xtyz')
    im_unscrambled = image.synchronized_order(im_scrambled, im)
    
    yield assert_equal, im_unscrambled.coordmap, im.coordmap
    yield assert_almost_equal, im_unscrambled.get_data(), im.get_data()
    yield assert_equal, im_unscrambled, im
    yield assert_true, im_unscrambled == im
    yield assert_false, im_unscrambled != im

    # the images don't have to be the same shape

    data2 = np.random.standard_normal((3,11,9,4))
    im2 = Image(data, AffineTransform.from_params('ijkl', 'xyzt', np.diag([1,2,3,4,1])))

    im_scrambled2 = im2.reordered_axes('iljk').reordered_reference('xtyz')
    im_unscrambled2 = image.synchronized_order(im_scrambled2, im)

    yield assert_equal, im_unscrambled2.coordmap, im.coordmap

    # or the same coordmap

    data3 = np.random.standard_normal((3,11,9,4))
    im3 = Image(data, AffineTransform.from_params('ijkl', 'xyzt', np.diag([1,9,3,-2,1])))

    im_scrambled3 = im3.reordered_axes('iljk').reordered_reference('xtyz')
    im_unscrambled3 = image.synchronized_order(im_scrambled3, im)

    yield assert_equal, im_unscrambled3.axes, im.axes
    yield assert_equal, im_unscrambled3.reference, im.reference
开发者ID:Garyfallidis,项目名称:nipy,代码行数:36,代码来源:test_image.py

示例5: test_rollaxis

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_rollaxis():
    data = np.random.standard_normal((3,4,7,5))
    im = Image(data, AffineTransform.from_params('ijkl', 'xyzt', np.diag([1,2,3,4,1])))

    # for the inverse we must specify an integer
    yield assert_raises, ValueError, image.rollaxis, im, 'i', True

    # Check that rollaxis preserves diagonal affines, as claimed

    yield assert_almost_equal, image.rollaxis(im, 1).affine, np.diag([2,1,3,4,1])
    yield assert_almost_equal, image.rollaxis(im, 2).affine, np.diag([3,1,2,4,1])
    yield assert_almost_equal, image.rollaxis(im, 3).affine, np.diag([4,1,2,3,1])

    # Check that ambiguous axes raise an exception
    # 'l' appears both as an axis and a reference coord name
    # and in different places

    im_amb = Image(data, AffineTransform.from_params('ijkl', 'xylt', np.diag([1,2,3,4,1])))
    yield assert_raises, ValueError, image.rollaxis, im_amb, 'l'

    # But if it's unambiguous, then
    # 'l' can appear both as an axis and a reference coord name

    im_unamb = Image(data, AffineTransform.from_params('ijkl', 'xyzl', np.diag([1,2,3,4,1])))
    im_rolled = image.rollaxis(im_unamb, 'l')
    yield assert_almost_equal, im_rolled.get_data(), \
        im_unamb.get_data().transpose([3,0,1,2])

    for i, o, n in zip('ijkl', 'xyzt', range(4)):
        im_i = image.rollaxis(im, i)
        im_o = image.rollaxis(im, o)
        im_n = image.rollaxis(im, n)

        yield assert_almost_equal, im_i.get_data(), \
                                  im_o.get_data()

        yield assert_almost_equal, im_i.affine, \
            im_o.affine

        yield assert_almost_equal, im_n.get_data(), \
            im_o.get_data()

        for _im in [im_n, im_o, im_i]:
            im_n_inv = image.rollaxis(_im, n, inverse=True)

            yield assert_almost_equal, im_n_inv.affine, \
                im.affine

            yield assert_almost_equal, im_n_inv.get_data(), \
                im.get_data()
开发者ID:Garyfallidis,项目名称:nipy,代码行数:52,代码来源:test_image.py

示例6: test__eq__

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test__eq__():
    yield assert_true, E.a == E.a
    yield assert_false, E.a != E.a

    yield assert_false, E.a == E.b
    yield assert_true, E.a != E.b

    yield assert_true, E.singular == E.singular
    yield assert_false, E.singular != E.singular

    A = AffineTransform.from_params('ijk', 'xyz', np.diag([4,3,2,1]))
    B = AffineTransform.from_params('ijk', 'xyz', np.diag([4,3,2,1]))

    yield assert_true, A == B
    yield assert_false, A != B
开发者ID:Garyfallidis,项目名称:nipy,代码行数:17,代码来源:test_coordinate_map.py

示例7: test_renamed

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_renamed():

    A = AffineTransform.from_params('ijk', 'xyz', np.identity(4))

    ijk = CoordinateSystem('ijk')
    xyz = CoordinateSystem('xyz')
    C = CoordinateMap(ijk, xyz, np.log)

    for B in [A,C]:
        B_re = B.renamed_domain({'i':'foo'})
        yield assert_equal, B_re.function_domain.coord_names, ('foo', 'j', 'k')

        B_re = B.renamed_domain({'i':'foo','j':'bar'})
        yield assert_equal, B_re.function_domain.coord_names, ('foo', 'bar', 'k')

        B_re = B.renamed_range({'y':'foo'})
        yield assert_equal, B_re.function_range.coord_names, ('x', 'foo', 'z')

        B_re = B.renamed_range({0:'foo',1:'bar'})
        yield assert_equal, B_re.function_range.coord_names, ('foo', 'bar', 'z')

        B_re = B.renamed_domain({0:'foo',1:'bar'})
        yield assert_equal, B_re.function_domain.coord_names, ('foo', 'bar', 'k')

        B_re = B.renamed_range({'y':'foo','x':'bar'})
        yield assert_equal, B_re.function_range.coord_names, ('bar', 'foo', 'z')

        yield assert_raises, ValueError, B.renamed_range, {'foo':'y'}
        yield assert_raises, ValueError, B.renamed_domain, {'foo':'y'}
开发者ID:Garyfallidis,项目名称:nipy,代码行数:31,代码来源:test_coordinate_map.py

示例8: test_renamed

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_renamed():

    A = AffineTransform.from_params("ijk", "xyz", np.identity(4))

    ijk = CoordinateSystem("ijk")
    xyz = CoordinateSystem("xyz")
    C = CoordinateMap(ijk, xyz, np.log)

    for B in [A, C]:
        B_re = B.renamed_domain({"i": "foo"})
        yield assert_equal, B_re.function_domain.coord_names, ("foo", "j", "k")

        B_re = B.renamed_domain({"i": "foo", "j": "bar"})
        yield assert_equal, B_re.function_domain.coord_names, ("foo", "bar", "k")

        B_re = B.renamed_range({"y": "foo"})
        yield assert_equal, B_re.function_range.coord_names, ("x", "foo", "z")

        B_re = B.renamed_range({0: "foo", 1: "bar"})
        yield assert_equal, B_re.function_range.coord_names, ("foo", "bar", "z")

        B_re = B.renamed_domain({0: "foo", 1: "bar"})
        yield assert_equal, B_re.function_domain.coord_names, ("foo", "bar", "k")

        B_re = B.renamed_range({"y": "foo", "x": "bar"})
        yield assert_equal, B_re.function_range.coord_names, ("bar", "foo", "z")

        yield assert_raises, ValueError, B.renamed_range, {"foo": "y"}
        yield assert_raises, ValueError, B.renamed_domain, {"foo": "y"}
开发者ID:jonathan-taylor,项目名称:nipy,代码行数:31,代码来源:test_coordinate_map.py

示例9: test_product

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_product():
    affine1 = AffineTransform.from_params("i", "x", np.diag([2, 1]))
    affine2 = AffineTransform.from_params("j", "y", np.diag([3, 1]))
    affine = product(affine1, affine2)

    cm1 = CoordinateMap(CoordinateSystem("i"), CoordinateSystem("x"), np.log)

    cm2 = CoordinateMap(CoordinateSystem("j"), CoordinateSystem("y"), np.log)
    cm = product(cm1, cm2)

    yield assert_equal, affine.function_domain.coord_names, ("i", "j")
    yield assert_equal, affine.function_range.coord_names, ("x", "y")
    yield assert_almost_equal, cm([3, 4]), np.log([3, 4])
    yield assert_almost_equal, cm.function([[3, 4], [5, 6]]), np.log([[3, 4], [5, 6]])

    yield assert_equal, affine.function_domain.coord_names, ("i", "j")
    yield assert_equal, affine.function_range.coord_names, ("x", "y")
    yield assert_equal, affine.affine, np.diag([2, 3, 1])
开发者ID:jonathan-taylor,项目名称:nipy,代码行数:20,代码来源:test_coordinate_map.py

示例10: setup

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def setup():
    def f(x):
        return 2 * x

    def g(x):
        return x / 2.0

    x = CoordinateSystem("x", "x")
    E.a = CoordinateMap(x, x, f)
    E.b = CoordinateMap(x, x, f, inverse_function=g)
    E.c = CoordinateMap(x, x, g)
    E.d = CoordinateMap(x, x, g, inverse_function=f)
    E.e = AffineTransform.identity("ijk")
    A = np.identity(4)
    A[0:3] = np.random.standard_normal((3, 4))
    E.mapping = AffineTransform.from_params("ijk", "xyz", A)
    E.singular = AffineTransform.from_params(
        "ijk", "xyzt", np.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [8, 9, 10, 11], [0, 0, 0, 1]])
    )
开发者ID:jonathan-taylor,项目名称:nipy,代码行数:21,代码来源:test_coordinate_map.py

示例11: test_append_io_dim

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_append_io_dim():
    aff = np.diag([1, 2, 3, 1])
    in_dims = list("ijk")
    out_dims = list("xyz")
    cm = AffineTransform.from_params(in_dims, out_dims, aff)
    cm2 = append_io_dim(cm, "l", "t")
    yield assert_array_equal(cm2.affine, np.diag([1, 2, 3, 1, 1]))
    yield assert_equal(cm2.function_range.coord_names, out_dims + ["t"])
    yield assert_equal(cm2.function_domain.coord_names, in_dims + ["l"])
    cm2 = append_io_dim(cm, "l", "t", 9, 5)
    a2 = np.diag([1, 2, 3, 5, 1])
    a2[3, 4] = 9
    yield assert_array_equal(cm2.affine, a2)
    yield assert_equal(cm2.function_range.coord_names, out_dims + ["t"])
    yield assert_equal(cm2.function_domain.coord_names, in_dims + ["l"])
    # non square case
    aff = np.array([[2, 0, 0], [0, 3, 0], [0, 0, 1], [0, 0, 1]])
    cm = AffineTransform.from_params("ij", "xyz", aff)
    cm2 = append_io_dim(cm, "q", "t", 9, 5)
    a2 = np.array([[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 1], [0, 0, 5, 9], [0, 0, 0, 1]])
    yield assert_array_equal(cm2.affine, a2)
    yield assert_equal(cm2.function_range.coord_names, list("xyzt"))
    yield assert_equal(cm2.function_domain.coord_names, list("ijq"))
开发者ID:jonathan-taylor,项目名称:nipy,代码行数:25,代码来源:test_coordinate_map.py

示例12: test_ArrayLikeObj

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_ArrayLikeObj():
    obj = ArrayLikeObj()
    # create simple coordmap
    xform = np.eye(4)
    coordmap = AffineTransform.from_params('xyz', 'ijk', xform)
    
    # create image form array-like object and coordmap
    img = image.Image(obj, coordmap)
    yield assert_true, img.ndim == 3
    yield assert_true, img.shape == (2,3,4)
    yield assert_true, np.allclose(np.asarray(img), 1)
    yield assert_true, np.allclose(np.asarray(img), 1)
    img[:] = 4
    yield assert_true, np.allclose(np.asarray(img), 4)
开发者ID:Garyfallidis,项目名称:nipy,代码行数:16,代码来源:test_image.py

示例13: test_append_io_dim

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_append_io_dim():
    aff = np.diag([1,2,3,1])
    in_dims = list('ijk')
    out_dims = list('xyz')
    cm = AffineTransform.from_params(in_dims, out_dims, aff)
    cm2 = append_io_dim(cm, 'l', 't')
    yield assert_array_equal(cm2.affine, np.diag([1,2,3,1,1]))
    yield assert_equal(cm2.function_range.coord_names,
                       out_dims + ['t'])
    yield assert_equal(cm2.function_domain.coord_names,
                       in_dims + ['l'])
    cm2 = append_io_dim(cm, 'l', 't', 9, 5)
    a2 = np.diag([1,2,3,5,1])
    a2[3,4] = 9
    yield assert_array_equal(cm2.affine, a2)
    yield assert_equal(cm2.function_range.coord_names,
                       out_dims + ['t'])
    yield assert_equal(cm2.function_domain.coord_names,
                       in_dims + ['l'])
    # non square case
    aff = np.array([[2,0,0],
                    [0,3,0],
                    [0,0,1],
                    [0,0,1]])
    cm = AffineTransform.from_params('ij', 'xyz', aff)
    cm2 = append_io_dim(cm, 'q', 't', 9, 5)
    a2 = np.array([[2,0,0,0],
                   [0,3,0,0],
                   [0,0,0,1],
                   [0,0,5,9],
                   [0,0,0,1]])
    yield assert_array_equal(cm2.affine, a2)
    yield assert_equal(cm2.function_range.coord_names,
                       list('xyzt'))
    yield assert_equal(cm2.function_domain.coord_names,
                       list('ijq'))
开发者ID:Garyfallidis,项目名称:nipy,代码行数:38,代码来源:test_coordinate_map.py

示例14: test_affine_from_params

# 需要导入模块: from nipy.core.reference.coordinate_map import AffineTransform [as 别名]
# 或者: from nipy.core.reference.coordinate_map.AffineTransform import from_params [as 别名]
def test_affine_from_params():
    incs, outcs, aff = affine_v2w()
    cm = AffineTransform.from_params('ijk', 'xyz', aff)
    yield assert_equal, cm.affine, aff
    badaff = np.array([[1,2,3],[4,5,6]])
    yield assert_raises, ValueError, AffineTransform.from_params, 'ijk', 'xyz', badaff
开发者ID:Garyfallidis,项目名称:nipy,代码行数:8,代码来源:test_coordinate_map.py


注:本文中的nipy.core.reference.coordinate_map.AffineTransform.from_params方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。