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

DM-24731: Create a unit test framework for AssembleCoaddTask #393

Merged
merged 3 commits into from
Jul 14, 2020
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
38 changes: 19 additions & 19 deletions python/lsst/pipe/tasks/assembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,14 @@ def countMaskFromFootprint(mask, footprint, bitmask, ignoreMask):
class SafeClipAssembleCoaddConfig(AssembleCoaddConfig, pipelineConnections=AssembleCoaddConnections):
"""Configuration parameters for the SafeClipAssembleCoaddTask.
"""
assembleMeanCoadd = pexConfig.ConfigurableField(
target=AssembleCoaddTask,
doc="Task to assemble an initial Coadd using the MEAN statistic.",
)
assembleMeanClipCoadd = pexConfig.ConfigurableField(
target=AssembleCoaddTask,
doc="Task to assemble an initial Coadd using the MEANCLIP statistic.",
)
clipDetection = pexConfig.ConfigurableField(
target=SourceDetectionTask,
doc="Detect sources on difference between unclipped and clipped coadd")
Expand Down Expand Up @@ -1277,6 +1285,10 @@ def setDefaults(self):
self.sigmaClip = 1.5
self.clipIter = 3
self.statistic = "MEAN"
self.assembleMeanCoadd.statistic = 'MEAN'
self.assembleMeanClipCoadd.statistic = 'MEANCLIP'
self.assembleMeanCoadd.doWrite = False
self.assembleMeanClipCoadd.doWrite = False

def validate(self):
if self.doSigmaClip:
Expand Down Expand Up @@ -1406,6 +1418,8 @@ def __init__(self, *args, **kwargs):
AssembleCoaddTask.__init__(self, *args, **kwargs)
schema = afwTable.SourceTable.makeMinimalSchema()
self.makeSubtask("clipDetection", schema=schema)
self.makeSubtask("assembleMeanClipCoadd")
self.makeSubtask("assembleMeanCoadd")

@utils.inheritDoc(AssembleCoaddTask)
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, *args, **kwargs):
Expand Down Expand Up @@ -1488,25 +1502,11 @@ def buildDifferenceImage(self, skyInfo, tempExpRefList, imageScalerList, weightL
exp : `lsst.afw.image.Exposure`
Difference image of unclipped and clipped coadd wrapped in an Exposure
"""
# Clone and upcast self.config because current self.config is frozen
config = AssembleCoaddConfig()
# getattr necessary because subtasks do not survive Config.toDict()
# exclude connections because the class of self.config.connections is not
# the same as AssembleCoaddConfig.connections, and the connections are not
# needed to run this task anyway.
configIntersection = {k: getattr(self.config, k)
for k, v in self.config.toDict().items()
if (k in config.keys() and k != "connections")}
config.update(**configIntersection)

# statistic MEAN copied from self.config.statistic, but for clarity explicitly assign
config.statistic = 'MEAN'
task = AssembleCoaddTask(config=config)
coaddMean = task.run(skyInfo, tempExpRefList, imageScalerList, weightList).coaddExposure

config.statistic = 'MEANCLIP'
task = AssembleCoaddTask(config=config)
coaddClip = task.run(skyInfo, tempExpRefList, imageScalerList, weightList).coaddExposure
coaddMean = self.assembleMeanCoadd.run(skyInfo, tempExpRefList,
imageScalerList, weightList).coaddExposure

coaddClip = self.assembleMeanClipCoadd.run(skyInfo, tempExpRefList,
imageScalerList, weightList).coaddExposure

coaddDiff = coaddMean.getMaskedImage().Factory(coaddMean.getMaskedImage())
coaddDiff -= coaddClip.getMaskedImage()
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/tasks/dcrAssembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def prepareDcrInputs(self, templateCoadd, warpRefList, weightList):
except Exception as e:
self.log.warn("Unable to calculate restricted PSF, using default coadd PSF: %s" % e)
else:
psf = templateCoadd.psf
psf = templateCoadd.getPsf()
dcrModels = DcrModel.fromImage(templateCoadd.maskedImage,
self.config.dcrNumSubfilters,
filterInfo=filterInfo,
Expand Down