IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 28, 2014, 6:20:27 AM (12 years ago)
Author:
eugene
Message:

dropping options for stilts dvo import methods; fixing a number of previously ignored errors (eg, dropping non-existent tables); allowing queue questions to strip leading and trailing spaces (so we can read from an input file); echo back the response so input from a file is clearer; re-write big sql blocks with new sql utility code; updating names in MeanObject, ObjectThin to be more consistent; add a new test code program; update detection fields to match new schema; drop the code for the old now-unused tables (detecitonCalib, SkinnyObject, etc)

Location:
branches/eam_branches/ipp-20140717/ippToPsps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140717/ippToPsps

  • branches/eam_branches/ipp-20140717/ippToPsps/jython/objectbatch.py

    r36744 r37129  
    1515from scratchdb import ScratchDb
    1616from dvoobjects import DvoObjects
     17from sqlUtility import sqlUtility
    1718
    1819import logging.config
     
    3738                 scratchDb,
    3839                 dvoID,
    39                  batchID,
    40                  useFullTables):
     40                 batchID):
    4141
    4242       super(ObjectBatch, self).__init__(
     
    5050               batchID,
    5151               "OB",
    52                None,
    53                1)
     52               None)
    5453
    5554       try:
    56            ## XX pass in the existing connection to scratchDb
    5755           self.dvoObjects = DvoObjects(self.logger, self.config, self.skychunk, self.ippToPspsDb, self.scratchDb)
    5856       except:
     
    7472        self.region = self.scratchDb.getRegionNameFromThisDvoIndex(self.id)
    7573        self.ippToPspsDb.insertObjectMeta(self.batchID, self.region)
    76         if True:
    77             self.dvoObjects.nativeIngestRegion(self.region)
    78         else:
    79             self.dvoObjects.ingestRegion(self.region)
     74        self.dvoObjects.nativeIngestRegion(self.region)
    8075
    8176        cptTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpt")
     
    9085    def alterPspsTables(self):
    9186
     87        # XXX EAM 2014.07.24 : why is this no longer needed?
    9288        # 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 MeanObject CHANGE dec_ `dec` double")
    94       # self.scratchDb.execute("ALTER TABLE ObjectThin CHANGE dec_ `dec` double")
     89        # self.scratchDb.execute("ALTER TABLE MeanObject CHANGE dec_ `dec` double")
     90        # self.scratchDb.execute("ALTER TABLE ObjectThin CHANGE dec_ `dec` double")
    9591
    9692        return True
     
    10197    def indexIppTables(self):
    10298
    103         self.logger.infoPair("Creating indexes on", "IPP tables")
     99        # since dvopsps is now used, no action is needed here
     100        # self.logger.infoPair("Creating indexes on", "IPP tables")
    104101
    105102        return True
     
    109106    '''
    110107    def updateMeanObjectFromCps(self, cpsTable):
     108
     109        # list of all filters PSPS is interested in
     110        # XXX EAM : 2014.07.24 : this list should probably be in a config file somewhere
     111        interestedFilters = ['g', 'r', 'i', 'z', 'y']
     112       
     113        filters = self.scratchDb.getOrderedListOfFiltersFromPhotcodesTable(interestedFilters)
     114   
     115        # get a count of the available filters
     116        filterCount = self.scratchDb.getCountOfFiltersFromPhotcodesTable()
     117
     118        self.logger.infoPair("Available filters in Photcodes", filters)
     119
     120        # the 'code' now defines the order in the cps file that the mags are listed for a given filter
     121        self.logger.infoPair("Adding magnitudes from", "cps table")
     122        for filter in filters:
     123
     124            filterID = self.scratchDb.getFilterID(filter[1])
     125
     126            # NOTE: Manipulation of FLAGS from cpsTable is to move ID_SECF_OBJ_EXT flag (0x01000000)
     127            # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags
     128            # XXX EAM : 20140724 this manipulation is no longer needed : [grizy]Flags is now 4 byte (was 8 byte!)
     129
     130            # set the MeanObject fields based largely on dvopsps cps fields:
     131
     132            # XXX EAM 20140724 : filterCount is meant to match
     133            # Nsecfilt, but is potentially not determined correctly.
     134            # use a call to a dvo-native command which knows how to
     135            # find Nsecfilt (or save in the db with dvopsps)
     136
     137            # the math below depends on filterCount = Nsecfilt and MeanObject.row being 1 counting but cps being 0 counting?
     138            # cps.row has a count of MeanObject.row * Nsecfilt + Nfilter
     139            #  " + cpsTable + " AS cps ON (cps.row = (MeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
     140
     141            sql = "UPDATE MeanObject JOIN \
     142                   " + cpsTable + " AS cps ON (cps.row = (MeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
     143                   SET \
     144                    MeanObject." + filter[1] + "QfPerfect = -999 \
     145                   ,MeanObject." + filter[1] + "MeanPSFMag     = MAG \
     146                   ,MeanObject." + filter[1] + "MeanPSFMagErr  = MAG_ERR \
     147                   ,MeanObject." + filter[1] + "MeanPSFMagStd  = MAG_STDEV \
     148                   ,MeanObject." + filter[1] + "MeanPSFMagMin  = MAG_MIN \
     149                   ,MeanObject." + filter[1] + "MeanPSFMagMax  = MAG_MAX \
     150                   ,MeanObject." + filter[1] + "MeanPSFMagNpt  = NUSED \
     151                   ,MeanObject." + filter[1] + "MeanKronMag    = MAG_KRON \
     152                   ,MeanObject." + filter[1] + "MeanKronMagErr = MAG_KRON_ERR \
     153                   ,MeanObject." + filter[1] + "MeanKronMagStd = MAG_KRON_STDEV \
     154                   ,MeanObject." + filter[1] + "MeanKronMagNpt = NUSED_KRON \
     155                   ,MeanObject." + filter[1] + "MeanApMag      = MAG_AP \
     156                   ,MeanObject." + filter[1] + "MeanApMagErr   = MAG_AP_ERR \
     157                   ,MeanObject." + filter[1] + "MeanApMagStd   = MAG_AP_STDEV \
     158                   ,MeanObject." + filter[1] + "MeanApMagNpt   = NUSED_AP \
     159                   ,MeanObject." + filter[1] + "Flags = (0x7fff & FLAGS) | ((FLAGS >> 11) & 0x2000) "
     160
     161
     162            self.logger.info(sql)
     163            self.scratchDb.execute(sql)
     164
     165        # now set to null all MeanMagErr values > 0.5 (cut set by Gene, 2012-04-12)
     166        # XXX EAM 20140724 : keep this cut?
     167        cut = 0.5
     168        self.logger.infoPair("Setting to NULL all MeanMagErr value >", "%f" % cut)
     169        for filter in filters:
     170
     171            sql = "UPDATE MeanObject \
     172                   SET " + filter[1] + "MeanPSFMagErr = null \
     173                   WHERE " + filter[1] + "MeanPSFMagErr > " + str(cut)
     174            self.scratchDb.execute(sql)
     175
     176    '''
     177    Inserts stuff for all mags
     178    '''
     179    def updateObjectThinFromCps(self, cpsTable):
    111180
    112181        # list of all filters PSPS is interested in
     
    127196            filterID = self.scratchDb.getFilterID(filter[1])
    128197
    129             # NOTE: Manipulation of FLAGS from cpsTable is to move ID_SECF_OBJ_EXT flag (0x01000000)
    130             # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags
    131 
    132             sql = "UPDATE MeanObject JOIN \
    133                    " + cpsTable + " AS cps ON (cps.row = (MeanObject.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
    134                    SET \
    135                    MeanObject." + filter[1] + "QfPerfect = -999 \
    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] + "nIncPSFMag = -999 \
    141                    ,MeanObject." + filter[1] + "MeanPSFMagStd = -999 \
    142                    ,MeanObject." + filter[1] + "MinPSFMag = -999 \
    143                    ,MeanObject." + filter[1] + "MaxPSFMag = -999 \
    144                    ,MeanObject." + filter[1] + "nIncKronMag = -999 \
    145                    ,MeanObject." + filter[1] + "MeanKronMag = -999 \
    146                    ,MeanObject." + filter[1] + "MeanKronMagStd = -999 \
    147                    ,MeanObject." + filter[1] + "MeanApMag = MAG_AP \
    148                    ,MeanObject." + filter[1] + "MeanApMagErr = MAG_ERR \
    149                    ,MeanObject." + filter[1] + "MeanApMagStd = MAG_STDEV \
    150                    ,MeanObject." + filter[1] + "nIncApMag = -999 \
    151                    ,MeanObject." + filter[1] + "Flags = (0x7fff & FLAGS) | ((FLAGS >> 11) & 0x2000) "
    152 
    153 
    154             self.logger.info(sql)
    155             self.scratchDb.execute(sql)
    156 
    157         # now set to null all MeanMagErr values > 0.5 (cut set by Gene, 2012-04-12)
    158         cut = 0.5
    159         self.logger.infoPair("Setting to NULL all MeanMagErr value >", "%f" % cut)
    160         for filter in filters:
    161 
    162             sql = "UPDATE MeanObject \
    163                    SET " + filter[1] + "MeanPSFMagErr = null \
    164                    WHERE " + filter[1] + "MeanPSFMagErr > " + str(cut)
    165             self.scratchDb.execute(sql)
    166     '''
    167     Inserts stuff for all mags
    168     '''
    169     def updateObjectThinFromCps(self, cpsTable):
    170 
    171         # list of all filters PSPS is interested in
    172         interestedFilters = ['g', 'r', 'i', 'z', 'y']
    173        
    174         filters = self.scratchDb.getOrderedListOfFiltersFromPhotcodesTable(interestedFilters)
    175    
    176         # get a count of the available filters
    177         filterCount = self.scratchDb.getCountOfFiltersFromPhotcodesTable()
    178         # filterCount = len(filters)
    179 
    180         self.logger.infoPair("Available filters in Photcodes", filters)
    181 
    182         # the 'code' now defines the order in the cps file that the mags are listed for a given filter
    183         self.logger.infoPair("Adding magnitudes from", "cps table")
    184         for filter in filters:
    185 
    186             filterID = self.scratchDb.getFilterID(filter[1])
    187 
    188             # NOTE: Manipulation of FLAGS from cpsTable is to move ID_SECF_OBJ_EXT flag (0x01000000)
    189             # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags
    190 
     198            # XXX EAM 20140724 : this is quite awkward, add a objRow and ncode value to mysql db table?
    191199            sql = "UPDATE ObjectThin JOIN \
    192200                   " + cpsTable + " AS cps ON (cps.row = (ObjectThin.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
     
    196204            self.scratchDb.execute(sql)
    197205
     206        # XXX this does not seem like a good thing to leave in SQL
    198207        self.logger.infoPair("Calculating nDetections from", "n[filters]")
    199208        for filter in filters:
     
    203212                   WHERE n" + filter[1] + " != -999"
    204213            self.scratchDb.execute(sql)
    205            
    206 
    207214
    208215    '''
    209216    give objectName to objectThin
     217    XXX EAM 20140714 : This seems quite inefficient in SQL, move to dvopsps?
    210218    '''
    211219    def updateObjName(self):
     
    281289            return False
    282290
    283 
    284 
    285 
    286 
    287 
    288 
    289291    '''
    290292    Populates the Object table
     
    296298
    297299        if False:
     300            # XXX EAM 20140724 : this is probably wrong : flux measurements can be 0.0 or negative: please review
    298301            self.logger.infoPair("setting to null  > 1e-38 and < 1e-38 in", "cps FLUX_KRON_ERR")
    299302            sql = "UPDATE " + cpsTableName + " set FLUX_KRON_ERR = NULL where FLUX_KRON_ERR < 1e-37 AND FLUX_KRON_ERR > -1e-37 "
     303            self.exitProgram("review this code" + sql)
    300304     
    301305            try:
     
    315319
    316320       
    317         self.logger.infoPair("Populating", "ThinObject")
    318         self.logger.infoPair("Inserting objects from", "cpt file")
    319 
    320         # note `` around dec here, as this is a reserved word in MySQL
    321         sql = "INSERT IGNORE INTO ObjectThin (\
    322                objID \
    323                ,gcobjID \
    324                ,ippObjID \
    325                ,surveyID \
    326                ,skyCellID \
    327                ,randomID \
    328                ,batchID \
    329                ,dvoRegionID \
    330                ,dataRelease \
    331                ,objInfoFlag \
    332                ,qualityFlag \
    333                ,consistencyFlag \
    334                ,raStack \
    335                ,decStack \
    336                ,raStackErr \
    337                ,decStackErr \
    338                ,raMean \
    339                ,decMean \
    340                ,raMeanErr \
    341                ,decMeanErr \
    342                ,raMeanStd \
    343                ,decMeanStd \
    344                ,nStackObjectRows \
    345                ,nStackDetections \
    346                ,nDetections \
    347                 ) \
    348                SELECT \
    349                EXT_ID \
    350                , -999 \
    351                ,CAT_ID*1000000000 + OBJ_ID \
    352                ," + str(self.surveyID) + " \
    353                , -999 \
    354                , FLOOR(RAND()*9223372036854775807) \
    355                , " + str(self.batchID) + "\
    356                , -999 \
    357                , " + str(self.skychunk.dataRelease) + "\
    358                ,FLAGS \
    359                ,FLAGS >> 24 & 0xFF \
    360                , 0 \
    361                , -999 \
    362                , -999 \
    363                , -999 \
    364                , -999 \
    365                ,RA \
    366                ,DEC_ \
    367                ,RA_ERR \
    368                ,DEC_ERR \
    369                , -999 \
    370                , -999 \
    371                ,0 \
    372                ,0 \
    373                ,0 \
    374                 FROM " + cptTableName
     321        self.logger.info("Populating ThinObject")
     322        self.logger.info("Inserting objects from cpt file")
     323
     324        # note "dec" is a reserved word in MySQL
     325        # XXX EAM 20140724 : do not use INGORE unless we discover unavoidable problems...
     326        # INSERT IGNORE INTO ObjectThin
     327
     328        sqlLine = sqlUtility("INSERT INTO ObjectThin (")
     329
     330        sqlLine.group("objID",           "EXT_ID")
     331        # sqlLine.group("gcobjID",       "EXT_ID_GC")  # drop this one?
     332        sqlLine.group("ippObjID",        "OBJ_ID + (CAT_ID << 32)") # NOTE: shift by 32 bits exactly
     333        sqlLine.group("surveyID",        str(self.surveyID))
     334        sqlLine.group("skyCellID",       "-999") # XXX This does not make sense
     335        sqlLine.group("randomID",        "FLOOR(RAND()*9223372036854775807)") # XXX where does this number come from??
     336        sqlLine.group("batchID",         str(self.batchID))
     337        sqlLine.group("dvoRegionID",     "DVO_REGION") # XXX add to dvopsps output for cpt
     338        sqlLine.group("dataRelease",     str(self.skychunk.dataRelease))
     339        sqlLine.group("objInfoFlag",     "FLAGS")
     340        sqlLine.group("qualityFlag",     "FLAGS >> 24 & 0xFF")
     341        sqlLine.group("consistencyFlag", "0")
     342        sqlLine.group("raStack",         "RA_STK")
     343        sqlLine.group("decStack",        "DEC_STK")
     344        sqlLine.group("raStackErr",      "RA_STK_ERR")
     345        sqlLine.group("decStackErr",     "DEC_STK_ERR")
     346        sqlLine.group("raMean",          "RA_MEAN")
     347        sqlLine.group("decMean",         "DEC_MEAN")
     348        sqlLine.group("raMeanErr",       "RA_ERR")
     349        sqlLine.group("decMeanErr",      "DEC_ERR")
     350        sqlLine.group("raMeanStd",       "-999") # XXX I do not calculate this, use chisq?
     351        sqlLine.group("decMeanStd",      "-999")
     352        sqlLine.group("nStackObjectRows", "0") # XXX I need to add / define this in dvopsps
     353        sqlLine.group("nStackDetections", "0")
     354        sqlLine.group("nDetections",      "0")
     355        sql = sqlLine.make(") SELECT ", " FROM " + cptTableName)
    375356
    376357        try:
     
    390371        self.updateObjName()
    391372
    392 
    393373        self.logger.infoPair("update ObjectThin from ","cps table")
    394374
    395375        self.updateObjectThinFromCps(cpsTableName)
    396376
     377        # XXX EAM 20140724 : is this necessary??
    397378        #objects can have out of range ra dec in dvo - need to find and kill them at the end
    398379
Note: See TracChangeset for help on using the changeset viewer.