- 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/gpc1db.py
r37246 r37801 108 108 AND mjd_obs <= (to_days('" + tend + "') - 678941) " 109 109 # self.logger.infoPair("sql",sql) 110 elif batchType == "DF": 110 elif batchType == "DF": # this is specifically only for WARPSTACK types of diffs - 111 # it only makes sense for the date to come from the warp1 112 # may need to be more clever if we do other types of diffs 111 113 112 114 stage = "diff" 113 sql = "SELECT stuff from stufftable" 115 sql = "SELECT DISTINCT stage_extra1, radeg,decdeg \ 116 FROM addRun \ 117 JOIN addProcessedExp using (add_id) \ 118 JOIN minidvodbRun using (minidvodb_name) \ 119 JOIN minidvodbProcessed using (minidvodb_id) \ 120 JOIN mergedvodbRun using (minidvodb_id) \ 121 JOIN mergedvodbProcessed using (merge_id) \ 122 JOIN diffInputSkyfile \ 123 ON (diff_id = stage_id AND diff_skyfile_id = stage_extra1 \ 124 AND stage = 'diff') \ 125 JOIN skycell using (skycell_id, tess_id) \ 126 JOIN warpRun on (warp1 = warp_id \ 127 AND diffInputSkyfile.skycell_id = skycell_id) \ 128 JOIN fakeRun using (fake_id) \ 129 JOIN camRun using (cam_id) \ 130 JOIN chipRun using (chip_id) \ 131 JOIN rawExp using (exp_id) \ 132 WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 133 AND minidvodbRun.state = 'merged' \ 134 AND minidvodbProcessed.fault = 0 \ 135 AND mergedvodbRun.state = 'full' \ 136 AND mergedvodbProcessed.fault = 0 \ 137 AND addRun.stage = '" + stage + "' \ 138 AND addRun.state = 'full' \ 139 AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \ 140 AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \ 141 AND dateobs >= '" + tstart + "'\ 142 AND dateobs <= '" + tend + "'" 143 114 144 115 145 elif batchType == "FW": 116 146 117 147 stage = "forcedwarp" 118 sql = "SELECT differentStuff from Stufftable" 148 sql = "SELECT DISTINCT sky_id, radeg, decdeg FROM fullForceInput \ 149 JOIN addRun ON(fullForceInput.ff_id = addRun.stage_id, fullForceInput.warp_id = addRun.stage_extra1) \ 150 JOIN minidvodbRun USING(minidvodb_name) \ 151 JOIN minidvodbProcessed USING(minidvodb_id) \ 152 JOIN mergedvodbRun USING(minidvodb_id) \ 153 JOIN mergedvodbProcessed USING (merge_id) \ 154 JOIN fullForceRun USING(ff_id) \ 155 JOIN skycalRun using (skycal_id) \ 156 JOIN stackRun USING(stack_id) \ 157 JOIN stackSumSkyfile using (stack_id) \ 158 JOIN skycell USING(skycell_id) \ 159 WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 160 AND minidvodbRun.state = 'merged' \ 161 AND minidvodbProcessed.fault = 0 \ 162 AND mergedvodbRun.state = 'full' \ 163 AND mergedvodbProcessed.fault = 0 \ 164 AND addRun.stage = '" + stage + "' \ 165 AND addRun.state = 'full' \ 166 AND decdeg BETWEEN " + str(minDec) + " AND " + str(maxDec) + " \ 167 AND radeg BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \ 168 AND mjd_obs >= (to_days('" + tstart + "')-678941) \ 169 AND mjd_obs <= (to_days('" + tend + "') - 678941) " 119 170 120 171 try: … … 166 217 return imageIDs 167 218 219 220 221 222 223 168 224 ''' 169 225 Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved … … 196 252 return meta 197 253 254 255 ''' 256 Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved 257 ''' 258 def getDiffStageMeta(self, diffSkyfileID): 259 260 self.logger.debug("Querying GPC1 for stack meta data") 261 262 meta = [] 263 sql = "SELECT \ 264 filter,\ 265 diff_mode, \ 266 warp1, \ 267 stack2, \ 268 skycell_id, \ 269 diffRun.software_ver, \ 270 exp_time, \ 271 (to_days(dateobs)-678941 + time_to_sec(dateobs)/86400.) \ 272 FROM diffRun join diffInputSkyfile using (diff_id) \ 273 JOIN warpRun on (warp1=warp_id) \ 274 JOIN fakeRun using (fake_id) \ 275 JOIN camRun using (cam_id) \ 276 JOIN chipRun using (chip_id) \ 277 JOIN rawExp using (exp_id) \ 278 WHERE diff_skyfile_id = %d" % diffSkyfileID 279 #this is a crappy way to get the mjd from the diff but we don't save it anywhere 280 try: 281 rs = self.executeQuery(sql) 282 rs.first() 283 except: 284 self.logger.infoPair ("this sql is broken:",sql) 285 self.logger.errorPair("Can't query for", "stack meta data") 286 287 try: 288 meta.append(rs.getString(1)) 289 meta.append(rs.getString(2)) 290 meta.append(rs.getString(3)) 291 meta.append(rs.getString(4)) 292 meta.append(rs.getString(5)) 293 meta.append(rs.getString(6)) 294 meta.append(rs.getString(7)) 295 meta.append(rs.getString(8)) 296 except: 297 self.logger.errorPair("getDiffStageMeta()", "empty meta data") 298 299 return meta 300 301 ''' 302 get diff stage cmf name 303 ''' 304 def getDiffStageCmf(self, dvoDb, diffSkyfileID): 305 print "got here, diffstagecmf" 306 sql = "SELECT DISTINCT diffSkyfile.path_base \ 307 FROM mergedvodbRun join minidvodbRun using (minidvodb_id) \ 308 JOIN addRun using (minidvodb_name) \ 309 JOIN diffInputSkyfile on (diff_skyfile_id = stage_extra1 \ 310 AND diff_id = stage_id AND stage = 'diff') \ 311 JOIN diffSkyfile using (diff_id, skycell_id) \ 312 WHERE diff_skyfile_id = " + str(diffSkyfileID) + " \ 313 AND minidvodbRun.state = 'merged' \ 314 AND mergedvodbRun.state = 'full' \ 315 AND mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 316 AND stage = 'diff'" 317 318 try: 319 rs = self.executeQuery(sql) 320 rs.first() 321 except: 322 self.logger.infoPair("failed sql", sql) 323 self.logger.errorPair("can't query for diff cmf", "dfif_skyfile_id = %d" %diff_skyfile_id) 324 return None 325 print "query worked" 326 try: 327 pathBase = rs.getString(1) 328 except: 329 self.logger.errorPair("no diff cms found for diff_skyfile_id = %d" %diff_skyfile_id) 330 return None 331 print pathBase 332 files = [] 333 if pathBase.startswith("neb"): 334 print "open" 335 f=os.popen("neb-ls -p " + pathBase + ".cmf") 336 for i in f.readlines(): 337 print "i",i 338 files.append(i.rstrip()) 339 print "append" 340 print i 341 if len(files) < 1: return None 342 fits = Fits(self.logger, self.config, files[0]) 343 return fits 344 345 ''' 346 Gets a list of PSPS image IDs for this diff ID 347 ''' 348 def getImageIDsForThisDiffID(self, diffID): 349 350 self.logger.debug("Querying GPC1 for image IDs for diff ID: " + str(diffID)) 351 352 # JOIN stackInputSkyfile shoule use stack_id as well as warp_id, right? (maybe not -- the join to warp is first) 353 sql = "SELECT DISTINCT CONCAT(exp_id, SUBSTR(class_id, 3, 4)) FROM ( \ 354 SELECT DISTINCT exp_id,class_id \ 355 FROM warpSkyCellMap \ 356 JOIN warpRun USING(warp_id) \ 357 JOIN diffInputSkyfile on warp1 = warp_id \ 358 JOIN fakeRun using (fake_id) \ 359 JOIN camRun using (cam_id) \ 360 JOIN chipRun using (chip_id) \ 361 WHERE diffInputSkyfile.diff_skyfile_id = " + str(diffID) + ") AS a" 362 363 try: 364 rs = self.executeQuery(sql) 365 except: 366 self.logger.infoPair("failed sql:",sql) 367 self.logger.exception("Can't query for imageIDs") 368 369 370 imageIDs = [] 371 while (rs.next()): 372 imageIDs.append(rs.getString(1)) 373 rs.close() 374 375 return imageIDs 376 377 378 379 380 198 381 ''' 199 382 Gets some camera-stage meta data for this cam_id … … 368 551 def getStackStageCmf(self, dvoDb, stackID): 369 552 370 '''371 sql = "SELECT DISTINCT staticskyResult.path_base \372 FROM staticskyRun \373 JOIN staticskyInput USING(sky_id) \374 JOIN staticskyResult USING(sky_id) \375 JOIN stackRun USING(stack_id) \376 JOIN stackSumSkyfile USING(stack_id) \377 JOIN addRun ON sky_id = stage_id \378 JOIN minidvodbRun USING (minidvodb_name) \379 WHERE stack_id = " + str(stackID) + " \380 AND minidvodbRun.minidvodb_group = '" + dvoDb + "' \381 AND minidvodbRun.state = 'merged' \382 AND stage = 'staticsky'"383 '''384 385 553 sql = "SELECT DISTINCT skycalResult.path_base \ 386 554 FROM skycalRun \ … … 432 600 fits = Fits(self.logger, self.config, files[0]) 433 601 return fits 434 435 # XXX validate the file?436 # if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):437 438 # now find and loop through all cmf files at this path_base439 440 ## XXX the code below was needed when we ingested from staticsky (N files per run)441 ## XXX ingesting from skycal solves this problem (1 file per run)442 ## files=os.popen("neb-ls " + pathBase + "%cmf")443 ## for i in files.readlines():444 ## nebPath = i.rstrip()445 ##446 ## # now attempt to run 'neb-ls -p' to actually read this cmf file447 ## try:448 ## self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'")449 ## paths=os.popen("neb-ls -p " + nebPath)450 ## path = paths.readline().rstrip()451 ## if len(path) < 1:452 ## self.logger.debug("zero length path - skipping")453 ## raise454 ##455 ## print "starint stack stage cmf 3"456 ##457 ## # if we get here, then the cmf is readable, now check the stack_id458 ## fits = Fits(self.logger, self.config, path)459 ## if fits.getPrimaryHeaderValue("STK_ID") == str(stackID):460 ## # we have the right file!461 ## self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))462 ## return fits463 ## else:464 ## # this is not the correct file465 ## self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID)))466 ##467 ## # an exception here means that nebulous could not read this file, so we just skip it468 ## except:469 ## self.logger.debug("NEB FAILED SKIPPING")470 ## pass471 602 472 603 '''
Note:
See TracChangeset
for help on using the changeset viewer.
