Example #1
0
    def testLanczosFunction2D(self):
        """A test for LanczosFunction2D"""
        def basicLanczos1(x, n):
            return sinc(x) * sinc(x / float(n))

        for n in range(1, 5):
            f = afwMath.LanczosFunction2D(n)
            self.assertEquals(f.getOrder(), n)

            for xOffset in (-10.0, 0.0, 0.05):
                for yOffset in (-0.01, 0.0, 7.5):
                    f.setParameters((xOffset, yOffset))
                    g = f.clone()
                    #                    self.assertEquals(g.getOrder(), n)
                    for x in numpy.arange(-10.0, 10.1, 2.0):
                        for y in numpy.arange(-10.0, 10.1, 2.0):
                            xAdj = x - xOffset
                            yAdj = y - yOffset
                            predVal = basicLanczos1(xAdj, n) * basicLanczos1(
                                yAdj, n)
                            if not numpy.allclose(predVal, f(x, y)):
                                self.fail(
                                    "%s = %s != %s for n=%s, x=%s, " +
                                    "xOffset=%s, yOffset=%s, xAdj=%s, yAdj=%s"
                                    % (type(f).__name__, f(x, y), predVal, n,
                                       x, xOffset, yOffset, xAdj, yAdj))
                            if not numpy.allclose(predVal, g(x, y)):
                                self.fail(
                                    "%s = %s != %s for n=%s, x=%s, " +
                                    "xOffset=%s, yOffset=%s, xAdj=%s, yAdj=%s; clone"
                                    % (type(g).__name__, g(x, y), predVal, n,
                                       x, xOffset, yOffset, xAdj, yAdj))
Example #2
0
    def testLanczosFunction2D(self):
        def basicLanczos1(x, n):
            return sinc(x) * sinc(x / float(n))

        errMsg = "{} = {} != {} for n={}, x={}, xOffset={}, yOffset={}, xAdj={}, yAdj={}"
        for n in range(1, 5):
            f = afwMath.LanczosFunction2D(n)
            self.assertEqual(f.getOrder(), n)

            for xOffset in (-10.0, 0.0, 0.05):
                for yOffset in (-0.01, 0.0, 7.5):
                    f.setParameters((xOffset, yOffset))
                    g = f.clone()
                    for x in np.arange(-10.0, 10.1, 2.0):
                        for y in np.arange(-10.0, 10.1, 2.0):
                            xAdj = x - xOffset
                            yAdj = y - yOffset
                            predVal = basicLanczos1(xAdj, n) * \
                                basicLanczos1(yAdj, n)
                            msg = errMsg.format(
                                type(f).__name__, f(x, y), predVal, n, x,
                                xOffset, yOffset, xAdj, yAdj)
                            self.assertFloatsAlmostEqual(f(x, y),
                                                         predVal,
                                                         msg=msg,
                                                         atol=self.atol,
                                                         rtol=None)
                            msg = errMsg.format(
                                type(g).__name__, g(x, y), predVal, n, x,
                                xOffset, yOffset, xAdj, yAdj)
                            self.assertFloatsAlmostEqual(g(x, y),
                                                         predVal,
                                                         msg=msg,
                                                         atol=self.atol,
                                                         rtol=None)
Example #3
0
 def testCast(self):
     for instance in (afwMath.Chebyshev1Function1F(2),
                      afwMath.GaussianFunction1F(1.0),
                      afwMath.LanczosFunction1F(3),
                      afwMath.NullFunction1F(),
                      afwMath.PolynomialFunction1F(2)):
         Class = type(instance)
         base = instance.clone()
         self.assertEqual(type(base), afwMath.Function1F)
         derived = Class.cast(base)
         self.assertEqual(type(derived), Class)
     for instance in (afwMath.Chebyshev1Function1D(2),
                      afwMath.GaussianFunction1D(1.0),
                      afwMath.LanczosFunction1D(3),
                      afwMath.NullFunction1D(),
                      afwMath.PolynomialFunction1D(2)):
         Class = type(instance)
         base = instance.clone()
         self.assertEqual(type(base), afwMath.Function1D)
         derived = Class.cast(base)
         self.assertEqual(type(derived), Class)
     for instance in (afwMath.Chebyshev1Function2F(2),
                      afwMath.GaussianFunction2F(1.0, 1.0),
                      afwMath.DoubleGaussianFunction2F(1.0),
                      afwMath.LanczosFunction2F(3),
                      afwMath.NullFunction2F(),
                      afwMath.PolynomialFunction2F(2)):
         Class = type(instance)
         base = instance.clone()
         self.assertEqual(type(base), afwMath.Function2F)
         derived = Class.cast(base)
         self.assertEqual(type(derived), Class)
     for instance in (afwMath.Chebyshev1Function2D(2),
                      afwMath.GaussianFunction2D(1.0, 1.0),
                      afwMath.DoubleGaussianFunction2D(1.0),
                      afwMath.LanczosFunction2D(3),
                      afwMath.NullFunction2D(),
                      afwMath.PolynomialFunction2D(2)):
         Class = type(instance)
         base = instance.clone()
         self.assertEqual(type(base), afwMath.Function2D)
         derived = Class.cast(base)
         self.assertEqual(type(derived), Class)