def main(): defVerbosity = 5 usage = """usage: %%prog [options] snap1 snap2 snapdiff Notes: - image arguments are paths to Expsosure (calexp) fits files - snap1 is convolved """ parser = optparse.OptionParser(usage) parser.add_option('--s1', help='snap1') parser.add_option('--s2', help='snap2') parser.add_option('--sdiff', help='snap2 - snap1.x.kernel') parser.add_option('--warp', action='store_true', default=False, help='astrometrically warp snap1') parser.add_option('-v', '--verbosity', type=int, default=defVerbosity, help='verbosity of Trace messages') (options, args) = parser.parse_args() if None in (options.s1, options.s2, options.sdiff): parser.print_help() sys.exit(1) print('Verbosity =', options.verbosity) logUtils.trace_set_at("lsst.ip.diffim", options.verbosity) snap1Exp = afwImage.ExposureF(options.s1) snap2Exp = afwImage.ExposureF(options.s2) config = ipDiffim.SnapPsfMatchTask.ConfigClass() config.kernel.name = "AL" subconfig = config.kernel.active snapDiff = subtractSnaps(snap1Exp, snap2Exp, subconfig, doWarping=options.warp) snapDiff.writeFits(options.sdiff)
def testTraceSetAt(self): log_name = "lsst.afw" trace_set_at(log_name, 2) trace2_log = getLogger(f"TRACE2.{log_name}") trace3_log = getLogger(f"TRACE3.{log_name}") self.assertEqual(trace2_log.getEffectiveLevel(), logging.DEBUG) self.assertEqual(trace3_log.getEffectiveLevel(), logging.INFO) # Check that child loggers are affected. log_name = "lsst.daf" child3_log = getLogger("TRACE3.lsst.daf") child2_log = getLogger("TRACE2.lsst.daf") self.assertEqual(child3_log.getEffectiveLevel(), logging.WARNING) self.assertEqual(child2_log.getEffectiveLevel(), logging.WARNING) trace_set_at("lsst", 2) self.assertEqual(child3_log.getEffectiveLevel(), logging.INFO) self.assertEqual(child2_log.getEffectiveLevel(), logging.DEBUG) # Also check the root logger. trace_set_at("", 3) self.assertEqual(trace3_log.getEffectiveLevel(), logging.INFO) self.assertEqual(getLogger("TRACE3.test").getEffectiveLevel(), logging.DEBUG)
import os import sys import unittest import lsst.utils.tests as tests import lsst.utils import lsst.afw.display as afwDisplay import lsst.afw.geom as afwGeom import lsst.afw.image as afwImage import lsst.afw.math as afwMath import lsst.ip.diffim as ipDiffim import lsst.ip.diffim.diffimTools as diffimTools import lsst.utils.logging as logUtils import lsst.pex.config as pexConfig logUtils.trace_set_at("lsst.ip.diffim", 6) logger = logUtils.getLogger("lsst.ip.diffim.compareLambdaTypes") logger.setLevel(logging.DEBUG) display = True writefits = False # This one compares DeltaFunction kernels of different types; iterate lambdaVal for different strengths CFHTTORUN = 'cal-53535-i-797722_1' class DiffimTestCases(unittest.TestCase): # D = I - (K.x.T + bg) def setUp(self, CFHT=True):
def main(): defDataDir = lsst.utils.getPackageDir('afwdata') defSciencePath = os.path.join(defDataDir, "DC3a-Sim", "sci", "v26-e0", "v26-e0-c011-a10.sci.fits") defTemplatePath = os.path.join(defDataDir, "DC3a-Sim", "sci", "v5-e0", "v5-e0-c011-a10.sci.fits") defOutputPath = 'diffExposure.fits' defVerbosity = 0 defFwhm = 3.5 sigma2fwhm = 2. * np.sqrt(2. * np.log(2.)) usage = """usage: %%prog [options] [scienceExposure [templateExposure [outputExposure]]]] Notes: - image arguments are paths to Expoure fits files - image arguments must NOT include the final _img.fits - the result is science image - template image - the template exposure is convolved, the science exposure is not - default scienceExposure=%s - default templateExposure=%s - default outputExposure=%s """ % (defSciencePath, defTemplatePath, defOutputPath) parser = optparse.OptionParser(usage) parser.add_option('-v', '--verbosity', type=int, default=defVerbosity, help='verbosity of Trace messages') parser.add_option('-d', '--display', action='store_true', default=False, help='display the images') parser.add_option('-b', '--bg', action='store_true', default=False, help='subtract backgrounds using afw') parser.add_option('--fwhmS', type=float, help='Science Image Psf Fwhm (pixel)') parser.add_option('--fwhmT', type=float, help='Template Image Psf Fwhm (pixel)') (options, args) = parser.parse_args() def getArg(ind, defValue): if ind < len(args): return args[ind] return defValue sciencePath = getArg(0, defSciencePath) templatePath = getArg(1, defTemplatePath) outputPath = getArg(2, defOutputPath) if sciencePath is None or templatePath is None: parser.print_help() sys.exit(1) print('Science exposure: ', sciencePath) print('Template exposure:', templatePath) print('Output exposure: ', outputPath) templateExposure = afwImage.ExposureF(templatePath) scienceExposure = afwImage.ExposureF(sciencePath) config = ipDiffim.ImagePsfMatchTask.ConfigClass() config.kernel.name = "AL" subconfig = config.kernel.active fwhmS = defFwhm if options.fwhmS: if scienceExposure.hasPsf(): sciPsf = scienceExposure.getPsf() fwhm = sciPsf.computeShape(sciPsf.getAveragePosition() ).getDeterminantRadius() * sigma2fwhm print('NOTE: Embedded Psf has FwhmS =', fwhm) print('USING: FwhmS =', options.fwhmS) fwhmS = options.fwhmS fwhmT = defFwhm if options.fwhmT: if templateExposure.hasPsf(): templPsf = templateExposure.getPsf() fwhm = templPsf.computeShape(templPsf.getAveragePosition() ).getDeterminantRadius() * sigma2fwhm print('NOTE: Embedded Psf has FwhmT =', fwhm) print('USING: FwhmT =', options.fwhmT) fwhmT = options.fwhmT bgSub = False if options.bg: print('Background subtract =', options.bg) bgSub = True if options.verbosity > 0: print('Verbosity =', options.verbosity) logUtils.trace_set_at("lsst.ip.diffim", options.verbosity) #### if bgSub: diffimTools.backgroundSubtract(subconfig.afwBackgroundConfig, [ templateExposure.getMaskedImage(), scienceExposure.getMaskedImage() ]) else: if not subconfig.fitForBackground: print('NOTE: no background subtraction at all is requested') # ImagePsfMatchTask requires a candidateList or that the exposoure have a PSF for detection if not scienceExposure.hasPsf(): sigmaS = fwhmS / sigma2fwhm kSize = int(6 * sigmaS) # minimum kernel size for FWHM oddKSize = kSize + 1 if kSize % 2 == 0 else kSize scienceExposure.setPsf(SingleGaussianPsf(oddKSize, oddKSize, sigmaS)) psfmatch = ipDiffim.ImagePsfMatchTask(config) results = psfmatch.subtractExposures(templateExposure, scienceExposure, templateFwhmPix=fwhmT, scienceFwhmPix=fwhmS) differenceExposure = results.subtractedExposure differenceExposure.writeFits(outputPath) if False: psfMatchingKernel = results.psfMatchingKernel backgroundModel = results.backgroundModel kernelCellSet = results.kernelCellSet diffimTools.writeKernelCellSet(kernelCellSet, psfMatchingKernel, backgroundModel, re.sub('.fits', '', outputPath))
def main(): defSciencePath = None defTemplatePath = None defOutputPath = 'diffImage.fits' defVerbosity = 5 defFwhm = 3.5 usage = """usage: %%prog [options] [scienceImage [templateImage [outputImage]]]] Notes: - image arguments are paths to MaskedImage fits files - image arguments must NOT include the final _img.fits - the result is science image - template image - the template image is convolved, the science image is not - default scienceMaskedImage=%s - default templateMaskedImage=%s - default outputImage=%s """ % (defSciencePath, defTemplatePath, defOutputPath) parser = optparse.OptionParser(usage) parser.add_option('-v', '--verbosity', type=int, default=defVerbosity, help='verbosity of Trace messages') parser.add_option('-d', '--display', action='store_true', default=False, help='display the images') parser.add_option('-b', '--bg', action='store_true', default=False, help='subtract backgrounds') parser.add_option('--fwhmS', type=float, help='Science Image Psf Fwhm (pixel)') parser.add_option('--fwhmT', type=float, help='Template Image Psf Fwhm (pixel)') parser.add_option('-w', '--writeOutput', action='store_true', default=False, help='Write out the subtracted image?') (options, args) = parser.parse_args() def getArg(ind, defValue): if ind < len(args): return args[ind] return defValue sciencePath = getArg(0, defSciencePath) templatePath = getArg(1, defTemplatePath) outputPath = getArg(2, defOutputPath) if sciencePath is None or templatePath is None: parser.print_help() sys.exit(1) print('Science image: ', sciencePath) print('Template image:', templatePath) print('Output image: ', outputPath) fwhmS = defFwhm if options.fwhmS: print('FwhmS =', options.fwhmS) fwhmS = options.fwhmS fwhmT = defFwhm if options.fwhmT: print('Fwhmt =', options.fwhmT) fwhmT = options.fwhmT display = False if options.display: print('Display =', options.display) display = True bgSub = False if options.bg: print('Background subtract =', options.bg) bgSub = True if options.verbosity > 0: print('Verbosity =', options.verbosity) logUtils.trace_set_at("lsst.ip.diffim", options.verbosity) writeOutput = False if options.writeOutput: print('writeOutput =', options.writeOutput) writeOutput = True #### templateExposure = afwImage.ExposureF(templatePath) scienceExposure = afwImage.ExposureF(sciencePath) templateMaskedImage = templateExposure.getMaskedImage() scienceMaskedImage = scienceExposure.getMaskedImage() config = ipDiffim.ImagePsfMatchTask.ConfigClass() config.kernel.name = "AL" subconfig = config.kernel.active if bgSub: diffimTools.backgroundSubtract( subconfig.afwBackgroundConfig, [templateMaskedImage, scienceMaskedImage]) else: if not subconfig.fitForBackground: print('NOTE: no background subtraction at all is requested') psfmatch = ipDiffim.ImagePsfMatchTask(config) candidateList = psfmatch.makeCandidateList(templateExposure, scienceExposure, subconfig.kernelSize) results = psfmatch.subtractMaskedImages(templateMaskedImage, scienceMaskedImage, candidateList, templateFwhmPix=fwhmT, scienceFwhmPix=fwhmS) differenceMaskedImage = results.subtractedMaskedImage if writeOutput: differenceMaskedImage.writeFits(outputPath) if False: spatialKernel = results.psfMatchingKernel print(spatialKernel.getSpatialParameters()) if display: afwDisplay.Display().mtv(differenceMaskedImage, title="Difference Masked Image")
# see <http://www.lsstcorp.org/LegalNotices/>. # import os import unittest import lsst.utils.tests import lsst.utils import lsst.afw.image as afwImage import lsst.afw.math as afwMath import lsst.geom as geom import lsst.ip.diffim as ipDiffim import lsst.utils.logging as logUtils verbosity = 3 logUtils.trace_set_at("lsst.ip.diffim", verbosity) # known input images try: defDataDir = lsst.utils.getPackageDir('afwdata') except Exception: defDataDir = None # This one tests convolve and subtract class DiffimTestCases(lsst.utils.tests.TestCase): # D = I - (K.x.T + bg) def setUp(self): self.config = ipDiffim.ImagePsfMatchTask.ConfigClass()