From 1aea690f944ce9cff99ffd7fa0c0b56ee0774f77 Mon Sep 17 00:00:00 2001 From: Steve Goldman <32876747+s-goldman@users.noreply.github.com> Date: Thu, 28 May 2026 15:26:12 -0400 Subject: [PATCH 1/4] initial commit. --- stwcs/tests/test_headerlet.py | 4 ++-- stwcs/wcsutil/wcsdiff.py | 37 ++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/stwcs/tests/test_headerlet.py b/stwcs/tests/test_headerlet.py index 399e9250..e34ca81e 100644 --- a/stwcs/tests/test_headerlet.py +++ b/stwcs/tests/test_headerlet.py @@ -245,13 +245,13 @@ def test_apply_as_alternate_method(self): 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_cpdisp=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_cpdisp=True)[0]) class TestRestoreHeaderlet: diff --git a/stwcs/wcsutil/wcsdiff.py b/stwcs/wcsutil/wcsdiff.py index 8f8395ca..a5e3bfde 100644 --- a/stwcs/wcsutil/wcsdiff.py +++ b/stwcs/wcsutil/wcsdiff.py @@ -6,7 +6,7 @@ def is_wcs_identical(scifile, file2, sciextlist, fextlist, scikey=" ", - file2key=" ", verbose=False): + file2key=" ", ignore_cpdisp=False, verbose=False): """ Compares the WCS solution of 2 files. @@ -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_cpdisp: bool + True: ignore CPDIS1 and CPDIS2 when comparing WCS solutions verbose: bool True: print to stdout @@ -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_cpdisp: + 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: From de240d7b5a36b602c68568f244336d36de2a4fa9 Mon Sep 17 00:00:00 2001 From: Steve Goldman <32876747+s-goldman@users.noreply.github.com> Date: Thu, 28 May 2026 16:42:16 -0400 Subject: [PATCH 2/4] added changelog entry. --- CHANGES.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1b4bad0f..b2885adc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------ From 62321bc6625f0030b25e97df3e5fbda426075e5b Mon Sep 17 00:00:00 2001 From: Steve Goldman <32876747+s-goldman@users.noreply.github.com> Date: Thu, 28 May 2026 16:55:07 -0400 Subject: [PATCH 3/4] cpdisp to cpdis --- stwcs/tests/test_headerlet.py | 4 ++-- stwcs/wcsutil/wcsdiff.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stwcs/tests/test_headerlet.py b/stwcs/tests/test_headerlet.py index e34ca81e..911f84a4 100644 --- a/stwcs/tests/test_headerlet.py +++ b/stwcs/tests/test_headerlet.py @@ -245,13 +245,13 @@ def test_apply_as_alternate_method(self): assert(wcsdiff.is_wcs_identical(self.comp_file, self.headerlet_name, [('SCI', 1), ('SCI', 2)], [("SIPWCS", 1), ("SIPWCS", 2)], - scikey='K', verbose=True, ignore_cpdisp=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, ignore_cpdisp=True)[0]) + scikey='P', verbose=True, ignore_cpdis=True)[0]) class TestRestoreHeaderlet: diff --git a/stwcs/wcsutil/wcsdiff.py b/stwcs/wcsutil/wcsdiff.py index a5e3bfde..0b91cdea 100644 --- a/stwcs/wcsutil/wcsdiff.py +++ b/stwcs/wcsutil/wcsdiff.py @@ -6,7 +6,7 @@ def is_wcs_identical(scifile, file2, sciextlist, fextlist, scikey=" ", - file2key=" ", ignore_cpdisp=False, verbose=False): + file2key=" ", ignore_cpdis=False, verbose=False): """ Compares the WCS solution of 2 files. @@ -26,7 +26,7 @@ def is_wcs_identical(scifile, file2, sciextlist, fextlist, scikey=" ", alternate WCS key in scifile file2key: string alternate WCS key in file2 - ignore_cpdisp: bool + ignore_cpdis: bool True: ignore CPDIS1 and CPDIS2 when comparing WCS solutions verbose: bool True: print to stdout @@ -85,7 +85,7 @@ 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 ignore_cpdisp: + if ignore_cpdis: pass else: if w1.cpdis1 or w2.cpdis1: From b6f96bf371d27d27613411297586d594c63e635b Mon Sep 17 00:00:00 2001 From: Steve Goldman <32876747+s-goldman@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:06:34 -0400 Subject: [PATCH 4/4] make modified wcs distict in test_apply_as_alternate. --- stwcs/tests/test_headerlet.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stwcs/tests/test_headerlet.py b/stwcs/tests/test_headerlet.py index 911f84a4..d909e81f 100644 --- a/stwcs/tests/test_headerlet.py +++ b/stwcs/tests/test_headerlet.py @@ -240,7 +240,15 @@ 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)],