Changeset 36736 for trunk/ippToPsps/jython/objectbatch.py
- Timestamp:
- May 9, 2014, 10:07:40 AM (12 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/objectbatch.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/objectbatch.py
r35496 r36736 91 91 92 92 # 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") 94 95 95 96 return True … … 107 108 Inserts stuff for all mags 108 109 ''' 109 def insertM ags(self, cpsTable):110 def insertMeanMags(self, cpsTable): 110 111 111 112 # list of all filters PSPS is interested in … … 129 130 # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags 130 131 131 sql = "UPDATE ObjectJOIN \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]) + ")) \ 133 134 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) 155 144 self.scratchDb.execute(sql) 156 145 … … 158 147 for filter in filters: 159 148 # 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) \ 161 150 SET nDetections = nDetections + n" + filter[1] + " \ 162 151 WHERE n" + filter[1] + " != -999" … … 171 160 for filter in filters: 172 161 173 sql = "UPDATE Object \162 sql = "UPDATE MeanObject \ 174 163 SET " + filter[1] + "MeanPSFMagErr = null \ 175 164 WHERE " + filter[1] + "MeanPSFMagErr > " + str(cut) 176 165 self.scratchDb.execute(sql) 177 166 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 colors196 '''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)215 167 216 168 ''' 217 169 Populates the Object table 218 170 ''' 219 def populateObjectT able(self):171 def populateObjectThinTable(self): 220 172 221 173 cptTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cpt") … … 242 194 243 195 244 self.logger.infoPair("Populating", " Object s")196 self.logger.infoPair("Populating", "ThinObject") 245 197 self.logger.infoPair("Inserting objects from", "cpt file") 246 198 247 199 # note `` around dec here, as this is a reserved word in MySQL 248 sql = "INSERT IGNORE INTO Object (\200 sql = "INSERT IGNORE INTO ObjectThin (\ 249 201 objID \ 202 ,gcobjID \ 250 203 ,ippObjID \ 204 ,surveyID \ 205 ,skyCellID \ 206 ,randomID \ 207 ,batchID \ 208 ,dataRelease \ 251 209 ,objInfoFlag \ 252 210 ,qualityFlag \ 253 ,surveyID \ 254 ,ra \ 255 ,`dec` \ 256 ,raErr \ 257 ,decErr \ 211 ,raMean \ 212 ,decMean \ 213 ,raMeanErr \ 214 ,decMeanErr \ 258 215 ,nDetections \ 259 ,qfPerfect \ 260 ,sgSep \ 261 ,dataRelease \ 262 ,Random \ 263 ,batchID \ 264 ) \ 216 ) \ 265 217 SELECT \ 266 218 EXT_ID \ 219 , -999 \ 267 220 ,CAT_ID*1000000000 + OBJ_ID \ 221 ," + str(self.surveyID) + " \ 222 ,-999 \ 223 , RAND() \ 224 , " + str(self.batchID) + "\ 225 , " + str(self.skychunk.dataRelease) + "\ 268 226 ,FLAGS \ 269 227 ,FLAGS >> 24 & 0xFF \ 270 ," + str(self.surveyID) + " \271 228 ,RA \ 272 229 ,DEC_ \ … … 274 231 ,DEC_ERR \ 275 232 ,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 282 234 283 235 try: … … 289 241 # add row count columns so we can perform joins to get colors 290 242 self.logger.infoPair("Adding 'row' columns to", "Object and cps tables") 291 self.scratchDb.addRowCountColumn("Object ", "row")243 self.scratchDb.addRowCountColumn("ObjectThin", "row") 292 244 self.scratchDb.addRowCountColumn(cpsTableName, "row") 293 245 294 self.insertMags(cpsTableName)246 # self.insertMeanMags(cpsTableName) 295 247 296 248 #don't do this as we removed those columns.. … … 312 264 #count out of range 313 265 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) 315 271 316 272 rs = self.scratchDb.executeQuery(sql) … … 321 277 322 278 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) 324 284 self.logger.infoPair("Deleting", str(nToDelete) + " objects outside of ra/dec range") 325 285 … … 327 287 self.scratchDb.execute(sql) 328 288 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) 330 290 return False 331 291 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") 334 294 self.logger.infoPair("Purging from scratch Db", self.region + " region") 335 295 336 296 self.dvoObjects.purgeRegion(self.region) 337 297 338 self.setMinMaxObjID(["Object "])298 self.setMinMaxObjID(["ObjectThin"]) 339 299 340 300 return True … … 343 303 Populates the ObjectCalColor table 344 304 ''' 345 def populate ObjectCalColorTable(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 ( \ 350 310 objID \ 351 ,ippObjID \ 352 ,dataRelease \ 311 ,gcobjID \ 353 312 ) \ 354 313 SELECT \ 355 314 objID \ 356 ,ippObjID \ 357 ,dataRelease \ 358 FROM Object" 315 ,gcobjID \ 316 FROM ObjectThin" 359 317 try: 360 318 self.scratchDb.execute(sql) 361 319 except: 362 self.logger.errorPair("Couldn't populate ObjectCalColortable", sql)320 self.logger.errorPair("Couldn't populate MeanObject table", sql) 363 321 return False 364 322 323 self.insertMeanMags("MeanObject") 365 324 return True 366 325 … … 370 329 def populatePspsTables(self): 371 330 372 if not self.populateObjectT able(): return False331 if not self.populateObjectThinTable(): return False 373 332 #if not self.populateObjectCalColorTable(): return False 333 if not self.populateMeanObjectTable(): return False 374 334 375 335 # 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") 378 338 379 339 # XXX EAM : note that in mysql versions later than 5.1, this fails … … 386 346 self.scratchDb.execute("set session old_alter_table=1") 387 347 388 self.scratchDb.execute("ALTER IGNORE TABLE Object ADD UNIQUE INDEX(objID)")348 self.scratchDb.execute("ALTER IGNORE TABLE ObjectThin ADD UNIQUE INDEX(objID)") 389 349 if self.scratchDb.version > 5.1: 390 350 self.scratchDb.execute("set session old_alter_table=0") 391 351 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 392 377 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.
