- Timestamp:
- Jun 7, 2014, 5:36:39 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140423/ippToPsps/jython/detectionbatch.py
r35994 r36826 257 257 ,psfWidMinor \ 258 258 ,psfTheta \ 259 ,momentFwhm \ 260 ,momentWidMajor \ 261 ,momentWidMinor \ 259 ,momentXX \ 260 ,momentXY \ 261 ,momentYY \ 262 ,momentM3C \ 263 ,momentM3S \ 264 ,momentM4C \ 265 ,momentM4S \ 266 ,momentR1 \ 267 ,momentRH \ 262 268 ,apResid \ 263 269 ,dapResid \ … … 319 325 ," + self.safeDictionaryAccess(header, 'FWHM_MIN') + " \ 320 326 ," + self.safeDictionaryAccess(header, 'ANGLE') + " \ 321 , ( " + self.safeDictionaryAccess(header, 'IQ_FW1') + " + " + self.safeDictionaryAccess(header, 'IQ_FW2') + " ) / 2.0 \ 322 ," + self.safeDictionaryAccess(header, 'IQ_FW1') + " \ 323 ," + self.safeDictionaryAccess(header, 'IQ_FW2') + " \ 327 ,-999 \ 328 ,-999 \ 329 ,-999 \ 330 ,-999 \ 331 ,-999 \ 332 ,-999 \ 333 ,-999 \ 334 ,-999 \ 335 ,-999 \ 324 336 ," + self.safeDictionaryAccess(header, 'APMIFIT') + " \ 325 337 ," + self.safeDictionaryAccess(header, 'DAPMIFIT') + " \ … … 398 410 sql = "INSERT IGNORE INTO " + pspsTableName + " ( \ 399 411 ippDetectID \ 412 ,randomDetID \ 400 413 ,filterID \ 401 414 ,surveyID \ … … 407 420 ,psfFlux \ 408 421 ,psfFluxErr \ 409 ,peakADU \ 410 ,psfWidMajor \ 411 ,psfWidMinor \ 422 ,psfMajorFWHM \ 423 ,psfMinorFWHM \ 412 424 ,psfTheta \ 425 ,psfCore \ 413 426 ,psfLikelihood \ 414 427 ,psfQf \ … … 416 429 ,momentXY \ 417 430 ,momentYY \ 431 ,momentR1 \ 432 ,momentRH \ 433 ,momentM3C \ 434 ,momentM3S \ 435 ,momentM4C \ 436 ,momentM4S \ 418 437 ,apFlux \ 419 438 ,kronFlux \ … … 424 443 ,sky \ 425 444 ,skyErr \ 426 ,sgSep \ 427 ,activeFlag \ 428 ,assocDate \ 429 ,historyModNum \ 445 ,pltScale \ 446 ,posAngle \ 430 447 ,dataRelease \ 431 448 ) \ 432 449 SELECT \ 433 450 IPP_IDET \ 451 , FLOOR(RAND()*9223372036854775807) \ 434 452 , " + str(self.filterID) + "\ 435 453 , " + str(self.surveyID) + " \ … … 441 459 ,PSF_INST_FLUX / " + self.header['EXPTIME'] + " \ 442 460 ,PSF_INST_FLUX_SIG / " + self.header['EXPTIME'] + " \ 443 ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + self.header['EXPTIME'] + " \444 461 ,PSF_MAJOR \ 445 462 ,PSF_MINOR \ 446 463 ,PSF_THETA \ 464 ,-999 \ 447 465 ,psfLikelihood(EXT_NSIGMA) \ 448 466 ,PSF_QF \ … … 450 468 ,MOMENTS_XY \ 451 469 ,MOMENTS_YY \ 470 ,MOMENTS_R1 \ 471 ,MOMENTS_RH \ 472 ,MOMENTS_M3C \ 473 ,MOMENTS_M3S \ 474 ,MOMENTS_M4C \ 475 ,MOMENTS_M4S \ 452 476 ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \ 453 477 ,KRON_FLUX / " + self.header['EXPTIME'] + " \ … … 458 482 ,SKY / " + self.header['EXPTIME'] + " \ 459 483 ,SKY_SIGMA / " + self.header['EXPTIME'] + " \ 460 ,EXT_NSIGMA \ 461 , 0 \ 462 , '" + self.dateStr + "' \ 463 , 0 \ 484 ,PLTSCALE \ 485 ,POSANGLE \ 464 486 , " + str(self.skychunk.dataRelease) + "\ 465 487 FROM " + ippTableName … … 496 518 # we don't delete these anymore 497 519 results['NULLINSTFLUX'] = 0; 498 results['NULLPEAKADU'] = 0;520 499 521 500 522 ''' … … 531 553 def populateDetectionCalibTableUpdateInsert(self, ota): 532 554 533 tableName = "Detection Calib_" + ota555 tableName = "Detection_" + ota 534 556 # drop then re-create table 535 self.scratchDb.dropTable(tableName)536 sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"537 try: self.scratchDb.execute(sql)538 except: pass557 #self.scratchDb.dropTable(tableName) 558 #sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib" 559 #try: self.scratchDb.execute(sql) 560 #except: pass 539 561 540 562 # insert all detections into table … … 555 577 ,surveyID \ 556 578 FROM Detection_" + ota 557 self.scratchDb.execute(sql)579 # self.scratchDb.execute(sql) 558 580 559 581 # insert calibration information from dvoDetections into the Table … … 564 586 a.decErr = b.decErr, \ 565 587 a.zp = b.zp, \ 566 a.zpErr = b.zpErr, \567 588 a.expTime = b.expTime, \ 568 589 a.airMass = b.airMass \ … … 577 598 578 599 # target table name: 579 tableName = "Detection Calib_" + ota600 tableName = "Detection_" + ota 580 601 # drop then re-create table 581 self.scratchDb.dropTable(tableName)582 sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"583 try: self.scratchDb.execute(sql)584 except: pass602 #self.scratchDb.dropTable(tableName) 603 #sql = "CREATE TABLE " + tableName + " LIKE Detection" 604 #try: self.scratchDb.execute(sql) 605 #except: pass 585 606 586 607 externID = self.imageIDs[ota] 587 608 588 609 imageID = self.scratchDb.getImageIDFromExternID(externID) 589 self.logger.infoPair("obtained","imageID") 590 591 # check for & create output directory first 592 datadumpDir = "/tmp/datadump" 593 try: 594 statinfo = os.stat(datadumpDir) 595 # check on the stat results? 596 except: 597 print "making the data dump directory ", datadumpDir 598 os.mkdir(datadumpDir) 599 os.chmod(datadumpDir, 0777) 600 statinfo = os.stat(datadumpDir) 601 602 dumpFile = datadumpDir + "/genetest.xx.dat" 603 files = glob.glob(dumpFile) 604 if len(files) > 0: 605 os.unlink(dumpFile) 610 self.logger.infoPair("obtained imageID",imageID) 611 self.logger.infoPair("obtained externID",externID) 606 612 607 613 # insert all detections into table 608 sql = "SELECT \ 609 a.objID, \ 610 a.detectID, \ 611 a.ippObjID, \ 612 a.ippDetectID, \ 613 a.filterID, \ 614 a.surveyID, \ 615 b.ra, \ 616 b.dec_, \ 617 b.raErr, \ 618 b.decErr, \ 619 b.zp, \ 620 b.zpErr, \ 621 b.expTime, \ 622 b.airMass, \ 623 " + str(self.skychunk.dataRelease) + " \ 624 FROM \ 625 Detection_" + ota + " as a \ 626 JOIN " + self.scratchDb.dvoDetectionTable + " as b \ 627 ON (a.objID = b.objID AND a.detectID = b.detectID) \ 628 WHERE b.imageID = " + str(imageID) + \ 629 " INTO OUTFILE '" + dumpFile + "'" 614 sql = "Update Detection_" + ota + " AS a, "+ self.scratchDb.dvoDetectionTable + " as b \ 615 set a.ra=b.ra, \ 616 a.dec = b.dec_, \ 617 a.raErr = b.raErr, \ 618 a.decErr = b.decErr, \ 619 a.zp = b.zp, \ 620 a.expTime = b.expTime, \ 621 a.airMass = b.airMass \ 622 WHERE (a.objID = b.objID AND a.detectID = b.detectID) \ 623 AND b.imageID = " + str(imageID) \ 624 630 625 631 626 try: self.scratchDb.execute(sql) 632 627 except: 633 self.logger.info("failed to select data for detectionCalib") 634 self.logger.infoPair("sql: ", sql) 635 raise 636 637 sql = "LOAD DATA INFILE '" + dumpFile + "' INTO TABLE " + tableName 638 try: self.scratchDb.execute(sql) 639 except: 640 self.logger.info("failed to load data from infile for detectionCalib") 628 self.logger.info("failed to update data for detectionCalib") 641 629 self.logger.infoPair("sql: ", sql) 642 630 raise … … 751 739 # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of 752 740 # the column in PSPS 753 self.scratchDb.execute("ALTER TABLE Detection CalibCHANGE dec_ `dec` double")741 self.scratchDb.execute("ALTER TABLE Detection CHANGE dec_ `dec` double") 754 742 755 743 return True … … 818 806 return False 819 807 820 self.logger.info("populate stuff ");808 #self.logger.info("populate stuff "); 821 809 # populate remainder of tables 822 810 self.populateDetectionTable(chipname, results) 823 self.logger.info("successful populate ");811 #self.logger.info("successful populate "); 824 812 # now add DVO IDs 825 813 self.updateDvoIDs("Detection_" + chipname, self.imageIDs[chipname]) 826 self.logger.info("updated dvoids")814 #self.logger.info("updated dvoids") 827 815 results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + chipname, "objID") 828 816 #self.logger.info("deleted nulls") 829 817 self.updateImageID("Detection_" + chipname, x, y) 830 self.logger.info("updateImageId")818 #self.logger.info("updateImageId") 831 819 rowCount = self.scratchDb.getRowCount("Detection_" + chipname) 832 self.logger.info("got row count")833 self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |",820 #self.logger.info("got row count") 821 self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d |", 834 822 chipname, 835 823 results['ORIGINALTOTAL'], 836 824 results['SATDET'], 837 825 results['NULLINSTFLUX'], 838 results['NULLPEAKADU'],839 826 results['NULLOBJID'], 840 827 rowCount) … … 842 829 self.totalSatDet = self.totalSatDet + results['SATDET'] 843 830 self.totalNulIInstFlux = self.totalNulIInstFlux + results['NULLINSTFLUX'] 844 self.totalNullPeakFlux = self.totalNullPeakFlux + results['NULLPEAKADU']845 831 self.totalNullObjID = self.totalNullObjID + results['NULLOBJID'] 846 832 self.totalDetections = self.totalDetections + rowCount … … 867 853 self.scratchDb.execute(sql) 868 854 869 self.logger.info("updated imagedata") 870 self.populateSkinnyObjectTable(chipname) 871 self.logger.info("updated skinnyobject") 872 #self.populateObjectCalColorTable(chipname) 873 #self.logger.info("updated objectcalcolor") 855 #self.logger.info("updated imagedata") 856 874 857 self.populateDetectionCalibTable(chipname) 875 self.logger.info("updated detectioncalibtable")858 #self.logger.info("updated detectioncalibtable") 876 859 877 860 # add these to list of tables to export later … … 882 865 self.logger.info("export Detection") 883 866 884 self.tablesToExport.append("SkinnyObject_" + chipname) 885 self.logger.info("export Skinny") 886 887 #self.tablesToExport.append("ObjectCalColor_" + chipname) 888 self.tablesToExport.append("DetectionCalib_" + chipname) 889 self.logger.info("export DetectionCalib") 890 867 891 868 tables.append("Detection_" + chipname) 892 869 self.logger.info("updated detectioncalibtable") … … 910 887 results = {} 911 888 self.totalOriginal = self.totalSatDet = self.totalNulIInstFlux = self.totalNullPeakFlux = self.totalNullObjID = self.totalDetections = 0 912 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+ ---------------+")913 self.logger.info("| OTA | Initial total | Sat Det | NULL instFlux | NULL peak ADU | NULLobj ID | Remainder |")914 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+ ---------------+")889 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+") 890 self.logger.info("| OTA | Initial total | Sat Det | NULL instFlux | NULL obj ID | Remainder |") 891 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+") 915 892 for x in range(self.startX, self.endX): 916 893 for y in range(self.startY, self.endY): … … 937 914 938 915 # print totals 939 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+ ---------------+")916 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+") 940 917 self.logger.info("| Total | %13d | %13d | %13d | %13d | %13d | %13d |", 941 918 self.totalOriginal, … … 945 922 self.totalNullObjID, 946 923 self.totalDetections) 947 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+ ---------------+")924 self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+") 948 925 949 926 # if we only have one table export, i.e. FrameMeta, then get out of here (skip batch, but do not abort) … … 961 938 sql = "UPDATE FrameMeta SET nOTA = %d, numPhotoRef = %d" % (otaCount, self.totalNumPhotoRef) 962 939 self.scratchDb.execute(sql) 940 #to make it stop 941 #test = self.scratchDb.getRowCount("Object") 942 #return False 963 943 964 944 return True … … 1040 1020 1041 1021 # XXX EAM NOTE : this is fragile : requires PS1_V4 1042 columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ"1022 columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PSF_INST_FLUX PSF_INST_FLUX_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY MOMENTS_R1 MOMENTS_RH MOMENTS_M3C MOMENTS_M3S MOMENTS_M4C MOMENTS_M4S AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ POSANGLE PLTSCALE" 1043 1023 1044 1024 return super(DetectionBatch, self).importIppTables(columns, regex)
Note:
See TracChangeset
for help on using the changeset viewer.
