def makeExposure(imgArray, psfArray, imgVariance): """Convert an image and corresponding PSF into an exposure. Set the (constant) variance plane equal to ``imgVariance``. Parameters ---------- imgArray : `numpy.ndarray` 2D array containing the image. psfArray : `numpy.ndarray` 2D array containing the PSF image. imgVariance : `float` or `numpy.ndarray` Set the variance plane to this value. If an array, must be broadcastable to ``imgArray.shape``. Returns ------- im1ex : `lsst.afw.image.Exposure` The new exposure. """ # All this code to convert the template image array/psf array into an exposure. bbox = geom.Box2I(geom.Point2I(0, 0), geom.Point2I(imgArray.shape[1] - 1, imgArray.shape[0] - 1)) im1ex = afwImage.ExposureD(bbox) im1ex.image.array[:, :] = imgArray im1ex.variance.array[:, :] = imgVariance psfBox = geom.Box2I(geom.Point2I(-12, -12), geom.Point2I(12, 12)) # a 25x25 pixel psf psf = afwImage.ImageD(psfBox) psfBox.shift(geom.Extent2I(-(-size[0]//2), -(-size[1]//2))) # -N//2 != -(N//2) for odd numbers im1_psf_sub = psfArray[psfBox.getMinY():psfBox.getMaxY() + 1, psfBox.getMinX():psfBox.getMaxX() + 1] psf.getArray()[:, :] = im1_psf_sub psfK = afwMath.FixedKernel(psf) psfNew = measAlg.KernelPsf(psfK) im1ex.setPsf(psfNew) wcs = makeWcs() im1ex.setWcs(wcs) return im1ex
def makeExposure(imgArray, psfArray, imgVariance): """! Convert an image numpy.array and corresponding PSF numpy.array into an exposure. Add the (constant) variance plane equal to `imgVariance`. @param imgArray 2-d numpy.array containing the image @param psfArray 2-d numpy.array containing the PSF image @param imgVariance variance of input image @return a new exposure containing the image, PSF and desired variance plane """ # All this code to convert the template image array/psf array into an exposure. bbox = geom.Box2I( geom.Point2I(0, 0), geom.Point2I(imgArray.shape[1] - 1, imgArray.shape[0] - 1)) im1ex = afwImage.ExposureD(bbox) im1ex.getMaskedImage().getImage().getArray()[:, :] = imgArray im1ex.getMaskedImage().getVariance().getArray()[:, :] = imgVariance psfBox = geom.Box2I(geom.Point2I(-12, -12), geom.Point2I(12, 12)) # a 25x25 pixel psf psf = afwImage.ImageD(psfBox) psfBox.shift(geom.Extent2I(size[0] // 2, size[1] // 2)) im1_psf_sub = psfArray[psfBox.getMinX():psfBox.getMaxX() + 1, psfBox.getMinY():psfBox.getMaxY() + 1] psf.getArray()[:, :] = im1_psf_sub psfK = afwMath.FixedKernel(psf) psfNew = measAlg.KernelPsf(psfK) im1ex.setPsf(psfNew) wcs = makeWcs() im1ex.setWcs(wcs) return im1ex
print " Divide exposure by sigma squared = %s" % ( coaddComponent.getSigmaSq(), ) blurredExposure = coaddComponent.getBlurredExposure() blurredMaskedImage = blurredExposure.getMaskedImage() sigmaSq = coaddComponent.getSigmaSq() if saveImages: blurredExposure.writeFits("blurred%s" % (fileName, )) blurredMaskedImage /= sigmaSq if saveImages: blurredExposure.writeFits("scaledBlurred%s" % (fileName, )) print " Remap blurred exposure to match coadd WCS" remappedBlurredMaskedImage = afwImage.MaskedImageD( coaddExposure.getWidth(), coaddExposure.getHeight()) remappedBlurredExposure = afwImage.ExposureD( remappedBlurredMaskedImage, coaddWcs) if saveImages: remappedBlurredExposure.writeFits("remappedBlurred%s" % (fileName, )) nGoodPix = afwMath.warpExposure(remappedBlurredExposure, blurredExposure, afwMath.LanczosWarpingKernel(3)) nPix = coaddExposure.getWidth() * coaddExposure.getHeight() print " Remapped image has %d good pixels (%0.0f %%)" % ( nGoodPix, 100 * nGoodPix / float(nPix)) print " Add remapped blurred exposure to coadd and save updated coadd exposure" coaddUtils.addToCoadd(coaddMaskedImage, depthMap, remappedBlurredExposure.getMaskedImage(), coaddMask) coaddExposure.writeFits(outName)