I want to correct the header and the disposition of data content of a fits file. I show in the next script the way I am trying to update the fits.
cubefits = 'data.fits'
hdul = fits.open(cubefits,mode='update')
hdul.info()
hdul.readall()
hd = hdul[0].header
data = hdul[0].data
NAXIS1 = 761
NAXIS2 = 1297
NAXIS3 = 833
data.shape = (833,1297,761)
I notice that the header does not match the data shape, so, I rearrange it as follows:
data_new = np.moveaxis( data,0,2 )
data_new = np.moveaxis( data_new,0,1 )
hdul[0].data = data_new
where data_new.shape = (761,1297,833).
Then, I close to save hdul.close().
But when I load it again the hdul[0].data.shape is correct but the data are mixed up and
NAXIS1 = 833
NAXIS2 = 1297
NAXIS3 = 761
I found out, that it is just the standard disposition of the fits data. NAXIS1 corresponds to the 0 axes in the data array.