IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31403


Ignore:
Timestamp:
Apr 28, 2011, 3:55:01 PM (15 years ago)
Author:
rhenders
Message:

skipping missing smf files; can now use either full dvo tables, or on-the-fly ones; screening out objID duplicates using a UNIQUE column and UPDATE IGNORE

File:
1 edited

Legend:

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

    r31389 r31403  
    11#!/usr/bin/env jython
    22
     3import os.path
     4import sys
    35import stilts
    46from java.lang import *
     
    1719    Constructor
    1820    '''
    19     def __init__(self, logger, camID, inputFile, test=False):
     21    def __init__(self, logger, camID, inputFile, test=False, useFullTables=False):
    2022       super(DetectionBatch, self).__init__(
    2123               logger,
    2224               "detection",
    2325               inputFile,
    24                "MD04") # TODO
     26               "MD04",
     27               useFullTables) # TODO
    2528               #"3PI") # TODO
    2629
     
    177180
    178181        tableName = "ImageMeta_" + ota
    179         self.logger.info("   Dealing with table " + tableName)
    180182       
    181183        # drop then re-create table
     
    321323
    322324        tableName = "Detection_" + ota
    323         self.logger.info("   Dealing with table " + tableName)
    324325       
    325326        # drop then re-create table
     
    396397
    397398        tableName = "SkinnyObject_" + ota
    398         self.logger.info("   Dealing with table " + tableName)
    399399       
    400400        # drop then re-create table
     
    425425
    426426        tableName = "ObjectCalColor_" + ota
    427         self.logger.info("   Dealing with table " + tableName)
    428427       
    429428        # drop then re-create table
     
    451450
    452451    '''
    453     Applies indexes to the PSPS tables TODO need this?
    454     '''
    455     def indexPspsTables(self):
    456 
     452    Applies indexes and other constraints to the PSPS tables
     453    '''
     454    def alterPspsTables(self):
     455
     456        self.logger.info("Altering PSPS tables")
    457457        self.logger.info("Creating indexes on PSPS tables")
    458 #        self.createIndex("StackDetection", "ippDetectID")
    459  #       self.createIndex("StackApFlx", "ippDetectID")
    460   #      self.createIndex("StackModelFit", "ippDetectID")
     458        self.scratchDb.makeColumnUnique("Detection", "objID")
     459        self.scratchDb.createIndex("Detection", "ippDetectID")
    461460
    462461    '''
     
    482481    Updates provided table with DVO IDs from DVO table
    483482    '''
    484     def updateDvoIDs(self, table, sourceID, imageID):
    485 
    486         self.logger.info("Updating table '" + table + "' with DVO IDs...")
    487         sql = "UPDATE " + table + " AS a, dvoDetection AS b SET \
     483    def updateDvoIDs(self, table, sourceID, externID):
     484
     485        imageID = self.scratchDb.getImageIDFromExternID(sourceID, externID)
     486        self.logger.info("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID)
     487        sql = "UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetection + " AS b SET \
    488488               a.ippObjID = b.ippObjID, \
    489489               a.detectID = b.detectID, \
     
    495495
    496496        self.scratchDb.stmt.execute(sql)
    497         self.logger.info("...done")
    498497
    499498
     
    527526
    528527                # store sourceID/imageID combo in Db so DVO can look up later
    529                 self.scratchDb.insertNewDvoImage(header['SOURCEID'], header['IMAGEID'])
     528                if not self.useFullTables:
     529                    self.scratchDb.insertNewDvoImage(header['SOURCEID'], header['IMAGEID'])
    530530
    531531                # store these for later
     
    538538             
    539539        # now run DVO code to get all IDs
    540         self.getIDsFromDVO()
     540        if not self.useFullTables: self.getIDsFromDVO()
    541541
    542542        # loop through all OTAs again to update with DVO IDs
     
    555555
    556556                ota = "XY%d%d" % (x, y)
     557                self.logger.info("******************* Dealing with OTA " + ota + " *******************")
    557558
    558559                # populate remainder of tables
     
    561562                # now add DVO IDs
    562563                self.updateDvoIDs("Detection_" + ota, sourceIDs[ota], imageIDs[ota])
    563 
    564564                self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + ota, "objID")
    565565                self.updateImageID("Detection_" + ota, x, y)
     
    571571
    572572                # update ImageMeta with count of detections for this OTA and photoCodeID
    573                 sql = "UPDATE ImageMeta_" + ota + " SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(header['SOURCEID'], header['IMAGEID']))
     573                sql = "UPDATE ImageMeta_" + ota + " SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(sourceIDs[ota], imageIDs[ota]))
    574574                self.scratchDb.stmt.execute(sql)
    575575
     
    633633gpc1Db = Gpc1Db(logger)
    634634camIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.V2", "cam")
    635 #camIDs = gpc1Db.getIDsInThisDVODbForThisStage("ThreePi.V1", "cam")
    636635
    637636logger.info("Found %d exposures" % len(camIDs))
     
    640639for camID in camIDs:
    641640
     641    logger.info("-------------------------------------------------- cam ID: %d" % camID)
     642
    642643    file = gpc1Db.getCameraStageSmf(camID)
    643     detectionBatch = DetectionBatch(logger, camID, file, False)
    644 
    645     if detectionBatch.alreadyProcessed():
     644    if not os.path.isfile(file):
     645        logger.error("Cannot read file at '" + file)
     646        continue
     647
     648    detectionBatch = DetectionBatch(logger, camID, file, False, True)
     649
     650    if not detectionBatch.alreadyProcessed():
    646651
    647652        detectionBatch.createEmptyPspsTables()
    648         #detectionBatch.importIppTables(".*.psf")
     653        detectionBatch.importIppTables(".*.psf")
    649654        if detectionBatch.populatePspsTables():
    650655            detectionBatch.exportPspsTablesToFits("([a-zA-Z]+)")
    651656            detectionBatch.writeBatchManifest()
    652             detectionBatch.reportNullsInAllPspsTables(False)
    653             detectionBatch.createTarball()
    654             detectionBatch.publishToDatastore()
     657            #detectionBatch.reportNullsInAllPspsTables(False)
     658            #detectionBatch.createTarball()
     659            #detectionBatch.publishToDatastore()
    655660   
    656     i = i+1
    657     if i > 0: break
    658 
     661            i = i+1
     662           # if i > 0: sys.exit()
     663
Note: See TracChangeset for help on using the changeset viewer.