Skip to content

Commit

Permalink
add DecorrelateALKernelTask as a subtask
Browse files Browse the repository at this point in the history
Updates from code review
  • Loading branch information
djreiss committed Jun 29, 2016
1 parent c151a0d commit 6002c36
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions python/lsst/pipe/tasks/imageDifference.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
from lsst.ip.diffim import ImagePsfMatchTask, DipoleAnalysis, \
SourceFlagChecker, KernelCandidateF, cast_KernelCandidateF, makeKernelBasisList, \
KernelCandidateQa, DiaCatalogSourceSelectorTask, DiaCatalogSourceSelectorConfig, \
GetCoaddAsTemplateTask, GetCalexpAsTemplateTask, DipoleFitTask
GetCoaddAsTemplateTask, GetCalexpAsTemplateTask, DipoleFitTask, DecorrelateALKernelTask
import lsst.ip.diffim.diffimTools as diffimTools
import lsst.ip.diffim.utils as diUtils
from lsst.ip.diffim.imageDecorrelation import decorrelateExposure

FwhmPerSigma = 2 * math.sqrt(2 * math.log(2))
IqrToSigma = 0.741
Expand Down Expand Up @@ -67,7 +66,7 @@ class ImageDifferenceConfig(pexConfig.Config):
"Ignored if doPreConvolve false.")
doDetection = pexConfig.Field(dtype=bool, default=True, doc="Detect sources?")
doDecorrelation = pexConfig.Field(dtype=bool, default=False,
doc="Perform diffim decorrelation to undo pixel correlation due to convolution? "
doc="Perform diffim decorrelation to undo pixel correlation due to A&L kernel convolution? "
"If True, also update the diffim PSF.")
doMerge = pexConfig.Field(dtype=bool, default=True,
doc="Merge positive and negative diaSources with grow radius set by growFootprint")
Expand Down Expand Up @@ -108,6 +107,10 @@ class ImageDifferenceConfig(pexConfig.Config):
target=ImagePsfMatchTask,
doc="Warp and PSF match template to exposure, then subtract",
)
decorrelate = pexConfig.ConfigurableField(
target=DecorrelateALKernelTask,
doc="Decorrelate effects of A&L kernel convolution on image difference, only if doSubtract is True",
)
detection = pexConfig.ConfigurableField(
target=SourceDetectionTask,
doc="Low-threshold detection for final measurement",
Expand Down Expand Up @@ -167,6 +170,10 @@ def setDefaults(self):
# DiaSource Detection
self.detection.thresholdPolarity = "both"
self.detection.thresholdValue = 5.5
# If decorrelation is turned on, no need to "hack" the detection threshold to decrease the number of
# false detections, so set it back to 5.0
if self.doDecorrelation and self.doSubtract:
self.detection.thresholdValue = 5.0
self.detection.reEstimateBackground = False
self.detection.thresholdType = "pixel_stdev"

Expand Down Expand Up @@ -212,6 +219,7 @@ def __init__(self, butler=None, **kwargs):
pipeBase.CmdLineTask.__init__(self, **kwargs)
self.makeSubtask("subtract")
self.makeSubtask("getTemplate")
self.makeSubtask("decorrelate")

if self.config.doUseRegister:
self.makeSubtask("register")
Expand Down Expand Up @@ -516,10 +524,13 @@ def run(self, sensorRef, templateIdList=None):
template = self.getTemplate.run(exposure, sensorRef, templateIdList=templateIdList)
subtractedExposure.setPsf(template.exposure.getPsf())

# If doSubtract is False, then subtractedExposure was fetched from disk (above), thus it may have
# already been decorrelated. Thus, we do not do decorrelation if doSubtract is False.
if self.config.doDecorrelation and self.config.doSubtract:
self.log.info("Running diffim decorrelation; updating diffim PSF.")
subtractedExposure, _ = decorrelateExposure(templateExposure, exposure, subtractedExposure,
subtractRes.psfMatchingKernel, self.log)
decorrResult = self.decorrelate.run(templateExposure, exposure,
subtractedExposure,
subtractRes.psfMatchingKernel)
subtractedExposure = decorrResult.correctedExposure

if self.config.doDetection:
self.log.info("Running diaSource detection")
Expand Down

0 comments on commit 6002c36

Please sign in to comment.