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-34910: Test DCR correction with ComCam #86

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions python/lsst/drp/tasks/assemble_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ def __init__(self, *, config=None):
self.outputs.remove("inputMap")

if not self.config.doWriteArtifactMasks:
self.outputs.remove("artifactMasks")
try:
self.outputs.remove("artifactMasks")
except KeyError:
pass


class AssembleCoaddConfig(
Expand Down Expand Up @@ -847,9 +850,12 @@ def assembleMetadata(self, coaddExposure, warpRefList, weightList, psfMatchedWar
coaddInputs.visits.reserve(len(warpList))

# psfMatchedWarpRefList should be empty except in CompareWarpCoadd.
if self._doUsePsfMatchedPolygons:
# Set validPolygons for warp before addVisitToCoadd
self._setValidPolygons(warpList, psfMatchedWarpRefList)
try:
if self._doUsePsfMatchedPolygons:
# Set validPolygons for warp before addVisitToCoadd
self._setValidPolygons(warpList, psfMatchedWarpRefList)
except TypeError:
pass

for warp, weight in zip(warpList, weightList):
self.inputRecorder.addVisitToCoadd(coaddInputs, warp, weight)
Expand Down
56 changes: 30 additions & 26 deletions python/lsst/drp/tasks/dcr_assemble_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class DcrAssembleCoaddConnections(
AssembleCoaddConnections,
dimensions=("tract", "patch", "band", "skymap"),
defaultTemplates={
"inputWarpName": "deep",
"inputCoaddName": "deep",
"inputWarpName": "goodSeeing",
"inputCoaddName": "goodSeeing",
"outputCoaddName": "dcr",
"warpType": "direct",
"warpTypeSuffix": "",
Expand Down Expand Up @@ -240,8 +240,8 @@ def setDefaults(self):
self.assembleStaticSkyModel.retarget(CompareWarpAssembleCoaddTask)
self.doNImage = True
self.assembleStaticSkyModel.warpType = self.warpType
# The deepCoadd and nImage files will be overwritten by this Task, so
# don't write them the first time.
# The goodSeeingCoadd and nImage files will be overwritten by this
# Task, so don't write them the first time.
self.assembleStaticSkyModel.doNImage = False
self.assembleStaticSkyModel.doWrite = False
self.detectPsfSources.returnOriginalFootprints = False
Expand Down Expand Up @@ -278,8 +278,8 @@ class DcrAssembleCoaddTask(CompareWarpAssembleCoaddTask):
For full details of the mathematics and algorithm, please see
DMTN-037: DCR-matched template generation (https://dmtn-037.lsst.io).

This Task produces a DCR-corrected deepCoadd, as well as a dcrCoadd for
each subfilter used in the iterative calculation.
This Task produces a DCR-corrected goodSeeingCoadd, as well as a dcrCoadd
for each subfilter used in the iterative calculation.
It begins by dividing the bandpass-defining filter into N equal bandwidth
"subfilters", and divides the flux in each pixel from an initial coadd
equally into each as a "dcrModel". Because the airmass and parallactic
Expand Down Expand Up @@ -351,9 +351,8 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):

# Construct list of input Deferred Datasets
warpRefList = inputData["inputWarps"]
psfMatchedWarpRefList = inputData["psfMatchedWarps"]

inputs = self.prepareInputs(warpRefList, psfMatchedWarpRefList)
inputs = self.prepareInputs(warpRefList, inputData["skyInfo"].bbox)
self.log.info("Found %d %s", len(inputs.warpRefList), self.getTempExpDatasetName(self.warpType))
if len(inputs.warpRefList) == 0:
self.log.warning("No coadd temporary exposures found")
Expand All @@ -365,7 +364,6 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
warpRefList=inputs.warpRefList,
imageScalerList=inputs.imageScalerList,
weightList=inputs.weightList,
psfMatchedWarpRefList=inputs.psfMatchedWarpRefList,
supplementaryData=supplementaryData,
)

Expand Down Expand Up @@ -501,17 +499,7 @@ def prepareDcrInputs(self, templateCoadd, warpRefList, weightList):
return dcrModels

@timeMethod
def run(
self,
skyInfo,
*,
warpRefList,
imageScalerList,
weightList,
psfMatchedWarpRefList=None,
supplementaryData=None,
**kwargs
):
def run(self, skyInfo, *, warpRefList, imageScalerList, weightList, supplementaryData=None, **kwargs):
r"""Assemble the coadd.

Requires additional inputs Struct ``supplementaryData`` to contain a
Expand Down Expand Up @@ -546,9 +534,6 @@ def run(
The image scalars correct for the zero point of the exposures.
weightList : `list` [`float`]
The weight to give each input exposure in the coadd.
psfMatchedWarpRefList : `list` \
[`lsst.daf.butler.DeferredDatasetHandle`], optional
The data references to the input PSF-matched warped exposures.
supplementaryData : `lsst.pipe.base.Struct`
Result struct returned by ``_makeSupplementaryData`` with
attributes:
Expand Down Expand Up @@ -611,6 +596,14 @@ def run(
skyInfo.bbox.getWidth() / subregionSize[0]
)
subIter = 0

# Calculate the initial convergence metric for the whole patch and add
# to the metadata.
convergenceMetricInitial = self.calculateConvergence(
dcrModels, self.exposure, skyInfo.bbox, warpRefList, weightList, stats.ctrl
)
self.metadata["initialConvergence"] = convergenceMetricInitial

for subBBox in subBBoxIter(skyInfo.bbox, subregionSize):
modelIter = 0
subIter += 1
Expand Down Expand Up @@ -721,12 +714,25 @@ def run(
100 * (convergenceList[0] - convergenceMetric) / convergenceMetric,
)

# Calculate the final convergence metric for the whole patch and add to
# the metadata.
convergenceMetricFinal = self.calculateConvergence(
dcrModels, subExposures, skyInfo.bbox, warpRefList, weightList, stats.ctrl
)
self.metadata["finalConvergence"] = convergenceMetricFinal

# Improvement between inital and final convergence metric for the
# whole patch and add to the metadata.
convergenceMetricImprovement = (
100 * (convergenceMetricInitial - convergenceMetricFinal) / convergenceMetricInitial
)
self.metadata["improvedConvergence"] = convergenceMetricImprovement

dcrCoadds = self.fillCoadd(
dcrModels,
skyInfo,
warpRefList,
weightList,
psfMatchedWarpRefList=psfMatchedWarpRefList,
calibration=self.scaleZeroPoint.getPhotoCalib(),
coaddInputs=templateCoadd.getInfo().getCoaddInputs(),
mask=baseMask,
Expand Down Expand Up @@ -1126,7 +1132,6 @@ def fillCoadd(
skyInfo,
warpRefList,
weightList,
psfMatchedWarpRefList=None,
calibration=None,
coaddInputs=None,
mask=None,
Expand Down Expand Up @@ -1175,7 +1180,6 @@ def fillCoadd(
coaddExposure,
warpRefList,
weightList,
psfMatchedWarpRefList=psfMatchedWarpRefList,
)
# Overwrite the PSF
coaddExposure.setPsf(dcrModels.psf)
Expand Down
Loading