Changeset 33144
- Timestamp:
- Jan 25, 2012, 1:30:33 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/gpc1db.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/gpc1db.py
r32778 r33144 46 46 JOIN chipRun USING (chip_id) \ 47 47 JOIN rawExp USING (exp_id) \ 48 WHERE minidvodbRun.minidvodb_group = '" + dvoDb + "' \ 48 JOIN mergedvodbRun using (minidvodb_id) \ 49 WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 49 50 AND minidvodbRun.state = 'merged' \ 51 AND mergedvodbRun.state = 'full' \ 50 52 AND minidvodbProcessed.fault = 0 \ 51 53 AND addRun.stage = '" + stage + "' \ … … 56 58 elif batchType == "ST": 57 59 58 stage = "staticsky "60 stage = "staticsky_multi" 59 61 sql = "SELECT DISTINCT stack_id FROM staticskyInput \ 60 62 JOIN addRun ON(staticskyInput.sky_id = addRun.stage_id) \ … … 67 69 AND addRun.state = 'full'" 68 70 71 print sql 69 72 try: 70 73 rs = self.executeQuery(sql) … … 193 196 194 197 try: 195 # get path to base dir of cmf files198 # get path to base dir of cmf files 196 199 path = rs.getString(1) 197 path = path[0:path.rfind("/")]198 200 except: 199 201 self.logger.errorPair("No smf files found for cam_id", str(camID) ) … … 204 206 if path.startswith("neb"): 205 207 206 f=os.popen("neb-ls -p "+path+" /%smf")208 f=os.popen("neb-ls -p "+path+"%smf") 207 209 for i in f.readlines(): 208 210 files.append(i.rstrip()) … … 210 212 # or not a neb path 211 213 else: 212 files = glob.glob(path + " /*.smf")214 files = glob.glob(path + ".smf") 213 215 214 216 if len(files) < 1: return None … … 219 221 ''' 220 222 Gets the path to the cmf file for this stack_id 221 ''' 222 def getStackStageCmf(self, stackID): 223 224 sql = "SELECT staticskyResult.path_base \ 225 FROM staticskyRun \ 226 JOIN staticskyInput USING(sky_id) \ 223 224 The logic here is fairly ridiculous due to issues with how GPC1 stores info regarding multi-filter stacks. In partcular, it 225 is impossible to find a full path for a cmf file for a given stack_id 226 227 Instead, we get a path_base to a directory with a collection of cmfs. neb-ls will list 5 files, but a number < 5 may actually exist 228 meaning that neb-ls -p will fail. 229 230 our logic is as follows: 231 232 - use stack_id and the DVO label to find a path base for all cmfs 233 - loop through all the potential cmfs, run neb-ls -p on each 234 - if neb-ls -p fails, then the file does not exists and we ignore it 235 - if neb-ls -p succeeds, we open that cmf file and check the STK_ID value in its header to see if it is the one we want 236 - if it is, great, exit 237 - if not, try the next one in the list 238 239 ''' 240 def getStackStageCmf(self, dvoDb, stackID): 241 242 ''' 243 sql = "SELECT DISTINCT staticskyResult.path_base \ 244 FROM staticskyRun \ 245 JOIN staticskyInput USING(sky_id) \ 227 246 JOIN staticskyResult USING(sky_id) \ 228 JOIN stackRun USING(stack_id) \247 JOIN stackRun USING(stack_id) \ 229 248 JOIN stackSumSkyfile USING(stack_id) \ 230 WHERE stack_id = %s" % stackID 231 249 JOIN addRun ON sky_id = stage_id \ 250 JOIN minidvodbRun USING (minidvodb_name) \ 251 WHERE stack_id = " + str(stackID) + " \ 252 AND minidvodbRun.minidvodb_group = '" + dvoDb + "' \ 253 AND minidvodbRun.state = 'merged' \ 254 AND stage = 'staticsky_multi'" 255 ''' 256 257 sql = "SELECT DISTINCT staticskyResult.path_base \ 258 FROM staticskyRun \ 259 JOIN staticskyInput USING(sky_id) \ 260 JOIN staticskyResult USING(sky_id) \ 261 JOIN stackRun USING(stack_id) \ 262 JOIN stackSumSkyfile USING(stack_id) \ 263 JOIN addRun ON sky_id = stage_id \ 264 JOIN minidvodbRun USING (minidvodb_name) \ 265 JOIN mergedvodbRun using (minidvodb_id) \ 266 WHERE stack_id = " + str(stackID) + " \ 267 AND minidvodbRun.state = 'merged' \ 268 AND mergedvodbRun.state = 'full' \ 269 AND mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 270 AND stage = 'staticsky_multi'" 271 272 273 # get single path base for the directory containing all cmf files, one of which is hopefully for our stack_id 232 274 try: 233 275 rs = self.executeQuery(sql) … … 235 277 pathBase = rs.getString(1) 236 278 237 # now find ALL cmf files at this path_base as there can be more than one 238 f=os.popen("neb-ls -p " + pathBase + "%cmf") 239 for i in f.readlines(): 240 241 path = i.rstrip() 242 fits = Fits(self.logger, self.doc, path) 243 244 # we need to check if this is the correct cmf file, and if so then break and return 245 if fits.getPrimaryHeaderValue("STK_ID") == str(stackID): 246 return fits 247 248 except: 249 self.logger.exception("Can't query for stack cmfs") 250 251 self.logger.error("Could not find stack cmf") 279 # now find and loop through all cmf files at this path_base 280 files=os.popen("neb-ls " + pathBase + "%cmf") 281 for i in files.readlines(): 282 283 nebPath = i.rstrip() 284 285 # now attempt to run 'neb-ls -p' to actually read this cmf file 286 try: 287 self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'") 288 paths=os.popen("neb-ls -p " + nebPath) 289 path = paths.readline().rstrip() 290 if len(path) < 1: 291 self.logger.debug("zero length path - skipping") 292 raise 293 294 # if we get here, then the cmf is readable, now check the stack_id 295 fits = Fits(self.logger, self.doc, path) 296 if fits.getPrimaryHeaderValue("STK_ID") == str(stackID): 297 # we have the right file! 298 self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID))) 299 return fits 300 else: 301 # this is not the correct file 302 self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID))) 303 304 # an exception here means that nebulous could not read this file, so we just skip it 305 except: 306 self.logger.debug("NEB FAILED SKIPPING") 307 pass 308 309 except: 310 self.logger.errorPair("Can't query for stack cmfs", "stack_id = %d" % stackID) 311 312 self.logger.errorPair("Couldn't find stack cmf for", "stack_id = %d" % stackID) 252 313 return None 253 314
Note:
See TracChangeset
for help on using the changeset viewer.
