IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 10, 2011, 9:40:49 AM (15 years ago)
Author:
rhenders
Message:

using base-class run() methid; overriden versions of importIppTables() and exportPspsTablesToFits(); reworked alreadyProcessed() method;

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/detectionbatch.py

    r31406 r31504  
    66from java.lang import *
    77from java.sql import *
     8
    89from batch import Batch
    910from gpc1db import Gpc1Db
     11from ipptopspsdb import IppToPspsDb
     12from scratchdb import ScratchDb
    1013
    1114import logging.config
     
    1922    Constructor
    2023    '''
    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
    2234       super(DetectionBatch, self).__init__(
    2335               logger,
     36               gpc1Db,
     37               ippToPspsDb,
     38               scratchDb,
     39               camID,
    2440               "detection",
    2541               inputFile,
    26                "MD04",
    27                useFullTables) # TODO
     42               "MD04", # TODO
    2843               #"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)
    3955
    4056       # create an output filename, which is {expID}.FITS
     
    167183        ," + self.header['PCA2X0Y2'] + " \
    168184        )"
    169         self.scratchDb.stmt.execute(sql)
     185        self.scratchDb.execute(sql)
    170186
    171187        self.scratchDb.updateAllRows("FrameMeta", "surveyID", str(self.surveyID))
     
    184200        self.scratchDb.dropTable(tableName)
    185201        sql = "CREATE TABLE " + tableName + " LIKE ImageMeta"
    186         try: self.scratchDb.stmt.execute(sql)
     202        try: self.scratchDb.execute(sql)
    187203        except: pass
    188204
     
    310326               )"
    311327
    312         self.scratchDb.stmt.execute(sql)
     328        self.scratchDb.execute(sql)
    313329        self.scratchDb.updateFilterID(tableName, self.filter)
    314330        self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
    315331        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'])
    317333        self.scratchDb.replaceNullsInThisColumn(tableName, "polyOrder", "0")
    318334
     
    327343        self.scratchDb.dropTable(tableName)
    328344        sql = "CREATE TABLE " + tableName + " LIKE Detection"
    329         try: self.scratchDb.stmt.execute(sql)
     345        try: self.scratchDb.execute(sql)
    330346        except: pass
    331347
     
    375391               ,EXT_NSIGMA \
    376392               FROM " + ota + "_psf"
    377 
    378         self.scratchDb.stmt.execute(sql)
     393        self.scratchDb.execute(sql)
    379394
    380395        # set obsTime
    381396        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)
    383398        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease))
    384399        self.scratchDb.updateAllRows(tableName, "historyModNum", "0")
     
    387402        self.scratchDb.updateFilterID(tableName, self.filter)
    388403
    389         # now delete bad flux
     404        # now delete bad flux and bad chip positions
    390405        self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "instFlux")
    391406        self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "peakADU")
     
    401416        self.scratchDb.dropTable(tableName)
    402417        sql = "CREATE TABLE " + tableName + " LIKE SkinnyObject"
    403         try: self.scratchDb.stmt.execute(sql)
     418        try: self.scratchDb.execute(sql)
    404419        except: pass
    405420
     
    415430               ,surveyID \
    416431               FROM Detection_" + ota
    417         self.scratchDb.stmt.execute(sql)
     432        self.scratchDb.execute(sql)
    418433
    419434        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease))
     
    429444        self.scratchDb.dropTable(tableName)
    430445        sql = "CREATE TABLE " + tableName + " LIKE ObjectCalColor"
    431         try: self.scratchDb.stmt.execute(sql)
     446        try: self.scratchDb.execute(sql)
    432447        except: pass
    433448
     
    443458               ,filterID \
    444459               FROM Detection_" + ota
    445         self.scratchDb.stmt.execute(sql)
     460        self.scratchDb.execute(sql)
    446461
    447462        self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
     
    484499
    485500        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)
    487502        sql = "UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetection + " AS b SET \
    488503               a.ippObjID = b.ippObjID, \
     
    494509               AND b.imageID = " + str(imageID)
    495510
    496         self.scratchDb.stmt.execute(sql)
     511        self.scratchDb.execute(sql)
    497512
    498513
     
    511526
    512527        # loop through all OTAs and populate ImageMeta extensions
     528        self.logger.info("Reading all fits headers and populating ImageMeta tables")
    513529        for x in range(self.startX, self.endX):
    514530            for y in range(self.startY, self.endY):
     
    524540                # load corresponding header into memory
    525541                header = self.findAndReadFITSHeader(ota + ".hdr", file)
     542                if not header:
     543                    self.logger.error("No header found for OTA " + ota)
     544                    continue
     545
    526546
    527547                # store sourceID/imageID combo in Db so DVO can look up later
     
    578598
    579599                # 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)
    582603
    583604                self.populateSkinnyObjectTable(ota)
     
    603624        # update FrameMeta with count OTAs in this file and total number of photometric reference sources
    604625        sql = "UPDATE FrameMeta SET nOTA = %d, numPhotoRef = %d" % (otaCount, self.totalNumPhotoRef)
    605         self.scratchDb.stmt.execute(sql)
     626        self.scratchDb.execute(sql)
    606627       
    607628        return True
     
    613634
    614635        sql = "UPDATE " + tableName + " SET imageID = %d%d%d" % (self.expID, x, y)
    615         self.scratchDb.stmt.execute(sql)
     636        self.scratchDb.execute(sql)
    616637
    617638    '''
     
    619640    '''
    620641    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];
    621647
    622648        return self.ippToPspsDb.alreadyProcessed("detection", "exp_id", self.expID)
     
    634660
    635661
     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
     677useFullTables=True
     678testMode=False
     679
    636680logging.config.fileConfig("logging.conf")
    637681logger = logging.getLogger("detectionbatch")
     682logger.setLevel(logging.INFO)
    638683logger.info("Starting")
    639684
    640685gpc1Db = Gpc1Db(logger)
     686ippToPspsDb = IppToPspsDb(logger)
     687scratchDb = ScratchDb(logger, useFullTables)
     688
    641689camIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.V2", "cam")
    642690logger.info("Found %d exposures" % len(camIDs))
     
    645693for camID in camIDs:
    646694
    647     logger.info("-------------------------------------------------- cam ID: %d" % camID)
     695    #if camID < 43764: continue # TODO
    648696
    649697    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.