Hi I am trying to extract a layer of my fits cube that as NAXIS 4 and write the data from one layer to a new file. Below is what I have tried.
'''
import matplotlib.pyplot as plt
from astropy.wcs import WCS
from astropy.io import fits
fname = ( '/home/natasha/Documents/J1601.7-7544_aFix_pol_I_15arcsec_5pln_cor.fits') #"MAR24/meerkat-hydra-selfcal-1-MFS-image.fits" # <---- Change me
with fits.open(fname) as hdul:
data = hdul[0].data
hdr = hdul[0].header
wcs = WCS(hdr)
fig = plt.figure(figsize=(12,12))
newdata = data[:,:,0,0]
hdu = fits.TableHDU(data=newdata)
hdu.writeto('/home/natasha/Documents/J1601test.fits')
ax = fig.add_subplot(projection=wcs.celestial)
ax.imshow(data[0,0,:,:], vmin=-1e-4, vmax=1e-3)
ax.set_xlabel("RA")
ax.set_ylabel("Dec")
'''
But I get : '''
Traceback (most recent call last):
File "new 1.py", line 27, in <module>
hdu = fits.TableHDU(data=newdata)
File "/usr/lib/python3/dist-packages/astropy/io/fits/hdu/table.py", line 738, in __init__
super().__init__(data, header, name=name, ver=ver, character_as_bytes=character_as_bytes)
File "/usr/lib/python3/dist-packages/astropy/io/fits/hdu/table.py", line 368, in __init__
raise TypeError('Table data has incorrect type.')
TypeError: Table data has incorrect type.
'''