IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 11, 2015, 1:31:50 PM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/ippToPsps/jython/stackbatch.py

    r37246 r37801  
    7373       # we just need one valid filter to get the generic metadata
    7474       validFilter = 'none'
    75 
     75       validFilterCount = 0
    7676       # get a list of stackIDs, identify the CMFs, read the headers:
    7777       for filter in self.filters:
     
    8181           stackID = gpc1Db.getStackIDFromSkyIDAndFilter(skychunk.dvoLabel, skyID, filterName)
    8282           self.stackIDs[filter] = stackID
    83 
     83           if (stackID > 0):
     84               validFilterCount=validFilterCount + 1
    8485           if (stackID <= 0):
    8586               continue
     
    115116           self.logger.errorPair("can't find any valid stacks...?? ","??")
    116117           raise
     118       # did we find any valid stacks?
     119       if validFilterCount == 0:
     120           self.logger.errorPair("can't find any valid stacks...?? ","??")
     121           raise
     122       else:
     123           self.logger.infoPair("number of filters found:",validFilterCount)
    117124   
    118125       validStackID = self.stackIDs[validFilter]
     
    154161
    155162       self.dropTableVerbose("StackObjectThin")
    156        self.dropTableVerbose("StackObjectRaw")
     163       self.dropTableVerbose("StackObjectAttributes")
    157164       
    158165       self.dropTableVerbose("StackModelFitExtra")
     
    162169
    163170       self.dropTableVerbose("StackApFlx")
    164        self.dropTableVerbose("StackApFlxFull")
    165        self.dropTableVerbose("StackApFlxFullC1")
    166        self.dropTableVerbose("StackApFlxFullC2")
     171       self.dropTableVerbose("StackApFlxEGUnc")
     172       self.dropTableVerbose("StackApFlxEGCon6")
     173       self.dropTableVerbose("StackApFlxEGCon8")
    167174
    168175       self.dropTableVerbose("StackPetrosian")
     
    284291        self.selectDvoObjIDs()
    285292
     293        self.generateRandomIDs()
     294
     295        self.generateStackDetectRowIDsAndPspsUniqueIDs()
     296
    286297        # add indexes StackObjectThin
    287298        self.scratchDb.createIndex("StackObjectThin", "objID")
     
    325336            sqlLine.group("a."+filter+"ApMag",         "b.Map")
    326337            sqlLine.group("a."+filter+"ApMagErr",      "b.dMap")
    327             sqlLine.group("a."+filter+"telluricExt",   "b.telluricExt")
     338          #  sqlLine.group("a."+filter+"telluricExt",   "b.telluricExt")
    328339
    329340            sqlLine.group("a."+filter+"infoFlag2",     "(b.flags << 13)")
     
    365376
    366377    '''
    367     Populates the StackObjectRaw table
    368     '''
    369     def populateStackObjectRaw(self):
    370 
    371         tablename = "StackObjectRaw"
     378    Populates the StackObjectAttributes table
     379    '''
     380    def populateStackObjectAttributes(self):
     381
     382        tablename = "StackObjectAttributes"
    372383
    373384        self.logger.infoPair("Procesing table", tablename)
    374385        self.insertDvoIDs(tablename, "StackObjectThin")
    375 
     386       
    376387        # if we are going to add a key, do it here so it is useful
    377388        self.scratchDb.createIndex(tablename, "objID")
     
    420431            sqlLine.group("a."+filter+"KronFluxErr",   "b.KRON_FLUX_ERR / " + str(exptime))
    421432            sqlLine.group("a."+filter+"ApFillFac",     "b.AP_NPIX / (3.14159265359 * POW(b.AP_MAG_RADIUS - 0.5, 2))")
    422             sqlLine.group("a."+filter+"ApRadius",      "b.AP_MAG_RADIUS")
     433#            sqlLine.group("a."+filter+"ApRadius",      "b.AP_MAG_RADIUS")
    423434            sqlLine.group("a."+filter+"KronRad",       "b.MOMENTS_R1 * 2.5")
    424435            sqlLine.group("a."+filter+"PlateScale",    "b.PLTSCALE")
     
    430441            except:
    431442                self.logger.errorPair('failed sql',sql)
    432                 return
     443                raise
    433444
    434445            # insert detection information for each filter based on the DVO contents
     
    446457            except:
    447458                self.logger.errorPair('failed sql',sql)
    448                 return
     459                raise
    449460
    450461
     
    549560        # insert detection information for each filter based on the
    550561        # DVO contents.  Since I already have extracted
    551         # StackObjectRaw, this is probably faster using that table:
     562        # StackObjectAttributes, this is probably faster using that table:
    552563        sqlLine = sqlUtility("UPDATE " + tablename + " AS a, " + self.scratchDb.dvoDetectionTable + " as b SET")
    553564        sqlLine.group("a." + filter + model + "Mag",       "a." + filter + model + "Mag + b.zp")
    554         sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID")
    555 
     565        sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID" + " AND b.imageID = " + str(self.imageIDs[filter]))
    556566        try:
    557567            self.scratchDb.execute(sql)
    558568        except:
    559569            self.logger.errorPair('failed sql',sql)
    560             return
    561 
     570            raise
    562571        # we have (modulo signs):
    563572        # gRaExp  = gra  + (X_EXT - gxPos)*gPlateScale / cos(gdec)
     
    583592
    584593        # insert detection information for each filter based on the DVO contents
    585         sqlLine = sqlUtility("UPDATE " + tablename + " AS a, StackObjectThin as b, StackObjectRaw as c SET ")
     594        sqlLine = sqlUtility("UPDATE " + tablename + " AS a, StackObjectThin as b, StackObjectAttributes as c SET ")
    586595        sqlLine.group(extR, rawR + " - (" + extR + " - " + rawX + ")*" + rawS + " / 3600.0 / cos(radians(" + rawD + "))")
    587596        sqlLine.group(extD, rawD + " + (" + extD + " - " + rawY + ")*" + rawS + " / 3600.0")
     
    596605        except:
    597606            self.logger.errorPair('failed sql',sql)
    598             return
     607            raise
    599608
    600609    '''
     
    655664        sqlLine.group("a." + filter + "petCf",        "b.PETRO_FILL")
    656665
    657         sql = sqlLine.makeEquals("WHERE a." + filter + "ippDetectID = b.IPP_IDET")
     666        sql = sqlLine.makeEquals("WHERE a." + filter + "ippDetectID = b.IPP_IDET ")
    658667
    659668        try: self.scratchDb.execute(sql)
     
    670679        except:
    671680            self.logger.errorPair('failed sql',sql)
    672             return
     681            raise
    673682
    674683    '''
     
    690699
    691700        for filter in self.filters:
    692             self.populateStackApFlxFilter(tablename, "", filter)
    693             self.populateStackApFlxFilter(tablename, "C1", filter)
    694             self.populateStackApFlxFilter(tablename, "C2", filter)
     701            self.populateStackApFlxFilter(tablename, "Unc", filter)
     702            self.populateStackApFlxFilter(tablename, "Con6", filter)
     703            self.populateStackApFlxFilter(tablename, "Con8", filter)
    695704
    696705        self.deleteRowsWithNoStackData(tablename)
     
    698707
    699708    '''
    700     Populates the StackApFlxFull table
    701     '''
    702     def populateStackApFlxFull(self, version):
    703 
    704         tablename = "StackApFlxFull" + version
     709    Populates the StackApFlxEG table
     710    '''
     711    def populateStackApFlxEG(self, version):
     712
     713        tablename = "StackApFlxEG" + version
    705714
    706715        if self.config.camera == "simtest":
     
    721730
    722731    '''
    723     Updates aperture fluxes for StackApFkx table
     732    Updates aperture fluxes for StackApFlx table
    724733    '''
    725734    def populateStackApFlxFilter(self, tablename, version, filter):
     
    728737
    729738        # order of the 3 convolutions is fixed (raw, C1, C2) = (1, 2, 3)
    730         if version == "":   
     739        if version == "Unc":   
    731740            psfCondition = "(b.table_index % 3 = 1)"
    732741            prefix = ""
    733         if version == "C1":
     742        if version == "Con6":
    734743            psfCondition = "(b.table_index % 3 = 2)"
    735             prefix = "c1"
    736         if version == "C2":
     744            prefix = "c6"
     745        if version == "Con8":
    737746            psfCondition = "(b.table_index % 3 = 0)"
    738             prefix = "c2"
     747            prefix = "c8"
    739748
    740749        if prefix == "none":
     
    769778        except:
    770779            self.logger.errorPair('failed sql',sql)
    771             return
     780            raise
    772781
    773782        # set the flux values from the cmf file
     
    833842            sqlLine.group(field + "Err",       field + "err" + " * POW(10, 3.56 - 0.4* b.zp)")
    834843            sqlLine.group(field + "Std",       field + "Std" + " * POW(10, 3.56 - 0.4* b.zp)")
    835         sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID")
     844        sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID AND b.imageID = " + str(self.imageIDs[filter]) )
    836845        self.scratchDb.execute(sql)
    837846
     
    931940
    932941        return True
     942
     943    def generateRandomIDs(self):
     944        sql = "UPDATE StackObjectThin set randomStackObjID = FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)"
     945        try: self.scratchDb.execute(sql)
     946        except:
     947            self.logger.errorPair('failed sql',sql)
     948            raise
     949
     950
     951    def generateStackDetectRowIDsAndPspsUniqueIDs(self):
     952        sql = "UPDATE StackObjectThin join (select @r:=@r+1 rownum, objID from \
     953        (select @r:=0) r, StackObjectThin t) as foo using (objID) set \
     954        stackDetectRowID = ((" + str(self.batchID) + " << 32 ) + rownum), \
     955        uniquePspsSTid = ((" +str(self.batchID)+ "*1000000000 ) + rownum)";
     956        try: self.scratchDb.execute(sql)
     957        except:
     958            self.logger.errorPair('failed sql',sql)
     959            raise
     960       
    933961
    934962    '''
     
    951979        sqlLine.group("skyCellID",        "'" + str(self.skycellID) + "'")
    952980        sqlLine.group("dataRelease",      "'" + str(self.skychunk.dataRelease) + "'")
    953         sqlLine.group("randomStackObjID", "FLOOR(RAND()*9223372036854775807)")
     981   #     sqlLine.group("randomStackObjID", "FLOOR(RAND()*9223372036854775807)")
    954982
    955983        whereClause = " WHERE ("
     
    971999        except:
    9721000            self.logger.errorPair('failed sql',sql)
    973             return
     1001            raise
    9741002
    9751003    '''
     
    9821010            self.scratchDb.addColumn(table, filter + "haveData", "tinyint")
    9831011
    984         fields = "objID, ippObjID, randomStackObjID, primaryDetection, bestDetection, "
     1012        fields = "objID, ippObjID, randomStackObjID, primaryDetection, bestDetection, uniquePspsSTID, "
    9851013
    9861014        for i in range(len(self.filters)):
     
    9881016            fields += filter + "ippDetectID, "
    9891017            fields += filter + "stackDetectID, "
    990             fields += filter + "stackMetaID" # careful here: do not add comma to last entry
     1018            fields += filter + "stackMetaID " # careful here: do not add comma to last entry
    9911019            if (i < len(self.filters) - 1):
    9921020                fields += ", "
    993        
     1021
     1022        if (table == "StackObjectAttributes"):
     1023            fields += ", stackDetectRowID "
    9941024        sql  = "INSERT INTO " + table + " (" + fields + ") "
    9951025        sql += "SELECT " + fields + " FROM " + mainTable
     
    9981028        except:
    9991029            self.logger.errorPair('failed sql',sql)
    1000             return
    1001    
     1030            raise
     1031
     1032
     1033       
    10021034    '''
    10031035    Does the processing, i.e. pulling stuff from IPP tables into PSPS tables
     
    10361068        self.populateStackObjectThin()
    10371069
    1038         self.populateStackObjectRaw()
     1070        self.populateStackObjectAttributes()
    10391071
    10401072        if self.stackType != "NIGHTLY_STACK":
     
    10531085            self.populateStackApFlx()
    10541086
    1055             self.populateStackApFlxFull("")
    1056             self.populateStackApFlxFull("C1")
    1057             self.populateStackApFlxFull("C2")
     1087            self.populateStackApFlxEG("Unc")
     1088            self.populateStackApFlxEG("Con6")
     1089            self.populateStackApFlxEG("Con8")
    10581090
    10591091        # delete rows with no content. for the other tables, this is done in
     
    11301162        self.logger.infoPair("Done. Imported", "%d tables" % count)
    11311163        self.indexIppTables()
    1132                      
     1164#        return False
    11331165        return True
Note: See TracChangeset for help on using the changeset viewer.