IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 5, 2016, 3:34:49 PM (11 years ago)
Author:
eugene
Message:

need to handle possibly NULL / NaN values in the headers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/detectionbatch.py

    r39133 r39305  
    149149        sqlLine.group("analysisVer",           self.analysisVer);
    150150        sqlLine.group("md5sum",                str(self.md5sum))
     151
     152        # these lines should write "NULL" if the header contains NaN -- NULLs are converted below
     153        # to -999 for the sql database (a terrible solution, but mandatory?)
     154
    151155        sqlLine.group("photoScat",             self.getKeyFloat(self.header, "%.8f", 'ZPT_ERR'));
    152156        sqlLine.group("expStart",              self.getKeyFloat(self.header, "%.10f", 'MJD-OBS'));
     
    218222        else: ccdID = 0
    219223
     224        ### any operations below which act on the output of getKeyFloat need to be
     225        ### able to handle NULL results.
     226
    220227        # XXX hard-wired platescale : 0.257
    221228        pltscale = 0.257
    222229        pltscale2 = pltscale * pltscale
    223230
    224         psfFwhmMajor = pltscale * self.getKeyFloat(header, "%.8f", 'FWHM_MAJ')
    225         psfFwhmMinor = pltscale * self.getKeyFloat(header, "%.8f", 'FWHM_MIN')
    226         psfFWHM = 0.5*(psfFwhmMajor + psfFwhmMinor)
     231        # NOTE: getKeyFloat returns the header value if it is a float,
     232        # -999 if the value is missing and "NULL" if the value in the
     233        # header is a NaN.  any math operations below need to handle
     234        # these cases correctly
     235
     236        # NOTE 2: getKeyFloat NOW returns the header value if it is a
     237        # float or "NULL" if the value is missing or if the value in
     238        # the header is a NaN.  any math operations below need to
     239        # handle these cases correctly
     240
     241        psfFwhmMajor = self.getKeyFloat(header, "%.8f", 'FWHM_MAJ')
     242        if (psfFwhmMajor != "NULL"): psfFwhmMajor *= pltscale
     243
     244        psfFwhmMinor = self.getKeyFloat(header, "%.8f", 'FWHM_MIN')
     245        if (psfFwhmMinor != "NULL"): psfFwhmMinor *= pltscale
     246
     247        psfFWHM = "NULL"
     248        if (psfFwhmMajor != "NULL") and (psfFwhmMinor != "NULL"):
     249            psfFWHM = 0.5*(psfFwhmMajor + psfFwhmMinor)
    227250
    228251        psfmodel_name = self.getKeyValue(header, 'PSFMODEL')
     
    231254        ast_cdx = self.getKeyFloat(header, "%.8f",'AST_CDX')
    232255        ast_cdy = self.getKeyFloat(header, "%.8f",'AST_CDY')
    233         astroscat = math.sqrt(ast_cdx**2 + ast_cdy**2)
     256
     257        astroscat = "NULL"
     258        if (ast_cdx != "NULL") and (ast_cdy != "NULL"):
     259            astroscat = math.sqrt(ast_cdx**2 + ast_cdy**2)
    234260       
    235261        # Convert detectionThreshold to appropriate magnitudes
    236         detectionThreshold = self.getKeyFloat(header, "%.8f", 'DETEFF.MAGREF')
     262        magref = self.getKeyFloat(header, "%.8f", 'DETEFF.MAGREF')
    237263        expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME')
    238264        zp      = self.getKeyFloat(header, "%.8f", 'ZPT_OBS')
    239265
     266        # zp correction from DVO
    240267        zpImage = self.scratchDb.getImageZeroPoint(self.imageIDs[ota])
    241268
    242         # XXX zp correction should come from DVO
    243         detectionThreshold = detectionThreshold + zpImage + 2.5 * math.log10(expTime)
    244        
     269        if (zpImage == "NULL"):
     270            zpImage = zp
     271
     272        detectionThreshold = "NULL"
     273        if (magref != "NULL") and (zpImage != "NULL") and (expTime != "NULL"):
     274            detectionThreshold = magref + zpImage + 2.5 * math.log10(expTime)
     275       
     276        # other header fields which depend on pltscale:
     277        momentMajor =        self.getKeyFloat(header, "%.8f", 'IQ_FW1'))
     278        momentMinor =        self.getKeyFloat(header, "%.8f", 'IQ_FW2'))
     279        momentM2C =          self.getKeyFloat(header, "%.8f", 'IQ_M2C'))
     280        momentM2S =          self.getKeyFloat(header, "%.8f", 'IQ_M2S'))
     281        momentM3 =           self.getKeyFloat(header, "%.8f", 'IQ_M3'))
     282        momentM4 =           self.getKeyFloat(header, "%.8f", 'IQ_M4'))
     283
     284        if (momentMajor != "NULL"): momentMajor *= pltscale
     285        if (momentMinor != "NULL"): momentMinor *= pltscale
     286        if (momentM2C   != "NULL"): momentM2C   *= pltscale2
     287        if (momentM2S   != "NULL"): momentM2S   *= pltscale2
     288        if (momentM3    != "NULL"): momentM3    *= pltscale2
     289        if (momentM4    != "NULL"): momentM4    *= pltscale2
     290
    245291        # insert image metadata into table
    246292        sqlLine = sqlUtility("INSERT INTO " + tableName + "(")
     
    265311        sqlLine.group("psfWidMinor",        psfFwhmMinor)
    266312        sqlLine.group("psfTheta",           self.getKeyFloat(header, "%.8f", 'ANGLE'))
    267         sqlLine.group("momentMajor",        pltscale * self.getKeyFloat(header, "%.8f", 'IQ_FW1'))
    268         sqlLine.group("momentMinor",        pltscale * self.getKeyFloat(header, "%.8f", 'IQ_FW2'))
    269         sqlLine.group("momentM2C",          pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M2C'))
    270         sqlLine.group("momentM2S",          pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M2S'))
    271         sqlLine.group("momentM3",           pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M3'))
    272         sqlLine.group("momentM4",           pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M4'))
     313        sqlLine.group("momentMajor",        momentMajor)
     314        sqlLine.group("momentMinor",        momentMinor)
     315        sqlLine.group("momentM2C",          momentM2C)
     316        sqlLine.group("momentM2S",          momentM2S)
     317        sqlLine.group("momentM3",           momentM3)
     318        sqlLine.group("momentM4",           momentM4)
    273319        sqlLine.group("apResid",            self.getKeyFloat(header, "%.8f", 'APMIFIT'))
    274320        sqlLine.group("dapResid",           self.getKeyFloat(header, "%.8f", 'DAPMIFIT'))
     
    374420        # CZW: 20151110 This needs to get the deteff header as well.
    375421        nInjected = int(self.getKeyInt(deteffHeader, 0, 'DETEFF.NUM'))
    376         magref = self.getKeyFloat(deteffHeader, "%.8f", 'DETEFF.MAGREF')
    377 
     422        magref  = self.getKeyFloat(deteffHeader, "%.8f", 'DETEFF.MAGREF')
    378423        expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME')
    379424        zp      = self.getKeyFloat(header, "%.8f", 'ZPT_OBS')
     
    382427        zpImage = self.scratchDb.getImageZeroPoint(self.imageIDs[ota])
    383428
    384         if zpImage < 0.0:
     429        if (zpImage == "NULL"):
    385430            zpImage = zp
    386431
    387         detectionThreshold = magref + zpImage + 2.5 * math.log10(expTime)
     432        detectionThreshold = "NULL"
     433        if (magref != "NULL") and (zpImage != "NULL") and (expTime != "NULL"):
     434            detectionThreshold = magref + zpImage + 2.5 * math.log10(expTime)
    388435
    389436        sqlLine.group("frameID",          str(self.expID))
Note: See TracChangeset for help on using the changeset viewer.