Changeset 31994 for trunk/ippToPsps
- Timestamp:
- Aug 3, 2011, 11:57:31 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/dvoToMySQL.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/dvoToMySQL.py
r31972 r31994 27 27 28 28 ''' 29 def __init__(self, logger, RESETTABLES):29 def __init__(self, logger, doc, RESETTABLES): 30 30 31 31 # set up logging 32 32 self.logger = logger 33 self.doc = doc 33 34 self.logger.infoSeparator() 34 self.logger.info("Started dvoToMySql")35 self.dvoMetaTable = "dvoMetaFull"36 self.dvoDetectionTable = "dvoDetectionFull"37 38 # open config39 self.doc = ElementTree(file="config.xml")40 35 self.dvoLocation = self.doc.find("dvo/location").text 41 36 37 # create database object 38 self.scratchDb = ScratchDb(logger, self.doc, 1) 39 42 40 # 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") 45 42 self.logger.infoPair("Importing DVO database at", self.dvoLocation) 46 47 # create database objects48 self.scratchDb = ScratchDb(logger, self.doc, 1)49 43 50 44 # create DVO tables … … 52 46 53 47 # 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 56 50 self.scratchDb.execute(sql) 57 51 … … 65 59 # NB what we and smf files call IMAGE_ID, DVO calls EXTERN_ID. We are sticking 66 60 # 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 + " ( \ 69 63 sourceID, \ 70 64 imageID, \ … … 93 87 # get just filename, without extension 94 88 file = os.path.basename(os.path.splitext(file)[0]) 95 self.logger.info ("---------------------------------------------: " + file)89 self.logger.infoSeparator() 96 90 97 91 if self.scratchDb.alreadyImportedThisDvoTable(file): continue … … 116 110 117 111 # shove SOURCE_IDs into measurement table 118 self.logger.info ("Adding SOURCE_IDs into measurements table")112 self.logger.infoPair("Adding", "SOURCE_IDs") 119 113 sql = "ALTER TABLE " + cpmTableName + " ADD COLUMN (SOURCE_ID SMALLINT)" 120 114 self.scratchDb.execute(sql) … … 125 119 126 120 # shove PSPS objID in measurement table 127 self.logger.info ("Adding PSPS objID into measurements table")121 self.logger.infoPair("Adding","PSPS objIDs") 128 122 sql = "ALTER TABLE "+cpmTableName+" ADD COLUMN (PSPS_OBJ_ID BIGINT)" 129 123 self.scratchDb.execute(sql) … … 138 132 # PSPS object IDs assigned in the corresponding cpt file. This is believed to be a chip-boundary 139 133 # 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 + " (\ 142 136 sourceID \ 143 137 ,imageID \ … … 163 157 164 158 # now drop what we don't need 165 self.logger.info ("Dropping tables")159 self.logger.infoPair("Dropping table", cpmTableName) 166 160 self.scratchDb.dropTable(cpmTableName) 161 self.logger.infoPair("Dropping table", cptTableName) 167 162 self.scratchDb.dropTable(cptTableName) 168 163 … … 199 194 for table in tables: 200 195 201 self.logger.info ("Reading IPP table " + table.name + " from FITS file")196 self.logger.infoPair("Reading IPP table", table.name) 202 197 table = stilts.tpipe(table, cmd='explodeall') 203 198 204 199 # 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") 206 201 table = stilts.tpipe(table, cmd='replaceval -Infinity null *') 207 202 table = stilts.tpipe(table, cmd='replaceval Infinity null *') 208 203 209 204 #try: 210 self.logger.info ("Writing FITS table todatabase")205 self.logger.infoPair("Writing FITS table to", "database") 211 206 table.cmd_keepcols(columns).write(self.scratchDb.url + '#' + tableName) 212 207 #except: … … 218 213 return tableName 219 214 215 216 ''' 217 Start of program. 218 ''' 219 220 if len(sys.argv) > 1: CONFIG = sys.argv[1] 221 else: 222 print "** Usage: " + sys.argv[0] + " <configPath> [reset]" 223 sys.exit(1) 224 225 # open config file 226 configDoc = ElementTree(file=CONFIG) 227 228 220 229 logging.config.fileConfig("logging.conf") 221 230 logging.setLoggerClass(PSLogger) … … 225 234 RESETTABLES = 0 226 235 227 if len(sys.argv) > 1 and sys.argv[1] == "reset":236 if len(sys.argv) > 2 and sys.argv[2] == "reset": 228 237 response = raw_input("* Are you ABSOLUTELY sure you want to recreate the DVO tables (y/n)? ") 229 238 if response == "y": RESETTABLES = 1 230 231 dvoToMySql = DvoToMySql(logger, RESETTABLES) 239 else: sys.exit(1) 240 241 dvoToMySql = DvoToMySql(logger, configDoc, RESETTABLES) 232 242 233 243 logger.infoPair("Program...", "complete")
Note:
See TracChangeset
for help on using the changeset viewer.
