Skip to content

Commit

Permalink
Update (minimally) examples/runSubtractExposures.py
Browse files Browse the repository at this point in the history
per new ImagePsfMatchTask API and stack coding standards
  • Loading branch information
yalsayyad committed Jun 28, 2017
1 parent 9f3f0f0 commit 8938b34
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions examples/runSubtractExposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +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
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 @@ -34,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 @@ -60,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 Down Expand Up @@ -91,11 +91,6 @@ def getArg(ind, defValue):
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 @@ -112,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')

# ImagePsfTask 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 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 @@ -134,5 +136,6 @@ def getArg(ind, defValue):
def run():
main()


if __name__ == '__main__':
run()

0 comments on commit 8938b34

Please sign in to comment.