Changeset 37750
- Timestamp:
- Dec 16, 2014, 5:30:25 PM (12 years ago)
- Location:
- trunk/ippToPsps
- Files:
-
- 2 added
- 3 edited
-
config/tables.DF.vot (modified) (1 diff)
-
jython/diffbatch.py (modified) (16 diffs)
-
jython/dvodiffdetections.py (added)
-
jython/dvodiffobjects.py (added)
-
jython/gpc1db.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/config/tables.DF.vot
r37748 r37750 283 283 <DESCRIPTION>flag indicating provenance information</DESCRIPTION> 284 284 </FIELD> 285 <FIELD name="infoFlag2" arraysize="1" datatype="long" unit="dimensionless" default="-999"> 286 <DESCRIPTION>flag indicating provenance information</DESCRIPTION> 287 </FIELD> 285 288 <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="dimensionless" default="NA"> 286 289 <DESCRIPTION>Data release when this detection was originally taken. Recalibrations do not affect this value.</DESCRIPTION> -
trunk/ippToPsps/jython/diffbatch.py
r37749 r37750 6 6 import time 7 7 import stilts 8 8 import re 9 9 from java.lang import * 10 10 from java.sql import * … … 178 178 Populates the Diff table for this OTA 179 179 ''' 180 def populateDiff Table(self, ota, results):180 def populateDiffDetectionTable(self): 181 181 182 182 pspsTableName = "DiffDetection" 183 ippTableName = " diff_psf"183 ippTableName = "SkyChip_psf" 184 184 185 results['ORIGINALTOTAL'] = self.scratchDb.getRowCount(ippTableName)185 #results['ORIGINALTOTAL'] = self.scratchDb.getRowCount(ippTableName) 186 186 187 187 # drop then re-create table 188 self.scratchDb.dropTable(pspsTableName)189 sql = "CREATE TABLE " + pspsTableName + " LIKE DiffDetection"190 try: self.scratchDb.execute(sql)191 except: pass188 #self.scratchDb.dropTable(pspsTableName) 189 #sql = "CREATE TABLE " + pspsTableName + " LIKE DiffDetection" 190 #try: self.scratchDb.execute(sql) 191 #except: pass 192 192 193 193 # XXX we no longer delete detections with funny mags (eg PSF_INST_MAG < -17.5) … … 195 195 196 196 BEFORE = self.scratchDb.getRowCount(ippTableName) 197 results['SATDET'] = 0197 #results['SATDET'] = 0 198 198 199 199 extTimeString = str(self.expTime) … … 206 206 # XXX apFluxF or apFluxNpix + apFluxRadius? 207 207 208 sqlLine.group("ippDetectID", "IPP_IDET") 208 sqlLine.group("ippDetectID", "IPP_IDET") 209 sqlLine.group("diffDetMetaID", str(self.diffSkyFileID)); 209 210 sqlLine.group("randomDiffID", "FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)") 210 211 sqlLine.group("filterID", str(self.filterID)) 211 sqlLine.group("surveyID", str(self.surveyID)) 212 ##sqlLine.group("obsTime", str(self.obsTime)) I have expTime 212 sqlLine.group("surveyID", str(self.surveyID)) 213 sqlLine.group("skycellID", str(self.skycellID)) 214 ## sqlLine.group("obsTime", str(self.obsTime)) 213 215 sqlLine.group("expTime", str(self.expTime)) 214 216 sqlLine.group("xPos", "X_PSF") … … 228 230 sqlLine.group("psfFlux", "PSF_INST_FLUX / " + extTimeString) 229 231 sqlLine.group("psfFluxErr", "PSF_INST_FLUX_SIG / " + extTimeString) 230 if (self.id >= 982483): 231 sqlLine.group("psfMajorFWHM", "PSF_FWHM_MAJ")232 sqlLine.group("psfMinorFWHM", "PSF_FWHM_MIN")233 sqlLine.group("psfCore", "PSF_CORE")232 # if (self.id >= 982483): #we don't have PSF_FWHM_MAJ or MIN or PSF_CORE 233 # sqlLine.group("psfMajorFWHM", "PSF_FWHM_MAJ") 234 # sqlLine.group("psfMinorFWHM", "PSF_FWHM_MIN") 235 # sqlLine.group("psfCore", "PSF_CORE") 234 236 sqlLine.group("psfTheta", "PSF_THETA") 235 237 sqlLine.group("psfQf", "PSF_QF") … … 249 251 sqlLine.group("apFlux", "AP_FLUX / " + extTimeString) 250 252 sqlLine.group("apFluxErr", "AP_FLUX_SIG / " + extTimeString) 251 sqlLine.group("apFillF", "AP_NPIX / (3.14159265359 * POW(AP_MAG_RADIUS - 0.5, 2))")253 # sqlLine.group("apFillF", "AP_NPIX / (3.14159265359 * POW(AP_MAG_RADIUS - 0.5, 2))") 252 254 # sqlLine.group("apRadius", "AP_MAG_RADIUS") 253 255 sqlLine.group("kronFlux", "KRON_FLUX / " + extTimeString) … … 291 293 292 294 # we don't delete these anymore 293 results['NULLINSTFLUX'] = 0;295 #results['NULLINSTFLUX'] = 0; 294 296 295 297 296 298 # insert stuff from dvo 299 self.logger.infoPair("inserting dvo info:find imageID"," from externID") 300 imageID = self.scratchDb.getImageIDFromExternID(self.diffSkyFileID) 301 self.logger.infoPair("updating","diffdetection") 302 sqlLine = sqlUtility("UPDATE DiffDetection as a, " + self.scratchDb.dvoDetectionTable + " as b SET ") 303 sqlLine.group("a.diffObjID", "b.objId") 304 305 sql = sqlLine.makeEquals("WHERE a.ippDetectID = b.ippDetectID AND b.imageID = " +str( imageID)) 306 307 try: self.scratchDb.execute(sql) 308 except: 309 self.logger.errorPair("failed sql:",sql) 310 raise 311 self.logger.infoPair("need to cull"," nulls objid") 312 self.logger.infoPair("need to add","uniquePSPSDFid") 297 313 298 314 … … 304 320 self.logger.infoPair("Procesing table", "DiffToImage") 305 321 306 imageIDs = self.gpc1Db.getImageIDsForThisDiffID( diffkmetaID)322 imageIDs = self.gpc1Db.getImageIDsForThisDiffID(self.diffSkyFileID) 307 323 308 324 for imageID in imageIDs: … … 310 326 sql = "INSERT INTO DiffToImage (diffMetaID, imageID) \ 311 327 VALUES (\ 312 " + str( diffmetaID) + ", " + imageID + ")"328 " + str(self.diffSkyFileID) + ", " + imageID + ")" 313 329 self.scratchDb.execute(sql) 314 330 … … 335 351 self.scratchDb.makeColumnPrimaryKey("DiffDetection", "ippDetectID") 336 352 337 self.populateDiffMeta()353 #self.populateDiffMeta() 338 354 339 355 # dictionary objects to hold imageIDs for later … … 355 371 self.logger.infoPair("Creating indexes on", "IPP tables") 356 372 357 self.scratchDb.createIndex(extension, "IPP_IDET")373 #self.scratchDb.createIndex(extension, "IPP_IDET") 358 374 # try the test Chip 359 self.scratchDb.createIndex(" Chip_psf", "IPP_IDET")375 self.scratchDb.createIndex("SkyChip_psf", "IPP_IDET") 360 376 361 377 self.logger.infoPair("created indexes on", "IPP tables") … … 391 407 392 408 def updatePspsUniqueIDs(self,table): 393 sql = "UPDATE "+table+" join (select @r:=@r+1 rownum, objID from \409 sql = "UPDATE "+table+" join (select @r:=@r+1 rownum, diffobjID from \ 394 410 (select @r:=0) r, "+table+" t) as foo using (objID) set \ 395 uniquePsps P2id = ((" +str(self.batchID)+ "*1000000000 ) + rownum)"411 uniquePspsDFid = ((" +str(self.batchID)+ "*1000000000 ) + rownum)" 396 412 try: self.scratchDb.execute(sql) 397 413 except: … … 402 418 Does the processing, i.e. pulling stuff from IPP tables into PSPS tables 403 419 ''' 404 def populatePspsTablesChip(self, chipname, x, y, results, tables):405 # XXX EAM NOTE: drop tables Detection_* here so406 # they do not polute the db?407 # XXX or put an explicit drop at the end of the loop?408 409 # self.logger.infoTitle("Processing " + chipname)410 # this is a bit crude: if the chip is not present, this test will fail and the chip411 # will be (correctly) skipped. would be better to carry that information explicitly ("chip is missing")412 413 # XXX keep this in or not?414 # if not self.scratchDb.astrometricSolutionOK(chipname):415 # self.logger.info("| %5s | ------------- Bad astrometric solution : rejecting ------------ |" % chipname)416 # return False417 418 # does this chip exist in the DVO image table (if NOT, then skip it)419 if not self.scratchDb.haveThisChip(self.imageIDs[chipname], self.sourceIDs[chipname]):420 self.logger.info("| %5s | ------------- Chip not in DVO : rejecting ------------ |" % chipname)421 return False422 423 #self.logger.info("populate stuff ");424 # populate remainder of tables425 self.populateDetectionTable(chipname, results)426 #self.logger.info("successful populate ");427 # now add DVO IDs428 self.updateDvoIDs("Detection_" + chipname, self.imageIDs[chipname])429 #self.logger.info("updated dvoids")430 results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + chipname, "objID")431 #self.logger.info("deleted nulls")432 self.logger.info("add psps unique p2 ids")433 self.updatePspsUniqueIDs("Detection_" + chipname, self.imageIDs[chipname])434 self.updateImageID("Detection_" + chipname, x, y)435 #self.logger.info("updateImageId")436 rowCount = self.scratchDb.getRowCount("Detection_" + chipname)437 #self.logger.info("got row count")438 self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d |",439 chipname,440 results['ORIGINALTOTAL'],441 results['SATDET'],442 results['NULLINSTFLUX'],443 results['NULLOBJID'],444 rowCount)445 self.totalOriginal = self.totalOriginal + results['ORIGINALTOTAL']446 self.totalSatDet = self.totalSatDet + results['SATDET']447 self.totalNulIInstFlux = self.totalNulIInstFlux + results['NULLINSTFLUX']448 self.totalNullObjID = self.totalNullObjID + results['NULLOBJID']449 self.totalDetections = self.totalDetections + rowCount450 451 fractionKept = float(rowCount) / float(results['ORIGINALTOTAL'])452 # print "kept ", str(fractionKept), " detections from ", chipname453 454 if fractionKept < 0.8:455 # print "Too many rejected detections (", str(fractionKept), ", fail on exposure for", chipname456 self.logger.infoPair("Too many rejected detections, fail on exposure for", chipname)457 self.skipBatch = True458 return False;459 460 #self.logger.info("updated totals")461 # check we have something in this Detection table TODO add this to table above462 if rowCount < 1:463 self.logger.infoPair("Empty table for chip, fail on exposure", chipname)464 self.skipBatch = True465 return False;466 467 # update ImageMeta with count of detections for this CHIPNAME and photoCodeID468 sql = "UPDATE ImageMeta_" + chipname + " \469 SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + chipname), self.scratchDb.getPhotoCalID(self.imageIDs[chipname]))470 self.scratchDb.execute(sql)471 472 # add these to list of tables to export later473 self.tablesToExport.append("ImageMeta_" + chipname)474 self.logger.info("export ImageMeta")475 476 self.tablesToExport.append("Detection_" + chipname)477 self.logger.info("export Detection")478 479 tables.append("Detection_" + chipname)480 self.logger.info("updated detection")481 482 self.validChips.append(chipname)483 484 return True485 420 486 421 ''' … … 494 429 self.tablesToExport.append("DiffMeta") 495 430 self.populateDiffMeta() 431 self.logger.infoPair("populated","DiffMeta") 496 432 self.tablesToExport.append("DiffToImage") 497 433 self.populateDiffToImage() 434 self.logger.infoPair("populated","DiffToImage") 498 435 self.tablesToExport.append("DiffDetection") 499 self.populateDiffDetection ()500 436 self.populateDiffDetectionTable() 437 self.logger.infoPair("populated","DiffDetection") 501 438 502 439 … … 575 512 else: self.scratchDb.reportNulls(table.name + "_XY33", showPartials) 576 513 577 578 ''' 579 This function reads the cmf/smf file and loads it into the database as its own table 580 Overriding this method. Filter to only import *.psf extensions 581 ''' 582 def importIppTables(self, filter=""): 583 584 regex = ".*.psf" 585 if False and self.config.test and self.config.camera == "gpc1": 586 regex = "XY01.psf" 514 ''' 515 Imports IPP tables from FITS file 516 Accepts a regular expression to match the tables so not all tables need to be imported 517 (This regex feature is not currently used...) 518 ''' 519 def importIppTables(self, columns="*", tableRE=""): 520 521 if self.config.retry: return True 522 523 self.logger.infoPair("Importing DF tables with table match expression: ", tableRE) 524 525 count = 0 526 fileName = self.fits.getPath() 587 527 588 print "my ID: " + str(self.id) 589 590 if (self.id < 982483): 591 # XXX EAM NOTE : this is fragile : requires PS1_V4 592 columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PSF_MAJOR PSF_MINOR PSF_THETA PSF_QF PSF_QF_PERFECT PSF_CHISQ EXT_NSIGMA MOMENTS_XX MOMENTS_XY MOMENTS_YY MOMENTS_R1 MOMENTS_RH MOMENTS_M3C MOMENTS_M3S MOMENTS_M4C MOMENTS_M4S AP_MAG_RADIUS KRON_FLUX KRON_FLUX_ERR SKY SKY_SIGMA FLAGS FLAGS2" 593 else: 594 # XXX EAM NOTE : this is fragile : requires PS1_V5 595 columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG POSANGLE PLTSCALE PSF_INST_FLUX PSF_INST_FLUX_SIG PSF_FWHM_MAJ PSF_FWHM_MIN PSF_THETA PSF_CORE PSF_QF PSF_QF_PERFECT PSF_CHISQ EXT_NSIGMA MOMENTS_XX MOMENTS_XY MOMENTS_YY MOMENTS_R1 MOMENTS_RH MOMENTS_M3C MOMENTS_M3S MOMENTS_M4C MOMENTS_M4S AP_FLUX AP_FLUX_SIG AP_NPIX AP_MAG_RADIUS KRON_FLUX KRON_FLUX_ERR SKY SKY_SIGMA FLAGS FLAGS2" 596 597 return super(DetectionBatch, self).importIppTables(columns, regex) 528 self.logger.infoPair("using filename:",fileName) 529 530 try: 531 tables = stilts.treads(fileName) 532 except: 533 self.logger.errorPair("STILTS could not import from", fileName) 534 return False 535 536 # count = 0 537 for table in tables: 538 539 match = re.match(tableRE, table.name) 540 if not match: continue 541 542 self.logger.infoPair("Reading IPP table", table.name) 543 table = stilts.tpipe(table, cmd='addcol table_index $0') 544 table = stilts.tpipe(table, cmd='explodeall') 545 546 # drop any previous tables before import 547 self.scratchDb.dropTable(table.name) 548 549 550 # IPP FITS files are littered with infinities, so remove these 551 self.logger.info("Removing Infinity values from all columns") 552 table = stilts.tpipe(table, cmd='keepcols "' + columns + '"') 553 table = stilts.tpipe(table, cmd='replaceval -Infinity null *') 554 table = stilts.tpipe(table, cmd='replaceval Infinity null *') 555 556 try: 557 table.write(self.scratchDb.url + '#' + table.name) 558 count = count + 1 559 except: 560 self.logger.exception("Problem writing table '" + table.name + "' to the database") 561 562 self.logger.infoPair("Done. Imported", "%d tables" % count) 563 self.indexIppTables() 564 565 return True 566 567 568 569 570 598 571 599 572 ''' … … 601 574 ''' 602 575 def exportPspsTablesToFits(self, regex="(.*)"): 603 return super(DetectionBatch, self).exportPspsTablesToFits("([a-zA-Z]+)") 576 return super(DiffBatch, self).exportPspsTablesToFits("([a-zA-Z]+)") 577 578 579 ''' 580 Drop a table and report hte drop 581 ''' 582 def dropTableVerbose(self, table): 583 self.logger.infoPair("dropping table:",table) 584 self.scratchDb.dropTable(table) 585 -
trunk/ippToPsps/jython/gpc1db.py
r37749 r37750 354 354 FROM warpSkyCellMap \ 355 355 JOIN warpRun USING(warp_id) \ 356 JOIN diffInputSkyfile on warp1 = warp_id \ 357 WHERE diffInputSkyfile.diff_skyfile_id = " + str(diffID) + " AS a" 358 359 try: 360 rs = self.executeQuery(sql) 361 except: 356 JOIN diffInputSkyfile on warp1 = warp_id \ 357 JOIN fakeRun using (fake_id) \ 358 JOIN camRun using (cam_id) \ 359 JOIN chipRun using (chip_id) \ 360 WHERE diffInputSkyfile.diff_skyfile_id = " + str(diffID) + ") AS a" 361 362 try: 363 rs = self.executeQuery(sql) 364 except: 365 self.logger.infoPair("failed sql:",sql) 362 366 self.logger.exception("Can't query for imageIDs") 367 363 368 364 369 imageIDs = []
Note:
See TracChangeset
for help on using the changeset viewer.
