Changeset 35097 for trunk/ippToPsps/jython/dvo.py
- Timestamp:
- Feb 6, 2013, 3:16:35 PM (13 years ago)
- Location:
- trunk/ippToPsps
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps
- Property svn:mergeinfo changed
-
trunk/ippToPsps/jython
- Property svn:ignore
-
old new 1 1 *.class 2 Makefile 3 Makefile.in
-
- Property svn:ignore
-
trunk/ippToPsps/jython/dvo.py
r34107 r35097 33 33 34 34 ''' 35 def __init__(self, logger, config, s cratchDbName="ipptopsps_scratch"):35 def __init__(self, logger, config, skychunk, ippToPspsDb, scratchDbName=None): 36 36 37 37 # set up logging 38 38 self.logger = logger 39 39 self.config = config 40 self.skychunk = skychunk 41 self.ippToPspsDb = ippToPspsDb 40 42 41 43 # set up empty lists … … 46 48 self.regionsIngestedButOutOfDate = [] 47 49 48 # connect to the specified scratch database 50 # connect to the specified scratch database, if a name is given, otherwise use the first version 49 51 try: 50 self.scratchDb = ScratchDb(self.logger, self.config, scratchDbName)52 self.scratchDb = ScratchDb(self.logger, self.config, '1', scratchDbName) 51 53 except: raise 52 54 55 # we have (still) 3 modes of ingest from dvo cpt/cps/cpm files 56 # 1) dvograbber (useFullTables == FALSE), 57 # 2) jython/stilts (useStilts == TRUE, useFullTables == TRUE) 58 # 3) dvopsps (useStilts == FALSE, useFullTables == TRUE) 59 # my goal (EAM, 2013/01/31) is to migrate to only dvopsps 60 61 self.useStilts = 0 53 62 self.scratchDb.setUseFullTables(True) 54 63 55 64 # decide if we are using the right DVO for this scratchDb 56 self.correctDvo = self.scratchDb.isCorrectDvo(self. config.dvoLocation)65 self.correctDvo = self.scratchDb.isCorrectDvo(self.skychunk.dvoLocation) 57 66 58 67 # this scratch Db either has no DVO info ingested, or a different DVO ingested. Prompt user 59 68 if not self.correctDvo: 60 69 print "*******************************************************************************" 61 self.logger.warning("Wrong or no DVO in use. Do you want to reset and use '" + self. config.dvoLocation + "'?")70 self.logger.warning("Wrong or no DVO in use. Do you want to reset and use '" + self.skychunk.dvoLocation + "'?") 62 71 response = raw_input("(y/n) ") 63 72 if response == "y": … … 101 110 102 111 # check if we have up-to-date version 103 path = self. config.dvoLocation + "/Photcodes.dat"112 path = self.skychunk.dvoLocation + "/Photcodes.dat" 104 113 if self.scratchDb.alreadyImportedThisDvoTable(path): 105 114 self.logger.debugPair("DVO Photcodes.dat file", "up-to-date") … … 126 135 127 136 # check if we have up-to-date version 128 path = self. config.dvoLocation + "/Images.dat"137 path = self.skychunk.dvoLocation + "/Images.dat" 129 138 if self.scratchDb.alreadyImportedThisDvoTable(path): 130 139 self.logger.debugPair("DVO Images.dat file", "up-to-date") … … 151 160 if not self.correctDvo: return False 152 161 153 path = self. config.dvoLocation + "/SkyTable.fits"162 path = self.skychunk.dvoLocation + "/SkyTable.fits" 154 163 if self.scratchDb.alreadyImportedThisDvoTable(path): 155 164 self.logger.debugPair("DVO SkyTable.fits file", "up-to-date") … … 158 167 self.logger.infoSeparator() 159 168 self.logger.infoPair("DVO SkyTable.fits file", "NOT up-to-date") 160 self.importFits( 169 170 if self.useStilts: 171 self.importFits( 161 172 path, 162 173 "R_MIN R_MAX D_MIN D_MAX INDEX NAME", 163 174 self.scratchDb.dvoSkyTable) 175 else: 176 177 # create dvoSkyTable 178 sql = "drop TABLE dvoSkyTable" 179 try: 180 self.scratchDb.execute(sql) 181 except: pass 182 183 # create dvoSkyTable 184 sql = "CREATE TABLE dvoSkyTable (R_MIN REAL, R_MAX REAL, D_MIN REAL, D_MAX REAL, INDEX_ INT, NAME CHAR(18))" 185 self.scratchDb.execute(sql) 186 187 # TODO path to DVO prog hardcoded temporarily 188 cmd = "dvopsps skytable" 189 cmd += " -dbhost " + self.scratchDb.dbHost 190 cmd += " -dbname " + self.scratchDb.dbName 191 cmd += " -dbuser " + self.scratchDb.dbUser 192 cmd += " -dbpass " + self.scratchDb.dbPass 193 cmd += " -D CATDIR " + self.skychunk.dvoLocation 194 195 self.logger.infoPair("Running dvopsps", cmd) 196 p = Popen(cmd, shell=True, stdout=PIPE) 197 p.wait() 164 198 165 199 self.logger.infoPair("Adding index to", self.scratchDb.dvoSkyTable) … … 168 202 169 203 self.scratchDb.setImportedThisDvoTable(path) 170 self.logger.infoPair("Finished importing SkyTable at", self. config.dvoLocation)204 self.logger.infoPair("Finished importing SkyTable at", self.skychunk.dvoLocation) 171 205 172 206 return True … … 231 265 paths = [] 232 266 for fileType in self.ingestFileTypes: 233 paths.append(self. config.dvoLocation + "/" + regionPath + "." + fileType)267 paths.append(self.skychunk.dvoLocation + "/" + regionPath + "." + fileType) 234 268 235 269 # check for the existence of all interested file types … … 304 338 # go no further if we've already partly ingested a different DVO 305 339 if not self.correctDvo: 306 self.logger.infoPair("Wrong DVO in use", self. config.dvoLocation)340 self.logger.infoPair("Wrong DVO in use", self.skychunk.dvoLocation) 307 341 return 308 342 … … 387 421 size = 0.0 388 422 for region in regions: 389 423 self.logger.infoPair("sizes for region", region) 390 424 # get combined size of all interested files 391 425 for fileType in self.ingestFileTypes: 392 size = size + self.getDiskSize(self.config.dvoLocation + "/" + region + "." + fileType) 426 size = size + self.getDiskSize(self.skychunk.dvoLocation + "/" + region + "." + fileType) 427 # EAM TEST I/O 428 self.logger.infoPair(fileType, size) 393 429 394 430 return size … … 519 555 try: 520 556 if attempts > 0: self.logger.infoPair("Attempt %d to write" % attempts, table.name) 521 table.cmd_keepcols("CODE NAME TYPE_AS_INT ").write(self.scratchDb.url + '#' + tableName)557 table.cmd_keepcols("CODE NAME TYPE_AS_INT C_LAM K").write(self.scratchDb.url + '#' + tableName) 522 558 break 523 559 except: … … 532 568 return tableName 533 569 570 571 ''' 572 ingest skyregion into MySQL database using the native DVO program dvopsps 573 Populates dvoDetections and dvoDone with FITS tables from DVO for the defined sky area, this 574 includes purging detections outside sky area 575 ''' 576 def nativeIngestDetections(self, boxId, raCenter, decCenter, boxSize): 577 578 # XXX put the chunk below in a separate method 579 # blow away existing dvoDetection table 580 581 # clear the 'ingested' field for all boxes 582 self.ippToPspsDb.clearIngestedBoxes() 583 584 # drop detections table 585 self.logger.infoPair("Dropping table", self.scratchDb.dvoDetectionTable) 586 self.scratchDb.dropTable(self.scratchDb.dvoDetectionTable) 587 588 # create detections table 589 self.logger.infoPair("Creating table", self.scratchDb.dvoDetectionTable) 590 sql = "CREATE TABLE " + self.scratchDb.dvoDetectionTable + " LIKE dvoDetection" 591 try: self.scratchDb.execute(sql) 592 except: 593 self.logger.errorPair("Unable to create table", self.scratchDb.dvoDetectionTable) 594 return False 595 self.scratchDb.changeEngineToInnoDB(self.scratchDb.dvoDetectionTable) 596 597 # add fileID column 598 sql = "ALTER TABLE " + self.scratchDb.dvoDetectionTable + " ADD fileID INT NOT NULL" 599 try: self.scratchDb.execute(sql) 600 except: 601 self.logger.errorPair("Unable to add fileID column to ", self.scratchDb.dvoDetectionTable) 602 return False 603 604 # add an index to the fileID column 605 self.scratchDb.createIndex(self.scratchDb.dvoDetectionTable, "fileID") 606 607 # make sure we have an up-to-date Images table 608 self.loadImages() 609 610 # dvopsps -D catdir CATDIR -region .... -dbhost xx -dbname xx -dbuser xx -dbpass xx 611 halfSize = boxSize / 2.0 612 # -region raCenter-halfSize raCenter+halfSize decCenter-halfSize decCenter+halfSize 613 614 # TODO path to DVO prog hardcoded temporarily 615 cmd = "dvopsps detections" 616 cmd += " -dbhost " + self.scratchDb.dbHost 617 cmd += " -dbname " + self.scratchDb.dbName 618 cmd += " -dbuser " + self.scratchDb.dbUser 619 cmd += " -dbpass " + self.scratchDb.dbPass 620 cmd += " -D CATDIR " + self.skychunk.dvoLocation 621 cmd += " -region " 622 cmd += " " + str(raCenter-halfSize) 623 cmd += " " + str(raCenter+halfSize) 624 cmd += " " + str(decCenter-halfSize) 625 cmd += " " + str(decCenter+halfSize) 626 627 if self.skychunk.parallel: 628 cmd += " -parallel" 629 630 self.logger.infoPair("Running dvopsps", cmd) 631 p = Popen(cmd, shell=True, stdout=PIPE) 632 p.wait() 633 634 self.ippToPspsDb.setIngestedBox(boxId) 635 636 # add fileID column 637 sql = "ANALYZE TABLE " + self.scratchDb.dvoDetectionTable 638 try: self.scratchDb.execute(sql) 639 except: 640 self.logger.errorPair("Unable to analyze mysql table", self.scratchDb.dvoDetectionTable) 641 return False 642 643 # update lists after attempted sync 644 # self.printSummary() 645 646 return True
Note:
See TracChangeset
for help on using the changeset viewer.
