Example #1
0
    def writeDefects(self, maskFile, ccd, format=None):
        """Given a Mask, find the defects for each amp in the specified CCD (0-indexed).
        If format is provided, it's expected to be used as "format % (ccd, amp)" to generate
        a .paf filename to write the defects too.  If it's "-", write to stdout"""

        # Metadata should have validity range keywords, but it doesn't.
        if False:
            metaData = afwImage.readMetadata(maskFile, 0)

        hdu = ccd + 2
        im = afwImage.ImageF(maskFile, hdu)
        im -= 1
        im *= -1
        mask = afwImage.MaskU(im.getBBox(afwImage.PARENT))
        mask.set(0x0)
        mask = afwImage.makeMaskedImage(im, mask)

        for amp in self.ampList():
            subMask = mask.Factory(mask, self.getTrimSecBBox(amp),
                                   afwImage.LOCAL)

            ds = afwDetection.makeFootprintSet(subMask,
                                               afwDetection.Threshold(0.5),
                                               "INTRP")

            if False:
                ds9.setDefaultFrame(amp)

                ds9.mtv(subMask)
                ds9.dot("Amp %d" % amp, 0, 0)

            if not format:
                return

            if format == "-":
                fd = sys.stdout
            else:
                fd = open(format % (ccd, amp), "w")

            print >> fd, """\
#<?cfg paf policy ?>
#
# Defects for CCD%03d amp %02d generated from %s, HDU %d
#
# Coordinates are trimmed and per-amp not per-CCD.  If you change this, the ISR will have to change
#
# Generated by $HeadURL$
#
""" % (ccd, amp, maskFile, hdu),

            for foot in ds.getFootprints():
                afwDetectionUtils.writeFootprintAsDefects(fd, foot)
Example #2
0
    def writeDefects(self, maskFile, ccd, format=None):
        """Given a Mask, find the defects for each amp in the specified CCD (0-indexed).
        If format is provided, it's expected to be used as "format % (ccd, amp)" to generate
        a .paf filename to write the defects too.  If it's "-", write to stdout"""

        # Metadata should have validity range keywords, but it doesn't.
        if False:
            metaData = afwImage.readMetadata(maskFile, 0)

        hdu = ccd + 2
        im = afwImage.ImageF(maskFile, hdu)
        im -= 1
        im *= -1
        mask = afwImage.MaskU(im.getBBox(afwImage.PARENT)); mask.set(0x0)
        mask = afwImage.makeMaskedImage(im, mask)

        for amp in self.ampList():
            subMask = mask.Factory(mask, self.getTrimSecBBox(amp), afwImage.LOCAL)

            ds = afwDetection.makeFootprintSet(subMask, afwDetection.Threshold(0.5), "INTRP")

            if False:
                ds9.setDefaultFrame(amp)
                
                ds9.mtv(subMask)
                ds9.dot("Amp %d" % amp, 0, 0)

            if not format:
                return

            if format == "-":
                fd = sys.stdout
            else:
                fd = open(format % (ccd, amp), "w")

            print >> fd, """\
#<?cfg paf policy ?>
#
# Defects for CCD%03d amp %02d generated from %s, HDU %d
#
# Coordinates are trimmed and per-amp not per-CCD.  If you change this, the ISR will have to change
#
# Generated by $HeadURL$
#
""" % (ccd, amp, maskFile, hdu),
                          
            for foot in ds.getFootprints():
                afwDetectionUtils.writeFootprintAsDefects(fd, foot)
Example #3
0
    def testWriteDefect(self):
        """Write a Footprint as a set of Defects"""
        region = afwGeom.Box2I(afwGeom.Point2I(0,0), afwGeom.Extent2I(12,10))
        foot = afwDetect.Footprint(0, region)
        for y, x0, x1 in [(3, 3, 5), (3, 7, 7),
                          (4, 2, 3), (4, 5, 7),
                          (5, 2, 3), (5, 5, 8),
                          (6, 3, 5),
                          ]:
            foot.addSpan(y, x0, x1)

        if True:
            fd = open("/dev/null", "w")
        else:
            fd = sys.stdout

        afwDetectUtils.writeFootprintAsDefects(fd, foot)
Example #4
0
    def testWriteDefect(self):
        """Write a Footprint as a set of Defects"""
        region = afwGeom.Box2I(afwGeom.Point2I(0,0), afwGeom.Extent2I(12,10))
        foot = afwDetect.Footprint(0, region)
        for y, x0, x1 in [(3, 3, 5), (3, 7, 7),
                          (4, 2, 3), (4, 5, 7),
                          (5, 2, 3), (5, 5, 8),
                          (6, 3, 5),
                          ]:
            foot.addSpan(y, x0, x1)

        if True:
            fd = open("/dev/null", "w")
        else:
            fd = sys.stdout

        afwDetectUtils.writeFootprintAsDefects(fd, foot)
def MaskPolicyFromImage(fitsfile, policyfile):
    # input bad pixel image
    maskImage = afwImage.ImageF(fitsfile)

    # turn into masked image for detection
    maskedImage = afwImage.MaskedImageF(maskImage)

    # find bad regions
    thresh = afwDetection.Threshold(0.5)
    ds = afwDetection.DetectionSetF(maskedImage, thresh)
    fpList = ds.getFootprints()

    buff = open(policyfile, 'w')
    buff.write('#<?cfg paf policy ?>\n')
    buff.write('# Bad pixels for CFHT image %s\n' % (fitsfile))
    buff.write('# Coordinates are for untrimmed image\n')

    for i in range(fpList.size()):
        afwDetectionUtils.writeFootprintAsDefects(buff, fpList[i])
    buff.close()
def MaskPolicyFromImage(fitsfile, policyfile):
    # input bad pixel image
    maskImage   = afwImage.ImageF(fitsfile)

    # turn into masked image for detection
    maskedImage = afwImage.MaskedImageF(maskImage)

    # find bad regions
    thresh    = afwDetection.Threshold(0.5)
    ds        = afwDetection.DetectionSetF(maskedImage, thresh)
    fpList    = ds.getFootprints()

    buff = open(policyfile, 'w')
    buff.write('#<?cfg paf policy ?>\n')
    buff.write('# Bad pixels for CFHT image %s\n' % (fitsfile))
    buff.write('# Coordinates are for untrimmed image\n')
    
    for i in range(fpList.size()):
        afwDetectionUtils.writeFootprintAsDefects(buff, fpList[i])
    buff.close()
Example #7
0
    def testWriteDefect(self):
        """Write a Footprint as a set of Defects"""
        region = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(12, 10))
        spanSet = afwGeom.SpanSet([afwGeom.Span(*span) for span in [(3, 3, 5),
                                                                    (3, 7, 7),
                                                                    (4, 2, 3),
                                                                    (4, 5, 7),
                                                                    (5, 2, 3),
                                                                    (5, 5, 8),
                                                                    (6, 3, 5)]])
        foot = afwDetect.Footprint(spanSet, region)

        openedFile = False
        if True:
            fd = open("/dev/null", "w")
            openedFile = True
        else:
            fd = sys.stdout

        afwDetectUtils.writeFootprintAsDefects(fd, foot)
        if openedFile:
            fd.close()