##// END OF EJS Templates
Adicion del metodo saveFigure() para guardar archivos de imagen de la clase Figure(). Se modifica los xaxis se muestran en formato datetime, falta hacer ajustes en los ticks de acuerdo al intervalo [xmin, xmax]
Daniel Valdez -
r209:8c431837892b
parent child
Show More
@@ -1,673 +1,675
1 1 '''
2 2 Created on September , 2012
3 3 @author:
4 4 '''
5 5 from xml.etree.ElementTree import Element, SubElement, ElementTree
6 6 from xml.etree import ElementTree as ET
7 7 from xml.dom import minidom
8 8
9 9 import sys
10 10 import datetime
11 11 from model.jrodataIO import *
12 12 from model.jroprocessing import *
13 13 from model.jroplot import *
14 14
15 15 def prettify(elem):
16 16 """Return a pretty-printed XML string for the Element.
17 17 """
18 18 rough_string = ET.tostring(elem, 'utf-8')
19 19 reparsed = minidom.parseString(rough_string)
20 20 return reparsed.toprettyxml(indent=" ")
21 21
22 22 class ParameterConf():
23 23
24 24 id = None
25 25 name = None
26 26 value = None
27 27 format = None
28 28
29 29 ELEMENTNAME = 'Parameter'
30 30
31 31 def __init__(self):
32 32
33 33 self.format = 'str'
34 34
35 35 def getElementName(self):
36 36
37 37 return self.ELEMENTNAME
38 38
39 39 def getValue(self):
40 40
41 41 if self.format == 'list':
42 42 strList = self.value.split(',')
43 43 return strList
44 44
45 45 if self.format == 'intlist':
46 46 strList = self.value.split(',')
47 47 intList = [int(x) for x in strList]
48 48 return intList
49 49
50 50 if self.format == 'floatlist':
51 51 strList = self.value.split(',')
52 52 floatList = [float(x) for x in strList]
53 53 return floatList
54 54
55 55 if self.format == 'date':
56 56 strList = self.value.split('/')
57 57 intList = [int(x) for x in strList]
58 58 date = datetime.date(intList[0], intList[1], intList[2])
59 59 return date
60 60
61 61 if self.format == 'time':
62 62 strList = self.value.split(':')
63 63 intList = [int(x) for x in strList]
64 64 time = datetime.time(intList[0], intList[1], intList[2])
65 65 return time
66 66
67 67 func = eval(self.format)
68 68
69 69 return func(self.value)
70 70
71 71 def setup(self, id, name, value, format='str'):
72 72
73 73 self.id = id
74 74 self.name = name
75 75 self.value = str(value)
76 76 self.format = format
77 77
78 78 def makeXml(self, opElement):
79 79
80 80 parmElement = SubElement(opElement, self.ELEMENTNAME)
81 81 parmElement.set('id', str(self.id))
82 82 parmElement.set('name', self.name)
83 83 parmElement.set('value', self.value)
84 84 parmElement.set('format', self.format)
85 85
86 86 def readXml(self, parmElement):
87 87
88 88 self.id = parmElement.get('id')
89 89 self.name = parmElement.get('name')
90 90 self.value = parmElement.get('value')
91 91 self.format = parmElement.get('format')
92 92
93 93 def printattr(self):
94 94
95 95 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
96 96
97 97 class OperationConf():
98 98
99 99 id = None
100 100 name = None
101 101 priority = None
102 102 type = None
103 103
104 104 parmConfObjList = []
105 105
106 106 ELEMENTNAME = 'Operation'
107 107
108 108 def __init__(self):
109 109
110 110 id = 0
111 111 name = None
112 112 priority = None
113 113 type = 'self'
114 114
115 115
116 116 def __getNewId(self):
117 117
118 118 return int(self.id)*10 + len(self.parmConfObjList) + 1
119 119
120 120 def getElementName(self):
121 121
122 122 return self.ELEMENTNAME
123 123
124 124 def getParameterObjList(self):
125 125
126 126 return self.parmConfObjList
127 127
128 128 def setup(self, id, name, priority, type):
129 129
130 130 self.id = id
131 131 self.name = name
132 132 self.type = type
133 133 self.priority = priority
134 134
135 135 self.parmConfObjList = []
136 136
137 137 def addParameter(self, name, value, format='str'):
138 138
139 139 id = self.__getNewId()
140 140
141 141 parmConfObj = ParameterConf()
142 142 parmConfObj.setup(id, name, value, format)
143 143
144 144 self.parmConfObjList.append(parmConfObj)
145 145
146 146 return parmConfObj
147 147
148 148 def makeXml(self, upElement):
149 149
150 150 opElement = SubElement(upElement, self.ELEMENTNAME)
151 151 opElement.set('id', str(self.id))
152 152 opElement.set('name', self.name)
153 153 opElement.set('type', self.type)
154 154 opElement.set('priority', str(self.priority))
155 155
156 156 for parmConfObj in self.parmConfObjList:
157 157 parmConfObj.makeXml(opElement)
158 158
159 159 def readXml(self, opElement):
160 160
161 161 self.id = opElement.get('id')
162 162 self.name = opElement.get('name')
163 163 self.type = opElement.get('type')
164 164 self.priority = opElement.get('priority')
165 165
166 166 self.parmConfObjList = []
167 167
168 168 parmElementList = opElement.getiterator(ParameterConf().getElementName())
169 169
170 170 for parmElement in parmElementList:
171 171 parmConfObj = ParameterConf()
172 172 parmConfObj.readXml(parmElement)
173 173 self.parmConfObjList.append(parmConfObj)
174 174
175 175 def printattr(self):
176 176
177 177 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
178 178 self.id,
179 179 self.name,
180 180 self.type,
181 181 self.priority)
182 182
183 183 for parmConfObj in self.parmConfObjList:
184 184 parmConfObj.printattr()
185 185
186 186 def createObject(self):
187 187
188 188 if self.type == 'self':
189 189 raise ValueError, "This operation type cannot be created"
190 190
191 191 if self.type == 'other':
192 192 className = eval(self.name)
193 193 opObj = className()
194 194
195 195 return opObj
196 196
197 197 class ProcUnitConf():
198 198
199 199 id = None
200 200 name = None
201 201 datatype = None
202 202 inputId = None
203 203
204 204 opConfObjList = []
205 205
206 206 procUnitObj = None
207 207 opObjList = []
208 208
209 209 ELEMENTNAME = 'ProcUnit'
210 210
211 211 def __init__(self):
212 212
213 213 self.id = None
214 214 self.datatype = None
215 215 self.name = None
216 216 self.inputId = None
217 217
218 218 self.opConfObjList = []
219 219
220 220 self.procUnitObj = None
221 221 self.opObjDict = {}
222 222
223 223 def __getPriority(self):
224 224
225 225 return len(self.opConfObjList)+1
226 226
227 227 def __getNewId(self):
228 228
229 229 return int(self.id)*10 + len(self.opConfObjList) + 1
230 230
231 231 def getElementName(self):
232 232
233 233 return self.ELEMENTNAME
234 234
235 235 def getId(self):
236 236
237 237 return str(self.id)
238 238
239 239 def getInputId(self):
240 240
241 241 return str(self.inputId)
242 242
243 243 def getOperationObjList(self):
244 244
245 245 return self.opConfObjList
246 246
247 247 def getProcUnitObj(self):
248 248
249 249 return self.procUnitObj
250 250
251 251 def setup(self, id, name, datatype, inputId):
252 252
253 253 self.id = id
254 254 self.name = name
255 255 self.datatype = datatype
256 256 self.inputId = inputId
257 257
258 258 self.opConfObjList = []
259 259
260 260 self.addOperation(name='init', optype='self')
261 261
262 262 def addOperation(self, name, optype='self'):
263 263
264 264 id = self.__getNewId()
265 265 priority = self.__getPriority()
266 266
267 267 opConfObj = OperationConf()
268 268 opConfObj.setup(id, name=name, priority=priority, type=optype)
269 269
270 270 self.opConfObjList.append(opConfObj)
271 271
272 272 return opConfObj
273 273
274 274 def makeXml(self, procUnitElement):
275 275
276 276 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
277 277 upElement.set('id', str(self.id))
278 278 upElement.set('name', self.name)
279 279 upElement.set('datatype', self.datatype)
280 280 upElement.set('inputId', str(self.inputId))
281 281
282 282 for opConfObj in self.opConfObjList:
283 283 opConfObj.makeXml(upElement)
284 284
285 285 def readXml(self, upElement):
286 286
287 287 self.id = upElement.get('id')
288 288 self.name = upElement.get('name')
289 289 self.datatype = upElement.get('datatype')
290 290 self.inputId = upElement.get('inputId')
291 291
292 292 self.opConfObjList = []
293 293
294 294 opElementList = upElement.getiterator(OperationConf().getElementName())
295 295
296 296 for opElement in opElementList:
297 297 opConfObj = OperationConf()
298 298 opConfObj.readXml(opElement)
299 299 self.opConfObjList.append(opConfObj)
300 300
301 301 def printattr(self):
302 302
303 303 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
304 304 self.id,
305 305 self.name,
306 306 self.datatype,
307 307 self.inputId)
308 308
309 309 for opConfObj in self.opConfObjList:
310 310 opConfObj.printattr()
311 311
312 312 def createObjects(self):
313 313
314 314 className = eval(self.name)
315 315 procUnitObj = className()
316 316
317 317 for opConfObj in self.opConfObjList:
318 318
319 319 if opConfObj.type == 'self':
320 320 continue
321 321
322 322 opObj = opConfObj.createObject()
323 323
324 324 self.opObjDict[opConfObj.id] = opObj
325 325 procUnitObj.addOperation(opObj, opConfObj.id)
326 326
327 327 self.procUnitObj = procUnitObj
328 328
329 329 return procUnitObj
330 330
331 331 def run(self):
332 332
333 333 finalSts = False
334 334
335 335 for opConfObj in self.opConfObjList:
336 336
337 337 kwargs = {}
338 338 for parmConfObj in opConfObj.getParameterObjList():
339 339 kwargs[parmConfObj.name] = parmConfObj.getValue()
340 340
341 341 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
342 342 sts = self.procUnitObj.call(opConfObj, **kwargs)
343 343 finalSts = finalSts or sts
344 344
345 345 return finalSts
346 346
347 347 class ReadUnitConf(ProcUnitConf):
348 348
349 349 path = None
350 350 startDate = None
351 351 endDate = None
352 352 startTime = None
353 353 endTime = None
354 354 online = None
355 355 expLabel = None
356 356 delay = None
357 357
358 358 ELEMENTNAME = 'ReadUnit'
359 359
360 360 def __init__(self):
361 361
362 362 self.id = None
363 363 self.datatype = None
364 364 self.name = None
365 365 self.inputId = 0
366 366
367 367 self.opConfObjList = []
368 368 self.opObjList = []
369 369
370 370 def getElementName(self):
371 371
372 372 return self.ELEMENTNAME
373 373
374 374 def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60):
375 375
376 376 self.id = id
377 377 self.name = name
378 378 self.datatype = datatype
379 379
380 380 self.path = path
381 381 self.startDate = startDate
382 382 self.endDate = endDate
383 383 self.startTime = startTime
384 384 self.endTime = endTime
385 385 self.online = online
386 386 self.expLabel = expLabel
387 387 self.delay = delay
388 388
389 389 self.addRunOperation()
390 390
391 391 def addRunOperation(self):
392 392
393 393 opObj = self.addOperation(name = 'run', optype = 'self')
394 394
395 395 opObj.addParameter(name='path' , value=self.path, format='str')
396 396 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
397 397 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
398 398 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
399 399 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
400 400 opObj.addParameter(name='expLabel' , value=self.expLabel, format='str')
401 401 opObj.addParameter(name='online' , value=self.online, format='int')
402 402 opObj.addParameter(name='delay' , value=self.delay, format='float')
403 403
404 404 return opObj
405 405
406 406
407 407 class Controller():
408 408
409 409 id = None
410 410 name = None
411 411 description = None
412 412 # readUnitConfObjList = None
413 413 procUnitConfObjDict = None
414 414
415 415 ELEMENTNAME = 'Controller'
416 416
417 417 def __init__(self):
418 418
419 419 self.id = None
420 420 self.name = None
421 421 self.description = None
422 422
423 423 # self.readUnitConfObjList = []
424 424 self.procUnitConfObjDict = {}
425 425
426 426 def __getNewId(self):
427 427
428 428 id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1
429 429
430 430 return str(id)
431 431
432 432 def getElementName(self):
433 433
434 434 return self.ELEMENTNAME
435 435
436 436 def setup(self, id, name, description):
437 437
438 438 self.id = id
439 439 self.name = name
440 440 self.description = description
441 441
442 442 def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60):
443 443
444 444 id = self.__getNewId()
445 445 name = '%sReader' %(datatype)
446 446
447 447 readUnitConfObj = ReadUnitConf()
448 448 readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay)
449 449
450 450 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
451 451
452 452 return readUnitConfObj
453 453
454 454 def addProcUnit(self, datatype, inputId):
455 455
456 456 id = self.__getNewId()
457 457 name = '%sProc' %(datatype)
458 458
459 459 procUnitConfObj = ProcUnitConf()
460 460 procUnitConfObj.setup(id, name, datatype, inputId)
461 461
462 462 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
463 463
464 464 return procUnitConfObj
465 465
466 466 def makeXml(self):
467 467
468 468 projectElement = Element('Controller')
469 469 projectElement.set('id', str(self.id))
470 470 projectElement.set('name', self.name)
471 471 projectElement.set('description', self.description)
472 472
473 473 # for readUnitConfObj in self.readUnitConfObjList:
474 474 # readUnitConfObj.makeXml(projectElement)
475 475
476 476 for procUnitConfObj in self.procUnitConfObjDict.values():
477 477 procUnitConfObj.makeXml(projectElement)
478 478
479 479 self.projectElement = projectElement
480 480
481 481 def writeXml(self, filename):
482 482
483 483 self.makeXml()
484 484
485 485 print prettify(self.projectElement)
486 486
487 487 ElementTree(self.projectElement).write(filename, method='xml')
488 488
489 489 def readXml(self, filename):
490 490
491 491 #tree = ET.parse(filename)
492 492 self.projectElement = None
493 493 # self.readUnitConfObjList = []
494 494 self.procUnitConfObjDict = {}
495 495
496 496 self.projectElement = ElementTree().parse(filename)
497 497
498 498 self.project = self.projectElement.tag
499 499
500 500 self.id = self.projectElement.get('id')
501 501 self.name = self.projectElement.get('name')
502 502 self.description = self.projectElement.get('description')
503 503
504 504 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
505 505
506 506 for readUnitElement in readUnitElementList:
507 507 readUnitConfObj = ReadUnitConf()
508 508 readUnitConfObj.readXml(readUnitElement)
509 509
510 510 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
511 511
512 512 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
513 513
514 514 for procUnitElement in procUnitElementList:
515 515 procUnitConfObj = ProcUnitConf()
516 516 procUnitConfObj.readXml(procUnitElement)
517 517
518 518 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
519 519
520 520 def printattr(self):
521 521
522 522 print "Controller[%s]: name = %s, description = %s" %(self.id,
523 523 self.name,
524 524 self.description)
525 525
526 526 # for readUnitConfObj in self.readUnitConfObjList:
527 527 # readUnitConfObj.printattr()
528 528
529 529 for procUnitConfObj in self.procUnitConfObjDict.values():
530 530 procUnitConfObj.printattr()
531 531
532 532 def createObjects(self):
533 533
534 534 # for readUnitConfObj in self.readUnitConfObjList:
535 535 # readUnitConfObj.createObjects()
536 536
537 537 for procUnitConfObj in self.procUnitConfObjDict.values():
538 538 procUnitConfObj.createObjects()
539 539
540 540 def __connect(self, objIN, obj):
541 541
542 542 obj.setInput(objIN.getOutput())
543 543
544 544 def connectObjects(self):
545 545
546 546 for puConfObj in self.procUnitConfObjDict.values():
547 547
548 548 inputId = puConfObj.getInputId()
549 549
550 550 if int(inputId) == 0:
551 551 continue
552 552
553 553 puConfINObj = self.procUnitConfObjDict[inputId]
554 554
555 555 puObj = puConfObj.getProcUnitObj()
556 556 puINObj = puConfINObj.getProcUnitObj()
557 557
558 558 self.__connect(puINObj, puObj)
559 559
560 560 def run(self):
561 561
562 562 # for readUnitConfObj in self.readUnitConfObjList:
563 563 # readUnitConfObj.run()
564 564
565 565 while(True):
566 566
567 567 finalSts = False
568 568
569 569 for procUnitConfObj in self.procUnitConfObjDict.values():
570 570 #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
571 571 sts = procUnitConfObj.run()
572 572 finalSts = finalSts or sts
573 573
574 574 #If every process unit finished so end process
575 575 if not(finalSts):
576 576 print "Every process units have finished"
577 577 break
578 578
579 579 if __name__ == '__main__':
580 580
581 581 desc = "Segundo Test"
582 582 filename = "schain.xml"
583 583
584 584 controllerObj = Controller()
585 585
586 586 controllerObj.setup(id = '191', name='test01', description=desc)
587 587
588 588 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
589 589 path='/Users/dsuarez/Remote/IMAGING',
590 590 startDate='2011/03/20',
591 591 endDate='2012/12/31',
592 592 startTime='06:10:00',
593 593 endTime='23:59:59',
594 594 online=0)
595 595
596 596 opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks')
597 597
598 598 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
599 599
600 600 opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
601 601 opObj10.addParameter(name='channelList', value='0,1,2,4,6,7', format='intlist')
602 602
603 603 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
604 604 opObj11.addParameter(name='idfigure', value='1', format='int')
605 605 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
606 606 # opObj11.addParameter(name='zmin', value='70', format='int')
607 607 # opObj11.addParameter(name='zmax', value='90', format='int')
608 608 opObj11.addParameter(name='showprofile', value='0', format='int')
609 opObj11.addParameter(name='save', value='1', format='int')
610 opObj11.addParameter(name='filename', value='/Users/dsuarez/Pictures/SpectraPlot.png', format='str')
609 611
610 612 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
611 613 opObj11.addParameter(name='idfigure', value='10', format='int')
612 614 opObj11.addParameter(name='wintitle', value='RTI', format='str')
613 615 # opObj11.addParameter(name='zmin', value='70', format='int')
614 616 # opObj11.addParameter(name='zmax', value='90', format='int')
615 617 opObj11.addParameter(name='showprofile', value='0', format='int')
616 618
617 619 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
618 620 # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist')
619 621 #
620 622 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
621 623 # opObj12.addParameter(name='n', value='2', format='int')
622 624 #
623 625 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
624 626 # opObj11.addParameter(name='idfigure', value='2', format='int')
625 627 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
626 628 # opObj11.addParameter(name='zmin', value='70', format='int')
627 629 # opObj11.addParameter(name='zmax', value='90', format='int')
628 630 #
629 631 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
630 632 # opObj10.addParameter(name='channelList', value='2,6', format='intlist')
631 633 #
632 634 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
633 635 # opObj12.addParameter(name='n', value='2', format='int')
634 636 #
635 637 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
636 638 # opObj11.addParameter(name='idfigure', value='3', format='int')
637 639 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
638 640 # opObj11.addParameter(name='zmin', value='70', format='int')
639 641 # opObj11.addParameter(name='zmax', value='90', format='int')
640 642
641 643
642 644 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
643 645 # opObj12.addParameter(name='ncode', value='2', format='int')
644 646 # opObj12.addParameter(name='nbauds', value='8', format='int')
645 647 # opObj12.addParameter(name='code0', value='001110011', format='int')
646 648 # opObj12.addParameter(name='code1', value='001110011', format='int')
647 649
648 650
649 651
650 652 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId())
651 653 #
652 654 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
653 655 # opObj21.addParameter(name='n', value='2', format='int')
654 656 #
655 657 # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
656 658 # opObj11.addParameter(name='idfigure', value='4', format='int')
657 659 # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str')
658 660 # opObj11.addParameter(name='zmin', value='70', format='int')
659 661 # opObj11.addParameter(name='zmax', value='90', format='int')
660 662
661 663 print "Escribiendo el archivo XML"
662 664
663 665 controllerObj.writeXml(filename)
664 666
665 667 print "Leyendo el archivo XML"
666 668 controllerObj.readXml(filename)
667 669 #controllerObj.printattr()
668 670
669 671 controllerObj.createObjects()
670 672 controllerObj.connectObjects()
671 673 controllerObj.run()
672 674
673 675 No newline at end of file
@@ -1,256 +1,262
1 1 import numpy
2 2 import mpldriver
3 3
4 4
5 5 class Figure:
6 6
7 7 __driver = mpldriver
8 8 fig = None
9 9
10 10 idfigure = None
11 11 wintitle = None
12 12 width = None
13 13 height = None
14 14 nplots = None
15 15
16 16 axesObjList = []
17 17
18 18 WIDTH = None
19 19 HEIGHT = None
20 20
21 21 def __init__(self):
22 22
23 23 raise ValueError, "This method is not implemented"
24 24
25 25 def __del__(self):
26 26
27 27 self.__driver.closeFigure()
28 28
29 29 def getAxesObjList(self):
30 30
31 31 return self.axesObjList
32 32
33 33 def getSubplots(self):
34 34
35 35 raise ValueError, "Abstract method: This method should be defined"
36 36
37 37 def getScreenDim(self):
38 38
39 39 nrow, ncol = self.getSubplots()
40 40
41 41 width = self.WIDTH*ncol
42 42 height = self.HEIGHT*nrow
43 43
44 44 return width, height
45 45
46 46 def init(self, idfigure, nplots, wintitle):
47 47
48 48 raise ValueError, "This method has been replaced with createFigure"
49 49
50 50 def createFigure(self, idfigure, wintitle):
51 51
52 52 """
53 53 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
54 54 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
55 55 y self.HEIGHT y el numero de subplots (nrow, ncol)
56 56
57 57 Input:
58 58 idfigure : Los parametros necesarios son
59 59 wintitle :
60 60
61 61 """
62 62
63 63 self.idfigure = idfigure
64 64
65 65 self.wintitle = wintitle
66 66
67 67 self.width, self.height = self.getScreenDim()
68 68
69 69 self.fig = self.__driver.createFigure(self.idfigure,
70 70 self.wintitle,
71 71 self.width,
72 72 self.height)
73 73
74 74 self.axesObjList = []
75 75
76 76 def setDriver(self, driver=mpldriver):
77 77
78 78 self.__driver = driver
79 79
80 80 def setTitle(self, title):
81 81
82 82 self.__driver.setTitle(self.fig, title)
83 83
84 84 def setWinTitle(self, title):
85 85
86 86 self.__driver.setWinTitle(self.fig, title=title)
87 87
88 88 def setTextFromAxes(self, text):
89 89
90 90 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
91 91
92 92 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
93 93
94 94 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
95 95
96 96 def addAxes(self, *args):
97 97 """
98 98
99 99 Input:
100 100 *args : Los parametros necesarios son
101 101 nrow, ncol, xpos, ypos, colspan, rowspan
102 102 """
103 103
104 104 axesObj = Axes(self.fig, *args)
105 105 self.axesObjList.append(axesObj)
106 106
107 def saveFigure(self, *args):
108 self.__driver.saveFigure(self.fig, *args)
109
107 110 def draw(self):
108 111
109 112 self.__driver.draw(self.fig)
110 113
111 114 def run(self):
112 115
113 116 raise ValueError, "This method is not implemented"
114 117
115 118 axesList = property(getAxesObjList)
116 119
117 120
118 121 class Axes:
119 122
120 123 __driver = mpldriver
121 124 fig = None
122 125 ax = None
123 126 plot = None
124 127
125 128 firsttime = None
126 129
127 130 __showprofile = False
128 131
129 132 __zmin = None
130 133 __zmax = None
131 134
132 135 def __init__(self, *args):
133 136
134 137 """
135 138
136 139 Input:
137 140 *args : Los parametros necesarios son
138 141 fig, nrow, ncol, xpos, ypos, colspan, rowspan
139 142 """
140 143
141 144 ax = self.__driver.createAxes(*args)
142 145 self.fig = args[0]
143 146 self.ax = ax
144 147 self.plot = None
145 148
146 149 self.firsttime = True
147 150
148 151 def setText(self, text):
149 152
150 153 self.__driver.setAxesText(self.ax, text)
151 154
155 def setXAxisAsTime(self):
156 pass
157
152 158 def pline(self, x, y,
153 159 xmin=None, xmax=None,
154 160 ymin=None, ymax=None,
155 161 xlabel='', ylabel='',
156 162 title='',
157 163 **kwargs):
158 164
159 165 """
160 166
161 167 Input:
162 168 x :
163 169 y :
164 170 xmin :
165 171 xmax :
166 172 ymin :
167 173 ymax :
168 174 xlabel :
169 175 ylabel :
170 176 title :
171 177 **kwargs : Los parametros aceptados son
172 178
173 179 ticksize
174 180 ytick_visible
175 181 """
176 182
177 183 if self.firsttime:
178 184
179 185 if xmin == None: xmin = numpy.nanmin(x)
180 186 if xmax == None: xmax = numpy.nanmax(x)
181 187 if ymin == None: ymin = numpy.nanmin(y)
182 188 if ymax == None: ymax = numpy.nanmax(y)
183 189
184 190 self.plot = self.__driver.createPline(self.ax, x, y,
185 191 xmin, xmax,
186 192 ymin, ymax,
187 193 xlabel=xlabel,
188 194 ylabel=ylabel,
189 195 title=title,
190 196 **kwargs)
191 197 self.firsttime = False
192 198 return
193 199
194 200 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
195 201 ylabel=ylabel,
196 202 title=title)
197 203
198 204
199 205 def pcolor(self, x, y, z,
200 206 xmin=None, xmax=None,
201 207 ymin=None, ymax=None,
202 208 zmin=None, zmax=None,
203 209 xlabel='', ylabel='',
204 210 title='', rti = False,
205 211 **kwargs):
206 212
207 213 """
208 214 Input:
209 215 x :
210 216 y :
211 217 x :
212 218 xmin :
213 219 xmax :
214 220 ymin :
215 221 ymax :
216 222 zmin :
217 223 zmax :
218 224 xlabel :
219 225 ylabel :
220 226 title :
221 227 **kwargs : Los parametros aceptados son
222 228 ticksize=9,
223 229 cblabel=''
224 230 rti = True or False
225 231 """
226 232
227 233 if self.firsttime:
228 234
229 235 if xmin == None: xmin = numpy.nanmin(x)
230 236 if xmax == None: xmax = numpy.nanmax(x)
231 237 if ymin == None: ymin = numpy.nanmin(y)
232 238 if ymax == None: ymax = numpy.nanmax(y)
233 239 if zmin == None: zmin = numpy.nanmin(z)
234 240 if zmax == None: zmax = numpy.nanmax(z)
235 241
236 242
237 243 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
238 244 xmin, xmax,
239 245 ymin, ymax,
240 246 zmin, zmax,
241 247 xlabel=xlabel,
242 248 ylabel=ylabel,
243 249 title=title,
244 250 **kwargs)
245 251 self.firsttime = False
246 252 if self.__zmin == None: self.__zmin = zmin
247 253 if self.__zmax == None: self.__zmax = zmax
248 254 return
249 255
250 256 if rti:
251 257 self.__driver.addpcolor(self.ax, x, y, z, self.__zmin, self.__zmax)
252 258 return
253 259
254 260 self.__driver.pcolor(self.plot, z, xlabel=xlabel, ylabel=ylabel, title=title)
255 261
256 262 No newline at end of file
@@ -1,250 +1,272
1 1 import numpy
2 import datetime
2 3 import matplotlib
3 4 matplotlib.use("TKAgg")
4 5 import matplotlib.pyplot
6 import matplotlib.dates
5 7 #import scitools.numpyutils
6 8 from mpl_toolkits.axes_grid1 import make_axes_locatable
7 9
10 from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter
11
8 12 def init(idfigure, wintitle, width, height, facecolor="w"):
9 13
10 14 matplotlib.pyplot.ioff()
11 15 fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
12 16 fig.canvas.manager.set_window_title(wintitle)
13 17 fig.canvas.manager.resize(width, height)
14 18 matplotlib.pyplot.ion()
15 19
16 20 return fig
17 21
18 22 def setWinTitle(fig, title):
19 23
20 24 fig.canvas.manager.set_window_title(title)
21 25
22 26 def setTitle(idfigure, title):
23 27 fig = matplotlib.pyplot.figure(idfigure)
24 28 fig.suptitle(title)
25 29
26 30 def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan):
27 31 fig = matplotlib.pyplot.figure(idfigure)
28 32 ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan)
29 33 return ax
30 34
31 35 def setTextFromAxes(idfigure, ax, title):
32 36 fig = matplotlib.pyplot.figure(idfigure)
33 37 ax.annotate(title, xy=(.1, .99),
34 38 xycoords='figure fraction',
35 39 horizontalalignment='left', verticalalignment='top',
36 40 fontsize=10)
37 41
38 42 def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime):
39 43
40 44 if firsttime:
41 45 ax.plot(x, y)
42 46 ax.set_xlim([xmin,xmax])
43 47 ax.set_ylim([ymin,ymax])
44 48 ax.set_xlabel(xlabel, size=8)
45 49 ax.set_ylabel(ylabel, size=8)
46 50 ax.set_title(title, size=10)
47 51 matplotlib.pyplot.tight_layout()
48 52 else:
49 53 ax.lines[0].set_data(x,y)
50 54
51 55 def draw(idfigure):
52 56
53 57 fig = matplotlib.pyplot.figure(idfigure)
54 58 fig.canvas.draw()
55 59
56 60 def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh):
57 61
58 62 if firsttime:
59 63 divider = make_axes_locatable(ax)
60 64 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
61 65 fig1 = ax.get_figure()
62 66 fig1.add_axes(ax_cb)
63 67
64 68 ax.set_xlim([xmin,xmax])
65 69 ax.set_ylim([ymin,ymax])
66 70 ax.set_xlabel(xlabel)
67 71 ax.set_ylabel(ylabel)
68 72 ax.set_title(title)
69 73 print x
70 74 imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
71 75 matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
72 76 ax_cb.yaxis.tick_right()
73 77 for tl in ax_cb.get_yticklabels():
74 78 tl.set_visible(True)
75 79 ax_cb.yaxis.tick_right()
76 80 matplotlib.pyplot.tight_layout()
77 81 return imesh
78 82 else:
79 83 # ax.set_xlim([xmin,xmax])
80 84 # ax.set_ylim([ymin,ymax])
81 85 ax.set_xlabel(xlabel)
82 86 ax.set_ylabel(ylabel)
83 87 ax.set_title(title)
84 88
85 89 z = z.T
86 90 # z = z[0:-1,0:-1]
87 91 mesh.set_array(z.ravel())
88 92
89 93 return mesh
90 94
91 95 ###########################################
92 96 #Actualizacion de las funciones del driver
93 97 ###########################################
94 98
95 99 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
96 100
97 101 matplotlib.pyplot.ioff()
98 102 fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
99 103 fig.canvas.manager.set_window_title(wintitle)
100 104 fig.canvas.manager.resize(width, height)
101 105 matplotlib.pyplot.ion()
102 106
103 107 return fig
104 108
105 109 def closeFigure():
106 110
107 111 matplotlib.pyplot.ioff()
108 112 matplotlib.pyplot.show()
109 113
110 114 return
111 115
116 def saveFigure(fig, filename):
117 fig.savefig(filename)
118
112 119 def setWinTitle(fig, title):
113 120
114 121 fig.canvas.manager.set_window_title(title)
115 122
116 123 def setTitle(fig, title):
117 124
118 125 fig.suptitle(title)
119 126
120 127 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
121 128
122 129 matplotlib.pyplot.figure(fig.number)
123 130 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
124 131 (xpos, ypos),
125 132 colspan=colspan,
126 133 rowspan=rowspan)
127 134 return axes
128 135
129 136 def setAxesText(ax, text):
130 137
131 138 ax.annotate(text,
132 139 xy = (.1, .99),
133 140 xycoords = 'figure fraction',
134 141 horizontalalignment = 'left',
135 142 verticalalignment = 'top',
136 143 fontsize = 10)
137 144
138 145 def printLabels(ax, xlabel, ylabel, title):
139 146
140 147 ax.set_xlabel(xlabel, size=11)
141 148 ax.set_ylabel(ylabel, size=11)
142 149 ax.set_title(title, size=12)
143 150
144 151 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
145 152 ticksize=9, xtick_visible=True, ytick_visible=True,
146 153 nxticks=4, nyticks=10,
147 154 grid=None):
148 155
149 156 """
150 157
151 158 Input:
152 159 grid : None, 'both', 'x', 'y'
153 160 """
154 161
155 162 ax.plot(x, y)
156 163 ax.set_xlim([xmin,xmax])
157 164 ax.set_ylim([ymin,ymax])
158 165
159 166 printLabels(ax, xlabel, ylabel, title)
160 167
161 168 ######################################################
162 169 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin)
163 170 ax.set_xticks(xtickspos)
164 171
165 172 for tick in ax.get_xticklabels():
166 173 tick.set_visible(xtick_visible)
167 174
168 175 for tick in ax.xaxis.get_major_ticks():
169 176 tick.label.set_fontsize(ticksize)
170 177
171 178 ######################################################
172 179 for tick in ax.get_yticklabels():
173 180 tick.set_visible(ytick_visible)
174 181
175 182 for tick in ax.yaxis.get_major_ticks():
176 183 tick.label.set_fontsize(ticksize)
177 184
178 185 ######################################################
179 186 if grid != None:
180 187 ax.grid(b=True, which='major', axis=grid)
181 188
182 189 matplotlib.pyplot.tight_layout()
183 190
184 191 iplot = ax.lines[-1]
185 192
186 193 return iplot
187 194
188 195 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
189 196
190 197 ax = iplot.get_axes()
191 198
192 199 printLabels(ax, xlabel, ylabel, title)
193 200
194 201 iplot.set_data(x, y)
195 202
196 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''):
203 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel='',XAxisAsTime=False):
197 204
198 205 divider = make_axes_locatable(ax)
199 206 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
200 207 fig = ax.get_figure()
201 208 fig.add_axes(ax_cb)
202 209
203 210 ax.set_xlim([xmin,xmax])
211
212 if XAxisAsTime:
213 seconds = numpy.array([xmin, xmax])
214 datesList = map(datetime.datetime.fromtimestamp, seconds)
215 ax.set_xlim([datesList[0],datesList[-1]])
216 ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10)))
217 ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60)))
218 ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S"))
219 xdateList = map(datetime.datetime.fromtimestamp, x)
220 xdate = matplotlib.dates.date2num(xdateList)
221 x = xdate
222
223
204 224 ax.set_ylim([ymin,ymax])
205 225
206 226 printLabels(ax, xlabel, ylabel, title)
207 227
208 228 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
209 229 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
210 230 cb.set_label(cblabel)
211 231
212 232 ax_cb.yaxis.tick_right()
213 233
214 234 for tl in ax_cb.get_yticklabels():
215 235 tl.set_visible(True)
216 236
217 237 for tick in ax.yaxis.get_major_ticks():
218 238 tick.label.set_fontsize(ticksize)
219 239
220 240 for tick in ax.xaxis.get_major_ticks():
221 241 tick.label.set_fontsize(ticksize)
222 242
223 243 for tick in cb.ax.get_yticklabels():
224 244 tick.set_fontsize(ticksize)
225 245
226 246 ax_cb.yaxis.tick_right()
227 247 matplotlib.pyplot.tight_layout()
228 248
229 249 return imesh
230 250
231 251 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
232 252
233 253 z = z.T
234 254
235 255 ax = imesh.get_axes()
236 256
237 257 printLabels(ax, xlabel, ylabel, title)
238 258
239 259 imesh.set_array(z.ravel())
240 260
241 261 def addpcolor(ax, x, y, z, zmin, zmax):
262 xdateList = map(datetime.datetime.fromtimestamp, x)
263 xdate = matplotlib.dates.date2num(xdateList)
242 264
243 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
265 imesh = ax.pcolormesh(xdate,y,z.T,vmin=zmin,vmax=zmax)
244 266
245 267 def draw(fig):
246 268
247 269 if type(fig) == 'int':
248 270 raise ValueError, "This parameter should be of tpye matplotlib figure"
249 271
250 272 fig.canvas.draw() No newline at end of file
@@ -1,364 +1,371
1 1 import numpy
2 2 import datetime
3 3 from graphics.figure import *
4 4
5 5 class RTIPlot(Figure):
6 6
7 7 __isConfig = None
8 8 __nsubplots = None
9 9
10 10 WIDTHPROF = None
11 11 HEIGHTPROF = None
12 12
13 13 def __init__(self):
14 14
15 15 self.__timerange = 30*60
16 16 self.__isConfig = False
17 17 self.__nsubplots = 1
18 18
19 19 self.WIDTH = 800
20 20 self.HEIGHT = 400
21 21 self.WIDTHPROF = 120
22 22 self.HEIGHTPROF = 0
23 23
24 24 def getSubplots(self):
25 25
26 26 ncol = 1
27 27 nrow = self.nplots
28 28
29 29 return nrow, ncol
30 30
31 31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
32 32
33 33 self.__showprofile = showprofile
34 34 self.nplots = nplots
35 35
36 36 ncolspan = 1
37 37 colspan = 1
38 38 if showprofile:
39 39 ncolspan = 7
40 40 colspan = 6
41 41 self.__nsubplots = 2
42 42 self.WIDTH += self.WIDTHPROF
43 43 self.HEIGHT += self.HEIGHTPROF
44 44
45 45 self.createFigure(idfigure, wintitle)
46 46
47 47 nrow, ncol = self.getSubplots()
48 48
49 49 counter = 0
50 50 for y in range(nrow):
51 51 for x in range(ncol):
52 52
53 53 if counter >= self.nplots:
54 54 break
55 55
56 56 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
57 57
58 58 if showprofile:
59 59 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
60 60
61 61 counter += 1
62 62
63 63 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
64 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
64 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
65 65
66 66 """
67 67
68 68 Input:
69 69 dataOut :
70 70 idfigure :
71 71 wintitle :
72 72 channelList :
73 73 showProfile :
74 74 xmin : None,
75 75 xmax : None,
76 76 ymin : None,
77 77 ymax : None,
78 78 zmin : None,
79 79 zmax : None
80 80 """
81 81
82 82 if channelList == None:
83 83 channelIndexList = dataOut.channelIndexList
84 84 else:
85 85 channelIndexList = []
86 86 for channel in channelList:
87 87 if channel not in dataOut.channelList:
88 88 raise ValueError, "Channel %d is not in dataOut.channelList"
89 89 channelIndexList.append(channel)
90 90
91 91 x = dataOut.getDatatime()
92 92 y = dataOut.getHeiRange()
93 93 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
94 94 avg = numpy.average(z, axis=1)
95 95
96 96 noise = dataOut.getNoise()
97 97
98 98 if not self.__isConfig:
99 99
100 100 nplots = len(channelIndexList)
101 101
102 102 self.setup(idfigure=idfigure,
103 103 nplots=nplots,
104 104 wintitle=wintitle,
105 105 showprofile=showprofile)
106 106
107 107 if xmin == None: xmin = numpy.min(x)
108 108 if xmax == None: xmax = xmin + self.__timerange
109 109 if ymin == None: ymin = numpy.nanmin(y)
110 110 if ymax == None: ymax = numpy.nanmax(y)
111 111 if zmin == None: zmin = numpy.nanmin(avg)*0.9
112 112 if zmax == None: zmax = numpy.nanmax(avg)*0.9
113 113
114 114 self.__isConfig = True
115 115
116 116 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
117 117 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
118 118 xlabel = "Velocity (m/s)"
119 119 ylabel = "Range (Km)"
120 120
121 121 self.setWinTitle(title)
122 122
123 123 for i in range(self.nplots):
124 124 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
125 125 axes = self.axesList[i*self.__nsubplots]
126 126 z = avg[i].reshape((1,-1))
127 127 axes.pcolor(x, y, z,
128 128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
129 xlabel=xlabel, ylabel=ylabel, title=title, rti=True,
129 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
130 130 ticksize=9, cblabel='')
131 131
132 132 if self.__showprofile:
133 133 axes = self.axesList[i*self.__nsubplots +1]
134 134 axes.pline(avg[i], y,
135 135 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
136 136 xlabel='dB', ylabel='', title='',
137 137 ytick_visible=False,
138 138 grid='x')
139 139
140 140 self.draw()
141 141
142 if save:
143 self.saveFigure(filename)
144
142 145 class SpectraPlot(Figure):
143 146
144 147 __isConfig = None
145 148 __nsubplots = None
146 149
147 150 WIDTHPROF = None
148 151 HEIGHTPROF = None
149 152
150 153 def __init__(self):
151 154
152 155 self.__isConfig = False
153 156 self.__nsubplots = 1
154 157
155 158 self.WIDTH = 300
156 159 self.HEIGHT = 400
157 160 self.WIDTHPROF = 120
158 161 self.HEIGHTPROF = 0
159 162
160 163 def getSubplots(self):
161 164
162 165 ncol = int(numpy.sqrt(self.nplots)+0.9)
163 166 nrow = int(self.nplots*1./ncol + 0.9)
164 167
165 168 return nrow, ncol
166 169
167 170 def setup(self, idfigure, nplots, wintitle, showprofile=True):
168 171
169 172 self.__showprofile = showprofile
170 173 self.nplots = nplots
171 174
172 175 ncolspan = 1
173 176 colspan = 1
174 177 if showprofile:
175 178 ncolspan = 3
176 179 colspan = 2
177 180 self.__nsubplots = 2
178 181 self.WIDTH += self.WIDTHPROF
179 182 self.HEIGHT += self.HEIGHTPROF
180 183
181 184 self.createFigure(idfigure, wintitle)
182 185
183 186 nrow, ncol = self.getSubplots()
184 187
185 188 counter = 0
186 189 for y in range(nrow):
187 190 for x in range(ncol):
188 191
189 192 if counter >= self.nplots:
190 193 break
191 194
192 195 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
193 196
194 197 if showprofile:
195 198 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
196 199
197 200 counter += 1
198 201
199 202 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
200 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
203 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
201 204
202 205 """
203 206
204 207 Input:
205 208 dataOut :
206 209 idfigure :
207 210 wintitle :
208 211 channelList :
209 212 showProfile :
210 213 xmin : None,
211 214 xmax : None,
212 215 ymin : None,
213 216 ymax : None,
214 217 zmin : None,
215 218 zmax : None
216 219 """
217 220
218 221 if channelList == None:
219 222 channelIndexList = dataOut.channelIndexList
220 223 else:
221 224 channelIndexList = []
222 225 for channel in channelList:
223 226 if channel not in dataOut.channelList:
224 227 raise ValueError, "Channel %d is not in dataOut.channelList"
225 228 channelIndexList.append(channel)
226 229
227 230 x = dataOut.getVelRange(1)
228 231 y = dataOut.getHeiRange()
229 232 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
230 233 avg = numpy.average(z, axis=1)
231 234
232 235 noise = dataOut.getNoise()
233 236
234 237 if not self.__isConfig:
235 238
236 239 nplots = len(channelIndexList)
237 240
238 241 self.setup(idfigure=idfigure,
239 242 nplots=nplots,
240 243 wintitle=wintitle,
241 244 showprofile=showprofile)
242 245
243 246 if xmin == None: xmin = numpy.nanmin(x)
244 247 if xmax == None: xmax = numpy.nanmax(x)
245 248 if ymin == None: ymin = numpy.nanmin(y)
246 249 if ymax == None: ymax = numpy.nanmax(y)
247 250 if zmin == None: zmin = numpy.nanmin(avg)*0.9
248 251 if zmax == None: zmax = numpy.nanmax(avg)*0.9
249 252
250 253 self.__isConfig = True
251 254
252 255 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
253 256 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
254 257 xlabel = "Velocity (m/s)"
255 258 ylabel = "Range (Km)"
256 259
257 260 self.setWinTitle(title)
258 261
259 262 for i in range(self.nplots):
260 263 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
261 264 axes = self.axesList[i*self.__nsubplots]
262 265 axes.pcolor(x, y, z[i,:,:],
263 266 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
264 267 xlabel=xlabel, ylabel=ylabel, title=title,
265 268 ticksize=9, cblabel='')
266 269
267 270 if self.__showprofile:
268 271 axes = self.axesList[i*self.__nsubplots +1]
269 272 axes.pline(avg[i], y,
270 273 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
271 274 xlabel='dB', ylabel='', title='',
272 275 ytick_visible=False,
273 276 grid='x')
274 277
275 278 self.draw()
279
280 if save:
281 self.saveFigure(filename)
276 282
277 283 class Scope(Figure):
278 284
279 285 __isConfig = None
280 286
281 287 def __init__(self):
282 288
283 289 self.__isConfig = False
284 290 self.WIDTH = 600
285 291 self.HEIGHT = 200
286 292
287 293 def getSubplots(self):
288 294
289 295 nrow = self.nplots
290 296 ncol = 3
291 297 return nrow, ncol
292 298
293 299 def setup(self, idfigure, nplots, wintitle):
294 300
295 301 self.createFigure(idfigure, wintitle)
296 302
297 303 nrow,ncol = self.getSubplots()
298 304 colspan = 3
299 305 rowspan = 1
300 306
301 307 for i in range(nplots):
302 308 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
303 309
304 310 self.nplots = nplots
305 311
306 312 def run(self, dataOut, idfigure, wintitle="", channelList=None,
307 xmin=None, xmax=None, ymin=None, ymax=None):
313 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
308 314
309 315 """
310 316
311 317 Input:
312 318 dataOut :
313 319 idfigure :
314 320 wintitle :
315 321 channelList :
316 322 xmin : None,
317 323 xmax : None,
318 324 ymin : None,
319 325 ymax : None,
320 326 """
321 327
322 328 if channelList == None:
323 329 channelList = dataOut.channelList
324 330
325 331 x = dataOut.heightList
326 332 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
327 333 y = y.real
328 334
329 335 noise = dataOut.getNoise()
330 336
331 337 if not self.__isConfig:
332 338 nplots = len(channelList)
333 339
334 340 self.setup(idfigure=idfigure,
335 341 nplots=nplots,
336 342 wintitle=wintitle)
337 343
338 344 if xmin == None: xmin = numpy.nanmin(x)
339 345 if xmax == None: xmax = numpy.nanmax(x)
340 346 if ymin == None: ymin = numpy.nanmin(y)
341 347 if ymax == None: ymax = numpy.nanmax(y)
342 348
343 349 self.__isConfig = True
344 350
345 351
346 352 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
347 353 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
348 354 xlabel = "Range (Km)"
349 355 ylabel = "Intensity"
350 356
351 357 self.setWinTitle(title)
352 358
353 359 for i in range(len(self.axesList)):
354 360 title = "Channel %d: %4.2fdB" %(i, noise[i])
355 361 axes = self.axesList[i]
356 362 ychannel = y[i,:]
357 363 axes.pline(x, ychannel,
358 364 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
359 365 xlabel=xlabel, ylabel=ylabel, title=title)
360 366
361 367 self.draw()
362 368
363
369 if save:
370 self.saveFigure(filename)
364 371 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now