Write distortion keywords with the WCS key suffix in to_fits() - #20446
anishmehta24 wants to merge 4 commits into
Conversation
WCS.to_fits() wrote CPDISn / DPn.* for every WCS key, while _read_distortion_kw() looks up CPDISna / DPna.* for an alternate key since astropy#19228, so a secondary WCS's lookup-table distortion did not survive a round trip. _write_distortion_kw() now takes the key and to_fits() passes the explicit key or the object's own key.
|
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.
|
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
|
Yes, I am. Sorry, I missed the box; it is checked now. |
|
This looks good to me. I just need to run regression tests before formal approval. Drizzlepac: https://github.com/spacetelescope/RegressionTests/actions/runs/35685694447 One |
Applies @pllim's suggested change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WyCUJcDPnCnQMmuDwsnDmD
|
Instead of wasting compute resources with LLM, you could have just clicked a button and accept my suggested changes... |
Description
This pull request is to address
WCS.to_fits()writing the lookup-table distortion keywords without the alternate-WCS key suffix. Since #19228_read_distortion_kw()looks forCPDIS1A/DP1A.*when a WCS is loaded withkey="A", but_write_distortion_kw()always wroteCPDIS1/DP1.*, so the distortion of a secondary WCS did not surviveto_fits()followed byWCS(hdulist[0].header, hdulist, key="A")(the round trip in the issue).Changes:
_write_distortion_kw(hdulist, dist="CPDIS", key=" ")appends the stripped, upper-cased key to the axis number the same way_read_distortion_kw()builds its keywords (CPDIS1A,DP1A.EXTVER,DP1A.NAXES,DP1A.AXIS.n, and the matchingWCSDVARREXTVER).to_fits()passes the explicitkeywhen given, and otherwise the object's own key (self.wcs.alt), which is also whatto_header()uses for the rest of the header. The primary WCS (key=" ") output is byte-for-byte unchanged.Test:
test_alternate_wcs_distortion_to_fits_roundtrip, parametrized over" "and"A", builds a WCS with two lookup tables, writes it withto_fits(), checks the suffixed keywords (and that no unsuffixed ones are written for"A"), reads it back with the same key and compares the tables, and checks that an explicitto_fits(key="B")wins over the object's key. The"A"case fails onmainwithKeyError: "Keyword 'CPDIS1A' not found.".astropy/wcs/testspass locally (468 passed, 21 skipped) with a source build against wcslib bundled in the repo.Fixes #20441
AI Disclosure
Claude Code (Claude Opus 5, claude-opus-5) was used, driven by me, to trace the read/write asymmetry from the issue, write the change in
_write_distortion_kw/to_fits, the regression test, and the first draft of this description; I reviewed and ran everything. The code and the test as submitted are AI generated.Merge method
🤖 Generated with Claude Code