我想在整个天空的草图上绘制一个FITS图像。
我在绘制整个天空时得到了这么多:
import matplotlib.pyplot as plt
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits
image_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
image_data = fits.getdata(image_file, ext=0)
plt.subplot(111, projection='aitoff')
plt.grid(True)
plt.imshow(image_data, cmap='gray')
plt.show()
但我似乎无法使FITS图像与网格正确对齐
image_data
只是一个像素值数组,实际上并不包含有关天空图上像素的位置和方向的任何信息。您还必须从FITS文件中提取该信息。
import matplotlib.pyplot as plt
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits
from astropy.wcs import WCS
from astropy.visualization.wcsaxes.frame import EllipticalFrame
image_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
image_header = fits.open(image_file)[0].header # extract header info
image_data = fits.getdata(image_file, ext=0)
# use the WCS class to get coordinate info and projection axes to use
wcs = WCS(image_header)
# make the axes using the EllipticalFrame class
ax = plt.subplot(projection=wcs, frame_class=EllipticalFrame)
# add the image
im = ax.imshow(image_data, origin='lower')
# add a grid
overlay = ax.get_coords_overlay('fk5')
overlay.grid(color='white', ls='dotted')
由于特定的图像示例不会延伸到整个天空,您只会看到一个小补丁(但您可以根据需要使用ax.set_xlim()
和ax.set_ylim()
扩展绘图,虽然我不确定单位是什么,它也值得注意到这个图像实际上只是覆盖了一小片天空),但是如果你的图像在整个天空上,它看起来就像是aitoff投影,如here所示。
我认为这只适用于最新版本的astropy(v3.1),Matplotlib(v3.0.2),因此需要Python> = 3.5。
您可能还想查看healpy,尽管在astropy示例FITS文件中无法读取。