Fix WCS distortion keyword handling for alternate WCS keys#19228
Fix WCS distortion keyword handling for alternate WCS keys#19228Shreyaav18 wants to merge 5 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.
|
| if key == '' or key == ' ': | ||
| key_suffix = '' | ||
| else: | ||
| key_suffix = key |
There was a problem hiding this comment.
Previous line guarantees that key cannot be ' '.
| if key == '' or key == ' ': | |
| key_suffix = '' | |
| else: | |
| key_suffix = key | |
| key_suffix = key |
| ) | ||
| dp = (d_kw + str(i)).strip() | ||
|
|
||
| dp = (d_kw + str(i) + key_suffix).strip() |
There was a problem hiding this comment.
I don't think strip() is needed here.
| tables = {} | ||
| for i in range(1, self.naxis + 1): | ||
| d_error_key = err_kw + str(i) | ||
| d_error_key = err_kw + str(i) + key_suffix |
There was a problem hiding this comment.
Maybe store str(i) + key_suffix as it is reused a couple of times? Just a very minor suggestion.
| for key_name in set(header): | ||
| if key_name.startswith(dp + "."): | ||
| del header[key_name] |
There was a problem hiding this comment.
Please undo this. IMO key is appropriate.
|
Also please fix pre-commit |
|
@mcara Changes addressed. All review comments have been implemented and pre-commit checks are passing locally. Looking forward to your final review! |
|
Hi @mcara |
|
I understand the stwcs concern. Happy to help troubleshoot or modify the approach if needed |
Description
This pull request addresses issues with WCS distortion lookup tables on secondary WCSes (alternate WCS with key='A', 'B', etc.).
Problem: When a FITS header contains multiple WCS definitions (primary and alternate), the distortion keywords were not respecting WCS key suffixes as specified in the FITS WCS distortion paper. This caused two issues:
Secondary WCS incorrectly loading primary distortion: A secondary WCS without its own distortion keywords (
CPDIS1A,CPDIS2A) would incorrectly load the primary WCS's distortion instead of having none.Crash when secondary WCS has its own distortion: When secondary distortion keywords were properly defined with suffixes, the code would fail to read them and crash with "Unrecognized/unimplemented distortion function: LOOKUP".
Solution: Modified
_read_distortion_kw()to accept akeyparameter and apply the appropriate suffix to all distortion-related keywords (CPDIS{i},CPERR{i},DP{i}.*), ensuring each WCS only reads its own distortion keywords.Changes:
keyparameter to_read_distortion_kw()methodTesting:
Fixes #18914