I am handling two fits file (the header in the following), EXEMPLE case where it does work and the Orion case where it does not work.
The few lines necessary to read and handle the fits.
from astropy.io import fits
from astropy.wcs import WCS
hdul = fits.open(cubefits)
hdul.info()
hdul.readall()
hd = hdul[0].header
wcs = WCS(hd)
For the EXAMPLE (in the following) I obtain a correct output when I print the wcs:
WCS Keywords
Number of WCS axes: 3
CTYPE : 'RA---TAN' 'DEC--TAN' 'FREQ'
CRVAL : 0.70395330810396 0.69721933449752 125.0
CRPIX : 507.90474039695 503.02270076207 1.0
PC1_1 PC1_2 PC1_3 : 1.0 0.0 0.0
PC2_1 PC2_2 PC2_3 : 0.0 1.0 0.0
PC3_1 PC3_2 PC3_3 : 0.0 0.0 1.0
CDELT : 0.0013888888888889 0.0013888888888889 1.0
NAXIS : 1009 1009 181
For the Orion case I have an error by launching the same code:
In [94]: wcs = WCS(hd)
WARNING: FITSFixedWarning: The WCS transformation has more axes (3) than the image it is associated with (0) [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'celfix' made the change 'Ill-conditioned coordinate transformation parameter'. [astropy.wcs.wcs]
---------------------------------------------------------------------------
InvalidTransformError Traceback (most recent call last)
Input In [94], in <cell line: 1>()
----> 1 wcs = WCS(hd)
InvalidTransformError: ERROR 7 in wcsset() at line 2660 of file cextern/wcslib/C/wcs.c:
Ill-conditioned coordinate transformation parameter.
ERROR 4 in celset() at line 441 of file cextern/wcslib/C/cel.c:
Ill-conditioned coordinate transformation parameters
No valid solution for latp for these values of phip, phi0, and theta0.
Here the headers of the two fits files:
### EXAMPLE
SIMPLE = T / conforms to FITS standard
BITPIX = -64 / array data type
NAXIS = 3 / number of array dimensions
NAXIS1 = 1009
NAXIS2 = 1009
NAXIS3 = 181
WCSAXES = 3 / Number of coordinate axes
CRPIX1 = 507.90474039695 / Pixel coordinate of reference point
CRPIX2 = 503.02270076207 / Pixel coordinate of reference point
CRPIX3 = 1.0 / Pixel coordinate of reference point
CDELT1 = 0.0013888888888889 / [deg] Coordinate increment at reference point
CDELT2 = 0.0013888888888889 / [deg] Coordinate increment at reference point
CDELT3 = 1.0 / [Hz] Coordinate increment at reference point
CUNIT1 = 'deg' / Units of coordinate increment and value
CUNIT2 = 'deg' / Units of coordinate increment and value
CUNIT3 = 'Hz' / Units of coordinate increment and value
CTYPE1 = 'RA---TAN' / Right ascension, gnomonic projection
CTYPE2 = 'DEC--TAN' / Declination, gnomonic projection
CTYPE3 = 'FREQ' / Frequency (linear)
CRVAL1 = 0.70395330810396 / [deg] Coordinate value at reference point
CRVAL2 = 0.69721933449752 / [deg] Coordinate value at reference point
CRVAL3 = 125.0 / [Hz] Coordinate value at reference point
LONPOLE = 180.0 / [deg] Native longitude of celestial pole
LATPOLE = 0.69721933449752 / [deg] Native latitude of celestial pole
RADESYS = 'ICRS' / Equatorial coordinate system
CUBE =
DATAS =
DATE = '2020-03-30 15:48:36.001328' / date of the creation
### ORION
SIMPLE = T / conforms to FITS standard
BITPIX = 8 / array data type
NAXIS = 0 / number of array dimensions
EXTEND = T /
HIERARCH LASER_SHIFT = '-5.603303303303305' / [sample] Shift between kids and la
CONTINUE '100_S49749_NA_NA'
SCAN = '49749 '
OBJECT = 'OrionSim' /
OBSTYPE = 'OTF ' / Observation Type
OBSDATE = '2022-08-31T00:00:00.000'
SITELAT = '-23.00575' / [deg] Site latitude
SITELONG= '-67.7592222222222'
SITEELEV= '5105.0 ' / [m] Site elevation
PROJID = 'E-0109.A-0442A-2022'
SCANNUM = '49749 '
OBS-ID = '49749 '
DATE = '2023-02-15T11:57:57.513287'
EXPTIME = '395.13672846369445' / [s] Exposure time
DATE-OBS= '2022-08-31T11:01:12.421'
DATE-END= '2022-08-31T11:07:47.558'
ORIGIN = 'None '
NINT = '736 ' / Total number of blocs
NPTINT = '2048 ' / Number of points per bloc
NSAMPLES= '1507328 '
LABEL = 'None '
INTTIME = '0.000262144' / [s] Integration Time per sample
WCSAXES = 3 / Number of coordinate axes
CRPIX1 = 381 / Pixel coordinate of reference point
CRPIX2 = 649 / Pixel coordinate of reference point
CRPIX3 = 0.00000000000 / Pixel coordinate of reference point
CDELT1 = 0.0011111111111111 / [deg] Coordinate increment at reference point
CDELT2 = 0.0011111111111111 / [deg] Coordinate increment at reference point
CDELT3 = 600000000.000 / [Hz] Coordinate increment at reference point
CUNIT1 = 'deg' / Units of coordinate increment and value
CUNIT2 = 'deg' / Units of coordinate increment and value
CUNIT3 = 'Hz' / Units of coordinate increment and value
CTYPE1 = 'RA---SFL' / Right ascension, Sanson-Flamsteed projection
CTYPE2 = 'DEC--SFL' / Declination, Sanson-Flamsteed projection
CTYPE3 = 'FREQ' / Coordinate type code
CRVAL1 = 83.8402938843 / [deg] Coordinate value at reference point
CRVAL2 = -5.18931388855 / [deg] Coordinate value at reference point
CRVAL3 = 0.600000000000 / [Hz] Coordinate value at reference point
LONPOLE = 0.0 / [deg] Native longitude of celestial pole
LATPOLE = 69.997710986349 / [deg] Native latitude of celestial pole
MJDREF = 0.0 / [d] MJD of fiducial time
RADESYS = 'ICRS' / Equatorial coordinate system
CRDELT1 = 0 /
CRDELT2 = 0 /