Skip to content

Commit

Permalink
Merge pull request #72 from lsst/tickets/DM-46342
Browse files Browse the repository at this point in the history
DM-46342: Reorder and pad artifact mask handles
  • Loading branch information
arunkannawadi authored Sep 18, 2024
2 parents dd43f7e + afcb1ef commit b7c32bf
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions python/lsst/drp/tasks/assemble_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class AssembleCoaddConfig(
default=True,
)
doWriteArtifactMasks = pexConfig.Field(
doc="Persist artifact masks?",
doc="Persist artifact masks? Should be True for CompareWarp only.",
dtype=bool,
default=False,
)
Expand Down Expand Up @@ -293,18 +293,31 @@ def setDefaults(self):
def validate(self):
super().validate()
if self.doInterp and self.statistic not in ["MEAN", "MEDIAN", "MEANCLIP", "VARIANCE", "VARIANCECLIP"]:
raise ValueError(
"Must set doInterp=False for statistic=%s, which does not "
"compute and set a non-zero coadd variance estimate." % (self.statistic)
raise pexConfig.FieldValidationError(
self.__class__.doInterp,
self,
f"Must set doInterp=False for statistic={self.statistic}, which does not "
"compute and set a non-zero coadd variance estimate.",
)

unstackableStats = ["NOTHING", "ERROR", "ORMASK"]
if not hasattr(afwMath.Property, self.statistic) or self.statistic in unstackableStats:
stackableStats = [
str(k) for k in afwMath.Property.__members__.keys() if str(k) not in unstackableStats
]
raise ValueError(
"statistic %s is not allowed. Please choose one of %s." % (self.statistic, stackableStats)
raise pexConfig.FieldValidationError(
self.__class__.statistic,
self,
f"statistic {self.statistic} is not allowed. Please choose one of {stackableStats}.",
)

# Admittedly, it's odd for a parent class to condition on a child class
# but such is the case until the CompareWarp refactor in DM-38630.
if self.doWriteArtifactMasks and not isinstance(self, CompareWarpAssembleCoaddConfig):
raise pexConfig.FieldValidationError(
self.__class__.doWriteArtifactMasks,
self,
"doWriteArtifactMasks is only valid for CompareWarpAssembleCoaddConfig.",
)


Expand Down Expand Up @@ -441,19 +454,13 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
log.warning("doMaskBrightObjects is set to True, but brightObjectMask not loaded")
self.processResults(retStruct.coaddExposure, inputData["brightObjectMask"], outputDataId)

if self.config.doWriteArtifactMasks and supplementaryData: # branch to see if running CompareWarp.
dataIds = [ref.dataId for ref in inputs.warpRefList]
psfMatchedDataIds = [ref.dataId for ref in supplementaryData.warpRefList]

if dataIds != psfMatchedDataIds:
supplementaryData.warpRefList = reorderAndPadList(
supplementaryData.warpRefList, psfMatchedDataIds, dataIds
)
for warpRef, altMask, outputRef in zip(
inputs.warpRefList, retStruct.altMaskList, outputRefs.artifactMasks
):
if warpRef is None:
continue
if self.config.doWriteArtifactMasks:
artifactMasksRefList = reorderAndPadList(
outputRefs.artifactMasks,
[ref.dataId for ref in outputRefs.artifactMasks],
[ref.dataId for ref in inputs.warpRefList],
)
for altMask, outputRef in zip(retStruct.altMaskList, artifactMasksRefList, strict=True):
mask = afwImage.Mask(retStruct.coaddExposure.getBBox())
self.applyAltMaskPlanes(mask, altMask)
butlerQC.put(mask, outputRef)
Expand Down

0 comments on commit b7c32bf

Please sign in to comment.