astropy: Incompatible results from WCS.pixel_to_world between astropy 3.x and 4.x (distortion in WCSLIB 6.3 + Cutout2D)
EDIT: The cause identified in https://github.com/astropy/astropy/issues/11216#issuecomment-755754911
Description
The use of WCS.pixel_to_world
gives different results when using astropy 3.x or 4.x (same environment).
Expected behavior
The two astropy versions should give the same results, or expected incompatibilities should be quoted explicitly in the documentation.
Actual behavior
The two astropy versions give different results, and I could not find a documentation on it.
Steps to Reproduce
The common.fits
can be found here (37 KB).
from astropy.io import fits
from astropy.wcs import WCS
fn = "common.fits"
header = fits.open(fn)[0].header
w = WCS(header)
print(w.pixel_to_world([[0, 0]], 0))
# astropy 3.2.2:
# <SkyCoord (FK5: equinox=2000.0): (ra, dec) in deg
# [[(250.51824533, -75.47419369), (250.51824533, -75.47419369)]]>
# astropy 4.0.1.post1:
# <SkyCoord (FK5: equinox=2000.0): (ra, dec) in deg
# [[(251.99786293, -75.83653121), (251.99786293, -75.83653121)]]>
I am not sure what’s happening here. I have the impression the information from the header is used differently in the two astropy versions, but I cannot find what has changed explicitly in the documentation.
System Details
Darwin-20.2.0-x86_64-i386-64bit
Python 3.7.1 (default, Oct 23 2018, 14:07:42)
[Clang 4.0.1 (tags/RELEASE_401/final)]
Numpy 1.16.2
astropy 3.2.2
Scipy 1.4.1
Matplotlib 3.0.1
Darwin-20.2.0-x86_64-i386-64bit
Python 3.7.1 (default, Oct 23 2018, 14:07:42)
[Clang 4.0.1 (tags/RELEASE_401/final)]
Numpy 1.16.2
astropy 4.0.1.post1
Scipy 1.4.1
Matplotlib 3.0.1
Checked also using the official docker images (https://hub.docker.com/u/continuumio/): 2019.10 (astropy 3.2.2), 2020.02 (astropy 4.0), 2020.07 (astropy 4.0.1.post1), 2020.11 (astropy 4.0.2).
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 54 (38 by maintainers)
I note that the distortion-free parts of the WCS (using the header without the
CQDIS
/DQ
cards) return identical results: 3.2.24.2
IOW in the 4.x version the distortion seems to offset the point by almost exactly the full distance to
CRPIX1, CRPIX2
again (instead of ~64 mas, blowing up the field by a factor of 2)! Unless this is an almost pathologically distorted WCS (does not look like it, with diagonal coefficients close to 1.0 AFAICS), this looks like a serious bug.Hi @pllim – thanks for the follow-up. I did not get more into the details since last year, and did not encounter this problem again in my work.
Interestingly enough, I cannot find an open issue here to indicate any plans of adding distortion support in
Cutout2D
…From what I understand,
It is not a genuine bug as it is mentioned in the doc (I would call it a limitation perhaps), and this should be resolved the day Cutout2D gets updated to include the distortion part (if this is the plan one day).
Also,
There is no difference between
all_pix2world
andwcs_pix2world
which means thatall_*
does nothing special to handle distortions: everything is handled internally to WCSLIB.I added a “Close?” label but I’ll keep it open for a bit more in case others have opinions on how to improve the user experience regarding WCSLIB upgrades. 😸
Thanks for your patience and understanding!
Thanks! I think one can close the issue then.
Actually, that info is available but it is kinda hidden. 😬
Thanks @dhomeier, I think you found where the issue is coming from (distortion).
By bisecting, I found the PR that introduced behavior changes: https://github.com/astropy/astropy/pull/9125: update wcslib to 6.4
Actually, this PR made an update from WCSLIB 6.2 to 6.4 directly. And looking at WCSLIB changelog, one can read for 6.3:
https://github.com/astropy/astropy/blob/4b242e6f5465410aa575f844e1a0b81db4534c94/cextern/wcslib/CHANGES#L160-L169
So the way distortions are treated changed (for good or bad - that I do not know). It is not a bug in astropy then, but this should probably be documented somewhere else than just in the changelog of WCSLIB.
~At the very least,
w.to_header()
might give a clue.~ (Thanks for the info!)Also, what about the dev version of astropy? 💭
Thanks - which information in particular do you have in mind? here is the header: