使用astropy/fits d从matplotlib绘图中检索投影值

2024-06-27 20:40:39 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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文档,不清楚某些值是如何获得的,比如那些与原点有关的值。使用的fits文件可以从哈勃遗留档案免费获得,尽管任何x,y数据在技术上都应该是合适的。fits头包含前面提到的转换的所有值,但是我不完全理解它们的用法。我想这有点遥不可及,但如果你能帮忙,谢谢你。在


Tags: image信息数据文件pltopenax投影hst
1条回答
网友
1楼 · 发布于 2024-06-27 20:40:39

一旦有了WCS对象,就可以使用两种方法从x、y->;RA、Dec或相反的方法进行转换。它们分别是w.all_pix2world()和{},例如

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])

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

^{pr2}$

其中RA,Dec是以度为单位的。 最好使用all_pix2world而不是wcs_pix2world来应用所有的变换(核心WCS从像素到RA的变换,CDi_j矩阵和CRPIXi/CRVALi以及任何{}多项式)来应用所有的变换(通常哈勃仪器就是这样)

相关问题 更多 >