IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31402


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

skipping missing cmf files; hardcoded stuff to access nightly or deep stacks for MD04; code to swicth between 'full' dvo tables, or on-the-fly; adding uniquness to objID tabkle due to duplicates coming out of IPP; getting meta data from GPC1 rather than cmf headers as formats are inconststent

File:
1 edited

Legend:

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

    r31356 r31402  
    11#!/usr/bin/env jython
     2
     3import os.path
     4import sys
    25
    36import stilts
     
    1720    Constructor
    1821    '''
    19     def __init__(self, logger, skyID, inputFile):
     22    def __init__(self, logger, skyID, inputFile, stackType, useFullTables=False):
    2023       super(StackBatch, self).__init__(
    2124               logger,
    2225               "stack",
    2326               inputFile,
    24                "MD04") # TODO
     27               "MD04",
     28               useFullTables) # TODO
    2529
    2630       self.logger.info("StackBatch constructor. Creating batch from: '" + inputFile + "'")
    2731
    2832       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
    2950
    3051       # delete PSPS tables
     
    4364       #self.scratchDb.dropTable("SkyChip_xrad")
    4465
     66       self.logger.info("Stack type: " + self.safeDictionaryAccess(self.header, self.stackType))
    4567       # 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"
    5669
    5770       # create an output filename, which is {filterID}{skycellID}.FITS
     
    6477
    6578       # 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)
    6780
    6881       # 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'])
    7084
    7185    '''
     
    7488    def updateStackMetaID(self, table):
    7589
    76         sql = "UPDATE " + table + "  SET stackMetaID=" + self.header['STK_ID']
     90        sql = "UPDATE " + table + "  SET stackMetaID=" + str(self.stackID)
    7791        self.scratchDb.stmt.execute(sql)
    7892
     
    8296    def updateStackTypeID(self, table):
    8397
    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 + "'"
    8599        self.scratchDb.stmt.execute(sql)
    86100
     
    195209            "+modelLong+"Covar78=b.EXT_COVAR_06_07,  \
    196210            "+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)  \
    199213            WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
    200214
     
    214228        ,photoZero \
    215229        ,expTime \
    216         ,nP2Images \
    217230        ,psfModelID \
    218231        ,ctype1 \
     
    229242        ,pc002002 \
    230243         ) VALUES ( \
    231         " + self.header['STK_ID'] + " \
     244        " + str(self.stackID) + " \
    232245        ," + self.skycell + " \
    233246        ," + str(self.scratchDb.getPhotoCalID(self.header['SOURCEID'], self.header['IMAGEID'])) + " \
    234247        ," + self.header['FPA.ZP'] + " \
    235248        ," + self.header['EXPTIME'] + " \
    236         ," + self.header['NINPUTS'] + " \
    237         ,'" + self.header['PSFMODEL'] + "' \
     249        ,'" + self.safeDictionaryAccess(self.header, 'PSFMODEL') + "' \
    238250        ,'" + self.header['CTYPE1'] + "' \
    239251        ,'" + self.header['CTYPE2'] + "' \
     
    439451        self.logger.info("Procesing StackToImage table")
    440452
    441         imageIDs = self.gpc1Db.getImageIDsForThisStackID(self.header['STK_ID'])
     453        imageIDs = self.gpc1Db.getImageIDsForThisStackID(self.stackID)
    442454
    443455        for imageID in imageIDs:
    444456            sql = "INSERT INTO StackToImage (stackMetaID, imageID) \
    445457                   VALUES (\
    446                    " + self.header['STK_ID'] + ", " + imageID + ")"
     458                   " + str(self.stackID) + ", " + imageID + ")"
    447459            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)
    448464
    449465    '''
     
    489505    Applies indexes to the PSPS tables
    490506    '''
    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")
    494511        self.scratchDb.createIndex("StackDetection", "ippDetectID")
    495512        self.scratchDb.createIndex("StackApFlx", "ippDetectID")
     
    512529    def updateDvoIDs(self, table):
    513530
     531        imageID = self.scratchDb.getImageIDFromExternID(self.header['SOURCEID'], self.header['IMAGEID'])
     532
    514533        self.logger.info("Updating table '" + table + "' with DVO IDs...")
    515         sql = "UPDATE " + table + " AS a, dvoDetection AS b SET \
     534        sql = "UPDATE IGNORE " + table + " AS a, dvoDetectionFull AS b SET \
    516535               a.ippObjID = b.ippObjID, \
    517536               a.stackDetectID = b.detectID, \
     
    519538               WHERE a.ippDetectID = b.ippDetectID \
    520539               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)
    524542
    525543
     
    529547    def populatePspsTables(self):
    530548
    531         if not self.getIDsFromDVO(): return False
     549        if not self.useFullTables:
     550            if not self.getIDsFromDVO():
     551                return False
    532552
    533553        self.populateStackMeta()
     
    548568    def alreadyProcessed(self):
    549569
    550         return self.ippToPspsDb.alreadyProcessed("stack", "sky_id", self.skyID)
    551 
    552 
     570        return self.ippToPspsDb.alreadyProcessed("stack", "stack_id", self.stackID)
    553571
    554572logging.config.fileConfig("logging.conf")
     
    556574logger.info("Starting")
    557575gpc1Db = Gpc1Db(logger)
     576stackType = "NIGHTLY_STACK"
    558577skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.Staticsky", "staticsky")
     578#skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.GENE.PSPSDEEP", "staticsky")
     579#stackType = "DEEP_STACK"
    559580#skyIDs = [689]
    560581#skyIDs = [299]
    561 skyIDs = [306]
     582#skyIDs = [302]
     583#skyIDs = [8508]
    562584i = 0
    563585for skyID in skyIDs:
    564586
    565     logger.info(" sky ID = %d" % skyID)
     587    logger.info("-------------------------------------------------- sky ID: %d" % skyID)
    566588
    567589    cmfFiles = gpc1Db.getStackStageCmfs(skyID)
     
    569591    for file in cmfFiles:
    570592
    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():
    575600
    576601            stackBatch.createEmptyPspsTables()
     
    578603            if stackBatch.populatePspsTables():
    579604 
    580                 stackBatch.reportNullsInAllPspsTables(False)
     605                #stackBatch.reportNullsInAllPspsTables(False)
    581606                stackBatch.exportPspsTablesToFits()
    582607                stackBatch.writeBatchManifest()
     
    584609                #stackBatch.publishToDatastore()
    585610
    586         i = i + 1
    587         if i > 0: break # TODO just doing one filter for now
     611                i = i + 1
     612                #if i > 0: sys.exit()
    588613
    589614logger.info("Finished")
Note: See TracChangeset for help on using the changeset viewer.