Skip to content

Commit

Permalink
add logging instead of warning
Browse files Browse the repository at this point in the history
  • Loading branch information
PFLeget committed Sep 18, 2024
1 parent 2577c4c commit 0b0b8d4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions python/lsst/meas/algorithms/gp_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from jax import jit
import jax.numpy as jnp

import warnings
import logging

__all__ = ["interpolateOverDefectsGP"]

Expand Down Expand Up @@ -276,7 +276,9 @@ class InterpolateOverDefectGaussianProcess:
The threshold for sub-dividing the bad pixel array to avoid memory error. Default is 20000.
correlation_length_cut : `int`, optional
The factor by which to dilate the bounding box around defects. Default is 5.
log : `lsst.log.Log`, `logging.Logger` or `None`, optional
Logger object used to write out messages. If `None` a default
logger will be used.
"""

def __init__(
Expand All @@ -289,6 +291,7 @@ def __init__(
threshold_dynamic_binning=1000,
threshold_subdivide=20000,
correlation_length_cut=5,
log=None,
):
if method == "jax":
self.GaussianProcess = GaussianProcessJax
Expand All @@ -297,6 +300,7 @@ def __init__(
else:
raise ValueError("Invalid method. Must be 'jax' or 'treegp'.")

self.log = log or logging.getLogger(__name__)
self.bin_spacing = bin_spacing
self.threshold_subdivide = threshold_subdivide
self.threshold_dynamic_binning = threshold_dynamic_binning
Expand Down Expand Up @@ -397,7 +401,7 @@ def interpolate_sub_masked_image(self, sub_masked_image):
)
# Do nothing if bad pixel is None.
if bad_pixel.size == 0 or good_pixel.size == 0:
warnings.warn("No bad or good pixels found. No interpolation performed.")
self.log.info("No bad or good pixels found. No interpolation performed.")
return sub_masked_image
# Do GP interpolation if bad pixel found.
else:
Expand All @@ -411,7 +415,7 @@ def interpolate_sub_masked_image(self, sub_masked_image):
filter_finite = np.isfinite(good_pixel[:, 2:]).T[0]
good_pixel = good_pixel[filter_finite]
if good_pixel.size == 0:
warnings.warn(
self.log.info(
"No bad or good pixels found. No interpolation performed."
)
return sub_masked_image
Expand All @@ -421,7 +425,7 @@ def interpolate_sub_masked_image(self, sub_masked_image):
try:
good_pixel = self._good_pixel_binning(copy.deepcopy(good_pixel))
except Exception:
warnings.warn(
self.log.info(
"Binning failed, use original good pixel array in interpolation."
)

Expand Down Expand Up @@ -461,6 +465,7 @@ def interpolateOverDefectsGP(
bin_spacing=25,
threshold_dynamic_binning=1000,
threshold_subdivide=20000,
log=None,
):
"""
Interpolate over defects in an image using Gaussian Process interpolation.
Expand All @@ -485,6 +490,9 @@ def interpolateOverDefectsGP(
The threshold for dynamic binning. Default is 1000.
threshold_subdivide : `int`, optional
The threshold for subdividing defects. Default is 20000.
log : `lsst.log.Log`, `logging.Logger` or `None`, optional
Logger object used to write out messages. If `None` a default
logger will be used.
Returns
-------
Expand All @@ -496,8 +504,9 @@ def interpolateOverDefectsGP(
If no defects are found in the image.
"""
log = log or logging.getLogger(__name__)
if badList == [] or badList is None:
warnings.warn("WARNING: no defects found. No interpolation performed.")
log.info("No defects found. No interpolation performed.")
return
gp = InterpolateOverDefectGaussianProcess(
image,
Expand All @@ -507,5 +516,6 @@ def interpolateOverDefectsGP(
bin_spacing=bin_spacing,
threshold_dynamic_binning=threshold_dynamic_binning,
threshold_subdivide=threshold_subdivide,
log=log,
)
gp.interpolate_over_defects()

0 comments on commit 0b0b8d4

Please sign in to comment.