def writeDefectsFile(bboxList, path): maskBBox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(1,1)) for box in bboxList: maskBBox.include(box) defectsMaskedImage = afwImage.MaskedImageF(maskBBox) defectList = measAlg.DefectListT() for bbox in bboxList: nd = measAlg.Defect(bbox) defectList.append(nd) maskPixelsFromDefectList(defectsMaskedImage, defectList, maskName='BAD') defectsMaskedImage.getMask().writeFits(MaskFileName) print("wrote %s with bbox %s" % (MaskFileName, maskBBox,))
def writeDefectsFile(bboxList, path): maskBBox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(1, 1)) for box in bboxList: maskBBox.include(box) defectsMaskedImage = afwImage.MaskedImageF(maskBBox) defectList = measAlg.DefectListT() for bbox in bboxList: nd = measAlg.Defect(bbox) defectList.append(nd) maskPixelsFromDefectList(defectsMaskedImage, defectList, maskName='BAD') defectsMaskedImage.getMask().writeFits(MaskFileName) print("wrote %s with bbox %s" % (MaskFileName, maskBBox,))
def testDefectBase(self): """Test DefectBases""" defectList = [] ccdImage = afwImage.MaskedImageF(250, 225) ccdImage.set(self.setVal, 0, self.setVal) # # Insert some defects into the Ccd # for x0, y0, x1, y1 in [ (34, 0, 35, 80), (34, 81, 34, 100), (180, 100, 182, 130), ]: bbox = afwGeom.Box2I(afwGeom.Point2I(x0, y0), afwGeom.Point2I(x1, y1)) defectList.append(measAlg.Defect(bbox)) bad = ccdImage.Factory(ccdImage, bbox, afwImage.LOCAL) bad.set(100) ipIsr.maskPixelsFromDefectList(ccdImage, defectList, maskName='BAD') mask = ccdImage.getMask() bitMask = mask.getPlaneBitMask('BAD') for d in defectList: bad = mask.Factory(mask, d.getBBox(), afwImage.LOCAL) self.assertTrue((bad.getArray() & bitMask == bitMask).all()) if display: ds9.mtv(ccdImage.getImage(), title="Defects") for d in defectList: displayUtils.drawBBox(d.getBBox(), ctype=ds9.CYAN, borderWidth=.5) ds9.incrDefaultFrame() ipIsr.interpolateDefectList(ccdImage, defectList, 2.) im = ccdImage.getImage() for d in defectList: intrp = im.Factory(im, d.getBBox()) expect = np.empty_like(intrp.getArray()) expect[:] = self.setVal self.assertImagesEqual(intrp, expect) if display: ds9.mtv(ccdImage.getImage(), title="Defects Interpolated") for d in defectList: displayUtils.drawBBox(d.getBBox(), ctype=ds9.CYAN, borderWidth=.5) ds9.incrDefaultFrame()
def testDefectBase(self): """Test DefectBases""" defectList = [] ccdImage = afwImage.MaskedImageF(250, 225) ccdImage.set(self.setVal, 0, self.setVal) # # Insert some defects into the Ccd # for x0, y0, x1, y1 in [ (34, 0, 35, 80), (34, 81, 34, 100), (180, 100, 182, 130), ]: bbox = afwGeom.Box2I(afwGeom.Point2I(x0, y0), afwGeom.Point2I(x1, y1)) defectList.append(measAlg.Defect(bbox)) bad = ccdImage.Factory(ccdImage, bbox, afwImage.LOCAL) bad.set(100) ipIsr.maskPixelsFromDefectList(ccdImage, defectList, maskName='BAD') mask = ccdImage.getMask() bitMask = mask.getPlaneBitMask('BAD') for d in defectList: bad = mask.Factory(mask, d.getBBox(), afwImage.LOCAL) self.assertTrue((bad.getArray() & bitMask == bitMask).all()) if display: disp = afwDisplay.Display() disp.mtv(ccdImage.getImage(), title=self._testMethodName + ": Defects") for d in defectList: afwDisplay.utils.drawBBox(d.getBBox(), ctype=afwDisplay.CYAN, borderWidth=.5) disp.incrDefaultFrame() ipIsr.interpolateDefectList(ccdImage, defectList, 2.) im = ccdImage.getImage() for d in defectList: intrp = im.Factory(im, d.getBBox()) expect = np.empty_like(intrp.getArray()) expect[:] = self.setVal self.assertImagesEqual(intrp, expect) if display: disp = afwDisplay.Display() disp.mtv(ccdImage.getImage(), title=self._testMethodName + ": Defects Interpolated") for d in defectList: afwDisplay.utils.drawBBox(d.getBBox(), ctype=afwDisplay.CYAN, borderWidth=.5) disp.incrDefaultFrame()