- Timestamp:
- Jan 11, 2015, 1:31:50 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140904/ippToPsps/jython/stackbatch.py
r37246 r37801 73 73 # we just need one valid filter to get the generic metadata 74 74 validFilter = 'none' 75 75 validFilterCount = 0 76 76 # get a list of stackIDs, identify the CMFs, read the headers: 77 77 for filter in self.filters: … … 81 81 stackID = gpc1Db.getStackIDFromSkyIDAndFilter(skychunk.dvoLabel, skyID, filterName) 82 82 self.stackIDs[filter] = stackID 83 83 if (stackID > 0): 84 validFilterCount=validFilterCount + 1 84 85 if (stackID <= 0): 85 86 continue … … 115 116 self.logger.errorPair("can't find any valid stacks...?? ","??") 116 117 raise 118 # did we find any valid stacks? 119 if validFilterCount == 0: 120 self.logger.errorPair("can't find any valid stacks...?? ","??") 121 raise 122 else: 123 self.logger.infoPair("number of filters found:",validFilterCount) 117 124 118 125 validStackID = self.stackIDs[validFilter] … … 154 161 155 162 self.dropTableVerbose("StackObjectThin") 156 self.dropTableVerbose("StackObject Raw")163 self.dropTableVerbose("StackObjectAttributes") 157 164 158 165 self.dropTableVerbose("StackModelFitExtra") … … 162 169 163 170 self.dropTableVerbose("StackApFlx") 164 self.dropTableVerbose("StackApFlx Full")165 self.dropTableVerbose("StackApFlx FullC1")166 self.dropTableVerbose("StackApFlx FullC2")171 self.dropTableVerbose("StackApFlxEGUnc") 172 self.dropTableVerbose("StackApFlxEGCon6") 173 self.dropTableVerbose("StackApFlxEGCon8") 167 174 168 175 self.dropTableVerbose("StackPetrosian") … … 284 291 self.selectDvoObjIDs() 285 292 293 self.generateRandomIDs() 294 295 self.generateStackDetectRowIDsAndPspsUniqueIDs() 296 286 297 # add indexes StackObjectThin 287 298 self.scratchDb.createIndex("StackObjectThin", "objID") … … 325 336 sqlLine.group("a."+filter+"ApMag", "b.Map") 326 337 sqlLine.group("a."+filter+"ApMagErr", "b.dMap") 327 sqlLine.group("a."+filter+"telluricExt", "b.telluricExt")338 # sqlLine.group("a."+filter+"telluricExt", "b.telluricExt") 328 339 329 340 sqlLine.group("a."+filter+"infoFlag2", "(b.flags << 13)") … … 365 376 366 377 ''' 367 Populates the StackObject Rawtable368 ''' 369 def populateStackObject Raw(self):370 371 tablename = "StackObject Raw"378 Populates the StackObjectAttributes table 379 ''' 380 def populateStackObjectAttributes(self): 381 382 tablename = "StackObjectAttributes" 372 383 373 384 self.logger.infoPair("Procesing table", tablename) 374 385 self.insertDvoIDs(tablename, "StackObjectThin") 375 386 376 387 # if we are going to add a key, do it here so it is useful 377 388 self.scratchDb.createIndex(tablename, "objID") … … 420 431 sqlLine.group("a."+filter+"KronFluxErr", "b.KRON_FLUX_ERR / " + str(exptime)) 421 432 sqlLine.group("a."+filter+"ApFillFac", "b.AP_NPIX / (3.14159265359 * POW(b.AP_MAG_RADIUS - 0.5, 2))") 422 sqlLine.group("a."+filter+"ApRadius", "b.AP_MAG_RADIUS")433 # sqlLine.group("a."+filter+"ApRadius", "b.AP_MAG_RADIUS") 423 434 sqlLine.group("a."+filter+"KronRad", "b.MOMENTS_R1 * 2.5") 424 435 sqlLine.group("a."+filter+"PlateScale", "b.PLTSCALE") … … 430 441 except: 431 442 self.logger.errorPair('failed sql',sql) 432 r eturn443 raise 433 444 434 445 # insert detection information for each filter based on the DVO contents … … 446 457 except: 447 458 self.logger.errorPair('failed sql',sql) 448 r eturn459 raise 449 460 450 461 … … 549 560 # insert detection information for each filter based on the 550 561 # DVO contents. Since I already have extracted 551 # StackObject Raw, this is probably faster using that table:562 # StackObjectAttributes, this is probably faster using that table: 552 563 sqlLine = sqlUtility("UPDATE " + tablename + " AS a, " + self.scratchDb.dvoDetectionTable + " as b SET") 553 564 sqlLine.group("a." + filter + model + "Mag", "a." + filter + model + "Mag + b.zp") 554 sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID") 555 565 sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID" + " AND b.imageID = " + str(self.imageIDs[filter])) 556 566 try: 557 567 self.scratchDb.execute(sql) 558 568 except: 559 569 self.logger.errorPair('failed sql',sql) 560 return 561 570 raise 562 571 # we have (modulo signs): 563 572 # gRaExp = gra + (X_EXT - gxPos)*gPlateScale / cos(gdec) … … 583 592 584 593 # insert detection information for each filter based on the DVO contents 585 sqlLine = sqlUtility("UPDATE " + tablename + " AS a, StackObjectThin as b, StackObject Rawas c SET ")594 sqlLine = sqlUtility("UPDATE " + tablename + " AS a, StackObjectThin as b, StackObjectAttributes as c SET ") 586 595 sqlLine.group(extR, rawR + " - (" + extR + " - " + rawX + ")*" + rawS + " / 3600.0 / cos(radians(" + rawD + "))") 587 596 sqlLine.group(extD, rawD + " + (" + extD + " - " + rawY + ")*" + rawS + " / 3600.0") … … 596 605 except: 597 606 self.logger.errorPair('failed sql',sql) 598 r eturn607 raise 599 608 600 609 ''' … … 655 664 sqlLine.group("a." + filter + "petCf", "b.PETRO_FILL") 656 665 657 sql = sqlLine.makeEquals("WHERE a." + filter + "ippDetectID = b.IPP_IDET ")666 sql = sqlLine.makeEquals("WHERE a." + filter + "ippDetectID = b.IPP_IDET ") 658 667 659 668 try: self.scratchDb.execute(sql) … … 670 679 except: 671 680 self.logger.errorPair('failed sql',sql) 672 r eturn681 raise 673 682 674 683 ''' … … 690 699 691 700 for filter in self.filters: 692 self.populateStackApFlxFilter(tablename, " ", filter)693 self.populateStackApFlxFilter(tablename, "C 1", filter)694 self.populateStackApFlxFilter(tablename, "C 2", filter)701 self.populateStackApFlxFilter(tablename, "Unc", filter) 702 self.populateStackApFlxFilter(tablename, "Con6", filter) 703 self.populateStackApFlxFilter(tablename, "Con8", filter) 695 704 696 705 self.deleteRowsWithNoStackData(tablename) … … 698 707 699 708 ''' 700 Populates the StackApFlx Fulltable701 ''' 702 def populateStackApFlx Full(self, version):703 704 tablename = "StackApFlx Full" + version709 Populates the StackApFlxEG table 710 ''' 711 def populateStackApFlxEG(self, version): 712 713 tablename = "StackApFlxEG" + version 705 714 706 715 if self.config.camera == "simtest": … … 721 730 722 731 ''' 723 Updates aperture fluxes for StackApF kx table732 Updates aperture fluxes for StackApFlx table 724 733 ''' 725 734 def populateStackApFlxFilter(self, tablename, version, filter): … … 728 737 729 738 # order of the 3 convolutions is fixed (raw, C1, C2) = (1, 2, 3) 730 if version == " ":739 if version == "Unc": 731 740 psfCondition = "(b.table_index % 3 = 1)" 732 741 prefix = "" 733 if version == "C 1":742 if version == "Con6": 734 743 psfCondition = "(b.table_index % 3 = 2)" 735 prefix = "c 1"736 if version == "C 2":744 prefix = "c6" 745 if version == "Con8": 737 746 psfCondition = "(b.table_index % 3 = 0)" 738 prefix = "c 2"747 prefix = "c8" 739 748 740 749 if prefix == "none": … … 769 778 except: 770 779 self.logger.errorPair('failed sql',sql) 771 r eturn780 raise 772 781 773 782 # set the flux values from the cmf file … … 833 842 sqlLine.group(field + "Err", field + "err" + " * POW(10, 3.56 - 0.4* b.zp)") 834 843 sqlLine.group(field + "Std", field + "Std" + " * POW(10, 3.56 - 0.4* b.zp)") 835 sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID ")844 sql = sqlLine.makeEquals("WHERE a.objID = b.objID AND a." + filter + "ippDetectID = b.ippDetectID AND b.imageID = " + str(self.imageIDs[filter]) ) 836 845 self.scratchDb.execute(sql) 837 846 … … 931 940 932 941 return True 942 943 def generateRandomIDs(self): 944 sql = "UPDATE StackObjectThin set randomStackObjID = FLOOR(RAND("+str(self.batchID)+")*9223372036854775807)" 945 try: self.scratchDb.execute(sql) 946 except: 947 self.logger.errorPair('failed sql',sql) 948 raise 949 950 951 def generateStackDetectRowIDsAndPspsUniqueIDs(self): 952 sql = "UPDATE StackObjectThin join (select @r:=@r+1 rownum, objID from \ 953 (select @r:=0) r, StackObjectThin t) as foo using (objID) set \ 954 stackDetectRowID = ((" + str(self.batchID) + " << 32 ) + rownum), \ 955 uniquePspsSTid = ((" +str(self.batchID)+ "*1000000000 ) + rownum)"; 956 try: self.scratchDb.execute(sql) 957 except: 958 self.logger.errorPair('failed sql',sql) 959 raise 960 933 961 934 962 ''' … … 951 979 sqlLine.group("skyCellID", "'" + str(self.skycellID) + "'") 952 980 sqlLine.group("dataRelease", "'" + str(self.skychunk.dataRelease) + "'") 953 sqlLine.group("randomStackObjID", "FLOOR(RAND()*9223372036854775807)")981 # sqlLine.group("randomStackObjID", "FLOOR(RAND()*9223372036854775807)") 954 982 955 983 whereClause = " WHERE (" … … 971 999 except: 972 1000 self.logger.errorPair('failed sql',sql) 973 r eturn1001 raise 974 1002 975 1003 ''' … … 982 1010 self.scratchDb.addColumn(table, filter + "haveData", "tinyint") 983 1011 984 fields = "objID, ippObjID, randomStackObjID, primaryDetection, bestDetection, "1012 fields = "objID, ippObjID, randomStackObjID, primaryDetection, bestDetection, uniquePspsSTID, " 985 1013 986 1014 for i in range(len(self.filters)): … … 988 1016 fields += filter + "ippDetectID, " 989 1017 fields += filter + "stackDetectID, " 990 fields += filter + "stackMetaID " # careful here: do not add comma to last entry1018 fields += filter + "stackMetaID " # careful here: do not add comma to last entry 991 1019 if (i < len(self.filters) - 1): 992 1020 fields += ", " 993 1021 1022 if (table == "StackObjectAttributes"): 1023 fields += ", stackDetectRowID " 994 1024 sql = "INSERT INTO " + table + " (" + fields + ") " 995 1025 sql += "SELECT " + fields + " FROM " + mainTable … … 998 1028 except: 999 1029 self.logger.errorPair('failed sql',sql) 1000 return 1001 1030 raise 1031 1032 1033 1002 1034 ''' 1003 1035 Does the processing, i.e. pulling stuff from IPP tables into PSPS tables … … 1036 1068 self.populateStackObjectThin() 1037 1069 1038 self.populateStackObject Raw()1070 self.populateStackObjectAttributes() 1039 1071 1040 1072 if self.stackType != "NIGHTLY_STACK": … … 1053 1085 self.populateStackApFlx() 1054 1086 1055 self.populateStackApFlx Full("")1056 self.populateStackApFlx Full("C1")1057 self.populateStackApFlx Full("C2")1087 self.populateStackApFlxEG("Unc") 1088 self.populateStackApFlxEG("Con6") 1089 self.populateStackApFlxEG("Con8") 1058 1090 1059 1091 # delete rows with no content. for the other tables, this is done in … … 1130 1162 self.logger.infoPair("Done. Imported", "%d tables" % count) 1131 1163 self.indexIppTables() 1132 1164 # return False 1133 1165 return True
Note:
See TracChangeset
for help on using the changeset viewer.
