Changeset 38837
- Timestamp:
- Oct 10, 2015, 12:40:44 PM (11 years ago)
- Location:
- trunk/ippToPsps/jython
- Files:
-
- 10 edited
-
batch.py (modified) (2 diffs)
-
detectionbatch.py (modified) (14 diffs)
-
dvo.py (modified) (3 diffs)
-
forcedwarpbatch.py (modified) (2 diffs)
-
ipptopspsdb.py (modified) (5 diffs)
-
mysql.py (modified) (2 diffs)
-
scratchdb.py (modified) (7 diffs)
-
setupScratchDb.py (modified) (2 diffs)
-
sqlUtility.py (modified) (6 diffs)
-
stackbatch.py (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/batch.py
r38602 r38837 234 234 235 235 ''' 236 Returns the stringkeyword value from this header or else "NULL"236 Returns the float keyword value from this header or else "NULL" 237 237 ''' 238 238 def getKeyFloat(self, header, format, key): 239 239 240 240 if key in header: 241 value = f ormat % float(header[key])241 value = float(format % float(header[key])) 242 242 else: 243 243 self.logger.errorPair("Missing header field", key) 244 value = f ormat % -999.9244 value = float(format % -999.9) 245 245 246 246 return value … … 414 414 ''' 415 415 def createEmptyPspsTables(self): 416 print "THIS SUCKS" 417 self.pspsTables = stilts.treads(self.pspsVoTableFilePath) 418 for table in self.pspsTables: 419 self.logger.debug("Creating PSPS table: " + table.name) 420 self.logger.infoPair("creating psps table ",table.name) 421 table.write(self.scratchDb.url + '#' + table.name) 422 self.tablesToExport.append(table.name) 423 424 return True 416 self.pspsTables = stilts.treads(self.pspsVoTableFilePath) 417 for table in self.pspsTables: 418 self.logger.debug("Creating PSPS table: " + table.name) 419 self.logger.infoPair("creating psps table ",table.name) 420 table.write(self.scratchDb.url + '#' + table.name) 421 self.tablesToExport.append(table.name) 422 423 return True 425 424 426 425 ''' -
trunk/ippToPsps/jython/detectionbatch.py
r38810 r38837 3 3 import os.path 4 4 import sys 5 import math 5 6 import glob 6 7 import time … … 184 185 def populateImageMetaTable(self, ota, header): 185 186 187 # the supplied 'header' matches this chip 188 # self.header is the PHU header for this smf 189 186 190 tableName = "ImageMeta_" + ota 187 191 188 # we drop the table before calling this funct oin so it is not left behind on failure192 # we drop the table before calling this function so it is not left behind on failure 189 193 sql = "CREATE TABLE " + tableName + " LIKE ImageMeta" 190 try: self.scratchDb.execute(sql) 191 except: pass 194 self.scratchDb.execute(sql) 192 195 193 196 if (ota[0:2] == "XY"): ccdID = ota[2:4] … … 200 203 psfFwhmMajor = pltscale * self.getKeyFloat(header, "%.8f", 'FWHM_MAJ') 201 204 psfFwhmMinor = pltscale * self.getKeyFloat(header, "%.8f", 'FWHM_MIN') 202 psfF whm = 0.5*(float(psfFwhmMajor) + float(psfFwhmMinor))205 psfFWHM = 0.5*(psfFwhmMajor + psfFwhmMinor) 203 206 204 207 psfmodel_name = self.getKeyValue(header, 'PSFMODEL') … … 207 210 ast_cdx = self.getKeyFloat(header, "%.8f",'AST_CDX') 208 211 ast_cdy = self.getKeyFloat(header, "%.8f",'AST_CDY') 209 astroscat = sqrt(ast_cdx^2 + ast_cdy^2) 212 astroscat = math.sqrt(ast_cdx**2 + ast_cdy**2) 213 214 # Convert detectionThreshold to appropriate magnitudes 215 detectionThreshold = self.getKeyFloat(header, "%.8f", 'DETEFF.MAGREF') 216 expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME') 217 zp = self.getKeyFloat(header, "%.8f", 'ZPT_OBS') 218 219 # XXX zp correction should come from DVO 220 detectionThreshold = detectionThreshold + zp - 2.5 * math.log10(expTime) 210 221 211 222 # insert image metadata into table 212 223 sqlLine = sqlUtility("INSERT INTO " + tableName + "(") 213 224 214 ## extract ZPT_OBS and define the zpFactor, apply to sky, skyScat? 215 216 sqlLine.group("frameID", str(self.expID)) 217 sqlLine.group("ccdID", str(ccdID)) 218 sqlLine.group("bias", str(self.bias)) 219 sqlLine.group("biasScat", str(self.biasScat)) 220 sqlLine.group("sky", self.getKeyFloat(header, "%.8f", 'MSKY_MN')) 221 sqlLine.group("skyScat", self.getKeyFloat(header, "%.8f", 'MSKY_SIG')) 222 sqlLine.group("completMag", self.getKeyFloat(header, "%.8f", 'FLIMIT')) 223 sqlLine.group("astroScat", astroscat) 224 sqlLine.group("photoScat", self.getKeyFloat(self.header, "%.8f", 'ZPT_ERR')) 225 sqlLine.group("numAstroRef", self.getKeyValue(header, 'NASTRO')) 226 sqlLine.group("numPhotoRef", self.getKeyValue(header, 'NASTRO')) 227 sqlLine.group("nAxis1", self.getKeyInt(header, 0, 'NAXIS1')) 228 sqlLine.group("nAxis2", self.getKeyInt(header, 0, 'NAXIS2')) 229 sqlLine.group("psfModelID" psfmodelID) 230 sqlLine.group("psfFwhm", str(psfFwhm)) 231 sqlLine.group("psfWidMajor", psfFwhmMajor) 232 sqlLine.group("psfWidMinor", psfFwhmMinor) 233 sqlLine.group("psfTheta", self.getKeyFloat(header, "%.8f", 'ANGLE')) 234 sqlLine.group("momentMajor", pltscale * self.getKeyFloat(header, "%.8f", 'IQ_FW1')) 235 sqlLine.group("momentMinor", pltscale * self.getKeyFloat(header, "%.8f", 'IQ_FW2')) 236 sqlLine.group("momentM2C", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M2C')) 237 sqlLine.group("momentM2S", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M2S')) 238 sqlLine.group("momentM3", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M3')) 239 sqlLine.group("momentM4", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M4')) 240 sqlLine.group("apResid", self.getKeyFloat(header, "%.8f", 'APMIFIT')) 241 sqlLine.group("dapResid", self.getKeyFloat(header, "%.8f", 'DAPMIFIT')) 242 sqlLine.group("detectorID", self.getKeyValue(header, 'DETECTOR')) 243 sqlLine.group("qaFlags", str(self.scratchDb.getDvoImageFlags(header['IMAGEID']))) 244 sqlLine.group("detrend1", self.getKeyValue(header, 'DETREND.MASK')) 245 sqlLine.group("detrend2", self.getKeyValue(header, 'DETREND.DARK')) 246 sqlLine.group("detrend3", self.getKeyValue(header, 'DETREND.FLAT')) 247 #what happens if it can't find it? 248 # CZW: I think this should properly trap the fringe 249 if self.getKeyValue(header, 'DETREND.FRINGE') != "NULL": 225 sqlLine.group("frameID", self.expID) 226 sqlLine.group("ccdID", ccdID) 227 sqlLine.group("bias", self.bias) 228 sqlLine.group("biasScat", self.biasScat) 229 sqlLine.group("sky", self.getKeyFloat(header, "%.8f", 'MSKY_MN')) 230 sqlLine.group("skyScat", self.getKeyFloat(header, "%.8f", 'MSKY_SIG')) 231 sqlLine.group("detectionThreshold", detectionThreshold) 232 sqlLine.group("astroScat", astroscat) 233 sqlLine.group("photoScat", self.getKeyFloat(header, "%.8f", 'ZPT_ERR')) 234 sqlLine.group("photoZero", zp) 235 sqlLine.group("nAstroRef", self.getKeyValue(header, 'NASTRO')) 236 sqlLine.group("nPhotoRef", self.getKeyValue(header, 'NASTRO')) 237 sqlLine.group("nAxis1", self.getKeyInt(header, 0, 'NAXIS1')) 238 sqlLine.group("nAxis2", self.getKeyInt(header, 0, 'NAXIS2')) 239 sqlLine.group("psfModelID", psfmodelID) 240 sqlLine.group("psfFWHM", psfFWHM) 241 sqlLine.group("psfWidMajor", psfFwhmMajor) 242 sqlLine.group("psfWidMinor", psfFwhmMinor) 243 sqlLine.group("psfTheta", self.getKeyFloat(header, "%.8f", 'ANGLE')) 244 sqlLine.group("momentMajor", pltscale * self.getKeyFloat(header, "%.8f", 'IQ_FW1')) 245 sqlLine.group("momentMinor", pltscale * self.getKeyFloat(header, "%.8f", 'IQ_FW2')) 246 sqlLine.group("momentM2C", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M2C')) 247 sqlLine.group("momentM2S", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M2S')) 248 sqlLine.group("momentM3", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M3')) 249 sqlLine.group("momentM4", pltscale2 * self.getKeyFloat(header, "%.8f", 'IQ_M4')) 250 sqlLine.group("apResid", self.getKeyFloat(header, "%.8f", 'APMIFIT')) 251 sqlLine.group("dapResid", self.getKeyFloat(header, "%.8f", 'DAPMIFIT')) 252 sqlLine.group("detectorID", self.getKeyValue(header, 'DETECTOR')) 253 sqlLine.group("qaFlags", self.scratchDb.getDvoImageFlags(header['IMAGEID'])) 254 sqlLine.group("detrend1", self.getKeyValue(header, 'DETREND.MASK')) 255 sqlLine.group("detrend2", self.getKeyValue(header, 'DETREND.DARK')) 256 sqlLine.group("detrend3", self.getKeyValue(header, 'DETREND.FLAT')) 257 258 # DETREND.FRINGE is not required : check if it is in the header before setting 259 if 'DETREND.FRINGE' in header: 250 260 sqlLine.group("detrend4", self.getKeyValue(header, 'DETREND.FRINGE')) 251 261 … … 256 266 # sqlLine.group("detrend8", " ") 257 267 258 sqlLine.group("photoZero", self.getKeyFloat(self.header, "%.8f", 'ZPT_OBS'))259 268 sqlLine.group("ctype1", self.getKeyValue(header, 'CTYPE1')) 260 269 sqlLine.group("ctype2", self.getKeyValue(header, 'CTYPE2')) … … 307 316 308 317 sql = sqlLine.make(") VALUES ( ", ")") 309 310 try: self.scratchDb.execute(sql) 311 except: 312 self.logger.errorPair('failed sql: ', sql) 313 raise 318 self.scratchDb.execute(sql) 314 319 315 320 self.scratchDb.updateFilterID(tableName, self.filter) 316 321 self.scratchDb.updateAllRows(tableName, "processingVersion", str(self.skychunk.processingVersion)) 322 317 323 if 'NASTRO' in header: self.totalNumPhotoRef = self.totalNumPhotoRef + int(header['NASTRO']) 318 324 self.scratchDb.replaceNullsInThisColumn(tableName, "polyOrder", "0") … … 428 434 # instrumental fluxes in counts/sec and calibrated sizes (arcsec). 429 435 # below, we convert instrumental fluxes to Jy 436 437 # NOTE: math operations below take place in SQL, not JYTHON. thus we use (e.g.) 438 # abs() not math.fabs() 430 439 431 440 sqlLine.group("ippDetectID", "IPP_IDET") … … 644 653 645 654 ota = "XY%d%d" % (x, y) 655 if ota not in self.imageIDs: continue 646 656 647 657 # I need better control over this.. … … 682 692 if x==7 and y==7: continue 683 693 684 extension = "XY%d%d_psf" % (x, y) 694 ota = "XY%d%d" % (x, y) 695 if ota not in self.imageIDs: continue 696 697 extension = ota + "_psf" 685 698 self.scratchDb.createIndex(extension, "IPP_IDET") 699 686 700 # try the test Chip 687 701 self.scratchDb.createIndex("Chip_psf", "IPP_IDET") … … 698 712 699 713 # XXX : EAM 20150925 : is this IGNORE necessary? 700 sql = "UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \ 701 a.objID = b.objID, \ 702 a.detectID = b.detectID, \ 703 a.ippObjID = b.ippObjID, \ 704 a.dvoRegionID = b.catID, \ 705 a.ra = b.ra, \ 706 a.dec = b.dec_, \ 707 a.zp = b.zp, \ 708 a.telluricExt = b.telluricExt, \ 709 a.airmass = b.airmass, \ 710 a.infoFlag3 = b.flags, \ 711 a.expTime = b.expTime, \ 712 a.psfFlux = a.psfFlux * b.zpFactor, \ 713 a.psfFluxErr = a.psfFluxErr * b.zpFactor, \ 714 a.apFlux = a.apFlux * b.zpFactor, \ 715 a.apFluxErr = a.apFluxErr * b.zpFactor, \ 716 a.kronFlux = a.kronFlux * b.zpFactor, \ 717 a.kronFluxErr = a.kronFluxErr * b.zpFactor \ 718 a.sky = a.sky * b.zpFactor, \ 719 a.skyErr = a.skyErr * b.zpFactor \ 720 WHERE a.ippDetectID = b.ippDetectID \ 721 AND b.imageID = " + str(imageID) 722 723 ## a.psfFlux = a.psfFlux * 3630.78 * POW(10.0, -0.4*b.zp), \ 724 ## a.psfFluxErr = a.psfFluxErr * 3630.78 * POW(10.0, -0.4*b.zp), \ 725 ## a.apFlux = a.apFlux * 3630.78 * POW(10.0, -0.4*b.zp), \ 726 ## a.apFluxErr = a.apFluxErr * 3630.78 * POW(10.0, -0.4*b.zp), \ 727 ## a.kronFlux = a.kronFlux * 3630.78 * POW(10.0, -0.4*b.zp), \ 728 ## a.kronFluxErr = a.kronFluxErr * 3630.78 * POW(10.0, -0.4*b.zp) \ 714 sqlLine = sqlUtility("UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET") 715 sqlLine.group("a.objID", "b.objID") 716 sqlLine.group("a.detectID", "b.detectID") 717 sqlLine.group("a.ippObjID", "b.ippObjID") 718 sqlLine.group("a.dvoRegionID", "b.catID") 719 sqlLine.group("a.ra", "b.ra") 720 sqlLine.group("a.dec", "b.dec_") 721 sqlLine.group("a.zp", "b.zp") 722 sqlLine.group("a.telluricExt", "b.telluricExt") 723 sqlLine.group("a.airmass", "b.airmass") 724 sqlLine.group("a.infoFlag3", "b.flags") 725 sqlLine.group("a.expTime", "b.expTime") 726 sqlLine.group("a.psfFlux", "a.psfFlux * b.zpFactor") 727 sqlLine.group("a.psfFluxErr", "a.psfFluxErr * b.zpFactor") 728 sqlLine.group("a.apFlux", "a.apFlux * b.zpFactor") 729 sqlLine.group("a.apFluxErr", "a.apFluxErr * b.zpFactor") 730 sqlLine.group("a.kronFlux", "a.kronFlux * b.zpFactor") 731 sqlLine.group("a.kronFluxErr", "a.kronFluxErr * b.zpFactor") 732 sqlLine.group("a.sky", "a.sky * b.zpFactor") 733 sqlLine.group("a.skyErr", "a.skyErr * b.zpFactor") 734 735 sql = sqlLine.makeEquals("WHERE a.ippDetectID = b.ippDetectID AND b.imageID = " + str(imageID)) 736 737 ## a.psfFlux = a.psfFlux * 3630.78 * POW(10.0, -0.4*b.zp), \ 729 738 730 739 # instrumental flux vs Janskies: … … 741 750 # NOTE: update dvopsps to populate zpFactor = 3630.78 * ten(-0.4*zp) 742 751 743 print sql 744 try: self.scratchDb.execute(sql) 745 except: 746 self.logger.infoPair("failed sql",sql) 747 raise 752 self.scratchDb.execute(sql) 753 748 754 ''' 749 755 Updates table and generates pspsuniqueids … … 929 935 930 936 # update FrameMeta with count OTAs in this file and total number of photometric reference sources 931 sql = "UPDATE FrameMeta SET nOTA = %d, n umPhotoRef = %d" % (otaCount, self.totalNumPhotoRef)937 sql = "UPDATE FrameMeta SET nOTA = %d, nPhotoRef = %d" % (otaCount, self.totalNumPhotoRef) 932 938 self.scratchDb.execute(sql) 933 939 #to make it stop … … 939 945 def removeDuplicateObjects(self): 940 946 941 sql = "DROP TABLE SkinnyObject_All" 942 try: 943 self.scratchDb.execute(sql) 944 except: 945 print "SkinnyObject_All table not yet defined" 947 self.scratchDb.dropTable("SkinnyObject_All") 946 948 947 949 sql = "CREATE TABLE SkinnyObject_All (objID bigint, ippObjID bigint, chipID char(16))" 948 try: 949 self.scratchDb.execute(sql) 950 except: 951 print "failed to create table SkinnyObject_All" 952 raise 950 self.scratchDb.execute(sql) 953 951 954 952 for chipname in self.validChips: … … 956 954 sql = "INSERT INTO SkinnyObject_All (objID, ippObjID, chipID) \ 957 955 SELECT objID, ippObjID, '" + chipname + "' from SkinnyObject_" + chipname 958 try: 959 self.scratchDb.execute(sql) 960 except: 961 print "failed to insert entry SkinnyObject_All: ", chipname 962 raise 963 956 self.scratchDb.execute(sql) 964 957 965 958 Nduplicates = 0 -
trunk/ippToPsps/jython/dvo.py
r38365 r38837 167 167 return False 168 168 169 self.logger.infoSeparator() 170 self.logger.infoPair("DVO SkyTable.fits file", "NOT up-to-date") 171 172 # drop dvoSkyTable (if it exists) 173 sql = "drop TABLE dvoSkyTable" 174 try: self.scratchDb.execute(sql) 175 except: pass 169 # self.logger.infoSeparator() 170 # self.logger.infoPair("DVO SkyTable.fits file", "NOT up-to-date") 171 # print "--- go" 172 173 self.scratchDb.dropTable("dvoSkyTable") 176 174 177 175 # create dvoSkyTable 178 sql = "CREATE TABLE dvoSkyTable (R_MIN REAL, R_MAX REAL, D_MIN REAL, D_MAX REAL, INDEX_INT, NAME CHAR(18))"176 sql = "CREATE TABLE dvoSkyTable (R_MIN REAL, R_MAX REAL, D_MIN REAL, D_MAX REAL, REGION_ID INT, NAME CHAR(18))" 179 177 self.scratchDb.execute(sql) 180 178 … … 196 194 self.logger.infoPair("Adding index to", self.scratchDb.dvoSkyTable) 197 195 198 self.scratchDb.createIndex(self.scratchDb.dvoSkyTable, " INDEX")196 self.scratchDb.createIndex(self.scratchDb.dvoSkyTable, "REGION_ID") 199 197 200 198 self.scratchDb.setImportedThisDvoTable(path) … … 580 578 self.ippToPspsDb.clearIngestedBoxes(self.scratchDb.dbHost) 581 579 582 if True: 583 print "*******************************************************************************" 580 if False: 584 581 self.logger.warning("about to delete detection table and re-ingest; is this correct?") 585 #response = raw_input("(y/n) ")586 #if response != "y":587 #raise588 #self.logger.warning("Are you ABSOLUTELY sure you want to do this?")589 #response = raw_input("(y/n) ")590 #if response != "y":591 #raise582 response = raw_input("(y/n) ") 583 if response != "y": 584 raise 585 self.logger.warning("Are you ABSOLUTELY sure you want to do this?") 586 response = raw_input("(y/n) ") 587 if response != "y": 588 raise 592 589 593 590 # blow away existing dvoDetection table & re-crate -
trunk/ippToPsps/jython/forcedwarpbatch.py
r38827 r38837 404 404 imageID = self.scratchDb.getImageIDFromExternID(self.warpSkyFileID[num]) 405 405 self.logger.infoPair("updating","forcedWarpMeasurement_"+forcedWarpID) 406 406 407 sqlLine = sqlUtility("UPDATE ForcedWarpMeasurement_"+forcedWarpID+" as a, " + self.scratchDb.dvoDetectionTable + " as b SET ") 407 408 sqlLine.group("a.objID", "b.objID") … … 414 415 sqlLine.group("a.FinfoFlag3", "b.flags") 415 416 416 sqlLine.group("a.FpsfFlux", "a.FpsfFlux * b.zpFactor")417 sqlLine.group("a.FpsfFluxErr", "a.FpsfFluxErr * b.zpFactor")418 sqlLine.group("a.FapFlux", "a.FapFlux * b.zpFactor")419 sqlLine.group("a.FapFluxErr", "a.FapFluxErr * b.zpFactor")420 sqlLine.group("a.FkronFlux", "a.FkronFlux * b.zpFactor")421 sqlLine.group("a.FkronFluxErr", "a.FkronFluxErr * b.zpFactor")422 sqlLine.group("a.Fsky", "a.Fsky * b.zpFactor")423 sqlLine.group("a.FskyErr", "a.FskyErr * b.zpFactor")417 sqlLine.group("a.FpsfFlux", "a.FpsfFlux * b.zpFactor") 418 sqlLine.group("a.FpsfFluxErr", "a.FpsfFluxErr * b.zpFactor") 419 sqlLine.group("a.FapFlux", "a.FapFlux * b.zpFactor") 420 sqlLine.group("a.FapFluxErr", "a.FapFluxErr * b.zpFactor") 421 sqlLine.group("a.FkronFlux", "a.FkronFlux * b.zpFactor") 422 sqlLine.group("a.FkronFluxErr", "a.FkronFluxErr * b.zpFactor") 423 sqlLine.group("a.Fsky", "a.Fsky * b.zpFactor") 424 sqlLine.group("a.FskyErr", "a.FskyErr * b.zpFactor") 424 425 425 426 sql = sqlLine.makeEquals("WHERE a.ippDetectID = b.ippDetectID AND b.imageID = " +str( imageID)) -
trunk/ippToPsps/jython/ipptopspsdb.py
r38763 r38837 914 914 915 915 ''' 916 Returns boolean value for this column in clients table 917 ''' 918 def existsClient(self, host, pid): 919 920 sql = "SELECT id FROM clients WHERE host = '" + host + "' AND pid = " + str(pid) + " LIMIT 1" 921 922 try: 923 rs = self.executeQuery(sql) 924 if rs.first() is False: return False 925 except: 926 self.logger.exception("Unable to check if " + host + "-" + str(pid) + " is in clients table") 927 928 return True 929 930 ''' 916 931 Update clients, or inserts it for the first time 917 932 ''' 918 933 def updateClient(self, type, host, pid): 919 934 920 try: 935 if self.existsClient(host, pid): 936 self.execute("UPDATE clients SET timestamp = now() WHERE host = '" + host + "' AND pid = " + str(pid)) 937 else: 921 938 self.insertClient(type, host, pid) 922 except:923 self.execute("UPDATE clients SET timestamp = now() WHERE host = '" + host + "' AND pid = " + str(pid))924 939 925 940 ''' … … 1337 1352 1338 1353 for id in ids: 1339 sql = "INSERT IGNORE INTO pending \ 1354 # why is there an IGNORE here? we have deleted old versions already above 1355 sql = "INSERT INTO pending \ 1340 1356 (box_id, batch_type, stage_id) \ 1341 1357 VALUES \ 1342 1358 (" + str(box_id) + ", '" + batchType + "', " + str(id) + ")" 1343 1359 1344 print sql 1345 try: self.execute(sql) 1346 except: 1347 print "failed to insert into pending" 1348 print "sql: " + sql 1349 raise 1360 self.execute(sql) 1350 1361 1351 1362 ''' … … 1656 1667 def storeAllItems(self, rows): 1657 1668 1658 try: 1659 self.execute("DROP TABLE all_pending") 1660 except: 1661 pass 1669 self.dropTable("all_pending") 1662 1670 1663 1671 self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)") 1664 1672 for row in rows: 1665 1666 1673 try: 1667 1674 sql = "INSERT INTO all_pending (stage_id, ra_bore, dec_bore) \ … … 1678 1685 ''' 1679 1686 def storeAllItemsInDvodb(self, rows, dvo_db, batchType): 1680 1681 #try:1682 # self.execute("DROP TABLE all_pending")1683 #except:1684 # pass1685 1687 1686 1688 #self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)") … … 1699 1701 #self.logger.infoPair("Items written to Db", "%d" % count) 1700 1702 1701 1702 1703 1703 ''' 1704 1704 Gets all items in the all_pending temporary table within the bounds of this box -
trunk/ippToPsps/jython/mysql.py
r37917 r38837 230 230 def dropTable(self, table): 231 231 232 sql = "DROP TABLE " + table232 sql = "DROP TABLE IF EXISTS " + table 233 233 try: self.execute(sql) 234 234 except: return … … 334 334 335 335 stmt = self.con.createStatement() 336 stmt.execute(sql) 336 337 try: stmt.execute(sql) 338 except Exception, e: 339 print "--- Error calling mysql: " 340 print "--- sql: " + sql 341 print "--- " + str(e) 342 os._exit(2) 337 343 stmt.close() 338 344 -
trunk/ippToPsps/jython/scratchdb.py
r38823 r38837 475 475 # drop and create Images table 476 476 self.logger.infoPair("Creating DVO table", dvoImagesTable) 477 sql = "DROP TABLE " + dvoImagesTable 478 479 try: self.execute(sql) 480 except: pass 481 477 self.dropTable(dvoImagesTable) 478 482 479 sql = "CREATE TABLE " + dvoImagesTable + " ( \ 483 480 SOURCE_ID SMALLINT, \ … … 495 492 # now detection table 496 493 self.logger.infoPair("Dropping DVO table", dvoDetectionTable) 497 sql = "DROP TABLE " + dvoDetectionTable + " IF EXISTS" 498 try: self.execute(sql) 499 except: 500 self.logger.errorPair("problem dropping DVO table", dvoDetectionTable) 501 pass 494 self.dropTable(dvoDetectionTable) 502 495 503 496 self.logger.infoPair("Creating DVO table", "dvoDetection") … … 514 507 decErr FLOAT, \ 515 508 zp FLOAT, \ 509 zpFactor FLOAT, \ 516 510 telluricExt FLOAT, \ 517 511 airmass FLOAT, \ … … 554 548 555 549 tableName = self.getDbFriendlyTableName(region + "." + fileType) 556 sql = "DROP TABLE " + tableName 557 try: self.execute(sql) 558 except: 559 self.logger.errorPair("Unable to drop table", tableName) 560 pass 550 self.dropTable(tableName) 561 551 562 552 # deletedDetectionCount = detectionCount - self.getRowCount(self.dvoDetectionTable) … … 583 573 584 574 sql = "set @@max_heap_table_size = " + str(tableSize) 585 try: self.execute(sql) 586 except: 587 self.logger.errorPair("Unable to set max MEMORY table size for ", self.dvoDetectionTable) 588 return False 575 self.execute(sql) 589 576 590 577 # create detections table 591 578 self.logger.infoPair("Creating table", self.dvoDetectionTable) 592 579 sql = "CREATE TABLE " + self.dvoDetectionTable + " LIKE dvoDetection" 593 try: self.execute(sql) 594 except: 595 self.logger.errorPair("Unable to create table", self.dvoDetectionTable) 596 return False 580 self.execute(sql) 597 581 598 582 # XXX changing the dvoDetectionFull table to MEMORY … … 660 644 661 645 sql = "SELECT \ 662 INDEX_, \646 REGION_ID, \ 663 647 R_MIN+ (R_MAX - R_MIN)/2.0, \ 664 648 D_MIN + (D_MAX - D_MIN)/2.0, \ … … 689 673 690 674 region = "" 691 sql = "SELECT NAME FROM " + self.dvoSkyTable + " WHERE INDEX_= " + str(index)675 sql = "SELECT NAME FROM " + self.dvoSkyTable + " WHERE REGION_ID = " + str(index) 692 676 try: 693 677 rs = self.executeQuery(sql) -
trunk/ippToPsps/jython/setupScratchDb.py
r35178 r38837 88 88 self.logger.infoPair("Installing", "initialization tables") 89 89 tablepath = self.config.configDir + "tables.IN.vot" 90 tables = stilts.treads(tablepath) 90 try: 91 tables = stilts.treads(tablepath) 92 except Exception, e: 93 print "--- problem reading tables.IN.vot" 94 print "--- " + str(e) 95 os._exit(3) 91 96 92 97 for table in tables: … … 94 99 self.logger.infoPair("Creating IN table: ", table.name) 95 100 self.logger.debug("Creating IN table: " + table.name) 96 table.write(self.scratchDb.url + '#' + table.name) 101 try: table.write(self.scratchDb.url + '#' + table.name) 102 except Exception, e: print "--- " + str(e) 97 103 98 104 # create basic DVO tables -
trunk/ippToPsps/jython/sqlUtility.py
r37246 r38837 12 12 self.fields = [] 13 13 self.values = [] 14 self.startString = st artString14 self.startString = str(startString) 15 15 return 16 16 17 17 def group(self,field,value): 18 self.fields.append(field) 19 self.values.append(value) 18 self.fields.append(str(field)) 19 self.values.append(str(value)) 20 print "* " + str(field) + " = " + str(value) 20 21 return 21 22 … … 30 31 output += ", " 31 32 32 output += " " + middleString+ " "33 output += " " + str(middleString) + " " 33 34 34 35 for i in range(len(self.values)): … … 37 38 output += ", " 38 39 39 output += " " + endString40 output += " " + str(endString) 40 41 41 42 return output … … 51 52 output += ", " 52 53 53 output += " " + middleString+ " "54 output += " " + str(middleString) + " " 54 55 55 56 for i in range(len(self.values)): … … 58 59 output += ", " 59 60 60 output += " " + endString61 output += " " + str(endString) 61 62 62 63 return output … … 72 73 output += ", " 73 74 74 output += " " + endString75 output += " " + str(endString) 75 76 76 77 return output -
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.
