def readImage(filename=None): """Read an image and background subtract it""" if not filename: dataDir = eups.productDir("afwdata") if not dataDir: raise RuntimeError("You must provide a filename or setup afwdata to run these examples") filename = os.path.join(eups.productDir("afwdata"), "CFHT", "D4", "cal-53535-i-797722_1") bbox = afwGeom.Box2I(afwGeom.Point2I(270, 2530), afwGeom.Extent2I(512, 512)) else: bbox = None mi = afwImage.MaskedImageF(filename, 0, None, bbox, afwImage.LOCAL) mi.setXY0(afwGeom.Point2I(0, 0)) # # Subtract the background. We'd use a canned procedure, but that's in meas/utils/sourceDetection.py. We # can't fix those pesky cosmic rays either, as that's in a dependent product (meas/algorithms) too # bctrl = afwMath.BackgroundControl(afwMath.Interpolate.NATURAL_SPLINE) bctrl.setNxSample(int(mi.getWidth()/256) + 1) bctrl.setNySample(int(mi.getHeight()/256) + 1) sctrl = bctrl.getStatisticsControl() sctrl.setNumSigmaClip(3.0) sctrl.setNumIter(2) im = mi.getImage() try: backobj = afwMath.makeBackground(im, bctrl) except Exception, e: print >> sys.stderr, e, bctrl.setInterpStyle(afwMath.Interpolate.CONSTANT) backobj = afwMath.makeBackground(im, bctrl)
def readImage(filename=None): """Read an image and background subtract it""" if not filename: try: afwDataDir = lsst.utils.getPackageDir("afwdata") except Exception: raise RuntimeError( "You must provide a filename or setup afwdata to run these examples" ) filename = os.path.join(afwDataDir, "CFHT", "D4", "cal-53535-i-797722_1.fits") bbox = afwGeom.Box2I(afwGeom.Point2I(270, 2530), afwGeom.Extent2I(512, 512)) else: bbox = None mi = afwImage.MaskedImageF(filename, bbox=bbox, origin=afwImage.LOCAL) mi.setXY0(afwGeom.Point2I(0, 0)) # # Subtract the background. We'd use a canned procedure, but that's in meas/utils/sourceDetection.py. We # can't fix those pesky cosmic rays either, as that's in a dependent product (meas/algorithms) too # bctrl = afwMath.BackgroundControl(afwMath.Interpolate.NATURAL_SPLINE) bctrl.setNxSample(int(mi.getWidth() / 256) + 1) bctrl.setNySample(int(mi.getHeight() / 256) + 1) sctrl = bctrl.getStatisticsControl() sctrl.setNumSigmaClip(3.0) sctrl.setNumIter(2) im = mi.getImage() try: backobj = afwMath.makeBackground(im, bctrl) except Exception as e: print(e, end=' ', file=sys.stderr) bctrl.setInterpStyle(afwMath.Interpolate.CONSTANT) backobj = afwMath.makeBackground(im, bctrl) im -= backobj.getImageF() # # Find sources # threshold = afwDetect.Threshold(5, afwDetect.Threshold.STDEV) npixMin = 5 # we didn't smooth fs = afwDetect.FootprintSet(mi, threshold, "DETECTED", npixMin) grow, isotropic = 1, False fs = afwDetect.FootprintSet(fs, grow, isotropic) fs.setMask(mi.getMask(), "DETECTED") return mi, fs
def readImage(filename=None): """Read an image and background subtract it""" if not filename: try: afwDataDir = lsst.utils.getPackageDir("afwdata") except Exception: raise RuntimeError( "You must provide a filename or setup afwdata to run these examples" ) filename = os.path.join(afwDataDir, "CFHT", "D4", "cal-53535-i-797722_1") bbox = afwGeom.Box2I(afwGeom.Point2I(270, 2530), afwGeom.Extent2I(512, 512)) else: bbox = None mi = afwImage.MaskedImageF(filename, 0, None, bbox, afwImage.LOCAL) mi.setXY0(afwGeom.Point2I(0, 0)) # # Subtract the background. We'd use a canned procedure, but that's in meas/utils/sourceDetection.py. We # can't fix those pesky cosmic rays either, as that's in a dependent product (meas/algorithms) too # bctrl = afwMath.BackgroundControl(afwMath.Interpolate.NATURAL_SPLINE) bctrl.setNxSample(int(mi.getWidth() / 256) + 1) bctrl.setNySample(int(mi.getHeight() / 256) + 1) sctrl = bctrl.getStatisticsControl() sctrl.setNumSigmaClip(3.0) sctrl.setNumIter(2) im = mi.getImage() try: backobj = afwMath.makeBackground(im, bctrl) except Exception, e: print >> sys.stderr, e, bctrl.setInterpStyle(afwMath.Interpolate.CONSTANT) backobj = afwMath.makeBackground(im, bctrl)
def backgroundSubtract(config, maskedImages): backgrounds = [] t0 = time.time() algorithm = config.algorithm binsize = config.binSize undersample = config.undersampleStyle bctrl = afwMath.BackgroundControl(algorithm) bctrl.setUndersampleStyle(undersample) for maskedImage in maskedImages: bctrl.setNxSample(maskedImage.getWidth() // binsize + 1) bctrl.setNySample(maskedImage.getHeight() // binsize + 1) image = maskedImage.getImage() backobj = afwMath.makeBackground(image, bctrl) image -= backobj.getImageF() backgrounds.append(backobj.getImageF()) del backobj t1 = time.time() logger = Log.getLogger("ip.diffim.backgroundSubtract") logger.debug("Total time for background subtraction : %.2f s", (t1 - t0)) return backgrounds
def backgroundSubtract(config, maskedImages): backgrounds = [] t0 = time.time() algorithm = config.algorithm binsize = config.binSize undersample = config.undersampleStyle bctrl = afwMath.BackgroundControl(algorithm) bctrl.setUndersampleStyle(undersample) for maskedImage in maskedImages: bctrl.setNxSample(maskedImage.getWidth()//binsize + 1) bctrl.setNySample(maskedImage.getHeight()//binsize + 1) image = maskedImage.getImage() backobj = afwMath.makeBackground(image, bctrl) image -= backobj.getImageF() backgrounds.append(backobj.getImageF()) del backobj t1 = time.time() pexLog.Trace("lsst.ip.diffim.backgroundSubtract", 1, "Total time for background subtraction : %.2f s" % (t1-t0)) return backgrounds
def backgroundSubtract(config, maskedImages): """Subtract the background from masked images. Parameters ---------- config : TODO: DM-17458 TODO: DM-17458 maskedImages : `list` of `lsst.afw.image.MaskedImage` TODO: DM-17458 Returns ------- TODO: DM-17458 TODO: DM-17458 """ backgrounds = [] t0 = time.time() algorithm = config.algorithm binsize = config.binSize undersample = config.undersampleStyle bctrl = afwMath.BackgroundControl(algorithm) bctrl.setUndersampleStyle(undersample) for maskedImage in maskedImages: bctrl.setNxSample(maskedImage.getWidth() // binsize + 1) bctrl.setNySample(maskedImage.getHeight() // binsize + 1) image = maskedImage.getImage() backobj = afwMath.makeBackground(image, bctrl) image -= backobj.getImageF() backgrounds.append(backobj.getImageF()) del backobj t1 = time.time() logger = Log.getLogger("ip.diffim.backgroundSubtract") logger.debug("Total time for background subtraction : %.2f s", (t1 - t0)) return backgrounds
def backgroundSubtract(config, maskedImages): """Subtract the background from masked images. Parameters ---------- config : TODO: DM-17458 TODO: DM-17458 maskedImages : `list` of `lsst.afw.image.MaskedImage` TODO: DM-17458 Returns ------- TODO: DM-17458 TODO: DM-17458 """ backgrounds = [] t0 = time.time() algorithm = config.algorithm binsize = config.binSize undersample = config.undersampleStyle bctrl = afwMath.BackgroundControl(algorithm) bctrl.setUndersampleStyle(undersample) for maskedImage in maskedImages: bctrl.setNxSample(maskedImage.getWidth()//binsize + 1) bctrl.setNySample(maskedImage.getHeight()//binsize + 1) image = maskedImage.getImage() backobj = afwMath.makeBackground(image, bctrl) image -= backobj.getImageF() backgrounds.append(backobj.getImageF()) del backobj t1 = time.time() logger = Log.getLogger("ip.diffim.backgroundSubtract") logger.debug("Total time for background subtraction : %.2f s", (t1 - t0)) return backgrounds