@@ -1,1325 +1,1321 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on September , 2012 |
|
3 | 3 | @author: |
|
4 | 4 | ''' |
|
5 | 5 | |
|
6 | 6 | import sys |
|
7 | 7 | import ast |
|
8 | 8 | import datetime |
|
9 | 9 | import traceback |
|
10 | 10 | import math |
|
11 | 11 | from multiprocessing import Process, Queue, cpu_count |
|
12 | 12 | |
|
13 | 13 | import schainpy |
|
14 | 14 | import schainpy.admin |
|
15 | 15 | |
|
16 | 16 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
17 | 17 | from xml.dom import minidom |
|
18 | 18 | |
|
19 | 19 | from schainpy.model import * |
|
20 | 20 | from time import sleep |
|
21 | 21 | |
|
22 | 22 | def prettify(elem): |
|
23 | 23 | """Return a pretty-printed XML string for the Element. |
|
24 | 24 | """ |
|
25 | 25 | rough_string = tostring(elem, 'utf-8') |
|
26 | 26 | reparsed = minidom.parseString(rough_string) |
|
27 | 27 | return reparsed.toprettyxml(indent=" ") |
|
28 | 28 | |
|
29 | 29 | def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_day=False): |
|
30 | 30 | skip = 0 |
|
31 | 31 | cursor = 0 |
|
32 | 32 | nFiles = None |
|
33 | 33 | processes = [] |
|
34 | ||
|
35 | ||
|
36 | ||
|
37 | ||
|
38 | 34 | dt1 = datetime.datetime.strptime(startDate, '%Y/%m/%d') |
|
39 | 35 | dt2 = datetime.datetime.strptime(endDate, '%Y/%m/%d') |
|
40 | 36 | days = (dt2 - dt1).days |
|
41 | 37 | |
|
42 | 38 | for day in range(days+1): |
|
43 | 39 | skip = 0 |
|
44 | 40 | cursor = 0 |
|
45 | 41 | q = Queue() |
|
46 | 42 | processes = [] |
|
47 | 43 | dt = (dt1 + datetime.timedelta(day)).strftime('%Y/%m/%d') |
|
48 | 44 | firstProcess = Process(target=child, args=(cursor, skip, q, dt)) |
|
49 | 45 | firstProcess.start() |
|
50 | 46 | if by_day: |
|
51 | 47 | continue |
|
52 | 48 | nFiles = q.get() |
|
53 | 49 | firstProcess.terminate() |
|
54 | 50 | skip = int(math.ceil(nFiles/nProcess)) |
|
55 | 51 | while True: |
|
56 | 52 | processes.append(Process(target=child, args=(cursor, skip, q, dt))) |
|
57 | 53 | processes[cursor].start() |
|
58 | 54 | if nFiles < cursor*skip: |
|
59 | 55 | break |
|
60 | 56 | cursor += 1 |
|
61 | 57 | |
|
62 | 58 | def beforeExit(exctype, value, trace): |
|
63 | 59 | for process in processes: |
|
64 | 60 | process.terminate() |
|
65 | 61 | process.join() |
|
66 | 62 | print traceback.print_tb(trace) |
|
67 | 63 | |
|
68 | 64 | sys.excepthook = beforeExit |
|
69 | 65 | |
|
70 | 66 | for process in processes: |
|
71 | 67 | process.join() |
|
72 | 68 | process.terminate() |
|
73 | 69 | sys.exit() |
|
74 | 70 | |
|
75 | 71 | |
|
76 | 72 | class ParameterConf(): |
|
77 | 73 | |
|
78 | 74 | id = None |
|
79 | 75 | name = None |
|
80 | 76 | value = None |
|
81 | 77 | format = None |
|
82 | 78 | |
|
83 | 79 | __formated_value = None |
|
84 | 80 | |
|
85 | 81 | ELEMENTNAME = 'Parameter' |
|
86 | 82 | |
|
87 | 83 | def __init__(self): |
|
88 | 84 | |
|
89 | 85 | self.format = 'str' |
|
90 | 86 | |
|
91 | 87 | def getElementName(self): |
|
92 | 88 | |
|
93 | 89 | return self.ELEMENTNAME |
|
94 | 90 | |
|
95 | 91 | def getValue(self): |
|
96 | 92 | |
|
97 | 93 | value = self.value |
|
98 | 94 | format = self.format |
|
99 | 95 | |
|
100 | 96 | if self.__formated_value != None: |
|
101 | 97 | |
|
102 | 98 | return self.__formated_value |
|
103 | 99 | |
|
104 | 100 | if format == 'obj': |
|
105 | 101 | return value |
|
106 | 102 | |
|
107 | 103 | if format == 'str': |
|
108 | 104 | self.__formated_value = str(value) |
|
109 | 105 | return self.__formated_value |
|
110 | 106 | |
|
111 | 107 | if value == '': |
|
112 | 108 | raise ValueError, "%s: This parameter value is empty" %self.name |
|
113 | 109 | |
|
114 | 110 | if format == 'list': |
|
115 | 111 | strList = value.split(',') |
|
116 | 112 | |
|
117 | 113 | self.__formated_value = strList |
|
118 | 114 | |
|
119 | 115 | return self.__formated_value |
|
120 | 116 | |
|
121 | 117 | if format == 'intlist': |
|
122 | 118 | """ |
|
123 | 119 | Example: |
|
124 | 120 | value = (0,1,2) |
|
125 | 121 | """ |
|
126 | 122 | |
|
127 | 123 | new_value = ast.literal_eval(value) |
|
128 | 124 | |
|
129 | 125 | if type(new_value) not in (tuple, list): |
|
130 | 126 | new_value = [int(new_value)] |
|
131 | 127 | |
|
132 | 128 | self.__formated_value = new_value |
|
133 | 129 | |
|
134 | 130 | return self.__formated_value |
|
135 | 131 | |
|
136 | 132 | if format == 'floatlist': |
|
137 | 133 | """ |
|
138 | 134 | Example: |
|
139 | 135 | value = (0.5, 1.4, 2.7) |
|
140 | 136 | """ |
|
141 | 137 | |
|
142 | 138 | new_value = ast.literal_eval(value) |
|
143 | 139 | |
|
144 | 140 | if type(new_value) not in (tuple, list): |
|
145 | 141 | new_value = [float(new_value)] |
|
146 | 142 | |
|
147 | 143 | self.__formated_value = new_value |
|
148 | 144 | |
|
149 | 145 | return self.__formated_value |
|
150 | 146 | |
|
151 | 147 | if format == 'date': |
|
152 | 148 | strList = value.split('/') |
|
153 | 149 | intList = [int(x) for x in strList] |
|
154 | 150 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
155 | 151 | |
|
156 | 152 | self.__formated_value = date |
|
157 | 153 | |
|
158 | 154 | return self.__formated_value |
|
159 | 155 | |
|
160 | 156 | if format == 'time': |
|
161 | 157 | strList = value.split(':') |
|
162 | 158 | intList = [int(x) for x in strList] |
|
163 | 159 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
164 | 160 | |
|
165 | 161 | self.__formated_value = time |
|
166 | 162 | |
|
167 | 163 | return self.__formated_value |
|
168 | 164 | |
|
169 | 165 | if format == 'pairslist': |
|
170 | 166 | """ |
|
171 | 167 | Example: |
|
172 | 168 | value = (0,1),(1,2) |
|
173 | 169 | """ |
|
174 | 170 | |
|
175 | 171 | new_value = ast.literal_eval(value) |
|
176 | 172 | |
|
177 | 173 | if type(new_value) not in (tuple, list): |
|
178 | 174 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
179 | 175 | |
|
180 | 176 | if type(new_value[0]) not in (tuple, list): |
|
181 | 177 | if len(new_value) != 2: |
|
182 | 178 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
183 | 179 | new_value = [new_value] |
|
184 | 180 | |
|
185 | 181 | for thisPair in new_value: |
|
186 | 182 | if len(thisPair) != 2: |
|
187 | 183 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
188 | 184 | |
|
189 | 185 | self.__formated_value = new_value |
|
190 | 186 | |
|
191 | 187 | return self.__formated_value |
|
192 | 188 | |
|
193 | 189 | if format == 'multilist': |
|
194 | 190 | """ |
|
195 | 191 | Example: |
|
196 | 192 | value = (0,1,2),(3,4,5) |
|
197 | 193 | """ |
|
198 | 194 | multiList = ast.literal_eval(value) |
|
199 | 195 | |
|
200 | 196 | if type(multiList[0]) == int: |
|
201 | 197 | multiList = ast.literal_eval("(" + value + ")") |
|
202 | 198 | |
|
203 | 199 | self.__formated_value = multiList |
|
204 | 200 | |
|
205 | 201 | return self.__formated_value |
|
206 | 202 | |
|
207 | 203 | if format == 'bool': |
|
208 | 204 | value = int(value) |
|
209 | 205 | |
|
210 | 206 | if format == 'int': |
|
211 | 207 | value = float(value) |
|
212 | 208 | |
|
213 | 209 | format_func = eval(format) |
|
214 | 210 | |
|
215 | 211 | self.__formated_value = format_func(value) |
|
216 | 212 | |
|
217 | 213 | return self.__formated_value |
|
218 | 214 | |
|
219 | 215 | def updateId(self, new_id): |
|
220 | 216 | |
|
221 | 217 | self.id = str(new_id) |
|
222 | 218 | |
|
223 | 219 | def setup(self, id, name, value, format='str'): |
|
224 | 220 | |
|
225 | 221 | self.id = str(id) |
|
226 | 222 | self.name = name |
|
227 | 223 | if format == 'obj': |
|
228 | 224 | self.value = value |
|
229 | 225 | else: |
|
230 | 226 | self.value = str(value) |
|
231 | 227 | self.format = str.lower(format) |
|
232 | 228 | |
|
233 | 229 | self.getValue() |
|
234 | 230 | |
|
235 | 231 | return 1 |
|
236 | 232 | |
|
237 | 233 | def update(self, name, value, format='str'): |
|
238 | 234 | |
|
239 | 235 | self.name = name |
|
240 | 236 | self.value = str(value) |
|
241 | 237 | self.format = format |
|
242 | 238 | |
|
243 | 239 | def makeXml(self, opElement): |
|
244 | 240 | if self.name not in ('queue',): |
|
245 | 241 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
246 | 242 | parmElement.set('id', str(self.id)) |
|
247 | 243 | parmElement.set('name', self.name) |
|
248 | 244 | parmElement.set('value', self.value) |
|
249 | 245 | parmElement.set('format', self.format) |
|
250 | 246 | |
|
251 | 247 | def readXml(self, parmElement): |
|
252 | 248 | |
|
253 | 249 | self.id = parmElement.get('id') |
|
254 | 250 | self.name = parmElement.get('name') |
|
255 | 251 | self.value = parmElement.get('value') |
|
256 | 252 | self.format = str.lower(parmElement.get('format')) |
|
257 | 253 | |
|
258 | 254 | #Compatible with old signal chain version |
|
259 | 255 | if self.format == 'int' and self.name == 'idfigure': |
|
260 | 256 | self.name = 'id' |
|
261 | 257 | |
|
262 | 258 | def printattr(self): |
|
263 | 259 | |
|
264 | 260 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
265 | 261 | |
|
266 | 262 | class OperationConf(): |
|
267 | 263 | |
|
268 | 264 | id = None |
|
269 | 265 | name = None |
|
270 | 266 | priority = None |
|
271 | 267 | type = None |
|
272 | 268 | |
|
273 | 269 | parmConfObjList = [] |
|
274 | 270 | |
|
275 | 271 | ELEMENTNAME = 'Operation' |
|
276 | 272 | |
|
277 | 273 | def __init__(self): |
|
278 | 274 | |
|
279 | 275 | self.id = '0' |
|
280 | 276 | self.name = None |
|
281 | 277 | self.priority = None |
|
282 | 278 | self.type = 'self' |
|
283 | 279 | |
|
284 | 280 | |
|
285 | 281 | def __getNewId(self): |
|
286 | 282 | |
|
287 | 283 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
288 | 284 | |
|
289 | 285 | def updateId(self, new_id): |
|
290 | 286 | |
|
291 | 287 | self.id = str(new_id) |
|
292 | 288 | |
|
293 | 289 | n = 1 |
|
294 | 290 | for parmObj in self.parmConfObjList: |
|
295 | 291 | |
|
296 | 292 | idParm = str(int(new_id)*10 + n) |
|
297 | 293 | parmObj.updateId(idParm) |
|
298 | 294 | |
|
299 | 295 | n += 1 |
|
300 | 296 | |
|
301 | 297 | def getElementName(self): |
|
302 | 298 | |
|
303 | 299 | return self.ELEMENTNAME |
|
304 | 300 | |
|
305 | 301 | def getParameterObjList(self): |
|
306 | 302 | |
|
307 | 303 | return self.parmConfObjList |
|
308 | 304 | |
|
309 | 305 | def getParameterObj(self, parameterName): |
|
310 | 306 | |
|
311 | 307 | for parmConfObj in self.parmConfObjList: |
|
312 | 308 | |
|
313 | 309 | if parmConfObj.name != parameterName: |
|
314 | 310 | continue |
|
315 | 311 | |
|
316 | 312 | return parmConfObj |
|
317 | 313 | |
|
318 | 314 | return None |
|
319 | 315 | |
|
320 | 316 | def getParameterObjfromValue(self, parameterValue): |
|
321 | 317 | |
|
322 | 318 | for parmConfObj in self.parmConfObjList: |
|
323 | 319 | |
|
324 | 320 | if parmConfObj.getValue() != parameterValue: |
|
325 | 321 | continue |
|
326 | 322 | |
|
327 | 323 | return parmConfObj.getValue() |
|
328 | 324 | |
|
329 | 325 | return None |
|
330 | 326 | |
|
331 | 327 | def getParameterValue(self, parameterName): |
|
332 | 328 | |
|
333 | 329 | parameterObj = self.getParameterObj(parameterName) |
|
334 | 330 | |
|
335 | 331 | # if not parameterObj: |
|
336 | 332 | # return None |
|
337 | 333 | |
|
338 | 334 | value = parameterObj.getValue() |
|
339 | 335 | |
|
340 | 336 | return value |
|
341 | 337 | |
|
342 | 338 | |
|
343 | 339 | def getKwargs(self): |
|
344 | 340 | |
|
345 | 341 | kwargs = {} |
|
346 | 342 | |
|
347 | 343 | for parmConfObj in self.parmConfObjList: |
|
348 | 344 | if self.name == 'run' and parmConfObj.name == 'datatype': |
|
349 | 345 | continue |
|
350 | 346 | |
|
351 | 347 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
352 | 348 | |
|
353 | 349 | return kwargs |
|
354 | 350 | |
|
355 | 351 | def setup(self, id, name, priority, type): |
|
356 | 352 | |
|
357 | 353 | self.id = str(id) |
|
358 | 354 | self.name = name |
|
359 | 355 | self.type = type |
|
360 | 356 | self.priority = priority |
|
361 | 357 | |
|
362 | 358 | self.parmConfObjList = [] |
|
363 | 359 | |
|
364 | 360 | def removeParameters(self): |
|
365 | 361 | |
|
366 | 362 | for obj in self.parmConfObjList: |
|
367 | 363 | del obj |
|
368 | 364 | |
|
369 | 365 | self.parmConfObjList = [] |
|
370 | 366 | |
|
371 | 367 | def addParameter(self, name, value, format='str'): |
|
372 | 368 | |
|
373 | 369 | id = self.__getNewId() |
|
374 | 370 | |
|
375 | 371 | parmConfObj = ParameterConf() |
|
376 | 372 | if not parmConfObj.setup(id, name, value, format): |
|
377 | 373 | return None |
|
378 | 374 | |
|
379 | 375 | self.parmConfObjList.append(parmConfObj) |
|
380 | 376 | |
|
381 | 377 | return parmConfObj |
|
382 | 378 | |
|
383 | 379 | def changeParameter(self, name, value, format='str'): |
|
384 | 380 | |
|
385 | 381 | parmConfObj = self.getParameterObj(name) |
|
386 | 382 | parmConfObj.update(name, value, format) |
|
387 | 383 | |
|
388 | 384 | return parmConfObj |
|
389 | 385 | |
|
390 | 386 | def makeXml(self, procUnitElement): |
|
391 | 387 | |
|
392 | 388 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
393 | 389 | opElement.set('id', str(self.id)) |
|
394 | 390 | opElement.set('name', self.name) |
|
395 | 391 | opElement.set('type', self.type) |
|
396 | 392 | opElement.set('priority', str(self.priority)) |
|
397 | 393 | |
|
398 | 394 | for parmConfObj in self.parmConfObjList: |
|
399 | 395 | parmConfObj.makeXml(opElement) |
|
400 | 396 | |
|
401 | 397 | def readXml(self, opElement): |
|
402 | 398 | |
|
403 | 399 | self.id = opElement.get('id') |
|
404 | 400 | self.name = opElement.get('name') |
|
405 | 401 | self.type = opElement.get('type') |
|
406 | 402 | self.priority = opElement.get('priority') |
|
407 | 403 | |
|
408 | 404 | #Compatible with old signal chain version |
|
409 | 405 | #Use of 'run' method instead 'init' |
|
410 | 406 | if self.type == 'self' and self.name == 'init': |
|
411 | 407 | self.name = 'run' |
|
412 | 408 | |
|
413 | 409 | self.parmConfObjList = [] |
|
414 | 410 | |
|
415 | 411 | parmElementList = opElement.iter(ParameterConf().getElementName()) |
|
416 | 412 | |
|
417 | 413 | for parmElement in parmElementList: |
|
418 | 414 | parmConfObj = ParameterConf() |
|
419 | 415 | parmConfObj.readXml(parmElement) |
|
420 | 416 | |
|
421 | 417 | #Compatible with old signal chain version |
|
422 | 418 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
423 | 419 | if self.type != 'self' and self.name == 'Plot': |
|
424 | 420 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
425 | 421 | self.name = parmConfObj.value |
|
426 | 422 | continue |
|
427 | 423 | |
|
428 | 424 | self.parmConfObjList.append(parmConfObj) |
|
429 | 425 | |
|
430 | 426 | def printattr(self): |
|
431 | 427 | |
|
432 | 428 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
433 | 429 | self.id, |
|
434 | 430 | self.name, |
|
435 | 431 | self.type, |
|
436 | 432 | self.priority) |
|
437 | 433 | |
|
438 | 434 | for parmConfObj in self.parmConfObjList: |
|
439 | 435 | parmConfObj.printattr() |
|
440 | 436 | |
|
441 | 437 | def createObject(self, plotter_queue=None): |
|
442 | 438 | |
|
443 | 439 | |
|
444 | 440 | if self.type == 'self': |
|
445 | 441 | raise ValueError, "This operation type cannot be created" |
|
446 | 442 | |
|
447 | 443 | if self.type == 'plotter': |
|
448 | 444 | #Plotter(plotter_name) |
|
449 | 445 | if not plotter_queue: |
|
450 | 446 | raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)" |
|
451 | 447 | |
|
452 | 448 | opObj = Plotter(self.name, plotter_queue) |
|
453 | 449 | |
|
454 | 450 | if self.type == 'external' or self.type == 'other': |
|
455 | 451 | |
|
456 | 452 | className = eval(self.name) |
|
457 | 453 | kwargs = self.getKwargs() |
|
458 | 454 | |
|
459 | 455 | opObj = className(**kwargs) |
|
460 | 456 | |
|
461 | 457 | return opObj |
|
462 | 458 | |
|
463 | 459 | |
|
464 | 460 | class ProcUnitConf(): |
|
465 | 461 | |
|
466 | 462 | id = None |
|
467 | 463 | name = None |
|
468 | 464 | datatype = None |
|
469 | 465 | inputId = None |
|
470 | 466 | parentId = None |
|
471 | 467 | |
|
472 | 468 | opConfObjList = [] |
|
473 | 469 | |
|
474 | 470 | procUnitObj = None |
|
475 | 471 | opObjList = [] |
|
476 | 472 | |
|
477 | 473 | ELEMENTNAME = 'ProcUnit' |
|
478 | 474 | |
|
479 | 475 | def __init__(self): |
|
480 | 476 | |
|
481 | 477 | self.id = None |
|
482 | 478 | self.datatype = None |
|
483 | 479 | self.name = None |
|
484 | 480 | self.inputId = None |
|
485 | 481 | |
|
486 | 482 | self.opConfObjList = [] |
|
487 | 483 | |
|
488 | 484 | self.procUnitObj = None |
|
489 | 485 | self.opObjDict = {} |
|
490 | 486 | |
|
491 | 487 | def __getPriority(self): |
|
492 | 488 | |
|
493 | 489 | return len(self.opConfObjList)+1 |
|
494 | 490 | |
|
495 | 491 | def __getNewId(self): |
|
496 | 492 | |
|
497 | 493 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
498 | 494 | |
|
499 | 495 | def getElementName(self): |
|
500 | 496 | |
|
501 | 497 | return self.ELEMENTNAME |
|
502 | 498 | |
|
503 | 499 | def getId(self): |
|
504 | 500 | |
|
505 | 501 | return self.id |
|
506 | 502 | |
|
507 | 503 | def updateId(self, new_id, parentId=parentId): |
|
508 | 504 | |
|
509 | 505 | |
|
510 | 506 | new_id = int(parentId)*10 + (int(self.id) % 10) |
|
511 | 507 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) |
|
512 | 508 | |
|
513 | 509 | #If this proc unit has not inputs |
|
514 | 510 | if self.inputId == '0': |
|
515 | 511 | new_inputId = 0 |
|
516 | 512 | |
|
517 | 513 | n = 1 |
|
518 | 514 | for opConfObj in self.opConfObjList: |
|
519 | 515 | |
|
520 | 516 | idOp = str(int(new_id)*10 + n) |
|
521 | 517 | opConfObj.updateId(idOp) |
|
522 | 518 | |
|
523 | 519 | n += 1 |
|
524 | 520 | |
|
525 | 521 | self.parentId = str(parentId) |
|
526 | 522 | self.id = str(new_id) |
|
527 | 523 | self.inputId = str(new_inputId) |
|
528 | 524 | |
|
529 | 525 | |
|
530 | 526 | def getInputId(self): |
|
531 | 527 | |
|
532 | 528 | return self.inputId |
|
533 | 529 | |
|
534 | 530 | def getOperationObjList(self): |
|
535 | 531 | |
|
536 | 532 | return self.opConfObjList |
|
537 | 533 | |
|
538 | 534 | def getOperationObj(self, name=None): |
|
539 | 535 | |
|
540 | 536 | for opConfObj in self.opConfObjList: |
|
541 | 537 | |
|
542 | 538 | if opConfObj.name != name: |
|
543 | 539 | continue |
|
544 | 540 | |
|
545 | 541 | return opConfObj |
|
546 | 542 | |
|
547 | 543 | return None |
|
548 | 544 | |
|
549 | 545 | def getOpObjfromParamValue(self, value=None): |
|
550 | 546 | |
|
551 | 547 | for opConfObj in self.opConfObjList: |
|
552 | 548 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
553 | 549 | continue |
|
554 | 550 | return opConfObj |
|
555 | 551 | return None |
|
556 | 552 | |
|
557 | 553 | def getProcUnitObj(self): |
|
558 | 554 | |
|
559 | 555 | return self.procUnitObj |
|
560 | 556 | |
|
561 | 557 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
562 | 558 | |
|
563 | 559 | #Compatible with old signal chain version |
|
564 | 560 | if datatype==None and name==None: |
|
565 | 561 | raise ValueError, "datatype or name should be defined" |
|
566 | 562 | |
|
567 | 563 | if name==None: |
|
568 | 564 | if 'Proc' in datatype: |
|
569 | 565 | name = datatype |
|
570 | 566 | else: |
|
571 | 567 | name = '%sProc' %(datatype) |
|
572 | 568 | |
|
573 | 569 | if datatype==None: |
|
574 | 570 | datatype = name.replace('Proc','') |
|
575 | 571 | |
|
576 | 572 | self.id = str(id) |
|
577 | 573 | self.name = name |
|
578 | 574 | self.datatype = datatype |
|
579 | 575 | self.inputId = inputId |
|
580 | 576 | self.parentId = parentId |
|
581 | 577 | |
|
582 | 578 | self.opConfObjList = [] |
|
583 | 579 | |
|
584 | 580 | self.addOperation(name='run', optype='self') |
|
585 | 581 | |
|
586 | 582 | def removeOperations(self): |
|
587 | 583 | |
|
588 | 584 | for obj in self.opConfObjList: |
|
589 | 585 | del obj |
|
590 | 586 | |
|
591 | 587 | self.opConfObjList = [] |
|
592 | 588 | self.addOperation(name='run') |
|
593 | 589 | |
|
594 | 590 | def addParameter(self, **kwargs): |
|
595 | 591 | ''' |
|
596 | 592 | Add parameters to "run" operation |
|
597 | 593 | ''' |
|
598 | 594 | opObj = self.opConfObjList[0] |
|
599 | 595 | |
|
600 | 596 | opObj.addParameter(**kwargs) |
|
601 | 597 | |
|
602 | 598 | return opObj |
|
603 | 599 | |
|
604 | 600 | def addOperation(self, name, optype='self'): |
|
605 | 601 | |
|
606 | 602 | id = self.__getNewId() |
|
607 | 603 | priority = self.__getPriority() |
|
608 | 604 | |
|
609 | 605 | opConfObj = OperationConf() |
|
610 | 606 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
611 | 607 | |
|
612 | 608 | self.opConfObjList.append(opConfObj) |
|
613 | 609 | |
|
614 | 610 | return opConfObj |
|
615 | 611 | |
|
616 | 612 | def makeXml(self, projectElement): |
|
617 | 613 | |
|
618 | 614 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
619 | 615 | procUnitElement.set('id', str(self.id)) |
|
620 | 616 | procUnitElement.set('name', self.name) |
|
621 | 617 | procUnitElement.set('datatype', self.datatype) |
|
622 | 618 | procUnitElement.set('inputId', str(self.inputId)) |
|
623 | 619 | |
|
624 | 620 | for opConfObj in self.opConfObjList: |
|
625 | 621 | opConfObj.makeXml(procUnitElement) |
|
626 | 622 | |
|
627 | 623 | def readXml(self, upElement): |
|
628 | 624 | |
|
629 | 625 | self.id = upElement.get('id') |
|
630 | 626 | self.name = upElement.get('name') |
|
631 | 627 | self.datatype = upElement.get('datatype') |
|
632 | 628 | self.inputId = upElement.get('inputId') |
|
633 | 629 | |
|
634 | 630 | if self.ELEMENTNAME == "ReadUnit": |
|
635 | 631 | self.datatype = self.datatype.replace("Reader", "") |
|
636 | 632 | |
|
637 | 633 | if self.ELEMENTNAME == "ProcUnit": |
|
638 | 634 | self.datatype = self.datatype.replace("Proc", "") |
|
639 | 635 | |
|
640 | 636 | if self.inputId == 'None': |
|
641 | 637 | self.inputId = '0' |
|
642 | 638 | |
|
643 | 639 | self.opConfObjList = [] |
|
644 | 640 | |
|
645 | 641 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
646 | 642 | |
|
647 | 643 | for opElement in opElementList: |
|
648 | 644 | opConfObj = OperationConf() |
|
649 | 645 | opConfObj.readXml(opElement) |
|
650 | 646 | self.opConfObjList.append(opConfObj) |
|
651 | 647 | |
|
652 | 648 | def printattr(self): |
|
653 | 649 | |
|
654 | 650 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
655 | 651 | self.id, |
|
656 | 652 | self.name, |
|
657 | 653 | self.datatype, |
|
658 | 654 | self.inputId) |
|
659 | 655 | |
|
660 | 656 | for opConfObj in self.opConfObjList: |
|
661 | 657 | opConfObj.printattr() |
|
662 | 658 | |
|
663 | 659 | |
|
664 | 660 | def getKwargs(self): |
|
665 | 661 | |
|
666 | 662 | opObj = self.opConfObjList[0] |
|
667 | 663 | kwargs = opObj.getKwargs() |
|
668 | 664 | |
|
669 | 665 | return kwargs |
|
670 | 666 | |
|
671 | 667 | def createObjects(self, plotter_queue=None): |
|
672 | 668 | |
|
673 | 669 | className = eval(self.name) |
|
674 | 670 | kwargs = self.getKwargs() |
|
675 | 671 | procUnitObj = className(**kwargs) |
|
676 | 672 | |
|
677 | 673 | for opConfObj in self.opConfObjList: |
|
678 | 674 | |
|
679 | 675 | if opConfObj.type=='self' and self.name=='run': |
|
680 | 676 | continue |
|
681 | 677 | elif opConfObj.type=='self': |
|
682 | 678 | procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs()) |
|
683 | 679 | continue |
|
684 | 680 | |
|
685 | 681 | opObj = opConfObj.createObject(plotter_queue) |
|
686 | 682 | |
|
687 | 683 | self.opObjDict[opConfObj.id] = opObj |
|
688 | 684 | |
|
689 | 685 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
690 | 686 | |
|
691 | 687 | self.procUnitObj = procUnitObj |
|
692 | 688 | |
|
693 | 689 | return procUnitObj |
|
694 | 690 | |
|
695 | 691 | def run(self): |
|
696 | 692 | |
|
697 | 693 | is_ok = False |
|
698 | 694 | |
|
699 | 695 | for opConfObj in self.opConfObjList: |
|
700 | 696 | |
|
701 | 697 | kwargs = {} |
|
702 | 698 | for parmConfObj in opConfObj.getParameterObjList(): |
|
703 | 699 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
704 | 700 | continue |
|
705 | 701 | |
|
706 | 702 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
707 | 703 | |
|
708 | 704 | #ini = time.time() |
|
709 | 705 | |
|
710 | 706 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
711 | 707 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
712 | 708 | opName = opConfObj.name, |
|
713 | 709 | opId = opConfObj.id, |
|
714 | 710 | ) |
|
715 | 711 | |
|
716 | 712 | # total_time = time.time() - ini |
|
717 | 713 | # |
|
718 | 714 | # if total_time > 0.002: |
|
719 | 715 | # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time) |
|
720 | 716 | |
|
721 | 717 | is_ok = is_ok or sts |
|
722 | 718 | |
|
723 | 719 | return is_ok |
|
724 | 720 | |
|
725 | 721 | def close(self): |
|
726 | 722 | |
|
727 | 723 | for opConfObj in self.opConfObjList: |
|
728 | 724 | if opConfObj.type == 'self': |
|
729 | 725 | continue |
|
730 | 726 | |
|
731 | 727 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
732 | 728 | opObj.close() |
|
733 | 729 | |
|
734 | 730 | self.procUnitObj.close() |
|
735 | 731 | |
|
736 | 732 | return |
|
737 | 733 | |
|
738 | 734 | class ReadUnitConf(ProcUnitConf): |
|
739 | 735 | |
|
740 | 736 | path = None |
|
741 | 737 | startDate = None |
|
742 | 738 | endDate = None |
|
743 | 739 | startTime = None |
|
744 | 740 | endTime = None |
|
745 | 741 | |
|
746 | 742 | ELEMENTNAME = 'ReadUnit' |
|
747 | 743 | |
|
748 | 744 | def __init__(self): |
|
749 | 745 | |
|
750 | 746 | self.id = None |
|
751 | 747 | self.datatype = None |
|
752 | 748 | self.name = None |
|
753 | 749 | self.inputId = None |
|
754 | 750 | |
|
755 | 751 | self.parentId = None |
|
756 | 752 | |
|
757 | 753 | self.opConfObjList = [] |
|
758 | 754 | self.opObjList = [] |
|
759 | 755 | |
|
760 | 756 | def getElementName(self): |
|
761 | 757 | |
|
762 | 758 | return self.ELEMENTNAME |
|
763 | 759 | |
|
764 | 760 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, queue=None, **kwargs): |
|
765 | 761 | |
|
766 | 762 | #Compatible with old signal chain version |
|
767 | 763 | if datatype==None and name==None: |
|
768 | 764 | raise ValueError, "datatype or name should be defined" |
|
769 | 765 | |
|
770 | 766 | if name==None: |
|
771 | 767 | if 'Reader' in datatype: |
|
772 | 768 | name = datatype |
|
773 | 769 | else: |
|
774 | 770 | name = '%sReader' %(datatype) |
|
775 | 771 | |
|
776 | 772 | if datatype==None: |
|
777 | 773 | datatype = name.replace('Reader','') |
|
778 | 774 | |
|
779 | 775 | self.id = id |
|
780 | 776 | self.name = name |
|
781 | 777 | self.datatype = datatype |
|
782 | 778 | |
|
783 | 779 | self.path = os.path.abspath(path) |
|
784 | 780 | self.startDate = startDate |
|
785 | 781 | self.endDate = endDate |
|
786 | 782 | self.startTime = startTime |
|
787 | 783 | self.endTime = endTime |
|
788 | 784 | |
|
789 | 785 | self.inputId = '0' |
|
790 | 786 | self.parentId = parentId |
|
791 | 787 | self.queue = queue |
|
792 | 788 | self.addRunOperation(**kwargs) |
|
793 | 789 | |
|
794 | 790 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): |
|
795 | 791 | |
|
796 | 792 | #Compatible with old signal chain version |
|
797 | 793 | if datatype==None and name==None: |
|
798 | 794 | raise ValueError, "datatype or name should be defined" |
|
799 | 795 | |
|
800 | 796 | if name==None: |
|
801 | 797 | if 'Reader' in datatype: |
|
802 | 798 | name = datatype |
|
803 | 799 | else: |
|
804 | 800 | name = '%sReader' %(datatype) |
|
805 | 801 | |
|
806 | 802 | if datatype==None: |
|
807 | 803 | datatype = name.replace('Reader','') |
|
808 | 804 | |
|
809 | 805 | self.datatype = datatype |
|
810 | 806 | self.name = name |
|
811 | 807 | self.path = path |
|
812 | 808 | self.startDate = startDate |
|
813 | 809 | self.endDate = endDate |
|
814 | 810 | self.startTime = startTime |
|
815 | 811 | self.endTime = endTime |
|
816 | 812 | |
|
817 | 813 | self.inputId = '0' |
|
818 | 814 | self.parentId = parentId |
|
819 | 815 | |
|
820 | 816 | self.updateRunOperation(**kwargs) |
|
821 | 817 | |
|
822 | 818 | def removeOperations(self): |
|
823 | 819 | |
|
824 | 820 | for obj in self.opConfObjList: |
|
825 | 821 | del obj |
|
826 | 822 | |
|
827 | 823 | self.opConfObjList = [] |
|
828 | 824 | |
|
829 | 825 | def addRunOperation(self, **kwargs): |
|
830 | 826 | |
|
831 | 827 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
832 | 828 | |
|
833 | 829 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
834 | 830 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
835 | 831 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
836 | 832 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
837 | 833 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
838 | 834 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
839 | 835 | opObj.addParameter(name='queue' , value=self.queue, format='obj') |
|
840 | 836 | |
|
841 | 837 | for key, value in kwargs.items(): |
|
842 | 838 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
843 | 839 | |
|
844 | 840 | return opObj |
|
845 | 841 | |
|
846 | 842 | def updateRunOperation(self, **kwargs): |
|
847 | 843 | |
|
848 | 844 | opObj = self.getOperationObj(name = 'run') |
|
849 | 845 | opObj.removeParameters() |
|
850 | 846 | |
|
851 | 847 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
852 | 848 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
853 | 849 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
854 | 850 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
855 | 851 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
856 | 852 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
857 | 853 | |
|
858 | 854 | for key, value in kwargs.items(): |
|
859 | 855 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
860 | 856 | |
|
861 | 857 | return opObj |
|
862 | 858 | |
|
863 | 859 | # def makeXml(self, projectElement): |
|
864 | 860 | # |
|
865 | 861 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
866 | 862 | # procUnitElement.set('id', str(self.id)) |
|
867 | 863 | # procUnitElement.set('name', self.name) |
|
868 | 864 | # procUnitElement.set('datatype', self.datatype) |
|
869 | 865 | # procUnitElement.set('inputId', str(self.inputId)) |
|
870 | 866 | # |
|
871 | 867 | # for opConfObj in self.opConfObjList: |
|
872 | 868 | # opConfObj.makeXml(procUnitElement) |
|
873 | 869 | |
|
874 | 870 | def readXml(self, upElement): |
|
875 | 871 | |
|
876 | 872 | self.id = upElement.get('id') |
|
877 | 873 | self.name = upElement.get('name') |
|
878 | 874 | self.datatype = upElement.get('datatype') |
|
879 | 875 | self.inputId = upElement.get('inputId') |
|
880 | 876 | |
|
881 | 877 | if self.ELEMENTNAME == "ReadUnit": |
|
882 | 878 | self.datatype = self.datatype.replace("Reader", "") |
|
883 | 879 | |
|
884 | 880 | if self.inputId == 'None': |
|
885 | 881 | self.inputId = '0' |
|
886 | 882 | |
|
887 | 883 | self.opConfObjList = [] |
|
888 | 884 | |
|
889 | 885 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
890 | 886 | |
|
891 | 887 | for opElement in opElementList: |
|
892 | 888 | opConfObj = OperationConf() |
|
893 | 889 | opConfObj.readXml(opElement) |
|
894 | 890 | self.opConfObjList.append(opConfObj) |
|
895 | 891 | |
|
896 | 892 | if opConfObj.name == 'run': |
|
897 | 893 | self.path = opConfObj.getParameterValue('path') |
|
898 | 894 | self.startDate = opConfObj.getParameterValue('startDate') |
|
899 | 895 | self.endDate = opConfObj.getParameterValue('endDate') |
|
900 | 896 | self.startTime = opConfObj.getParameterValue('startTime') |
|
901 | 897 | self.endTime = opConfObj.getParameterValue('endTime') |
|
902 | 898 | |
|
903 | 899 | class Project(): |
|
904 | 900 | |
|
905 | 901 | id = None |
|
906 | 902 | name = None |
|
907 | 903 | description = None |
|
908 | 904 | filename = None |
|
909 | 905 | |
|
910 | 906 | procUnitConfObjDict = None |
|
911 | 907 | |
|
912 | 908 | ELEMENTNAME = 'Project' |
|
913 | 909 | |
|
914 | 910 | plotterQueue = None |
|
915 | 911 | |
|
916 | 912 | def __init__(self, plotter_queue=None): |
|
917 | 913 | |
|
918 | 914 | self.id = None |
|
919 | 915 | self.name = None |
|
920 | 916 | self.description = None |
|
921 | 917 | |
|
922 | 918 | self.plotterQueue = plotter_queue |
|
923 | 919 | |
|
924 | 920 | self.procUnitConfObjDict = {} |
|
925 | 921 | |
|
926 | 922 | def __getNewId(self): |
|
927 | 923 | |
|
928 | 924 | idList = self.procUnitConfObjDict.keys() |
|
929 | 925 | |
|
930 | 926 | id = int(self.id)*10 |
|
931 | 927 | |
|
932 | 928 | while True: |
|
933 | 929 | id += 1 |
|
934 | 930 | |
|
935 | 931 | if str(id) in idList: |
|
936 | 932 | continue |
|
937 | 933 | |
|
938 | 934 | break |
|
939 | 935 | |
|
940 | 936 | return str(id) |
|
941 | 937 | |
|
942 | 938 | def getElementName(self): |
|
943 | 939 | |
|
944 | 940 | return self.ELEMENTNAME |
|
945 | 941 | |
|
946 | 942 | def getId(self): |
|
947 | 943 | |
|
948 | 944 | return self.id |
|
949 | 945 | |
|
950 | 946 | def updateId(self, new_id): |
|
951 | 947 | |
|
952 | 948 | self.id = str(new_id) |
|
953 | 949 | |
|
954 | 950 | keyList = self.procUnitConfObjDict.keys() |
|
955 | 951 | keyList.sort() |
|
956 | 952 | |
|
957 | 953 | n = 1 |
|
958 | 954 | newProcUnitConfObjDict = {} |
|
959 | 955 | |
|
960 | 956 | for procKey in keyList: |
|
961 | 957 | |
|
962 | 958 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
963 | 959 | idProcUnit = str(int(self.id)*10 + n) |
|
964 | 960 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
965 | 961 | |
|
966 | 962 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
967 | 963 | n += 1 |
|
968 | 964 | |
|
969 | 965 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
970 | 966 | |
|
971 | 967 | def setup(self, id, name, description): |
|
972 | 968 | |
|
973 | 969 | self.id = str(id) |
|
974 | 970 | self.name = name |
|
975 | 971 | self.description = description |
|
976 | 972 | |
|
977 | 973 | def update(self, name, description): |
|
978 | 974 | |
|
979 | 975 | self.name = name |
|
980 | 976 | self.description = description |
|
981 | 977 | |
|
982 | 978 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
983 | 979 | |
|
984 | 980 | if id is None: |
|
985 | 981 | idReadUnit = self.__getNewId() |
|
986 | 982 | else: |
|
987 | 983 | idReadUnit = str(id) |
|
988 | 984 | |
|
989 | 985 | readUnitConfObj = ReadUnitConf() |
|
990 | 986 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
991 | 987 | |
|
992 | 988 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
993 | 989 | |
|
994 | 990 | return readUnitConfObj |
|
995 | 991 | |
|
996 | 992 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
997 | 993 | |
|
998 | 994 | idProcUnit = self.__getNewId() |
|
999 | 995 | |
|
1000 | 996 | procUnitConfObj = ProcUnitConf() |
|
1001 | 997 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
1002 | 998 | |
|
1003 | 999 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1004 | 1000 | |
|
1005 | 1001 | return procUnitConfObj |
|
1006 | 1002 | |
|
1007 | 1003 | def removeProcUnit(self, id): |
|
1008 | 1004 | |
|
1009 | 1005 | if id in self.procUnitConfObjDict.keys(): |
|
1010 | 1006 | self.procUnitConfObjDict.pop(id) |
|
1011 | 1007 | |
|
1012 | 1008 | def getReadUnitId(self): |
|
1013 | 1009 | |
|
1014 | 1010 | readUnitConfObj = self.getReadUnitObj() |
|
1015 | 1011 | |
|
1016 | 1012 | return readUnitConfObj.id |
|
1017 | 1013 | |
|
1018 | 1014 | def getReadUnitObj(self): |
|
1019 | 1015 | |
|
1020 | 1016 | for obj in self.procUnitConfObjDict.values(): |
|
1021 | 1017 | if obj.getElementName() == "ReadUnit": |
|
1022 | 1018 | return obj |
|
1023 | 1019 | |
|
1024 | 1020 | return None |
|
1025 | 1021 | |
|
1026 | 1022 | def getProcUnitObj(self, id=None, name=None): |
|
1027 | 1023 | |
|
1028 | 1024 | if id != None: |
|
1029 | 1025 | return self.procUnitConfObjDict[id] |
|
1030 | 1026 | |
|
1031 | 1027 | if name != None: |
|
1032 | 1028 | return self.getProcUnitObjByName(name) |
|
1033 | 1029 | |
|
1034 | 1030 | return None |
|
1035 | 1031 | |
|
1036 | 1032 | def getProcUnitObjByName(self, name): |
|
1037 | 1033 | |
|
1038 | 1034 | for obj in self.procUnitConfObjDict.values(): |
|
1039 | 1035 | if obj.name == name: |
|
1040 | 1036 | return obj |
|
1041 | 1037 | |
|
1042 | 1038 | return None |
|
1043 | 1039 | |
|
1044 | 1040 | def procUnitItems(self): |
|
1045 | 1041 | |
|
1046 | 1042 | return self.procUnitConfObjDict.items() |
|
1047 | 1043 | |
|
1048 | 1044 | def makeXml(self): |
|
1049 | 1045 | |
|
1050 | 1046 | projectElement = Element('Project') |
|
1051 | 1047 | projectElement.set('id', str(self.id)) |
|
1052 | 1048 | projectElement.set('name', self.name) |
|
1053 | 1049 | projectElement.set('description', self.description) |
|
1054 | 1050 | |
|
1055 | 1051 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1056 | 1052 | procUnitConfObj.makeXml(projectElement) |
|
1057 | 1053 | |
|
1058 | 1054 | self.projectElement = projectElement |
|
1059 | 1055 | |
|
1060 | 1056 | def writeXml(self, filename=None): |
|
1061 | 1057 | |
|
1062 | 1058 | if filename == None: |
|
1063 | 1059 | if self.filename: |
|
1064 | 1060 | filename = self.filename |
|
1065 | 1061 | else: |
|
1066 | 1062 | filename = "schain.xml" |
|
1067 | 1063 | |
|
1068 | 1064 | if not filename: |
|
1069 | 1065 | print "filename has not been defined. Use setFilename(filename) for do it." |
|
1070 | 1066 | return 0 |
|
1071 | 1067 | |
|
1072 | 1068 | abs_file = os.path.abspath(filename) |
|
1073 | 1069 | |
|
1074 | 1070 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
1075 | 1071 | print "No write permission on %s" %os.path.dirname(abs_file) |
|
1076 | 1072 | return 0 |
|
1077 | 1073 | |
|
1078 | 1074 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
1079 | 1075 | print "File %s already exists and it could not be overwriten" %abs_file |
|
1080 | 1076 | return 0 |
|
1081 | 1077 | |
|
1082 | 1078 | self.makeXml() |
|
1083 | 1079 | |
|
1084 | 1080 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
1085 | 1081 | |
|
1086 | 1082 | self.filename = abs_file |
|
1087 | 1083 | |
|
1088 | 1084 | return 1 |
|
1089 | 1085 | |
|
1090 | 1086 | def readXml(self, filename = None): |
|
1091 | 1087 | |
|
1092 | 1088 | if not filename: |
|
1093 | 1089 | print "filename is not defined" |
|
1094 | 1090 | return 0 |
|
1095 | 1091 | |
|
1096 | 1092 | abs_file = os.path.abspath(filename) |
|
1097 | 1093 | |
|
1098 | 1094 | if not os.path.isfile(abs_file): |
|
1099 | 1095 | print "%s file does not exist" %abs_file |
|
1100 | 1096 | return 0 |
|
1101 | 1097 | |
|
1102 | 1098 | self.projectElement = None |
|
1103 | 1099 | self.procUnitConfObjDict = {} |
|
1104 | 1100 | |
|
1105 | 1101 | try: |
|
1106 | 1102 | self.projectElement = ElementTree().parse(abs_file) |
|
1107 | 1103 | except: |
|
1108 | 1104 | print "Error reading %s, verify file format" %filename |
|
1109 | 1105 | return 0 |
|
1110 | 1106 | |
|
1111 | 1107 | self.project = self.projectElement.tag |
|
1112 | 1108 | |
|
1113 | 1109 | self.id = self.projectElement.get('id') |
|
1114 | 1110 | self.name = self.projectElement.get('name') |
|
1115 | 1111 | self.description = self.projectElement.get('description') |
|
1116 | 1112 | |
|
1117 | 1113 | readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) |
|
1118 | 1114 | |
|
1119 | 1115 | for readUnitElement in readUnitElementList: |
|
1120 | 1116 | readUnitConfObj = ReadUnitConf() |
|
1121 | 1117 | readUnitConfObj.readXml(readUnitElement) |
|
1122 | 1118 | |
|
1123 | 1119 | if readUnitConfObj.parentId == None: |
|
1124 | 1120 | readUnitConfObj.parentId = self.id |
|
1125 | 1121 | |
|
1126 | 1122 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1127 | 1123 | |
|
1128 | 1124 | procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) |
|
1129 | 1125 | |
|
1130 | 1126 | for procUnitElement in procUnitElementList: |
|
1131 | 1127 | procUnitConfObj = ProcUnitConf() |
|
1132 | 1128 | procUnitConfObj.readXml(procUnitElement) |
|
1133 | 1129 | |
|
1134 | 1130 | if procUnitConfObj.parentId == None: |
|
1135 | 1131 | procUnitConfObj.parentId = self.id |
|
1136 | 1132 | |
|
1137 | 1133 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1138 | 1134 | |
|
1139 | 1135 | self.filename = abs_file |
|
1140 | 1136 | |
|
1141 | 1137 | return 1 |
|
1142 | 1138 | |
|
1143 | 1139 | def printattr(self): |
|
1144 | 1140 | |
|
1145 | 1141 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
1146 | 1142 | self.name, |
|
1147 | 1143 | self.description) |
|
1148 | 1144 | |
|
1149 | 1145 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1150 | 1146 | procUnitConfObj.printattr() |
|
1151 | 1147 | |
|
1152 | 1148 | def createObjects(self): |
|
1153 | 1149 | |
|
1154 | 1150 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1155 | 1151 | procUnitConfObj.createObjects(self.plotterQueue) |
|
1156 | 1152 | |
|
1157 | 1153 | def __connect(self, objIN, thisObj): |
|
1158 | 1154 | |
|
1159 | 1155 | thisObj.setInput(objIN.getOutputObj()) |
|
1160 | 1156 | |
|
1161 | 1157 | def connectObjects(self): |
|
1162 | 1158 | |
|
1163 | 1159 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1164 | 1160 | |
|
1165 | 1161 | inputId = thisPUConfObj.getInputId() |
|
1166 | 1162 | |
|
1167 | 1163 | if int(inputId) == 0: |
|
1168 | 1164 | continue |
|
1169 | 1165 | |
|
1170 | 1166 | #Get input object |
|
1171 | 1167 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1172 | 1168 | puObjIN = puConfINObj.getProcUnitObj() |
|
1173 | 1169 | |
|
1174 | 1170 | #Get current object |
|
1175 | 1171 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1176 | 1172 | |
|
1177 | 1173 | self.__connect(puObjIN, thisPUObj) |
|
1178 | 1174 | |
|
1179 | 1175 | def __handleError(self, procUnitConfObj, send_email=True): |
|
1180 | 1176 | |
|
1181 | 1177 | import socket |
|
1182 | 1178 | |
|
1183 | 1179 | err = traceback.format_exception(sys.exc_info()[0], |
|
1184 | 1180 | sys.exc_info()[1], |
|
1185 | 1181 | sys.exc_info()[2]) |
|
1186 | 1182 | |
|
1187 | 1183 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1188 | 1184 | print "***** %s" %err[-1] |
|
1189 | 1185 | |
|
1190 | 1186 | message = "".join(err) |
|
1191 | 1187 | |
|
1192 | 1188 | sys.stderr.write(message) |
|
1193 | 1189 | |
|
1194 | 1190 | if not send_email: |
|
1195 | 1191 | return |
|
1196 | 1192 | |
|
1197 | 1193 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) |
|
1198 | 1194 | |
|
1199 | 1195 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
1200 | 1196 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
1201 | 1197 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
1202 | 1198 | subtitle += "Configuration file: %s\n" %self.filename |
|
1203 | 1199 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
1204 | 1200 | |
|
1205 | 1201 | readUnitConfObj = self.getReadUnitObj() |
|
1206 | 1202 | if readUnitConfObj: |
|
1207 | 1203 | subtitle += "\nInput parameters:\n" |
|
1208 | 1204 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path |
|
1209 | 1205 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype |
|
1210 | 1206 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate |
|
1211 | 1207 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate |
|
1212 | 1208 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime |
|
1213 | 1209 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime |
|
1214 | 1210 | |
|
1215 | 1211 | adminObj = schainpy.admin.SchainNotify() |
|
1216 | 1212 | adminObj.sendAlert(message=message, |
|
1217 | 1213 | subject=subject, |
|
1218 | 1214 | subtitle=subtitle, |
|
1219 | 1215 | filename=self.filename) |
|
1220 | 1216 | |
|
1221 | 1217 | def isPaused(self): |
|
1222 | 1218 | return 0 |
|
1223 | 1219 | |
|
1224 | 1220 | def isStopped(self): |
|
1225 | 1221 | return 0 |
|
1226 | 1222 | |
|
1227 | 1223 | def runController(self): |
|
1228 | 1224 | """ |
|
1229 | 1225 | returns 0 when this process has been stopped, 1 otherwise |
|
1230 | 1226 | """ |
|
1231 | 1227 | |
|
1232 | 1228 | if self.isPaused(): |
|
1233 | 1229 | print "Process suspended" |
|
1234 | 1230 | |
|
1235 | 1231 | while True: |
|
1236 | 1232 | sleep(0.1) |
|
1237 | 1233 | |
|
1238 | 1234 | if not self.isPaused(): |
|
1239 | 1235 | break |
|
1240 | 1236 | |
|
1241 | 1237 | if self.isStopped(): |
|
1242 | 1238 | break |
|
1243 | 1239 | |
|
1244 | 1240 | print "Process reinitialized" |
|
1245 | 1241 | |
|
1246 | 1242 | if self.isStopped(): |
|
1247 | 1243 | print "Process stopped" |
|
1248 | 1244 | return 0 |
|
1249 | 1245 | |
|
1250 | 1246 | return 1 |
|
1251 | 1247 | |
|
1252 | 1248 | def setFilename(self, filename): |
|
1253 | 1249 | |
|
1254 | 1250 | self.filename = filename |
|
1255 | 1251 | |
|
1256 | 1252 | def setPlotterQueue(self, plotter_queue): |
|
1257 | 1253 | |
|
1258 | 1254 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1259 | 1255 | |
|
1260 | 1256 | def getPlotterQueue(self): |
|
1261 | 1257 | |
|
1262 | 1258 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1263 | 1259 | |
|
1264 | 1260 | def useExternalPlotter(self): |
|
1265 | 1261 | |
|
1266 | 1262 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1267 | 1263 | |
|
1268 | 1264 | def run(self): |
|
1269 | 1265 | |
|
1270 | 1266 | |
|
1271 | 1267 | print "*"*60 |
|
1272 | 1268 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ |
|
1273 | 1269 | print "*"*60 |
|
1274 | 1270 | |
|
1275 | 1271 | |
|
1276 | 1272 | keyList = self.procUnitConfObjDict.keys() |
|
1277 | 1273 | keyList.sort() |
|
1278 | 1274 | |
|
1279 | 1275 | while(True): |
|
1280 | 1276 | |
|
1281 | 1277 | is_ok = False |
|
1282 | 1278 | |
|
1283 | 1279 | for procKey in keyList: |
|
1284 | 1280 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1285 | 1281 | |
|
1286 | 1282 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1287 | 1283 | |
|
1288 | 1284 | try: |
|
1289 | 1285 | sts = procUnitConfObj.run() |
|
1290 | 1286 | is_ok = is_ok or sts |
|
1291 | 1287 | except KeyboardInterrupt: |
|
1292 | 1288 | is_ok = False |
|
1293 | 1289 | break |
|
1294 | 1290 | except ValueError, e: |
|
1295 | 1291 | sleep(0.5) |
|
1296 | 1292 | self.__handleError(procUnitConfObj, send_email=True) |
|
1297 | 1293 | is_ok = False |
|
1298 | 1294 | break |
|
1299 | 1295 | except: |
|
1300 | 1296 | sleep(0.5) |
|
1301 | 1297 | self.__handleError(procUnitConfObj) |
|
1302 | 1298 | is_ok = False |
|
1303 | 1299 | break |
|
1304 | 1300 | |
|
1305 | 1301 | #If every process unit finished so end process |
|
1306 | 1302 | if not(is_ok): |
|
1307 | 1303 | # print "Every process unit have finished" |
|
1308 | 1304 | break |
|
1309 | 1305 | |
|
1310 | 1306 | if not self.runController(): |
|
1311 | 1307 | break |
|
1312 | 1308 | |
|
1313 | 1309 | #Closing every process |
|
1314 | 1310 | for procKey in keyList: |
|
1315 | 1311 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1316 | 1312 | procUnitConfObj.close() |
|
1317 | 1313 | |
|
1318 | 1314 | print "Process finished" |
|
1319 | 1315 | |
|
1320 | 1316 | def start(self): |
|
1321 | 1317 | |
|
1322 | 1318 | self.writeXml() |
|
1323 | 1319 | self.createObjects() |
|
1324 | 1320 | self.connectObjects() |
|
1325 | 1321 | self.run() |
@@ -1,8 +1,7 | |||
|
1 | 1 | from jroplot_voltage import * |
|
2 | 2 | from jroplot_spectra import * |
|
3 | 3 | from jroplot_heispectra import * |
|
4 | 4 | from jroplot_correlation import * |
|
5 | 5 | from jroplot_parameters import * |
|
6 | 6 | from jroplot_data import * |
|
7 | 7 | from jroplotter import * |
|
8 | No newline at end of file |
@@ -1,690 +1,693 | |||
|
1 | 1 | |
|
2 | 2 | import os |
|
3 | 3 | import zmq |
|
4 | 4 | import time |
|
5 | 5 | import numpy |
|
6 | 6 | import datetime |
|
7 | 7 | import numpy as np |
|
8 | import matplotlib | |
|
9 | matplotlib.use('TkAgg') | |
|
8 | 10 | import matplotlib.pyplot as plt |
|
9 | 11 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
10 | 12 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
11 | 13 | from multiprocessing import Process |
|
12 | 14 | |
|
13 | 15 | from schainpy.model.proc.jroproc_base import Operation |
|
14 | 16 | |
|
15 |
|
|
|
17 | plt.ioff() | |
|
16 | 18 | |
|
17 | 19 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) |
|
18 | 20 | |
|
19 | 21 | d1970 = datetime.datetime(1970,1,1) |
|
20 | 22 | |
|
21 | 23 | class PlotData(Operation, Process): |
|
22 | 24 | |
|
23 | 25 | CODE = 'Figure' |
|
24 | 26 | colormap = 'jro' |
|
25 | 27 | CONFLATE = True |
|
26 | 28 | __MAXNUMX = 80 |
|
27 | 29 | __MAXNUMY = 80 |
|
28 | 30 | __missing = 1E30 |
|
29 | 31 | |
|
30 | 32 | def __init__(self, **kwargs): |
|
31 | 33 | |
|
32 | 34 | Operation.__init__(self, plot=True, **kwargs) |
|
33 | 35 | Process.__init__(self) |
|
34 | 36 | self.kwargs['code'] = self.CODE |
|
35 | 37 | self.mp = False |
|
36 | 38 | self.dataOut = None |
|
37 | 39 | self.isConfig = False |
|
38 | 40 | self.figure = None |
|
39 | 41 | self.axes = [] |
|
40 | 42 | self.localtime = kwargs.pop('localtime', True) |
|
41 | 43 | self.show = kwargs.get('show', True) |
|
42 | 44 | self.save = kwargs.get('save', False) |
|
43 | 45 | self.colormap = kwargs.get('colormap', self.colormap) |
|
44 | 46 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
45 | 47 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
46 | 48 | self.showprofile = kwargs.get('showprofile', True) |
|
47 | 49 | self.title = kwargs.get('wintitle', '') |
|
48 | 50 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
49 | 51 | self.zmin = kwargs.get('zmin', None) |
|
50 | 52 | self.zmax = kwargs.get('zmax', None) |
|
51 | 53 | self.xmin = kwargs.get('xmin', None) |
|
52 | 54 | self.xmax = kwargs.get('xmax', None) |
|
53 | 55 | self.xrange = kwargs.get('xrange', 24) |
|
54 | 56 | self.ymin = kwargs.get('ymin', None) |
|
55 | 57 | self.ymax = kwargs.get('ymax', None) |
|
56 | 58 | self.throttle_value = 5 |
|
57 | 59 | |
|
58 | 60 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
59 | 61 | |
|
60 | 62 | if x_buffer.shape[0] < 2: |
|
61 | 63 | return x_buffer, y_buffer, z_buffer |
|
62 | 64 | |
|
63 | 65 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
64 | 66 | x_median = np.median(deltas) |
|
65 | 67 | |
|
66 | 68 | index = np.where(deltas > 5*x_median) |
|
67 | 69 | |
|
68 | 70 | if len(index[0]) != 0: |
|
69 | 71 | z_buffer[::, index[0], ::] = self.__missing |
|
70 | 72 | z_buffer = np.ma.masked_inside(z_buffer, |
|
71 | 73 | 0.99*self.__missing, |
|
72 | 74 | 1.01*self.__missing) |
|
73 | 75 | |
|
74 | 76 | return x_buffer, y_buffer, z_buffer |
|
75 | 77 | |
|
76 | 78 | def decimate(self): |
|
77 | 79 | |
|
78 | 80 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
79 | 81 | dy = int(len(self.y)/self.__MAXNUMY) + 1 |
|
80 | 82 | |
|
81 | 83 | # x = self.x[::dx] |
|
82 | 84 | x = self.x |
|
83 | 85 | y = self.y[::dy] |
|
84 | 86 | z = self.z[::, ::, ::dy] |
|
85 | 87 | |
|
86 | 88 | return x, y, z |
|
87 | 89 | |
|
88 | 90 | def __plot(self): |
|
89 | 91 | |
|
90 | 92 | print 'plotting...{}'.format(self.CODE) |
|
91 | 93 | |
|
92 | 94 | if self.show: |
|
95 | print 'showing' | |
|
93 | 96 | self.figure.show() |
|
94 | 97 | |
|
95 | 98 | self.plot() |
|
96 | 99 | plt.tight_layout() |
|
97 | 100 | self.figure.canvas.manager.set_window_title('{} {} - Date:{}'.format(self.title, self.CODE.upper(), |
|
98 | 101 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S'))) |
|
99 | 102 | |
|
100 | 103 | if self.save: |
|
101 | 104 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
102 | 105 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
103 | 106 | print 'Saving figure: {}'.format(figname) |
|
104 | 107 | self.figure.savefig(figname) |
|
105 | 108 | |
|
106 | 109 | self.figure.canvas.draw() |
|
107 | 110 | |
|
108 | 111 | def plot(self): |
|
109 | 112 | |
|
110 | 113 | print 'plotting...{}'.format(self.CODE.upper()) |
|
111 | 114 | return |
|
112 | 115 | |
|
113 | 116 | def run(self): |
|
114 | 117 | |
|
115 | 118 | print '[Starting] {}'.format(self.name) |
|
116 | 119 | context = zmq.Context() |
|
117 | 120 | receiver = context.socket(zmq.SUB) |
|
118 | 121 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
119 | 122 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
120 | 123 | receiver.connect("ipc:///tmp/zmq.plots") |
|
121 | 124 | |
|
122 | 125 | while True: |
|
123 | 126 | try: |
|
124 | 127 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) |
|
125 | 128 | self.dataOut = self.data['dataOut'] |
|
126 | 129 | self.times = self.data['times'] |
|
127 | 130 | self.times.sort() |
|
128 | 131 | self.throttle_value = self.data['throttle'] |
|
129 | 132 | self.min_time = self.times[0] |
|
130 | 133 | self.max_time = self.times[-1] |
|
131 | 134 | |
|
132 | 135 | if self.isConfig is False: |
|
133 | 136 | self.setup() |
|
134 | 137 | self.isConfig = True |
|
135 | 138 | self.__plot() |
|
136 | 139 | |
|
137 | 140 | if self.data['ENDED'] is True: |
|
138 | 141 | self.isConfig = False |
|
139 | 142 | |
|
140 | 143 | except zmq.Again as e: |
|
141 | 144 | print 'Waiting for data...' |
|
142 | 145 | plt.pause(self.throttle_value) |
|
143 | 146 | |
|
144 | 147 | def close(self): |
|
145 | 148 | if self.dataOut: |
|
146 | 149 | self.__plot() |
|
147 | 150 | |
|
148 | 151 | |
|
149 | 152 | class PlotSpectraData(PlotData): |
|
150 | 153 | |
|
151 | 154 | CODE = 'spc' |
|
152 | 155 | colormap = 'jro' |
|
153 | 156 | CONFLATE = False |
|
154 | 157 | |
|
155 | 158 | def setup(self): |
|
156 | 159 | |
|
157 | 160 | ncolspan = 1 |
|
158 | 161 | colspan = 1 |
|
159 | 162 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) |
|
160 | 163 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) |
|
161 | 164 | self.width = 3.6*self.ncols |
|
162 | 165 | self.height = 3.2*self.nrows |
|
163 | 166 | if self.showprofile: |
|
164 | 167 | ncolspan = 3 |
|
165 | 168 | colspan = 2 |
|
166 | 169 | self.width += 1.2*self.ncols |
|
167 | 170 | |
|
168 | 171 | self.ylabel = 'Range [Km]' |
|
169 | 172 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
170 | 173 | |
|
171 | 174 | if self.figure is None: |
|
172 | 175 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
173 | 176 | edgecolor='k', |
|
174 | 177 | facecolor='w') |
|
175 | 178 | else: |
|
176 | 179 | self.figure.clf() |
|
177 | 180 | |
|
178 | 181 | n = 0 |
|
179 | 182 | for y in range(self.nrows): |
|
180 | 183 | for x in range(self.ncols): |
|
181 | 184 | if n >= self.dataOut.nChannels: |
|
182 | 185 | break |
|
183 | 186 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) |
|
184 | 187 | if self.showprofile: |
|
185 | 188 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) |
|
186 | 189 | |
|
187 | 190 | ax.firsttime = True |
|
188 | 191 | self.axes.append(ax) |
|
189 | 192 | n += 1 |
|
190 | 193 | |
|
191 | 194 | def plot(self): |
|
192 | 195 | |
|
193 | 196 | if self.xaxis == "frequency": |
|
194 | 197 | x = self.dataOut.getFreqRange(1)/1000. |
|
195 | 198 | xlabel = "Frequency (kHz)" |
|
196 | 199 | elif self.xaxis == "time": |
|
197 | 200 | x = self.dataOut.getAcfRange(1) |
|
198 | 201 | xlabel = "Time (ms)" |
|
199 | 202 | else: |
|
200 | 203 | x = self.dataOut.getVelRange(1) |
|
201 | 204 | xlabel = "Velocity (m/s)" |
|
202 | 205 | |
|
203 | 206 | y = self.dataOut.getHeiRange() |
|
204 | 207 | z = self.data[self.CODE] |
|
205 | 208 | |
|
206 | 209 | for n, ax in enumerate(self.axes): |
|
207 | 210 | |
|
208 | 211 | if ax.firsttime: |
|
209 | 212 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
210 | 213 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
211 | 214 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
212 | 215 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
213 | 216 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
214 | 217 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
215 | 218 | ax.plot = ax.pcolormesh(x, y, z[n].T, |
|
216 | 219 | vmin=self.zmin, |
|
217 | 220 | vmax=self.zmax, |
|
218 | 221 | cmap=plt.get_cmap(self.colormap) |
|
219 | 222 | ) |
|
220 | 223 | divider = make_axes_locatable(ax) |
|
221 | 224 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
222 | 225 | self.figure.add_axes(cax) |
|
223 | 226 | plt.colorbar(ax.plot, cax) |
|
224 | 227 | |
|
225 | 228 | ax.set_xlim(self.xmin, self.xmax) |
|
226 | 229 | ax.set_ylim(self.ymin, self.ymax) |
|
227 | 230 | |
|
228 | 231 | ax.set_ylabel(self.ylabel) |
|
229 | 232 | ax.set_xlabel(xlabel) |
|
230 | 233 | |
|
231 | 234 | ax.firsttime = False |
|
232 | 235 | |
|
233 | 236 | if self.showprofile: |
|
234 | 237 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
235 | 238 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
236 | 239 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
237 | 240 | ax.ax_profile.set_xlabel('dB') |
|
238 | 241 | ax.ax_profile.grid(b=True, axis='x') |
|
239 | 242 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
240 | 243 | color="k", linestyle="dashed", lw=2)[0] |
|
241 | 244 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
242 | 245 | else: |
|
243 | 246 | ax.plot.set_array(z[n].T.ravel()) |
|
244 | 247 | if self.showprofile: |
|
245 | 248 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
246 | 249 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
247 | 250 | |
|
248 | 251 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
249 | 252 | size=8) |
|
250 | 253 | self.saveTime = self.max_time |
|
251 | 254 | |
|
252 | 255 | |
|
253 | 256 | class PlotCrossSpectraData(PlotData): |
|
254 | 257 | |
|
255 | 258 | CODE = 'cspc' |
|
256 | 259 | zmin_coh = None |
|
257 | 260 | zmax_coh = None |
|
258 | 261 | zmin_phase = None |
|
259 | 262 | zmax_phase = None |
|
260 | 263 | CONFLATE = False |
|
261 | 264 | |
|
262 | 265 | def setup(self): |
|
263 | 266 | |
|
264 | 267 | ncolspan = 1 |
|
265 | 268 | colspan = 1 |
|
266 | 269 | self.ncols = 2 |
|
267 | 270 | self.nrows = self.dataOut.nPairs |
|
268 | 271 | self.width = 3.6*self.ncols |
|
269 | 272 | self.height = 3.2*self.nrows |
|
270 | 273 | |
|
271 | 274 | self.ylabel = 'Range [Km]' |
|
272 | 275 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
273 | 276 | |
|
274 | 277 | if self.figure is None: |
|
275 | 278 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
276 | 279 | edgecolor='k', |
|
277 | 280 | facecolor='w') |
|
278 | 281 | else: |
|
279 | 282 | self.figure.clf() |
|
280 | 283 | |
|
281 | 284 | for y in range(self.nrows): |
|
282 | 285 | for x in range(self.ncols): |
|
283 | 286 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) |
|
284 | 287 | ax.firsttime = True |
|
285 | 288 | self.axes.append(ax) |
|
286 | 289 | |
|
287 | 290 | def plot(self): |
|
288 | 291 | |
|
289 | 292 | if self.xaxis == "frequency": |
|
290 | 293 | x = self.dataOut.getFreqRange(1)/1000. |
|
291 | 294 | xlabel = "Frequency (kHz)" |
|
292 | 295 | elif self.xaxis == "time": |
|
293 | 296 | x = self.dataOut.getAcfRange(1) |
|
294 | 297 | xlabel = "Time (ms)" |
|
295 | 298 | else: |
|
296 | 299 | x = self.dataOut.getVelRange(1) |
|
297 | 300 | xlabel = "Velocity (m/s)" |
|
298 | 301 | |
|
299 | 302 | y = self.dataOut.getHeiRange() |
|
300 | 303 | z_coh = self.data['cspc_coh'] |
|
301 | 304 | z_phase = self.data['cspc_phase'] |
|
302 | 305 | |
|
303 | 306 | for n in range(self.nrows): |
|
304 | 307 | ax = self.axes[2*n] |
|
305 | 308 | ax1 = self.axes[2*n+1] |
|
306 | 309 | if ax.firsttime: |
|
307 | 310 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
308 | 311 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
309 | 312 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
310 | 313 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
311 | 314 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 |
|
312 | 315 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 |
|
313 | 316 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 |
|
314 | 317 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 |
|
315 | 318 | |
|
316 | 319 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, |
|
317 | 320 | vmin=self.zmin_coh, |
|
318 | 321 | vmax=self.zmax_coh, |
|
319 | 322 | cmap=plt.get_cmap(self.colormap_coh) |
|
320 | 323 | ) |
|
321 | 324 | divider = make_axes_locatable(ax) |
|
322 | 325 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
323 | 326 | self.figure.add_axes(cax) |
|
324 | 327 | plt.colorbar(ax.plot, cax) |
|
325 | 328 | |
|
326 | 329 | ax.set_xlim(self.xmin, self.xmax) |
|
327 | 330 | ax.set_ylim(self.ymin, self.ymax) |
|
328 | 331 | |
|
329 | 332 | ax.set_ylabel(self.ylabel) |
|
330 | 333 | ax.set_xlabel(xlabel) |
|
331 | 334 | ax.firsttime = False |
|
332 | 335 | |
|
333 | 336 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, |
|
334 | 337 | vmin=self.zmin_phase, |
|
335 | 338 | vmax=self.zmax_phase, |
|
336 | 339 | cmap=plt.get_cmap(self.colormap_phase) |
|
337 | 340 | ) |
|
338 | 341 | divider = make_axes_locatable(ax1) |
|
339 | 342 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
340 | 343 | self.figure.add_axes(cax) |
|
341 | 344 | plt.colorbar(ax1.plot, cax) |
|
342 | 345 | |
|
343 | 346 | ax1.set_xlim(self.xmin, self.xmax) |
|
344 | 347 | ax1.set_ylim(self.ymin, self.ymax) |
|
345 | 348 | |
|
346 | 349 | ax1.set_ylabel(self.ylabel) |
|
347 | 350 | ax1.set_xlabel(xlabel) |
|
348 | 351 | ax1.firsttime = False |
|
349 | 352 | else: |
|
350 | 353 | ax.plot.set_array(z_coh[n].T.ravel()) |
|
351 | 354 | ax1.plot.set_array(z_phase[n].T.ravel()) |
|
352 | 355 | |
|
353 | 356 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
354 | 357 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
355 | 358 | self.saveTime = self.max_time |
|
356 | 359 | |
|
357 | 360 | |
|
358 | 361 | class PlotSpectraMeanData(PlotSpectraData): |
|
359 | 362 | |
|
360 | 363 | CODE = 'spc_mean' |
|
361 | 364 | colormap = 'jet' |
|
362 | 365 | |
|
363 | 366 | def plot(self): |
|
364 | 367 | |
|
365 | 368 | if self.xaxis == "frequency": |
|
366 | 369 | x = self.dataOut.getFreqRange(1)/1000. |
|
367 | 370 | xlabel = "Frequency (kHz)" |
|
368 | 371 | elif self.xaxis == "time": |
|
369 | 372 | x = self.dataOut.getAcfRange(1) |
|
370 | 373 | xlabel = "Time (ms)" |
|
371 | 374 | else: |
|
372 | 375 | x = self.dataOut.getVelRange(1) |
|
373 | 376 | xlabel = "Velocity (m/s)" |
|
374 | 377 | |
|
375 | 378 | y = self.dataOut.getHeiRange() |
|
376 | 379 | z = self.data['spc'] |
|
377 | 380 | mean = self.data['mean'][self.max_time] |
|
378 | 381 | |
|
379 | 382 | for n, ax in enumerate(self.axes): |
|
380 | 383 | |
|
381 | 384 | if ax.firsttime: |
|
382 | 385 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
383 | 386 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
384 | 387 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
385 | 388 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
386 | 389 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
387 | 390 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
388 | 391 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
389 | 392 | vmin=self.zmin, |
|
390 | 393 | vmax=self.zmax, |
|
391 | 394 | cmap=plt.get_cmap(self.colormap) |
|
392 | 395 | ) |
|
393 | 396 | ax.plt_dop = ax.plot(mean[n], y, |
|
394 | 397 | color='k')[0] |
|
395 | 398 | |
|
396 | 399 | divider = make_axes_locatable(ax) |
|
397 | 400 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
398 | 401 | self.figure.add_axes(cax) |
|
399 | 402 | plt.colorbar(ax.plt, cax) |
|
400 | 403 | |
|
401 | 404 | ax.set_xlim(self.xmin, self.xmax) |
|
402 | 405 | ax.set_ylim(self.ymin, self.ymax) |
|
403 | 406 | |
|
404 | 407 | ax.set_ylabel(self.ylabel) |
|
405 | 408 | ax.set_xlabel(xlabel) |
|
406 | 409 | |
|
407 | 410 | ax.firsttime = False |
|
408 | 411 | |
|
409 | 412 | if self.showprofile: |
|
410 | 413 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
411 | 414 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
412 | 415 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
413 | 416 | ax.ax_profile.set_xlabel('dB') |
|
414 | 417 | ax.ax_profile.grid(b=True, axis='x') |
|
415 | 418 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
416 | 419 | color="k", linestyle="dashed", lw=2)[0] |
|
417 | 420 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
418 | 421 | else: |
|
419 | 422 | ax.plt.set_array(z[n].T.ravel()) |
|
420 | 423 | ax.plt_dop.set_data(mean[n], y) |
|
421 | 424 | if self.showprofile: |
|
422 | 425 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
423 | 426 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
424 | 427 | |
|
425 | 428 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
426 | 429 | size=8) |
|
427 | 430 | self.saveTime = self.max_time |
|
428 | 431 | |
|
429 | 432 | |
|
430 | 433 | class PlotRTIData(PlotData): |
|
431 | 434 | |
|
432 | 435 | CODE = 'rti' |
|
433 | 436 | colormap = 'jro' |
|
434 | 437 | |
|
435 | 438 | def setup(self): |
|
436 | 439 | self.ncols = 1 |
|
437 | 440 | self.nrows = self.dataOut.nChannels |
|
438 | 441 | self.width = 10 |
|
439 | 442 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
440 | 443 | if self.nrows==1: |
|
441 | 444 | self.height += 1 |
|
442 | 445 | self.ylabel = 'Range [Km]' |
|
443 | 446 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
444 | 447 | |
|
445 | 448 | if self.figure is None: |
|
446 | 449 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
447 | 450 | edgecolor='k', |
|
448 | 451 | facecolor='w') |
|
449 | 452 | else: |
|
450 | 453 | self.figure.clf() |
|
451 | 454 | self.axes = [] |
|
452 | 455 | |
|
453 | 456 | for n in range(self.nrows): |
|
454 | 457 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
455 | 458 | ax.firsttime = True |
|
456 | 459 | self.axes.append(ax) |
|
457 | 460 | |
|
458 | 461 | def plot(self): |
|
459 | 462 | |
|
460 | 463 | self.x = np.array(self.times) |
|
461 | 464 | self.y = self.dataOut.getHeiRange() |
|
462 | 465 | self.z = [] |
|
463 | 466 | |
|
464 | 467 | for ch in range(self.nrows): |
|
465 | 468 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
466 | 469 | |
|
467 | 470 | self.z = np.array(self.z) |
|
468 | 471 | for n, ax in enumerate(self.axes): |
|
469 | 472 | |
|
470 | 473 | x, y, z = self.fill_gaps(*self.decimate()) |
|
471 | 474 | xmin = self.min_time |
|
472 | 475 | xmax = xmin+self.xrange*60*60 |
|
473 | 476 | if ax.firsttime: |
|
474 | 477 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
475 | 478 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
476 | 479 | self.zmin = self.zmin if self.zmin else np.nanmin(self.z) |
|
477 | 480 | self.zmax = self.zmax if self.zmax else np.nanmax(self.z) |
|
478 | 481 | plot = ax.pcolormesh(x, y, z[n].T, |
|
479 | 482 | vmin=self.zmin, |
|
480 | 483 | vmax=self.zmax, |
|
481 | 484 | cmap=plt.get_cmap(self.colormap) |
|
482 | 485 | ) |
|
483 | 486 | divider = make_axes_locatable(ax) |
|
484 | 487 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
485 | 488 | self.figure.add_axes(cax) |
|
486 | 489 | plt.colorbar(plot, cax) |
|
487 | 490 | ax.set_ylim(self.ymin, self.ymax) |
|
488 | 491 | |
|
489 | 492 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
490 | 493 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
491 | 494 | |
|
492 | 495 | ax.set_ylabel(self.ylabel) |
|
493 | 496 | |
|
494 | 497 | # if self.xmin is None: |
|
495 | 498 | # xmin = self.min_time |
|
496 | 499 | # else: |
|
497 | 500 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
498 | 501 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
499 | 502 | |
|
500 | 503 | ax.set_xlim(xmin, xmax) |
|
501 | 504 | ax.firsttime = False |
|
502 | 505 | else: |
|
503 | 506 | ax.collections.remove(ax.collections[0]) |
|
504 | 507 | ax.set_xlim(xmin, xmax) |
|
505 | 508 | plot = ax.pcolormesh(x, y, z[n].T, |
|
506 | 509 | vmin=self.zmin, |
|
507 | 510 | vmax=self.zmax, |
|
508 | 511 | cmap=plt.get_cmap(self.colormap) |
|
509 | 512 | ) |
|
510 | 513 | ax.set_title('{} {}'.format(self.titles[n], |
|
511 | 514 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
512 | 515 | size=8) |
|
513 | 516 | |
|
514 | 517 | self.saveTime = self.min_time |
|
515 | 518 | |
|
516 | 519 | |
|
517 | 520 | class PlotCOHData(PlotRTIData): |
|
518 | 521 | |
|
519 | 522 | CODE = 'coh' |
|
520 | 523 | |
|
521 | 524 | def setup(self): |
|
522 | 525 | |
|
523 | 526 | self.ncols = 1 |
|
524 | 527 | self.nrows = self.dataOut.nPairs |
|
525 | 528 | self.width = 10 |
|
526 | 529 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
527 | 530 | if self.nrows==1: |
|
528 | 531 | self.height += 1 |
|
529 | 532 | self.ylabel = 'Range [Km]' |
|
530 | 533 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] |
|
531 | 534 | |
|
532 | 535 | if self.figure is None: |
|
533 | 536 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
534 | 537 | edgecolor='k', |
|
535 | 538 | facecolor='w') |
|
536 | 539 | else: |
|
537 | 540 | self.figure.clf() |
|
538 | 541 | self.axes = [] |
|
539 | 542 | |
|
540 | 543 | for n in range(self.nrows): |
|
541 | 544 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
542 | 545 | ax.firsttime = True |
|
543 | 546 | self.axes.append(ax) |
|
544 | 547 | |
|
545 | 548 | |
|
546 | 549 | class PlotNoiseData(PlotData): |
|
547 | 550 | CODE = 'noise' |
|
548 | 551 | |
|
549 | 552 | def setup(self): |
|
550 | 553 | |
|
551 | 554 | self.ncols = 1 |
|
552 | 555 | self.nrows = 1 |
|
553 | 556 | self.width = 10 |
|
554 | 557 | self.height = 3.2 |
|
555 | 558 | self.ylabel = 'Intensity [dB]' |
|
556 | 559 | self.titles = ['Noise'] |
|
557 | 560 | |
|
558 | 561 | if self.figure is None: |
|
559 | 562 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
560 | 563 | edgecolor='k', |
|
561 | 564 | facecolor='w') |
|
562 | 565 | else: |
|
563 | 566 | self.figure.clf() |
|
564 | 567 | self.axes = [] |
|
565 | 568 | |
|
566 | 569 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) |
|
567 | 570 | self.ax.firsttime = True |
|
568 | 571 | |
|
569 | 572 | def plot(self): |
|
570 | 573 | |
|
571 | 574 | x = self.times |
|
572 | 575 | xmin = self.min_time |
|
573 | 576 | xmax = xmin+self.xrange*60*60 |
|
574 | 577 | if self.ax.firsttime: |
|
575 | 578 | for ch in self.dataOut.channelList: |
|
576 | 579 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
577 | 580 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
578 | 581 | self.ax.firsttime = False |
|
579 | 582 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
580 | 583 | self.ax.xaxis.set_major_locator(LinearLocator(6)) |
|
581 | 584 | self.ax.set_ylabel(self.ylabel) |
|
582 | 585 | plt.legend() |
|
583 | 586 | else: |
|
584 | 587 | for ch in self.dataOut.channelList: |
|
585 | 588 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
586 | 589 | self.ax.lines[ch].set_data(x, y) |
|
587 | 590 | |
|
588 | 591 | self.ax.set_xlim(xmin, xmax) |
|
589 | 592 | self.ax.set_ylim(min(y)-5, max(y)+5) |
|
590 | 593 | self.saveTime = self.min_time |
|
591 | 594 | |
|
592 | 595 | |
|
593 | 596 | class PlotWindProfilerData(PlotRTIData): |
|
594 | 597 | CODE = 'wind' |
|
595 | 598 | colormap = 'seismic' |
|
596 | 599 | |
|
597 | 600 | def setup(self): |
|
598 | 601 | self.ncols = 1 |
|
599 | 602 | self.nrows = self.dataOut.data_output.shape[0] |
|
600 | 603 | self.width = 10 |
|
601 | 604 | self.height = 2.2*self.nrows |
|
602 | 605 | self.ylabel = 'Height [Km]' |
|
603 | 606 | self.titles = ['Zonal' ,'Meridional', 'Vertical'] |
|
604 | 607 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
605 | 608 | self.windFactor = [1, 1, 100] |
|
606 | 609 | |
|
607 | 610 | if self.figure is None: |
|
608 | 611 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
609 | 612 | edgecolor='k', |
|
610 | 613 | facecolor='w') |
|
611 | 614 | else: |
|
612 | 615 | self.figure.clf() |
|
613 | 616 | self.axes = [] |
|
614 | 617 | |
|
615 | 618 | for n in range(self.nrows): |
|
616 | 619 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
617 | 620 | ax.firsttime = True |
|
618 | 621 | self.axes.append(ax) |
|
619 | 622 | |
|
620 | 623 | def plot(self): |
|
621 | 624 | |
|
622 | 625 | self.x = np.array(self.times) |
|
623 | 626 | self.y = self.dataOut.heightList |
|
624 | 627 | self.z = [] |
|
625 | 628 | |
|
626 | 629 | for ch in range(self.nrows): |
|
627 | 630 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
628 | 631 | |
|
629 | 632 | self.z = np.array(self.z) |
|
630 | 633 | self.z = numpy.ma.masked_invalid(self.z) |
|
631 | 634 | |
|
632 | 635 | cmap=plt.get_cmap(self.colormap) |
|
633 | 636 | cmap.set_bad('white', 1.) |
|
634 | 637 | |
|
635 | 638 | for n, ax in enumerate(self.axes): |
|
636 | 639 | x, y, z = self.fill_gaps(*self.decimate()) |
|
637 | 640 | xmin = self.min_time |
|
638 | 641 | xmax = xmin+self.xrange*60*60 |
|
639 | 642 | if ax.firsttime: |
|
640 | 643 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
641 | 644 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
642 | 645 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) |
|
643 | 646 | self.zmin = self.zmin if self.zmin else -self.zmax |
|
644 | 647 | |
|
645 | 648 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
646 | 649 | vmin=self.zmin, |
|
647 | 650 | vmax=self.zmax, |
|
648 | 651 | cmap=cmap |
|
649 | 652 | ) |
|
650 | 653 | divider = make_axes_locatable(ax) |
|
651 | 654 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
652 | 655 | cax.set_ylabel(self.clabels[n]) |
|
653 | 656 | self.figure.add_axes(cax) |
|
654 | 657 | plt.colorbar(plot, cax) |
|
655 | 658 | ax.set_ylim(self.ymin, self.ymax) |
|
656 | 659 | |
|
657 | 660 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
658 | 661 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
659 | 662 | |
|
660 | 663 | ax.set_ylabel(self.ylabel) |
|
661 | 664 | |
|
662 | 665 | ax.set_xlim(xmin, xmax) |
|
663 | 666 | ax.firsttime = False |
|
664 | 667 | else: |
|
665 | 668 | ax.collections.remove(ax.collections[0]) |
|
666 | 669 | ax.set_xlim(xmin, xmax) |
|
667 | 670 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
668 | 671 | vmin=self.zmin, |
|
669 | 672 | vmax=self.zmax, |
|
670 | 673 | cmap=plt.get_cmap(self.colormap) |
|
671 | 674 | ) |
|
672 | 675 | ax.set_title('{} {}'.format(self.titles[n], |
|
673 | 676 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
674 | 677 | size=8) |
|
675 | 678 | |
|
676 | 679 | self.saveTime = self.min_time |
|
677 | 680 | |
|
678 | 681 | |
|
679 | 682 | class PlotSNRData(PlotRTIData): |
|
680 | 683 | CODE = 'snr' |
|
681 | 684 | colormap = 'jet' |
|
682 | 685 | |
|
683 | 686 | class PlotDOPData(PlotRTIData): |
|
684 | 687 | CODE = 'dop' |
|
685 | 688 | colormap = 'jet' |
|
686 | 689 | |
|
687 | 690 | |
|
688 | 691 | class PlotPHASEData(PlotCOHData): |
|
689 | 692 | CODE = 'phase' |
|
690 | 693 | colormap = 'seismic' |
@@ -1,240 +1,240 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os, sys |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | import traceback |
|
10 | 10 | |
|
11 | 11 | from time import sleep |
|
12 | 12 | from threading import Lock |
|
13 | 13 | # from threading import Thread |
|
14 | 14 | |
|
15 | 15 | import schainpy |
|
16 | 16 | import schainpy.admin |
|
17 | 17 | |
|
18 | 18 | from schainpy.model.proc.jroproc_base import Operation |
|
19 | 19 | from schainpy.model.serializer.data import obj2Dict, dict2Obj |
|
20 | 20 | from jroplot_correlation import * |
|
21 | 21 | from jroplot_heispectra import * |
|
22 | 22 | from jroplot_parameters import * |
|
23 | 23 | from jroplot_spectra import * |
|
24 | 24 | from jroplot_voltage import * |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | class Plotter(Operation): |
|
28 | 28 | |
|
29 | 29 | isConfig = None |
|
30 | 30 | name = None |
|
31 | 31 | __queue = None |
|
32 | 32 | |
|
33 | def __init__(self, plotter_name, plotter_queue=None): | |
|
33 | def __init__(self, plotter_name, plotter_queue=None, **kwargs): | |
|
34 | 34 | |
|
35 | Operation.__init__(self) | |
|
35 | Operation.__init__(self, **kwargs) | |
|
36 | 36 | |
|
37 | 37 | self.isConfig = False |
|
38 | 38 | self.name = plotter_name |
|
39 | 39 | self.__queue = plotter_queue |
|
40 | 40 | |
|
41 | 41 | def getSubplots(self): |
|
42 | 42 | |
|
43 | 43 | nrow = self.nplots |
|
44 | 44 | ncol = 1 |
|
45 | 45 | return nrow, ncol |
|
46 | 46 | |
|
47 | 47 | def setup(self, **kwargs): |
|
48 | 48 | |
|
49 | 49 | print "Initializing ..." |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | def run(self, dataOut, id=None, **kwargs): |
|
53 | 53 | |
|
54 | 54 | """ |
|
55 | 55 | |
|
56 | 56 | Input: |
|
57 | 57 | dataOut : |
|
58 | 58 | id : |
|
59 | 59 | """ |
|
60 | 60 | |
|
61 | 61 | packDict = {} |
|
62 | 62 | |
|
63 | 63 | packDict['id'] = id |
|
64 | 64 | packDict['name'] = self.name |
|
65 | 65 | packDict['kwargs'] = kwargs |
|
66 | 66 | |
|
67 | 67 | # packDict['data'] = obj2Dict(dataOut) |
|
68 | 68 | packDict['data'] = dataOut |
|
69 | 69 | |
|
70 | 70 | self.__queue.put(packDict) |
|
71 | 71 | |
|
72 | 72 | # class PlotManager(Thread): |
|
73 | 73 | class PlotManager(): |
|
74 | 74 | |
|
75 | 75 | __err = False |
|
76 | 76 | __stop = False |
|
77 | 77 | __realtime = False |
|
78 | 78 | |
|
79 | 79 | controllerThreadObj = None |
|
80 | 80 | |
|
81 | 81 | plotterList = ['Scope', |
|
82 | 82 | 'SpectraPlot', 'RTIPlot', |
|
83 | 83 | 'SpectraCutPlot', |
|
84 | 84 | 'CrossSpectraPlot', 'CoherenceMap', |
|
85 | 85 | 'PowerProfilePlot', 'Noise', 'BeaconPhase', |
|
86 | 86 | 'CorrelationPlot', |
|
87 | 87 | 'SpectraHeisScope','RTIfromSpectraHeis'] |
|
88 | 88 | |
|
89 | 89 | def __init__(self, plotter_queue): |
|
90 | 90 | |
|
91 | 91 | # Thread.__init__(self) |
|
92 | 92 | # self.setDaemon(True) |
|
93 | 93 | |
|
94 | 94 | self.__queue = plotter_queue |
|
95 | 95 | self.__lock = Lock() |
|
96 | 96 | |
|
97 | 97 | self.plotInstanceDict = {} |
|
98 | 98 | |
|
99 | 99 | self.__err = False |
|
100 | 100 | self.__stop = False |
|
101 | 101 | self.__realtime = False |
|
102 | 102 | |
|
103 | 103 | def __handleError(self, name="", send_email=False): |
|
104 | 104 | |
|
105 | 105 | err = traceback.format_exception(sys.exc_info()[0], |
|
106 | 106 | sys.exc_info()[1], |
|
107 | 107 | sys.exc_info()[2]) |
|
108 | 108 | |
|
109 | 109 | print "***** Error occurred in PlotManager *****" |
|
110 | 110 | print "***** [%s]: %s" %(name, err[-1]) |
|
111 | 111 | |
|
112 | 112 | message = "\nError ocurred in %s:\n" %name |
|
113 | 113 | message += "".join(err) |
|
114 | 114 | |
|
115 | 115 | sys.stderr.write(message) |
|
116 | 116 | |
|
117 | 117 | if not send_email: |
|
118 | 118 | return |
|
119 | 119 | |
|
120 | 120 | import socket |
|
121 | 121 | |
|
122 | 122 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name) |
|
123 | 123 | |
|
124 | 124 | subtitle = "%s:\n" %(name) |
|
125 | 125 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
126 | 126 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
127 | 127 | # subtitle += "Configuration file: %s\n" %self.filename |
|
128 | 128 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
129 | 129 | |
|
130 | 130 | adminObj = schainpy.admin.SchainNotify() |
|
131 | 131 | adminObj.sendAlert(message=message, |
|
132 | 132 | subject=subject, |
|
133 | 133 | subtitle=subtitle) |
|
134 | 134 | |
|
135 | 135 | def run(self): |
|
136 | 136 | |
|
137 | 137 | if self.__queue.empty(): |
|
138 | 138 | return |
|
139 | 139 | |
|
140 | 140 | if self.__err: |
|
141 | 141 | serial_data = self.__queue.get() |
|
142 | 142 | self.__queue.task_done() |
|
143 | 143 | return |
|
144 | 144 | |
|
145 | 145 | self.__lock.acquire() |
|
146 | 146 | |
|
147 | 147 | # if self.__queue.full(): |
|
148 | 148 | # for i in range(int(self.__queue.qsize()/2)): |
|
149 | 149 | # serial_data = self.__queue.get() |
|
150 | 150 | # self.__queue.task_done() |
|
151 | 151 | |
|
152 | 152 | n = int(self.__queue.qsize()/3 + 1) |
|
153 | 153 | |
|
154 | 154 | for i in range(n): |
|
155 | 155 | |
|
156 | 156 | if self.__queue.empty(): |
|
157 | 157 | break |
|
158 | 158 | |
|
159 | 159 | serial_data = self.__queue.get() |
|
160 | 160 | self.__queue.task_done() |
|
161 | 161 | |
|
162 | 162 | plot_id = serial_data['id'] |
|
163 | 163 | plot_name = serial_data['name'] |
|
164 | 164 | kwargs = serial_data['kwargs'] |
|
165 | 165 | # dataDict = serial_data['data'] |
|
166 | 166 | # |
|
167 | 167 | # dataPlot = dict2Obj(dataDict) |
|
168 | 168 | |
|
169 | 169 | dataPlot = serial_data['data'] |
|
170 | 170 | |
|
171 | 171 | if plot_id not in self.plotInstanceDict.keys(): |
|
172 | 172 | className = eval(plot_name) |
|
173 | self.plotInstanceDict[plot_id] = className() | |
|
173 | self.plotInstanceDict[plot_id] = className(**kwargs) | |
|
174 | 174 | |
|
175 | 175 | plotter = self.plotInstanceDict[plot_id] |
|
176 | 176 | try: |
|
177 | 177 | plotter.run(dataPlot, plot_id, **kwargs) |
|
178 | 178 | except: |
|
179 | 179 | self.__err = True |
|
180 | 180 | self.__handleError(plot_name, send_email=True) |
|
181 | 181 | break |
|
182 | 182 | |
|
183 | 183 | self.__lock.release() |
|
184 | 184 | |
|
185 | 185 | def isEmpty(self): |
|
186 | 186 | |
|
187 | 187 | return self.__queue.empty() |
|
188 | 188 | |
|
189 | 189 | def stop(self): |
|
190 | 190 | |
|
191 | 191 | self.__lock.acquire() |
|
192 | 192 | |
|
193 | 193 | self.__stop = True |
|
194 | 194 | |
|
195 | 195 | self.__lock.release() |
|
196 | 196 | |
|
197 | 197 | def close(self): |
|
198 | 198 | |
|
199 | 199 | self.__lock.acquire() |
|
200 | 200 | |
|
201 | 201 | for plot_id in self.plotInstanceDict.keys(): |
|
202 | 202 | plotter = self.plotInstanceDict[plot_id] |
|
203 | 203 | plotter.close() |
|
204 | 204 | |
|
205 | 205 | self.__lock.release() |
|
206 | 206 | |
|
207 | 207 | def setController(self, controllerThreadObj): |
|
208 | 208 | |
|
209 | 209 | self.controllerThreadObj = controllerThreadObj |
|
210 | 210 | |
|
211 | 211 | def start(self): |
|
212 | 212 | |
|
213 | 213 | if not self.controllerThreadObj.isRunning(): |
|
214 | 214 | raise RuntimeError, "controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method" |
|
215 | 215 | |
|
216 | 216 | self.join() |
|
217 | 217 | |
|
218 | 218 | def join(self): |
|
219 | 219 | |
|
220 | 220 | #Execute plotter while controller is running |
|
221 | 221 | while self.controllerThreadObj.isRunning(): |
|
222 | 222 | self.run() |
|
223 | 223 | |
|
224 | 224 | self.controllerThreadObj.stop() |
|
225 | 225 | |
|
226 | 226 | #Wait until plotter queue is empty |
|
227 | 227 | while not self.isEmpty(): |
|
228 | 228 | self.run() |
|
229 | 229 | |
|
230 | 230 | self.close() |
|
231 | 231 | |
|
232 | 232 | def isErrorDetected(self): |
|
233 | 233 | |
|
234 | 234 | self.__lock.acquire() |
|
235 | 235 | |
|
236 | 236 | err = self.__err |
|
237 | 237 | |
|
238 | 238 | self.__lock.release() |
|
239 | 239 | |
|
240 | 240 | return err |
|
1 | NO CONTENT: modified file |
@@ -1,445 +1,445 | |||
|
1 | 1 | ''' |
|
2 | 2 | @author: Juan C. Espinoza |
|
3 | 3 | ''' |
|
4 | 4 | |
|
5 | 5 | import time |
|
6 | 6 | import json |
|
7 | 7 | import numpy |
|
8 | 8 | import paho.mqtt.client as mqtt |
|
9 | 9 | import zmq |
|
10 | 10 | import cPickle as pickle |
|
11 | 11 | import datetime |
|
12 | 12 | from zmq.utils.monitor import recv_monitor_message |
|
13 | 13 | from functools import wraps |
|
14 | 14 | from threading import Thread |
|
15 | 15 | from multiprocessing import Process |
|
16 | 16 | |
|
17 | 17 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
18 | 18 | |
|
19 | 19 | MAXNUMX = 100 |
|
20 | 20 | MAXNUMY = 100 |
|
21 | 21 | |
|
22 | 22 | class PrettyFloat(float): |
|
23 | 23 | def __repr__(self): |
|
24 | 24 | return '%.2f' % self |
|
25 | 25 | |
|
26 | 26 | def roundFloats(obj): |
|
27 | 27 | if isinstance(obj, list): |
|
28 | 28 | return map(roundFloats, obj) |
|
29 | 29 | elif isinstance(obj, float): |
|
30 | 30 | return round(obj, 2) |
|
31 | 31 | |
|
32 | 32 | def decimate(z): |
|
33 | 33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
34 | 34 | |
|
35 | 35 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
36 | 36 | |
|
37 | 37 | return z[::, ::dy] |
|
38 | 38 | |
|
39 | 39 | class throttle(object): |
|
40 | 40 | """Decorator that prevents a function from being called more than once every |
|
41 | 41 | time period. |
|
42 | 42 | To create a function that cannot be called more than once a minute, but |
|
43 | 43 | will sleep until it can be called: |
|
44 | 44 | @throttle(minutes=1) |
|
45 | 45 | def foo(): |
|
46 | 46 | pass |
|
47 | 47 | |
|
48 | 48 | for i in range(10): |
|
49 | 49 | foo() |
|
50 | 50 | print "This function has run %s times." % i |
|
51 | 51 | """ |
|
52 | 52 | |
|
53 | 53 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
54 | 54 | self.throttle_period = datetime.timedelta( |
|
55 | 55 | seconds=seconds, minutes=minutes, hours=hours |
|
56 | 56 | ) |
|
57 | 57 | |
|
58 | 58 | self.time_of_last_call = datetime.datetime.min |
|
59 | 59 | |
|
60 | 60 | def __call__(self, fn): |
|
61 | 61 | @wraps(fn) |
|
62 | 62 | def wrapper(*args, **kwargs): |
|
63 | 63 | now = datetime.datetime.now() |
|
64 | 64 | time_since_last_call = now - self.time_of_last_call |
|
65 | 65 | time_left = self.throttle_period - time_since_last_call |
|
66 | 66 | |
|
67 | 67 | if time_left > datetime.timedelta(seconds=0): |
|
68 | 68 | return |
|
69 | 69 | |
|
70 | 70 | self.time_of_last_call = datetime.datetime.now() |
|
71 | 71 | return fn(*args, **kwargs) |
|
72 | 72 | |
|
73 | 73 | return wrapper |
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | class PublishData(Operation): |
|
77 | 77 | """Clase publish.""" |
|
78 | 78 | |
|
79 | 79 | def __init__(self, **kwargs): |
|
80 | 80 | """Inicio.""" |
|
81 | 81 | Operation.__init__(self, **kwargs) |
|
82 | 82 | self.isConfig = False |
|
83 | 83 | self.client = None |
|
84 | 84 | self.zeromq = None |
|
85 | 85 | self.mqtt = None |
|
86 | 86 | |
|
87 | 87 | def on_disconnect(self, client, userdata, rc): |
|
88 | 88 | if rc != 0: |
|
89 | 89 | print("Unexpected disconnection.") |
|
90 | 90 | self.connect() |
|
91 | 91 | |
|
92 | 92 | def connect(self): |
|
93 | 93 | print 'trying to connect' |
|
94 | 94 | try: |
|
95 | 95 | self.client.connect( |
|
96 | 96 | host=self.host, |
|
97 | 97 | port=self.port, |
|
98 | 98 | keepalive=60*10, |
|
99 | 99 | bind_address='') |
|
100 | 100 | self.client.loop_start() |
|
101 | 101 | # self.client.publish( |
|
102 | 102 | # self.topic + 'SETUP', |
|
103 | 103 | # json.dumps(setup), |
|
104 | 104 | # retain=True |
|
105 | 105 | # ) |
|
106 | 106 | except: |
|
107 | 107 | print "MQTT Conection error." |
|
108 | 108 | self.client = False |
|
109 | 109 | |
|
110 | 110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, **kwargs): |
|
111 | 111 | self.counter = 0 |
|
112 | 112 | self.topic = kwargs.get('topic', 'schain') |
|
113 | 113 | self.delay = kwargs.get('delay', 0) |
|
114 | 114 | self.plottype = kwargs.get('plottype', 'spectra') |
|
115 | 115 | self.host = kwargs.get('host', "10.10.10.82") |
|
116 | 116 | self.port = kwargs.get('port', 3000) |
|
117 | 117 | self.clientId = clientId |
|
118 | 118 | self.cnt = 0 |
|
119 | 119 | self.zeromq = zeromq |
|
120 | 120 | self.mqtt = kwargs.get('plottype', 0) |
|
121 | 121 | self.client = None |
|
122 | 122 | setup = [] |
|
123 | 123 | if mqtt is 1: |
|
124 | 124 | self.client = mqtt.Client( |
|
125 | 125 | client_id=self.clientId + self.topic + 'SCHAIN', |
|
126 | 126 | clean_session=True) |
|
127 | 127 | self.client.on_disconnect = self.on_disconnect |
|
128 | 128 | self.connect() |
|
129 | 129 | for plot in self.plottype: |
|
130 | 130 | setup.append({ |
|
131 | 131 | 'plot': plot, |
|
132 | 132 | 'topic': self.topic + plot, |
|
133 | 133 | 'title': getattr(self, plot + '_' + 'title', False), |
|
134 | 134 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), |
|
135 | 135 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), |
|
136 | 136 | 'xrange': getattr(self, plot + '_' + 'xrange', False), |
|
137 | 137 | 'yrange': getattr(self, plot + '_' + 'yrange', False), |
|
138 | 138 | 'zrange': getattr(self, plot + '_' + 'zrange', False), |
|
139 | 139 | }) |
|
140 | 140 | if zeromq is 1: |
|
141 | 141 | context = zmq.Context() |
|
142 | 142 | self.zmq_socket = context.socket(zmq.PUSH) |
|
143 | 143 | server = kwargs.get('server', 'zmq.pipe') |
|
144 | 144 | |
|
145 | 145 | if 'tcp://' in server: |
|
146 | 146 | address = server |
|
147 | 147 | else: |
|
148 | 148 | address = 'ipc:///tmp/%s' % server |
|
149 | 149 | |
|
150 | 150 | self.zmq_socket.connect(address) |
|
151 | 151 | time.sleep(1) |
|
152 | 152 | |
|
153 | 153 | def publish_data(self): |
|
154 | 154 | self.dataOut.finished = False |
|
155 | 155 | if self.mqtt is 1: |
|
156 | 156 | yData = self.dataOut.heightList[:2].tolist() |
|
157 | 157 | if self.plottype == 'spectra': |
|
158 | 158 | data = getattr(self.dataOut, 'data_spc') |
|
159 | 159 | z = data/self.dataOut.normFactor |
|
160 | 160 | zdB = 10*numpy.log10(z) |
|
161 | 161 | xlen, ylen = zdB[0].shape |
|
162 | 162 | dx = int(xlen/MAXNUMX) + 1 |
|
163 | 163 | dy = int(ylen/MAXNUMY) + 1 |
|
164 | 164 | Z = [0 for i in self.dataOut.channelList] |
|
165 | 165 | for i in self.dataOut.channelList: |
|
166 | 166 | Z[i] = zdB[i][::dx, ::dy].tolist() |
|
167 | 167 | payload = { |
|
168 | 168 | 'timestamp': self.dataOut.utctime, |
|
169 | 169 | 'data': roundFloats(Z), |
|
170 | 170 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
171 | 171 | 'interval': self.dataOut.getTimeInterval(), |
|
172 | 172 | 'type': self.plottype, |
|
173 | 173 | 'yData': yData |
|
174 | 174 | } |
|
175 | 175 | # print payload |
|
176 | 176 | |
|
177 | 177 | elif self.plottype in ('rti', 'power'): |
|
178 | 178 | data = getattr(self.dataOut, 'data_spc') |
|
179 | 179 | z = data/self.dataOut.normFactor |
|
180 | 180 | avg = numpy.average(z, axis=1) |
|
181 | 181 | avgdB = 10*numpy.log10(avg) |
|
182 | 182 | xlen, ylen = z[0].shape |
|
183 | 183 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
184 | 184 | AVG = [0 for i in self.dataOut.channelList] |
|
185 | 185 | for i in self.dataOut.channelList: |
|
186 | 186 | AVG[i] = avgdB[i][::dy].tolist() |
|
187 | 187 | payload = { |
|
188 | 188 | 'timestamp': self.dataOut.utctime, |
|
189 | 189 | 'data': roundFloats(AVG), |
|
190 | 190 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
191 | 191 | 'interval': self.dataOut.getTimeInterval(), |
|
192 | 192 | 'type': self.plottype, |
|
193 | 193 | 'yData': yData |
|
194 | 194 | } |
|
195 | 195 | elif self.plottype == 'noise': |
|
196 | 196 | noise = self.dataOut.getNoise()/self.dataOut.normFactor |
|
197 | 197 | noisedB = 10*numpy.log10(noise) |
|
198 | 198 | payload = { |
|
199 | 199 | 'timestamp': self.dataOut.utctime, |
|
200 | 200 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), |
|
201 | 201 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
202 | 202 | 'interval': self.dataOut.getTimeInterval(), |
|
203 | 203 | 'type': self.plottype, |
|
204 | 204 | 'yData': yData |
|
205 | 205 | } |
|
206 | 206 | elif self.plottype == 'snr': |
|
207 | 207 | data = getattr(self.dataOut, 'data_SNR') |
|
208 | 208 | avgdB = 10*numpy.log10(data) |
|
209 | 209 | |
|
210 | 210 | ylen = data[0].size |
|
211 | 211 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
212 | 212 | AVG = [0 for i in self.dataOut.channelList] |
|
213 | 213 | for i in self.dataOut.channelList: |
|
214 | 214 | AVG[i] = avgdB[i][::dy].tolist() |
|
215 | 215 | payload = { |
|
216 | 216 | 'timestamp': self.dataOut.utctime, |
|
217 | 217 | 'data': roundFloats(AVG), |
|
218 | 218 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
219 | 219 | 'type': self.plottype, |
|
220 | 220 | 'yData': yData |
|
221 | 221 | } |
|
222 | 222 | else: |
|
223 | 223 | print "Tipo de grafico invalido" |
|
224 | 224 | payload = { |
|
225 | 225 | 'data': 'None', |
|
226 | 226 | 'timestamp': 'None', |
|
227 | 227 | 'type': None |
|
228 | 228 | } |
|
229 | 229 | # print 'Publishing data to {}'.format(self.host) |
|
230 | 230 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
231 | 231 | |
|
232 | 232 | if self.zeromq is 1: |
|
233 | 233 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) |
|
234 | 234 | self.zmq_socket.send_pyobj(self.dataOut) |
|
235 | 235 | |
|
236 | 236 | def run(self, dataOut, **kwargs): |
|
237 | 237 | self.dataOut = dataOut |
|
238 | 238 | if not self.isConfig: |
|
239 | 239 | self.setup(**kwargs) |
|
240 | 240 | self.isConfig = True |
|
241 | 241 | |
|
242 | 242 | self.publish_data() |
|
243 | 243 | time.sleep(self.delay) |
|
244 | 244 | |
|
245 | 245 | def close(self): |
|
246 | 246 | if self.zeromq is 1: |
|
247 | 247 | self.dataOut.finished = True |
|
248 |
|
|
|
248 | self.zmq_socket.send_pyobj(self.dataOut) | |
|
249 | 249 | |
|
250 | 250 | if self.client: |
|
251 | 251 | self.client.loop_stop() |
|
252 | 252 | self.client.disconnect() |
|
253 | 253 | |
|
254 | 254 | |
|
255 | 255 | class ReceiverData(ProcessingUnit, Process): |
|
256 | 256 | |
|
257 | 257 | throttle_value = 5 |
|
258 | 258 | |
|
259 | 259 | def __init__(self, **kwargs): |
|
260 | 260 | |
|
261 | 261 | ProcessingUnit.__init__(self, **kwargs) |
|
262 | 262 | Process.__init__(self) |
|
263 | 263 | self.mp = False |
|
264 | 264 | self.isConfig = False |
|
265 | 265 | self.isWebConfig = False |
|
266 | 266 | self.plottypes =[] |
|
267 | 267 | self.connections = 0 |
|
268 | 268 | server = kwargs.get('server', 'zmq.pipe') |
|
269 | 269 | plot_server = kwargs.get('plot_server', 'zmq.web') |
|
270 | 270 | if 'tcp://' in server: |
|
271 | 271 | address = server |
|
272 | 272 | else: |
|
273 | 273 | address = 'ipc:///tmp/%s' % server |
|
274 | 274 | |
|
275 | 275 | if 'tcp://' in plot_server: |
|
276 | 276 | plot_address = plot_server |
|
277 | 277 | else: |
|
278 | 278 | plot_address = 'ipc:///tmp/%s' % plot_server |
|
279 | 279 | |
|
280 | 280 | self.address = address |
|
281 | 281 | self.plot_address = plot_address |
|
282 | 282 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] |
|
283 | 283 | self.realtime = kwargs.get('realtime', False) |
|
284 | 284 | self.throttle_value = kwargs.get('throttle', 5) |
|
285 | 285 | self.sendData = self.initThrottle(self.throttle_value) |
|
286 | 286 | self.setup() |
|
287 | 287 | |
|
288 | 288 | def setup(self): |
|
289 | 289 | |
|
290 | 290 | self.data = {} |
|
291 | 291 | self.data['times'] = [] |
|
292 | 292 | for plottype in self.plottypes: |
|
293 | 293 | self.data[plottype] = {} |
|
294 | 294 | self.data['noise'] = {} |
|
295 | 295 | self.data['throttle'] = self.throttle_value |
|
296 | 296 | self.data['ENDED'] = False |
|
297 | 297 | self.isConfig = True |
|
298 | 298 | self.data_web = {} |
|
299 | 299 | |
|
300 | 300 | def event_monitor(self, monitor): |
|
301 | 301 | |
|
302 | 302 | events = {} |
|
303 | 303 | |
|
304 | 304 | for name in dir(zmq): |
|
305 | 305 | if name.startswith('EVENT_'): |
|
306 | 306 | value = getattr(zmq, name) |
|
307 | 307 | events[value] = name |
|
308 | 308 | |
|
309 | 309 | while monitor.poll(): |
|
310 | 310 | evt = recv_monitor_message(monitor) |
|
311 | 311 | if evt['event'] == 32: |
|
312 | 312 | self.connections += 1 |
|
313 | 313 | if evt['event'] == 512: |
|
314 | 314 | pass |
|
315 | 315 | if self.connections == 0 and self.started is True: |
|
316 | 316 | self.ended = True |
|
317 | 317 | |
|
318 | 318 | evt.update({'description': events[evt['event']]}) |
|
319 | 319 | |
|
320 | 320 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
321 | 321 | break |
|
322 | 322 | monitor.close() |
|
323 | 323 | print("event monitor thread done!") |
|
324 | 324 | |
|
325 | 325 | def initThrottle(self, throttle_value): |
|
326 | 326 | |
|
327 | 327 | @throttle(seconds=throttle_value) |
|
328 | 328 | def sendDataThrottled(fn_sender, data): |
|
329 | 329 | fn_sender(data) |
|
330 | 330 | |
|
331 | 331 | return sendDataThrottled |
|
332 | 332 | |
|
333 | 333 | def send(self, data): |
|
334 | 334 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) |
|
335 | 335 | self.sender.send_pyobj(data) |
|
336 | 336 | |
|
337 | 337 | def update(self): |
|
338 | 338 | |
|
339 | 339 | t = self.dataOut.utctime |
|
340 | 340 | |
|
341 | 341 | if t in self.data['times']: |
|
342 | 342 | return |
|
343 | 343 | |
|
344 | 344 | self.data['times'].append(t) |
|
345 | 345 | self.data['dataOut'] = self.dataOut |
|
346 | 346 | |
|
347 | 347 | for plottype in self.plottypes: |
|
348 | 348 | if plottype == 'spc': |
|
349 | 349 | z = self.dataOut.data_spc/self.dataOut.normFactor |
|
350 | 350 | self.data[plottype] = 10*numpy.log10(z) |
|
351 | 351 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) |
|
352 | 352 | if plottype == 'cspc': |
|
353 | 353 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) |
|
354 | 354 | self.data['cspc_coh'] = numpy.abs(jcoherence) |
|
355 | 355 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi |
|
356 | 356 | if plottype == 'rti': |
|
357 | 357 | self.data[plottype][t] = self.dataOut.getPower() |
|
358 | 358 | if plottype == 'snr': |
|
359 | 359 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) |
|
360 | 360 | if plottype == 'dop': |
|
361 | 361 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) |
|
362 | 362 | if plottype == 'mean': |
|
363 | 363 | self.data[plottype][t] = self.dataOut.data_MEAN |
|
364 | 364 | if plottype == 'std': |
|
365 | 365 | self.data[plottype][t] = self.dataOut.data_STD |
|
366 | 366 | if plottype == 'coh': |
|
367 | 367 | self.data[plottype][t] = self.dataOut.getCoherence() |
|
368 | 368 | if plottype == 'phase': |
|
369 | 369 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) |
|
370 | 370 | if plottype == 'wind': |
|
371 | 371 | self.data[plottype][t] = self.dataOut.data_output |
|
372 | 372 | if self.realtime: |
|
373 | 373 | self.data_web['timestamp'] = t |
|
374 | 374 | if plottype == 'spc': |
|
375 | 375 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) |
|
376 | 376 | elif plottype == 'cspc': |
|
377 | 377 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) |
|
378 | 378 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) |
|
379 | 379 | elif plottype == 'noise': |
|
380 | 380 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) |
|
381 | 381 | else: |
|
382 | 382 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) |
|
383 | 383 | self.data_web['interval'] = self.dataOut.getTimeInterval() |
|
384 | 384 | self.data_web['type'] = plottype |
|
385 | 385 | |
|
386 | 386 | def run(self): |
|
387 | 387 | |
|
388 | 388 | print '[Starting] {} from {}'.format(self.name, self.address) |
|
389 | 389 | |
|
390 | 390 | self.context = zmq.Context() |
|
391 | 391 | self.receiver = self.context.socket(zmq.PULL) |
|
392 | 392 | self.receiver.bind(self.address) |
|
393 | 393 | monitor = self.receiver.get_monitor_socket() |
|
394 | 394 | self.sender = self.context.socket(zmq.PUB) |
|
395 | 395 | if self.realtime: |
|
396 | 396 | self.sender_web = self.context.socket(zmq.PUB) |
|
397 | 397 | self.sender_web.connect(self.plot_address) |
|
398 | 398 | time.sleep(1) |
|
399 | 399 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
400 | 400 | |
|
401 | 401 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
402 | 402 | t.start() |
|
403 | 403 | |
|
404 | 404 | while True: |
|
405 | 405 | self.dataOut = self.receiver.recv_pyobj() |
|
406 | 406 | # print '[Receiving] {} - {}'.format(self.dataOut.type, |
|
407 | 407 | # self.dataOut.datatime.ctime()) |
|
408 | 408 | |
|
409 | 409 | self.update() |
|
410 | 410 | |
|
411 | 411 | if self.dataOut.finished is True: |
|
412 | 412 | self.send(self.data) |
|
413 | 413 | self.connections -= 1 |
|
414 | 414 | if self.connections == 0 and self.started: |
|
415 | 415 | self.ended = True |
|
416 | 416 | self.data['ENDED'] = True |
|
417 | 417 | self.send(self.data) |
|
418 | 418 | self.setup() |
|
419 | 419 | else: |
|
420 | 420 | if self.realtime: |
|
421 | 421 | self.send(self.data) |
|
422 | 422 | self.sender_web.send_string(json.dumps(self.data_web)) |
|
423 | 423 | else: |
|
424 | 424 | self.sendData(self.send, self.data) |
|
425 | 425 | self.started = True |
|
426 | 426 | |
|
427 | 427 | return |
|
428 | 428 | |
|
429 | 429 | def sendToWeb(self): |
|
430 | 430 | |
|
431 | 431 | if not self.isWebConfig: |
|
432 | 432 | context = zmq.Context() |
|
433 | 433 | sender_web_config = context.socket(zmq.PUB) |
|
434 | 434 | if 'tcp://' in self.plot_address: |
|
435 | 435 | dum, address, port = self.plot_address.split(':') |
|
436 | 436 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) |
|
437 | 437 | else: |
|
438 | 438 | conf_address = self.plot_address + '.config' |
|
439 | 439 | sender_web_config.bind(conf_address) |
|
440 | 440 | time.sleep(1) |
|
441 | 441 | for kwargs in self.operationKwargs.values(): |
|
442 | 442 | if 'plot' in kwargs: |
|
443 | 443 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) |
|
444 | 444 | sender_web_config.send_string(json.dumps(kwargs)) |
|
445 | 445 | self.isWebConfig = True |
@@ -1,87 +1,87 | |||
|
1 | 1 | import argparse |
|
2 | 2 | |
|
3 | 3 | from schainpy.controller import Project, multiSchain |
|
4 | 4 | |
|
5 | 5 | desc = "HF_EXAMPLE" |
|
6 | 6 | |
|
7 | 7 | def fiber(cursor, skip, q, dt): |
|
8 | 8 | |
|
9 | 9 | controllerObj = Project() |
|
10 | 10 | |
|
11 | 11 | controllerObj.setup(id='191', name='test01', description=desc) |
|
12 | 12 | |
|
13 | 13 | readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader', |
|
14 | 14 | path='/home/nanosat/data/hysell_data20/pdata', |
|
15 | 15 | startDate=dt, |
|
16 | 16 | endDate=dt, |
|
17 | 17 | startTime="00:00:00", |
|
18 | 18 | endTime="23:59:59", |
|
19 | 19 | online=0, |
|
20 | 20 | #set=1426485881, |
|
21 | 21 | delay=10, |
|
22 | 22 | walk=1, |
|
23 | 23 | queue=q, |
|
24 | 24 | cursor=cursor, |
|
25 | 25 | skip=skip, |
|
26 | 26 | #timezone=-5*3600 |
|
27 | 27 | ) |
|
28 | 28 | |
|
29 | 29 | # #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') |
|
30 | 30 | # |
|
31 | 31 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
32 | 32 | # opObj11 = procUnitConfObj2.addParameter(name='pairsList', value='(0,1)', format='pairslist') |
|
33 | 33 | # |
|
34 |
|
|
|
35 |
|
|
|
34 | procUnitConfObj3 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=readUnitConfObj.getId()) | |
|
35 | opObj11 = procUnitConfObj3.addOperation(name='SpectralMoments', optype='other') | |
|
36 | 36 | |
|
37 | 37 | # |
|
38 | 38 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
39 | 39 | # opObj11.addParameter(name='id', value='1000', format='int') |
|
40 | 40 | # opObj11.addParameter(name='wintitle', value='HF_Jicamarca_Spc', format='str') |
|
41 | 41 | # opObj11.addParameter(name='channelList', value='0', format='intlist') |
|
42 | 42 | # opObj11.addParameter(name='zmin', value='-120', format='float') |
|
43 | 43 | # opObj11.addParameter(name='zmax', value='-70', format='float') |
|
44 | 44 | # opObj11.addParameter(name='save', value='1', format='int') |
|
45 | 45 | # opObj11.addParameter(name='figpath', value=figpath, format='str') |
|
46 | 46 | |
|
47 | 47 | # opObj11 = procUnitConfObj2.addOperation(name='RTIPlot', optype='other') |
|
48 | 48 | # opObj11.addParameter(name='id', value='2000', format='int') |
|
49 | 49 | # opObj11.addParameter(name='wintitzmaxle', value='HF_Jicamarca', format='str') |
|
50 | 50 | # opObj11.addParameter(name='showprofile', value='0', format='int') |
|
51 | 51 | # # opObj11.addParameter(name='channelList', value='0', format='intlist') |
|
52 | 52 | # # opObj11.addParameter(name='xmin', value='0', format='float') |
|
53 | 53 | # opObj11.addParameter(name='xmin', value='0', format='float') |
|
54 | 54 | # opObj11.addParameter(name='xmax', value='24', format='float') |
|
55 | 55 | |
|
56 | 56 | # opObj11.addParameter(name='zmin', value='-110', format='float') |
|
57 | 57 | # opObj11.addParameter(name='zmax', value='-70', format='float') |
|
58 | 58 | # opObj11.addParameter(name='save', value='0', format='int') |
|
59 | 59 | # # opObj11.addParameter(name='figpath', value='/tmp/', format='str') |
|
60 | 60 | # |
|
61 |
opObj12 = procUnitConfObj |
|
|
61 | opObj12 = procUnitConfObj3.addOperation(name='PublishData', optype='other') | |
|
62 | 62 | opObj12.addParameter(name='zeromq', value=1, format='int') |
|
63 | 63 | |
|
64 | 64 | |
|
65 | 65 | # opObj13 = procUnitConfObj3.addOperation(name='PublishData', optype='other') |
|
66 | 66 | # opObj13.addParameter(name='zeromq', value=1, format='int') |
|
67 | 67 | # opObj13.addParameter(name='server', value="juanca", format='str') |
|
68 | 68 | |
|
69 | 69 | opObj12.addParameter(name='delay', value=1, format='int') |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | # print "Escribiendo el archivo XML" |
|
73 | 73 | # controllerObj.writeXml(filename) |
|
74 | 74 | # print "Leyendo el archivo XML" |
|
75 | 75 | # controllerObj.readXml(filename) |
|
76 | 76 | |
|
77 | 77 | |
|
78 | 78 | # timeit.timeit('controllerObj.run()', number=2) |
|
79 | 79 | |
|
80 | 80 | controllerObj.start() |
|
81 | 81 | |
|
82 | 82 | |
|
83 | 83 | if __name__ == '__main__': |
|
84 | 84 | parser = argparse.ArgumentParser(description='Set number of parallel processes') |
|
85 | 85 | parser.add_argument('--nProcess', default=1, type=int) |
|
86 | 86 | args = parser.parse_args() |
|
87 | 87 | multiSchain(fiber, nProcess=args.nProcess, startDate='2015/09/26', endDate='2015/09/26') |
@@ -1,50 +1,58 | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | ''' |
|
3 | 3 | Created on Jul 7, 2014 |
|
4 | 4 | |
|
5 | 5 | @author: roj-idl71 |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | |
|
9 | 9 | from schainpy.controller import Project |
|
10 | 10 | |
|
11 | 11 | if __name__ == '__main__': |
|
12 | 12 | desc = "Segundo Test" |
|
13 | 13 | |
|
14 | 14 | controllerObj = Project() |
|
15 | 15 | controllerObj.setup(id='191', name='test01', description=desc) |
|
16 | 16 | |
|
17 | 17 | proc1 = controllerObj.addProcUnit(name='ReceiverData') |
|
18 | 18 | proc1.addParameter(name='realtime', value='0', format='bool') |
|
19 | proc1.addParameter(name='plottypes', value='rti', format='str') | |
|
20 |
|
|
|
19 | proc1.addParameter(name='plottypes', value='rti,coh,phase,snr,dop', format='str') | |
|
20 | proc1.addParameter(name='throttle', value='10', format='int') | |
|
21 | 21 | proc1.addParameter(name='plot_server', value='tcp://10.10.10.82:7000', format='str') |
|
22 | 22 | ## TODO Agregar direccion de server de publicacion a graficos como variable |
|
23 | 23 | |
|
24 | 24 | op1 = proc1.addOperation(name='PlotRTIData', optype='other') |
|
25 | 25 | op1.addParameter(name='wintitle', value='Julia 150Km', format='str') |
|
26 | 26 | op1.addParameter(name='save', value='/home/nanosat/Pictures', format='str') |
|
27 | op1.addParameter(name='show', value='0', format='bool') | |
|
28 | op1.addParameter(name='colormap', value='jet', format='str') | |
|
27 | 29 | # |
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
30 | op2 = proc1.addOperation(name='PlotCOHData', optype='other') | |
|
31 | op2.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
|
32 | op2.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
33 | op2.addParameter(name='colormap', value='jet', format='str') | |
|
34 | op2.addParameter(name='show', value='0', format='bool') | |
|
31 | 35 | # # |
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
36 | op6 = proc1.addOperation(name='PlotPHASEData', optype='other') | |
|
37 | op6.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
|
38 | op6.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
39 | op6.addParameter(name='show', value='1', format='bool') | |
|
35 | 40 | # |
|
36 | 41 | # proc2 = controllerObj.addProcUnit(name='ReceiverData') |
|
37 | 42 | # proc2.addParameter(name='server', value='juanca', format='str') |
|
38 | 43 | # proc2.addParameter(name='plottypes', value='snr,dop', format='str') |
|
39 | 44 | # |
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
45 | op3 = proc1.addOperation(name='PlotSNRData', optype='other') | |
|
46 | op3.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
|
47 | op3.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
48 | op3.addParameter(name='show', value='0', format='bool') | |
|
43 | 49 | # |
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
50 | op4 = proc1.addOperation(name='PlotDOPData', optype='other') | |
|
51 | op4.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
|
52 | op4.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
|
53 | op4.addParameter(name='show', value='0', format='bool') | |
|
54 | op4.addParameter(name='colormap', value='jet', format='str') | |
|
47 | 55 | |
|
48 | 56 | |
|
49 | 57 | |
|
50 | 58 | controllerObj.start() |
@@ -1,1 +1,1 | |||
|
1 | <Project description="Segundo Test" id="191" name="test01"><ProcUnit datatype="ReceiverData" id="1911" inputId="0" name="ReceiverData"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="bool" id="191111" name="realtime" value="1" /><Parameter format="str" id="191112" name="plottypes" value="rti" /><Parameter format="str" id="191113" name="plot_server" value="tcp://10.10.10.82:7000" /></Operation><Operation id="19112" name="PlotRTIData" priority="2" type="other"><Parameter format="str" id="191121" name="wintitle" value="Julia 150Km" /><Parameter format="str" id="191122" name="save" value="/home/nanosat/Pictures" /></Operation></ProcUnit></Project> No newline at end of file | |
|
1 | <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/hysell_data20/pdata" /><Parameter format="date" id="191113" name="startDate" value="2015/09/26" /><Parameter format="date" id="191114" name="endDate" value="2015/09/26" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="cursor" value="2" /><Parameter format="int" id="191119" name="skip" value="720" /><Parameter format="int" id="191120" name="delay" value="10" /><Parameter format="int" id="191121" name="walk" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="ParametersProc" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="int" id="191332" name="delay" value="1" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now