##// END OF EJS Templates
Se agrego selectHeisa VoltageProc
Miguel Valdez -
r219:70dd31f0d294
parent child
Show More
@@ -1,675 +1,694
1 1 '''
2 2 Created on September , 2012
3 3 @author:
4 4 '''
5 5 from xml.etree.ElementTree import Element, SubElement, ElementTree
6 6 from xml.etree import ElementTree as ET
7 7 from xml.dom import minidom
8 8
9 9 import sys
10 10 import datetime
11 11 from model.jrodataIO import *
12 12 from model.jroprocessing import *
13 13 from model.jroplot import *
14 14
15 15 def prettify(elem):
16 16 """Return a pretty-printed XML string for the Element.
17 17 """
18 18 rough_string = ET.tostring(elem, 'utf-8')
19 19 reparsed = minidom.parseString(rough_string)
20 20 return reparsed.toprettyxml(indent=" ")
21 21
22 22 class ParameterConf():
23 23
24 24 id = None
25 25 name = None
26 26 value = None
27 27 format = None
28 28
29 29 ELEMENTNAME = 'Parameter'
30 30
31 31 def __init__(self):
32 32
33 33 self.format = 'str'
34 34
35 35 def getElementName(self):
36 36
37 37 return self.ELEMENTNAME
38 38
39 39 def getValue(self):
40 40
41 41 if self.format == 'list':
42 42 strList = self.value.split(',')
43 43 return strList
44 44
45 45 if self.format == 'intlist':
46 46 strList = self.value.split(',')
47 47 intList = [int(x) for x in strList]
48 48 return intList
49 49
50 50 if self.format == 'floatlist':
51 51 strList = self.value.split(',')
52 52 floatList = [float(x) for x in strList]
53 53 return floatList
54 54
55 55 if self.format == 'date':
56 56 strList = self.value.split('/')
57 57 intList = [int(x) for x in strList]
58 58 date = datetime.date(intList[0], intList[1], intList[2])
59 59 return date
60 60
61 61 if self.format == 'time':
62 62 strList = self.value.split(':')
63 63 intList = [int(x) for x in strList]
64 64 time = datetime.time(intList[0], intList[1], intList[2])
65 65 return time
66 66
67 67 func = eval(self.format)
68 68
69 69 return func(self.value)
70 70
71 71 def setup(self, id, name, value, format='str'):
72 72
73 73 self.id = id
74 74 self.name = name
75 75 self.value = str(value)
76 76 self.format = format
77 77
78 78 def makeXml(self, opElement):
79 79
80 80 parmElement = SubElement(opElement, self.ELEMENTNAME)
81 81 parmElement.set('id', str(self.id))
82 82 parmElement.set('name', self.name)
83 83 parmElement.set('value', self.value)
84 84 parmElement.set('format', self.format)
85 85
86 86 def readXml(self, parmElement):
87 87
88 88 self.id = parmElement.get('id')
89 89 self.name = parmElement.get('name')
90 90 self.value = parmElement.get('value')
91 91 self.format = parmElement.get('format')
92 92
93 93 def printattr(self):
94 94
95 95 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
96 96
97 97 class OperationConf():
98 98
99 99 id = None
100 100 name = None
101 101 priority = None
102 102 type = None
103 103
104 104 parmConfObjList = []
105 105
106 106 ELEMENTNAME = 'Operation'
107 107
108 108 def __init__(self):
109 109
110 110 id = 0
111 111 name = None
112 112 priority = None
113 113 type = 'self'
114 114
115 115
116 116 def __getNewId(self):
117 117
118 118 return int(self.id)*10 + len(self.parmConfObjList) + 1
119 119
120 120 def getElementName(self):
121 121
122 122 return self.ELEMENTNAME
123 123
124 124 def getParameterObjList(self):
125 125
126 126 return self.parmConfObjList
127 127
128 128 def setup(self, id, name, priority, type):
129 129
130 130 self.id = id
131 131 self.name = name
132 132 self.type = type
133 133 self.priority = priority
134 134
135 135 self.parmConfObjList = []
136 136
137 137 def addParameter(self, name, value, format='str'):
138 138
139 139 id = self.__getNewId()
140 140
141 141 parmConfObj = ParameterConf()
142 142 parmConfObj.setup(id, name, value, format)
143 143
144 144 self.parmConfObjList.append(parmConfObj)
145 145
146 146 return parmConfObj
147 147
148 148 def makeXml(self, upElement):
149 149
150 150 opElement = SubElement(upElement, self.ELEMENTNAME)
151 151 opElement.set('id', str(self.id))
152 152 opElement.set('name', self.name)
153 153 opElement.set('type', self.type)
154 154 opElement.set('priority', str(self.priority))
155 155
156 156 for parmConfObj in self.parmConfObjList:
157 157 parmConfObj.makeXml(opElement)
158 158
159 159 def readXml(self, opElement):
160 160
161 161 self.id = opElement.get('id')
162 162 self.name = opElement.get('name')
163 163 self.type = opElement.get('type')
164 164 self.priority = opElement.get('priority')
165 165
166 166 self.parmConfObjList = []
167 167
168 168 parmElementList = opElement.getiterator(ParameterConf().getElementName())
169 169
170 170 for parmElement in parmElementList:
171 171 parmConfObj = ParameterConf()
172 172 parmConfObj.readXml(parmElement)
173 173 self.parmConfObjList.append(parmConfObj)
174 174
175 175 def printattr(self):
176 176
177 177 print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME,
178 178 self.id,
179 179 self.name,
180 180 self.type,
181 181 self.priority)
182 182
183 183 for parmConfObj in self.parmConfObjList:
184 184 parmConfObj.printattr()
185 185
186 186 def createObject(self):
187 187
188 188 if self.type == 'self':
189 189 raise ValueError, "This operation type cannot be created"
190 190
191 191 if self.type == 'other':
192 192 className = eval(self.name)
193 193 opObj = className()
194 194
195 195 return opObj
196 196
197 197 class ProcUnitConf():
198 198
199 199 id = None
200 200 name = None
201 201 datatype = None
202 202 inputId = None
203 203
204 204 opConfObjList = []
205 205
206 206 procUnitObj = None
207 207 opObjList = []
208 208
209 209 ELEMENTNAME = 'ProcUnit'
210 210
211 211 def __init__(self):
212 212
213 213 self.id = None
214 214 self.datatype = None
215 215 self.name = None
216 216 self.inputId = None
217 217
218 218 self.opConfObjList = []
219 219
220 220 self.procUnitObj = None
221 221 self.opObjDict = {}
222 222
223 223 def __getPriority(self):
224 224
225 225 return len(self.opConfObjList)+1
226 226
227 227 def __getNewId(self):
228 228
229 229 return int(self.id)*10 + len(self.opConfObjList) + 1
230 230
231 231 def getElementName(self):
232 232
233 233 return self.ELEMENTNAME
234 234
235 235 def getId(self):
236 236
237 237 return str(self.id)
238 238
239 239 def getInputId(self):
240 240
241 241 return str(self.inputId)
242 242
243 243 def getOperationObjList(self):
244 244
245 245 return self.opConfObjList
246 246
247 247 def getProcUnitObj(self):
248 248
249 249 return self.procUnitObj
250 250
251 251 def setup(self, id, name, datatype, inputId):
252 252
253 253 self.id = id
254 254 self.name = name
255 255 self.datatype = datatype
256 256 self.inputId = inputId
257 257
258 258 self.opConfObjList = []
259 259
260 260 self.addOperation(name='init', optype='self')
261
262 def addParameter(self, **kwargs):
263
264 opObj = self.opConfObjList[0]
265
266 opObj.addParameter(**kwargs)
261 267
268 return opObj
269
262 270 def addOperation(self, name, optype='self'):
263 271
264 272 id = self.__getNewId()
265 273 priority = self.__getPriority()
266 274
267 275 opConfObj = OperationConf()
268 276 opConfObj.setup(id, name=name, priority=priority, type=optype)
269 277
270 278 self.opConfObjList.append(opConfObj)
271 279
272 280 return opConfObj
273 281
274 282 def makeXml(self, procUnitElement):
275 283
276 284 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
277 285 upElement.set('id', str(self.id))
278 286 upElement.set('name', self.name)
279 287 upElement.set('datatype', self.datatype)
280 288 upElement.set('inputId', str(self.inputId))
281 289
282 290 for opConfObj in self.opConfObjList:
283 291 opConfObj.makeXml(upElement)
284 292
285 293 def readXml(self, upElement):
286 294
287 295 self.id = upElement.get('id')
288 296 self.name = upElement.get('name')
289 297 self.datatype = upElement.get('datatype')
290 298 self.inputId = upElement.get('inputId')
291 299
292 300 self.opConfObjList = []
293 301
294 302 opElementList = upElement.getiterator(OperationConf().getElementName())
295 303
296 304 for opElement in opElementList:
297 305 opConfObj = OperationConf()
298 306 opConfObj.readXml(opElement)
299 307 self.opConfObjList.append(opConfObj)
300 308
301 309 def printattr(self):
302 310
303 311 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
304 312 self.id,
305 313 self.name,
306 314 self.datatype,
307 315 self.inputId)
308 316
309 317 for opConfObj in self.opConfObjList:
310 318 opConfObj.printattr()
311 319
312 320 def createObjects(self):
313 321
314 322 className = eval(self.name)
315 323 procUnitObj = className()
316 324
317 325 for opConfObj in self.opConfObjList:
318 326
319 327 if opConfObj.type == 'self':
320 328 continue
321 329
322 330 opObj = opConfObj.createObject()
323 331
324 332 self.opObjDict[opConfObj.id] = opObj
325 333 procUnitObj.addOperation(opObj, opConfObj.id)
326 334
327 335 self.procUnitObj = procUnitObj
328 336
329 337 return procUnitObj
330 338
331 339 def run(self):
332 340
333 341 finalSts = False
334 342
335 343 for opConfObj in self.opConfObjList:
336 344
337 345 kwargs = {}
338 346 for parmConfObj in opConfObj.getParameterObjList():
339 347 kwargs[parmConfObj.name] = parmConfObj.getValue()
340 348
341 349 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
342 350 sts = self.procUnitObj.call(opConfObj, **kwargs)
343 351 finalSts = finalSts or sts
344 352
345 353 return finalSts
346 354
347 355 class ReadUnitConf(ProcUnitConf):
348 356
349 357 path = None
350 358 startDate = None
351 359 endDate = None
352 360 startTime = None
353 361 endTime = None
354 362 online = None
355 363 expLabel = None
356 364 delay = None
357 365
358 366 ELEMENTNAME = 'ReadUnit'
359 367
360 368 def __init__(self):
361 369
362 370 self.id = None
363 371 self.datatype = None
364 372 self.name = None
365 373 self.inputId = 0
366 374
367 375 self.opConfObjList = []
368 376 self.opObjList = []
369 377
370 378 def getElementName(self):
371 379
372 380 return self.ELEMENTNAME
373 381
374 382 def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60):
375 383
376 384 self.id = id
377 385 self.name = name
378 386 self.datatype = datatype
379 387
380 388 self.path = path
381 389 self.startDate = startDate
382 390 self.endDate = endDate
383 391 self.startTime = startTime
384 392 self.endTime = endTime
385 393 self.online = online
386 394 self.expLabel = expLabel
387 395 self.delay = delay
388 396
389 397 self.addRunOperation()
390 398
391 399 def addRunOperation(self):
392 400
393 401 opObj = self.addOperation(name = 'run', optype = 'self')
394 402
395 403 opObj.addParameter(name='path' , value=self.path, format='str')
396 404 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
397 405 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
398 406 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
399 407 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
400 408 opObj.addParameter(name='expLabel' , value=self.expLabel, format='str')
401 409 opObj.addParameter(name='online' , value=self.online, format='int')
402 410 opObj.addParameter(name='delay' , value=self.delay, format='float')
403 411
404 412 return opObj
405 413
406 414
407 415 class Controller():
408 416
409 417 id = None
410 418 name = None
411 419 description = None
412 420 # readUnitConfObjList = None
413 421 procUnitConfObjDict = None
414 422
415 423 ELEMENTNAME = 'Controller'
416 424
417 425 def __init__(self):
418 426
419 427 self.id = None
420 428 self.name = None
421 429 self.description = None
422 430
423 431 # self.readUnitConfObjList = []
424 432 self.procUnitConfObjDict = {}
425 433
426 434 def __getNewId(self):
427 435
428 436 id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1
429 437
430 438 return str(id)
431 439
432 440 def getElementName(self):
433 441
434 442 return self.ELEMENTNAME
435 443
436 444 def setup(self, id, name, description):
437 445
438 446 self.id = id
439 447 self.name = name
440 448 self.description = description
441 449
442 450 def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60):
443 451
444 452 id = self.__getNewId()
445 453 name = '%sReader' %(datatype)
446 454
447 455 readUnitConfObj = ReadUnitConf()
448 456 readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay)
449 457
450 458 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
451 459
452 460 return readUnitConfObj
453 461
454 462 def addProcUnit(self, datatype, inputId):
455 463
456 464 id = self.__getNewId()
457 465 name = '%sProc' %(datatype)
458 466
459 467 procUnitConfObj = ProcUnitConf()
460 468 procUnitConfObj.setup(id, name, datatype, inputId)
461 469
462 470 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
463 471
464 472 return procUnitConfObj
465 473
466 474 def makeXml(self):
467 475
468 476 projectElement = Element('Controller')
469 477 projectElement.set('id', str(self.id))
470 478 projectElement.set('name', self.name)
471 479 projectElement.set('description', self.description)
472 480
473 481 # for readUnitConfObj in self.readUnitConfObjList:
474 482 # readUnitConfObj.makeXml(projectElement)
475 483
476 484 for procUnitConfObj in self.procUnitConfObjDict.values():
477 485 procUnitConfObj.makeXml(projectElement)
478 486
479 487 self.projectElement = projectElement
480 488
481 489 def writeXml(self, filename):
482 490
483 491 self.makeXml()
484 492
485 493 print prettify(self.projectElement)
486 494
487 495 ElementTree(self.projectElement).write(filename, method='xml')
488 496
489 497 def readXml(self, filename):
490 498
491 499 #tree = ET.parse(filename)
492 500 self.projectElement = None
493 501 # self.readUnitConfObjList = []
494 502 self.procUnitConfObjDict = {}
495 503
496 504 self.projectElement = ElementTree().parse(filename)
497 505
498 506 self.project = self.projectElement.tag
499 507
500 508 self.id = self.projectElement.get('id')
501 509 self.name = self.projectElement.get('name')
502 510 self.description = self.projectElement.get('description')
503 511
504 512 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
505 513
506 514 for readUnitElement in readUnitElementList:
507 515 readUnitConfObj = ReadUnitConf()
508 516 readUnitConfObj.readXml(readUnitElement)
509 517
510 518 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
511 519
512 520 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
513 521
514 522 for procUnitElement in procUnitElementList:
515 523 procUnitConfObj = ProcUnitConf()
516 524 procUnitConfObj.readXml(procUnitElement)
517 525
518 526 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
519 527
520 528 def printattr(self):
521 529
522 530 print "Controller[%s]: name = %s, description = %s" %(self.id,
523 531 self.name,
524 532 self.description)
525 533
526 534 # for readUnitConfObj in self.readUnitConfObjList:
527 535 # readUnitConfObj.printattr()
528 536
529 537 for procUnitConfObj in self.procUnitConfObjDict.values():
530 538 procUnitConfObj.printattr()
531 539
532 540 def createObjects(self):
533 541
534 542 # for readUnitConfObj in self.readUnitConfObjList:
535 543 # readUnitConfObj.createObjects()
536 544
537 545 for procUnitConfObj in self.procUnitConfObjDict.values():
538 546 procUnitConfObj.createObjects()
539 547
540 548 def __connect(self, objIN, obj):
541 549
542 550 obj.setInput(objIN.getOutput())
543 551
544 552 def connectObjects(self):
545 553
546 554 for puConfObj in self.procUnitConfObjDict.values():
547 555
548 556 inputId = puConfObj.getInputId()
549 557
550 558 if int(inputId) == 0:
551 559 continue
552 560
553 561 puConfINObj = self.procUnitConfObjDict[inputId]
554 562
555 563 puObj = puConfObj.getProcUnitObj()
556 564 puINObj = puConfINObj.getProcUnitObj()
557 565
558 566 self.__connect(puINObj, puObj)
559 567
560 568 def run(self):
561 569
562 570 # for readUnitConfObj in self.readUnitConfObjList:
563 571 # readUnitConfObj.run()
564 572
565 573 while(True):
566 574
567 575 finalSts = False
568 576
569 577 for procUnitConfObj in self.procUnitConfObjDict.values():
570 578 #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
571 579 sts = procUnitConfObj.run()
572 580 finalSts = finalSts or sts
573 581
574 582 #If every process unit finished so end process
575 583 if not(finalSts):
576 584 print "Every process units have finished"
577 585 break
578 586
579 587 if __name__ == '__main__':
580 588
581 589 desc = "Segundo Test"
582 590 filename = "schain.xml"
583 591
584 592 controllerObj = Controller()
585 593
586 594 controllerObj.setup(id = '191', name='test01', description=desc)
587 595
588 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
589 path='/Users/dsuarez/Remote/IMAGING',
590 startDate='2011/03/20',
596 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
597 path='data/rawdata/',
598 startDate='2011/01/01',
591 599 endDate='2012/12/31',
592 startTime='06:10:00',
600 startTime='00:00:00',
593 601 endTime='23:59:59',
594 602 online=0)
595 603
596 604 opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks')
597 605
598 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
606 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
607
608 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
609 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
610
611 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
612 opObj10.addParameter(name='minHei', value='90', format='float')
613 opObj10.addParameter(name='maxHei', value='180', format='float')
614
615 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
616 opObj12.addParameter(name='n', value='10', format='int')
599 617
600 opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
601 opObj10.addParameter(name='channelList', value='0,1,2,4,6,7', format='intlist')
618 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
619 procUnitConfObj1.addParameter(name='nFFTPoints', value='16', format='int')
602 620
603 621 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
604 622 opObj11.addParameter(name='idfigure', value='1', format='int')
605 623 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
606 # opObj11.addParameter(name='zmin', value='70', format='int')
607 # opObj11.addParameter(name='zmax', value='90', format='int')
608 opObj11.addParameter(name='showprofile', value='0', format='int')
609 opObj11.addParameter(name='save', value='1', format='int')
610 opObj11.addParameter(name='filename', value='/Users/dsuarez/Pictures/SpectraPlot.png', format='str')
624 opObj11.addParameter(name='zmin', value='40', format='int')
625 opObj11.addParameter(name='zmax', value='80', format='int')
626 opObj11.addParameter(name='showprofile', value='1', format='int')
611 627
612 628 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
613 629 opObj11.addParameter(name='idfigure', value='10', format='int')
614 630 opObj11.addParameter(name='wintitle', value='RTI', format='str')
615 # opObj11.addParameter(name='zmin', value='70', format='int')
616 # opObj11.addParameter(name='zmax', value='90', format='int')
617 opObj11.addParameter(name='showprofile', value='0', format='int')
631 # opObj11.addParameter(name='xmin', value='21', format='float')
632 # opObj11.addParameter(name='xmax', value='22', format='float')
633 opObj11.addParameter(name='zmin', value='40', format='int')
634 opObj11.addParameter(name='zmax', value='80', format='int')
635 opObj11.addParameter(name='showprofile', value='1', format='int')
636 opObj11.addParameter(name='timerange', value=str(20), format='int')
618 637
619 638 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
620 639 # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist')
621 640 #
622 641 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
623 642 # opObj12.addParameter(name='n', value='2', format='int')
624 643 #
625 644 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
626 645 # opObj11.addParameter(name='idfigure', value='2', format='int')
627 646 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
628 647 # opObj11.addParameter(name='zmin', value='70', format='int')
629 648 # opObj11.addParameter(name='zmax', value='90', format='int')
630 649 #
631 650 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
632 651 # opObj10.addParameter(name='channelList', value='2,6', format='intlist')
633 652 #
634 653 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
635 654 # opObj12.addParameter(name='n', value='2', format='int')
636 655 #
637 656 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
638 657 # opObj11.addParameter(name='idfigure', value='3', format='int')
639 658 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
640 659 # opObj11.addParameter(name='zmin', value='70', format='int')
641 660 # opObj11.addParameter(name='zmax', value='90', format='int')
642 661
643 662
644 663 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
645 664 # opObj12.addParameter(name='ncode', value='2', format='int')
646 665 # opObj12.addParameter(name='nbauds', value='8', format='int')
647 666 # opObj12.addParameter(name='code0', value='001110011', format='int')
648 667 # opObj12.addParameter(name='code1', value='001110011', format='int')
649 668
650 669
651 670
652 671 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId())
653 672 #
654 673 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
655 674 # opObj21.addParameter(name='n', value='2', format='int')
656 675 #
657 676 # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
658 677 # opObj11.addParameter(name='idfigure', value='4', format='int')
659 678 # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str')
660 679 # opObj11.addParameter(name='zmin', value='70', format='int')
661 680 # opObj11.addParameter(name='zmax', value='90', format='int')
662 681
663 682 print "Escribiendo el archivo XML"
664 683
665 684 controllerObj.writeXml(filename)
666 685
667 686 print "Leyendo el archivo XML"
668 687 controllerObj.readXml(filename)
669 688 #controllerObj.printattr()
670 689
671 690 controllerObj.createObjects()
672 691 controllerObj.connectObjects()
673 692 controllerObj.run()
674 693
675 694 No newline at end of file
@@ -1,511 +1,511
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 5 '''
6 6 import sys
7 7 import numpy
8 8 import copy
9 9
10 10 class Header:
11 11
12 12 def __init__(self):
13 13 raise
14 14
15 15 def copy(self):
16 16 return copy.deepcopy(self)
17 17
18 18 def read():
19 19 pass
20 20
21 21 def write():
22 22 pass
23 23
24 24 class BasicHeader(Header):
25 25
26 26 size = None
27 27 version = None
28 28 dataBlock = None
29 29 utc = None
30 30 miliSecond = None
31 31 timeZone = None
32 32 dstFlag = None
33 33 errorCount = None
34 34 struct = None
35 35
36 36 def __init__(self):
37 37
38 38 self.size = 0
39 39 self.version = 0
40 40 self.dataBlock = 0
41 41 self.utc = 0
42 42 self.miliSecond = 0
43 43 self.timeZone = 0
44 44 self.dstFlag = 0
45 45 self.errorCount = 0
46 46 self.struct = numpy.dtype([
47 47 ('nSize','<u4'),
48 48 ('nVersion','<u2'),
49 49 ('nDataBlockId','<u4'),
50 50 ('nUtime','<u4'),
51 51 ('nMilsec','<u2'),
52 52 ('nTimezone','<i2'),
53 53 ('nDstflag','<i2'),
54 54 ('nErrorCount','<u4')
55 55 ])
56 56
57 57
58 58 def read(self, fp):
59 59 try:
60 60 header = numpy.fromfile(fp, self.struct,1)
61 61 self.size = int(header['nSize'][0])
62 62 self.version = int(header['nVersion'][0])
63 63 self.dataBlock = int(header['nDataBlockId'][0])
64 64 self.utc = int(header['nUtime'][0])
65 65 self.miliSecond = int(header['nMilsec'][0])
66 66 self.timeZone = int(header['nTimezone'][0])
67 67 self.dstFlag = int(header['nDstflag'][0])
68 68 self.errorCount = int(header['nErrorCount'][0])
69 69
70 70 except Exception, e:
71 71 print "BasicHeader: " + e
72 72 return 0
73 73
74 74 return 1
75 75
76 76 def write(self, fp):
77 77 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
78 78 header = numpy.array(headerTuple,self.struct)
79 79 header.tofile(fp)
80 80
81 81 return 1
82 82
83 83 class SystemHeader(Header):
84 84
85 85 size = None
86 86 nSamples = None
87 87 nProfiles = None
88 88 nChannels = None
89 89 adcResolution = None
90 90 pciDioBusWidth = None
91 91 struct = None
92 92
93 93 def __init__(self):
94 94 self.size = 0
95 95 self.nSamples = 0
96 96 self.nProfiles = 0
97 97 self.nChannels = 0
98 98 self.adcResolution = 0
99 99 self.pciDioBusWidth = 0
100 100 self.struct = numpy.dtype([
101 101 ('nSize','<u4'),
102 102 ('nNumSamples','<u4'),
103 103 ('nNumProfiles','<u4'),
104 104 ('nNumChannels','<u4'),
105 105 ('nADCResolution','<u4'),
106 106 ('nPCDIOBusWidth','<u4'),
107 107 ])
108 108
109 109
110 110 def read(self, fp):
111 111 try:
112 112 header = numpy.fromfile(fp,self.struct,1)
113 113 self.size = header['nSize'][0]
114 114 self.nSamples = header['nNumSamples'][0]
115 115 self.nProfiles = header['nNumProfiles'][0]
116 116 self.nChannels = header['nNumChannels'][0]
117 117 self.adcResolution = header['nADCResolution'][0]
118 118 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
119 119
120 120 except Exception, e:
121 121 print "SystemHeader: " + e
122 122 return 0
123 123
124 124 return 1
125 125
126 126 def write(self, fp):
127 127 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
128 128 header = numpy.array(headerTuple,self.struct)
129 129 header.tofile(fp)
130 130
131 131 return 1
132 132
133 133 class RadarControllerHeader(Header):
134 134
135 135 size = None
136 136 expType = None
137 137 nTx = None
138 138 ipp = None
139 139 txA = None
140 140 txB = None
141 141 nWindows = None
142 142 numTaus = None
143 143 codeType = None
144 144 line6Function = None
145 145 line5Function = None
146 146 fClock = None
147 147 prePulseBefore = None
148 148 prePulserAfter = None
149 149 rangeIpp = None
150 150 rangeTxA = None
151 151 rangeTxB = None
152 152 struct = None
153 153
154 154 def __init__(self):
155 155 self.size = 0
156 156 self.expType = 0
157 157 self.nTx = 0
158 158 self.ipp = 0
159 159 self.txA = 0
160 160 self.txB = 0
161 161 self.nWindows = 0
162 162 self.numTaus = 0
163 163 self.codeType = 0
164 164 self.line6Function = 0
165 165 self.line5Function = 0
166 166 self.fClock = 0
167 167 self.prePulseBefore = 0
168 168 self.prePulserAfter = 0
169 169 self.rangeIpp = 0
170 170 self.rangeTxA = 0
171 171 self.rangeTxB = 0
172 172 self.struct = numpy.dtype([
173 173 ('nSize','<u4'),
174 174 ('nExpType','<u4'),
175 175 ('nNTx','<u4'),
176 176 ('fIpp','<f4'),
177 177 ('fTxA','<f4'),
178 178 ('fTxB','<f4'),
179 179 ('nNumWindows','<u4'),
180 180 ('nNumTaus','<u4'),
181 181 ('nCodeType','<u4'),
182 182 ('nLine6Function','<u4'),
183 183 ('nLine5Function','<u4'),
184 184 ('fClock','<f4'),
185 185 ('nPrePulseBefore','<u4'),
186 186 ('nPrePulseAfter','<u4'),
187 187 ('sRangeIPP','<a20'),
188 188 ('sRangeTxA','<a20'),
189 189 ('sRangeTxB','<a20'),
190 190 ])
191 191
192 192 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
193 193
194 194 self.samplingWindow = None
195 195 self.nHeights = None
196 196 self.firstHeight = None
197 197 self.deltaHeight = None
198 198 self.samplesWin = None
199 199
200 200 self.nCode = None
201 201 self.nBaud = None
202 202 self.code = None
203 203 self.flip1 = None
204 204 self.flip2 = None
205 205
206 206 self.dynamic = numpy.array([],numpy.dtype('byte'))
207 207
208 208
209 209 def read(self, fp):
210 210 try:
211 211 startFp = fp.tell()
212 212 header = numpy.fromfile(fp,self.struct,1)
213 213 self.size = int(header['nSize'][0])
214 214 self.expType = int(header['nExpType'][0])
215 215 self.nTx = int(header['nNTx'][0])
216 216 self.ipp = float(header['fIpp'][0])
217 217 self.txA = float(header['fTxA'][0])
218 218 self.txB = float(header['fTxB'][0])
219 219 self.nWindows = int(header['nNumWindows'][0])
220 220 self.numTaus = int(header['nNumTaus'][0])
221 221 self.codeType = int(header['nCodeType'][0])
222 222 self.line6Function = int(header['nLine6Function'][0])
223 223 self.line5Function = int(header['nLine5Function'][0])
224 224 self.fClock = float(header['fClock'][0])
225 225 self.prePulseBefore = int(header['nPrePulseBefore'][0])
226 226 self.prePulserAfter = int(header['nPrePulseAfter'][0])
227 227 self.rangeIpp = header['sRangeIPP'][0]
228 228 self.rangeTxA = header['sRangeTxA'][0]
229 229 self.rangeTxB = header['sRangeTxB'][0]
230 230 # jump Dynamic Radar Controller Header
231 231 jumpFp = self.size - 116
232 232 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
233 233 #pointer backward to dynamic header and read
234 234 backFp = fp.tell() - jumpFp
235 235 fp.seek(backFp)
236 236
237 237 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
238 238 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
239 239 self.firstHeight = self.samplingWindow['h0']
240 240 self.deltaHeight = self.samplingWindow['dh']
241 241 self.samplesWin = self.samplingWindow['nsa']
242 242
243 243 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
244 244
245 245 if self.codeType != 0:
246 246 self.nCode = int(numpy.fromfile(fp,'<u4',1))
247 247 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
248 248 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
249 249 tempList = []
250 250 for ic in range(self.nCode):
251 251 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
252 252 tempList.append(temp)
253 253 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
254 254 self.code = 2.0*self.code - 1.0
255 255
256 256 if self.line5Function == RCfunction.FLIP:
257 257 self.flip1 = numpy.fromfile(fp,'<u4',1)
258 258
259 259 if self.line6Function == RCfunction.FLIP:
260 260 self.flip2 = numpy.fromfile(fp,'<u4',1)
261 261
262 262 endFp = self.size + startFp
263 263 jumpFp = endFp - fp.tell()
264 264 if jumpFp > 0:
265 265 fp.seek(jumpFp)
266 266
267 267 except Exception, e:
268 268 print "RadarControllerHeader: " + e
269 269 return 0
270 270
271 271 return 1
272 272
273 273 def write(self, fp):
274 274 headerTuple = (self.size,
275 275 self.expType,
276 276 self.nTx,
277 277 self.ipp,
278 278 self.txA,
279 279 self.txB,
280 280 self.nWindows,
281 281 self.numTaus,
282 282 self.codeType,
283 283 self.line6Function,
284 284 self.line5Function,
285 285 self.fClock,
286 286 self.prePulseBefore,
287 287 self.prePulserAfter,
288 288 self.rangeIpp,
289 289 self.rangeTxA,
290 290 self.rangeTxB)
291 291
292 292 header = numpy.array(headerTuple,self.struct)
293 293 header.tofile(fp)
294 294
295 295 dynamic = self.dynamic
296 296 dynamic.tofile(fp)
297 297
298 298 return 1
299 299
300 300
301 301
302 302 class ProcessingHeader(Header):
303 303
304 304 size = None
305 305 dtype = None
306 306 blockSize = None
307 307 profilesPerBlock = None
308 308 dataBlocksPerFile = None
309 309 nWindows = None
310 310 processFlags = None
311 311 nCohInt = None
312 312 nIncohInt = None
313 313 totalSpectra = None
314 314 struct = None
315 315 flag_dc = None
316 316 flag_cspc = None
317 317
318 318 def __init__(self):
319 319 self.size = 0
320 320 self.dtype = 0
321 321 self.blockSize = 0
322 322 self.profilesPerBlock = 0
323 323 self.dataBlocksPerFile = 0
324 324 self.nWindows = 0
325 325 self.processFlags = 0
326 326 self.nCohInt = 0
327 327 self.nIncohInt = 0
328 328 self.totalSpectra = 0
329 329 self.struct = numpy.dtype([
330 330 ('nSize','<u4'),
331 331 ('nDataType','<u4'),
332 332 ('nSizeOfDataBlock','<u4'),
333 333 ('nProfilesperBlock','<u4'),
334 334 ('nDataBlocksperFile','<u4'),
335 335 ('nNumWindows','<u4'),
336 336 ('nProcessFlags','<u4'),
337 337 ('nCoherentIntegrations','<u4'),
338 338 ('nIncoherentIntegrations','<u4'),
339 339 ('nTotalSpectra','<u4')
340 340 ])
341 341 self.samplingWindow = 0
342 342 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
343 343 self.nHeights = 0
344 344 self.firstHeight = 0
345 345 self.deltaHeight = 0
346 346 self.samplesWin = 0
347 347 self.spectraComb = 0
348 348 self.nCode = None
349 349 self.code = None
350 350 self.nBaud = None
351 351 self.shif_fft = False
352 352 self.flag_dc = False
353 353 self.flag_cspc = False
354 354
355 355 def read(self, fp):
356 356 try:
357 357 header = numpy.fromfile(fp,self.struct,1)
358 358 self.size = int(header['nSize'][0])
359 359 self.dtype = int(header['nDataType'][0])
360 360 self.blockSize = int(header['nSizeOfDataBlock'][0])
361 361 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
362 362 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
363 363 self.nWindows = int(header['nNumWindows'][0])
364 364 self.processFlags = int(header['nProcessFlags'])
365 365 self.nCohInt = int(header['nCoherentIntegrations'][0])
366 366 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
367 367 self.totalSpectra = int(header['nTotalSpectra'][0])
368 368 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
369 369 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
370 self.firstHeight = int(self.samplingWindow['h0'][0])
371 self.deltaHeight = int(self.samplingWindow['dh'][0])
370 self.firstHeight = float(self.samplingWindow['h0'][0])
371 self.deltaHeight = float(self.samplingWindow['dh'][0])
372 372 self.samplesWin = self.samplingWindow['nsa']
373 373 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
374 374
375 375 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
376 376 self.nCode = int(numpy.fromfile(fp,'<u4',1))
377 377 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
378 378 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
379 379
380 380 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
381 381 self.shif_fft = True
382 382 else:
383 383 self.shif_fft = False
384 384
385 385 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
386 386 self.flag_dc = True
387 387
388 388 nChannels = 0
389 389 nPairs = 0
390 390 pairList = []
391 391
392 392 for i in range( 0, self.totalSpectra*2, 2 ):
393 393 if self.spectraComb[i] == self.spectraComb[i+1]:
394 394 nChannels = nChannels + 1 #par de canales iguales
395 395 else:
396 396 nPairs = nPairs + 1 #par de canales diferentes
397 397 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
398 398
399 399 self.flag_cspc = False
400 400 if nPairs > 0:
401 401 self.flag_cspc = True
402 402
403 403 except Exception, e:
404 404 print "ProcessingHeader: " + e
405 405 return 0
406 406
407 407 return 1
408 408
409 409 def write(self, fp):
410 410 headerTuple = (self.size,
411 411 self.dtype,
412 412 self.blockSize,
413 413 self.profilesPerBlock,
414 414 self.dataBlocksPerFile,
415 415 self.nWindows,
416 416 self.processFlags,
417 417 self.nCohInt,
418 418 self.nIncohInt,
419 419 self.totalSpectra)
420 420
421 421 header = numpy.array(headerTuple,self.struct)
422 422 header.tofile(fp)
423 423
424 424 if self.nWindows != 0:
425 425 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
426 426 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
427 427 samplingWindow.tofile(fp)
428 428
429 429
430 430 if self.totalSpectra != 0:
431 431 spectraComb = numpy.array([],numpy.dtype('u1'))
432 432 spectraComb = self.spectraComb
433 433 spectraComb.tofile(fp)
434 434
435 435
436 436 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
437 437 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
438 438 nCode.tofile(fp)
439 439
440 440 nBaud = self.nBaud
441 441 nBaud.tofile(fp)
442 442
443 443 code = self.code.reshape(nCode*nBaud)
444 444 code.tofile(fp)
445 445
446 446 return 1
447 447
448 448 class RCfunction:
449 449 NONE=0
450 450 FLIP=1
451 451 CODE=2
452 452 SAMPLING=3
453 453 LIN6DIV256=4
454 454 SYNCHRO=5
455 455
456 456 class nCodeType:
457 457 NONE=0
458 458 USERDEFINE=1
459 459 BARKER2=2
460 460 BARKER3=3
461 461 BARKER4=4
462 462 BARKER5=5
463 463 BARKER7=6
464 464 BARKER11=7
465 465 BARKER13=8
466 466 AC128=9
467 467 COMPLEMENTARYCODE2=10
468 468 COMPLEMENTARYCODE4=11
469 469 COMPLEMENTARYCODE8=12
470 470 COMPLEMENTARYCODE16=13
471 471 COMPLEMENTARYCODE32=14
472 472 COMPLEMENTARYCODE64=15
473 473 COMPLEMENTARYCODE128=16
474 474 CODE_BINARY28=17
475 475
476 476 class PROCFLAG:
477 477 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
478 478 DECODE_DATA = numpy.uint32(0x00000002)
479 479 SPECTRA_CALC = numpy.uint32(0x00000004)
480 480 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
481 481 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
482 482 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
483 483
484 484 DATATYPE_CHAR = numpy.uint32(0x00000040)
485 485 DATATYPE_SHORT = numpy.uint32(0x00000080)
486 486 DATATYPE_LONG = numpy.uint32(0x00000100)
487 487 DATATYPE_INT64 = numpy.uint32(0x00000200)
488 488 DATATYPE_FLOAT = numpy.uint32(0x00000400)
489 489 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
490 490
491 491 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
492 492 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
493 493 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
494 494
495 495 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
496 496 DEFLIP_DATA = numpy.uint32(0x00010000)
497 497 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
498 498
499 499 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
500 500 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
501 501 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
502 502 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
503 503 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
504 504
505 505 EXP_NAME_ESP = numpy.uint32(0x00200000)
506 506 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
507 507
508 508 OPERATION_MASK = numpy.uint32(0x0000003F)
509 509 DATATYPE_MASK = numpy.uint32(0x00000FC0)
510 510 DATAARRANGE_MASK = numpy.uint32(0x00007000)
511 511 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
@@ -1,903 +1,985
1 1 '''
2 2
3 3 $Author: dsuarez $
4 4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 5 '''
6 6 import os
7 7 import numpy
8 8 import datetime
9 9 import time
10 10
11 11 from jrodata import *
12 12 from jrodataIO import *
13 13 from jroplot import *
14 14
15 15 class ProcessingUnit:
16 16
17 17 """
18 18 Esta es la clase base para el procesamiento de datos.
19 19
20 20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
21 21 - Metodos internos (callMethod)
22 22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
23 23 tienen que ser agreagados con el metodo "add".
24 24
25 25 """
26 26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
27 27 dataIn = None
28 28
29 29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
30 30 dataOut = None
31 31
32 32
33 33 objectDict = None
34 34
35 35 def __init__(self):
36 36
37 37 self.objectDict = {}
38 38
39 39 def init(self):
40 40
41 41 raise ValueError, "Not implemented"
42 42
43 43 def addOperation(self, object, objId):
44 44
45 45 """
46 46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
47 47 identificador asociado a este objeto.
48 48
49 49 Input:
50 50
51 51 object : objeto de la clase "Operation"
52 52
53 53 Return:
54 54
55 55 objId : identificador del objeto, necesario para ejecutar la operacion
56 56 """
57 57
58 58 self.objectDict[objId] = object
59 59
60 60 return objId
61 61
62 62 def operation(self, **kwargs):
63 63
64 64 """
65 65 Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los
66 66 atributos del objeto dataOut
67 67
68 68 Input:
69 69
70 70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
71 71 """
72 72
73 73 raise ValueError, "ImplementedError"
74 74
75 75 def callMethod(self, name, **kwargs):
76 76
77 77 """
78 78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
79 79
80 80 Input:
81 81 name : nombre del metodo a ejecutar
82 82
83 83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
84 84
85 85 """
86 86 if name != 'run':
87 87
88 88 if name == 'init' and self.dataIn.isEmpty():
89 89 self.dataOut.flagNoData = True
90 90 return False
91 91
92 92 if name != 'init' and self.dataOut.isEmpty():
93 93 return False
94 94
95 95 methodToCall = getattr(self, name)
96 96
97 97 methodToCall(**kwargs)
98 98
99 99 if name != 'run':
100 100 return True
101 101
102 102 if self.dataOut.isEmpty():
103 103 return False
104 104
105 105 return True
106 106
107 107 def callObject(self, objId, **kwargs):
108 108
109 109 """
110 110 Ejecuta la operacion asociada al identificador del objeto "objId"
111 111
112 112 Input:
113 113
114 114 objId : identificador del objeto a ejecutar
115 115
116 116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
117 117
118 118 Return:
119 119
120 120 None
121 121 """
122 122
123 123 if self.dataOut.isEmpty():
124 124 return False
125 125
126 126 object = self.objectDict[objId]
127 127
128 128 object.run(self.dataOut, **kwargs)
129 129
130 130 return True
131 131
132 132 def call(self, operationConf, **kwargs):
133 133
134 134 """
135 135 Return True si ejecuta la operacion "operationConf.name" con los
136 136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
137 137 La operacion puede ser de dos tipos:
138 138
139 139 1. Un metodo propio de esta clase:
140 140
141 141 operation.type = "self"
142 142
143 143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
144 144 operation.type = "other".
145 145
146 146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
147 147 "addOperation" e identificado con el operation.id
148 148
149 149
150 150 con el id de la operacion.
151 151
152 152 Input:
153 153
154 154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
155 155
156 156 """
157 157
158 158 if operationConf.type == 'self':
159 159 sts = self.callMethod(operationConf.name, **kwargs)
160 160
161 161 if operationConf.type == 'other':
162 162 sts = self.callObject(operationConf.id, **kwargs)
163 163
164 164 return sts
165 165
166 166 def setInput(self, dataIn):
167 167
168 168 self.dataIn = dataIn
169 169
170 170 def getOutput(self):
171 171
172 172 return self.dataOut
173 173
174 174 class Operation():
175 175
176 176 """
177 177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
178 178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
179 179 acumulacion dentro de esta clase
180 180
181 181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
182 182
183 183 """
184 184
185 185 __buffer = None
186 186 __isConfig = False
187 187
188 188 def __init__(self):
189 189
190 190 pass
191 191
192 192 def run(self, dataIn, **kwargs):
193 193
194 194 """
195 195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
196 196
197 197 Input:
198 198
199 199 dataIn : objeto del tipo JROData
200 200
201 201 Return:
202 202
203 203 None
204 204
205 205 Affected:
206 206 __buffer : buffer de recepcion de datos.
207 207
208 208 """
209 209
210 210 raise ValueError, "ImplementedError"
211 211
212 212 class VoltageProc(ProcessingUnit):
213 213
214 214
215 215 def __init__(self):
216 216
217 217 self.objectDict = {}
218 218 self.dataOut = Voltage()
219 219
220 220 def init(self):
221 221
222 222 self.dataOut.copy(self.dataIn)
223 223 # No necesita copiar en cada init() los atributos de dataIn
224 224 # la copia deberia hacerse por cada nuevo bloque de datos
225 225
226 226 def selectChannels(self, channelList):
227 227
228 228 channelIndexList = []
229 229
230 230 for channel in channelList:
231 231 index = self.dataOut.channelList.index(channel)
232 232 channelIndexList.append(index)
233 233
234 234 self.selectChannelsByIndex(channelIndexList)
235 235
236 236 def selectChannelsByIndex(self, channelIndexList):
237 237 """
238 238 Selecciona un bloque de datos en base a canales segun el channelIndexList
239 239
240 240 Input:
241 241 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
242 242
243 243 Affected:
244 244 self.dataOut.data
245 245 self.dataOut.channelIndexList
246 246 self.dataOut.nChannels
247 247 self.dataOut.m_ProcessingHeader.totalSpectra
248 248 self.dataOut.systemHeaderObj.numChannels
249 249 self.dataOut.m_ProcessingHeader.blockSize
250 250
251 251 Return:
252 252 None
253 253 """
254 254
255 255 for channelIndex in channelIndexList:
256 256 if channelIndex not in self.dataOut.channelIndexList:
257 257 print channelIndexList
258 258 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
259 259
260 260 nChannels = len(channelIndexList)
261 261
262 262 data = self.dataOut.data[channelIndexList,:]
263 263
264 264 self.dataOut.data = data
265 265 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
266 266 # self.dataOut.nChannels = nChannels
267 267
268 268 return 1
269
270 def selectHeights(self, minHei, maxHei):
271 """
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
273 minHei <= height <= maxHei
274
275 Input:
276 minHei : valor minimo de altura a considerar
277 maxHei : valor maximo de altura a considerar
278
279 Affected:
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
281
282 Return:
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
284 """
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
287
288 if (maxHei > self.dataOut.heightList[-1]):
289 maxHei = self.dataOut.heightList[-1]
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
291
292 minIndex = 0
293 maxIndex = 0
294 data = self.dataOut.heightList
295
296 for i,val in enumerate(data):
297 if val < minHei:
298 continue
299 else:
300 minIndex = i;
301 break
302
303 for i,val in enumerate(data):
304 if val <= maxHei:
305 maxIndex = i;
306 else:
307 break
308
309 self.selectHeightsByIndex(minIndex, maxIndex)
310
311 return 1
312
313
314 def selectHeightsByIndex(self, minIndex, maxIndex):
315 """
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
317 minIndex <= index <= maxIndex
318
319 Input:
320 minIndex : valor de indice minimo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
322
323 Affected:
324 self.dataOut.data
325 self.dataOut.heightList
326
327 Return:
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
329 """
330
331 if (minIndex < 0) or (minIndex > maxIndex):
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
333
334 if (maxIndex >= self.dataOut.nHeights):
335 maxIndex = self.dataOut.nHeights-1
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
337
338 nHeights = maxIndex - minIndex + 1
339
340 #voltage
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
342
343 firstHeight = self.dataOut.heightList[minIndex]
344
345 self.dataOut.data = data
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
347
348 return 1
349
269 350
270 351 class CohInt(Operation):
271 352
272 353 __profIndex = 0
273 354 __withOverapping = False
274 355
275 356 __byTime = False
276 357 __initime = None
277 358 __lastdatatime = None
278 359 __integrationtime = None
279 360
280 361 __buffer = None
281 362
282 363 __dataReady = False
283 364
284 365 n = None
285 366
286 367
287 368 def __init__(self):
288 369
289 370 self.__isConfig = False
290 371
291 372 def setup(self, n=None, timeInterval=None, overlapping=False):
292 373 """
293 374 Set the parameters of the integration class.
294 375
295 376 Inputs:
296 377
297 378 n : Number of coherent integrations
298 379 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
299 380 overlapping :
300 381
301 382 """
302 383
303 384 self.__initime = None
304 385 self.__lastdatatime = 0
305 386 self.__buffer = None
306 387 self.__dataReady = False
307 388
308 389
309 390 if n == None and timeInterval == None:
310 391 raise ValueError, "n or timeInterval should be specified ..."
311 392
312 393 if n != None:
313 394 self.n = n
314 395 self.__byTime = False
315 396 else:
316 397 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
317 398 self.n = 9999
318 399 self.__byTime = True
319 400
320 401 if overlapping:
321 402 self.__withOverapping = True
322 403 self.__buffer = None
323 404 else:
324 405 self.__withOverapping = False
325 406 self.__buffer = 0
326 407
327 408 self.__profIndex = 0
328 409
329 410 def putData(self, data):
330 411
331 412 """
332 413 Add a profile to the __buffer and increase in one the __profileIndex
333 414
334 415 """
335 416
336 417 if not self.__withOverapping:
337 418 self.__buffer += data.copy()
338 419 self.__profIndex += 1
339 420 return
340 421
341 422 #Overlapping data
342 423 nChannels, nHeis = data.shape
343 424 data = numpy.reshape(data, (1, nChannels, nHeis))
344 425
345 426 #If the buffer is empty then it takes the data value
346 427 if self.__buffer == None:
347 428 self.__buffer = data
348 429 self.__profIndex += 1
349 430 return
350 431
351 432 #If the buffer length is lower than n then stakcing the data value
352 433 if self.__profIndex < self.n:
353 434 self.__buffer = numpy.vstack((self.__buffer, data))
354 435 self.__profIndex += 1
355 436 return
356 437
357 438 #If the buffer length is equal to n then replacing the last buffer value with the data value
358 439 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
359 440 self.__buffer[self.n-1] = data
360 441 self.__profIndex = self.n
361 442 return
362 443
363 444
364 445 def pushData(self):
365 446 """
366 447 Return the sum of the last profiles and the profiles used in the sum.
367 448
368 449 Affected:
369 450
370 451 self.__profileIndex
371 452
372 453 """
373 454
374 455 if not self.__withOverapping:
375 456 data = self.__buffer
376 457 n = self.__profIndex
377 458
378 459 self.__buffer = 0
379 460 self.__profIndex = 0
380 461
381 462 return data, n
382 463
383 464 #Integration with Overlapping
384 465 data = numpy.sum(self.__buffer, axis=0)
385 466 n = self.__profIndex
386 467
387 468 return data, n
388 469
389 470 def byProfiles(self, data):
390 471
391 472 self.__dataReady = False
392 473 avgdata = None
393 474 n = None
394 475
395 476 self.putData(data)
396 477
397 478 if self.__profIndex == self.n:
398 479
399 480 avgdata, n = self.pushData()
400 481 self.__dataReady = True
401 482
402 483 return avgdata
403 484
404 485 def byTime(self, data, datatime):
405 486
406 487 self.__dataReady = False
407 488 avgdata = None
408 489 n = None
409 490
410 491 self.putData(data)
411 492
412 493 if (datatime - self.__initime) >= self.__integrationtime:
413 494 avgdata, n = self.pushData()
414 495 self.n = n
415 496 self.__dataReady = True
416 497
417 498 return avgdata
418 499
419 500 def integrate(self, data, datatime=None):
420 501
421 502 if self.__initime == None:
422 503 self.__initime = datatime
423 504
424 505 if self.__byTime:
425 506 avgdata = self.byTime(data, datatime)
426 507 else:
427 508 avgdata = self.byProfiles(data)
428 509
429 510
430 511 self.__lastdatatime = datatime
431 512
432 513 if avgdata == None:
433 514 return None, None
434 515
435 516 avgdatatime = self.__initime
436 517
437 518 deltatime = datatime -self.__lastdatatime
438 519
439 520 if not self.__withOverapping:
440 521 self.__initime = datatime
441 522 else:
442 523 self.__initime += deltatime
443 524
444 525 return avgdata, avgdatatime
445 526
446 527 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
447 528
448 529 if not self.__isConfig:
449 530 self.setup(n, timeInterval, overlapping)
450 531 self.__isConfig = True
451 532
452 533 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
453 534
454 535 # dataOut.timeInterval *= n
455 536 dataOut.flagNoData = True
456 537
457 538 if self.__dataReady:
458 539 dataOut.data = avgdata
459 540 dataOut.nCohInt *= self.n
460 541 dataOut.utctime = avgdatatime
461 542 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
462 543 dataOut.flagNoData = False
463 544
464 545
465 546 class SpectraProc(ProcessingUnit):
466 547
467 548 def __init__(self):
468 549
469 550 self.objectDict = {}
470 551 self.buffer = None
471 552 self.firstdatatime = None
472 553 self.profIndex = 0
473 554 self.dataOut = Spectra()
474 555
475 556 def __updateObjFromInput(self):
476 557
477 558 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
478 559 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
479 560 self.dataOut.channelList = self.dataIn.channelList
480 561 self.dataOut.heightList = self.dataIn.heightList
481 562 self.dataOut.dtype = self.dataIn.dtype
482 563 # self.dataOut.nHeights = self.dataIn.nHeights
483 564 # self.dataOut.nChannels = self.dataIn.nChannels
484 565 self.dataOut.nBaud = self.dataIn.nBaud
485 566 self.dataOut.nCode = self.dataIn.nCode
486 567 self.dataOut.code = self.dataIn.code
487 568 self.dataOut.nProfiles = self.dataOut.nFFTPoints
488 569 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
489 570 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
490 571 self.dataOut.utctime = self.firstdatatime
491 572 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
492 573 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
493 574 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
494 575 self.dataOut.nCohInt = self.dataIn.nCohInt
495 576 self.dataOut.nIncohInt = 1
496 577 self.dataOut.ippSeconds = self.dataIn.ippSeconds
497 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nConInt*self.dataOut.nIncohInt
498
578
579 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nCohInt*self.dataOut.nIncohInt
580
499 581 def __getFft(self):
500 582 """
501 583 Convierte valores de Voltaje a Spectra
502 584
503 585 Affected:
504 586 self.dataOut.data_spc
505 587 self.dataOut.data_cspc
506 588 self.dataOut.data_dc
507 589 self.dataOut.heightList
508 590 self.dataOut.m_BasicHeader
509 591 self.dataOut.m_ProcessingHeader
510 592 self.dataOut.radarControllerHeaderObj
511 593 self.dataOut.systemHeaderObj
512 594 self.profIndex
513 595 self.buffer
514 596 self.dataOut.flagNoData
515 597 self.dataOut.dtype
516 598 self.dataOut.nPairs
517 599 self.dataOut.nChannels
518 600 self.dataOut.nProfiles
519 601 self.dataOut.systemHeaderObj.numChannels
520 602 self.dataOut.m_ProcessingHeader.totalSpectra
521 603 self.dataOut.m_ProcessingHeader.profilesPerBlock
522 604 self.dataOut.m_ProcessingHeader.numHeights
523 605 self.dataOut.m_ProcessingHeader.spectraComb
524 606 self.dataOut.m_ProcessingHeader.shif_fft
525 607 """
526 608 fft_volt = numpy.fft.fft(self.buffer,axis=1)
527 609 dc = fft_volt[:,0,:]
528 610
529 611 #calculo de self-spectra
530 612 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
531 613 spc = fft_volt * numpy.conjugate(fft_volt)
532 614 spc = spc.real
533 615
534 616 blocksize = 0
535 617 blocksize += dc.size
536 618 blocksize += spc.size
537 619
538 620 cspc = None
539 621 pairIndex = 0
540 622 if self.dataOut.pairsList != None:
541 623 #calculo de cross-spectra
542 624 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
543 625 for pair in self.dataOut.pairsList:
544 626 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
545 627 pairIndex += 1
546 628 blocksize += cspc.size
547 629
548 630 self.dataOut.data_spc = spc
549 631 self.dataOut.data_cspc = cspc
550 632 self.dataOut.data_dc = dc
551 633 self.dataOut.blockSize = blocksize
552 634
553 635 def init(self, nFFTPoints=None, pairsList=None):
554 636
555 637 if self.dataIn.type == "Spectra":
556 638 self.dataOut.copy(self.dataIn)
557 639 return
558 640
559 641 if self.dataIn.type == "Voltage":
560 642
561 643 if nFFTPoints == None:
562 644 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
563 645
564 646 if pairsList == None:
565 647 nPairs = 0
566 648 else:
567 649 nPairs = len(pairsList)
568 650
569 651 self.dataOut.nFFTPoints = nFFTPoints
570 652 self.dataOut.pairsList = pairsList
571 653 self.dataOut.nPairs = nPairs
572 654
573 655 if self.buffer == None:
574 656 self.buffer = numpy.zeros((self.dataIn.nChannels,
575 657 self.dataOut.nFFTPoints,
576 658 self.dataIn.nHeights),
577 659 dtype='complex')
578 660
579 661
580 662 self.buffer[:,self.profIndex,:] = self.dataIn.data
581 663 self.profIndex += 1
582 664
583 665 if self.firstdatatime == None:
584 666 self.firstdatatime = self.dataIn.utctime
585 667
586 668 if self.profIndex == self.dataOut.nFFTPoints:
587 669 self.__updateObjFromInput()
588 670 self.__getFft()
589 671
590 672 self.dataOut.flagNoData = False
591 673
592 674 self.buffer = None
593 675 self.firstdatatime = None
594 676 self.profIndex = 0
595 677
596 678 return
597 679
598 680 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
599 681
600 682 def selectChannels(self, channelList):
601 683
602 684 channelIndexList = []
603 685
604 686 for channel in channelList:
605 687 index = self.dataOut.channelList.index(channel)
606 688 channelIndexList.append(index)
607 689
608 690 self.selectChannelsByIndex(channelIndexList)
609 691
610 692 def selectChannelsByIndex(self, channelIndexList):
611 693 """
612 694 Selecciona un bloque de datos en base a canales segun el channelIndexList
613 695
614 696 Input:
615 697 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
616 698
617 699 Affected:
618 700 self.dataOut.data_spc
619 701 self.dataOut.channelIndexList
620 702 self.dataOut.nChannels
621 703
622 704 Return:
623 705 None
624 706 """
625 707
626 708 for channelIndex in channelIndexList:
627 709 if channelIndex not in self.dataOut.channelIndexList:
628 710 print channelIndexList
629 711 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
630 712
631 713 nChannels = len(channelIndexList)
632 714
633 715 data_spc = self.dataOut.data_spc[channelIndexList,:]
634 716
635 717 self.dataOut.data_spc = data_spc
636 718 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
637 719 # self.dataOut.nChannels = nChannels
638 720
639 721 return 1
640 722
641 723
642 724 class IncohInt(Operation):
643 725
644 726
645 727 __profIndex = 0
646 728 __withOverapping = False
647 729
648 730 __byTime = False
649 731 __initime = None
650 732 __lastdatatime = None
651 733 __integrationtime = None
652 734
653 735 __buffer_spc = None
654 736 __buffer_cspc = None
655 737 __buffer_dc = None
656 738
657 739 __dataReady = False
658 740
659 741 n = None
660 742
661 743
662 744 def __init__(self):
663 745
664 746 self.__isConfig = False
665 747
666 748 def setup(self, n=None, timeInterval=None, overlapping=False):
667 749 """
668 750 Set the parameters of the integration class.
669 751
670 752 Inputs:
671 753
672 754 n : Number of coherent integrations
673 755 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
674 756 overlapping :
675 757
676 758 """
677 759
678 760 self.__initime = None
679 761 self.__lastdatatime = 0
680 762 self.__buffer_spc = None
681 763 self.__buffer_cspc = None
682 764 self.__buffer_dc = None
683 765 self.__dataReady = False
684 766
685 767
686 768 if n == None and timeInterval == None:
687 769 raise ValueError, "n or timeInterval should be specified ..."
688 770
689 771 if n != None:
690 772 self.n = n
691 773 self.__byTime = False
692 774 else:
693 775 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
694 776 self.n = 9999
695 777 self.__byTime = True
696 778
697 779 if overlapping:
698 780 self.__withOverapping = True
699 781 else:
700 782 self.__withOverapping = False
701 783 self.__buffer_spc = 0
702 784 self.__buffer_cspc = 0
703 785 self.__buffer_dc = 0
704 786
705 787 self.__profIndex = 0
706 788
707 789 def putData(self, data_spc, data_cspc, data_dc):
708 790
709 791 """
710 792 Add a profile to the __buffer_spc and increase in one the __profileIndex
711 793
712 794 """
713 795
714 796 if not self.__withOverapping:
715 797 self.__buffer_spc += data_spc
716 798
717 799 if data_cspc == None:
718 800 self.__buffer_cspc = None
719 801 else:
720 802 self.__buffer_cspc += data_cspc
721 803
722 804 if data_dc == None:
723 805 self.__buffer_dc = None
724 806 else:
725 807 self.__buffer_dc += data_dc
726 808
727 809 self.__profIndex += 1
728 810 return
729 811
730 812 #Overlapping data
731 813 nChannels, nFFTPoints, nHeis = data_spc.shape
732 814 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
733 815 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
734 816 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
735 817
736 818 #If the buffer is empty then it takes the data value
737 819 if self.__buffer_spc == None:
738 820 self.__buffer_spc = data_spc.copy()
739 821
740 822 if data_cspc == None:
741 823 self.__buffer_cspc = None
742 824 else:
743 825 self.__buffer_cspc += data_cspc.copy()
744 826
745 827 if data_dc == None:
746 828 self.__buffer_dc = None
747 829 else:
748 830 self.__buffer_dc += data_dc.copy()
749 831
750 832 self.__profIndex += 1
751 833 return
752 834
753 835 #If the buffer length is lower than n then stakcing the data value
754 836 if self.__profIndex < self.n:
755 837 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
756 838
757 839 if self.__buffer_cspc != None:
758 840 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
759 841
760 842 if self.__buffer_dc != None:
761 843 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
762 844
763 845 self.__profIndex += 1
764 846 return
765 847
766 848 #If the buffer length is equal to n then replacing the last buffer value with the data value
767 849 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
768 850 self.__buffer_spc[self.n-1] = data_spc
769 851
770 852 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
771 853 self.__buffer_cspc[self.n-1] = data_cspc
772 854
773 855 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
774 856 self.__buffer_dc[self.n-1] = data_dc
775 857
776 858 self.__profIndex = self.n
777 859 return
778 860
779 861
780 862 def pushData(self):
781 863 """
782 864 Return the sum of the last profiles and the profiles used in the sum.
783 865
784 866 Affected:
785 867
786 868 self.__profileIndex
787 869
788 870 """
789 871 data_spc = None
790 872 data_cspc = None
791 873 data_dc = None
792 874
793 875 if not self.__withOverapping:
794 876 data_spc = self.__buffer_spc
795 877 data_cspc = self.__buffer_cspc
796 878 data_dc = self.__buffer_dc
797 879
798 880 n = self.__profIndex
799 881
800 882 self.__buffer_spc = 0
801 883 self.__buffer_cspc = 0
802 884 self.__buffer_dc = 0
803 885 self.__profIndex = 0
804 886
805 887 return data_spc, data_cspc, data_dc, n
806 888
807 889 #Integration with Overlapping
808 890 data_spc = numpy.sum(self.__buffer_spc, axis=0)
809 891
810 892 if self.__buffer_cspc != None:
811 893 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
812 894
813 895 if self.__buffer_dc != None:
814 896 data_dc = numpy.sum(self.__buffer_dc, axis=0)
815 897
816 898 n = self.__profIndex
817 899
818 900 return data_spc, data_cspc, data_dc, n
819 901
820 902 def byProfiles(self, *args):
821 903
822 904 self.__dataReady = False
823 905 avgdata_spc = None
824 906 avgdata_cspc = None
825 907 avgdata_dc = None
826 908 n = None
827 909
828 910 self.putData(*args)
829 911
830 912 if self.__profIndex == self.n:
831 913
832 914 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
833 915 self.__dataReady = True
834 916
835 917 return avgdata_spc, avgdata_cspc, avgdata_dc
836 918
837 919 def byTime(self, datatime, *args):
838 920
839 921 self.__dataReady = False
840 922 avgdata_spc = None
841 923 avgdata_cspc = None
842 924 avgdata_dc = None
843 925 n = None
844 926
845 927 self.putData(*args)
846 928
847 929 if (datatime - self.__initime) >= self.__integrationtime:
848 930 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
849 931 self.n = n
850 932 self.__dataReady = True
851 933
852 934 return avgdata_spc, avgdata_cspc, avgdata_dc
853 935
854 936 def integrate(self, datatime, *args):
855 937
856 938 if self.__initime == None:
857 939 self.__initime = datatime
858 940
859 941 if self.__byTime:
860 942 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
861 943 else:
862 944 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
863 945
864 946 self.__lastdatatime = datatime
865 947
866 948 if avgdata_spc == None:
867 949 return None, None, None, None
868 950
869 951 avgdatatime = self.__initime
870 952
871 953 deltatime = datatime -self.__lastdatatime
872 954
873 955 if not self.__withOverapping:
874 956 self.__initime = datatime
875 957 else:
876 958 self.__initime += deltatime
877 959
878 960 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
879 961
880 962 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
881 963
882 964 if not self.__isConfig:
883 965 self.setup(n, timeInterval, overlapping)
884 966 self.__isConfig = True
885 967
886 968 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
887 969 dataOut.data_spc,
888 970 dataOut.data_cspc,
889 971 dataOut.data_dc)
890 972
891 973 # dataOut.timeInterval *= n
892 974 dataOut.flagNoData = True
893 975
894 976 if self.__dataReady:
895 977 dataOut.data_spc = avgdata_spc
896 978 dataOut.data_cspc = avgdata_cspc
897 979 dataOut.data_dc = avgdata_dc
898 980
899 981 dataOut.nIncohInt *= self.n
900 982 dataOut.utctime = avgdatatime
901 983 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
902 984 dataOut.flagNoData = False
903 985 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now