wcs.to_header() function giving mixed up header keywords
See original GitHub issueDescription
There are three ways to specify the rotation/scale information. The two can be combined into one matrix (CD1_1 through CD2_2) or the rotation matrix can be given as PC1_1 through PC2_2 and the pixel scale as CDELT1/CDELT2. The third way is to give CDELT1/CDELT2 and a rotation angle as CROTA2.
What wcs.to_header() outputs looks like the second but the values of the PC matrix are actually what should be in a CD matrix and the CDELT value are nonsensical (1x1 degree pixels).
Here are the adjustments that need to be made to the headers to make them work properly:
fname, extension = os.path.splitext(file)
fits.delval(file, 'CDELT1')
fits.delval(file, 'CDELT2')
pc1_1 = fits.getval(file, 'PC1_1')
pc1_2 = fits.getval(file, 'PC1_2')
pc2_1 = fits.getval(file, 'PC2_1')
pc2_2 = fits.getval(file, 'PC2_2')
fits.setval(file, 'CD2_2', value=pc2_2, after='CRPIX2')
fits.setval(file, 'CD2_1', value=pc2_1, after='CRPIX2')
fits.setval(file, 'CD1_2', value=pc1_2, after='CRPIX2')
fits.setval(file, 'CD1_1', value=pc1_1, after='CRPIX2')
fits.delval(file, 'PC1_1')
fits.delval(file, 'PC1_2')
fits.delval(file, 'PC2_1')
Expected behavior
Actual behavior
Steps to Reproduce
- [First Step]
- [Second Step]
- [and so on…]
# Put your Python code snippet here.
System Details
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Tutorial wcs module — Kapteyn Package (home)
An object of this class is created using the header of the FITS file for which we want WCS transformations. It accepts also...
Read more >WCS — Astropy v5.2
When None , only the standard image header keywords are considered (and the underlying wcspih() C function is called). To use binary table...
Read more >Tutorial wcs module — Kapteyn 3.0.0-beta documentation
Support for 'mixed' coordinates; Support for conversions between different celestial systems; Objects have useful attributes; Easy to combine with other ...
Read more >WCS — Astropy v1.0.4
When None, only the standard image header keywords are considered (and the underlying wcspih() C function is called). To use binary table image...
Read more >CIAO 2.0 Release Notes - Chandra X-ray Center
Supported functions include those in the standard math library and conditional ... If the DEFOCUS header keyword is absent, the tool will give...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The discussion in question is probably #1084.
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