IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 8, 2011, 3:01:58 PM (15 years ago)
Author:
rhenders
Message:

removed old start-up code; removed redundant alreadyProcessed() method; using new loggin method; fixed issue where NULLs could not be cast to strings in embedded SQL; now getting camera metadata in constructor

File:
1 edited

Legend:

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

    r31821 r31848  
    33import os.path
    44import sys
     5import time
    56import stilts
    67from java.lang import *
     
    3233                 gpc1Db,
    3334                 ippToPspsDb,
    34                  camID,
    35                  inputFile):
     35                 camID):
    3636
    3737       super(DetectionBatch, self).__init__(
     
    4242               camID,
    4343               "detection",
    44                inputFile,
     44               gpc1Db.getCameraStageSmf(camID),
    4545               #"MD04") # TODO
    4646               "3PI")
    4747
    4848       if not self.everythingOK: return
     49
     50       # get camera meta data
     51       meta = self.gpc1Db.getCameraStageMeta(self.id)
     52       self.expID = meta[0];
     53       self.expName = meta[1];
     54       self.distGroup = meta[2];
     55       self.analysisVer = meta[3];
     56       self.bias = meta[4];
     57       self.biasScat = meta[5];
     58
     59       if not self.analysisVer: self.analysisVer = -999
    4960
    5061       # create an output filename, which is {expID}.FITS
     
    89100        super(DetectionBatch, self).printMe()
    90101
    91         self.logger.info("Cam ID:                 %d" % self.id)
    92         self.logger.info("Exp ID:                 %d" % self.expID)
    93         self.logger.info("Exp name:               %s" % self.expName)
    94         self.logger.info("Distribution group:     %s" % self.distGroup)
    95 
    96 
     102        self.logger.infoPair("Cam ID", "%d" % self.id)
     103        self.logger.infoPair("Exp ID", "%d" % self.expID)
     104        self.logger.infoPair("Exp name", "%s" % self.expName)
     105        self.logger.infoPair("Distribution group", "%s" % self.distGroup)
    97106
    98107    '''
     
    100109    '''
    101110    def populateFrameMeta(self):
    102         self.logger.info("Procesing FrameMeta table")
     111        self.logger.infoPair("Proccesing table", "FrameMeta")
    103112
    104113        sql = "INSERT INTO FrameMeta (\
     
    287296               ," + self.safeDictionaryAccess(header, 'CNAXIS1') + " \
    288297               ," + self.safeDictionaryAccess(header, 'CNAXIS2') + " \
    289                ," + str((float(self.safeDictionaryAccess(header, 'FWHM_MAJ')) + float(self.safeDictionaryAccess(header, 'FWHM_MIN')))/2.0) + " \
     298               , ( " + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " + " + self.safeDictionaryAccess(header, 'FWHM_MIN') + " ) / 2.0 \
    290299               ," + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " \
    291300               ," + self.safeDictionaryAccess(header, 'FWHM_MIN') + " \
    292301               ," + self.safeDictionaryAccess(header, 'ANGLE') + " \
    293                ," + str((float(self.safeDictionaryAccess(header, 'IQ_FW1')) + float(self.safeDictionaryAccess(header, 'IQ_FW2')))/2.0) + " \
     302               , ( " + self.safeDictionaryAccess(header, 'IQ_FW1') + " + " + self.safeDictionaryAccess(header, 'IQ_FW2') + " ) / 2.0 \
    294303               ," + self.safeDictionaryAccess(header, 'IQ_FW1') + " \
    295304               ," + self.safeDictionaryAccess(header, 'IQ_FW2') + " \
     
    336345               )"
    337346
    338         self.scratchDb.execute(sql)
     347        try: self.scratchDb.execute(sql)
     348        except: print sql
     349
    339350        self.scratchDb.updateFilterID(tableName, self.filter)
    340351        self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
     
    357368
    358369        # insert all detections into table
    359         sql = "INSERT INTO " + tableName + " ( \
     370        sql = "INSERT IGNORE INTO " + tableName + " ( \
    360371               ippDetectID \
    361372               ,xPos \
     
    483494    def alterPspsTables(self):
    484495
    485         self.logger.info("Altering PSPS tables")
    486         self.logger.info("Creating indexes on PSPS tables")
     496        self.logger.debug("Altering PSPS tables")
     497        self.logger.debug("Creating indexes on PSPS tables")
    487498        self.scratchDb.makeColumnUnique("Detection", "objID")
    488499        self.scratchDb.makeColumnPrimaryKey("Detection", "ippDetectID")
     
    493504    def indexIppTables(self):
    494505
    495         self.logger.info("Creating indexes on IPP tables")
     506        self.logger.infoPair("Creating indexes on", "IPP tables")
    496507
    497508        for x in range(self.startX, self.endX):
     
    567578        imageIDs = {}
    568579
    569         file = open(self.inputFitsPath, 'r')
    570 
    571580        # loop through all OTAs and populate ImageMeta extensions
    572         self.logger.info("Reading all fits headers and populating ImageMeta tables")
     581        self.logger.infoPair("Reading", "FITS headers")
     582        self.logger.infoPair("Populating table", "ImageMeta")
    573583        for x in range(self.startX, self.endX):
    574584            for y in range(self.startY, self.endY):
     
    583593               
    584594                # load corresponding header into memory
    585                 header = self.findAndReadFITSHeader(ota + ".hdr", file)
     595                header = self.fits.findAndReadHeader(ota + ".hdr")
    586596                if not header:
    587597                    self.logger.error("No header found for OTA " + ota)
    588598                    continue
    589 
    590599
    591600                # store sourceID/imageID combo in Db so DVO can look up later
     
    626635                if ota not in sourceIDs: continue
    627636
    628                 self.logger.info("******************* Dealing with OTA " + ota + " *******************")
     637                self.logger.infoMiniSeparator()
    629638
    630639                # populate remainder of tables
     
    639648                # check we have something in this Detection table
    640649                if self.scratchDb.getRowCount("Detection_" + ota) < 1:
    641                     self.logger.info("Empty tables for ota " + ota + ". Skipping.")
     650                    self.logger.infoPair("Skipping empty table for ota", ota)
    642651                    continue;
    643652
     
    682691
    683692    '''
    684     Checks whether this batch has already been processed and published
    685     '''
    686     def alreadyProcessed(self):
    687 
    688         meta = self.gpc1Db.getCameraStageMeta(self.id)
    689         self.expID = meta[0];
    690         self.expName = meta[1];
    691         self.distGroup = meta[2];
    692         self.analysisVer = meta[3];
    693         self.bias = meta[4];
    694         self.biasScat = meta[5];
    695 
    696         if not self.analysisVer: self.analysisVer = -999
    697 
    698         #return self.ippToPspsDb.alreadyProcessed("detection", "exp_id", self.expID)
    699         return 0
    700 
    701 
    702     '''
    703693    Overriding this method
    704694    '''
     
    728718       return super(DetectionBatch, self).exportPspsTablesToFits("([a-zA-Z]+)")
    729719
    730 
    731 logging.config.fileConfig("logging.conf")
    732 logger = logging.getLogger("ippToPspsLog")
    733 logger.setLevel(logging.INFO)
    734 logger.info("Starting")
    735 
    736 configDoc = ElementTree(file="config.xml")
    737 dvoGpc1Label = configDoc.find("dvo/gpc1Label").text
    738 
    739 gpc1Db = Gpc1Db(logger)
    740 ippToPspsDb = IppToPspsDb(logger)
    741 
    742 ids = gpc1Db.getIDsInThisDVODbForThisStage(dvoGpc1Label, "cam")
    743 for id in ids:
    744 
    745     if not int(configDoc.find("options/force").text) and ippToPspsDb.alreadyProcessed(id): continue
    746 
    747     file = gpc1Db.getCameraStageSmf(id)
    748 
    749     detectionBatch = DetectionBatch(logger,
    750                                     configDoc,
    751                                     gpc1Db,
    752                                     ippToPspsDb,
    753                                     id,
    754                                     file)
    755     detectionBatch.printMe()
    756     detectionBatch.run()
    757 
Note: See TracChangeset for help on using the changeset viewer.