IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34107 for trunk/ippToPsps


Ignore:
Timestamp:
Jun 29, 2012, 9:09:49 AM (14 years ago)
Author:
eugene
Message:

add the function importPhotcodes to deal with special-case of table translation

File:
1 edited

Legend:

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

    r34104 r34107  
    109109        self.logger.infoPair("DVO Photcodes.dat file", "NOT up-to-date")
    110110
    111         self.importFits(
     111        self.importPhotcodes(
    112112                path,
    113                 "CODE NAME TYPE",
    114113                self.scratchDb.dvoPhotcodesTable)
    115114        self.logger.infoPair("Adding primary key to", self.scratchDb.dvoPhotcodesTable)
    … …  
    491490      return tableName
    492491
     492    '''
     493    Imports the Photcode file
     494    '''
     495    def importPhotcodes(self, path, tableName):
     496
     497      self.logger.infoPair("Importing file", "%s (%s)" % (path, self.getFileSizeStr(self.getDiskSize(path))))
     498      self.logger.debugPair("Writing to database table", tableName)
     499
     500      tables = stilts.treads(path)
     501
     502      # complain if len(tables) > 1
     503
     504      self.logger.debugPair("Reading IPP table", tables[0].name)
     505      table = stilts.tpipe(tables[0], cmd='explodeall')
     506     
     507      # IPP FITS files are littered with infinity values. Remove them (probably not needed for photcodes)
     508      self.logger.debugPair("Removing", "infinity values")
     509      table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
     510      table = stilts.tpipe(table, cmd='replaceval Infinity null *')
     511
     512      # convert the 1-char field TYPE to an int for querying ease (probably more sophisticated was to do this...)
     513      table = stilts.tpipe(table, cmd='addcol -after TYPE TYPE_AS_INT "TYPE + 0"')
     514
     515      attempts = 0
     516      self.logger.debugPair("Writing table to database",  table.name)
     517      while True:
     518   
     519          try:
     520              if attempts > 0: self.logger.infoPair("Attempt %d to write" % attempts, table.name)
     521              table.cmd_keepcols("CODE NAME TYPE_AS_INT").write(self.scratchDb.url + '#' + tableName)
     522              break
     523          except:
     524              # wait a few secs then try again
     525              time.sleep(2)
     526              attempts = attempts + 1
     527             
     528              count = count + 1
     529             
     530      self.logger.debugPair("Finished importing", tableName)
     531
     532      return tableName
     533
Note: See TracChangeset for help on using the changeset viewer.