New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Singular matrix error when setting WCS #9883
Comments
Running the example snippet on master I get the same traceback (with wcslib line numbers slightly changed):
|
specutils had a similar problem showing up on astropy/specutils#160. |
I wonder if this ever worked or if it is supposed to even work. A quick look at the header and WCSLIB code shows that the presence of Specifically, it looks like there is not enough information to infer plate scale and WCSLIB defaults to 0 => singular PC matrix. The "fix" below is a nonsense and I have no idea what it means but it makes your header not to crash when creating a WCS object: In [11]: header['XPIXELSZ'] = 1
...: header['YPIXELSZ'] = 1
...: for k in range(5):
...: header['AMDY{:d}'.format(k)] = np.random.rand()
...: header['AMDX{:d}'.format(k)] = np.random.rand()
...: header['AMDREX{:d}'.format(k)] = np.random.rand()
...: header['AMDREY{:d}'.format(k)] = np.random.rand()
...: wcs.WCS(header)
WARNING: FITSFixedWarning: RADECSYS= 'FK5' / Coordinate system, per TCC ObjSys
the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'datfix' made the change 'Invalid parameter value: inconsistent date '2020-01-13T01:08:52.636000''. [astropy.wcs.wcs]
Out[11]:
WCS Keywords
Number of WCS axes: 2
CTYPE : 'RA---TAN' 'DEC--TAN'
CRVAL : 1.0432582341946395e-308 2.14739352155e-313
CRPIX : 1290.6021065659497 671.0189656991273
PC1_1 PC1_2 : 0.0008094668730622751 -0.0012388367513387422
PC2_1 PC2_2 : -0.0013736800038028686 0.0008669474893213419
CDELT : -0.00014110467379405977 0.00014110467379405977
NAXIS : 1024 1024 Alternatively, remove In [12]: d = fits.open(os.path.join(ddir, imname))
...: header = d[0].header
...: del header['CNPIX*']
...: del header['MJD-OBS']
...: header['RADESYSa'] = header['RADECSYS']
...: del header['RADECSYS']
...: header
...: wcs.WCS(header, naxis=(1,2))
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 58861.047831 from DATE-OBS'. [astropy.wcs.wcs]
Out[12]:
WCS Keywords
Number of WCS axes: 2
CTYPE : 'RA---TAN' 'DEC--TAN'
CRVAL : 326.07266745682 -1.3576216518211
CRPIX : 475.2301142 475.2737288
CD1_1 CD1_2 : 7.555095534183e-05 0.0
CD2_1 CD2_2 : -0.0 7.5640676530211e-05
NAXIS : 1024 1024 |
@dhomeier in that |
If it is indeed the case of invalid WCS, then the expectation is that the user fixes the data. |
Yes, this causes this error. I have seen it in some more frustrating solar data. |
OK, that does sound bad. We had been discussing if explicitly setting CDELT to 1 would help in the present case, but it seemed counterintuitive, as the respective So is there a good reference on what constitutes a valid set of WCS keywords? Here the best take seems to be @mcara's suggestion to remove |
Because removing these keywords does not any longer trigger special DSS WCS processing in the WCSLIB. Then your WCS is assumed to be a regular |
@dhomeier A valid set of WCS keywords is defined in the WCS papers which is what |
Thanks @mcara .. deleting the "CNPIX1" and "CNPIX2" keywords did indeed let the header be parsed by WCS.
resulted in
Why doesn't wcslint or WCS itself complain about these header keys though? As far as what convention it was based on ... I don't know. |
Probably because |
Can someone ping someone who works for APO? |
I think my question should be rephrased as : "given that CNPIX* header keywords imply that you should have additional specific keys, could an error be given that indicates such?" I can send a message to our local APO people and see if I can find out more. |
Ah, I see. That is a tough question. We had these kind of issues with SIP and it is a mess (a sample of the kind of discussion is here #4761 but there are many more issues). If "standard" (DSS, APO???) says it is OK to have missing coefficients then there is little that can be done. But this ( |
That's the thing: is it actually required to be present? |
I don't know, as I can't find a standard anywhere. However, if not having it crashes wcslib, then I think it's required for wcslib at least. |
In that case the fix for your particular issue should be in not deleting |
I do not think it works like that. I think the |
For reference: https://archive.stsci.edu/dss/booklet_n.pdf Take a look at how I, in particular, like:
|
To me, at this point, this issue looks more like a bug in whatever software was used to create the WCS in @rhiannonlynne's image: either |
Here is the software that illustrates this kind of WCS: https://gsss.stsci.edu/Software/GetImage/GetImage.htm |
Looks like the data creator made invalid WCS? Should we close? |
Hi humans 👋 - this issue was labeled as Close? approximately 17 hours ago. If you think this issue should not be closed, a maintainer should remove the Close? label - otherwise, I will close this issue in 7 days. If you believe I commented on this issue incorrectly, please report this here |
I'm going to close this issue as per my previous message, but if you feel that this issue should stay open, then feel free to re-open and remove the Close? label. If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here |
Description
I have a series of images, all of which produce an error when trying to set a WCS:
Expected behavior
I expected to get an astropy.wcs.WCS object to use to convert sky and pixel coordinates.
Actual behavior
When reading the image either with CCDData (which creates a WCS automatically) or with astropy.io.fits.open(), and then passing the header to astropy.wcs.WCS myself, I get the SingularMatrixError message above.
I also get a related error if I just run wcslint on the fits file directly:
Steps to Reproduce
Example image is available at https://epyc.astro.washington.edu/~lynnej/astropy_issue2_image.fits
Either just opening the file and passing the header to WCS directly, or first editing the header for the issues that wcslint reported result in the SingularMatrixError.
System Details
Darwin-19.2.0-x86_64-i386-64bit
Python 3.7.6 (default, Jan 8 2020, 13:42:34)
[Clang 4.0.1 (tags/RELEASE_401/final)]
Numpy 1.18.1
astropy 4.0
Scipy 1.3.1
The text was updated successfully, but these errors were encountered: