Skip to content

Commit

Permalink
moving forward in passing current unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PFLeget committed May 29, 2024
1 parent 2827028 commit 864b8af
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions python/lsst/meas/algorithms/gp_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def jax_rbf_h(x1, x2, sigma, correlation_length):
return K

def updateMaskFromArray(mask, bad_pixel, interpBit):

Check failure on line 81 in python/lsst/meas/algorithms/gp_interpolation.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E302

expected 2 blank lines, found 1
x0 = mask.getX0()
y0 = mask.getY0()
for row in bad_pixel:
x = int(row[0] - x0)
y = int(row[1] - y0)
mask.array[x, y] |= interpBit
x0 = mask.getX0()
y0 = mask.getY0()
for row in bad_pixel:
x = int(row[0] - x0)
y = int(row[1] - y0)
mask.array[y, x] |= interpBit

class GaussianProcessJax:

Check failure on line 89 in python/lsst/meas/algorithms/gp_interpolation.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E302

expected 2 blank lines, found 1
def __init__(self, std=1.0, correlation_length=1.0, white_noise=0.0, mean=0.0):
Expand Down Expand Up @@ -180,10 +180,10 @@ def fit(self, x_good, y_good):
self.gp = treegp.GPInterpolation(
kernel=KERNEL,
optimizer="none",
normalize=True,
normalize=False,
white_noise=self.white_noise,
)
self.gp.initialize(x_good, y_good)
self.gp.initialize(x_good, y_good - self.mean)
self.gp.solve()

def predict(self, x_bad):
Expand All @@ -198,7 +198,7 @@ def predict(self, x_bad):
"""
y_pred = self.gp.predict(x_bad)
return y_pred
return y_pred + self.mean


class InterpolateOverDefectGaussianProcess:
Expand Down Expand Up @@ -330,6 +330,13 @@ 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:])
if np.isnan(kernel_amplitude):
filtre_nan = np.isnan(good_pixel[:, 2:])
good_pixel = good_pixel[~filtre_nan]
if good_pixel.size == 0:
warnings.warn('No bad or good pixels found. No interpolation performed.')
return sub_masked_image
kernel_amplitude = np.std(good_pixel[:, 2:])
try:
good_pixel = self._good_pixel_binning(copy.deepcopy(good_pixel))
except:
Expand Down Expand Up @@ -371,19 +378,20 @@ 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:
warnings.warn('WARNING: no defects found. No interpolation performed.')
return
Expand Down

0 comments on commit 864b8af

Please sign in to comment.