##// END OF EJS Templates
sumado de stride en stride. ej 96 -> 24x4 -> 1
José Chávez -
r1116:277434aacbd1
parent child
Show More
@@ -6,14 +6,14 from jroproc_base import ProcessingUnit, Operation
6 from schainpy.model.data.jrodata import Voltage
6 from schainpy.model.data.jrodata import Voltage
7 from time import time
7 from time import time
8
8
9 class VoltageProc(ProcessingUnit):
9 class VoltageProc(ProcessingUnit):
10
10
11
11
12 def __init__(self, **kwargs):
12 def __init__(self, **kwargs):
13
13
14 ProcessingUnit.__init__(self, **kwargs)
14 ProcessingUnit.__init__(self, **kwargs)
15
15
16 # self.objectDict = {}
16 # self.objectDict = {}
17 self.dataOut = Voltage()
17 self.dataOut = Voltage()
18 self.flip = 1
18 self.flip = 1
19
19
@@ -24,7 +24,7 class VoltageProc(ProcessingUnit):
24 if self.dataIn.type == 'Voltage':
24 if self.dataIn.type == 'Voltage':
25 self.dataOut.copy(self.dataIn)
25 self.dataOut.copy(self.dataIn)
26
26
27 # self.dataOut.copy(self.dataIn)
27 # self.dataOut.copy(self.dataIn)
28
28
29 def __updateObjFromAmisrInput(self):
29 def __updateObjFromAmisrInput(self):
30
30
@@ -37,7 +37,7 class VoltageProc(ProcessingUnit):
37 self.dataOut.data = self.dataIn.data
37 self.dataOut.data = self.dataIn.data
38 self.dataOut.utctime = self.dataIn.utctime
38 self.dataOut.utctime = self.dataIn.utctime
39 self.dataOut.channelList = self.dataIn.channelList
39 self.dataOut.channelList = self.dataIn.channelList
40 # self.dataOut.timeInterval = self.dataIn.timeInterval
40 # self.dataOut.timeInterval = self.dataIn.timeInterval
41 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.nProfiles = self.dataIn.nProfiles
42 self.dataOut.nProfiles = self.dataIn.nProfiles
43
43
@@ -51,19 +51,19 class VoltageProc(ProcessingUnit):
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54 #
54 #
55 # pass#
55 # pass#
56 #
56 #
57 # def init(self):
57 # def init(self):
58 #
58 #
59 #
59 #
60 # if self.dataIn.type == 'AMISR':
60 # if self.dataIn.type == 'AMISR':
61 # self.__updateObjFromAmisrInput()
61 # self.__updateObjFromAmisrInput()
62 #
62 #
63 # if self.dataIn.type == 'Voltage':
63 # if self.dataIn.type == 'Voltage':
64 # self.dataOut.copy(self.dataIn)
64 # self.dataOut.copy(self.dataIn)
65 # # No necesita copiar en cada init() los atributos de dataIn
65 # # No necesita copiar en cada init() los atributos de dataIn
66 # # la copia deberia hacerse por cada nuevo bloque de datos
66 # # la copia deberia hacerse por cada nuevo bloque de datos
67
67
68 def selectChannels(self, channelList):
68 def selectChannels(self, channelList):
69
69
@@ -112,7 +112,7 class VoltageProc(ProcessingUnit):
112
112
113 self.dataOut.data = data
113 self.dataOut.data = data
114 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
114 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 # self.dataOut.nChannels = nChannels
115 # self.dataOut.nChannels = nChannels
116
116
117 return 1
117 return 1
118
118
@@ -198,7 +198,7 class VoltageProc(ProcessingUnit):
198 else:
198 else:
199 data = self.dataOut.data[:, minIndex:maxIndex]
199 data = self.dataOut.data[:, minIndex:maxIndex]
200
200
201 # firstHeight = self.dataOut.heightList[minIndex]
201 # firstHeight = self.dataOut.heightList[minIndex]
202
202
203 self.dataOut.data = data
203 self.dataOut.data = data
204 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
204 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
@@ -313,33 +313,30 class VoltageProc(ProcessingUnit):
313
313
314 self.dataOut.data[:,:,botLim:topLim+1] = ynew
314 self.dataOut.data[:,:,botLim:topLim+1] = ynew
315
315
316 # import collections
316 # import collections
317
317
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):
337
334
338 Operation.__init__(self, **kwargs)
335 Operation.__init__(self, **kwargs)
339
336
340 # self.isConfig = False
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
@@ -440,12 +440,12 class CohInt(Operation):
440
440
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:
@@ -484,9 +519,9 class CohInt(Operation):
484
519
485 avgdatatime = self.__initime
520 avgdatatime = self.__initime
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
@@ -511,11 +546,10 class CohInt(Operation):
511 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
546 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
512 self.__dataReady = True
547 self.__dataReady = True
513 return avgdata, avgdatatime
548 return avgdata, avgdatatime
514
515
549
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 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,16 +559,22 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:
528 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
562 if stride is None:
563 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
564 else:
565 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
529
566
530 # dataOut.timeInterval *= n
567
568 # dataOut.timeInterval *= n
531 dataOut.flagNoData = True
569 dataOut.flagNoData = True
532
570
533 if self.__dataReady:
571 if self.__dataReady:
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
537 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
575 # print avgdata, avgdatatime
576 # raise
577 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
538 dataOut.flagNoData = False
578 dataOut.flagNoData = False
539
579
540 class Decoder(Operation):
580 class Decoder(Operation):
General Comments 0
You need to be logged in to leave comments. Login now