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-17018: deprecate and disable ScaleZeroPointTask #321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
55 changes: 40 additions & 15 deletions python/lsst/pipe/tasks/assembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,19 @@ class AssembleCoaddConfig(CoaddBaseTask.ConfigClass, pipeBase.PipelineTaskConfig
"Passed to StatisticsControl.setCalcErrorFromInputVariance()",
default=True,
)
doScaleZeroPoint = pexConfig.Field(
dtype=bool,
default=False,
doc="Run ScaleZeroPointTask to adjust the photometric zero point of the coadd warps.",
deprecated=("This task exists to manage the removal of the scaleZeroPoint config below."
"This will be removed after v19.")
)
scaleZeroPoint = pexConfig.ConfigurableField(
target=ScaleZeroPointTask,
doc="Task to adjust the photometric zero point of the coadd temp exposures",
doc="Task to adjust the photometric zero point of the coadd warps.",
deprecated=("PhotoCalib calibrates images to nJy, keeping them in the same units."
" See RFC-545 for the deprecation discussion."
" This will be removed after v19.")
)
doInterp = pexConfig.Field(
doc="Interpolate over NaN pixels? Also extrapolate, if necessary, but the results are ugly.",
Expand Down Expand Up @@ -374,7 +384,10 @@ def __init__(self, *args, **kwargs):

super().__init__(**kwargs)
self.makeSubtask("interpImage")
self.makeSubtask("scaleZeroPoint")
if self.config.doScaleZeroPoint:
self.makeSubtask("scaleZeroPoint")
else:
self.scaleZeroPoint = None

if self.config.doMaskBrightObjects:
mask = afwImage.Mask()
Expand Down Expand Up @@ -649,15 +662,18 @@ def prepareInputs(self, refList):
if numpy.isnan(tempExp.image.array).all():
continue
maskedImage = tempExp.getMaskedImage()
imageScaler = self.scaleZeroPoint.computeImageScaler(
exposure=tempExp,
dataRef=tempExpRef,
)
try:
imageScaler.scaleMaskedImage(maskedImage)
except Exception as e:
self.log.warn("Scaling failed for %s (skipping it): %s", tempExpRef.dataId, e)
continue

if self.scaleZeroPoint is not None:
imageScaler = self.scaleZeroPoint.computeImageScaler(
exposure=tempExp,
dataRef=tempExpRef,
)
try:
imageScaler.scaleMaskedImage(maskedImage)
except Exception as e:
self.log.warn("Scaling failed for %s (skipping it): %s", tempExpRef.dataId, e)
continue

statObj = afwMath.makeStatistics(maskedImage.getVariance(), maskedImage.getMask(),
afwMath.MEANCLIP, statsCtrl)
meanVar, meanVarErr = statObj.getResult(afwMath.MEANCLIP)
Expand All @@ -672,7 +688,10 @@ def prepareInputs(self, refList):

tempExpRefList.append(tempExpRef)
weightList.append(weight)
imageScalerList.append(imageScaler)
if self.scaleZeroPoint is not None:
imageScalerList.append(imageScaler)
else:
imageScalerList.append(None)

return pipeBase.Struct(tempExpRefList=tempExpRefList, weightList=weightList,
imageScalerList=imageScalerList)
Expand Down Expand Up @@ -763,7 +782,11 @@ def run(self, skyInfo, tempExpRefList, imageScalerList, weightList,
altMaskList = [None]*len(tempExpRefList)

coaddExposure = afwImage.ExposureF(skyInfo.bbox, skyInfo.wcs)
coaddExposure.setPhotoCalib(self.scaleZeroPoint.getPhotoCalib())
if self.scaleZeroPoint is None:
# The coadd is in nJy, and we do not propogate errors from the warps.
coaddExposure.setPhotoCalib(afwImage.PhotoCalib(1.0, 0.0))
else:
coaddExposure.setPhotoCalib(self.scaleZeroPoint.getPhotoCalib())
coaddExposure.getInfo().setCoaddInputs(self.inputRecorder.makeCoaddInputs())
self.assembleMetadata(coaddExposure, tempExpRefList, weightList)
coaddMaskedImage = coaddExposure.getMaskedImage()
Expand Down Expand Up @@ -910,7 +933,8 @@ def assembleSubregion(self, coaddExposure, bbox, tempExpRefList, imageScalerList
mask = maskedImage.getMask()
if altMask is not None:
self.applyAltMaskPlanes(mask, altMask)
imageScaler.scaleMaskedImage(maskedImage)
if imageScaler is not None:
imageScaler.scaleMaskedImage(maskedImage)

# Add 1 for each pixel which is not excluded by the exclude mask.
# In legacyCoadd, pixels may also be excluded by afwMath.statisticsStack.
Expand Down Expand Up @@ -2359,7 +2383,8 @@ def _readAndComputeWarpDiff(self, warpRef, imageScaler, templateCoadd):
return None
warp = warpRef.get(datasetType=warpName, immediate=True)
# direct image scaler OK for PSF-matched Warp
imageScaler.scaleMaskedImage(warp.getMaskedImage())
if imageScaler is not None:
imageScaler.scaleMaskedImage(warp.getMaskedImage())
mi = warp.getMaskedImage()
if self.config.doScaleWarpVariance:
try:
Expand Down