Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.7.8 (TBD)
-----------

- Bug fix addressing astropy wcs change enabling secondary distortion correction
keywords. [#246]


1.7.7 (2026-03-05)
------------------

Expand Down
12 changes: 10 additions & 2 deletions stwcs/tests/test_headerlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,26 @@ def test_apply_as_primary_method(self):
@pytest.mark.skipif(os.name == "nt", reason="FIXME: Crash on Windows")
def test_apply_as_alternate_method(self):
hlet = headerlet.create_headerlet(self.comp_file, hdrname='test1')

# Make the headerlet WCS distinct from the current primary WCS
hlet['SIPWCS', 1].header['CRPIX1'] += 1
hlet['SIPWCS', 1].header['CRPIX2'] += 1
hlet['SIPWCS', 2].header['CRPIX1'] += 2
hlet['SIPWCS', 2].header['CRPIX2'] += 2

hlet.apply_as_alternate(self.comp_file, wcskey='K', wcsname='KK')
assert fits.getval(self.comp_file, 'WCSNAMEK', ext=('SCI', 1)) == 'KK'
hlet.writeto(self.headerlet_name, overwrite=True)
assert(wcsdiff.is_wcs_identical(self.comp_file, self.headerlet_name,
[('SCI', 1), ('SCI', 2)],
[("SIPWCS", 1), ("SIPWCS", 2)],
scikey='K', verbose=True)[0])
scikey='K', verbose=True, ignore_cpdis=True)[0])
headerlet.apply_headerlet_as_alternate(self.comp_file,
self.headerlet_name, wcskey='P')
assert(wcsdiff.is_wcs_identical(self.comp_file, self.headerlet_name,
[('SCI', 1), ('SCI', 2)],
[("SIPWCS", 1), ("SIPWCS", 2)],
scikey='P', verbose=True)[0])
scikey='P', verbose=True, ignore_cpdis=True)[0])

class TestRestoreHeaderlet:

Expand Down
37 changes: 21 additions & 16 deletions stwcs/wcsutil/wcsdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def is_wcs_identical(scifile, file2, sciextlist, fextlist, scikey=" ",
file2key=" ", verbose=False):
file2key=" ", ignore_cpdis=False, verbose=False):
"""
Compares the WCS solution of 2 files.

Expand All @@ -26,6 +26,8 @@ def is_wcs_identical(scifile, file2, sciextlist, fextlist, scikey=" ",
alternate WCS key in scifile
file2key: string
alternate WCS key in file2
ignore_cpdis: bool
True: ignore CPDIS1 and CPDIS2 when comparing WCS solutions
verbose: bool
True: print to stdout

Expand Down Expand Up @@ -83,21 +85,24 @@ def is_wcs_identical(scifile, file2, sciextlist, fextlist, scikey=" ",
# logger.info('SIP coefficients do not match')
diff['SIP_B'] = (w1.sip.b, w2.sip.b)
result = False
if w1.cpdis1 or w2.cpdis1:
if w1.cpdis1 and not w2.cpdis1 or w2.cpdis1 and not w1.cpdis1:
diff['CPDIS1'] = "CPDIS1 missing"
result = False
if w1.cpdis2 and not w2.cpdis2 or w2.cpdis2 and not w1.cpdis2:
diff['CPDIS2'] = "CPDIS2 missing"
result = False
if not np.allclose(w1.cpdis1.data, w2.cpdis1.data, rtol=10**(-7)):
# logger.info('NPOL distortions do not match')
diff['CPDIS1_data'] = (w1.cpdis1.data, w2.cpdis1.data)
result = False
if not np.allclose(w1.cpdis2.data, w2.cpdis2.data, rtol=10**(-7)):
# logger.info('NPOL distortions do not match')
diff['CPDIS2_data'] = (w1.cpdis2.data, w2.cpdis2.data)
result = False
if ignore_cpdis:
pass
else:
if w1.cpdis1 or w2.cpdis1:
if w1.cpdis1 and not w2.cpdis1 or w2.cpdis1 and not w1.cpdis1:
diff['CPDIS1'] = "CPDIS1 missing"
result = False
if w1.cpdis2 and not w2.cpdis2 or w2.cpdis2 and not w1.cpdis2:
diff['CPDIS2'] = "CPDIS2 missing"
result = False
if not np.allclose(w1.cpdis1.data, w2.cpdis1.data, rtol=10**(-7)):
# logger.info('NPOL distortions do not match')
diff['CPDIS1_data'] = (w1.cpdis1.data, w2.cpdis1.data)
result = False
if not np.allclose(w1.cpdis2.data, w2.cpdis2.data, rtol=10**(-7)):
# logger.info('NPOL distortions do not match')
diff['CPDIS2_data'] = (w1.cpdis2.data, w2.cpdis2.data)
result = False
if w1.det2im1 or w2.det2im1:
if w1.det2im1 and not w2.det2im1 or \
w2.det2im1 and not w1.det2im1:
Expand Down
Loading