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-5081: Mark amplifier edges SUSPECT if brighter-fatter is applied. #104

Merged
merged 2 commits into from
Aug 7, 2019
Merged
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
51 changes: 44 additions & 7 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,11 @@ def run(self, ccdExposure, camera=None, bias=None, linearizer=None, crosstalkSou
self.log.info("Masking defects.")
self.maskDefect(ccdExposure, defects)

if self.config.numEdgeSuspect > 0:
self.log.info("Masking edges as SUSPECT.")
self.maskEdges(ccdExposure, numEdgePixels=self.config.numEdgeSuspect,
maskPlane="SUSPECT")

if self.config.doNanMasking:
self.log.info("Masking NAN value pixels.")
self.maskNan(ccdExposure)
Expand Down Expand Up @@ -1325,6 +1330,16 @@ def run(self, ccdExposure, camera=None, bias=None, linearizer=None, crosstalkSou
bfCorr -= interpExp.getMaskedImage().getImage()
image += bfCorr

# Applying the brighter-fatter correction applies a
# convolution to the science image. At the edges this
# convolution may not have sufficient valid pixels to
# produce a valid correction. Mark pixels within the size
# of the brighter-fatter kernel as EDGE to warn of this
# fact.
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.")

self.debugView(ccdExposure, "doBrighterFatter")

if self.config.doDark:
Expand Down Expand Up @@ -2070,7 +2085,7 @@ def maskDefect(self, exposure, defectBaseList):
Exposure to process.
defectBaseList : `lsst.meas.algorithms.Defects` or `list` of
`lsst.afw.image.DefectBase`.
List of defects to mask and interpolate.
List of defects to mask.

Notes
-----
Expand All @@ -2084,15 +2099,30 @@ def maskDefect(self, exposure, defectBaseList):
defectList = defectBaseList
defectList.maskPixels(maskedImage, maskName="BAD")

if self.config.numEdgeSuspect > 0:
def maskEdges(self, exposure, numEdgePixels=0, maskPlane="SUSPECT"):
"""!Mask edge pixels with applicable mask plane.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to process.
numEdgePixels : `int`, optional
Number of edge pixels to mask.
maskPlane : `str`, optional
Mask plane name to use.
"""
maskedImage = exposure.getMaskedImage()
maskBitMask = maskedImage.getMask().getPlaneBitMask(maskPlane)

if numEdgePixels > 0:
goodBBox = maskedImage.getBBox()
# This makes a bbox numEdgeSuspect pixels smaller than the image on each side
goodBBox.grow(-self.config.numEdgeSuspect)
# Mask pixels outside goodBBox as SUSPECT
goodBBox.grow(-numEdgePixels)
# Mask pixels outside goodBBox
SourceDetectionTask.setEdgeBits(
maskedImage,
goodBBox,
maskedImage.getMask().getPlaneBitMask("SUSPECT")
maskBitMask
)

def maskAndInterpolateDefects(self, exposure, defectBaseList):
Expand All @@ -2102,10 +2132,17 @@ def maskAndInterpolateDefects(self, exposure, defectBaseList):
----------
exposure : `lsst.afw.image.Exposure`
Exposure to process.
defectBaseList : `List` of `Defects`
defectBaseList : `lsst.meas.algorithms.Defects` or `list` of
`lsst.afw.image.DefectBase`.
List of defects to mask and interpolate.

See Also
--------
lsst.ip.isr.isrTask.maskDefect()
"""
self.maskDefects(exposure, defectBaseList)
self.maskDefect(exposure, defectBaseList)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...how did this work before? Did this work before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a clear answer.

self.maskEdges(exposure, numEdgePixels=self.config.numEdgeSuspect,
maskPlane="SUSPECT")
isrFunctions.interpolateFromMask(
maskedImage=exposure.getMaskedImage(),
fwhm=self.config.fwhm,
Expand Down