Changeset 31402 for trunk/ippToPsps/jython/stackbatch.py
- Timestamp:
- Apr 28, 2011, 3:52:48 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/stackbatch.py (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/stackbatch.py
r31356 r31402 1 1 #!/usr/bin/env jython 2 3 import os.path 4 import sys 2 5 3 6 import stilts … … 17 20 Constructor 18 21 ''' 19 def __init__(self, logger, skyID, inputFile ):22 def __init__(self, logger, skyID, inputFile, stackType, useFullTables=False): 20 23 super(StackBatch, self).__init__( 21 24 logger, 22 25 "stack", 23 26 inputFile, 24 "MD04") # TODO 27 "MD04", 28 useFullTables) # TODO 25 29 26 30 self.logger.info("StackBatch constructor. Creating batch from: '" + inputFile + "'") 27 31 28 32 self.skyID = skyID 33 34 # get filterID using init table 35 self.filter = self.header['FPA.FILTER'] 36 self.filter = self.filter[0:1] 37 38 self.stackType = stackType 39 meta = self.gpc1Db.getStackStageMeta(self.skyID, self.header['FPA.FILTER']) 40 if len(meta) < 1: return 41 self.stackID = meta[0]; 42 self.skycell = meta[1]; 43 44 # determine skycell from header value 45 #self.skycell = "skycell.34" #= self.header['SKYCELL'] 46 self.skycell = self.skycell[8:] 47 48 self.logger.info("Processing stack with ID: %d, type: %s and skycell: %s filter: %s" % (self.stackID, self.stackType, self.skycell, self.filter)) 49 29 50 30 51 # delete PSPS tables … … 43 64 #self.scratchDb.dropTable("SkyChip_xrad") 44 65 66 self.logger.info("Stack type: " + self.safeDictionaryAccess(self.header, self.stackType)) 45 67 # obs time makes no sense except for nightly stacks 46 self.logger.info("Stack type: " + self.header['STK_TYPE']) 47 if self.header['STK_TYPE'] != "NIGHTLY_STACK": self.header['MJD-OBS'] = "-999" 48 49 # determine skycell from header value 50 self.skycell = self.header['SKYCELL'] 51 self.skycell = self.skycell[8:] 52 53 # get filterID using init table 54 self.filter = self.header['FPA.FILTER'] 55 self.filter = self.filter[0:1] 68 #if self.header['STK_TYPE'] != "NIGHTLY_STACK": self.header['MJD-OBS'] = "-999" 56 69 57 70 # create an output filename, which is {filterID}{skycellID}.FITS … … 64 77 65 78 # insert what we know about this stack batch into the stack table 66 self.ippToPspsDb.insertStackMeta(self.batchID, self.skyID, self. header['STK_ID'], self.filter, self.header['STK_TYPE'])79 self.ippToPspsDb.insertStackMeta(self.batchID, self.skyID, self.stackID, self.filter, self.stackType) 67 80 68 81 # insert sourceID/imageID combo so DVO can look it up 69 self.scratchDb.insertNewDvoImage(self.header['SOURCEID'], self.header['IMAGEID']) 82 if not self.useFullTables: 83 self.scratchDb.insertNewDvoImage(self.header['SOURCEID'], self.header['IMAGEID']) 70 84 71 85 ''' … … 74 88 def updateStackMetaID(self, table): 75 89 76 sql = "UPDATE " + table + " SET stackMetaID=" + s elf.header['STK_ID']90 sql = "UPDATE " + table + " SET stackMetaID=" + str(self.stackID) 77 91 self.scratchDb.stmt.execute(sql) 78 92 … … 82 96 def updateStackTypeID(self, table): 83 97 84 sql = "UPDATE "+table+" AS a, StackType AS b SET a.stackTypeID=b.stackTypeID WHERE b.name = '" +self.header['STK_TYPE']+"'"98 sql = "UPDATE "+table+" AS a, StackType AS b SET a.stackTypeID=b.stackTypeID WHERE b.name = '" + self.stackType + "'" 85 99 self.scratchDb.stmt.execute(sql) 86 100 … … 195 209 "+modelLong+"Covar78=b.EXT_COVAR_06_07, \ 196 210 "+modelLong+"Covar88=b.EXT_COVAR_07_07, \ 197 "+ modelLong+"serNu=b.EXT_PAR_07, \198 "+ modelLong+"serNuErr=SQRT(EXT_COVAR_07_07) \211 "+"serNu=b.EXT_PAR_07, \ 212 "+"serNuErr=SQRT(EXT_COVAR_07_07) \ 199 213 WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'" 200 214 … … 214 228 ,photoZero \ 215 229 ,expTime \ 216 ,nP2Images \217 230 ,psfModelID \ 218 231 ,ctype1 \ … … 229 242 ,pc002002 \ 230 243 ) VALUES ( \ 231 " + s elf.header['STK_ID']+ " \244 " + str(self.stackID) + " \ 232 245 ," + self.skycell + " \ 233 246 ," + str(self.scratchDb.getPhotoCalID(self.header['SOURCEID'], self.header['IMAGEID'])) + " \ 234 247 ," + self.header['FPA.ZP'] + " \ 235 248 ," + self.header['EXPTIME'] + " \ 236 ," + self.header['NINPUTS'] + " \ 237 ,'" + self.header['PSFMODEL'] + "' \ 249 ,'" + self.safeDictionaryAccess(self.header, 'PSFMODEL') + "' \ 238 250 ,'" + self.header['CTYPE1'] + "' \ 239 251 ,'" + self.header['CTYPE2'] + "' \ … … 439 451 self.logger.info("Procesing StackToImage table") 440 452 441 imageIDs = self.gpc1Db.getImageIDsForThisStackID(self. header['STK_ID'])453 imageIDs = self.gpc1Db.getImageIDsForThisStackID(self.stackID) 442 454 443 455 for imageID in imageIDs: 444 456 sql = "INSERT INTO StackToImage (stackMetaID, imageID) \ 445 457 VALUES (\ 446 " + s elf.header['STK_ID']+ ", " + imageID + ")"458 " + str(self.stackID) + ", " + imageID + ")" 447 459 self.scratchDb.stmt.execute(sql) 460 461 # now update StackMeta with correct number of inputs 462 sql = "UPDATE StackMeta SET nP2Images = (SELECT COUNT(*) FROM StackToImage)" 463 self.scratchDb.stmt.execute(sql) 448 464 449 465 ''' … … 489 505 Applies indexes to the PSPS tables 490 506 ''' 491 def indexPspsTables(self): 492 493 self.logger.info("Creating indexes on PSPS tables") 507 def alterPspsTables(self): 508 509 self.logger.info("Altering PSPS tables") 510 self.scratchDb.makeColumnUnique("StackDetection", "objID") 494 511 self.scratchDb.createIndex("StackDetection", "ippDetectID") 495 512 self.scratchDb.createIndex("StackApFlx", "ippDetectID") … … 512 529 def updateDvoIDs(self, table): 513 530 531 imageID = self.scratchDb.getImageIDFromExternID(self.header['SOURCEID'], self.header['IMAGEID']) 532 514 533 self.logger.info("Updating table '" + table + "' with DVO IDs...") 515 sql = "UPDATE " + table + " AS a, dvoDetectionAS b SET \534 sql = "UPDATE IGNORE " + table + " AS a, dvoDetectionFull AS b SET \ 516 535 a.ippObjID = b.ippObjID, \ 517 536 a.stackDetectID = b.detectID, \ … … 519 538 WHERE a.ippDetectID = b.ippDetectID \ 520 539 AND b.sourceID = " + self.header['SOURCEID'] + "\ 521 AND b.imageID = " + self.header['IMAGEID'] 522 self.scratchDb.stmt.execute(sql) 523 self.logger.info("...done") 540 AND b.imageID = " + str(imageID) 541 self.scratchDb.stmt.execute(sql) 524 542 525 543 … … 529 547 def populatePspsTables(self): 530 548 531 if not self.getIDsFromDVO(): return False 549 if not self.useFullTables: 550 if not self.getIDsFromDVO(): 551 return False 532 552 533 553 self.populateStackMeta() … … 548 568 def alreadyProcessed(self): 549 569 550 return self.ippToPspsDb.alreadyProcessed("stack", "sky_id", self.skyID) 551 552 570 return self.ippToPspsDb.alreadyProcessed("stack", "stack_id", self.stackID) 553 571 554 572 logging.config.fileConfig("logging.conf") … … 556 574 logger.info("Starting") 557 575 gpc1Db = Gpc1Db(logger) 576 stackType = "NIGHTLY_STACK" 558 577 skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.Staticsky", "staticsky") 578 #skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.GENE.PSPSDEEP", "staticsky") 579 #stackType = "DEEP_STACK" 559 580 #skyIDs = [689] 560 581 #skyIDs = [299] 561 skyIDs = [306] 582 #skyIDs = [302] 583 #skyIDs = [8508] 562 584 i = 0 563 585 for skyID in skyIDs: 564 586 565 logger.info(" sky ID =%d" % skyID)587 logger.info("-------------------------------------------------- sky ID: %d" % skyID) 566 588 567 589 cmfFiles = gpc1Db.getStackStageCmfs(skyID) … … 569 591 for file in cmfFiles: 570 592 571 logger.info("-------------- New Batch ----------") 572 stackBatch = StackBatch(logger, skyID, file) 573 574 if stackBatch.alreadyProcessed(): 593 if not os.path.isfile(file): 594 logger.error("Cannot read file at '" + file) 595 continue 596 597 stackBatch = StackBatch(logger, skyID, file, stackType, True) 598 599 if not stackBatch.alreadyProcessed(): 575 600 576 601 stackBatch.createEmptyPspsTables() … … 578 603 if stackBatch.populatePspsTables(): 579 604 580 stackBatch.reportNullsInAllPspsTables(False)605 #stackBatch.reportNullsInAllPspsTables(False) 581 606 stackBatch.exportPspsTablesToFits() 582 607 stackBatch.writeBatchManifest() … … 584 609 #stackBatch.publishToDatastore() 585 610 586 i = i + 1587 if i > 0: break # TODO just doing one filter for now611 i = i + 1 612 #if i > 0: sys.exit() 588 613 589 614 logger.info("Finished")
Note:
See TracChangeset
for help on using the changeset viewer.
