- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/jython/gpc1db.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/ippToPsps/jython/gpc1db.py
r32018 r33415 20 20 Constructor 21 21 ''' 22 def __init__(self, logger, doc):23 super(Gpc1Db, self).__init__(logger, doc, "gpc1database")22 def __init__(self, logger, config): 23 super(Gpc1Db, self).__init__(logger, config, "gpc1database") 24 24 25 25 ''' … … 32 32 33 33 ''' 34 TODO 35 ''' 36 def getIDsInThisDVODbForThisStageFudge(self): 37 38 sql = "SELECT staticskyRun.sky_id \ 39 FROM staticskyInput, staticskyRun, stackRun, staticskyResult \ 40 WHERE staticskyRun.sky_id = staticskyInput.sky_id \ 41 AND staticskyInput.stack_id = stackRun.stack_id \ 42 AND staticskyInput.sky_id = staticskyResult.sky_id \ 43 AND staticskyRun.label like 'MD04.staticsky' \ 44 AND stackRun.filter like 'i%'" 45 46 try: 47 rs = self.executeQuery(sql) 48 except: 49 self.logger.exception("Can't query for ids in DVO") 34 Gets a list of ids in this DVO database for this stage, could be cam or staticsky, for a box with defined center and side length 35 ''' 36 def getIDsInThisDVODbForThisStageInThisBox(self, dvoDb, batchType, ra=180., dec=0., side=181.): 37 38 halfSide = side/2.0 39 return self.getIDsInThisDVODbForThisStage(dvoDb, batchType, ra-halfSide, ra+halfSide, dec-halfSide, dec+halfSide) 40 41 42 ''' 43 Gets a list of ids in this DVO database for this stage, could be cam or staticsky, and a box can be defined with equatorial coordinates 44 ''' 45 def getIDsInThisDVODbForThisStage(self, dvoDb, batchType, minRA=-999, maxRA=999, minDec=-999, maxDec=999): 46 47 self.logger.debugPair("GPC1 RA range", "%.2f -> %.2f" % (minRA, maxRA)) 48 self.logger.debugPair("GPC1 Dec range", "%.2f -> %.2f" % (minDec, maxDec)) 50 49 51 50 ids = [] 52 while (rs.next()):53 ids.append(rs.getInt(1))54 55 rs.close()56 57 self.logger.debug("Found %d items in DVO database '" % (len(ids)))58 59 return ids60 61 '''62 Gets a list of ids in this DVO database for this stage, could be cam or staticsky (so far)63 '''64 def getIDsInThisDVODbForThisStage(self, dvoDb, batchType):65 51 66 52 if batchType == "P2": # TODO define these someplace … … 71 57 JOIN minidvodbRun USING(minidvodb_name) \ 72 58 JOIN minidvodbProcessed USING(minidvodb_id) \ 73 WHERE minidvodbRun.minidvodb_group = '" + dvoDb + "' \ 59 JOIN camRun ON (stage_id = cam_id) \ 60 JOIN chipRun USING (chip_id) \ 61 JOIN rawExp USING (exp_id) \ 62 JOIN mergedvodbRun using (minidvodb_id) \ 63 WHERE mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 74 64 AND minidvodbRun.state = 'merged' \ 65 AND mergedvodbRun.state = 'full' \ 75 66 AND minidvodbProcessed.fault = 0 \ 76 67 AND addRun.stage = '" + stage + "' \ 77 AND addRun.state = 'full'" 68 AND addRun.state = 'full' \ 69 AND decl BETWEEN RADIANS(" + str(minDec) + ") AND RADIANS(" + str(maxDec) + ") \ 70 AND ra BETWEEN RADIANS(" + str(minRA) + ") AND RADIANS(" + str(maxRA) + ")" 78 71 79 72 elif batchType == "ST": 80 73 81 stage = "staticsky" 82 sql = "SELECT DISTINCT stack_id \ 83 FROM staticskyInput \ 74 stage = "staticsky_multi" 75 sql = "SELECT DISTINCT stack_id FROM staticskyInput \ 84 76 JOIN addRun ON(staticskyInput.sky_id = addRun.stage_id) \ 85 77 JOIN minidvodbRun USING(minidvodb_name) \ … … 90 82 AND addRun.stage = '" + stage + "' \ 91 83 AND addRun.state = 'full'" 92 93 try: 94 rs = self.executeQuery(sql) 84 85 try: 86 rs = self.executeQuery(sql) 87 while (rs.next()): ids.append(rs.getInt(1)) 88 rs.close() 95 89 except: 96 90 self.logger.exception("Can't query for ids in DVO") 97 98 ids = [] 99 while (rs.next()): 100 ids.append(rs.getInt(1)) 101 102 rs.close() 91 return ids 92 103 93 104 94 self.logger.debug("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage)) … … 154 144 rs = self.executeQuery(sql) 155 145 rs.first() 146 except: 147 self.logger.errorPair("Can't query for", "stack meta data") 148 149 try: 156 150 meta.append(rs.getString(1)) 157 151 meta.append(rs.getString(2)) 158 152 meta.append(rs.getString(3)) 159 153 except: 160 self.logger.e xception("Can't query for stack meta")161 154 self.logger.errorPair("getStackStageMeta()", "empty meta data") 155 162 156 return meta 163 157 … … 178 172 rs = self.executeQuery(sql) 179 173 rs.first() 174 except: 175 self.logger.errorPair("Can't query for", "camera meta data") 176 177 try: 180 178 meta.append(rs.getInt(1)) 181 179 meta.append(rs.getString(2)) … … 185 183 meta.append(rs.getString(6)) 186 184 except: 187 self.logger.e xception("Can't query for camera meta")185 self.logger.errorPair("getCameraStageMeta()", "empty meta data") 188 186 189 187 return meta … … 205 203 rs.first() 206 204 except: 207 self.logger.exception("Can't query for camera smfs") 208 209 # get path to base dir of cmf files 210 path = rs.getString(1) 211 path = path[0:path.rfind("/")] 205 self.logger.errorPair("Can't query for smf file for cam_id", str(camID)) 206 return None 207 208 try: 209 # get path to base dir of cmf files 210 path = rs.getString(1) 211 except: 212 self.logger.errorPair("No smf files found for cam_id", str(camID) ) 213 return None 212 214 213 215 # list all smf files if a neb path … … 215 217 if path.startswith("neb"): 216 218 217 f=os.popen("neb-ls -p "+path+" /%smf")219 f=os.popen("neb-ls -p "+path+"%smf") 218 220 for i in f.readlines(): 219 221 files.append(i.rstrip()) … … 221 223 # or not a neb path 222 224 else: 223 files = glob.glob(path + " /*.smf")225 files = glob.glob(path + ".smf") 224 226 225 227 if len(files) < 1: return None 226 228 227 return Fits(self.logger, self. doc, files[0]) # TODO just returning first file - check229 return Fits(self.logger, self.config, files[0]) # TODO just returning first file - check 228 230 229 231 230 232 ''' 231 233 Gets the path to the cmf file for this stack_id 232 ''' 233 def getStackStageCmf(self, stackID): 234 235 sql = "SELECT staticskyResult.path_base \ 236 FROM staticskyRun \ 237 JOIN staticskyInput USING(sky_id) \ 234 235 The logic here is fairly ridiculous due to issues with how GPC1 stores info regarding multi-filter stacks. In partcular, it 236 is impossible to find a full path for a cmf file for a given stack_id 237 238 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 239 meaning that neb-ls -p will fail. 240 241 our logic is as follows: 242 243 - use stack_id and the DVO label to find a path base for all cmfs 244 - loop through all the potential cmfs, run neb-ls -p on each 245 - if neb-ls -p fails, then the file does not exists and we ignore it 246 - 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 247 - if it is, great, exit 248 - if not, try the next one in the list 249 250 ''' 251 def getStackStageCmf(self, dvoDb, stackID): 252 253 ''' 254 sql = "SELECT DISTINCT staticskyResult.path_base \ 255 FROM staticskyRun \ 256 JOIN staticskyInput USING(sky_id) \ 238 257 JOIN staticskyResult USING(sky_id) \ 239 JOIN stackRun USING(stack_id) \258 JOIN stackRun USING(stack_id) \ 240 259 JOIN stackSumSkyfile USING(stack_id) \ 241 WHERE stack_id = %s" % stackID 242 260 JOIN addRun ON sky_id = stage_id \ 261 JOIN minidvodbRun USING (minidvodb_name) \ 262 WHERE stack_id = " + str(stackID) + " \ 263 AND minidvodbRun.minidvodb_group = '" + dvoDb + "' \ 264 AND minidvodbRun.state = 'merged' \ 265 AND stage = 'staticsky_multi'" 266 ''' 267 268 sql = "SELECT DISTINCT staticskyResult.path_base \ 269 FROM staticskyRun \ 270 JOIN staticskyInput USING(sky_id) \ 271 JOIN staticskyResult USING(sky_id) \ 272 JOIN stackRun USING(stack_id) \ 273 JOIN stackSumSkyfile USING(stack_id) \ 274 JOIN addRun ON sky_id = stage_id \ 275 JOIN minidvodbRun USING (minidvodb_name) \ 276 JOIN mergedvodbRun using (minidvodb_id) \ 277 WHERE stack_id = " + str(stackID) + " \ 278 AND minidvodbRun.state = 'merged' \ 279 AND mergedvodbRun.state = 'full' \ 280 AND mergedvodbRun.mergedvodb = '" + dvoDb + "' \ 281 AND stage = 'staticsky_multi'" 282 283 284 # get single path base for the directory containing all cmf files, one of which is hopefully for our stack_id 243 285 try: 244 286 rs = self.executeQuery(sql) … … 246 288 pathBase = rs.getString(1) 247 289 248 # now find ALL cmf files at this path_base as there can be more than one 249 f=os.popen("neb-ls -p " + pathBase + "%cmf") 250 for i in f.readlines(): 251 252 path = i.rstrip() 253 fits = Fits(self.logger, self.doc, path) 254 255 # we need to check if this is the correct cmf file, and if so then break and return 256 if fits.getPrimaryHeaderValue("STK_ID") == str(stackID): 257 return fits 258 259 except: 260 self.logger.exception("Can't query for stack cmfs") 261 262 self.logger.error("Could not find stack cmf") 290 # now find and loop through all cmf files at this path_base 291 files=os.popen("neb-ls " + pathBase + "%cmf") 292 for i in files.readlines(): 293 294 nebPath = i.rstrip() 295 296 # now attempt to run 'neb-ls -p' to actually read this cmf file 297 try: 298 self.logger.debug("Trying to neb-ls -p on '" + nebPath + "'") 299 paths=os.popen("neb-ls -p " + nebPath) 300 path = paths.readline().rstrip() 301 if len(path) < 1: 302 self.logger.debug("zero length path - skipping") 303 raise 304 305 # if we get here, then the cmf is readable, now check the stack_id 306 fits = Fits(self.logger, self.config, path) 307 if fits.getPrimaryHeaderValue("STK_ID") == str(stackID): 308 # we have the right file! 309 self.logger.debug("SUCCESS!: %s == %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID))) 310 return fits 311 else: 312 # this is not the correct file 313 self.logger.debug("STACK ID: %s != %s"% (fits.getPrimaryHeaderValue("STK_ID"), str(stackID))) 314 315 # an exception here means that nebulous could not read this file, so we just skip it 316 except: 317 self.logger.debug("NEB FAILED SKIPPING") 318 pass 319 320 except: 321 self.logger.errorPair("Can't query for stack cmfs", "stack_id = %d" % stackID) 322 323 self.logger.errorPair("Couldn't find stack cmf for", "stack_id = %d" % stackID) 263 324 return None 264 325
Note:
See TracChangeset
for help on using the changeset viewer.
