python提取图片中的曲线_如何从fits图像中提取点扩散函数?

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

假设您有一个图像image.fits,那么您可以使用astropy.modeling来拟合PSF,在计算出它在所提供图像中的中心位置之后,就可以使用astropy.modeling来拟合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()

你可能感兴趣的:(python提取图片中的曲线)