@@ -318,19 +318,16 class VoltageProc(ProcessingUnit): | |||||
318 | class CohInt(Operation): |
|
318 | class CohInt(Operation): | |
319 |
|
319 | |||
320 | isConfig = False |
|
320 | isConfig = False | |
321 |
|
||||
322 | __profIndex = 0 |
|
321 | __profIndex = 0 | |
323 | __withOverapping = False |
|
|||
324 |
|
||||
325 | __byTime = False |
|
322 | __byTime = False | |
326 | __initime = None |
|
323 | __initime = None | |
327 | __lastdatatime = None |
|
324 | __lastdatatime = None | |
328 | __integrationtime = None |
|
325 | __integrationtime = None | |
329 |
|
||||
330 | __buffer = None |
|
326 | __buffer = None | |
331 |
|
327 | __bufferStride = [] | ||
332 | __dataReady = False |
|
328 | __dataReady = False | |
333 |
|
329 | __profIndexStride = 0 | ||
|
330 | __dataToPutStride = False | |||
334 | n = None |
|
331 | n = None | |
335 |
|
332 | |||
336 | def __init__(self, **kwargs): |
|
333 | def __init__(self, **kwargs): | |
@@ -339,7 +336,7 class CohInt(Operation): | |||||
339 |
|
336 | |||
340 |
|
|
337 | # self.isConfig = False | |
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 | Set the parameters of the integration class. |
|
341 | Set the parameters of the integration class. | |
345 |
|
342 | |||
@@ -355,6 +352,7 class CohInt(Operation): | |||||
355 | self.__buffer = None |
|
352 | self.__buffer = None | |
356 | self.__dataReady = False |
|
353 | self.__dataReady = False | |
357 | self.byblock = byblock |
|
354 | self.byblock = byblock | |
|
355 | self.stride = stride | |||
358 |
|
356 | |||
359 | if n == None and timeInterval == None: |
|
357 | if n == None and timeInterval == None: | |
360 | raise ValueError, "n or timeInterval should be specified ..." |
|
358 | raise ValueError, "n or timeInterval should be specified ..." | |
@@ -368,10 +366,10 class CohInt(Operation): | |||||
368 | self.__byTime = True |
|
366 | self.__byTime = True | |
369 |
|
367 | |||
370 | if overlapping: |
|
368 | if overlapping: | |
371 | self.__withOverapping = True |
|
369 | self.__withOverlapping = True | |
372 | self.__buffer = None |
|
370 | self.__buffer = None | |
373 | else: |
|
371 | else: | |
374 | self.__withOverapping = False |
|
372 | self.__withOverlapping = False | |
375 | self.__buffer = 0 |
|
373 | self.__buffer = 0 | |
376 |
|
374 | |||
377 | self.__profIndex = 0 |
|
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 | self.__buffer += data.copy() |
|
385 | self.__buffer += data.copy() | |
388 | self.__profIndex += 1 |
|
386 | self.__profIndex += 1 | |
389 | return |
|
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 | data = self.__buffer |
|
423 | data = self.__buffer | |
426 | n = self.__profIndex |
|
424 | n = self.__profIndex | |
427 |
|
425 | |||
@@ -432,6 +430,8 class CohInt(Operation): | |||||
432 |
|
430 | |||
433 | #Integration with Overlapping |
|
431 | #Integration with Overlapping | |
434 | data = numpy.sum(self.__buffer, axis=0) |
|
432 | data = numpy.sum(self.__buffer, axis=0) | |
|
433 | # print data | |||
|
434 | # raise | |||
435 | n = self.__profIndex |
|
435 | n = self.__profIndex | |
436 |
|
436 | |||
437 | return data, n |
|
437 | return data, n | |
@@ -441,11 +441,11 class CohInt(Operation): | |||||
441 | self.__dataReady = False |
|
441 | self.__dataReady = False | |
442 | avgdata = None |
|
442 | avgdata = None | |
443 | # n = None |
|
443 | # n = None | |
444 |
|
444 | # print data | ||
|
445 | # raise | |||
445 | self.putData(data) |
|
446 | self.putData(data) | |
446 |
|
447 | |||
447 | if self.__profIndex == self.n: |
|
448 | if self.__profIndex == self.n: | |
448 |
|
||||
449 | avgdata, n = self.pushData() |
|
449 | avgdata, n = self.pushData() | |
450 | self.__dataReady = True |
|
450 | self.__dataReady = True | |
451 |
|
451 | |||
@@ -466,6 +466,41 class CohInt(Operation): | |||||
466 |
|
466 | |||
467 | return avgdata |
|
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 | def integrate(self, data, datatime=None): |
|
504 | def integrate(self, data, datatime=None): | |
470 |
|
505 | |||
471 | if self.__initime == None: |
|
506 | if self.__initime == None: | |
@@ -486,7 +521,7 class CohInt(Operation): | |||||
486 |
|
521 | |||
487 | deltatime = datatime -self.__lastdatatime |
|
522 | deltatime = datatime - self.__lastdatatime | |
488 |
|
523 | |||
489 | if not self.__withOverapping: |
|
524 | if not self.__withOverlapping: | |
490 | self.__initime = datatime |
|
525 | self.__initime = datatime | |
491 | else: |
|
526 | else: | |
492 | self.__initime += deltatime |
|
527 | self.__initime += deltatime | |
@@ -512,10 +547,9 class CohInt(Operation): | |||||
512 | self.__dataReady = True |
|
547 | self.__dataReady = True | |
513 | return avgdata, avgdatatime |
|
548 | return avgdata, avgdatatime | |
514 |
|
549 | |||
515 |
|
550 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | ||
516 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs): |
|
|||
517 | if not self.isConfig: |
|
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 | self.isConfig = True |
|
553 | self.isConfig = True | |
520 |
|
554 | |||
521 | if dataOut.flagDataAsBlock: |
|
555 | if dataOut.flagDataAsBlock: | |
@@ -525,7 +559,11 class CohInt(Operation): | |||||
525 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
559 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
526 | dataOut.nProfiles /= self.n |
|
560 | dataOut.nProfiles /= self.n | |
527 | else: |
|
561 | else: | |
|
562 | if stride is None: | |||
528 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
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 | # dataOut.timeInterval *= n | |
531 | dataOut.flagNoData = True |
|
569 | dataOut.flagNoData = True | |
@@ -534,6 +572,8 class CohInt(Operation): | |||||
534 | dataOut.data = avgdata |
|
572 | dataOut.data = avgdata | |
535 | dataOut.nCohInt *= self.n |
|
573 | dataOut.nCohInt *= self.n | |
536 | dataOut.utctime = avgdatatime |
|
574 | dataOut.utctime = avgdatatime | |
|
575 | # print avgdata, avgdatatime | |||
|
576 | # raise | |||
537 |
|
|
577 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
538 | dataOut.flagNoData = False |
|
578 | dataOut.flagNoData = False | |
539 |
|
579 |
General Comments 0
You need to be logged in to leave comments.
Login now