IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37138


Ignore:
Timestamp:
Jul 29, 2014, 12:16:23 PM (12 years ago)
Author:
eugene
Message:

move importIppSTTables from batch.py to stackbatch.py and rename importIppTables; make batch:run call importIppTables consistently for all batch types

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

Legend:

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

    r37133 r37138  
    381381             self.tablesToExport.append(table.name)
    382382
    383          return self.alterPspsTables();
     383         return True
    384384
    385385    '''
     
    391391
    392392    '''
    393     Alter PSPS tables
     393    Alter PSPS tables (Subclass implements this)
    394394    '''   
    395395    def alterPspsTables(self):
     
    447447      self.indexIppTables()
    448448
    449       return True
    450     '''
    451     Imports IPP tables from FITS file
    452 
    453     Accepts a regular expression filter so not all tables need to be imported
    454     '''
    455     def importIppSTTables(self, columns="*", filter=""):
    456 
    457       self.logger.infoPair("Importing ST tables with filter", filter)
    458 
    459       # print "trying to read ", self.fits.getPath()
    460 
    461       # ST has 5 cmf files - all with the same table names. To counter this we do it like this.
    462 
    463       filters = ["g","r","i","z","y"]
    464       count = 0
    465       for f in filters:
    466           skip = 0
    467           if (f == "g"):
    468               if self.gstackID > 0: 
    469                   fileName = self.gfits.getPath()
    470               else:
    471                   skip = 1
    472           if (f == "r"):
    473               if self.rstackID > 0:
    474                   fileName = self.rfits.getPath()
    475               else:
    476                   skip = 1
    477           if (f == "i"):
    478               if self.istackID > 0:
    479                   fileName = self.ifits.getPath()
    480               else:
    481                   skip = 1
    482           if (f == "z"):
    483               if self.zstackID > 0:
    484                   fileName = self.zfits.getPath()
    485               else:
    486                   skip = 1
    487           if (f == "y"):
    488               if self.ystackID > 0:
    489                   fileName = self.yfits.getPath()
    490               else:
    491                   skip = 1
    492 
    493           if skip == 1:
    494               self.logger.infoPair("no files for filter" , f)
    495           else:
    496              self.logger.infoPair("using filename:",fileName)
    497          
    498              try:
    499               tables = stilts.treads(fileName)
    500              except:
    501               self.logger.errorPair("STILTS could not import from", fileName)
    502               return False
    503              
    504              #count = 0
    505              for table in tables:
    506              
    507               # print "import smf table ", table
    508               match = re.match(filter, table.name)
    509              
    510               if not match: continue
    511               self.logger.infoPair("Reading IPP table", f + table.name)
    512               table = stilts.tpipe(table, cmd='addcol table_index $0')
    513                  
    514               table = stilts.tpipe(table, cmd='explodeall')
    515                  
    516               # print "read smf table ", table
    517                  
    518               # drop any previous tables before import
    519               self.scratchDb.dropTable(f + table.name)
    520                  
    521               # IPP FITS files are littered with infinities, so remove these
    522               self.logger.debug("Removing Infinity values from all columns")
    523               table = stilts.tpipe(table, cmd='keepcols "' + columns + '"')
    524               table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
    525               table = stilts.tpipe(table, cmd='replaceval Infinity null *')
    526               # print "cleaned up values ", table
    527                  
    528               try:
    529                   table.write(self.scratchDb.url + '#' + f + table.name)
    530                   # XXX this one is not needed
    531                   # self.scratchDb.killLastConnectionID()
    532                   count = count + 1
    533               except:
    534                   self.logger.exception("Problem writing table '" + f + table.name + "' to the database")
    535                      
    536       self.logger.infoPair("Done. Imported", "%d tables" % count)
    537       self.indexIppTables()
    538                      
    539449      return True
    540450
     
    641551    def run(self):
    642552
    643         # this is badly named : it creates the tables and then fills in
    644         # the ImageMeta tables for each ota (alterPspsTables)
     553        # creates the empty PSPS tables
    645554        if not self.createEmptyPspsTables():
    646555            self.logger.errorPair("Aborting this batch", "could not create empty PSPS tables")
     
    648557            raise
    649558
     559        # fill in basic, not cmf/smf data (eg, ImageMeta for detectionbatch)
     560        if not self.alterPspsTables():
     561            self.logger.errorPair("Aborting this batch", "could not alter PSPS tables for batch type")
     562            self.ippToPspsDb.updateProcessed(self.batchID, -1)
     563            raise
     564
    650565        # for P2/ST, this reads the detection tables from the CMF/SMF file(s)
    651566        # for OB, this imports object data from DVO
    652         if self.batchType == "ST":
    653             self.logger.infoPair("did we get here","?") 
    654             if not self.importIppSTTables():
    655                 self.logger.errorPair("skipping this batch", "could not import ST IPP tables")
    656                 self.ippToPspsDb.updateProcessed(self.batchID, -1)
    657                 raise
    658             self.logger.infoPair("we did the ST","yes")
    659         else:   
    660             # if not ST we do this
    661             if not self.importIppTables():
    662                 if self.batchType == "OB":
    663                     self.logger.errorPair("skipping this batch", "no dvo tables for this region")
    664                     self.ippToPspsDb.updateProcessed(self.batchID, 1)
    665                     return True
    666                 self.logger.errorPair("Aborting this batch", "could not import IPP tables")
    667                 self.ippToPspsDb.updateProcessed(self.batchID, -1)
    668                 raise
     567        if not self.importIppTables():
     568            if self.batchType == "OB":
     569                self.logger.errorPair("skipping this batch", "no dvo tables for this region")
     570                self.ippToPspsDb.updateProcessed(self.batchID, 1)
     571                return True
     572            self.logger.errorPair("Aborting this batch", "could not import IPP tables")
     573            self.ippToPspsDb.updateProcessed(self.batchID, -1)
     574            raise
     575
    669576        self.logger.infoPair("populatePspsTables","ok")
    670577        if not self.populatePspsTables():
     
    700607                            tarballFile)
    701608
     609# XXX why is this down here??
    702610from datastore import Datastore
    703611
  • branches/eam_branches/ipp-20140717/ippToPsps/jython/stackbatch.py

    r37133 r37138  
    7575 #      self.logger.infoPair("y stackID ",ystackID)
    7676 #      raise
    77        # from each stackget fits name from getStackStageCmf
     77       # from each stack, get fits name from getStackStageCmf
    7878       if gstackID > 0:
    7979           self.logger.infoPair ("finding fits file for: ","g.00000")
     
    141141
    142142       metastackid = -999
    143        if gstackID > 0:
    144            metastackid = gstackID
    145        if rstackID > 0:
    146            metastackid = rstackID
    147        if istackID > 0:
    148            metastackid = istackID   
    149        if zstackID > 0:
    150            metastackid = zstackID
    151        if ystackID > 0:
    152            metastackid = ystackID
     143       if gstackID > 0: metastackid = gstackID
     144       if rstackID > 0: metastackid = rstackID
     145       if istackID > 0: metastackid = istackID   
     146       if zstackID > 0: metastackid = zstackID
     147       if ystackID > 0: metastackid = ystackID
     148
    153149       #there is probably a better way to do this
    154150       if metastackid < 0:
     
    159155       ## this should be ok - it takes a stack_id and returns filter/skycell etc.
    160156
    161 
    162157       if not meta:
    163158           self.logger.errorPair("Could not get stack", "metadata")
     
    174169       # we need 1133.081 for skycell, but store as an int, so instead store 1133081
    175170       # projection cell is just the 1133 bit
     171
    176172       # This Is how it should be done
    177173       #self.projectioncell = self.skycell[8:12]
     
    217213
    218214       self.scratchDb.dropTable("StackToImage")
    219              # self.testprint()
     215       # self.testprint()
    220216
    221217       # for PV2 we will have (grizy) of stack meta and skychip     
    222 
    223218
    224219       # delete IPP tables
     
    13351330    def exportPspsTablesToFits(self, regex="(.*)"):
    13361331        return super(StackBatch, self).exportPspsTablesToFits("(Stack.*)")
     1332
     1333    '''
     1334    Imports IPP tables from FITS file
     1335    Accepts a regular expression to match the tables so not all tables need to be imported
     1336    (This regex feature is not currently used...)
     1337    '''
     1338    def importIppTables(self, columns="*", tableRE=""):
     1339
     1340      self.logger.infoPair("Importing ST tables with table match expression: ", tableRE)
     1341
     1342      # print "trying to read ", self.fits.getPath()
     1343
     1344      # ST has 5 cmf files - all with the same table names. To counter this we do it like this.
     1345
     1346      filters = ["g","r","i","z","y"]
     1347      count = 0
     1348      for f in filters:
     1349          skip = 0
     1350          if (f == "g"):
     1351              if self.gstackID > 0: 
     1352                  fileName = self.gfits.getPath()
     1353              else:
     1354                  skip = 1
     1355          if (f == "r"):
     1356              if self.rstackID > 0:
     1357                  fileName = self.rfits.getPath()
     1358              else:
     1359                  skip = 1
     1360          if (f == "i"):
     1361              if self.istackID > 0:
     1362                  fileName = self.ifits.getPath()
     1363              else:
     1364                  skip = 1
     1365          if (f == "z"):
     1366              if self.zstackID > 0:
     1367                  fileName = self.zfits.getPath()
     1368              else:
     1369                  skip = 1
     1370          if (f == "y"):
     1371              if self.ystackID > 0:
     1372                  fileName = self.yfits.getPath()
     1373              else:
     1374                  skip = 1
     1375
     1376          if skip == 1:
     1377              self.logger.infoPair("no files for filter" , f)
     1378          else:
     1379             self.logger.infoPair("using filename:",fileName)
     1380         
     1381             try:
     1382              tables = stilts.treads(fileName)
     1383             except:
     1384              self.logger.errorPair("STILTS could not import from", fileName)
     1385              return False
     1386             
     1387             #count = 0
     1388             for table in tables:
     1389             
     1390              # print "import smf table ", table
     1391              match = re.match(tableRE, table.name)
     1392             
     1393              if not match: continue
     1394              self.logger.infoPair("Reading IPP table", f + table.name)
     1395              table = stilts.tpipe(table, cmd='addcol table_index $0')
     1396                 
     1397              table = stilts.tpipe(table, cmd='explodeall')
     1398                 
     1399              # print "read smf table ", table
     1400                 
     1401              # drop any previous tables before import
     1402              self.scratchDb.dropTable(f + table.name)
     1403                 
     1404              # IPP FITS files are littered with infinities, so remove these
     1405              self.logger.debug("Removing Infinity values from all columns")
     1406              table = stilts.tpipe(table, cmd='keepcols "' + columns + '"')
     1407              table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
     1408              table = stilts.tpipe(table, cmd='replaceval Infinity null *')
     1409              # print "cleaned up values ", table
     1410                 
     1411              try:
     1412                  table.write(self.scratchDb.url + '#' + f + table.name)
     1413                  count = count + 1
     1414              except:
     1415                  self.logger.exception("Problem writing table '" + f + table.name + "' to the database")
     1416                     
     1417      self.logger.infoPair("Done. Imported", "%d tables" % count)
     1418      self.indexIppTables()
     1419                     
     1420      return True
Note: See TracChangeset for help on using the changeset viewer.