IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 8, 2015, 11:24:21 AM (11 years ago)
Author:
eugene
Message:

to generate the FG rows, we need to generate possible output entries for each galaxy model type, fill in data for each one, then delete rows with no data

File:
1 edited

Legend:

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

    r39075 r39079  
    138138        for filter in filters:
    139139            filterID = self.scratchDb.getFilterID(filter[1])
    140 
     140           
    141141            photcodeName = "NONE"
    142142            if self.config.camera == "gpc1":
     
    144144            if self.config.camera == "simtest":
    145145                photcodeName = "SIMTEST." + filter[1] + ".ForcedWarp"
    146 
     146           
    147147            photcode = self.scratchDb.getPhotcodeByName(photcodeName)
    148 
     148           
    149149            # This is going to need to join elsewhere to get all the fields?
    150150            # XforcedSummaryID, Ra, Dec, RaErr, DecErr
    151151            # Should GalChiSq fold in Npix somehow?
    152 
     152           
    153153            sqlLine = sqlUtility("UPDATE ForcedGalaxyShape AS a, " + cpqTable + " AS b SET")
    154154            sqlLine.group("a." + filter[1] + "ippDetectID",     "b.DET_ID")
     
    162162            sqlLine.group("a." + filter[1] + "GalChisq",        "b.CHISQ")
    163163
     164            # we insert data for each of the possible model types, counting the number of filter/model values
     165            # selected for each type.  later we will delete rows for which nFilter is 0
     166            sqlLine.group("a.nFilter", "a.nFilter + 1")
     167           
    164168            # These fields don't exist.
    165169            # sqlLine.group("a." + filter[1] + "GalRa",           "b.RA")
     
    167171            # sqlLine.group("a." + filter[1] + "GalRaErr",        "b.RA_ERR")
    168172            # sqlLine.group("a." + filter[1] + "GalDecErr",       "b.DEC_ERR")
    169 
     173           
    170174            sql = sqlLine.makeEquals("WHERE a.ippObjID = (b.OBJ_ID + (b.CAT_ID << 32)) AND a.galModelType = b.MODEL_TYPE AND b.Photcode = " + str(photcode))
    171 
     175           
    172176            self.logger.debugPair("cpq sql: ", sql)
    173 
     177           
    174178            self.scratchDb.execute(sql)
    175179
     
    183187       
    184188        self.logger.info("Populating ForcedGalaxyShape")
    185         self.logger.info("Inserting from cpq file")
    186 
    187         sqlLine = sqlUtility("INSERT INTO ForcedGalaxyShape (")
    188 
    189         sqlLine.group("objID",      "EXT_ID")
    190         # uniquePspsFGid is set elsewhere
    191         sqlLine.group("ippObjID",   "OBJ_ID + (CAT_ID << 32)")
    192         # batchID isn't in the schema, should it be?
    193         # sqlLine.group("batchID",    "'" + str(self.batchID) + "'")
    194         # surveyID is set where?
    195         sqlLine.group("randomForcedGalID",      "RAND("+str(self.batchID)+")")
    196        
    197         sql = sqlLine.makeRaw(") SELECT ", " FROM " + cptTableName)
    198 
    199         print "--- sql: " + sql
    200 
     189
     190        # the cpt file has the basic object data (IDs).  insert a row for each of the
     191        # model types of interest, listed in the array below
     192        self.logger.info("Inserting from cpt file")
     193        for modelName in ["PS_MODEL_EXP", "PS_MODEL_DEV", "PS_MODEL_SERSIC"]:
     194            modelID = self.scratchDb.getFitModelID(modelName)
     195            ## assert on modelID > 0
     196
     197            sqlLine = sqlUtility("INSERT INTO ForcedGalaxyShape (")
     198
     199            # uniquePspsFGid is set elsewhere
     200            # batchID isn't in the schema, should it be?
     201
     202            sqlLine.group("objID",             "EXT_ID")
     203            sqlLine.group("ippObjID",          "OBJ_ID + (CAT_ID << 32)")
     204            sqlLine.group("surveyID",          str(self.surveyID))
     205            sqlLine.group("randomForcedGalID", "RAND("+str(self.batchID)+")")
     206            sqlLine.group("nFilter",           "0")
     207            sqlLine.group("galModelType",      str(modelID))
     208
     209            sql = sqlLine.makeRaw(") SELECT ", " FROM " + cptTableName)
     210
     211            print "--- sql: " + sql
     212
     213            self.scratchDb.execute(sql)
     214
     215        # add in the actual galaxy photometry & shape measurements
     216        self.logger.infoPair("update ForcedGalaxyShape from ","cpq table")
     217        self.updateForcedGalaxyShapeFromCpq(cpqTableName)
     218
     219        # drop the rows with no galaxy photometry
     220        self.logger.infoPair("dropping rows with no data", "ForcedGalaxyShape")
     221        sql = "DELETE FROM ForcedGalaxyShape WHERE nFilter = 0"
    201222        self.scratchDb.execute(sql)
    202223
    203         self.logger.infoPair("Adding 'row' columns to", "Forced Galaxy, cpt tables")
     224        # now we need to generate a unique psps ID:
     225        self.logger.infoPair("Adding 'row' columns to", "ForcedGalaxyShape table")
    204226        self.scratchDb.addRowCountColumn("ForcedGalaxyShape", "row")
    205         self.scratchDb.addRowCountColumn(cpqTableName, "row")
    206227
    207228        self.logger.infoPair("generating unique ids for ","ForcedGalaxyShape")
    208229        self.updatePspsUniqueIDs()
    209230
    210         self.logger.infoPair("update ForcedGalaxyShape from ","cpq table")
    211         self.updateForcedGalaxyShapeFromCpq(cpqTableName)
    212        
    213231        self.logger.infoPair("Dropping row column from ", "ForcedGalaxyShape table")
    214232        self.scratchDb.dropColumn("ForcedGalaxyShape", "row")
     
    216234        self.logger.infoPair("setting minmaxobjid for ", "ForcedGalaxyShape table")
    217235        self.setMinMaxObjID(["ForcedGalaxyShape"])
     236
    218237        self.logger.infoPair("checking if we have detections", "ForcedGalaxyShape table")
    219 
    220238        rowcount = self.scratchDb.getRowCount("ForcedGalaxyShape")
    221239
Note: See TracChangeset for help on using the changeset viewer.