Coverage for python/lsst/pipe/tasks/interpImage.py : 57%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # LSST Data Management System # Copyright 2008-2015 AURA/LSST. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <https://www.lsstcorp.org/LegalNotices/>. #
"""Config for InterpImageTask """
dtype=bool, doc="Smoothly taper to the fallback value at the edge of the image?", default=True, ) dtype=str, doc="Type of statistic to calculate edge fallbackValue for interpolation", allowed={ "MEAN": "mean", "MEDIAN": "median", "MEANCLIP": "clipped mean", "USER": "user value set in fallbackUserValue config", }, default="MEDIAN", ) dtype=float, doc="If fallbackValueType is 'USER' then use this as the fallbackValue; ignored otherwise", default=0.0, ) dtype=bool, doc=("Allow negative values for egde interpolation fallbackValue? If False, set " "fallbackValue to max(fallbackValue, 0.0)"), default=False, ) doc="Transpose image before interpolating? " "This allows the interpolation to act over columns instead of rows.")
pexConfig.Config.validate(self) if self.useFallbackValueAtEdge: if (not self.negativeFallbackAllowed and self.fallbackValueType == "USER" and self.fallbackUserValue < 0.0): raise ValueError("User supplied fallbackValue is negative (%.2f) but " "negativeFallbackAllowed is False" % self.fallbackUserValue)
"""Interpolate over bad image pixels """
"""Set the edge fallbackValue for interpolation
@param[in] mi input maksedImage on which to calculate the statistics Must be provided if fallbackValueType != "USER".
@return fallbackValue The value set/computed based on the fallbackValueType and negativeFallbackAllowed config parameters """ fallbackValue = afwMath.makeStatistics(mi, afwMath.MEAN).getValue() elif self.config.fallbackValueType == 'MEANCLIP': fallbackValue = afwMath.makeStatistics(mi, afwMath.MEANCLIP).getValue() elif self.config.fallbackValueType == 'USER': fallbackValue = self.config.fallbackUserValue else: raise NotImplementedError("%s : %s not implemented" % ("fallbackValueType", self.config.fallbackValueType))
self.log.warn("Negative interpolation edge fallback value computed but " "negativeFallbackAllowed is False: setting fallbackValue to 0.0") fallbackValue = max(fallbackValue, 0.0)
(self.config.fallbackValueType, fallbackValue))
"""!Interpolate in place over pixels in a maskedImage marked as bad
Pixels to be interpolated are set by either a mask planeName provided by the caller OR a defects list of type `~lsst.meas.algorithms.Defects` If both are provided an exception is raised.
Note that the interpolation code in meas_algorithms currently doesn't use the input PSF (though it's a required argument), so it's not important to set the input PSF parameters exactly. This PSF is set here as the psf attached to the "image" (i.e if the image passed in is an Exposure). Otherwise, a psf model is created using measAlg.GaussianPsfFactory with the value of fwhmPixels (the value passed in by the caller, or the default defaultFwhm set in measAlg.GaussianPsfFactory if None).
@param[in,out] image MaskedImage OR Exposure to be interpolated @param[in] planeName name of mask plane over which to interpolate If None, must provide a defects list. @param[in] fwhmPixels FWHM of core star (pixels) If None the default is used, where the default is set to the exposure psf if available @param[in] defects List of defects of type measAlg.Defects over which to interpolate. """
# set defectList from defects OR mask planeName provided if defects is None: raise ValueError("No defects or plane name provided") else: if not isinstance(defects, measAlg.Defects): defectList = measAlg.Defects(defects) else: defectList = defects planeName = "defects" else: raise ValueError("Provide EITHER a planeName OR a list of defects, not both") raise ValueError("maskedImage does not contain mask plane %s" % planeName)
# set psf from exposure if provided OR using modelPsf with fwhmPixels provided self.log.info("Setting psf for interpolation from image") (str(fwhmPixels) if fwhmPixels is not None else (str(self.config.modelPsf.defaultFwhm)) + " [default]"))
def transposeContext(self, maskedImage, defects): """Context manager to potentially transpose an image
This applies the ``transpose`` configuration setting.
Transposing the image allows us to interpolate along columns instead of rows, which is useful when the saturation trails are typically oriented along rows on the warped/coadded images, instead of along columns as they typically are in raw CCD images.
Parameters ---------- maskedImage : `lsst.afw.image.MaskedImage` Image on which to perform interpolation. defects : `lsst.meas.algorithms.Defects` List of defects to interpolate over.
Yields ------ useImage : `lsst.afw.image.MaskedImage` Image to use for interpolation; it may have been transposed. useDefects : `lsst.meas.algorithms.Defects` List of defects to use for interpolation; they may have been transposed. """ """Transpose an image""" transposed = image.array.T.copy() # Copy to force row-major; required for ndarray+pybind return image.Factory(transposed, False, lsst.geom.Point2I(*reversed(image.getXY0())))
useImage = afwImage.makeMaskedImage(transposeImage(maskedImage.image), transposeImage(maskedImage.mask), transposeImage(maskedImage.variance)) useDefects = defects.transpose() maskedImage.image.array = useImage.image.array.T maskedImage.mask.array = useImage.mask.array.T maskedImage.variance.array = useImage.variance.array.T
"""Interpolate over defects in an image
Parameters ---------- maskedImage : `lsst.afw.image.MaskedImage` Image on which to perform interpolation. psf : `lsst.afw.detection.Psf` Point-spread function; currently unused. defectList : `lsst.meas.algorithms.Defects` List of defects to interpolate over. fallbackValue : `float` Value to set when interpolation fails. """ return self.config.useFallbackValueAtEdge) |