I want to make an RGB image using 3 FITS files: one IR image from Spitzer and the other two from UVIT. I tried to make them using make_lupton_rgb in Astropy, but it doesn't work in the case of FITS files with unequal dimensions. I tried to use DS9, but I cannot export the resultant RGB image due to different dimensions. How do I get around this?

hdu1 = fits.open('fuv_.fits')
fdata = hdu1[0].data
w1 = wcs.WCS(hdu1[0].header)
hdu2 = fits.open('nuvcrop.fits')
ndata = hdu2[0].data
w2 = wcs.WCS(hdu2[0].header)

datat = hdu3[0].data

fig = plt.figure(figsize=(40, 40))
ax = plt.subplot(projection=w2)

rgb_default = make_lupton_rgb(0.5*ndata, 0.5*ndata,3*fdata)#, filename="qw.jpeg")
plt.imshow(datat, origin='lower')
  • $\begingroup$ An RGB image consists of three values per pixel, so your three images need some values for these pixels. Unless I misunderstand, isn't it just a question of interpolating your three images to a common grid? $\endgroup$
    – pela
    Commented Feb 1, 2023 at 15:28

1 Answer 1


You can use the reproject package to interpolate two of the fits files onto the WCS of the third file.

import numpy as np
import matplotlib.pyplot as plt
import astropy.visualization
import reproject

fdata hdu1[0].data

ndata, _ = reproject.reproject_interp(hdu2[0], hdu1[0].header)

datat, _ = reproject.reproject_interp(hdu3[0], hdu1[0].header)

image_rgb = astropy.visualization.make_lupton_rgb(fdata, ndata, datat, filename="qw.jpeg)

This is just an example, make sure to choose to interpolate onto the coordinate system of whatever image you desire.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .