1

I am looking for a way to check if there is valid WCS data in the FITS file header or not.

When creating a WCS from FITS file with no WCS inside (ds9 does not see any WCS for example) I surprisingly had no warnings or errors.

from astropy import wcs, fits

hdu = fits.open(path_to_fit_file)
header = hdu[0].header
w = wcs.WCS(header)
print(w)

This code gave

WCS Keywords

Number of WCS axes: 2
CTYPE : ''  ''  
CRVAL : 0.0  0.0  
CRPIX : 0.0  0.0  
PC1_1 PC1_2  : 1.0  0.0  
PC2_1 PC2_2  : 0.0  1.0  
CDELT : 1.0  1.0  
NAXIS : 1920  1200

wcs.validate also does not return a clear answer, only some warnings.

Here is a full header:

SIMPLE  =                    T / C# FITS: 07/16/2023 02:02:13                   
BITPIX  =                   16                                                  
NAXIS   =                    2 / Dimensionality                                 
NAXIS1  =                 1920                                                  
NAXIS2  =                 1200                                                                                        
BLKLEVEL=                    0 /                                                                                  
CAMID   = '926f8841ad8ccd139'  /                                                
OBJCTALT=     34.4417644433851 /                                                
GPS_EU  =               3868.9 / EndShutterMicroSeconds                         
OBJECT  = 'Sa11    '           /                                                
EQUINOX =     2023.53719335833 /                                                
OBJCTAZ =     215.096223700444 /                                                
EXTEND  =                    T / Extensions are permitted                       
BZERO   =                32768 /                                                
BSCALE  =                    1 /                                                
ROWORDER= 'TOP-DOWN'           /                                                
EXPTIME =                    3 / seconds                                        
XPIXSZ  =                 5.86 / microns, includes binning if any               
YPIXSZ  =                 5.86 / microns, includes binning if any               
XBINNING=                    1 /                                                
YBINNING=                    1 /                                                
CCD-TEMP=                -15.1 / C                                              
FRAMETYP= 'Light   '           /                                                
SWCREATE= 'SharpCap v4.0.9268.0, 64 bit' /                                      
DATE-OBS= '2023-07-15T23:02:10.0038605' / GPS:Start Exposure                    
DATE-END= '2023-07-15T23:02:13.1115415' / System Clock:Frame Received           
DATE-OB2= '2023-07-15T23:02:13.0038689' / GPS:End Exposure                      
DATE-AVG= '2023-07-15T23:02:11.5038647' / GPS:Mid Exposure                                                                     
FOCALLEN=                  300 /                                                
RA      =     281.387381627622 / Epoch : JNOW                                   
DEC     =    0.507833420011808 / Epoch : JNOW                                   
OBJCTRA = '18 45 32.000'       / Epoch : JNOW                                   
OBJCTDEC= '+00 30 28.000'      / Epoch : JNOW                                                                                
END                                                                                                 
Viktor
  • 313
  • 2
  • 11
  • Reading through the FITS 4.0 standard document, section 8 ("world-coordinate systems"), I see a lot of "may" and "optional" mentions, together with a list of default values, but I don't notice a mandatory keyword. So it looks like WCS specifiation is largely optional, with default values assumed, and that is what you see here. In fact, that default WCS is just a 1-to-1 pixel coordinate system: a pixel corresponds to itself. – 9769953 Jul 26 '23 at 09:06
  • 1
    [continued] That would also mean there is no way to verify a FITS file has an invalid WCS (other than going out of bounds and such, e.g. declination being larger than 100). You'll have to define for yourself what consistutes a valid WCS, and what a missing or invalid WCS. Which is context dependent. You could check for e.g. CDELT being 1.0, that seems a reasonably valid check for most instruments (and 1.0 can likely be compared directly to 1.0, since the float 1.0 is exact, as long as it's not the result of a calculation; which is likely the case here). – 9769953 Jul 26 '23 at 09:10

0 Answers0