From 23d02b9160682f92ada9b41e3ab0d4f8ec8ba80a Mon Sep 17 00:00:00 2001 From: Christopher Waters Date: Wed, 6 Sep 2023 16:14:33 -0700 Subject: [PATCH] Check linearity residual fit for too-few points. --- python/lsst/cp/pipe/linearity.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/python/lsst/cp/pipe/linearity.py b/python/lsst/cp/pipe/linearity.py index b974491d..9c4996bf 100644 --- a/python/lsst/cp/pipe/linearity.py +++ b/python/lsst/cp/pipe/linearity.py @@ -551,15 +551,20 @@ def run(self, inputPtc, dummy, camera, inputDims, # The residuals that we record are the final residuals compared to # a linear model, after everything has been (properly?) linearized. - postLinearFit, _, _, _ = irlsFit( - [0.0, 100.0], - inputAbscissa[mask], - linearizeModel[mask], - funcPolynomial, - ) - residuals = linearizeModel - (postLinearFit[0] + postLinearFit[1] * inputAbscissa) - # We set masked residuals to nan. - residuals[~mask] = np.nan + if mask.sum() < 2: + self.log.warning("Amp %s in detector %s has not enough points in linear ordinate " + "for residuals. Skipping!", ampName, detector.getName()) + residuals = np.full_like(linearizeModel, np.nan) + else: + postLinearFit, _, _, _ = irlsFit( + [0.0, 100.0], + inputAbscissa[mask], + linearizeModel[mask], + funcPolynomial, + ) + residuals = linearizeModel - (postLinearFit[0] + postLinearFit[1] * inputAbscissa) + # We set masked residuals to nan. + residuals[~mask] = np.nan linearizer.fitResiduals[ampName] = residuals