IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 9, 2014, 10:07:40 AM (12 years ago)
Author:
heather
Message:

ipptopsps: stacks are happy, objects are in progress

File:
1 edited

Legend:

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

    r35496 r36736  
    9191
    9292        # dec is reserved in MySQL, so STILTS replaces if with dec_, which PSPS doesn't like. so, force it back again using ``
    93         self.scratchDb.execute("ALTER TABLE Object CHANGE dec_ `dec` double")
     93      #  self.scratchDb.execute("ALTER TABLE MeanObject CHANGE dec_ `dec` double")
     94      #  self.scratchDb.execute("ALTER TABLE ObjectThin CHANGE dec_ `dec` double")
    9495
    9596        return True
     
    107108    Inserts stuff for all mags
    108109    '''
    109     def insertMags(self, cpsTable):
     110    def insertMeanMags(self, cpsTable):
    110111
    111112        # list of all filters PSPS is interested in
     
    129130            # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags
    130131
    131             sql = "UPDATE Object JOIN \
    132                    " + cpsTable + " AS cps ON (cps.row = (Object.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
     132            sql = "UPDATE MeanObject JOIN ObjectThin using (objID) JOIN \
     133                   " + cpsTable + " AS cps ON (cps.row = (ObjectThin.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
    133134                   SET \
    134                    n" + filter[1] + " = NCODE \
    135                    ," + filter[1] + "MeanPSFMag = MAG \
    136                    ," + filter[1] + "MeanPSFMagErr = MAG_ERR \
    137                    ," + filter[1] + "MeanKronMag = MAG_KRON \
    138                    ," + filter[1] + "MeanKronMagErr = MAG_KRON_ERR \
    139                    ," + filter[1] + "StackPSFMag = STACK_PSF_MAG \
    140                    ," + filter[1] + "StackPSFMagErr = STACK_PSF_MAG_ERR \
    141                    ," + filter[1] + "StackKronMag = STACK_KRON_MAG \
    142                    ," + filter[1] + "StackKronMagErr = STACK_KRON_MAG_ERR \
    143                    ," + filter[1] + "20pct = MAG_20/1000 \
    144                    ," + filter[1] + "80pct = MAG_80/1000 \
    145                    ," + filter[1] + "Flags = (0x7fff & FLAGS) | ((FLAGS >> 11) & 0x2000) \
    146                    ," + filter[1] + "StackDetectID = STACK_DETECT_ID"
    147 
    148 # old method for setting the Stack (PSF,Kron) Mags:
    149 #                  ," + filter[1] + "StackPSFMag = -2.5 * log10(FLUX_PSF) + 8.9 \
    150 #                  ," + filter[1] + "StackPSFMagErr = FLUX_PSF_ERR / FLUX_PSF \
    151 #                  ," + filter[1] + "StackKronMag = -2.5 * log10(FLUX_KRON) + 8.9 \
    152 #                  ," + filter[1] + "StackKronMagErr = FLUX_KRON_ERR / FLUX_KRON \
    153 
    154             #self.logger.info(sql)
     135                   ObjectThin.n" + filter[1] + " = NCODE \
     136                   ,MeanObject." + filter[1] + "MeanPSFMag = MAG \
     137                   ,MeanObject." + filter[1] + "MeanPSFMagErr = MAG_ERR \
     138                   ,MeanObject." + filter[1] + "MeanKronMag = MAG_KRON \
     139                   ,MeanObject." + filter[1] + "MeanKronMagErr = MAG_KRON_ERR \
     140                   ,MeanObject." + filter[1] + "Flags = (0x7fff & FLAGS) | ((FLAGS >> 11) & 0x2000) "
     141
     142
     143            self.logger.info(sql)
    155144            self.scratchDb.execute(sql)
    156145
     
    158147        for filter in filters:
    159148            # now do a sum of n[filters], but do not include the ones with -999
    160             sql = "UPDATE Object \
     149            sql = "UPDATE ObjectThin join MeanObject using (objID) \
    161150                   SET nDetections = nDetections + n" + filter[1] + " \
    162151                   WHERE n" + filter[1] + " != -999"
     
    171160        for filter in filters:
    172161
    173             sql = "UPDATE Object \
     162            sql = "UPDATE MeanObject \
    174163                   SET " + filter[1] + "MeanPSFMagErr = null \
    175164                   WHERE " + filter[1] + "MeanPSFMagErr > " + str(cut)
    176165            self.scratchDb.execute(sql)
    177166
    178         self.logger.infoPair("Setting to NULL all x20pct =", "32.767" )
    179         for filter in filters:
    180             sql  = "UPDATE Object \
    181                    SET " + filter[1] + "20pct = null \
    182                    WHERE " + filter[1] + "20pct > 32.766"
    183             self.scratchDb.execute(sql)
    184         self.logger.infoPair("Setting to NULL all x80pct =", "32.767" )
    185         for filter in filters:
    186             sql  = "UPDATE Object \
    187                     SET " + filter[1] + "80pct = null \
    188                     WHERE " + filter[1] + "80pct > 32.766"
    189             self.scratchDb.execute(sql)
    190 
    191 
    192 
    193 
    194     '''
    195     Inserts colors
    196     '''
    197     def updateColors(self):
    198 
    199         self.logger.infoPair("Calculating", "colors")
    200         sql = "UPDATE Object \
    201                SET \
    202                grMeanColor = (gMeanMag - rMeanMag) \
    203                ,riMeanColor = (rMeanMag - iMeanMag) \
    204                ,izMeanColor = (iMeanMag - zMeanMag) \
    205                ,zyMeanColor = (zMeanMag - yMeanMag) \
    206                ,grMeanColorErr = SQRT(POW(gMeanMagErr,2) + POW(rMeanMagErr,2)) \
    207                ,riMeanColorErr = SQRT(POW(rMeanMagErr,2) + POW(iMeanMagErr,2)) \
    208                ,izMeanColorErr = SQRT(POW(iMeanMagErr,2) + POW(zMeanMagErr,2)) \
    209                ,zyMeanColorErr = SQRT(POW(zMeanMagErr,2) + POW(yMeanMagErr,2)) \
    210                    "
    211         try:
    212             self.scratchDb.execute(sql)
    213         except:
    214             self.logger.errorPair("Couldn't calculate colors", sql)
    215167
    216168    '''
    217169    Populates the Object table
    218170    '''
    219     def populateObjectTable(self):
     171    def populateObjectThinTable(self):
    220172
    221173        cptTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpt")
     
    242194
    243195       
    244         self.logger.infoPair("Populating", "Object s")
     196        self.logger.infoPair("Populating", "ThinObject")
    245197        self.logger.infoPair("Inserting objects from", "cpt file")
    246198
    247199        # note `` around dec here, as this is a reserved word in MySQL
    248         sql = "INSERT IGNORE INTO Object (\
     200        sql = "INSERT IGNORE INTO ObjectThin (\
    249201               objID \
     202               ,gcobjID \
    250203               ,ippObjID \
     204               ,surveyID \
     205               ,skyCellID \
     206               ,randomID \
     207               ,batchID \
     208               ,dataRelease \
    251209               ,objInfoFlag \
    252210               ,qualityFlag \
    253                ,surveyID \
    254                ,ra \
    255                ,`dec` \
    256                ,raErr \
    257                ,decErr \
     211               ,raMean \
     212               ,decMean \
     213               ,raMeanErr \
     214               ,decMeanErr \
    258215               ,nDetections \
    259                ,qfPerfect \
    260                ,sgSep \
    261                ,dataRelease \
    262                ,Random \
    263                ,batchID \
    264                ) \
     216                ) \
    265217               SELECT \
    266218               EXT_ID \
     219               , -999 \
    267220               ,CAT_ID*1000000000 + OBJ_ID \
     221               ," + str(self.surveyID) + " \
     222               ,-999 \
     223               , RAND() \
     224               , " + str(self.batchID) + "\
     225               , " + str(self.skychunk.dataRelease) + "\
    268226               ,FLAGS \
    269227               ,FLAGS >> 24 & 0xFF \
    270                ," + str(self.surveyID) + " \
    271228               ,RA \
    272229               ,DEC_ \
     
    274231               ,DEC_ERR \
    275232               ,0 \
    276                ,PSF_QF_PERF \
    277                ,STARGAL_SEP \
    278                , " + str(self.skychunk.dataRelease) + "\
    279                , RAND() \
    280                , " + str(self.batchID) + "\
    281                FROM " + cptTableName
     233                FROM " + cptTableName
    282234
    283235        try:
     
    289241        # add row count columns so we can perform joins to get colors
    290242        self.logger.infoPair("Adding 'row' columns to", "Object and cps tables")
    291         self.scratchDb.addRowCountColumn("Object", "row")
     243        self.scratchDb.addRowCountColumn("ObjectThin", "row")
    292244        self.scratchDb.addRowCountColumn(cpsTableName, "row")
    293245
    294         self.insertMags(cpsTableName)
     246 #       self.insertMeanMags(cpsTableName)
    295247
    296248#don't do this as we removed those columns..
     
    312264        #count out of range
    313265
    314         sql = "SELECT count(*) FROM Object where Object.dec > " + str(decMax) + " or Object.dec < " + str(decMin) + " or Object.ra > " + str(raMax) + " or Object.ra < " + str(raMin)       
     266        sql = "SELECT count(*) FROM ObjectThin where \
     267              ObjectThin.decMean > " + str(decMax) + " \
     268              or ObjectThin.decMean < " + str(decMin) + " \
     269              or ObjectThin.raMean > " + str(raMax) + " \
     270              or ObjectThin.raMean < " + str(raMin)       
    315271   
    316272        rs = self.scratchDb.executeQuery(sql)
     
    321277       
    322278 
    323         sql = "DELETE FROM Object where Object.dec > " + str(decMax) + " or Object.dec < " + str(decMin) + " or Object.ra > " + str(raMax) + " or Object.ra < " + str(raMin)
     279        sql = "DELETE FROM ObjectThin where \
     280              ObjectThin.decMean > " + str(decMax) + " or \
     281              ObjectThin.decMean < " + str(decMin) + " or \
     282              ObjectThin.raMean > " + str(raMax) + " or \
     283              ObjectThin.raMean < " + str(raMin)
    324284        self.logger.infoPair("Deleting", str(nToDelete) + " objects outside of ra/dec range")
    325285
     
    327287            self.scratchDb.execute(sql)
    328288        except:
    329             self.logger.errorPair("Couldn't cull outsiders from Object table", sql)
     289            self.logger.errorPair("Couldn't cull outsiders from ObjectThin table", sql)
    330290            return False
    331291
    332         self.logger.infoPair("Dropping row column from", "Object table")
    333         self.scratchDb.dropColumn("Object", "row")
     292        self.logger.infoPair("Dropping row column from", "ObjectThin table")
     293        self.scratchDb.dropColumn("ObjectThin", "row")
    334294        self.logger.infoPair("Purging from scratch Db", self.region + " region")
    335295
    336296        self.dvoObjects.purgeRegion(self.region)
    337297
    338         self.setMinMaxObjID(["Object"])
     298        self.setMinMaxObjID(["ObjectThin"])
    339299
    340300        return True
     
    343303    Populates the ObjectCalColor table
    344304    '''
    345     def populateObjectCalColorTable(self):
    346 
    347         self.logger.infoPair("Populating", "ObjectCalColor")
    348 
    349         sql = "INSERT INTO ObjectCalColor ( \
     305    def populateMeanObjectTable(self):
     306
     307        self.logger.infoPair("Populating", "MeanObject")
     308
     309        sql = "INSERT INTO MeanObject ( \
    350310               objID \
    351                ,ippObjID \
    352                ,dataRelease \
     311               ,gcobjID \
    353312               ) \
    354313               SELECT \
    355314               objID \
    356                ,ippObjID \
    357                ,dataRelease \
    358                FROM Object"
     315               ,gcobjID \
     316               FROM ObjectThin"
    359317        try:
    360318            self.scratchDb.execute(sql)
    361319        except:
    362             self.logger.errorPair("Couldn't populate ObjectCalColor table", sql)
     320            self.logger.errorPair("Couldn't populate MeanObject table", sql)
    363321            return False
    364322
     323        self.insertMeanMags("MeanObject")
    365324        return True
    366325
     
    370329    def populatePspsTables(self):
    371330
    372         if not self.populateObjectTable(): return False
     331        if not self.populateObjectThinTable(): return False
    373332        #if not self.populateObjectCalColorTable(): return False
     333        if not self.populateMeanObjectTable(): return False
    374334
    375335        # now remove the objID duplicates. We could not do this before as cpt/cps tables relate by row number
    376         self.logger.infoPair("Forcing uniqueness on", "objID in Object table")
    377         rowCountBefore = self.scratchDb.getRowCount("Object")
     336        self.logger.infoPair("Forcing uniqueness on", "objID in ObjectThin table")
     337        rowCountBefore = self.scratchDb.getRowCount("ObjectThin")
    378338
    379339        # XXX EAM : note that in mysql versions later than 5.1, this fails
     
    386346            self.scratchDb.execute("set session old_alter_table=1")
    387347           
    388         self.scratchDb.execute("ALTER IGNORE TABLE Object ADD UNIQUE INDEX(objID)")
     348        self.scratchDb.execute("ALTER IGNORE TABLE ObjectThin ADD UNIQUE INDEX(objID)")
    389349        if self.scratchDb.version > 5.1:
    390350            self.scratchDb.execute("set session old_alter_table=0")
    391351
     352        rowCountAfter = self.scratchDb.getRowCount("ObjectThin")
     353        self.logger.infoPair("Number of duplicated objIDs removed", "%d out of %d" % ((rowCountBefore - rowCountAfter), rowCountBefore))
     354
     355        self.logger.infoPair("Forcing uniqueness on", "objID in MeanObject table")
     356        rowCountBefore = self.scratchDb.getRowCount("MeanObject")
     357
     358        # XXX EAM : note that in mysql versions later than 5.1, this fails
     359        # unless the following is called first:
     360        # set session old_alter_table=1
     361        # follow the command with
     362        # set session old_alter_table=0
     363        # OF COURSE, this fails for mysql version < 5.5...
     364        if self.scratchDb.version > 5.1:
     365            self.scratchDb.execute("set session old_alter_table=1")
     366           
     367        self.scratchDb.execute("ALTER IGNORE TABLE MeanObject ADD UNIQUE INDEX(objID)")
     368        if self.scratchDb.version > 5.1:
     369            self.scratchDb.execute("set session old_alter_table=0")
     370
     371        rowCountAfter = self.scratchDb.getRowCount("MeanObject")
     372        self.logger.infoPair("Number of duplicated objIDs removed", "%d out of %d" % ((rowCountBefore - rowCountAfter), rowCountBefore))
     373
     374
     375        #this is abuse of something but this is how I get the object batches to crash to further investigate them
     376       
    392377        rowCountAfter = self.scratchDb.getRowCount("Object")
    393         self.logger.infoPair("Number of duplicated objIDs removed", "%d out of %d" % ((rowCountBefore - rowCountAfter), rowCountBefore))
    394 
    395         return True
    396 
     378        #return True
     379        return False
Note: See TracChangeset for help on using the changeset viewer.