Changeset 38837 for trunk/ippToPsps/jython/detectionbatch.py
- Timestamp:
- Oct 10, 2015, 12:40:44 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/detectionbatch.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
