Changeset 31965 for trunk/ippToPsps/jython/dvoToMySQL.py
- Timestamp:
- Aug 1, 2011, 4:05:53 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/dvoToMySQL.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/dvoToMySQL.py
r31398 r31965 10 10 from subprocess import call, PIPE, Popen 11 11 12 from gpc1db import Gpc1Db12 from pslogger import PSLogger 13 13 from scratchdb import ScratchDb 14 14 … … 27 27 28 28 ''' 29 def __init__(self, logger , pathToDvo):29 def __init__(self, logger): 30 30 31 31 # set up logging 32 32 self.logger = logger 33 self. pathToDvo = pathToDvo34 self.logger. debug("DvoToMySql class constructor")35 36 self. logger.debug("Important DVO database at " + self.pathToDvo)33 self.logger.infoSeparator() 34 self.logger.info("Started dvoToMySql") 35 self.dvoMetaTable = "dvoMetaFull" 36 self.dvoDetectionTable = "dvoDetectionFull" 37 37 38 38 # open config 39 doc = ElementTree(file="config.xml") 39 self.doc = ElementTree(file="config.xml") 40 self.dvoLocation = self.doc.find("dvo/location").text 41 42 # some log stuff 43 self.logger.infoPair("Using DVO meta table", self.dvoMetaTable) 44 self.logger.infoPair("Using DVO detection table", self.dvoDetectionTable) 45 self.logger.infoPair("Importing DVO database at", self.dvoLocation) 40 46 41 47 # create database objects 42 self.scratchDb = ScratchDb(logger) 43 self.gpc1Db = Gpc1Db(self.logger) 48 self.scratchDb = ScratchDb(logger, self.doc, 1) 44 49 45 50 # create DVO tables … … 47 52 48 53 # import Images.dat table 54 self.logger.infoPair("Deleting from table", self.dvoMetaTable) 49 55 sql = "DELETE FROM dvoMetaFull" 50 self.scratchDb. stmt.execute(sql)51 52 imagesTableName = self.importFits(self. pathToDvo,56 self.scratchDb.execute(sql) 57 58 imagesTableName = self.importFits(self.dvoLocation, 53 59 "", 54 60 "Images.dat", 55 " IMAGE_ID SOURCE_ID CCDNUM EXTERN_ID FLAGS PHOTCODE NSTAR")56 self.scratchDb.createIndex(imagesTableName, " IMAGE_ID")61 "SOURCE_ID IMAGE_ID CCDNUM EXTERN_ID FLAGS PHOTCODE NSTAR") 62 self.scratchDb.createIndex(imagesTableName, "EXTERN_ID") 57 63 58 64 # insert into dvoMetaFull 65 # NB what we and smf files call IMAGE_ID, DVO calls EXTERN_ID. We are sticking 66 # with the smf name 59 67 self.logger.info("Inserting all image meta data into database") 60 sql = "INSERT INTO dvoMeta New( \68 sql = "INSERT INTO dvoMetaFull ( \ 61 69 sourceID, \ 62 70 imageID, \ … … 71 79 PHOTCODE \ 72 80 FROM " + imagesTableName 73 self.scratchDb. stmt.execute(sql)81 self.scratchDb.execute(sql) 74 82 75 83 subdirs = ['n0000'] … … 77 85 for subdir in subdirs: 78 86 79 files = glob.glob( pathToDvo+ "/" + subdir + "/*.cpm")87 files = glob.glob(self.dvoLocation + "/" + subdir + "/*.cpm") 80 88 81 89 #files = ['0247.06', '0244.06', '0244.10'] … … 90 98 91 99 # import cpm table and index 92 cpmTableName = self.importFits(self. pathToDvo,100 cpmTableName = self.importFits(self.dvoLocation, 93 101 subdir, 94 102 file + ".cpm", … … 98 106 99 107 # import cpt table and index 100 cptTableName = self.importFits(self. pathToDvo,108 cptTableName = self.importFits(self.dvoLocation, 101 109 subdir, 102 110 file + ".cpt", … … 107 115 # shove SOURCE_IDs into measurement table 108 116 self.logger.info("Adding SOURCE_IDs into measurements table") 109 sql = "ALTER TABLE " +cpmTableName+" ADD COLUMN (SOURCE_ID SMALLINT)"110 self.scratchDb. stmt.execute(sql)111 sql = "UPDATE " +cpmTableName+" AS a, "+imagesTableName+" AS b \117 sql = "ALTER TABLE " + cpmTableName + " ADD COLUMN (SOURCE_ID SMALLINT)" 118 self.scratchDb.execute(sql) 119 sql = "UPDATE " + cpmTableName + " AS a, " + imagesTableName + " AS b \ 112 120 SET a.SOURCE_ID = b.SOURCE_ID \ 113 121 WHERE a.IMAGE_ID = b.IMAGE_ID" 114 self.scratchDb. stmt.execute(sql)122 self.scratchDb.execute(sql) 115 123 116 124 # shove PSPS objID in measurement table 117 125 self.logger.info("Adding PSPS objID into measurements table") 118 126 sql = "ALTER TABLE "+cpmTableName+" ADD COLUMN (PSPS_OBJ_ID BIGINT)" 119 self.scratchDb. stmt.execute(sql)127 self.scratchDb.execute(sql) 120 128 sql = "UPDATE "+cpmTableName+" AS a, "+cptTableName+" AS b \ 121 129 SET a.PSPS_OBJ_ID = b.EXT_ID \ 122 130 WHERE a.CAT_ID = b.CAT_ID \ 123 131 AND a.OBJ_ID = b.OBJ_ID" 124 self.scratchDb. stmt.execute(sql)125 126 self.logger.info ("Putting everything into dvoDetectionFull table")132 self.scratchDb.execute(sql) 133 134 self.logger.infoPair("Populating", self.dvoDetectionTable) 127 135 sql = "INSERT IGNORE INTO dvoDetectionFull (\ 128 136 sourceID \ … … 142 150 ,DB_FLAGS \ 143 151 FROM " + cpmTableName 144 self.scratchDb. stmt.execute(sql)152 self.scratchDb.execute(sql) 145 153 146 154 # now drop what we don't need … … 173 181 tableName = tableName.replace('.', '_') 174 182 175 self.logger.info("Attempting to import tables from '" + fullPath + "' to '" + tableName + "'") 183 self.logger.infoPair("Importing tables from file", fullPath) 184 self.logger.infoPair("Writing to database table", tableName) 176 185 177 186 tables = stilts.treads(fullPath) … … 195 204 count = count + 1 196 205 197 self.logger.info ("Done. Imported%d tables" % count)206 self.logger.infoPair("Finished importing", "%d tables" % count) 198 207 199 208 return tableName 200 209 201 210 logging.config.fileConfig("logging.conf") 202 logger = logging.getLogger("dvotomysql") 203 logger.info("Starting") 204 205 dvoToMySql = DvoToMySql(logger, "/data/ipp005.0/gpc1/catdirs/MD04.merges/MD04.merge") 206 #dvoToMySql = DvoToMySql(logger, "/export/ippc00.1/rhenders/MD04.merge") 207 208 logger.info("Program complete") 209 211 logging.setLoggerClass(PSLogger) 212 logger = logging.getLogger("dvoToMySQLLog") 213 logger.setLevel(logging.INFO) 214 215 216 dvoToMySql = DvoToMySql(logger) 217 218 logger.infoPair("Program...", "complete") 219
Note:
See TracChangeset
for help on using the changeset viewer.
