##// END OF EJS Templates
Version: 2.1.3.2...
Miguel Valdez -
r672:a1a5642b5594
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,19 +1,23
1 1 VERSIONS:
2 2
3 3 2.1.2:
4 4 -jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread
5 5 Server thread opens and closes remote server each time file list is sent
6 6 -jroplot_spectra.py: Noise path was not being created saving noise data.
7 7 -jroIO_base.py: startTime can be greater than endTime
8 8
9 9 2.1.3:
10 10 -jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
11 11 -jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
12 12 Bug fixed selecting heights by block (selecting profiles instead heights)
13 13 -jroproc_voltage.py: New feature added: decoding data by block using FFT.
14 14 -jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits object instead schainpy.mode.data.jrodata.Fits object.
15 15 -jroIO_heispectra.py: Channel index list does not exist.
16 16
17 17 2.1.3.1:
18 18 -GUI: every icon were resized
19 19 -jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file
20
21 2.1.3.2:
22 -GUI: user interaction enhanced
23 -controller_api.py: Safe access to ControllerThead No newline at end of file
@@ -1,7 +1,7
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 __version__ = "2.1.3.1" No newline at end of file
7 __version__ = "2.1.3.2" No newline at end of file
@@ -1,1096 +1,1142
1 1 '''
2 2 Created on September , 2012
3 3 @author:
4 4 '''
5 5 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
6 6 from xml.dom import minidom
7 7
8 8 from model import *
9
10 try:
11 from gevent import sleep
12 except:
13 from time import sleep
9 from time import sleep
14 10
11 import sys
15 12 import ast
13 import traceback
14
15 SCHAIN_MAIL = "miguel.urco@jro.igp.gob.pe"
16 EMAIL_SERVER = "jro.igp.gob.pe"
16 17
17 18 def prettify(elem):
18 19 """Return a pretty-printed XML string for the Element.
19 20 """
20 21 rough_string = tostring(elem, 'utf-8')
21 22 reparsed = minidom.parseString(rough_string)
22 23 return reparsed.toprettyxml(indent=" ")
23 24
24 25 class ParameterConf():
25 26
26 27 id = None
27 28 name = None
28 29 value = None
29 30 format = None
30 31
31 32 __formated_value = None
32 33
33 34 ELEMENTNAME = 'Parameter'
34 35
35 36 def __init__(self):
36 37
37 38 self.format = 'str'
38 39
39 40 def getElementName(self):
40 41
41 42 return self.ELEMENTNAME
42 43
43 44 def getValue(self):
44 45
45 46 value = self.value
46 47 format = self.format
47 48
48 49 if self.__formated_value != None:
49 50
50 51 return self.__formated_value
51 52
52 53 if format == 'str':
53 54 self.__formated_value = str(value)
54 55 return self.__formated_value
55 56
56 57 if value == '':
57 58 raise ValueError, "%s: This parameter value is empty" %self.name
58 59
59 60 if format == 'bool':
60 61 value = int(value)
61 62
62 63 if format == 'list':
63 64 strList = value.split(',')
64 65
65 66 self.__formated_value = strList
66 67
67 68 return self.__formated_value
68 69
69 70 if format == 'intlist':
70 71 """
71 72 Example:
72 73 value = (0,1,2)
73 74 """
74 75 value = value.replace('(', '')
75 76 value = value.replace(')', '')
76 77
77 78 value = value.replace('[', '')
78 79 value = value.replace(']', '')
79 80
80 81 strList = value.split(',')
81 82 intList = [int(float(x)) for x in strList]
82 83
83 84 self.__formated_value = intList
84 85
85 86 return self.__formated_value
86 87
87 88 if format == 'floatlist':
88 89 """
89 90 Example:
90 91 value = (0.5, 1.4, 2.7)
91 92 """
92 93
93 94 value = value.replace('(', '')
94 95 value = value.replace(')', '')
95 96
96 97 value = value.replace('[', '')
97 98 value = value.replace(']', '')
98 99
99 100 strList = value.split(',')
100 101 floatList = [float(x) for x in strList]
101 102
102 103 self.__formated_value = floatList
103 104
104 105 return self.__formated_value
105 106
106 107 if format == 'date':
107 108 strList = value.split('/')
108 109 intList = [int(x) for x in strList]
109 110 date = datetime.date(intList[0], intList[1], intList[2])
110 111
111 112 self.__formated_value = date
112 113
113 114 return self.__formated_value
114 115
115 116 if format == 'time':
116 117 strList = value.split(':')
117 118 intList = [int(x) for x in strList]
118 119 time = datetime.time(intList[0], intList[1], intList[2])
119 120
120 121 self.__formated_value = time
121 122
122 123 return self.__formated_value
123 124
124 125 if format == 'pairslist':
125 126 """
126 127 Example:
127 128 value = (0,1),(1,2)
128 129 """
129 130
130 131 value = value.replace('(', '')
131 132 value = value.replace(')', '')
132 133
133 134 value = value.replace('[', '')
134 135 value = value.replace(']', '')
135 136
136 137 strList = value.split(',')
137 138 intList = [int(item) for item in strList]
138 139 pairList = []
139 140 for i in range(len(intList)/2):
140 141 pairList.append((intList[i*2], intList[i*2 + 1]))
141 142
142 143 self.__formated_value = pairList
143 144
144 145 return self.__formated_value
145 146
146 147 if format == 'multilist':
147 148 """
148 149 Example:
149 150 value = (0,1,2),(3,4,5)
150 151 """
151 152 multiList = ast.literal_eval(value)
152 153
153 154 if type(multiList[0]) == int:
154 155 multiList = ast.literal_eval("(" + value + ")")
155 156
156 157 self.__formated_value = multiList
157 158
158 159 return self.__formated_value
159 160
160 161 format_func = eval(format)
161 162
162 163 self.__formated_value = format_func(value)
163 164
164 165 return self.__formated_value
165 166
166 167 def updateId(self, new_id):
167 168
168 169 self.id = str(new_id)
169 170
170 171 def setup(self, id, name, value, format='str'):
171 172
172 173 self.id = str(id)
173 174 self.name = name
174 175 self.value = str(value)
175 176 self.format = str.lower(format)
176 177
177 178 try:
178 179 self.getValue()
179 180 except:
180 181 return 0
181 182
182 183 return 1
183 184
184 185 def update(self, name, value, format='str'):
185 186
186 187 self.name = name
187 188 self.value = str(value)
188 189 self.format = format
189 190
190 191 def makeXml(self, opElement):
191 192
192 193 parmElement = SubElement(opElement, self.ELEMENTNAME)
193 194 parmElement.set('id', str(self.id))
194 195 parmElement.set('name', self.name)
195 196 parmElement.set('value', self.value)
196 197 parmElement.set('format', self.format)
197 198
198 199 def readXml(self, parmElement):
199 200
200 201 self.id = parmElement.get('id')
201 202 self.name = parmElement.get('name')
202 203 self.value = parmElement.get('value')
203 204 self.format = str.lower(parmElement.get('format'))
204 205
205 206 #Compatible with old signal chain version
206 207 if self.format == 'int' and self.name == 'idfigure':
207 208 self.name = 'id'
208 209
209 210 def printattr(self):
210 211
211 212 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
212 213
213 214 class OperationConf():
214 215
215 216 id = None
216 217 name = None
217 218 priority = None
218 219 type = None
219 220
220 221 parmConfObjList = []
221 222
222 223 ELEMENTNAME = 'Operation'
223 224
224 225 def __init__(self):
225 226
226 227 self.id = '0'
227 228 self.name = None
228 229 self.priority = None
229 230 self.type = 'self'
230 231
231 232
232 233 def __getNewId(self):
233 234
234 235 return int(self.id)*10 + len(self.parmConfObjList) + 1
235 236
236 237 def updateId(self, new_id):
237 238
238 239 self.id = str(new_id)
239 240
240 241 n = 1
241 242 for parmObj in self.parmConfObjList:
242 243
243 244 idParm = str(int(new_id)*10 + n)
244 245 parmObj.updateId(idParm)
245 246
246 247 n += 1
247 248
248 249 def getElementName(self):
249 250
250 251 return self.ELEMENTNAME
251 252
252 253 def getParameterObjList(self):
253 254
254 255 return self.parmConfObjList
255 256
256 257 def getParameterObj(self, parameterName):
257 258
258 259 for parmConfObj in self.parmConfObjList:
259 260
260 261 if parmConfObj.name != parameterName:
261 262 continue
262 263
263 264 return parmConfObj
264 265
265 266 return None
266 267
267 268 def getParameterObjfromValue(self, parameterValue):
268 269
269 270 for parmConfObj in self.parmConfObjList:
270 271
271 272 if parmConfObj.getValue() != parameterValue:
272 273 continue
273 274
274 275 return parmConfObj.getValue()
275 276
276 277 return None
277 278
278 279 def getParameterValue(self, parameterName):
279 280
280 281 parameterObj = self.getParameterObj(parameterName)
281 282
282 283 # if not parameterObj:
283 284 # return None
284 285
285 286 value = parameterObj.getValue()
286 287
287 288 return value
288 289
289 290 def setup(self, id, name, priority, type):
290 291
291 292 self.id = str(id)
292 293 self.name = name
293 294 self.type = type
294 295 self.priority = priority
295 296
296 297 self.parmConfObjList = []
297 298
298 299 def removeParameters(self):
299 300
300 301 for obj in self.parmConfObjList:
301 302 del obj
302 303
303 304 self.parmConfObjList = []
304 305
305 306 def addParameter(self, name, value, format='str'):
306 307
307 308 id = self.__getNewId()
308 309
309 310 parmConfObj = ParameterConf()
310 311 if not parmConfObj.setup(id, name, value, format):
311 312 return None
312 313
313 314 self.parmConfObjList.append(parmConfObj)
314 315
315 316 return parmConfObj
316 317
317 318 def changeParameter(self, name, value, format='str'):
318 319
319 320 parmConfObj = self.getParameterObj(name)
320 321 parmConfObj.update(name, value, format)
321 322
322 323 return parmConfObj
323 324
324 325 def makeXml(self, upElement):
325 326
326 327 opElement = SubElement(upElement, self.ELEMENTNAME)
327 328 opElement.set('id', str(self.id))
328 329 opElement.set('name', self.name)
329 330 opElement.set('type', self.type)
330 331 opElement.set('priority', str(self.priority))
331 332
332 333 for parmConfObj in self.parmConfObjList:
333 334 parmConfObj.makeXml(opElement)
334 335
335 336 def readXml(self, opElement):
336 337
337 338 self.id = opElement.get('id')
338 339 self.name = opElement.get('name')
339 340 self.type = opElement.get('type')
340 341 self.priority = opElement.get('priority')
341 342
342 343 #Compatible with old signal chain version
343 344 #Use of 'run' method instead 'init'
344 345 if self.type == 'self' and self.name == 'init':
345 346 self.name = 'run'
346 347
347 348 self.parmConfObjList = []
348 349
349 350 parmElementList = opElement.getiterator(ParameterConf().getElementName())
350 351
351 352 for parmElement in parmElementList:
352 353 parmConfObj = ParameterConf()
353 354 parmConfObj.readXml(parmElement)
354 355
355 356 #Compatible with old signal chain version
356 357 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
357 358 if self.type != 'self' and self.name == 'Plot':
358 359 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
359 360 self.name = parmConfObj.value
360 361 continue
361 362
362 363 self.parmConfObjList.append(parmConfObj)
363 364
364 365 def printattr(self):
365 366
366 367 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
367 368 self.id,
368 369 self.name,
369 370 self.type,
370 371 self.priority)
371 372
372 373 for parmConfObj in self.parmConfObjList:
373 374 parmConfObj.printattr()
374 375
375 376 def createObject(self):
376 377
377 378 if self.type == 'self':
378 379 raise ValueError, "This operation type cannot be created"
379 380
380 381 if self.type == 'external' or self.type == 'other':
381 382 className = eval(self.name)
382 383 opObj = className()
383 384
384 385 return opObj
385 386
386 387 class ProcUnitConf():
387 388
388 389 id = None
389 390 name = None
390 391 datatype = None
391 392 inputId = None
392 393 parentId = None
393 394
394 395 opConfObjList = []
395 396
396 397 procUnitObj = None
397 398 opObjList = []
398 399
399 400 ELEMENTNAME = 'ProcUnit'
400 401
401 402 def __init__(self):
402 403
403 404 self.id = None
404 405 self.datatype = None
405 406 self.name = None
406 407 self.inputId = None
407 408
408 409 self.opConfObjList = []
409 410
410 411 self.procUnitObj = None
411 412 self.opObjDict = {}
412 413
413 414 def __getPriority(self):
414 415
415 416 return len(self.opConfObjList)+1
416 417
417 418 def __getNewId(self):
418 419
419 420 return int(self.id)*10 + len(self.opConfObjList) + 1
420 421
421 422 def getElementName(self):
422 423
423 424 return self.ELEMENTNAME
424 425
425 426 def getId(self):
426 427
427 428 return self.id
428 429
429 430 def updateId(self, new_id, parentId=parentId):
430 431
431 432
432 433 new_id = int(parentId)*10 + (int(self.id) % 10)
433 434 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
434 435
435 436 #If this proc unit has not inputs
436 437 if self.inputId == '0':
437 438 new_inputId = 0
438 439
439 440 n = 1
440 441 for opConfObj in self.opConfObjList:
441 442
442 443 idOp = str(int(new_id)*10 + n)
443 444 opConfObj.updateId(idOp)
444 445
445 446 n += 1
446 447
447 448 self.parentId = str(parentId)
448 449 self.id = str(new_id)
449 450 self.inputId = str(new_inputId)
450 451
451 452
452 453 def getInputId(self):
453 454
454 455 return self.inputId
455 456
456 457 def getOperationObjList(self):
457 458
458 459 return self.opConfObjList
459 460
460 461 def getOperationObj(self, name=None):
461 462
462 463 for opConfObj in self.opConfObjList:
463 464
464 465 if opConfObj.name != name:
465 466 continue
466 467
467 468 return opConfObj
468 469
469 470 return None
470 471
471 472 def getOpObjfromParamValue(self, value=None):
472 473
473 474 for opConfObj in self.opConfObjList:
474 475 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
475 476 continue
476 477 return opConfObj
477 478 return None
478 479
479 480 def getProcUnitObj(self):
480 481
481 482 return self.procUnitObj
482 483
483 484 def setup(self, id, name, datatype, inputId, parentId=None):
484 485
485 486 #Compatible with old signal chain version
486 487 if datatype==None and name==None:
487 488 raise ValueError, "datatype or name should be defined"
488 489
489 490 if name==None:
490 491 if 'Proc' in datatype:
491 492 name = datatype
492 493 else:
493 494 name = '%sProc' %(datatype)
494 495
495 496 if datatype==None:
496 497 datatype = name.replace('Proc','')
497 498
498 499 self.id = str(id)
499 500 self.name = name
500 501 self.datatype = datatype
501 502 self.inputId = inputId
502 503 self.parentId = parentId
503 504
504 505 self.opConfObjList = []
505 506
506 507 self.addOperation(name='run', optype='self')
507 508
508 509 def removeOperations(self):
509 510
510 511 for obj in self.opConfObjList:
511 512 del obj
512 513
513 514 self.opConfObjList = []
514 515 self.addOperation(name='run')
515 516
516 517 def addParameter(self, **kwargs):
517 518 '''
518 519 Add parameters to "run" operation
519 520 '''
520 521 opObj = self.opConfObjList[0]
521 522
522 523 opObj.addParameter(**kwargs)
523 524
524 525 return opObj
525 526
526 527 def addOperation(self, name, optype='self'):
527 528
528 529 id = self.__getNewId()
529 530 priority = self.__getPriority()
530 531
531 532 opConfObj = OperationConf()
532 533 opConfObj.setup(id, name=name, priority=priority, type=optype)
533 534
534 535 self.opConfObjList.append(opConfObj)
535 536
536 537 return opConfObj
537 538
538 539 def makeXml(self, procUnitElement):
539 540
540 541 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
541 542 upElement.set('id', str(self.id))
542 543 upElement.set('name', self.name)
543 544 upElement.set('datatype', self.datatype)
544 545 upElement.set('inputId', str(self.inputId))
545 546
546 547 for opConfObj in self.opConfObjList:
547 548 opConfObj.makeXml(upElement)
548 549
549 550 def readXml(self, upElement):
550 551
551 552 self.id = upElement.get('id')
552 553 self.name = upElement.get('name')
553 554 self.datatype = upElement.get('datatype')
554 555 self.inputId = upElement.get('inputId')
555 556
556 557 if self.ELEMENTNAME == "ReadUnit":
557 558 self.datatype = self.datatype.replace("Reader", "")
558 559
559 560 if self.ELEMENTNAME == "ProcUnit":
560 561 self.datatype = self.datatype.replace("Proc", "")
561 562
562 563 if self.inputId == 'None':
563 564 self.inputId = '0'
564 565
565 566 self.opConfObjList = []
566 567
567 568 opElementList = upElement.getiterator(OperationConf().getElementName())
568 569
569 570 for opElement in opElementList:
570 571 opConfObj = OperationConf()
571 572 opConfObj.readXml(opElement)
572 573 self.opConfObjList.append(opConfObj)
573 574
574 575 def printattr(self):
575 576
576 577 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
577 578 self.id,
578 579 self.name,
579 580 self.datatype,
580 581 self.inputId)
581 582
582 583 for opConfObj in self.opConfObjList:
583 584 opConfObj.printattr()
584 585
585 586 def createObjects(self):
586 587
587 588 className = eval(self.name)
588 589 procUnitObj = className()
589 590
590 591 for opConfObj in self.opConfObjList:
591 592
592 593 if opConfObj.type == 'self':
593 594 continue
594 595
595 596 opObj = opConfObj.createObject()
596 597
597 598 self.opObjDict[opConfObj.id] = opObj
598 599 procUnitObj.addOperation(opObj, opConfObj.id)
599 600
600 601 self.procUnitObj = procUnitObj
601 602
602 603 return procUnitObj
603 604
604 605 def run(self):
605 606
606 finalSts = False
607 is_ok = False
607 608
608 609 for opConfObj in self.opConfObjList:
609 610
610 611 kwargs = {}
611 612 for parmConfObj in opConfObj.getParameterObjList():
612 613 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
613 614 continue
614 615
615 616 kwargs[parmConfObj.name] = parmConfObj.getValue()
616 617
617 618 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
618 619 sts = self.procUnitObj.call(opType = opConfObj.type,
619 620 opName = opConfObj.name,
620 621 opId = opConfObj.id,
621 622 **kwargs)
622 finalSts = finalSts or sts
623 is_ok = is_ok or sts
623 624
624 return finalSts
625 return is_ok
625 626
626 627 def close(self):
627 628
628 629 for opConfObj in self.opConfObjList:
629 630 if opConfObj.type == 'self':
630 631 continue
631 632
632 633 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
633 634 opObj.close()
634 635
635 636 self.procUnitObj.close()
636 637
637 638 return
638 639
639 640 class ReadUnitConf(ProcUnitConf):
640 641
641 642 path = None
642 643 startDate = None
643 644 endDate = None
644 645 startTime = None
645 646 endTime = None
646 647
647 648 ELEMENTNAME = 'ReadUnit'
648 649
649 650 def __init__(self):
650 651
651 652 self.id = None
652 653 self.datatype = None
653 654 self.name = None
654 655 self.inputId = None
655 656
656 657 self.parentId = None
657 658
658 659 self.opConfObjList = []
659 660 self.opObjList = []
660 661
661 662 def getElementName(self):
662 663
663 664 return self.ELEMENTNAME
664 665
665 666 def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs):
666 667
667 668 #Compatible with old signal chain version
668 669 if datatype==None and name==None:
669 670 raise ValueError, "datatype or name should be defined"
670 671
671 672 if name==None:
672 673 if 'Reader' in datatype:
673 674 name = datatype
674 675 else:
675 676 name = '%sReader' %(datatype)
676 677
677 678 if datatype==None:
678 679 datatype = name.replace('Reader','')
679 680
680 681 self.id = id
681 682 self.name = name
682 683 self.datatype = datatype
683 684
684 685 self.path = path
685 686 self.startDate = startDate
686 687 self.endDate = endDate
687 688 self.startTime = startTime
688 689 self.endTime = endTime
689 690
690 691 self.inputId = '0'
691 692 self.parentId = parentId
692 693
693 694 self.addRunOperation(**kwargs)
694 695
695 696 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
696 697
697 698 #Compatible with old signal chain version
698 699 if datatype==None and name==None:
699 700 raise ValueError, "datatype or name should be defined"
700 701
701 702 if name==None:
702 703 if 'Reader' in datatype:
703 704 name = datatype
704 705 else:
705 706 name = '%sReader' %(datatype)
706 707
707 708 if datatype==None:
708 709 datatype = name.replace('Reader','')
709 710
710 711 self.datatype = datatype
711 712 self.name = name
712 713 self.path = path
713 714 self.startDate = startDate
714 715 self.endDate = endDate
715 716 self.startTime = startTime
716 717 self.endTime = endTime
717 718
718 719 self.inputId = '0'
719 720 self.parentId = parentId
720 721
721 722 self.updateRunOperation(**kwargs)
722 723
723 724 def addRunOperation(self, **kwargs):
724 725
725 726 opObj = self.addOperation(name = 'run', optype = 'self')
726 727
727 728 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
728 729 opObj.addParameter(name='path' , value=self.path, format='str')
729 730 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
730 731 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
731 732 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
732 733 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
733 734
734 735 for key, value in kwargs.items():
735 736 opObj.addParameter(name=key, value=value, format=type(value).__name__)
736 737
737 738 return opObj
738 739
739 740 def updateRunOperation(self, **kwargs):
740 741
741 742 opObj = self.getOperationObj(name = 'run')
742 743 opObj.removeParameters()
743 744
744 745 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
745 746 opObj.addParameter(name='path' , value=self.path, format='str')
746 747 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
747 748 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
748 749 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
749 750 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
750 751
751 752 for key, value in kwargs.items():
752 753 opObj.addParameter(name=key, value=value, format=type(value).__name__)
753 754
754 755 return opObj
755 756
756 757 class Project():
757 758
758 759 id = None
759 760 name = None
760 761 description = None
761 762 # readUnitConfObjList = None
762 763 procUnitConfObjDict = None
763 764
764 765 ELEMENTNAME = 'Project'
765 766
766 def __init__(self, control=None, dataq=None):
767 def __init__(self):
767 768
768 769 self.id = None
769 770 self.name = None
770 771 self.description = None
771 772
772 773 self.procUnitConfObjDict = {}
773 774
774 #global data_q
775 #data_q = dataq
776
777 if control==None:
778 control = {'stop':False,'pause':False}
779
780 self.control = control
781
782 775 def __getNewId(self):
783 776
784 777 id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1
785 778
786 779 return str(id)
787 780
788 781 def getElementName(self):
789 782
790 783 return self.ELEMENTNAME
791 784
792 785 def getId(self):
793 786
794 787 return self.id
795 788
796 789 def updateId(self, new_id):
797 790
798 791 self.id = str(new_id)
799 792
800 793 keyList = self.procUnitConfObjDict.keys()
801 794 keyList.sort()
802 795
803 796 n = 1
804 797 newProcUnitConfObjDict = {}
805 798
806 799 for procKey in keyList:
807 800
808 801 procUnitConfObj = self.procUnitConfObjDict[procKey]
809 802 idProcUnit = str(int(self.id)*10 + n)
810 803 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
811 804
812 805 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
813 806 n += 1
814 807
815 808 self.procUnitConfObjDict = newProcUnitConfObjDict
816 809
817 810 def setup(self, id, name, description):
818 811
819 812 self.id = str(id)
820 813 self.name = name
821 814 self.description = description
822 815
823 816 def update(self, name, description):
824 817
825 818 self.name = name
826 819 self.description = description
827 820
828 821 def addReadUnit(self, datatype=None, name=None, **kwargs):
829 822
830 823 idReadUnit = self.__getNewId()
831 824
832 825 readUnitConfObj = ReadUnitConf()
833 826 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
834 827
835 828 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
836 829
837 830 return readUnitConfObj
838 831
839 832 def addProcUnit(self, inputId='0', datatype=None, name=None):
840 833
841 834 idProcUnit = self.__getNewId()
842 835
843 836 procUnitConfObj = ProcUnitConf()
844 837 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
845 838
846 839 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
847 840
848 841 return procUnitConfObj
849 842
850 843 def removeProcUnit(self, id):
851 844
852 845 if id in self.procUnitConfObjDict.keys():
853 846 self.procUnitConfObjDict.pop(id)
854 847
855 848 def getReadUnitId(self):
856 849
857 850 readUnitConfObj = self.getReadUnitObj()
858 851
859 852 return readUnitConfObj.id
860 853
861 854 def getReadUnitObj(self):
862 855
863 856 for obj in self.procUnitConfObjDict.values():
864 857 if obj.getElementName() == "ReadUnit":
865 858 return obj
866 859
867 860 return None
868 861
869 862 def getProcUnitObj(self, id=None, name=None):
870 863
871 864 if id != None:
872 865 return self.procUnitConfObjDict[id]
873 866
874 867 if name != None:
875 868 return self.getProcUnitObjByName(name)
876 869
877 870 return None
878 871
879 872 def getProcUnitObjByName(self, name):
880 873
881 874 for obj in self.procUnitConfObjDict.values():
882 875 if obj.name == name:
883 876 return obj
884 877
885 878 return None
886 879
887 880 def procUnitItems(self):
888 881
889 882 return self.procUnitConfObjDict.items()
890 883
891 884 def makeXml(self):
892 885
893 886 projectElement = Element('Project')
894 887 projectElement.set('id', str(self.id))
895 888 projectElement.set('name', self.name)
896 889 projectElement.set('description', self.description)
897 890
898 891 for procUnitConfObj in self.procUnitConfObjDict.values():
899 892 procUnitConfObj.makeXml(projectElement)
900 893
901 894 self.projectElement = projectElement
902 895
903 896 def writeXml(self, filename):
904 897
905 898 self.makeXml()
906 899
907 900 #print prettify(self.projectElement)
908 901
909 902 ElementTree(self.projectElement).write(filename, method='xml')
910 903
911 904 def readXml(self, filename):
912 905
913 906 self.projectElement = None
914 907 self.procUnitConfObjDict = {}
915 908
916 909 self.projectElement = ElementTree().parse(filename)
917 910
918 911 self.project = self.projectElement.tag
919 912
920 913 self.id = self.projectElement.get('id')
921 914 self.name = self.projectElement.get('name')
922 915 self.description = self.projectElement.get('description')
923 916
924 917 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
925 918
926 919 for readUnitElement in readUnitElementList:
927 920 readUnitConfObj = ReadUnitConf()
928 921 readUnitConfObj.readXml(readUnitElement)
929 922
930 923 if readUnitConfObj.parentId == None:
931 924 readUnitConfObj.parentId = self.id
932 925
933 926 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
934 927
935 928 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
936 929
937 930 for procUnitElement in procUnitElementList:
938 931 procUnitConfObj = ProcUnitConf()
939 932 procUnitConfObj.readXml(procUnitElement)
940 933
941 934 if procUnitConfObj.parentId == None:
942 935 procUnitConfObj.parentId = self.id
943 936
944 937 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
945 938
946 939 def printattr(self):
947 940
948 941 print "Project[%s]: name = %s, description = %s" %(self.id,
949 942 self.name,
950 943 self.description)
951 944
952 945 for procUnitConfObj in self.procUnitConfObjDict.values():
953 946 procUnitConfObj.printattr()
954 947
955 948 def createObjects(self):
956 949
957 950 for procUnitConfObj in self.procUnitConfObjDict.values():
958 951 procUnitConfObj.createObjects()
959 952
960 953 def __connect(self, objIN, thisObj):
961 954
962 955 thisObj.setInput(objIN.getOutputObj())
963 956
964 957 def connectObjects(self):
965 958
966 959 for thisPUConfObj in self.procUnitConfObjDict.values():
967 960
968 961 inputId = thisPUConfObj.getInputId()
969 962
970 963 if int(inputId) == 0:
971 964 continue
972 965
973 966 #Get input object
974 967 puConfINObj = self.procUnitConfObjDict[inputId]
975 968 puObjIN = puConfINObj.getProcUnitObj()
976 969
977 970 #Get current object
978 971 thisPUObj = thisPUConfObj.getProcUnitObj()
979 972
980 973 self.__connect(puObjIN, thisPUObj)
981 974
975 def isPaused(self):
976 return 0
977
978 def isStopped(self):
979 return 0
980
981 def runController(self):
982 """
983 returns 0 when this process has been stopped, 1 otherwise
984 """
985
986 if self.isPaused():
987 print "Process suspended"
988
989 while True:
990 sleep(0.1)
991
992 if not self.isPaused():
993 break
994
995 if self.isStopped():
996 break
997
998 print "Process reinitialized"
999
1000 if self.isStopped():
1001 print "Process stopped"
1002 return 0
1003
1004 return 1
1005
982 1006 def run(self):
983 1007
984 1008 print
985 print "*"*50
1009 print "*"*60
986 1010 print " Starting SIGNAL CHAIN PROCESSING "
987 print "*"*50
1011 print "*"*60
988 1012 print
989 1013
990 1014 keyList = self.procUnitConfObjDict.keys()
991 1015 keyList.sort()
992 1016
993 1017 while(True):
994 1018
995 finalSts = False
1019 is_ok = False
996 1020
997 1021 for procKey in keyList:
998 1022 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
999 1023
1000 1024 procUnitConfObj = self.procUnitConfObjDict[procKey]
1001 sts = procUnitConfObj.run()
1002 finalSts = finalSts or sts
1025
1026 message = ""
1027 try:
1028 sts = procUnitConfObj.run()
1029 is_ok = is_ok or sts
1030 except:
1031 sleep(1)
1032 err = traceback.format_exception(sys.exc_info()[0],
1033 sys.exc_info()[1],
1034 sys.exc_info()[2])
1035
1036 for thisLine in err:
1037 message += thisLine
1038
1039 print message
1040 # self.sendReport(message)
1041 sleep(0.1)
1042 is_ok = False
1043
1044 break
1003 1045
1004 1046 #If every process unit finished so end process
1005 if not(finalSts):
1047 if not(is_ok):
1048 print message
1006 1049 print "Every process unit have finished"
1007 1050 break
1008 1051
1009 if self.control['pause']:
1010 print "Process suspended"
1011
1012 while True:
1013 sleep(0.1)
1014
1015 if not self.control['pause']:
1016 break
1017
1018 if self.control['stop']:
1019 break
1020 print "Process reinitialized"
1021
1022 if self.control['stop']:
1023 # print "Process stopped"
1052 if not self.runController():
1024 1053 break
1025 1054
1026 1055 #Closing every process
1027 1056 for procKey in keyList:
1028 1057 procUnitConfObj = self.procUnitConfObjDict[procKey]
1029 1058 procUnitConfObj.close()
1030 1059
1031 1060 print "Process finished"
1032 1061
1033 1062 def start(self, filename):
1034 1063
1035 1064 self.writeXml(filename)
1036 1065 self.readXml(filename)
1037 1066
1038 1067 self.createObjects()
1039 1068 self.connectObjects()
1040 1069 self.run()
1070
1071 def sendReport(self, message, subject="Error occurred in Signal Chain", email=SCHAIN_MAIL):
1072
1073 import smtplib
1074
1075 print subject
1076 print "Sending report to %s ..." %email
1077
1078 message = 'From: (Python Signal Chain API) ' + email + '\n' + \
1079 'To: ' + email + '\n' + \
1080 'Subject: ' + str(subject) + '\n' + \
1081 'Content-type: text/html\n\n' + message
1082
1083 server = smtplib.SMTP(EMAIL_SERVER)
1084 server.sendmail(email.split(',')[0],
1085 email.split(','), message)
1086 server.quit()
1041 1087
1042 1088 if __name__ == '__main__':
1043 1089
1044 1090 desc = "Segundo Test"
1045 1091 filename = "schain.xml"
1046 1092
1047 1093 controllerObj = Project()
1048 1094
1049 1095 controllerObj.setup(id = '191', name='test01', description=desc)
1050 1096
1051 1097 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
1052 1098 path='data/rawdata/',
1053 1099 startDate='2011/01/01',
1054 1100 endDate='2012/12/31',
1055 1101 startTime='00:00:00',
1056 1102 endTime='23:59:59',
1057 1103 online=1,
1058 1104 walk=1)
1059 1105
1060 1106 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
1061 1107
1062 1108 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
1063 1109 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
1064 1110
1065 1111 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
1066 1112 opObj10.addParameter(name='minHei', value='90', format='float')
1067 1113 opObj10.addParameter(name='maxHei', value='180', format='float')
1068 1114
1069 1115 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
1070 1116 opObj12.addParameter(name='n', value='10', format='int')
1071 1117
1072 1118 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
1073 1119 procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
1074 1120 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
1075 1121
1076 1122
1077 1123 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
1078 1124 opObj11.addParameter(name='idfigure', value='1', format='int')
1079 1125 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
1080 1126 opObj11.addParameter(name='zmin', value='40', format='int')
1081 1127 opObj11.addParameter(name='zmax', value='90', format='int')
1082 1128 opObj11.addParameter(name='showprofile', value='1', format='int')
1083 1129
1084 1130 print "Escribiendo el archivo XML"
1085 1131
1086 1132 controllerObj.writeXml(filename)
1087 1133
1088 1134 print "Leyendo el archivo XML"
1089 1135 controllerObj.readXml(filename)
1090 1136 #controllerObj.printattr()
1091 1137
1092 1138 controllerObj.createObjects()
1093 1139 controllerObj.connectObjects()
1094 1140 controllerObj.run()
1095 1141
1096 1142 No newline at end of file
@@ -1,139 +1,141
1 1 import threading
2 2
3 3 from PyQt4 import QtCore
4 4 from PyQt4.QtCore import SIGNAL
5 5
6 6 from schainpy.controller import Project
7 7
8 8 class ControllerThread(threading.Thread, Project):
9 9
10 10 def __init__(self, filename):
11 11
12 12 threading.Thread.__init__(self)
13 13 Project.__init__(self)
14 14
15 15 self.setDaemon(True)
16 16
17 17 self.filename = filename
18
19 self.lock = threading.Lock()
18 20 self.control = {'stop':False, 'pause':False}
19 21
20 22 def __del__(self):
21 23
22 24 self.control['stop'] = True
23 # self.pause(1)
24 # self.wait()
25 25
26 26 def stop(self):
27
28 self.lock.acquire()
29
27 30 self.control['stop'] = True
28 31
32 self.lock.release()
33
29 34 def pause(self):
35
36 self.lock.acquire()
37
30 38 self.control['pause'] = not(self.control['pause'])
39 paused = self.control['pause']
40
41 self.lock.release()
31 42
32 return self.control['pause']
43 return paused
33 44
34 def __run(self):
45 def isPaused(self):
35 46
36 print
37 print "*"*40
38 print " Starting SIGNAL CHAIN PROCESSING "
39 print "*"*40
40 print
47 self.lock.acquire()
48 paused = self.control['pause']
49 self.lock.release()
41 50
42 keyList = self.procUnitConfObjDict.keys()
43 keyList.sort()
44
45 while(True):
46
47 finalSts = False
48 #executed proc units
49 procUnitExecutedList = []
50
51 for procKey in keyList:
52 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
53
54 procUnitConfObj = self.procUnitConfObjDict[procKey]
55
56 inputId = procUnitConfObj.getInputId()
57
58 sts = procUnitConfObj.run()
59 finalSts = finalSts or sts
60
61 procUnitExecutedList.append(procUnitConfObj.id)
62
63 #If every process unit finished so end process
64 if not(finalSts):
65 print "Every process unit have finished"
66 break
67
68 if self.control['pause']:
69 print "Process suspended"
70
71 while True:
72 sleep(0.1)
73
74 if not self.control['pause']:
75 break
76
77 if self.control['stop']:
78 break
79 print "Process reinitialized"
80
81 if self.control['stop']:
82 # print "Process stopped"
83 break
84
85 #Closing every process
86 for procKey in keyList:
87 procUnitConfObj = self.procUnitConfObjDict[procKey]
88 procUnitConfObj.close()
89
90 print "Process finished"
51 return paused
52
53 def isStopped(self):
91 54
55 self.lock.acquire()
56 stopped = self.control['stop']
57 self.lock.release()
58
59 return stopped
60
92 61 def run(self):
93 62 self.control['stop'] = False
94 63 self.control['pause'] = False
95 64
96 65 self.readXml(self.filename)
97 66 self.createObjects()
98 67 self.connectObjects()
99 68 Project.run(self)
100 69
101 70 def isRunning(self):
102 71
103 72 return self.is_alive()
104 73
105 74 def isFinished(self):
106 75
107 76 return not self.is_alive()
108 77
109 78 class ControllerQThread(QtCore.QThread, Project):
110 79
111 80 def __init__(self, filename):
112 81
113 82 QtCore.QThread.__init__(self)
114 83 Project.__init__(self)
115 84
116 85 self.filename = filename
86
87 self.lock = threading.Lock()
117 88 self.control = {'stop':False, 'pause':False}
118 89
119 90 def __del__(self):
120 91
121 92 self.control['stop'] = True
122 93 self.wait()
123 94
124 95 def stop(self):
96
97 self.lock.acquire()
98
125 99 self.control['stop'] = True
126 100
101 self.lock.release()
102
127 103 def pause(self):
104
105 self.lock.acquire()
106
128 107 self.control['pause'] = not(self.control['pause'])
129
108 paused = self.control['pause']
109
110 self.lock.release()
111
112 return paused
113
114 def isPaused(self):
115
116 self.lock.acquire()
117 paused = self.control['pause']
118 self.lock.release()
119
120 return paused
121
122 def isStopped(self):
123
124 self.lock.acquire()
125 stopped = self.control['stop']
126 self.lock.release()
127
128 return stopped
129
130 130 def run(self):
131
131 132 self.control['stop'] = False
132 133 self.control['pause'] = False
133 134
134 135 self.readXml(self.filename)
135 136 self.createObjects()
136 137 self.connectObjects()
137 138 self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1)
138 139 Project.run(self)
139 self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) No newline at end of file
140 self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1)
141 No newline at end of file
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,344 +1,343
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Form implementation generated from reading ui file '/home/alex/ui/MainWindow_21_02_13_v49.ui'
4 4 #
5 5 # Created: Mon Mar 24 13:28:36 2014
6 6 # by: PyQt4 UI code generator 4.10
7 7 #
8 8 # WARNING! All changes made in this file will be lost!
9 9
10 10 from PyQt4 import QtCore, QtGui
11 11 from windows import *
12 12
13 13 try:
14 14 _fromUtf8 = QtCore.QString.fromUtf8
15 15 except AttributeError:
16 16 def _fromUtf8(s):
17 17 return s
18 18
19 19 try:
20 20 _encoding = QtGui.QApplication.UnicodeUTF8
21 21 def _translate(context, text, disambig):
22 22 return QtGui.QApplication.translate(context, text, disambig, _encoding)
23 23 except AttributeError:
24 24 def _translate(context, text, disambig):
25 25 return QtGui.QApplication.translate(context, text, disambig)
26 26
27 27 import os
28 28 from schainpy.gui.figures import tools
29 29 from schainpy import __version__
30 30
31 31 FIGURES_PATH = tools.get_path()
32 32
33 33 class Ui_EnvWindow(object):
34 34 paused = False
35 35
36 36 def restorePauseIcon(self):
37 37
38 38 icon_name = "pause.png"
39 39 iconPause = QtGui.QIcon()
40 40 iconPause.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH, icon_name) )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
41 41 self.actionPauseToolbar.setIcon(iconPause)
42 42
43 43 def restoreStartIcon(self):
44 44
45 45 icon_name = "start.png"
46 46 iconStart = QtGui.QIcon()
47 47 iconStart.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH, icon_name) )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
48 48 self.actionStarToolbar.setIcon(iconStart)
49 49
50 50 def changePauseIcon(self, paused=False):
51 51
52 52 if paused == True:
53 53 icon_name = "pausered.png"
54 54 else:
55 55 icon_name = "pause.png"
56 56
57 57 iconPause = QtGui.QIcon()
58 58 iconPause.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH, icon_name) )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
59 59 self.actionPauseToolbar.setIcon(iconPause)
60 60
61 61 return
62 62
63 63 def changeStartIcon(self, started=False):
64 64
65 65 if started == True:
66 66 icon_name = "startred.png"
67 67 else:
68 68 icon_name = "start.png"
69 69
70 70 iconStart = QtGui.QIcon()
71 71 iconStart.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH, icon_name) )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
72 72 self.actionStarToolbar.setIcon(iconStart)
73 73
74 74 return
75 75
76 76 def setupUi(self, MainWindow):
77 77
78 78 self.paused=False
79 79
80 80 MainWindow.setObjectName(_fromUtf8("MainWindow"))
81 81 MainWindow.resize(1200, 800)
82 82
83 83 self.centralWidget = QtGui.QWidget(MainWindow)
84 84 self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
85 85 self.gridLayout_16 = QtGui.QGridLayout(self.centralWidget)
86 86 self.gridLayout_16.setObjectName(_fromUtf8("gridLayout_16"))
87 87 self.splitter_2 = QtGui.QSplitter(self.centralWidget)
88 88 self.splitter_2.setOrientation(QtCore.Qt.Horizontal)
89 89 self.splitter_2.setObjectName(_fromUtf8("splitter_2"))
90 90 self.projectExplorerTree = QtGui.QTreeView(self.splitter_2)
91 91 self.projectExplorerTree.setObjectName(_fromUtf8("projectExplorerTree"))
92 92 self.splitter = QtGui.QSplitter(self.splitter_2)
93 93 self.splitter.setOrientation(QtCore.Qt.Vertical)
94 94 self.splitter.setObjectName(_fromUtf8("splitter"))
95 95 self.tabWidgetProject = QtGui.QTabWidget(self.splitter)
96 96 self.tabWidgetProject.setMinimumSize(QtCore.QSize(0, 278))
97 97 self.tabWidgetProject.setMaximumSize(QtCore.QSize(16777215, 16777215))
98 98 self.tabWidgetProject.setObjectName(_fromUtf8("tabWidgetProject"))
99 99
100 100 self.tabConsole = QtGui.QTabWidget(self.splitter)
101 101 self.tabConsole.setMinimumSize(QtCore.QSize(0, 0))
102 102 self.tabConsole.setObjectName(_fromUtf8("tabConsole"))
103 103 self.tab_5 = QtGui.QWidget()
104 104 self.tab_5.setObjectName(_fromUtf8("tab_5"))
105 105 self.gridLayout_4 = QtGui.QGridLayout(self.tab_5)
106 106 self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
107 107 self.console = QtGui.QTextEdit(self.tab_5)
108 108 self.console.setObjectName(_fromUtf8("console"))
109 109 self.gridLayout_4.addWidget(self.console, 0, 0, 1, 1)
110 110 self.tabConsole.addTab(self.tab_5, _fromUtf8(""))
111 111 self.tabWidget = QtGui.QTabWidget(self.splitter_2)
112 112 self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
113 113 self.tabProjectProperty = QtGui.QWidget()
114 114 self.tabProjectProperty.setObjectName(_fromUtf8("tabProjectProperty"))
115 115 self.gridLayout_8 = QtGui.QGridLayout(self.tabProjectProperty)
116 116 self.gridLayout_8.setObjectName(_fromUtf8("gridLayout_8"))
117 117 self.treeProjectProperties = QtGui.QTreeView(self.tabProjectProperty)
118 118 self.treeProjectProperties.setObjectName(_fromUtf8("treeProjectProperties"))
119 119 self.gridLayout_8.addWidget(self.treeProjectProperties, 0, 0, 1, 1)
120 120 self.tabWidget.addTab(self.tabProjectProperty, _fromUtf8(""))
121 121 self.gridLayout_16.addWidget(self.splitter_2, 1, 0, 1, 1)
122 122
123 123 MainWindow.setCentralWidget(self.centralWidget)
124 124 self.toolBar = QtGui.QToolBar(MainWindow)
125 125 self.toolBar.setObjectName(_fromUtf8("toolBar"))
126 126 MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
127 127
128 128 self.menuBar = QtGui.QMenuBar(MainWindow)
129 129 self.menuBar.setGeometry(QtCore.QRect(0, 0, 1065, 25))
130 130 self.menuBar.setObjectName(_fromUtf8("menuBar"))
131 131 self.menuProject = QtGui.QMenu(self.menuBar)
132 132 self.menuProject.setObjectName(_fromUtf8("menuProject"))
133 133 self.menuRun = QtGui.QMenu(self.menuBar)
134 134 self.menuRun.setObjectName(_fromUtf8("menuRun"))
135 135 self.menuOptions = QtGui.QMenu(self.menuBar)
136 136 self.menuOptions.setObjectName(_fromUtf8("menuOptions"))
137 137 self.menuHelp = QtGui.QMenu(self.menuBar)
138 138 self.menuHelp.setObjectName(_fromUtf8("menuHelp"))
139 139 MainWindow.setMenuBar(self.menuBar)
140 140
141 141 iconOpen = QtGui.QIcon()
142 142 iconOpen.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"open.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
143 143 iconCreate = QtGui.QIcon()
144 144 iconCreate.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"new.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
145 145 iconSave = QtGui.QIcon()
146 146 iconSave.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"save.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
147 147 iconStart = QtGui.QIcon()
148 148 iconStart.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"start.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
149 149 iconStop = QtGui.QIcon()
150 150 iconStop.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"stop.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
151 151 iconPause = QtGui.QIcon()
152 152 iconPause.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"pause.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
153 153 iconAddPU = QtGui.QIcon()
154 154 iconAddPU.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"branch.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
155 155 iconClose = QtGui.QIcon()
156 156 iconClose.addPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"close.png") )), QtGui.QIcon.Normal, QtGui.QIcon.Off)
157 157
158 158
159 159 self.actionOpen = QtGui.QAction(MainWindow)
160 160 self.actionOpen.setIcon(iconOpen)
161 161 self.actionOpen.setObjectName(_fromUtf8("actionOpen"))
162 162 self.actionCreate = QtGui.QAction(MainWindow)
163 163 self.actionCreate.setIcon(iconCreate)
164 164 self.actionCreate.setObjectName(_fromUtf8("actionCreate"))
165 165 self.actionSave = QtGui.QAction(MainWindow)
166 166 self.actionSave.setIcon(iconSave)
167 167 self.actionSave.setObjectName(_fromUtf8("actionSave"))
168 168 self.actionClose = QtGui.QAction(MainWindow)
169 169 self.actionClose.setIcon(iconClose)
170 170 self.actionClose.setObjectName(_fromUtf8("actionClose"))
171 171 self.actionStart = QtGui.QAction(MainWindow)
172 172 self.actionStart.setIcon(iconStart)
173 173 self.actionStart.setObjectName(_fromUtf8("actionStart"))
174 174 self.actionPause = QtGui.QAction(MainWindow)
175 175 self.actionPause.setIcon(iconPause)
176 176 self.actionPause.setObjectName(_fromUtf8("actionPause"))
177 177 self.actionStop = QtGui.QAction(MainWindow)
178 178 self.actionStop.setIcon(iconStop)
179 179 self.actionStop.setObjectName(_fromUtf8("actionStop"))
180 180 self.actionAbout = QtGui.QAction(MainWindow)
181 181 self.actionAbout.setObjectName(_fromUtf8("actionAbout"))
182 182
183 183 self.actionOpenToolbar = QtGui.QAction(MainWindow)
184 184 self.actionOpenToolbar.setIcon(iconOpen)
185 185 self.actionOpenToolbar.setObjectName(_fromUtf8("actionOpenToolbar"))
186 186 self.actionCreateToolbar = QtGui.QAction(MainWindow)
187 187 self.actionCreateToolbar.setIcon(iconCreate)
188 188 self.actionCreateToolbar.setObjectName(_fromUtf8("actionCreateToolbar"))
189 189 self.actionSaveToolbar = QtGui.QAction(MainWindow)
190 190 self.actionSaveToolbar.setIcon(iconSave)
191 191 self.actionSaveToolbar.setObjectName(_fromUtf8("actionSaveToolbar"))
192 192 self.actionStarToolbar = QtGui.QAction(MainWindow)
193 193 self.actionStarToolbar.setIcon(iconStart)
194 194 self.actionStarToolbar.setObjectName(_fromUtf8("actionStarToolbar"))
195 195 self.actionStopToolbar = QtGui.QAction(MainWindow)
196 196 self.actionStopToolbar.setIcon(iconStop)
197 197 self.actionStopToolbar.setObjectName(_fromUtf8("actionStopToolbar"))
198 198 self.actionPauseToolbar = QtGui.QAction(MainWindow)
199 199 self.actionPause.setIcon(iconPause)
200 200 self.actionPauseToolbar.setIcon(iconPause)
201 201 self.actionPauseToolbar.setObjectName(_fromUtf8("actionPauseToolbar"))
202 202 self.actionAddPU = QtGui.QAction(MainWindow)
203 203 self.actionAddPU.setIcon(iconAddPU)
204 204 self.actionAddPU.setObjectName(_fromUtf8("actionAddPU"))
205 205 self.actionFTP = QtGui.QAction(MainWindow)
206 206 self.actionFTP.setObjectName(_fromUtf8("actionFTP"))
207 207 self.toolBar.addAction(self.actionOpenToolbar)
208 208 self.toolBar.addSeparator()
209 209 self.toolBar.addAction(self.actionCreateToolbar)
210 210 self.toolBar.addSeparator()
211 211 self.toolBar.addAction(self.actionAddPU)
212 212 self.toolBar.addSeparator()
213 213 self.toolBar.addAction(self.actionSaveToolbar)
214 214 self.toolBar.addSeparator()
215 215 self.toolBar.addAction(self.actionStarToolbar)
216 216 self.toolBar.addSeparator()
217 217 self.toolBar.addAction(self.actionPauseToolbar)
218 218 self.toolBar.addSeparator()
219 219 self.toolBar.addAction(self.actionStopToolbar)
220 220 self.toolBar.addSeparator()
221 221
222 222 # self.actionPause.triggered.connect(self.changePauseIcon)
223 223 # self.actionPauseToolbar.triggered.connect(self.changePauseIcon)
224 224
225 225 self.menuProject.addAction(self.actionOpen)
226 226 self.menuProject.addAction(self.actionCreate)
227 227 self.menuProject.addAction(self.actionSave)
228 228 self.menuProject.addAction(self.actionClose)
229 229 self.menuRun.addAction(self.actionStart)
230 230 self.menuRun.addAction(self.actionPause)
231 231 self.menuRun.addAction(self.actionStop)
232 232 self.menuOptions.addAction(self.actionFTP)
233 233 self.menuHelp.addAction(self.actionAbout)
234 234 self.menuBar.addAction(self.menuProject.menuAction())
235 235 self.menuBar.addAction(self.menuRun.menuAction())
236 236 self.menuBar.addAction(self.menuOptions.menuAction())
237 237 self.menuBar.addAction(self.menuHelp.menuAction())
238 238
239 239 self.tabConsole.setCurrentIndex(0)
240 240 self.tabWidget.setCurrentIndex(0)
241 241
242 242 def retranslateUi(self, MainWindow):
243 243
244 244 MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
245 245
246 246 self.tabConsole.setTabText(self.tabConsole.indexOf(self.tab_5), _translate("MainWindow", "Console", None))
247 247
248 248 self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabProjectProperty), _translate("MainWindow", "Project Property", None))
249 249 self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar", None))
250 250 self.menuProject.setTitle(_translate("MainWindow", "Project", None))
251 251 self.menuRun.setTitle(_translate("MainWindow", "Run", None))
252 252 self.menuOptions.setTitle(_translate("MainWindow", "Options", None))
253 253 self.menuHelp.setTitle(_translate("MainWindow", "Help", None))
254 254 self.actionOpen.setText(_translate("MainWindow", "Open", None))
255 255 self.actionCreate.setText(_translate("MainWindow", "Create", None))
256 256 self.actionSave.setText(_translate("MainWindow", "Save", None))
257 257 self.actionClose.setText(_translate("MainWindow", "Close", None))
258 258 self.actionStart.setText(_translate("MainWindow", "Start", None))
259 259 self.actionPause.setText(_translate("MainWindow", "Pause", None))
260 260 self.actionStop.setText(_translate("MainWindow", "Stop", None))
261 261 self.actionAbout.setText(_translate("MainWindow", "About SChain", None))
262 262 self.actionOpenToolbar.setText(_translate("MainWindow", "openToolbar", None))
263 263 self.actionOpenToolbar.setToolTip(_translate("MainWindow", "Open a project", None))
264 264 self.actionCreateToolbar.setText(_translate("MainWindow", "createToolbar", None))
265 265 self.actionCreateToolbar.setToolTip(_translate("MainWindow", "Create a new project", None))
266 266 self.actionSaveToolbar.setText(_translate("MainWindow", "saveToolbar", None))
267 267 self.actionSaveToolbar.setToolTip(_translate("MainWindow", "Save a project", None))
268 268 self.actionStarToolbar.setText(_translate("MainWindow", "starToolbar", None))
269 269 self.actionStarToolbar.setToolTip(_translate("MainWindow", "Start process", None))
270 270 self.actionStopToolbar.setText(_translate("MainWindow", "stopToolbar", None))
271 271 self.actionStopToolbar.setToolTip(_translate("MainWindow", "Stop process", None))
272 272 self.actionPauseToolbar.setText(_translate("MainWindow", "pauseToolbar", None))
273 273 self.actionPauseToolbar.setToolTip(_translate("MainWindow", "Pause process", None))
274 274 self.actionAddPU.setText(_translate("MainWindow", "Add Processing Unit", None))
275 275 self.actionFTP.setText(_translate("MainWindow", "FTP", None))
276 276
277 277 def closeEvent(self, event):
278 278
279 279 reply = QtGui.QMessageBox.question(self, 'Message',
280 280 "Are you sure to quit?", QtGui.QMessageBox.Yes |
281 281 QtGui.QMessageBox.No, QtGui.QMessageBox.No)
282 282 if reply == QtGui.QMessageBox.Yes:
283 283 event.accept()
284 284 else:
285 285 event.ignore()
286 286
287 287 def aboutEvent(self):
288 288 title = "Signal Chain Processing Software v%s" %__version__
289 289 message = """
290 Developed by Jicamarca Radio Observatory
291 Any comment to miguel.urco@jro.igp.gob.pe
292 """
293
290 Developed by Jicamarca Radio Observatory
291 Any comment to miguel.urco@jro.igp.gob.pe
292 """
294 293 QtGui.QMessageBox.about(self, title, message)
295 294
296 295
297 296 class Ui_BasicWindow(Ui_EnvWindow, Ui_ProjectTab, Ui_VoltageTab, Ui_SpectraTab, Ui_SpectraHeisTab, Ui_CorrelationTab):
298 297
299 298 def setupUi(self, MainWindow):
300 299
301 300 Ui_EnvWindow.setupUi(self, MainWindow)
302 301
303 302 Ui_ProjectTab.setupUi(self)
304 303 Ui_VoltageTab.setupUi(self)
305 304 Ui_SpectraTab.setupUi(self)
306 305 Ui_SpectraHeisTab.setupUi(self)
307 306 Ui_CorrelationTab.setupUi(self)
308 307
309 308 self.retranslateUi(MainWindow)
310 309
311 310 QtCore.QMetaObject.connectSlotsByName(MainWindow)
312 311
313 312 def retranslateUi(self, MainWindow):
314 313
315 314 Ui_EnvWindow.retranslateUi(self, MainWindow)
316 315
317 316 Ui_ProjectTab.retranslateUi(self)
318 317 Ui_VoltageTab.retranslateUi(self)
319 318 Ui_SpectraTab.retranslateUi(self)
320 319 Ui_SpectraHeisTab.retranslateUi(self)
321 320 Ui_CorrelationTab.retranslateUi(self)
322 321
323 322
324 323 class Ui_AdvancedWindow(Ui_EnvWindow):
325 324
326 325 def setupUi(self, AdvancedWindow):
327 326
328 327 Ui_MainWindow.setupUi(self, AdvancedWindow)
329 328
330 329 def retranslateUi(self, AdvancedWindow):
331 330
332 331 Ui_MainWindow.retranslateUi(self, AdvancedWindow)
333 332
334 333
335 334
336 335 if __name__ == "__main__":
337 336 import sys
338 337 app = QtGui.QApplication(sys.argv)
339 338 MainWindow = QtGui.QMainWindow()
340 339 ui = Ui_BasicWindow()
341 340 ui.setupUi(MainWindow)
342 341 MainWindow.show()
343 342 sys.exit(app.exec_())
344 343
@@ -1,721 +1,724
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 5 '''
6 6 import numpy
7 7 import copy
8 8 import datetime
9 9
10 10 SPEED_OF_LIGHT = 299792458
11 11 SPEED_OF_LIGHT = 3e8
12 12
13 13 BASIC_STRUCTURE = numpy.dtype([
14 14 ('nSize','<u4'),
15 15 ('nVersion','<u2'),
16 16 ('nDataBlockId','<u4'),
17 17 ('nUtime','<u4'),
18 18 ('nMilsec','<u2'),
19 19 ('nTimezone','<i2'),
20 20 ('nDstflag','<i2'),
21 21 ('nErrorCount','<u4')
22 22 ])
23 23
24 24 SYSTEM_STRUCTURE = numpy.dtype([
25 25 ('nSize','<u4'),
26 26 ('nNumSamples','<u4'),
27 27 ('nNumProfiles','<u4'),
28 28 ('nNumChannels','<u4'),
29 29 ('nADCResolution','<u4'),
30 30 ('nPCDIOBusWidth','<u4'),
31 31 ])
32 32
33 33 RADAR_STRUCTURE = numpy.dtype([
34 34 ('nSize','<u4'),
35 35 ('nExpType','<u4'),
36 36 ('nNTx','<u4'),
37 37 ('fIpp','<f4'),
38 38 ('fTxA','<f4'),
39 39 ('fTxB','<f4'),
40 40 ('nNumWindows','<u4'),
41 41 ('nNumTaus','<u4'),
42 42 ('nCodeType','<u4'),
43 43 ('nLine6Function','<u4'),
44 44 ('nLine5Function','<u4'),
45 45 ('fClock','<f4'),
46 46 ('nPrePulseBefore','<u4'),
47 47 ('nPrePulseAfter','<u4'),
48 48 ('sRangeIPP','<a20'),
49 49 ('sRangeTxA','<a20'),
50 50 ('sRangeTxB','<a20'),
51 51 ])
52 52
53 53 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
54 54
55 55
56 56 PROCESSING_STRUCTURE = numpy.dtype([
57 57 ('nSize','<u4'),
58 58 ('nDataType','<u4'),
59 59 ('nSizeOfDataBlock','<u4'),
60 60 ('nProfilesperBlock','<u4'),
61 61 ('nDataBlocksperFile','<u4'),
62 62 ('nNumWindows','<u4'),
63 63 ('nProcessFlags','<u4'),
64 64 ('nCoherentIntegrations','<u4'),
65 65 ('nIncoherentIntegrations','<u4'),
66 66 ('nTotalSpectra','<u4')
67 67 ])
68 68
69 69 class Header(object):
70 70
71 71 def __init__(self):
72 72 raise
73 73
74 74 def copy(self):
75 75 return copy.deepcopy(self)
76 76
77 77 def read(self):
78 78
79 79 raise ValueError
80 80
81 81 def write(self):
82 82
83 83 raise ValueError
84 84
85 85 def printInfo(self):
86 86
87 print "#"*100
88 print self.__class__.__name__.upper()
89 print "#"*100
87 message = "#"*50 + "\n"
88 message += self.__class__.__name__.upper() + "\n"
89 message += "#"*50 + "\n"
90
90 91 for key in self.__dict__.keys():
91 print "%s = %s" %(key, self.__dict__[key])
92 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
93
94 print message
92 95
93 96 class BasicHeader(Header):
94 97
95 98 size = None
96 99 version = None
97 100 dataBlock = None
98 101 utc = None
99 102 ltc = None
100 103 miliSecond = None
101 104 timeZone = None
102 105 dstFlag = None
103 106 errorCount = None
104 107 datatime = None
105 108
106 109 __LOCALTIME = None
107 110
108 111 def __init__(self, useLocalTime=True):
109 112
110 113 self.size = 24
111 114 self.version = 0
112 115 self.dataBlock = 0
113 116 self.utc = 0
114 117 self.miliSecond = 0
115 118 self.timeZone = 0
116 119 self.dstFlag = 0
117 120 self.errorCount = 0
118 121
119 122 self.useLocalTime = useLocalTime
120 123
121 124 def read(self, fp):
122 125 try:
123 126
124 127 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
125 128
126 129 self.size = int(header['nSize'][0])
127 130 self.version = int(header['nVersion'][0])
128 131 self.dataBlock = int(header['nDataBlockId'][0])
129 132 self.utc = int(header['nUtime'][0])
130 133 self.miliSecond = int(header['nMilsec'][0])
131 134 self.timeZone = int(header['nTimezone'][0])
132 135 self.dstFlag = int(header['nDstflag'][0])
133 136 self.errorCount = int(header['nErrorCount'][0])
134 137
135 138 except Exception, e:
136 139 print "BasicHeader: "
137 140 print e
138 141 return 0
139 142
140 143 return 1
141 144
142 145 def write(self, fp):
143 146
144 147 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
145 148 header = numpy.array(headerTuple, BASIC_STRUCTURE)
146 149 header.tofile(fp)
147 150
148 151 return 1
149 152
150 153 def get_ltc(self):
151 154
152 155 return self.utc - self.timeZone*60
153 156
154 157 def set_ltc(self, value):
155 158
156 159 self.utc = value + self.timeZone*60
157 160
158 161 def get_datatime(self):
159 162
160 163 return datetime.datetime.utcfromtimestamp(self.ltc)
161 164
162 165 ltc = property(get_ltc, set_ltc)
163 166 datatime = property(get_datatime)
164 167
165 168 class SystemHeader(Header):
166 169
167 170 size = None
168 171 nSamples = None
169 172 nProfiles = None
170 173 nChannels = None
171 174 adcResolution = None
172 175 pciDioBusWidth = None
173 176
174 177 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
175 178
176 179 self.size = 24
177 180 self.nSamples = nSamples
178 181 self.nProfiles = nProfiles
179 182 self.nChannels = nChannels
180 183 self.adcResolution = adcResolution
181 184 self.pciDioBusWidth = pciDioBusWith
182 185
183 186 def read(self, fp):
184 187
185 188 startFp = fp.tell()
186 189
187 190 try:
188 191 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
189 192
190 193 self.size = header['nSize'][0]
191 194 self.nSamples = header['nNumSamples'][0]
192 195 self.nProfiles = header['nNumProfiles'][0]
193 196 self.nChannels = header['nNumChannels'][0]
194 197 self.adcResolution = header['nADCResolution'][0]
195 198 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
196 199
197 200 except Exception, e:
198 201 print "SystemHeader: " + e
199 202 return 0
200 203
201 204 endFp = self.size + startFp
202 205
203 206 if fp.tell() != endFp:
204 207 raise IOError, "System Header is not consistent"
205 208
206 209 return 1
207 210
208 211 def write(self, fp):
209 212
210 213 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
211 214 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
212 215 header.tofile(fp)
213 216
214 217 return 1
215 218
216 219 class RadarControllerHeader(Header):
217 220
218 221 size = None
219 222 expType = None
220 223 nTx = None
221 224 ipp = None
222 225 txA = None
223 226 txB = None
224 227 nWindows = None
225 228 numTaus = None
226 229 codeType = None
227 230 line6Function = None
228 231 line5Function = None
229 232 fClock = None
230 233 prePulseBefore = None
231 234 prePulserAfter = None
232 235 rangeIpp = None
233 236 rangeTxA = None
234 237 rangeTxB = None
235 238
236 239 __size = None
237 240
238 241 def __init__(self, expType=2, nTx=1,
239 242 ippKm=None, txA=0, txB=0,
240 243 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
241 244 numTaus=0, line6Function=0, line5Function=0, fClock=None,
242 245 prePulseBefore=0, prePulseAfter=0,
243 246 codeType=0, nCode=0, nBaud=0, code=None,
244 247 flip1=0, flip2=0):
245 248
246 249 self.size = 116
247 250 self.expType = expType
248 251 self.nTx = nTx
249 252 self.ipp = ippKm
250 253 self.txA = txA
251 254 self.txB = txB
252 255 self.rangeIpp = ippKm
253 256 self.rangeTxA = txA
254 257 self.rangeTxB = txB
255 258
256 259 self.nWindows = nWindows
257 260 self.numTaus = numTaus
258 261 self.codeType = codeType
259 262 self.line6Function = line6Function
260 263 self.line5Function = line5Function
261 264 self.fClock = fClock
262 265 self.prePulseBefore = prePulseBefore
263 266 self.prePulserAfter = prePulseAfter
264 267
265 268 self.nHeights = nHeights
266 269 self.firstHeight = firstHeight
267 270 self.deltaHeight = deltaHeight
268 271 self.samplesWin = nHeights
269 272
270 273 self.nCode = nCode
271 274 self.nBaud = nBaud
272 275 self.code = code
273 276 self.flip1 = flip1
274 277 self.flip2 = flip2
275 278
276 279 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
277 280 # self.dynamic = numpy.array([],numpy.dtype('byte'))
278 281
279 282 if self.fClock is None and self.deltaHeight is not None:
280 283 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
281 284
282 285 def read(self, fp):
283 286
284 287
285 288 startFp = fp.tell()
286 289 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
287 290
288 291 size = int(header['nSize'][0])
289 292 self.expType = int(header['nExpType'][0])
290 293 self.nTx = int(header['nNTx'][0])
291 294 self.ipp = float(header['fIpp'][0])
292 295 self.txA = float(header['fTxA'][0])
293 296 self.txB = float(header['fTxB'][0])
294 297 self.nWindows = int(header['nNumWindows'][0])
295 298 self.numTaus = int(header['nNumTaus'][0])
296 299 self.codeType = int(header['nCodeType'][0])
297 300 self.line6Function = int(header['nLine6Function'][0])
298 301 self.line5Function = int(header['nLine5Function'][0])
299 302 self.fClock = float(header['fClock'][0])
300 303 self.prePulseBefore = int(header['nPrePulseBefore'][0])
301 304 self.prePulserAfter = int(header['nPrePulseAfter'][0])
302 305 self.rangeIpp = header['sRangeIPP'][0]
303 306 self.rangeTxA = header['sRangeTxA'][0]
304 307 self.rangeTxB = header['sRangeTxB'][0]
305 308
306 309 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
307 310
308 311 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
309 312 self.firstHeight = samplingWindow['h0']
310 313 self.deltaHeight = samplingWindow['dh']
311 314 self.samplesWin = samplingWindow['nsa']
312 315
313 316 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
314 317
315 318 self.code_size = 0
316 319 if self.codeType != 0:
317 320 self.nCode = int(numpy.fromfile(fp,'<u4',1))
318 321 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
319 322
320 323 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
321 324 for ic in range(self.nCode):
322 325 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
323 326 for ib in range(self.nBaud-1,-1,-1):
324 327 code[ic,ib] = temp[ib/32]%2
325 328 temp[ib/32] = temp[ib/32]/2
326 329
327 330 self.code = 2.0*code - 1.0
328 331 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
329 332
330 333 # if self.line5Function == RCfunction.FLIP:
331 334 # self.flip1 = numpy.fromfile(fp,'<u4',1)
332 335 #
333 336 # if self.line6Function == RCfunction.FLIP:
334 337 # self.flip2 = numpy.fromfile(fp,'<u4',1)
335 338
336 339 endFp = size + startFp
337 340
338 341 if fp.tell() != endFp:
339 342 raise IOError, "Radar Controller Header is not consistent"
340 343
341 344 return 1
342 345
343 346 def write(self, fp):
344 347
345 348 headerTuple = (self.size,
346 349 self.expType,
347 350 self.nTx,
348 351 self.ipp,
349 352 self.txA,
350 353 self.txB,
351 354 self.nWindows,
352 355 self.numTaus,
353 356 self.codeType,
354 357 self.line6Function,
355 358 self.line5Function,
356 359 self.fClock,
357 360 self.prePulseBefore,
358 361 self.prePulserAfter,
359 362 self.rangeIpp,
360 363 self.rangeTxA,
361 364 self.rangeTxB)
362 365
363 366 header = numpy.array(headerTuple,RADAR_STRUCTURE)
364 367 header.tofile(fp)
365 368
366 369 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
367 370 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
368 371 samplingWindow.tofile(fp)
369 372
370 373 if self.numTaus > 0:
371 374 self.Taus.tofile(fp)
372 375
373 376 if self.codeType !=0:
374 377 nCode = numpy.array(self.nCode, '<u4')
375 378 nCode.tofile(fp)
376 379 nBaud = numpy.array(self.nBaud, '<u4')
377 380 nBaud.tofile(fp)
378 381 code1 = (self.code + 1.0)/2.
379 382
380 383 for ic in range(self.nCode):
381 384 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
382 385 start = 0
383 386 end = 32
384 387 for i in range(len(tempx)):
385 388 code_selected = code1[ic,start:end]
386 389 for j in range(len(code_selected)-1,-1,-1):
387 390 if code_selected[j] == 1:
388 391 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
389 392 start = start + 32
390 393 end = end + 32
391 394
392 395 tempx = tempx.astype('u4')
393 396 tempx.tofile(fp)
394 397
395 398 # if self.line5Function == RCfunction.FLIP:
396 399 # self.flip1.tofile(fp)
397 400 #
398 401 # if self.line6Function == RCfunction.FLIP:
399 402 # self.flip2.tofile(fp)
400 403
401 404 return 1
402 405
403 406 def get_ippSeconds(self):
404 407 '''
405 408 '''
406 409 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
407 410
408 411 return ippSeconds
409 412
410 413 def set_ippSeconds(self, ippSeconds):
411 414 '''
412 415 '''
413 416
414 417 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
415 418
416 419 return
417 420
418 421 def get_size(self):
419 422
420 423 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
421 424
422 425 if self.codeType != 0:
423 426 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
424 427
425 428 return self.__size
426 429
427 430 def set_size(self, value):
428 431
429 432 self.__size = value
430 433
431 434 return
432 435
433 436 ippSeconds = property(get_ippSeconds, set_ippSeconds)
434 437 size = property(get_size, set_size)
435 438
436 439 class ProcessingHeader(Header):
437 440
438 441 # size = None
439 442 dtype = None
440 443 blockSize = None
441 444 profilesPerBlock = None
442 445 dataBlocksPerFile = None
443 446 nWindows = None
444 447 processFlags = None
445 448 nCohInt = None
446 449 nIncohInt = None
447 450 totalSpectra = None
448 451
449 452 flag_dc = None
450 453 flag_cspc = None
451 454
452 455 def __init__(self):
453 456
454 457 # self.size = 0
455 458 self.dtype = 0
456 459 self.blockSize = 0
457 460 self.profilesPerBlock = 0
458 461 self.dataBlocksPerFile = 0
459 462 self.nWindows = 0
460 463 self.processFlags = 0
461 464 self.nCohInt = 0
462 465 self.nIncohInt = 0
463 466 self.totalSpectra = 0
464 467
465 468 self.nHeights = 0
466 469 self.firstHeight = 0
467 470 self.deltaHeight = 0
468 471 self.samplesWin = 0
469 472 self.spectraComb = 0
470 473 self.nCode = None
471 474 self.code = None
472 475 self.nBaud = None
473 476
474 477 self.shif_fft = False
475 478 self.flag_dc = False
476 479 self.flag_cspc = False
477 480 self.flag_decode = False
478 481 self.flag_deflip = False
479 482
480 483 def read(self, fp):
481 484
482 485 startFp = fp.tell()
483 486
484 487 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
485 488
486 489 size = int(header['nSize'][0])
487 490 self.dtype = int(header['nDataType'][0])
488 491 self.blockSize = int(header['nSizeOfDataBlock'][0])
489 492 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
490 493 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
491 494 self.nWindows = int(header['nNumWindows'][0])
492 495 self.processFlags = header['nProcessFlags']
493 496 self.nCohInt = int(header['nCoherentIntegrations'][0])
494 497 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
495 498 self.totalSpectra = int(header['nTotalSpectra'][0])
496 499
497 500 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
498 501
499 502 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
500 503 self.firstHeight = float(samplingWindow['h0'][0])
501 504 self.deltaHeight = float(samplingWindow['dh'][0])
502 505 self.samplesWin = samplingWindow['nsa'][0]
503 506
504 507 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
505 508
506 509 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
507 510 self.nCode = int(numpy.fromfile(fp,'<u4',1))
508 511 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
509 512 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
510 513
511 514 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
512 515 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
513 516 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
514 517
515 518 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
516 519 self.shif_fft = True
517 520 else:
518 521 self.shif_fft = False
519 522
520 523 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
521 524 self.flag_dc = True
522 525 else:
523 526 self.flag_dc = False
524 527
525 528 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
526 529 self.flag_decode = True
527 530 else:
528 531 self.flag_decode = False
529 532
530 533 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
531 534 self.flag_deflip = True
532 535 else:
533 536 self.flag_deflip = False
534 537
535 538 nChannels = 0
536 539 nPairs = 0
537 540 pairList = []
538 541
539 542 for i in range( 0, self.totalSpectra*2, 2 ):
540 543 if self.spectraComb[i] == self.spectraComb[i+1]:
541 544 nChannels = nChannels + 1 #par de canales iguales
542 545 else:
543 546 nPairs = nPairs + 1 #par de canales diferentes
544 547 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
545 548
546 549 self.flag_cspc = False
547 550 if nPairs > 0:
548 551 self.flag_cspc = True
549 552
550 553 endFp = size + startFp
551 554
552 555 if fp.tell() != endFp:
553 556 raise IOError, "Processing Header is not consistent"
554 557
555 558 return 1
556 559
557 560 def write(self, fp):
558 561 #Clear DEFINE_PROCESS_CODE
559 562 # self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
560 563
561 564 headerTuple = (self.size,
562 565 self.dtype,
563 566 self.blockSize,
564 567 self.profilesPerBlock,
565 568 self.dataBlocksPerFile,
566 569 self.nWindows,
567 570 self.processFlags,
568 571 self.nCohInt,
569 572 self.nIncohInt,
570 573 self.totalSpectra)
571 574
572 575 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
573 576 header.tofile(fp)
574 577
575 578 if self.nWindows != 0:
576 579 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
577 580 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
578 581 samplingWindow.tofile(fp)
579 582
580 583 if self.totalSpectra != 0:
581 584 # spectraComb = numpy.array([],numpy.dtype('u1'))
582 585 spectraComb = self.spectraComb
583 586 spectraComb.tofile(fp)
584 587
585 588 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
586 589 nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
587 590 nCode.tofile(fp)
588 591
589 592 nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
590 593 nBaud.tofile(fp)
591 594
592 595 code = self.code.reshape(self.nCode*self.nBaud)
593 596 code = code.astype(numpy.dtype('<f4'))
594 597 code.tofile(fp)
595 598
596 599 return 1
597 600
598 601 def get_size(self):
599 602
600 603 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
601 604
602 605 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
603 606 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
604 607 self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
605 608
606 609 return self.__size
607 610
608 611 def set_size(self, value):
609 612
610 613 self.__size = value
611 614
612 615 return
613 616
614 617 size = property(get_size, set_size)
615 618
616 619 class RCfunction:
617 620 NONE=0
618 621 FLIP=1
619 622 CODE=2
620 623 SAMPLING=3
621 624 LIN6DIV256=4
622 625 SYNCHRO=5
623 626
624 627 class nCodeType:
625 628 NONE=0
626 629 USERDEFINE=1
627 630 BARKER2=2
628 631 BARKER3=3
629 632 BARKER4=4
630 633 BARKER5=5
631 634 BARKER7=6
632 635 BARKER11=7
633 636 BARKER13=8
634 637 AC128=9
635 638 COMPLEMENTARYCODE2=10
636 639 COMPLEMENTARYCODE4=11
637 640 COMPLEMENTARYCODE8=12
638 641 COMPLEMENTARYCODE16=13
639 642 COMPLEMENTARYCODE32=14
640 643 COMPLEMENTARYCODE64=15
641 644 COMPLEMENTARYCODE128=16
642 645 CODE_BINARY28=17
643 646
644 647 class PROCFLAG:
645 648
646 649 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
647 650 DECODE_DATA = numpy.uint32(0x00000002)
648 651 SPECTRA_CALC = numpy.uint32(0x00000004)
649 652 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
650 653 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
651 654 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
652 655
653 656 DATATYPE_CHAR = numpy.uint32(0x00000040)
654 657 DATATYPE_SHORT = numpy.uint32(0x00000080)
655 658 DATATYPE_LONG = numpy.uint32(0x00000100)
656 659 DATATYPE_INT64 = numpy.uint32(0x00000200)
657 660 DATATYPE_FLOAT = numpy.uint32(0x00000400)
658 661 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
659 662
660 663 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
661 664 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
662 665 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
663 666
664 667 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
665 668 DEFLIP_DATA = numpy.uint32(0x00010000)
666 669 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
667 670
668 671 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
669 672 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
670 673 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
671 674 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
672 675 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
673 676
674 677 EXP_NAME_ESP = numpy.uint32(0x00200000)
675 678 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
676 679
677 680 OPERATION_MASK = numpy.uint32(0x0000003F)
678 681 DATATYPE_MASK = numpy.uint32(0x00000FC0)
679 682 DATAARRANGE_MASK = numpy.uint32(0x00007000)
680 683 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
681 684
682 685 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
683 686 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
684 687 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
685 688 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
686 689 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
687 690 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
688 691
689 692 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
690 693
691 694 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
692 695 PROCFLAG.DATATYPE_SHORT,
693 696 PROCFLAG.DATATYPE_LONG,
694 697 PROCFLAG.DATATYPE_INT64,
695 698 PROCFLAG.DATATYPE_FLOAT,
696 699 PROCFLAG.DATATYPE_DOUBLE]
697 700
698 701 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
699 702
700 703 def get_dtype_index(numpy_dtype):
701 704
702 705 index = None
703 706
704 707 for i in range(len(NUMPY_DTYPE_LIST)):
705 708 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
706 709 index = i
707 710 break
708 711
709 712 return index
710 713
711 714 def get_numpy_dtype(index):
712 715
713 716 return NUMPY_DTYPE_LIST[index]
714 717
715 718 def get_procflag_dtype(index):
716 719
717 720 return PROCFLAG_DTYPE_LIST[index]
718 721
719 722 def get_dtype_width(index):
720 723
721 724 return DTYPE_WIDTH[index] No newline at end of file
@@ -1,442 +1,442
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 matplotlib.use('GTKAgg')
10 matplotlib.use('WXAgg')
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 *
16 16
17 17 ###########################################
18 18 #Actualizacion de las funciones del driver
19 19 ###########################################
20 20
21 21 def createFigure(id, wintitle, width, height, facecolor="w", show=True):
22 22
23 23 matplotlib.pyplot.ioff()
24 24 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor)
25 25 fig.canvas.manager.set_window_title(wintitle)
26 26 fig.canvas.manager.resize(width, height)
27 27 matplotlib.pyplot.ion()
28 28 if show:
29 29 matplotlib.pyplot.show()
30 30
31 31 return fig
32 32
33 33 def closeFigure(show=False, fig=None):
34 34
35 35 matplotlib.pyplot.ioff()
36 matplotlib.pyplot.pause(0.1)
36 # matplotlib.pyplot.pause(0.1)
37 37
38 38 if show:
39 39 matplotlib.pyplot.show()
40 40
41 41 if fig != None:
42 matplotlib.pyplot.close(fig)
43 matplotlib.pyplot.pause(0.1)
44 matplotlib.pyplot.ion()
42 matplotlib.pyplot.close(fig.number)
43 # matplotlib.pyplot.pause(0.1)
44 # matplotlib.pyplot.ion()
45 45 return
46 46
47 47 matplotlib.pyplot.close("all")
48 matplotlib.pyplot.pause(0.1)
49 matplotlib.pyplot.ion()
48 # matplotlib.pyplot.pause(0.1)
49 # matplotlib.pyplot.ion()
50 50 return
51 51
52 52 def saveFigure(fig, filename):
53 53
54 matplotlib.pyplot.ioff()
54 # matplotlib.pyplot.ioff()
55 55 fig.savefig(filename)
56 matplotlib.pyplot.ion()
56 # matplotlib.pyplot.ion()
57 57
58 58 def setWinTitle(fig, title):
59 59
60 60 fig.canvas.manager.set_window_title(title)
61 61
62 62 def setTitle(fig, title):
63 63
64 64 fig.suptitle(title)
65 65
66 66 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
67 67
68 68 matplotlib.pyplot.ioff()
69 69 matplotlib.pyplot.figure(fig.number)
70 70 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
71 71 (xpos, ypos),
72 72 colspan=colspan,
73 73 rowspan=rowspan,
74 74 polar=polar)
75 75
76 76 matplotlib.pyplot.ion()
77 77 return axes
78 78
79 79 def setAxesText(ax, text):
80 80
81 81 ax.annotate(text,
82 82 xy = (.1, .99),
83 83 xycoords = 'figure fraction',
84 84 horizontalalignment = 'left',
85 85 verticalalignment = 'top',
86 86 fontsize = 10)
87 87
88 88 def printLabels(ax, xlabel, ylabel, title):
89 89
90 90 ax.set_xlabel(xlabel, size=11)
91 91 ax.set_ylabel(ylabel, size=11)
92 92 ax.set_title(title, size=8)
93 93
94 94 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
95 95 ticksize=9, xtick_visible=True, ytick_visible=True,
96 96 nxticks=4, nyticks=10,
97 97 grid=None,color='blue'):
98 98
99 99 """
100 100
101 101 Input:
102 102 grid : None, 'both', 'x', 'y'
103 103 """
104 104
105 105 matplotlib.pyplot.ioff()
106 106
107 107 ax.set_xlim([xmin,xmax])
108 108 ax.set_ylim([ymin,ymax])
109 109
110 110 printLabels(ax, xlabel, ylabel, title)
111 111
112 112 ######################################################
113 113 if (xmax-xmin)<=1:
114 114 xtickspos = numpy.linspace(xmin,xmax,nxticks)
115 115 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
116 116 ax.set_xticks(xtickspos)
117 117 else:
118 118 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
119 119 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
120 120 ax.set_xticks(xtickspos)
121 121
122 122 for tick in ax.get_xticklabels():
123 123 tick.set_visible(xtick_visible)
124 124
125 125 for tick in ax.xaxis.get_major_ticks():
126 126 tick.label.set_fontsize(ticksize)
127 127
128 128 ######################################################
129 129 for tick in ax.get_yticklabels():
130 130 tick.set_visible(ytick_visible)
131 131
132 132 for tick in ax.yaxis.get_major_ticks():
133 133 tick.label.set_fontsize(ticksize)
134 134
135 135 ax.plot(x, y, color=color)
136 136 iplot = ax.lines[-1]
137 137
138 138 ######################################################
139 139 if '0.' in matplotlib.__version__[0:2]:
140 140 print "The matplotlib version has to be updated to 1.1 or newer"
141 141 return iplot
142 142
143 143 if '1.0.' in matplotlib.__version__[0:4]:
144 144 print "The matplotlib version has to be updated to 1.1 or newer"
145 145 return iplot
146 146
147 147 if grid != None:
148 148 ax.grid(b=True, which='major', axis=grid)
149 149
150 150 matplotlib.pyplot.tight_layout()
151 151
152 152 matplotlib.pyplot.ion()
153 153
154 154 return iplot
155 155
156 156 def set_linedata(ax, x, y, idline):
157 157
158 158 ax.lines[idline].set_data(x,y)
159 159
160 160 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
161 161
162 162 ax = iplot.get_axes()
163 163
164 164 printLabels(ax, xlabel, ylabel, title)
165 165
166 166 set_linedata(ax, x, y, idline=0)
167 167
168 168 def addpline(ax, x, y, color, linestyle, lw):
169 169
170 170 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
171 171
172 172
173 173 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
174 174 xlabel='', ylabel='', title='', ticksize = 9,
175 175 colormap='jet',cblabel='', cbsize="5%",
176 176 XAxisAsTime=False):
177 177
178 178 matplotlib.pyplot.ioff()
179 179
180 180 divider = make_axes_locatable(ax)
181 181 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
182 182 fig = ax.get_figure()
183 183 fig.add_axes(ax_cb)
184 184
185 185 ax.set_xlim([xmin,xmax])
186 186 ax.set_ylim([ymin,ymax])
187 187
188 188 printLabels(ax, xlabel, ylabel, title)
189 189
190 190 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
191 191 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
192 192 cb.set_label(cblabel)
193 193
194 194 # for tl in ax_cb.get_yticklabels():
195 195 # tl.set_visible(True)
196 196
197 197 for tick in ax.yaxis.get_major_ticks():
198 198 tick.label.set_fontsize(ticksize)
199 199
200 200 for tick in ax.xaxis.get_major_ticks():
201 201 tick.label.set_fontsize(ticksize)
202 202
203 203 for tick in cb.ax.get_yticklabels():
204 204 tick.set_fontsize(ticksize)
205 205
206 206 ax_cb.yaxis.tick_right()
207 207
208 208 if '0.' in matplotlib.__version__[0:2]:
209 209 print "The matplotlib version has to be updated to 1.1 or newer"
210 210 return imesh
211 211
212 212 if '1.0.' in matplotlib.__version__[0:4]:
213 213 print "The matplotlib version has to be updated to 1.1 or newer"
214 214 return imesh
215 215
216 216 matplotlib.pyplot.tight_layout()
217 217
218 218 if XAxisAsTime:
219 219
220 220 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
221 221 ax.xaxis.set_major_formatter(FuncFormatter(func))
222 222 ax.xaxis.set_major_locator(LinearLocator(7))
223 223
224 224 matplotlib.pyplot.ion()
225 225 return imesh
226 226
227 227 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
228 228
229 229 z = z.T
230 230 ax = imesh.get_axes()
231 231 printLabels(ax, xlabel, ylabel, title)
232 232 imesh.set_array(z.ravel())
233 233
234 234 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
235 235
236 236 printLabels(ax, xlabel, ylabel, title)
237 237
238 238 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
239 239
240 240 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
241 241
242 242 printLabels(ax, xlabel, ylabel, title)
243 243
244 244 ax.collections.remove(ax.collections[0])
245 245
246 246 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
247 247
248 248 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
249 249 ticksize=9, xtick_visible=True, ytick_visible=True,
250 250 nxticks=4, nyticks=10,
251 251 grid=None):
252 252
253 253 """
254 254
255 255 Input:
256 256 grid : None, 'both', 'x', 'y'
257 257 """
258 258
259 259 matplotlib.pyplot.ioff()
260 260
261 261 lines = ax.plot(x.T, y)
262 262 leg = ax.legend(lines, legendlabels, loc='upper right')
263 263 leg.get_frame().set_alpha(0.5)
264 264 ax.set_xlim([xmin,xmax])
265 265 ax.set_ylim([ymin,ymax])
266 266 printLabels(ax, xlabel, ylabel, title)
267 267
268 268 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
269 269 ax.set_xticks(xtickspos)
270 270
271 271 for tick in ax.get_xticklabels():
272 272 tick.set_visible(xtick_visible)
273 273
274 274 for tick in ax.xaxis.get_major_ticks():
275 275 tick.label.set_fontsize(ticksize)
276 276
277 277 for tick in ax.get_yticklabels():
278 278 tick.set_visible(ytick_visible)
279 279
280 280 for tick in ax.yaxis.get_major_ticks():
281 281 tick.label.set_fontsize(ticksize)
282 282
283 283 iplot = ax.lines[-1]
284 284
285 285 if '0.' in matplotlib.__version__[0:2]:
286 286 print "The matplotlib version has to be updated to 1.1 or newer"
287 287 return iplot
288 288
289 289 if '1.0.' in matplotlib.__version__[0:4]:
290 290 print "The matplotlib version has to be updated to 1.1 or newer"
291 291 return iplot
292 292
293 293 if grid != None:
294 294 ax.grid(b=True, which='major', axis=grid)
295 295
296 296 matplotlib.pyplot.tight_layout()
297 297
298 298 matplotlib.pyplot.ion()
299 299
300 300 return iplot
301 301
302 302
303 303 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
304 304
305 305 ax = iplot.get_axes()
306 306
307 307 printLabels(ax, xlabel, ylabel, title)
308 308
309 309 for i in range(len(ax.lines)):
310 310 line = ax.lines[i]
311 311 line.set_data(x[i,:],y)
312 312
313 313 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
314 314 ticksize=9, xtick_visible=True, ytick_visible=True,
315 315 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
316 316 grid=None, XAxisAsTime=False):
317 317
318 318 """
319 319
320 320 Input:
321 321 grid : None, 'both', 'x', 'y'
322 322 """
323 323
324 324 matplotlib.pyplot.ioff()
325 325
326 326 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
327 327 lines = ax.plot(x, y.T, linestyle=linestyle, marker=marker, markersize=markersize)
328 328 leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
329 329 handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
330 330
331 331 for label in leg.get_texts(): label.set_fontsize(9)
332 332
333 333 ax.set_xlim([xmin,xmax])
334 334 ax.set_ylim([ymin,ymax])
335 335 printLabels(ax, xlabel, ylabel, title)
336 336
337 337 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
338 338 # ax.set_xticks(xtickspos)
339 339
340 340 for tick in ax.get_xticklabels():
341 341 tick.set_visible(xtick_visible)
342 342
343 343 for tick in ax.xaxis.get_major_ticks():
344 344 tick.label.set_fontsize(ticksize)
345 345
346 346 for tick in ax.get_yticklabels():
347 347 tick.set_visible(ytick_visible)
348 348
349 349 for tick in ax.yaxis.get_major_ticks():
350 350 tick.label.set_fontsize(ticksize)
351 351
352 352 iplot = ax.lines[-1]
353 353
354 354 if '0.' in matplotlib.__version__[0:2]:
355 355 print "The matplotlib version has to be updated to 1.1 or newer"
356 356 return iplot
357 357
358 358 if '1.0.' in matplotlib.__version__[0:4]:
359 359 print "The matplotlib version has to be updated to 1.1 or newer"
360 360 return iplot
361 361
362 362 if grid != None:
363 363 ax.grid(b=True, which='major', axis=grid)
364 364
365 365 matplotlib.pyplot.tight_layout()
366 366
367 367 if XAxisAsTime:
368 368
369 369 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
370 370 ax.xaxis.set_major_formatter(FuncFormatter(func))
371 371 ax.xaxis.set_major_locator(LinearLocator(7))
372 372
373 373 matplotlib.pyplot.ion()
374 374
375 375 return iplot
376 376
377 377 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
378 378
379 379 ax = iplot.get_axes()
380 380
381 381 printLabels(ax, xlabel, ylabel, title)
382 382
383 383 for i in range(len(ax.lines)):
384 384 line = ax.lines[i]
385 385 line.set_data(x,y[i,:])
386 386
387 387 def createPolar(ax, x, y,
388 388 xlabel='', ylabel='', title='', ticksize = 9,
389 389 colormap='jet',cblabel='', cbsize="5%",
390 390 XAxisAsTime=False):
391 391
392 392 matplotlib.pyplot.ioff()
393 393
394 394 ax.plot(x,y,'bo', markersize=5)
395 395 # ax.set_rmax(90)
396 396 ax.set_ylim(0,90)
397 397 ax.set_yticks(numpy.arange(0,90,20))
398 398 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
399 399 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
400 400 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
401 401 ax.yaxis.labelpad = 230
402 402 printLabels(ax, xlabel, ylabel, title)
403 403 iplot = ax.lines[-1]
404 404
405 405 if '0.' in matplotlib.__version__[0:2]:
406 406 print "The matplotlib version has to be updated to 1.1 or newer"
407 407 return iplot
408 408
409 409 if '1.0.' in matplotlib.__version__[0:4]:
410 410 print "The matplotlib version has to be updated to 1.1 or newer"
411 411 return iplot
412 412
413 413 # if grid != None:
414 414 # ax.grid(b=True, which='major', axis=grid)
415 415
416 416 matplotlib.pyplot.tight_layout()
417 417
418 418 matplotlib.pyplot.ion()
419 419
420 420
421 421 return iplot
422 422
423 423 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
424 424
425 425 ax = iplot.get_axes()
426 426
427 427 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
428 428 printLabels(ax, xlabel, ylabel, title)
429 429
430 430 set_linedata(ax, x, y, idline=0)
431 431
432 432 def draw(fig):
433 433
434 434 if type(fig) == 'int':
435 435 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
436 436
437 437 fig.canvas.draw()
438 438
439 439 def pause(interval=0.000001):
440 440
441 441 matplotlib.pyplot.pause(interval)
442 442 No newline at end of file
@@ -1,38 +1,39
1 1 '''
2 2 Created on Jul 16, 2014
3 3
4 4 @author: roj-idl71
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.utils',
23 23 'schainpy.gui',
24 24 'schainpy.gui.figures',
25 25 'schainpy.gui.viewcontroller',
26 26 'schainpy.gui.viewer',
27 27 'schainpy.gui.viewer.windows'},
28 28 py_modules=['schainpy.serializer.DataTranslate',
29 29 'schainpy.serializer.JROSerializer'],
30 30 package_data={'schainpy.gui.figures': ['*.png']},
31 31 include_package_data=True,
32 32 scripts =['schainpy/gui/schainGUI'],
33 33 install_requires=["numpy >= 1.6.0",
34 34 "scipy >= 0.9.0",
35 35 "h5py >= 2.0.1",
36 "wxpython >= 2.8",
36 37 "matplotlib >= 1.0.0"
37 38 ],
38 39 ) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now