IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37160


Ignore:
Timestamp:
Jul 31, 2014, 2:34:33 PM (12 years ago)
Author:
eugene
Message:

add method getKeyFloat to generate a safe header float for sql; add some options to handle test data cases; StackModelFit* now basically works

Location:
branches/eam_branches/ipp-20140717/ippToPsps/jython
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140717/ippToPsps/jython/batch.py

    r37138 r37160  
    242242
    243243         if key in header: return header[key]
     244         else:
     245             self.logger.errorPair("Missing header field", key)
     246             return "NULL"
     247
     248    '''
     249    Returns the string keyword value from this header or else "NULL"
     250    '''
     251    def getKeyFloat(self, header, format, key):
     252
     253         if key in header:
     254             value = format % float(header[key])
     255             return value
    244256         else:
    245257             self.logger.errorPair("Missing header field", key)
  • branches/eam_branches/ipp-20140717/ippToPsps/jython/config.py

    r37156 r37160  
    2424        self.resetDvo = False
    2525        self.gpc1test = True
     26        self.retry = False
     27        self.camera = "gpc1"
    2628
    2729        if sys.argv.count("-test"):
     
    4749            sys.argv.remove("-reset-dvo")
    4850
     51        if sys.argv.count("-retry"):
     52            self.retry = True
     53            sys.argv.remove("-retry")
     54
     55        if sys.argv.count("-simtest"):
     56            self.camera = "simtest"
     57            sys.argv.remove("-simtest")
     58
    4959        print "test: " + str(self.test)
    5060        print "gpc1test: " + str(self.gpc1test)
    5161        print "resetDvo: " + str(self.resetDvo)
     62        print "retry: " + str(self.retry)
     63        print "camera: " + self.camera
    5264
    5365        for arg in sys.argv:
  • branches/eam_branches/ipp-20140717/ippToPsps/jython/dvo.py

    r37156 r37160  
    679679                useP2 = 1
    680680
    681         if (useP2 ==0 and useST ==1):
     681        if (useP2 == 0 and useST == 1):
    682682            # grab only stacks
    683             if self.config.gpc1test:
    684                 # gpc1test -> SIMTEST.x.SkyChip
     683            if (self.config.camera == "simtest"):
     684                # SIMTEST.x.SkyChip
    685685                cmd += " -photcode-start 14100 -photcode-end 14500"
    686686            else:
     
    688688                cmd += " -photcode-start 11000 -photcode-end 11500"
    689689
    690         if (useP2 ==1 and useST==0):
    691             #grab only P2s (4000-4500 are test cameras, SIMTEST and SIMMOSAIC)
    692             if self.config.gpc1test:
    693                 # gpc1test -> SIMTEST.x.Chip
     690        if (useP2 == 1 and useST == 0):
     691            # grab only P2s (4000-4500 are test cameras, SIMTEST and SIMMOSAIC)
     692            if (self.config.camera == "simtest"):
     693                # SIMTEST.x.Chip
    694694                cmd += " -photcode-start  4100 -photcode-end 4500"
    695695            else:
  • branches/eam_branches/ipp-20140717/ippToPsps/jython/mysql.py

    r37156 r37160  
    283283            #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'")
    284284
    285     def addPrimaryKeyWithIgnore(self, table, column)
     285    def addPrimaryKeyWithIgnore(self, table, column):
    286286        # note that in mysql versions later than 5.1, this fails
    287287        # unless the following is called first:
  • branches/eam_branches/ipp-20140717/ippToPsps/jython/stackbatch.py

    r37156 r37160  
    103103
    104104           if not (str(stackID) == header['IMAGEID']):
    105                self.logger.errorPair("inconsistency: header IMAGEID does not match stackID", stackID + " vs " + header['IMAGEID'])
     105               self.logger.errorPair("inconsistency: header IMAGEID does not match stackID", str(stackID) + " vs " + header['IMAGEID'])
    106106               raise
    107107
     
    173173
    174174       # delete IPP tables
    175        self.logger.info("dropping Stack cmf tables")
    176        for filter in self.filters:
    177            tableName = filter + "SkyChip_psf"
    178            self.scratchDb.dropTable(tableName)
    179            tableName = filter + "SkyChip_xrad"
    180            self.scratchDb.dropTable(tableName)
    181            tableName = filter + "SkyChip_xsrc"
    182            self.scratchDb.dropTable(tableName)
    183            tableName = filter + "SkyChip_xfit"
    184            self.scratchDb.dropTable(tableName)
     175       if not self.config.retry:
     176           self.logger.info("dropping Stack cmf tables")
     177           for filter in self.filters:
     178               tableName = filter + "SkyChip_psf"
     179               self.scratchDb.dropTable(tableName)
     180               tableName = filter + "SkyChip_xrad"
     181               self.scratchDb.dropTable(tableName)
     182               tableName = filter + "SkyChip_xsrc"
     183               self.scratchDb.dropTable(tableName)
     184               tableName = filter + "SkyChip_xfit"
     185               self.scratchDb.dropTable(tableName)
    185186
    186187       # create an output filename, which is {stackID}.FITS
     
    350351        self.logger.infoPair("Populating table", tablename)
    351352
    352         self.fwhm_maj    = self.getKeyValue(header, 'FWHM_MAJ')
    353         self.fwhm_maj_uq = self.getKeyValue(header, 'FW_MJ_UQ')
    354         self.psfmodel    = self.getKeyValue(header, 'PSFMODEL')
    355 
    356         if (self.fwhm_maj    == "NULL"): self.fwhm_maj    = -999
    357         if (self.fwhm_maj_uq == "NULL"): self.fwhm_maj_uq = -999
     353        fwhm_maj    = self.getKeyValue(header, 'FWHM_MAJ')
     354        fwhm_maj_uq = self.getKeyValue(header, 'FW_MJ_UQ')
     355        psfmodel    = self.getKeyValue(header, 'PSFMODEL')
     356
     357        if (fwhm_maj    == "NULL"): fwhm_maj    = -999
     358        if (fwhm_maj_uq == "NULL"): fwhm_maj_uq = -999
    358359
    359360        # make a table
     
    363364        photoCalID = str(self.scratchDb.getPhotoCalID(stackID))
    364365
    365         # XXX mysql is sensitive to values which are ambiugously float.  eg
     366        # mysql is sensitive to values which are ambiugously float.  eg
    366367        # a warning is raised if we try to insert '25.' into a float field.
    367         # I should make a function to sanitize float values to a desired number
    368         # of decimal points
    369         zpString = "%5.5f" % float(header['FPA.ZP'])
     368        # use getKeyFloat(hdr, format, key) to avoid this problem
    370369
    371370        sql = "CREATE TABLE " + tablename + " LIKE StackMeta"
     
    382381        sqlLine.group("skyCellID",     self.skycell)           
    383382        sqlLine.group("photoCalID",    photoCalID)
    384         sqlLine.group("photoZero",     zpString)    # XXX see note above
    385         sqlLine.group("expTime",       header['EXPTIME']
    386         sqlLine.group("psfModelID",    self.psfmodel)           
    387         sqlLine.group("psfFwhm_mean",  str(self.fwhm_maj))     
    388         sqlLine.group("psfFwhm_max",   str(self.fwhm_maj_uq))   
     383        sqlLine.group("photoZero",     self.getKeyFloat(header, "%.5f", 'FPA.ZP'))
     384        sqlLine.group("expTime",       self.getKeyFloat(header, "%.5f", 'EXPTIME')
     385        sqlLine.group("psfModelID",    psfmodel)           
     386        sqlLine.group("psfFwhm_mean",  fwhm_maj)     
     387        sqlLine.group("psfFwhm_max",   fwhm_maj_uq)   
    389388        sqlLine.group("ctype1",        header['CTYPE1']) 
    390389        sqlLine.group("ctype2",        header['CTYPE2']) 
    391         sqlLine.group("crval1",        header['CRVAL1'])   
    392         sqlLine.group("crval2",        header['CRVAL2'])   
    393         sqlLine.group("crpix1",        header['CRPIX1'])   
    394         sqlLine.group("crpix2",        header['CRPIX2'])   
    395         sqlLine.group("cdelt1",        header['CDELT1'])   
    396         sqlLine.group("cdelt2",        header['CDELT2'])   
    397         sqlLine.group("pc001001",      header['PC001001'])
    398         sqlLine.group("pc001002",      header['PC001002'])
    399         sqlLine.group("pc002001",      header['PC002001'])
    400         sqlLine.group("pc002002",      header['PC002002'])
     390        sqlLine.group("crval1",        self.getKeyFloat(header, "%.8f", 'CRVAL1'))   
     391        sqlLine.group("crval2",        self.getKeyFloat(header, "%.8f", 'CRVAL2'))   
     392        sqlLine.group("crpix1",        self.getKeyFloat(header, "%.8f", 'CRPIX1'))   
     393        sqlLine.group("crpix2",        self.getKeyFloat(header, "%.8f", 'CRPIX2'))   
     394        sqlLine.group("cdelt1",        self.getKeyFloat(header, "%.8e", 'CDELT1'))   
     395        sqlLine.group("cdelt2",        self.getKeyFloat(header, "%.8e", 'CDELT2'))   
     396        sqlLine.group("pc001001",      self.getKeyFloat(header, "%.8e", 'PC001001'))
     397        sqlLine.group("pc001002",      self.getKeyFloat(header, "%.8e", 'PC001002'))
     398        sqlLine.group("pc002001",      self.getKeyFloat(header, "%.8e", 'PC002001'))
     399        sqlLine.group("pc002002",      self.getKeyFloat(header, "%.8e", 'PC002002'))
    401400
    402401        sql = sqlLine.make(") VALUES ( ", ")")
     
    469468            # insert values coming from the CMF, not carried by DVO
    470469            header = self.headerSet[filter]
    471             exptime = header['EXPTIME']
     470            exptime = self.getKeyFloat(header, "%.5f", "EXPTIME")
    472471
    473472            sqlLine = sqlUtility("UPDATE StackObjectThin AS a , " + filter + "SkyChip_psf AS b SET")
     
    516515
    517516            header = self.headerSet[filter]
    518             exptime = header['EXPTIME']
     517            exptime = self.getKeyFloat(header, "%.5f", "EXPTIME")
    519518
    520519            # insert all the detections
     
    603602
    604603        for filter in self.filters:
    605             populateStackModelFitFilter(model, ippModelType, filter)
     604            self.populateStackModelFitFilter(model, ippModelType, filter)
    606605
    607606    '''
    608607    Updates parameters for a particular model in the StackModelFit table
    609608    '''
    610     def populateStackModelFitFilter(self, model, ippModelType, filter, exptime):
     609    def populateStackModelFitFilter(self, model, ippModelType, filter):
     610
     611        if self.stackIDs[filter] <= 0:
     612            self.logger.infoPair("no stack data for filter" , filter)
     613            return True
     614
     615        table = "StackModelFit" + model
    611616
    612617        header  = self.headerSet[filter]
    613         exptime = header['EXPTIME']
    614 
    615         sqlLine = sqlUtility("UPDATE StackModelFit AS a, " + filter + "SkyChip_xfit AS b SET")
     618        exptime = self.getKeyFloat(header, "%.5f", "EXPTIME")
     619
     620        sqlLine = sqlUtility("UPDATE " + table + " AS a, " + filter + "SkyChip_xfit AS b SET")
    616621
    617622        # these lines yield the flux, flux error values, but I do not think we want those in the database...
     
    630635        sqlLine.group("a." + filter + model + "PhiErr",    "b.EXT_THETA_ERR") # these are not correctly defined.
    631636
    632         sqlLine.group("a." + filter + model + "Ra",        "b.RA_EXT")
    633         sqlLine.group("a." + filter + model + "Dec",       "b.DEC_EXT")
    634 
    635         sqlLine.group("a." + filter + model + "RaErr",     "b.X_EXT_SIG * b.PLTSCALE")
    636         sqlLine.group("a." + filter + model + "DecErr",    "b.Y_EXT_SIG * b.PLTSCALE")
     637        # XXX this is tricky: RA_EXT is not defined, but X_EXT is...
     638        # sqlLine.group("a." + filter + model + "Ra",        "b.RA_EXT")
     639        # sqlLine.group("a." + filter + model + "Dec",       "b.DEC_EXT")
     640        # sqlLine.group("a." + filter + model + "RaErr",     "b.X_EXT_SIG * b.PLTSCALE")
     641        # sqlLine.group("a." + filter + model + "DecErr",    "b.Y_EXT_SIG * b.PLTSCALE")
    637642
    638643        # sersic fit has an extra parameter
     
    874879
    875880        self.logger.infoPair("Creating indexes on", "IPP tables")
    876         self.scratchDb.createIndex("SkyChip_psf", "IPP_IDET")
     881        self.scratchDb.createIndex("SkyChip_psf",  "IPP_IDET")
    877882        self.scratchDb.createIndex("SkyChip_xfit", "IPP_IDET")
    878883        self.scratchDb.createIndex("SkyChip_xrad", "IPP_IDET")
     
    10911096    '''
    10921097    def importIppTables(self, columns="*", tableRE=""):
    1093 
    1094       self.logger.infoPair("Importing ST tables with table match expression: ", tableRE)
    1095 
    1096       count = 0
    1097       for filter in self.filters:
    1098           if self.stackIDs[filter] <= 0: 
    1099               self.logger.infoPair("no files for filter" , filter)
    1100               continue
    1101 
    1102           fileName = self.fits[filter].getPath()
    1103          
    1104           self.logger.infoPair("using filename:",fileName)
    1105          
    1106           try:
    1107               tables = stilts.treads(fileName)
    1108           except:
    1109               self.logger.errorPair("STILTS could not import from", fileName)
    1110               return False
     1098       
     1099        if self.config.retry: return True
     1100
     1101        self.logger.infoPair("Importing ST tables with table match expression: ", tableRE)
     1102
     1103        count = 0
     1104        for filter in self.filters:
     1105            if self.stackIDs[filter] <= 0: 
     1106                self.logger.infoPair("no files for filter" , filter)
     1107                continue
     1108
     1109            fileName = self.fits[filter].getPath()
     1110           
     1111            self.logger.infoPair("using filename:",fileName)
     1112           
     1113            try:
     1114                tables = stilts.treads(fileName)
     1115            except:
     1116                self.logger.errorPair("STILTS could not import from", fileName)
     1117                return False
     1118           
     1119            # count = 0
     1120            for table in tables:
    11111121             
    1112           # count = 0
    1113           for table in tables:
    1114              
    1115               # print "import smf table ", table
    1116               match = re.match(tableRE, table.name)
    1117               if not match: continue
    1118 
    1119               self.logger.infoPair("Reading IPP table", filter + table.name)
    1120               table = stilts.tpipe(table, cmd='addcol table_index $0')
    1121               table = stilts.tpipe(table, cmd='explodeall')
     1122                # print "import smf table ", table
     1123                match = re.match(tableRE, table.name)
     1124                if not match: continue
     1125
     1126                self.logger.infoPair("Reading IPP table", filter + table.name)
     1127                table = stilts.tpipe(table, cmd='addcol table_index $0')
     1128                table = stilts.tpipe(table, cmd='explodeall')
    11221129                 
    1123               # print "read smf table ", table
     1130                # print "read smf table ", table
     1131               
     1132                # drop any previous tables before import
     1133                self.scratchDb.dropTable(filter + table.name)
    11241134                 
    1125               # drop any previous tables before import
    1126               self.scratchDb.dropTable(filter + table.name)
     1135                # IPP FITS files are littered with infinities, so remove these
     1136                self.logger.debug("Removing Infinity values from all columns")
     1137                table = stilts.tpipe(table, cmd='keepcols "' + columns + '"')
     1138                table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
     1139                table = stilts.tpipe(table, cmd='replaceval Infinity null *')
     1140                # print "cleaned up values ", table
    11271141                 
    1128               # IPP FITS files are littered with infinities, so remove these
    1129               self.logger.debug("Removing Infinity values from all columns")
    1130               table = stilts.tpipe(table, cmd='keepcols "' + columns + '"')
    1131               table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
    1132               table = stilts.tpipe(table, cmd='replaceval Infinity null *')
    1133               # print "cleaned up values ", table
    1134                  
    1135               try:
    1136                   table.write(self.scratchDb.url + '#' + filter + table.name)
    1137                   count = count + 1
    1138               except:
    1139                   self.logger.exception("Problem writing table '" + filter + table.name + "' to the database")
     1142                try:
     1143                    table.write(self.scratchDb.url + '#' + filter + table.name)
     1144                    count = count + 1
     1145                except:
     1146                    self.logger.exception("Problem writing table '" + filter + table.name + "' to the database")
    11401147                     
    1141       self.logger.infoPair("Done. Imported", "%d tables" % count)
    1142       self.indexIppTables()
     1148        self.logger.infoPair("Done. Imported", "%d tables" % count)
     1149        self.indexIppTables()
    11431150                     
    1144       return True
     1151        return True
Note: See TracChangeset for help on using the changeset viewer.