Skip to content

Commit d0a629b

Browse files
dhomeiermcara
andcommitted
Update wcs tests and bundle build for WCSLIB 7.4
Updated versions and warnings in wcs/tests, ignore wcs.FITSFixedWarning; add test_distortion_header for TPD coefficients in to_header and Cutout2D. Fixed wcshdo_format syntax to build with < C99 compilers. Co-authored-by: Mihai Cara <[email protected]>
1 parent 6c48586 commit d0a629b

7 files changed

Lines changed: 96 additions & 16 deletions

File tree

‎CHANGES.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ astropy.visualization
318318
astropy.wcs
319319
^^^^^^^^^^^
320320

321+
- Updated bundled version of ``WCSLIB`` to v7.4, fixing a bug that caused
322+
the coefficients of the TPD distortion function to not be written to the
323+
header. [#11260]
324+
321325

322326
Other Changes and Additions
323327
---------------------------
13 KB
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
HDU 1:
2+
WCS key ' ':
3+
- RADECSYS= 'ICRS ' / Astrometric system
4+
the RADECSYS keyword is deprecated, use RADESYSa.
5+
- The WCS transformation has more axes (2) than the image it is
6+
associated with (0)
7+
- Removed redundant SCAMP distortion parameters because SIP
8+
parameters are also present
9+
- 'datfix' made the change 'Set MJD-OBS to 55007.362083 from DATE-
10+
OBS'.
11+
12+
HDU 2:
13+
WCS key ' ':
14+
- The WCS transformation has more axes (3) than the image it is
15+
associated with (0)
16+
- 'datfix' made the change 'Success'.
17+
- 'unitfix' made the change 'Changed units:
18+
'HZ' -> 'Hz'.
19+
- 'celfix' made the change 'In CUNIT3 : Mismatched units type
20+
'length': have 'Hz', want 'm''.

‎astropy/wcs/tests/test_wcs.py‎

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from astropy.tests.helper import assert_quantity_allclose
2323
from astropy.io import fits
2424
from astropy.coordinates import SkyCoord
25+
from astropy.nddata import Cutout2D
2526

2627

2728
_WCSLIB_VER = Version(_wcs.__version__)
@@ -117,11 +118,15 @@ def test_fixes():
117118
with pytest.raises(wcs.InvalidTransformError), pytest.warns(wcs.FITSFixedWarning) as w:
118119
wcs.WCS(header, translate_units='dhs')
119120

120-
assert len(w) == 2
121+
if _WCSLIB_VER >= Version('7.4'):
122+
assert len(w) == 3
123+
assert "'datfix' made the change 'Success'." in str(w.pop().message)
124+
else:
125+
assert len(w) == 2
121126

122127
first_wmsg = str(w[0].message)
123128
assert 'unitfix' in first_wmsg and 'Hz' in first_wmsg and 'M/S' in first_wmsg
124-
assert 'm/s' in str(w[1].message)
129+
assert 'plane angle' in str(w[1].message) and 'm/s' in str(w[1].message)
125130

126131

127132
# Ignore "PV2_2 = 0.209028857410973 invalid keyvalue" warning seen on Windows.
@@ -145,6 +150,7 @@ def test_pix2world():
145150
"""
146151
# TODO: write this to test the expected output behavior of pix2world,
147152
# currently this just makes sure it doesn't error out in unexpected ways
153+
# (and compares `wcs.pc` and `result` values?)
148154
filename = get_pkg_data_filename('data/sip2.fits')
149155
with pytest.warns(wcs.FITSFixedWarning) as caught_warnings:
150156
# this raises a warning unimportant for this testing the pix2world
@@ -153,7 +159,10 @@ def test_pix2world():
153159
ww = wcs.WCS(filename)
154160

155161
# might as well monitor for changing behavior
156-
assert len(caught_warnings) == 1
162+
if _WCSLIB_VER >= Version('7.4'):
163+
assert len(caught_warnings) == 2
164+
else:
165+
assert len(caught_warnings) == 1
157166

158167
n = 3
159168
pixels = (np.arange(n) * np.ones((2, n))).T
@@ -162,18 +171,17 @@ def test_pix2world():
162171
# Catch #2791
163172
ww.wcs_pix2world(pixels[..., 0], pixels[..., 1], 0, ra_dec_order=True)
164173

165-
close_enough = 1e-8
166174
# assuming that the data of sip2.fits doesn't change
167175
answer = np.array([[0.00024976, 0.00023018],
168176
[0.00023043, -0.00024997]])
169177

170-
assert np.all(np.abs(ww.wcs.pc - answer) < close_enough)
178+
assert np.allclose(ww.wcs.pc, answer, atol=1.e-8)
171179

172180
answer = np.array([[202.39265216, 47.17756518],
173181
[202.39335826, 47.17754619],
174182
[202.39406436, 47.1775272]])
175183

176-
assert np.all(np.abs(result - answer) < close_enough)
184+
assert np.allclose(result, answer, atol=1.e-8, rtol=1.e-10)
177185

178186

179187
def test_load_fits_path():
@@ -319,13 +327,19 @@ def test_invalid_shape():
319327

320328
def test_warning_about_defunct_keywords():
321329
header = get_pkg_data_contents('data/defunct_keywords.hdr', encoding='binary')
330+
if _WCSLIB_VER >= Version('7.4'):
331+
n_warn = 5
332+
else:
333+
n_warn = 4
334+
322335
# Make sure the warnings come out every time...
323336
for _ in range(2):
324337
with pytest.warns(wcs.FITSFixedWarning) as w:
325338
wcs.WCS(header)
326339

327-
assert len(w) == 4
328-
for item in w:
340+
assert len(w) == n_warn
341+
# 7.4 adds a fifth warning "'datfix' made the change 'Success'."
342+
for item in w[:4]:
329343
assert 'PCi_ja' in str(item.message)
330344

331345

@@ -431,14 +445,14 @@ def test_find_all_wcs_crash():
431445
def test_validate():
432446
results = wcs.validate(get_pkg_data_filename("data/validate.fits"))
433447
results_txt = sorted(set([x.strip() for x in repr(results).splitlines()]))
434-
version = wcs._wcs.__version__
435-
if version[0] in ['6', '7']:
448+
if _WCSLIB_VER >= Version('7.4'):
449+
filename = 'data/validate.7.4.txt'
450+
elif _WCSLIB_VER >= Version('6.0'):
436451
filename = 'data/validate.6.txt'
437-
elif version[0] == '5':
438-
if version >= '5.13':
439-
filename = 'data/validate.5.13.txt'
440-
else:
441-
filename = 'data/validate.5.0.txt'
452+
elif _WCSLIB_VER >= Version('5.13'):
453+
filename = 'data/validate.5.13.txt'
454+
elif _WCSLIB_VER >= Version('5.0'):
455+
filename = 'data/validate.5.0.txt'
442456
else:
443457
filename = 'data/validate.txt'
444458
with open(get_pkg_data_filename(filename), "r") as fd:
@@ -1450,3 +1464,40 @@ def test_no_pixel_area():
14501464

14511465
# Pixel scales still possible
14521466
assert_quantity_allclose(w.proj_plane_pixel_scales(), 1)
1467+
1468+
1469+
@pytest.mark.skipif('_WCSLIB_VER < Version("7.4")',
1470+
reason="TPD coefficients incomplete prior to wcslib 7.4")
1471+
def test_distortion_header(tmpdir):
1472+
"""
1473+
Test that plate distortion model is correctly described by `wcs.to_header()`
1474+
and preserved when creating a Cutout2D from the image, writing it to FITS,
1475+
and reading it back from the file.
1476+
"""
1477+
path = get_pkg_data_filename("data/dss.14.29.56-62.41.05.fits.gz")
1478+
cen = np.array((50, 50))
1479+
siz = np.array((20, 20))
1480+
1481+
with fits.open(path) as hdulist:
1482+
with pytest.warns(wcs.FITSFixedWarning):
1483+
w = wcs.WCS(hdulist[0].header)
1484+
cut = Cutout2D(hdulist[0].data, position=cen, size=siz, wcs=w)
1485+
1486+
# This converts the DSS plate solution model with AMD[XY]n coefficients into a
1487+
# Template Polynomial Distortion model (TPD.FWD.n coefficients);
1488+
# not testing explicitly for the header keywords here.
1489+
1490+
w0 = wcs.WCS(w.wcs.to_header())
1491+
assert w.pixel_to_world(0, 0).separation(w0.pixel_to_world(0, 0)) < 1.e-3 * u.mas
1492+
assert w.pixel_to_world(*cen).separation(w0.pixel_to_world(*cen)) < 1.e-3 * u.mas
1493+
1494+
w1 = wcs.WCS(cut.wcs.to_header())
1495+
assert w.pixel_to_world(*cen).separation(w1.pixel_to_world(*(siz / 2))) < 1.e-3 * u.mas
1496+
1497+
cutfile = str(tmpdir.join('cutout.fits'))
1498+
fits.writeto(cutfile, cut.data, cut.wcs.to_header())
1499+
1500+
with fits.open(cutfile) as hdulist:
1501+
w2 = wcs.WCS(hdulist[0].header)
1502+
1503+
assert w.pixel_to_world(*cen).separation(w2.pixel_to_world(*(siz / 2))) < 1.e-3 * u.mas

‎astropy/wcs/tests/test_wcsprm.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ def test_fix():
414414
del fix_ref['obsfix']
415415
if Version(version) >= Version('7.1'):
416416
w.dateref = '1858-11-17'
417+
if Version(version) >= Version('7.4'):
418+
fix_ref['datfix'] = 'Success'
419+
417420
assert w.fix() == fix_ref
418421

419422

‎cextern/wcslib/C/wcshdr.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,8 @@ void wcshdo_format(
19461946
int emax = -999;
19471947
int emin = +999;
19481948
int precision = 0;
1949-
for (int i = 0; i < nval; i++) {
1949+
int i;
1950+
for (i = 0; i < nval; i++) {
19501951
// Double precision has at least 15 significant digits, and up to 17:
19511952
// http://en.wikipedia.org/wiki/Double-precision_floating-point_format
19521953
char cval[24];

‎setup.cfg‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ filterwarnings =
140140
ignore:parallel reading does not currently work, so falling back to serial
141141
# Ignore pytest.PytestUnhandledThreadExceptionWarning from SAMP, pytest>=6.2
142142
ignore:Exception in thread
143+
ignore:'datfix' made the change:astropy.wcs.wcs.FITSFixedWarning
143144
doctest_norecursedirs =
144145
*/setup_package.py
145146
doctest_subpackage_requires =

0 commit comments

Comments
 (0)