1

I have a FITS file of 4545x4545 pixels with a header containing its coordinate system. Since DS9 (another software to view and handle FITS images) handles the color map scaling better, I had the idea of:

  1. open the FITS file using DS9 to tweak the color map of the image,
  2. save this image in a PNG file,
  3. load this PNG file in matplotlib and add the header from the original FITS file, so I can add the coordinate system to the PNG file.

But the coordinates are not showing correctly, because the pixelization changes to different values in every step. How can I do this correctly?

This the relevant part of my code:

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')
  • pyavm (https://github.com/astrofrog/pyavm) is meant to add FITS headers to png images. You might also look at http://aplpy.readthedocs.io/en/stable/api/aplpy.make_rgb_cube.html. A fairly involved example of how to do this is here: https://github.com/keflavich/W51_ALMA_2013.1.00308.S/blob/b2d71e9e1b608fee5b596e755d1b8a7a24f8fa44/plot_code/overview_rgb_figure.py. None of these are answers, but they might point you in the right direction – keflavich Feb 02 '17 at 01:00

0 Answers0