【问题标题】:How do you extract a point spread function from a fits image?如何从拟合图像中提取点扩散函数?
【发布时间】:2019-06-20 11:10:32
【问题描述】:

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

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

【问题讨论】:

    标签: python fits


    【解决方案1】:

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

    假设您只有一个带有 PSF 的图像 image.fits,您可以使用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

    【讨论】:

      【解决方案2】:

      我建议使用astropyphotoutils 中提供的功能。我已经在 astropy 中使用 airy convolution 对 PSF 进行建模,但根据您的问题,我认为 photoutils PSFePSF 页面是您正在寻找的。​​p>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-09
        • 2018-12-10
        • 1970-01-01
        • 2019-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多