在图像中绘制几个字段

时间:2019-03-04 10:21:48

标签: python-3.x astropy fits

如何在单个图像中绘制几个FITS字段?每个FITS文件都覆盖天空的相邻部分。

HDU的data字段仅包含图像。因此,要在正确的坐标处绘制每个图像,我需要从header字段中获取信息。但是我如何在pyplot上传递这些信息?

我尝试使用astropy.WCS进行以下操作,以便将标头中的信息用于绘图中

import matplotlib.pyplot as plt
from astropy.io import fits
from astropy.wcs import WCS

image_files = ['file1.fits', 'file2.fits']
for image_file in image_files:
    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)

    ax = plt.subplot(projection=wcs)
    im = ax.imshow(image_data, origin='lower')

这仅显示最后一张图像。


我期望这样的事情:

expected result

图像的两个部分都来自不同的拟合文件

file1

file2

1 个答案:

答案 0 :(得分:1)

我找到了Montage software。有一个名为montage-wrapper的Python包装器。 mosaic函数通过将多个FITS图像并置来产生新的FITS图像。然后可以读取并绘制新的FITS文件。

import montage_wrapper as montage

montage.mosaic(input_directory, output_directory)

hdu = fits.open(filename)
image_header = hdu[0].header
image_data = hdu[0].data

wcs = WCS(image_header)
ax = plt.subplot(projection=wcs)
im = ax.imshow(image_data, origin='lower')
plt.show()

其中input_directory包含file1.fitsfile2.fits