Ejemplo n.º 1
0
    def testUnityConvolution(self):
        """Verify that convolution with a centered delta function reproduces the original.
        """
        # create a delta function kernel that has 1,1 in the center
        kFunc = afwMath.IntegerDeltaFunction2D(0.0, 0.0)
        kernel = afwMath.AnalyticKernel(3, 3, kFunc)
        doNormalize = False
        doCopyEdge = False

        afwMath.convolve(self.cnvImage, self.maskedImage.getImage(), kernel,
                         doNormalize, doCopyEdge)

        afwMath.convolve(self.cnvMaskedImage, self.maskedImage, kernel,
                         doNormalize, doCopyEdge)
        cnvImMaskVarArr = self.cnvMaskedImage.getArrays()

        skipMaskArr = numpy.array(numpy.isnan(cnvImMaskVarArr[0]),
                                  dtype=numpy.uint16)

        kernelDescr = "Centered DeltaFunctionKernel (testing unity convolution)"
        self.assertImagesAlmostEqual(self.cnvImage,
                                     self.maskedImage.getImage(),
                                     skipMask=skipMaskArr,
                                     msg=kernelDescr)
        self.assertMaskedImagesAlmostEqual(self.cnvMaskedImage,
                                           self.maskedImage,
                                           skipMask=skipMaskArr,
                                           msg=kernelDescr)
Ejemplo n.º 2
0
    def testIntegerDeltaFunction2D(self):
        def basicDelta(x, xo):
            return (x == xo)

        errMsg = "{} = {} != {} for x={}, y={}, xo={}, yo={}"
        for xo in np.arange(-5.0, 5.0, 1.0):
            for yo in np.arange(-5.0, 5.0, 1.0):
                f = afwMath.IntegerDeltaFunction2D(xo, yo)
                g = f.clone()
                for x in np.arange(-5.0, 5.0, 1.0):
                    for y in np.arange(-5.0, 5.0, 1.0):
                        predVal = basicDelta(x, xo) * basicDelta(y, yo)
                        msg = errMsg.format(
                            type(f).__name__, f(x, y), predVal, x, y, xo, yo)
                        self.assertFloatsAlmostEqual(f(x, y),
                                                     predVal,
                                                     msg=msg,
                                                     atol=self.atol,
                                                     rtol=None)
                        msg = errMsg.format(
                            type(g).__name__, g(x, y), predVal, x, y, xo,
                            yo) + "; clone"
                        self.assertFloatsAlmostEqual(g(x, y),
                                                     predVal,
                                                     msg=msg,
                                                     atol=self.atol,
                                                     rtol=None)
Ejemplo n.º 3
0
    def testUnityConvolution(self):
        """Verify that convolution with a centered delta function reproduces the original.
        """
        # create a delta function kernel that has 1,1 in the center
        kFunc = afwMath.IntegerDeltaFunction2D(0.0, 0.0)
        kernel = afwMath.AnalyticKernel(3, 3, kFunc)
        doNormalize = False
        doCopyEdge = False

        afwMath.convolve(self.cnvImage, self.maskedImage.getImage(), kernel, doNormalize, doCopyEdge)
        cnvImArr = self.cnvImage.getArray()
        
        afwMath.convolve(self.cnvMaskedImage, self.maskedImage, kernel, doNormalize, doCopyEdge)
        cnvImMaskVarArr = self.cnvMaskedImage.getArrays()

        refCnvImMaskVarArr = self.maskedImage.getArrays()
        
        skipMaskArr = numpy.isnan(cnvImMaskVarArr[0])

        kernelDescr = "Centered DeltaFunctionKernel (testing unity convolution)"
        errStr = imTestUtils.imagesDiffer(cnvImArr, refCnvImMaskVarArr[0], skipMaskArr=skipMaskArr)
        if errStr:
            self.fail("convolve(Image, kernel=%s, doNormalize=%s, doCopyEdge=%s) failed:\n%s" % \
                (kernelDescr, doNormalize, doCopyEdge, errStr))
        errStr = imTestUtils.maskedImagesDiffer(cnvImMaskVarArr, refCnvImMaskVarArr, skipMaskArr=skipMaskArr)
        if errStr:
            self.fail("convolve(MaskedImage, kernel=%s, doNormalize=%s, doCopyEdge=%s) failed:\n%s" % \
                (kernelDescr, doNormalize, doCopyEdge, errStr))
        self.assert_(sameMaskPlaneDicts(self.cnvMaskedImage, self.maskedImage),
            "convolve(MaskedImage, kernel=%s, doNormalize=%s, doCopyEdge=%s) failed:\n%s" % \
            (kernelDescr, doNormalize, doCopyEdge, "convolved mask dictionary does not match input"))
Ejemplo n.º 4
0
    def testIntegerDeltaFunction2D(self):
        """A test for IntegerDeltaFunction2D"""
        def basicDelta(x, xo):
            return (x == xo)

        for xo in numpy.arange(-5.0, 5.0, 1.0):
            for yo in numpy.arange(-5.0, 5.0, 1.0):
                f = afwMath.IntegerDeltaFunction2D(xo, yo)
                g = f.clone()
                for x in numpy.arange(-5.0, 5.0, 1.0):
                    for y in numpy.arange(-5.0, 5.0, 1.0):
                        predVal = basicDelta(x, xo) * basicDelta(y, yo)
                        if predVal != f(x, y):
                            self.fail("%s = %s != %s for x=%s, y=%s, xo=%s, yo=%s" % \
                                (type(f).__name__, f(x, y), predVal, x, y, xo, yo))
                        if predVal != g(x, y):
                            self.fail("%s = %s != %s for x=%s, y=%s, xo=%s, yo=%s; clone" % \
                                (type(g).__name__, g(x, y), predVal, x, y, xo, yo))