Ejemplo n.º 1
0
    def testWeightedStats(self):
        """Test that bug from #1697 (weighted stats returning NaN) stays fixed."""
        
        rand = afwMath.Random()
        mu   = 10000

        edgeMask = afwImage.MaskU.getPlaneBitMask("EDGE")

        badPixelMask = afwImage.MaskU.getPlaneBitMask("EDGE")
        statsCtrl = afwMath.StatisticsControl()
        statsCtrl.setNumSigmaClip(3.0)
        statsCtrl.setNumIter(2)
        statsCtrl.setAndMask(badPixelMask)

        for weight in (300.0, 10.0, 1.0):
            print "Testing with weight=%0.1f" % (weight,)
            maskedImageList = afwImage.vectorMaskedImageF() # [] is rejected by afwMath.statisticsStack
            weightList = []

            nx, ny = 256, 256
            for i in range(3):
                print "Processing ", i
                maskedImage = afwImage.MaskedImageF(nx, ny)
                maskedImageList.append(maskedImage)

                afwMath.randomPoissonImage(maskedImage.getImage(), rand, mu)
                maskedImage.getVariance().set(mu)
                weightList.append(weight)
                    
            self.reportBadPixels(maskedImage, badPixelMask)

            print "Stack: ",
            coaddMaskedImage = afwMath.statisticsStack(
                maskedImageList, afwMath.MEANCLIP, statsCtrl, weightList)
            self.reportBadPixels(coaddMaskedImage, badPixelMask)
Ejemplo n.º 2
0
    def testWeightedStats(self):
        """Test that bug from #1697 (weighted stats returning NaN) stays fixed."""

        rand = afwMath.Random()
        mu = 10000

        edgeMask = afwImage.MaskU.getPlaneBitMask("EDGE")

        badPixelMask = afwImage.MaskU.getPlaneBitMask("EDGE")
        statsCtrl = afwMath.StatisticsControl()
        statsCtrl.setNumSigmaClip(3.0)
        statsCtrl.setNumIter(2)
        statsCtrl.setAndMask(badPixelMask)

        for weight in (300.0, 10.0, 1.0):
            print "Testing with weight=%0.1f" % (weight,)
            maskedImageList = afwImage.vectorMaskedImageF()  # [] is rejected by afwMath.statisticsStack
            weightList = []

            nx, ny = 256, 256
            for i in range(3):
                print "Processing ", i
                maskedImage = afwImage.MaskedImageF(nx, ny)
                maskedImageList.append(maskedImage)

                afwMath.randomPoissonImage(maskedImage.getImage(), rand, mu)
                maskedImage.getVariance().set(mu)
                weightList.append(weight)

            self.reportBadPixels(maskedImage, badPixelMask)

            print "Stack: ",
            coaddMaskedImage = afwMath.statisticsStack(maskedImageList, afwMath.MEANCLIP, statsCtrl, weightList)
            self.reportBadPixels(coaddMaskedImage, badPixelMask)
Ejemplo n.º 3
0
 def testRandomPoissonImage(self):
     mu = 10
     afwMath.randomPoissonImage(self.image, self.rand, mu)
     stats = afwMath.makeStatistics(self.image, afwMath.MEAN | afwMath.VARIANCE)
     if False:
         print "mu = %g.  mean = %g, variance = %g" % \
               (mu, stats.getValue(afwMath.MEAN), stats.getValue(afwMath.VARIANCE))
     self.assertAlmostEqual(stats.getValue(afwMath.MEAN), mu, 1)
     self.assertAlmostEqual(stats.getValue(afwMath.VARIANCE), mu, 1)
Ejemplo n.º 4
0
    x0 = x - (psf_size - 1) / 2
    y0 = y - (psf_size - 1) / 2
    box = afwGeom.BoxI(afwGeom.PointI(x0, y0),
                       afwGeom.ExtentI(psf_size, psf_size))
    subim = afwImage.ImageF(im, box, afwImage.LOCAL)

try:
    subim += psf_im
except NotImplementedError:
    psf_im = psf_im.convertF()
    subim += psf_im

print(" subim = ", subim)

back_im = afwImage.ImageF(im.getBBox())
afwMath.randomPoissonImage(back_im, rand, 100)
im += back_im
display.mtv(im)
display.incrDefaultFrame()
mask = afwImage.MaskU(im.getBBox())
masked_im = afwImage.MaskedImageF(im, mask, im)

sys.exit()

threshold = afwDetect.createThreshold(5., 'stdev')
fs = afwDetect.FootprintSet(masked_im, threshold, 'DETECTED')
#display.mtv(masked_im)
#display.incrDefaultFrame()

bctrl = afwMath.BackgroundControl(11, 11)
bkgd = afwMath.makeBackground(masked_im, bctrl)