IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36728


Ignore:
Timestamp:
May 2, 2014, 9:16:57 PM (12 years ago)
Author:
heather
Message:

StackObject is 95% done, has some nulls, and StackToImage is done

File:
1 edited

Legend:

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

    r36727 r36728  
    280280    def updateStackMetaID(self, table):
    281281
    282         sql = "UPDATE " + table + "  SET stackMetaID=" + str(self.id)
     282        sql = "UPDATE " + table + "  SET gstackMetaID=" + str(self.gstackID) + " \
     283              , rstackMetaID=" + str(self.rstackID) + " \
     284              , istackMetaID=" + str(self.istackID) + " \
     285              , zstackMetaID=" + str(self.zstackID) + " \
     286              , ystackMetaID=" + str(self.ystackID)   
     287     
    283288        self.scratchDb.execute(sql)
    284289
     
    683688
    684689             # insert all the detections
    685              sql = "INSERT INTO StackObject(\
    686                    "+f+"ippDetectID \
    687                    ,"+f+"xPos \
    688                    ,"+f+"yPos \
    689                    ,"+f+"xPosErr \
    690                    ,"+f+"yPosErr \
    691                    ,"+f+"PSFFlux \
    692                    ,"+f+"PSFFluxErr \
    693                    ,"+f+"sky \
    694                    ,"+f+"skyErr \
    695                    ,"+f+"psfMajorFWHM \
    696                    ,"+f+"psfMinorFWHM \
    697                    ,"+f+"psfTheta \
    698                    ,"+f+"psfLikelihood \
    699                    ,"+f+"infoFlag \
    700                    ,"+f+"psfQf \
    701                    ,"+f+"psfQfPerfect \
    702                    ,"+f+"psfChiSq \
    703                    ,"+f+"momentXX \
    704                    ,"+f+"momentXY \
    705                    ,"+f+"momentYY \
    706                    ,"+f+"momentR1 \
    707                    ,"+f+"momentRH \
    708                    ,"+f+"ApFlux \
    709                    ,"+f+"ApFluxErr \
    710                    ,"+f+"KronFlux \
    711                    ,"+f+"KronFluxErr \
    712                    ,"+f+"KronRad \
    713                    ,"+f+"nFrames \
    714                    ) \
    715                    SELECT \
    716                    IPP_IDET \
    717                    ,X_PSF \
    718                    ,Y_PSF \
    719                    ,X_PSF_SIG \
    720                    ,Y_PSF_SIG \
    721                    ,PSF_INST_FLUX / " + str(exptime) + " \
    722                    ,PSF_INST_FLUX_SIG / " + str(exptime) + " \
    723                    ,SKY / " + str(exptime) + " \
    724                    ,SKY_SIGMA / " + str(exptime) + " \
    725                    ,PSF_MAJOR \
    726                    ,PSF_MINOR \
    727                    ,PSF_THETA \
    728                    ,psfLikelihood(EXT_NSIGMA) \
    729                    , FLAGS2 << 32 | FLAGS \
    730                    ,PSF_QF \
    731                    ,PSF_QF_PERFECT \
    732                    ,PSF_CHISQ / PSF_NDOF \
    733                    ,MOMENTS_XX \
    734                    ,MOMENTS_XY \
    735                    ,MOMENTS_YY \
    736                    ,MOMENTS_R1 \
    737                    ,MOMENTS_RH \
    738                    ,POW(10.0, -0.4*AP_MAG) / " + str(exptime) + " \
    739                    ,NULL \
    740                    ,KRON_FLUX / " + str(exptime) + " \
    741                    ,KRON_FLUX_ERR / " + str(exptime) + " \
    742                    ,MOMENTS_R1 * 2.5 \
    743                    ,N_FRAMES \
    744                    FROM " + f + "SkyChip_psf"
    745              
     690             sql = "UPDATE StackObject as a , " + f + "SkyChip_psf as b set \
     691                   a."+f+"xPos = b.X_PSF \
     692                   ,a."+f+"yPos = b.Y_PSF \
     693                   ,a."+f+"xPosErr = b.X_PSF_SIG \
     694                   ,a."+f+"yPosErr = b.Y_PSF_SIG \
     695                   ,a."+f+"PSFFlux = b.PSF_INST_FLUX / " + str(exptime) + " \
     696                   ,a."+f+"PSFFluxErr = b.PSF_INST_FLUX_SIG / " + str(exptime) + " \
     697                   ,a."+f+"sky = b.SKY / " + str(exptime) + " \
     698                   ,a."+f+"skyErr = b.SKY_SIGMA / " + str(exptime) + " \
     699                   ,a."+f+"psfMajorFWHM = b.PSF_MAJOR \
     700                   ,a."+f+"psfMinorFWHM = b.PSF_MINOR \
     701                   ,a."+f+"psfTheta = b.PSF_THETA \
     702                   ,a."+f+"psfCore = NULL \
     703                   ,a."+f+"psfLikelihood = psfLikelihood(b.EXT_NSIGMA) \
     704                   ,a."+f+"infoFlag = b.FLAGS2 << 32 | FLAGS \
     705                   ,a."+f+"psfQf = b.PSF_QF \
     706                   ,a."+f+"psfQfPerfect = b.PSF_QF_PERFECT \
     707                   ,a."+f+"psfChiSq = b.PSF_CHISQ / b.PSF_NDOF \
     708                   ,a."+f+"momentXX = b.MOMENTS_XX \
     709                   ,a."+f+"momentXY = b.MOMENTS_XY \
     710                   ,a."+f+"momentYY = b.MOMENTS_YY \
     711                   ,a."+f+"momentR1 = b.MOMENTS_R1 \
     712                   ,a."+f+"momentRH = b.MOMENTS_RH \
     713                   ,a."+f+"ApFlux = POW(10.0, -0.4*b.AP_MAG) / " + str(exptime) + " \
     714                   ,a."+f+"ApFluxErr = NULL \
     715                   ,a."+f+"ApFillFac = NULL \
     716                   ,a."+f+"KronFlux = b.KRON_FLUX / " + str(exptime) + " \
     717                   ,a."+f+"KronFluxErr = b.KRON_FLUX_ERR / " + str(exptime) + " \
     718                   ,a."+f+"KronRad = b.MOMENTS_R1 * 2.5 \
     719                   ,a."+f+"PSFMag = b.PSF_INST_MAG    \
     720                   ,a."+f+"PSFMagErr = b.PSF_INST_MAG_SIG    \
     721                   ,a."+f+"ApMag = b.AP_MAG    \
     722                   ,a."+f+"ApMagErr = NULL    \
     723                   ,a."+f+"KronMag = NULL    \
     724                   ,a."+f+"KronMagErr = NULL    \
     725                   ,a."+f+"nFrames = b. N_FRAMES \
     726                   WHERE a." + f + "ippDetectID=b.IPP_IDET "
     727             self.logger.infoPair('sql', sql)     
    746728             try:
    747729                 self.scratchDb.execute(sql)
     
    764746        except:
    765747            self.logger.errorPair('failed update surveyID on','StackObject')
    766            
     748            raise
    767749#        self.scratchDb.updateFilterID("StackObject", f+".00000")
    768750       
    769751        self.scratchDb.updateAllRows("StackObject", "dataRelease", str(self.skychunk.dataRelease))
    770         ##self.updateStackMetaID("StackObject")
    771        
     752        try:
     753            self.updateStackMetaID("StackObject")
     754        except:
     755            self.logger.errorPair("failed update stack meta id on ", "StackObject")
     756            raise
    772757        ##self.updateStackTypeID("StackObject")
    773758       
     
    1014999
    10151000        self.logger.infoPair("Procesing table", "StackToImage")
    1016 
    1017         imageIDs = self.gpc1Db.getImageIDsForThisStackID(self.id)
    1018 
    1019         for imageID in imageIDs:
    1020             sql = "INSERT INTO StackToImage (stackMetaID, imageID) \
     1001        filters = ['g','r','i','z','y']
     1002        for f in filters:
     1003           
     1004            if f == 'g':
     1005                stackmetaid = self.gstackID
     1006            if f == 'r':
     1007                stackmetaid = self.rstackID
     1008            if f == 'i':
     1009                stackmetaid = self.istackID
     1010            if f == 'z':
     1011                stackmetaid = self.zstackID
     1012            if f == 'y':
     1013                stackmetaid = self.ystackID
     1014            if stackmetaid > 0:
     1015   
     1016                imageIDs = self.gpc1Db.getImageIDsForThisStackID(stackmetaid)
     1017
     1018                for imageID in imageIDs:
     1019                    sql = "INSERT INTO StackToImage (stackMetaID, imageID) \
    10211020                   VALUES (\
    1022                    " + str(self.id) + ", " + imageID + ")"
    1023             self.scratchDb.execute(sql)
     1021                   " + str(stackmetaid) + ", " + imageID + ")"
     1022                    self.scratchDb.execute(sql)
    10241023
    10251024        # now update StackMeta with correct number of inputs
    1026         sql = "UPDATE StackMeta SET nP2Images = (SELECT COUNT(distinct(floor(imageID/100))) FROM StackToImage)"
    1027         self.scratchDb.execute(sql)
    1028 
    1029 
    1030     '''   
    1031     Populates the StackObjectCalib table
    1032     XXX this can probably get a big speed increase by using 'SELECT () INTO OUTFILE '/tmp/name' and then
    1033     calling the load data infile '/tmp/name' into table;
    1034     '''
    1035     def populateStackObjectCalibInsertUpdate(self):
    1036         self.logger.infoPair("Processing table", "StackObject")
    1037         tableName = "StackObject"
    1038 
    1039         imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
    1040         self.logger.infoPair("obtained","imageID")
    1041 
    1042         # insert calibration information from dvoDetections into the Table
    1043         sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
    1044             SET a.ra = b.ra, \
    1045             a.dec = b.dec_, \
    1046             a.raErr = b.raErr, \
    1047             a.decErr = b.decErr, \
    1048             a.zp = b.zp, \
    1049             a.expTime = b.expTime, \
    1050             a.airMass = b.airMass   \
    1051             WHERE a.stackDetectID = b.detectID \
    1052             AND b.imageID = " + str(imageID)
    1053         self.scratchDb.execute(sql)
    1054         self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
     1025                    sql = "UPDATE "+f+"StackMeta SET nP2Images = (SELECT COUNT(distinct(floor(imageID/100))) FROM StackToImage where stackMetaID = "+str(stackmetaid)+")"
     1026                    self.scratchDb.execute(sql)
     1027
    10551028       
    10561029    def populateStackObjectFromDvo(self):
     
    10941067                      a." + f + "zp = b.zp, \
    10951068                      a." + f + "expTime = b.expTime, \
     1069                      a." + f + "ippDetectID = b.ippDetectID, \
    10961070                      a." + f + "stackDetectID = b.detectID   \
    10971071                      WHERE a.objID = b.objID \
     
    11041078        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    11051079
    1106         ## XXX write this with the select/insert
    1107         # self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.skychunk.dataRelease))
    1108 
    11091080    '''
    11101081    Applies indexes to the PSPS tables
     
    11191090        self.scratchDb.createIndex("StackApFlx", "ippDetectID")
    11201091        self.scratchDb.createIndex("StackModelFit", "ippDetectID")
    1121 
    1122         # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of
    1123         # the column in PSPS
    1124         ## we don't have that in stacks anymore (it is now gdec/rdec/etc)
    1125         ##self.scratchDb.execute("ALTER TABLE StackObject CHANGE dec_ `dec` double")
    11261092
    11271093        return True
     
    12011167
    12021168        print "update dvo sql: ", sql
    1203         # response = raw_input("update dvo...")
    12041169        self.scratchDb.execute(sql)
    12051170   
     
    12111176        self.logger.infoPair("starting","populatePspsTables");
    12121177        self.skipBatch = False
    1213      
    1214         # HAF everything is commented out for now with ##
    12151178        if not self.useFullTables:
    12161179             if not self.getIDsFromDVO():
     
    12181181        #do some basics first
    12191182        # populate stack meta per filter
    1220         # insert objid per filter to each table           
     1183        # insert objid/stackdetectid per filter to each table           
    12211184        self.tablesToExport=[]   
    12221185
     
    12571220            self.tablesToExport.append("yStackMeta")
    12581221
    1259         self.logger.infoPair("populating","StackObject")
    1260         # need to index on objid or it is stupidly slow
     1222        self.logger.infoPair("populating ","StackObject")
     1223        # need to index on objid and ippdetectid  or it is stupidly slow
    12611224        self.scratchDb.createIndex("StackObject", "objID")
    1262         self.scratchDb.createIndex("StackModelFit", "objID")
    1263         self.scratchDb.createIndex("StackApFlx", "objID")
    1264 
    1265 
    1266 
    1267         #ok, now we have the shell stackObjects - these need to be filled.
     1225        #populate from dvo the (f)ippDetectID into StackObject 
    12681226        self.populateStackObjectFromDvo()
     1227        #index the ippDetectids for the next step
     1228        self.scratchDb.createIndex("StackObject", "gippDetectID")
     1229        self.scratchDb.createIndex("StackObject", "rippDetectID")
     1230        self.scratchDb.createIndex("StackObject", "iippDetectID")
     1231        self.scratchDb.createIndex("StackObject", "zippDetectID")
     1232        self.scratchDb.createIndex("StackObject", "yippDetectID")
    12691233        self.populateStackObject()
    1270        
    1271         ##if self.stackType != "NIGHTLY_STACK":
    1272             ##self.logger.infoPair("populating","StackModelFit")
    1273             ##self.populateStackModelFit()
    1274             ##self.logger.infoPair("populating","StackApFlx")
    1275             ##self.populateStackApFlx()
     1234        # stackObject should be done, pending a few NULL columns (need help)
     1235
     1236        if self.stackType != "NIGHTLY_STACK":
     1237
     1238            self.logger.infoPair("populating ","StackModelFit")
     1239
     1240            self.scratchDb.createIndex("StackModelFit", "objID")
     1241        #populate from dvo the (f)ippdetectid into stackModelFit
     1242
     1243        #index the ippDetectIds for the next step
     1244            self.scratchDb.createIndex("StackModelFit", "gippDetectID")
     1245            self.scratchDb.createIndex("StackModelFit", "rippDetectID")
     1246            self.scratchDb.createIndex("StackModelFit", "iippDetectID")
     1247            self.scratchDb.createIndex("StackModelFit", "zippDetectID")
     1248            self.scratchDb.createIndex("StackModelFit", "yippDetectID")
     1249        #populate stackModelFit
     1250        #cull the entries that should not be (how?)
     1251
     1252            self.logger.infoPair("populating ","StackApFlx")
     1253           
     1254            self.scratchDb.createIndex("StackApFlx", "objID")
     1255        #populate from dvo the (f)ippDetectID into StackApFlx
     1256       
     1257        #index the ippDetectIDs for the next step
     1258            self.scratchDb.createIndex("StackApFlx", "gippDetectID")
     1259            self.scratchDb.createIndex("StackApFlx", "rippDetectID")
     1260            self.scratchDb.createIndex("StackApFlx", "iippDetectID")
     1261            self.scratchDb.createIndex("StackApFlx", "zippDetectID")
     1262            self.scratchDb.createIndex("StackApFlx", "yippDetectID")
     1263        #populate StackApFlx
     1264        #cull the entries that should not be (how?)
     1265       
     1266       
    12761267        self.logger.infoPair("populating","StackToImage")
    12771268        self.populateStackToImage()
    1278         ##self.logger.infoPair("populating","StackObjectCalib")
    1279         ##self.populateStackObjectCalib()
    1280 
    1281         ##self.setMinMaxObjID(["StackObject"])
     1269       
     1270        self.setMinMaxObjID(["StackObject"])
    12821271       
    12831272        ##if self.totalDetections < 1:
     
    12901279        self.tablesToExport.append("StackApFlx")
    12911280
    1292 
    1293 
    12941281        self.logger.infoPair("finishing","populatePspsTables");
    1295 #        raise
    12961282        return True
    12971283    '''
Note: See TracChangeset for help on using the changeset viewer.