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-23083: Update large masks for BF convolution issues #123

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions python/lsst/ip/isr/isrFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ def makeThresholdMask(maskedImage, threshold, growFootprints=1, maskName='SAT'):
return measAlg.Defects.fromFootprintList(fpList)


def growMasks(mask, radius=0, maskNameList=['BAD'], maskValue="BAD"):
"""Grow a mask by an amount and add to the requested plane.

Parameters
----------
mask : `lsst.afw.image.Mask`
Mask image to process.
radius : scalar
Amount to grow the mask.
maskNameList : `str` or `list` [`str`]
Mask names that should be grown.
maskValue : `str`
Mask plane to assign the newly masked pixels to.
"""
if radius > 0:
thresh = afwDetection.Threshold(mask.getPlaneBitMask(maskNameList), afwDetection.Threshold.BITMASK)
fpSet = afwDetection.FootprintSet(mask, thresh)
fpSet = afwDetection.FootprintSet(fpSet, rGrow=radius, isotropic=False)
fpSet.setMask(mask, maskValue)


def interpolateFromMask(maskedImage, fwhm, growSaturatedFootprints=1,
maskNameList=['SAT'], fallbackValue=None):
"""Interpolate over defects identified by a particular set of mask planes.
Expand All @@ -154,12 +175,9 @@ def interpolateFromMask(maskedImage, fwhm, growSaturatedFootprints=1,
mask = maskedImage.getMask()

if growSaturatedFootprints > 0 and "SAT" in maskNameList:
thresh = afwDetection.Threshold(mask.getPlaneBitMask("SAT"), afwDetection.Threshold.BITMASK)
fpSet = afwDetection.FootprintSet(mask, thresh)
# If we are interpolating over an area larger than the original masked region, we need
# to expand the original mask bit to the full area to explain why we interpolated there.
fpSet = afwDetection.FootprintSet(fpSet, rGrow=growSaturatedFootprints, isotropic=False)
fpSet.setMask(mask, "SAT")
growMasks(mask, radius=growSaturatedFootprints, maskNameList=['SAT'], maskValue="SAT")

thresh = afwDetection.Threshold(mask.getPlaneBitMask(maskNameList), afwDetection.Threshold.BITMASK)
fpSet = afwDetection.FootprintSet(mask, thresh)
Expand Down
16 changes: 15 additions & 1 deletion python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@ class IsrTaskConfig(pipeBase.PipelineTaskConfig,
default=True,
doc="Should the gain be applied when applying the brighter fatter correction?"
)
brighterFatterMaskGrowSize = pexConfig.Field(
dtype=int,
default=0,
doc="Number of pixels to grow the masks listed in config.maskListToInterpolate "
" when brighter-fatter correction is applied."
)

# Dark subtraction.
doDark = pexConfig.Field(
Expand Down Expand Up @@ -1341,9 +1347,17 @@ def run(self, ccdExposure, camera=None, bias=None, linearizer=None, crosstalkSou
# produce a valid correction. Mark pixels within the size
# of the brighter-fatter kernel as EDGE to warn of this
# fact.
self.log.info("Ensuring image edges are masked as SUSPECT to the brighter-fatter kernel size.")
self.maskEdges(ccdExposure, numEdgePixels=numpy.max(bfKernel.shape) // 2,
maskPlane="EDGE")
self.log.warn("Ensuring image edges are masked as SUSPECT to the brighter-fatter kernel size.")

if self.config.brighterFatterMaskGrowSize > 0:
self.log.info("Growing masks to account for brighter-fatter kernel convolution.")
for maskPlane in self.config.maskListToInterpolate:
isrFunctions.growMasks(ccdExposure.getMask(),
radius=self.config.brighterFatterMaskGrowSize,
maskNameList=maskPlane,
maskValue=maskPlane)

self.debugView(ccdExposure, "doBrighterFatter")

Expand Down