223 Interpolate over the defects in the image.
225 Change self.masked_image .
228 self.
log.info(
"No defects found. No interpolation performed.")
231 bad_pixel_mask = mask.getPlaneBitMask(self.
defects)
232 bad_mask_span_set = SpanSet.fromMask(mask, bad_pixel_mask).split()
235 global_xmin, global_xmax = bbox.minX, bbox.maxX
236 global_ymin, global_ymax = bbox.minY, bbox.maxY
238 for spanset
in bad_mask_span_set:
239 bbox = spanset.getBBox()
244 bbox = bbox.dilatedBy(
247 xmin, xmax = max([global_xmin, bbox.minX]), min(global_xmax, bbox.maxX)
248 ymin, ymax = max([global_ymin, bbox.minY]), min(global_ymax, bbox.maxY)
257 Performs pixel binning using treegp.meanify
267 The binned array of pixels.
270 n_pixels = len(pixels[:, 0])
272 if n_pixels / self.
bin_spacing**2 < n_pixels / dynamic_binning**2:
275 bin_spacing = dynamic_binning
276 binning = treegp.meanify(bin_spacing=bin_spacing, statistics=
"mean")
283 [binning.coords0[:, 0], binning.coords0[:, 1], binning.params0]
288 Interpolate the masked sub-image.
292 masked_sub_image : `lsst.afw.image.MaskedImage`
293 The sub-masked image to be interpolated.
297 `lsst.afw.image.MaskedImage`
298 The interpolated sub-masked image.
304 bad_pixel, good_pixel = ctUtils.findGoodPixelsAroundBadPixels(
305 masked_sub_image, self.
defects, buffer=cut
308 if bad_pixel.size == 0
or good_pixel.size == 0:
309 self.
log.info(
"No bad or good pixels found. No interpolation performed.")
310 return masked_sub_image
314 sub_image_array = masked_sub_image.getVariance().array
315 white_noise = np.sqrt(
316 np.mean(sub_image_array[np.isfinite(sub_image_array)])
318 kernel_amplitude = np.max(good_pixel[:, 2:])
319 if not np.isfinite(kernel_amplitude):
320 filter_finite = np.isfinite(good_pixel[:, 2:]).T[0]
321 good_pixel = good_pixel[filter_finite]
322 if good_pixel.size == 0:
324 "No bad or good pixels found. No interpolation performed."
326 return masked_sub_image
329 kernel_amplitude = np.max(good_pixel[:, 2:])
336 "Binning failed, use original good pixel array in interpolation."
343 std=np.sqrt(kernel_amplitude),
345 white_noise=white_noise,
348 gp.fit(good_pixel[:, :2], np.squeeze(good_pixel[:, 2:]))
350 gp_predict = gp.predict(bad_pixel[:, :2])
351 bad_pixel[:, 2:] = gp_predict.reshape(np.shape(bad_pixel[:, 2:]))
353 self.
log.info(
"sub-divide bad pixel array to avoid memory error.")
356 gp_predict = gp.predict(bad_pixel[i:end, :2])
357 bad_pixel[i:end, 2:] = gp_predict.reshape(
358 np.shape(bad_pixel[i:end, 2:])
362 ctUtils.updateImageFromArray(masked_sub_image.image, bad_pixel)
364 return masked_sub_image