[REDACTED]\Python310\site-packages\regularizepsf\corrector.py:239: RuntimeWarning: invalid value encountered in divide
[v / v.sum() for v in self._evaluations.values()], dtype=float)
but what's been surprising is that I am only getting this when making model some images and not others.
from typing import List
from pathlib import Path
import regularizepsf as rpsf
import numpy as np
COMA_PSF_SIZE = 16 # size of the PSF model to use in pixels
COMA_PATCH_SIZE = 128 # square side dimension PSF will be applied over
COMA_ALPHA = 3 # see paper
COMA_EPSILON = 0.3 # see paper
fwhm_x_target, fwhm_y_target = 2.855, 2.8514
IMAGES_FOLDER = Path("G:/Raw Data/Summer 2003/September 8, 2003/m23")
def make_coma_correction_model(
images: List[str] | List[Path], xfwhm_target: float, yfwhm_target: float
) -> rpsf.ArrayCorrector:
# Define the target PSF
@rpsf.simple_psf
def target(
x,
y,
x0=COMA_PATCH_SIZE / 2,
y0=COMA_PATCH_SIZE / 2,
sigma_x=xfwhm_target / 2.355,
sigma_y=yfwhm_target / 2.355,
):
return np.exp(
-(
np.square(x - x0) / (2 * np.square(sigma_x))
+ np.square(y - y0) / (2 * np.square(sigma_y))
)
)
target_evaluation = target(
*np.meshgrid(np.arange(COMA_PATCH_SIZE), np.arange(COMA_PATCH_SIZE))
)
# Extract all the stars from that image and create a PSF model with a target PSF
image_paths = [str(p) for p in images] # No support for pathlib.Path yet
cpc = rpsf.CoordinatePatchCollection.find_stars_and_average(
image_paths, COMA_PSF_SIZE, COMA_PATCH_SIZE
)
return cpc.to_array_corrector(target_evaluation)
def ac1():
ac_1_images = [ IMAGES_FOLDER / f"m23_3.5-{x}.fit" for x in range (101, 121)]
return make_coma_correction_model(
ac_1_images, fwhm_x_target, fwhm_y_target
)
def ac2():
ac_2_images = [ IMAGES_FOLDER / f"m23_3.5-{x}.fit" for x in range (521, 541)]
return make_coma_correction_model(ac_2_images, fwhm_x_target, fwhm_y_target)
if __name__ == "__main__":
# Note that when generating array corrector model using ac1, we don't get any warning
# While when using ac2, we do. See this by just ac1 and commenting ac2 and vice versa.
ac1()
ac2()
Are these regions in the original images where it wasn't possible to generate a psf model?