IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 12, 2014, 4:10:18 PM (12 years ago)
Author:
eugene
Message:

merge changes from branches/eam_branches/ipp-20140717

File:
1 edited

Legend:

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

    r36726 r37246  
    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    '''
     
    373394             self.tablesToExport.append(table.name)
    374395
    375          return self.alterPspsTables();
     396         return True
    376397
    377398    '''
     
    383404
    384405    '''
    385     Alter PSPS tables
     406    Alter PSPS tables (Subclass implements this)
    386407    '''   
    387408    def alterPspsTables(self):
     
    417438
    418439          # print "read smf table ", table
     440          self.logger.infoPair("read smf table", table)
    419441
    420442          # drop any previous tables before import
     
    440462
    441463      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
    532464
    533465    '''
     
    548480           # get everything from table
    549481           try:
    550                print "reading table from mysql ", table
    551482               _table = stilts.tread(self.scratchDb.url + '#SELECT * FROM ' + table)
    552483               self.scratchDb.killLastConnectionID()
     
    633564    def run(self):
    634565
    635         # this is badly named : it creates the tables and then fills in
    636         # the ImageMeta tables for each ota (alterPspsTables)
     566        # creates the empty PSPS tables
    637567        if not self.createEmptyPspsTables():
    638568            self.logger.errorPair("Aborting this batch", "could not create empty PSPS tables")
     
    640570            raise
    641571
     572        # fill in basic, not cmf/smf data (eg, ImageMeta for detectionbatch)
     573        if not self.alterPspsTables():
     574            self.logger.errorPair("Aborting this batch", "could not alter PSPS tables for batch type")
     575            self.ippToPspsDb.updateProcessed(self.batchID, -1)
     576            raise
     577
    642578        # for P2/ST, this reads the detection tables from the CMF/SMF file(s)
    643579        # 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
     580        if not self.importIppTables():
     581            if self.batchType == "OB":
     582                self.logger.errorPair("skipping this batch", "no dvo tables for this region")
     583                self.ippToPspsDb.updateProcessed(self.batchID, 1)
     584                return True
     585            self.logger.errorPair("Aborting this batch", "could not import IPP tables")
     586            self.ippToPspsDb.updateProcessed(self.batchID, -1)
     587            raise
     588
    661589        self.logger.infoPair("populatePspsTables","ok")
    662590        if not self.populatePspsTables():
     
    692620                            tarballFile)
    693621
     622        if self.config.onebatch:
     623            self.logger.infoPair("onebatch requested", "exiting")
     624            sys.exit(0)
     625
     626# XXX why is this down here??
    694627from datastore import Datastore
    695 
Note: See TracChangeset for help on using the changeset viewer.