@@ -318,19 +318,16 class VoltageProc(ProcessingUnit): | |||
|
318 | 318 | class CohInt(Operation): |
|
319 | 319 | |
|
320 | 320 | isConfig = False |
|
321 | ||
|
322 | 321 | __profIndex = 0 |
|
323 | __withOverapping = False | |
|
324 | ||
|
325 | 322 | __byTime = False |
|
326 | 323 | __initime = None |
|
327 | 324 | __lastdatatime = None |
|
328 | 325 | __integrationtime = None |
|
329 | ||
|
330 | 326 | __buffer = None |
|
331 | ||
|
327 | __bufferStride = [] | |
|
332 | 328 | __dataReady = False |
|
333 | ||
|
329 | __profIndexStride = 0 | |
|
330 | __dataToPutStride = False | |
|
334 | 331 | n = None |
|
335 | 332 | |
|
336 | 333 | def __init__(self, **kwargs): |
@@ -339,7 +336,7 class CohInt(Operation): | |||
|
339 | 336 | |
|
340 | 337 |
|
|
341 | 338 | |
|
342 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): | |
|
339 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
|
343 | 340 | """ |
|
344 | 341 | Set the parameters of the integration class. |
|
345 | 342 | |
@@ -355,6 +352,7 class CohInt(Operation): | |||
|
355 | 352 | self.__buffer = None |
|
356 | 353 | self.__dataReady = False |
|
357 | 354 | self.byblock = byblock |
|
355 | self.stride = stride | |
|
358 | 356 | |
|
359 | 357 | if n == None and timeInterval == None: |
|
360 | 358 | raise ValueError, "n or timeInterval should be specified ..." |
@@ -368,10 +366,10 class CohInt(Operation): | |||
|
368 | 366 | self.__byTime = True |
|
369 | 367 | |
|
370 | 368 | if overlapping: |
|
371 | self.__withOverapping = True | |
|
369 | self.__withOverlapping = True | |
|
372 | 370 | self.__buffer = None |
|
373 | 371 | else: |
|
374 | self.__withOverapping = False | |
|
372 | self.__withOverlapping = False | |
|
375 | 373 | self.__buffer = 0 |
|
376 | 374 | |
|
377 | 375 | self.__profIndex = 0 |
@@ -383,7 +381,7 class CohInt(Operation): | |||
|
383 | 381 | |
|
384 | 382 | """ |
|
385 | 383 | |
|
386 | if not self.__withOverapping: | |
|
384 | if not self.__withOverlapping: | |
|
387 | 385 | self.__buffer += data.copy() |
|
388 | 386 | self.__profIndex += 1 |
|
389 | 387 | return |
@@ -421,7 +419,7 class CohInt(Operation): | |||
|
421 | 419 | |
|
422 | 420 | """ |
|
423 | 421 | |
|
424 | if not self.__withOverapping: | |
|
422 | if not self.__withOverlapping: | |
|
425 | 423 | data = self.__buffer |
|
426 | 424 | n = self.__profIndex |
|
427 | 425 | |
@@ -432,6 +430,8 class CohInt(Operation): | |||
|
432 | 430 | |
|
433 | 431 | #Integration with Overlapping |
|
434 | 432 | data = numpy.sum(self.__buffer, axis=0) |
|
433 | # print data | |
|
434 | # raise | |
|
435 | 435 | n = self.__profIndex |
|
436 | 436 | |
|
437 | 437 | return data, n |
@@ -441,11 +441,11 class CohInt(Operation): | |||
|
441 | 441 | self.__dataReady = False |
|
442 | 442 | avgdata = None |
|
443 | 443 | # n = None |
|
444 | ||
|
444 | # print data | |
|
445 | # raise | |
|
445 | 446 | self.putData(data) |
|
446 | 447 | |
|
447 | 448 | if self.__profIndex == self.n: |
|
448 | ||
|
449 | 449 | avgdata, n = self.pushData() |
|
450 | 450 | self.__dataReady = True |
|
451 | 451 | |
@@ -466,6 +466,41 class CohInt(Operation): | |||
|
466 | 466 | |
|
467 | 467 | return avgdata |
|
468 | 468 | |
|
469 | def integrateByStride(self, data, datatime): | |
|
470 | # print data | |
|
471 | if self.__profIndex == 0: | |
|
472 | self.__buffer = [[data.copy(), datatime]] | |
|
473 | else: | |
|
474 | self.__buffer.append([data.copy(), datatime]) | |
|
475 | self.__profIndex += 1 | |
|
476 | self.__dataReady = False | |
|
477 | ||
|
478 | if self.__profIndex == self.n * self.stride : | |
|
479 | self.__dataToPutStride = True | |
|
480 | self.__profIndexStride = 0 | |
|
481 | self.__profIndex = 0 | |
|
482 | self.__bufferStride = [] | |
|
483 | for i in range(self.stride): | |
|
484 | current = self.__buffer[i::self.stride] | |
|
485 | data = numpy.sum([t[0] for t in current], axis=0) | |
|
486 | avgdatatime = numpy.average([t[1] for t in current]) | |
|
487 | # print data | |
|
488 | self.__bufferStride.append((data, avgdatatime)) | |
|
489 | ||
|
490 | if self.__dataToPutStride: | |
|
491 | self.__dataReady = False | |
|
492 | self.__profIndexStride += 1 | |
|
493 | if self.__profIndexStride == self.stride: | |
|
494 | self.__dataReady = True | |
|
495 | self.__dataToPutStride = False | |
|
496 | self.__profIndexStride = 0 | |
|
497 | # print self.__bufferStride[self.__profIndexStride - 1] | |
|
498 | # raise | |
|
499 | return (numpy.sum([t[0] for t in self.__bufferStride], axis=0), numpy.average([t[1] for t in self.__bufferStride])) | |
|
500 | ||
|
501 | ||
|
502 | return None, None | |
|
503 | ||
|
469 | 504 | def integrate(self, data, datatime=None): |
|
470 | 505 | |
|
471 | 506 | if self.__initime == None: |
@@ -486,7 +521,7 class CohInt(Operation): | |||
|
486 | 521 | |
|
487 | 522 | deltatime = datatime -self.__lastdatatime |
|
488 | 523 | |
|
489 | if not self.__withOverapping: | |
|
524 | if not self.__withOverlapping: | |
|
490 | 525 | self.__initime = datatime |
|
491 | 526 | else: |
|
492 | 527 | self.__initime += deltatime |
@@ -512,10 +547,9 class CohInt(Operation): | |||
|
512 | 547 | self.__dataReady = True |
|
513 | 548 | return avgdata, avgdatatime |
|
514 | 549 | |
|
515 | ||
|
516 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs): | |
|
550 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
|
517 | 551 | if not self.isConfig: |
|
518 | self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
|
552 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
|
519 | 553 | self.isConfig = True |
|
520 | 554 | |
|
521 | 555 | if dataOut.flagDataAsBlock: |
@@ -525,7 +559,11 class CohInt(Operation): | |||
|
525 | 559 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
526 | 560 | dataOut.nProfiles /= self.n |
|
527 | 561 | else: |
|
562 | if stride is None: | |
|
528 | 563 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
564 | else: | |
|
565 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
|
566 | ||
|
529 | 567 | |
|
530 | 568 |
|
|
531 | 569 | dataOut.flagNoData = True |
@@ -534,6 +572,8 class CohInt(Operation): | |||
|
534 | 572 | dataOut.data = avgdata |
|
535 | 573 | dataOut.nCohInt *= self.n |
|
536 | 574 | dataOut.utctime = avgdatatime |
|
575 | # print avgdata, avgdatatime | |
|
576 | # raise | |
|
537 | 577 |
|
|
538 | 578 | dataOut.flagNoData = False |
|
539 | 579 |
General Comments 0
You need to be logged in to leave comments.
Login now