From f096fbe3fdb559b86e2e9ab2c12e8cdf9137dd3d Mon Sep 17 00:00:00 2001 From: Audrey Budlong Date: Thu, 5 Dec 2024 11:50:17 -0800 Subject: [PATCH 1/3] Update dcr_assemble_coadd to reflect required configurations --- python/lsst/drp/tasks/assemble_coadd.py | 14 ++++++++++---- python/lsst/drp/tasks/dcr_assemble_coadd.py | 19 +++++-------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/python/lsst/drp/tasks/assemble_coadd.py b/python/lsst/drp/tasks/assemble_coadd.py index 9e445778..ccfadfdf 100644 --- a/python/lsst/drp/tasks/assemble_coadd.py +++ b/python/lsst/drp/tasks/assemble_coadd.py @@ -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( @@ -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) diff --git a/python/lsst/drp/tasks/dcr_assemble_coadd.py b/python/lsst/drp/tasks/dcr_assemble_coadd.py index 0adb7f9f..58642093 100644 --- a/python/lsst/drp/tasks/dcr_assemble_coadd.py +++ b/python/lsst/drp/tasks/dcr_assemble_coadd.py @@ -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": "", @@ -240,7 +240,7 @@ 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 + # 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 @@ -278,7 +278,7 @@ 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 + 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 @@ -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") @@ -365,7 +364,6 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs): warpRefList=inputs.warpRefList, imageScalerList=inputs.imageScalerList, weightList=inputs.weightList, - psfMatchedWarpRefList=inputs.psfMatchedWarpRefList, supplementaryData=supplementaryData, ) @@ -508,7 +506,6 @@ def run( warpRefList, imageScalerList, weightList, - psfMatchedWarpRefList=None, supplementaryData=None, **kwargs ): @@ -546,9 +543,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: @@ -726,7 +720,6 @@ def run( skyInfo, warpRefList, weightList, - psfMatchedWarpRefList=psfMatchedWarpRefList, calibration=self.scaleZeroPoint.getPhotoCalib(), coaddInputs=templateCoadd.getInfo().getCoaddInputs(), mask=baseMask, @@ -1126,7 +1119,6 @@ def fillCoadd( skyInfo, warpRefList, weightList, - psfMatchedWarpRefList=None, calibration=None, coaddInputs=None, mask=None, @@ -1175,7 +1167,6 @@ def fillCoadd( coaddExposure, warpRefList, weightList, - psfMatchedWarpRefList=psfMatchedWarpRefList, ) # Overwrite the PSF coaddExposure.setPsf(dcrModels.psf) From a5c6602d6be102bc54d8ed2f2a277f0fb444bdc6 Mon Sep 17 00:00:00 2001 From: Audrey Budlong Date: Wed, 22 Jan 2025 22:02:12 -0800 Subject: [PATCH 2/3] Set convergence in task metadata to indicate overall performance --- python/lsst/drp/tasks/dcr_assemble_coadd.py | 24 +++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/python/lsst/drp/tasks/dcr_assemble_coadd.py b/python/lsst/drp/tasks/dcr_assemble_coadd.py index 58642093..e4cef716 100644 --- a/python/lsst/drp/tasks/dcr_assemble_coadd.py +++ b/python/lsst/drp/tasks/dcr_assemble_coadd.py @@ -240,8 +240,8 @@ def setDefaults(self): self.assembleStaticSkyModel.retarget(CompareWarpAssembleCoaddTask) self.doNImage = True self.assembleStaticSkyModel.warpType = self.warpType - # The goodSeeingCoadd 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 @@ -605,6 +605,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 @@ -715,6 +723,18 @@ 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, From 8bcca9306841155c3422ce9382562b3464749c5c Mon Sep 17 00:00:00 2001 From: Audrey Budlong Date: Sat, 25 Jan 2025 12:11:31 -0800 Subject: [PATCH 3/3] Black formatting --- python/lsst/drp/tasks/dcr_assemble_coadd.py | 25 ++++++++------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/python/lsst/drp/tasks/dcr_assemble_coadd.py b/python/lsst/drp/tasks/dcr_assemble_coadd.py index e4cef716..7f91d17f 100644 --- a/python/lsst/drp/tasks/dcr_assemble_coadd.py +++ b/python/lsst/drp/tasks/dcr_assemble_coadd.py @@ -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 goodSeeingCoadd, 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 @@ -499,16 +499,7 @@ def prepareDcrInputs(self, templateCoadd, warpRefList, weightList): return dcrModels @timeMethod - def run( - self, - skyInfo, - *, - warpRefList, - imageScalerList, - weightList, - 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 @@ -611,7 +602,7 @@ def run( convergenceMetricInitial = self.calculateConvergence( dcrModels, self.exposure, skyInfo.bbox, warpRefList, weightList, stats.ctrl ) - self.metadata['initialConvergence'] = convergenceMetricInitial + self.metadata["initialConvergence"] = convergenceMetricInitial for subBBox in subBBoxIter(skyInfo.bbox, subregionSize): modelIter = 0 @@ -728,12 +719,14 @@ def run( convergenceMetricFinal = self.calculateConvergence( dcrModels, subExposures, skyInfo.bbox, warpRefList, weightList, stats.ctrl ) - self.metadata['finalConvergence'] = convergenceMetricFinal + 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 + convergenceMetricImprovement = ( + 100 * (convergenceMetricInitial - convergenceMetricFinal) / convergenceMetricInitial + ) + self.metadata["improvedConvergence"] = convergenceMetricImprovement dcrCoadds = self.fillCoadd( dcrModels,