0

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:

expected result

where both parts of the image come from different fits files which are

file1

and

file2

usernumber
  • 1,958
  • 1
  • 21
  • 58

1 Answers1

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.

usernumber
  • 1,958
  • 1
  • 21
  • 58
  • 1
    You should try http://reproject.readthedocs.org/, which uses the same algorithm as montage but is being more actively maintained (it's by the same developer) – keflavich Mar 05 '19 at 18:57
  • @keflavich By using the `reproject_interp` function then plotting both images in the same figure? – usernumber Mar 06 '19 at 09:41
  • yes, or reproject_exact; you can just use reproject instead of montage – keflavich Mar 06 '19 at 13:56