How to make circular cut-out from FITS file and preserve the WCS

270 Views Asked by At

I have been able to extract the region I want using the following code:

hdulist = fits.open('/Users/Wesley/OneDrive/Documents/Honours/Data and Code/M101-10/2-Luminosity/M101-LMIPS24.fits')
hdu = hdulist[0]
wcs = WCS(hdulist[0].header)

center = PixCoord(144, 144)
aperture = CirclePixelRegion(center, 85)
mask = aperture.to_mask(mode='exact')
data = mask.cutout(hdu.data, wcs=wcs)
weighted_data = mask.multiply(hdu.data)
hdulist.close()

plt.subplot(1, 1, 1)
plt.title("Data cutout multiplied by mask", size=9)
plt.imshow(weighted_data, cmap=plt.cm.viridis, origin='lower')

hdulist[0].data = weighted_data
hdulist.writeto('/Users/Wesley/OneDrive/Documents/Honours/Data and Code/M101-10/2-Luminosity/M101-Test.fits', overwrite="True")

Preserved WCS before cutout

Unpreserved WCS after cutout

But I have not been able to find a way to preserve the WCS. I have been able to do this using a rectangular cutout using 2Dcutout and preserve the WCS. Can anyone hit me with some tips?

0

There are 0 best solutions below