1

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?

Yann
  • 2,426
  • 1
  • 16
  • 33
  • How/where do we see the WCS info? Could you add those infos (what the _preserved_ and _non-preserved_ scenarios look like) to your question? – Brandt Sep 15 '21 at 08:23
  • @Brandt I have added images of the the preserved and non-preserved scenarios – Wesley Van Kempen Sep 15 '21 at 08:45
  • And what is the code you are using for the rectangular cut? – Brandt Sep 15 '21 at 12:07
  • It looks like the pixel of reference is wrong. It's a long time since last FITS cutout, but I think it is lower-left pixel...but I may be wrong...anyhow, check that: it looks like your reference pixel has moved from the rectangular cutout to the middle of the circular one. – Brandt Sep 15 '21 at 12:11

0 Answers0