IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31994 for trunk/ippToPsps


Ignore:
Timestamp:
Aug 3, 2011, 11:57:31 AM (15 years ago)
Author:
rhenders
Message:

lots of improvements to logging; improved check that user really wants to delete DVO tables; constructor now takes config doc as arg; first arg to program is path to config; dangerous reset option is now a second option

File:
1 edited

Legend:

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

    r31972 r31994  
    2727
    2828    '''
    29     def __init__(self, logger, RESETTABLES):
     29    def __init__(self, logger, doc, RESETTABLES):
    3030
    3131        # set up logging
    3232        self.logger = logger
     33        self.doc = doc
    3334        self.logger.infoSeparator()
    34         self.logger.info("Started dvoToMySql")
    35         self.dvoMetaTable = "dvoMetaFull"
    36         self.dvoDetectionTable = "dvoDetectionFull"
    37 
    38         # open config
    39         self.doc = ElementTree(file="config.xml")
    4035        self.dvoLocation = self.doc.find("dvo/location").text
    4136
     37        # create database object
     38        self.scratchDb = ScratchDb(logger, self.doc, 1)
     39
    4240        # some log stuff
    43         self.logger.infoPair("Using DVO meta table", self.dvoMetaTable)
    44         self.logger.infoPair("Using DVO detection table", self.dvoDetectionTable)
     41        self.logger.infoPair("Started", "dvoToMySql")
    4542        self.logger.infoPair("Importing DVO database at", self.dvoLocation)
    46 
    47         # create database objects
    48         self.scratchDb = ScratchDb(logger, self.doc, 1)
    4943
    5044        # create DVO tables
     
    5246
    5347        # import Images.dat table
    54         self.logger.infoPair("Deleting from table", self.dvoMetaTable)
    55         sql = "DELETE FROM dvoMetaFull"
     48        self.logger.infoPair("Deleting from table", self.scratchDb.dvoMetaTable)
     49        sql = "DELETE FROM " + self.scratchDb.dvoMetaTable
    5650        self.scratchDb.execute(sql)
    5751
     
    6559        # NB what we and smf files call IMAGE_ID, DVO calls EXTERN_ID. We are sticking
    6660        # with the smf name
    67         self.logger.info("Inserting all image meta data into database")
    68         sql = "INSERT INTO dvoMetaFull ( \
     61        self.logger.infoPair("Populating", "all image meta data")
     62        sql = "INSERT INTO " + self.scratchDb.dvoMetaTable + " ( \
    6963               sourceID, \
    7064               imageID, \
     
    9387                # get just filename, without extension
    9488                file = os.path.basename(os.path.splitext(file)[0])
    95                 self.logger.info("---------------------------------------------: " + file)
     89                self.logger.infoSeparator()
    9690
    9791                if self.scratchDb.alreadyImportedThisDvoTable(file): continue
     
    116110     
    117111                # shove SOURCE_IDs into measurement table
    118                 self.logger.info("Adding SOURCE_IDs into measurements table")
     112                self.logger.infoPair("Adding", "SOURCE_IDs")
    119113                sql = "ALTER TABLE " + cpmTableName + " ADD COLUMN (SOURCE_ID SMALLINT)"
    120114                self.scratchDb.execute(sql)
     
    125119
    126120                # shove PSPS objID in measurement table
    127                 self.logger.info("Adding PSPS objID into measurements table")
     121                self.logger.infoPair("Adding","PSPS objIDs")
    128122                sql = "ALTER TABLE "+cpmTableName+" ADD COLUMN (PSPS_OBJ_ID BIGINT)"
    129123                self.scratchDb.execute(sql)
     
    138132                # PSPS object IDs assigned in the corresponding cpt file. This is believed to be a chip-boundary
    139133                # issue within DVO. So, for now, we take the first IMAGE_ID/DET_ID detection we find, and ignore the rest
    140                 self.logger.infoPair("Populating", self.dvoDetectionTable)
    141                 sql = "INSERT IGNORE INTO dvoDetectionFull (\
     134                self.logger.infoPair("Populating", self.scratchDb.dvoDetectionTable)
     135                sql = "INSERT IGNORE INTO " + self.scratchDb.dvoDetectionTable + " (\
    142136                       sourceID \
    143137                       ,imageID \
     
    163157
    164158                # now drop what we don't need
    165                 self.logger.info("Dropping tables")
     159                self.logger.infoPair("Dropping table", cpmTableName)
    166160                self.scratchDb.dropTable(cpmTableName)
     161                self.logger.infoPair("Dropping table", cptTableName)
    167162                self.scratchDb.dropTable(cptTableName)
    168163       
     
    199194      for table in tables:
    200195
    201           self.logger.info("Reading IPP table " + table.name + " from FITS file")
     196          self.logger.infoPair("Reading IPP table", table.name)
    202197          table = stilts.tpipe(table, cmd='explodeall')
    203198     
    204199          # IPP FITS files are littered with infinities, so remove these
    205           self.logger.info("Removing Infinity values from all columns")
     200          self.logger.infoPair("Removing", "infinity values")
    206201          table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
    207202          table = stilts.tpipe(table, cmd='replaceval Infinity null *')
    208203
    209204          #try:
    210           self.logger.info("Writing FITS table to database")
     205          self.logger.infoPair("Writing FITS table to", "database")
    211206          table.cmd_keepcols(columns).write(self.scratchDb.url + '#' + tableName)
    212207          #except:
     
    218213      return tableName
    219214
     215
     216'''
     217Start of program.
     218'''
     219
     220if len(sys.argv) > 1: CONFIG  = sys.argv[1]
     221else:
     222    print "** Usage: " + sys.argv[0] + " <configPath> [reset]"
     223    sys.exit(1)
     224
     225# open config file
     226configDoc = ElementTree(file=CONFIG)
     227
     228
    220229logging.config.fileConfig("logging.conf")
    221230logging.setLoggerClass(PSLogger)
     
    225234RESETTABLES = 0
    226235
    227 if len(sys.argv) > 1 and sys.argv[1] == "reset":
     236if len(sys.argv) > 2 and sys.argv[2] == "reset":
    228237    response = raw_input("* Are you ABSOLUTELY sure you want to recreate the DVO tables (y/n)? ")
    229238    if response == "y": RESETTABLES = 1
    230 
    231 dvoToMySql = DvoToMySql(logger, RESETTABLES)
     239    else: sys.exit(1)
     240
     241dvoToMySql = DvoToMySql(logger, configDoc, RESETTABLES)
    232242
    233243logger.infoPair("Program...", "complete")
Note: See TracChangeset for help on using the changeset viewer.