From 4b46410a60318138892d9726eb2f472f619d425d Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Thu, 15 Dec 2016 16:58:28 -0500 Subject: Add tests --- stwcs/tests/test_updatewcs.py | 65 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) (limited to 'stwcs/tests/test_updatewcs.py') diff --git a/stwcs/tests/test_updatewcs.py b/stwcs/tests/test_updatewcs.py index b7e75c8..4afd7cd 100644 --- a/stwcs/tests/test_updatewcs.py +++ b/stwcs/tests/test_updatewcs.py @@ -296,12 +296,69 @@ def test_add_radesys(): fits.setval(acs_file, ext=0, keyword="NPOLFILE", value=npol_file) fits.setval(acs_file, ext=0, keyword="D2IMFILE", value=d2imfile) - #shutil.copyfile('orig/ibof01ahq_flt.fits', './ibof01ahq_flt.fits') updatewcs.updatewcs(acs_file) - # updatewcs.updatewcs('ibof01ahq_flt.fits') for ext in [('SCI', 1), ('SCI', 2)]: hdr = fits.getheader(acs_file, ext) assert hdr['RADESYS'] == 'FK5' - #hdr = fits.getheader('ibof01ahq_flt.fits', ext=('SCI', 1)) - #assert hdr['RADESYS'] == 'ICRS' +def test_update_d2im_distortion(): + acs_orig_file = get_filepath('j94f05bgq_flt.fits') + current_dir = os.path.abspath(os.path.curdir) + acs_file = get_filepath('j94f05bgq_flt.fits', current_dir) + + idctab = get_filepath('postsm4_idc.fits') + npol_file = get_filepath('qbu16424j_npl.fits') + d2imfile = get_filepath('new_wfc_d2i.fits') + newd2im = get_filepath('new_wfc_d2i.fits', current_dir) + print('newd2im', newd2im) + try: + os.remove(acs_file) + except OSError: + pass + shutil.copyfile(acs_orig_file, acs_file) + fits.setval(acs_file, ext=0, keyword="IDCTAB", value=idctab) + fits.setval(acs_file, ext=0, keyword="NPOLFILE", value=npol_file) + fits.setval(acs_file, ext=0, keyword="D2IMFILE", value=d2imfile) + updatewcs.updatewcs(acs_file) + d2imerr1 = fits.getval(acs_file, ext=1, keyword='D2IMERR1') + d2imerr4 = fits.getval(acs_file, ext=4, keyword='D2IMERR1') + shutil.copyfile(d2imfile, newd2im) + newf = fits.open(newd2im, mode='update') + for ext in newf[1:]: + ext.data *= 100 + newf.close() + fits.setval(acs_file, keyword="D2IMFILE", value=newd2im) + updatewcs.updatewcs(acs_file) + nd2imerr1 = fits.getval(acs_file, ext=1, keyword='D2IMERR1') + nd2imerr4 = fits.getval(acs_file, ext=4, keyword='D2IMERR1') + assert np.isclose(d2imerr1 * 100, nd2imerr1) + assert np.isclose(d2imerr4 * 100, nd2imerr4) + + +def test_apply_d2im(): + from stwcs.updatewcs import apply_corrections as appc + acs_orig_file = get_filepath('j94f05bgq_flt.fits') + current_dir = os.path.abspath(os.path.curdir) + fname = get_filepath('j94f05bgq_flt.fits', current_dir) + d2imfile = get_filepath('new_wfc_d2i.fits') + try: + os.remove(fname) + except OSError: + pass + shutil.copyfile(acs_orig_file, fname) + fits.setval(fname, ext=0, keyword="D2IMFILE", value=d2imfile) + fits.setval(fname, ext=0, keyword="IDCTAB", value='N/A') + fits.setval(fname, ext=0, keyword="NPOLFILE", value='N/A') + # If D2IMEXT does not exist, the correction should be applied + assert appc.apply_d2im_correction(fname, d2imcorr=True) + updatewcs.updatewcs(fname) + + # Test the case when D2IMFILE == D2IMEXT + assert not appc.apply_d2im_correction(fname, d2imcorr=True) + assert not appc.apply_d2im_correction(fname, d2imcorr=False) + + fits.setval(fname, ext=0, keyword='D2IMFILE', value="N/A") + assert not appc.apply_d2im_correction(fname, d2imcorr=True) + # No D2IMFILE keyword in primary header + fits.delval(fname, ext=0, keyword='D2IMFILE') + assert not appc.apply_d2im_correction(fname, d2imcorr=True) -- cgit From c4ca4b31d032b0e1ccab795843c1d1933bcbb7e1 Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Thu, 15 Dec 2016 20:17:22 -0500 Subject: reference pytest correctly --- stwcs/tests/test_updatewcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stwcs/tests/test_updatewcs.py') diff --git a/stwcs/tests/test_updatewcs.py b/stwcs/tests/test_updatewcs.py index 4afd7cd..ca034fa 100644 --- a/stwcs/tests/test_updatewcs.py +++ b/stwcs/tests/test_updatewcs.py @@ -325,7 +325,7 @@ def test_update_d2im_distortion(): shutil.copyfile(d2imfile, newd2im) newf = fits.open(newd2im, mode='update') for ext in newf[1:]: - ext.data *= 100 + ext.data = ext.data * 100 newf.close() fits.setval(acs_file, keyword="D2IMFILE", value=newd2im) updatewcs.updatewcs(acs_file) -- cgit From aed4fedd83502944f3401b382b02bbddc862cfe2 Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Fri, 16 Dec 2016 16:01:24 -0500 Subject: remove a print statement --- stwcs/tests/test_updatewcs.py | 1 - 1 file changed, 1 deletion(-) (limited to 'stwcs/tests/test_updatewcs.py') diff --git a/stwcs/tests/test_updatewcs.py b/stwcs/tests/test_updatewcs.py index ca034fa..675e78f 100644 --- a/stwcs/tests/test_updatewcs.py +++ b/stwcs/tests/test_updatewcs.py @@ -310,7 +310,6 @@ def test_update_d2im_distortion(): npol_file = get_filepath('qbu16424j_npl.fits') d2imfile = get_filepath('new_wfc_d2i.fits') newd2im = get_filepath('new_wfc_d2i.fits', current_dir) - print('newd2im', newd2im) try: os.remove(acs_file) except OSError: -- cgit From 68255f10fccc6171658f31b1550290f4f4d59a28 Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Fri, 16 Dec 2016 16:34:43 -0500 Subject: try to fix test failing on travis but passing on redaht --- stwcs/tests/test_updatewcs.py | 1 + 1 file changed, 1 insertion(+) (limited to 'stwcs/tests/test_updatewcs.py') diff --git a/stwcs/tests/test_updatewcs.py b/stwcs/tests/test_updatewcs.py index 675e78f..218f4f2 100644 --- a/stwcs/tests/test_updatewcs.py +++ b/stwcs/tests/test_updatewcs.py @@ -325,6 +325,7 @@ def test_update_d2im_distortion(): newf = fits.open(newd2im, mode='update') for ext in newf[1:]: ext.data = ext.data * 100 + newf.flush() newf.close() fits.setval(acs_file, keyword="D2IMFILE", value=newd2im) updatewcs.updatewcs(acs_file) -- cgit From 61a9c34dabee4cfad1c2e97cbee1cba5be7331e4 Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Sun, 18 Dec 2016 15:33:15 -0500 Subject: use with - cm --- stwcs/tests/test_updatewcs.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'stwcs/tests/test_updatewcs.py') diff --git a/stwcs/tests/test_updatewcs.py b/stwcs/tests/test_updatewcs.py index 218f4f2..c4e58db 100644 --- a/stwcs/tests/test_updatewcs.py +++ b/stwcs/tests/test_updatewcs.py @@ -322,11 +322,10 @@ def test_update_d2im_distortion(): d2imerr1 = fits.getval(acs_file, ext=1, keyword='D2IMERR1') d2imerr4 = fits.getval(acs_file, ext=4, keyword='D2IMERR1') shutil.copyfile(d2imfile, newd2im) - newf = fits.open(newd2im, mode='update') - for ext in newf[1:]: - ext.data = ext.data * 100 - newf.flush() - newf.close() + with fits.open(newd2im, mode='update') as newf: + for ext in newf[1:]: + ext.data = ext.data * 100 + fits.setval(acs_file, keyword="D2IMFILE", value=newd2im) updatewcs.updatewcs(acs_file) nd2imerr1 = fits.getval(acs_file, ext=1, keyword='D2IMERR1') -- cgit