Changeset 31109
- Timestamp:
- Apr 1, 2011, 4:25:54 PM (15 years ago)
- Location:
- trunk/ippToPsps/jython
- Files:
-
- 3 edited
-
batch.py (modified) (5 diffs)
-
initbatch.py (modified) (2 diffs)
-
stackbatch.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/batch.py
r31105 r31109 16 16 Constructor 17 17 ''' 18 def __init__(self, batchType, inputFitsPath, outputFitsPath, dbHost, dbName, dbUser, dbPass ):18 def __init__(self, batchType, inputFitsPath, outputFitsPath, dbHost, dbName, dbUser, dbPass, survey): 19 19 20 # set up class variables 20 21 self.pspsVoTableFilePath = "../config/" + batchType + "/tables.vot" 21 22 self.inputFitsPath = inputFitsPath … … 25 26 self.dbUser = dbUser 26 27 self.dbPass = dbPass 28 self.survey = survey 29 30 # set up JDBC connection 27 31 self.url = "jdbc:mysql://"+self.dbHost+"/"+self.dbName+"?user="+self.dbUser+"&password="+self.dbPass 28 32 self.con = DriverManager.getConnection(self.url) 33 self.stmt = self.con.createStatement() 29 34 35 # get survey ID from init table 36 sql = "SELECT surveyID from Survey WHERE name = '" + survey + "'" 37 rs = self.stmt.executeQuery(sql) 38 rs.first() 39 self.surveyID = rs.getInt(1) 40 30 41 # store today's date 31 42 now = datetime.datetime.now(); 32 43 self.dateStr = now.strftime("%Y-%m-%d") 33 44 34 self.parseFitsHeader() 45 if self.inputFitsPath != "": 46 self.parseFitsHeader() 35 47 36 48 ''' … … 38 50 ''' 39 51 def __del__(self): 52 40 53 print "Batch destructor" 54 self.stmt.close() 41 55 self.con.close() 42 56 57 ''' 58 Updates a table with surveyID 59 ''' 60 def updateSurveyID(self, table): 61 62 sql = "UPDATE " + table + " SET surveyID=%d" % self.surveyID 63 self.stmt.execute(sql) 64 65 ''' 66 Updates a table with filterID grabbed from Filter init table 67 ''' 68 def updateFilterID(self, table): 69 70 sql = "UPDATE "+table+" AS a, Filter AS b SET a.filterID=b.filterID WHERE b.filterType = '" + self.filter + "'" 71 self.stmt.execute(sql) 43 72 44 73 ''' … … 87 116 table.write(self.url + '#' + table.name) 88 117 118 self.indexPspsTables() 119 120 ''' 121 Subclass should implement this to index IPP tables 122 ''' 123 def indexIppTables(self): 124 print "indexIppTables not implemented" 125 126 127 ''' 128 Adds an index to the supplied table and column 129 ''' 130 def createIndex(self, table, column): 131 132 print "Creating index on column '"+column+"' for table '"+table+"'" 133 134 sql = "CREATE INDEX "+table+"_index ON "+table+" ("+column+")" 135 try: 136 self.stmt.execute(sql) 137 except: 138 print "Index already in place on '" + column + "' for table '" + table + "'" 139 140 141 ''' 142 Subclass should implement this to index PSPS tables 143 ''' 144 def indexPspsTables(self): 145 print "indexPspsTables not implemented" 146 147 89 148 ''' 90 149 Imports IPP tables from FITS file … … 101 160 except: 102 161 print "ERROR table " + table.name + " is busted" 162 163 self.indexIppTables() 103 164 104 165 ''' -
trunk/ippToPsps/jython/initbatch.py
r31107 r31109 6 6 from batch import Batch 7 7 8 ''' 9 Class encapsulating the init batch type (IN) 10 ''' 8 11 class InitBatch(Batch): 9 12 … … 14 17 super(InitBatch, self).__init__( 15 18 "init", 16 #"/data/ipp053.0/eugene/md04.20110320/staticsky/MD04.V2/skycell.087/MD04.V2.skycell.087.stk.280.000.cmf",17 19 "", 18 20 "init.fits", -
trunk/ippToPsps/jython/stackbatch.py
r31105 r31109 16 16 #"/data/ipp053.0/eugene/md04.20110320/staticsky/MD04.V2/skycell.087/MD04.V2.skycell.087.stk.280.000.cmf", 17 17 "demo.fits", 18 " multi.fits",18 "stack.fits", 19 19 "ippdb01", 20 20 "ippToPsps", 21 21 "ipp", 22 "ipp") 22 "ipp", 23 "MD04") # TODO 24 25 26 27 ''' 28 Updates a table with stackMetaID 29 ''' 30 def updateStackMetaID(self, table): 31 32 sql = "UPDATE " + table + " SET stackMetaID=" + self.header['STK_ID'] 33 self.stmt.execute(sql) 34 35 ''' 36 Updates a table with stackTypeID grabbed from FitModel init table 37 ''' 38 def updateStackTypeID(self, table): 39 40 sql = "UPDATE "+table+" AS a, StackType AS b SET a.stackTypeID=b.stackTypeID WHERE b.name = '"+self.header['STK_TYPE']+"'" 41 self.stmt.execute(sql) 23 42 24 43 … … 26 45 Updates aperture fluxes for StackApFkx table 27 46 ''' 28 def updateApFlxs(self, stmt,prefix, psfCondition):47 def updateApFlxs(self, prefix, psfCondition): 29 48 30 49 sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \ … … 71 90 WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition 72 91 73 s tmt.execute(sql)92 self.stmt.execute(sql) 74 93 75 94 ''' 76 95 Updates parameters for a particular model in the StackModelFit table 77 96 ''' 78 def updateModelFit(self, stmt, model, ippModelType): 97 def updateModelFit(self, model, ippModelType): 98 99 if model == "ser": 100 modelLong = "sersic" 101 else: 102 modelLong = model; 79 103 80 104 sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \ 81 "+model+"Covar11=b.EXT_COVAR_00_00, \ 82 "+model+"Covar12=b.EXT_COVAR_00_01, \ 83 "+model+"Covar13=b.EXT_COVAR_00_02, \ 84 "+model+"Covar14=b.EXT_COVAR_00_03, \ 85 "+model+"Covar15=b.EXT_COVAR_00_04, \ 86 "+model+"Covar16=b.EXT_COVAR_00_05, \ 87 "+model+"Covar17=b.EXT_COVAR_00_06, \ 88 "+model+"Covar22=b.EXT_COVAR_01_01, \ 89 "+model+"Covar23=b.EXT_COVAR_01_02, \ 90 "+model+"Covar24=b.EXT_COVAR_01_03, \ 91 "+model+"Covar25=b.EXT_COVAR_01_04, \ 92 "+model+"Covar26=b.EXT_COVAR_01_05, \ 93 "+model+"Covar27=b.EXT_COVAR_01_06, \ 94 "+model+"Covar33=b.EXT_COVAR_02_02, \ 95 "+model+"Covar34=b.EXT_COVAR_02_03, \ 96 "+model+"Covar35=b.EXT_COVAR_02_04, \ 97 "+model+"Covar36=b.EXT_COVAR_02_05, \ 98 "+model+"Covar37=b.EXT_COVAR_02_06, \ 99 "+model+"Covar44=b.EXT_COVAR_03_03, \ 100 "+model+"Covar45=b.EXT_COVAR_03_04, \ 101 "+model+"Covar46=b.EXT_COVAR_03_05, \ 102 "+model+"Covar47=b.EXT_COVAR_03_06, \ 103 "+model+"Covar55=b.EXT_COVAR_04_04, \ 104 "+model+"Covar56=b.EXT_COVAR_04_05, \ 105 "+model+"Covar57=b.EXT_COVAR_04_06, \ 106 "+model+"Covar66=b.EXT_COVAR_05_05, \ 107 "+model+"Covar67=b.EXT_COVAR_05_06, \ 108 "+model+"Covar77=b.EXT_COVAR_06_06 \ 105 "+model+"Radius=b.EXT_WIDTH_MAJ, \ 106 "+model+"Mag=b.EXT_INST_MAG, \ 107 "+model+"MagErr=b.EXT_INST_MAG_SIG, \ 108 "+model+"Ab=b.EXT_WIDTH_MAJ/b.EXT_WIDTH_MIN, \ 109 "+model+"Phi=b.EXT_THETA, \ 110 "+modelLong+"Covar11=b.EXT_COVAR_00_00, \ 111 "+modelLong+"Covar12=b.EXT_COVAR_00_01, \ 112 "+modelLong+"Covar13=b.EXT_COVAR_00_02, \ 113 "+modelLong+"Covar14=b.EXT_COVAR_00_03, \ 114 "+modelLong+"Covar15=b.EXT_COVAR_00_04, \ 115 "+modelLong+"Covar16=b.EXT_COVAR_00_05, \ 116 "+modelLong+"Covar17=b.EXT_COVAR_00_06, \ 117 "+modelLong+"Covar22=b.EXT_COVAR_01_01, \ 118 "+modelLong+"Covar23=b.EXT_COVAR_01_02, \ 119 "+modelLong+"Covar24=b.EXT_COVAR_01_03, \ 120 "+modelLong+"Covar25=b.EXT_COVAR_01_04, \ 121 "+modelLong+"Covar26=b.EXT_COVAR_01_05, \ 122 "+modelLong+"Covar27=b.EXT_COVAR_01_06, \ 123 "+modelLong+"Covar33=b.EXT_COVAR_02_02, \ 124 "+modelLong+"Covar34=b.EXT_COVAR_02_03, \ 125 "+modelLong+"Covar35=b.EXT_COVAR_02_04, \ 126 "+modelLong+"Covar36=b.EXT_COVAR_02_05, \ 127 "+modelLong+"Covar37=b.EXT_COVAR_02_06, \ 128 "+modelLong+"Covar44=b.EXT_COVAR_03_03, \ 129 "+modelLong+"Covar45=b.EXT_COVAR_03_04, \ 130 "+modelLong+"Covar46=b.EXT_COVAR_03_05, \ 131 "+modelLong+"Covar47=b.EXT_COVAR_03_06, \ 132 "+modelLong+"Covar55=b.EXT_COVAR_04_04, \ 133 "+modelLong+"Covar56=b.EXT_COVAR_04_05, \ 134 "+modelLong+"Covar57=b.EXT_COVAR_04_06, \ 135 "+modelLong+"Covar66=b.EXT_COVAR_05_05, \ 136 "+modelLong+"Covar67=b.EXT_COVAR_05_06, \ 137 "+modelLong+"Covar77=b.EXT_COVAR_06_06 \ 109 138 WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'" 110 139 111 s tmt.execute(sql)140 self.stmt.execute(sql) 112 141 113 142 # sersic fit has an extra parameter 114 143 if ippModelType == "PS_MODEL_SERSIC": 115 144 sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \ 116 "+model +"Covar18=b.EXT_COVAR_00_07, \117 "+model +"Covar28=b.EXT_COVAR_01_07, \118 "+model +"Covar38=b.EXT_COVAR_02_07, \119 "+model +"Covar48=b.EXT_COVAR_03_07, \120 "+model +"Covar58=b.EXT_COVAR_04_07, \121 "+model +"Covar68=b.EXT_COVAR_05_07, \122 "+model +"Covar78=b.EXT_COVAR_06_07, \123 "+model +"Covar88=b.EXT_COVAR_07_07 \145 "+modelLong+"Covar18=b.EXT_COVAR_00_07, \ 146 "+modelLong+"Covar28=b.EXT_COVAR_01_07, \ 147 "+modelLong+"Covar38=b.EXT_COVAR_02_07, \ 148 "+modelLong+"Covar48=b.EXT_COVAR_03_07, \ 149 "+modelLong+"Covar58=b.EXT_COVAR_04_07, \ 150 "+modelLong+"Covar68=b.EXT_COVAR_05_07, \ 151 "+modelLong+"Covar78=b.EXT_COVAR_06_07, \ 152 "+modelLong+"Covar88=b.EXT_COVAR_07_07 \ 124 153 WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'" 125 154 126 s tmt.execute(sql)155 self.stmt.execute(sql) 127 156 128 157 … … 130 159 Populates the StackMeta table, mainly from dictionary values found in IPP FITS header 131 160 ''' 132 def populateStackMeta(self , stmt):161 def populateStackMeta(self): 133 162 print "Procesing StackMeta table"; 134 163 … … 169 198 )" 170 199 print sql 171 stmt.execute(sql) 200 self.stmt.execute(sql) 201 202 self.updateSurveyID("StackMeta") 203 self.updateFilterID("StackMeta") 204 self.updateStackTypeID("StackMeta") 172 205 173 206 ''' 174 207 Populates the StackDetection table 175 208 ''' 176 def populateStackDetection(self , stmt):209 def populateStackDetection(self): 177 210 print "Procesing StackDetection table"; 178 211 179 212 # insert all the detections 180 sql = "INSERT INTO StackDetection \ 181 (ippDetectID, xPos, yPos, xPosErr, yPosErr, instFlux, instFluxErr, sky, skyErr, sgSep, psfWidMajor, psfWidMinor, psfTheta, psfCf, nFrames) \ 213 sql = "INSERT INTO StackDetection (\ 214 ippDetectID \ 215 ,xPos \ 216 ,yPos \ 217 ,xPosErr \ 218 ,yPosErr \ 219 ,instFlux \ 220 ,instFluxErr \ 221 ,peakFlux \ 222 ,sky \ 223 ,skyErr \ 224 ,sgSep \ 225 ,psfWidMajor \ 226 ,psfWidMinor \ 227 ,psfTheta \ 228 ,psfCf \ 229 ,nFrames \ 230 ) \ 182 231 SELECT \ 183 IPP_IDET, X_PSF, Y_PSF, X_PSF_SIG, Y_PSF_SIG, PSF_INST_FLUX, PSF_INST_FLUX_SIG, SKY, SKY_SIGMA, EXT_NSIGMA, PSF_MAJOR, PSF_MINOR, PSF_THETA, PSF_QF, N_FRAMES \ 232 IPP_IDET \ 233 ,X_PSF \ 234 ,Y_PSF \ 235 ,X_PSF_SIG \ 236 ,Y_PSF_SIG \ 237 ,PSF_INST_FLUX \ 238 ,PSF_INST_FLUX_SIG \ 239 ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / "+self.header['EXPTIME']+" \ 240 ,SKY \ 241 ,SKY_SIGMA \ 242 ,EXT_NSIGMA \ 243 ,PSF_MAJOR \ 244 ,PSF_MINOR \ 245 ,PSF_THETA \ 246 ,PSF_QF \ 247 ,N_FRAMES \ 184 248 FROM SkyChip_psf" 185 249 186 stmt.execute(sql) 250 self.stmt.execute(sql) 251 252 if self.header['STK_TYPE'] != "NIGHTLY_STACK": 253 sql = "UPDATE StackDetection SET obsTime = " + self.header['MJD-OBS'] 254 self.stmt.execute(sql) 187 255 188 256 189 257 sql = "UPDATE StackDetection SET skycellID = " + self.skycell + ", assocDate = '"+self.dateStr+"'" 190 stmt.execute(sql) 191 192 ''' 193 Populates the StackModelFit table 194 ''' 195 def populateStackModelFit(self, stmt): 196 print "Procesing StackModelFit table"; 197 198 # insert all the detections 199 sql = "INSERT INTO StackModelFit (ippDetectID) SELECT DISTINCT IPP_IDET from SkyChip_xfit" 200 stmt.execute(sql) 201 202 # populate model parameters 203 print " Adding deVaucouleurs fit" 204 self.updateModelFit(stmt, "deV", "PS_MODEL_DEV") 205 print " Adding exponential fit" 206 self.updateModelFit(stmt, "exp", "PS_MODEL_EXP") 207 print " Adding sersic fit" 208 self.updateModelFit(stmt, "sersic", "PS_MODEL_SERSIC") 209 258 self.stmt.execute(sql) 259 self.updateSurveyID("StackDetection") 260 self.updateFilterID("StackDetection") 261 self.updateStackMetaID("StackDetection") 262 self.updateStackTypeID("StackDetection") 210 263 211 264 ''' 212 265 Populates the StackApFlx table 213 266 ''' 214 def populateStackApFlx(self , stmt):267 def populateStackApFlx(self): 215 268 print "Procesing StackApFlx table"; 216 269 … … 220 273 DISTINCT IPP_IDET \ 221 274 FROM SkyChip_xrad" 222 s tmt.execute(sql)275 self.stmt.execute(sql) 223 276 224 277 print " Adding 1st convolved fluxes" 225 #self.updateApFlxs(stmt,"c1", "< 7.0")278 self.updateApFlxs("c1", "< 7.0") 226 279 print " Adding 2nd convolved fluxes" 227 # self.updateApFlxs(stmt, "c2", "> 7.0") 228 229 230 # now add in the extended source stuff 231 sql = "UPDATE StackApFlx AS a, SkyChip_xsrc AS b SET petRadius=b.PETRO_RADIUS WHERE a.ippDetectID=b.IPP_IDET" 232 stmt.execute(sql) 280 self.updateApFlxs("c2", "> 7.0") 281 282 print " Adding petrosian stuff for extended sources" 283 sql = "UPDATE StackApFlx AS a, SkyChip_xsrc AS b SET \ 284 petRadius=b.PETRO_RADIUS \ 285 ,petRadiusErr=b.PETRO_RADIUS_ERR \ 286 ,petMag=b.PETRO_MAG \ 287 ,petMagErr=b.PETRO_MAG_ERR \ 288 ,petR50=b.PETRO_RADIUS_50 \ 289 ,petR50Err=b.PETRO_RADIUS_50_ERR \ 290 ,petR90=b.PETRO_RADIUS_90 \ 291 ,petR90Err=b.PETRO_RADIUS_90_ERR \ 292 WHERE a.ippDetectID=b.IPP_IDET" 293 self.stmt.execute(sql) 294 295 self.updateSurveyID("StackApFlx") 296 self.updateFilterID("StackApFlx") 297 self.updateStackMetaID("StackApFlx") 298 self.updateStackTypeID("StackApFlx") 233 299 234 300 #rs = stmt.executeQuery(sql) … … 240 306 241 307 #rs.close() 308 309 ''' 310 Populates the StackModelFit table 311 ''' 312 def populateStackModelFit(self): 313 print "Procesing StackModelFit table"; 314 315 # insert all the detections 316 sql = "INSERT INTO StackModelFit (ippDetectID) SELECT DISTINCT IPP_IDET from SkyChip_xfit" 317 self.stmt.execute(sql) 318 319 # populate model parameters 320 print " Adding deVaucouleurs fit" 321 self.updateModelFit("deV", "PS_MODEL_DEV") 322 print " Adding exponential fit" 323 self.updateModelFit("exp", "PS_MODEL_EXP") 324 print " Adding sersic fit" 325 self.updateModelFit("ser", "PS_MODEL_SERSIC") 326 327 self.updateSurveyID("StackModelFit") 328 self.updateFilterID("StackModelFit") 329 self.updateStackMetaID("StackModelFit") 330 self.updateStackTypeID("StackModelFit") 331 332 333 ''' 334 Applies indexes to the PSPS tables 335 ''' 336 def indexPspsTables(self): 337 338 print "Creating indexes on PSPS tables" 339 self.createIndex("StackDetection", "ippDetectID") 340 self.createIndex("StackApFlx", "ippDetectID") 341 self.createIndex("StackModelFit", "ippDetectID") 342 343 ''' 344 Applies indexes to the IPP tables 345 ''' 346 def indexIppTables(self): 347 348 print "Creating indexes on IPP tables" 349 self.createIndex("SkyChip_psf", "IPP_IDET") 350 self.createIndex("SkyChip_xfit", "IPP_IDET") 351 self.createIndex("SkyChip_xrad", "IPP_IDET") 352 self.createIndex("SkyChip_xsrc", "IPP_IDET") 242 353 243 354 ''' … … 250 361 self.skycell = self.skycell[8:] 251 362 252 stmt = self.con.createStatement() 253 self.populateStackMeta(stmt) 254 self.populateStackDetection(stmt) 255 self.populateStackModelFit(stmt) 256 self.populateStackApFlx(stmt) 257 stmt.close() 363 # get filterID using init table 364 self.filter = self.header['FPA.FILTER'] 365 self.filter = self.filter[0:1] 366 367 self.populateStackMeta() 368 self.populateStackDetection() 369 self.populateStackModelFit() 370 self.populateStackApFlx() 258 371 259 372 … … 263 376 stackBatch.process() 264 377 stackBatch.exportPspsTablesToFits() 265 stackBatch
Note:
See TracChangeset
for help on using the changeset viewer.
