예제 #1
0
    def getFluxPortion(self, strayFlux=True):
        """!
        Return a HeavyFootprint containing the flux apportioned to this peak.

        @param[in]     strayFlux   include stray flux also?
        """
        if self.templateFootprint is None or self.fluxPortion is None:
            return None
        heavy = afwDet.makeHeavyFootprint(self.templateFootprint, self.fluxPortion)
        if strayFlux:
            if self.strayFlux is not None:
                heavy = afwDet.mergeHeavyFootprints(heavy, self.strayFlux)

        return heavy
예제 #2
0
    def getFluxPortion(self, strayFlux=True):
        """!
        Return a HeavyFootprint containing the flux apportioned to this peak.

        @param[in]     strayFlux   include stray flux also?
        """
        if self.templateFootprint is None or self.fluxPortion is None:
            return None
        heavy = afwDet.makeHeavyFootprint(self.templateFootprint, self.fluxPortion)
        if strayFlux:
            if self.strayFlux is not None:
                heavy = afwDet.mergeHeavyFootprints(heavy, self.strayFlux)

        return heavy
예제 #3
0
    def testMergeHeavyFootprints(self):
        mi = afwImage.MaskedImageF(20, 10)
        objectPixelVal = (42, 0x9, 400)

        spanList = []
        for y, x0, x1 in [(1, 9, 12), (2, 12, 13), (3, 11, 15)]:
            spanList.append(afwGeom.Span(y, x0, x1))
            for x in range(x0, x1 + 1):
                mi[x, y, afwImage.LOCAL] = objectPixelVal

        foot = afwDetect.Footprint(afwGeom.SpanSet(spanList))

        hfoot1 = afwDetect.makeHeavyFootprint(self.foot, self.mi)
        hfoot2 = afwDetect.makeHeavyFootprint(foot, mi)

        hsum = afwDetect.mergeHeavyFootprints(hfoot1, hfoot2)

        bb = hsum.getBBox()
        self.assertEqual(bb.getMinX(), 9)
        self.assertEqual(bb.getMaxX(), 15)
        self.assertEqual(bb.getMinY(), 1)
        self.assertEqual(bb.getMaxY(), 3)

        msum = afwImage.MaskedImageF(20, 10)
        hsum.insert(msum)

        sa = msum.getImage().getArray()

        self.assertFloatsEqual(sa[1, 9:13], objectPixelVal[0])
        self.assertFloatsEqual(sa[2, 12:14],
                               objectPixelVal[0] + self.objectPixelVal[0])
        self.assertFloatsEqual(sa[2, 10:12], self.objectPixelVal[0])

        sv = msum.getVariance().getArray()

        self.assertFloatsEqual(sv[1, 9:13], objectPixelVal[2])
        self.assertFloatsEqual(sv[2, 12:14],
                               objectPixelVal[2] + self.objectPixelVal[2])
        self.assertFloatsEqual(sv[2, 10:12], self.objectPixelVal[2])

        sm = msum.getMask().getArray()

        self.assertFloatsEqual(sm[1, 9:13], objectPixelVal[1])
        self.assertFloatsEqual(sm[2, 12:14],
                               objectPixelVal[1] | self.objectPixelVal[1])
        self.assertFloatsEqual(sm[2, 10:12], self.objectPixelVal[1])

        if False:
            import matplotlib
            matplotlib.use('Agg')
            import pylab as plt
            im1 = afwImage.ImageF(bb)
            hfoot1.insert(im1)
            im2 = afwImage.ImageF(bb)
            hfoot2.insert(im2)
            im3 = afwImage.ImageF(bb)
            hsum.insert(im3)
            plt.clf()
            plt.subplot(1, 3, 1)
            plt.imshow(im1.getArray(), interpolation='nearest', origin='lower')
            plt.subplot(1, 3, 2)
            plt.imshow(im2.getArray(), interpolation='nearest', origin='lower')
            plt.subplot(1, 3, 3)
            plt.imshow(im3.getArray(), interpolation='nearest', origin='lower')
            plt.savefig('merge.png')
예제 #4
0
    def testMergeHeavyFootprints(self):
        mi = afwImage.MaskedImageF(20, 10)
        objectPixelVal = (42, 0x9, 400)

        spanList = []
        for y, x0, x1 in [(1, 9, 12),
                          (2, 12, 13),
                          (3, 11, 15)]:
            spanList.append(afwGeom.Span(y, x0, x1))
            for x in range(x0, x1 + 1):
                mi[x, y, afwImage.LOCAL] = objectPixelVal

        foot = afwDetect.Footprint(afwGeom.SpanSet(spanList))

        hfoot1 = afwDetect.makeHeavyFootprint(self.foot, self.mi)
        hfoot2 = afwDetect.makeHeavyFootprint(foot, mi)

        hsum = afwDetect.mergeHeavyFootprints(hfoot1, hfoot2)

        bb = hsum.getBBox()
        self.assertEqual(bb.getMinX(), 9)
        self.assertEqual(bb.getMaxX(), 15)
        self.assertEqual(bb.getMinY(), 1)
        self.assertEqual(bb.getMaxY(), 3)

        msum = afwImage.MaskedImageF(20, 10)
        hsum.insert(msum)

        sa = msum.getImage().getArray()

        self.assertFloatsEqual(sa[1, 9:13], objectPixelVal[0])
        self.assertFloatsEqual(
            sa[2, 12:14], objectPixelVal[0] + self.objectPixelVal[0])
        self.assertFloatsEqual(sa[2, 10:12], self.objectPixelVal[0])

        sv = msum.getVariance().getArray()

        self.assertFloatsEqual(sv[1, 9:13], objectPixelVal[2])
        self.assertFloatsEqual(
            sv[2, 12:14], objectPixelVal[2] + self.objectPixelVal[2])
        self.assertFloatsEqual(sv[2, 10:12], self.objectPixelVal[2])

        sm = msum.getMask().getArray()

        self.assertFloatsEqual(sm[1, 9:13], objectPixelVal[1])
        self.assertFloatsEqual(
            sm[2, 12:14], objectPixelVal[1] | self.objectPixelVal[1])
        self.assertFloatsEqual(sm[2, 10:12], self.objectPixelVal[1])

        if False:
            import matplotlib
            matplotlib.use('Agg')
            import pylab as plt
            im1 = afwImage.ImageF(bb)
            hfoot1.insert(im1)
            im2 = afwImage.ImageF(bb)
            hfoot2.insert(im2)
            im3 = afwImage.ImageF(bb)
            hsum.insert(im3)
            plt.clf()
            plt.subplot(1, 3, 1)
            plt.imshow(im1.getArray(), interpolation='nearest', origin='lower')
            plt.subplot(1, 3, 2)
            plt.imshow(im2.getArray(), interpolation='nearest', origin='lower')
            plt.subplot(1, 3, 3)
            plt.imshow(im3.getArray(), interpolation='nearest', origin='lower')
            plt.savefig('merge.png')