Page 1 sur 1

astropy-wcs FITS error solution

Posté : 01 nov. 2023, 03:13
par dan_adrian
Prism v.11 creates a FITS header that is not compatible with astropy.wcs (world coord. system).
In order to assure compatibility, I had to delete the following header information

Code : Tout sélectionner


from astropy.io import fits

# open the fits
hdul = fits.open('PRISM01.fits', mode='update')
h = hdul[0].header

# remove keywords
h.remove('XPIXELSZ')
h.remove('YPIXELSZ')
h.remove('CDELTM1')
h.remove('CDELTM2')

# save the header
hdul.flush()

# Close
hdul.close()
Test:

Code : Tout sélectionner

from astropy.wcs import WCS
from astropy.io import fits


hdulist = fits.open('PRISM01.fits')  

wcs = WCS(hdulist[0].header)  
wcs

Output:

Code : Tout sélectionner

WCS Keywords

Number of WCS axes: 2
CTYPE : 'RA---TAN'  'DEC--TAN'  
CRVAL : 338.9776673617  33.94929211956  
CRPIX : 2262.5  1812.5  
CD1_1 CD1_2  : -8.023616067367e-06  -0.0002569870529751  
CD2_1 CD2_2  : -0.0002570335859688  7.94778752437e-06  
NAXIS : 4524  3624

Without keyword deletion:

Code : Tout sélectionner


ValueError: ERROR 5 in wcsset() at line 2775 of file cextern/wcslib/C/wcs.c:
Invalid parameter value.
ERROR 4 in linset() at line 737 of file cextern/wcslib/C/lin.c:
Failed to initialize distortion functions.
ERROR 3 in dssset() at line 2697 of file cextern/wcslib/C/dis.c:
Coefficient scale for DSS on axis 1 is zero..


Re: astropy-wcs FITS error solution

Posté : 14 nov. 2023, 01:28
par Cyril Cavadore
Interesting finding.
FITS header is a nightmare, there's no normalization whatsoever and everyone does what he wants...