Skip to content

Commit

Permalink
Handle the overscan as integer to calculate the median
Browse files Browse the repository at this point in the history
Even if the overscan image is floating, it's really ints with lots of
ties which must be handled carefully to get sub-integer precision.

You should never estimate overscan on "real" floating images, but
there's an option to prevent the conversion to int in case you do
  • Loading branch information
RobertLuptonTheGood committed Oct 9, 2018
1 parent 1c0d065 commit 15f97b2
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions python/lsst/ip/isr/isrFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def illuminationCorrection(maskedImage, illumMaskedImage, illumScale):
maskedImage.scaledDivides(1./illumScale, illumMaskedImage)


def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1, statControl=None):
def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1, statControl=None,
overscanIsInt=True):
"""Apply overscan correction in-place
The ``ampMaskedImage`` and ``overscanImage`` are modified, with the fit
Expand Down Expand Up @@ -319,6 +320,9 @@ def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1,
``fitType`` indicates a polynomial or spline.
statControl : `lsst.afw.math.StatisticsControl`
Statistics control object. In particular, we pay attention to numSigmaClip
overscanIsInt : `bool`
Treat the overscan region as consisting of integers, even if it's been
converted to float. E.g. handle ties properly
Returns
-------
Expand All @@ -336,10 +340,27 @@ def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1,

numSigmaClip = statControl.getNumSigmaClip()

if fitType in ('MEAN', 'MEANCLIP', 'MEDIAN',):
if fitType in ('MEAN', 'MEANCLIP'):
fitType = afwMath.stringToStatisticsProperty(fitType)
offImage = afwMath.makeStatistics(overscanImage, fitType, statControl).getValue()
overscanFit = offImage
elif fitType in ('MEDIAN',):
if overscanIsInt:
# we need an image with integer pixels to handle ties properly
if hasattr(overscanImage, "image"):
imageI = overscanImage.image.convertI()
overscanImageI = afwImage.MaskedImageI(imageI, overscanImage.mask, overscanImage.variance)
else:
overscanImageI = overscanImage.convertI()
else:
overscanImageI = overscanImage

fitType = afwMath.stringToStatisticsProperty(fitType)
offImage = afwMath.makeStatistics(overscanImageI, fitType, statControl).getValue()
overscanFit = offImage

if overscanIsInt:
del overscanImageI
elif fitType in ('POLY', 'CHEB', 'LEG', 'NATURAL_SPLINE', 'CUBIC_SPLINE', 'AKIMA_SPLINE'):
if hasattr(overscanImage, "getImage"):
biasArray = overscanImage.getImage().getArray()
Expand Down

0 comments on commit 15f97b2

Please sign in to comment.