Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of deprecated PsfAttributes #67

Merged
merged 2 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 22 additions & 26 deletions examples/runSubtractExposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@
import os
import optparse
import re
import numpy as num
import numpy as np

import lsst.afw.image as afwImage
import lsst.log.utils as logUtils
import lsst.meas.algorithms as measAlg
from lsst.meas.algorithms import SingleGaussianPsf

import lsst.ip.diffim as ipDiffim
import lsst.ip.diffim.diffimTools as diffimTools


def main():
defDataDir = lsst.utils.getPackageDir('afwdata')
imageProcDir = lsst.utils.getPackageDir('ip_diffim')

defSciencePath = os.path.join(defDataDir, "DC3a-Sim", "sci", "v26-e0", "v26-e0-c011-a10.sci")
defTemplatePath = os.path.join(defDataDir, "DC3a-Sim", "sci", "v5-e0", "v5-e0-c011-a10.sci")
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 = 5
defVerbosity = 0
defFwhm = 3.5
sigma2fwhm = 2. * num.sqrt(2. * num.log(2.))
sigma2fwhm = 2. * np.sqrt(2. * np.log(2.))

usage = """usage: %%prog [options] [scienceExposure [templateExposure [outputExposure]]]]

Expand All @@ -35,7 +34,7 @@ def main():
- the template exposure is convolved, the science exposure is not
- default scienceExposure=%s
- default templateExposure=%s
- default outputExposure=%s
- default outputExposure=%s
""" % (defSciencePath, defTemplatePath, defOutputPath)

parser = optparse.OptionParser(usage)
Expand All @@ -61,7 +60,7 @@ def getArg(ind, defValue):
templatePath = getArg(1, defTemplatePath)
outputPath = getArg(2, defOutputPath)

if sciencePath == None or templatePath == None:
if sciencePath is None or templatePath is None:
parser.print_help()
sys.exit(1)

Expand All @@ -79,30 +78,19 @@ def getArg(ind, defValue):
fwhmS = defFwhm
if options.fwhmS:
if scienceExposure.hasPsf():
width, height = scienceExposure.getPsf().getKernel().getDimensions()
psfAttr = measAlg.PsfAttributes(scienceExposure.getPsf(), width//2, height//2)
s = psfAttr.computeGaussianWidth(psfAttr.ADAPTIVE_MOMENT) # gaussian sigma in pixels
fwhm = s * sigma2fwhm
fwhm = scienceExposure.getPsf().computeShape().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():
width, height = templateExposure.getPsf().getKernel().getDimensions()
psfAttr = measAlg.PsfAttributes(templateExposure.getPsf(), width//2, height//2)
s = psfAttr.computeGaussianWidth(psfAttr.ADAPTIVE_MOMENT) # gaussian sigma in pixels
fwhm = s * sigma2fwhm
fwhm = templateExposure.getPsf().computeShape().getDeterminantRadius() * sigma2fwhm
print('NOTE: Embedded Psf has FwhmT =', fwhm)
print('USING: 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)
Expand All @@ -119,14 +107,21 @@ def getArg(ind, defValue):
[templateExposure.getMaskedImage(),
scienceExposure.getMaskedImage()])
else:
if subconfig.fitForBackground == False:
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.run(templateExposure, scienceExposure, "subtractExposures",
templateFwhmPix=fwhmT, scienceFwhmPix=fwhmS)
results = psfmatch.subtractExposures(templateExposure, scienceExposure,
templateFwhmPix=fwhmT, scienceFwhmPix=fwhmS)

differenceExposure = results.subtractedImage
differenceExposure = results.subtractedExposure
differenceExposure.writeFits(outputPath)

if False:
Expand All @@ -141,5 +136,6 @@ def getArg(ind, defValue):
def run():
main()


if __name__ == '__main__':
run()
14 changes: 4 additions & 10 deletions python/lsst/ip/diffim/modelPsfMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.log as log
import lsst.meas.algorithms as measAlg
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
from .makeKernelBasisList import makeKernelBasisList
Expand Down Expand Up @@ -299,15 +298,10 @@ def run(self, exposure, referencePsfModel, kernelSum=1.0):
result = self._buildCellSet(exposure, referencePsfModel)
kernelCellSet = result.kernelCellSet
referencePsfModel = result.referencePsfModel
width, height = referencePsfModel.getLocalKernel().getDimensions()
psfAttr1 = measAlg.PsfAttributes(exposure.getPsf(), width//2, height//2)
psfAttr2 = measAlg.PsfAttributes(referencePsfModel, width//2, height//2)
s1 = psfAttr1.computeGaussianWidth(psfAttr1.ADAPTIVE_MOMENT) # gaussian sigma in pixels
s2 = psfAttr2.computeGaussianWidth(psfAttr2.ADAPTIVE_MOMENT) # gaussian sigma in pixels
fwhm1 = s1 * sigma2fwhm # science Psf
fwhm2 = s2 * sigma2fwhm # template Psf

basisList = makeKernelBasisList(self.kConfig, fwhm1, fwhm2, metadata=self.metadata)
fwhmScience = exposure.getPsf().computeShape().getDeterminantRadius() * sigma2fwhm
fwhmModel = referencePsfModel.computeShape().getDeterminantRadius() * sigma2fwhm

basisList = makeKernelBasisList(self.kConfig, fwhmScience, fwhmModel, metadata=self.metadata)
spatialSolution, psfMatchingKernel, backgroundModel = self._solve(kernelCellSet, basisList)

if psfMatchingKernel.isSpatiallyVarying():
Expand Down