Skip to content

Commit

Permalink
suppress numpy NAN warnings
Browse files Browse the repository at this point in the history
We don't care, and they clutter the output.
  • Loading branch information
PaulPrice committed Feb 5, 2018
1 parent 5d77ab8 commit bf1499c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
15 changes: 8 additions & 7 deletions python/lsst/ip/isr/isrFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@ def overscanCorrection(ampMaskedImage, overscanImage, fitType='MEDIAN', order=1,
weights=1-collapsedMask.astype(int))
# Binning is just a histogram, with weights equal to the values.
# Use a similar trick to get the bin centers (this deals with different numbers per bin).
values = numpy.histogram(indices, bins=numBins,
weights=collapsed.data*~collapsedMask)[0]/numPerBin
binCenters = numpy.histogram(indices, bins=numBins,
weights=indices*~collapsedMask)[0]/numPerBin
interp = afwMath.makeInterpolate(binCenters.astype(float)[numPerBin > 0],
values.astype(float)[numPerBin > 0],
afwMath.stringToInterpStyle(fitType))
with numpy.errstate(invalid="ignore"): # suppress NAN warnings
values = numpy.histogram(indices, bins=numBins,
weights=collapsed.data*~collapsedMask)[0]/numPerBin
binCenters = numpy.histogram(indices, bins=numBins,
weights=indices*~collapsedMask)[0]/numPerBin
interp = afwMath.makeInterpolate(binCenters.astype(float)[numPerBin > 0],
values.astype(float)[numPerBin > 0],
afwMath.stringToInterpStyle(fitType))
fitBiasArr = numpy.array([interp.interpolate(i) for i in indices])

import lsstDebug
Expand Down
31 changes: 16 additions & 15 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,21 +933,22 @@ def brighterFatterCorrection(self, exposure, kernel, maxIter, threshold, applyGa
tmpArray = tempImage.getArray()
outArray = outImage.getArray()

# First derivative term
gradTmp = numpy.gradient(tmpArray[startY:endY, startX:endX])
gradOut = numpy.gradient(outArray[startY:endY, startX:endX])
first = (gradTmp[0]*gradOut[0] + gradTmp[1]*gradOut[1])[1:-1, 1:-1]

# Second derivative term
diffOut20 = numpy.diff(outArray, 2, 0)[startY:endY, startX + 1:endX - 1]
diffOut21 = numpy.diff(outArray, 2, 1)[startY + 1:endY - 1, startX:endX]
second = tmpArray[startY + 1:endY - 1, startX + 1:endX - 1]*(diffOut20 + diffOut21)

corr[startY + 1:endY - 1, startX + 1:endX - 1] = 0.5*(first + second)

tmpArray[:, :] = image.getArray()[:, :]
tmpArray[nanIndex] = 0.
tmpArray[startY:endY, startX:endX] += corr[startY:endY, startX:endX]
with numpy.errstate(invalid="ignore", over="ignore"):
# First derivative term
gradTmp = numpy.gradient(tmpArray[startY:endY, startX:endX])
gradOut = numpy.gradient(outArray[startY:endY, startX:endX])
first = (gradTmp[0]*gradOut[0] + gradTmp[1]*gradOut[1])[1:-1, 1:-1]

# Second derivative term
diffOut20 = numpy.diff(outArray, 2, 0)[startY:endY, startX + 1:endX - 1]
diffOut21 = numpy.diff(outArray, 2, 1)[startY + 1:endY - 1, startX:endX]
second = tmpArray[startY + 1:endY - 1, startX + 1:endX - 1]*(diffOut20 + diffOut21)

corr[startY + 1:endY - 1, startX + 1:endX - 1] = 0.5*(first + second)

tmpArray[:, :] = image.getArray()[:, :]
tmpArray[nanIndex] = 0.
tmpArray[startY:endY, startX:endX] += corr[startY:endY, startX:endX]

if iteration > 0:
diff = numpy.sum(numpy.abs(prev_image - tmpArray))
Expand Down

0 comments on commit bf1499c

Please sign in to comment.