IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 12, 2015, 12:24:24 PM (12 years ago)
Author:
eugene
Message:

various updates merged from trunk

File:
1 edited

Legend:

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

    r36726 r37820  
    3737                 batchID,
    3838                 batchType,
    39                  fits,
    40                  useFullTables):
    41 
    42         # print "starting the batch"
    43 
    44         # self.printline = 0
    45         # self.testprint()
     39                 fits):
    4640
    4741        self.readHeader = False
     
    4943        self.skychunk = skychunk
    5044        self.fits = fits
    51         self.useFullTables = useFullTables
    5245
    5346        # set up logging
     
    5548        self.logger.infoSeparator()
    5649        self.logger.debug("Batch class constructor")
    57 
    58         # self.testprint()
    5950
    6051        # set up class variables
     
    6859        self.pspsVoTableFilePath = self.config.configDir + "tables." + batchType + ".vot"
    6960
    70         # self.testprint()
    71 
    7261        # check FITS file is ok
    7362        if self.fits:
     
    7968                raise
    8069
    81         self.scratchDb.setUseFullTables(self.useFullTables)
     70        # define the dvo table names
     71        self.scratchDb.setDvoTableNames()
    8272
    8373        # TODO
     
    10797        if not os.path.exists(self.localOutPath): os.makedirs(self.localOutPath)
    10898
    109         # self.testprint()
    110 
    11199        # store today's date
    112100        now = datetime.datetime.now();
    113101        self.dateStr = now.strftime("%Y-%m-%d")
    114102
    115         # create DVO tables if accessing DVO directly
    116         if not self.useFullTables: self.scratchDb.createDvoTables()
     103        # create DVO tables (scratch database)
     104        self.scratchDb.createDvoTables()
    117105
    118106        # dump stuff to the log
     
    120108        self.logger.infoPair("Batch name", self.batchName)
    121109        self.logger.infoPair("Survey ID", "%d" % self.surveyID)
    122         self.logger.infoBool("Use full DVO tables?", self.useFullTables)
    123110
    124111        if self.fits:
    125112            self.logger.infoPair("Input FITS file", self.fits.getOriginalPath())
    126113            self.logger.infoPair("Input FITS primary header", "%s cards found" % self.fits.getPrimaryHeaderCardCount())
    127 
    128         # self.testprint()
    129114
    130115        self.logger.infoPair("Output path", self.localOutPath)
     
    237222             self.logger.errorPair("Missing header field", key)
    238223             return "NULL"
     224
     225    '''
     226    Returns the string keyword value from this header or else "NULL"
     227    '''
     228    def getKeyValue(self, header, key):
     229
     230         if key in header: return header[key]
     231         else:
     232             self.logger.errorPair("Missing header field", key)
     233             return "NULL"
     234
     235    '''
     236    Returns the string keyword value from this header or else "NULL"
     237    '''
     238    def getKeyFloat(self, header, format, key):
     239
     240         if key in header:
     241             value = format % float(header[key])
     242         else:
     243             self.logger.errorPair("Missing header field", key)
     244             value = format % -999.9
     245
     246         return value
     247
     248    '''
     249    Returns the string keyword value from this header or else "NULL"
     250    '''
     251    def getKeyInt(self, header, defValue, key):
     252
     253         if key in header:
     254             value = str(int(header[key]))
     255         else:
     256             self.logger.errorPair("Missing header field", key)
     257             value = str(defValue)
     258
     259         return value
    239260
    240261    '''
     
    362383        self.logger.infoPair("Max objID", "%ld" % self.maxObjID)
    363384
     385
     386    '''                                                                                           
     387    Sets min and max obj ID using the provided table, or list of tables                           
     388    '''
     389    def setMinMaxDiffObjID(self, tables):
     390        first = True
     391        self.totalDetections = 0
     392        for table in tables:
     393            sql = "SELECT MIN(diffObjID), MAX(diffObjID), COUNT(diffObjID) FROM " + table
     394            rs = self.scratchDb.executeQuery(sql)
     395            rs.first()
     396            self.totalDetections = self.totalDetections + rs.getLong(3)
     397            if first:
     398                self.minObjID = rs.getLong(1)
     399                self.maxObjID = rs.getLong(2)
     400            else:
     401                if rs.getLong(1) < self.minObjID: self.minObjID = rs.getLong(1)
     402                if rs.getLong(2) > self.maxObjID: self.maxObjID = rs.getLong(2)
     403            first = False
     404            rs.close()
     405        self.ippToPspsDb.updateDetectionStats(self.batchID, self.minObjID, self.maxObjID, self.totalDetections)
     406        self.logger.infoPair("Total detections", "%ld" % self.totalDetections)
     407        self.logger.infoPair("Min objID", "%ld" % self.minObjID)
     408        self.logger.infoPair("Max objID", "%ld" % self.maxObjID)
     409
     410
     411
    364412    '''
    365413    Creates PSPS tables from VOTable descriptions
     
    373421             self.tablesToExport.append(table.name)
    374422
    375          return self.alterPspsTables();
     423         return True
    376424
    377425    '''
     
    383431
    384432    '''
    385     Alter PSPS tables
     433    Alter PSPS tables (Subclass implements this)
    386434    '''   
    387435    def alterPspsTables(self):
     
    417465
    418466          # print "read smf table ", table
     467          self.logger.infoPair("read smf table", table)
    419468
    420469          # drop any previous tables before import
     
    440489
    441490      return True
    442     '''
    443     Imports IPP tables from FITS file
    444 
    445     Accepts a regular expression filter so not all tables need to be imported
    446     '''
    447     def importIppSTTables(self, columns="*", filter=""):
    448 
    449       self.logger.infoPair("Importing ST tables with filter", filter)
    450 
    451       # print "trying to read ", self.fits.getPath()
    452 
    453       # ST has 5 cmf files - all with the same table names. To counter this we do it like this.
    454 
    455       filters = ["g","r","i","z","y"]
    456       count = 0
    457       for f in filters:
    458           skip = 0
    459           if (f == "g"):
    460               if self.gstackID > 0: 
    461                   fileName = self.gfits.getPath()
    462               else:
    463                   skip = 1
    464           if (f == "r"):
    465               if self.rstackID > 0:
    466                   fileName = self.rfits.getPath()
    467               else:
    468                   skip = 1
    469           if (f == "i"):
    470               if self.istackID > 0:
    471                   fileName = self.ifits.getPath()
    472               else:
    473                   skip = 1
    474           if (f == "z"):
    475               if self.zstackID > 0:
    476                   fileName = self.zfits.getPath()
    477               else:
    478                   skip = 1
    479           if (f == "y"):
    480               if self.ystackID > 0:
    481                   fileName = self.yfits.getPath()
    482               else:
    483                   skip = 1
    484 
    485           if skip == 1:
    486               self.logger.infoPair("no files for filter" , f)
    487           else:
    488              self.logger.infoPair("using filename:",fileName)
    489          
    490              try:
    491               tables = stilts.treads(fileName)
    492              except:
    493               self.logger.errorPair("STILTS could not import from", fileName)
    494               return False
    495              
    496              #count = 0
    497              for table in tables:
    498              
    499               # print "import smf table ", table
    500               match = re.match(filter, table.name)
    501              
    502               if not match: continue
    503               self.logger.infoPair("Reading IPP table", f + table.name)
    504               table = stilts.tpipe(table, cmd='addcol table_index $0')
    505                  
    506               table = stilts.tpipe(table, cmd='explodeall')
    507                  
    508               # print "read smf table ", table
    509                  
    510               # drop any previous tables before import
    511               self.scratchDb.dropTable(f + table.name)
    512                  
    513               # IPP FITS files are littered with infinities, so remove these
    514               self.logger.debug("Removing Infinity values from all columns")
    515               table = stilts.tpipe(table, cmd='keepcols "' + columns + '"')
    516               table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
    517               table = stilts.tpipe(table, cmd='replaceval Infinity null *')
    518               # print "cleaned up values ", table
    519                  
    520               try:
    521                   table.write(self.scratchDb.url + '#' + f + table.name)
    522                   # XXX this one is not needed
    523                   # self.scratchDb.killLastConnectionID()
    524                   count = count + 1
    525               except:
    526                   self.logger.exception("Problem writing table '" + f + table.name + "' to the database")
    527                      
    528       self.logger.infoPair("Done. Imported", "%d tables" % count)
    529       self.indexIppTables()
    530                      
    531       return True
    532491
    533492    '''
     
    548507           # get everything from table
    549508           try:
    550                print "reading table from mysql ", table
    551509               _table = stilts.tread(self.scratchDb.url + '#SELECT * FROM ' + table)
    552510               self.scratchDb.killLastConnectionID()
     
    633591    def run(self):
    634592
    635         # this is badly named : it creates the tables and then fills in
    636         # the ImageMeta tables for each ota (alterPspsTables)
     593        # creates the empty PSPS tables
    637594        if not self.createEmptyPspsTables():
    638595            self.logger.errorPair("Aborting this batch", "could not create empty PSPS tables")
     
    640597            raise
    641598
     599        # fill in basic, not cmf/smf data (eg, ImageMeta for detectionbatch)
     600        if not self.alterPspsTables():
     601            self.logger.errorPair("Aborting this batch", "could not alter PSPS tables for batch type")
     602            self.ippToPspsDb.updateProcessed(self.batchID, -1)
     603            raise
     604
    642605        # for P2/ST, this reads the detection tables from the CMF/SMF file(s)
    643606        # for OB, this imports object data from DVO
    644         if self.batchType == "ST":
    645             self.logger.infoPair("did we get here","?") 
    646             if not self.importIppSTTables():
    647                 self.logger.errorPair("skipping this batch", "could not import ST IPP tables")
    648                 self.ippToPspsDb.updateProcessed(self.batchID, -1)
    649                 raise
    650             self.logger.infoPair("we did the ST","yes")
    651         else:   
    652             # if not ST we do this
    653             if not self.importIppTables():
    654                 if self.batchType == "OB":
    655                     self.logger.errorPair("skipping this batch", "no dvo tables for this region")
    656                     self.ippToPspsDb.updateProcessed(self.batchID, 1)
    657                     return True
    658                 self.logger.errorPair("Aborting this batch", "could not import IPP tables")
    659                 self.ippToPspsDb.updateProcessed(self.batchID, -1)
    660                 raise
     607        if not self.importIppTables():
     608            if (self.batchType == "OB" or self.batchType =="DO" or self.batchType =="FO"):
     609                self.logger.errorPair("skipping this batch", "no dvo tables for this region")
     610                self.ippToPspsDb.updateProcessed(self.batchID, 1)
     611                return True
     612            self.logger.errorPair("Aborting this batch", "could not import IPP tables")
     613            self.ippToPspsDb.updateProcessed(self.batchID, -1)
     614            raise
     615
    661616        self.logger.infoPair("populatePspsTables","ok")
    662617        if not self.populatePspsTables():
     
    692647                            tarballFile)
    693648
     649        if self.config.onebatch:
     650            self.logger.infoPair("onebatch requested", "exiting")
     651            sys.exit(0)
     652
     653# XXX why is this down here??
    694654from datastore import Datastore
    695 
Note: See TracChangeset for help on using the changeset viewer.