diff --git a/python/lsst/meas/algorithms/gp_interpolation.py b/python/lsst/meas/algorithms/gp_interpolation.py index 35378fd67..3cafaee2f 100644 --- a/python/lsst/meas/algorithms/gp_interpolation.py +++ b/python/lsst/meas/algorithms/gp_interpolation.py @@ -9,6 +9,8 @@ from jax import jit import jax.numpy as jnp +import warnings + __all__ = ["interpolateOverDefectsGP"] @@ -307,7 +309,7 @@ def interpolate_sub_masked_image(self, sub_masked_image): sub_masked_image, self.defects, buffer=cut ) # Do nothing if bad pixel is None. - if np.shape(bad_pixel)[0] == 0: + if bad_pixel.size == 0 or good_pixel.size == 0: return sub_masked_image # Do GP interpolation if bad pixel found. else: @@ -318,7 +320,10 @@ def interpolate_sub_masked_image(self, sub_masked_image): np.mean(sub_image_array[np.isfinite(sub_image_array)]) ) kernel_amplitude = np.std(good_pixel[:, 2:]) - good_pixel = self._good_pixel_binning(copy.deepcopy(good_pixel)) + try: + good_pixel = self._good_pixel_binning(copy.deepcopy(good_pixel)) + except: + warnings.warn('Binning failed, use original good pixel array in interpolate over.') gp = self.GaussianProcess( std=np.sqrt(kernel_amplitude), @@ -355,19 +360,21 @@ def interpolateOverDefectsGP(image, fwhm, badList, method="treegp", bin_spacing= Returns: None """ - import pickle - dic = {'image': image, - 'fwhm': fwhm, - 'badList': badList, - 'method': method, - 'bin_spacing': bin_spacing, - 'threshold_subdivide': - threshold_subdivide} - file_name_out = get_name_pkl() - fileout = open(file_name_out, 'wb') - print(f'JE PASSE PAR LA | {file_name_out}') - pickle.dump(dic, fileout) - fileout.close() + # import pickle + # dic = {'image': image, + # 'fwhm': fwhm, + # 'badList': badList, + # 'method': method, + # 'bin_spacing': bin_spacing, + # 'threshold_subdivide': + # threshold_subdivide} + # file_name_out = get_name_pkl() + # fileout = open(file_name_out, 'wb') + # print(f'JE PASSE PAR LA | {file_name_out}') + # pickle.dump(dic, fileout) + # fileout.close() + if badList == [] or badList is None: + return gp = InterpolateOverDefectGaussianProcess(image, defects=badList, method=method, fwhm=fwhm, bin_spacing=bin_spacing, threshold_subdivide=threshold_subdivide)