##// END OF EJS Templates
Version 2.1.3: ...
Miguel Valdez -
r664:9aee9f7a8e3e
parent child
Show More

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

@@ -1,8 +1,15
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 -jroplot_heispectra.py: SpectraHeisScope was not showing the right channel
8
9 2.1.3:
10 -jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
11 -jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
12 Bug fixed selecting heights by block (selecting profiles instead heights)
13 -jroproc_voltage.py: New feature added: decoding data by block using FFT.
14 -jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits object instead schainpy.mode.data.jrodata.Fits object.
15 -jroIO_heispectra.py: Channel index list does not exist. 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.2" No newline at end of file
7 __version__ = "2.1.3" No newline at end of file
@@ -1,1097 +1,1096
1 1 '''
2 2 Created on September , 2012
3 3 @author:
4 4 '''
5 from xml.etree.ElementTree import Element, SubElement
6 from xml.etree import ElementTree as ET
5 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
7 6 from xml.dom import minidom
8 7
9 8 from model import *
10 9
11 10 try:
12 11 from gevent import sleep
13 12 except:
14 13 from time import sleep
15 14
16 15 import ast
17 16
18 17 def prettify(elem):
19 18 """Return a pretty-printed XML string for the Element.
20 19 """
21 rough_string = ET.tostring(elem, 'utf-8')
20 rough_string = tostring(elem, 'utf-8')
22 21 reparsed = minidom.parseString(rough_string)
23 22 return reparsed.toprettyxml(indent=" ")
24 23
25 24 class ParameterConf():
26 25
27 26 id = None
28 27 name = None
29 28 value = None
30 29 format = None
31 30
32 31 __formated_value = None
33 32
34 33 ELEMENTNAME = 'Parameter'
35 34
36 35 def __init__(self):
37 36
38 37 self.format = 'str'
39 38
40 39 def getElementName(self):
41 40
42 41 return self.ELEMENTNAME
43 42
44 43 def getValue(self):
45 44
46 45 value = self.value
47 46 format = self.format
48 47
49 48 if self.__formated_value != None:
50 49
51 50 return self.__formated_value
52 51
53 52 if format == 'str':
54 53 self.__formated_value = str(value)
55 54 return self.__formated_value
56 55
57 56 if value == '':
58 57 raise ValueError, "%s: This parameter value is empty" %self.name
59 58
60 59 if format == 'bool':
61 60 value = int(value)
62 61
63 62 if format == 'list':
64 63 strList = value.split(',')
65 64
66 65 self.__formated_value = strList
67 66
68 67 return self.__formated_value
69 68
70 69 if format == 'intlist':
71 70 """
72 71 Example:
73 72 value = (0,1,2)
74 73 """
75 74 value = value.replace('(', '')
76 75 value = value.replace(')', '')
77 76
78 77 value = value.replace('[', '')
79 78 value = value.replace(']', '')
80 79
81 80 strList = value.split(',')
82 81 intList = [int(float(x)) for x in strList]
83 82
84 83 self.__formated_value = intList
85 84
86 85 return self.__formated_value
87 86
88 87 if format == 'floatlist':
89 88 """
90 89 Example:
91 90 value = (0.5, 1.4, 2.7)
92 91 """
93 92
94 93 value = value.replace('(', '')
95 94 value = value.replace(')', '')
96 95
97 96 value = value.replace('[', '')
98 97 value = value.replace(']', '')
99 98
100 99 strList = value.split(',')
101 100 floatList = [float(x) for x in strList]
102 101
103 102 self.__formated_value = floatList
104 103
105 104 return self.__formated_value
106 105
107 106 if format == 'date':
108 107 strList = value.split('/')
109 108 intList = [int(x) for x in strList]
110 109 date = datetime.date(intList[0], intList[1], intList[2])
111 110
112 111 self.__formated_value = date
113 112
114 113 return self.__formated_value
115 114
116 115 if format == 'time':
117 116 strList = value.split(':')
118 117 intList = [int(x) for x in strList]
119 118 time = datetime.time(intList[0], intList[1], intList[2])
120 119
121 120 self.__formated_value = time
122 121
123 122 return self.__formated_value
124 123
125 124 if format == 'pairslist':
126 125 """
127 126 Example:
128 127 value = (0,1),(1,2)
129 128 """
130 129
131 130 value = value.replace('(', '')
132 131 value = value.replace(')', '')
133 132
134 133 value = value.replace('[', '')
135 134 value = value.replace(']', '')
136 135
137 136 strList = value.split(',')
138 137 intList = [int(item) for item in strList]
139 138 pairList = []
140 139 for i in range(len(intList)/2):
141 140 pairList.append((intList[i*2], intList[i*2 + 1]))
142 141
143 142 self.__formated_value = pairList
144 143
145 144 return self.__formated_value
146 145
147 146 if format == 'multilist':
148 147 """
149 148 Example:
150 149 value = (0,1,2),(3,4,5)
151 150 """
152 151 multiList = ast.literal_eval(value)
153 152
154 153 if type(multiList[0]) == int:
155 154 multiList = ast.literal_eval("(" + value + ")")
156 155
157 156 self.__formated_value = multiList
158 157
159 158 return self.__formated_value
160 159
161 160 format_func = eval(format)
162 161
163 162 self.__formated_value = format_func(value)
164 163
165 164 return self.__formated_value
166 165
167 166 def updateId(self, new_id):
168 167
169 168 self.id = str(new_id)
170 169
171 170 def setup(self, id, name, value, format='str'):
172 171
173 172 self.id = str(id)
174 173 self.name = name
175 174 self.value = str(value)
176 175 self.format = str.lower(format)
177 176
178 177 try:
179 178 self.getValue()
180 179 except:
181 180 return 0
182 181
183 182 return 1
184 183
185 184 def update(self, name, value, format='str'):
186 185
187 186 self.name = name
188 187 self.value = str(value)
189 188 self.format = format
190 189
191 190 def makeXml(self, opElement):
192 191
193 192 parmElement = SubElement(opElement, self.ELEMENTNAME)
194 193 parmElement.set('id', str(self.id))
195 194 parmElement.set('name', self.name)
196 195 parmElement.set('value', self.value)
197 196 parmElement.set('format', self.format)
198 197
199 198 def readXml(self, parmElement):
200 199
201 200 self.id = parmElement.get('id')
202 201 self.name = parmElement.get('name')
203 202 self.value = parmElement.get('value')
204 203 self.format = str.lower(parmElement.get('format'))
205 204
206 205 #Compatible with old signal chain version
207 206 if self.format == 'int' and self.name == 'idfigure':
208 207 self.name = 'id'
209 208
210 209 def printattr(self):
211 210
212 211 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
213 212
214 213 class OperationConf():
215 214
216 215 id = None
217 216 name = None
218 217 priority = None
219 218 type = None
220 219
221 220 parmConfObjList = []
222 221
223 222 ELEMENTNAME = 'Operation'
224 223
225 224 def __init__(self):
226 225
227 226 self.id = '0'
228 227 self.name = None
229 228 self.priority = None
230 229 self.type = 'self'
231 230
232 231
233 232 def __getNewId(self):
234 233
235 234 return int(self.id)*10 + len(self.parmConfObjList) + 1
236 235
237 236 def updateId(self, new_id):
238 237
239 238 self.id = str(new_id)
240 239
241 240 n = 1
242 241 for parmObj in self.parmConfObjList:
243 242
244 243 idParm = str(int(new_id)*10 + n)
245 244 parmObj.updateId(idParm)
246 245
247 246 n += 1
248 247
249 248 def getElementName(self):
250 249
251 250 return self.ELEMENTNAME
252 251
253 252 def getParameterObjList(self):
254 253
255 254 return self.parmConfObjList
256 255
257 256 def getParameterObj(self, parameterName):
258 257
259 258 for parmConfObj in self.parmConfObjList:
260 259
261 260 if parmConfObj.name != parameterName:
262 261 continue
263 262
264 263 return parmConfObj
265 264
266 265 return None
267 266
268 267 def getParameterObjfromValue(self, parameterValue):
269 268
270 269 for parmConfObj in self.parmConfObjList:
271 270
272 271 if parmConfObj.getValue() != parameterValue:
273 272 continue
274 273
275 274 return parmConfObj.getValue()
276 275
277 276 return None
278 277
279 278 def getParameterValue(self, parameterName):
280 279
281 280 parameterObj = self.getParameterObj(parameterName)
282 281
283 282 # if not parameterObj:
284 283 # return None
285 284
286 285 value = parameterObj.getValue()
287 286
288 287 return value
289 288
290 289 def setup(self, id, name, priority, type):
291 290
292 291 self.id = str(id)
293 292 self.name = name
294 293 self.type = type
295 294 self.priority = priority
296 295
297 296 self.parmConfObjList = []
298 297
299 298 def removeParameters(self):
300 299
301 300 for obj in self.parmConfObjList:
302 301 del obj
303 302
304 303 self.parmConfObjList = []
305 304
306 305 def addParameter(self, name, value, format='str'):
307 306
308 307 id = self.__getNewId()
309 308
310 309 parmConfObj = ParameterConf()
311 310 if not parmConfObj.setup(id, name, value, format):
312 311 return None
313 312
314 313 self.parmConfObjList.append(parmConfObj)
315 314
316 315 return parmConfObj
317 316
318 317 def changeParameter(self, name, value, format='str'):
319 318
320 319 parmConfObj = self.getParameterObj(name)
321 320 parmConfObj.update(name, value, format)
322 321
323 322 return parmConfObj
324 323
325 324 def makeXml(self, upElement):
326 325
327 326 opElement = SubElement(upElement, self.ELEMENTNAME)
328 327 opElement.set('id', str(self.id))
329 328 opElement.set('name', self.name)
330 329 opElement.set('type', self.type)
331 330 opElement.set('priority', str(self.priority))
332 331
333 332 for parmConfObj in self.parmConfObjList:
334 333 parmConfObj.makeXml(opElement)
335 334
336 335 def readXml(self, opElement):
337 336
338 337 self.id = opElement.get('id')
339 338 self.name = opElement.get('name')
340 339 self.type = opElement.get('type')
341 340 self.priority = opElement.get('priority')
342 341
343 342 #Compatible with old signal chain version
344 343 #Use of 'run' method instead 'init'
345 344 if self.type == 'self' and self.name == 'init':
346 345 self.name = 'run'
347 346
348 347 self.parmConfObjList = []
349 348
350 349 parmElementList = opElement.getiterator(ParameterConf().getElementName())
351 350
352 351 for parmElement in parmElementList:
353 352 parmConfObj = ParameterConf()
354 353 parmConfObj.readXml(parmElement)
355 354
356 355 #Compatible with old signal chain version
357 356 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
358 357 if self.type != 'self' and self.name == 'Plot':
359 358 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
360 359 self.name = parmConfObj.value
361 360 continue
362 361
363 362 self.parmConfObjList.append(parmConfObj)
364 363
365 364 def printattr(self):
366 365
367 366 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
368 367 self.id,
369 368 self.name,
370 369 self.type,
371 370 self.priority)
372 371
373 372 for parmConfObj in self.parmConfObjList:
374 373 parmConfObj.printattr()
375 374
376 375 def createObject(self):
377 376
378 377 if self.type == 'self':
379 378 raise ValueError, "This operation type cannot be created"
380 379
381 380 if self.type == 'external' or self.type == 'other':
382 381 className = eval(self.name)
383 382 opObj = className()
384 383
385 384 return opObj
386 385
387 386 class ProcUnitConf():
388 387
389 388 id = None
390 389 name = None
391 390 datatype = None
392 391 inputId = None
393 392 parentId = None
394 393
395 394 opConfObjList = []
396 395
397 396 procUnitObj = None
398 397 opObjList = []
399 398
400 399 ELEMENTNAME = 'ProcUnit'
401 400
402 401 def __init__(self):
403 402
404 403 self.id = None
405 404 self.datatype = None
406 405 self.name = None
407 406 self.inputId = None
408 407
409 408 self.opConfObjList = []
410 409
411 410 self.procUnitObj = None
412 411 self.opObjDict = {}
413 412
414 413 def __getPriority(self):
415 414
416 415 return len(self.opConfObjList)+1
417 416
418 417 def __getNewId(self):
419 418
420 419 return int(self.id)*10 + len(self.opConfObjList) + 1
421 420
422 421 def getElementName(self):
423 422
424 423 return self.ELEMENTNAME
425 424
426 425 def getId(self):
427 426
428 427 return self.id
429 428
430 429 def updateId(self, new_id, parentId=parentId):
431 430
432 431
433 432 new_id = int(parentId)*10 + (int(self.id) % 10)
434 433 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
435 434
436 435 #If this proc unit has not inputs
437 436 if self.inputId == '0':
438 437 new_inputId = 0
439 438
440 439 n = 1
441 440 for opConfObj in self.opConfObjList:
442 441
443 442 idOp = str(int(new_id)*10 + n)
444 443 opConfObj.updateId(idOp)
445 444
446 445 n += 1
447 446
448 447 self.parentId = str(parentId)
449 448 self.id = str(new_id)
450 449 self.inputId = str(new_inputId)
451 450
452 451
453 452 def getInputId(self):
454 453
455 454 return self.inputId
456 455
457 456 def getOperationObjList(self):
458 457
459 458 return self.opConfObjList
460 459
461 460 def getOperationObj(self, name=None):
462 461
463 462 for opConfObj in self.opConfObjList:
464 463
465 464 if opConfObj.name != name:
466 465 continue
467 466
468 467 return opConfObj
469 468
470 469 return None
471 470
472 471 def getOpObjfromParamValue(self, value=None):
473 472
474 473 for opConfObj in self.opConfObjList:
475 474 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
476 475 continue
477 476 return opConfObj
478 477 return None
479 478
480 479 def getProcUnitObj(self):
481 480
482 481 return self.procUnitObj
483 482
484 483 def setup(self, id, name, datatype, inputId, parentId=None):
485 484
486 485 #Compatible with old signal chain version
487 486 if datatype==None and name==None:
488 487 raise ValueError, "datatype or name should be defined"
489 488
490 489 if name==None:
491 490 if 'Proc' in datatype:
492 491 name = datatype
493 492 else:
494 493 name = '%sProc' %(datatype)
495 494
496 495 if datatype==None:
497 496 datatype = name.replace('Proc','')
498 497
499 498 self.id = str(id)
500 499 self.name = name
501 500 self.datatype = datatype
502 501 self.inputId = inputId
503 502 self.parentId = parentId
504 503
505 504 self.opConfObjList = []
506 505
507 506 self.addOperation(name='run', optype='self')
508 507
509 508 def removeOperations(self):
510 509
511 510 for obj in self.opConfObjList:
512 511 del obj
513 512
514 513 self.opConfObjList = []
515 514 self.addOperation(name='run')
516 515
517 516 def addParameter(self, **kwargs):
518 517 '''
519 518 Add parameters to "run" operation
520 519 '''
521 520 opObj = self.opConfObjList[0]
522 521
523 522 opObj.addParameter(**kwargs)
524 523
525 524 return opObj
526 525
527 526 def addOperation(self, name, optype='self'):
528 527
529 528 id = self.__getNewId()
530 529 priority = self.__getPriority()
531 530
532 531 opConfObj = OperationConf()
533 532 opConfObj.setup(id, name=name, priority=priority, type=optype)
534 533
535 534 self.opConfObjList.append(opConfObj)
536 535
537 536 return opConfObj
538 537
539 538 def makeXml(self, procUnitElement):
540 539
541 540 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
542 541 upElement.set('id', str(self.id))
543 542 upElement.set('name', self.name)
544 543 upElement.set('datatype', self.datatype)
545 544 upElement.set('inputId', str(self.inputId))
546 545
547 546 for opConfObj in self.opConfObjList:
548 547 opConfObj.makeXml(upElement)
549 548
550 549 def readXml(self, upElement):
551 550
552 551 self.id = upElement.get('id')
553 552 self.name = upElement.get('name')
554 553 self.datatype = upElement.get('datatype')
555 554 self.inputId = upElement.get('inputId')
556 555
557 556 if self.ELEMENTNAME == "ReadUnit":
558 557 self.datatype = self.datatype.replace("Reader", "")
559 558
560 559 if self.ELEMENTNAME == "ProcUnit":
561 560 self.datatype = self.datatype.replace("Proc", "")
562 561
563 562 if self.inputId == 'None':
564 563 self.inputId = '0'
565 564
566 565 self.opConfObjList = []
567 566
568 567 opElementList = upElement.getiterator(OperationConf().getElementName())
569 568
570 569 for opElement in opElementList:
571 570 opConfObj = OperationConf()
572 571 opConfObj.readXml(opElement)
573 572 self.opConfObjList.append(opConfObj)
574 573
575 574 def printattr(self):
576 575
577 576 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
578 577 self.id,
579 578 self.name,
580 579 self.datatype,
581 580 self.inputId)
582 581
583 582 for opConfObj in self.opConfObjList:
584 583 opConfObj.printattr()
585 584
586 585 def createObjects(self):
587 586
588 587 className = eval(self.name)
589 588 procUnitObj = className()
590 589
591 590 for opConfObj in self.opConfObjList:
592 591
593 592 if opConfObj.type == 'self':
594 593 continue
595 594
596 595 opObj = opConfObj.createObject()
597 596
598 597 self.opObjDict[opConfObj.id] = opObj
599 598 procUnitObj.addOperation(opObj, opConfObj.id)
600 599
601 600 self.procUnitObj = procUnitObj
602 601
603 602 return procUnitObj
604 603
605 604 def run(self):
606 605
607 606 finalSts = False
608 607
609 608 for opConfObj in self.opConfObjList:
610 609
611 610 kwargs = {}
612 611 for parmConfObj in opConfObj.getParameterObjList():
613 612 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
614 613 continue
615 614
616 615 kwargs[parmConfObj.name] = parmConfObj.getValue()
617 616
618 617 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
619 618 sts = self.procUnitObj.call(opType = opConfObj.type,
620 619 opName = opConfObj.name,
621 620 opId = opConfObj.id,
622 621 **kwargs)
623 622 finalSts = finalSts or sts
624 623
625 624 return finalSts
626 625
627 626 def close(self):
628 627
629 628 for opConfObj in self.opConfObjList:
630 629 if opConfObj.type == 'self':
631 630 continue
632 631
633 632 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
634 633 opObj.close()
635 634
636 635 self.procUnitObj.close()
637 636
638 637 return
639 638
640 639 class ReadUnitConf(ProcUnitConf):
641 640
642 641 path = None
643 642 startDate = None
644 643 endDate = None
645 644 startTime = None
646 645 endTime = None
647 646
648 647 ELEMENTNAME = 'ReadUnit'
649 648
650 649 def __init__(self):
651 650
652 651 self.id = None
653 652 self.datatype = None
654 653 self.name = None
655 654 self.inputId = None
656 655
657 656 self.parentId = None
658 657
659 658 self.opConfObjList = []
660 659 self.opObjList = []
661 660
662 661 def getElementName(self):
663 662
664 663 return self.ELEMENTNAME
665 664
666 665 def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs):
667 666
668 667 #Compatible with old signal chain version
669 668 if datatype==None and name==None:
670 669 raise ValueError, "datatype or name should be defined"
671 670
672 671 if name==None:
673 672 if 'Reader' in datatype:
674 673 name = datatype
675 674 else:
676 675 name = '%sReader' %(datatype)
677 676
678 677 if datatype==None:
679 678 datatype = name.replace('Reader','')
680 679
681 680 self.id = id
682 681 self.name = name
683 682 self.datatype = datatype
684 683
685 684 self.path = path
686 685 self.startDate = startDate
687 686 self.endDate = endDate
688 687 self.startTime = startTime
689 688 self.endTime = endTime
690 689
691 690 self.inputId = '0'
692 691 self.parentId = parentId
693 692
694 693 self.addRunOperation(**kwargs)
695 694
696 695 def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs):
697 696
698 697 #Compatible with old signal chain version
699 698 if datatype==None and name==None:
700 699 raise ValueError, "datatype or name should be defined"
701 700
702 701 if name==None:
703 702 if 'Reader' in datatype:
704 703 name = datatype
705 704 else:
706 705 name = '%sReader' %(datatype)
707 706
708 707 if datatype==None:
709 708 datatype = name.replace('Reader','')
710 709
711 710 self.datatype = datatype
712 711 self.name = name
713 712 self.path = path
714 713 self.startDate = startDate
715 714 self.endDate = endDate
716 715 self.startTime = startTime
717 716 self.endTime = endTime
718 717
719 718 self.inputId = '0'
720 719 self.parentId = parentId
721 720
722 721 self.updateRunOperation(**kwargs)
723 722
724 723 def addRunOperation(self, **kwargs):
725 724
726 725 opObj = self.addOperation(name = 'run', optype = 'self')
727 726
728 727 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
729 728 opObj.addParameter(name='path' , value=self.path, format='str')
730 729 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
731 730 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
732 731 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
733 732 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
734 733
735 734 for key, value in kwargs.items():
736 735 opObj.addParameter(name=key, value=value, format=type(value).__name__)
737 736
738 737 return opObj
739 738
740 739 def updateRunOperation(self, **kwargs):
741 740
742 741 opObj = self.getOperationObj(name = 'run')
743 742 opObj.removeParameters()
744 743
745 744 opObj.addParameter(name='datatype' , value=self.datatype, format='str')
746 745 opObj.addParameter(name='path' , value=self.path, format='str')
747 746 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
748 747 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
749 748 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
750 749 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
751 750
752 751 for key, value in kwargs.items():
753 752 opObj.addParameter(name=key, value=value, format=type(value).__name__)
754 753
755 754 return opObj
756 755
757 756 class Project():
758 757
759 758 id = None
760 759 name = None
761 760 description = None
762 761 # readUnitConfObjList = None
763 762 procUnitConfObjDict = None
764 763
765 764 ELEMENTNAME = 'Project'
766 765
767 766 def __init__(self, control=None, dataq=None):
768 767
769 768 self.id = None
770 769 self.name = None
771 770 self.description = None
772 771
773 772 self.procUnitConfObjDict = {}
774 773
775 774 #global data_q
776 775 #data_q = dataq
777 776
778 777 if control==None:
779 778 control = {'stop':False,'pause':False}
780 779
781 780 self.control = control
782 781
783 782 def __getNewId(self):
784 783
785 784 id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1
786 785
787 786 return str(id)
788 787
789 788 def getElementName(self):
790 789
791 790 return self.ELEMENTNAME
792 791
793 792 def getId(self):
794 793
795 794 return self.id
796 795
797 796 def updateId(self, new_id):
798 797
799 798 self.id = str(new_id)
800 799
801 800 keyList = self.procUnitConfObjDict.keys()
802 801 keyList.sort()
803 802
804 803 n = 1
805 804 newProcUnitConfObjDict = {}
806 805
807 806 for procKey in keyList:
808 807
809 808 procUnitConfObj = self.procUnitConfObjDict[procKey]
810 809 idProcUnit = str(int(self.id)*10 + n)
811 810 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
812 811
813 812 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
814 813 n += 1
815 814
816 815 self.procUnitConfObjDict = newProcUnitConfObjDict
817 816
818 817 def setup(self, id, name, description):
819 818
820 819 self.id = str(id)
821 820 self.name = name
822 821 self.description = description
823 822
824 823 def update(self, name, description):
825 824
826 825 self.name = name
827 826 self.description = description
828 827
829 828 def addReadUnit(self, datatype=None, name=None, **kwargs):
830 829
831 830 idReadUnit = self.__getNewId()
832 831
833 832 readUnitConfObj = ReadUnitConf()
834 833 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
835 834
836 835 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
837 836
838 837 return readUnitConfObj
839 838
840 839 def addProcUnit(self, inputId='0', datatype=None, name=None):
841 840
842 841 idProcUnit = self.__getNewId()
843 842
844 843 procUnitConfObj = ProcUnitConf()
845 844 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
846 845
847 846 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
848 847
849 848 return procUnitConfObj
850 849
851 850 def removeProcUnit(self, id):
852 851
853 852 if id in self.procUnitConfObjDict.keys():
854 853 self.procUnitConfObjDict.pop(id)
855 854
856 855 def getReadUnitId(self):
857 856
858 857 readUnitConfObj = self.getReadUnitObj()
859 858
860 859 return readUnitConfObj.id
861 860
862 861 def getReadUnitObj(self):
863 862
864 863 for obj in self.procUnitConfObjDict.values():
865 864 if obj.getElementName() == "ReadUnit":
866 865 return obj
867 866
868 867 return None
869 868
870 869 def getProcUnitObj(self, id=None, name=None):
871 870
872 871 if id != None:
873 872 return self.procUnitConfObjDict[id]
874 873
875 874 if name != None:
876 875 return self.getProcUnitObjByName(name)
877 876
878 877 return None
879 878
880 879 def getProcUnitObjByName(self, name):
881 880
882 881 for obj in self.procUnitConfObjDict.values():
883 882 if obj.name == name:
884 883 return obj
885 884
886 885 return None
887 886
888 887 def procUnitItems(self):
889 888
890 889 return self.procUnitConfObjDict.items()
891 890
892 891 def makeXml(self):
893 892
894 893 projectElement = Element('Project')
895 894 projectElement.set('id', str(self.id))
896 895 projectElement.set('name', self.name)
897 896 projectElement.set('description', self.description)
898 897
899 898 for procUnitConfObj in self.procUnitConfObjDict.values():
900 899 procUnitConfObj.makeXml(projectElement)
901 900
902 901 self.projectElement = projectElement
903 902
904 903 def writeXml(self, filename):
905 904
906 905 self.makeXml()
907 906
908 907 #print prettify(self.projectElement)
909 908
910 909 ElementTree(self.projectElement).write(filename, method='xml')
911 910
912 911 def readXml(self, filename):
913 912
914 913 self.projectElement = None
915 914 self.procUnitConfObjDict = {}
916 915
917 916 self.projectElement = ElementTree().parse(filename)
918 917
919 918 self.project = self.projectElement.tag
920 919
921 920 self.id = self.projectElement.get('id')
922 921 self.name = self.projectElement.get('name')
923 922 self.description = self.projectElement.get('description')
924 923
925 924 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
926 925
927 926 for readUnitElement in readUnitElementList:
928 927 readUnitConfObj = ReadUnitConf()
929 928 readUnitConfObj.readXml(readUnitElement)
930 929
931 930 if readUnitConfObj.parentId == None:
932 931 readUnitConfObj.parentId = self.id
933 932
934 933 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
935 934
936 935 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
937 936
938 937 for procUnitElement in procUnitElementList:
939 938 procUnitConfObj = ProcUnitConf()
940 939 procUnitConfObj.readXml(procUnitElement)
941 940
942 941 if procUnitConfObj.parentId == None:
943 942 procUnitConfObj.parentId = self.id
944 943
945 944 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
946 945
947 946 def printattr(self):
948 947
949 948 print "Project[%s]: name = %s, description = %s" %(self.id,
950 949 self.name,
951 950 self.description)
952 951
953 952 for procUnitConfObj in self.procUnitConfObjDict.values():
954 953 procUnitConfObj.printattr()
955 954
956 955 def createObjects(self):
957 956
958 957 for procUnitConfObj in self.procUnitConfObjDict.values():
959 958 procUnitConfObj.createObjects()
960 959
961 960 def __connect(self, objIN, thisObj):
962 961
963 962 thisObj.setInput(objIN.getOutputObj())
964 963
965 964 def connectObjects(self):
966 965
967 966 for thisPUConfObj in self.procUnitConfObjDict.values():
968 967
969 968 inputId = thisPUConfObj.getInputId()
970 969
971 970 if int(inputId) == 0:
972 971 continue
973 972
974 973 #Get input object
975 974 puConfINObj = self.procUnitConfObjDict[inputId]
976 975 puObjIN = puConfINObj.getProcUnitObj()
977 976
978 977 #Get current object
979 978 thisPUObj = thisPUConfObj.getProcUnitObj()
980 979
981 980 self.__connect(puObjIN, thisPUObj)
982 981
983 982 def run(self):
984 983
985 984 print
986 985 print "*"*50
987 986 print " Starting SIGNAL CHAIN PROCESSING "
988 987 print "*"*50
989 988 print
990 989
991 990 keyList = self.procUnitConfObjDict.keys()
992 991 keyList.sort()
993 992
994 993 while(True):
995 994
996 995 finalSts = False
997 996
998 997 for procKey in keyList:
999 998 # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
1000 999
1001 1000 procUnitConfObj = self.procUnitConfObjDict[procKey]
1002 1001 sts = procUnitConfObj.run()
1003 1002 finalSts = finalSts or sts
1004 1003
1005 1004 #If every process unit finished so end process
1006 1005 if not(finalSts):
1007 1006 print "Every process unit have finished"
1008 1007 break
1009 1008
1010 1009 if self.control['pause']:
1011 1010 print "Process suspended"
1012 1011
1013 1012 while True:
1014 1013 sleep(0.1)
1015 1014
1016 1015 if not self.control['pause']:
1017 1016 break
1018 1017
1019 1018 if self.control['stop']:
1020 1019 break
1021 1020 print "Process reinitialized"
1022 1021
1023 1022 if self.control['stop']:
1024 1023 # print "Process stopped"
1025 1024 break
1026 1025
1027 1026 #Closing every process
1028 1027 for procKey in keyList:
1029 1028 procUnitConfObj = self.procUnitConfObjDict[procKey]
1030 1029 procUnitConfObj.close()
1031 1030
1032 1031 print "Process finished"
1033 1032
1034 1033 def start(self, filename):
1035 1034
1036 1035 self.writeXml(filename)
1037 1036 self.readXml(filename)
1038 1037
1039 1038 self.createObjects()
1040 1039 self.connectObjects()
1041 1040 self.run()
1042 1041
1043 1042 if __name__ == '__main__':
1044 1043
1045 1044 desc = "Segundo Test"
1046 1045 filename = "schain.xml"
1047 1046
1048 1047 controllerObj = Project()
1049 1048
1050 1049 controllerObj.setup(id = '191', name='test01', description=desc)
1051 1050
1052 1051 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
1053 1052 path='data/rawdata/',
1054 1053 startDate='2011/01/01',
1055 1054 endDate='2012/12/31',
1056 1055 startTime='00:00:00',
1057 1056 endTime='23:59:59',
1058 1057 online=1,
1059 1058 walk=1)
1060 1059
1061 1060 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
1062 1061
1063 1062 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
1064 1063 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
1065 1064
1066 1065 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
1067 1066 opObj10.addParameter(name='minHei', value='90', format='float')
1068 1067 opObj10.addParameter(name='maxHei', value='180', format='float')
1069 1068
1070 1069 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
1071 1070 opObj12.addParameter(name='n', value='10', format='int')
1072 1071
1073 1072 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
1074 1073 procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
1075 1074 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
1076 1075
1077 1076
1078 1077 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
1079 1078 opObj11.addParameter(name='idfigure', value='1', format='int')
1080 1079 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
1081 1080 opObj11.addParameter(name='zmin', value='40', format='int')
1082 1081 opObj11.addParameter(name='zmax', value='90', format='int')
1083 1082 opObj11.addParameter(name='showprofile', value='1', format='int')
1084 1083
1085 1084 print "Escribiendo el archivo XML"
1086 1085
1087 1086 controllerObj.writeXml(filename)
1088 1087
1089 1088 print "Leyendo el archivo XML"
1090 1089 controllerObj.readXml(filename)
1091 1090 #controllerObj.printattr()
1092 1091
1093 1092 controllerObj.createObjects()
1094 1093 controllerObj.connectObjects()
1095 1094 controllerObj.run()
1096 1095
1097 1096 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,240 +1,240
1 1 from PyQt4 import QtCore, QtGui
2 2
3 3 try:
4 4 _fromUtf8 = QtCore.QString.fromUtf8
5 5 except AttributeError:
6 6 def _fromUtf8(s):
7 7 return s
8 8
9 9 try:
10 10 _encoding = QtGui.QApplication.UnicodeUTF8
11 11 def _translate(context, text, disambig):
12 12 return QtGui.QApplication.translate(context, text, disambig, _encoding)
13 13 except AttributeError:
14 14 def _translate(context, text, disambig):
15 15 return QtGui.QApplication.translate(context, text, disambig)
16 16
17 17 class Ui_SpectraHeisTab(object):
18 18
19 19 def setupUi(self):
20 20
21 21 self.tabSpectraHeis = QtGui.QWidget()
22 22 self.tabSpectraHeis.setObjectName(_fromUtf8("tabSpectraHeis"))
23 23 self.gridLayout_23 = QtGui.QGridLayout(self.tabSpectraHeis)
24 24 self.gridLayout_23.setObjectName(_fromUtf8("gridLayout_23"))
25 25 self.frame_6 = QtGui.QFrame(self.tabSpectraHeis)
26 26 self.frame_6.setFrameShape(QtGui.QFrame.StyledPanel)
27 27 self.frame_6.setFrameShadow(QtGui.QFrame.Raised)
28 28 self.frame_6.setObjectName(_fromUtf8("frame_6"))
29 29 self.gridLayout_22 = QtGui.QGridLayout(self.frame_6)
30 30 self.gridLayout_22.setObjectName(_fromUtf8("gridLayout_22"))
31 31 self.specHeisGraphClear = QtGui.QPushButton(self.frame_6)
32 32 self.specHeisGraphClear.setObjectName(_fromUtf8("specHeisGraphClear"))
33 33 self.gridLayout_22.addWidget(self.specHeisGraphClear, 0, 1, 1, 1)
34 34 self.specHeisOpOk = QtGui.QPushButton(self.frame_6)
35 35 self.specHeisOpOk.setObjectName(_fromUtf8("specHeisOpOk"))
36 36 self.gridLayout_22.addWidget(self.specHeisOpOk, 0, 0, 1, 1)
37 37 self.gridLayout_23.addWidget(self.frame_6, 1, 0, 1, 1)
38 38 self.tabWidgetSpectraHeis = QtGui.QTabWidget(self.tabSpectraHeis)
39 39 self.tabWidgetSpectraHeis.setObjectName(_fromUtf8("tabWidgetSpectraHeis"))
40 40 self.tabopSpectraHeis = QtGui.QWidget()
41 41 self.tabopSpectraHeis.setObjectName(_fromUtf8("tabopSpectraHeis"))
42 42 self.gridLayout_21 = QtGui.QGridLayout(self.tabopSpectraHeis)
43 43 self.gridLayout_21.setObjectName(_fromUtf8("gridLayout_21"))
44 44 spacerItem21 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
45 45 self.gridLayout_21.addItem(spacerItem21, 0, 1, 1, 1)
46 46 self.specHeisOpCobIncInt = QtGui.QComboBox(self.tabopSpectraHeis)
47 47 self.specHeisOpCobIncInt.setObjectName(_fromUtf8("specHeisOpCobIncInt"))
48 48 self.specHeisOpCobIncInt.addItem(_fromUtf8(""))
49 49 self.gridLayout_21.addWidget(self.specHeisOpCobIncInt, 1, 0, 1, 1)
50 50 self.specHeisOpCebIncoherent = QtGui.QCheckBox(self.tabopSpectraHeis)
51 51 self.specHeisOpCebIncoherent.setObjectName(_fromUtf8("specHeisOpCebIncoherent"))
52 52 self.gridLayout_21.addWidget(self.specHeisOpCebIncoherent, 0, 0, 1, 1)
53 53 self.specHeisOpIncoherent = QtGui.QLineEdit(self.tabopSpectraHeis)
54 54 self.specHeisOpIncoherent.setObjectName(_fromUtf8("specHeisOpIncoherent"))
55 55 self.gridLayout_21.addWidget(self.specHeisOpIncoherent, 1, 1, 1, 1)
56 56 spacerItem22 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
57 57 self.gridLayout_21.addItem(spacerItem22, 2, 0, 1, 1)
58 58 self.tabWidgetSpectraHeis.addTab(self.tabopSpectraHeis, _fromUtf8(""))
59 59 self.tabgraphSpectraHeis = QtGui.QWidget()
60 60 self.tabgraphSpectraHeis.setObjectName(_fromUtf8("tabgraphSpectraHeis"))
61 61 self.gridLayout_20 = QtGui.QGridLayout(self.tabgraphSpectraHeis)
62 62 self.gridLayout_20.setObjectName(_fromUtf8("gridLayout_20"))
63 63 self.label_54 = QtGui.QLabel(self.tabgraphSpectraHeis)
64 64 self.label_54.setObjectName(_fromUtf8("label_54"))
65 65 self.gridLayout_20.addWidget(self.label_54, 1, 0, 1, 1)
66 66 self.specHeisGraphToolPath = QtGui.QToolButton(self.tabgraphSpectraHeis)
67 67 self.specHeisGraphToolPath.setObjectName(_fromUtf8("specHeisGraphToolPath"))
68 68 self.gridLayout_20.addWidget(self.specHeisGraphToolPath, 0, 6, 1, 1)
69 69 self.specHeisGraphCebRTIplot = QtGui.QCheckBox(self.tabgraphSpectraHeis)
70 70 self.specHeisGraphCebRTIplot.setText(_fromUtf8(""))
71 71 self.specHeisGraphCebRTIplot.setObjectName(_fromUtf8("specHeisGraphCebRTIplot"))
72 72 self.gridLayout_20.addWidget(self.specHeisGraphCebRTIplot, 4, 2, 1, 1)
73 73 self.label_62 = QtGui.QLabel(self.tabgraphSpectraHeis)
74 74 self.label_62.setObjectName(_fromUtf8("label_62"))
75 75 self.gridLayout_20.addWidget(self.label_62, 7, 0, 1, 1)
76 76 self.label_63 = QtGui.QLabel(self.tabgraphSpectraHeis)
77 77 self.label_63.setObjectName(_fromUtf8("label_63"))
78 78 self.gridLayout_20.addWidget(self.label_63, 8, 0, 1, 1)
79 79 self.label_64 = QtGui.QLabel(self.tabgraphSpectraHeis)
80 80 self.label_64.setObjectName(_fromUtf8("label_64"))
81 81 self.gridLayout_20.addWidget(self.label_64, 9, 0, 1, 1)
82 82 self.label_65 = QtGui.QLabel(self.tabgraphSpectraHeis)
83 83 self.label_65.setObjectName(_fromUtf8("label_65"))
84 84 self.gridLayout_20.addWidget(self.label_65, 10, 0, 1, 1)
85 85 spacerItem23 = QtGui.QSpacerItem(134, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
86 86 self.gridLayout_20.addItem(spacerItem23, 11, 0, 1, 2)
87 87 self.specHeisGgraphftpratio = QtGui.QLineEdit(self.tabgraphSpectraHeis)
88 88 self.specHeisGgraphftpratio.setObjectName(_fromUtf8("specHeisGgraphftpratio"))
89 89 self.gridLayout_20.addWidget(self.specHeisGgraphftpratio, 10, 1, 1, 6)
90 90 self.specHeisGraphftpRTIplot = QtGui.QCheckBox(self.tabgraphSpectraHeis)
91 91 self.specHeisGraphftpRTIplot.setText(_fromUtf8(""))
92 92 self.specHeisGraphftpRTIplot.setObjectName(_fromUtf8("specHeisGraphftpRTIplot"))
93 93 self.gridLayout_20.addWidget(self.specHeisGraphftpRTIplot, 4, 6, 1, 1)
94 94 self.specHeisGgraphTminTmax = QtGui.QLineEdit(self.tabgraphSpectraHeis)
95 95 self.specHeisGgraphTminTmax.setObjectName(_fromUtf8("specHeisGgraphTminTmax"))
96 96 self.gridLayout_20.addWidget(self.specHeisGgraphTminTmax, 8, 1, 1, 6)
97 97 self.label_60 = QtGui.QLabel(self.tabgraphSpectraHeis)
98 98 self.label_60.setObjectName(_fromUtf8("label_60"))
99 99 self.gridLayout_20.addWidget(self.label_60, 5, 0, 1, 1)
100 100 self.label_61 = QtGui.QLabel(self.tabgraphSpectraHeis)
101 101 self.label_61.setObjectName(_fromUtf8("label_61"))
102 102 self.gridLayout_20.addWidget(self.label_61, 6, 0, 1, 1)
103 103 self.specHeisGraphPrefix = QtGui.QLineEdit(self.tabgraphSpectraHeis)
104 104 self.specHeisGraphPrefix.setObjectName(_fromUtf8("specHeisGraphPrefix"))
105 105 self.gridLayout_20.addWidget(self.specHeisGraphPrefix, 1, 1, 1, 6)
106 106 self.label_56 = QtGui.QLabel(self.tabgraphSpectraHeis)
107 107 self.label_56.setObjectName(_fromUtf8("label_56"))
108 108 self.gridLayout_20.addWidget(self.label_56, 2, 4, 1, 1)
109 109 self.label_57 = QtGui.QLabel(self.tabgraphSpectraHeis)
110 110 self.label_57.setObjectName(_fromUtf8("label_57"))
111 111 self.gridLayout_20.addWidget(self.label_57, 2, 6, 1, 1)
112 112 self.label_58 = QtGui.QLabel(self.tabgraphSpectraHeis)
113 113 self.label_58.setObjectName(_fromUtf8("label_58"))
114 114 self.gridLayout_20.addWidget(self.label_58, 3, 0, 1, 1)
115 115 self.specHeisGraphCebSpectraplot = QtGui.QCheckBox(self.tabgraphSpectraHeis)
116 116 self.specHeisGraphCebSpectraplot.setText(_fromUtf8(""))
117 117 self.specHeisGraphCebSpectraplot.setObjectName(_fromUtf8("specHeisGraphCebSpectraplot"))
118 118 self.gridLayout_20.addWidget(self.specHeisGraphCebSpectraplot, 3, 2, 1, 1)
119 119 self.specHeisGgraphYminYmax = QtGui.QLineEdit(self.tabgraphSpectraHeis)
120 120 self.specHeisGgraphYminYmax.setObjectName(_fromUtf8("specHeisGgraphYminYmax"))
121 121 self.gridLayout_20.addWidget(self.specHeisGgraphYminYmax, 7, 1, 1, 6)
122 122 self.label_53 = QtGui.QLabel(self.tabgraphSpectraHeis)
123 123 self.label_53.setObjectName(_fromUtf8("label_53"))
124 124 self.gridLayout_20.addWidget(self.label_53, 0, 0, 1, 1)
125 125 self.label_55 = QtGui.QLabel(self.tabgraphSpectraHeis)
126 126 self.label_55.setObjectName(_fromUtf8("label_55"))
127 127 self.gridLayout_20.addWidget(self.label_55, 2, 2, 1, 1)
128 128 self.specHeisGraphSaveRTIplot = QtGui.QCheckBox(self.tabgraphSpectraHeis)
129 129 self.specHeisGraphSaveRTIplot.setText(_fromUtf8(""))
130 130 self.specHeisGraphSaveRTIplot.setObjectName(_fromUtf8("specHeisGraphSaveRTIplot"))
131 131 self.gridLayout_20.addWidget(self.specHeisGraphSaveRTIplot, 4, 4, 1, 1)
132 132 spacerItem24 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
133 133 self.gridLayout_20.addItem(spacerItem24, 2, 3, 1, 1)
134 134 self.specHeisGgraphXminXmax = QtGui.QLineEdit(self.tabgraphSpectraHeis)
135 135 self.specHeisGgraphXminXmax.setObjectName(_fromUtf8("specHeisGgraphXminXmax"))
136 136 self.gridLayout_20.addWidget(self.specHeisGgraphXminXmax, 6, 1, 1, 6)
137 137 self.specHeisGgraphChannelList = QtGui.QLineEdit(self.tabgraphSpectraHeis)
138 138 self.specHeisGgraphChannelList.setObjectName(_fromUtf8("specHeisGgraphChannelList"))
139 139 self.gridLayout_20.addWidget(self.specHeisGgraphChannelList, 5, 1, 1, 6)
140 140 self.specHeisGgraphTimeRange = QtGui.QLineEdit(self.tabgraphSpectraHeis)
141 141 self.specHeisGgraphTimeRange.setObjectName(_fromUtf8("specHeisGgraphTimeRange"))
142 142 self.gridLayout_20.addWidget(self.specHeisGgraphTimeRange, 9, 1, 1, 6)
143 143 spacerItem25 = QtGui.QSpacerItem(106, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
144 144 self.gridLayout_20.addItem(spacerItem25, 11, 3, 1, 3)
145 145 self.specHeisGraphSaveSpectra = QtGui.QCheckBox(self.tabgraphSpectraHeis)
146 146 self.specHeisGraphSaveSpectra.setText(_fromUtf8(""))
147 147 self.specHeisGraphSaveSpectra.setObjectName(_fromUtf8("specHeisGraphSaveSpectra"))
148 148 self.gridLayout_20.addWidget(self.specHeisGraphSaveSpectra, 3, 4, 1, 1)
149 149 self.specHeisGraphftpSpectra = QtGui.QCheckBox(self.tabgraphSpectraHeis)
150 150 self.specHeisGraphftpSpectra.setText(_fromUtf8(""))
151 151 self.specHeisGraphftpSpectra.setObjectName(_fromUtf8("specHeisGraphftpSpectra"))
152 152 self.gridLayout_20.addWidget(self.specHeisGraphftpSpectra, 3, 6, 1, 1)
153 153 self.label_59 = QtGui.QLabel(self.tabgraphSpectraHeis)
154 154 self.label_59.setObjectName(_fromUtf8("label_59"))
155 155 self.gridLayout_20.addWidget(self.label_59, 4, 0, 1, 1)
156 156 spacerItem26 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
157 157 self.gridLayout_20.addItem(spacerItem26, 2, 5, 1, 1)
158 158 self.specHeisGraphPath = QtGui.QLineEdit(self.tabgraphSpectraHeis)
159 159 self.specHeisGraphPath.setObjectName(_fromUtf8("specHeisGraphPath"))
160 160 self.gridLayout_20.addWidget(self.specHeisGraphPath, 0, 1, 1, 5)
161 161 self.tabWidgetSpectraHeis.addTab(self.tabgraphSpectraHeis, _fromUtf8(""))
162 162 self.taboutputSpectraHeis = QtGui.QWidget()
163 163 self.taboutputSpectraHeis.setObjectName(_fromUtf8("taboutputSpectraHeis"))
164 164 self.gridLayout_19 = QtGui.QGridLayout(self.taboutputSpectraHeis)
165 165 self.gridLayout_19.setObjectName(_fromUtf8("gridLayout_19"))
166 166 self.label_67 = QtGui.QLabel(self.taboutputSpectraHeis)
167 167 self.label_67.setObjectName(_fromUtf8("label_67"))
168 168 self.gridLayout_19.addWidget(self.label_67, 1, 0, 1, 1)
169 169 self.label_68 = QtGui.QLabel(self.taboutputSpectraHeis)
170 170 self.label_68.setObjectName(_fromUtf8("label_68"))
171 171 self.gridLayout_19.addWidget(self.label_68, 2, 0, 1, 2)
172 172 self.label_66 = QtGui.QLabel(self.taboutputSpectraHeis)
173 173 self.label_66.setObjectName(_fromUtf8("label_66"))
174 174 self.gridLayout_19.addWidget(self.label_66, 0, 0, 1, 1)
175 175 spacerItem27 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
176 176 self.gridLayout_19.addItem(spacerItem27, 4, 0, 1, 1)
177 177 self.specHeisOutputToolPath = QtGui.QToolButton(self.taboutputSpectraHeis)
178 178 self.specHeisOutputToolPath.setObjectName(_fromUtf8("specHeisOutputToolPath"))
179 179 self.gridLayout_19.addWidget(self.specHeisOutputToolPath, 1, 4, 1, 1)
180 180 self.specHeisOutputPath = QtGui.QLineEdit(self.taboutputSpectraHeis)
181 181 self.specHeisOutputPath.setObjectName(_fromUtf8("specHeisOutputPath"))
182 182 self.gridLayout_19.addWidget(self.specHeisOutputPath, 1, 3, 1, 1)
183 183 self.specHeisOutputComdata = QtGui.QComboBox(self.taboutputSpectraHeis)
184 184 self.specHeisOutputComdata.setObjectName(_fromUtf8("specHeisOutputComdata"))
185 185 self.specHeisOutputComdata.addItem(_fromUtf8(""))
186 186 self.gridLayout_19.addWidget(self.specHeisOutputComdata, 0, 3, 1, 2)
187 187 self.label_69 = QtGui.QLabel(self.taboutputSpectraHeis)
188 188 self.label_69.setObjectName(_fromUtf8("label_69"))
189 189 self.gridLayout_19.addWidget(self.label_69, 3, 0, 1, 2)
190 190 self.specHeisOutputblocksperfile = QtGui.QLineEdit(self.taboutputSpectraHeis)
191 191 self.specHeisOutputblocksperfile.setObjectName(_fromUtf8("specHeisOutputblocksperfile"))
192 192 self.gridLayout_19.addWidget(self.specHeisOutputblocksperfile, 2, 3, 1, 1)
193 193 self.specHeisOutputMetada = QtGui.QLineEdit(self.taboutputSpectraHeis)
194 194 self.specHeisOutputMetada.setObjectName(_fromUtf8("specHeisOutputMetada"))
195 195 self.gridLayout_19.addWidget(self.specHeisOutputMetada, 3, 3, 1, 1)
196 196 self.specHeisOutputMetadaToolPath = QtGui.QToolButton(self.taboutputSpectraHeis)
197 197 self.specHeisOutputMetadaToolPath.setObjectName(_fromUtf8("specHeisOutputMetadaToolPath"))
198 198 self.gridLayout_19.addWidget(self.specHeisOutputMetadaToolPath, 3, 4, 1, 1)
199 199 self.tabWidgetSpectraHeis.addTab(self.taboutputSpectraHeis, _fromUtf8(""))
200 200 self.gridLayout_23.addWidget(self.tabWidgetSpectraHeis, 0, 0, 1, 1)
201 201
202 202 self.tabWidgetProject.addTab(self.tabSpectraHeis, _fromUtf8(""))
203 203
204 204 self.tabWidgetSpectraHeis.setCurrentIndex(0)
205 205
206 206 def retranslateUi(self):
207 207
208 208 self.specHeisGraphClear.setText(_translate("MainWindow", "Clear", None))
209 209 self.specHeisOpOk.setText(_translate("MainWindow", "Ok", None))
210 210 self.specHeisOpCobIncInt.setItemText(0, _translate("MainWindow", "Time Interval", None))
211 211 self.specHeisOpCebIncoherent.setText(_translate("MainWindow", "Incoherent Intergration", None))
212 212
213 213 self.tabWidgetSpectraHeis.setTabText(self.tabWidgetSpectraHeis.indexOf(self.tabopSpectraHeis), _translate("MainWindow", "Operation", None))
214 214 self.label_54.setText(_translate("MainWindow", "Prefix", None))
215 215 self.specHeisGraphToolPath.setText(_translate("MainWindow", "...", None))
216 216 self.label_62.setText(_translate("MainWindow", "Intensity range (dB)", None))
217 217 self.label_63.setText(_translate("MainWindow", "Time range (hours):", None))
218 218 self.label_64.setText(_translate("MainWindow", "Time interval:", None))
219 219 self.label_65.setText(_translate("MainWindow", "Wr Period", None))
220 220 self.label_60.setText(_translate("MainWindow", "Channel List:", None))
221 221 self.label_61.setText(_translate("MainWindow", "Frequency range", None))
222 222 self.label_56.setText(_translate("MainWindow", "Save", None))
223 223 self.label_57.setText(_translate("MainWindow", "ftp", None))
224 224 self.label_58.setText(_translate("MainWindow", "Spectra Plot", None))
225 225 self.label_53.setText(_translate("MainWindow", "Path", None))
226 226 self.label_55.setText(_translate("MainWindow", "Show", None))
227 227 self.label_59.setText(_translate("MainWindow", "RTI Plot", None))
228 228
229 229 self.tabWidgetSpectraHeis.setTabText(self.tabWidgetSpectraHeis.indexOf(self.tabgraphSpectraHeis), _translate("MainWindow", "Graphics", None))
230 230 self.label_67.setText(_translate("MainWindow", "Path:", None))
231 self.label_68.setText(_translate("MainWindow", "Blocks per File:", None))
231 self.label_68.setText(_translate("MainWindow", "Blocks per file:", None))
232 232 self.label_66.setText(_translate("MainWindow", "Type:", None))
233 233
234 234 self.tabWidgetSpectraHeis.setTabText(self.tabWidgetSpectraHeis.indexOf(self.taboutputSpectraHeis), _translate("MainWindow", "Output", None))
235 235 self.specHeisOutputToolPath.setText(_translate("MainWindow", "...", None))
236 236 self.specHeisOutputComdata.setItemText(0, _translate("MainWindow", ".fits", None))
237 self.label_69.setText(_translate("MainWindow", "Metada", None))
237 self.label_69.setText(_translate("MainWindow", "Metadata file:", None))
238 238 self.specHeisOutputMetadaToolPath.setText(_translate("MainWindow", "...", None))
239 239
240 240 self.tabWidgetProject.setTabText(self.tabWidgetProject.indexOf(self.tabSpectraHeis), _translate("MainWindow", "SpectraHeis", None))
@@ -1,1132 +1,1128
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 5 '''
6 6
7 7 import copy
8 8 import numpy
9 9 import datetime
10 10
11 11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 12
13 13 def getNumpyDtype(dataTypeCode):
14 14
15 15 if dataTypeCode == 0:
16 16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
17 17 elif dataTypeCode == 1:
18 18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
19 19 elif dataTypeCode == 2:
20 20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
21 21 elif dataTypeCode == 3:
22 22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
23 23 elif dataTypeCode == 4:
24 24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
25 25 elif dataTypeCode == 5:
26 26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
27 27 else:
28 28 raise ValueError, 'dataTypeCode was not defined'
29 29
30 30 return numpyDtype
31 31
32 32 def getDataTypeCode(numpyDtype):
33 33
34 34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
35 35 datatype = 0
36 36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
37 37 datatype = 1
38 38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
39 39 datatype = 2
40 40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
41 41 datatype = 3
42 42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
43 43 datatype = 4
44 44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
45 45 datatype = 5
46 46 else:
47 47 datatype = None
48 48
49 49 return datatype
50 50
51 51 def hildebrand_sekhon(data, navg):
52 52 """
53 53 This method is for the objective determination of the noise level in Doppler spectra. This
54 54 implementation technique is based on the fact that the standard deviation of the spectral
55 55 densities is equal to the mean spectral density for white Gaussian noise
56 56
57 57 Inputs:
58 58 Data : heights
59 59 navg : numbers of averages
60 60
61 61 Return:
62 62 -1 : any error
63 63 anoise : noise's level
64 64 """
65 65
66 66 sortdata = numpy.sort(data,axis=None)
67 67 lenOfData = len(sortdata)
68 68 nums_min = lenOfData/10
69 69
70 70 if (lenOfData/10) > 2:
71 71 nums_min = lenOfData/10
72 72 else:
73 73 nums_min = 2
74 74
75 75 sump = 0.
76 76
77 77 sumq = 0.
78 78
79 79 j = 0
80 80
81 81 cont = 1
82 82
83 83 while((cont==1)and(j<lenOfData)):
84 84
85 85 sump += sortdata[j]
86 86
87 87 sumq += sortdata[j]**2
88 88
89 89 if j > nums_min:
90 90 rtest = float(j)/(j-1) + 1.0/navg
91 91 if ((sumq*j) > (rtest*sump**2)):
92 92 j = j - 1
93 93 sump = sump - sortdata[j]
94 94 sumq = sumq - sortdata[j]**2
95 95 cont = 0
96 96
97 97 j += 1
98 98
99 99 lnoise = sump /j
100 100 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
101 101 return lnoise
102 102
103 103 class Beam:
104 104 def __init__(self):
105 105 self.codeList = []
106 106 self.azimuthList = []
107 107 self.zenithList = []
108 108
109 109 class GenericData(object):
110 110
111 111 flagNoData = True
112 112
113 113 def __init__(self):
114 114
115 115 raise ValueError, "This class has not been implemented"
116 116
117 117 def copy(self, inputObj=None):
118 118
119 119 if inputObj == None:
120 120 return copy.deepcopy(self)
121 121
122 122 for key in inputObj.__dict__.keys():
123 123 self.__dict__[key] = inputObj.__dict__[key]
124 124
125 125 def deepcopy(self):
126 126
127 127 return copy.deepcopy(self)
128 128
129 129 def isEmpty(self):
130 130
131 131 return self.flagNoData
132 132
133 133 class JROData(GenericData):
134 134
135 135 # m_BasicHeader = BasicHeader()
136 136 # m_ProcessingHeader = ProcessingHeader()
137 137
138 138 systemHeaderObj = SystemHeader()
139 139
140 140 radarControllerHeaderObj = RadarControllerHeader()
141 141
142 142 # data = None
143 143
144 144 type = None
145 145
146 146 datatype = None #dtype but in string
147 147
148 148 # dtype = None
149 149
150 150 # nChannels = None
151 151
152 152 # nHeights = None
153 153
154 154 nProfiles = None
155 155
156 156 heightList = None
157 157
158 158 channelList = None
159 159
160 160 flagDiscontinuousBlock = False
161 161
162 162 useLocalTime = False
163 163
164 164 utctime = None
165 165
166 166 timeZone = None
167 167
168 168 dstFlag = None
169 169
170 170 errorCount = None
171 171
172 172 blocksize = None
173 173
174 174 # nCode = None
175 175 #
176 176 # nBaud = None
177 177 #
178 178 # code = None
179 179
180 180 flagDecodeData = False #asumo q la data no esta decodificada
181 181
182 182 flagDeflipData = False #asumo q la data no esta sin flip
183 183
184 184 flagShiftFFT = False
185 185
186 186 # ippSeconds = None
187 187
188 188 # timeInterval = None
189 189
190 190 nCohInt = None
191 191
192 192 # noise = None
193 193
194 194 windowOfFilter = 1
195 195
196 196 #Speed of ligth
197 197 C = 3e8
198 198
199 199 frequency = 49.92e6
200 200
201 201 realtime = False
202 202
203 203 beacon_heiIndexList = None
204 204
205 205 last_block = None
206 206
207 207 blocknow = None
208 208
209 209 azimuth = None
210 210
211 211 zenith = None
212 212
213 213 beam = Beam()
214 214
215 215 profileIndex = None
216 216
217 217 def __init__(self):
218 218
219 219 raise ValueError, "This class has not been implemented"
220 220
221 221 def getNoise(self):
222 222
223 223 raise ValueError, "Not implemented"
224 224
225 225 def getNChannels(self):
226 226
227 227 return len(self.channelList)
228 228
229 229 def getChannelIndexList(self):
230 230
231 231 return range(self.nChannels)
232 232
233 233 def getNHeights(self):
234 234
235 235 return len(self.heightList)
236 236
237 237 def getHeiRange(self, extrapoints=0):
238 238
239 239 heis = self.heightList
240 240 # deltah = self.heightList[1] - self.heightList[0]
241 241 #
242 242 # heis.append(self.heightList[-1])
243 243
244 244 return heis
245 245
246 246 def getltctime(self):
247 247
248 248 if self.useLocalTime:
249 249 return self.utctime - self.timeZone*60
250 250
251 251 return self.utctime
252 252
253 253 def getDatatime(self):
254 254
255 255 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
256 256 return datatimeValue
257 257
258 258 def getTimeRange(self):
259 259
260 260 datatime = []
261 261
262 262 datatime.append(self.ltctime)
263 263 datatime.append(self.ltctime + self.timeInterval+60)
264 264
265 265 datatime = numpy.array(datatime)
266 266
267 267 return datatime
268 268
269 269 def getFmax(self):
270 270
271 271 PRF = 1./(self.ippSeconds * self.nCohInt)
272 272
273 273 fmax = PRF/2.
274 274
275 275 return fmax
276 276
277 277 def getVmax(self):
278 278
279 279 _lambda = self.C/self.frequency
280 280
281 281 vmax = self.getFmax() * _lambda
282 282
283 283 return vmax
284 284
285 285 def get_ippSeconds(self):
286 286 '''
287 287 '''
288 288 return self.radarControllerHeaderObj.ippSeconds
289 289
290 290 def set_ippSeconds(self, ippSeconds):
291 291 '''
292 292 '''
293 293
294 294 self.radarControllerHeaderObj.ippSeconds = ippSeconds
295 295
296 296 return
297 297
298 298 def get_dtype(self):
299 299 '''
300 300 '''
301 301 return getNumpyDtype(self.datatype)
302 302
303 303 def set_dtype(self, numpyDtype):
304 304 '''
305 305 '''
306 306
307 307 self.datatype = getDataTypeCode(numpyDtype)
308 308
309 309 def get_code(self):
310 310 '''
311 311 '''
312 312 return self.radarControllerHeaderObj.code
313 313
314 314 def set_code(self, code):
315 315 '''
316 316 '''
317 317 self.radarControllerHeaderObj.code = code
318 318
319 319 return
320 320
321 321 def get_ncode(self):
322 322 '''
323 323 '''
324 324 return self.radarControllerHeaderObj.nCode
325 325
326 326 def set_ncode(self, nCode):
327 327 '''
328 328 '''
329 329 self.radarControllerHeaderObj.nCode = nCode
330 330
331 331 return
332 332
333 333 def get_nbaud(self):
334 334 '''
335 335 '''
336 336 return self.radarControllerHeaderObj.nBaud
337 337
338 338 def set_nbaud(self, nBaud):
339 339 '''
340 340 '''
341 341 self.radarControllerHeaderObj.nBaud = nBaud
342 342
343 343 return
344 344 # def getTimeInterval(self):
345 345 #
346 346 # raise IOError, "This method should be implemented inside each Class"
347 347
348 348 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
349 349 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
350 350 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
351 351 #noise = property(getNoise, "I'm the 'nHeights' property.")
352 352 datatime = property(getDatatime, "I'm the 'datatime' property")
353 353 ltctime = property(getltctime, "I'm the 'ltctime' property")
354 354 ippSeconds = property(get_ippSeconds, set_ippSeconds)
355 355 dtype = property(get_dtype, set_dtype)
356 356 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
357 357 code = property(get_code, set_code)
358 358 nCode = property(get_ncode, set_ncode)
359 359 nBaud = property(get_nbaud, set_nbaud)
360 360
361 361 class Voltage(JROData):
362 362
363 363 #data es un numpy array de 2 dmensiones (canales, alturas)
364 364 data = None
365 365
366 366 def __init__(self):
367 367 '''
368 368 Constructor
369 369 '''
370 370
371 371 self.useLocalTime = True
372 372
373 373 self.radarControllerHeaderObj = RadarControllerHeader()
374 374
375 375 self.systemHeaderObj = SystemHeader()
376 376
377 377 self.type = "Voltage"
378 378
379 379 self.data = None
380 380
381 381 # self.dtype = None
382 382
383 383 # self.nChannels = 0
384 384
385 385 # self.nHeights = 0
386 386
387 387 self.nProfiles = None
388 388
389 389 self.heightList = None
390 390
391 391 self.channelList = None
392 392
393 393 # self.channelIndexList = None
394 394
395 395 self.flagNoData = True
396 396
397 397 self.flagDiscontinuousBlock = False
398 398
399 399 self.utctime = None
400 400
401 401 self.timeZone = None
402 402
403 403 self.dstFlag = None
404 404
405 405 self.errorCount = None
406 406
407 407 self.nCohInt = None
408 408
409 409 self.blocksize = None
410 410
411 411 self.flagDecodeData = False #asumo q la data no esta decodificada
412 412
413 413 self.flagDeflipData = False #asumo q la data no esta sin flip
414 414
415 415 self.flagShiftFFT = False
416 416
417 417 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
418 418
419 419 self.profileIndex = 0
420 420
421 421 def getNoisebyHildebrand(self, channel = None):
422 422 """
423 423 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
424 424
425 425 Return:
426 426 noiselevel
427 427 """
428 428
429 429 if channel != None:
430 430 data = self.data[channel]
431 431 nChannels = 1
432 432 else:
433 433 data = self.data
434 434 nChannels = self.nChannels
435 435
436 436 noise = numpy.zeros(nChannels)
437 437 power = data * numpy.conjugate(data)
438 438
439 439 for thisChannel in range(nChannels):
440 440 if nChannels == 1:
441 441 daux = power[:].real
442 442 else:
443 443 daux = power[thisChannel,:].real
444 444 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
445 445
446 446 return noise
447 447
448 448 def getNoise(self, type = 1, channel = None):
449 449
450 450 if type == 1:
451 451 noise = self.getNoisebyHildebrand(channel)
452 452
453 453 return 10*numpy.log10(noise)
454 454
455 455 def getPower(self, channel = None):
456 456
457 457 if channel != None:
458 458 data = self.data[channel]
459 459 else:
460 460 data = self.data
461 461
462 462 power = data * numpy.conjugate(data)
463 463
464 464 return 10*numpy.log10(power.real)
465 465
466 466 def getTimeInterval(self):
467 467
468 468 timeInterval = self.ippSeconds * self.nCohInt
469 469
470 470 return timeInterval
471 471
472 472 noise = property(getNoise, "I'm the 'nHeights' property.")
473 473 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
474 474
475 475 class Spectra(JROData):
476 476
477 477 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
478 478 data_spc = None
479 479
480 480 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
481 481 data_cspc = None
482 482
483 483 #data es un numpy array de 2 dmensiones (canales, alturas)
484 484 data_dc = None
485 485
486 486 nFFTPoints = None
487 487
488 488 # nPairs = None
489 489
490 490 pairsList = None
491 491
492 492 nIncohInt = None
493 493
494 494 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
495 495
496 496 nCohInt = None #se requiere para determinar el valor de timeInterval
497 497
498 498 ippFactor = None
499 499
500 500 profileIndex = 0
501 501
502 502 def __init__(self):
503 503 '''
504 504 Constructor
505 505 '''
506 506
507 507 self.useLocalTime = True
508 508
509 509 self.radarControllerHeaderObj = RadarControllerHeader()
510 510
511 511 self.systemHeaderObj = SystemHeader()
512 512
513 513 self.type = "Spectra"
514 514
515 515 # self.data = None
516 516
517 517 # self.dtype = None
518 518
519 519 # self.nChannels = 0
520 520
521 521 # self.nHeights = 0
522 522
523 523 self.nProfiles = None
524 524
525 525 self.heightList = None
526 526
527 527 self.channelList = None
528 528
529 529 # self.channelIndexList = None
530 530
531 531 self.pairsList = None
532 532
533 533 self.flagNoData = True
534 534
535 535 self.flagDiscontinuousBlock = False
536 536
537 537 self.utctime = None
538 538
539 539 self.nCohInt = None
540 540
541 541 self.nIncohInt = None
542 542
543 543 self.blocksize = None
544 544
545 545 self.nFFTPoints = None
546 546
547 547 self.wavelength = None
548 548
549 549 self.flagDecodeData = False #asumo q la data no esta decodificada
550 550
551 551 self.flagDeflipData = False #asumo q la data no esta sin flip
552 552
553 553 self.flagShiftFFT = False
554 554
555 555 self.ippFactor = 1
556 556
557 557 #self.noise = None
558 558
559 559 self.beacon_heiIndexList = []
560 560
561 561 self.noise_estimation = None
562 562
563 563
564 564 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
565 565 """
566 566 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
567 567
568 568 Return:
569 569 noiselevel
570 570 """
571 571
572 572 noise = numpy.zeros(self.nChannels)
573 573
574 574 for channel in range(self.nChannels):
575 575 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
576 576 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
577 577
578 578 return noise
579 579
580 580 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
581 581
582 582 if self.noise_estimation != None:
583 583 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
584 584 else:
585 585 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
586 586 return noise
587 587
588 588
589 589 def getFreqRange(self, extrapoints=0):
590 590
591 591 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
592 592 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
593 593
594 594 return freqrange
595 595
596 596 def getVelRange(self, extrapoints=0):
597 597
598 598 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
599 599 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
600 600
601 601 return velrange
602 602
603 603 def getNPairs(self):
604 604
605 605 return len(self.pairsList)
606 606
607 607 def getPairsIndexList(self):
608 608
609 609 return range(self.nPairs)
610 610
611 611 def getNormFactor(self):
612 612
613 613 pwcode = 1
614 614
615 615 if self.flagDecodeData:
616 616 pwcode = numpy.sum(self.code[0]**2)
617 617 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
618 618 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
619 619
620 620 return normFactor
621 621
622 622 def getFlagCspc(self):
623 623
624 624 if self.data_cspc is None:
625 625 return True
626 626
627 627 return False
628 628
629 629 def getFlagDc(self):
630 630
631 631 if self.data_dc is None:
632 632 return True
633 633
634 634 return False
635 635
636 636 def getTimeInterval(self):
637 637
638 638 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
639 639
640 640 return timeInterval
641 641
642 642 def setValue(self, value):
643 643
644 644 print "This property should not be initialized"
645 645
646 646 return
647 647
648 648 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
649 649 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
650 650 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
651 651 flag_cspc = property(getFlagCspc, setValue)
652 652 flag_dc = property(getFlagDc, setValue)
653 653 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
654 654 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
655 655
656 656 class SpectraHeis(Spectra):
657 657
658 658 data_spc = None
659 659
660 660 data_cspc = None
661 661
662 662 data_dc = None
663 663
664 664 nFFTPoints = None
665 665
666 666 # nPairs = None
667 667
668 668 pairsList = None
669 669
670 670 nCohInt = None
671 671
672 672 nIncohInt = None
673 673
674 674 def __init__(self):
675 675
676 676 self.radarControllerHeaderObj = RadarControllerHeader()
677 677
678 678 self.systemHeaderObj = SystemHeader()
679 679
680 680 self.type = "SpectraHeis"
681 681
682 682 # self.dtype = None
683 683
684 684 # self.nChannels = 0
685 685
686 686 # self.nHeights = 0
687 687
688 688 self.nProfiles = None
689 689
690 690 self.heightList = None
691 691
692 692 self.channelList = None
693 693
694 694 # self.channelIndexList = None
695 695
696 696 self.flagNoData = True
697 697
698 698 self.flagDiscontinuousBlock = False
699 699
700 700 # self.nPairs = 0
701 701
702 702 self.utctime = None
703 703
704 704 self.blocksize = None
705 705
706 706 self.profileIndex = 0
707 707
708 708 self.nCohInt = 1
709 709
710 710 self.nIncohInt = 1
711 711
712 712 def getNormFactor(self):
713 713 pwcode = 1
714 714 if self.flagDecodeData:
715 715 pwcode = numpy.sum(self.code[0]**2)
716 716
717 717 normFactor = self.nIncohInt*self.nCohInt*pwcode
718 718
719 719 return normFactor
720 720
721 721 def getTimeInterval(self):
722 722
723 723 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
724 724
725 725 return timeInterval
726 726
727 727 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
728 728 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
729 729
730 730 class Fits(JROData):
731 731
732 732 heightList = None
733 733
734 734 channelList = None
735 735
736 736 flagNoData = True
737 737
738 738 flagDiscontinuousBlock = False
739 739
740 740 useLocalTime = False
741 741
742 742 utctime = None
743 743
744 744 timeZone = None
745 745
746 746 # ippSeconds = None
747 747
748 748 # timeInterval = None
749 749
750 750 nCohInt = None
751 751
752 752 nIncohInt = None
753 753
754 754 noise = None
755 755
756 756 windowOfFilter = 1
757 757
758 758 #Speed of ligth
759 759 C = 3e8
760 760
761 761 frequency = 49.92e6
762 762
763 763 realtime = False
764 764
765 765
766 766 def __init__(self):
767 767
768 768 self.type = "Fits"
769 769
770 770 self.nProfiles = None
771 771
772 772 self.heightList = None
773 773
774 774 self.channelList = None
775 775
776 776 # self.channelIndexList = None
777 777
778 778 self.flagNoData = True
779 779
780 780 self.utctime = None
781 781
782 782 self.nCohInt = 1
783 783
784 784 self.nIncohInt = 1
785 785
786 786 self.useLocalTime = True
787 787
788 788 self.profileIndex = 0
789 789
790 790 # self.utctime = None
791 791 # self.timeZone = None
792 792 # self.ltctime = None
793 793 # self.timeInterval = None
794 794 # self.header = None
795 795 # self.data_header = None
796 796 # self.data = None
797 797 # self.datatime = None
798 798 # self.flagNoData = False
799 799 # self.expName = ''
800 800 # self.nChannels = None
801 801 # self.nSamples = None
802 802 # self.dataBlocksPerFile = None
803 803 # self.comments = ''
804 804 #
805 805
806 806
807 807 def getltctime(self):
808 808
809 809 if self.useLocalTime:
810 810 return self.utctime - self.timeZone*60
811 811
812 812 return self.utctime
813 813
814 814 def getDatatime(self):
815 815
816 816 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
817 817 return datatime
818 818
819 819 def getTimeRange(self):
820 820
821 821 datatime = []
822 822
823 823 datatime.append(self.ltctime)
824 824 datatime.append(self.ltctime + self.timeInterval)
825 825
826 826 datatime = numpy.array(datatime)
827 827
828 828 return datatime
829 829
830 830 def getHeiRange(self):
831 831
832 832 heis = self.heightList
833 833
834 834 return heis
835 835
836 def isEmpty(self):
837
838 return self.flagNoData
839
840 836 def getNHeights(self):
841 837
842 838 return len(self.heightList)
843 839
844 840 def getNChannels(self):
845 841
846 842 return len(self.channelList)
847 843
848 844 def getChannelIndexList(self):
849 845
850 846 return range(self.nChannels)
851 847
852 848 def getNoise(self, type = 1):
853 849
854 850 #noise = numpy.zeros(self.nChannels)
855 851
856 852 if type == 1:
857 853 noise = self.getNoisebyHildebrand()
858 854
859 855 if type == 2:
860 856 noise = self.getNoisebySort()
861 857
862 858 if type == 3:
863 859 noise = self.getNoisebyWindow()
864 860
865 861 return noise
866 862
867 863 def getTimeInterval(self):
868 864
869 865 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
870 866
871 867 return timeInterval
872 868
873 869 datatime = property(getDatatime, "I'm the 'datatime' property")
874 870 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
875 871 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
876 872 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
877 873 noise = property(getNoise, "I'm the 'nHeights' property.")
878 874
879 875 ltctime = property(getltctime, "I'm the 'ltctime' property")
880 876 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
881 877
882 878 class Correlation(JROData):
883 879
884 880 noise = None
885 881
886 882 SNR = None
887 883
888 884 pairsAutoCorr = None #Pairs of Autocorrelation
889 885
890 886 #--------------------------------------------------
891 887
892 888 data_corr = None
893 889
894 890 data_volt = None
895 891
896 892 lagT = None # each element value is a profileIndex
897 893
898 894 lagR = None # each element value is in km
899 895
900 896 pairsList = None
901 897
902 898 calculateVelocity = None
903 899
904 900 nPoints = None
905 901
906 902 nAvg = None
907 903
908 904 bufferSize = None
909 905
910 906 def __init__(self):
911 907 '''
912 908 Constructor
913 909 '''
914 910 self.radarControllerHeaderObj = RadarControllerHeader()
915 911
916 912 self.systemHeaderObj = SystemHeader()
917 913
918 914 self.type = "Correlation"
919 915
920 916 self.data = None
921 917
922 918 self.dtype = None
923 919
924 920 self.nProfiles = None
925 921
926 922 self.heightList = None
927 923
928 924 self.channelList = None
929 925
930 926 self.flagNoData = True
931 927
932 928 self.flagDiscontinuousBlock = False
933 929
934 930 self.utctime = None
935 931
936 932 self.timeZone = None
937 933
938 934 self.dstFlag = None
939 935
940 936 self.errorCount = None
941 937
942 938 self.blocksize = None
943 939
944 940 self.flagDecodeData = False #asumo q la data no esta decodificada
945 941
946 942 self.flagDeflipData = False #asumo q la data no esta sin flip
947 943
948 944 self.pairsList = None
949 945
950 946 self.nPoints = None
951 947
952 948 def getLagTRange(self, extrapoints=0):
953 949
954 950 lagTRange = self.lagT
955 951 diff = lagTRange[1] - lagTRange[0]
956 952 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
957 953 lagTRange = numpy.hstack((lagTRange, extra))
958 954
959 955 return lagTRange
960 956
961 957 def getLagRRange(self, extrapoints=0):
962 958
963 959 return self.lagR
964 960
965 961 def getPairsList(self):
966 962
967 963 return self.pairsList
968 964
969 965 def getCalculateVelocity(self):
970 966
971 967 return self.calculateVelocity
972 968
973 969 def getNPoints(self):
974 970
975 971 return self.nPoints
976 972
977 973 def getNAvg(self):
978 974
979 975 return self.nAvg
980 976
981 977 def getBufferSize(self):
982 978
983 979 return self.bufferSize
984 980
985 981 def getPairsAutoCorr(self):
986 982 pairsList = self.pairsList
987 983 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
988 984
989 985 for l in range(len(pairsList)):
990 986 firstChannel = pairsList[l][0]
991 987 secondChannel = pairsList[l][1]
992 988
993 989 #Obteniendo pares de Autocorrelacion
994 990 if firstChannel == secondChannel:
995 991 pairsAutoCorr[firstChannel] = int(l)
996 992
997 993 pairsAutoCorr = pairsAutoCorr.astype(int)
998 994
999 995 return pairsAutoCorr
1000 996
1001 997 def getNoise(self, mode = 2):
1002 998
1003 999 indR = numpy.where(self.lagR == 0)[0][0]
1004 1000 indT = numpy.where(self.lagT == 0)[0][0]
1005 1001
1006 1002 jspectra0 = self.data_corr[:,:,indR,:]
1007 1003 jspectra = copy.copy(jspectra0)
1008 1004
1009 1005 num_chan = jspectra.shape[0]
1010 1006 num_hei = jspectra.shape[2]
1011 1007
1012 1008 freq_dc = jspectra.shape[1]/2
1013 1009 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1014 1010
1015 1011 if ind_vel[0]<0:
1016 1012 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1017 1013
1018 1014 if mode == 1:
1019 1015 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1020 1016
1021 1017 if mode == 2:
1022 1018
1023 1019 vel = numpy.array([-2,-1,1,2])
1024 1020 xx = numpy.zeros([4,4])
1025 1021
1026 1022 for fil in range(4):
1027 1023 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1028 1024
1029 1025 xx_inv = numpy.linalg.inv(xx)
1030 1026 xx_aux = xx_inv[0,:]
1031 1027
1032 1028 for ich in range(num_chan):
1033 1029 yy = jspectra[ich,ind_vel,:]
1034 1030 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1035 1031
1036 1032 junkid = jspectra[ich,freq_dc,:]<=0
1037 1033 cjunkid = sum(junkid)
1038 1034
1039 1035 if cjunkid.any():
1040 1036 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1041 1037
1042 1038 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1043 1039
1044 1040 return noise
1045 1041
1046 1042 def getTimeInterval(self):
1047 1043
1048 1044 timeInterval = self.ippSeconds * self.nCohInt * self.nPoints
1049 1045
1050 1046 return timeInterval
1051 1047
1052 1048 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1053 1049 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
1054 1050 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
1055 1051 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
1056 1052 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
1057 1053 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
1058 1054
1059 1055
1060 1056 class Parameters(JROData):
1061 1057
1062 1058 #Information from previous data
1063 1059
1064 1060 inputUnit = None #Type of data to be processed
1065 1061
1066 1062 operation = None #Type of operation to parametrize
1067 1063
1068 1064 normFactor = None #Normalization Factor
1069 1065
1070 1066 groupList = None #List of Pairs, Groups, etc
1071 1067
1072 1068 #Parameters
1073 1069
1074 1070 data_param = None #Parameters obtained
1075 1071
1076 1072 data_pre = None #Data Pre Parametrization
1077 1073
1078 1074 data_SNR = None #Signal to Noise Ratio
1079 1075
1080 1076 # heightRange = None #Heights
1081 1077
1082 1078 abscissaList = None #Abscissa, can be velocities, lags or time
1083 1079
1084 1080 noise = None #Noise Potency
1085 1081
1086 1082 utctimeInit = None #Initial UTC time
1087 1083
1088 1084 paramInterval = None #Time interval to calculate Parameters in seconds
1089 1085
1090 1086 #Fitting
1091 1087
1092 1088 data_error = None #Error of the estimation
1093 1089
1094 1090 constants = None
1095 1091
1096 1092 library = None
1097 1093
1098 1094 #Output signal
1099 1095
1100 1096 outputInterval = None #Time interval to calculate output signal in seconds
1101 1097
1102 1098 data_output = None #Out signal
1103 1099
1104 1100
1105 1101
1106 1102 def __init__(self):
1107 1103 '''
1108 1104 Constructor
1109 1105 '''
1110 1106 self.radarControllerHeaderObj = RadarControllerHeader()
1111 1107
1112 1108 self.systemHeaderObj = SystemHeader()
1113 1109
1114 1110 self.type = "Parameters"
1115 1111
1116 1112 def getTimeRange1(self):
1117 1113
1118 1114 datatime = []
1119 1115
1120 1116 if self.useLocalTime:
1121 1117 time1 = self.utctimeInit - self.timeZone*60
1122 1118 else:
1123 1119 time1 = utctimeInit
1124 1120
1125 1121 # datatime.append(self.utctimeInit)
1126 1122 # datatime.append(self.utctimeInit + self.outputInterval)
1127 1123 datatime.append(time1)
1128 1124 datatime.append(time1 + self.outputInterval)
1129 1125
1130 1126 datatime = numpy.array(datatime)
1131 1127
1132 1128 return datatime
@@ -1,19 +1,14
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 5 '''
6 6
7 7 from jroIO_voltage import *
8 8 from jroIO_spectra import *
9 9 from jroIO_heispectra import *
10 10 from jroIO_usrp import *
11
12 # try:
13 # from jroIO_usrp_api import *
14 # except:
15 # print "jroIO_usrp_api could not be imported"
16 11
17 12 from jroIO_amisr import *
18 13 from jroIO_HDF5 import *
19 14 from jroIO_hf import * No newline at end of file
@@ -1,849 +1,845
1 1 '''
2 2 Created on Jul 3, 2014
3 3
4 4 @author: roj-idl71
5 5 '''
6 6
7 7 import os, sys
8 8 import time, datetime
9 9 import numpy
10 10 import fnmatch
11 11 import glob
12
13 try:
14 from gevent import sleep
15 except:
16 from time import sleep
12 from time import sleep
17 13
18 14 try:
19 15 import pyfits
20 except:
21 """
22 """
16 except ImportError, e:
17 print "Fits data cannot be used. Install pyfits module"
23 18
24 19 from xml.etree.ElementTree import ElementTree
25 20
26 21 from jroIO_base import isRadarFolder, isNumber
22 from schainpy.model.data.jrodata import Fits
27 23 from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit
28 24
29 class Fits:
25 class PyFits(object):
30 26 name=None
31 27 format=None
32 28 array =None
33 29 data =None
34 30 thdulist=None
35 31 prihdr=None
36 32 hdu=None
37 33
38 34 def __init__(self):
39 35
40 36 pass
41 37
42 38 def setColF(self,name,format,array):
43 39 self.name=name
44 40 self.format=format
45 41 self.array=array
46 42 a1=numpy.array([self.array],dtype=numpy.float32)
47 43 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
48 44 return self.col1
49 45
50 46 # def setColP(self,name,format,data):
51 47 # self.name=name
52 48 # self.format=format
53 49 # self.data=data
54 50 # a2=numpy.array([self.data],dtype=numpy.float32)
55 51 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
56 52 # return self.col2
57 53
58 54
59 55 def writeData(self,name,format,data):
60 56 self.name=name
61 57 self.format=format
62 58 self.data=data
63 59 a2=numpy.array([self.data],dtype=numpy.float32)
64 60 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
65 61 return self.col2
66 62
67 63 def cFImage(self,idblock,year,month,day,hour,minute,second):
68 64 self.hdu= pyfits.PrimaryHDU(idblock)
69 65 self.hdu.header.set("Year",year)
70 66 self.hdu.header.set("Month",month)
71 67 self.hdu.header.set("Day",day)
72 68 self.hdu.header.set("Hour",hour)
73 69 self.hdu.header.set("Minute",minute)
74 70 self.hdu.header.set("Second",second)
75 71 return self.hdu
76 72
77 73
78 74 def Ctable(self,colList):
79 75 self.cols=pyfits.ColDefs(colList)
80 76 self.tbhdu = pyfits.new_table(self.cols)
81 77 return self.tbhdu
82 78
83 79
84 80 def CFile(self,hdu,tbhdu):
85 81 self.thdulist=pyfits.HDUList([hdu,tbhdu])
86 82
87 83 def wFile(self,filename):
88 84 if os.path.isfile(filename):
89 85 os.remove(filename)
90 86 self.thdulist.writeto(filename)
91 87
92 88
93 89 class ParameterConf:
94 90 ELEMENTNAME = 'Parameter'
95 91 def __init__(self):
96 92 self.name = ''
97 93 self.value = ''
98 94
99 95 def readXml(self, parmElement):
100 96 self.name = parmElement.get('name')
101 97 self.value = parmElement.get('value')
102 98
103 99 def getElementName(self):
104 100 return self.ELEMENTNAME
105 101
106 class Metadata:
102 class Metadata(object):
107 103
108 104 def __init__(self, filename):
109 105 self.parmConfObjList = []
110 106 self.readXml(filename)
111 107
112 108 def readXml(self, filename):
113 109 self.projectElement = None
114 110 self.procUnitConfObjDict = {}
115 111 self.projectElement = ElementTree().parse(filename)
116 112 self.project = self.projectElement.tag
117 113
118 114 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
119 115
120 116 for parmElement in parmElementList:
121 117 parmConfObj = ParameterConf()
122 118 parmConfObj.readXml(parmElement)
123 119 self.parmConfObjList.append(parmConfObj)
124 120
125 121 class FitsWriter(Operation):
126 122
127 123 def __init__(self):
128 124 self.isConfig = False
129 125 self.dataBlocksPerFile = None
130 126 self.blockIndex = 0
131 127 self.flagIsNewFile = 1
132 128 self.fitsObj = None
133 129 self.optchar = 'P'
134 130 self.ext = '.fits'
135 131 self.setFile = 0
136 132
137 def setFitsHeader(self, dataOut, metadatafile):
133 def setFitsHeader(self, dataOut, metadatafile=None):
138 134
139 135 header_data = pyfits.PrimaryHDU()
140 136
141 metadata4fits = Metadata(metadatafile)
142 for parameter in metadata4fits.parmConfObjList:
143 parm_name = parameter.name
144 parm_value = parameter.value
137 header_data.header['EXPNAME'] = "RADAR DATA"
138 header_data.header['DATATYPE'] = "SPECTRA"
139 header_data.header['COMMENT'] = ""
140
141 if metadatafile:
145 142
146 # if parm_value == 'fromdatadatetime':
147 # value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
148 # elif parm_value == 'fromdataheights':
149 # value = dataOut.nHeights
150 # elif parm_value == 'fromdatachannel':
151 # value = dataOut.nChannels
152 # elif parm_value == 'fromdatasamples':
153 # value = dataOut.nFFTPoints
154 # else:
155 # value = parm_value
156
157 header_data.header[parm_name] = parm_value
143 metadata4fits = Metadata(metadatafile)
158 144
145 for parameter in metadata4fits.parmConfObjList:
146 parm_name = parameter.name
147 parm_value = parameter.value
148
149 header_data.header[parm_name] = parm_value
159 150
160 151 header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
161 152 header_data.header['CHANNELLIST'] = str(dataOut.channelList)
162 153 header_data.header['NCHANNELS'] = dataOut.nChannels
163 154 #header_data.header['HEIGHTS'] = dataOut.heightList
164 155 header_data.header['NHEIGHTS'] = dataOut.nHeights
165 156
166 157 header_data.header['IPPSECONDS'] = dataOut.ippSeconds
167 158 header_data.header['NCOHINT'] = dataOut.nCohInt
168 159 header_data.header['NINCOHINT'] = dataOut.nIncohInt
169 160 header_data.header['TIMEZONE'] = dataOut.timeZone
170 161 header_data.header['NBLOCK'] = self.blockIndex
171 162
172 163 header_data.writeto(self.filename)
173 164
174 165 self.addExtension(dataOut.heightList,'HEIGHTLIST')
175 166
176 167
177 def setup(self, dataOut, path, dataBlocksPerFile, metadatafile):
168 def setup(self, dataOut, path, dataBlocksPerFile=100, metadatafile=None):
178 169
179 170 self.path = path
180 171 self.dataOut = dataOut
181 172 self.metadatafile = metadatafile
182 173 self.dataBlocksPerFile = dataBlocksPerFile
183 174
184 175 def open(self):
185 176 self.fitsObj = pyfits.open(self.filename, mode='update')
186 177
187 178
188 179 def addExtension(self, data, tagname):
189 180 self.open()
190 181 extension = pyfits.ImageHDU(data=data, name=tagname)
191 182 #extension.header['TAG'] = tagname
192 183 self.fitsObj.append(extension)
193 184 self.write()
194 185
195 186 def addData(self, data):
196 187 self.open()
197 188 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE'])
198 189 extension.header['UTCTIME'] = self.dataOut.utctime
199 190 self.fitsObj.append(extension)
200 191 self.blockIndex += 1
201 192 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
202 193
203 194 self.write()
204 195
205 196 def write(self):
206 197
207 198 self.fitsObj.flush(verbose=True)
208 199 self.fitsObj.close()
209 200
210 201
211 202 def setNextFile(self):
212 203
213 204 ext = self.ext
214 205 path = self.path
215 206
216 207 timeTuple = time.localtime( self.dataOut.utctime)
217 208 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
218 209
219 210 fullpath = os.path.join( path, subfolder )
220 211 if not( os.path.exists(fullpath) ):
221 212 os.mkdir(fullpath)
222 213 self.setFile = -1 #inicializo mi contador de seteo
223 214 else:
224 215 filesList = os.listdir( fullpath )
225 216 if len( filesList ) > 0:
226 217 filesList = sorted( filesList, key=str.lower )
227 218 filen = filesList[-1]
228 219
229 220 if isNumber( filen[8:11] ):
230 221 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
231 222 else:
232 223 self.setFile = -1
233 224 else:
234 225 self.setFile = -1 #inicializo mi contador de seteo
235 226
236 227 setFile = self.setFile
237 228 setFile += 1
238 229
239 230 thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
240 231 timeTuple.tm_year,
241 232 timeTuple.tm_yday,
242 233 setFile,
243 234 ext )
244 235
245 236 filename = os.path.join( path, subfolder, thisFile )
246 237
247 238 self.blockIndex = 0
248 239 self.filename = filename
249 240 self.setFile = setFile
250 241 self.flagIsNewFile = 1
251 242
252 243 print 'Writing the file: %s'%self.filename
253 244
254 245 self.setFitsHeader(self.dataOut, self.metadatafile)
255 246
256 247 return 1
257 248
258 249 def writeBlock(self):
259 250 self.addData(self.dataOut.data_spc)
260 251 self.flagIsNewFile = 0
261 252
262 253
263 254 def __setNewBlock(self):
264 255
265 256 if self.flagIsNewFile:
266 257 return 1
267 258
268 259 if self.blockIndex < self.dataBlocksPerFile:
269 260 return 1
270 261
271 262 if not( self.setNextFile() ):
272 263 return 0
273 264
274 265 return 1
275 266
276 267 def writeNextBlock(self):
277 268 if not( self.__setNewBlock() ):
278 269 return 0
279 270 self.writeBlock()
280 271 return 1
281 272
282 273 def putData(self):
283 274 if self.flagIsNewFile:
284 275 self.setNextFile()
285 276 self.writeNextBlock()
286 277
287 278 def run(self, dataOut, **kwargs):
288 279 if not(self.isConfig):
289 280 self.setup(dataOut, **kwargs)
290 281 self.isConfig = True
291 282 self.putData()
292 283
293 284
294 285 class FitsReader(ProcessingUnit):
295 286
296 287 # __TIMEZONE = time.timezone
297 288
298 289 expName = None
299 290 datetimestr = None
300 291 utc = None
301 292 nChannels = None
302 293 nSamples = None
303 294 dataBlocksPerFile = None
304 295 comments = None
305 296 lastUTTime = None
306 297 header_dict = None
307 298 data = None
308 299 data_header_dict = None
309 300
310 301 def __init__(self):
311 302 self.isConfig = False
312 303 self.ext = '.fits'
313 304 self.setFile = 0
314 305 self.flagNoMoreFiles = 0
315 306 self.flagIsNewFile = 1
316 307 self.flagDiscontinuousBlock = None
317 308 self.fileIndex = None
318 309 self.filename = None
319 310 self.fileSize = None
320 311 self.fitsObj = None
321 312 self.timeZone = None
322 313 self.nReadBlocks = 0
323 314 self.nTotalBlocks = 0
324 315 self.dataOut = self.createObjByDefault()
325 316 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
326 317 self.blockIndex = 1
327 318
328 319 def createObjByDefault(self):
329 320
330 321 dataObj = Fits()
331 322
332 323 return dataObj
333 324
334 325 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
335 326 try:
336 327 fitsObj = pyfits.open(filename,'readonly')
337 328 except:
338 329 raise IOError, "The file %s can't be opened" %(filename)
339 330
340 331 header = fitsObj[0].header
341 332 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
342 333 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
343 334
344 335 ltc = utc
345 336 if useLocalTime:
346 337 ltc -= time.timezone
347 338 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
348 339 thisTime = thisDatetime.time()
349 340
350 341 if not ((startTime <= thisTime) and (endTime > thisTime)):
351 342 return None
352 343
353 344 return thisDatetime
354 345
355 346 def __setNextFileOnline(self):
356 347 raise ValueError, "No implemented"
357 348
358 349 def __setNextFileOffline(self):
359 350 idFile = self.fileIndex
360 351
361 352 while (True):
362 353 idFile += 1
363 354 if not(idFile < len(self.filenameList)):
364 355 self.flagNoMoreFiles = 1
365 356 print "No more Files"
366 357 return 0
367 358
368 359 filename = self.filenameList[idFile]
369 360
370 361 # if not(self.__verifyFile(filename)):
371 362 # continue
372 363
373 364 fileSize = os.path.getsize(filename)
374 365 fitsObj = pyfits.open(filename,'readonly')
375 366 break
376 367
377 368 self.flagIsNewFile = 1
378 369 self.fileIndex = idFile
379 370 self.filename = filename
380 371 self.fileSize = fileSize
381 372 self.fitsObj = fitsObj
382 373 self.blockIndex = 0
383 374 print "Setting the file: %s"%self.filename
384 375
385 376 return 1
386 377
387 378 def __setValuesFromHeader(self):
388 379
389 380 self.dataOut.header = self.header_dict
390 381 self.dataOut.expName = self.expName
391 self.dataOut.nChannels = self.nChannels
382
392 383 self.dataOut.timeZone = self.timeZone
393 384 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
394 385 self.dataOut.comments = self.comments
395 386 # self.dataOut.timeInterval = self.timeInterval
396 387 self.dataOut.channelList = self.channelList
397 388 self.dataOut.heightList = self.heightList
398 389
399 390 self.dataOut.nCohInt = self.nCohInt
400 391 self.dataOut.nIncohInt = self.nIncohInt
401 392
393 self.dataOut.ippSeconds = self.ippSeconds
394
402 395 def readHeader(self):
403 396 headerObj = self.fitsObj[0]
404 397
405 398 self.header_dict = headerObj.header
406 399 if 'EXPNAME' in headerObj.header.keys():
407 400 self.expName = headerObj.header['EXPNAME']
408 401
409 402 if 'DATATYPE' in headerObj.header.keys():
410 403 self.dataType = headerObj.header['DATATYPE']
411 404
412 405 self.datetimestr = headerObj.header['DATETIME']
413 406 channelList = headerObj.header['CHANNELLIST']
414 407 channelList = channelList.split('[')
415 408 channelList = channelList[1].split(']')
416 409 channelList = channelList[0].split(',')
417 410 channelList = [int(ch) for ch in channelList]
418 411 self.channelList = channelList
419 412 self.nChannels = headerObj.header['NCHANNELS']
420 413 self.nHeights = headerObj.header['NHEIGHTS']
421 414 self.ippSeconds = headerObj.header['IPPSECONDS']
422 415 self.nCohInt = headerObj.header['NCOHINT']
423 416 self.nIncohInt = headerObj.header['NINCOHINT']
424 417 self.dataBlocksPerFile = headerObj.header['NBLOCK']
425 418 self.timeZone = headerObj.header['TIMEZONE']
426 419
427 420 # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
428 421
429 422 if 'COMMENT' in headerObj.header.keys():
430 423 self.comments = headerObj.header['COMMENT']
431 424
432 425 self.readHeightList()
433 426
434 427 def readHeightList(self):
435 428 self.blockIndex = self.blockIndex + 1
436 429 obj = self.fitsObj[self.blockIndex]
437 430 self.heightList = obj.data
438 431 self.blockIndex = self.blockIndex + 1
439 432
440 433 def readExtension(self):
441 434 obj = self.fitsObj[self.blockIndex]
442 435 self.heightList = obj.data
443 436 self.blockIndex = self.blockIndex + 1
444 437
445 438 def setNextFile(self):
446 439
447 440 if self.online:
448 441 newFile = self.__setNextFileOnline()
449 442 else:
450 443 newFile = self.__setNextFileOffline()
451 444
452 445 if not(newFile):
453 446 return 0
454 447
455 448 self.readHeader()
456 449 self.__setValuesFromHeader()
457 450 self.nReadBlocks = 0
458 451 # self.blockIndex = 1
459 452 return 1
460 453
461 454 def __searchFilesOffLine(self,
462 455 path,
463 456 startDate,
464 457 endDate,
465 458 startTime=datetime.time(0,0,0),
466 459 endTime=datetime.time(23,59,59),
467 460 set=None,
468 461 expLabel='',
469 462 ext='.fits',
470 463 walk=True):
471 464
472 465 pathList = []
473 466
474 467 if not walk:
475 468 pathList.append(path)
476 469
477 470 else:
478 471 dirList = []
479 472 for thisPath in os.listdir(path):
480 473 if not os.path.isdir(os.path.join(path,thisPath)):
481 474 continue
482 475 if not isRadarFolder(thisPath):
483 476 continue
484 477
485 478 dirList.append(thisPath)
486 479
487 480 if not(dirList):
488 481 return None, None
489 482
490 483 thisDate = startDate
491 484
492 485 while(thisDate <= endDate):
493 486 year = thisDate.timetuple().tm_year
494 487 doy = thisDate.timetuple().tm_yday
495 488
496 489 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
497 490 if len(matchlist) == 0:
498 491 thisDate += datetime.timedelta(1)
499 492 continue
500 493 for match in matchlist:
501 494 pathList.append(os.path.join(path,match,expLabel))
502 495
503 496 thisDate += datetime.timedelta(1)
504 497
505 498 if pathList == []:
506 499 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
507 500 return None, None
508 501
509 502 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
510 503
511 504 filenameList = []
512 505 datetimeList = []
513 506
514 507 for i in range(len(pathList)):
515 508
516 509 thisPath = pathList[i]
517 510
518 511 fileList = glob.glob1(thisPath, "*%s" %ext)
519 512 fileList.sort()
520 513
521 514 for thisFile in fileList:
522 515
523 516 filename = os.path.join(thisPath,thisFile)
524 517 thisDatetime = self.isFileinThisTime(filename, startTime, endTime)
525 518
526 519 if not(thisDatetime):
527 520 continue
528 521
529 522 filenameList.append(filename)
530 523 datetimeList.append(thisDatetime)
531 524
532 525 if not(filenameList):
533 526 print "Any file was found for the time range %s - %s" %(startTime, endTime)
534 527 return None, None
535 528
536 529 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
537 530 print
538 531
539 532 for i in range(len(filenameList)):
540 533 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
541 534
542 535 self.filenameList = filenameList
543 536 self.datetimeList = datetimeList
544 537
545 538 return pathList, filenameList
546 539
547 540 def setup(self, path=None,
548 541 startDate=None,
549 542 endDate=None,
550 543 startTime=datetime.time(0,0,0),
551 544 endTime=datetime.time(23,59,59),
552 545 set=0,
553 546 expLabel = "",
554 547 ext = None,
555 548 online = False,
556 549 delay = 60,
557 550 walk = True):
558 551
559 552 if path == None:
560 553 raise ValueError, "The path is not valid"
561 554
562 555 if ext == None:
563 556 ext = self.ext
564 557
565 558 if not(online):
566 559 print "Searching files in offline mode ..."
567 560 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
568 561 startTime=startTime, endTime=endTime,
569 562 set=set, expLabel=expLabel, ext=ext,
570 563 walk=walk)
571 564
572 565 if not(pathList):
573 566 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
574 567 datetime.datetime.combine(startDate,startTime).ctime(),
575 568 datetime.datetime.combine(endDate,endTime).ctime())
576 569
577 570 sys.exit(-1)
578 571
579 572 self.fileIndex = -1
580 573 self.pathList = pathList
581 574 self.filenameList = filenameList
582 575
583 576 self.online = online
584 577 self.delay = delay
585 578 ext = ext.lower()
586 579 self.ext = ext
587 580
588 581 if not(self.setNextFile()):
589 582 if (startDate!=None) and (endDate!=None):
590 583 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
591 584 elif startDate != None:
592 585 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
593 586 else:
594 587 print "No files"
595 588
596 589 sys.exit(-1)
597 590
598 591
599 592
600 593 def readBlock(self):
601 594 dataObj = self.fitsObj[self.blockIndex]
602 595
603 596 self.data = dataObj.data
604 597 self.data_header_dict = dataObj.header
605 598 self.utc = self.data_header_dict['UTCTIME']
606 599
607 600 self.flagIsNewFile = 0
608 601 self.blockIndex += 1
609 602 self.nTotalBlocks += 1
610 603 self.nReadBlocks += 1
611 604
612 605 return 1
613 606
614 607 def __jumpToLastBlock(self):
615 608 raise ValueError, "No implemented"
616 609
617 610 def __waitNewBlock(self):
618 611 """
619 612 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
620 613
621 614 Si el modo de lectura es OffLine siempre retorn 0
622 615 """
623 616 if not self.online:
624 617 return 0
625 618
626 619 if (self.nReadBlocks >= self.dataBlocksPerFile):
627 620 return 0
628 621
629 622 currentPointer = self.fp.tell()
630 623
631 624 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
632 625
633 626 for nTries in range( self.nTries ):
634 627
635 628 self.fp.close()
636 629 self.fp = open( self.filename, 'rb' )
637 630 self.fp.seek( currentPointer )
638 631
639 632 self.fileSize = os.path.getsize( self.filename )
640 633 currentSize = self.fileSize - currentPointer
641 634
642 635 if ( currentSize >= neededSize ):
643 636 self.__rdBasicHeader()
644 637 return 1
645 638
646 639 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
647 640 sleep( self.delay )
648 641
649 642
650 643 return 0
651 644
652 645 def __setNewBlock(self):
653 646
654 647 if self.online:
655 648 self.__jumpToLastBlock()
656 649
657 650 if self.flagIsNewFile:
658 651 return 1
659 652
660 653 self.lastUTTime = self.utc
661 654
662 655 if self.online:
663 656 if self.__waitNewBlock():
664 657 return 1
665 658
666 659 if self.nReadBlocks < self.dataBlocksPerFile:
667 660 return 1
668 661
669 662 if not(self.setNextFile()):
670 663 return 0
671 664
672 665 deltaTime = self.utc - self.lastUTTime
673 666
674 667 self.flagDiscontinuousBlock = 0
675 668
676 669 if deltaTime > self.maxTimeStep:
677 670 self.flagDiscontinuousBlock = 1
678 671
679 672 return 1
680 673
681 674
682 675 def readNextBlock(self):
683 676 if not(self.__setNewBlock()):
684 677 return 0
685 678
686 679 if not(self.readBlock()):
687 680 return 0
688 681
689 682 return 1
690 683
684 def printInfo(self):
685
686 pass
691 687
692 688 def getData(self):
693 689
694 690 if self.flagNoMoreFiles:
695 691 self.dataOut.flagNoData = True
696 692 print 'Process finished'
697 693 return 0
698 694
699 695 self.flagDiscontinuousBlock = 0
700 696 self.flagIsNewBlock = 0
701 697
702 698 if not(self.readNextBlock()):
703 699 return 0
704 700
705 if self.data == None:
701 if self.data is None:
706 702 self.dataOut.flagNoData = True
707 703 return 0
708 704
709 705 self.dataOut.data = self.data
710 706 self.dataOut.data_header = self.data_header_dict
711 707 self.dataOut.utctime = self.utc
712 708
713 709 # self.dataOut.header = self.header_dict
714 710 # self.dataOut.expName = self.expName
715 711 # self.dataOut.nChannels = self.nChannels
716 712 # self.dataOut.timeZone = self.timeZone
717 713 # self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
718 714 # self.dataOut.comments = self.comments
719 715 # # self.dataOut.timeInterval = self.timeInterval
720 716 # self.dataOut.channelList = self.channelList
721 717 # self.dataOut.heightList = self.heightList
722 718 self.dataOut.flagNoData = False
723 719
724 720 return self.dataOut.data
725 721
726 722 def run(self, **kwargs):
727 723
728 724 if not(self.isConfig):
729 725 self.setup(**kwargs)
730 726 self.isConfig = True
731 727
732 728 self.getData()
733 729
734 730 class SpectraHeisWriter(Operation):
735 731 # set = None
736 732 setFile = None
737 733 idblock = None
738 734 doypath = None
739 735 subfolder = None
740 736
741 737 def __init__(self):
742 self.wrObj = Fits()
738 self.wrObj = PyFits()
743 739 # self.dataOut = dataOut
744 740 self.nTotalBlocks=0
745 741 # self.set = None
746 742 self.setFile = None
747 743 self.idblock = 0
748 744 self.wrpath = None
749 745 self.doypath = None
750 746 self.subfolder = None
751 747 self.isConfig = False
752 748
753 749 def isNumber(str):
754 750 """
755 751 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
756 752
757 753 Excepciones:
758 754 Si un determinado string no puede ser convertido a numero
759 755 Input:
760 756 str, string al cual se le analiza para determinar si convertible a un numero o no
761 757
762 758 Return:
763 759 True : si el string es uno numerico
764 760 False : no es un string numerico
765 761 """
766 762 try:
767 763 float( str )
768 764 return True
769 765 except:
770 766 return False
771 767
772 768 def setup(self, dataOut, wrpath):
773 769
774 770 if not(os.path.exists(wrpath)):
775 771 os.mkdir(wrpath)
776 772
777 773 self.wrpath = wrpath
778 774 # self.setFile = 0
779 775 self.dataOut = dataOut
780 776
781 777 def putData(self):
782 778 name= time.localtime( self.dataOut.utctime)
783 779 ext=".fits"
784 780
785 781 if self.doypath == None:
786 782 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
787 783 self.doypath = os.path.join( self.wrpath, self.subfolder )
788 784 os.mkdir(self.doypath)
789 785
790 786 if self.setFile == None:
791 787 # self.set = self.dataOut.set
792 788 self.setFile = 0
793 789 # if self.set != self.dataOut.set:
794 790 ## self.set = self.dataOut.set
795 791 # self.setFile = 0
796 792
797 793 #make the filename
798 794 thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
799 795
800 796 filename = os.path.join(self.wrpath,self.subfolder, thisFile)
801 797
802 798 idblock = numpy.array([self.idblock],dtype="int64")
803 799 header=self.wrObj.cFImage(idblock=idblock,
804 800 year=time.gmtime(self.dataOut.utctime).tm_year,
805 801 month=time.gmtime(self.dataOut.utctime).tm_mon,
806 802 day=time.gmtime(self.dataOut.utctime).tm_mday,
807 803 hour=time.gmtime(self.dataOut.utctime).tm_hour,
808 804 minute=time.gmtime(self.dataOut.utctime).tm_min,
809 805 second=time.gmtime(self.dataOut.utctime).tm_sec)
810 806
811 807 c=3E8
812 808 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
813 809 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
814 810
815 811 colList = []
816 812
817 813 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
818 814
819 815 colList.append(colFreq)
820 816
821 817 nchannel=self.dataOut.nChannels
822 818
823 819 for i in range(nchannel):
824 820 col = self.wrObj.writeData(name="PCh"+str(i+1),
825 821 format=str(self.dataOut.nFFTPoints)+'E',
826 822 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
827 823
828 824 colList.append(col)
829 825
830 826 data=self.wrObj.Ctable(colList=colList)
831 827
832 828 self.wrObj.CFile(header,data)
833 829
834 830 self.wrObj.wFile(filename)
835 831
836 832 #update the setFile
837 833 self.setFile += 1
838 834 self.idblock += 1
839 835
840 836 return 1
841 837
842 838 def run(self, dataOut, **kwargs):
843 839
844 840 if not(self.isConfig):
845 841
846 842 self.setup(dataOut, **kwargs)
847 843 self.isConfig = True
848 844
849 845 self.putData() No newline at end of file
@@ -1,343 +1,343
1 1 import numpy
2 2
3 3 from jroproc_base import ProcessingUnit, Operation
4 4 from schainpy.model.data.jrodata import SpectraHeis
5 5
6 6 class SpectraHeisProc(ProcessingUnit):
7 7
8 8 def __init__(self):
9 9
10 10 ProcessingUnit.__init__(self)
11 11
12 12 # self.buffer = None
13 13 # self.firstdatatime = None
14 14 # self.profIndex = 0
15 15 self.dataOut = SpectraHeis()
16 16
17 17 def __updateObjFromVoltage(self):
18 18
19 19 self.dataOut.timeZone = self.dataIn.timeZone
20 20 self.dataOut.dstFlag = self.dataIn.dstFlag
21 21 self.dataOut.errorCount = self.dataIn.errorCount
22 22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
23 23
24 24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
25 25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
26 26 self.dataOut.channelList = self.dataIn.channelList
27 27 self.dataOut.heightList = self.dataIn.heightList
28 28 # self.dataOut.dtype = self.dataIn.dtype
29 29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
30 30 # self.dataOut.nHeights = self.dataIn.nHeights
31 31 # self.dataOut.nChannels = self.dataIn.nChannels
32 32 self.dataOut.nBaud = self.dataIn.nBaud
33 33 self.dataOut.nCode = self.dataIn.nCode
34 34 self.dataOut.code = self.dataIn.code
35 35 # self.dataOut.nProfiles = 1
36 36 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
37 37 self.dataOut.nFFTPoints = self.dataIn.nHeights
38 38 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
39 39 # self.dataOut.flagNoData = self.dataIn.flagNoData
40 40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
41 41 self.dataOut.utctime = self.dataIn.utctime
42 42 # self.dataOut.utctime = self.firstdatatime
43 43 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
44 44 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
45 45 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
46 46 self.dataOut.nCohInt = self.dataIn.nCohInt
47 47 self.dataOut.nIncohInt = 1
48 48 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
49 49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
50 50
51 51 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
52 52 # self.dataOut.set=self.dataIn.set
53 53 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
54 54
55 55
56 56 def __updateObjFromFits(self):
57 57
58 58 self.dataOut.utctime = self.dataIn.utctime
59 self.dataOut.channelIndexList = self.dataIn.channelIndexList
59 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
60 60
61 61 self.dataOut.channelList = self.dataIn.channelList
62 62 self.dataOut.heightList = self.dataIn.heightList
63 63 self.dataOut.data_spc = self.dataIn.data
64 64 self.dataOut.ippSeconds = self.dataIn.ippSeconds
65 65 self.dataOut.nCohInt = self.dataIn.nCohInt
66 66 self.dataOut.nIncohInt = self.dataIn.nIncohInt
67 67 # self.dataOut.timeInterval = self.dataIn.timeInterval
68 68 self.dataOut.timeZone = self.dataIn.timeZone
69 69 self.dataOut.useLocalTime = True
70 70 # self.dataOut.
71 71 # self.dataOut.
72 72
73 73 def __getFft(self):
74 74
75 75 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
76 76 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
77 77 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
78 78 self.dataOut.data_spc = spc
79 79
80 80 def run(self):
81 81
82 82 self.dataOut.flagNoData = True
83 83
84 84 if self.dataIn.type == "Fits":
85 85 self.__updateObjFromFits()
86 86 self.dataOut.flagNoData = False
87 87 return
88 88
89 89 if self.dataIn.type == "SpectraHeis":
90 90 self.dataOut.copy(self.dataIn)
91 91 return
92 92
93 93 if self.dataIn.type == "Voltage":
94 94 self.__updateObjFromVoltage()
95 95 self.__getFft()
96 96 self.dataOut.flagNoData = False
97 97
98 98 return
99 99
100 100 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
101 101
102 102
103 103 def selectChannels(self, channelList):
104 104
105 105 channelIndexList = []
106 106
107 107 for channel in channelList:
108 108 index = self.dataOut.channelList.index(channel)
109 109 channelIndexList.append(index)
110 110
111 111 self.selectChannelsByIndex(channelIndexList)
112 112
113 113 def selectChannelsByIndex(self, channelIndexList):
114 114 """
115 115 Selecciona un bloque de datos en base a canales segun el channelIndexList
116 116
117 117 Input:
118 118 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
119 119
120 120 Affected:
121 121 self.dataOut.data
122 122 self.dataOut.channelIndexList
123 123 self.dataOut.nChannels
124 124 self.dataOut.m_ProcessingHeader.totalSpectra
125 125 self.dataOut.systemHeaderObj.numChannels
126 126 self.dataOut.m_ProcessingHeader.blockSize
127 127
128 128 Return:
129 129 None
130 130 """
131 131
132 132 for channelIndex in channelIndexList:
133 133 if channelIndex not in self.dataOut.channelIndexList:
134 134 print channelIndexList
135 135 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
136 136
137 137 # nChannels = len(channelIndexList)
138 138
139 139 data_spc = self.dataOut.data_spc[channelIndexList,:]
140 140
141 141 self.dataOut.data_spc = data_spc
142 142 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
143 143
144 144 return 1
145 145
146 146 class IncohInt4SpectraHeis(Operation):
147 147
148 148 isConfig = False
149 149
150 150 __profIndex = 0
151 151 __withOverapping = False
152 152
153 153 __byTime = False
154 154 __initime = None
155 155 __lastdatatime = None
156 156 __integrationtime = None
157 157
158 158 __buffer = None
159 159
160 160 __dataReady = False
161 161
162 162 n = None
163 163
164 164
165 165 def __init__(self):
166 166
167 167 Operation.__init__(self)
168 168 # self.isConfig = False
169 169
170 170 def setup(self, n=None, timeInterval=None, overlapping=False):
171 171 """
172 172 Set the parameters of the integration class.
173 173
174 174 Inputs:
175 175
176 176 n : Number of coherent integrations
177 177 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
178 178 overlapping :
179 179
180 180 """
181 181
182 182 self.__initime = None
183 183 self.__lastdatatime = 0
184 184 self.__buffer = None
185 185 self.__dataReady = False
186 186
187 187
188 188 if n == None and timeInterval == None:
189 189 raise ValueError, "n or timeInterval should be specified ..."
190 190
191 191 if n != None:
192 192 self.n = n
193 193 self.__byTime = False
194 194 else:
195 195 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
196 196 self.n = 9999
197 197 self.__byTime = True
198 198
199 199 if overlapping:
200 200 self.__withOverapping = True
201 201 self.__buffer = None
202 202 else:
203 203 self.__withOverapping = False
204 204 self.__buffer = 0
205 205
206 206 self.__profIndex = 0
207 207
208 208 def putData(self, data):
209 209
210 210 """
211 211 Add a profile to the __buffer and increase in one the __profileIndex
212 212
213 213 """
214 214
215 215 if not self.__withOverapping:
216 216 self.__buffer += data.copy()
217 217 self.__profIndex += 1
218 218 return
219 219
220 220 #Overlapping data
221 221 nChannels, nHeis = data.shape
222 222 data = numpy.reshape(data, (1, nChannels, nHeis))
223 223
224 224 #If the buffer is empty then it takes the data value
225 225 if self.__buffer is None:
226 226 self.__buffer = data
227 227 self.__profIndex += 1
228 228 return
229 229
230 230 #If the buffer length is lower than n then stakcing the data value
231 231 if self.__profIndex < self.n:
232 232 self.__buffer = numpy.vstack((self.__buffer, data))
233 233 self.__profIndex += 1
234 234 return
235 235
236 236 #If the buffer length is equal to n then replacing the last buffer value with the data value
237 237 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
238 238 self.__buffer[self.n-1] = data
239 239 self.__profIndex = self.n
240 240 return
241 241
242 242
243 243 def pushData(self):
244 244 """
245 245 Return the sum of the last profiles and the profiles used in the sum.
246 246
247 247 Affected:
248 248
249 249 self.__profileIndex
250 250
251 251 """
252 252
253 253 if not self.__withOverapping:
254 254 data = self.__buffer
255 255 n = self.__profIndex
256 256
257 257 self.__buffer = 0
258 258 self.__profIndex = 0
259 259
260 260 return data, n
261 261
262 262 #Integration with Overlapping
263 263 data = numpy.sum(self.__buffer, axis=0)
264 264 n = self.__profIndex
265 265
266 266 return data, n
267 267
268 268 def byProfiles(self, data):
269 269
270 270 self.__dataReady = False
271 271 avgdata = None
272 272 # n = None
273 273
274 274 self.putData(data)
275 275
276 276 if self.__profIndex == self.n:
277 277
278 278 avgdata, n = self.pushData()
279 279 self.__dataReady = True
280 280
281 281 return avgdata
282 282
283 283 def byTime(self, data, datatime):
284 284
285 285 self.__dataReady = False
286 286 avgdata = None
287 287 n = None
288 288
289 289 self.putData(data)
290 290
291 291 if (datatime - self.__initime) >= self.__integrationtime:
292 292 avgdata, n = self.pushData()
293 293 self.n = n
294 294 self.__dataReady = True
295 295
296 296 return avgdata
297 297
298 298 def integrate(self, data, datatime=None):
299 299
300 300 if self.__initime == None:
301 301 self.__initime = datatime
302 302
303 303 if self.__byTime:
304 304 avgdata = self.byTime(data, datatime)
305 305 else:
306 306 avgdata = self.byProfiles(data)
307 307
308 308
309 309 self.__lastdatatime = datatime
310 310
311 311 if avgdata is None:
312 312 return None, None
313 313
314 314 avgdatatime = self.__initime
315 315
316 316 deltatime = datatime -self.__lastdatatime
317 317
318 318 if not self.__withOverapping:
319 319 self.__initime = datatime
320 320 else:
321 321 self.__initime += deltatime
322 322
323 323 return avgdata, avgdatatime
324 324
325 325 def run(self, dataOut, **kwargs):
326 326
327 327 if not self.isConfig:
328 328 self.setup(**kwargs)
329 329 self.isConfig = True
330 330
331 331 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
332 332
333 333 # dataOut.timeInterval *= n
334 334 dataOut.flagNoData = True
335 335
336 336 if self.__dataReady:
337 337 dataOut.data_spc = avgdata
338 338 dataOut.nIncohInt *= self.n
339 339 # dataOut.nCohInt *= self.n
340 340 dataOut.utctime = avgdatatime
341 341 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
342 342 # dataOut.timeInterval = self.__timeInterval*self.n
343 343 dataOut.flagNoData = False No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now