【问题标题】:Retrieve projection values from matplotlib plot with astropy/fits data使用 astropy/fits 数据从 matplotlib 图中检索投影值
【发布时间】:2019-08-02 05:06:29
【问题描述】:

我需要获取 matplotlib 投影的转换后的 x,y 像素值。特别是这是一个天文世界坐标系转换,来自 fit 数据文件。数据文件提供了一个提供投影信息的标题,但我知道没有人在不知道我没有的信息的情况下直接使用它。这是当前代码:

image_detection = fits.open("hst_12311_08_wfc3_uvis_total_drz.fits")['SCI'].data

wlist = fits.open("hst_12311_08_wfc3_uvis_total_drz.fits")['SCI']

w = wcs.WCS(wlist.header)
mean, median, std = sigma_clipped_stats(image_detection, sigma=3.0)

iraffind = IRAFStarFinder(fwhm=3.0, threshold=5*std, exclude_border=True)
sources = iraffind(image_detection - median)

positions = (sources['xcentroid'], sources['ycentroid'])
apertures = CircularAperture(positions, r = 4.0)

fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection = w)
ax.imshow(transform(image_detection), cmap='gray_r', origin='lower')
# ax.colorbar()
apertures.plot(color='blue', lw=1.5, alpha=0.5)
plt.savefig("apertures.pdf")
ax.xlabel('Right Ascension')
ax.ylabel('Declination')
plt.show()

我所追求的是那些以 x,y 给出的位置值,转换为世界坐标,由投影绘制。我检查了 WCS 上的 astropy 文档,不清楚如何获得某些值,例如与原点有关的值。使用的 fit 文件可从 Hubble Legacy Archive 中免费获得,但任何 x,y 数据在技术上都应该是合适的。 fit 标头包含上述转换的所有值,尽管我不完全理解它们的用法。我认为这有点远,但如果你能提供帮助,谢谢。

【问题讨论】:

  • 您希望将 FITS 图像中的 x,y 映射到 RA,Dec 还是绘图坐标中的 x,y 映射到 RA,Dec ?
  • 我正在寻找 x,y 转换后的数据,即 RA,Dec. 中的 x,y 值是什么。我不确定这与绘图坐标数据不同,因为它们按像素排列并且应该是相同的。

标签: python matplotlib projection astropy


【解决方案1】:

一旦您拥有WCS 对象,您就可以使用两种方法从 x,y->RA,Dec 或相反的方向进行转换。这些分别是w.all_pix2world()w.all_world2pix(),例如

from astropy.io import fits
from astropy import wcs

wlist = fits.open("hst_12311_08_wfc3_uvis_total_drz.fits")['SCI']
w = wcs.WCS(wlist.header)

# Convert chip center from pixels to RA, Dec
radec_coords = w.all_pix2world(3057, 3045, 1)
print("RA, Dec=", radec_coords[0], radec_coords[1])

# Convert a RA, Dec pair to x,y
coords = [(279.1017383673262, -23.90274423755417)] # CRVAL1, 2 from header
pix_coords = w.all_world2pix(coords, 1)
print("X,Y=", pix_coords[0][0], pix_coords[0][1])

这将产生输出(允许舍入...)

 RA, Dec= 279.10174439, -23.90274424
 X,Y= 3057.5, 3045.0

RA、Dec 以度为单位。 最好使用all_pix2world 而不是wcs_pix2world 来应用所有转换(核心WCS 从像素到RA 的转换,由CDi_j 矩阵和CRPIXi/CRVALi 给出的Dec,以及任何-SIP 多项式)如果图像中可能存在图像失真(通常是哈勃仪器的情况)

【讨论】:

    猜你喜欢
    • 2022-11-21
    • 2016-08-27
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    相关资源
    最近更新 更多