我有一个4545x4545像素的FITS文件,其标题包含其坐标系。由于DS9(另一个查看和处理FITS图像的软件)可以更好地处理彩色地图缩放,因此我有了一个想法:使用DS9打开FITS文件来调整图像的颜色映射
将此图像保存到PNG文件中
在matplotlib中加载这个PNG文件,并从原始FITS文件中添加头文件,这样我就可以将坐标系添加到PNG文件中。在
但是坐标显示不正确,因为像素化在每个步骤中都会更改为不同的值。如何正确地执行此操作?在
以下是我代码的相关部分:from astropy.io import fits
import matplotlib.pyplot as plt
import aplpy
from wcsaxes import WCSAxes
from astropy import wcs
import sys
import matplotlib.image as mpimg
image_fits = 'image_in.fits'
image_png = 'image_in.png' # this came from the one before, has different pixelization
image_data_png = mpimg.imread(image_png)
image_head_fits = fits.getheader(image_fits)
hdu_list = fits.open(image_fits)
F = aplpy.FITSFigure(hdu_list, figure=plt.figure(1))
fig = plt.figure()
mywcs = wcs.WCS(image_head_fits)
ax = WCSAxes(fig,[0.1, 0.1, 0.8, 0.8],wcs=mywcs)
fig.add_axes(ax)
ax.imshow(image_data_png)
plt.savefig('image_out.png')