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-33530: Spline fitter fails when insufficient length array input #207

Merged
merged 2 commits into from
Feb 7, 2022
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
26 changes: 24 additions & 2 deletions python/lsst/ip/isr/overscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ def splineFit(self, indices, collapsed, numBins):
weights=collapsed.data*~collapsed.mask)[0]/numPerBin
binCenters = np.histogram(indices, bins=numBins,
weights=indices*~collapsed.mask)[0]/numPerBin

if len(binCenters[numPerBin > 0]) < 5:
self.log.warn("Cannot do spline fitting for overscan: %s valid points.",
len(binCenters[numPerBin > 0]))
# Return a scalar value if we have one, otherwise
# return zero. This amplifier is hopefully already
# masked.
if len(values[numPerBin > 0]) != 0:
return float(values[numPerBin > 0][0])
else:
return 0.0

interp = afwMath.makeInterpolate(binCenters.astype(float)[numPerBin > 0],
values.astype(float)[numPerBin > 0],
afwMath.stringToInterpStyle(self.config.fitType))
Expand Down Expand Up @@ -482,9 +494,19 @@ def measureVectorOverscan(self, image):
'AKIMA_SPLINE': (self.splineFit, self.splineEval)
}[self.config.fitType]

# These are the polynomial coefficients, or an
# interpolation object.
coeffs = fitter(indices, collapsed, self.config.order)
overscanVector = evaler(indices, coeffs)
maskArray = self.maskExtrapolated(collapsed)

if isinstance(coeffs, float):
self.log.warn("Using fallback value %f due to fitter failure. Amplifier will be masked.",
coeffs)
overscanVector = np.full_like(indices, coeffs)
maskArray = np.full_like(collapsed, True, dtype=bool)
else:
# Otherwise we can just use things as normal.
overscanVector = evaler(indices, coeffs)
maskArray = self.maskExtrapolated(collapsed)
return pipeBase.Struct(overscanValue=np.array(overscanVector),
maskArray=maskArray,
isTransposed=isTransposed)
Expand Down