131 def run(self, image, planeName=None, fwhmPixels=None, defects=None):
132 """Interpolate in place over pixels in a maskedImage marked as bad
133
134 Pixels to be interpolated are set by either a mask planeName provided
135 by the caller OR a defects list of type `~lsst.meas.algorithms.Defects`
136 If both are provided an exception is raised.
137
138 Note that the interpolation code in meas_algorithms currently doesn't
139 use the input PSF (though it's a required argument), so it's not
140 important to set the input PSF parameters exactly. This PSF is set
141 here as the psf attached to the "image" (i.e if the image passed in
142 is an Exposure). Otherwise, a psf model is created using
143 measAlg.GaussianPsfFactory with the value of fwhmPixels (the value
144 passed in by the caller, or the default defaultFwhm set in
145 measAlg.GaussianPsfFactory if None).
146
147 Parameters
148 ----------
149 image : `lsst.afw.image.MaskedImage` or `lsst.afw.image.exposure.Exposure`
150 MaskedImage OR Exposure to be interpolated.
151 planeName : `str`, optional
152 Name of mask plane over which to interpolate.
153 If None, must provide a defects list.
154 fwhmPixels : `int`, optional
155 FWHM of core star (pixels).
156 If None the default is used, where the default
157 is set to the exposure psf if available.
158 defects : `lsst.meas.algorithms.Defects`, optional
159 List of defects of type ipIsr.Defects
160 over which to interpolate.
161 """
162 try:
163 maskedImage = image.getMaskedImage()
164 except AttributeError:
165 maskedImage = image
166
167
168 if planeName is None:
169 if defects is None:
170 raise ValueError("No defects or plane name provided")
171 else:
172 if not isinstance(defects, ipIsr.Defects):
173 defectList = ipIsr.Defects(defects)
174 else:
175 defectList = defects
176 planeName = "defects"
177 else:
178 if defects is not None:
179 raise ValueError("Provide EITHER a planeName OR a list of defects, not both")
180 if planeName not in maskedImage.getMask().getMaskPlaneDict():
181 raise ValueError("maskedImage does not contain mask plane %s" % planeName)
182 defectList = ipIsr.Defects.fromMask(maskedImage, planeName)
183
184
185 try:
186 psf = image.getPsf()
187 self.log.info("Setting psf for interpolation from image")
188 except AttributeError:
189 self.log.info("Creating psf model for interpolation from fwhm(pixels) = %s",
190 str(fwhmPixels) if fwhmPixels is not None else
191 (str(self.config.modelPsf.defaultFwhm)) + " [default]")
192 psf = self.config.modelPsf.apply(fwhm=fwhmPixels)
193
194 fallbackValue = 0.0
195 if self.config.useFallbackValueAtEdge:
196 fallbackValue = self._setFallbackValue(maskedImage)
197
198 self.interpolateImage(maskedImage, psf, defectList, fallbackValue)
199
200 self.log.info("Interpolated over %d %s pixels.", len(defectList), planeName)
201