##// END OF EJS Templates
Version 2.2.5 Fixed several bugs, add jro colormap for spectra/rti, add ParamWriter, TODO: Fix decimation currently disabled
Juan C. Valdez -
r860:5c2852893069
parent child
Show More
@@ -1,36 +1,19
1 Prerequisites:
2
3 Core:
4 -numpy 1.8.0
5 -scipy
6 -math
7 -matplotlib
8 -h5py
9 -ftplib
10 -paramiko (optional for SendTFilesToServer)
11 -stuffr (optional for jroIO_hf)
12 -pyfits (Fits data)
13
14 GUI:
15 -PyQt4
16 -wxPython
17
18 1 Signal Chain Installation:
19 2
20 1. Install numpy, matplotlib, TKAgg
3 1. Install system dependencies: python-pip python-dev gfortran libpng-dev freetype* libblas-dev liblapack-dev libatlas-base-dev python-qt4
21 4 2. Install digital_rf_hdf5 module (developed by Haystack Observatory)
22 5 if you want to use USRP data
23 6 3. untar schainpy-x.x.x.tar.gz
24 7 4. cd schainpy-x.x.x
25 8 5. execute:
26 [hostname]$ sudo pyhon setup.py install
9 [hostname]$ sudo pip install ./
27 10 6. testing gui:
28 11 [hostname]$ schainGUI (enter)
29 12
30 13 If you want to use serialization and zerorpc you will need to install the next packages:
31 14
32 15 1. zerorpc
33 16 [hostname]$ sudo port install zerorpc
34 17
35 18 2. cPickle, msgpack and msgpack_numpy
36 19 [hostname]$ sudo port install cPickle msgpack mspack_numpy No newline at end of file
@@ -1,1294 +1,1294
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 schainpy
11 11 import schainpy.admin
12 12
13 13 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
14 14 from xml.dom import minidom
15 15
16 16 from schainpy.model import *
17 17 from time import sleep
18 18
19 19 def prettify(elem):
20 20 """Return a pretty-printed XML string for the Element.
21 21 """
22 22 rough_string = tostring(elem, 'utf-8')
23 23 reparsed = minidom.parseString(rough_string)
24 24 return reparsed.toprettyxml(indent=" ")
25 25
26 26 class ParameterConf():
27 27
28 28 id = None
29 29 name = None
30 30 value = None
31 31 format = None
32 32
33 33 __formated_value = None
34 34
35 35 ELEMENTNAME = 'Parameter'
36 36
37 37 def __init__(self):
38 38
39 39 self.format = 'str'
40 40
41 41 def getElementName(self):
42 42
43 43 return self.ELEMENTNAME
44 44
45 45 def getValue(self):
46 46
47 47 value = self.value
48 48 format = self.format
49 49
50 50 if self.__formated_value != None:
51 51
52 52 return self.__formated_value
53 53
54 54 if format == 'str':
55 55 self.__formated_value = str(value)
56 56 return self.__formated_value
57 57
58 58 if value == '':
59 59 raise ValueError, "%s: This parameter value is empty" %self.name
60 60
61 61 if format == 'list':
62 62 strList = value.split(',')
63 63
64 64 self.__formated_value = strList
65 65
66 66 return self.__formated_value
67 67
68 68 if format == 'intlist':
69 69 """
70 70 Example:
71 71 value = (0,1,2)
72 72 """
73 73
74 74 new_value = ast.literal_eval(value)
75 75
76 76 if type(new_value) not in (tuple, list):
77 77 new_value = [int(new_value)]
78 78
79 79 self.__formated_value = new_value
80 80
81 81 return self.__formated_value
82 82
83 83 if format == 'floatlist':
84 84 """
85 85 Example:
86 86 value = (0.5, 1.4, 2.7)
87 87 """
88 88
89 89 new_value = ast.literal_eval(value)
90 90
91 91 if type(new_value) not in (tuple, list):
92 92 new_value = [float(new_value)]
93 93
94 94 self.__formated_value = new_value
95 95
96 96 return self.__formated_value
97 97
98 98 if format == 'date':
99 99 strList = value.split('/')
100 100 intList = [int(x) for x in strList]
101 101 date = datetime.date(intList[0], intList[1], intList[2])
102 102
103 103 self.__formated_value = date
104 104
105 105 return self.__formated_value
106 106
107 107 if format == 'time':
108 108 strList = value.split(':')
109 109 intList = [int(x) for x in strList]
110 110 time = datetime.time(intList[0], intList[1], intList[2])
111 111
112 112 self.__formated_value = time
113 113
114 114 return self.__formated_value
115 115
116 116 if format == 'pairslist':
117 117 """
118 118 Example:
119 119 value = (0,1),(1,2)
120 120 """
121 121
122 122 new_value = ast.literal_eval(value)
123 123
124 124 if type(new_value) not in (tuple, list):
125 125 raise ValueError, "%s has to be a tuple or list of pairs" %value
126 126
127 127 if type(new_value[0]) not in (tuple, list):
128 128 if len(new_value) != 2:
129 129 raise ValueError, "%s has to be a tuple or list of pairs" %value
130 130 new_value = [new_value]
131 131
132 132 for thisPair in new_value:
133 133 if len(thisPair) != 2:
134 134 raise ValueError, "%s has to be a tuple or list of pairs" %value
135 135
136 136 self.__formated_value = new_value
137 137
138 138 return self.__formated_value
139 139
140 140 if format == 'multilist':
141 141 """
142 142 Example:
143 143 value = (0,1,2),(3,4,5)
144 144 """
145 145 multiList = ast.literal_eval(value)
146 146
147 147 if type(multiList[0]) == int:
148 148 multiList = ast.literal_eval("(" + value + ")")
149 149
150 150 self.__formated_value = multiList
151 151
152 152 return self.__formated_value
153 153
154 154 if format == 'bool':
155 155 value = int(value)
156 156
157 157 if format == 'int':
158 158 value = float(value)
159 159
160 160 format_func = eval(format)
161 161
162 162 self.__formated_value = format_func(value)
163 163
164 164 return self.__formated_value
165 165
166 166 def updateId(self, new_id):
167 167
168 168 self.id = str(new_id)
169 169
170 170 def setup(self, id, name, value, format='str'):
171 171
172 172 self.id = str(id)
173 173 self.name = name
174 174 self.value = str(value)
175 175 self.format = str.lower(format)
176 176
177 177 self.getValue()
178 178
179 179 return 1
180 180
181 181 def update(self, name, value, format='str'):
182 182
183 183 self.name = name
184 184 self.value = str(value)
185 185 self.format = format
186 186
187 187 def makeXml(self, opElement):
188 188
189 189 parmElement = SubElement(opElement, self.ELEMENTNAME)
190 190 parmElement.set('id', str(self.id))
191 191 parmElement.set('name', self.name)
192 192 parmElement.set('value', self.value)
193 193 parmElement.set('format', self.format)
194 194
195 195 def readXml(self, parmElement):
196 196
197 197 self.id = parmElement.get('id')
198 198 self.name = parmElement.get('name')
199 199 self.value = parmElement.get('value')
200 200 self.format = str.lower(parmElement.get('format'))
201 201
202 202 #Compatible with old signal chain version
203 203 if self.format == 'int' and self.name == 'idfigure':
204 204 self.name = 'id'
205 205
206 206 def printattr(self):
207 207
208 208 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
209 209
210 210 class OperationConf():
211 211
212 212 id = None
213 213 name = None
214 214 priority = None
215 215 type = None
216 216
217 217 parmConfObjList = []
218 218
219 219 ELEMENTNAME = 'Operation'
220 220
221 221 def __init__(self):
222 222
223 223 self.id = '0'
224 224 self.name = None
225 225 self.priority = None
226 226 self.type = 'self'
227 227
228 228
229 229 def __getNewId(self):
230 230
231 231 return int(self.id)*10 + len(self.parmConfObjList) + 1
232 232
233 233 def updateId(self, new_id):
234 234
235 235 self.id = str(new_id)
236 236
237 237 n = 1
238 238 for parmObj in self.parmConfObjList:
239 239
240 240 idParm = str(int(new_id)*10 + n)
241 241 parmObj.updateId(idParm)
242 242
243 243 n += 1
244 244
245 245 def getElementName(self):
246 246
247 247 return self.ELEMENTNAME
248 248
249 249 def getParameterObjList(self):
250 250
251 251 return self.parmConfObjList
252 252
253 253 def getParameterObj(self, parameterName):
254 254
255 255 for parmConfObj in self.parmConfObjList:
256 256
257 257 if parmConfObj.name != parameterName:
258 258 continue
259 259
260 260 return parmConfObj
261 261
262 262 return None
263 263
264 264 def getParameterObjfromValue(self, parameterValue):
265 265
266 266 for parmConfObj in self.parmConfObjList:
267 267
268 268 if parmConfObj.getValue() != parameterValue:
269 269 continue
270 270
271 271 return parmConfObj.getValue()
272 272
273 273 return None
274 274
275 275 def getParameterValue(self, parameterName):
276 276
277 277 parameterObj = self.getParameterObj(parameterName)
278 278
279 279 # if not parameterObj:
280 280 # return None
281 281
282 282 value = parameterObj.getValue()
283 283
284 284 return value
285 285
286 286 def setup(self, id, name, priority, type):
287 287
288 288 self.id = str(id)
289 289 self.name = name
290 290 self.type = type
291 291 self.priority = priority
292 292
293 293 self.parmConfObjList = []
294 294
295 295 def removeParameters(self):
296 296
297 297 for obj in self.parmConfObjList:
298 298 del obj
299 299
300 300 self.parmConfObjList = []
301 301
302 302 def addParameter(self, name, value, format='str'):
303 303
304 304 id = self.__getNewId()
305 305
306 306 parmConfObj = ParameterConf()
307 307 if not parmConfObj.setup(id, name, value, format):
308 308 return None
309 309
310 310 self.parmConfObjList.append(parmConfObj)
311 311
312 312 return parmConfObj
313 313
314 314 def changeParameter(self, name, value, format='str'):
315 315
316 316 parmConfObj = self.getParameterObj(name)
317 317 parmConfObj.update(name, value, format)
318 318
319 319 return parmConfObj
320 320
321 321 def makeXml(self, procUnitElement):
322 322
323 323 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
324 324 opElement.set('id', str(self.id))
325 325 opElement.set('name', self.name)
326 326 opElement.set('type', self.type)
327 327 opElement.set('priority', str(self.priority))
328 328
329 329 for parmConfObj in self.parmConfObjList:
330 330 parmConfObj.makeXml(opElement)
331 331
332 332 def readXml(self, opElement):
333 333
334 334 self.id = opElement.get('id')
335 335 self.name = opElement.get('name')
336 336 self.type = opElement.get('type')
337 337 self.priority = opElement.get('priority')
338 338
339 339 #Compatible with old signal chain version
340 340 #Use of 'run' method instead 'init'
341 341 if self.type == 'self' and self.name == 'init':
342 342 self.name = 'run'
343 343
344 344 self.parmConfObjList = []
345 345
346 parmElementList = opElement.getiterator(ParameterConf().getElementName())
346 parmElementList = opElement.iter(ParameterConf().getElementName())
347 347
348 348 for parmElement in parmElementList:
349 349 parmConfObj = ParameterConf()
350 350 parmConfObj.readXml(parmElement)
351 351
352 352 #Compatible with old signal chain version
353 353 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
354 354 if self.type != 'self' and self.name == 'Plot':
355 355 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
356 356 self.name = parmConfObj.value
357 357 continue
358 358
359 359 self.parmConfObjList.append(parmConfObj)
360 360
361 361 def printattr(self):
362 362
363 363 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
364 364 self.id,
365 365 self.name,
366 366 self.type,
367 367 self.priority)
368 368
369 369 for parmConfObj in self.parmConfObjList:
370 370 parmConfObj.printattr()
371 371
372 372 def createObject(self, plotter_queue=None):
373 373
374 374 if self.type == 'self':
375 375 raise ValueError, "This operation type cannot be created"
376 376
377 377 if self.type == 'plotter':
378 378 #Plotter(plotter_name)
379 379 if not plotter_queue:
380 380 raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)"
381 381
382 382 opObj = Plotter(self.name, plotter_queue)
383 383
384 384 if self.type == 'external' or self.type == 'other':
385 385 className = eval(self.name)
386 386 opObj = className()
387 387
388 388 return opObj
389 389
390 390 class ProcUnitConf():
391 391
392 392 id = None
393 393 name = None
394 394 datatype = None
395 395 inputId = None
396 396 parentId = None
397 397
398 398 opConfObjList = []
399 399
400 400 procUnitObj = None
401 401 opObjList = []
402 402
403 403 ELEMENTNAME = 'ProcUnit'
404 404
405 405 def __init__(self):
406 406
407 407 self.id = None
408 408 self.datatype = None
409 409 self.name = None
410 410 self.inputId = None
411 411
412 412 self.opConfObjList = []
413 413
414 414 self.procUnitObj = None
415 415 self.opObjDict = {}
416 416
417 417 def __getPriority(self):
418 418
419 419 return len(self.opConfObjList)+1
420 420
421 421 def __getNewId(self):
422 422
423 423 return int(self.id)*10 + len(self.opConfObjList) + 1
424 424
425 425 def getElementName(self):
426 426
427 427 return self.ELEMENTNAME
428 428
429 429 def getId(self):
430 430
431 431 return self.id
432 432
433 433 def updateId(self, new_id, parentId=parentId):
434 434
435 435
436 436 new_id = int(parentId)*10 + (int(self.id) % 10)
437 437 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
438 438
439 439 #If this proc unit has not inputs
440 440 if self.inputId == '0':
441 441 new_inputId = 0
442 442
443 443 n = 1
444 444 for opConfObj in self.opConfObjList:
445 445
446 446 idOp = str(int(new_id)*10 + n)
447 447 opConfObj.updateId(idOp)
448 448
449 449 n += 1
450 450
451 451 self.parentId = str(parentId)
452 452 self.id = str(new_id)
453 453 self.inputId = str(new_inputId)
454 454
455 455
456 456 def getInputId(self):
457 457
458 458 return self.inputId
459 459
460 460 def getOperationObjList(self):
461 461
462 462 return self.opConfObjList
463 463
464 464 def getOperationObj(self, name=None):
465 465
466 466 for opConfObj in self.opConfObjList:
467 467
468 468 if opConfObj.name != name:
469 469 continue
470 470
471 471 return opConfObj
472 472
473 473 return None
474 474
475 475 def getOpObjfromParamValue(self, value=None):
476 476
477 477 for opConfObj in self.opConfObjList:
478 478 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
479 479 continue
480 480 return opConfObj
481 481 return None
482 482
483 483 def getProcUnitObj(self):
484 484
485 485 return self.procUnitObj
486 486
487 487 def setup(self, id, name, datatype, inputId, parentId=None):
488 488
489 489 #Compatible with old signal chain version
490 490 if datatype==None and name==None:
491 491 raise ValueError, "datatype or name should be defined"
492 492
493 493 if name==None:
494 494 if 'Proc' in datatype:
495 495 name = datatype
496 496 else:
497 497 name = '%sProc' %(datatype)
498 498
499 499 if datatype==None:
500 500 datatype = name.replace('Proc','')
501 501
502 502 self.id = str(id)
503 503 self.name = name
504 504 self.datatype = datatype
505 505 self.inputId = inputId
506 506 self.parentId = parentId
507 507
508 508 self.opConfObjList = []
509 509
510 510 self.addOperation(name='run', optype='self')
511 511
512 512 def removeOperations(self):
513 513
514 514 for obj in self.opConfObjList:
515 515 del obj
516 516
517 517 self.opConfObjList = []
518 518 self.addOperation(name='run')
519 519
520 520 def addParameter(self, **kwargs):
521 521 '''
522 522 Add parameters to "run" operation
523 523 '''
524 524 opObj = self.opConfObjList[0]
525 525
526 526 opObj.addParameter(**kwargs)
527 527
528 528 return opObj
529 529
530 530 def addOperation(self, name, optype='self'):
531 531
532 532 id = self.__getNewId()
533 533 priority = self.__getPriority()
534 534
535 535 opConfObj = OperationConf()
536 536 opConfObj.setup(id, name=name, priority=priority, type=optype)
537 537
538 538 self.opConfObjList.append(opConfObj)
539 539
540 540 return opConfObj
541 541
542 542 def makeXml(self, projectElement):
543 543
544 544 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
545 545 procUnitElement.set('id', str(self.id))
546 546 procUnitElement.set('name', self.name)
547 547 procUnitElement.set('datatype', self.datatype)
548 548 procUnitElement.set('inputId', str(self.inputId))
549 549
550 550 for opConfObj in self.opConfObjList:
551 551 opConfObj.makeXml(procUnitElement)
552 552
553 553 def readXml(self, upElement):
554 554
555 555 self.id = upElement.get('id')
556 556 self.name = upElement.get('name')
557 557 self.datatype = upElement.get('datatype')
558 558 self.inputId = upElement.get('inputId')
559 559
560 560 if self.ELEMENTNAME == "ReadUnit":
561 561 self.datatype = self.datatype.replace("Reader", "")
562 562
563 563 if self.ELEMENTNAME == "ProcUnit":
564 564 self.datatype = self.datatype.replace("Proc", "")
565 565
566 566 if self.inputId == 'None':
567 567 self.inputId = '0'
568 568
569 569 self.opConfObjList = []
570 570
571 opElementList = upElement.getiterator(OperationConf().getElementName())
571 opElementList = upElement.iter(OperationConf().getElementName())
572 572
573 573 for opElement in opElementList:
574 574 opConfObj = OperationConf()
575 575 opConfObj.readXml(opElement)
576 576 self.opConfObjList.append(opConfObj)
577 577
578 578 def printattr(self):
579 579
580 580 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
581 581 self.id,
582 582 self.name,
583 583 self.datatype,
584 584 self.inputId)
585 585
586 586 for opConfObj in self.opConfObjList:
587 587 opConfObj.printattr()
588 588
589 589 def createObjects(self, plotter_queue=None):
590 590
591 591 className = eval(self.name)
592 592 procUnitObj = className()
593 593
594 594 for opConfObj in self.opConfObjList:
595 595
596 596 if opConfObj.type == 'self':
597 597 continue
598 598
599 599 opObj = opConfObj.createObject(plotter_queue)
600 600
601 601 self.opObjDict[opConfObj.id] = opObj
602 602 procUnitObj.addOperation(opObj, opConfObj.id)
603 603
604 604 self.procUnitObj = procUnitObj
605 605
606 606 return procUnitObj
607 607
608 608 def run(self):
609 609
610 610 is_ok = False
611 611
612 612 for opConfObj in self.opConfObjList:
613 613
614 614 kwargs = {}
615 615 for parmConfObj in opConfObj.getParameterObjList():
616 616 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
617 617 continue
618 618
619 619 kwargs[parmConfObj.name] = parmConfObj.getValue()
620 620
621 621 ini = time.time()
622 622
623 623 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
624 624 sts = self.procUnitObj.call(opType = opConfObj.type,
625 625 opName = opConfObj.name,
626 626 opId = opConfObj.id,
627 627 **kwargs)
628 628
629 629 # total_time = time.time() - ini
630 630 #
631 631 # if total_time > 0.002:
632 632 # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time)
633 633
634 634 is_ok = is_ok or sts
635 635
636 636 return is_ok
637 637
638 638 def close(self):
639 639
640 640 for opConfObj in self.opConfObjList:
641 641 if opConfObj.type == 'self':
642 642 continue
643 643
644 644 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
645 645 opObj.close()
646 646
647 647 self.procUnitObj.close()
648 648
649 649 return
650 650
651 651 class ReadUnitConf(ProcUnitConf):
652 652
653 653 path = None
654 654 startDate = None
655 655 endDate = None
656 656 startTime = None
657 657 endTime = None
658 658
659 659 ELEMENTNAME = 'ReadUnit'
660 660
661 661 def __init__(self):
662 662
663 663 self.id = None
664 664 self.datatype = None
665 665 self.name = None
666 666 self.inputId = None
667 667
668 668 self.parentId = None
669 669
670 670 self.opConfObjList = []
671 671 self.opObjList = []
672 672
673 673 def getElementName(self):
674 674
675 675 return self.ELEMENTNAME
676 676
677 677 def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs):
678 678
679 679 #Compatible with old signal chain version
680 680 if datatype==None and name==None:
681 681 raise ValueError, "datatype or name should be defined"
682 682
683 683 if name==None:
684 684 if 'Reader' in datatype:
685 685 name = datatype
686 686 else:
687 687 name = '%sReader' %(datatype)
688 688
689 689 if datatype==None:
690 690 datatype = name.replace('Reader','')
691 691
692 692 self.id = id
693 693 self.name = name
694 694 self.datatype = datatype
695 695
696 696 self.path = os.path.abspath(path)
697 697 self.startDate = startDate
698 698 self.endDate = endDate
699 699 self.startTime = startTime
700 700 self.endTime = endTime
701 701
702 702 self.inputId = '0'
703 703 self.parentId = parentId
704 704
705 705 self.addRunOperation(**kwargs)
706 706
707 707 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
708 708
709 709 #Compatible with old signal chain version
710 710 if datatype==None and name==None:
711 711 raise ValueError, "datatype or name should be defined"
712 712
713 713 if name==None:
714 714 if 'Reader' in datatype:
715 715 name = datatype
716 716 else:
717 717 name = '%sReader' %(datatype)
718 718
719 719 if datatype==None:
720 720 datatype = name.replace('Reader','')
721 721
722 722 self.datatype = datatype
723 723 self.name = name
724 724 self.path = path
725 725 self.startDate = startDate
726 726 self.endDate = endDate
727 727 self.startTime = startTime
728 728 self.endTime = endTime
729 729
730 730 self.inputId = '0'
731 731 self.parentId = parentId
732 732
733 733 self.updateRunOperation(**kwargs)
734 734
735 735 def removeOperations(self):
736 736
737 737 for obj in self.opConfObjList:
738 738 del obj
739 739
740 740 self.opConfObjList = []
741 741
742 742 def addRunOperation(self, **kwargs):
743 743
744 744 opObj = self.addOperation(name = 'run', optype = 'self')
745 745
746 746 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
747 747 opObj.addParameter(name='path' , value=self.path, format='str')
748 748 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
749 749 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
750 750 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
751 751 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
752 752
753 753 for key, value in kwargs.items():
754 754 opObj.addParameter(name=key, value=value, format=type(value).__name__)
755 755
756 756 return opObj
757 757
758 758 def updateRunOperation(self, **kwargs):
759 759
760 760 opObj = self.getOperationObj(name = 'run')
761 761 opObj.removeParameters()
762 762
763 763 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
764 764 opObj.addParameter(name='path' , value=self.path, format='str')
765 765 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
766 766 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
767 767 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
768 768 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
769 769
770 770 for key, value in kwargs.items():
771 771 opObj.addParameter(name=key, value=value, format=type(value).__name__)
772 772
773 773 return opObj
774 774
775 775 # def makeXml(self, projectElement):
776 776 #
777 777 # procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
778 778 # procUnitElement.set('id', str(self.id))
779 779 # procUnitElement.set('name', self.name)
780 780 # procUnitElement.set('datatype', self.datatype)
781 781 # procUnitElement.set('inputId', str(self.inputId))
782 782 #
783 783 # for opConfObj in self.opConfObjList:
784 784 # opConfObj.makeXml(procUnitElement)
785 785
786 786 def readXml(self, upElement):
787 787
788 788 self.id = upElement.get('id')
789 789 self.name = upElement.get('name')
790 790 self.datatype = upElement.get('datatype')
791 791 self.inputId = upElement.get('inputId')
792 792
793 793 if self.ELEMENTNAME == "ReadUnit":
794 794 self.datatype = self.datatype.replace("Reader", "")
795 795
796 796 if self.inputId == 'None':
797 797 self.inputId = '0'
798 798
799 799 self.opConfObjList = []
800 800
801 opElementList = upElement.getiterator(OperationConf().getElementName())
801 opElementList = upElement.iter(OperationConf().getElementName())
802 802
803 803 for opElement in opElementList:
804 804 opConfObj = OperationConf()
805 805 opConfObj.readXml(opElement)
806 806 self.opConfObjList.append(opConfObj)
807 807
808 808 if opConfObj.name == 'run':
809 809 self.path = opConfObj.getParameterValue('path')
810 810 self.startDate = opConfObj.getParameterValue('startDate')
811 811 self.endDate = opConfObj.getParameterValue('endDate')
812 812 self.startTime = opConfObj.getParameterValue('startTime')
813 813 self.endTime = opConfObj.getParameterValue('endTime')
814 814
815 815 class Project():
816 816
817 817 id = None
818 818 name = None
819 819 description = None
820 820 filename = None
821 821
822 822 procUnitConfObjDict = None
823 823
824 824 ELEMENTNAME = 'Project'
825 825
826 826 plotterQueue = None
827 827
828 828 def __init__(self, plotter_queue=None):
829 829
830 830 self.id = None
831 831 self.name = None
832 832 self.description = None
833 833
834 834 self.plotterQueue = plotter_queue
835 835
836 836 self.procUnitConfObjDict = {}
837 837
838 838 def __getNewId(self):
839 839
840 840 idList = self.procUnitConfObjDict.keys()
841 841
842 842 id = int(self.id)*10
843 843
844 844 while True:
845 845 id += 1
846 846
847 847 if str(id) in idList:
848 848 continue
849 849
850 850 break
851 851
852 852 return str(id)
853 853
854 854 def getElementName(self):
855 855
856 856 return self.ELEMENTNAME
857 857
858 858 def getId(self):
859 859
860 860 return self.id
861 861
862 862 def updateId(self, new_id):
863 863
864 864 self.id = str(new_id)
865 865
866 866 keyList = self.procUnitConfObjDict.keys()
867 867 keyList.sort()
868 868
869 869 n = 1
870 870 newProcUnitConfObjDict = {}
871 871
872 872 for procKey in keyList:
873 873
874 874 procUnitConfObj = self.procUnitConfObjDict[procKey]
875 875 idProcUnit = str(int(self.id)*10 + n)
876 876 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
877 877
878 878 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
879 879 n += 1
880 880
881 881 self.procUnitConfObjDict = newProcUnitConfObjDict
882 882
883 883 def setup(self, id, name, description):
884 884
885 885 self.id = str(id)
886 886 self.name = name
887 887 self.description = description
888 888
889 889 def update(self, name, description):
890 890
891 891 self.name = name
892 892 self.description = description
893 893
894 894 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
895 895
896 896 if id is None:
897 897 idReadUnit = self.__getNewId()
898 898 else:
899 899 idReadUnit = str(id)
900 900
901 901 readUnitConfObj = ReadUnitConf()
902 902 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
903 903
904 904 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
905 905
906 906 return readUnitConfObj
907 907
908 908 def addProcUnit(self, inputId='0', datatype=None, name=None):
909 909
910 910 idProcUnit = self.__getNewId()
911 911
912 912 procUnitConfObj = ProcUnitConf()
913 913 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
914 914
915 915 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
916 916
917 917 return procUnitConfObj
918 918
919 919 def removeProcUnit(self, id):
920 920
921 921 if id in self.procUnitConfObjDict.keys():
922 922 self.procUnitConfObjDict.pop(id)
923 923
924 924 def getReadUnitId(self):
925 925
926 926 readUnitConfObj = self.getReadUnitObj()
927 927
928 928 return readUnitConfObj.id
929 929
930 930 def getReadUnitObj(self):
931 931
932 932 for obj in self.procUnitConfObjDict.values():
933 933 if obj.getElementName() == "ReadUnit":
934 934 return obj
935 935
936 936 return None
937 937
938 938 def getProcUnitObj(self, id=None, name=None):
939 939
940 940 if id != None:
941 941 return self.procUnitConfObjDict[id]
942 942
943 943 if name != None:
944 944 return self.getProcUnitObjByName(name)
945 945
946 946 return None
947 947
948 948 def getProcUnitObjByName(self, name):
949 949
950 950 for obj in self.procUnitConfObjDict.values():
951 951 if obj.name == name:
952 952 return obj
953 953
954 954 return None
955 955
956 956 def procUnitItems(self):
957 957
958 958 return self.procUnitConfObjDict.items()
959 959
960 960 def makeXml(self):
961 961
962 962 projectElement = Element('Project')
963 963 projectElement.set('id', str(self.id))
964 964 projectElement.set('name', self.name)
965 965 projectElement.set('description', self.description)
966 966
967 967 for procUnitConfObj in self.procUnitConfObjDict.values():
968 968 procUnitConfObj.makeXml(projectElement)
969 969
970 970 self.projectElement = projectElement
971 971
972 972 def writeXml(self, filename=None):
973 973
974 974 if filename == None:
975 975 if self.filename:
976 976 filename = self.filename
977 977 else:
978 978 filename = "schain.xml"
979 979
980 980 if not filename:
981 981 print "filename has not been defined. Use setFilename(filename) for do it."
982 982 return 0
983 983
984 984 abs_file = os.path.abspath(filename)
985 985
986 986 if not os.access(os.path.dirname(abs_file), os.W_OK):
987 987 print "No write permission on %s" %os.path.dirname(abs_file)
988 988 return 0
989 989
990 990 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
991 991 print "File %s already exists and it could not be overwriten" %abs_file
992 992 return 0
993 993
994 994 self.makeXml()
995 995
996 996 ElementTree(self.projectElement).write(abs_file, method='xml')
997 997
998 998 self.filename = abs_file
999 999
1000 1000 return 1
1001 1001
1002 1002 def readXml(self, filename = None):
1003 1003
1004 1004 if not filename:
1005 1005 print "filename is not defined"
1006 1006 return 0
1007 1007
1008 1008 abs_file = os.path.abspath(filename)
1009 1009
1010 1010 if not os.path.isfile(abs_file):
1011 1011 print "%s file does not exist" %abs_file
1012 1012 return 0
1013 1013
1014 1014 self.projectElement = None
1015 1015 self.procUnitConfObjDict = {}
1016 1016
1017 1017 try:
1018 1018 self.projectElement = ElementTree().parse(abs_file)
1019 1019 except:
1020 1020 print "Error reading %s, verify file format" %filename
1021 1021 return 0
1022 1022
1023 1023 self.project = self.projectElement.tag
1024 1024
1025 1025 self.id = self.projectElement.get('id')
1026 1026 self.name = self.projectElement.get('name')
1027 1027 self.description = self.projectElement.get('description')
1028 1028
1029 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
1029 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1030 1030
1031 1031 for readUnitElement in readUnitElementList:
1032 1032 readUnitConfObj = ReadUnitConf()
1033 1033 readUnitConfObj.readXml(readUnitElement)
1034 1034
1035 1035 if readUnitConfObj.parentId == None:
1036 1036 readUnitConfObj.parentId = self.id
1037 1037
1038 1038 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1039 1039
1040 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
1040 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1041 1041
1042 1042 for procUnitElement in procUnitElementList:
1043 1043 procUnitConfObj = ProcUnitConf()
1044 1044 procUnitConfObj.readXml(procUnitElement)
1045 1045
1046 1046 if procUnitConfObj.parentId == None:
1047 1047 procUnitConfObj.parentId = self.id
1048 1048
1049 1049 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1050 1050
1051 1051 self.filename = abs_file
1052 1052
1053 1053 return 1
1054 1054
1055 1055 def printattr(self):
1056 1056
1057 1057 print "Project[%s]: name = %s, description = %s" %(self.id,
1058 1058 self.name,
1059 1059 self.description)
1060 1060
1061 1061 for procUnitConfObj in self.procUnitConfObjDict.values():
1062 1062 procUnitConfObj.printattr()
1063 1063
1064 1064 def createObjects(self):
1065 1065
1066 1066 for procUnitConfObj in self.procUnitConfObjDict.values():
1067 1067 procUnitConfObj.createObjects(self.plotterQueue)
1068 1068
1069 1069 def __connect(self, objIN, thisObj):
1070 1070
1071 1071 thisObj.setInput(objIN.getOutputObj())
1072 1072
1073 1073 def connectObjects(self):
1074 1074
1075 1075 for thisPUConfObj in self.procUnitConfObjDict.values():
1076 1076
1077 1077 inputId = thisPUConfObj.getInputId()
1078 1078
1079 1079 if int(inputId) == 0:
1080 1080 continue
1081 1081
1082 1082 #Get input object
1083 1083 puConfINObj = self.procUnitConfObjDict[inputId]
1084 1084 puObjIN = puConfINObj.getProcUnitObj()
1085 1085
1086 1086 #Get current object
1087 1087 thisPUObj = thisPUConfObj.getProcUnitObj()
1088 1088
1089 1089 self.__connect(puObjIN, thisPUObj)
1090 1090
1091 1091 def __handleError(self, procUnitConfObj, send_email=True):
1092 1092
1093 1093 import socket
1094 1094
1095 1095 err = traceback.format_exception(sys.exc_info()[0],
1096 1096 sys.exc_info()[1],
1097 1097 sys.exc_info()[2])
1098 1098
1099 1099 print "***** Error occurred in %s *****" %(procUnitConfObj.name)
1100 1100 print "***** %s" %err[-1]
1101 1101
1102 1102 message = "".join(err)
1103 1103
1104 1104 sys.stderr.write(message)
1105 1105
1106 1106 if not send_email:
1107 1107 return
1108 1108
1109 1109 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name)
1110 1110
1111 1111 subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1112 1112 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
1113 1113 subtitle += "Working directory: %s\n" %os.path.abspath("./")
1114 1114 subtitle += "Configuration file: %s\n" %self.filename
1115 1115 subtitle += "Time: %s\n" %str(datetime.datetime.now())
1116 1116
1117 1117 readUnitConfObj = self.getReadUnitObj()
1118 1118 if readUnitConfObj:
1119 1119 subtitle += "\nInput parameters:\n"
1120 1120 subtitle += "[Data path = %s]\n" %readUnitConfObj.path
1121 1121 subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype
1122 1122 subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate
1123 1123 subtitle += "[End date = %s]\n" %readUnitConfObj.endDate
1124 1124 subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime
1125 1125 subtitle += "[End time = %s]\n" %readUnitConfObj.endTime
1126 1126
1127 1127 adminObj = schainpy.admin.SchainNotify()
1128 1128 adminObj.sendAlert(message=message,
1129 1129 subject=subject,
1130 1130 subtitle=subtitle,
1131 1131 filename=self.filename)
1132 1132
1133 1133 def isPaused(self):
1134 1134 return 0
1135 1135
1136 1136 def isStopped(self):
1137 1137 return 0
1138 1138
1139 1139 def runController(self):
1140 1140 """
1141 1141 returns 0 when this process has been stopped, 1 otherwise
1142 1142 """
1143 1143
1144 1144 if self.isPaused():
1145 1145 print "Process suspended"
1146 1146
1147 1147 while True:
1148 1148 sleep(0.1)
1149 1149
1150 1150 if not self.isPaused():
1151 1151 break
1152 1152
1153 1153 if self.isStopped():
1154 1154 break
1155 1155
1156 1156 print "Process reinitialized"
1157 1157
1158 1158 if self.isStopped():
1159 1159 print "Process stopped"
1160 1160 return 0
1161 1161
1162 1162 return 1
1163 1163
1164 1164 def setFilename(self, filename):
1165 1165
1166 1166 self.filename = filename
1167 1167
1168 1168 def setPlotterQueue(self, plotter_queue):
1169 1169
1170 1170 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1171 1171
1172 1172 def getPlotterQueue(self):
1173 1173
1174 1174 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1175 1175
1176 1176 def useExternalPlotter(self):
1177 1177
1178 1178 raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class"
1179 1179
1180 1180 def run(self):
1181 1181
1182 1182 print
1183 1183 print "*"*60
1184 1184 print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__
1185 1185 print "*"*60
1186 1186 print
1187 1187
1188 1188 keyList = self.procUnitConfObjDict.keys()
1189 1189 keyList.sort()
1190 1190
1191 1191 while(True):
1192 1192
1193 1193 is_ok = False
1194 1194
1195 1195 for procKey in keyList:
1196 1196 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
1197 1197
1198 1198 procUnitConfObj = self.procUnitConfObjDict[procKey]
1199 1199
1200 1200 try:
1201 1201 sts = procUnitConfObj.run()
1202 1202 is_ok = is_ok or sts
1203 1203 except KeyboardInterrupt:
1204 1204 is_ok = False
1205 1205 break
1206 1206 except ValueError, e:
1207 1207 sleep(0.5)
1208 1208 self.__handleError(procUnitConfObj, send_email=True)
1209 1209 is_ok = False
1210 1210 break
1211 1211 except:
1212 1212 sleep(0.5)
1213 1213 self.__handleError(procUnitConfObj)
1214 1214 is_ok = False
1215 1215 break
1216 1216
1217 1217 #If every process unit finished so end process
1218 1218 if not(is_ok):
1219 1219 # print "Every process unit have finished"
1220 1220 break
1221 1221
1222 1222 if not self.runController():
1223 1223 break
1224 1224
1225 1225 #Closing every process
1226 1226 for procKey in keyList:
1227 1227 procUnitConfObj = self.procUnitConfObjDict[procKey]
1228 1228 procUnitConfObj.close()
1229 1229
1230 1230 print "Process finished"
1231 1231
1232 1232 def start(self):
1233 1233
1234 1234 self.writeXml()
1235 1235
1236 1236 self.createObjects()
1237 1237 self.connectObjects()
1238 1238 self.run()
1239 1239
1240 1240 if __name__ == '__main__':
1241 1241
1242 1242 desc = "Segundo Test"
1243 1243 filename = "schain.xml"
1244 1244
1245 1245 controllerObj = Project()
1246 1246
1247 1247 controllerObj.setup(id = '191', name='test01', description=desc)
1248 1248
1249 1249 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
1250 1250 path='data/rawdata/',
1251 1251 startDate='2011/01/01',
1252 1252 endDate='2012/12/31',
1253 1253 startTime='00:00:00',
1254 1254 endTime='23:59:59',
1255 1255 online=1,
1256 1256 walk=1)
1257 1257
1258 1258 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
1259 1259
1260 1260 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
1261 1261 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
1262 1262
1263 1263 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
1264 1264 opObj10.addParameter(name='minHei', value='90', format='float')
1265 1265 opObj10.addParameter(name='maxHei', value='180', format='float')
1266 1266
1267 1267 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
1268 1268 opObj12.addParameter(name='n', value='10', format='int')
1269 1269
1270 1270 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
1271 1271 procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
1272 1272 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
1273 1273
1274 1274
1275 1275 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
1276 1276 opObj11.addParameter(name='idfigure', value='1', format='int')
1277 1277 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
1278 1278 opObj11.addParameter(name='zmin', value='40', format='int')
1279 1279 opObj11.addParameter(name='zmax', value='90', format='int')
1280 1280 opObj11.addParameter(name='showprofile', value='1', format='int')
1281 1281
1282 1282 print "Escribiendo el archivo XML"
1283 1283
1284 1284 controllerObj.writeXml(filename)
1285 1285
1286 1286 print "Leyendo el archivo XML"
1287 1287 controllerObj.readXml(filename)
1288 1288 #controllerObj.printattr()
1289 1289
1290 1290 controllerObj.createObjects()
1291 1291 controllerObj.connectObjects()
1292 1292 controllerObj.run()
1293 1293
1294 1294 No newline at end of file
@@ -1,661 +1,665
1 1 import os
2 2 import numpy
3 3 import time, datetime
4 4 import mpldriver
5 5
6 6 from schainpy.model.proc.jroproc_base import Operation
7 7
8 8 def isTimeInHourRange(datatime, xmin, xmax):
9 9
10 10 if xmin == None or xmax == None:
11 11 return 1
12 12 hour = datatime.hour + datatime.minute/60.0
13 13
14 14 if xmin < (xmax % 24):
15 15
16 16 if hour >= xmin and hour <= xmax:
17 17 return 1
18 18 else:
19 19 return 0
20 20
21 21 else:
22 22
23 23 if hour >= xmin or hour <= (xmax % 24):
24 24 return 1
25 25 else:
26 26 return 0
27 27
28 28 return 0
29 29
30 30 def isRealtime(utcdatatime):
31 31
32 32 utcnow = time.mktime(time.localtime())
33 33 delta = abs(utcnow - utcdatatime) # abs
34 34 if delta >= 30.:
35 35 return False
36 36 return True
37 37
38 38 class Figure(Operation):
39 39
40 40 __driver = mpldriver
41 41 fig = None
42 42
43 43 id = None
44 44 wintitle = None
45 45 width = None
46 46 height = None
47 47 nplots = None
48 48 timerange = None
49 49
50 50 axesObjList = []
51 51
52 52 WIDTH = 300
53 53 HEIGHT = 200
54 54 PREFIX = 'fig'
55 55
56 56 xmin = None
57 57 xmax = None
58 58
59 59 counter_imagwr = 0
60 60
61 61 figfile = None
62 62
63 63 created = False
64 64
65 65 def __init__(self):
66 66
67 67 raise NotImplementedError
68 68
69 69 def __del__(self):
70 70
71 71 self.__driver.closeFigure()
72 72
73 73 def getFilename(self, name, ext='.png'):
74 74
75 75 path = '%s%03d' %(self.PREFIX, self.id)
76 76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
77 77 return os.path.join(path, filename)
78 78
79 79 def getAxesObjList(self):
80 80
81 81 return self.axesObjList
82 82
83 83 def getSubplots(self):
84 84
85 85 raise NotImplementedError
86 86
87 87 def getScreenDim(self, widthplot, heightplot):
88 88
89 89 nrow, ncol = self.getSubplots()
90 90
91 91 widthscreen = widthplot*ncol
92 92 heightscreen = heightplot*nrow
93 93
94 94 return widthscreen, heightscreen
95 95
96 96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
97 97
98 98 # if self.xmin != None and self.xmax != None:
99 99 # if timerange == None:
100 100 # timerange = self.xmax - self.xmin
101 101 # xmin = self.xmin + timerange
102 102 # xmax = self.xmax + timerange
103 103 #
104 104 # return xmin, xmax
105 105
106 106 if timerange == None and (xmin==None or xmax==None):
107 107 timerange = 14400 #seconds
108 108
109 109 if timerange != None:
110 110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
111 111 else:
112 112 txmin = x[0] #- x[0] % 10*60
113 113
114 114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116 116
117 117 if timerange != None:
118 118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
119 119 xmax = xmin + timerange/(60*60.)
120 120
121 121 d1970 = datetime.datetime(1970,1,1)
122 122
123 123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
124 124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
125 125
126 126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
127 127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
128 128
129 129 return xmin_sec, xmax_sec
130 130
131 131 def init(self, id, nplots, wintitle):
132 132
133 133 raise NotImplementedError, "This method has been replaced by createFigure"
134 134
135 135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
136 136
137 137 """
138 138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
139 139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
140 140 y self.HEIGHT y el numero de subplots (nrow, ncol)
141 141
142 142 Input:
143 143 id : Los parametros necesarios son
144 144 wintitle :
145 145
146 146 """
147 147
148 148 if widthplot == None:
149 149 widthplot = self.WIDTH
150 150
151 151 if heightplot == None:
152 152 heightplot = self.HEIGHT
153 153
154 154 self.id = id
155 155
156 156 self.wintitle = wintitle
157 157
158 158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
159 159
160 160 # if self.created:
161 161 # self.__driver.closeFigure(self.fig)
162 162
163 163 if not self.created:
164 164 self.fig = self.__driver.createFigure(id=self.id,
165 165 wintitle=self.wintitle,
166 166 width=self.widthscreen,
167 167 height=self.heightscreen,
168 168 show=show)
169 169 else:
170 170 self.__driver.clearFigure(self.fig)
171 171
172 172 self.axesObjList = []
173 173 self.counter_imagwr = 0
174 174
175 175 self.created = True
176 176
177 177 def setDriver(self, driver=mpldriver):
178 178
179 179 self.__driver = driver
180 180
181 181 def setTitle(self, title):
182 182
183 183 self.__driver.setTitle(self.fig, title)
184 184
185 185 def setWinTitle(self, title):
186 186
187 187 self.__driver.setWinTitle(self.fig, title=title)
188 188
189 189 def setTextFromAxes(self, text):
190 190
191 191 raise NotImplementedError, "This method has been replaced with Axes.setText"
192 192
193 193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
194 194
195 195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
196 196
197 197 def addAxes(self, *args):
198 198 """
199 199
200 200 Input:
201 201 *args : Los parametros necesarios son
202 202 nrow, ncol, xpos, ypos, colspan, rowspan
203 203 """
204 204
205 205 axesObj = Axes(self.fig, *args)
206 206 self.axesObjList.append(axesObj)
207 207
208 208 def saveFigure(self, figpath, figfile, *args):
209 209
210 210 filename = os.path.join(figpath, figfile)
211 211
212 212 fullpath = os.path.split(filename)[0]
213 213
214 214 if not os.path.exists(fullpath):
215 215 subpath = os.path.split(fullpath)[0]
216 216
217 217 if not os.path.exists(subpath):
218 218 os.mkdir(subpath)
219 219
220 220 os.mkdir(fullpath)
221 221
222 222 self.__driver.saveFigure(self.fig, filename, *args)
223 223
224 224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
225 225
226 226 self.counter_imagwr += 1
227 227 if self.counter_imagwr < wr_period:
228 228 return
229 229
230 230 self.counter_imagwr = 0
231 231
232 232 if save:
233 233
234 234 if not figfile:
235 235
236 236 if not thisDatetime:
237 237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
238 238 return
239 239
240 240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
241 241 figfile = self.getFilename(name = str_datetime)
242 242
243 243 if self.figfile == None:
244 244 self.figfile = figfile
245 245
246 246 if update_figfile:
247 247 self.figfile = figfile
248 248
249 249 # store png plot to local folder
250 250 self.saveFigure(figpath, self.figfile)
251 251
252 252
253 253 if not ftp:
254 254 return
255 255
256 256 if not thisDatetime:
257 257 return
258 258
259 259 # store png plot to FTP server according to RT-Web format
260 260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
261 261 # ftp_filename = os.path.join(figpath, name)
262 262 self.saveFigure(figpath, ftp_filename)
263 263
264 264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
265 265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
266 266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
267 267 FTP_WEI = '%2.2d'%FTP_WEI
268 268 EXP_CODE = '%3.3d'%EXP_CODE
269 269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
270 270 PLOT_CODE = '%2.2d'%PLOT_CODE
271 271 PLOT_POS = '%2.2d'%PLOT_POS
272 272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
273 273 return name
274 274
275 275 def draw(self):
276 276
277 277 self.__driver.draw(self.fig)
278 278
279 279 def run(self):
280 280
281 281 raise NotImplementedError
282 282
283 283 def close(self, show=False):
284 284
285 285 self.__driver.closeFigure(show=show, fig=self.fig)
286 286
287 287 axesList = property(getAxesObjList)
288 288
289 289
290 290 class Axes:
291 291
292 292 __driver = mpldriver
293 293 fig = None
294 294 ax = None
295 295 plot = None
296 296 __missing = 1E30
297 297 __firsttime = None
298 298
299 299 __showprofile = False
300 300
301 301 xmin = None
302 302 xmax = None
303 303 ymin = None
304 304 ymax = None
305 305 zmin = None
306 306 zmax = None
307 307
308 308 x_buffer = None
309 309 z_buffer = None
310 310
311 311 decimationx = None
312 312 decimationy = None
313 313
314 314 __MAXNUMX = 200
315 __MAXNUMY = 400
315 __MAXNUMY = 100
316 316
317 317 __MAXNUMTIME = 500
318 318
319 319 def __init__(self, *args):
320 320
321 321 """
322 322
323 323 Input:
324 324 *args : Los parametros necesarios son
325 325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
326 326 """
327 327
328 328 ax = self.__driver.createAxes(*args)
329 329 self.fig = args[0]
330 330 self.ax = ax
331 331 self.plot = None
332 332
333 333 self.__firsttime = True
334 334 self.idlineList = []
335 335
336 336 self.x_buffer = numpy.array([])
337 337 self.z_buffer = numpy.array([])
338 338
339 339 def setText(self, text):
340 340
341 341 self.__driver.setAxesText(self.ax, text)
342 342
343 343 def setXAxisAsTime(self):
344 344 pass
345 345
346 346 def pline(self, x, y,
347 347 xmin=None, xmax=None,
348 348 ymin=None, ymax=None,
349 349 xlabel='', ylabel='',
350 350 title='',
351 351 **kwargs):
352 352
353 353 """
354 354
355 355 Input:
356 356 x :
357 357 y :
358 358 xmin :
359 359 xmax :
360 360 ymin :
361 361 ymax :
362 362 xlabel :
363 363 ylabel :
364 364 title :
365 365 **kwargs : Los parametros aceptados son
366 366
367 367 ticksize
368 368 ytick_visible
369 369 """
370 370
371 371 if self.__firsttime:
372 372
373 373 if xmin == None: xmin = numpy.nanmin(x)
374 374 if xmax == None: xmax = numpy.nanmax(x)
375 375 if ymin == None: ymin = numpy.nanmin(y)
376 376 if ymax == None: ymax = numpy.nanmax(y)
377 377
378 378 self.plot = self.__driver.createPline(self.ax, x, y,
379 379 xmin, xmax,
380 380 ymin, ymax,
381 381 xlabel=xlabel,
382 382 ylabel=ylabel,
383 383 title=title,
384 384 **kwargs)
385 385
386 386 self.idlineList.append(0)
387 387 self.__firsttime = False
388 388 return
389 389
390 390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
391 391 ylabel=ylabel,
392 392 title=title)
393 393
394 394 # self.__driver.pause()
395 395
396 396 def addpline(self, x, y, idline, **kwargs):
397 397 lines = self.ax.lines
398 398
399 399 if idline in self.idlineList:
400 400 self.__driver.set_linedata(self.ax, x, y, idline)
401 401
402 402 if idline not in(self.idlineList):
403 403 self.__driver.addpline(self.ax, x, y, **kwargs)
404 404 self.idlineList.append(idline)
405 405
406 406 return
407 407
408 408 def pmultiline(self, x, y,
409 409 xmin=None, xmax=None,
410 410 ymin=None, ymax=None,
411 411 xlabel='', ylabel='',
412 412 title='',
413 413 **kwargs):
414 414
415 415 if self.__firsttime:
416 416
417 417 if xmin == None: xmin = numpy.nanmin(x)
418 418 if xmax == None: xmax = numpy.nanmax(x)
419 419 if ymin == None: ymin = numpy.nanmin(y)
420 420 if ymax == None: ymax = numpy.nanmax(y)
421 421
422 422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
423 423 xmin, xmax,
424 424 ymin, ymax,
425 425 xlabel=xlabel,
426 426 ylabel=ylabel,
427 427 title=title,
428 428 **kwargs)
429 429 self.__firsttime = False
430 430 return
431 431
432 432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
433 433 ylabel=ylabel,
434 434 title=title)
435 435
436 436 # self.__driver.pause()
437 437
438 438 def pmultilineyaxis(self, x, y,
439 439 xmin=None, xmax=None,
440 440 ymin=None, ymax=None,
441 441 xlabel='', ylabel='',
442 442 title='',
443 443 **kwargs):
444 444
445 445 if self.__firsttime:
446 446
447 447 if xmin == None: xmin = numpy.nanmin(x)
448 448 if xmax == None: xmax = numpy.nanmax(x)
449 449 if ymin == None: ymin = numpy.nanmin(y)
450 450 if ymax == None: ymax = numpy.nanmax(y)
451 451
452 452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
453 453 xmin, xmax,
454 454 ymin, ymax,
455 455 xlabel=xlabel,
456 456 ylabel=ylabel,
457 457 title=title,
458 458 **kwargs)
459 459 if self.xmin == None: self.xmin = xmin
460 460 if self.xmax == None: self.xmax = xmax
461 461 if self.ymin == None: self.ymin = ymin
462 462 if self.ymax == None: self.ymax = ymax
463 463
464 464 self.__firsttime = False
465 465 return
466 466
467 467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
468 468 ylabel=ylabel,
469 469 title=title)
470 470
471 471 # self.__driver.pause()
472 472
473 473 def pcolor(self, x, y, z,
474 474 xmin=None, xmax=None,
475 475 ymin=None, ymax=None,
476 476 zmin=None, zmax=None,
477 477 xlabel='', ylabel='',
478 478 title='', colormap='jet',
479 479 **kwargs):
480 480
481 481 """
482 482 Input:
483 483 x :
484 484 y :
485 485 x :
486 486 xmin :
487 487 xmax :
488 488 ymin :
489 489 ymax :
490 490 zmin :
491 491 zmax :
492 492 xlabel :
493 493 ylabel :
494 494 title :
495 495 **kwargs : Los parametros aceptados son
496 496 ticksize=9,
497 497 cblabel=''
498 498 """
499 499
500 500 #Decimating data
501 501 xlen = len(x)
502 502 ylen = len(y)
503 503
504 decimationx = numpy.floor(xlen/self.__MAXNUMX) - 1 if numpy.floor(xlen/self.__MAXNUMX)>1 else 1
505 decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1
506
504 decimationx = int(xlen/self.__MAXNUMX)+1 \
505 if int(xlen/self.__MAXNUMX)>1 else 1
506 decimationy = int(ylen/self.__MAXNUMY) \
507 if int(ylen/self.__MAXNUMY)>1 else 1
508
509 x_buffer = x#[::decimationx]
510 y_buffer = y#[::decimationy]
511 z_buffer = z#[::decimationx, ::decimationy]
507 512
508 x_buffer = x[::decimationx]
509 y_buffer = y[::decimationy]
510 z_buffer = z[::decimationx, ::decimationy]
511 513 #===================================================
512 514
513 515 if self.__firsttime:
514 516
515 517 if xmin == None: xmin = numpy.nanmin(x)
516 518 if xmax == None: xmax = numpy.nanmax(x)
517 519 if ymin == None: ymin = numpy.nanmin(y)
518 520 if ymax == None: ymax = numpy.nanmax(y)
519 521 if zmin == None: zmin = numpy.nanmin(z)
520 522 if zmax == None: zmax = numpy.nanmax(z)
521 523
522 524
523 525 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
524 526 y_buffer,
525 527 z_buffer,
526 528 xmin, xmax,
527 529 ymin, ymax,
528 530 zmin, zmax,
529 531 xlabel=xlabel,
530 532 ylabel=ylabel,
531 533 title=title,
532 534 colormap=colormap,
533 535 **kwargs)
534 536
535 537 if self.xmin == None: self.xmin = xmin
536 538 if self.xmax == None: self.xmax = xmax
537 539 if self.ymin == None: self.ymin = ymin
538 540 if self.ymax == None: self.ymax = ymax
539 541 if self.zmin == None: self.zmin = zmin
540 542 if self.zmax == None: self.zmax = zmax
541 543
542 544 self.__firsttime = False
543 545 return
544 546
545 547 self.__driver.pcolor(self.plot,
546 548 z_buffer,
547 549 xlabel=xlabel,
548 550 ylabel=ylabel,
549 551 title=title)
550 552
551 553 # self.__driver.pause()
552 554
553 555 def pcolorbuffer(self, x, y, z,
554 556 xmin=None, xmax=None,
555 557 ymin=None, ymax=None,
556 558 zmin=None, zmax=None,
557 559 xlabel='', ylabel='',
558 560 title='', rti = True, colormap='jet',
559 561 maxNumX = None, maxNumY = None,
560 562 **kwargs):
561 563
562 564 if maxNumX == None:
563 565 maxNumX = self.__MAXNUMTIME
564 566
565 567 if maxNumY == None:
566 maxNumY = self.__MAXNUMY
568 maxNumY = self.__MAXNUMY
567 569
568 if self.__firsttime:
570 if self.__firsttime:
569 571 self.z_buffer = z
570 572 self.x_buffer = numpy.hstack((self.x_buffer, x))
571 573
572 574 if xmin == None: xmin = numpy.nanmin(x)
573 575 if xmax == None: xmax = numpy.nanmax(x)
574 576 if ymin == None: ymin = numpy.nanmin(y)
575 577 if ymax == None: ymax = numpy.nanmax(y)
576 578 if zmin == None: zmin = numpy.nanmin(z)
577 579 if zmax == None: zmax = numpy.nanmax(z)
578 580
579 581 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
580 582 xmin, xmax,
581 583 ymin, ymax,
582 584 zmin, zmax,
583 585 xlabel=xlabel,
584 586 ylabel=ylabel,
585 587 title=title,
586 588 colormap=colormap,
587 589 **kwargs)
588 590
589 591 if self.xmin == None: self.xmin = xmin
590 592 if self.xmax == None: self.xmax = xmax
591 593 if self.ymin == None: self.ymin = ymin
592 594 if self.ymax == None: self.ymax = ymax
593 595 if self.zmin == None: self.zmin = zmin
594 596 if self.zmax == None: self.zmax = zmax
595 597
596 598 self.__firsttime = False
597 599 return
598 600
599 601 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
600 602 self.z_buffer = numpy.hstack((self.z_buffer, z))
601 603 z_buffer = self.z_buffer.reshape(-1,len(y))
602 604
603 605 #Decimating data
604 606 xlen = len(self.x_buffer)
605 607 ylen = len(y)
606 608
607 decimationx = numpy.floor(xlen/maxNumX) + 1
608 decimationy = numpy.floor(ylen/maxNumY) + 1
609 decimationx = int(xlen/self.__MAXNUMX) \
610 if int(xlen/self.__MAXNUMX)>1 else 1
611 decimationy = int(ylen/self.__MAXNUMY) \
612 if int(ylen/self.__MAXNUMY)>1 else 1
609 613
610 x_buffer = self.x_buffer[::decimationx]
611 y_buffer = y[::decimationy]
612 z_buffer = z_buffer[::decimationx, ::decimationy]
614 x_buffer = self.x_buffer#[::decimationx]
615 y_buffer = y#[::decimationy]
616 z_buffer = z_buffer#[::decimationx, ::decimationy]
613 617 #===================================================
614 618
615 619 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
616 620
617 621 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
618 622 xlabel=xlabel,
619 623 ylabel=ylabel,
620 624 title=title,
621 625 colormap=colormap)
622 626
623 627 # self.__driver.pause()
624 628
625 629 def polar(self, x, y,
626 630 title='', xlabel='',ylabel='',**kwargs):
627 631
628 632 if self.__firsttime:
629 633 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
630 634 self.__firsttime = False
631 635 self.x_buffer = x
632 636 self.y_buffer = y
633 637 return
634 638
635 639 self.x_buffer = numpy.hstack((self.x_buffer,x))
636 640 self.y_buffer = numpy.hstack((self.y_buffer,y))
637 641 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
638 642 ylabel=ylabel,
639 643 title=title)
640 644
641 645 # self.__driver.pause()
642 646
643 647 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
644 648
645 649 if x_buffer.shape[0] < 2:
646 650 return x_buffer, y_buffer, z_buffer
647 651
648 652 deltas = x_buffer[1:] - x_buffer[0:-1]
649 653 x_median = numpy.median(deltas)
650 654
651 655 index = numpy.where(deltas > 5*x_median)
652 656
653 657 if len(index[0]) != 0:
654 658 z_buffer[index[0],::] = self.__missing
655 659 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
656 660
657 661 return x_buffer, y_buffer, z_buffer
658 662
659 663
660 664
661 665 No newline at end of file
@@ -1,1949 +1,1951
1 1 import os
2 2 import datetime
3 3 import numpy
4 4
5 5 from figure import Figure, isRealtime, isTimeInHourRange
6 6 from plotting_codes import *
7 7
8 import matplotlib.pyplot as plt
9
8 10 class MomentsPlot(Figure):
9 11
10 12 isConfig = None
11 13 __nsubplots = None
12 14
13 15 WIDTHPROF = None
14 16 HEIGHTPROF = None
15 17 PREFIX = 'prm'
16 18
17 19 def __init__(self):
18 20
19 21 self.isConfig = False
20 22 self.__nsubplots = 1
21 23
22 24 self.WIDTH = 280
23 25 self.HEIGHT = 250
24 26 self.WIDTHPROF = 120
25 27 self.HEIGHTPROF = 0
26 28 self.counter_imagwr = 0
27 29
28 30 self.PLOT_CODE = MOMENTS_CODE
29 31
30 32 self.FTP_WEI = None
31 33 self.EXP_CODE = None
32 34 self.SUB_EXP_CODE = None
33 35 self.PLOT_POS = None
34 36
35 37 def getSubplots(self):
36 38
37 39 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 40 nrow = int(self.nplots*1./ncol + 0.9)
39 41
40 42 return nrow, ncol
41 43
42 44 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43 45
44 46 self.__showprofile = showprofile
45 47 self.nplots = nplots
46 48
47 49 ncolspan = 1
48 50 colspan = 1
49 51 if showprofile:
50 52 ncolspan = 3
51 53 colspan = 2
52 54 self.__nsubplots = 2
53 55
54 56 self.createFigure(id = id,
55 57 wintitle = wintitle,
56 58 widthplot = self.WIDTH + self.WIDTHPROF,
57 59 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 60 show=show)
59 61
60 62 nrow, ncol = self.getSubplots()
61 63
62 64 counter = 0
63 65 for y in range(nrow):
64 66 for x in range(ncol):
65 67
66 68 if counter >= self.nplots:
67 69 break
68 70
69 71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70 72
71 73 if showprofile:
72 74 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73 75
74 76 counter += 1
75 77
76 78 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 79 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 80 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 81 server=None, folder=None, username=None, password=None,
80 82 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81 83
82 84 """
83 85
84 86 Input:
85 87 dataOut :
86 88 id :
87 89 wintitle :
88 90 channelList :
89 91 showProfile :
90 92 xmin : None,
91 93 xmax : None,
92 94 ymin : None,
93 95 ymax : None,
94 96 zmin : None,
95 97 zmax : None
96 98 """
97 99
98 100 if dataOut.flagNoData:
99 101 return None
100 102
101 103 if realtime:
102 104 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 105 print 'Skipping this plot function'
104 106 return
105 107
106 108 if channelList == None:
107 109 channelIndexList = dataOut.channelIndexList
108 110 else:
109 111 channelIndexList = []
110 112 for channel in channelList:
111 113 if channel not in dataOut.channelList:
112 114 raise ValueError, "Channel %d is not in dataOut.channelList"
113 115 channelIndexList.append(dataOut.channelList.index(channel))
114 116
115 117 factor = dataOut.normFactor
116 118 x = dataOut.abscissaList
117 119 y = dataOut.heightList
118 120
119 121 z = dataOut.data_pre[channelIndexList,:,:]/factor
120 122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
121 123 avg = numpy.average(z, axis=1)
122 124 noise = dataOut.noise/factor
123 125
124 126 zdB = 10*numpy.log10(z)
125 127 avgdB = 10*numpy.log10(avg)
126 128 noisedB = 10*numpy.log10(noise)
127 129
128 130 #thisDatetime = dataOut.datatime
129 131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 132 title = wintitle + " Parameters"
131 133 xlabel = "Velocity (m/s)"
132 134 ylabel = "Range (Km)"
133 135
134 136 update_figfile = False
135 137
136 138 if not self.isConfig:
137 139
138 140 nplots = len(channelIndexList)
139 141
140 142 self.setup(id=id,
141 143 nplots=nplots,
142 144 wintitle=wintitle,
143 145 showprofile=showprofile,
144 146 show=show)
145 147
146 148 if xmin == None: xmin = numpy.nanmin(x)
147 149 if xmax == None: xmax = numpy.nanmax(x)
148 150 if ymin == None: ymin = numpy.nanmin(y)
149 151 if ymax == None: ymax = numpy.nanmax(y)
150 152 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
151 153 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
152 154
153 155 self.FTP_WEI = ftp_wei
154 156 self.EXP_CODE = exp_code
155 157 self.SUB_EXP_CODE = sub_exp_code
156 158 self.PLOT_POS = plot_pos
157 159
158 160 self.isConfig = True
159 161 update_figfile = True
160 162
161 163 self.setWinTitle(title)
162 164
163 165 for i in range(self.nplots):
164 166 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
165 167 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
166 168 axes = self.axesList[i*self.__nsubplots]
167 169 axes.pcolor(x, y, zdB[i,:,:],
168 170 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
169 171 xlabel=xlabel, ylabel=ylabel, title=title,
170 172 ticksize=9, cblabel='')
171 173 #Mean Line
172 174 mean = dataOut.data_param[i, 1, :]
173 175 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
174 176
175 177 if self.__showprofile:
176 178 axes = self.axesList[i*self.__nsubplots +1]
177 179 axes.pline(avgdB[i], y,
178 180 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
179 181 xlabel='dB', ylabel='', title='',
180 182 ytick_visible=False,
181 183 grid='x')
182 184
183 185 noiseline = numpy.repeat(noisedB[i], len(y))
184 186 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
185 187
186 188 self.draw()
187 189
188 190 self.save(figpath=figpath,
189 191 figfile=figfile,
190 192 save=save,
191 193 ftp=ftp,
192 194 wr_period=wr_period,
193 195 thisDatetime=thisDatetime)
194 196
195 197
196 198
197 199 class SkyMapPlot(Figure):
198 200
199 201 __isConfig = None
200 202 __nsubplots = None
201 203
202 204 WIDTHPROF = None
203 205 HEIGHTPROF = None
204 206 PREFIX = 'mmap'
205 207
206 208 def __init__(self):
207 209
208 210 self.isConfig = False
209 211 self.__nsubplots = 1
210 212
211 213 # self.WIDTH = 280
212 214 # self.HEIGHT = 250
213 215 self.WIDTH = 600
214 216 self.HEIGHT = 600
215 217 self.WIDTHPROF = 120
216 218 self.HEIGHTPROF = 0
217 219 self.counter_imagwr = 0
218 220
219 221 self.PLOT_CODE = MSKYMAP_CODE
220 222
221 223 self.FTP_WEI = None
222 224 self.EXP_CODE = None
223 225 self.SUB_EXP_CODE = None
224 226 self.PLOT_POS = None
225 227
226 228 def getSubplots(self):
227 229
228 230 ncol = int(numpy.sqrt(self.nplots)+0.9)
229 231 nrow = int(self.nplots*1./ncol + 0.9)
230 232
231 233 return nrow, ncol
232 234
233 235 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
234 236
235 237 self.__showprofile = showprofile
236 238 self.nplots = nplots
237 239
238 240 ncolspan = 1
239 241 colspan = 1
240 242
241 243 self.createFigure(id = id,
242 244 wintitle = wintitle,
243 245 widthplot = self.WIDTH, #+ self.WIDTHPROF,
244 246 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
245 247 show=show)
246 248
247 249 nrow, ncol = 1,1
248 250 counter = 0
249 251 x = 0
250 252 y = 0
251 253 self.addAxes(1, 1, 0, 0, 1, 1, True)
252 254
253 255 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
254 256 tmin=0, tmax=24, timerange=None,
255 257 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
256 258 server=None, folder=None, username=None, password=None,
257 259 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
258 260
259 261 """
260 262
261 263 Input:
262 264 dataOut :
263 265 id :
264 266 wintitle :
265 267 channelList :
266 268 showProfile :
267 269 xmin : None,
268 270 xmax : None,
269 271 ymin : None,
270 272 ymax : None,
271 273 zmin : None,
272 274 zmax : None
273 275 """
274 276
275 277 arrayParameters = dataOut.data_param
276 278 error = arrayParameters[:,-1]
277 279 indValid = numpy.where(error == 0)[0]
278 280 finalMeteor = arrayParameters[indValid,:]
279 281 finalAzimuth = finalMeteor[:,3]
280 282 finalZenith = finalMeteor[:,4]
281 283
282 284 x = finalAzimuth*numpy.pi/180
283 285 y = finalZenith
284 286 x1 = [dataOut.ltctime, dataOut.ltctime]
285 287
286 288 #thisDatetime = dataOut.datatime
287 289 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
288 290 title = wintitle + " Parameters"
289 291 xlabel = "Zonal Zenith Angle (deg) "
290 292 ylabel = "Meridional Zenith Angle (deg)"
291 293 update_figfile = False
292 294
293 295 if not self.isConfig:
294 296
295 297 nplots = 1
296 298
297 299 self.setup(id=id,
298 300 nplots=nplots,
299 301 wintitle=wintitle,
300 302 showprofile=showprofile,
301 303 show=show)
302 304
303 305 if self.xmin is None and self.xmax is None:
304 306 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
305 307
306 308 if timerange != None:
307 309 self.timerange = timerange
308 310 else:
309 311 self.timerange = self.xmax - self.xmin
310 312
311 313 self.FTP_WEI = ftp_wei
312 314 self.EXP_CODE = exp_code
313 315 self.SUB_EXP_CODE = sub_exp_code
314 316 self.PLOT_POS = plot_pos
315 317 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
316 318 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
317 319 self.isConfig = True
318 320 update_figfile = True
319 321
320 322 self.setWinTitle(title)
321 323
322 324 i = 0
323 325 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
324 326
325 327 axes = self.axesList[i*self.__nsubplots]
326 328 nevents = axes.x_buffer.shape[0] + x.shape[0]
327 329 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
328 330 axes.polar(x, y,
329 331 title=title, xlabel=xlabel, ylabel=ylabel,
330 332 ticksize=9, cblabel='')
331 333
332 334 self.draw()
333 335
334 336 self.save(figpath=figpath,
335 337 figfile=figfile,
336 338 save=save,
337 339 ftp=ftp,
338 340 wr_period=wr_period,
339 341 thisDatetime=thisDatetime,
340 342 update_figfile=update_figfile)
341 343
342 344 if dataOut.ltctime >= self.xmax:
343 345 self.isConfigmagwr = wr_period
344 346 self.isConfig = False
345 347 update_figfile = True
346 348 axes.__firsttime = True
347 349 self.xmin += self.timerange
348 350 self.xmax += self.timerange
349 351
350 352
351 353
352 354
353 355 class WindProfilerPlot(Figure):
354 356
355 357 __isConfig = None
356 358 __nsubplots = None
357 359
358 360 WIDTHPROF = None
359 361 HEIGHTPROF = None
360 362 PREFIX = 'wind'
361 363
362 364 def __init__(self):
363 365
364 366 self.timerange = None
365 367 self.isConfig = False
366 368 self.__nsubplots = 1
367 369
368 370 self.WIDTH = 800
369 371 self.HEIGHT = 300
370 372 self.WIDTHPROF = 120
371 373 self.HEIGHTPROF = 0
372 374 self.counter_imagwr = 0
373 375
374 376 self.PLOT_CODE = WIND_CODE
375 377
376 378 self.FTP_WEI = None
377 379 self.EXP_CODE = None
378 380 self.SUB_EXP_CODE = None
379 381 self.PLOT_POS = None
380 382 self.tmin = None
381 383 self.tmax = None
382 384
383 385 self.xmin = None
384 386 self.xmax = None
385 387
386 388 self.figfile = None
387 389
388 390 def getSubplots(self):
389 391
390 392 ncol = 1
391 393 nrow = self.nplots
392 394
393 395 return nrow, ncol
394 396
395 397 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
396 398
397 399 self.__showprofile = showprofile
398 400 self.nplots = nplots
399 401
400 402 ncolspan = 1
401 403 colspan = 1
402 404
403 405 self.createFigure(id = id,
404 406 wintitle = wintitle,
405 407 widthplot = self.WIDTH + self.WIDTHPROF,
406 408 heightplot = self.HEIGHT + self.HEIGHTPROF,
407 409 show=show)
408 410
409 411 nrow, ncol = self.getSubplots()
410 412
411 413 counter = 0
412 414 for y in range(nrow):
413 415 if counter >= self.nplots:
414 416 break
415 417
416 418 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
417 419 counter += 1
418 420
419 421 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
420 422 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
421 423 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
422 424 timerange=None, SNRthresh = None,
423 425 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
424 426 server=None, folder=None, username=None, password=None,
425 427 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
426 428 """
427 429
428 430 Input:
429 431 dataOut :
430 432 id :
431 433 wintitle :
432 434 channelList :
433 435 showProfile :
434 436 xmin : None,
435 437 xmax : None,
436 438 ymin : None,
437 439 ymax : None,
438 440 zmin : None,
439 441 zmax : None
440 442 """
441 443
442 444 # if timerange is not None:
443 445 # self.timerange = timerange
444 446 #
445 447 # tmin = None
446 448 # tmax = None
447 449
448 450 x = dataOut.getTimeRange1(dataOut.outputInterval)
449 # y = dataOut.heightList
450 451 y = dataOut.heightList
451
452 452 z = dataOut.data_output.copy()
453 453 nplots = z.shape[0] #Number of wind dimensions estimated
454
454 455 nplotsw = nplots
455 456
456 457 #If there is a SNR function defined
457 458 if dataOut.data_SNR is not None:
458 459 nplots += 1
459 460 SNR = dataOut.data_SNR
460 461 SNRavg = numpy.average(SNR, axis=0)
461
462
462 463 SNRdB = 10*numpy.log10(SNR)
463 464 SNRavgdB = 10*numpy.log10(SNRavg)
464
465
465 466 if SNRthresh == None: SNRthresh = -5.0
466 467 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
467
468
468 469 for i in range(nplotsw):
469 470 z[i,ind] = numpy.nan
470
471
471 472
472 473 # showprofile = False
473 474 # thisDatetime = dataOut.datatime
474 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
475 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
476 thisDatetime = datetime.datetime.now()
475 477 title = wintitle + "Wind"
476 478 xlabel = ""
477 479 ylabel = "Height (km)"
478 480 update_figfile = False
479 481
480 482 if not self.isConfig:
481 483
482 484 self.setup(id=id,
483 485 nplots=nplots,
484 486 wintitle=wintitle,
485 487 showprofile=showprofile,
486 488 show=show)
487 489
488 490 if timerange is not None:
489 491 self.timerange = timerange
490 492
491 493 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
492 494
493 if ymin == None: ymin = numpy.nanmin(y)
494 if ymax == None: ymax = numpy.nanmax(y)
495 #if ymin == None: ymin = numpy.nanmin(y)
496 #if ymax == None: ymax = numpy.nanmax(y)
495 497
496 498 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
497 499 #if numpy.isnan(zmax): zmax = 50
498 500 if zmin == None: zmin = -zmax
499 501
500 502 if nplotsw == 3:
501 503 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
502 504 if zmin_ver == None: zmin_ver = -zmax_ver
503 505
504 if dataOut.data_SNR is not None:
505 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
506 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
506 # if dataOut.data_SNR is not None:
507 # if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
508 # if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
507 509
508 510
509 511 self.FTP_WEI = ftp_wei
510 512 self.EXP_CODE = exp_code
511 513 self.SUB_EXP_CODE = sub_exp_code
512 514 self.PLOT_POS = plot_pos
513 515
514 516 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
515 517 self.isConfig = True
516 518 self.figfile = figfile
517 519 update_figfile = True
518 520
519 521 self.setWinTitle(title)
520 522
521 if ((self.xmax - x[1]) < (x[1]-x[0])):
522 x[1] = self.xmax
523 #if ((self.xmax - x[1]) < (x[1]-x[0])):
524 # x[1] = self.xmax
523 525
524 526 strWind = ['Zonal', 'Meridional', 'Vertical']
525 527 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
526 528 zmaxVector = [zmax, zmax, zmax_ver]
527 529 zminVector = [zmin, zmin, zmin_ver]
528 530 windFactor = [1,1,100]
529 531
530 532 for i in range(nplotsw):
531 533
532 534 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
533 535 axes = self.axesList[i*self.__nsubplots]
534 536
535 537 z1 = z[i,:].reshape((1,-1))*windFactor[i]
536
538
537 539 axes.pcolorbuffer(x, y, z1,
538 540 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
539 541 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
540 542 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
541 543
542 544 if dataOut.data_SNR is not None:
543 545 i += 1
544 546 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 547 axes = self.axesList[i*self.__nsubplots]
546
548
547 549 SNRavgdB = SNRavgdB.reshape((1,-1))
548
550
549 551 axes.pcolorbuffer(x, y, SNRavgdB,
550 552 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
551 553 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
552 554 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
553 555
554 556 self.draw()
555 557
556 558 self.save(figpath=figpath,
557 559 figfile=figfile,
558 560 save=save,
559 561 ftp=ftp,
560 562 wr_period=wr_period,
561 563 thisDatetime=thisDatetime,
562 564 update_figfile=update_figfile)
563 565
564 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
565 self.counter_imagwr = wr_period
566 if False and dataOut.ltctime + dataOut.outputInterval >= self.xmax:
567 self.counter_imagwr = wr_period
566 568 self.isConfig = False
567 569 update_figfile = True
568 570
569 571
570 572 class ParametersPlot(Figure):
571 573
572 574 __isConfig = None
573 575 __nsubplots = None
574 576
575 577 WIDTHPROF = None
576 578 HEIGHTPROF = None
577 579 PREFIX = 'param'
578 580
579 581 nplots = None
580 582 nchan = None
581 583
582 584 def __init__(self):
583 585
584 586 self.timerange = None
585 587 self.isConfig = False
586 588 self.__nsubplots = 1
587 589
588 590 self.WIDTH = 800
589 591 self.HEIGHT = 180
590 592 self.WIDTHPROF = 120
591 593 self.HEIGHTPROF = 0
592 594 self.counter_imagwr = 0
593 595
594 596 self.PLOT_CODE = RTI_CODE
595 597
596 598 self.FTP_WEI = None
597 599 self.EXP_CODE = None
598 600 self.SUB_EXP_CODE = None
599 601 self.PLOT_POS = None
600 602 self.tmin = None
601 603 self.tmax = None
602 604
603 605 self.xmin = None
604 606 self.xmax = None
605 607
606 608 self.figfile = None
607 609
608 610 def getSubplots(self):
609 611
610 612 ncol = 1
611 613 nrow = self.nplots
612 614
613 615 return nrow, ncol
614 616
615 617 def setup(self, id, nplots, wintitle, show=True):
616 618
617 619 self.nplots = nplots
618 620
619 621 ncolspan = 1
620 622 colspan = 1
621 623
622 624 self.createFigure(id = id,
623 625 wintitle = wintitle,
624 626 widthplot = self.WIDTH + self.WIDTHPROF,
625 627 heightplot = self.HEIGHT + self.HEIGHTPROF,
626 628 show=show)
627 629
628 630 nrow, ncol = self.getSubplots()
629 631
630 632 counter = 0
631 633 for y in range(nrow):
632 634 for x in range(ncol):
633 635
634 636 if counter >= self.nplots:
635 637 break
636 638
637 639 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
638 640
639 641 counter += 1
640 642
641 643 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
642 644 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
643 645 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
644 646 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
645 647 server=None, folder=None, username=None, password=None,
646 648 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
647 649
648 650 """
649 651
650 652 Input:
651 653 dataOut :
652 654 id :
653 655 wintitle :
654 656 channelList :
655 657 showProfile :
656 658 xmin : None,
657 659 xmax : None,
658 660 ymin : None,
659 661 ymax : None,
660 662 zmin : None,
661 663 zmax : None
662 664 """
663 665
664 666 if colormap:
665 667 colormap="jet"
666 668 else:
667 669 colormap="RdBu_r"
668 670
669 671 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
670 672 return
671 673
672 674 if channelList == None:
673 675 channelIndexList = range(dataOut.data_param.shape[0])
674 676 else:
675 677 channelIndexList = []
676 678 for channel in channelList:
677 679 if channel not in dataOut.channelList:
678 680 raise ValueError, "Channel %d is not in dataOut.channelList"
679 681 channelIndexList.append(dataOut.channelList.index(channel))
680 682
681 683 x = dataOut.getTimeRange1(dataOut.paramInterval)
682 684 y = dataOut.getHeiRange()
683 685
684 686 if dataOut.data_param.ndim == 3:
685 687 z = dataOut.data_param[channelIndexList,paramIndex,:]
686 688 else:
687 689 z = dataOut.data_param[channelIndexList,:]
688 690
689 691 if showSNR:
690 692 #SNR data
691 693 SNRarray = dataOut.data_SNR[channelIndexList,:]
692 694 SNRdB = 10*numpy.log10(SNRarray)
693 695 ind = numpy.where(SNRdB < SNRthresh)
694 696 z[ind] = numpy.nan
695 697
696 698 thisDatetime = dataOut.datatime
697 699 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
698 700 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
699 701 xlabel = ""
700 702 ylabel = "Range (Km)"
701 703
702 704 update_figfile = False
703 705
704 706 if not self.isConfig:
705 707
706 708 nchan = len(channelIndexList)
707 709 self.nchan = nchan
708 710 self.plotFact = 1
709 711 nplots = nchan
710 712
711 713 if showSNR:
712 714 nplots = nchan*2
713 715 self.plotFact = 2
714 716 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
715 717 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
716 718
717 719 self.setup(id=id,
718 720 nplots=nplots,
719 721 wintitle=wintitle,
720 722 show=show)
721 723
722 724 if timerange != None:
723 725 self.timerange = timerange
724 726
725 727 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
726 728
727 729 if ymin == None: ymin = numpy.nanmin(y)
728 730 if ymax == None: ymax = numpy.nanmax(y)
729 731 if zmin == None: zmin = numpy.nanmin(z)
730 732 if zmax == None: zmax = numpy.nanmax(z)
731 733
732 734 self.FTP_WEI = ftp_wei
733 735 self.EXP_CODE = exp_code
734 736 self.SUB_EXP_CODE = sub_exp_code
735 737 self.PLOT_POS = plot_pos
736 738
737 739 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
738 740 self.isConfig = True
739 741 self.figfile = figfile
740 742 update_figfile = True
741 743
742 744 self.setWinTitle(title)
743 745
744 746 for i in range(self.nchan):
745 747 index = channelIndexList[i]
746 748 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
747 749 axes = self.axesList[i*self.plotFact]
748 750 z1 = z[i,:].reshape((1,-1))
749 751 axes.pcolorbuffer(x, y, z1,
750 752 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
751 753 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
752 754 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
753 755
754 756 if showSNR:
755 757 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
756 758 axes = self.axesList[i*self.plotFact + 1]
757 759 SNRdB1 = SNRdB[i,:].reshape((1,-1))
758 760 axes.pcolorbuffer(x, y, SNRdB1,
759 761 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
760 762 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
761 763 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
762 764
763 765
764 766 self.draw()
765 767
766 768 if dataOut.ltctime >= self.xmax:
767 769 self.counter_imagwr = wr_period
768 770 self.isConfig = False
769 771 update_figfile = True
770 772
771 773 self.save(figpath=figpath,
772 774 figfile=figfile,
773 775 save=save,
774 776 ftp=ftp,
775 777 wr_period=wr_period,
776 778 thisDatetime=thisDatetime,
777 779 update_figfile=update_figfile)
778 780
779 781
780 782
781 class Parameters1Plot(Figure):
783 class ParametersPlot(Figure):
782 784
783 785 __isConfig = None
784 786 __nsubplots = None
785 787
786 788 WIDTHPROF = None
787 789 HEIGHTPROF = None
788 790 PREFIX = 'prm'
789 791
790 792 def __init__(self):
791 793
792 794 self.timerange = 2*60*60
793 795 self.isConfig = False
794 796 self.__nsubplots = 1
795 797
796 798 self.WIDTH = 800
797 799 self.HEIGHT = 150
798 800 self.WIDTHPROF = 120
799 801 self.HEIGHTPROF = 0
800 802 self.counter_imagwr = 0
801 803
802 804 self.PLOT_CODE = PARMS_CODE
803 805
804 806 self.FTP_WEI = None
805 807 self.EXP_CODE = None
806 808 self.SUB_EXP_CODE = None
807 809 self.PLOT_POS = None
808 810 self.tmin = None
809 811 self.tmax = None
810 812
811 813 self.xmin = None
812 814 self.xmax = None
813 815
814 816 self.figfile = None
815 817
816 818 def getSubplots(self):
817 819
818 820 ncol = 1
819 821 nrow = self.nplots
820 822
821 823 return nrow, ncol
822 824
823 825 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
824 826
825 827 self.__showprofile = showprofile
826 828 self.nplots = nplots
827 829
828 830 ncolspan = 1
829 831 colspan = 1
830 832
831 833 self.createFigure(id = id,
832 834 wintitle = wintitle,
833 835 widthplot = self.WIDTH + self.WIDTHPROF,
834 836 heightplot = self.HEIGHT + self.HEIGHTPROF,
835 837 show=show)
836 838
837 839 nrow, ncol = self.getSubplots()
838 840
839 841 counter = 0
840 842 for y in range(nrow):
841 843 for x in range(ncol):
842 844
843 845 if counter >= self.nplots:
844 846 break
845 847
846 848 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
847 849
848 850 if showprofile:
849 851 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
850 852
851 853 counter += 1
852 854
853 855 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
854 856 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
855 857 parameterIndex = None, onlyPositive = False,
856 858 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
857 859 DOP = True,
858 860 zlabel = "", parameterName = "", parameterObject = "data_param",
859 861 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
860 862 server=None, folder=None, username=None, password=None,
861 863 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
862 864
863 865 """
864 866
865 867 Input:
866 868 dataOut :
867 869 id :
868 870 wintitle :
869 871 channelList :
870 872 showProfile :
871 873 xmin : None,
872 874 xmax : None,
873 875 ymin : None,
874 876 ymax : None,
875 877 zmin : None,
876 878 zmax : None
877 879 """
878 880
879 881 data_param = getattr(dataOut, parameterObject)
880 882
881 883 if channelList == None:
882 884 channelIndexList = numpy.arange(data_param.shape[0])
883 885 else:
884 886 channelIndexList = numpy.array(channelList)
885 887
886 888 nchan = len(channelIndexList) #Number of channels being plotted
887 889
888 890 if nchan < 1:
889 891 return
890 892
891 893 nGraphsByChannel = 0
892 894
893 895 if SNR:
894 896 nGraphsByChannel += 1
895 897 if DOP:
896 898 nGraphsByChannel += 1
897 899
898 900 if nGraphsByChannel < 1:
899 901 return
900 902
901 903 nplots = nGraphsByChannel*nchan
902 904
903 905 if timerange is not None:
904 906 self.timerange = timerange
905 907
906 908 #tmin = None
907 909 #tmax = None
908 910 if parameterIndex == None:
909 911 parameterIndex = 1
910 912
911 913 x = dataOut.getTimeRange1(dataOut.paramInterval)
912 914 y = dataOut.heightList
913 915 z = data_param[channelIndexList,parameterIndex,:].copy()
914 916
915 917 zRange = dataOut.abscissaList
916 918 # nChannels = z.shape[0] #Number of wind dimensions estimated
917 919 # thisDatetime = dataOut.datatime
918 920
919 921 if dataOut.data_SNR is not None:
920 922 SNRarray = dataOut.data_SNR[channelIndexList,:]
921 923 SNRdB = 10*numpy.log10(SNRarray)
922 924 # SNRavgdB = 10*numpy.log10(SNRavg)
923 925 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
924 926 z[ind] = numpy.nan
925 927
926 928 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
927 929 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
928 930 xlabel = ""
929 931 ylabel = "Range (Km)"
930 932
931 933 if (SNR and not onlySNR): nplots = 2*nplots
932 934
933 935 if onlyPositive:
934 936 colormap = "jet"
935 937 zmin = 0
936 938 else: colormap = "RdBu_r"
937 939
938 940 if not self.isConfig:
939 941
940 942 self.setup(id=id,
941 943 nplots=nplots,
942 944 wintitle=wintitle,
943 945 showprofile=showprofile,
944 946 show=show)
945 947
946 948 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
947 949
948 950 if ymin == None: ymin = numpy.nanmin(y)
949 951 if ymax == None: ymax = numpy.nanmax(y)
950 952 if zmin == None: zmin = numpy.nanmin(zRange)
951 953 if zmax == None: zmax = numpy.nanmax(zRange)
952 954
953 955 if SNR:
954 956 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
955 957 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
956 958
957 959 self.FTP_WEI = ftp_wei
958 960 self.EXP_CODE = exp_code
959 961 self.SUB_EXP_CODE = sub_exp_code
960 962 self.PLOT_POS = plot_pos
961 963
962 964 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
963 965 self.isConfig = True
964 966 self.figfile = figfile
965 967
966 968 self.setWinTitle(title)
967 969
968 970 if ((self.xmax - x[1]) < (x[1]-x[0])):
969 971 x[1] = self.xmax
970 972
971 973 for i in range(nchan):
972 974
973 975 if (SNR and not onlySNR): j = 2*i
974 976 else: j = i
975 977
976 978 j = nGraphsByChannel*i
977 979
978 980 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
979 981 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
980 982
981 983 if not onlySNR:
982 984 axes = self.axesList[j*self.__nsubplots]
983 985 z1 = z[i,:].reshape((1,-1))
984 986 axes.pcolorbuffer(x, y, z1,
985 987 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
986 988 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
987 989 ticksize=9, cblabel=zlabel, cbsize="1%")
988 990
989 991 if DOP:
990 992 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
991 993
992 994 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
993 995 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
994 996 axes = self.axesList[j]
995 997 z1 = z[i,:].reshape((1,-1))
996 998 axes.pcolorbuffer(x, y, z1,
997 999 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
998 1000 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
999 1001 ticksize=9, cblabel=zlabel, cbsize="1%")
1000 1002
1001 1003 if SNR:
1002 1004 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1003 1005 axes = self.axesList[(j)*self.__nsubplots]
1004 1006 if not onlySNR:
1005 1007 axes = self.axesList[(j + 1)*self.__nsubplots]
1006 1008
1007 1009 axes = self.axesList[(j + nGraphsByChannel-1)]
1008 1010
1009 1011 z1 = SNRdB[i,:].reshape((1,-1))
1010 1012 axes.pcolorbuffer(x, y, z1,
1011 1013 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1012 1014 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1013 1015 ticksize=9, cblabel=zlabel, cbsize="1%")
1014 1016
1015 1017
1016 1018
1017 1019 self.draw()
1018 1020
1019 1021 if x[1] >= self.axesList[0].xmax:
1020 1022 self.counter_imagwr = wr_period
1021 1023 self.isConfig = False
1022 1024 self.figfile = None
1023 1025
1024 1026 self.save(figpath=figpath,
1025 1027 figfile=figfile,
1026 1028 save=save,
1027 1029 ftp=ftp,
1028 1030 wr_period=wr_period,
1029 1031 thisDatetime=thisDatetime,
1030 1032 update_figfile=False)
1031 1033
1032 1034 class SpectralFittingPlot(Figure):
1033 1035
1034 1036 __isConfig = None
1035 1037 __nsubplots = None
1036 1038
1037 1039 WIDTHPROF = None
1038 1040 HEIGHTPROF = None
1039 1041 PREFIX = 'prm'
1040 1042
1041 1043
1042 1044 N = None
1043 1045 ippSeconds = None
1044 1046
1045 1047 def __init__(self):
1046 1048 self.isConfig = False
1047 1049 self.__nsubplots = 1
1048 1050
1049 1051 self.PLOT_CODE = SPECFIT_CODE
1050 1052
1051 1053 self.WIDTH = 450
1052 1054 self.HEIGHT = 250
1053 1055 self.WIDTHPROF = 0
1054 1056 self.HEIGHTPROF = 0
1055 1057
1056 1058 def getSubplots(self):
1057 1059
1058 1060 ncol = int(numpy.sqrt(self.nplots)+0.9)
1059 1061 nrow = int(self.nplots*1./ncol + 0.9)
1060 1062
1061 1063 return nrow, ncol
1062 1064
1063 1065 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1064 1066
1065 1067 showprofile = False
1066 1068 self.__showprofile = showprofile
1067 1069 self.nplots = nplots
1068 1070
1069 1071 ncolspan = 5
1070 1072 colspan = 4
1071 1073 if showprofile:
1072 1074 ncolspan = 5
1073 1075 colspan = 4
1074 1076 self.__nsubplots = 2
1075 1077
1076 1078 self.createFigure(id = id,
1077 1079 wintitle = wintitle,
1078 1080 widthplot = self.WIDTH + self.WIDTHPROF,
1079 1081 heightplot = self.HEIGHT + self.HEIGHTPROF,
1080 1082 show=show)
1081 1083
1082 1084 nrow, ncol = self.getSubplots()
1083 1085
1084 1086 counter = 0
1085 1087 for y in range(nrow):
1086 1088 for x in range(ncol):
1087 1089
1088 1090 if counter >= self.nplots:
1089 1091 break
1090 1092
1091 1093 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1092 1094
1093 1095 if showprofile:
1094 1096 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1095 1097
1096 1098 counter += 1
1097 1099
1098 1100 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1099 1101 xmin=None, xmax=None, ymin=None, ymax=None,
1100 1102 save=False, figpath='./', figfile=None, show=True):
1101 1103
1102 1104 """
1103 1105
1104 1106 Input:
1105 1107 dataOut :
1106 1108 id :
1107 1109 wintitle :
1108 1110 channelList :
1109 1111 showProfile :
1110 1112 xmin : None,
1111 1113 xmax : None,
1112 1114 zmin : None,
1113 1115 zmax : None
1114 1116 """
1115 1117
1116 1118 if cutHeight==None:
1117 1119 h=270
1118 1120 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1119 1121 cutHeight = dataOut.heightList[heightindex]
1120 1122
1121 1123 factor = dataOut.normFactor
1122 1124 x = dataOut.abscissaList[:-1]
1123 1125 #y = dataOut.getHeiRange()
1124 1126
1125 1127 z = dataOut.data_pre[:,:,heightindex]/factor
1126 1128 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1127 1129 avg = numpy.average(z, axis=1)
1128 1130 listChannels = z.shape[0]
1129 1131
1130 1132 #Reconstruct Function
1131 1133 if fit==True:
1132 1134 groupArray = dataOut.groupList
1133 1135 listChannels = groupArray.reshape((groupArray.size))
1134 1136 listChannels.sort()
1135 1137 spcFitLine = numpy.zeros(z.shape)
1136 1138 constants = dataOut.constants
1137 1139
1138 1140 nGroups = groupArray.shape[0]
1139 1141 nChannels = groupArray.shape[1]
1140 1142 nProfiles = z.shape[1]
1141 1143
1142 1144 for f in range(nGroups):
1143 1145 groupChann = groupArray[f,:]
1144 1146 p = dataOut.data_param[f,:,heightindex]
1145 1147 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1146 1148 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1147 1149 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1148 1150 spcFitLine[groupChann,:] = fitLineAux
1149 1151 # spcFitLine = spcFitLine/factor
1150 1152
1151 1153 z = z[listChannels,:]
1152 1154 spcFitLine = spcFitLine[listChannels,:]
1153 1155 spcFitLinedB = 10*numpy.log10(spcFitLine)
1154 1156
1155 1157 zdB = 10*numpy.log10(z)
1156 1158 #thisDatetime = dataOut.datatime
1157 1159 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1158 1160 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1159 1161 xlabel = "Velocity (m/s)"
1160 1162 ylabel = "Spectrum"
1161 1163
1162 1164 if not self.isConfig:
1163 1165
1164 1166 nplots = listChannels.size
1165 1167
1166 1168 self.setup(id=id,
1167 1169 nplots=nplots,
1168 1170 wintitle=wintitle,
1169 1171 showprofile=showprofile,
1170 1172 show=show)
1171 1173
1172 1174 if xmin == None: xmin = numpy.nanmin(x)
1173 1175 if xmax == None: xmax = numpy.nanmax(x)
1174 1176 if ymin == None: ymin = numpy.nanmin(zdB)
1175 1177 if ymax == None: ymax = numpy.nanmax(zdB)+2
1176 1178
1177 1179 self.isConfig = True
1178 1180
1179 1181 self.setWinTitle(title)
1180 1182 for i in range(self.nplots):
1181 1183 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1182 1184 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1183 1185 axes = self.axesList[i*self.__nsubplots]
1184 1186 if fit == False:
1185 1187 axes.pline(x, zdB[i,:],
1186 1188 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1187 1189 xlabel=xlabel, ylabel=ylabel, title=title
1188 1190 )
1189 1191 if fit == True:
1190 1192 fitline=spcFitLinedB[i,:]
1191 1193 y=numpy.vstack([zdB[i,:],fitline] )
1192 1194 legendlabels=['Data','Fitting']
1193 1195 axes.pmultilineyaxis(x, y,
1194 1196 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1195 1197 xlabel=xlabel, ylabel=ylabel, title=title,
1196 1198 legendlabels=legendlabels, marker=None,
1197 1199 linestyle='solid', grid='both')
1198 1200
1199 1201 self.draw()
1200 1202
1201 1203 self.save(figpath=figpath,
1202 1204 figfile=figfile,
1203 1205 save=save,
1204 1206 ftp=ftp,
1205 1207 wr_period=wr_period,
1206 1208 thisDatetime=thisDatetime)
1207 1209
1208 1210
1209 1211 class EWDriftsPlot(Figure):
1210 1212
1211 1213 __isConfig = None
1212 1214 __nsubplots = None
1213 1215
1214 1216 WIDTHPROF = None
1215 1217 HEIGHTPROF = None
1216 1218 PREFIX = 'drift'
1217 1219
1218 1220 def __init__(self):
1219 1221
1220 1222 self.timerange = 2*60*60
1221 1223 self.isConfig = False
1222 1224 self.__nsubplots = 1
1223 1225
1224 1226 self.WIDTH = 800
1225 1227 self.HEIGHT = 150
1226 1228 self.WIDTHPROF = 120
1227 1229 self.HEIGHTPROF = 0
1228 1230 self.counter_imagwr = 0
1229 1231
1230 1232 self.PLOT_CODE = EWDRIFT_CODE
1231 1233
1232 1234 self.FTP_WEI = None
1233 1235 self.EXP_CODE = None
1234 1236 self.SUB_EXP_CODE = None
1235 1237 self.PLOT_POS = None
1236 1238 self.tmin = None
1237 1239 self.tmax = None
1238 1240
1239 1241 self.xmin = None
1240 1242 self.xmax = None
1241 1243
1242 1244 self.figfile = None
1243 1245
1244 1246 def getSubplots(self):
1245 1247
1246 1248 ncol = 1
1247 1249 nrow = self.nplots
1248 1250
1249 1251 return nrow, ncol
1250 1252
1251 1253 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1252 1254
1253 1255 self.__showprofile = showprofile
1254 1256 self.nplots = nplots
1255 1257
1256 1258 ncolspan = 1
1257 1259 colspan = 1
1258 1260
1259 1261 self.createFigure(id = id,
1260 1262 wintitle = wintitle,
1261 1263 widthplot = self.WIDTH + self.WIDTHPROF,
1262 1264 heightplot = self.HEIGHT + self.HEIGHTPROF,
1263 1265 show=show)
1264 1266
1265 1267 nrow, ncol = self.getSubplots()
1266 1268
1267 1269 counter = 0
1268 1270 for y in range(nrow):
1269 1271 if counter >= self.nplots:
1270 1272 break
1271 1273
1272 1274 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1273 1275 counter += 1
1274 1276
1275 1277 def run(self, dataOut, id, wintitle="", channelList=None,
1276 1278 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1277 1279 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1278 1280 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1279 1281 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1280 1282 server=None, folder=None, username=None, password=None,
1281 1283 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1282 1284 """
1283 1285
1284 1286 Input:
1285 1287 dataOut :
1286 1288 id :
1287 1289 wintitle :
1288 1290 channelList :
1289 1291 showProfile :
1290 1292 xmin : None,
1291 1293 xmax : None,
1292 1294 ymin : None,
1293 1295 ymax : None,
1294 1296 zmin : None,
1295 1297 zmax : None
1296 1298 """
1297 1299
1298 1300 if timerange is not None:
1299 1301 self.timerange = timerange
1300 1302
1301 1303 tmin = None
1302 1304 tmax = None
1303 1305
1304 1306 x = dataOut.getTimeRange1(dataOut.outputInterval)
1305 1307 # y = dataOut.heightList
1306 1308 y = dataOut.heightList
1307 1309
1308 1310 z = dataOut.data_output
1309 1311 nplots = z.shape[0] #Number of wind dimensions estimated
1310 1312 nplotsw = nplots
1311 1313
1312 1314 #If there is a SNR function defined
1313 1315 if dataOut.data_SNR is not None:
1314 1316 nplots += 1
1315 1317 SNR = dataOut.data_SNR
1316 1318
1317 1319 if SNR_1:
1318 1320 SNR += 1
1319 1321
1320 1322 SNRavg = numpy.average(SNR, axis=0)
1321 1323
1322 1324 SNRdB = 10*numpy.log10(SNR)
1323 1325 SNRavgdB = 10*numpy.log10(SNRavg)
1324 1326
1325 1327 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1326 1328
1327 1329 for i in range(nplotsw):
1328 1330 z[i,ind] = numpy.nan
1329 1331
1330 1332
1331 1333 showprofile = False
1332 1334 # thisDatetime = dataOut.datatime
1333 1335 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1334 1336 title = wintitle + " EW Drifts"
1335 1337 xlabel = ""
1336 1338 ylabel = "Height (Km)"
1337 1339
1338 1340 if not self.isConfig:
1339 1341
1340 1342 self.setup(id=id,
1341 1343 nplots=nplots,
1342 1344 wintitle=wintitle,
1343 1345 showprofile=showprofile,
1344 1346 show=show)
1345 1347
1346 1348 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1347 1349
1348 1350 if ymin == None: ymin = numpy.nanmin(y)
1349 1351 if ymax == None: ymax = numpy.nanmax(y)
1350 1352
1351 1353 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1352 1354 if zminZonal == None: zminZonal = -zmaxZonal
1353 1355 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1354 1356 if zminVertical == None: zminVertical = -zmaxVertical
1355 1357
1356 1358 if dataOut.data_SNR is not None:
1357 1359 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1358 1360 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1359 1361
1360 1362 self.FTP_WEI = ftp_wei
1361 1363 self.EXP_CODE = exp_code
1362 1364 self.SUB_EXP_CODE = sub_exp_code
1363 1365 self.PLOT_POS = plot_pos
1364 1366
1365 1367 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1366 1368 self.isConfig = True
1367 1369
1368 1370
1369 1371 self.setWinTitle(title)
1370 1372
1371 1373 if ((self.xmax - x[1]) < (x[1]-x[0])):
1372 1374 x[1] = self.xmax
1373 1375
1374 1376 strWind = ['Zonal','Vertical']
1375 1377 strCb = 'Velocity (m/s)'
1376 1378 zmaxVector = [zmaxZonal, zmaxVertical]
1377 1379 zminVector = [zminZonal, zminVertical]
1378 1380
1379 1381 for i in range(nplotsw):
1380 1382
1381 1383 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1382 1384 axes = self.axesList[i*self.__nsubplots]
1383 1385
1384 1386 z1 = z[i,:].reshape((1,-1))
1385 1387
1386 1388 axes.pcolorbuffer(x, y, z1,
1387 1389 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1388 1390 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1389 1391 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1390 1392
1391 1393 if dataOut.data_SNR is not None:
1392 1394 i += 1
1393 1395 if SNR_1:
1394 1396 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1395 1397 else:
1396 1398 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1397 1399 axes = self.axesList[i*self.__nsubplots]
1398 1400 SNRavgdB = SNRavgdB.reshape((1,-1))
1399 1401
1400 1402 axes.pcolorbuffer(x, y, SNRavgdB,
1401 1403 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1402 1404 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1403 1405 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1404 1406
1405 1407 self.draw()
1406 1408
1407 1409 if x[1] >= self.axesList[0].xmax:
1408 1410 self.counter_imagwr = wr_period
1409 1411 self.isConfig = False
1410 1412 self.figfile = None
1411 1413
1412 1414
1413 1415
1414 1416
1415 1417 class PhasePlot(Figure):
1416 1418
1417 1419 __isConfig = None
1418 1420 __nsubplots = None
1419 1421
1420 1422 PREFIX = 'mphase'
1421 1423
1422 1424 def __init__(self):
1423 1425
1424 1426 self.timerange = 24*60*60
1425 1427 self.isConfig = False
1426 1428 self.__nsubplots = 1
1427 1429 self.counter_imagwr = 0
1428 1430 self.WIDTH = 600
1429 1431 self.HEIGHT = 300
1430 1432 self.WIDTHPROF = 120
1431 1433 self.HEIGHTPROF = 0
1432 1434 self.xdata = None
1433 1435 self.ydata = None
1434 1436
1435 1437 self.PLOT_CODE = MPHASE_CODE
1436 1438
1437 1439 self.FTP_WEI = None
1438 1440 self.EXP_CODE = None
1439 1441 self.SUB_EXP_CODE = None
1440 1442 self.PLOT_POS = None
1441 1443
1442 1444
1443 1445 self.filename_phase = None
1444 1446
1445 1447 self.figfile = None
1446 1448
1447 1449 def getSubplots(self):
1448 1450
1449 1451 ncol = 1
1450 1452 nrow = 1
1451 1453
1452 1454 return nrow, ncol
1453 1455
1454 1456 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1455 1457
1456 1458 self.__showprofile = showprofile
1457 1459 self.nplots = nplots
1458 1460
1459 1461 ncolspan = 7
1460 1462 colspan = 6
1461 1463 self.__nsubplots = 2
1462 1464
1463 1465 self.createFigure(id = id,
1464 1466 wintitle = wintitle,
1465 1467 widthplot = self.WIDTH+self.WIDTHPROF,
1466 1468 heightplot = self.HEIGHT+self.HEIGHTPROF,
1467 1469 show=show)
1468 1470
1469 1471 nrow, ncol = self.getSubplots()
1470 1472
1471 1473 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1472 1474
1473 1475
1474 1476 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1475 1477 xmin=None, xmax=None, ymin=None, ymax=None,
1476 1478 timerange=None,
1477 1479 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1478 1480 server=None, folder=None, username=None, password=None,
1479 1481 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1480 1482
1481 1483
1482 1484 tmin = None
1483 1485 tmax = None
1484 1486 x = dataOut.getTimeRange1(dataOut.outputInterval)
1485 1487 y = dataOut.getHeiRange()
1486 1488
1487 1489
1488 1490 #thisDatetime = dataOut.datatime
1489 1491 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1490 1492 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1491 1493 xlabel = "Local Time"
1492 1494 ylabel = "Phase"
1493 1495
1494 1496
1495 1497 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1496 1498 phase_beacon = dataOut.data_output
1497 1499 update_figfile = False
1498 1500
1499 1501 if not self.isConfig:
1500 1502
1501 1503 self.nplots = phase_beacon.size
1502 1504
1503 1505 self.setup(id=id,
1504 1506 nplots=self.nplots,
1505 1507 wintitle=wintitle,
1506 1508 showprofile=showprofile,
1507 1509 show=show)
1508 1510
1509 1511 if timerange is not None:
1510 1512 self.timerange = timerange
1511 1513
1512 1514 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1513 1515
1514 1516 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1515 1517 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1516 1518
1517 1519 self.FTP_WEI = ftp_wei
1518 1520 self.EXP_CODE = exp_code
1519 1521 self.SUB_EXP_CODE = sub_exp_code
1520 1522 self.PLOT_POS = plot_pos
1521 1523
1522 1524 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1523 1525 self.isConfig = True
1524 1526 self.figfile = figfile
1525 1527 self.xdata = numpy.array([])
1526 1528 self.ydata = numpy.array([])
1527 1529
1528 1530 #open file beacon phase
1529 1531 path = '%s%03d' %(self.PREFIX, self.id)
1530 1532 beacon_file = os.path.join(path,'%s.txt'%self.name)
1531 1533 self.filename_phase = os.path.join(figpath,beacon_file)
1532 1534 update_figfile = True
1533 1535
1534 1536
1535 1537 #store data beacon phase
1536 1538 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1537 1539
1538 1540 self.setWinTitle(title)
1539 1541
1540 1542
1541 1543 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1542 1544
1543 1545 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1544 1546
1545 1547 axes = self.axesList[0]
1546 1548
1547 1549 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1548 1550
1549 1551 if len(self.ydata)==0:
1550 1552 self.ydata = phase_beacon.reshape(-1,1)
1551 1553 else:
1552 1554 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1553 1555
1554 1556
1555 1557 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1556 1558 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1557 1559 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1558 1560 XAxisAsTime=True, grid='both'
1559 1561 )
1560 1562
1561 1563 self.draw()
1562 1564
1563 1565 self.save(figpath=figpath,
1564 1566 figfile=figfile,
1565 1567 save=save,
1566 1568 ftp=ftp,
1567 1569 wr_period=wr_period,
1568 1570 thisDatetime=thisDatetime,
1569 1571 update_figfile=update_figfile)
1570 1572
1571 1573 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1572 1574 self.counter_imagwr = wr_period
1573 1575 self.isConfig = False
1574 1576 update_figfile = True
1575 1577
1576 1578
1577 1579
1578 1580 class NSMeteorDetection1Plot(Figure):
1579 1581
1580 1582 isConfig = None
1581 1583 __nsubplots = None
1582 1584
1583 1585 WIDTHPROF = None
1584 1586 HEIGHTPROF = None
1585 1587 PREFIX = 'nsm'
1586 1588
1587 1589 zminList = None
1588 1590 zmaxList = None
1589 1591 cmapList = None
1590 1592 titleList = None
1591 1593 nPairs = None
1592 1594 nChannels = None
1593 1595 nParam = None
1594 1596
1595 1597 def __init__(self):
1596 1598
1597 1599 self.isConfig = False
1598 1600 self.__nsubplots = 1
1599 1601
1600 1602 self.WIDTH = 750
1601 1603 self.HEIGHT = 250
1602 1604 self.WIDTHPROF = 120
1603 1605 self.HEIGHTPROF = 0
1604 1606 self.counter_imagwr = 0
1605 1607
1606 1608 self.PLOT_CODE = SPEC_CODE
1607 1609
1608 1610 self.FTP_WEI = None
1609 1611 self.EXP_CODE = None
1610 1612 self.SUB_EXP_CODE = None
1611 1613 self.PLOT_POS = None
1612 1614
1613 1615 self.__xfilter_ena = False
1614 1616 self.__yfilter_ena = False
1615 1617
1616 1618 def getSubplots(self):
1617 1619
1618 1620 ncol = 3
1619 1621 nrow = int(numpy.ceil(self.nplots/3.0))
1620 1622
1621 1623 return nrow, ncol
1622 1624
1623 1625 def setup(self, id, nplots, wintitle, show=True):
1624 1626
1625 1627 self.nplots = nplots
1626 1628
1627 1629 ncolspan = 1
1628 1630 colspan = 1
1629 1631
1630 1632 self.createFigure(id = id,
1631 1633 wintitle = wintitle,
1632 1634 widthplot = self.WIDTH + self.WIDTHPROF,
1633 1635 heightplot = self.HEIGHT + self.HEIGHTPROF,
1634 1636 show=show)
1635 1637
1636 1638 nrow, ncol = self.getSubplots()
1637 1639
1638 1640 counter = 0
1639 1641 for y in range(nrow):
1640 1642 for x in range(ncol):
1641 1643
1642 1644 if counter >= self.nplots:
1643 1645 break
1644 1646
1645 1647 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1646 1648
1647 1649 counter += 1
1648 1650
1649 1651 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1650 1652 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1651 1653 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1652 1654 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1653 1655 server=None, folder=None, username=None, password=None,
1654 1656 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1655 1657 xaxis="frequency"):
1656 1658
1657 1659 """
1658 1660
1659 1661 Input:
1660 1662 dataOut :
1661 1663 id :
1662 1664 wintitle :
1663 1665 channelList :
1664 1666 showProfile :
1665 1667 xmin : None,
1666 1668 xmax : None,
1667 1669 ymin : None,
1668 1670 ymax : None,
1669 1671 zmin : None,
1670 1672 zmax : None
1671 1673 """
1672 1674 #SEPARAR EN DOS PLOTS
1673 1675 nParam = dataOut.data_param.shape[1] - 3
1674 1676
1675 1677 utctime = dataOut.data_param[0,0]
1676 1678 tmet = dataOut.data_param[:,1].astype(int)
1677 1679 hmet = dataOut.data_param[:,2].astype(int)
1678 1680
1679 1681 x = dataOut.abscissaList
1680 1682 y = dataOut.heightList
1681 1683
1682 1684 z = numpy.zeros((nParam, y.size, x.size - 1))
1683 1685 z[:,:] = numpy.nan
1684 1686 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1685 1687 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1686 1688
1687 1689 xlabel = "Time (s)"
1688 1690 ylabel = "Range (km)"
1689 1691
1690 1692 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1691 1693
1692 1694 if not self.isConfig:
1693 1695
1694 1696 nplots = nParam
1695 1697
1696 1698 self.setup(id=id,
1697 1699 nplots=nplots,
1698 1700 wintitle=wintitle,
1699 1701 show=show)
1700 1702
1701 1703 if xmin is None: xmin = numpy.nanmin(x)
1702 1704 if xmax is None: xmax = numpy.nanmax(x)
1703 1705 if ymin is None: ymin = numpy.nanmin(y)
1704 1706 if ymax is None: ymax = numpy.nanmax(y)
1705 1707 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1706 1708 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1707 1709 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1708 1710 if vmin is None: vmin = -vmax
1709 1711 if wmin is None: wmin = 0
1710 1712 if wmax is None: wmax = 50
1711 1713
1712 1714 pairsList = dataOut.groupList
1713 1715 self.nPairs = len(dataOut.groupList)
1714 1716
1715 1717 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1716 1718 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1717 1719 titleList = ["SNR","Radial Velocity","Coherence"]
1718 1720 cmapList = ["jet","RdBu_r","jet"]
1719 1721
1720 1722 for i in range(self.nPairs):
1721 1723 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1722 1724 titleList = titleList + [strAux1]
1723 1725 cmapList = cmapList + ["RdBu_r"]
1724 1726
1725 1727 self.zminList = zminList
1726 1728 self.zmaxList = zmaxList
1727 1729 self.cmapList = cmapList
1728 1730 self.titleList = titleList
1729 1731
1730 1732 self.FTP_WEI = ftp_wei
1731 1733 self.EXP_CODE = exp_code
1732 1734 self.SUB_EXP_CODE = sub_exp_code
1733 1735 self.PLOT_POS = plot_pos
1734 1736
1735 1737 self.isConfig = True
1736 1738
1737 1739 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1738 1740
1739 1741 for i in range(nParam):
1740 1742 title = self.titleList[i] + ": " +str_datetime
1741 1743 axes = self.axesList[i]
1742 1744 axes.pcolor(x, y, z[i,:].T,
1743 1745 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1744 1746 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1745 1747 self.draw()
1746 1748
1747 1749 if figfile == None:
1748 1750 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1749 1751 name = str_datetime
1750 1752 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1751 1753 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1752 1754 figfile = self.getFilename(name)
1753 1755
1754 1756 self.save(figpath=figpath,
1755 1757 figfile=figfile,
1756 1758 save=save,
1757 1759 ftp=ftp,
1758 1760 wr_period=wr_period,
1759 1761 thisDatetime=thisDatetime)
1760 1762
1761 1763
1762 1764 class NSMeteorDetection2Plot(Figure):
1763 1765
1764 1766 isConfig = None
1765 1767 __nsubplots = None
1766 1768
1767 1769 WIDTHPROF = None
1768 1770 HEIGHTPROF = None
1769 1771 PREFIX = 'nsm'
1770 1772
1771 1773 zminList = None
1772 1774 zmaxList = None
1773 1775 cmapList = None
1774 1776 titleList = None
1775 1777 nPairs = None
1776 1778 nChannels = None
1777 1779 nParam = None
1778 1780
1779 1781 def __init__(self):
1780 1782
1781 1783 self.isConfig = False
1782 1784 self.__nsubplots = 1
1783 1785
1784 1786 self.WIDTH = 750
1785 1787 self.HEIGHT = 250
1786 1788 self.WIDTHPROF = 120
1787 1789 self.HEIGHTPROF = 0
1788 1790 self.counter_imagwr = 0
1789 1791
1790 1792 self.PLOT_CODE = SPEC_CODE
1791 1793
1792 1794 self.FTP_WEI = None
1793 1795 self.EXP_CODE = None
1794 1796 self.SUB_EXP_CODE = None
1795 1797 self.PLOT_POS = None
1796 1798
1797 1799 self.__xfilter_ena = False
1798 1800 self.__yfilter_ena = False
1799 1801
1800 1802 def getSubplots(self):
1801 1803
1802 1804 ncol = 3
1803 1805 nrow = int(numpy.ceil(self.nplots/3.0))
1804 1806
1805 1807 return nrow, ncol
1806 1808
1807 1809 def setup(self, id, nplots, wintitle, show=True):
1808 1810
1809 1811 self.nplots = nplots
1810 1812
1811 1813 ncolspan = 1
1812 1814 colspan = 1
1813 1815
1814 1816 self.createFigure(id = id,
1815 1817 wintitle = wintitle,
1816 1818 widthplot = self.WIDTH + self.WIDTHPROF,
1817 1819 heightplot = self.HEIGHT + self.HEIGHTPROF,
1818 1820 show=show)
1819 1821
1820 1822 nrow, ncol = self.getSubplots()
1821 1823
1822 1824 counter = 0
1823 1825 for y in range(nrow):
1824 1826 for x in range(ncol):
1825 1827
1826 1828 if counter >= self.nplots:
1827 1829 break
1828 1830
1829 1831 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1830 1832
1831 1833 counter += 1
1832 1834
1833 1835 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1834 1836 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1835 1837 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1836 1838 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1837 1839 server=None, folder=None, username=None, password=None,
1838 1840 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1839 1841 xaxis="frequency"):
1840 1842
1841 1843 """
1842 1844
1843 1845 Input:
1844 1846 dataOut :
1845 1847 id :
1846 1848 wintitle :
1847 1849 channelList :
1848 1850 showProfile :
1849 1851 xmin : None,
1850 1852 xmax : None,
1851 1853 ymin : None,
1852 1854 ymax : None,
1853 1855 zmin : None,
1854 1856 zmax : None
1855 1857 """
1856 1858 #Rebuild matrix
1857 1859 utctime = dataOut.data_param[0,0]
1858 1860 cmet = dataOut.data_param[:,1].astype(int)
1859 1861 tmet = dataOut.data_param[:,2].astype(int)
1860 1862 hmet = dataOut.data_param[:,3].astype(int)
1861 1863
1862 1864 nParam = 3
1863 1865 nChan = len(dataOut.groupList)
1864 1866 x = dataOut.abscissaList
1865 1867 y = dataOut.heightList
1866 1868
1867 1869 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1868 1870 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1869 1871 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1870 1872 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1871 1873
1872 1874 xlabel = "Time (s)"
1873 1875 ylabel = "Range (km)"
1874 1876
1875 1877 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1876 1878
1877 1879 if not self.isConfig:
1878 1880
1879 1881 nplots = nParam*nChan
1880 1882
1881 1883 self.setup(id=id,
1882 1884 nplots=nplots,
1883 1885 wintitle=wintitle,
1884 1886 show=show)
1885 1887
1886 1888 if xmin is None: xmin = numpy.nanmin(x)
1887 1889 if xmax is None: xmax = numpy.nanmax(x)
1888 1890 if ymin is None: ymin = numpy.nanmin(y)
1889 1891 if ymax is None: ymax = numpy.nanmax(y)
1890 1892 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1891 1893 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1892 1894 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1893 1895 if vmin is None: vmin = -vmax
1894 1896 if wmin is None: wmin = 0
1895 1897 if wmax is None: wmax = 50
1896 1898
1897 1899 self.nChannels = nChan
1898 1900
1899 1901 zminList = []
1900 1902 zmaxList = []
1901 1903 titleList = []
1902 1904 cmapList = []
1903 1905 for i in range(self.nChannels):
1904 1906 strAux1 = "SNR Channel "+ str(i)
1905 1907 strAux2 = "Radial Velocity Channel "+ str(i)
1906 1908 strAux3 = "Spectral Width Channel "+ str(i)
1907 1909
1908 1910 titleList = titleList + [strAux1,strAux2,strAux3]
1909 1911 cmapList = cmapList + ["jet","RdBu_r","jet"]
1910 1912 zminList = zminList + [SNRmin,vmin,wmin]
1911 1913 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1912 1914
1913 1915 self.zminList = zminList
1914 1916 self.zmaxList = zmaxList
1915 1917 self.cmapList = cmapList
1916 1918 self.titleList = titleList
1917 1919
1918 1920 self.FTP_WEI = ftp_wei
1919 1921 self.EXP_CODE = exp_code
1920 1922 self.SUB_EXP_CODE = sub_exp_code
1921 1923 self.PLOT_POS = plot_pos
1922 1924
1923 1925 self.isConfig = True
1924 1926
1925 1927 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1926 1928
1927 1929 for i in range(self.nplots):
1928 1930 title = self.titleList[i] + ": " +str_datetime
1929 1931 axes = self.axesList[i]
1930 1932 axes.pcolor(x, y, z[i,:].T,
1931 1933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1932 1934 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1933 1935 self.draw()
1934 1936
1935 1937 if figfile == None:
1936 1938 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1937 1939 name = str_datetime
1938 1940 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1939 1941 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1940 1942 figfile = self.getFilename(name)
1941 1943
1942 1944 self.save(figpath=figpath,
1943 1945 figfile=figfile,
1944 1946 save=save,
1945 1947 ftp=ftp,
1946 1948 wr_period=wr_period,
1947 1949 thisDatetime=thisDatetime)
1948 1950
1949 1951
@@ -1,1527 +1,1530
1 1 '''
2 2 Created on Jul 9, 2014
3 3
4 4 @author: roj-idl71
5 5 '''
6 6 import os
7 7 import datetime
8 8 import numpy
9 9
10 10 from figure import Figure, isRealtime, isTimeInHourRange
11 11 from plotting_codes import *
12 12
13 13 class SpectraPlot(Figure):
14 14
15 15 isConfig = None
16 16 __nsubplots = None
17 17
18 18 WIDTHPROF = None
19 19 HEIGHTPROF = None
20 20 PREFIX = 'spc'
21 21
22 22 def __init__(self):
23 23
24 24 self.isConfig = False
25 25 self.__nsubplots = 1
26 26
27 27 self.WIDTH = 250
28 28 self.HEIGHT = 250
29 29 self.WIDTHPROF = 120
30 30 self.HEIGHTPROF = 0
31 31 self.counter_imagwr = 0
32 32
33 33 self.PLOT_CODE = SPEC_CODE
34 34
35 35 self.FTP_WEI = None
36 36 self.EXP_CODE = None
37 37 self.SUB_EXP_CODE = None
38 38 self.PLOT_POS = None
39 39
40 40 self.__xfilter_ena = False
41 41 self.__yfilter_ena = False
42 42
43 43 def getSubplots(self):
44 44
45 45 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 46 nrow = int(self.nplots*1./ncol + 0.9)
47 47
48 48 return nrow, ncol
49 49
50 50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51 51
52 52 self.__showprofile = showprofile
53 53 self.nplots = nplots
54 54
55 55 ncolspan = 1
56 56 colspan = 1
57 57 if showprofile:
58 58 ncolspan = 3
59 59 colspan = 2
60 60 self.__nsubplots = 2
61 61
62 62 self.createFigure(id = id,
63 63 wintitle = wintitle,
64 64 widthplot = self.WIDTH + self.WIDTHPROF,
65 65 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 66 show=show)
67 67
68 68 nrow, ncol = self.getSubplots()
69 69
70 70 counter = 0
71 71 for y in range(nrow):
72 72 for x in range(ncol):
73 73
74 74 if counter >= self.nplots:
75 75 break
76 76
77 77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78 78
79 79 if showprofile:
80 80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81 81
82 82 counter += 1
83 83
84 84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 85 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 87 server=None, folder=None, username=None, password=None,
88 88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 xaxis="frequency", colormap='jet'):
89 xaxis="velocity", **kwargs):
90 90
91 91 """
92 92
93 93 Input:
94 94 dataOut :
95 95 id :
96 96 wintitle :
97 97 channelList :
98 98 showProfile :
99 99 xmin : None,
100 100 xmax : None,
101 101 ymin : None,
102 102 ymax : None,
103 103 zmin : None,
104 104 zmax : None
105 105 """
106 106
107 colormap = kwargs.get('colormap','jet')
108
107 109 if realtime:
108 110 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 111 print 'Skipping this plot function'
110 112 return
111 113
112 114 if channelList == None:
113 115 channelIndexList = dataOut.channelIndexList
114 116 else:
115 117 channelIndexList = []
116 118 for channel in channelList:
117 119 if channel not in dataOut.channelList:
118 120 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
119 121 channelIndexList.append(dataOut.channelList.index(channel))
120 122
121 123 factor = dataOut.normFactor
122 124
123 125 if xaxis == "frequency":
124 126 x = dataOut.getFreqRange(1)/1000.
125 127 xlabel = "Frequency (kHz)"
126 128
127 129 elif xaxis == "time":
128 130 x = dataOut.getAcfRange(1)
129 131 xlabel = "Time (ms)"
130 132
131 133 else:
132 134 x = dataOut.getVelRange(1)
133 135 xlabel = "Velocity (m/s)"
134 136
135 137 ylabel = "Range (Km)"
136 138
137 139 y = dataOut.getHeiRange()
138 140
139 141 z = dataOut.data_spc/factor
140 142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
141 143 zdB = 10*numpy.log10(z)
142 144
143 145 avg = numpy.average(z, axis=1)
144 146 avgdB = 10*numpy.log10(avg)
145 147
146 148 noise = dataOut.getNoise()/factor
147 149 noisedB = 10*numpy.log10(noise)
148 150
149 151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
150 152 title = wintitle + " Spectra"
151 153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
152 154 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
153 155
154 156 if not self.isConfig:
155 157
156 158 nplots = len(channelIndexList)
157 159
158 160 self.setup(id=id,
159 161 nplots=nplots,
160 162 wintitle=wintitle,
161 163 showprofile=showprofile,
162 164 show=show)
163 165
164 166 if xmin == None: xmin = numpy.nanmin(x)
165 167 if xmax == None: xmax = numpy.nanmax(x)
166 168 if ymin == None: ymin = numpy.nanmin(y)
167 169 if ymax == None: ymax = numpy.nanmax(y)
168 170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
169 171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
170 172
171 173 self.FTP_WEI = ftp_wei
172 174 self.EXP_CODE = exp_code
173 175 self.SUB_EXP_CODE = sub_exp_code
174 176 self.PLOT_POS = plot_pos
175 177
176 178 self.isConfig = True
177 179
178 180 self.setWinTitle(title)
179 181
180 182 for i in range(self.nplots):
181 183 index = channelIndexList[i]
182 184 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
183 185 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
184 186 if len(dataOut.beam.codeList) != 0:
185 187 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
186 188
187 189 axes = self.axesList[i*self.__nsubplots]
188 190 axes.pcolor(x, y, zdB[index,:,:],
189 191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
190 192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
191 193 ticksize=9, cblabel='')
192 194
193 195 if self.__showprofile:
194 196 axes = self.axesList[i*self.__nsubplots +1]
195 197 axes.pline(avgdB[index,:], y,
196 198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
197 199 xlabel='dB', ylabel='', title='',
198 200 ytick_visible=False,
199 201 grid='x')
200 202
201 203 noiseline = numpy.repeat(noisedB[index], len(y))
202 204 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
203 205
204 206 self.draw()
205 207
206 208 if figfile == None:
207 209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
208 210 name = str_datetime
209 211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
210 212 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
211 213 figfile = self.getFilename(name)
212 214
213 215 self.save(figpath=figpath,
214 216 figfile=figfile,
215 217 save=save,
216 218 ftp=ftp,
217 219 wr_period=wr_period,
218 220 thisDatetime=thisDatetime)
219 221
220 222 class CrossSpectraPlot(Figure):
221 223
222 224 isConfig = None
223 225 __nsubplots = None
224 226
225 227 WIDTH = None
226 228 HEIGHT = None
227 229 WIDTHPROF = None
228 230 HEIGHTPROF = None
229 231 PREFIX = 'cspc'
230 232
231 233 def __init__(self):
232 234
233 235 self.isConfig = False
234 236 self.__nsubplots = 4
235 237 self.counter_imagwr = 0
236 238 self.WIDTH = 250
237 239 self.HEIGHT = 250
238 240 self.WIDTHPROF = 0
239 241 self.HEIGHTPROF = 0
240 242
241 243 self.PLOT_CODE = CROSS_CODE
242 244 self.FTP_WEI = None
243 245 self.EXP_CODE = None
244 246 self.SUB_EXP_CODE = None
245 247 self.PLOT_POS = None
246 248
247 249 def getSubplots(self):
248 250
249 251 ncol = 4
250 252 nrow = self.nplots
251 253
252 254 return nrow, ncol
253 255
254 256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255 257
256 258 self.__showprofile = showprofile
257 259 self.nplots = nplots
258 260
259 261 ncolspan = 1
260 262 colspan = 1
261 263
262 264 self.createFigure(id = id,
263 265 wintitle = wintitle,
264 266 widthplot = self.WIDTH + self.WIDTHPROF,
265 267 heightplot = self.HEIGHT + self.HEIGHTPROF,
266 268 show=True)
267 269
268 270 nrow, ncol = self.getSubplots()
269 271
270 272 counter = 0
271 273 for y in range(nrow):
272 274 for x in range(ncol):
273 275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
274 276
275 277 counter += 1
276 278
277 279 def run(self, dataOut, id, wintitle="", pairsList=None,
278 280 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
279 281 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
280 282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
281 283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
282 284 server=None, folder=None, username=None, password=None,
283 285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
284 286 xaxis='frequency'):
285 287
286 288 """
287 289
288 290 Input:
289 291 dataOut :
290 292 id :
291 293 wintitle :
292 294 channelList :
293 295 showProfile :
294 296 xmin : None,
295 297 xmax : None,
296 298 ymin : None,
297 299 ymax : None,
298 300 zmin : None,
299 301 zmax : None
300 302 """
301 303
302 304 if pairsList == None:
303 305 pairsIndexList = dataOut.pairsIndexList
304 306 else:
305 307 pairsIndexList = []
306 308 for pair in pairsList:
307 309 if pair not in dataOut.pairsList:
308 310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
309 311 pairsIndexList.append(dataOut.pairsList.index(pair))
310 312
311 313 if not pairsIndexList:
312 314 return
313 315
314 316 if len(pairsIndexList) > 4:
315 317 pairsIndexList = pairsIndexList[0:4]
316 318
317 319 factor = dataOut.normFactor
318 320 x = dataOut.getVelRange(1)
319 321 y = dataOut.getHeiRange()
320 322 z = dataOut.data_spc[:,:,:]/factor
321 323 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
322 324
323 325 noise = dataOut.noise/factor
324 326
325 327 zdB = 10*numpy.log10(z)
326 328 noisedB = 10*numpy.log10(noise)
327 329
328 330 if coh_min == None:
329 331 coh_min = 0.0
330 332 if coh_max == None:
331 333 coh_max = 1.0
332 334
333 335 if phase_min == None:
334 336 phase_min = -180
335 337 if phase_max == None:
336 338 phase_max = 180
337 339
338 340 #thisDatetime = dataOut.datatime
339 341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
340 342 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
341 343 # xlabel = "Velocity (m/s)"
342 344 ylabel = "Range (Km)"
343 345
344 346 if xaxis == "frequency":
345 347 x = dataOut.getFreqRange(1)/1000.
346 348 xlabel = "Frequency (kHz)"
347 349
348 350 elif xaxis == "time":
349 351 x = dataOut.getAcfRange(1)
350 352 xlabel = "Time (ms)"
351 353
352 354 else:
353 355 x = dataOut.getVelRange(1)
354 356 xlabel = "Velocity (m/s)"
355 357
356 358 if not self.isConfig:
357 359
358 360 nplots = len(pairsIndexList)
359 361
360 362 self.setup(id=id,
361 363 nplots=nplots,
362 364 wintitle=wintitle,
363 365 showprofile=False,
364 366 show=show)
365 367
366 368 avg = numpy.abs(numpy.average(z, axis=1))
367 369 avgdB = 10*numpy.log10(avg)
368 370
369 371 if xmin == None: xmin = numpy.nanmin(x)
370 372 if xmax == None: xmax = numpy.nanmax(x)
371 373 if ymin == None: ymin = numpy.nanmin(y)
372 374 if ymax == None: ymax = numpy.nanmax(y)
373 375 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
374 376 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
375 377
376 378 self.FTP_WEI = ftp_wei
377 379 self.EXP_CODE = exp_code
378 380 self.SUB_EXP_CODE = sub_exp_code
379 381 self.PLOT_POS = plot_pos
380 382
381 383 self.isConfig = True
382 384
383 385 self.setWinTitle(title)
384 386
385 387 for i in range(self.nplots):
386 388 pair = dataOut.pairsList[pairsIndexList[i]]
387 389
388 390 chan_index0 = dataOut.channelList.index(pair[0])
389 391 chan_index1 = dataOut.channelList.index(pair[1])
390 392
391 393 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
392 394 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
393 395 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
394 396 axes0 = self.axesList[i*self.__nsubplots]
395 397 axes0.pcolor(x, y, zdB,
396 398 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
397 399 xlabel=xlabel, ylabel=ylabel, title=title,
398 400 ticksize=9, colormap=power_cmap, cblabel='')
399 401
400 402 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
401 403 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
402 404 axes0 = self.axesList[i*self.__nsubplots+1]
403 405 axes0.pcolor(x, y, zdB,
404 406 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
405 407 xlabel=xlabel, ylabel=ylabel, title=title,
406 408 ticksize=9, colormap=power_cmap, cblabel='')
407 409
408 410 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
409 411 coherence = numpy.abs(coherenceComplex)
410 412 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
411 413 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
412 414
413 415 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
414 416 axes0 = self.axesList[i*self.__nsubplots+2]
415 417 axes0.pcolor(x, y, coherence,
416 418 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
417 419 xlabel=xlabel, ylabel=ylabel, title=title,
418 420 ticksize=9, colormap=coherence_cmap, cblabel='')
419 421
420 422 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
421 423 axes0 = self.axesList[i*self.__nsubplots+3]
422 424 axes0.pcolor(x, y, phase,
423 425 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
424 426 xlabel=xlabel, ylabel=ylabel, title=title,
425 427 ticksize=9, colormap=phase_cmap, cblabel='')
426 428
427 429
428 430
429 431 self.draw()
430 432
431 433 self.save(figpath=figpath,
432 434 figfile=figfile,
433 435 save=save,
434 436 ftp=ftp,
435 437 wr_period=wr_period,
436 438 thisDatetime=thisDatetime)
437 439
438 440
439 441 class RTIPlot(Figure):
440 442
441 443 __isConfig = None
442 444 __nsubplots = None
443 445
444 446 WIDTHPROF = None
445 447 HEIGHTPROF = None
446 448 PREFIX = 'rti'
447 449
448 450 def __init__(self):
449 451
450 452 self.timerange = None
451 453 self.isConfig = False
452 454 self.__nsubplots = 1
453 455
454 456 self.WIDTH = 800
455 457 self.HEIGHT = 180
456 458 self.WIDTHPROF = 120
457 459 self.HEIGHTPROF = 0
458 460 self.counter_imagwr = 0
459 461
460 462 self.PLOT_CODE = RTI_CODE
461 463
462 464 self.FTP_WEI = None
463 465 self.EXP_CODE = None
464 466 self.SUB_EXP_CODE = None
465 467 self.PLOT_POS = None
466 468 self.tmin = None
467 469 self.tmax = None
468 470
469 471 self.xmin = None
470 472 self.xmax = None
471 473
472 474 self.figfile = None
473 475
474 476 def getSubplots(self):
475 477
476 478 ncol = 1
477 479 nrow = self.nplots
478 480
479 481 return nrow, ncol
480 482
481 483 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
482 484
483 485 self.__showprofile = showprofile
484 486 self.nplots = nplots
485 487
486 488 ncolspan = 1
487 489 colspan = 1
488 490 if showprofile:
489 491 ncolspan = 7
490 492 colspan = 6
491 493 self.__nsubplots = 2
492 494
493 495 self.createFigure(id = id,
494 496 wintitle = wintitle,
495 497 widthplot = self.WIDTH + self.WIDTHPROF,
496 498 heightplot = self.HEIGHT + self.HEIGHTPROF,
497 499 show=show)
498 500
499 501 nrow, ncol = self.getSubplots()
500 502
501 503 counter = 0
502 504 for y in range(nrow):
503 505 for x in range(ncol):
504 506
505 507 if counter >= self.nplots:
506 508 break
507 509
508 510 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
509 511
510 512 if showprofile:
511 513 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
512 514
513 515 counter += 1
514 516
515 517 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
516 518 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
517 timerange=None, colormap='jet',
519 timerange=None,
518 520 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
519 521 server=None, folder=None, username=None, password=None,
520 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
522 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
521 523
522 524 """
523 525
524 526 Input:
525 527 dataOut :
526 528 id :
527 529 wintitle :
528 530 channelList :
529 531 showProfile :
530 532 xmin : None,
531 533 xmax : None,
532 534 ymin : None,
533 535 ymax : None,
534 536 zmin : None,
535 537 zmax : None
536 538 """
537 539
540 colormap = kwargs.get('colormap', 'jet')
538 541 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
539 542 return
540 543
541 544 if channelList == None:
542 545 channelIndexList = dataOut.channelIndexList
543 546 else:
544 547 channelIndexList = []
545 548 for channel in channelList:
546 549 if channel not in dataOut.channelList:
547 550 raise ValueError, "Channel %d is not in dataOut.channelList"
548 551 channelIndexList.append(dataOut.channelList.index(channel))
549 552
550 553 if hasattr(dataOut, 'normFactor'):
551 554 factor = dataOut.normFactor
552 555 else:
553 556 factor = 1
554 557
555 558 # factor = dataOut.normFactor
556 559 x = dataOut.getTimeRange()
557 560 y = dataOut.getHeiRange()
558 561
559 562 # z = dataOut.data_spc/factor
560 563 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
561 564 # avg = numpy.average(z, axis=1)
562 565 # avgdB = 10.*numpy.log10(avg)
563 566 avgdB = dataOut.getPower()
564 567
565 568 thisDatetime = dataOut.datatime
566 569 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
567 570 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
568 571 xlabel = ""
569 572 ylabel = "Range (Km)"
570 573
571 574 update_figfile = False
572 575
573 576 if dataOut.ltctime >= self.xmax:
574 577 self.counter_imagwr = wr_period
575 578 self.isConfig = False
576 579 update_figfile = True
577 580
578 581 if not self.isConfig:
579 582
580 583 nplots = len(channelIndexList)
581 584
582 585 self.setup(id=id,
583 586 nplots=nplots,
584 587 wintitle=wintitle,
585 588 showprofile=showprofile,
586 589 show=show)
587 590
588 591 if timerange != None:
589 592 self.timerange = timerange
590 593
591 594 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
592 595
593 596 noise = dataOut.noise/factor
594 597 noisedB = 10*numpy.log10(noise)
595 598
596 599 if ymin == None: ymin = numpy.nanmin(y)
597 600 if ymax == None: ymax = numpy.nanmax(y)
598 601 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
599 602 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
600 603
601 604 self.FTP_WEI = ftp_wei
602 605 self.EXP_CODE = exp_code
603 606 self.SUB_EXP_CODE = sub_exp_code
604 607 self.PLOT_POS = plot_pos
605 608
606 609 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
607 610 self.isConfig = True
608 611 self.figfile = figfile
609 612 update_figfile = True
610 613
611 614 self.setWinTitle(title)
612 615
613 616 for i in range(self.nplots):
614 617 index = channelIndexList[i]
615 618 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
616 619 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
617 620 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
618 621 axes = self.axesList[i*self.__nsubplots]
619 622 zdB = avgdB[index].reshape((1,-1))
620 623 axes.pcolorbuffer(x, y, zdB,
621 624 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
622 625 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
623 626 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
624 627
625 628 if self.__showprofile:
626 629 axes = self.axesList[i*self.__nsubplots +1]
627 630 axes.pline(avgdB[index], y,
628 631 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
629 632 xlabel='dB', ylabel='', title='',
630 633 ytick_visible=False,
631 634 grid='x')
632 635
633 636 self.draw()
634 637
635 638 self.save(figpath=figpath,
636 639 figfile=figfile,
637 640 save=save,
638 641 ftp=ftp,
639 642 wr_period=wr_period,
640 643 thisDatetime=thisDatetime,
641 644 update_figfile=update_figfile)
642 645
643 646 class CoherenceMap(Figure):
644 647 isConfig = None
645 648 __nsubplots = None
646 649
647 650 WIDTHPROF = None
648 651 HEIGHTPROF = None
649 652 PREFIX = 'cmap'
650 653
651 654 def __init__(self):
652 655 self.timerange = 2*60*60
653 656 self.isConfig = False
654 657 self.__nsubplots = 1
655 658
656 659 self.WIDTH = 800
657 660 self.HEIGHT = 180
658 661 self.WIDTHPROF = 120
659 662 self.HEIGHTPROF = 0
660 663 self.counter_imagwr = 0
661 664
662 665 self.PLOT_CODE = COH_CODE
663 666
664 667 self.FTP_WEI = None
665 668 self.EXP_CODE = None
666 669 self.SUB_EXP_CODE = None
667 670 self.PLOT_POS = None
668 671 self.counter_imagwr = 0
669 672
670 673 self.xmin = None
671 674 self.xmax = None
672 675
673 676 def getSubplots(self):
674 677 ncol = 1
675 678 nrow = self.nplots*2
676 679
677 680 return nrow, ncol
678 681
679 682 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
680 683 self.__showprofile = showprofile
681 684 self.nplots = nplots
682 685
683 686 ncolspan = 1
684 687 colspan = 1
685 688 if showprofile:
686 689 ncolspan = 7
687 690 colspan = 6
688 691 self.__nsubplots = 2
689 692
690 693 self.createFigure(id = id,
691 694 wintitle = wintitle,
692 695 widthplot = self.WIDTH + self.WIDTHPROF,
693 696 heightplot = self.HEIGHT + self.HEIGHTPROF,
694 697 show=True)
695 698
696 699 nrow, ncol = self.getSubplots()
697 700
698 701 for y in range(nrow):
699 702 for x in range(ncol):
700 703
701 704 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
702 705
703 706 if showprofile:
704 707 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
705 708
706 709 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
707 710 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
708 711 timerange=None, phase_min=None, phase_max=None,
709 712 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
710 713 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
711 714 server=None, folder=None, username=None, password=None,
712 715 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
713 716
714 717 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
715 718 return
716 719
717 720 if pairsList == None:
718 721 pairsIndexList = dataOut.pairsIndexList
719 722 else:
720 723 pairsIndexList = []
721 724 for pair in pairsList:
722 725 if pair not in dataOut.pairsList:
723 726 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
724 727 pairsIndexList.append(dataOut.pairsList.index(pair))
725 728
726 729 if pairsIndexList == []:
727 730 return
728 731
729 732 if len(pairsIndexList) > 4:
730 733 pairsIndexList = pairsIndexList[0:4]
731 734
732 735 if phase_min == None:
733 736 phase_min = -180
734 737 if phase_max == None:
735 738 phase_max = 180
736 739
737 740 x = dataOut.getTimeRange()
738 741 y = dataOut.getHeiRange()
739 742
740 743 thisDatetime = dataOut.datatime
741 744
742 745 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
743 746 xlabel = ""
744 747 ylabel = "Range (Km)"
745 748 update_figfile = False
746 749
747 750 if not self.isConfig:
748 751 nplots = len(pairsIndexList)
749 752 self.setup(id=id,
750 753 nplots=nplots,
751 754 wintitle=wintitle,
752 755 showprofile=showprofile,
753 756 show=show)
754 757
755 758 if timerange != None:
756 759 self.timerange = timerange
757 760
758 761 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
759 762
760 763 if ymin == None: ymin = numpy.nanmin(y)
761 764 if ymax == None: ymax = numpy.nanmax(y)
762 765 if zmin == None: zmin = 0.
763 766 if zmax == None: zmax = 1.
764 767
765 768 self.FTP_WEI = ftp_wei
766 769 self.EXP_CODE = exp_code
767 770 self.SUB_EXP_CODE = sub_exp_code
768 771 self.PLOT_POS = plot_pos
769 772
770 773 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
771 774
772 775 self.isConfig = True
773 776 update_figfile = True
774 777
775 778 self.setWinTitle(title)
776 779
777 780 for i in range(self.nplots):
778 781
779 782 pair = dataOut.pairsList[pairsIndexList[i]]
780 783
781 784 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
782 785 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
783 786 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
784 787
785 788
786 789 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
787 790 coherence = numpy.abs(avgcoherenceComplex)
788 791
789 792 z = coherence.reshape((1,-1))
790 793
791 794 counter = 0
792 795
793 796 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
794 797 axes = self.axesList[i*self.__nsubplots*2]
795 798 axes.pcolorbuffer(x, y, z,
796 799 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
797 800 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
798 801 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
799 802
800 803 if self.__showprofile:
801 804 counter += 1
802 805 axes = self.axesList[i*self.__nsubplots*2 + counter]
803 806 axes.pline(coherence, y,
804 807 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
805 808 xlabel='', ylabel='', title='', ticksize=7,
806 809 ytick_visible=False, nxticks=5,
807 810 grid='x')
808 811
809 812 counter += 1
810 813
811 814 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
812 815
813 816 z = phase.reshape((1,-1))
814 817
815 818 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
816 819 axes = self.axesList[i*self.__nsubplots*2 + counter]
817 820 axes.pcolorbuffer(x, y, z,
818 821 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
819 822 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
820 823 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
821 824
822 825 if self.__showprofile:
823 826 counter += 1
824 827 axes = self.axesList[i*self.__nsubplots*2 + counter]
825 828 axes.pline(phase, y,
826 829 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
827 830 xlabel='', ylabel='', title='', ticksize=7,
828 831 ytick_visible=False, nxticks=4,
829 832 grid='x')
830 833
831 834 self.draw()
832 835
833 836 if dataOut.ltctime >= self.xmax:
834 837 self.counter_imagwr = wr_period
835 838 self.isConfig = False
836 839 update_figfile = True
837 840
838 841 self.save(figpath=figpath,
839 842 figfile=figfile,
840 843 save=save,
841 844 ftp=ftp,
842 845 wr_period=wr_period,
843 846 thisDatetime=thisDatetime,
844 847 update_figfile=update_figfile)
845 848
846 849 class PowerProfilePlot(Figure):
847 850
848 851 isConfig = None
849 852 __nsubplots = None
850 853
851 854 WIDTHPROF = None
852 855 HEIGHTPROF = None
853 856 PREFIX = 'spcprofile'
854 857
855 858 def __init__(self):
856 859 self.isConfig = False
857 860 self.__nsubplots = 1
858 861
859 862 self.PLOT_CODE = POWER_CODE
860 863
861 864 self.WIDTH = 300
862 865 self.HEIGHT = 500
863 866 self.counter_imagwr = 0
864 867
865 868 def getSubplots(self):
866 869 ncol = 1
867 870 nrow = 1
868 871
869 872 return nrow, ncol
870 873
871 874 def setup(self, id, nplots, wintitle, show):
872 875
873 876 self.nplots = nplots
874 877
875 878 ncolspan = 1
876 879 colspan = 1
877 880
878 881 self.createFigure(id = id,
879 882 wintitle = wintitle,
880 883 widthplot = self.WIDTH,
881 884 heightplot = self.HEIGHT,
882 885 show=show)
883 886
884 887 nrow, ncol = self.getSubplots()
885 888
886 889 counter = 0
887 890 for y in range(nrow):
888 891 for x in range(ncol):
889 892 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
890 893
891 894 def run(self, dataOut, id, wintitle="", channelList=None,
892 895 xmin=None, xmax=None, ymin=None, ymax=None,
893 896 save=False, figpath='./', figfile=None, show=True,
894 897 ftp=False, wr_period=1, server=None,
895 898 folder=None, username=None, password=None):
896 899
897 900
898 901 if channelList == None:
899 902 channelIndexList = dataOut.channelIndexList
900 903 channelList = dataOut.channelList
901 904 else:
902 905 channelIndexList = []
903 906 for channel in channelList:
904 907 if channel not in dataOut.channelList:
905 908 raise ValueError, "Channel %d is not in dataOut.channelList"
906 909 channelIndexList.append(dataOut.channelList.index(channel))
907 910
908 911 factor = dataOut.normFactor
909 912
910 913 y = dataOut.getHeiRange()
911 914
912 915 #for voltage
913 916 if dataOut.type == 'Voltage':
914 917 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
915 918 x = x.real
916 919 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
917 920
918 921 #for spectra
919 922 if dataOut.type == 'Spectra':
920 923 x = dataOut.data_spc[channelIndexList,:,:]/factor
921 924 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
922 925 x = numpy.average(x, axis=1)
923 926
924 927
925 928 xdB = 10*numpy.log10(x)
926 929
927 930 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
928 931 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
929 932 xlabel = "dB"
930 933 ylabel = "Range (Km)"
931 934
932 935 if not self.isConfig:
933 936
934 937 nplots = 1
935 938
936 939 self.setup(id=id,
937 940 nplots=nplots,
938 941 wintitle=wintitle,
939 942 show=show)
940 943
941 944 if ymin == None: ymin = numpy.nanmin(y)
942 945 if ymax == None: ymax = numpy.nanmax(y)
943 946 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
944 947 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
945 948
946 949 self.isConfig = True
947 950
948 951 self.setWinTitle(title)
949 952
950 953 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
951 954 axes = self.axesList[0]
952 955
953 956 legendlabels = ["channel %d"%x for x in channelList]
954 957 axes.pmultiline(xdB, y,
955 958 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
956 959 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
957 960 ytick_visible=True, nxticks=5,
958 961 grid='x')
959 962
960 963 self.draw()
961 964
962 965 self.save(figpath=figpath,
963 966 figfile=figfile,
964 967 save=save,
965 968 ftp=ftp,
966 969 wr_period=wr_period,
967 970 thisDatetime=thisDatetime)
968 971
969 972 class SpectraCutPlot(Figure):
970 973
971 974 isConfig = None
972 975 __nsubplots = None
973 976
974 977 WIDTHPROF = None
975 978 HEIGHTPROF = None
976 979 PREFIX = 'spc_cut'
977 980
978 981 def __init__(self):
979 982 self.isConfig = False
980 983 self.__nsubplots = 1
981 984
982 985 self.PLOT_CODE = POWER_CODE
983 986
984 987 self.WIDTH = 700
985 988 self.HEIGHT = 500
986 989 self.counter_imagwr = 0
987 990
988 991 def getSubplots(self):
989 992 ncol = 1
990 993 nrow = 1
991 994
992 995 return nrow, ncol
993 996
994 997 def setup(self, id, nplots, wintitle, show):
995 998
996 999 self.nplots = nplots
997 1000
998 1001 ncolspan = 1
999 1002 colspan = 1
1000 1003
1001 1004 self.createFigure(id = id,
1002 1005 wintitle = wintitle,
1003 1006 widthplot = self.WIDTH,
1004 1007 heightplot = self.HEIGHT,
1005 1008 show=show)
1006 1009
1007 1010 nrow, ncol = self.getSubplots()
1008 1011
1009 1012 counter = 0
1010 1013 for y in range(nrow):
1011 1014 for x in range(ncol):
1012 1015 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1013 1016
1014 1017 def run(self, dataOut, id, wintitle="", channelList=None,
1015 1018 xmin=None, xmax=None, ymin=None, ymax=None,
1016 1019 save=False, figpath='./', figfile=None, show=True,
1017 1020 ftp=False, wr_period=1, server=None,
1018 1021 folder=None, username=None, password=None,
1019 1022 xaxis="frequency"):
1020 1023
1021 1024
1022 1025 if channelList == None:
1023 1026 channelIndexList = dataOut.channelIndexList
1024 1027 channelList = dataOut.channelList
1025 1028 else:
1026 1029 channelIndexList = []
1027 1030 for channel in channelList:
1028 1031 if channel not in dataOut.channelList:
1029 1032 raise ValueError, "Channel %d is not in dataOut.channelList"
1030 1033 channelIndexList.append(dataOut.channelList.index(channel))
1031 1034
1032 1035 factor = dataOut.normFactor
1033 1036
1034 1037 y = dataOut.getHeiRange()
1035 1038
1036 1039 z = dataOut.data_spc/factor
1037 1040 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1038 1041
1039 1042 hei_index = numpy.arange(25)*3 + 20
1040 1043
1041 1044 if xaxis == "frequency":
1042 1045 x = dataOut.getFreqRange()/1000.
1043 1046 zdB = 10*numpy.log10(z[0,:,hei_index])
1044 1047 xlabel = "Frequency (kHz)"
1045 1048 ylabel = "Power (dB)"
1046 1049
1047 1050 elif xaxis == "time":
1048 1051 x = dataOut.getAcfRange()
1049 1052 zdB = z[0,:,hei_index]
1050 1053 xlabel = "Time (ms)"
1051 1054 ylabel = "ACF"
1052 1055
1053 1056 else:
1054 1057 x = dataOut.getVelRange()
1055 1058 zdB = 10*numpy.log10(z[0,:,hei_index])
1056 1059 xlabel = "Velocity (m/s)"
1057 1060 ylabel = "Power (dB)"
1058 1061
1059 1062 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1060 1063 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1061 1064
1062 1065 if not self.isConfig:
1063 1066
1064 1067 nplots = 1
1065 1068
1066 1069 self.setup(id=id,
1067 1070 nplots=nplots,
1068 1071 wintitle=wintitle,
1069 1072 show=show)
1070 1073
1071 1074 if xmin == None: xmin = numpy.nanmin(x)*0.9
1072 1075 if xmax == None: xmax = numpy.nanmax(x)*1.1
1073 1076 if ymin == None: ymin = numpy.nanmin(zdB)
1074 1077 if ymax == None: ymax = numpy.nanmax(zdB)
1075 1078
1076 1079 self.isConfig = True
1077 1080
1078 1081 self.setWinTitle(title)
1079 1082
1080 1083 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1081 1084 axes = self.axesList[0]
1082 1085
1083 1086 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1084 1087
1085 1088 axes.pmultilineyaxis( x, zdB,
1086 1089 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1087 1090 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1088 1091 ytick_visible=True, nxticks=5,
1089 1092 grid='x')
1090 1093
1091 1094 self.draw()
1092 1095
1093 1096 self.save(figpath=figpath,
1094 1097 figfile=figfile,
1095 1098 save=save,
1096 1099 ftp=ftp,
1097 1100 wr_period=wr_period,
1098 1101 thisDatetime=thisDatetime)
1099 1102
1100 1103 class Noise(Figure):
1101 1104
1102 1105 isConfig = None
1103 1106 __nsubplots = None
1104 1107
1105 1108 PREFIX = 'noise'
1106 1109
1107 1110 def __init__(self):
1108 1111
1109 1112 self.timerange = 24*60*60
1110 1113 self.isConfig = False
1111 1114 self.__nsubplots = 1
1112 1115 self.counter_imagwr = 0
1113 1116 self.WIDTH = 800
1114 1117 self.HEIGHT = 400
1115 1118 self.WIDTHPROF = 120
1116 1119 self.HEIGHTPROF = 0
1117 1120 self.xdata = None
1118 1121 self.ydata = None
1119 1122
1120 1123 self.PLOT_CODE = NOISE_CODE
1121 1124
1122 1125 self.FTP_WEI = None
1123 1126 self.EXP_CODE = None
1124 1127 self.SUB_EXP_CODE = None
1125 1128 self.PLOT_POS = None
1126 1129 self.figfile = None
1127 1130
1128 1131 self.xmin = None
1129 1132 self.xmax = None
1130 1133
1131 1134 def getSubplots(self):
1132 1135
1133 1136 ncol = 1
1134 1137 nrow = 1
1135 1138
1136 1139 return nrow, ncol
1137 1140
1138 1141 def openfile(self, filename):
1139 1142 dirname = os.path.dirname(filename)
1140 1143
1141 1144 if not os.path.exists(dirname):
1142 1145 os.mkdir(dirname)
1143 1146
1144 1147 f = open(filename,'w+')
1145 1148 f.write('\n\n')
1146 1149 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1147 1150 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1148 1151 f.close()
1149 1152
1150 1153 def save_data(self, filename_phase, data, data_datetime):
1151 1154
1152 1155 f=open(filename_phase,'a')
1153 1156
1154 1157 timetuple_data = data_datetime.timetuple()
1155 1158 day = str(timetuple_data.tm_mday)
1156 1159 month = str(timetuple_data.tm_mon)
1157 1160 year = str(timetuple_data.tm_year)
1158 1161 hour = str(timetuple_data.tm_hour)
1159 1162 minute = str(timetuple_data.tm_min)
1160 1163 second = str(timetuple_data.tm_sec)
1161 1164
1162 1165 data_msg = ''
1163 1166 for i in range(len(data)):
1164 1167 data_msg += str(data[i]) + ' '
1165 1168
1166 1169 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1167 1170 f.close()
1168 1171
1169 1172
1170 1173 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1171 1174
1172 1175 self.__showprofile = showprofile
1173 1176 self.nplots = nplots
1174 1177
1175 1178 ncolspan = 7
1176 1179 colspan = 6
1177 1180 self.__nsubplots = 2
1178 1181
1179 1182 self.createFigure(id = id,
1180 1183 wintitle = wintitle,
1181 1184 widthplot = self.WIDTH+self.WIDTHPROF,
1182 1185 heightplot = self.HEIGHT+self.HEIGHTPROF,
1183 1186 show=show)
1184 1187
1185 1188 nrow, ncol = self.getSubplots()
1186 1189
1187 1190 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1188 1191
1189 1192
1190 1193 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1191 1194 xmin=None, xmax=None, ymin=None, ymax=None,
1192 1195 timerange=None,
1193 1196 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1194 1197 server=None, folder=None, username=None, password=None,
1195 1198 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1196 1199
1197 1200 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1198 1201 return
1199 1202
1200 1203 if channelList == None:
1201 1204 channelIndexList = dataOut.channelIndexList
1202 1205 channelList = dataOut.channelList
1203 1206 else:
1204 1207 channelIndexList = []
1205 1208 for channel in channelList:
1206 1209 if channel not in dataOut.channelList:
1207 1210 raise ValueError, "Channel %d is not in dataOut.channelList"
1208 1211 channelIndexList.append(dataOut.channelList.index(channel))
1209 1212
1210 1213 x = dataOut.getTimeRange()
1211 1214 #y = dataOut.getHeiRange()
1212 1215 factor = dataOut.normFactor
1213 1216 noise = dataOut.noise[channelIndexList]/factor
1214 1217 noisedB = 10*numpy.log10(noise)
1215 1218
1216 1219 thisDatetime = dataOut.datatime
1217 1220
1218 1221 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1219 1222 xlabel = ""
1220 1223 ylabel = "Intensity (dB)"
1221 1224 update_figfile = False
1222 1225
1223 1226 if not self.isConfig:
1224 1227
1225 1228 nplots = 1
1226 1229
1227 1230 self.setup(id=id,
1228 1231 nplots=nplots,
1229 1232 wintitle=wintitle,
1230 1233 showprofile=showprofile,
1231 1234 show=show)
1232 1235
1233 1236 if timerange != None:
1234 1237 self.timerange = timerange
1235 1238
1236 1239 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1237 1240
1238 1241 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1239 1242 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1240 1243
1241 1244 self.FTP_WEI = ftp_wei
1242 1245 self.EXP_CODE = exp_code
1243 1246 self.SUB_EXP_CODE = sub_exp_code
1244 1247 self.PLOT_POS = plot_pos
1245 1248
1246 1249
1247 1250 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1248 1251 self.isConfig = True
1249 1252 self.figfile = figfile
1250 1253 self.xdata = numpy.array([])
1251 1254 self.ydata = numpy.array([])
1252 1255
1253 1256 update_figfile = True
1254 1257
1255 1258 #open file beacon phase
1256 1259 path = '%s%03d' %(self.PREFIX, self.id)
1257 1260 noise_file = os.path.join(path,'%s.txt'%self.name)
1258 1261 self.filename_noise = os.path.join(figpath,noise_file)
1259 1262
1260 1263 self.setWinTitle(title)
1261 1264
1262 1265 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1263 1266
1264 1267 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1265 1268 axes = self.axesList[0]
1266 1269
1267 1270 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1268 1271
1269 1272 if len(self.ydata)==0:
1270 1273 self.ydata = noisedB.reshape(-1,1)
1271 1274 else:
1272 1275 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1273 1276
1274 1277
1275 1278 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1276 1279 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1277 1280 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1278 1281 XAxisAsTime=True, grid='both'
1279 1282 )
1280 1283
1281 1284 self.draw()
1282 1285
1283 1286 if dataOut.ltctime >= self.xmax:
1284 1287 self.counter_imagwr = wr_period
1285 1288 self.isConfig = False
1286 1289 update_figfile = True
1287 1290
1288 1291 self.save(figpath=figpath,
1289 1292 figfile=figfile,
1290 1293 save=save,
1291 1294 ftp=ftp,
1292 1295 wr_period=wr_period,
1293 1296 thisDatetime=thisDatetime,
1294 1297 update_figfile=update_figfile)
1295 1298
1296 1299 #store data beacon phase
1297 1300 if save:
1298 1301 self.save_data(self.filename_noise, noisedB, thisDatetime)
1299 1302
1300 1303 class BeaconPhase(Figure):
1301 1304
1302 1305 __isConfig = None
1303 1306 __nsubplots = None
1304 1307
1305 1308 PREFIX = 'beacon_phase'
1306 1309
1307 1310 def __init__(self):
1308 1311
1309 1312 self.timerange = 24*60*60
1310 1313 self.isConfig = False
1311 1314 self.__nsubplots = 1
1312 1315 self.counter_imagwr = 0
1313 1316 self.WIDTH = 800
1314 1317 self.HEIGHT = 400
1315 1318 self.WIDTHPROF = 120
1316 1319 self.HEIGHTPROF = 0
1317 1320 self.xdata = None
1318 1321 self.ydata = None
1319 1322
1320 1323 self.PLOT_CODE = BEACON_CODE
1321 1324
1322 1325 self.FTP_WEI = None
1323 1326 self.EXP_CODE = None
1324 1327 self.SUB_EXP_CODE = None
1325 1328 self.PLOT_POS = None
1326 1329
1327 1330 self.filename_phase = None
1328 1331
1329 1332 self.figfile = None
1330 1333
1331 1334 self.xmin = None
1332 1335 self.xmax = None
1333 1336
1334 1337 def getSubplots(self):
1335 1338
1336 1339 ncol = 1
1337 1340 nrow = 1
1338 1341
1339 1342 return nrow, ncol
1340 1343
1341 1344 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1342 1345
1343 1346 self.__showprofile = showprofile
1344 1347 self.nplots = nplots
1345 1348
1346 1349 ncolspan = 7
1347 1350 colspan = 6
1348 1351 self.__nsubplots = 2
1349 1352
1350 1353 self.createFigure(id = id,
1351 1354 wintitle = wintitle,
1352 1355 widthplot = self.WIDTH+self.WIDTHPROF,
1353 1356 heightplot = self.HEIGHT+self.HEIGHTPROF,
1354 1357 show=show)
1355 1358
1356 1359 nrow, ncol = self.getSubplots()
1357 1360
1358 1361 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1359 1362
1360 1363 def save_phase(self, filename_phase):
1361 1364 f = open(filename_phase,'w+')
1362 1365 f.write('\n\n')
1363 1366 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1364 1367 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1365 1368 f.close()
1366 1369
1367 1370 def save_data(self, filename_phase, data, data_datetime):
1368 1371 f=open(filename_phase,'a')
1369 1372 timetuple_data = data_datetime.timetuple()
1370 1373 day = str(timetuple_data.tm_mday)
1371 1374 month = str(timetuple_data.tm_mon)
1372 1375 year = str(timetuple_data.tm_year)
1373 1376 hour = str(timetuple_data.tm_hour)
1374 1377 minute = str(timetuple_data.tm_min)
1375 1378 second = str(timetuple_data.tm_sec)
1376 1379 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1377 1380 f.close()
1378 1381
1379 1382
1380 1383 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1381 1384 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1382 1385 timerange=None,
1383 1386 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1384 1387 server=None, folder=None, username=None, password=None,
1385 1388 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1386 1389
1387 1390 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1388 1391 return
1389 1392
1390 1393 if pairsList == None:
1391 1394 pairsIndexList = dataOut.pairsIndexList[:10]
1392 1395 else:
1393 1396 pairsIndexList = []
1394 1397 for pair in pairsList:
1395 1398 if pair not in dataOut.pairsList:
1396 1399 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1397 1400 pairsIndexList.append(dataOut.pairsList.index(pair))
1398 1401
1399 1402 if pairsIndexList == []:
1400 1403 return
1401 1404
1402 1405 # if len(pairsIndexList) > 4:
1403 1406 # pairsIndexList = pairsIndexList[0:4]
1404 1407
1405 1408 hmin_index = None
1406 1409 hmax_index = None
1407 1410
1408 1411 if hmin != None and hmax != None:
1409 1412 indexes = numpy.arange(dataOut.nHeights)
1410 1413 hmin_list = indexes[dataOut.heightList >= hmin]
1411 1414 hmax_list = indexes[dataOut.heightList <= hmax]
1412 1415
1413 1416 if hmin_list.any():
1414 1417 hmin_index = hmin_list[0]
1415 1418
1416 1419 if hmax_list.any():
1417 1420 hmax_index = hmax_list[-1]+1
1418 1421
1419 1422 x = dataOut.getTimeRange()
1420 1423 #y = dataOut.getHeiRange()
1421 1424
1422 1425
1423 1426 thisDatetime = dataOut.datatime
1424 1427
1425 1428 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1426 1429 xlabel = "Local Time"
1427 1430 ylabel = "Phase (degrees)"
1428 1431
1429 1432 update_figfile = False
1430 1433
1431 1434 nplots = len(pairsIndexList)
1432 1435 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1433 1436 phase_beacon = numpy.zeros(len(pairsIndexList))
1434 1437 for i in range(nplots):
1435 1438 pair = dataOut.pairsList[pairsIndexList[i]]
1436 1439 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1437 1440 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1438 1441 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1439 1442 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1440 1443 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1441 1444
1442 1445 #print "Phase %d%d" %(pair[0], pair[1])
1443 1446 #print phase[dataOut.beacon_heiIndexList]
1444 1447
1445 1448 if dataOut.beacon_heiIndexList:
1446 1449 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1447 1450 else:
1448 1451 phase_beacon[i] = numpy.average(phase)
1449 1452
1450 1453 if not self.isConfig:
1451 1454
1452 1455 nplots = len(pairsIndexList)
1453 1456
1454 1457 self.setup(id=id,
1455 1458 nplots=nplots,
1456 1459 wintitle=wintitle,
1457 1460 showprofile=showprofile,
1458 1461 show=show)
1459 1462
1460 1463 if timerange != None:
1461 1464 self.timerange = timerange
1462 1465
1463 1466 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1464 1467
1465 1468 if ymin == None: ymin = 0
1466 1469 if ymax == None: ymax = 360
1467 1470
1468 1471 self.FTP_WEI = ftp_wei
1469 1472 self.EXP_CODE = exp_code
1470 1473 self.SUB_EXP_CODE = sub_exp_code
1471 1474 self.PLOT_POS = plot_pos
1472 1475
1473 1476 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1474 1477 self.isConfig = True
1475 1478 self.figfile = figfile
1476 1479 self.xdata = numpy.array([])
1477 1480 self.ydata = numpy.array([])
1478 1481
1479 1482 update_figfile = True
1480 1483
1481 1484 #open file beacon phase
1482 1485 path = '%s%03d' %(self.PREFIX, self.id)
1483 1486 beacon_file = os.path.join(path,'%s.txt'%self.name)
1484 1487 self.filename_phase = os.path.join(figpath,beacon_file)
1485 1488 #self.save_phase(self.filename_phase)
1486 1489
1487 1490
1488 1491 #store data beacon phase
1489 1492 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1490 1493
1491 1494 self.setWinTitle(title)
1492 1495
1493 1496
1494 1497 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1495 1498
1496 1499 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1497 1500
1498 1501 axes = self.axesList[0]
1499 1502
1500 1503 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1501 1504
1502 1505 if len(self.ydata)==0:
1503 1506 self.ydata = phase_beacon.reshape(-1,1)
1504 1507 else:
1505 1508 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1506 1509
1507 1510
1508 1511 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1509 1512 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1510 1513 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1511 1514 XAxisAsTime=True, grid='both'
1512 1515 )
1513 1516
1514 1517 self.draw()
1515 1518
1516 1519 if dataOut.ltctime >= self.xmax:
1517 1520 self.counter_imagwr = wr_period
1518 1521 self.isConfig = False
1519 1522 update_figfile = True
1520 1523
1521 1524 self.save(figpath=figpath,
1522 1525 figfile=figfile,
1523 1526 save=save,
1524 1527 ftp=ftp,
1525 1528 wr_period=wr_period,
1526 1529 thisDatetime=thisDatetime,
1527 1530 update_figfile=update_figfile)
@@ -1,466 +1,468
1 1 import numpy
2 2 import datetime
3 3 import sys
4 4 import matplotlib
5 5
6 6 if 'linux' in sys.platform:
7 7 matplotlib.use("TKAgg")
8 8
9 9 if 'darwin' in sys.platform:
10 10 matplotlib.use('TKAgg')
11 11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 12 import matplotlib.pyplot
13 13
14 14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 15 from matplotlib.ticker import FuncFormatter, LinearLocator
16 16
17 17 ###########################################
18 18 #Actualizacion de las funciones del driver
19 19 ###########################################
20 20
21 # create jro colormap
22
21 23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
22 24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
23 25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
24 26 matplotlib.pyplot.register_cmap(cmap=ncmap)
25 27
26 28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
27 29
28 30 matplotlib.pyplot.ioff()
29 31
30 32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
31 33 fig.canvas.manager.set_window_title(wintitle)
32 34 # fig.canvas.manager.resize(width, height)
33 35 matplotlib.pyplot.ion()
34 36
35 37 if show:
36 38 matplotlib.pyplot.show()
37 39
38 40 return fig
39 41
40 42 def closeFigure(show=False, fig=None):
41 43
42 44 # matplotlib.pyplot.ioff()
43 45 # matplotlib.pyplot.pause(0)
44 46
45 47 if show:
46 48 matplotlib.pyplot.show()
47 49
48 50 if fig != None:
49 51 matplotlib.pyplot.close(fig)
50 52 # matplotlib.pyplot.pause(0)
51 53 # matplotlib.pyplot.ion()
52 54
53 55 return
54 56
55 57 matplotlib.pyplot.close("all")
56 58 # matplotlib.pyplot.pause(0)
57 59 # matplotlib.pyplot.ion()
58 60
59 61 return
60 62
61 63 def saveFigure(fig, filename):
62 64
63 65 # matplotlib.pyplot.ioff()
64 66 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
65 67 # matplotlib.pyplot.ion()
66 68
67 69 def clearFigure(fig):
68 70
69 71 fig.clf()
70 72
71 73 def setWinTitle(fig, title):
72 74
73 75 fig.canvas.manager.set_window_title(title)
74 76
75 77 def setTitle(fig, title):
76 78
77 79 fig.suptitle(title)
78 80
79 81 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
80 82
81 83 matplotlib.pyplot.ioff()
82 84 matplotlib.pyplot.figure(fig.number)
83 85 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
84 86 (xpos, ypos),
85 87 colspan=colspan,
86 88 rowspan=rowspan,
87 89 polar=polar)
88 90
89 91 matplotlib.pyplot.ion()
90 92 return axes
91 93
92 94 def setAxesText(ax, text):
93 95
94 96 ax.annotate(text,
95 97 xy = (.1, .99),
96 98 xycoords = 'figure fraction',
97 99 horizontalalignment = 'left',
98 100 verticalalignment = 'top',
99 101 fontsize = 10)
100 102
101 103 def printLabels(ax, xlabel, ylabel, title):
102 104
103 105 ax.set_xlabel(xlabel, size=11)
104 106 ax.set_ylabel(ylabel, size=11)
105 107 ax.set_title(title, size=8)
106 108
107 109 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
108 110 ticksize=9, xtick_visible=True, ytick_visible=True,
109 111 nxticks=4, nyticks=10,
110 112 grid=None,color='blue'):
111 113
112 114 """
113 115
114 116 Input:
115 117 grid : None, 'both', 'x', 'y'
116 118 """
117 119
118 120 matplotlib.pyplot.ioff()
119 121
120 122 ax.set_xlim([xmin,xmax])
121 123 ax.set_ylim([ymin,ymax])
122 124
123 125 printLabels(ax, xlabel, ylabel, title)
124 126
125 127 ######################################################
126 128 if (xmax-xmin)<=1:
127 129 xtickspos = numpy.linspace(xmin,xmax,nxticks)
128 130 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
129 131 ax.set_xticks(xtickspos)
130 132 else:
131 133 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
132 134 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
133 135 ax.set_xticks(xtickspos)
134 136
135 137 for tick in ax.get_xticklabels():
136 138 tick.set_visible(xtick_visible)
137 139
138 140 for tick in ax.xaxis.get_major_ticks():
139 141 tick.label.set_fontsize(ticksize)
140 142
141 143 ######################################################
142 144 for tick in ax.get_yticklabels():
143 145 tick.set_visible(ytick_visible)
144 146
145 147 for tick in ax.yaxis.get_major_ticks():
146 148 tick.label.set_fontsize(ticksize)
147 149
148 150 ax.plot(x, y, color=color)
149 151 iplot = ax.lines[-1]
150 152
151 153 ######################################################
152 154 if '0.' in matplotlib.__version__[0:2]:
153 155 print "The matplotlib version has to be updated to 1.1 or newer"
154 156 return iplot
155 157
156 158 if '1.0.' in matplotlib.__version__[0:4]:
157 159 print "The matplotlib version has to be updated to 1.1 or newer"
158 160 return iplot
159 161
160 162 if grid != None:
161 163 ax.grid(b=True, which='major', axis=grid)
162 164
163 165 matplotlib.pyplot.tight_layout()
164 166
165 167 matplotlib.pyplot.ion()
166 168
167 169 return iplot
168 170
169 171 def set_linedata(ax, x, y, idline):
170 172
171 173 ax.lines[idline].set_data(x,y)
172 174
173 175 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
174 176
175 177 ax = iplot.get_axes()
176 178
177 179 printLabels(ax, xlabel, ylabel, title)
178 180
179 181 set_linedata(ax, x, y, idline=0)
180 182
181 183 def addpline(ax, x, y, color, linestyle, lw):
182 184
183 185 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
184 186
185 187
186 188 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
187 189 xlabel='', ylabel='', title='', ticksize = 9,
188 190 colormap='jet',cblabel='', cbsize="5%",
189 191 XAxisAsTime=False):
190 192
191 193 matplotlib.pyplot.ioff()
192 194
193 195 divider = make_axes_locatable(ax)
194 196 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
195 197 fig = ax.get_figure()
196 198 fig.add_axes(ax_cb)
197 199
198 200 ax.set_xlim([xmin,xmax])
199 201 ax.set_ylim([ymin,ymax])
200 202
201 203 printLabels(ax, xlabel, ylabel, title)
202 204
203 205 z = numpy.ma.masked_invalid(z)
204 206 cmap=matplotlib.pyplot.get_cmap(colormap)
205 cmap.set_bad('white',1.)
207 cmap.set_bad('white', 1.)
206 208 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
207 209 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
208 210 cb.set_label(cblabel)
209 211
210 212 # for tl in ax_cb.get_yticklabels():
211 213 # tl.set_visible(True)
212 214
213 215 for tick in ax.yaxis.get_major_ticks():
214 216 tick.label.set_fontsize(ticksize)
215 217
216 218 for tick in ax.xaxis.get_major_ticks():
217 219 tick.label.set_fontsize(ticksize)
218 220
219 221 for tick in cb.ax.get_yticklabels():
220 222 tick.set_fontsize(ticksize)
221 223
222 224 ax_cb.yaxis.tick_right()
223 225
224 226 if '0.' in matplotlib.__version__[0:2]:
225 227 print "The matplotlib version has to be updated to 1.1 or newer"
226 228 return imesh
227 229
228 230 if '1.0.' in matplotlib.__version__[0:4]:
229 231 print "The matplotlib version has to be updated to 1.1 or newer"
230 232 return imesh
231 233
232 234 matplotlib.pyplot.tight_layout()
233 235
234 236 if XAxisAsTime:
235 237
236 238 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
237 239 ax.xaxis.set_major_formatter(FuncFormatter(func))
238 240 ax.xaxis.set_major_locator(LinearLocator(7))
239 241
240 242 matplotlib.pyplot.ion()
241 243 return imesh
242 244
243 245 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
244 246
245 247 z = z.T
246 248 ax = imesh.get_axes()
247 249 printLabels(ax, xlabel, ylabel, title)
248 250 imesh.set_array(z.ravel())
249 251
250 252 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
251 253
252 254 printLabels(ax, xlabel, ylabel, title)
253 255
254 256 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
255 257
256 258 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
257 259
258 260 printLabels(ax, xlabel, ylabel, title)
259 261
260 262 ax.collections.remove(ax.collections[0])
261 263
262 264 z = numpy.ma.masked_invalid(z)
263 265
264 266 cmap=matplotlib.pyplot.get_cmap(colormap)
265 cmap.set_bad('white',1.)
267 cmap.set_bad('white', 1.)
266 268
267 269
268 270 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
269 271
270 272 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
271 273 ticksize=9, xtick_visible=True, ytick_visible=True,
272 274 nxticks=4, nyticks=10,
273 275 grid=None):
274 276
275 277 """
276 278
277 279 Input:
278 280 grid : None, 'both', 'x', 'y'
279 281 """
280 282
281 283 matplotlib.pyplot.ioff()
282 284
283 285 lines = ax.plot(x.T, y)
284 286 leg = ax.legend(lines, legendlabels, loc='upper right')
285 287 leg.get_frame().set_alpha(0.5)
286 288 ax.set_xlim([xmin,xmax])
287 289 ax.set_ylim([ymin,ymax])
288 290 printLabels(ax, xlabel, ylabel, title)
289 291
290 292 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
291 293 ax.set_xticks(xtickspos)
292 294
293 295 for tick in ax.get_xticklabels():
294 296 tick.set_visible(xtick_visible)
295 297
296 298 for tick in ax.xaxis.get_major_ticks():
297 299 tick.label.set_fontsize(ticksize)
298 300
299 301 for tick in ax.get_yticklabels():
300 302 tick.set_visible(ytick_visible)
301 303
302 304 for tick in ax.yaxis.get_major_ticks():
303 305 tick.label.set_fontsize(ticksize)
304 306
305 307 iplot = ax.lines[-1]
306 308
307 309 if '0.' in matplotlib.__version__[0:2]:
308 310 print "The matplotlib version has to be updated to 1.1 or newer"
309 311 return iplot
310 312
311 313 if '1.0.' in matplotlib.__version__[0:4]:
312 314 print "The matplotlib version has to be updated to 1.1 or newer"
313 315 return iplot
314 316
315 317 if grid != None:
316 318 ax.grid(b=True, which='major', axis=grid)
317 319
318 320 matplotlib.pyplot.tight_layout()
319 321
320 322 matplotlib.pyplot.ion()
321 323
322 324 return iplot
323 325
324 326
325 327 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
326 328
327 329 ax = iplot.get_axes()
328 330
329 331 printLabels(ax, xlabel, ylabel, title)
330 332
331 333 for i in range(len(ax.lines)):
332 334 line = ax.lines[i]
333 335 line.set_data(x[i,:],y)
334 336
335 337 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
336 338 ticksize=9, xtick_visible=True, ytick_visible=True,
337 339 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
338 340 grid=None, XAxisAsTime=False):
339 341
340 342 """
341 343
342 344 Input:
343 345 grid : None, 'both', 'x', 'y'
344 346 """
345 347
346 348 matplotlib.pyplot.ioff()
347 349
348 350 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
349 351 lines = ax.plot(x, y.T)
350 352 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
351 353 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
352 354
353 355 leg = ax.legend(lines, legendlabels,
354 356 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
355 357
356 358 for label in leg.get_texts(): label.set_fontsize(9)
357 359
358 360 ax.set_xlim([xmin,xmax])
359 361 ax.set_ylim([ymin,ymax])
360 362 printLabels(ax, xlabel, ylabel, title)
361 363
362 364 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
363 365 # ax.set_xticks(xtickspos)
364 366
365 367 for tick in ax.get_xticklabels():
366 368 tick.set_visible(xtick_visible)
367 369
368 370 for tick in ax.xaxis.get_major_ticks():
369 371 tick.label.set_fontsize(ticksize)
370 372
371 373 for tick in ax.get_yticklabels():
372 374 tick.set_visible(ytick_visible)
373 375
374 376 for tick in ax.yaxis.get_major_ticks():
375 377 tick.label.set_fontsize(ticksize)
376 378
377 379 iplot = ax.lines[-1]
378 380
379 381 if '0.' in matplotlib.__version__[0:2]:
380 382 print "The matplotlib version has to be updated to 1.1 or newer"
381 383 return iplot
382 384
383 385 if '1.0.' in matplotlib.__version__[0:4]:
384 386 print "The matplotlib version has to be updated to 1.1 or newer"
385 387 return iplot
386 388
387 389 if grid != None:
388 390 ax.grid(b=True, which='major', axis=grid)
389 391
390 392 matplotlib.pyplot.tight_layout()
391 393
392 394 if XAxisAsTime:
393 395
394 396 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
395 397 ax.xaxis.set_major_formatter(FuncFormatter(func))
396 398 ax.xaxis.set_major_locator(LinearLocator(7))
397 399
398 400 matplotlib.pyplot.ion()
399 401
400 402 return iplot
401 403
402 404 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
403 405
404 406 ax = iplot.get_axes()
405 407
406 408 printLabels(ax, xlabel, ylabel, title)
407 409
408 410 for i in range(len(ax.lines)):
409 411 line = ax.lines[i]
410 412 line.set_data(x,y[i,:])
411 413
412 414 def createPolar(ax, x, y,
413 415 xlabel='', ylabel='', title='', ticksize = 9,
414 416 colormap='jet',cblabel='', cbsize="5%",
415 417 XAxisAsTime=False):
416 418
417 419 matplotlib.pyplot.ioff()
418 420
419 421 ax.plot(x,y,'bo', markersize=5)
420 422 # ax.set_rmax(90)
421 423 ax.set_ylim(0,90)
422 424 ax.set_yticks(numpy.arange(0,90,20))
423 425 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
424 426 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
425 427 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
426 428 ax.yaxis.labelpad = 230
427 429 printLabels(ax, xlabel, ylabel, title)
428 430 iplot = ax.lines[-1]
429 431
430 432 if '0.' in matplotlib.__version__[0:2]:
431 433 print "The matplotlib version has to be updated to 1.1 or newer"
432 434 return iplot
433 435
434 436 if '1.0.' in matplotlib.__version__[0:4]:
435 437 print "The matplotlib version has to be updated to 1.1 or newer"
436 438 return iplot
437 439
438 440 # if grid != None:
439 441 # ax.grid(b=True, which='major', axis=grid)
440 442
441 443 matplotlib.pyplot.tight_layout()
442 444
443 445 matplotlib.pyplot.ion()
444 446
445 447
446 448 return iplot
447 449
448 450 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
449 451
450 452 ax = iplot.get_axes()
451 453
452 454 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
453 455 printLabels(ax, xlabel, ylabel, title)
454 456
455 457 set_linedata(ax, x, y, idline=0)
456 458
457 459 def draw(fig):
458 460
459 461 if type(fig) == 'int':
460 462 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
461 463
462 464 fig.canvas.draw()
463 465
464 466 def pause(interval=0.000001):
465 467
466 468 matplotlib.pyplot.pause(interval)
@@ -1,14 +1,14
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 5 '''
6 6
7 7 from jroIO_voltage import *
8 8 from jroIO_spectra import *
9 9 from jroIO_heispectra import *
10 10 from jroIO_usrp import *
11 11
12 12 from jroIO_kamisr import *
13 13 from jroIO_param import *
14 from jroIO_hf import * No newline at end of file
14 from jroIO_hf import *
@@ -1,1092 +1,1029
1 1 import numpy
2 2 import time
3 3 import os
4 4 import h5py
5 5 import re
6 6 import datetime
7 7
8 8 from schainpy.model.data.jrodata import *
9 9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 10 # from jroIO_base import *
11 11 from schainpy.model.io.jroIO_base import *
12 12 import schainpy
13 13
14 14
15 15 class ParamReader(ProcessingUnit):
16 16 '''
17 17 Reads HDF5 format files
18 18
19 19 path
20 20
21 21 startDate
22 22
23 23 endDate
24 24
25 25 startTime
26 26
27 27 endTime
28 28 '''
29 29
30 30 ext = ".hdf5"
31 31
32 32 optchar = "D"
33 33
34 34 timezone = None
35 35
36 36 startTime = None
37 37
38 38 endTime = None
39 39
40 40 fileIndex = None
41 41
42 42 utcList = None #To select data in the utctime list
43 43
44 44 blockList = None #List to blocks to be read from the file
45 45
46 46 blocksPerFile = None #Number of blocks to be read
47 47
48 48 blockIndex = None
49 49
50 50 path = None
51 51
52 52 #List of Files
53 53
54 54 filenameList = None
55 55
56 56 datetimeList = None
57 57
58 58 #Hdf5 File
59 59
60 60 listMetaname = None
61 61
62 62 listMeta = None
63 63
64 64 listDataname = None
65 65
66 66 listData = None
67 67
68 68 listShapes = None
69 69
70 70 fp = None
71 71
72 72 #dataOut reconstruction
73 73
74 74 dataOut = None
75 75
76 76
77 77 def __init__(self):
78 78 self.dataOut = Parameters()
79 79 return
80 80
81 81 def setup(self, **kwargs):
82 82
83 83 path = kwargs['path']
84 84 startDate = kwargs['startDate']
85 85 endDate = kwargs['endDate']
86 86 startTime = kwargs['startTime']
87 87 endTime = kwargs['endTime']
88 88 walk = kwargs['walk']
89 89 if kwargs.has_key('ext'):
90 90 ext = kwargs['ext']
91 91 else:
92 92 ext = '.hdf5'
93 93 if kwargs.has_key('timezone'):
94 94 self.timezone = kwargs['timezone']
95 95 else:
96 96 self.timezone = 'lt'
97 97
98 98 print "[Reading] Searching files in offline mode ..."
99 99 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
100 100 startTime=startTime, endTime=endTime,
101 101 ext=ext, walk=walk)
102 102
103 103 if not(filenameList):
104 104 print "There is no files into the folder: %s"%(path)
105 105 sys.exit(-1)
106 106
107 107 self.fileIndex = -1
108 108 self.startTime = startTime
109 109 self.endTime = endTime
110 110
111 111 self.__readMetadata()
112 112
113 113 self.__setNextFileOffline()
114 114
115 115 return
116 116
117 117 def __searchFilesOffLine(self,
118 118 path,
119 119 startDate=None,
120 120 endDate=None,
121 121 startTime=datetime.time(0,0,0),
122 122 endTime=datetime.time(23,59,59),
123 123 ext='.hdf5',
124 124 walk=True):
125 125
126 126 expLabel = ''
127 127 self.filenameList = []
128 128 self.datetimeList = []
129 129
130 130 pathList = []
131 131
132 132 JRODataObj = JRODataReader()
133 133 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
134 134
135 135 if dateList == []:
136 136 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
137 137 datetime.datetime.combine(startDate,startTime).ctime(),
138 138 datetime.datetime.combine(endDate,endTime).ctime())
139 139
140 140 return None, None
141 141
142 142 if len(dateList) > 1:
143 143 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
144 144 else:
145 145 print "[Reading] data was found for the date %s" %(dateList[0])
146 146
147 147 filenameList = []
148 148 datetimeList = []
149 149
150 150 #----------------------------------------------------------------------------------
151 151
152 152 for thisPath in pathList:
153 153 # thisPath = pathList[pathDict[file]]
154 154
155 155 fileList = glob.glob1(thisPath, "*%s" %ext)
156 156 fileList.sort()
157 157
158 158 for file in fileList:
159 159
160 160 filename = os.path.join(thisPath,file)
161 161
162 162 if not isFileInDateRange(filename, startDate, endDate):
163 163 continue
164 164
165 165 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
166 166
167 167 if not(thisDatetime):
168 168 continue
169 169
170 170 filenameList.append(filename)
171 171 datetimeList.append(thisDatetime)
172 172
173 173 if not(filenameList):
174 174 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
175 175 return None, None
176 176
177 177 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
178 178 print
179 179
180 180 for i in range(len(filenameList)):
181 181 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
182 182
183 183 self.filenameList = filenameList
184 184 self.datetimeList = datetimeList
185 185
186 186 return pathList, filenameList
187 187
188 188 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
189 189
190 190 """
191 191 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
192 192
193 193 Inputs:
194 194 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
195 195
196 196 startDate : fecha inicial del rango seleccionado en formato datetime.date
197 197
198 198 endDate : fecha final del rango seleccionado en formato datetime.date
199 199
200 200 startTime : tiempo inicial del rango seleccionado en formato datetime.time
201 201
202 202 endTime : tiempo final del rango seleccionado en formato datetime.time
203 203
204 204 Return:
205 205 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
206 206 fecha especificado, de lo contrario retorna False.
207 207
208 208 Excepciones:
209 209 Si el archivo no existe o no puede ser abierto
210 210 Si la cabecera no puede ser leida.
211 211
212 212 """
213 213
214 214 try:
215 215 fp = h5py.File(filename,'r')
216 216 grp1 = fp['Data']
217 217
218 218 except IOError:
219 219 traceback.print_exc()
220 220 raise IOError, "The file %s can't be opened" %(filename)
221 221 #chino rata
222 222 #In case has utctime attribute
223 223 grp2 = grp1['utctime']
224 224 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
225 225 thisUtcTime = grp2.value[0]
226 226
227 227 fp.close()
228 228
229 229 if self.timezone == 'lt':
230 230 thisUtcTime -= 5*3600
231 231
232 232 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
233 233 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
234 234 thisDate = thisDatetime.date()
235 235 thisTime = thisDatetime.time()
236 236
237 237 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
238 238 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239 239
240 240 #General case
241 241 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
242 242 #-----------o----------------------------o-----------
243 243 # startTime endTime
244 244
245 245 if endTime >= startTime:
246 246 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
247 247 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
248 248 return thisDatetime
249 249 return None
250 250
251 251 #If endTime < startTime then endTime belongs to the next day
252 252 #<<<<<<<<<<<o o>>>>>>>>>>>
253 253 #-----------o----------------------------o-----------
254 254 # endTime startTime
255 255
256 256 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
257 257 return None
258 258
259 259 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
260 260 return None
261 261
262 262 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
263 263 return None
264 264
265 265 return thisDatetime
266 266
267 267 def __setNextFileOffline(self):
268 268
269 269 self.fileIndex += 1
270 270 idFile = self.fileIndex
271 271
272 272 if not(idFile < len(self.filenameList)):
273 273 print "No more Files"
274 274 return 0
275 275
276 276 filename = self.filenameList[idFile]
277 277
278 278 filePointer = h5py.File(filename,'r')
279 279
280 280 self.filename = filename
281 281
282 282 self.fp = filePointer
283 283
284 284 print "Setting the file: %s"%self.filename
285 285
286 286 # self.__readMetadata()
287 287 self.__setBlockList()
288 288 self.__readData()
289 289 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
290 290 # self.nRecords = self.fp['Data'].attrs['nRecords']
291 291 self.blockIndex = 0
292 292 return 1
293 293
294 294 def __setBlockList(self):
295 295 '''
296 296 Selects the data within the times defined
297 297
298 298 self.fp
299 299 self.startTime
300 300 self.endTime
301 301
302 302 self.blockList
303 303 self.blocksPerFile
304 304
305 305 '''
306 306 fp = self.fp
307 307 startTime = self.startTime
308 308 endTime = self.endTime
309 309
310 310 grp = fp['Data']
311 311 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
312 312
313 313 #ERROOOOR
314 314 if self.timezone == 'lt':
315 315 thisUtcTime -= 5*3600
316 316
317 317 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
318 318
319 319 thisDate = thisDatetime.date()
320 320 thisTime = thisDatetime.time()
321 321
322 322 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
323 323 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324 324
325 325 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
326 326
327 327 self.blockList = ind
328 328 self.blocksPerFile = len(ind)
329 329
330 330 return
331 331
332 332 def __readMetadata(self):
333 333 '''
334 334 Reads Metadata
335 335
336 336 self.pathMeta
337 337
338 338 self.listShapes
339 339 self.listMetaname
340 340 self.listMeta
341 341
342 342 '''
343 343
344 344 # grp = self.fp['Data']
345 345 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
346 346 #
347 347 # if pathMeta == self.pathMeta:
348 348 # return
349 349 # else:
350 350 # self.pathMeta = pathMeta
351 351 #
352 352 # filePointer = h5py.File(self.pathMeta,'r')
353 353 # groupPointer = filePointer['Metadata']
354 354
355 355 filename = self.filenameList[0]
356 356
357 357 fp = h5py.File(filename,'r')
358 358
359 359 gp = fp['Metadata']
360 360
361 361 listMetaname = []
362 362 listMetadata = []
363 363 for item in gp.items():
364 364 name = item[0]
365 365
366 366 if name=='array dimensions':
367 367 table = gp[name][:]
368 368 listShapes = {}
369 369 for shapes in table:
370 370 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
371 371 else:
372 372 data = gp[name].value
373 373 listMetaname.append(name)
374 374 listMetadata.append(data)
375 375
376 376 # if name=='type':
377 377 # self.__initDataOut(data)
378 378
379 379 self.listShapes = listShapes
380 380 self.listMetaname = listMetaname
381 381 self.listMeta = listMetadata
382 382
383 383 fp.close()
384 384 return
385 385
386 386 def __readData(self):
387 387 grp = self.fp['Data']
388 388 listdataname = []
389 389 listdata = []
390 390
391 391 for item in grp.items():
392 392 name = item[0]
393 393 listdataname.append(name)
394 394
395 395 array = self.__setDataArray(grp[name],self.listShapes[name])
396 396 listdata.append(array)
397 397
398 398 self.listDataname = listdataname
399 399 self.listData = listdata
400 400 return
401 401
402 def __setDataArray(self, dataset, shapes):
403
404 nDims = shapes[0]
405
406 nDim2 = shapes[1] #Dimension 0
407 402
408 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
409
410 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
411
412 mode = shapes[4] #Mode of storing
413
414 blockList = self.blockList
415
416 blocksPerFile = self.blocksPerFile
417
418 #Depending on what mode the data was stored
419 if mode == 0: #Divided in channels
420 arrayData = dataset.value.astype(numpy.float)[0][blockList]
421 if mode == 1: #Divided in parameter
422 strds = 'table'
423 nDatas = nDim1
424 newShapes = (blocksPerFile,nDim2,nDim0)
425 elif mode==2: #Concatenated in a table
426 strds = 'table0'
427 arrayData = dataset[strds].value
428 #Selecting part of the dataset
429 utctime = arrayData[:,0]
430 u, indices = numpy.unique(utctime, return_index=True)
431
432 if blockList.size != indices.size:
433 indMin = indices[blockList[0]]
434 if blockList[-1] + 1 >= indices.size:
435 arrayData = arrayData[indMin:,:]
436 else:
437 indMax = indices[blockList[-1] + 1]
438 arrayData = arrayData[indMin:indMax,:]
439 return arrayData
440
441 #------- One dimension ---------------
442 if nDims == 0:
443 arrayData = dataset.value.astype(numpy.float)[0][blockList]
444
445 #------- Two dimensions -----------
446 elif nDims == 2:
447 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
448 newShapes = (blocksPerFile,nDim0)
449 nDatas = nDim1
450
451 for i in range(nDatas):
452 data = dataset[strds + str(i)].value
453 arrayData[:,i,:] = data[blockList,:]
454
455 #------- Three dimensions ---------
456 else:
457 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
458 for i in range(nDatas):
459
460 data = dataset[strds + str(i)].value
461
462 for b in range(blockList.size):
463 arrayData[b,:,i,:] = data[:,:,blockList[b]]
464
465 return arrayData
466 403
467 404 def __setDataOut(self):
468 405 listMeta = self.listMeta
469 406 listMetaname = self.listMetaname
470 407 listDataname = self.listDataname
471 408 listData = self.listData
472 409 listShapes = self.listShapes
473 410
474 411 blockIndex = self.blockIndex
475 412 # blockList = self.blockList
476 413
477 414 for i in range(len(listMeta)):
478 415 setattr(self.dataOut,listMetaname[i],listMeta[i])
479 416
480 417 for j in range(len(listData)):
481 418 nShapes = listShapes[listDataname[j]][0]
482 419 mode = listShapes[listDataname[j]][4]
483 420 if nShapes == 1:
484 421 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
485 422 elif nShapes > 1:
486 423 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
487 424 elif mode==0:
488 425 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
489 426 #Mode Meteors
490 427 elif mode ==2:
491 428 selectedData = self.__selectDataMode2(listData[j], blockIndex)
492 429 setattr(self.dataOut, listDataname[j], selectedData)
493 430 return
494 431
495 432 def __selectDataMode2(self, data, blockIndex):
496 433 utctime = data[:,0]
497 434 aux, indices = numpy.unique(utctime, return_inverse=True)
498 435 selInd = numpy.where(indices == blockIndex)[0]
499 436 selData = data[selInd,:]
500 437
501 438 return selData
502 439
503 440 def getData(self):
504 441
505 442 # if self.flagNoMoreFiles:
506 443 # self.dataOut.flagNoData = True
507 444 # print 'Process finished'
508 445 # return 0
509 446 #
510 447 if self.blockIndex==self.blocksPerFile:
511 448 if not( self.__setNextFileOffline() ):
512 449 self.dataOut.flagNoData = True
513 450 return 0
514 451
515 452 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
516 453 # self.dataOut.flagNoData = True
517 454 # return 0
518 455 # self.__readData()
519 456 self.__setDataOut()
520 457 self.dataOut.flagNoData = False
521 458
522 459 self.blockIndex += 1
523 460
524 461 return
525 462
526 463 def run(self, **kwargs):
527 464
528 465 if not(self.isConfig):
529 466 self.setup(**kwargs)
530 467 # self.setObjProperties()
531 468 self.isConfig = True
532 469
533 470 self.getData()
534 471
535 472 return
536 473
537 474 class ParamWriter(Operation):
538 475 '''
539 476 HDF5 Writer, stores parameters data in HDF5 format files
540 477
541 478 path: path where the files will be stored
542 479
543 480 blocksPerFile: number of blocks that will be saved in per HDF5 format file
544 481
545 482 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
546 483
547 484 metadataList: list of attributes that will be stored as metadata
548 485
549 486 dataList: list of attributes that will be stores as data
550 487
551 488 '''
552 489
553 490
554 491 ext = ".hdf5"
555 492
556 493 optchar = "D"
557 494
558 495 metaoptchar = "M"
559 496
560 497 metaFile = None
561 498
562 499 filename = None
563 500
564 501 path = None
565 502
566 503 setFile = None
567 504
568 505 fp = None
569 506
570 507 grp = None
571 508
572 509 ds = None
573 510
574 511 firsttime = True
575 512
576 513 #Configurations
577 514
578 515 blocksPerFile = None
579 516
580 517 blockIndex = None
581 518
582 519 dataOut = None
583 520
584 521 #Data Arrays
585 522
586 523 dataList = None
587 524
588 525 metadataList = None
589 526
590 527 # arrayDim = None
591 528
592 529 dsList = None #List of dictionaries with dataset properties
593 530
594 531 tableDim = None
595 532
596 533 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
597 534
598 535 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
599 536
600 537 currentDay = None
601 538
602 539 lastTime = None
603 540
604 541 def __init__(self):
605 542
606 543 Operation.__init__(self)
607 544 self.isConfig = False
608 545 return
609 546
610 547 def setup(self, dataOut, **kwargs):
611 548
612 549 self.path = kwargs['path']
613 550
614 551 if kwargs.has_key('blocksPerFile'):
615 552 self.blocksPerFile = kwargs['blocksPerFile']
616 553 else:
617 554 self.blocksPerFile = 10
618 555
619 556 self.metadataList = kwargs['metadataList']
620 557 self.dataList = kwargs['dataList']
621 558 self.dataOut = dataOut
622 559
623 560 if kwargs.has_key('mode'):
624 561 mode = kwargs['mode']
625 562
626 563 if type(mode) == int:
627 564 mode = numpy.zeros(len(self.dataList)) + mode
628 565 else:
629 566 mode = numpy.ones(len(self.dataList))
630 567
631 568 self.mode = mode
632 569
633 570 arrayDim = numpy.zeros((len(self.dataList),5))
634 571
635 572 #Table dimensions
636 573 dtype0 = self.dtype
637 574 tableList = []
638 575
639 576 #Dictionary and list of tables
640 577 dsList = []
641 578
642 579 for i in range(len(self.dataList)):
643 580 dsDict = {}
644 581 dataAux = getattr(self.dataOut, self.dataList[i])
645 582 dsDict['variable'] = self.dataList[i]
646 583 #--------------------- Conditionals ------------------------
647 584 #There is no data
648 585 if dataAux == None:
649 586 return 0
650 587
651 588 #Not array, just a number
652 589 #Mode 0
653 590 if type(dataAux)==float or type(dataAux)==int:
654 591 dsDict['mode'] = 0
655 592 dsDict['nDim'] = 0
656 593 arrayDim[i,0] = 0
657 594 dsList.append(dsDict)
658 595
659 596 #Mode 2: meteors
660 597 elif mode[i] == 2:
661 598 # dsDict['nDim'] = 0
662 599 dsDict['dsName'] = 'table0'
663 600 dsDict['mode'] = 2 # Mode meteors
664 601 dsDict['shape'] = dataAux.shape[-1]
665 602 dsDict['nDim'] = 0
666 603 dsDict['dsNumber'] = 1
667 604
668 605 arrayDim[i,3] = dataAux.shape[-1]
669 606 arrayDim[i,4] = mode[i] #Mode the data was stored
670 607
671 608 dsList.append(dsDict)
672 609
673 610 #Mode 1
674 611 else:
675 612 arrayDim0 = dataAux.shape #Data dimensions
676 613 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
677 614 arrayDim[i,4] = mode[i] #Mode the data was stored
678 615
679 616 strtable = 'table'
680 617 dsDict['mode'] = 1 # Mode parameters
681 618
682 619 # Three-dimension arrays
683 620 if len(arrayDim0) == 3:
684 621 arrayDim[i,1:-1] = numpy.array(arrayDim0)
685 622 nTables = int(arrayDim[i,2])
686 623 dsDict['dsNumber'] = nTables
687 624 dsDict['shape'] = arrayDim[i,2:4]
688 625 dsDict['nDim'] = 3
689 626
690 627 for j in range(nTables):
691 628 dsDict = dsDict.copy()
692 629 dsDict['dsName'] = strtable + str(j)
693 630 dsList.append(dsDict)
694 631
695 632 # Two-dimension arrays
696 633 elif len(arrayDim0) == 2:
697 634 arrayDim[i,2:-1] = numpy.array(arrayDim0)
698 635 nTables = int(arrayDim[i,2])
699 636 dsDict['dsNumber'] = nTables
700 637 dsDict['shape'] = arrayDim[i,3]
701 638 dsDict['nDim'] = 2
702 639
703 640 for j in range(nTables):
704 641 dsDict = dsDict.copy()
705 642 dsDict['dsName'] = strtable + str(j)
706 643 dsList.append(dsDict)
707 644
708 645 # One-dimension arrays
709 646 elif len(arrayDim0) == 1:
710 647 arrayDim[i,3] = arrayDim0[0]
711 648 dsDict['shape'] = arrayDim0[0]
712 649 dsDict['dsNumber'] = 1
713 650 dsDict['dsName'] = strtable + str(0)
714 651 dsDict['nDim'] = 1
715 652 dsList.append(dsDict)
716 653
717 654 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
718 655 tableList.append(table)
719 656
720 657 # self.arrayDim = arrayDim
721 658 self.dsList = dsList
722 659 self.tableDim = numpy.array(tableList, dtype = dtype0)
723 660 self.blockIndex = 0
724 661
725 662 timeTuple = time.localtime(dataOut.utctime)
726 663 self.currentDay = timeTuple.tm_yday
727 664 return 1
728 665
729 666 def putMetadata(self):
730 667
731 668 fp = self.createMetadataFile()
732 669 self.writeMetadata(fp)
733 670 fp.close()
734 671 return
735 672
736 673 def createMetadataFile(self):
737 674 ext = self.ext
738 675 path = self.path
739 676 setFile = self.setFile
740 677
741 678 timeTuple = time.localtime(self.dataOut.utctime)
742 679
743 680 subfolder = ''
744 681 fullpath = os.path.join( path, subfolder )
745 682
746 683 if not( os.path.exists(fullpath) ):
747 684 os.mkdir(fullpath)
748 685 setFile = -1 #inicializo mi contador de seteo
749 686
750 687 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
751 688 fullpath = os.path.join( path, subfolder )
752 689
753 690 if not( os.path.exists(fullpath) ):
754 691 os.mkdir(fullpath)
755 692 setFile = -1 #inicializo mi contador de seteo
756 693
757 694 else:
758 695 filesList = os.listdir( fullpath )
759 696 filesList = sorted( filesList, key=str.lower )
760 697 if len( filesList ) > 0:
761 698 filesList = [k for k in filesList if 'M' in k]
762 699 filen = filesList[-1]
763 700 # el filename debera tener el siguiente formato
764 701 # 0 1234 567 89A BCDE (hex)
765 702 # x YYYY DDD SSS .ext
766 703 if isNumber( filen[8:11] ):
767 704 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
768 705 else:
769 706 setFile = -1
770 707 else:
771 708 setFile = -1 #inicializo mi contador de seteo
772 709
773 710 setFile += 1
774 711
775 712 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
776 713 timeTuple.tm_year,
777 714 timeTuple.tm_yday,
778 715 setFile,
779 716 ext )
780 717
781 718 filename = os.path.join( path, subfolder, file )
782 719 self.metaFile = file
783 720 #Setting HDF5 File
784 721 fp = h5py.File(filename,'w')
785 722
786 723 return fp
787 724
788 725 def writeMetadata(self, fp):
789 726
790 727 grp = fp.create_group("Metadata")
791 728 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
792 729
793 730 for i in range(len(self.metadataList)):
794 731 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
795 732 return
796 733
797 734 def timeFlag(self):
798 735 currentTime = self.dataOut.utctime
799 736
800 737 if self.lastTime is None:
801 738 self.lastTime = currentTime
802 739
803 740 #Day
804 741 timeTuple = time.localtime(currentTime)
805 742 dataDay = timeTuple.tm_yday
806 743
807 744 #Time
808 745 timeDiff = currentTime - self.lastTime
809 746
810 747 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
811 748 if dataDay != self.currentDay:
812 749 self.currentDay = dataDay
813 750 return True
814 751 elif timeDiff > 3*60*60:
815 752 self.lastTime = currentTime
816 753 return True
817 754 else:
818 755 self.lastTime = currentTime
819 756 return False
820 757
821 758 def setNextFile(self):
822 759
823 760 ext = self.ext
824 761 path = self.path
825 762 setFile = self.setFile
826 763 mode = self.mode
827 764
828 765 timeTuple = time.localtime(self.dataOut.utctime)
829 766 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
830 767
831 768 fullpath = os.path.join( path, subfolder )
832 769
833 770 if os.path.exists(fullpath):
834 771 filesList = os.listdir( fullpath )
835 772 filesList = [k for k in filesList if 'D' in k]
836 773 if len( filesList ) > 0:
837 774 filesList = sorted( filesList, key=str.lower )
838 775 filen = filesList[-1]
839 776 # el filename debera tener el siguiente formato
840 777 # 0 1234 567 89A BCDE (hex)
841 778 # x YYYY DDD SSS .ext
842 779 if isNumber( filen[8:11] ):
843 780 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
844 781 else:
845 782 setFile = -1
846 783 else:
847 784 setFile = -1 #inicializo mi contador de seteo
848 785 else:
849 786 os.mkdir(fullpath)
850 787 setFile = -1 #inicializo mi contador de seteo
851 788
852 789 setFile += 1
853 790
854 791 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
855 792 timeTuple.tm_year,
856 793 timeTuple.tm_yday,
857 794 setFile,
858 795 ext )
859 796
860 797 filename = os.path.join( path, subfolder, file )
861 798
862 799 #Setting HDF5 File
863 800 fp = h5py.File(filename,'w')
864 801 #write metadata
865 802 self.writeMetadata(fp)
866 803 #Write data
867 804 grp = fp.create_group("Data")
868 805 # grp.attrs['metadata'] = self.metaFile
869 806
870 807 # grp.attrs['blocksPerFile'] = 0
871 808 ds = []
872 809 data = []
873 810 dsList = self.dsList
874 811 i = 0
875 812 while i < len(dsList):
876 813 dsInfo = dsList[i]
877 814 #One-dimension data
878 815 if dsInfo['mode'] == 0:
879 816 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
880 817 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
881 818 ds.append(ds0)
882 819 data.append([])
883 820 i += 1
884 821 continue
885 822 # nDimsForDs.append(nDims[i])
886 823
887 824 elif dsInfo['mode'] == 2:
888 825 grp0 = grp.create_group(dsInfo['variable'])
889 826 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
890 827 ds.append(ds0)
891 828 data.append([])
892 829 i += 1
893 830 continue
894 831
895 832 elif dsInfo['mode'] == 1:
896 833 grp0 = grp.create_group(dsInfo['variable'])
897 834
898 835 for j in range(dsInfo['dsNumber']):
899 836 dsInfo = dsList[i]
900 837 tableName = dsInfo['dsName']
901 838 shape = dsInfo['shape']
902 839
903 840 if dsInfo['nDim'] == 3:
904 841 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
905 842 else:
906 843 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
907 844
908 845 ds.append(ds0)
909 846 data.append([])
910 847 i += 1
911 848 # nDimsForDs.append(nDims[i])
912 849
913 850 fp.flush()
914 851 fp.close()
915 852
916 853 # self.nDatas = nDatas
917 854 # self.nDims = nDims
918 855 # self.nDimsForDs = nDimsForDs
919 856 #Saving variables
920 857 print 'Writing the file: %s'%filename
921 858 self.filename = filename
922 859 # self.fp = fp
923 860 # self.grp = grp
924 861 # self.grp.attrs.modify('nRecords', 1)
925 862 self.ds = ds
926 863 self.data = data
927 864 # self.setFile = setFile
928 865 self.firsttime = True
929 866 self.blockIndex = 0
930 867 return
931 868
932 869 def putData(self):
933 870
934 871 if self.blockIndex == self.blocksPerFile or self.timeFlag():
935 872 self.setNextFile()
936 873
937 874 # if not self.firsttime:
938 875 self.readBlock()
939 876 self.setBlock() #Prepare data to be written
940 877 self.writeBlock() #Write data
941 878
942 879 return
943 880
944 881 def readBlock(self):
945 882
946 883 '''
947 884 data Array configured
948 885
949 886
950 887 self.data
951 888 '''
952 889 dsList = self.dsList
953 890 ds = self.ds
954 891 #Setting HDF5 File
955 892 fp = h5py.File(self.filename,'r+')
956 893 grp = fp["Data"]
957 894 ind = 0
958 895
959 896 # grp.attrs['blocksPerFile'] = 0
960 897 while ind < len(dsList):
961 898 dsInfo = dsList[ind]
962 899
963 900 if dsInfo['mode'] == 0:
964 901 ds0 = grp[dsInfo['variable']]
965 902 ds[ind] = ds0
966 903 ind += 1
967 904 else:
968 905
969 906 grp0 = grp[dsInfo['variable']]
970 907
971 908 for j in range(dsInfo['dsNumber']):
972 909 dsInfo = dsList[ind]
973 910 ds0 = grp0[dsInfo['dsName']]
974 911 ds[ind] = ds0
975 912 ind += 1
976 913
977 914 self.fp = fp
978 915 self.grp = grp
979 916 self.ds = ds
980 917
981 918 return
982 919
983 920 def setBlock(self):
984 921 '''
985 922 data Array configured
986 923
987 924
988 925 self.data
989 926 '''
990 927 #Creating Arrays
991 928 dsList = self.dsList
992 929 data = self.data
993 930 ind = 0
994 931
995 932 while ind < len(dsList):
996 933 dsInfo = dsList[ind]
997 934 dataAux = getattr(self.dataOut, dsInfo['variable'])
998 935
999 936 mode = dsInfo['mode']
1000 937 nDim = dsInfo['nDim']
1001 938
1002 939 if mode == 0 or mode == 2 or nDim == 1:
1003 940 data[ind] = dataAux
1004 941 ind += 1
1005 942 # elif nDim == 1:
1006 943 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1007 944 # ind += 1
1008 945 elif nDim == 2:
1009 946 for j in range(dsInfo['dsNumber']):
1010 947 data[ind] = dataAux[j,:]
1011 948 ind += 1
1012 949 elif nDim == 3:
1013 950 for j in range(dsInfo['dsNumber']):
1014 951 data[ind] = dataAux[:,j,:]
1015 952 ind += 1
1016 953
1017 954 self.data = data
1018 955 return
1019 956
1020 957 def writeBlock(self):
1021 958 '''
1022 959 Saves the block in the HDF5 file
1023 960 '''
1024 961 dsList = self.dsList
1025 962
1026 963 for i in range(len(self.ds)):
1027 964 dsInfo = dsList[i]
1028 965 nDim = dsInfo['nDim']
1029 966 mode = dsInfo['mode']
1030 967
1031 968 # First time
1032 969 if self.firsttime:
1033 970 # self.ds[i].resize(self.data[i].shape)
1034 971 # self.ds[i][self.blockIndex,:] = self.data[i]
1035 972 if type(self.data[i]) == numpy.ndarray:
1036 973
1037 974 if nDim == 3:
1038 975 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1039 976 self.ds[i].resize(self.data[i].shape)
1040 977 if mode == 2:
1041 978 self.ds[i].resize(self.data[i].shape)
1042 979 self.ds[i][:] = self.data[i]
1043 980 else:
1044 981
1045 982 # From second time
1046 983 # Meteors!
1047 984 if mode == 2:
1048 985 dataShape = self.data[i].shape
1049 986 dsShape = self.ds[i].shape
1050 987 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1051 988 self.ds[i][dsShape[0]:,:] = self.data[i]
1052 989 # No dimension
1053 990 elif mode == 0:
1054 991 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1055 992 self.ds[i][0,-1] = self.data[i]
1056 993 # One dimension
1057 994 elif nDim == 1:
1058 995 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1059 996 self.ds[i][-1,:] = self.data[i]
1060 997 # Two dimension
1061 998 elif nDim == 2:
1062 999 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1063 1000 self.ds[i][self.blockIndex,:] = self.data[i]
1064 1001 # Three dimensions
1065 1002 elif nDim == 3:
1066 1003 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1067 1004 self.ds[i][:,:,-1] = self.data[i]
1068 1005
1069 1006 self.firsttime = False
1070 1007 self.blockIndex += 1
1071 1008
1072 1009 #Close to save changes
1073 1010 self.fp.flush()
1074 1011 self.fp.close()
1075 1012 return
1076 1013
1077 1014 def run(self, dataOut, **kwargs):
1078 1015
1079 1016 if not(self.isConfig):
1080 1017 flagdata = self.setup(dataOut, **kwargs)
1081 1018
1082 1019 if not(flagdata):
1083 1020 return
1084 1021
1085 1022 self.isConfig = True
1086 1023 # self.putMetadata()
1087 1024 self.setNextFile()
1088 1025
1089 1026 self.putData()
1090 1027 return
1091 1028
1092 1029
@@ -1,677 +1,679
1 1 '''
2 2 Created on Jul 2, 2014
3 3
4 4 @author: roj-idl71
5 5 '''
6 6 import numpy
7 7
8 8 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
9 9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
11 11 from schainpy.model.data.jrodata import Spectra
12 12
13 13 class SpectraReader(JRODataReader, ProcessingUnit):
14 14 """
15 15 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
16 16 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
17 17 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
18 18
19 19 paresCanalesIguales * alturas * perfiles (Self Spectra)
20 20 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
21 21 canales * alturas (DC Channels)
22 22
23 23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
24 24 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
25 25 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
26 26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
27 27
28 28 Example:
29 29 dpath = "/home/myuser/data"
30 30
31 31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
32 32
33 33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
34 34
35 35 readerObj = SpectraReader()
36 36
37 37 readerObj.setup(dpath, startTime, endTime)
38 38
39 39 while(True):
40 40
41 41 readerObj.getData()
42 42
43 43 print readerObj.data_spc
44 44
45 45 print readerObj.data_cspc
46 46
47 47 print readerObj.data_dc
48 48
49 49 if readerObj.flagNoMoreFiles:
50 50 break
51 51
52 52 """
53 53
54 54 pts2read_SelfSpectra = 0
55 55
56 56 pts2read_CrossSpectra = 0
57 57
58 58 pts2read_DCchannels = 0
59 59
60 60 ext = ".pdata"
61 61
62 62 optchar = "P"
63 63
64 64 dataOut = None
65 65
66 66 nRdChannels = None
67 67
68 68 nRdPairs = None
69 69
70 70 rdPairList = []
71 71
72 72 def __init__(self):
73 73 """
74 74 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
75 75
76 76 Inputs:
77 77 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
78 78 almacenar un perfil de datos cada vez que se haga un requerimiento
79 79 (getData). El perfil sera obtenido a partir del buffer de datos,
80 80 si el buffer esta vacio se hara un nuevo proceso de lectura de un
81 81 bloque de datos.
82 82 Si este parametro no es pasado se creara uno internamente.
83 83
84 84 Affected:
85 85 self.dataOut
86 86
87 87 Return : None
88 88 """
89 89
90 90 #Eliminar de la base la herencia
91 91 ProcessingUnit.__init__(self)
92 92
93 93 # self.isConfig = False
94 94
95 95 self.pts2read_SelfSpectra = 0
96 96
97 97 self.pts2read_CrossSpectra = 0
98 98
99 99 self.pts2read_DCchannels = 0
100 100
101 101 self.datablock = None
102 102
103 103 self.utc = None
104 104
105 105 self.ext = ".pdata"
106 106
107 107 self.optchar = "P"
108 108
109 109 self.basicHeaderObj = BasicHeader(LOCALTIME)
110 110
111 111 self.systemHeaderObj = SystemHeader()
112 112
113 113 self.radarControllerHeaderObj = RadarControllerHeader()
114 114
115 115 self.processingHeaderObj = ProcessingHeader()
116 116
117 117 self.online = 0
118 118
119 119 self.fp = None
120 120
121 121 self.idFile = None
122 122
123 123 self.dtype = None
124 124
125 125 self.fileSizeByHeader = None
126 126
127 127 self.filenameList = []
128 128
129 129 self.filename = None
130 130
131 131 self.fileSize = None
132 132
133 133 self.firstHeaderSize = 0
134 134
135 135 self.basicHeaderSize = 24
136 136
137 137 self.pathList = []
138 138
139 139 self.lastUTTime = 0
140 140
141 141 self.maxTimeStep = 30
142 142
143 143 self.flagNoMoreFiles = 0
144 144
145 145 self.set = 0
146 146
147 147 self.path = None
148 148
149 149 self.delay = 60 #seconds
150 150
151 151 self.nTries = 3 #quantity tries
152 152
153 153 self.nFiles = 3 #number of files for searching
154 154
155 155 self.nReadBlocks = 0
156 156
157 157 self.flagIsNewFile = 1
158 158
159 159 self.__isFirstTimeOnline = 1
160 160
161 161 # self.ippSeconds = 0
162 162
163 163 self.flagDiscontinuousBlock = 0
164 164
165 165 self.flagIsNewBlock = 0
166 166
167 167 self.nTotalBlocks = 0
168 168
169 169 self.blocksize = 0
170 170
171 171 self.dataOut = self.createObjByDefault()
172 172
173 173 self.profileIndex = 1 #Always
174 174
175 175
176 176 def createObjByDefault(self):
177 177
178 178 dataObj = Spectra()
179 179
180 180 return dataObj
181 181
182 182 def __hasNotDataInBuffer(self):
183 183 return 1
184 184
185 185
186 186 def getBlockDimension(self):
187 187 """
188 188 Obtiene la cantidad de puntos a leer por cada bloque de datos
189 189
190 190 Affected:
191 191 self.nRdChannels
192 192 self.nRdPairs
193 193 self.pts2read_SelfSpectra
194 194 self.pts2read_CrossSpectra
195 195 self.pts2read_DCchannels
196 196 self.blocksize
197 197 self.dataOut.nChannels
198 198 self.dataOut.nPairs
199 199
200 200 Return:
201 201 None
202 202 """
203 203 self.nRdChannels = 0
204 204 self.nRdPairs = 0
205 205 self.rdPairList = []
206 206
207 207 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
208 208 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
209 209 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
210 210 else:
211 211 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
212 212 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
213 213
214 214 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
215 215
216 216 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
217 217 self.blocksize = self.pts2read_SelfSpectra
218 218
219 219 if self.processingHeaderObj.flag_cspc:
220 220 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
221 221 self.blocksize += self.pts2read_CrossSpectra
222 222
223 223 if self.processingHeaderObj.flag_dc:
224 224 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
225 225 self.blocksize += self.pts2read_DCchannels
226 226
227 227 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
228 228
229 229
230 230 def readBlock(self):
231 231 """
232 232 Lee el bloque de datos desde la posicion actual del puntero del archivo
233 233 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
234 234 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
235 235 es seteado a 0
236 236
237 237 Return: None
238 238
239 239 Variables afectadas:
240 240
241 241 self.flagIsNewFile
242 242 self.flagIsNewBlock
243 243 self.nTotalBlocks
244 244 self.data_spc
245 245 self.data_cspc
246 246 self.data_dc
247 247
248 248 Exceptions:
249 249 Si un bloque leido no es un bloque valido
250 250 """
251 251 blockOk_flag = False
252 252 fpointer = self.fp.tell()
253 253
254 254 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
255 255 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
256 256
257 257 if self.processingHeaderObj.flag_cspc:
258 258 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
259 259 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
260 260
261 261 if self.processingHeaderObj.flag_dc:
262 262 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
263 263 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
264 264
265 265
266 266 if not(self.processingHeaderObj.shif_fft):
267 267 #desplaza a la derecha en el eje 2 determinadas posiciones
268 268 shift = int(self.processingHeaderObj.profilesPerBlock/2)
269 269 spc = numpy.roll( spc, shift , axis=2 )
270 270
271 271 if self.processingHeaderObj.flag_cspc:
272 272 #desplaza a la derecha en el eje 2 determinadas posiciones
273 273 cspc = numpy.roll( cspc, shift, axis=2 )
274 274
275 275 #Dimensions : nChannels, nProfiles, nSamples
276 276 spc = numpy.transpose( spc, (0,2,1) )
277 277 self.data_spc = spc
278 278
279 279 if self.processingHeaderObj.flag_cspc:
280 280 cspc = numpy.transpose( cspc, (0,2,1) )
281 281 self.data_cspc = cspc['real'] + cspc['imag']*1j
282 282 else:
283 283 self.data_cspc = None
284 284
285 285 if self.processingHeaderObj.flag_dc:
286 286 self.data_dc = dc['real'] + dc['imag']*1j
287 287 else:
288 288 self.data_dc = None
289 289
290 290 self.flagIsNewFile = 0
291 291 self.flagIsNewBlock = 1
292 292
293 293 self.nTotalBlocks += 1
294 294 self.nReadBlocks += 1
295 295
296 296 return 1
297 297
298 298 def getFirstHeader(self):
299 299
300 300 self.getBasicHeader()
301 301
302 302 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
303 303
304 304 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
305 305
306 306 # self.dataOut.ippSeconds = self.ippSeconds
307 307
308 308 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
309 309
310 310 self.dataOut.dtype = self.dtype
311 311
312 312 # self.dataOut.nPairs = self.nPairs
313 313
314 314 self.dataOut.pairsList = self.rdPairList
315 315
316 316 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
317 317
318 318 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
319 319
320 320 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
321 321
322 322 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
323 323
324 324 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
325 325
326 326 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
327 327
328 328 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
329 329
330 330 self.dataOut.flagShiftFFT = True #Data is always shifted
331 331
332 332 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
333 333
334 334 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
335 335
336 336 def getData(self):
337 337 """
338 338 First method to execute before "RUN" is called.
339 339
340 340 Copia el buffer de lectura a la clase "Spectra",
341 341 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
342 342 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
343 343
344 344 Return:
345 345 0 : Si no hay mas archivos disponibles
346 346 1 : Si hizo una buena copia del buffer
347 347
348 348 Affected:
349 349 self.dataOut
350 350
351 351 self.flagDiscontinuousBlock
352 352 self.flagIsNewBlock
353 353 """
354 354
355 355 if self.flagNoMoreFiles:
356 356 self.dataOut.flagNoData = True
357 357 print 'Process finished'
358 358 return 0
359 359
360 360 self.flagDiscontinuousBlock = 0
361 361 self.flagIsNewBlock = 0
362 362
363 363 if self.__hasNotDataInBuffer():
364 364
365 365 if not( self.readNextBlock() ):
366 366 self.dataOut.flagNoData = True
367 367 return 0
368 368
369 369 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
370 370
371 371 if self.data_spc is None:
372 372 self.dataOut.flagNoData = True
373 373 return 0
374 374
375 375 self.getBasicHeader()
376 376
377 377 self.getFirstHeader()
378 378
379 379 self.dataOut.data_spc = self.data_spc
380 380
381 381 self.dataOut.data_cspc = self.data_cspc
382 382
383 383 self.dataOut.data_dc = self.data_dc
384 384
385 385 self.dataOut.flagNoData = False
386 386
387 387 self.dataOut.realtime = self.online
388 388
389 389 return self.dataOut.data_spc
390 390
391 391 class SpectraWriter(JRODataWriter, Operation):
392 392
393 393 """
394 394 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
395 395 de los datos siempre se realiza por bloques.
396 396 """
397 397
398 398 ext = ".pdata"
399 399
400 400 optchar = "P"
401 401
402 402 shape_spc_Buffer = None
403 403
404 404 shape_cspc_Buffer = None
405 405
406 406 shape_dc_Buffer = None
407 407
408 408 data_spc = None
409 409
410 410 data_cspc = None
411 411
412 412 data_dc = None
413 413
414 414 # dataOut = None
415 415
416 416 def __init__(self):
417 417 """
418 418 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
419 419
420 420 Affected:
421 421 self.dataOut
422 422 self.basicHeaderObj
423 423 self.systemHeaderObj
424 424 self.radarControllerHeaderObj
425 425 self.processingHeaderObj
426 426
427 427 Return: None
428 428 """
429 429
430 430 Operation.__init__(self)
431 431
432 432 self.isConfig = False
433 433
434 434 self.nTotalBlocks = 0
435 435
436 436 self.data_spc = None
437 437
438 438 self.data_cspc = None
439 439
440 440 self.data_dc = None
441 441
442 442 self.fp = None
443 443
444 444 self.flagIsNewFile = 1
445 445
446 446 self.nTotalBlocks = 0
447 447
448 448 self.flagIsNewBlock = 0
449 449
450 450 self.setFile = None
451 451
452 452 self.dtype = None
453 453
454 454 self.path = None
455 455
456 456 self.noMoreFiles = 0
457 457
458 458 self.filename = None
459 459
460 460 self.basicHeaderObj = BasicHeader(LOCALTIME)
461 461
462 462 self.systemHeaderObj = SystemHeader()
463 463
464 464 self.radarControllerHeaderObj = RadarControllerHeader()
465 465
466 466 self.processingHeaderObj = ProcessingHeader()
467 467
468 468
469 469 def hasAllDataInBuffer(self):
470 470 return 1
471 471
472 472
473 473 def setBlockDimension(self):
474 474 """
475 475 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
476 476
477 477 Affected:
478 478 self.shape_spc_Buffer
479 479 self.shape_cspc_Buffer
480 480 self.shape_dc_Buffer
481 481
482 482 Return: None
483 483 """
484 484 self.shape_spc_Buffer = (self.dataOut.nChannels,
485 485 self.processingHeaderObj.nHeights,
486 486 self.processingHeaderObj.profilesPerBlock)
487 487
488 488 self.shape_cspc_Buffer = (self.dataOut.nPairs,
489 489 self.processingHeaderObj.nHeights,
490 490 self.processingHeaderObj.profilesPerBlock)
491 491
492 492 self.shape_dc_Buffer = (self.dataOut.nChannels,
493 493 self.processingHeaderObj.nHeights)
494 494
495 495
496 496 def writeBlock(self):
497 497 """
498 498 Escribe el buffer en el file designado
499 499
500 500 Affected:
501 501 self.data_spc
502 502 self.data_cspc
503 503 self.data_dc
504 504 self.flagIsNewFile
505 505 self.flagIsNewBlock
506 506 self.nTotalBlocks
507 507 self.nWriteBlocks
508 508
509 509 Return: None
510 510 """
511 511
512 512 spc = numpy.transpose( self.data_spc, (0,2,1) )
513 513 if not( self.processingHeaderObj.shif_fft ):
514 514 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
515 515 data = spc.reshape((-1))
516 516 data = data.astype(self.dtype[0])
517 517 data.tofile(self.fp)
518 518
519 519 if self.data_cspc is not None:
520 520 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
521 521 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
522 522 if not( self.processingHeaderObj.shif_fft ):
523 523 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
524 524 data['real'] = cspc.real
525 525 data['imag'] = cspc.imag
526 526 data = data.reshape((-1))
527 527 data.tofile(self.fp)
528 528
529 529 if self.data_dc is not None:
530 530 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
531 531 dc = self.data_dc
532 532 data['real'] = dc.real
533 533 data['imag'] = dc.imag
534 534 data = data.reshape((-1))
535 535 data.tofile(self.fp)
536 536
537 537 # self.data_spc.fill(0)
538 538 #
539 539 # if self.data_dc is not None:
540 540 # self.data_dc.fill(0)
541 541 #
542 542 # if self.data_cspc is not None:
543 543 # self.data_cspc.fill(0)
544 544
545 545 self.flagIsNewFile = 0
546 546 self.flagIsNewBlock = 1
547 547 self.nTotalBlocks += 1
548 548 self.nWriteBlocks += 1
549 549 self.blockIndex += 1
550 550
551 551 # print "[Writing] Block = %d04" %self.blockIndex
552 552
553 553 def putData(self):
554 554 """
555 555 Setea un bloque de datos y luego los escribe en un file
556 556
557 557 Affected:
558 558 self.data_spc
559 559 self.data_cspc
560 560 self.data_dc
561 561
562 562 Return:
563 563 0 : Si no hay data o no hay mas files que puedan escribirse
564 564 1 : Si se escribio la data de un bloque en un file
565 565 """
566 566
567 567 if self.dataOut.flagNoData:
568 568 return 0
569 569
570 570 self.flagIsNewBlock = 0
571 571
572 572 if self.dataOut.flagDiscontinuousBlock:
573 573 self.data_spc.fill(0)
574 self.data_cspc.fill(0)
575 self.data_dc.fill(0)
574 if self.dataOut.data_cspc is not None:
575 self.data_cspc.fill(0)
576 if self.dataOut.data_dc is not None:
577 self.data_dc.fill(0)
576 578 self.setNextFile()
577 579
578 580 if self.flagIsNewFile == 0:
579 581 self.setBasicHeader()
580 582
581 583 self.data_spc = self.dataOut.data_spc.copy()
582 584
583 585 if self.dataOut.data_cspc is not None:
584 586 self.data_cspc = self.dataOut.data_cspc.copy()
585 587
586 588 if self.dataOut.data_dc is not None:
587 589 self.data_dc = self.dataOut.data_dc.copy()
588 590
589 591 # #self.processingHeaderObj.dataBlocksPerFile)
590 592 if self.hasAllDataInBuffer():
591 593 # self.setFirstHeader()
592 594 self.writeNextBlock()
593 595
594 596 return 1
595 597
596 598 def __getBlockSize(self):
597 599 '''
598 600 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
599 601 '''
600 602
601 603 dtype_width = self.getDtypeWidth()
602 604
603 605 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
604 606
605 607 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
606 608 blocksize = (pts2write_SelfSpectra*dtype_width)
607 609
608 610 if self.dataOut.data_cspc is not None:
609 611 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
610 612 blocksize += (pts2write_CrossSpectra*dtype_width*2)
611 613
612 614 if self.dataOut.data_dc is not None:
613 615 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
614 616 blocksize += (pts2write_DCchannels*dtype_width*2)
615 617
616 618 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
617 619
618 620 return blocksize
619 621
620 622 def setFirstHeader(self):
621 623
622 624 """
623 625 Obtiene una copia del First Header
624 626
625 627 Affected:
626 628 self.systemHeaderObj
627 629 self.radarControllerHeaderObj
628 630 self.dtype
629 631
630 632 Return:
631 633 None
632 634 """
633 635
634 636 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
635 637 self.systemHeaderObj.nChannels = self.dataOut.nChannels
636 638 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
637 639
638 640 self.processingHeaderObj.dtype = 1 # Spectra
639 641 self.processingHeaderObj.blockSize = self.__getBlockSize()
640 642 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
641 643 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
642 644 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
643 645 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
644 646 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
645 647 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
646 648 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
647 649
648 650 if self.processingHeaderObj.totalSpectra > 0:
649 651 channelList = []
650 652 for channel in range(self.dataOut.nChannels):
651 653 channelList.append(channel)
652 654 channelList.append(channel)
653 655
654 656 pairsList = []
655 657 if self.dataOut.nPairs > 0:
656 658 for pair in self.dataOut.pairsList:
657 659 pairsList.append(pair[0])
658 660 pairsList.append(pair[1])
659 661
660 662 spectraComb = channelList + pairsList
661 663 spectraComb = numpy.array(spectraComb, dtype="u1")
662 664 self.processingHeaderObj.spectraComb = spectraComb
663 665
664 666 if self.dataOut.code is not None:
665 667 self.processingHeaderObj.code = self.dataOut.code
666 668 self.processingHeaderObj.nCode = self.dataOut.nCode
667 669 self.processingHeaderObj.nBaud = self.dataOut.nBaud
668 670
669 671 if self.processingHeaderObj.nWindows != 0:
670 672 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
671 673 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
672 674 self.processingHeaderObj.nHeights = self.dataOut.nHeights
673 675 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
674 676
675 677 self.processingHeaderObj.processFlags = self.getProcessFlags()
676 678
677 679 self.setBasicHeader()
@@ -1,294 +1,294
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $
5 5 '''
6 6
7 7 class ProcessingUnit(object):
8
8
9 9 """
10 10 Esta es la clase base para el procesamiento de datos.
11
11
12 12 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
13 13 - Metodos internos (callMethod)
14 14 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
15 15 tienen que ser agreagados con el metodo "add".
16
16
17 17 """
18 18 # objeto de datos de entrada (Voltage, Spectra o Correlation)
19 19 dataIn = None
20 20 dataInList = []
21
21
22 22 # objeto de datos de entrada (Voltage, Spectra o Correlation)
23 23 dataOut = None
24
24
25 25 operations2RunDict = None
26
26
27 27 isConfig = False
28
29
28
29
30 30 def __init__(self):
31
31
32 32 self.dataIn = None
33 33 self.dataInList = []
34
34
35 35 self.dataOut = None
36
36
37 37 self.operations2RunDict = {}
38
38
39 39 self.isConfig = False
40
40
41 41 def addOperation(self, opObj, objId):
42
42
43 43 """
44 44 Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
45 identificador asociado a este objeto.
46
45 identificador asociado a este objeto.
46
47 47 Input:
48
48
49 49 object : objeto de la clase "Operation"
50
50
51 51 Return:
52
52
53 53 objId : identificador del objeto, necesario para ejecutar la operacion
54 54 """
55
55
56 56 self.operations2RunDict[objId] = opObj
57
57
58 58 return objId
59
59
60 60 def getOperationObj(self, objId):
61
61
62 62 if objId not in self.operations2RunDict.keys():
63 63 return None
64
64
65 65 return self.operations2RunDict[objId]
66
66
67 67 def operation(self, **kwargs):
68
68
69 69 """
70 70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 71 atributos del objeto dataOut
72
72
73 73 Input:
74
74
75 75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 76 """
77
77
78 78 raise NotImplementedError
79
79
80 80 def callMethod(self, name, **kwargs):
81
81
82 82 """
83 83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84
84
85 85 Input:
86 86 name : nombre del metodo a ejecutar
87
87
88 88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89
89
90 90 """
91
91
92 92 #Checking the inputs
93 93 if name == 'run':
94
94
95 95 if not self.checkInputs():
96 96 self.dataOut.flagNoData = True
97 97 return False
98 98 else:
99 99 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
100 100 if self.dataOut.isEmpty():
101 101 return False
102
102
103 103 #Getting the pointer to method
104 104 methodToCall = getattr(self, name)
105
105
106 106 #Executing the self method
107 107 methodToCall(**kwargs)
108
108
109 109 #Checkin the outputs
110
110
111 111 # if name == 'run':
112 112 # pass
113 113 # else:
114 114 # pass
115 #
115 #
116 116 # if name != 'run':
117 117 # return True
118
118
119 119 if self.dataOut is None:
120 120 return False
121
121
122 122 if self.dataOut.isEmpty():
123 123 return False
124
124
125 125 return True
126
126
127 127 def callObject(self, objId, **kwargs):
128
128
129 129 """
130 130 Ejecuta la operacion asociada al identificador del objeto "objId"
131
131
132 132 Input:
133
133
134 134 objId : identificador del objeto a ejecutar
135
135
136 136 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
137
137
138 138 Return:
139
140 None
139
140 None
141 141 """
142
142
143 143 if self.dataOut.isEmpty():
144 144 return False
145
145
146 146 externalProcObj = self.operations2RunDict[objId]
147
147
148 148 externalProcObj.run(self.dataOut, **kwargs)
149
149
150 150 return True
151
151
152 152 def call(self, opType, opName=None, opId=None, **kwargs):
153
153
154 154 """
155 155 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
156 156 identificada con el id "opId"; con los argumentos "**kwargs".
157
157
158 158 False si la operacion no se ha ejecutado.
159
159
160 160 Input:
161
161
162 162 opType : Puede ser "self" o "external"
163
163
164 164 Depende del tipo de operacion para llamar a:callMethod or callObject:
165
165
166 166 1. If opType = "self": Llama a un metodo propio de esta clase:
167
167
168 168 name_method = getattr(self, name)
169 169 name_method(**kwargs)
170
171
170
171
172 172 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
173 173 clase "Operation" o de un derivado de ella:
174
174
175 175 instanceName = self.operationList[opId]
176 176 instanceName.run(**kwargs)
177
177
178 178 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
179 179 usada para llamar a un metodo interno de la clase Processing
180
180
181 181 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
182 182 "opId" sera usada para llamar al metodo "run" de la clase Operation
183 183 registrada anteriormente con ese Id
184
184
185 185 Exception:
186 186 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
187 187 "addOperation" e identificado con el valor "opId" = el id de la operacion.
188 188 De lo contrario retornara un error del tipo ValueError
189
189
190 190 """
191
191
192 192 if opType == 'self':
193
193
194 194 if not opName:
195 195 raise ValueError, "opName parameter should be defined"
196
196
197 197 sts = self.callMethod(opName, **kwargs)
198
198
199 199 elif opType == 'other' or opType == 'external' or opType == 'plotter':
200
200
201 201 if not opId:
202 202 raise ValueError, "opId parameter should be defined"
203
203
204 204 if opId not in self.operations2RunDict.keys():
205 205 raise ValueError, "Any operation with id=%s has been added" %str(opId)
206
206
207 207 sts = self.callObject(opId, **kwargs)
208
208
209 209 else:
210 210 raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
211
212 return sts
213
211
212 return sts
213
214 214 def setInput(self, dataIn):
215
215
216 216 self.dataIn = dataIn
217 217 self.dataInList.append(dataIn)
218
218
219 219 def getOutputObj(self):
220
220
221 221 return self.dataOut
222
222
223 223 def checkInputs(self):
224 224
225 225 for thisDataIn in self.dataInList:
226
226
227 227 if thisDataIn.isEmpty():
228 228 return False
229
229
230 230 return True
231
231
232 232 def setup(self):
233
233
234 234 raise NotImplementedError
235
235
236 236 def run(self):
237
237
238 238 raise NotImplementedError
239
239
240 240 def close(self):
241 241 #Close every thread, queue or any other object here is it is neccesary.
242 242 return
243
243
244 244 class Operation(object):
245
245
246 246 """
247 247 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
248 248 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
249 249 acumulacion dentro de esta clase
250
250
251 251 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
252
252
253 253 """
254
254
255 255 __buffer = None
256 256 isConfig = False
257
257
258 258 def __init__(self):
259
259
260 260 self.__buffer = None
261 261 self.isConfig = False
262
262
263 263 def setup(self):
264
264
265 265 self.isConfig = True
266
266
267 267 raise NotImplementedError
268 268
269 269 def run(self, dataIn, **kwargs):
270
270
271 271 """
272 272 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
273 273 atributos del objeto dataIn.
274
274
275 275 Input:
276
276
277 277 dataIn : objeto del tipo JROData
278
278
279 279 Return:
280
280
281 281 None
282
282
283 283 Affected:
284 284 __buffer : buffer de recepcion de datos.
285
285
286 286 """
287 287 if not self.isConfig:
288 288 self.setup(**kwargs)
289
289
290 290 raise NotImplementedError
291
291
292 292 def close(self):
293
294 pass No newline at end of file
293
294 pass
@@ -1,343 +1,345
1 1 import numpy
2 2
3 3 from jroproc_base import ProcessingUnit, Operation
4 4 from schainpy.model.data.jrodata import SpectraHeis
5 5
6 6 class SpectraHeisProc(ProcessingUnit):
7 7
8 8 def __init__(self):
9 9
10 10 ProcessingUnit.__init__(self)
11 11
12 12 # self.buffer = None
13 13 # self.firstdatatime = None
14 14 # self.profIndex = 0
15 15 self.dataOut = SpectraHeis()
16 16
17 17 def __updateObjFromVoltage(self):
18 18
19 19 self.dataOut.timeZone = self.dataIn.timeZone
20 20 self.dataOut.dstFlag = self.dataIn.dstFlag
21 21 self.dataOut.errorCount = self.dataIn.errorCount
22 22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
23 23
24 24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
25 25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
26 26 self.dataOut.channelList = self.dataIn.channelList
27 27 self.dataOut.heightList = self.dataIn.heightList
28 28 # self.dataOut.dtype = self.dataIn.dtype
29 29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
30 30 # self.dataOut.nHeights = self.dataIn.nHeights
31 31 # self.dataOut.nChannels = self.dataIn.nChannels
32 32 self.dataOut.nBaud = self.dataIn.nBaud
33 33 self.dataOut.nCode = self.dataIn.nCode
34 34 self.dataOut.code = self.dataIn.code
35 35 # self.dataOut.nProfiles = 1
36 self.dataOut.ippFactor = 1
37 self.dataOut.noise_estimation = None
36 38 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
37 39 self.dataOut.nFFTPoints = self.dataIn.nHeights
38 40 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
39 41 # self.dataOut.flagNoData = self.dataIn.flagNoData
40 42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
41 43 self.dataOut.utctime = self.dataIn.utctime
42 44 # self.dataOut.utctime = self.firstdatatime
43 45 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
44 46 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
45 47 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
46 48 self.dataOut.nCohInt = self.dataIn.nCohInt
47 49 self.dataOut.nIncohInt = 1
48 50 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
49 51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
50 52
51 53 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
52 54 # self.dataOut.set=self.dataIn.set
53 55 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
54 56
55 57
56 58 def __updateObjFromFits(self):
57 59
58 60 self.dataOut.utctime = self.dataIn.utctime
59 61 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
60 62
61 63 self.dataOut.channelList = self.dataIn.channelList
62 64 self.dataOut.heightList = self.dataIn.heightList
63 65 self.dataOut.data_spc = self.dataIn.data
64 66 self.dataOut.ippSeconds = self.dataIn.ippSeconds
65 67 self.dataOut.nCohInt = self.dataIn.nCohInt
66 68 self.dataOut.nIncohInt = self.dataIn.nIncohInt
67 69 # self.dataOut.timeInterval = self.dataIn.timeInterval
68 70 self.dataOut.timeZone = self.dataIn.timeZone
69 71 self.dataOut.useLocalTime = True
70 72 # self.dataOut.
71 73 # self.dataOut.
72 74
73 75 def __getFft(self):
74 76
75 77 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
76 78 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
77 79 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
78 80 self.dataOut.data_spc = spc
79 81
80 82 def run(self):
81 83
82 84 self.dataOut.flagNoData = True
83 85
84 86 if self.dataIn.type == "Fits":
85 87 self.__updateObjFromFits()
86 88 self.dataOut.flagNoData = False
87 89 return
88 90
89 91 if self.dataIn.type == "SpectraHeis":
90 92 self.dataOut.copy(self.dataIn)
91 93 return
92 94
93 95 if self.dataIn.type == "Voltage":
94 96 self.__updateObjFromVoltage()
95 97 self.__getFft()
96 98 self.dataOut.flagNoData = False
97 99
98 100 return
99 101
100 102 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
101 103
102 104
103 105 def selectChannels(self, channelList):
104 106
105 107 channelIndexList = []
106 108
107 109 for channel in channelList:
108 110 index = self.dataOut.channelList.index(channel)
109 111 channelIndexList.append(index)
110 112
111 113 self.selectChannelsByIndex(channelIndexList)
112 114
113 115 def selectChannelsByIndex(self, channelIndexList):
114 116 """
115 117 Selecciona un bloque de datos en base a canales segun el channelIndexList
116 118
117 119 Input:
118 120 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
119 121
120 122 Affected:
121 123 self.dataOut.data
122 124 self.dataOut.channelIndexList
123 125 self.dataOut.nChannels
124 126 self.dataOut.m_ProcessingHeader.totalSpectra
125 127 self.dataOut.systemHeaderObj.numChannels
126 128 self.dataOut.m_ProcessingHeader.blockSize
127 129
128 130 Return:
129 131 None
130 132 """
131 133
132 134 for channelIndex in channelIndexList:
133 135 if channelIndex not in self.dataOut.channelIndexList:
134 136 print channelIndexList
135 137 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
136 138
137 139 # nChannels = len(channelIndexList)
138 140
139 141 data_spc = self.dataOut.data_spc[channelIndexList,:]
140 142
141 143 self.dataOut.data_spc = data_spc
142 144 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
143 145
144 146 return 1
145 147
146 148 class IncohInt4SpectraHeis(Operation):
147 149
148 150 isConfig = False
149 151
150 152 __profIndex = 0
151 153 __withOverapping = False
152 154
153 155 __byTime = False
154 156 __initime = None
155 157 __lastdatatime = None
156 158 __integrationtime = None
157 159
158 160 __buffer = None
159 161
160 162 __dataReady = False
161 163
162 164 n = None
163 165
164 166
165 167 def __init__(self):
166 168
167 169 Operation.__init__(self)
168 170 # self.isConfig = False
169 171
170 172 def setup(self, n=None, timeInterval=None, overlapping=False):
171 173 """
172 174 Set the parameters of the integration class.
173 175
174 176 Inputs:
175 177
176 178 n : Number of coherent integrations
177 179 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
178 180 overlapping :
179 181
180 182 """
181 183
182 184 self.__initime = None
183 185 self.__lastdatatime = 0
184 186 self.__buffer = None
185 187 self.__dataReady = False
186 188
187 189
188 190 if n == None and timeInterval == None:
189 191 raise ValueError, "n or timeInterval should be specified ..."
190 192
191 193 if n != None:
192 194 self.n = n
193 195 self.__byTime = False
194 196 else:
195 197 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
196 198 self.n = 9999
197 199 self.__byTime = True
198 200
199 201 if overlapping:
200 202 self.__withOverapping = True
201 203 self.__buffer = None
202 204 else:
203 205 self.__withOverapping = False
204 206 self.__buffer = 0
205 207
206 208 self.__profIndex = 0
207 209
208 210 def putData(self, data):
209 211
210 212 """
211 213 Add a profile to the __buffer and increase in one the __profileIndex
212 214
213 215 """
214 216
215 217 if not self.__withOverapping:
216 218 self.__buffer += data.copy()
217 219 self.__profIndex += 1
218 220 return
219 221
220 222 #Overlapping data
221 223 nChannels, nHeis = data.shape
222 224 data = numpy.reshape(data, (1, nChannels, nHeis))
223 225
224 226 #If the buffer is empty then it takes the data value
225 227 if self.__buffer is None:
226 228 self.__buffer = data
227 229 self.__profIndex += 1
228 230 return
229 231
230 232 #If the buffer length is lower than n then stakcing the data value
231 233 if self.__profIndex < self.n:
232 234 self.__buffer = numpy.vstack((self.__buffer, data))
233 235 self.__profIndex += 1
234 236 return
235 237
236 238 #If the buffer length is equal to n then replacing the last buffer value with the data value
237 239 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
238 240 self.__buffer[self.n-1] = data
239 241 self.__profIndex = self.n
240 242 return
241 243
242 244
243 245 def pushData(self):
244 246 """
245 247 Return the sum of the last profiles and the profiles used in the sum.
246 248
247 249 Affected:
248 250
249 251 self.__profileIndex
250 252
251 253 """
252 254
253 255 if not self.__withOverapping:
254 256 data = self.__buffer
255 257 n = self.__profIndex
256 258
257 259 self.__buffer = 0
258 260 self.__profIndex = 0
259 261
260 262 return data, n
261 263
262 264 #Integration with Overlapping
263 265 data = numpy.sum(self.__buffer, axis=0)
264 266 n = self.__profIndex
265 267
266 268 return data, n
267 269
268 270 def byProfiles(self, data):
269 271
270 272 self.__dataReady = False
271 273 avgdata = None
272 274 # n = None
273 275
274 276 self.putData(data)
275 277
276 278 if self.__profIndex == self.n:
277 279
278 280 avgdata, n = self.pushData()
279 281 self.__dataReady = True
280 282
281 283 return avgdata
282 284
283 285 def byTime(self, data, datatime):
284 286
285 287 self.__dataReady = False
286 288 avgdata = None
287 289 n = None
288 290
289 291 self.putData(data)
290 292
291 293 if (datatime - self.__initime) >= self.__integrationtime:
292 294 avgdata, n = self.pushData()
293 295 self.n = n
294 296 self.__dataReady = True
295 297
296 298 return avgdata
297 299
298 300 def integrate(self, data, datatime=None):
299 301
300 302 if self.__initime == None:
301 303 self.__initime = datatime
302 304
303 305 if self.__byTime:
304 306 avgdata = self.byTime(data, datatime)
305 307 else:
306 308 avgdata = self.byProfiles(data)
307 309
308 310
309 311 self.__lastdatatime = datatime
310 312
311 313 if avgdata is None:
312 314 return None, None
313 315
314 316 avgdatatime = self.__initime
315 317
316 318 deltatime = datatime -self.__lastdatatime
317 319
318 320 if not self.__withOverapping:
319 321 self.__initime = datatime
320 322 else:
321 323 self.__initime += deltatime
322 324
323 325 return avgdata, avgdatatime
324 326
325 327 def run(self, dataOut, **kwargs):
326 328
327 329 if not self.isConfig:
328 330 self.setup(**kwargs)
329 331 self.isConfig = True
330 332
331 333 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
332 334
333 335 # dataOut.timeInterval *= n
334 336 dataOut.flagNoData = True
335 337
336 338 if self.__dataReady:
337 339 dataOut.data_spc = avgdata
338 340 dataOut.nIncohInt *= self.n
339 341 # dataOut.nCohInt *= self.n
340 342 dataOut.utctime = avgdatatime
341 343 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
342 344 # dataOut.timeInterval = self.__timeInterval*self.n
343 345 dataOut.flagNoData = False No newline at end of file
@@ -1,8 +1,8
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: Processor.py 1 2012-11-12 18:56:07Z murco $
5 5 '''
6 6
7 7 from jroutils_ftp import *
8 from jroutils_publish import PublishData No newline at end of file
8 from jroutils_publish import *
@@ -1,102 +1,152
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
10 10 from schainpy.model.proc.jroproc_base import Operation
11 11
12
13 12 class PrettyFloat(float):
14 13 def __repr__(self):
15 14 return '%.2f' % self
16 15
16
17 17 def pretty_floats(obj):
18 18 if isinstance(obj, float):
19 19 return PrettyFloat(obj)
20 20 elif isinstance(obj, dict):
21 21 return dict((k, pretty_floats(v)) for k, v in obj.items())
22 22 elif isinstance(obj, (list, tuple)):
23 return map(pretty_floats, obj)
23 return map(pretty_floats, obj)
24 24 return obj
25 25
26
26 27 class PublishData(Operation):
27
28 """Clase publish."""
29
28 30 __MAXNUMX = 80
29 31 __MAXNUMY = 80
30
32
31 33 def __init__(self):
32
34 """Inicio."""
33 35 Operation.__init__(self)
34
35 36 self.isConfig = False
36 self.client = None
37
38 @staticmethod
39 def on_disconnect(client, userdata, rc):
37 self.client = None
38
39 def on_disconnect(self, client, userdata, rc):
40 40 if rc != 0:
41 print("Unexpected disconnection.")
42
43 def setup(self, host, port=1883, username=None, password=None, **kwargs):
44
45 self.client = mqtt.Client()
41 print("Unexpected disconnection.")
42 self.connect()
43
44 def connect(self):
45 print 'trying to connect'
46 46 try:
47 self.client.connect(host=host, port=port, keepalive=60*10, bind_address='')
47 self.client.connect(
48 host=self.host,
49 port=self.port,
50 keepalive=60*10,
51 bind_address='')
52 print "connected"
53 self.client.loop_start()
54 # self.client.publish(
55 # self.topic + 'SETUP',
56 # json.dumps(setup),
57 # retain=True
58 # )
48 59 except:
60 print "MQTT Conection error."
49 61 self.client = False
62
63 def setup(self, host, port=1883, username=None, password=None, **kwargs):
64
50 65 self.topic = kwargs.get('topic', 'schain')
51 66 self.delay = kwargs.get('delay', 0)
67 self.plottype = kwargs.get('plottype', 'spectra')
52 68 self.host = host
53 69 self.port = port
54 70 self.cnt = 0
55
56 def run(self, dataOut, host, datatype='data_spc', **kwargs):
57
58 if not self.isConfig:
71 setup = []
72 for plot in self.plottype:
73 setup.append({
74 'plot': plot,
75 'topic': self.topic + plot,
76 'title': getattr(self, plot + '_' + 'title', False),
77 'xlabel': getattr(self, plot + '_' + 'xlabel', False),
78 'ylabel': getattr(self, plot + '_' + 'ylabel', False),
79 'xrange': getattr(self, plot + '_' + 'xrange', False),
80 'yrange': getattr(self, plot + '_' + 'yrange', False),
81 'zrange': getattr(self, plot + '_' + 'zrange', False),
82 })
83 self.client = mqtt.Client(
84 client_id='jc'+self.topic + 'SCHAIN',
85 clean_session=True)
86 self.client.on_disconnect = self.on_disconnect
87 self.connect()
88
89 def publish_data(self, plottype):
90 data = getattr(self.dataOut, 'data_spc')
91 if plottype == 'spectra':
92 z = data/self.dataOut.normFactor
93 zdB = 10*numpy.log10(z)
94 xlen, ylen = zdB[0].shape
95 dx = numpy.floor(xlen/self.__MAXNUMX) + 1
96 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
97 Z = [0 for i in self.dataOut.channelList]
98 for i in self.dataOut.channelList:
99 Z[i] = zdB[i][::dx, ::dy].tolist()
100 payload = {
101 'timestamp': self.dataOut.utctime,
102 'data': pretty_floats(Z),
103 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
104 'interval': self.dataOut.getTimeInterval(),
105 'xRange': [0, 80]
106 }
107
108 elif plottype in ('rti', 'power'):
109 z = data/self.dataOut.normFactor
110 avg = numpy.average(z, axis=1)
111 avgdB = 10*numpy.log10(avg)
112 xlen, ylen = z[0].shape
113 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
114 AVG = [0 for i in self.dataOut.channelList]
115 for i in self.dataOut.channelList:
116 AVG[i] = avgdB[i][::dy].tolist()
117 payload = {
118 'timestamp': self.dataOut.utctime,
119 'data': pretty_floats(AVG),
120 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
121 'interval': self.dataOut.getTimeInterval(),
122 'xRange': [0, 80]
123 }
124 elif plottype == 'noise':
125 noise = self.dataOut.getNoise()/self.dataOut.normFactor
126 noisedB = 10*numpy.log10(noise)
127 payload = {
128 'timestamp': self.dataOut.utctime,
129 'data': pretty_floats(noisedB.reshape(-1, 1).tolist()),
130 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
131 'interval': self.dataOut.getTimeInterval(),
132 'xRange': [0, 80]
133 }
134
135 print 'Publishing data to {}'.format(self.host)
136 print '*************************'
137 self.client.publish(self.topic + plottype, json.dumps(payload), qos=0)
138
139
140 def run(self, dataOut, host, **kwargs):
141 self.dataOut = dataOut
142 if not self.isConfig:
59 143 self.setup(host, **kwargs)
60 144 self.isConfig = True
61
62 data = getattr(dataOut, datatype)
63
64 z = data/dataOut.normFactor
65 zdB = 10*numpy.log10(z)
66 avg = numpy.average(z, axis=1)
67 avgdB = 10*numpy.log10(avg)
68
69 xlen ,ylen = zdB[0].shape
70
71
72 dx = numpy.floor(xlen/self.__MAXNUMX) + 1
73 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
74
75 Z = [0 for i in dataOut.channelList]
76 AVG = [0 for i in dataOut.channelList]
77
78 for i in dataOut.channelList:
79 Z[i] = zdB[i][::dx, ::dy].tolist()
80 AVG[i] = avgdB[i][::dy].tolist()
81
82 payload = {'timestamp':dataOut.utctime,
83 'data':pretty_floats(Z),
84 'data_profile':pretty_floats(AVG),
85 'channels': ['Ch %s' % ch for ch in dataOut.channelList],
86 'interval': dataOut.getTimeInterval(),
87 }
88
89
90 #if self.cnt==self.interval and self.client:
91 print 'Publishing data to {}'.format(self.host)
92 self.client.publish(self.topic, json.dumps(payload), qos=0)
93 time.sleep(self.delay)
94 #self.cnt = 0
95 #else:
96 # self.cnt += 1
97
98
145
146 map(self.publish_data, self.plottype)
147 time.sleep(self.delay)
148
99 149 def close(self):
100
101 if self.client:
102 self.client.disconnect() No newline at end of file
150 if self.client:
151 self.client.loop_stop()
152 self.client.disconnect()
@@ -1,40 +1,44
1 1 '''
2 2 Created on Jul 16, 2014
3 3
4 4 @author: @author: Miguel Urco
5 5 '''
6 6
7 7 from schainpy import __version__
8 8 from setuptools import setup, Extension
9 9
10 10 setup(name="schainpy",
11 11 version=__version__,
12 12 description="Python tools to read, write and process Jicamarca data",
13 13 author="Miguel Urco",
14 14 author_email="miguel.urco@jro.igp.gob.pe",
15 15 url="http://jro.igp.gob.pe",
16 16 packages = {'schainpy',
17 17 'schainpy.model',
18 18 'schainpy.model.data',
19 19 'schainpy.model.graphics',
20 20 'schainpy.model.io',
21 21 'schainpy.model.proc',
22 22 'schainpy.model.serializer',
23 23 'schainpy.model.utils',
24 24 'schainpy.gui',
25 25 'schainpy.gui.figures',
26 26 'schainpy.gui.viewcontroller',
27 27 'schainpy.gui.viewer',
28 28 'schainpy.gui.viewer.windows'},
29 29 py_modules=[''],
30 30 package_data={'': ['schain.conf.template'],
31 31 'schainpy.gui.figures': ['*.png','*.jpg'],
32 32 },
33 33 include_package_data=False,
34 34 scripts =['schainpy/gui/schainGUI',
35 35 'schainpy/scripts/schain'],
36 install_requires=["numpy >= 1.6.0",
36 install_requires=[
37 37 "scipy >= 0.9.0",
38 "h5py >= 2.0.1",
38 39 "matplotlib >= 1.0.0",
40 "pyfits >= 2.0.0",
41 "numpy >= 1.6.0",
42 "paramiko",
39 43 ],
40 44 ) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now