Exemplo n.º 1
0
    def testFindTwoStep(self):
        """
        Tests findTwoStep()
        """

        # parallelogram, rotation, scale, exact
        af = Affine.findTwoStep(x=self.x1[0:1], y=self.y1[0:1],
                                x_gl=self.x1, y_gl=self.y1+3)
        af_desired = Affine.find(x=self.x1, y=self.y1)
        np_test.assert_almost_equal(af.gl, af_desired.gl)
        np_test.assert_almost_equal(af.d, af_desired.d)
        np_test.assert_almost_equal(af.glError, numpy.zeros_like(self.x1))
        np_test.assert_almost_equal(af.dError, numpy.zeros_like(self.x1[0:1]))
        np_test.assert_almost_equal(af.rmsErrorEst, 0)

        # parallelogram, rotation, scale, parity, exact
        af = Affine.findTwoStep(x=self.x1[0:2], y=self.y1m[0:2],
                                x_gl=self.x1, y_gl=self.y1m+[2,-3])
        af_desired = Affine.find(x=self.x1, y=self.y1m)
        np_test.assert_almost_equal(af.gl, af_desired.gl)
        np_test.assert_almost_equal(af.d, af_desired.d)
        np_test.assert_almost_equal(af.glError, numpy.zeros_like(self.x1))
        np_test.assert_almost_equal(af.dError, numpy.zeros_like(self.x1[0:2]))
        np_test.assert_almost_equal(af.rmsErrorEst, 0)

        # parallelogram, rotation, scale, parity, not exact
        af = Affine.findTwoStep(x=self.x2, y=self.y2m,
                                x_gl=self.x2, y_gl=self.y2m+[2,-3])
        af_desired = Affine.find(x=self.x2, y=self.y2m)
        np_test.assert_almost_equal(af.gl, af_desired.gl)
        np_test.assert_almost_equal(af.d, af_desired.d)
        np_test.assert_almost_equal(af.rmsErrorEst, af_desired.rmsError, 
                                    decimal=0)
Exemplo n.º 2
0
    def testInverse(self):
        """
        Tests inverse method
        """

        #################################################
        #
        # parallelogram, scale, rotation, parity, exact
        #

        #
        af = Affine.find(x=self.x1, y=self.y1m)

        # test inverse
        af_inverse = af.inverse()
        np_test.assert_almost_equal(numpy.dot(af.gl, af_inverse.gl),
                                    numpy.identity(2))
        afi = Affine.find(x=self.y1m, y=self.x1)
        np_test.assert_almost_equal(af_inverse.gl, afi.gl)
        np_test.assert_almost_equal(af_inverse.d, afi.d)
        np_test.assert_almost_equal(self.x1, af_inverse.transform(self.y1m))

        # error
        np_test.assert_almost_equal(af_inverse.error, afi.error)
        np_test.assert_almost_equal(af_inverse.rmsError, afi.rmsError)

        #################################################
        #
        # parallelogram, scale, rotation, parity, not exact
        #
        # Note: only approximate comparisons because inverse of an optimal
        # (least squares) x->y transformation is not the optimal y->x.

        af = Affine.find(x=self.x2, y=self.y2m)

        # test inverse
        af_inverse = af.inverse()
        np_test.assert_almost_equal(numpy.dot(af.gl, af_inverse.gl),
                                    numpy.identity(2))
        afi = Affine.find(x=self.y2m, y=self.x2)
        np_test.assert_almost_equal(af_inverse.gl, afi.gl, decimal=1)
        np_test.assert_almost_equal(af_inverse.d, afi.d, decimal=1)
        np_test.assert_almost_equal(self.x2,
                                    af_inverse.transform(self.y2m),
                                    decimal=0)

        # error
        np_test.assert_almost_equal(af_inverse.error, afi.error, decimal=1)
        np_test.assert_almost_equal(af_inverse.rmsError,
                                    afi.rmsError,
                                    decimal=1)
Exemplo n.º 3
0
    def testScale(self):
        """
        Tests getScale and setScale
        """

        af1m_desired = Affine.find(x=self.x1, y=self.y1m)
        af1m_changed = Affine.find(x=self.x1, y=self.y1m)
        af1m_changed.scale = [1, 2]
        np_test.assert_almost_equal(af1m_changed.s, [[1, 0], [0, 2]])
        np_test.assert_almost_equal(af1m_changed.scale, [1, 2])
        np_test.assert_almost_equal(af1m_changed.q, af1m_desired.q)
        np_test.assert_almost_equal(af1m_changed.p, af1m_desired.p)
        np_test.assert_almost_equal(af1m_changed.m, af1m_desired.m)
        np_test.assert_almost_equal(af1m_changed.d, af1m_desired.d)
Exemplo n.º 4
0
    def testScale(self):
        """
        Tests getScale and setScale
        """

        af1m_desired = Affine.find(x=self.x1, y=self.y1m)
        af1m_changed = Affine.find(x=self.x1, y=self.y1m)
        af1m_changed.scale = [1, 2]
        np_test.assert_almost_equal(af1m_changed.s, [[1, 0], [0, 2]])
        np_test.assert_almost_equal(af1m_changed.scale, [1,2])
        np_test.assert_almost_equal(af1m_changed.q, af1m_desired.q)
        np_test.assert_almost_equal(af1m_changed.p, af1m_desired.p)
        np_test.assert_almost_equal(af1m_changed.m, af1m_desired.m)
        np_test.assert_almost_equal(af1m_changed.d, af1m_desired.d)
Exemplo n.º 5
0
    def testInverse(self):
        """
        Tests inverse method
        """

        #################################################
        #
        # parallelogram, scale, rotation, parity, exact
        #

        # 
        af = Affine.find(x=self.x1, y=self.y1m)

        # test inverse
        af_inverse = af.inverse()
        np_test.assert_almost_equal(numpy.dot(af.gl, af_inverse.gl),
                                    numpy.identity(2))
        afi = Affine.find(x=self.y1m, y=self.x1)
        np_test.assert_almost_equal(af_inverse.gl, afi.gl)
        np_test.assert_almost_equal(af_inverse.d, afi.d)
        np_test.assert_almost_equal(self.x1, af_inverse.transform(self.y1m))

        # error
        np_test.assert_almost_equal(af_inverse.error, afi.error)
        np_test.assert_almost_equal(af_inverse.rmsError, afi.rmsError)

        #################################################
        #
        # parallelogram, scale, rotation, parity, not exact
        #
        # Note: only approximate comparisons because inverse of an optimal
        # (least squares) x->y transformation is not the optimal y->x.
        
        af = Affine.find(x=self.x2, y=self.y2m)

        # test inverse
        af_inverse = af.inverse()
        np_test.assert_almost_equal(numpy.dot(af.gl, af_inverse.gl),
                                    numpy.identity(2))
        afi = Affine.find(x=self.y2m, y=self.x2)
        np_test.assert_almost_equal(af_inverse.gl, afi.gl, decimal=1)
        np_test.assert_almost_equal(af_inverse.d, afi.d, decimal=1)
        np_test.assert_almost_equal(self.x2, af_inverse.transform(self.y2m),
                                    decimal=0)

        # error
        np_test.assert_almost_equal(af_inverse.error, afi.error, decimal=1)
        np_test.assert_almost_equal(af_inverse.rmsError, afi.rmsError, 
                                    decimal=1)        
Exemplo n.º 6
0
 def testTransform(self):
     """
     Tests transform() method
     """
     af = Affine.find(x=self.x1, y=self.y1m)
     desired = numpy.inner(self.x1, af.gl) + af.d
     np_test.assert_almost_equal(af.transform(self.x1), desired)
Exemplo n.º 7
0
 def testTransform(self):
     """
     Tests transform() method
     """
     af = Affine.find(x=self.x1, y=self.y1m)
     desired = numpy.inner(self.x1, af.gl) + af.d
     np_test.assert_almost_equal(af.transform(self.x1), desired)
Exemplo n.º 8
0
    def testFind(self):
        """
        Tests find() method
        """

        af = Affine.find(x=self.x1, y=self.y1m)
        desired = numpy.inner(self.x1, af.gl) + af.d
        np_test.assert_almost_equal(self.y1m, desired)
Exemplo n.º 9
0
    def testFind(self):
        """
        Tests find() method
        """

        af = Affine.find(x=self.x1, y=self.y1m)
        desired = numpy.inner(self.x1, af.gl) + af.d
        np_test.assert_almost_equal(self.y1m, desired)
Exemplo n.º 10
0
    def testFindTwoStep(self):
        """
        Tests findTwoStep()
        """

        # parallelogram, rotation, scale, exact
        af = Affine.findTwoStep(x=self.x1[0:1],
                                y=self.y1[0:1],
                                x_gl=self.x1,
                                y_gl=self.y1 + 3)
        af_desired = Affine.find(x=self.x1, y=self.y1)
        np_test.assert_almost_equal(af.gl, af_desired.gl)
        np_test.assert_almost_equal(af.d, af_desired.d)
        np_test.assert_almost_equal(af.glError, numpy.zeros_like(self.x1))
        np_test.assert_almost_equal(af.dError, numpy.zeros_like(self.x1[0:1]))
        np_test.assert_almost_equal(af.rmsErrorEst, 0)

        # parallelogram, rotation, scale, parity, exact
        af = Affine.findTwoStep(x=self.x1[0:2],
                                y=self.y1m[0:2],
                                x_gl=self.x1,
                                y_gl=self.y1m + [2, -3])
        af_desired = Affine.find(x=self.x1, y=self.y1m)
        np_test.assert_almost_equal(af.gl, af_desired.gl)
        np_test.assert_almost_equal(af.d, af_desired.d)
        np_test.assert_almost_equal(af.glError, numpy.zeros_like(self.x1))
        np_test.assert_almost_equal(af.dError, numpy.zeros_like(self.x1[0:2]))
        np_test.assert_almost_equal(af.rmsErrorEst, 0)

        # parallelogram, rotation, scale, parity, not exact
        af = Affine.findTwoStep(x=self.x2,
                                y=self.y2m,
                                x_gl=self.x2,
                                y_gl=self.y2m + [2, -3])
        af_desired = Affine.find(x=self.x2, y=self.y2m)
        np_test.assert_almost_equal(af.gl, af_desired.gl)
        np_test.assert_almost_equal(af.d, af_desired.d)
        np_test.assert_almost_equal(af.rmsErrorEst,
                                    af_desired.rmsError,
                                    decimal=0)