Problems about using 'relax' keyword in WCS

Hello all, I’m reading the WCS coordinates from a image.fits files as:

from astropy.wcs import WCS
hdul = fits.open(files[i])
wcs = WCS(header=hdul[0].header)

But since my fits file is old (from ~20 years ago), the format is not standard, so Python pops several warnings and the coordinates are not correctly read:

WARNING: FITSFixedWarning: PC001001= -0.84620247 / Pixel Coordinate translation matrix
this form of the PCi_ja keyword is deprecated, use PCi_ja. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC001002= -0.53286151 / Pixel Coordinate translation matrix
this form of the PCi_ja keyword is deprecated, use PCi_ja. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC002001= 0.53286151 / Pixel Coordinate translation matrix
this form of the PCi_ja keyword is deprecated, use PCi_ja. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: PC002002= -0.84620247 / Pixel Coordinate translation matrix
this form of the PCi_ja keyword is deprecated, use PCi_ja. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: RADECSYS= 'FK5 ’ / The equatorial coordinate system
the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: ‘datfix’ made the change ‘Set MJD-OBS to 51577.000000 from DATE-OBS.
Set DATE-END to ‘2000-02-03T09:45:00’ from MJD-END’. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: ‘unitfix’ made the change 'Changed units:
‘degree’ → ‘deg’,
‘degree’ → ‘deg’. [astropy.wcs.wcs]

I did some searches and I think the keyword “relax” can solve these warnings (Header-reading relaxation constants — Astropy v5.1.1). But I didn’t find an example how to use it. Obviously, directly adding it does not work, e.g.,

wcs = WCS(header=hdul[0].header, relax = WCS.WCSHDR_PC00i00j)

I would appreciate a lot if anyone can provide some help here!!! Thanks!

1 Like

It is passed as a keyword argument just as above, but WCSHDR_* are constants directly in wcs, not the WCS class, i.e. you’d need to do

from astropy.wcs import WCS, WCSHDR_PC00i00j
wcs = WCS(header=hdul[0].header, relax=WCSHDR_PC00i00j)

or alternatively could just try relax=True.

Thanks a lot! I find the coordinates are still read incorrectly with relax = True, and I’m checking further…