Changeset 31504 for trunk/ippToPsps/jython/detectionbatch.py
- Timestamp:
- May 10, 2011, 9:40:49 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/detectionbatch.py (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/detectionbatch.py
r31406 r31504 6 6 from java.lang import * 7 7 from java.sql import * 8 8 9 from batch import Batch 9 10 from gpc1db import Gpc1Db 11 from ipptopspsdb import IppToPspsDb 12 from scratchdb import ScratchDb 10 13 11 14 import logging.config … … 19 22 Constructor 20 23 ''' 21 def __init__(self, logger, camID, inputFile, test=False, useFullTables=False): 24 def __init__(self, 25 logger, 26 gpc1Db, 27 ippToPspsDb, 28 scratchDb, 29 camID, 30 inputFile, 31 test=False, 32 useFullTables=False): 33 22 34 super(DetectionBatch, self).__init__( 23 35 logger, 36 gpc1Db, 37 ippToPspsDb, 38 scratchDb, 39 camID, 24 40 "detection", 25 41 inputFile, 26 "MD04", 27 useFullTables) # TODO 42 "MD04", # TODO 28 43 #"3PI") # TODO 29 30 self.logger.info("DetectionBatch constructor. Creating batch from: '" + inputFile + "'") 31 32 meta = self.gpc1Db.getCameraStageMeta(camID) 33 34 self.expID = meta[0]; 35 self.expName = meta[1]; 36 self.distGroup = meta[2]; 37 38 self.logger.info("Processing exposure with ID: %d, name: %s and distribution group: %s" % (self.expID, self.expName, self.distGroup)) 44 useFullTables) 45 46 if not self.everythingOK: return 47 48 # meta data to the log 49 self.logger.info("New Detection Batch:") 50 self.logger.info("Cam ID: %d" % self.id) 51 self.logger.info("file: %s" % inputFile) 52 self.logger.info("Exp ID: %d" % self.expID) 53 self.logger.info("Exp name: %s" % self.expName) 54 self.logger.info("Distribution group: %s" % self.distGroup) 39 55 40 56 # create an output filename, which is {expID}.FITS … … 167 183 ," + self.header['PCA2X0Y2'] + " \ 168 184 )" 169 self.scratchDb. stmt.execute(sql)185 self.scratchDb.execute(sql) 170 186 171 187 self.scratchDb.updateAllRows("FrameMeta", "surveyID", str(self.surveyID)) … … 184 200 self.scratchDb.dropTable(tableName) 185 201 sql = "CREATE TABLE " + tableName + " LIKE ImageMeta" 186 try: self.scratchDb. stmt.execute(sql)202 try: self.scratchDb.execute(sql) 187 203 except: pass 188 204 … … 310 326 )" 311 327 312 self.scratchDb. stmt.execute(sql)328 self.scratchDb.execute(sql) 313 329 self.scratchDb.updateFilterID(tableName, self.filter) 314 330 self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum)) 315 331 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease)) 316 self.totalNumPhotoRef = self.totalNumPhotoRef + int(header['NASTRO'])332 if 'NASTRO' in header: self.totalNumPhotoRef = self.totalNumPhotoRef + int(header['NASTRO']) 317 333 self.scratchDb.replaceNullsInThisColumn(tableName, "polyOrder", "0") 318 334 … … 327 343 self.scratchDb.dropTable(tableName) 328 344 sql = "CREATE TABLE " + tableName + " LIKE Detection" 329 try: self.scratchDb. stmt.execute(sql)345 try: self.scratchDb.execute(sql) 330 346 except: pass 331 347 … … 375 391 ,EXT_NSIGMA \ 376 392 FROM " + ota + "_psf" 377 378 self.scratchDb.stmt.execute(sql) 393 self.scratchDb.execute(sql) 379 394 380 395 # set obsTime 381 396 sql = "UPDATE " + tableName + " SET obsTime = %f, assocDate = '%s', activeFlag = 0" % (self.obsTime, self.dateStr) 382 self.scratchDb. stmt.execute(sql)397 self.scratchDb.execute(sql) 383 398 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease)) 384 399 self.scratchDb.updateAllRows(tableName, "historyModNum", "0") … … 387 402 self.scratchDb.updateFilterID(tableName, self.filter) 388 403 389 # now delete bad flux 404 # now delete bad flux and bad chip positions 390 405 self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "instFlux") 391 406 self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "peakADU") … … 401 416 self.scratchDb.dropTable(tableName) 402 417 sql = "CREATE TABLE " + tableName + " LIKE SkinnyObject" 403 try: self.scratchDb. stmt.execute(sql)418 try: self.scratchDb.execute(sql) 404 419 except: pass 405 420 … … 415 430 ,surveyID \ 416 431 FROM Detection_" + ota 417 self.scratchDb. stmt.execute(sql)432 self.scratchDb.execute(sql) 418 433 419 434 self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease)) … … 429 444 self.scratchDb.dropTable(tableName) 430 445 sql = "CREATE TABLE " + tableName + " LIKE ObjectCalColor" 431 try: self.scratchDb. stmt.execute(sql)446 try: self.scratchDb.execute(sql) 432 447 except: pass 433 448 … … 443 458 ,filterID \ 444 459 FROM Detection_" + ota 445 self.scratchDb. stmt.execute(sql)460 self.scratchDb.execute(sql) 446 461 447 462 self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum)) … … 484 499 485 500 imageID = self.scratchDb.getImageIDFromExternID(sourceID, externID) 486 self.logger. info("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID)501 self.logger.debug("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID) 487 502 sql = "UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetection + " AS b SET \ 488 503 a.ippObjID = b.ippObjID, \ … … 494 509 AND b.imageID = " + str(imageID) 495 510 496 self.scratchDb. stmt.execute(sql)511 self.scratchDb.execute(sql) 497 512 498 513 … … 511 526 512 527 # loop through all OTAs and populate ImageMeta extensions 528 self.logger.info("Reading all fits headers and populating ImageMeta tables") 513 529 for x in range(self.startX, self.endX): 514 530 for y in range(self.startY, self.endY): … … 524 540 # load corresponding header into memory 525 541 header = self.findAndReadFITSHeader(ota + ".hdr", file) 542 if not header: 543 self.logger.error("No header found for OTA " + ota) 544 continue 545 526 546 527 547 # store sourceID/imageID combo in Db so DVO can look up later … … 578 598 579 599 # update ImageMeta with count of detections for this OTA and photoCodeID 580 sql = "UPDATE ImageMeta_" + ota + " SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(sourceIDs[ota], imageIDs[ota])) 581 self.scratchDb.stmt.execute(sql) 600 sql = "UPDATE ImageMeta_" + ota + " \ 601 SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(sourceIDs[ota], imageIDs[ota])) 602 self.scratchDb.execute(sql) 582 603 583 604 self.populateSkinnyObjectTable(ota) … … 603 624 # update FrameMeta with count OTAs in this file and total number of photometric reference sources 604 625 sql = "UPDATE FrameMeta SET nOTA = %d, numPhotoRef = %d" % (otaCount, self.totalNumPhotoRef) 605 self.scratchDb. stmt.execute(sql)626 self.scratchDb.execute(sql) 606 627 607 628 return True … … 613 634 614 635 sql = "UPDATE " + tableName + " SET imageID = %d%d%d" % (self.expID, x, y) 615 self.scratchDb. stmt.execute(sql)636 self.scratchDb.execute(sql) 616 637 617 638 ''' … … 619 640 ''' 620 641 def alreadyProcessed(self): 642 643 meta = self.gpc1Db.getCameraStageMeta(self.id) 644 self.expID = meta[0]; 645 self.expName = meta[1]; 646 self.distGroup = meta[2]; 621 647 622 648 return self.ippToPspsDb.alreadyProcessed("detection", "exp_id", self.expID) … … 634 660 635 661 662 ''' 663 Overriding this method. Filter to only import *.psf extensions 664 ''' 665 def importIppTables(self, filter=""): 666 return super(DetectionBatch, self).importIppTables(".*.psf") 667 668 669 ''' 670 Overriding this method. Use regex to trim off, eg _XY33 extension 671 ''' 672 def exportPspsTablesToFits(self, regex="(.*)"): 673 return super(DetectionBatch, self).exportPspsTablesToFits("([a-zA-Z]+)") 674 675 676 # TODO put in config 677 useFullTables=True 678 testMode=False 679 636 680 logging.config.fileConfig("logging.conf") 637 681 logger = logging.getLogger("detectionbatch") 682 logger.setLevel(logging.INFO) 638 683 logger.info("Starting") 639 684 640 685 gpc1Db = Gpc1Db(logger) 686 ippToPspsDb = IppToPspsDb(logger) 687 scratchDb = ScratchDb(logger, useFullTables) 688 641 689 camIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.V2", "cam") 642 690 logger.info("Found %d exposures" % len(camIDs)) … … 645 693 for camID in camIDs: 646 694 647 logger.info("-------------------------------------------------- cam ID: %d" % camID)695 #if camID < 43764: continue # TODO 648 696 649 697 file = gpc1Db.getCameraStageSmf(camID) 650 if not os.path.isfile(file): 651 logger.error("Cannot read file at '" + file) 652 continue 653 654 detectionBatch = DetectionBatch(logger, camID, file, False, True) 655 656 if not detectionBatch.alreadyProcessed(): 657 658 detectionBatch.createEmptyPspsTables() 659 detectionBatch.importIppTables(".*.psf") 660 if detectionBatch.populatePspsTables(): 661 detectionBatch.exportPspsTablesToFits("([a-zA-Z]+)") 662 detectionBatch.writeBatchManifest() 663 #detectionBatch.reportNullsInAllPspsTables(False) 664 #detectionBatch.createTarball() 665 #detectionBatch.publishToDatastore() 666 667 i = i+1 668 # if i > 0: sys.exit() 669 698 699 detectionBatch = DetectionBatch(logger, 700 gpc1Db, 701 ippToPspsDb, 702 scratchDb, 703 camID, 704 file, 705 testMode, 706 useFullTables) 707 detectionBatch.run() 708
Note:
See TracChangeset
for help on using the changeset viewer.
