IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 1, 2011, 10:33:56 PM (15 years ago)
Author:
rhenders
Message:

Added log method; added lots of comments; change ambiguous methid name from process to populatePspsTables

File:
1 edited

Legend:

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

    r31109 r31112  
    3535        # get survey ID from init table
    3636        sql = "SELECT surveyID from Survey WHERE name = '" + survey + "'"
    37         rs = self.stmt.executeQuery(sql) 
    38         rs.first()
    39         self.surveyID = rs.getInt(1)
     37        try:
     38            rs = self.stmt.executeQuery(sql) 
     39            rs.first()
     40            self.surveyID = rs.getInt(1)
     41        except:
     42            self.log("No survey ID found for this survey: '" + survey + "'")
     43            self.surveyID = -1;
    4044   
    4145        # store today's date
     
    5155    def __del__(self):
    5256
    53         print "Batch destructor"
     57        self.log("Batch destructor")
    5458        self.stmt.close()
    5559        self.con.close()
    5660
    5761    '''
     62    Prints a log message with the current time
     63    '''
     64    def log(self, msg):
     65
     66        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " | " + msg
     67
     68    '''
    5869    Updates a table with surveyID
    5970    '''
     
    8293        while (True):
    8394           record = fitsFile.read(80)
     95
     96           # quit when we reach 'END'
    8497           if record.startswith("END"): break
     98
     99           # ignore comments
    85100           if record.startswith("COMMENT"): continue
    86101           match = re.match('(.*)=(.*)', record)
    87102           if match:
    88103
     104               # remove HIERARCH prefix
    89105               param = match.group(1).replace("HIERARCH", "")
    90106               param = param.strip()
    91107
    92108               value = match.group(2)
    93                #print value
     109               # remove trailing comment after / char, if there is one
    94110               index = value.find("/")
    95                if index != -1:
    96                    value = value[0:index]
    97                #print value
     111               if index != -1: value = value[0:index]
     112
     113               # remove ' chars around content
    98114               value = value.replace("'", "")
     115
     116               # remove leading and trailing whitespace
    99117               value = value.strip()
    100118
     119               # store in out dictionary object
    101120               self.header[param] = value
    102121
    103122               #print param + "|" + value + "|"
    104        
    105         print "Fields in FITS header: ", len(self.header)
    106         print "NINPUTS = ", self.header['NINPUTS']
    107123
    108124    '''
     
    113129         self.pspsTables = stilts.treads(self.pspsVoTableFilePath)
    114130         for table in self.pspsTables:
    115              print "Creating PSPS table: " + table.name
     131             self.log("Creating PSPS table: " + table.name)
    116132             table.write(self.url + '#' + table.name)
    117133
     
    122138    '''   
    123139    def indexIppTables(self):
    124         print "indexIppTables not implemented"
     140        self.log("indexIppTables not implemented")
    125141
    126142
     
    130146    def createIndex(self, table, column):
    131147
    132         print "Creating index on column '"+column+"' for table '"+table+"'"
     148        self.log("Creating index on column '"+column+"' for table '"+table+"'")
    133149
    134150        sql = "CREATE INDEX "+table+"_index ON "+table+" ("+column+")"
     
    136152            self.stmt.execute(sql)
    137153        except:
    138             print "Index already in place on '" + column + "' for table '" + table + "'"
     154            self.log("Index already in place on '" + column + "' for table '" + table + "'")
    139155
    140156
     
    143159    '''   
    144160    def indexPspsTables(self):
    145         print "indexPspsTables not implemented"
    146 
     161        self.log("indexPspsTables not implemented")
    147162
    148163    '''
     
    154169
    155170      for table in tables:
    156           print "Creating IPP table " + table.name
     171          self.log("Creating IPP table " + table.name)
    157172          table = stilts.tpipe(table, cmd='explodeall')
    158173          try:
    159174              table.write(self.url + '#' + table.name)
    160175          except:
    161               print "ERROR table " + table.name + " is busted"
    162 
    163           self.indexIppTables()
     176              self.log("ERROR problem writing table '" + table.name + "' to the database")
     177
     178      self.indexIppTables()
    164179
    165180    '''
     
    168183    def exportPspsTablesToFits(self):
    169184
    170         print "Exporting all PSPS tables to FITS"
     185        self.log("Exporting all PSPS tables to FITS")
    171186        _tables = []
    172187
    173         print "    Selecting database tables"
     188        self.log("    Selecting database tables")
    174189        for table in self.pspsTables:
    175190           _table = stilts.tread(self.url + '#SELECT * FROM ' + table.name)
     
    177192           _tables.append(_table)
    178193
    179         print "    Writing to FITS file " + self.outputFitsPath
     194        self.log("    Writing to FITS file " + self.outputFitsPath)
    180195        stilts.twrites(_tables, self.outputFitsPath, fmt='fits')
    181196
     
    184199    Main processing method - must be implemented by subclasses
    185200    '''
    186     def process(self):
    187         print "Not implemented yet"
    188 
     201    def populatePspsTables(self):
     202        self.log("Not implemented yet")
     203
Note: See TracChangeset for help on using the changeset viewer.