##// 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 6 from schainpy.model.data.jrodata import Voltage
7 7 from time import time
8 8
9 class VoltageProc(ProcessingUnit):
9 class VoltageProc(ProcessingUnit):
10 10
11 11
12 12 def __init__(self, **kwargs):
13 13
14 14 ProcessingUnit.__init__(self, **kwargs)
15 15
16 # self.objectDict = {}
16 # self.objectDict = {}
17 17 self.dataOut = Voltage()
18 18 self.flip = 1
19 19
@@ -24,7 +24,7 class VoltageProc(ProcessingUnit):
24 24 if self.dataIn.type == 'Voltage':
25 25 self.dataOut.copy(self.dataIn)
26 26
27 # self.dataOut.copy(self.dataIn)
27 # self.dataOut.copy(self.dataIn)
28 28
29 29 def __updateObjFromAmisrInput(self):
30 30
@@ -37,7 +37,7 class VoltageProc(ProcessingUnit):
37 37 self.dataOut.data = self.dataIn.data
38 38 self.dataOut.utctime = self.dataIn.utctime
39 39 self.dataOut.channelList = self.dataIn.channelList
40 # self.dataOut.timeInterval = self.dataIn.timeInterval
40 # self.dataOut.timeInterval = self.dataIn.timeInterval
41 41 self.dataOut.heightList = self.dataIn.heightList
42 42 self.dataOut.nProfiles = self.dataIn.nProfiles
43 43
@@ -51,19 +51,19 class VoltageProc(ProcessingUnit):
51 51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54 #
55 # pass#
56 #
57 # def init(self):
58 #
59 #
60 # if self.dataIn.type == 'AMISR':
61 # self.__updateObjFromAmisrInput()
62 #
63 # if self.dataIn.type == 'Voltage':
64 # self.dataOut.copy(self.dataIn)
65 # # No necesita copiar en cada init() los atributos de dataIn
66 # # la copia deberia hacerse por cada nuevo bloque de datos
54 #
55 # pass#
56 #
57 # def init(self):
58 #
59 #
60 # if self.dataIn.type == 'AMISR':
61 # self.__updateObjFromAmisrInput()
62 #
63 # if self.dataIn.type == 'Voltage':
64 # self.dataOut.copy(self.dataIn)
65 # # No necesita copiar en cada init() los atributos de dataIn
66 # # la copia deberia hacerse por cada nuevo bloque de datos
67 67
68 68 def selectChannels(self, channelList):
69 69
@@ -112,7 +112,7 class VoltageProc(ProcessingUnit):
112 112
113 113 self.dataOut.data = data
114 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 117 return 1
118 118
@@ -198,7 +198,7 class VoltageProc(ProcessingUnit):
198 198 else:
199 199 data = self.dataOut.data[:, minIndex:maxIndex]
200 200
201 # firstHeight = self.dataOut.heightList[minIndex]
201 # firstHeight = self.dataOut.heightList[minIndex]
202 202
203 203 self.dataOut.data = data
204 204 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
@@ -313,33 +313,30 class VoltageProc(ProcessingUnit):
313 313
314 314 self.dataOut.data[:,:,botLim:topLim+1] = ynew
315 315
316 # import collections
316 # import collections
317 317
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):
337 334
338 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 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
@@ -440,12 +440,12 class CohInt(Operation):
440 440
441 441 self.__dataReady = False
442 442 avgdata = None
443 # n = None
444
443 # n = None
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:
@@ -484,9 +519,9 class CohInt(Operation):
484 519
485 520 avgdatatime = self.__initime
486 521
487 deltatime = datatime -self.__lastdatatime
488
489 if not self.__withOverapping:
522 deltatime = datatime - self.__lastdatatime
523
524 if not self.__withOverlapping:
490 525 self.__initime = datatime
491 526 else:
492 527 self.__initime += deltatime
@@ -511,11 +546,10 class CohInt(Operation):
511 546 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
512 547 self.__dataReady = True
513 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 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,16 +559,22 class CohInt(Operation):
525 559 avgdata, avgdatatime = self.integrateByBlock(dataOut)
526 560 dataOut.nProfiles /= self.n
527 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 569 dataOut.flagNoData = True
532 570
533 571 if self.__dataReady:
534 572 dataOut.data = avgdata
535 573 dataOut.nCohInt *= self.n
536 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 578 dataOut.flagNoData = False
539 579
540 580 class Decoder(Operation):
General Comments 0
You need to be logged in to leave comments. Login now