Changeset 38837 for trunk/ippToPsps/jython/stackbatch.py
- Timestamp:
- Oct 10, 2015, 12:40:44 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/stackbatch.py (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/stackbatch.py
r38826 r38837 160 160 self.dropTableVerbose(tableName) 161 161 162 self.dropTableVerbose("StackMeta") 162 163 self.dropTableVerbose("StackObjectThin") 163 164 self.dropTableVerbose("StackObjectAttributes") … … 176 177 177 178 self.dropTableVerbose("StackToImage") 179 self.dropTableVerbose("StackDetEffMeta") 178 180 179 181 # delete IPP tables … … 217 219 218 220 header = self.headerSet[filter] 219 tablename = filter + "StackMeta" 221 220 222 stackID = self.stackIDs[filter] 221 223 filterName = filter + ".00000" 222 224 223 self.logger.infoPair("Populating table", tablename)224 225 fwhm_maj = self.getKeyFloat(header, "%.8f", 'FWHM_MAJ')226 fwhm_maj_uq = self.getKeyFloat(header, "%.8f", 'FW_MJ_UQ')227 psfmodel_name = self.getKeyValue(header, 'PSFMODEL')228 psfmodelID = self.scratchDb.getFitModelID(psfmodel_name)229 230 ast_cdx = self.getKeyFloat(header, "%.8f",'AST_CDX')231 ast_cdy = self.getKeyFloat(header, "%.8f",'AST_CDY')232 astroscat = sqrt(ast_cdx^2 + ast_cdy^2)233 234 225 # make a table 235 226 filterID = self.scratchDb.getFilterID(filter) … … 238 229 photoCalID = str(self.scratchDb.getPhotoCalID(stackID)) 239 230 231 tablename = filter + "StackMeta" 232 233 sql = "CREATE TABLE " + tablename + " LIKE StackMeta" 234 self.scratchDb.execute(sql) 235 236 self.logger.infoPair("Populating table", tablename) 237 238 # fwhm_maj = self.getKeyFloat(header, "%.8f", 'FWHM_MAJ') 239 # fwhm_maj_uq = self.getKeyFloat(header, "%.8f", 'FW_MJ_UQ') 240 241 # XXX hard-wired platescale : 0.25 242 pltscale = 0.25 243 pltscale2 = pltscale * pltscale 244 245 psfFwhmMajor = pltscale * self.getKeyFloat(header, "%.8f", 'FWHM_MAJ') 246 psfFwhmMinor = pltscale * self.getKeyFloat(header, "%.8f", 'FWHM_MIN') 247 psfFWHM = 0.5*(psfFwhmMajor + psfFwhmMinor) 248 249 psfmodel_name = self.getKeyValue(header, 'PSFMODEL') 250 psfmodelID = self.scratchDb.getFitModelID(psfmodel_name) 251 252 ast_cdx = self.getKeyFloat(header, "%.8f",'AST_CDX') 253 ast_cdy = self.getKeyFloat(header, "%.8f",'AST_CDY') 254 astroscat = math.sqrt(ast_cdx**2 + ast_cdy**2) 255 240 256 # Convert detectionThreshold to appropriate magnitudes 241 257 detectionThreshold = self.getKeyFloat(header, "%.8f", 'DETEFF.MAGREF') 242 258 expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME') 243 zp = self.getKeyFloat(header, "%.8f", 'FPA.ZP') 244 # CZW check? 259 zp = self.getKeyFloat(header, "%.8f", 'ZPT_OBS') 260 261 # XXX zp correction should come from DVO 245 262 detectionThreshold = detectionThreshold + zp - 2.5 * math.log10(expTime) 246 263 247 248 # mysql is sensitive to values which are ambiugously float. eg 249 # a warning is raised if we try to insert '25.' into a float field. 250 # use getKeyFloat(hdr, format, key) to avoid this problem 251 252 sql = "CREATE TABLE " + tablename + " LIKE StackMeta" 253 try: self.scratchDb.execute(sql) 254 except: pass 255 264 # insert stack metadata into table 256 265 sqlLine = sqlUtility("INSERT INTO " + tablename + " (") 257 266 258 sqlLine.group("stackImageID", str(stackID)) 259 sqlLine.group("batchID", str(self.batchID)) 260 sqlLine.group("surveyID", str(self.surveyID)) 261 sqlLine.group("filterID", str(filterID)) 262 sqlLine.group("stackTypeID", str(self.stackTypeID)) 263 sqlLine.group("tessID", str(self.tessID)) 264 sqlLine.group("projectionID", str(self.projectionID)) 265 sqlLine.group("skyCellID", str(self.skycellID)) 266 sqlLine.group("photoCalID", photoCalID) 267 sqlLine.group("analysisVer", str(self.analysisVer)) 268 sqlLine.group("detectionThreshold", detectionThreshold) 269 sqlLine.group("expTime", self.getKeyFloat(header, "%.5f", 'EXPTIME')) 270 sqlLine.group("psfModelID", psfmodelID) 271 sqlLine.group("psfFwhm_mean", fwhm_maj) 272 sqlLine.group("psfFwhm_max", fwhm_maj_uq) 273 sqlLine.group("astroScat", astroscat) 274 sqlLine.group("photoZero", self.getKeyFloat(header, "%.5f", 'FPA.ZP')) 275 sqlLine.group("ctype1", header['CTYPE1']) 276 sqlLine.group("ctype2", header['CTYPE2']) 277 sqlLine.group("crval1", self.getKeyFloat(header, "%.8f", 'CRVAL1')) 278 sqlLine.group("crval2", self.getKeyFloat(header, "%.8f", 'CRVAL2')) 279 sqlLine.group("crpix1", self.getKeyFloat(header, "%.8f", 'CRPIX1')) 280 sqlLine.group("crpix2", self.getKeyFloat(header, "%.8f", 'CRPIX2')) 281 sqlLine.group("cdelt1", self.getKeyFloat(header, "%.8e", 'CDELT1')) 282 sqlLine.group("cdelt2", self.getKeyFloat(header, "%.8e", 'CDELT2')) 283 sqlLine.group("pc001001", self.getKeyFloat(header, "%.8e", 'PC001001')) 284 sqlLine.group("pc001002", self.getKeyFloat(header, "%.8e", 'PC001002')) 285 sqlLine.group("pc002001", self.getKeyFloat(header, "%.8e", 'PC002001')) 286 sqlLine.group("pc002002", self.getKeyFloat(header, "%.8e", 'PC002002')) 287 sqlLine.group("processingVersion", str(self.skychunk.processingVersion)) 267 sqlLine.group("stackImageID", str(stackID)) 268 sqlLine.group("batchID", str(self.batchID)) 269 sqlLine.group("surveyID", str(self.surveyID)) 270 sqlLine.group("filterID", str(filterID)) 271 sqlLine.group("stackTypeID", str(self.stackTypeID)) 272 sqlLine.group("tessID", str(self.tessID)) 273 sqlLine.group("projectionID", str(self.projectionID)) 274 sqlLine.group("skyCellID", str(self.skycellID)) 275 sqlLine.group("photoCalID", photoCalID) 276 sqlLine.group("analysisVer", str(self.analysisVer)) 277 sqlLine.group("detectionThreshold", detectionThreshold) 278 sqlLine.group("expTime", self.getKeyFloat(header, "%.5f", 'EXPTIME')) 279 sqlLine.group("psfModelID", psfmodelID) 280 sqlLine.group("psfFWHM", psfFWHM) 281 sqlLine.group("psfWidMajor", psfFwhmMajor) 282 sqlLine.group("psfWidMinor", psfFwhmMinor) 283 sqlLine.group("psfTheta", self.getKeyFloat(header, "%.8f", 'ANGLE')) 284 # sqlLine.group("psfFwhm_mean", fwhm_maj) 285 # sqlLine.group("psfFwhm_max", fwhm_maj_uq) 286 sqlLine.group("astroScat", astroscat) 287 sqlLine.group("photoZero", zp) 288 sqlLine.group("ctype1", header['CTYPE1']) 289 sqlLine.group("ctype2", header['CTYPE2']) 290 sqlLine.group("crval1", self.getKeyFloat(header, "%.8f", 'CRVAL1')) 291 sqlLine.group("crval2", self.getKeyFloat(header, "%.8f", 'CRVAL2')) 292 sqlLine.group("crpix1", self.getKeyFloat(header, "%.8f", 'CRPIX1')) 293 sqlLine.group("crpix2", self.getKeyFloat(header, "%.8f", 'CRPIX2')) 294 sqlLine.group("cdelt1", self.getKeyFloat(header, "%.8e", 'CDELT1')) 295 sqlLine.group("cdelt2", self.getKeyFloat(header, "%.8e", 'CDELT2')) 296 sqlLine.group("pc001001", self.getKeyFloat(header, "%.8e", 'PC001001')) 297 sqlLine.group("pc001002", self.getKeyFloat(header, "%.8e", 'PC001002')) 298 sqlLine.group("pc002001", self.getKeyFloat(header, "%.8e", 'PC002001')) 299 sqlLine.group("pc002002", self.getKeyFloat(header, "%.8e", 'PC002002')) 300 sqlLine.group("processingVersion", str(self.skychunk.processingVersion)) 288 301 289 302 sql = sqlLine.make(") VALUES ( ", ")") … … 536 549 continue 537 550 551 cmfTable = filter + "SkyChip_xsrc" 552 if not cmfTable in self.tablesLoaded: 553 self.logger.infoPair("no xsrc data for filter" , filter) 554 continue 555 538 556 # insert all the detections 539 sqlLine = sqlUtility("UPDATE " + tablename + " AS a , " + filter + "SkyChip_xsrcAS b SET")557 sqlLine = sqlUtility("UPDATE " + tablename + " AS a , " + cmfTable + " AS b SET") 540 558 541 559 sqlLine.group("a."+filter+"haveData", "'1'") … … 612 630 return True 613 631 614 if self.scratchDb.getRowCount(filter+"SkyChip_xfit") <=0 : 632 cmfTable = filter + "SkyChip_xfit" 633 if not cmfTable in self.tablesLoaded: 634 self.logger.infoPair("no xfit data for filter" , filter) 635 return True 636 637 if self.scratchDb.getRowCount(cmfTable) <=0 : 615 638 self.logger.infoPair("no extended source information, trying to skip",filter) 616 639 return True … … 621 644 magtime = "%.5f" % (2.5*math.log10(float(header['EXPTIME']))) 622 645 623 sqlLine = sqlUtility("UPDATE " + tablename + " AS a, " + filter + "SkyChip_xfitAS b SET")646 sqlLine = sqlUtility("UPDATE " + tablename + " AS a, " + cmfTable + " AS b SET") 624 647 625 648 sqlLine.group("a."+filter+"haveData", "'1'") … … 775 798 return True 776 799 777 if self.scratchDb.getRowCount(filter+"SkyChip_xsrc") <=0 : 778 self.logger.infoPair("no extended source information, trying to skip",filter) 800 cmfTable = filter + "SkyChip_xsrc" 801 if not cmfTable in self.tablesLoaded: 802 self.logger.infoPair("no xsrc data for filter" , filter) 779 803 return True 780 804 805 if self.scratchDb.getRowCount(cmfTable) <=0 : 806 self.logger.infoPair("no extended source information, trying to skip", filter) 807 return True 781 808 782 809 header = self.headerSet[filter] … … 790 817 791 818 self.logger.infoPair("Adding", "petrosians for extended sources") 792 sqlLine = sqlUtility("UPDATE " + tablename + " AS a, " + filter + "SkyChip_xsrcAS b SET")819 sqlLine = sqlUtility("UPDATE " + tablename + " AS a, " + cmfTable + " AS b SET") 793 820 794 821 sqlLine.group("a."+filter+"haveData", "'1'") … … 904 931 905 932 # properly -999 these to start with. the default should take 906 # care of this, but does not 933 # care of this, but does not? 907 934 908 935 sqlLine = sqlUtility("UPDATE " + tablename + " SET") … … 925 952 # set the flux values from the cmf file 926 953 cmfTable = filter + "SkyChip_xrad" 954 955 # skip this table if it was not loaded from the cmf 956 if not cmfTable in self.tablesLoaded: 957 self.logger.infoPair("no xrad data for filter" , filter) 958 return True 927 959 928 960 # we have variable numbers of these columns. find out which are in use … … 1057 1089 sql += " AND " 1058 1090 1059 self.logger.infoPair('sql',sql)1060 1091 self.scratchDb.execute(sql) 1061 1092 … … 1084 1115 1085 1116 self.logger.infoPair("Creating indexes on", "IPP tables") 1086 self.scratchDb.createIndex(filter + "SkyChip_psf", "IPP_IDET") 1087 self.scratchDb.createIndex(filter + "SkyChip_xfit", "IPP_IDET") 1088 self.scratchDb.createIndex(filter + "SkyChip_xrad", "IPP_IDET") 1089 self.scratchDb.createIndex(filter + "SkyChip_xsrc", "IPP_IDET") 1117 1118 cmfTable = filter + "SkyChip_psf" 1119 if cmfTable in self.tablesLoaded: self.scratchDb.createIndex(cmfTable, "IPP_IDET") 1120 1121 cmfTable = filter + "SkyChip_xfit" 1122 if cmfTable in self.tablesLoaded: self.scratchDb.createIndex(cmfTable, "IPP_IDET") 1123 1124 cmfTable = filter + "SkyChip_xrad" 1125 if cmfTable in self.tablesLoaded: self.scratchDb.createIndex(cmfTable, "IPP_IDET") 1126 1127 cmfTable = filter + "SkyChip_xsrc" 1128 if cmfTable in self.tablesLoaded: self.scratchDb.createIndex(cmfTable, "IPP_IDET") 1090 1129 1091 1130 return True … … 1303 1342 self.logger.infoPair("Importing ST tables with table match expression: ", tableRE) 1304 1343 1344 self.tablesLoaded = [] 1345 1305 1346 count = 0 1306 1347 for filter in self.filters: … … 1319 1360 return False 1320 1361 1321 # count = 01322 1362 for table in tables: 1323 1363 … … 1344 1384 self.logger.exception("Problem writing table '" + filter + table.name + "' to the database") 1345 1385 1386 self.tablesLoaded.append(table.name) 1387 1388 # XXX validate required tables (do we need _psf?, _xsrc? etc) 1389 1346 1390 self.logger.infoPair("Done. Imported", "%d tables" % count) 1347 1391 self.indexIppTables()
Note:
See TracChangeset
for help on using the changeset viewer.
