astropy-wcs FITS error solution

L'analyse des images.
Répondre
dan_adrian
Messages : 29
Enregistré le : 09 août 2021, 10:03

astropy-wcs FITS error solution

Message 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..

Cyril Cavadore
Messages : 4492
Enregistré le : 18 juin 2009, 22:41
Localisation : 42

Re: astropy-wcs FITS error solution

Message par Cyril Cavadore »

Interesting finding.
FITS header is a nightmare, there's no normalization whatsoever and everyone does what he wants...
Cyril Cavadore, ALCOR-SYSTEM, Auteur de PRISM
http://www.alcor-system.com

Pour reporter vos problème, la marche à suivre est ici
viewtopic.php?f=7&t=1403
Répondre