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

时间:2019-04-27 18:13:40

标签: python fits

我是python编码的新手,我有一个.fits星星的图片,我想从中提取PSF。我该怎么做?

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

2 个答案:

答案 0 :(得分:2)

“从中提取PSF”到底是什么意思?您想找到它的位置吗?您要在它周围切一个盒子吗?您最终想要做什么呢?

假设其中只有一个图像image.fits,其中包含PSF,则可以在确定所提供图像的中心位置之后,使用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()

Image: 2D Gaussian fit to PSF

答案 1 :(得分:0)

我建议使用astropyphotoutils中可用的功能。我曾经用airy convolution来为PSF建模,但从您的问题来看,我认为photoutils PSFePSF页面正是您想要的。