From 1f87e08c731e5da975659e6aa17de042625404d2 Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Fri, 9 Dec 2016 14:35:25 -0500 Subject: save work --- stwcs/updatewcs/apply_corrections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stwcs/updatewcs') diff --git a/stwcs/updatewcs/apply_corrections.py b/stwcs/updatewcs/apply_corrections.py index 4a8e5ac..f3da018 100644 --- a/stwcs/updatewcs/apply_corrections.py +++ b/stwcs/updatewcs/apply_corrections.py @@ -158,7 +158,7 @@ def applyNpolCorr(fname, unpolcorr): fnpol0 = fileutil.osfn(fnpol0) if not fileutil.findFile(fnpol0): msg = '"NPOLFILE" exists in primary header but file {0} not found.' - 'Non-polynomial distortion correction will not be applied.'.format(file) + 'Non-polynomial distortion correction will not be applied.'.format(fnpol0) logger.critical(msg) raise IOError("NPOLFILE {0} not found".format(fnpol0)) try: -- cgit From a6eb705d7bcb11ae1951a9fef0c8256a49f5f52c Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Tue, 13 Dec 2016 15:07:24 -0500 Subject: fix problem with updating d2im file --- stwcs/updatewcs/apply_corrections.py | 70 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'stwcs/updatewcs') diff --git a/stwcs/updatewcs/apply_corrections.py b/stwcs/updatewcs/apply_corrections.py index f3da018..c554564 100644 --- a/stwcs/updatewcs/apply_corrections.py +++ b/stwcs/updatewcs/apply_corrections.py @@ -66,7 +66,7 @@ def setCorrections(fname, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=Tru if not npolcorr: acorr.remove('NPOLCorr') if 'DET2IMCorr' in acorr: - d2imcorr = applyD2ImCorr(fname, d2imcorr) + d2imcorr = apply_d2im_correction(fname, d2imcorr) if not d2imcorr: acorr.remove('DET2IMCorr') logger.info("Corrections to be applied to {0} {1}".format(fname, acorr)) @@ -211,40 +211,42 @@ def isOldStyleDGEO(fname, dgname): return False -def applyD2ImCorr(fname, d2imcorr): +def apply_d2im_correction(fname, d2imcorr): applyD2IMCorr = True + if not d2imcorr: + logger.info("D2IM correction not requested - not applying it.") + return False + # get D2IMFILE kw from primary header try: - # get D2IMFILE kw from primary header fd2im0 = fits.getval(fname, 'D2IMFILE') - if fd2im0 == 'N/A': - utils.remove_distortion(fname, "D2IMFILE") - return False - fd2im0 = fileutil.osfn(fd2im0) - if not fileutil.findFile(fd2im0): - msg = """\n\tKw D2IMFILE exists in primary header but file %s not found\n - Detector to image correction will not be applied\n""" % fd2im0 - logger.critical(msg) - print(msg) - raise IOError("D2IMFILE {0} not found".format(fd2im0)) - try: - # get D2IMEXT kw from first extension header - fd2imext = fits.getval(fname, 'D2IMEXT', ext=1) - fd2imext = fileutil.osfn(fd2imext) - if fd2imext and fileutil.findFile(fd2imext): - if fd2im0 != fd2imext: - applyD2IMCorr = True - else: - applyD2IMCorr = False - else: - # D2IM file defined in first extension may not be found - # but if a valid kw exists in the primary header, - # detector to image correction should be applied. - applyD2IMCorr = True - except KeyError: - # the case of D2IMFILE kw present in primary header but D2IMEXT missing - # in first extension header - applyD2IMCorr = True except KeyError: - print('D2IMFILE keyword not found in primary header') - applyD2IMCorr = False - return applyD2IMCorr + logger.info("D2IMFILE keyword is missing - D2IM correction will not be applied.") + + if fd2im0 == 'N/A': + utils.remove_distortion(fname, "D2IMFILE") + return False + fd2im0 = fileutil.osfn(fd2im0) + if not fileutil.findFile(fd2im0): + message = "D2IMFILE {0} not found.".format(fname) + logger.critical(message) + raise IOError(message) + try: + # get D2IMEXT kw from first extension header + fd2imext = fits.getval(fname, 'D2IMEXT', ext=1) + + except KeyError: + # the case of D2IMFILE kw present in primary header but D2IMEXT missing + # in first extension header + return True + fd2imext = fileutil.osfn(fd2imext) + if fd2imext and fileutil.findFile(fd2imext): + if fd2im0 != fd2imext: + applyD2IMCorr = True + else: + applyD2IMCorr = False + else: + # D2IM file defined in first extension may not be found + # but if a valid kw exists in the primary header, + # detector to image correction should be applied. + applyD2IMCorr = True + return applyD2IMCorr -- cgit 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/updatewcs/apply_corrections.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'stwcs/updatewcs') diff --git a/stwcs/updatewcs/apply_corrections.py b/stwcs/updatewcs/apply_corrections.py index c554564..247dba0 100644 --- a/stwcs/updatewcs/apply_corrections.py +++ b/stwcs/updatewcs/apply_corrections.py @@ -212,6 +212,28 @@ def isOldStyleDGEO(fname, dgname): def apply_d2im_correction(fname, d2imcorr): + """ + Logic to decide whether to apply the D2IM correction. + + Parameters + ---------- + fname : str + Science file name. + d2imcorr : bool + Flag indicating if D2IM is should be enabled if allowed. + + Return + ------ + applyD2IMCorr : bool + Flag whether to apply the correction. + + The D2IM correction is applied to a science file if it is in the + allowed corrections for the instrument. The name of the file + with the correction is saved in the ``D2IMFILE`` keyword in the + primary header. When the correction is applied the name of the + file is saved in the ``D2IMEXT`` keyword in the 1st extension header. + + """ applyD2IMCorr = True if not d2imcorr: logger.info("D2IM correction not requested - not applying it.") @@ -221,7 +243,7 @@ def apply_d2im_correction(fname, d2imcorr): fd2im0 = fits.getval(fname, 'D2IMFILE') except KeyError: logger.info("D2IMFILE keyword is missing - D2IM correction will not be applied.") - + return False if fd2im0 == 'N/A': utils.remove_distortion(fname, "D2IMFILE") return False -- cgit