Fix hardcoded degree units in fitswcs APE 14 world to pixel#19506
Fix hardcoded degree units in fitswcs APE 14 world to pixel#19506nabobalis wants to merge 6 commits intoastropy:mainfrom
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
It should be noted that this bug is only present in the high level API component: Your fix is in the wrong place though the bug must be in how |
|
So where should I move it to and what is the actual fix I need to implement? |
|
From a cursory look, I'm pretty sure the bug is here: astropy/astropy/wcs/wcsapi/fitswcs.py Lines 449 to 450 in 449a4c9 it's always accessing the component in degrees which it shouldn't be. |
c7b1810 to
d202074
Compare
Hopefully you meant preserve units, and not perverse units... 😹 |
Woops! |
adb9d27 to
6a99e7c
Compare
31944b7 to
6a79e8a
Compare
| b=48.25 * u.deg, | ||
| distance=0 * u.km, | ||
| radial_velocity=-(3.346e-3 / 2.725 * c).to(u.km / u.s), | ||
| radial_velocity=-(3.346e-3 / 2.725 * C_SI).to(u.km / u.s), |
| kwargs = {} | ||
| kwargs["frame"] = celestial_frame | ||
| # Very occasionally (i.e. with TAB) wcs does not convert the units to degrees | ||
| # Very occasionally (i.e. with TAB) wcs does not convert the units |
There was a problem hiding this comment.
Does this comment need updating now that this is not the only way the units might not be degrees?
| @@ -0,0 +1,3 @@ | |||
| def assert_celestial_component(component, index): | |||
There was a problem hiding this comment.
I don't really like this change but I had no better ideas to avoid me repeating this pattern in the unit tests.
Also since its now a callable, I am not checking its correct either.
|
That failure is: |
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
I don't see how this is your fault. Might just be a transient failure. 🤞 |
|
Sorry to ping, any chance of an update on this? Edit: I forgot about some setting for copilot which I have now disabled. |
There was a problem hiding this comment.
Pull request overview
This PR fixes FITS WCS (APE 14) world_to_pixel behavior when preserve_units=True, ensuring non-degree celestial units (e.g., arcsec, mas) are respected instead of being implicitly converted/hardcoded to degrees.
Changes:
- Update FITSWCS celestial component extraction to convert SkyCoord lon/lat to the WCS’ configured units rather than degrees.
- Refactor multiple tests to avoid hardcoding
"spherical.*.degree"component paths and add a regression test forarcsec/masround-tripping. - Add a WCS changelog bugfix fragment.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
astropy/wcs/wcsapi/fitswcs.py |
Adjusts celestial component extraction logic to preserve configured lon/lat units. |
astropy/wcs/wcsapi/tests/test_fitswcs.py |
Adds a regression test for non-degree units and updates component assertions to accept callables. |
astropy/wcs/wcsapi/wrappers/tests/test_sliced_wcs.py |
Updates assertions to avoid degree-string coupling, using a helper assertion instead. |
astropy/wcs/wcsapi/tests/helpers.py |
Introduces assert_celestial_component helper for reusable component checks. |
docs/changes/wcs/19506.bugfix.rst |
Documents the bugfix in the WCS changelog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| components[self.wcs.lng] = ( | ||
| "celestial", | ||
| 0, | ||
| lambda c: c.spherical.lon.to_value(lon_unit), | ||
| ) |
Description
I started using preserve_units with astropy 7.2 for my WCS and I have a roundtrip issues for my solar raster data.