示例#1
0
    def process(self, clipboard):
        """
        Run image subtraction
        """
        self.log.log(Log.INFO, "Running image subtraction")

        # grab exposures from clipboard
        templateExposure = clipboard.get(
            self.policy.getString("inputKeys.templateExposureKey"))
        scienceExposure = clipboard.get(
            self.policy.getString("inputKeys.scienceExposureKey"))

        # run image subtraction
        psfMatch = ipDiffim.ImagePsfMatch(self.diffImPolicy)
        results = psfMatch.subtractExposures(templateExposure, scienceExposure)

        # parse results
        differenceExposure, spatialKernel, backgroundModel, kernelCellSet = results

        #output products
        clipboard.put(self.policy.get("outputKeys.differenceExposureKey"),
                      differenceExposure)
        clipboard.put(self.policy.get("outputKeys.psfMatchingKernelKey"),
                      spatialKernel)
        clipboard.put(self.policy.get("outputKeys.backgroundFunctionKey"),
                      backgroundModel)
示例#2
0
    def match(self, template, input):
        """Convolve template to match input

        @param[in] template Template exposure
        @param[in] input Input exposure
        @output convolved template exposure
        """
        policy = self.config['diff'].getPolicy()
        matcher = diffim.ImagePsfMatch(policy)
        convolved, kernel, bg, cells = matcher.matchExposures(template,
                                                              input,
                                                              doWarping=False)
        # XXX dropping kernel, bg, cells on the floor
        return convolved
    def process(self, clipboard):
        """
        Run image subtraction
        """
        self.log.log(Log.INFO, "Running snap image subtraction")

        # grab exposures from clipboard
        snap0Exposure = clipboard.get(
            self.policy.getString("inputKeys.snap0ExposureKey"))
        snap1Exposure = clipboard.get(
            self.policy.getString("inputKeys.snap1ExposureKey"))

        # run image subtraction
        snapPolicy = ipDiffim.modifyForSnapSubtraction(self.diffImPolicy)
        psfmatch = ipDiffim.ImagePsfMatch(snapPolicy)
        results = psfmatch.subtractExposures(snap0Exposure,
                                             snap1Exposure,
                                             doWarping=False)
        snapDiff, kernelModel, bgModel, kernelCellSet = results

        # ACB debugging
        if False:
            import lsst.afw.image as afwImage
            kimage = afwImage.ImageD(kernelModel.getDimensions())
            kernelModel.computeImage(kimage, False)
            kimage.writeFits("/tmp/kernel.fits")

            snap0Exposure.writeFits("/tmp/exp0.fits")
            snap1Exposure.writeFits("/tmp/exp1.fits")
            snapDiff.writeFits("/tmp/diff.fits")

            # straight "-=" for comparison
            mi0 = snap0Exposure.getMaskedImage()
            mi1 = snap1Exposure.getMaskedImage()
            diffMI0 = afwImage.MaskedImageF(mi1, True)
            diffMI0 -= mi0
            diffMI0.writeFits("/tmp/sub.fits")

        #output products
        clipboard.put(self.policy.get("outputKeys.differenceExposureKey"),
                      snapDiff)
        clipboard.put(self.policy.get("outputKeys.kernelModelKey"),
                      kernelModel)
        clipboard.put(self.policy.get("outputKeys.backgroundModelKey"),
                      bgModel)
        clipboard.put(self.policy.get("outputKeys.kernelCellSetKey"),
                      kernelCellSet)
示例#4
0
def main():
    imageProcDir = lsst.utils.getPackageDir('ip_diffim')

    defSciencePath  = None
    defTemplatePath = None
    defOutputPath   = 'matchedImage.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 matched 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)')
                      
    (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 == None or templatePath == 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
        Trace.setVerbosity('lsst.ip.diffim', options.verbosity)
        
    ####
        
    templateMaskedImage = afwImage.MaskedImageF(templatePath)
    scienceMaskedImage  = afwImage.MaskedImageF(sciencePath)

    config = ipDiffim.ImagePsfMatch.ConfigClass()
    config.kernel.name = "AL"
    subconfig = config.kernel.active

    if bgSub:
        diffimTools.backgroundSubtract(subconfig.afwBackgroundConfig,
                                       [templateMaskedImage, scienceMaskedImage])
    else:
        if subconfig.fitForBackground == False:
            print 'NOTE: no background subtraction at all is requested'

    psfmatch = ipDiffim.ImagePsfMatch(subconfig)
    results  = psfmatch.matchMaskedImages(templateMaskedImage, scienceMaskedImage,
                                          templateFwhmPix = fwhmT, scienceFwhmPix = fwhmS)

    matchMaskedImage = results[0]
    matchMaskedImage.writeFits(outputPath)

    if False:
        spatialKernel = results[1]
        print spatialKernel.getSpatialParameters()
    
    if display:
        ds9.mtv(differenceMaskedImage)