问题
How would I plot several FITS fields in a single image ? Each FITS file covers a neighboring part of the sky.
The data
field of the HDU only contains the image. So to plot each image at the right coordinates, I need to get information from the header
field. But how do I pass that information on the pyplot?
I tried the following, using astropy.WCS
so that the information from the headers be used in the plots
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')
This only shows the last image.
I'm expecting something like this:
where both parts of the image come from different fits files which are
and
回答1:
I found the Montage software. There is a Python wrapper for it called montage-wrapper
. The mosaic function produces a new FITS image by juxtaposing several FITS images. That new FITS file can then be read and plotted.
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()
where input_directory
contains file1.fits
and file2.fits
.
来源:https://stackoverflow.com/questions/54981166/plot-several-fields-in-an-image