Changeset 37935
- Timestamp:
- Feb 25, 2015, 1:59:43 PM (11 years ago)
- Location:
- trunk/ippToPsps/jython
- Files:
-
- 7 edited
-
detectionbatch.py (modified) (2 diffs)
-
diffbatch.py (modified) (1 diff)
-
forcedwarpbatch.py (modified) (15 diffs)
-
gpc1db.py (modified) (4 diffs)
-
loader.py (modified) (1 diff)
-
objectbatch.py (modified) (12 diffs)
-
stackbatch.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/detectionbatch.py
r37917 r37935 401 401 # XXX EAM 2014072 : Is this still a problem? 402 402 sql = "UPDATE " + pspsTableName + " SET psfFlux = 1e20 WHERE psfFlux <= 0.0" 403 self.scratchDb.execute(sql) 404 403 try: self.scratchDb.execute(sql) 404 except: 405 self.logger.infoPair("failed sql",sql) 406 raise 405 407 sql = "UPDATE " + pspsTableName + " SET apFlux = 1e20 WHERE apFlux <= 0.0" 406 self.scratchDb.execute(sql) 407 408 try: self.scratchDb.execute(sql) 409 except: 410 self.logger.infoPair("failed sql",sql) 411 raise 408 412 sql = "UPDATE " + pspsTableName + " SET kronFlux = 1e20 WHERE kronFlux <= 0.0" 409 self.scratchDb.execute(sql) 410 413 try: self.scratchDb.execute(sql) 414 except: 415 self.logger.infoPair("failed sql",sql) 416 raise 411 417 # we don't delete these anymore 412 418 results['NULLINSTFLUX'] = 0; … … 604 610 AND b.imageID = " + str(imageID) 605 611 606 self.scratchDb.execute(sql) 607 612 try: self.scratchDb.execute(sql) 613 except: 614 self.logger.InfoPair("failed sql",sql) 615 raise 608 616 ''' 609 617 Updates table and generates pspsuniqueids -
trunk/ippToPsps/jython/diffbatch.py
r37917 r37935 423 423 AND b.imageID = " + str(imageID) 424 424 425 self.scratchDb.execute(sql) 426 425 try: self.scratchDb.execute(sql) 426 except: 427 self.logger.infoPair("failed sql",sql) 428 raise 427 429 ''' 428 430 Updates table and generates pspsuniqueids -
trunk/ippToPsps/jython/forcedwarpbatch.py
r37917 r37935 6 6 import time 7 7 import stilts 8 import re 8 9 9 10 from java.lang import * … … 54 55 forcedWarpID, 55 56 batchID, 56 "P2", 57 gpc1Db.getForcedWarpStageSmf(forcedWarpID) 58 57 "FW", 58 None) 59 # gpc1Db.getForcedWarpStageSmf(forcedWarpID) 60 # there is a funny problem with order here: we need to open the file first to read the header to get 61 # to skycell ID 62 #forcedWarpID = self.forcedWarpID 63 self.logger.infoPair("getting the fits file for add_id",forcedWarpID) 64 self.fits = gpc1Db.getForcedWarpStageCmf(skychunk.dvoLabel, forcedWarpID) 65 self.forcedWarpID = forcedWarpID 66 self.header = self.fits.getPrimaryHeader() 67 self.warpSkyFileID = self.getKeyValue(self.header,"IMAGEID") 68 self.filterName = self.getKeyValue(self.header,"FPA.FILTERID") 69 self.logger.infoPair("found filterName",self.filterName) 70 self.logger.infoPair("found warp_skyfile_id",self.warpSkyFileID) 59 71 # get camera meta data 60 meta = self.gpc1Db.getForcedWarpStageMeta(self.id) 72 73 meta = self.gpc1Db.getForcedWarpStageMeta(forcedWarpID, self.warpSkyFileID) 74 61 75 if not meta: 62 76 self.logger.errorPair("Could not get", "forced warp metadata") 63 77 raise 64 78 65 self.expID = meta[0]; 66 self.expName = meta[1]; 67 self.distGroup = meta[2]; 68 self.analysisVer = meta[3]; 69 self.bias = meta[4]; 70 self.biasScat = meta[5]; 79 self.expID = meta[0] 80 self.expTime = meta[1] 81 self.analysisVer = meta[2] 82 self.skycellName = meta[3] 83 self.tessName = meta[4] 84 85 self.logger.infoPair("found exp_id",str(self.expID)) 86 self.logger.infoPair("found exp_time",str(self.expTime)) 87 self.logger.infoPair("found skycell_id",self.skycellName) 88 self.logger.infoPair("found tess_id",self.tessName) 89 90 91 #tessName = self.getKeyValue(self.header, 'TESS_ID') 92 #self.tessID = self.scratchDb.getTessID(tessName) 71 93 72 94 if not self.analysisVer: self.analysisVer = -999 95 if self.analysisVer is None: self.analysisVer = "-999" 96 self.logger.infoPair("found analysisVer",self.analysisVer) 97 98 if self.tessName == 'RINGS.V3': 99 100 # skycell is, eg "skycell.1133.081" 101 # 0123456789012345 102 self.projectionID = self.skycellName[8:12] 103 #self.skycellID = self.skycellName[13:] 104 self.skycellID = self.skycellName[8:] 105 else: 106 # skycell is, eg "skycell.081" 107 # 01234567890 108 self.projectionID = 0 109 self.skycellID = self.skycellName[8:11] 110 self.skycellID=self.skycellName[8:] 111 if self.skycellID == "": 112 self.skycellID = -1 113 114 self.logger.infoPair("projection cell found ",self.projectionID) 115 self.logger.infoPair("skycell found", self.skycellID) 116 117 73 118 74 119 # create an output filename, which is {expID}.FITS 75 self.outputFitsFile = "%08d.FITS" % self.expID120 self.outputFitsFile = "%08d.FITS" % forcedWarpID 76 121 self.outputFitsPath = "%s/%s" % (self.localOutPath, self.outputFitsFile) 77 122 self.dropTableVerbose("ForcedWarpMeasurement") … … 79 124 self.dropTableVerbose("ForcedWarpMeta") 80 125 self.dropTableVerbose("ForcedWarpToImage") 126 self.dropTableVerbose("ForcedWarpLensing") 81 127 if not self.config.retry: 82 self.scratchDb.dropTable("ForcedWarpMeasurement") 83 self.scratchDb.dropTable("ForcedWarpExtended") 84 self.scratchDb.dropTable("ForcedWarpMeta") 85 self.scratchDb.dropTable("ForcedWarpToImage") 128 self.scratchDb.dropTable("ForcedWarpMeasurement") 129 self.scratchDb.dropTable("ForcedWarpExtended") 130 self.scratchDb.dropTable("ForcedWarpMeta") 131 self.scratchDb.dropTable("ForcedWarpToImage") 132 self.scratchDb.dropTable("ForcedWarpLensing") 86 133 self.historyModNum = "0" 87 134 88 135 # get a few primary header values. if in test mode, then use defaults 89 if self.safeDictionaryAccessWithDefault(self.header, 'MJD-OBS', "1") == "NULL": 90 self.logger.errorPair("Could not get", "MJD-OBS") 91 raise 92 93 94 if self.safeDictionaryAccessWithDefault(self.header, 'EXPTIME', "1") == "NULL": 95 self.logger.errorPair("Could not get", "EXPTIME") 96 raise 97 98 if self.safeDictionaryAccessWithDefault(self.header, 'FILTERID', "g.0000") == "NULL": 99 self.logger.errorPair("Could not get", "FILTERID") 100 raise 101 136 self.logger.infoPair("calculating ObsTime","ok") 102 137 # MJD-OBS is the exposure start, EXTIME / 172800 = (EXPTIME sec / 84600 sec/day) / 2 103 self.obsTime = float(self.header['MJD-OBS']) + (float(self. header['EXPTIME']) / 172800.0)104 138 self.obsTime = float(self.header['MJD-OBS']) + (float(self.expTime) / 172800.0) 139 self.logger.infoPair("obstime",self.obsTime) 105 140 # set up some defauts 106 141 self.calibModNum = 0 107 142 self.totalNumPhotoRef = 0 108 143 109 110 self.filter = self.header['FILTERID'][0:1] 111 self.filterID = self.scratchDb.getFilterID(self.filter) 144 self.filterID = self.scratchDb.getFilterID(self.filterName[0]) 145 self.logger.infoPair("filterID is ",self.filterID) 112 146 113 147 # insert what we know about this stack batch into the stack table 114 self.ippToPspsDb.insertDetectionMeta(self.batchID, self.expID, self.filter) 148 self.logger.infoPair("inserting basics into ","ForcedWarpMeta") 149 150 self.ippToPspsDb.insertForcedWarpMeta(int(self.batchID), int(self.expID), self.filterName[0]) 115 151 116 152 # dump stuff to log 117 self.logger.infoPair(" CamID", "%d" % self.id)118 self.logger.infoPair("Exp ID", "%d" %self.expID)119 self.logger.infoPair("Exp name", "%s" % self.expName) 120 self.logger.infoPair("Distribution group", "%s" % self.distGroup) 153 self.logger.infoPair("add ID", "%d" % self.id) 154 self.logger.infoPair("Exp ID", self.expID) 155 156 121 157 122 158 … … 129 165 self.logger.infoPair("Processing table", "ForcedWarpMeta") 130 166 131 photoCalID = str(self.scratchDb.getPhotoCalID(forcedWarpID))132 167 header = self.header 168 # photoCalID = str(self.scratchDb.getPhotoCalID(forcedWarpID)) 133 169 134 170 sqlLine = sqlUtility("INSERT INTO ForcedWarpMeta (") … … 136 172 #surveyID (below) 137 173 #filterdID (below) 174 sqlLine.group("forcedWarpID", str(self.forcedWarpID)) 138 175 sqlLine.group("skyCellID", str(self.skycellID)) 139 sqlLine.group("photoCalID", photoCalID)176 # sqlLine.group("photoCalID", photoCalID) 140 177 sqlLine.group("magSat", self.getKeyFloat(header, "%.8f", 'FSATUR')) 141 sqlLine.group("analVer", s elf.analysisVer);142 sqlLine.group("expTime", self.getKeyFloat(self.header, "%.8f", 'EXPREQ'));178 sqlLine.group("analVer", str(self.analysisVer)) 179 sqlLine.group("expTime",self.expTime) 143 180 sqlLine.group("completMag", self.getKeyFloat(header, "%.8f", 'FLIMIT')) 144 sqlLine.group("astroScat", self.getKeyFloat(header, "%.8f", 'CERROR')) 145 sqlLine.group("photoScat", self.getKeyFloat(self.header, "%.8f", 'ZPT_ERR')); 146 sqlLine.group("nAstroRef", self.getKeyValue(header, 'NASTRO')) 147 sqlLine.group("nPhotoRef", self.getKeyValue(header, 'NASTRO')) 181 # sqlLine.group("astroScat", self.getKeyFloat(header, "%.8f", 'CERROR')) 182 # sqlLine.group("photoScat", self.getKeyFloat(self.header, "%.8f", 'ZPT_ERR')); 183 #no nastro 184 # sqlLine.group("nAstroRef", self.getKeyValue(header, 'NASTRO')) 185 # sqlLine.group("nPhotoRef", self.getKeyValue(header, 'NASTRO')) 148 186 sqlLine.group("psfModelID", self.getKeyValue(header, 'PSFMODEL')) 149 187 sqlLine.group("psfFwhm_mean", self.getKeyFloat(header, "%.8f", 'FWHM_MAJ')) 150 188 sqlLine.group("psfFwhm_max", self.getKeyFloat(header, "%.8f", 'FW_MJ_UQ')) 151 sqlLine.group("photoZero", self.getKeyFloat(self.header, "%.8f", 'ZPT_OBS'))189 # sqlLine.group("photoZero", self.getKeyFloat(self.header, "%.8f", 'ZPT_OBS')) 152 190 #photoColor -- how do I set this? it's also not set in stack meta 153 191 sqlLine.group("ctype1", self.getKeyValue(self.header, 'CTYPE1')); … … 174 212 self.scratchDb.updateAllRows("ForcedWarpMeta", "batchID", str(self.batchID)) 175 213 self.scratchDb.updateAllRows("ForcedWarpMeta", "surveyID", str(self.surveyID)) 176 self.scratchDb.updateFilterID("ForcedWarpMeta", self.filter) 214 # self.scratchDb.updateFilterID("ForcedWarpMeta", self.filterID) 215 self.scratchDb.updateFilterID("ForcedWarpMeta",self.filterName[0]) 177 216 self.scratchDb.updateAllRows("ForcedWarpMeta", "calibModNum", str(self.calibModNum)) 178 217 self.scratchDb.updateAllRows("ForcedWarpMeta", "dataRelease", str(self.skychunk.dataRelease)) 179 self.tablesToExport.append("ForcedWarpMeta")218 #self.tablesToExport.append("ForcedWarpMeta") 180 219 181 220 ''' … … 186 225 self.logger.infoPair("Procesing table", "ForcedWarpToImage") 187 226 188 for filter in self.filters: 189 190 forcedwarpID = self.forcedwarpID 191 if forcedwarpID > 0: 227 forcedwarpID = self.forcedWarpID 228 if forcedwarpID > 0: 192 229 193 230 imageIDs = self.gpc1Db.getImageIDsForThisForcedWarpID(forcedwarpID) … … 198 235 VALUES (\ 199 236 " + str(forcedwarpID) + ", " + imageID + ")" 200 self.scratchDb.execute(sql) 201 237 try: self.scratchDb.execute(sql) 238 except: 239 self.logger.infoPair("can't execute sql",sql) 240 raise 202 241 # now update StackMeta with correct number of inputs 203 242 204 self.tablesToExport.append("ForcedWarpToImage")243 #self.tablesToExport.append("ForcedWarpToImage") 205 244 206 245 … … 211 250 Populates the ForcedWarpMeasurement table 212 251 ''' 213 def populateForcedWarpMeasurement Table(self, results):252 def populateForcedWarpMeasurement(self): 214 253 215 254 pspsTableName = "ForcedWarpMeasurement" 216 ippTableName = " ForcedWarpMeasurement_psf"255 ippTableName = "SkyChip_psf" 217 256 218 257 219 258 self.logger.infoPair("Procesing table", "ForcedWarpMeasurement") 220 259 260 BEFORE = self.scratchDb.getRowCount(ippTableName) 261 extTimeString = str(self.expTime) 262 263 #missing are zp, telluricExt, airmass (not easy to get ?) 264 265 sqlLine = sqlUtility("INSERT INTO " + pspsTableName + " (") 266 sqlLine.group("ippDetectID", "IPP_IDET") 267 sqlLine.group("forcedWarpID", str(self.forcedWarpID)); 268 sqlLine.group("randomWarpID", "FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)") 269 sqlLine.group("filterID", str(self.filterID)) 270 sqlLine.group("surveyID", str(self.surveyID)) 271 sqlLine.group("skycellID", str(self.skycellID)) 272 sqlLine.group("expTime", str(self.expTime)) 273 sqlLine.group("obsTime", str(self.obsTime)) 274 sqlLine.group("psfFlux", "PSF_INST_FLUX / "+extTimeString) 275 sqlLine.group("psfFluxErr", "PSF_INST_FLUX_SIG / "+extTimeString) 276 sqlLine.group("psfMajorFWHM", "PSF_FWHM_MAJ") 277 sqlLine.group("psfMinorFWHM", "PSF_FWHM_MIN") 278 sqlLine.group("psfTheta", "PSF_THETA") 279 sqlLine.group("psfCore", "PSF_CORE") 280 sqlLine.group("psfQf", "PSF_QF") 281 sqlLine.group("psfQfPerfect", "PSF_QF_PERFECT") 282 sqlLine.group("psfChiSq", "PSF_CHISQ") 283 sqlLine.group("psfLikelihood", "psfLikelihood(EXT_NSIGMA)") 284 sqlLine.group("momentXX", "MOMENTS_XX") 285 sqlLine.group("momentXY", "MOMENTS_XY") 286 sqlLine.group("momentYY", "MOMENTS_YY") 287 sqlLine.group("momentR1", "MOMENTS_R1") 288 sqlLine.group("momentRH", "MOMENTS_RH") 289 sqlLine.group("momentM3C", "MOMENTS_M3C") 290 sqlLine.group("momentM3S", "MOMENTS_M3S") 291 sqlLine.group("momentM4C", "MOMENTS_M4C") 292 sqlLine.group("momentM4S", "MOMENTS_M4S") 293 sqlLine.group("apFlux","AP_FLUX / " + extTimeString) 294 sqlLine.group("apFluxErr","AP_FLUX_SIG / " + extTimeString) 295 sqlLine.group("apFillF","AP_NPIX / (3.14159265359 * POW(AP_MAG_RADIUS - 0.5, 2))") 296 sqlLine.group("kronFlux","KRON_FLUX / " + extTimeString) 297 sqlLine.group("kronFluxErr","KRON_FLUX_ERR / " + extTimeString ) 298 sqlLine.group("kronRad","MOMENTS_R1 * 2.5") 299 sqlLine.group("sky","SKY /" +extTimeString) 300 sqlLine.group("skyErr","SKY_SIGMA / "+extTimeString) 301 sqlLine.group("infoFlag","FLAGS") 302 sqlLine.group("infoFlag2","FLAGS2") 303 sqlLine.group("dataRelease",str(self.skychunk.dataRelease)) 304 305 sql = sqlLine.makeRaw(") SELECT ", " FROM " + ippTableName) 306 307 try: self.scratchDb.execute(sql) 308 except: 309 self.logger.errorPair("failed sql: ", sql) 310 raise 311 312 313 314 221 315 # insert the per-object data (IDs, random stack ID, dataRelease, etc) 222 self.selectDvoObjIDs() 223 224 self.generateRandomIDs() 316 #self.selectDvoObjIDs() 317 self.logger.infoPair("inserting dvo info: find imageID","from externID") 318 imageID = self.scratchDb.getImageIDFromExternID(self.warpSkyFileID) 319 self.logger.infoPair("updating","forcedWarpMeasurement") 320 sqlLine = sqlUtility("UPDATE ForcedWarpMeasurement as a, " + self.scratchDb.dvoDetectionTable + " as b SET ") 321 sqlLine.group("a.objID","b.objID") 322 sqlLine.group("a.detectID","b.detectID") 323 sqlLine.group("a.ippObjID","b.ippObjID") 324 sqlLine.group("a.dvoRegionID","b.catID") 325 sqlLine.group("a.zp","b.zp") 326 sqlLine.group("a.telluricExt","b.telluricExt") 327 sqlLine.group("a.airmass","b.airmass") 328 sql = sqlLine.makeEquals("WHERE a.ippDetectID = b.ippDetectID AND b.imageID = " +str( imageID)) 329 try: self.scratchDb.execute(sql) 330 except: 331 self.logger.errorPair("failed sql:",sql) 332 raise 333 self.logger.infoPair("need to cull"," nulls objid") 334 results= self.scratchDb.reportAndDeleteRowsWithNULLS("ForcedWarpMeasurement", "objID") 335 336 337 338 # self.generateRandomIDs() 225 339 226 340 self.logger.infoPair("Adding 'row' columns to", "ForcedWarpMeasurement") … … 233 347 # add indexes ForcedWarpMeasurement 234 348 self.scratchDb.createIndex("ForcedWarpMeasurement", "objID") 235 349 self.scratchDb.createIndex("ForcedWarpMeasurement", "ippDetectID") 350 ''' 351 Populates the ForcedWarpExtended table 352 ''' 353 def populateForcedWarpExtended(self): 354 355 pspsTableName = "ForcedWarpExtended" 356 ippTableName = "SkyChip_xrad" 357 358 #self.tablesToExport.append("ForcedWarpExtended") 359 360 #isert stuff from SkyChip_psf 361 sqlLine = sqlUtility("INSERT INTO " + pspsTableName + " (") 362 sqlLine.group("ippDetectID", "IPP_IDET") 363 sqlLine.group("flxR5", "APER_FLUX_5") 364 sqlLine.group("flxR5Err", "APER_FLUX_ERR_5" ) 365 sqlLine.group("flxR5Std", "APER_FLUX_STDEV_5") 366 sqlLine.group("flxR5Fill", "APER_FILL_5") 367 sqlLine.group("flxR6", "APER_FLUX_6") 368 sqlLine.group("flxR6Err", "APER_FLUX_ERR_6" ) 369 sqlLine.group("flxR6Std", "APER_FLUX_STDEV_6") 370 sqlLine.group("flxR6Fill", "APER_FILL_6") 371 372 sql = sqlLine.makeRaw(") SELECT ", " FROM " + ippTableName) 373 374 try: self.scratchDb.execute(sql) 375 except: 376 self.logger.errorPair("failed sql: ", sql) 377 raise 378 379 #insert the things from FOrcedWarpMeasurement 380 self.logger.infoPair("inserting objID,etc from","ForcedWarpMeasurement") 381 sqlLine = sqlUtility("UPDATE " + pspsTableName + " as a, ForcedWarpMeasurement as b SET ") 382 sqlLine.group("a.objID","b.objID") 383 sqlLine.group("a.uniquePspsFWid","b.uniquePspsFWid") 384 sqlLine.group("a.detectID","b.detectID") 385 sqlLine.group("a.ippObjID","b.ippObjID") 386 sqlLine.group("a.filterID","b.filterID") 387 sqlLine.group("a.surveyID","b.surveyID") 388 sqlLine.group("a.forcedWarpID","b.forcedWarpID") 389 sqlLine.group("a.randomWarpID","b.randomWarpID") 390 sqlLine.group("a.skycellID","b.skycellID") 391 sqlLine.group("a.dvoRegionID","b.dvoRegionID") 392 sqlLine.group("a.obsTime","b.obsTime") 393 sql = sqlLine.makeEquals("Where a.ippDetectID = b.ippDetectID") 394 try: self.scratchDb.execute(sql) 395 except: 396 self.logger.errorPair("failed sql: ", sql) 397 raise 398 399 # add in the psps unique ids from stuff 400 self.logger.infoPair("adding information from Skychip_xrad into","ForcedWarpExtended") 401 402 # cull bad d 403 self.logger.infoPair("need to cull"," nulls objid") 404 results= self.scratchDb.reportAndDeleteRowsWithNULLS("ForcedWarpExtended", "objID") 405 406 self.scratchDb.createIndex("ForcedWarpExtended", "objID") 236 407 237 408 238 409 239 240 241 242 243 244 self.tablesToExport.append("ForcedWarpMeasurement") 245 246 247 ''' 248 Populates the ForcedWarpExtended table 249 ''' 250 def populateForcedWarpExtendedTable(self, results): 251 252 pspsTableName = "ForcedWarpExtended" 253 ippTableName = "ForcedWarpExtended_psf" 254 255 256 self.tablesToExport.append("ForcedWarpExtended") 257 258 # get dvo ids, 259 # add in the psps unique ids from stuff 410 ''' 411 Populates the ForcedWarpExtended table 412 ''' 413 def populateForcedWarpLensing(self): 414 415 pspsTableName = "ForcedWarpLensing" 416 ippTableName = "SkyChip_psf" 417 418 #self.tablesToExport.append("ForcedWarpExtended") 419 420 #isert stuff from SkyChip_psf 421 sqlLine = sqlUtility("INSERT INTO " + pspsTableName + " (") 422 sqlLine.group("ippDetectID", "IPP_IDET") 423 sqlLine.group("lensObjSmearX11", "LENS_X11_SM_OBJ") 424 sqlLine.group("lensObjSmearX12", "LENS_X12_SM_OBJ") 425 sqlLine.group("lensObjSmearX22", "LENS_X22_SM_OBJ") 426 sqlLine.group("lensObjSmearE1", "LENS_E1_SM_OBJ") 427 sqlLine.group("lensObjSmearE2", "LENS_E2_SM_OBJ") 428 sqlLine.group("lensObjShearX11", "LENS_X11_SH_OBJ") 429 sqlLine.group("lensObjShearX12", "LENS_X12_SH_OBJ") 430 sqlLine.group("lensObjShearX22", "LENS_X22_SH_OBJ") 431 sqlLine.group("lensObjShearE1", "LENS_E1_SH_OBJ") 432 sqlLine.group("lensObjShearE2", "LENS_E2_SH_OBJ") 433 sqlLine.group("lensPSFSmearX11", "LENS_X11_SM_PSF") 434 sqlLine.group("lensPSFSmearX12", "LENS_X12_SM_PSF") 435 sqlLine.group("lensPSFSmearX22", "LENS_X22_SM_PSF") 436 sqlLine.group("lensPSFSmearE1", "LENS_E1_SM_PSF") 437 sqlLine.group("lensPSFSmearE2", "LENS_E2_SM_PSF") 438 sqlLine.group("lensPSFShearX11", "LENS_X11_SH_PSF") 439 sqlLine.group("lensPSFShearX12", "LENS_X12_SH_PSF") 440 sqlLine.group("lensPSFShearX22", "LENS_X22_SH_PSF") 441 sqlLine.group("lensPSFShearE1", "LENS_E1_SH_PSF") 442 sqlLine.group("lensPSFShearE2", "LENS_E2_SH_PSF") 443 sql = sqlLine.makeRaw(") SELECT ", " FROM " + ippTableName) 444 445 try: self.scratchDb.execute(sql) 446 except: 447 self.logger.errorPair("failed sql: ", sql) 448 raise 449 450 #insert the things from FOrcedWarpMeasurement 451 self.logger.infoPair("inserting objID,etc from","ForcedWarpMeasurement") 452 sqlLine = sqlUtility("UPDATE " + pspsTableName + " as a, ForcedWarpMeasurement as b SET ") 453 sqlLine.group("a.objID","b.objID") 454 sqlLine.group("a.uniquePspsFWid","b.uniquePspsFWid") 455 sqlLine.group("a.detectID","b.detectID") 456 sqlLine.group("a.ippObjID","b.ippObjID") 457 sqlLine.group("a.filterID","b.filterID") 458 sqlLine.group("a.surveyID","b.surveyID") 459 sqlLine.group("a.forcedWarpID","b.forcedWarpID") 460 sqlLine.group("a.randomWarpID","b.randomWarpID") 461 sqlLine.group("a.skycellID","b.skycellID") 462 sqlLine.group("a.dvoRegionID","b.dvoRegionID") 463 sqlLine.group("a.obsTime","b.obsTime") 464 sql = sqlLine.makeEquals("Where a.ippDetectID = b.ippDetectID") 465 try: self.scratchDb.execute(sql) 466 except: 467 self.logger.errorPair("failed sql: ", sql) 468 raise 469 470 # add in the psps unique ids from stuff 471 self.logger.infoPair("adding information from Skychip_psf into","ForcedWarpLensing") 472 473 # cull bad d 474 self.logger.infoPair("need to cull"," nulls objid") 475 results= self.scratchDb.reportAndDeleteRowsWithNULLS("ForcedWarpLensing", "objID") 476 477 self.scratchDb.createIndex("ForcedWarpLensing", "objID") 478 479 260 480 261 481 ''' … … 269 489 270 490 #this should be done 491 self.logger.infoPair("Populating","ForcedWarpMeta") 271 492 self.populateForcedWarpMeta() 272 273 self.populateForcedWarpMeasurement() 493 self.tablesToExport.append("ForcedWarpMeta") 494 495 self.logger.infoPair("Populating","ForcedWarpMeasurement") 496 self.populateForcedWarpMeasurement() 497 self.tablesToExport.append("ForcedWarpMeasurement") 498 499 self.logger.infoPair("Populating","ForcedWarpExtended") 274 500 self.populateForcedWarpExtended() 501 self.tablesToExport.append("ForcedWarpExtended") 502 503 self.logger.infoPair("Populating","ForcedWarpLensing") 504 self.populateForcedWarpLensing() 505 self.tablesToExport.append("ForcedWarpLensing") 506 507 508 self.logger.infoPair("Populating","ForcedWarpToImage") 275 509 self.populateForcedWarpToImage() 276 510 self.tablesToExport.append("ForcedWarpToImage") 511 512 513 self.logger.infoPair("setting min/max objid from","ForcedWarpMeasurement") 277 514 self.setMinMaxObjID(["ForcedWarpMeasurement"]) 278 515 … … 286 523 ''' 287 524 def importIppTables(self, columns="*", tableRE=""): 288 525 count = 0 289 526 if self.config.retry: return True 290 527 self.logger.infoPair("Importing FW tables with table match expression: ", tableRE) … … 307 544 308 545 # drop any previous tables before import 546 309 547 self.scratchDb.dropTable(table.name) 310 548 … … 323 561 self.logger.infoPair("Done. Imported", "%d tables" % count) 324 562 self.indexIppTables() 325 326 563 return True 327 564 328 565 329 330 331 332 333 334 335 336 566 def generateRandomIDs(self): 337 sql = "UPDATE ForcedWarpMeasurement set randomWarpID = FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)" 338 try: self.scratchDb.execute(sql) 567 sql = "UPDATE ForcedWarpMeasurement set randomWarpID = FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)" 568 try: 569 self.scratchDb.execute(sql) 339 570 except: 340 571 self.logger.errorPair('failed sql',sql) 341 r eturn572 raise 342 573 343 574 … … 346 577 ''' 347 578 348 def generatePspsUniqueIDs(self): 349 # sql = "UPDATE ForcedWarpMeasurement join (select @r:=@r+1 rownum, objID from \ 350 # (select @r:=0) r, ForcedWarpMeasurement t) as foo using (objID) set \ 351 # uniquePspsFWid = ((" +str(self.batchID)+ "*1000000000 ) + rownum)" 579 def generateUniquePspsIDs(self): 352 580 sql = "UPDATE ForcedWarpMeasurement set uniquePspsFWid = (("+str(self.batchID)+"*1000000000 ) + row)" 353 354 581 try: self.scratchDb.execute(sql) 355 582 except: 356 583 self.logger.errorPair('failed sql',sql) 357 return 358 359 360 361 362 363 584 raise 585 586 ''' 587 Defines the tables to be exported to psps 588 ''' 364 589 365 590 def exportPspsTablesToFits(self, regex="(.*)"): 366 return super(DetectionBatch, self).exportPspsTablesToFits("(ForcedWarp.*)") 591 return super(ForcedWarpBatch, self).exportPspsTablesToFits("(ForcedWarp.*)") 592 593 594 ''' 595 Drop a table and report the drop 596 ''' 597 def dropTableVerbose(self, table): 598 self.logger.infoPair("dropping table:",table) 599 self.scratchDb.dropTable(table) 600 601 602 ''' 603 Applies indexes to the PSPS tables 604 ''' 605 def alterPspsTables(self): 606 607 self.logger.debug("Altering PSPS tables (currently does nothing in stackbatch)") 608 609 return True 610 611 ''' 612 Applies indexes to the IPP tables 613 ''' 614 def indexIppTables(self): 615 616 self.logger.infoPair("Creating indexes on", "IPP tables") 617 self.scratchDb.createIndex("SkyChip_psf", "IPP_IDET") 618 self.scratchDb.createIndex("SkyChip_xfit", "IPP_IDET") 619 self.scratchDb.createIndex("SkyChip_xrad", "IPP_IDET") 620 self.scratchDb.createIndex("SkyChip_xsrc", "IPP_IDET") 621 self.scratchDb.createIndex("SkyChip_xgal", "IPP_IDET") 622 623 return True 624 625 ''' 626 Updates table and generates pspsuniqueids 627 ''' 628 629 def updatePspsUniqueIDs(self,table): 630 sql = "UPDATE ForcedWarpMeasurement set uniquePspsFWid = (("+str(self.batchID)+"*1000000000 ) + row)" 631 try: self.scratchDb.execute(sql) 632 except: 633 self.logger.errorPair('failed sql',sql) 634 raise -
trunk/ippToPsps/jython/gpc1db.py
r37917 r37935 219 219 220 220 221 ''' 222 Gets a list of PSPS image IDs for this stack ID 223 ''' 224 def getImageIDsForThisForcedWarpID(self, forcedWarpID): 225 226 self.logger.debug("Querying GPC1 for image IDs for forcedWarp ID: " + str(forcedWarpID)) 227 228 # JOIN stackInputSkyfile shoule use stack_id as well as warp_id, right? (maybe not -- the join to warp is first) 229 sql = "SELECT DISTINCT CONCAT(exp_id, SUBSTR(class_id, 3, 4)) FROM ( \ 230 SELECT DISTINCT exp_id,class_id \ 231 FROM addRun join \ 232 fullForceInput on (fullForceInput.ff_id = addRun.stage_id and \ 233 fullForceInput.warp_id = addRun.stage_extra1) \ 234 JOIN fullForceResult using (ff_id, warp_id) \ 235 JOIN warpRun USING(warp_id) \ 236 JOIN warpSkyCellMap using (warp_id) \ 237 JOIN fakeRun USING(fake_id) \ 238 JOIN camRun USING(cam_id) \ 239 JOIN chipRun USING(chip_id) \ 240 WHERE add_id = " + str(forcedWarpID) + ") AS a" 241 242 try: 243 rs = self.executeQuery(sql) 244 except: 245 self.logger.exception("Can't query for imageIDs using :" + sql ) 246 247 imageIDs = [] 248 while (rs.next()): 249 imageIDs.append(rs.getString(1)) 250 rs.close() 251 252 return imageIDs 253 221 254 222 255 … … 251 284 252 285 return meta 286 287 ''' 288 Gets some forcedwarp stage meta data for this sky_id # TODO this SQL could surely be improved 289 ''' 290 def getForcedWarpStageMeta(self, forcedWarpID, warpSkyfileID): 291 self.logger.debug("Querying GPC1 for forced warp meta data") 292 293 meta = [] 294 295 sql = "SELECT \ 296 exp_id, \ 297 exp_time, \ 298 fullForceResult.software_ver, \ 299 skycell_id, \ 300 warpRun.tess_id \ 301 FROM fullForceInput join addRun on \ 302 (fullForceInput.ff_id = addRun.stage_id and fullForceInput.warp_id = addRun.stage_extra1) \ 303 JOIN fullForceResult using (ff_id,warp_id) \ 304 JOIN warpRun using (warp_id) \ 305 JOIN warpImfile using (warp_id) \ 306 JOIN fakeRun using (fake_id) \ 307 JOIN camRun using (cam_id) \ 308 JOIN chipRun using (chip_id) \ 309 JOIN rawExp using (exp_id) \ 310 WHERE add_id = " + str(forcedWarpID) + " \ 311 AND warp_skyfile_id = " + str(warpSkyfileID) 312 313 try: 314 rs = self.executeQuery(sql) 315 rs.first() 316 except: 317 self.logger.errorPair("Can't query for", "forced warp meta data") 318 319 try: 320 meta.append(rs.getString(1)) 321 meta.append(rs.getString(2)) 322 meta.append(rs.getString(3)) 323 meta.append(rs.getString(4)) 324 meta.append(rs.getString(5)) 325 326 except: 327 self.logger.errorPair("getForcedWarpStageMeta()", "empty meta data") 328 329 return meta 330 253 331 254 332 … … 300 378 301 379 ''' 380 get forcedwarp stage cmf 381 ''' 382 def getForcedWarpStageCmf(self, dvoDb, forcedWarpID): 383 sql = "SELECT DISTINCT fullForceResult.path_base \ 384 from fullForceInput join addRun on \ 385 (fullForceInput.ff_id = addRun.stage_id AND \ 386 fullForceInput.warp_id = addRun.stage_extra1) \ 387 join fullForceResult using (ff_id, warp_id) \ 388 where add_id = %d" % forcedWarpID 389 try: 390 rs = self.executeQuery(sql) 391 rs.first() 392 except: 393 self.logger.infoPair("failed sql", sql) 394 self.logger.errorPair("can't query for fullforce cmf", "add_id = %d" %forcedWarpID) 395 return None 396 397 try: 398 pathBase = rs.getString(1) 399 except: 400 self.logger.errorPair("no full force cmfs found for add_id = %d" %forcedWarpID) 401 return None 402 403 files = [] 404 if pathBase.startswith("neb"): 405 406 f=os.popen("neb-ls -p " + pathBase + ".cmf") 407 for i in f.readlines(): 408 409 files.append(i.rstrip()) 410 411 412 if len(files) < 1: return None 413 fits = Fits(self.logger, self.config, files[0]) 414 return fits 415 416 417 418 ''' 302 419 get diff stage cmf name 303 420 ''' … … 327 444 pathBase = rs.getString(1) 328 445 except: 329 self.logger.errorPair("no diff cm s found for diff_skyfile_id = %d" %diff_skyfile_id)446 self.logger.errorPair("no diff cmfs found for diff_skyfile_id = %d" %diff_skyfile_id) 330 447 return None 331 448 print pathBase -
trunk/ippToPsps/jython/loader.py
r37927 r37935 27 27 from diffobjectbatch import DiffObjectBatch 28 28 29 #from forcedwarpbatch import ForcedWarpBatch29 from forcedwarpbatch import ForcedWarpBatch 30 30 from forcedobjectbatch import ForcedObjectBatch 31 31 # -
trunk/ippToPsps/jython/objectbatch.py
r37873 r37935 186 186 SET " + filter[1] + "MeanPSFMagErr = null \ 187 187 WHERE " + filter[1] + "MeanPSFMagErr > " + str(cut) 188 self.scratchDb.execute(sql) 189 188 try: self.scratchDb.execute(sql) 189 except: 190 self.logger.infoPair("failed sql",sql) 191 raise 190 192 ''' 191 193 Inserts stuff for all mags … … 224 226 sql += "ObjectThin.nStackDetections = ObjectThin.nStackDetections + cps.NSTACK_DET" 225 227 self.logger.info(sql) 226 self.scratchDb.execute(sql) 227 228 try: self.scratchDb.execute(sql) 229 except: 230 self.logger.InfoPair("failed sql",sql) 231 raise 228 232 # XXX this does not seem like a good thing to leave in SQL 229 233 self.logger.infoPair("Calculating nDetections from", "n[filters]") … … 233 237 sql += "SET nDetections = nDetections + n" + filter[1] 234 238 sql += " WHERE n" + filter[1] + " != -999" 235 self.scratchDb.execute(sql) 236 239 try: self.scratchDb.execute(sql) 240 except: 241 self.logger.infoPair("failed sql",sql) 242 raise 237 243 ''' 238 244 give objectName to objectThin … … 257 263 except: 258 264 self.logger.errorPair("failed sql", sql) 265 raise 259 266 return False 260 267 … … 275 282 except: 276 283 self.logger.errorPair("failed sql", sql) 284 raise 277 285 return False 278 286 self.logger.infoPair("updating objName", "using means") … … 291 299 except: 292 300 self.logger.errorPair("failed sql", sql) 301 raise 293 302 return False 294 303 … … 309 318 except: 310 319 self.logger.errorPair("failed sql", sql) 320 raise 311 321 return False 312 322 … … 329 339 except: 330 340 self.logger.errorPair("Couldn't squash out of range stuff", sql) 331 return False 341 raise 342 332 343 333 344 self.logger.infoPair("setting to null > 1e-38 and < 1e-38 in", "cps FLUX_KRON") … … 338 349 except: 339 350 self.logger.errorPair("Couldn't squash out of range stuff", sql) 340 r eturn False351 raise 341 352 342 353 … … 420 431 421 432 rs = self.scratchDb.executeQuery(sql) 433 422 434 rs.first() 423 435 nToDelete = rs.getInt(1) … … 437 449 except: 438 450 self.logger.errorPair("Couldn't cull outsiders from ObjectThin table", sql) 439 r eturn False451 raise 440 452 441 453 ##Don't do this till after MeanObject … … 467 479 except: 468 480 self.logger.errorPair("Couldn't populate MeanObject table", sql) 469 r eturn False481 raise 470 482 471 483 self.logger.infoPair("Adding 'row' columns to", "MeanObject table") -
trunk/ippToPsps/jython/stackbatch.py
r37917 r37935 837 837 sql = sqlLine.makeEquals("WHERE a." + filter + "ippDetectID = b.IPP_IDET AND " + psfCondition) 838 838 839 self.scratchDb.execute(sql) 840 839 try: self.scratchDb.execute(sql) 840 except: 841 self.logger.infoPair("failed sql", sql) 842 raise 841 843 # instrumental flux, AB mags, Jy: 842 844 # flux_inst = cts / sec … … 859 861 sqlLine.group(field + "Std", field + "Std" + " * POW(10, 3.56 - 0.4* b.zp)") 860 862 sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID AND b.imageID = " + str(self.imageIDs[filter]) ) 861 self.scratchDb.execute(sql) 862 863 try: self.scratchDb.execute(sql) 864 except: 865 self.logger.infoPair("failed sql",sql) 866 raise 863 867 ''' 864 868 Populates the StackToImage table
Note:
See TracChangeset
for help on using the changeset viewer.
