Changeset 31112 for trunk/ippToPsps/jython/batch.py
- Timestamp:
- Apr 1, 2011, 10:33:56 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/batch.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/batch.py
r31109 r31112 35 35 # get survey ID from init table 36 36 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; 40 44 41 45 # store today's date … … 51 55 def __del__(self): 52 56 53 print "Batch destructor"57 self.log("Batch destructor") 54 58 self.stmt.close() 55 59 self.con.close() 56 60 57 61 ''' 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 ''' 58 69 Updates a table with surveyID 59 70 ''' … … 82 93 while (True): 83 94 record = fitsFile.read(80) 95 96 # quit when we reach 'END' 84 97 if record.startswith("END"): break 98 99 # ignore comments 85 100 if record.startswith("COMMENT"): continue 86 101 match = re.match('(.*)=(.*)', record) 87 102 if match: 88 103 104 # remove HIERARCH prefix 89 105 param = match.group(1).replace("HIERARCH", "") 90 106 param = param.strip() 91 107 92 108 value = match.group(2) 93 # print value109 # remove trailing comment after / char, if there is one 94 110 index = value.find("/") 95 if index != -1: 96 value = value[0:index] 97 # print value111 if index != -1: value = value[0:index] 112 113 # remove ' chars around content 98 114 value = value.replace("'", "") 115 116 # remove leading and trailing whitespace 99 117 value = value.strip() 100 118 119 # store in out dictionary object 101 120 self.header[param] = value 102 121 103 122 #print param + "|" + value + "|" 104 105 print "Fields in FITS header: ", len(self.header)106 print "NINPUTS = ", self.header['NINPUTS']107 123 108 124 ''' … … 113 129 self.pspsTables = stilts.treads(self.pspsVoTableFilePath) 114 130 for table in self.pspsTables: 115 print "Creating PSPS table: " + table.name131 self.log("Creating PSPS table: " + table.name) 116 132 table.write(self.url + '#' + table.name) 117 133 … … 122 138 ''' 123 139 def indexIppTables(self): 124 print "indexIppTables not implemented"140 self.log("indexIppTables not implemented") 125 141 126 142 … … 130 146 def createIndex(self, table, column): 131 147 132 print "Creating index on column '"+column+"' for table '"+table+"'"148 self.log("Creating index on column '"+column+"' for table '"+table+"'") 133 149 134 150 sql = "CREATE INDEX "+table+"_index ON "+table+" ("+column+")" … … 136 152 self.stmt.execute(sql) 137 153 except: 138 print "Index already in place on '" + column + "' for table '" + table + "'"154 self.log("Index already in place on '" + column + "' for table '" + table + "'") 139 155 140 156 … … 143 159 ''' 144 160 def indexPspsTables(self): 145 print "indexPspsTables not implemented" 146 161 self.log("indexPspsTables not implemented") 147 162 148 163 ''' … … 154 169 155 170 for table in tables: 156 print "Creating IPP table " + table.name171 self.log("Creating IPP table " + table.name) 157 172 table = stilts.tpipe(table, cmd='explodeall') 158 173 try: 159 174 table.write(self.url + '#' + table.name) 160 175 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() 164 179 165 180 ''' … … 168 183 def exportPspsTablesToFits(self): 169 184 170 print "Exporting all PSPS tables to FITS"185 self.log("Exporting all PSPS tables to FITS") 171 186 _tables = [] 172 187 173 print " Selecting database tables"188 self.log(" Selecting database tables") 174 189 for table in self.pspsTables: 175 190 _table = stilts.tread(self.url + '#SELECT * FROM ' + table.name) … … 177 192 _tables.append(_table) 178 193 179 print " Writing to FITS file " + self.outputFitsPath194 self.log(" Writing to FITS file " + self.outputFitsPath) 180 195 stilts.twrites(_tables, self.outputFitsPath, fmt='fits') 181 196 … … 184 199 Main processing method - must be implemented by subclasses 185 200 ''' 186 def p rocess(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.
