Skip to content

Commit

Permalink
Move SENSOR_EDGE pixels to the true EDGE of the PSF-Matched Warps
Browse files Browse the repository at this point in the history
* Remove directWarp's original "EDGE" plane; the true edge had moved inwards
* Allow directWarp's updated EDGE pixels (from PSF-matched EDGE) into the coadd,
  but mark as SENSOR_EDGE.
* Clear mask planes that would have been rejected outside the new valid polygon,
  and reject as NO_DATA instead, so that they do not propgate to INEXACT_PSF.
  This behavior may be turned off by setting doUsePsfMatchedPolygons=False.
  • Loading branch information
yalsayyad committed Feb 16, 2018
1 parent 41fa4b6 commit bdc1ced
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions python/lsst/pipe/tasks/assembleCoadd.py
Expand Up @@ -113,7 +113,7 @@ class AssembleCoaddConfig(CoaddBaseTask.ConfigClass):
default=False,
)
doUsePsfMatchedPolygons = pexConfig.Field(
doc="Use ValidPolygons from shrunk PsfMatched Calexps?",
doc="Use ValidPolygons from shrunk Psf-Matched Calexps? Should be set to True by CompareWarp only.",
dtype=bool,
default=False,
)
Expand Down Expand Up @@ -683,6 +683,17 @@ def applyAltMaskPlanes(self, mask, altMaskSpans):
and list of SpanSets to apply to the mask
"""
for plane, spanSetList in altMaskSpans.items():

if (plane == "NO_DATA" and self.config.doUsePsfMatchedPolygons and
"NO_DATA" in self.config.badMaskPlanes):
# Clear away any other masks outside the validPolygons. These pixels are no longer
# contributing to inexact PSFs, and will still be rejected because of NO_DATA.
# self.config.doUsePsfMatchedPolygons should be True only in CompareWarpAssemble
badMaskPlanes = self.getBadPixelMask()
print(len(spanSetList))
for spanSet in spanSetList:
spanSet.clippedTo(mask.getBBox()).clearMask(mask, badMaskPlanes)

maskClipValue = mask.addMaskPlane(plane)
for spanSet in spanSetList:
spanSet.clippedTo(mask.getBBox()).setMask(mask, 2**maskClipValue)
Expand Down Expand Up @@ -1380,6 +1391,7 @@ def setDefaults(self):
self.statistic = 'MEAN'
self.doUsePsfMatchedPolygons = True
self.badMaskPlanes.remove('EDGE')
self.removeMaskPlanes.append('EDGE')
self.assembleStaticSkyModel.badMaskPlanes = ["NO_DATA", ]
self.assembleStaticSkyModel.warpType = 'psfMatched'
self.assembleStaticSkyModel.statistic = 'MEANCLIP'
Expand Down Expand Up @@ -1607,8 +1619,30 @@ def assemble(self, skyInfo, tempExpRefList, imageScalerList, weightList,
badMaskPlanes.append("CLIPPED")
badPixelMask = afwImage.Mask.getPlaneBitMask(badMaskPlanes)

return AssembleCoaddTask.assemble(self, skyInfo, tempExpRefList, imageScalerList, weightList,
spanSetMaskList, mask=badPixelMask)
retStruct = AssembleCoaddTask.assemble(self, skyInfo, tempExpRefList, imageScalerList, weightList,
spanSetMaskList, mask=badPixelMask)

# Propagate PSF-matched EDGE pixels to coadd SENSOR_EDGE and INEXACT_PSF
# Psf-Matching moves the real edge inwards
self.applyAltEdgeMask(retStruct.coaddExposure.maskedImage.mask, spanSetMaskList)
return retStruct

def applyAltEdgeMask(self, mask, altMaskList):
"""!
\brief Propagate alt EDGE mask to SENSOR_EDGE AND INEXACT_PSF planes
@param mask: original mask
@param altMaskList: List of Dictionaries containing spanSet lists.
Each element contains the new mask plane name
(e.g. "CLIPPED and/or "NO_DATA") as the key,
and list of SpanSets to apply to the mask.
"""
maskSensorEdgeBit = mask.addMaskPlane("SENSOR_EDGE")
maskInexactPsfBit = mask.addMaskPlane("INEXACT_PSF")
maskValue = 2**maskSensorEdgeBit | 2**maskInexactPsfBit
for visitMask in altMaskList:
for spanSet in visitMask['EDGE']:
spanSet.clippedTo(mask.getBBox()).setMask(mask, maskValue)

def findArtifacts(self, templateCoadd, tempExpRefList, imageScalerList):
"""!
Expand Down

0 comments on commit bdc1ced

Please sign in to comment.