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

标签 python fits

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

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

最佳答案

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

假设您只有一张包含 PSF 的图像 image.fits,您可以使用 astropy.modeling 将 2D Gaussian 拟合到您的 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

关于python - 如何从拟合图像中提取点扩散函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55883497/

相关文章:

Python打开大适合数据缓冲区大小错误

python - 如何使用 FitsIO (python) 创建空的 FITS 图像?

python - 泡沫:谷歌应用引擎支持

python - 如何安装sklearn?

python : How to write list to csv with N items per row

c++ - 如何从CCfits获取图像数据

python - 从 SFTP 服务器打开 Astropy FITS 文件

python - 在模块中导入类

python - pyqt5 覆盖 dropEvent python