Skip to content

Commit 58acf26

Browse files
committed
Fix CTYPE parsing for WCS with SIP distortion extensions
The projection type was extracted from the last 3 characters of CTYPE, which fails for SIP extensions (e.g., "RA---TAN-SIP" would give "SIP" instead of "TAN"). Now extracts the projection from the fixed position [5:8] which works for both standard CTYPE ("RA---TAN") and SIP-extended CTYPE ("RA---TAN-SIP"). Fixes #26
1 parent 3633810 commit 58acf26

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

pyavm/avm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,11 @@ def from_wcs(cls, wcs, shape=None):
585585
self.Spatial.Equinox = wcs.wcs.equinox
586586

587587
# Projection
588+
# CTYPE format is CCCC-PPP or CCCC-PPP-SIP for SIP distortions
589+
# Extract projection from position 5:8 to handle both cases
588590

589-
proj1 = wcs.wcs.ctype[0][-3:]
590-
proj2 = wcs.wcs.ctype[1][-3:]
591+
proj1 = wcs.wcs.ctype[0][5:8]
592+
proj2 = wcs.wcs.ctype[1][5:8]
591593
if proj1 == proj2:
592594
self.Spatial.CoordsystemProjection = decode_ascii(proj1)
593595
else:

pyavm/tests/test_avm.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,21 @@ def test_controlled_vocabulary_dash_placeholder():
6060

6161
avm.Spectral.Band = ["Optical", "-", "Infrared"]
6262
assert avm.Spectral.Band == ["Optical", "-", "Infrared"]
63+
64+
65+
def test_from_wcs_sip():
66+
"""Test that WCS with SIP distortion extensions are handled correctly.
67+
68+
This is a regression test for issue #26.
69+
"""
70+
pytest.importorskip("astropy")
71+
from astropy.wcs import WCS
72+
73+
wcs = WCS(naxis=2)
74+
wcs.wcs.ctype = ["RA---TAN-SIP", "DEC--TAN-SIP"]
75+
wcs.wcs.crpix = [100, 100]
76+
wcs.wcs.crval = [180, 45]
77+
wcs.wcs.cdelt = [-0.001, 0.001]
78+
79+
avm = AVM.from_wcs(wcs)
80+
assert avm.Spatial.CoordsystemProjection == "TAN"

0 commit comments

Comments
 (0)