I’m trying to read the WSC coordinates of a FITS file but I’m having problems with the WCS module (astropy.wcs.WCS). I get the following error:
SingularMatrixError: ERROR 3 in wcsset() at line 2775 of file cextern\wcslib\C\wcs.c:
Linear transformation matrix is singular.
ERROR 3 in linset() at line 718 of file cextern\wcslib\C\lin.c:
PCi_ja matrix is singular.
Similar issues were due to having CDELT3 = 0, but I don’t have that entry, only CDELT1 and CDELT2.
This is the FITS header:
Hmm, I don’t quite get the same error as you report – are you running an older version of Astropy? – but I do get an error:
ValueError: ERROR 5 in wcsset() at line 2808 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 2716 of file cextern\wcslib\C\dis.c:
Coefficient scale for DSS on axis 1 is zero..
Your issue is very similar to a previously reported issue (Singular matrix error when setting WCS · Issue #9883 · astropy/astropy · GitHub), which was the inadvertent triggering of DSS-specific code in WCSLIB because the header happened to contain particular keywords. In your case, it appears to be the presence of the keywords
YPIXELSZ, which results in an error because you are lacking other DSS-specific keywords.
YPIXELSZ lets your header be parsed successfully, at least on my machine, so give that a try.
I updated astropy to the latest version (5.3.4) I had 5.3, but the issue was what you pointed out:
Removing those with
fixed it! Thank you so much!
Just to keep in mind in the future, how can I know if a FITS header will cause problems like this one? what keywords should I be looking for?
Heh, unfortunately, I have no idea. I debugged your particular situation by reducing the header to a minimal one that would definitely work, and then added back keywords until it broke.
I encourage you to report this bug on GitHub, since one would hope that the code could be improved to reduce the chance of mistakenly triggering the DSS-specific code.
Thank you, I just reported the bug on GitHub. Let’s hope it gets solved soon. Thank you for all your help!