228 Interpolate over the defects in the image.
230 Change self.masked_image .
233 self.
log.info(
"No defects found. No interpolation performed.")
236 bad_pixel_mask = mask.getPlaneBitMask(self.
defects)
237 bad_mask_span_set = SpanSet.fromMask(mask, bad_pixel_mask).split()
240 global_xmin, global_xmax = bbox.minX, bbox.maxX
241 global_ymin, global_ymax = bbox.minY, bbox.maxY
243 for spanset
in bad_mask_span_set:
244 bbox = spanset.getBBox()
249 bbox = bbox.dilatedBy(
252 xmin, xmax = max([global_xmin, bbox.minX]), min(global_xmax, bbox.maxX)
253 ymin, ymax = max([global_ymin, bbox.minY]), min(global_ymax, bbox.maxY)
262 Performs pixel binning using treegp.meanify
272 The binned array of pixels.
275 n_pixels = len(pixels[:, 0])
277 if n_pixels / self.
bin_spacing**2 < n_pixels / dynamic_binning**2:
280 bin_spacing = dynamic_binning
281 binning = treegp.meanify(bin_spacing=bin_spacing, statistics=
"mean")
288 [binning.coords0[:, 0], binning.coords0[:, 1], binning.params0]
293 Interpolate the masked sub-image.
297 masked_sub_image : `lsst.afw.image.MaskedImage`
298 The sub-masked image to be interpolated.
302 `lsst.afw.image.MaskedImage`
303 The interpolated sub-masked image.
309 bad_pixel, good_pixel = ctUtils.findGoodPixelsAroundBadPixels(
310 masked_sub_image, self.
defects, buffer=cut
313 if bad_pixel.size == 0
or good_pixel.size == 0:
314 self.
log.info(
"No bad or good pixels found. No interpolation performed.")
315 return masked_sub_image
319 sub_image_array = masked_sub_image.getVariance().array
320 white_noise = np.sqrt(
321 np.mean(sub_image_array[np.isfinite(sub_image_array)])
323 kernel_amplitude = np.max(good_pixel[:, 2:])
324 if not np.isfinite(kernel_amplitude):
325 filter_finite = np.isfinite(good_pixel[:, 2:]).T[0]
326 good_pixel = good_pixel[filter_finite]
327 if good_pixel.size == 0:
329 "No bad or good pixels found. No interpolation performed."
331 return masked_sub_image
334 kernel_amplitude = np.max(good_pixel[:, 2:])
341 "Binning failed, use original good pixel array in interpolation."
348 std=np.sqrt(kernel_amplitude),
350 white_noise=white_noise,
353 gp.fit(good_pixel[:, :2], np.squeeze(good_pixel[:, 2:]))
355 gp_predict = gp.predict(bad_pixel[:, :2])
356 bad_pixel[:, 2:] = gp_predict.reshape(np.shape(bad_pixel[:, 2:]))
358 self.
log.info(
"sub-divide bad pixel array to avoid memory error.")
361 gp_predict = gp.predict(bad_pixel[i:end, :2])
362 bad_pixel[i:end, 2:] = gp_predict.reshape(
363 np.shape(bad_pixel[i:end, 2:])
367 ctUtils.updateImageFromArray(masked_sub_image.image, bad_pixel)
369 return masked_sub_image