如何从拟合图像中提取点扩散函数



我是python编码的新手,我有一个星星的.fits图像,我想从中提取PSF。我将如何做到这一点?

在那之后,我将如何拟合高斯曲线?

"从中提取 PSF"到底是什么意思?你想找到它的位置吗?你想在它周围剪出一个盒子吗?你到底想用它做什么?

假设您只有一个包含 PSF 的图像image.fits,在确定 2D 高斯在提供的图像中的中心位置后,您可以使用 astropy.modeling 将 2D 高斯拟合到 PSF。

import numpy as np
import matplotlib.pyplot as plt
from astropy.modeling import models, fitting
from astropy.io import fits
# Load the data and find center of PSF
image = fits.getdata('path/image.fits')
cents = np.where(image == np.max(image))
xc = int(cents[1])
yc = int(cents[0])
# Cut out smaller box around PSF
bb = 30
box = image[yc-bb:yc+bb,xc-bb:xc+bb]
yp, xp = box.shape
# Generate grid of same size like box to put the fit on
y, x, = np.mgrid[:yp, :xp]
# Declare what function you want to fit to your data
f_init = models.Gaussian2D()
# Declare what fitting function you want to use
fit_f = fitting.LevMarLSQFitter()
# Fit the model to your data (box)
f = fit_f(f_init, x, y, box)
# Plot the data with the best-fit model
plt.figure(figsize=(8, 2.5))
plt.subplot(1, 3, 1)
plt.imshow(box)
plt.title("Data")
plt.subplot(1, 3, 2)
plt.imshow(f(x, y))
plt.title("Model")
plt.subplot(1, 3, 3)
plt.imshow(box - f(x, y))
plt.title("Residual")
plt.show()

图片:PSF 的 2D 高斯拟合

我建议使用astropy或photoutils中可用的函数。我已经在 astropy 中使用了通风卷积来模拟 PSF,但从您的问题来看,我认为 photoutils PSF 或 ePSF 页面就是您正在寻找的。

最新更新