##// END OF EJS Templates
new changes to indentify and select beams
Daniel Valdez -
r477:9729744d0cb2
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,690 +1,702
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 5 '''
6 6
7 7 import os, sys
8 8 import copy
9 9 import numpy
10 10 import datetime
11 11 import time
12 12 from jroheaderIO import SystemHeader, RadarControllerHeader
13 13
14 14
15 15 def hildebrand_sekhon(data, navg):
16 16
17 17 data = data.copy()
18 18
19 19 sortdata = numpy.sort(data,axis=None)
20 20 lenOfData = len(sortdata)
21 21 nums_min = lenOfData/10
22 22
23 23 if (lenOfData/10) > 2:
24 24 nums_min = lenOfData/10
25 25 else:
26 26 nums_min = 2
27 27
28 28 sump = 0.
29 29
30 30 sumq = 0.
31 31
32 32 j = 0
33 33
34 34 cont = 1
35 35
36 36 while((cont==1)and(j<lenOfData)):
37 37
38 38 sump += sortdata[j]
39 39
40 40 sumq += sortdata[j]**2
41 41
42 42 j += 1
43 43
44 44 if j > nums_min:
45 45 rtest = float(j)/(j-1) + 1.0/navg
46 46 if ((sumq*j) > (rtest*sump**2)):
47 47 j = j - 1
48 48 sump = sump - sortdata[j]
49 49 sumq = sumq - sortdata[j]**2
50 50 cont = 0
51 51
52 52 lnoise = sump /j
53 53 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
54 54 return lnoise
55 55
56 56 class JROData:
57 57
58 58 # m_BasicHeader = BasicHeader()
59 59 # m_ProcessingHeader = ProcessingHeader()
60 60
61 61 systemHeaderObj = SystemHeader()
62 62
63 63 radarControllerHeaderObj = RadarControllerHeader()
64 64
65 65 # data = None
66 66
67 67 type = None
68 68
69 69 dtype = None
70 70
71 71 # nChannels = None
72 72
73 73 # nHeights = None
74 74
75 75 nProfiles = None
76 76
77 77 heightList = None
78 78
79 79 channelList = None
80 80
81 81 flagNoData = True
82 82
83 83 flagTimeBlock = False
84 84
85 85 useLocalTime = False
86 86
87 87 utctime = None
88 88
89 89 timeZone = None
90 90
91 91 dstFlag = None
92 92
93 93 errorCount = None
94 94
95 95 blocksize = None
96 96
97 97 nCode = None
98 98
99 99 nBaud = None
100 100
101 101 code = None
102 102
103 103 flagDecodeData = False #asumo q la data no esta decodificada
104 104
105 105 flagDeflipData = False #asumo q la data no esta sin flip
106 106
107 107 flagShiftFFT = False
108 108
109 109 ippSeconds = None
110 110
111 111 timeInterval = None
112 112
113 113 nCohInt = None
114 114
115 115 noise = None
116 116
117 117 windowOfFilter = 1
118 118
119 119 #Speed of ligth
120 120 C = 3e8
121 121
122 122 frequency = 49.92e6
123 123
124 124 realtime = False
125 125
126 126 beacon_heiIndexList = None
127 127
128 128 last_block = None
129 129
130 130 blocknow = None
131 131
132 132 def __init__(self):
133 133
134 134 raise ValueError, "This class has not been implemented"
135 135
136 136 def copy(self, inputObj=None):
137 137
138 138 if inputObj == None:
139 139 return copy.deepcopy(self)
140 140
141 141 for key in inputObj.__dict__.keys():
142 142 self.__dict__[key] = inputObj.__dict__[key]
143 143
144 144 def deepcopy(self):
145 145
146 146 return copy.deepcopy(self)
147 147
148 148 def isEmpty(self):
149 149
150 150 return self.flagNoData
151 151
152 152 def getNoise(self):
153 153
154 154 raise ValueError, "Not implemented"
155 155
156 156 def getNChannels(self):
157 157
158 158 return len(self.channelList)
159 159
160 160 def getChannelIndexList(self):
161 161
162 162 return range(self.nChannels)
163 163
164 164 def getNHeights(self):
165 165
166 166 return len(self.heightList)
167 167
168 168 def getHeiRange(self, extrapoints=0):
169 169
170 170 heis = self.heightList
171 171 # deltah = self.heightList[1] - self.heightList[0]
172 172 #
173 173 # heis.append(self.heightList[-1])
174 174
175 175 return heis
176 176
177 177 def getltctime(self):
178 178
179 179 if self.useLocalTime:
180 180 return self.utctime - self.timeZone*60
181 181
182 182 return self.utctime
183 183
184 184 def getDatatime(self):
185 185
186 186 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
187 187 return datatime
188 188
189 189 def getTimeRange(self):
190 190
191 191 datatime = []
192 192
193 193 datatime.append(self.ltctime)
194 194 datatime.append(self.ltctime + self.timeInterval)
195 195
196 196 datatime = numpy.array(datatime)
197 197
198 198 return datatime
199 199
200 200 def getFmax(self):
201 201
202 202 PRF = 1./(self.ippSeconds * self.nCohInt)
203 203
204 204 fmax = PRF/2.
205 205
206 206 return fmax
207 207
208 208 def getVmax(self):
209 209
210 210 _lambda = self.C/self.frequency
211 211
212 212 vmax = self.getFmax() * _lambda
213 213
214 214 return vmax
215 215
216 216 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
217 217 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
218 218 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
219 219 noise = property(getNoise, "I'm the 'nHeights' property.")
220 220 datatime = property(getDatatime, "I'm the 'datatime' property")
221 221 ltctime = property(getltctime, "I'm the 'ltctime' property")
222 222
223 223 class Voltage(JROData):
224 224
225 225 #data es un numpy array de 2 dmensiones (canales, alturas)
226 226 data = None
227 227
228 228 def __init__(self):
229 229 '''
230 230 Constructor
231 231 '''
232 232
233 233 self.radarControllerHeaderObj = RadarControllerHeader()
234 234
235 235 self.systemHeaderObj = SystemHeader()
236 236
237 237 self.type = "Voltage"
238 238
239 239 self.data = None
240 240
241 241 self.dtype = None
242 242
243 243 # self.nChannels = 0
244 244
245 245 # self.nHeights = 0
246 246
247 247 self.nProfiles = None
248 248
249 249 self.heightList = None
250 250
251 251 self.channelList = None
252 252
253 253 # self.channelIndexList = None
254 254
255 255 self.flagNoData = True
256 256
257 257 self.flagTimeBlock = False
258 258
259 259 self.utctime = None
260 260
261 261 self.timeZone = None
262 262
263 263 self.dstFlag = None
264 264
265 265 self.errorCount = None
266 266
267 267 self.nCohInt = None
268 268
269 269 self.blocksize = None
270 270
271 271 self.flagDecodeData = False #asumo q la data no esta decodificada
272 272
273 273 self.flagDeflipData = False #asumo q la data no esta sin flip
274 274
275 275 self.flagShiftFFT = False
276 276
277 277
278 278 def getNoisebyHildebrand(self):
279 279 """
280 280 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
281 281
282 282 Return:
283 283 noiselevel
284 284 """
285 285
286 286 for channel in range(self.nChannels):
287 287 daux = self.data_spc[channel,:,:]
288 288 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
289 289
290 290 return self.noise
291 291
292 292 def getNoise(self, type = 1):
293 293
294 294 self.noise = numpy.zeros(self.nChannels)
295 295
296 296 if type == 1:
297 297 noise = self.getNoisebyHildebrand()
298 298
299 299 return 10*numpy.log10(noise)
300 300
301 301 class Spectra(JROData):
302 302
303 303 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
304 304 data_spc = None
305 305
306 306 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
307 307 data_cspc = None
308 308
309 309 #data es un numpy array de 2 dmensiones (canales, alturas)
310 310 data_dc = None
311 311
312 312 nFFTPoints = None
313 313
314 314 nPairs = None
315 315
316 316 pairsList = None
317 317
318 318 nIncohInt = None
319 319
320 320 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
321 321
322 322 nCohInt = None #se requiere para determinar el valor de timeInterval
323 323
324 324 ippFactor = None
325 325
326 326 def __init__(self):
327 327 '''
328 328 Constructor
329 329 '''
330 330
331 331 self.radarControllerHeaderObj = RadarControllerHeader()
332 332
333 333 self.systemHeaderObj = SystemHeader()
334 334
335 335 self.type = "Spectra"
336 336
337 337 # self.data = None
338 338
339 339 self.dtype = None
340 340
341 341 # self.nChannels = 0
342 342
343 343 # self.nHeights = 0
344 344
345 345 self.nProfiles = None
346 346
347 347 self.heightList = None
348 348
349 349 self.channelList = None
350 350
351 351 # self.channelIndexList = None
352 352
353 353 self.flagNoData = True
354 354
355 355 self.flagTimeBlock = False
356 356
357 357 self.utctime = None
358 358
359 359 self.nCohInt = None
360 360
361 361 self.nIncohInt = None
362 362
363 363 self.blocksize = None
364 364
365 365 self.nFFTPoints = None
366 366
367 367 self.wavelength = None
368 368
369 369 self.flagDecodeData = False #asumo q la data no esta decodificada
370 370
371 371 self.flagDeflipData = False #asumo q la data no esta sin flip
372 372
373 373 self.flagShiftFFT = False
374 374
375 375 self.ippFactor = 1
376 376
377 377 self.noise = None
378 378
379 379 self.beacon_heiIndexList = []
380 380
381 381
382 382 def getNoisebyHildebrand(self):
383 383 """
384 384 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
385 385
386 386 Return:
387 387 noiselevel
388 388 """
389 389 noise = numpy.zeros(self.nChannels)
390 390 for channel in range(self.nChannels):
391 391 daux = self.data_spc[channel,:,:]
392 392 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
393 393
394 394 return noise
395 395
396 396 def getNoise(self):
397 397 if self.noise != None:
398 398 return self.noise
399 399 else:
400 400 noise = self.getNoisebyHildebrand()
401 401 return noise
402 402
403 403
404 404 def getFreqRange(self, extrapoints=0):
405 405
406 406 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
407 407 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
408 408
409 409 return freqrange
410 410
411 411 def getVelRange(self, extrapoints=0):
412 412
413 413 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
414 414 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
415 415
416 416 return velrange
417 417
418 418 def getNPairs(self):
419 419
420 420 return len(self.pairsList)
421 421
422 422 def getPairsIndexList(self):
423 423
424 424 return range(self.nPairs)
425 425
426 426 def getNormFactor(self):
427 427 pwcode = 1
428 428 if self.flagDecodeData:
429 429 pwcode = numpy.sum(self.code[0]**2)
430 430 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
431 431 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
432 432
433 433 return normFactor
434 434
435 435 def getFlagCspc(self):
436 436
437 437 if self.data_cspc == None:
438 438 return True
439 439
440 440 return False
441 441
442 442 def getFlagDc(self):
443 443
444 444 if self.data_dc == None:
445 445 return True
446 446
447 447 return False
448 448
449 449 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
450 450 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
451 451 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
452 452 flag_cspc = property(getFlagCspc)
453 453 flag_dc = property(getFlagDc)
454 454
455 455 class SpectraHeis(JROData):
456 456
457 457 data_spc = None
458 458
459 459 data_cspc = None
460 460
461 461 data_dc = None
462 462
463 463 nFFTPoints = None
464 464
465 465 nPairs = None
466 466
467 467 pairsList = None
468 468
469 469 nIncohInt = None
470 470
471 471 def __init__(self):
472 472
473 473 self.radarControllerHeaderObj = RadarControllerHeader()
474 474
475 475 self.systemHeaderObj = SystemHeader()
476 476
477 477 self.type = "SpectraHeis"
478 478
479 479 self.dtype = None
480 480
481 481 # self.nChannels = 0
482 482
483 483 # self.nHeights = 0
484 484
485 485 self.nProfiles = None
486 486
487 487 self.heightList = None
488 488
489 489 self.channelList = None
490 490
491 491 # self.channelIndexList = None
492 492
493 493 self.flagNoData = True
494 494
495 495 self.flagTimeBlock = False
496 496
497 497 self.nPairs = 0
498 498
499 499 self.utctime = None
500 500
501 501 self.blocksize = None
502 502
503 503 class Fits:
504 504
505 505 heightList = None
506 506
507 507 channelList = None
508 508
509 509 flagNoData = True
510 510
511 511 flagTimeBlock = False
512 512
513 513 useLocalTime = False
514 514
515 515 utctime = None
516 516
517 517 timeZone = None
518 518
519 519 ippSeconds = None
520 520
521 521 timeInterval = None
522 522
523 523 nCohInt = None
524 524
525 525 nIncohInt = None
526 526
527 527 noise = None
528 528
529 529 windowOfFilter = 1
530 530
531 531 #Speed of ligth
532 532 C = 3e8
533 533
534 534 frequency = 49.92e6
535 535
536 536 realtime = False
537 537
538 538
539 539 def __init__(self):
540 540
541 541 self.type = "Fits"
542 542
543 543 self.nProfiles = None
544 544
545 545 self.heightList = None
546 546
547 547 self.channelList = None
548 548
549 549 # self.channelIndexList = None
550 550
551 551 self.flagNoData = True
552 552
553 553 self.utctime = None
554 554
555 555 self.nCohInt = None
556 556
557 557 self.nIncohInt = None
558 558
559 559 self.useLocalTime = True
560 560
561 561 # self.utctime = None
562 562 # self.timeZone = None
563 563 # self.ltctime = None
564 564 # self.timeInterval = None
565 565 # self.header = None
566 566 # self.data_header = None
567 567 # self.data = None
568 568 # self.datatime = None
569 569 # self.flagNoData = False
570 570 # self.expName = ''
571 571 # self.nChannels = None
572 572 # self.nSamples = None
573 573 # self.dataBlocksPerFile = None
574 574 # self.comments = ''
575 575 #
576 576
577 577
578 578 def getltctime(self):
579 579
580 580 if self.useLocalTime:
581 581 return self.utctime - self.timeZone*60
582 582
583 583 return self.utctime
584 584
585 585 def getDatatime(self):
586 586
587 587 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
588 588 return datatime
589 589
590 590 def getTimeRange(self):
591 591
592 592 datatime = []
593 593
594 594 datatime.append(self.ltctime)
595 595 datatime.append(self.ltctime + self.timeInterval)
596 596
597 597 datatime = numpy.array(datatime)
598 598
599 599 return datatime
600 600
601 601 def getHeiRange(self):
602 602
603 603 heis = self.heightList
604 604
605 605 return heis
606 606
607 607 def isEmpty(self):
608 608
609 609 return self.flagNoData
610 610
611 611 def getNHeights(self):
612 612
613 613 return len(self.heightList)
614 614
615 615 def getNChannels(self):
616 616
617 617 return len(self.channelList)
618 618
619 619 def getChannelIndexList(self):
620 620
621 621 return range(self.nChannels)
622 622
623 623 def getNoise(self, type = 1):
624 624
625 625 self.noise = numpy.zeros(self.nChannels)
626 626
627 627 if type == 1:
628 628 noise = self.getNoisebyHildebrand()
629 629
630 630 if type == 2:
631 631 noise = self.getNoisebySort()
632 632
633 633 if type == 3:
634 634 noise = self.getNoisebyWindow()
635 635
636 636 return noise
637 637
638 638 datatime = property(getDatatime, "I'm the 'datatime' property")
639 639 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
640 640 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
641 641 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
642 642 noise = property(getNoise, "I'm the 'nHeights' property.")
643 643 datatime = property(getDatatime, "I'm the 'datatime' property")
644 644 ltctime = property(getltctime, "I'm the 'ltctime' property")
645 645
646 646 ltctime = property(getltctime, "I'm the 'ltctime' property")
647 647
648 648 class AMISR:
649 649 def __init__(self):
650 650 self.flagNoData = True
651 651 self.data = None
652 652 self.utctime = None
653 653 self.type = "AMISR"
654 654
655 655 #propiedades para compatibilidad con Voltages
656 self.timeZone = 300#timezone like jroheader, difference in minutes between UTC and localtime
656 self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime
657 657 self.dstFlag = 0#self.dataIn.dstFlag
658 658 self.errorCount = 0#self.dataIn.errorCount
659 659 self.useLocalTime = True#self.dataIn.useLocalTime
660 660
661 661 self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy()
662 662 self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy()
663 663 self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR
664 664 self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
665 665
666 666 self.flagTimeBlock = None#self.dataIn.flagTimeBlock
667 667 #self.utctime = #self.firstdatatime
668 668 self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada
669 669 self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip
670 670
671 671 self.nCohInt = 1#self.dataIn.nCohInt
672 672 self.nIncohInt = 1
673 673 self.ippSeconds = 0.004#self.dataIn.ippSeconds, segun el filename/Setup/Tufile
674 674 self.windowOfFilter = None#self.dataIn.windowOfFilter
675 675
676 676 self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
677 677 self.frequency = 20000000#self.dataIn.frequency
678 678 self.realtime = 0#self.dataIn.realtime
679 679
680 680 #actualizar en la lectura de datos
681 681 self.heightList = None#self.dataIn.heightList
682 682 self.nProfiles = None#self.dataOut.nFFTPoints
683 683 self.nBaud = None#self.dataIn.nBaud
684 684 self.nCode = None#self.dataIn.nCode
685 685 self.code = None#self.dataIn.code
686 686
687 #consideracion para los Beams
688 self.beamCodeDict = None
689 self.beamRangeDict = None
690
691 def copy(self, inputObj=None):
692
693 if inputObj == None:
694 return copy.deepcopy(self)
695
696 for key in inputObj.__dict__.keys():
697 self.__dict__[key] = inputObj.__dict__[key]
698
687 699
688 700 def isEmpty(self):
689 701
690 702 return self.flagNoData No newline at end of file
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,2070 +1,2132
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 import math
11 11 from jrodata import *
12 12 from jrodataIO import *
13 13 from jroplot import *
14 14
15 15 try:
16 16 import cfunctions
17 17 except:
18 18 pass
19 19
20 20 class ProcessingUnit:
21 21
22 22 """
23 23 Esta es la clase base para el procesamiento de datos.
24 24
25 25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
26 26 - Metodos internos (callMethod)
27 27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
28 28 tienen que ser agreagados con el metodo "add".
29 29
30 30 """
31 31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
32 32 dataIn = None
33 33
34 34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
35 35 dataOut = None
36 36
37 37
38 38 objectDict = None
39 39
40 40 def __init__(self):
41 41
42 42 self.objectDict = {}
43 43
44 44 def init(self):
45 45
46 46 raise ValueError, "Not implemented"
47 47
48 48 def addOperation(self, object, objId):
49 49
50 50 """
51 51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
52 52 identificador asociado a este objeto.
53 53
54 54 Input:
55 55
56 56 object : objeto de la clase "Operation"
57 57
58 58 Return:
59 59
60 60 objId : identificador del objeto, necesario para ejecutar la operacion
61 61 """
62 62
63 63 self.objectDict[objId] = object
64 64
65 65 return objId
66 66
67 67 def operation(self, **kwargs):
68 68
69 69 """
70 70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 71 atributos del objeto dataOut
72 72
73 73 Input:
74 74
75 75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 76 """
77 77
78 78 raise ValueError, "ImplementedError"
79 79
80 80 def callMethod(self, name, **kwargs):
81 81
82 82 """
83 83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84 84
85 85 Input:
86 86 name : nombre del metodo a ejecutar
87 87
88 88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89 89
90 90 """
91 91 if name != 'run':
92 92
93 93 if name == 'init' and self.dataIn.isEmpty():
94 94 self.dataOut.flagNoData = True
95 95 return False
96 96
97 97 if name != 'init' and self.dataOut.isEmpty():
98 98 return False
99 99
100 100 methodToCall = getattr(self, name)
101 101
102 102 methodToCall(**kwargs)
103 103
104 104 if name != 'run':
105 105 return True
106 106
107 107 if self.dataOut.isEmpty():
108 108 return False
109 109
110 110 return True
111 111
112 112 def callObject(self, objId, **kwargs):
113 113
114 114 """
115 115 Ejecuta la operacion asociada al identificador del objeto "objId"
116 116
117 117 Input:
118 118
119 119 objId : identificador del objeto a ejecutar
120 120
121 121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
122 122
123 123 Return:
124 124
125 125 None
126 126 """
127 127
128 128 if self.dataOut.isEmpty():
129 129 return False
130 130
131 131 object = self.objectDict[objId]
132 132
133 133 object.run(self.dataOut, **kwargs)
134 134
135 135 return True
136 136
137 137 def call(self, operationConf, **kwargs):
138 138
139 139 """
140 140 Return True si ejecuta la operacion "operationConf.name" con los
141 141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
142 142 La operacion puede ser de dos tipos:
143 143
144 144 1. Un metodo propio de esta clase:
145 145
146 146 operation.type = "self"
147 147
148 148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
149 149 operation.type = "other".
150 150
151 151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
152 152 "addOperation" e identificado con el operation.id
153 153
154 154
155 155 con el id de la operacion.
156 156
157 157 Input:
158 158
159 159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
160 160
161 161 """
162 162
163 163 if operationConf.type == 'self':
164 164 sts = self.callMethod(operationConf.name, **kwargs)
165 165
166 166 if operationConf.type == 'other':
167 167 sts = self.callObject(operationConf.id, **kwargs)
168 168
169 169 return sts
170 170
171 171 def setInput(self, dataIn):
172 172
173 173 self.dataIn = dataIn
174 174
175 175 def getOutput(self):
176 176
177 177 return self.dataOut
178 178
179 179 class Operation():
180 180
181 181 """
182 182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
183 183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
184 184 acumulacion dentro de esta clase
185 185
186 186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
187 187
188 188 """
189 189
190 190 __buffer = None
191 191 __isConfig = False
192 192
193 193 def __init__(self):
194 194
195 195 pass
196 196
197 197 def run(self, dataIn, **kwargs):
198 198
199 199 """
200 200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
201 201
202 202 Input:
203 203
204 204 dataIn : objeto del tipo JROData
205 205
206 206 Return:
207 207
208 208 None
209 209
210 210 Affected:
211 211 __buffer : buffer de recepcion de datos.
212 212
213 213 """
214 214
215 215 raise ValueError, "ImplementedError"
216 216
217 217 class VoltageProc(ProcessingUnit):
218 218
219 219
220 220 def __init__(self):
221 221
222 222 self.objectDict = {}
223 223 self.dataOut = Voltage()
224 224 self.flip = 1
225 225
226 226 def __updateObjFromAmisrInput(self):
227 227
228 228 self.dataOut.timeZone = self.dataIn.timeZone
229 229 self.dataOut.dstFlag = self.dataIn.dstFlag
230 230 self.dataOut.errorCount = self.dataIn.errorCount
231 231 self.dataOut.useLocalTime = self.dataIn.useLocalTime
232 232
233 233 self.dataOut.flagNoData = self.dataIn.flagNoData
234 234 self.dataOut.data = self.dataIn.data
235 235 self.dataOut.utctime = self.dataIn.utctime
236 236 self.dataOut.channelList = self.dataIn.channelList
237 237 self.dataOut.timeInterval = self.dataIn.timeInterval
238 238 self.dataOut.heightList = self.dataIn.heightList
239 239 self.dataOut.nProfiles = self.dataIn.nProfiles
240 240
241 241 self.dataOut.nCohInt = self.dataIn.nCohInt
242 242 self.dataOut.ippSeconds = self.dataIn.ippSeconds
243 243 self.dataOut.frequency = self.dataIn.frequency
244 244
245 245 pass
246 246
247 247 def init(self):
248 248
249 249
250 250 if self.dataIn.type == 'AMISR':
251 251 self.__updateObjFromAmisrInput()
252 252
253 253 if self.dataIn.type == 'Voltage':
254 254 self.dataOut.copy(self.dataIn)
255 255 # No necesita copiar en cada init() los atributos de dataIn
256 256 # la copia deberia hacerse por cada nuevo bloque de datos
257 257
258 258 def selectChannels(self, channelList):
259 259
260 260 channelIndexList = []
261 261
262 262 for channel in channelList:
263 263 index = self.dataOut.channelList.index(channel)
264 264 channelIndexList.append(index)
265 265
266 266 self.selectChannelsByIndex(channelIndexList)
267 267
268 268 def selectChannelsByIndex(self, channelIndexList):
269 269 """
270 270 Selecciona un bloque de datos en base a canales segun el channelIndexList
271 271
272 272 Input:
273 273 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
274 274
275 275 Affected:
276 276 self.dataOut.data
277 277 self.dataOut.channelIndexList
278 278 self.dataOut.nChannels
279 279 self.dataOut.m_ProcessingHeader.totalSpectra
280 280 self.dataOut.systemHeaderObj.numChannels
281 281 self.dataOut.m_ProcessingHeader.blockSize
282 282
283 283 Return:
284 284 None
285 285 """
286 286
287 287 for channelIndex in channelIndexList:
288 288 if channelIndex not in self.dataOut.channelIndexList:
289 289 print channelIndexList
290 290 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
291 291
292 292 nChannels = len(channelIndexList)
293 293
294 294 data = self.dataOut.data[channelIndexList,:]
295 295
296 296 self.dataOut.data = data
297 297 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
298 298 # self.dataOut.nChannels = nChannels
299 299
300 300 return 1
301 301
302 302 def selectHeights(self, minHei=None, maxHei=None):
303 303 """
304 304 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
305 305 minHei <= height <= maxHei
306 306
307 307 Input:
308 308 minHei : valor minimo de altura a considerar
309 309 maxHei : valor maximo de altura a considerar
310 310
311 311 Affected:
312 312 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
313 313
314 314 Return:
315 315 1 si el metodo se ejecuto con exito caso contrario devuelve 0
316 316 """
317 317
318 318 if minHei == None:
319 319 minHei = self.dataOut.heightList[0]
320 320
321 321 if maxHei == None:
322 322 maxHei = self.dataOut.heightList[-1]
323 323
324 324 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
325 325 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
326 326
327 327
328 328 if (maxHei > self.dataOut.heightList[-1]):
329 329 maxHei = self.dataOut.heightList[-1]
330 330 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
331 331
332 332 minIndex = 0
333 333 maxIndex = 0
334 334 heights = self.dataOut.heightList
335 335
336 336 inda = numpy.where(heights >= minHei)
337 337 indb = numpy.where(heights <= maxHei)
338 338
339 339 try:
340 340 minIndex = inda[0][0]
341 341 except:
342 342 minIndex = 0
343 343
344 344 try:
345 345 maxIndex = indb[0][-1]
346 346 except:
347 347 maxIndex = len(heights)
348 348
349 349 self.selectHeightsByIndex(minIndex, maxIndex)
350 350
351 351 return 1
352 352
353 353
354 354 def selectHeightsByIndex(self, minIndex, maxIndex):
355 355 """
356 356 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
357 357 minIndex <= index <= maxIndex
358 358
359 359 Input:
360 360 minIndex : valor de indice minimo de altura a considerar
361 361 maxIndex : valor de indice maximo de altura a considerar
362 362
363 363 Affected:
364 364 self.dataOut.data
365 365 self.dataOut.heightList
366 366
367 367 Return:
368 368 1 si el metodo se ejecuto con exito caso contrario devuelve 0
369 369 """
370 370
371 371 if (minIndex < 0) or (minIndex > maxIndex):
372 372 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
373 373
374 374 if (maxIndex >= self.dataOut.nHeights):
375 375 maxIndex = self.dataOut.nHeights-1
376 376 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
377 377
378 378 nHeights = maxIndex - minIndex + 1
379 379
380 380 #voltage
381 381 data = self.dataOut.data[:,minIndex:maxIndex+1]
382 382
383 383 firstHeight = self.dataOut.heightList[minIndex]
384 384
385 385 self.dataOut.data = data
386 386 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
387 387
388 388 return 1
389 389
390 390
391 391 def filterByHeights(self, window):
392 392 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
393 393
394 394 if window == None:
395 395 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
396 396
397 397 newdelta = deltaHeight * window
398 398 r = self.dataOut.data.shape[1] % window
399 399 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
400 400 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
401 401 buffer = numpy.sum(buffer,2)
402 402 self.dataOut.data = buffer
403 403 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
404 404 self.dataOut.windowOfFilter = window
405 405
406 406 def deFlip(self):
407 407 self.dataOut.data *= self.flip
408 408 self.flip *= -1.
409 409
410 410 def setRadarFrequency(self, frequency=None):
411 411 if frequency != None:
412 412 self.dataOut.frequency = frequency
413 413
414 414 return 1
415 415
416 416 class CohInt(Operation):
417 417
418 418 __isConfig = False
419 419
420 420 __profIndex = 0
421 421 __withOverapping = False
422 422
423 423 __byTime = False
424 424 __initime = None
425 425 __lastdatatime = None
426 426 __integrationtime = None
427 427
428 428 __buffer = None
429 429
430 430 __dataReady = False
431 431
432 432 n = None
433 433
434 434
435 435 def __init__(self):
436 436
437 437 self.__isConfig = False
438 438
439 439 def setup(self, n=None, timeInterval=None, overlapping=False):
440 440 """
441 441 Set the parameters of the integration class.
442 442
443 443 Inputs:
444 444
445 445 n : Number of coherent integrations
446 446 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
447 447 overlapping :
448 448
449 449 """
450 450
451 451 self.__initime = None
452 452 self.__lastdatatime = 0
453 453 self.__buffer = None
454 454 self.__dataReady = False
455 455
456 456
457 457 if n == None and timeInterval == None:
458 458 raise ValueError, "n or timeInterval should be specified ..."
459 459
460 460 if n != None:
461 461 self.n = n
462 462 self.__byTime = False
463 463 else:
464 464 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
465 465 self.n = 9999
466 466 self.__byTime = True
467 467
468 468 if overlapping:
469 469 self.__withOverapping = True
470 470 self.__buffer = None
471 471 else:
472 472 self.__withOverapping = False
473 473 self.__buffer = 0
474 474
475 475 self.__profIndex = 0
476 476
477 477 def putData(self, data):
478 478
479 479 """
480 480 Add a profile to the __buffer and increase in one the __profileIndex
481 481
482 482 """
483 483
484 484 if not self.__withOverapping:
485 485 self.__buffer += data.copy()
486 486 self.__profIndex += 1
487 487 return
488 488
489 489 #Overlapping data
490 490 nChannels, nHeis = data.shape
491 491 data = numpy.reshape(data, (1, nChannels, nHeis))
492 492
493 493 #If the buffer is empty then it takes the data value
494 494 if self.__buffer == None:
495 495 self.__buffer = data
496 496 self.__profIndex += 1
497 497 return
498 498
499 499 #If the buffer length is lower than n then stakcing the data value
500 500 if self.__profIndex < self.n:
501 501 self.__buffer = numpy.vstack((self.__buffer, data))
502 502 self.__profIndex += 1
503 503 return
504 504
505 505 #If the buffer length is equal to n then replacing the last buffer value with the data value
506 506 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
507 507 self.__buffer[self.n-1] = data
508 508 self.__profIndex = self.n
509 509 return
510 510
511 511
512 512 def pushData(self):
513 513 """
514 514 Return the sum of the last profiles and the profiles used in the sum.
515 515
516 516 Affected:
517 517
518 518 self.__profileIndex
519 519
520 520 """
521 521
522 522 if not self.__withOverapping:
523 523 data = self.__buffer
524 524 n = self.__profIndex
525 525
526 526 self.__buffer = 0
527 527 self.__profIndex = 0
528 528
529 529 return data, n
530 530
531 531 #Integration with Overlapping
532 532 data = numpy.sum(self.__buffer, axis=0)
533 533 n = self.__profIndex
534 534
535 535 return data, n
536 536
537 537 def byProfiles(self, data):
538 538
539 539 self.__dataReady = False
540 540 avgdata = None
541 541 n = None
542 542
543 543 self.putData(data)
544 544
545 545 if self.__profIndex == self.n:
546 546
547 547 avgdata, n = self.pushData()
548 548 self.__dataReady = True
549 549
550 550 return avgdata
551 551
552 552 def byTime(self, data, datatime):
553 553
554 554 self.__dataReady = False
555 555 avgdata = None
556 556 n = None
557 557
558 558 self.putData(data)
559 559
560 560 if (datatime - self.__initime) >= self.__integrationtime:
561 561 avgdata, n = self.pushData()
562 562 self.n = n
563 563 self.__dataReady = True
564 564
565 565 return avgdata
566 566
567 567 def integrate(self, data, datatime=None):
568 568
569 569 if self.__initime == None:
570 570 self.__initime = datatime
571 571
572 572 if self.__byTime:
573 573 avgdata = self.byTime(data, datatime)
574 574 else:
575 575 avgdata = self.byProfiles(data)
576 576
577 577
578 578 self.__lastdatatime = datatime
579 579
580 580 if avgdata == None:
581 581 return None, None
582 582
583 583 avgdatatime = self.__initime
584 584
585 585 deltatime = datatime -self.__lastdatatime
586 586
587 587 if not self.__withOverapping:
588 588 self.__initime = datatime
589 589 else:
590 590 self.__initime += deltatime
591 591
592 592 return avgdata, avgdatatime
593 593
594 594 def run(self, dataOut, **kwargs):
595 595
596 596 if not self.__isConfig:
597 597 self.setup(**kwargs)
598 598 self.__isConfig = True
599 599
600 600 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
601 601
602 602 # dataOut.timeInterval *= n
603 603 dataOut.flagNoData = True
604 604
605 605 if self.__dataReady:
606 606 dataOut.data = avgdata
607 607 dataOut.nCohInt *= self.n
608 608 dataOut.utctime = avgdatatime
609 609 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
610 610 dataOut.flagNoData = False
611 611
612 612
613 613 class Decoder(Operation):
614 614
615 615 __isConfig = False
616 616 __profIndex = 0
617 617
618 618 code = None
619 619
620 620 nCode = None
621 621 nBaud = None
622 622
623 623 def __init__(self):
624 624
625 625 self.__isConfig = False
626 626
627 627 def setup(self, code, shape):
628 628
629 629 self.__profIndex = 0
630 630
631 631 self.code = code
632 632
633 633 self.nCode = len(code)
634 634 self.nBaud = len(code[0])
635 635
636 636 self.__nChannels, self.__nHeis = shape
637 637
638 638 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
639 639
640 640 __codeBuffer[:,0:self.nBaud] = self.code
641 641
642 642 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
643 643
644 644 self.ndatadec = self.__nHeis - self.nBaud + 1
645 645
646 646 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
647 647
648 648 def convolutionInFreq(self, data):
649 649
650 650 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
651 651
652 652 fft_data = numpy.fft.fft(data, axis=1)
653 653
654 654 conv = fft_data*fft_code
655 655
656 656 data = numpy.fft.ifft(conv,axis=1)
657 657
658 658 datadec = data[:,:-self.nBaud+1]
659 659
660 660 return datadec
661 661
662 662 def convolutionInFreqOpt(self, data):
663 663
664 664 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
665 665
666 666 data = cfunctions.decoder(fft_code, data)
667 667
668 668 datadec = data[:,:-self.nBaud+1]
669 669
670 670 return datadec
671 671
672 672 def convolutionInTime(self, data):
673 673
674 674 code = self.code[self.__profIndex]
675 675
676 676 for i in range(self.__nChannels):
677 677 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
678 678
679 679 return self.datadecTime
680 680
681 681 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
682 682
683 683 if code == None:
684 684 code = dataOut.code
685 685 else:
686 686 code = numpy.array(code).reshape(nCode,nBaud)
687 687 dataOut.code = code
688 688 dataOut.nCode = nCode
689 689 dataOut.nBaud = nBaud
690 690 dataOut.radarControllerHeaderObj.code = code
691 691 dataOut.radarControllerHeaderObj.nCode = nCode
692 692 dataOut.radarControllerHeaderObj.nBaud = nBaud
693 693
694 694
695 695 if not self.__isConfig:
696 696
697 697 self.setup(code, dataOut.data.shape)
698 698 self.__isConfig = True
699 699
700 700 if mode == 0:
701 701 datadec = self.convolutionInTime(dataOut.data)
702 702
703 703 if mode == 1:
704 704 datadec = self.convolutionInFreq(dataOut.data)
705 705
706 706 if mode == 2:
707 707 datadec = self.convolutionInFreqOpt(dataOut.data)
708 708
709 709 dataOut.data = datadec
710 710
711 711 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
712 712
713 713 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
714 714
715 715 if self.__profIndex == self.nCode-1:
716 716 self.__profIndex = 0
717 717 return 1
718 718
719 719 self.__profIndex += 1
720 720
721 721 return 1
722 722 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
723 723
724 724
725 725
726 726 class SpectraProc(ProcessingUnit):
727 727
728 728 def __init__(self):
729 729
730 730 self.objectDict = {}
731 731 self.buffer = None
732 732 self.firstdatatime = None
733 733 self.profIndex = 0
734 734 self.dataOut = Spectra()
735 735
736 736 def __updateObjFromInput(self):
737 737
738 738 self.dataOut.timeZone = self.dataIn.timeZone
739 739 self.dataOut.dstFlag = self.dataIn.dstFlag
740 740 self.dataOut.errorCount = self.dataIn.errorCount
741 741 self.dataOut.useLocalTime = self.dataIn.useLocalTime
742 742
743 743 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
744 744 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
745 745 self.dataOut.channelList = self.dataIn.channelList
746 746 self.dataOut.heightList = self.dataIn.heightList
747 747 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
748 748 # self.dataOut.nHeights = self.dataIn.nHeights
749 749 # self.dataOut.nChannels = self.dataIn.nChannels
750 750 self.dataOut.nBaud = self.dataIn.nBaud
751 751 self.dataOut.nCode = self.dataIn.nCode
752 752 self.dataOut.code = self.dataIn.code
753 753 self.dataOut.nProfiles = self.dataOut.nFFTPoints
754 754 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
755 755 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
756 756 self.dataOut.utctime = self.firstdatatime
757 757 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
758 758 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
759 759 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
760 760 self.dataOut.nCohInt = self.dataIn.nCohInt
761 761 self.dataOut.nIncohInt = 1
762 762 self.dataOut.ippSeconds = self.dataIn.ippSeconds
763 763 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
764 764
765 765 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
766 766 self.dataOut.frequency = self.dataIn.frequency
767 767 self.dataOut.realtime = self.dataIn.realtime
768 768
769 769 def __getFft(self):
770 770 """
771 771 Convierte valores de Voltaje a Spectra
772 772
773 773 Affected:
774 774 self.dataOut.data_spc
775 775 self.dataOut.data_cspc
776 776 self.dataOut.data_dc
777 777 self.dataOut.heightList
778 778 self.profIndex
779 779 self.buffer
780 780 self.dataOut.flagNoData
781 781 """
782 782 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
783 783 fft_volt = fft_volt.astype(numpy.dtype('complex'))
784 784 dc = fft_volt[:,0,:]
785 785
786 786 #calculo de self-spectra
787 787 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
788 788 spc = fft_volt * numpy.conjugate(fft_volt)
789 789 spc = spc.real
790 790
791 791 blocksize = 0
792 792 blocksize += dc.size
793 793 blocksize += spc.size
794 794
795 795 cspc = None
796 796 pairIndex = 0
797 797 if self.dataOut.pairsList != None:
798 798 #calculo de cross-spectra
799 799 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
800 800 for pair in self.dataOut.pairsList:
801 801 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
802 802 pairIndex += 1
803 803 blocksize += cspc.size
804 804
805 805 self.dataOut.data_spc = spc
806 806 self.dataOut.data_cspc = cspc
807 807 self.dataOut.data_dc = dc
808 808 self.dataOut.blockSize = blocksize
809 809 self.dataOut.flagShiftFFT = False
810 810
811 811 def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None):
812 812
813 813 self.dataOut.flagNoData = True
814 814
815 815 if self.dataIn.type == "Spectra":
816 816 self.dataOut.copy(self.dataIn)
817 817 return
818 818
819 819 if self.dataIn.type == "Voltage":
820 820
821 821 if nFFTPoints == None:
822 822 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
823 823
824 824 if pairsList == None:
825 825 nPairs = 0
826 826 else:
827 827 nPairs = len(pairsList)
828 828
829 829 if ippFactor == None:
830 830 ippFactor = 1
831 831 self.dataOut.ippFactor = ippFactor
832 832
833 833 self.dataOut.nFFTPoints = nFFTPoints
834 834 self.dataOut.pairsList = pairsList
835 835 self.dataOut.nPairs = nPairs
836 836
837 837 if self.buffer == None:
838 838 self.buffer = numpy.zeros((self.dataIn.nChannels,
839 839 nProfiles,
840 840 self.dataIn.nHeights),
841 841 dtype='complex')
842 842
843 843
844 844 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
845 845 self.profIndex += 1
846 846
847 847 if self.firstdatatime == None:
848 848 self.firstdatatime = self.dataIn.utctime
849 849
850 850 if self.profIndex == nProfiles:
851 851 self.__updateObjFromInput()
852 852 self.__getFft()
853 853
854 854 self.dataOut.flagNoData = False
855 855
856 856 self.buffer = None
857 857 self.firstdatatime = None
858 858 self.profIndex = 0
859 859
860 860 return
861 861
862 862 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
863 863
864 864 def selectChannels(self, channelList):
865 865
866 866 channelIndexList = []
867 867
868 868 for channel in channelList:
869 869 index = self.dataOut.channelList.index(channel)
870 870 channelIndexList.append(index)
871 871
872 872 self.selectChannelsByIndex(channelIndexList)
873 873
874 874 def selectChannelsByIndex(self, channelIndexList):
875 875 """
876 876 Selecciona un bloque de datos en base a canales segun el channelIndexList
877 877
878 878 Input:
879 879 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
880 880
881 881 Affected:
882 882 self.dataOut.data_spc
883 883 self.dataOut.channelIndexList
884 884 self.dataOut.nChannels
885 885
886 886 Return:
887 887 None
888 888 """
889 889
890 890 for channelIndex in channelIndexList:
891 891 if channelIndex not in self.dataOut.channelIndexList:
892 892 print channelIndexList
893 893 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
894 894
895 895 nChannels = len(channelIndexList)
896 896
897 897 data_spc = self.dataOut.data_spc[channelIndexList,:]
898 898
899 899 self.dataOut.data_spc = data_spc
900 900 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
901 901 # self.dataOut.nChannels = nChannels
902 902
903 903 return 1
904 904
905 905 def selectHeights(self, minHei, maxHei):
906 906 """
907 907 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
908 908 minHei <= height <= maxHei
909 909
910 910 Input:
911 911 minHei : valor minimo de altura a considerar
912 912 maxHei : valor maximo de altura a considerar
913 913
914 914 Affected:
915 915 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
916 916
917 917 Return:
918 918 1 si el metodo se ejecuto con exito caso contrario devuelve 0
919 919 """
920 920 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
921 921 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
922 922
923 923 if (maxHei > self.dataOut.heightList[-1]):
924 924 maxHei = self.dataOut.heightList[-1]
925 925 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
926 926
927 927 minIndex = 0
928 928 maxIndex = 0
929 929 heights = self.dataOut.heightList
930 930
931 931 inda = numpy.where(heights >= minHei)
932 932 indb = numpy.where(heights <= maxHei)
933 933
934 934 try:
935 935 minIndex = inda[0][0]
936 936 except:
937 937 minIndex = 0
938 938
939 939 try:
940 940 maxIndex = indb[0][-1]
941 941 except:
942 942 maxIndex = len(heights)
943 943
944 944 self.selectHeightsByIndex(minIndex, maxIndex)
945 945
946 946 return 1
947 947
948 948 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
949 949 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
950 950
951 951 if hei_ref != None:
952 952 newheis = numpy.where(self.dataOut.heightList>hei_ref)
953 953
954 954 minIndex = min(newheis[0])
955 955 maxIndex = max(newheis[0])
956 956 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
957 957 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
958 958
959 959 # determina indices
960 960 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
961 961 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
962 962 beacon_dB = numpy.sort(avg_dB)[-nheis:]
963 963 beacon_heiIndexList = []
964 964 for val in avg_dB.tolist():
965 965 if val >= beacon_dB[0]:
966 966 beacon_heiIndexList.append(avg_dB.tolist().index(val))
967 967
968 968 #data_spc = data_spc[:,:,beacon_heiIndexList]
969 969 data_cspc = None
970 970 if self.dataOut.data_cspc != None:
971 971 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
972 972 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
973 973
974 974 data_dc = None
975 975 if self.dataOut.data_dc != None:
976 976 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
977 977 #data_dc = data_dc[:,beacon_heiIndexList]
978 978
979 979 self.dataOut.data_spc = data_spc
980 980 self.dataOut.data_cspc = data_cspc
981 981 self.dataOut.data_dc = data_dc
982 982 self.dataOut.heightList = heightList
983 983 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
984 984
985 985 return 1
986 986
987 987
988 988 def selectHeightsByIndex(self, minIndex, maxIndex):
989 989 """
990 990 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
991 991 minIndex <= index <= maxIndex
992 992
993 993 Input:
994 994 minIndex : valor de indice minimo de altura a considerar
995 995 maxIndex : valor de indice maximo de altura a considerar
996 996
997 997 Affected:
998 998 self.dataOut.data_spc
999 999 self.dataOut.data_cspc
1000 1000 self.dataOut.data_dc
1001 1001 self.dataOut.heightList
1002 1002
1003 1003 Return:
1004 1004 1 si el metodo se ejecuto con exito caso contrario devuelve 0
1005 1005 """
1006 1006
1007 1007 if (minIndex < 0) or (minIndex > maxIndex):
1008 1008 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
1009 1009
1010 1010 if (maxIndex >= self.dataOut.nHeights):
1011 1011 maxIndex = self.dataOut.nHeights-1
1012 1012 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
1013 1013
1014 1014 nHeights = maxIndex - minIndex + 1
1015 1015
1016 1016 #Spectra
1017 1017 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
1018 1018
1019 1019 data_cspc = None
1020 1020 if self.dataOut.data_cspc != None:
1021 1021 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
1022 1022
1023 1023 data_dc = None
1024 1024 if self.dataOut.data_dc != None:
1025 1025 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
1026 1026
1027 1027 self.dataOut.data_spc = data_spc
1028 1028 self.dataOut.data_cspc = data_cspc
1029 1029 self.dataOut.data_dc = data_dc
1030 1030
1031 1031 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
1032 1032
1033 1033 return 1
1034 1034
1035 1035 def removeDC(self, mode = 2):
1036 1036 jspectra = self.dataOut.data_spc
1037 1037 jcspectra = self.dataOut.data_cspc
1038 1038
1039 1039
1040 1040 num_chan = jspectra.shape[0]
1041 1041 num_hei = jspectra.shape[2]
1042 1042
1043 1043 if jcspectra != None:
1044 1044 jcspectraExist = True
1045 1045 num_pairs = jcspectra.shape[0]
1046 1046 else: jcspectraExist = False
1047 1047
1048 1048 freq_dc = jspectra.shape[1]/2
1049 1049 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1050 1050
1051 1051 if ind_vel[0]<0:
1052 1052 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1053 1053
1054 1054 if mode == 1:
1055 1055 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1056 1056
1057 1057 if jcspectraExist:
1058 1058 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
1059 1059
1060 1060 if mode == 2:
1061 1061
1062 1062 vel = numpy.array([-2,-1,1,2])
1063 1063 xx = numpy.zeros([4,4])
1064 1064
1065 1065 for fil in range(4):
1066 1066 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1067 1067
1068 1068 xx_inv = numpy.linalg.inv(xx)
1069 1069 xx_aux = xx_inv[0,:]
1070 1070
1071 1071 for ich in range(num_chan):
1072 1072 yy = jspectra[ich,ind_vel,:]
1073 1073 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1074 1074
1075 1075 junkid = jspectra[ich,freq_dc,:]<=0
1076 1076 cjunkid = sum(junkid)
1077 1077
1078 1078 if cjunkid.any():
1079 1079 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1080 1080
1081 1081 if jcspectraExist:
1082 1082 for ip in range(num_pairs):
1083 1083 yy = jcspectra[ip,ind_vel,:]
1084 1084 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
1085 1085
1086 1086
1087 1087 self.dataOut.data_spc = jspectra
1088 1088 self.dataOut.data_cspc = jcspectra
1089 1089
1090 1090 return 1
1091 1091
1092 1092 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
1093 1093
1094 1094 jspectra = self.dataOut.data_spc
1095 1095 jcspectra = self.dataOut.data_cspc
1096 1096 jnoise = self.dataOut.getNoise()
1097 1097 num_incoh = self.dataOut.nIncohInt
1098 1098
1099 1099 num_channel = jspectra.shape[0]
1100 1100 num_prof = jspectra.shape[1]
1101 1101 num_hei = jspectra.shape[2]
1102 1102
1103 1103 #hei_interf
1104 1104 if hei_interf == None:
1105 1105 count_hei = num_hei/2 #Como es entero no importa
1106 1106 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
1107 1107 hei_interf = numpy.asarray(hei_interf)[0]
1108 1108 #nhei_interf
1109 1109 if (nhei_interf == None):
1110 1110 nhei_interf = 5
1111 1111 if (nhei_interf < 1):
1112 1112 nhei_interf = 1
1113 1113 if (nhei_interf > count_hei):
1114 1114 nhei_interf = count_hei
1115 1115 if (offhei_interf == None):
1116 1116 offhei_interf = 0
1117 1117
1118 1118 ind_hei = range(num_hei)
1119 1119 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
1120 1120 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
1121 1121 mask_prof = numpy.asarray(range(num_prof))
1122 1122 num_mask_prof = mask_prof.size
1123 1123 comp_mask_prof = [0, num_prof/2]
1124 1124
1125 1125
1126 1126 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
1127 1127 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
1128 1128 jnoise = numpy.nan
1129 1129 noise_exist = jnoise[0] < numpy.Inf
1130 1130
1131 1131 #Subrutina de Remocion de la Interferencia
1132 1132 for ich in range(num_channel):
1133 1133 #Se ordena los espectros segun su potencia (menor a mayor)
1134 1134 power = jspectra[ich,mask_prof,:]
1135 1135 power = power[:,hei_interf]
1136 1136 power = power.sum(axis = 0)
1137 1137 psort = power.ravel().argsort()
1138 1138
1139 1139 #Se estima la interferencia promedio en los Espectros de Potencia empleando
1140 1140 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1141 1141
1142 1142 if noise_exist:
1143 1143 # tmp_noise = jnoise[ich] / num_prof
1144 1144 tmp_noise = jnoise[ich]
1145 1145 junkspc_interf = junkspc_interf - tmp_noise
1146 1146 #junkspc_interf[:,comp_mask_prof] = 0
1147 1147
1148 1148 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
1149 1149 jspc_interf = jspc_interf.transpose()
1150 1150 #Calculando el espectro de interferencia promedio
1151 1151 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
1152 1152 noiseid = noiseid[0]
1153 1153 cnoiseid = noiseid.size
1154 1154 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
1155 1155 interfid = interfid[0]
1156 1156 cinterfid = interfid.size
1157 1157
1158 1158 if (cnoiseid > 0): jspc_interf[noiseid] = 0
1159 1159
1160 1160 #Expandiendo los perfiles a limpiar
1161 1161 if (cinterfid > 0):
1162 1162 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
1163 1163 new_interfid = numpy.asarray(new_interfid)
1164 1164 new_interfid = {x for x in new_interfid}
1165 1165 new_interfid = numpy.array(list(new_interfid))
1166 1166 new_cinterfid = new_interfid.size
1167 1167 else: new_cinterfid = 0
1168 1168
1169 1169 for ip in range(new_cinterfid):
1170 1170 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
1171 1171 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
1172 1172
1173 1173
1174 1174 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
1175 1175
1176 1176 #Removiendo la interferencia del punto de mayor interferencia
1177 1177 ListAux = jspc_interf[mask_prof].tolist()
1178 1178 maxid = ListAux.index(max(ListAux))
1179 1179
1180 1180
1181 1181 if cinterfid > 0:
1182 1182 for ip in range(cinterfid*(interf == 2) - 1):
1183 1183 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
1184 1184 cind = len(ind)
1185 1185
1186 1186 if (cind > 0):
1187 1187 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
1188 1188
1189 1189 ind = numpy.array([-2,-1,1,2])
1190 1190 xx = numpy.zeros([4,4])
1191 1191
1192 1192 for id1 in range(4):
1193 1193 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1194 1194
1195 1195 xx_inv = numpy.linalg.inv(xx)
1196 1196 xx = xx_inv[:,0]
1197 1197 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1198 1198 yy = jspectra[ich,mask_prof[ind],:]
1199 1199 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1200 1200
1201 1201
1202 1202 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
1203 1203 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
1204 1204
1205 1205 #Remocion de Interferencia en el Cross Spectra
1206 1206 if jcspectra == None: return jspectra, jcspectra
1207 1207 num_pairs = jcspectra.size/(num_prof*num_hei)
1208 1208 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
1209 1209
1210 1210 for ip in range(num_pairs):
1211 1211
1212 1212 #-------------------------------------------
1213 1213
1214 1214 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
1215 1215 cspower = cspower[:,hei_interf]
1216 1216 cspower = cspower.sum(axis = 0)
1217 1217
1218 1218 cspsort = cspower.ravel().argsort()
1219 1219 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1220 1220 junkcspc_interf = junkcspc_interf.transpose()
1221 1221 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
1222 1222
1223 1223 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
1224 1224
1225 1225 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1226 1226 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1227 1227 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
1228 1228
1229 1229 for iprof in range(num_prof):
1230 1230 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
1231 1231 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
1232 1232
1233 1233 #Removiendo la Interferencia
1234 1234 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
1235 1235
1236 1236 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
1237 1237 maxid = ListAux.index(max(ListAux))
1238 1238
1239 1239 ind = numpy.array([-2,-1,1,2])
1240 1240 xx = numpy.zeros([4,4])
1241 1241
1242 1242 for id1 in range(4):
1243 1243 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1244 1244
1245 1245 xx_inv = numpy.linalg.inv(xx)
1246 1246 xx = xx_inv[:,0]
1247 1247
1248 1248 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1249 1249 yy = jcspectra[ip,mask_prof[ind],:]
1250 1250 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1251 1251
1252 1252 #Guardar Resultados
1253 1253 self.dataOut.data_spc = jspectra
1254 1254 self.dataOut.data_cspc = jcspectra
1255 1255
1256 1256 return 1
1257 1257
1258 1258 def setRadarFrequency(self, frequency=None):
1259 1259 if frequency != None:
1260 1260 self.dataOut.frequency = frequency
1261 1261
1262 1262 return 1
1263 1263
1264 1264 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
1265 1265 #validacion de rango
1266 1266 if minHei == None:
1267 1267 minHei = self.dataOut.heightList[0]
1268 1268
1269 1269 if maxHei == None:
1270 1270 maxHei = self.dataOut.heightList[-1]
1271 1271
1272 1272 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
1273 1273 print 'minHei: %.2f is out of the heights range'%(minHei)
1274 1274 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
1275 1275 minHei = self.dataOut.heightList[0]
1276 1276
1277 1277 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
1278 1278 print 'maxHei: %.2f is out of the heights range'%(maxHei)
1279 1279 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
1280 1280 maxHei = self.dataOut.heightList[-1]
1281 1281
1282 1282 # validacion de velocidades
1283 1283 velrange = self.dataOut.getVelRange(1)
1284 1284
1285 1285 if minVel == None:
1286 1286 minVel = velrange[0]
1287 1287
1288 1288 if maxVel == None:
1289 1289 maxVel = velrange[-1]
1290 1290
1291 1291 if (minVel < velrange[0]) or (minVel > maxVel):
1292 1292 print 'minVel: %.2f is out of the velocity range'%(minVel)
1293 1293 print 'minVel is setting to %.2f'%(velrange[0])
1294 1294 minVel = velrange[0]
1295 1295
1296 1296 if (maxVel > velrange[-1]) or (maxVel < minVel):
1297 1297 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
1298 1298 print 'maxVel is setting to %.2f'%(velrange[-1])
1299 1299 maxVel = velrange[-1]
1300 1300
1301 1301 # seleccion de indices para rango
1302 1302 minIndex = 0
1303 1303 maxIndex = 0
1304 1304 heights = self.dataOut.heightList
1305 1305
1306 1306 inda = numpy.where(heights >= minHei)
1307 1307 indb = numpy.where(heights <= maxHei)
1308 1308
1309 1309 try:
1310 1310 minIndex = inda[0][0]
1311 1311 except:
1312 1312 minIndex = 0
1313 1313
1314 1314 try:
1315 1315 maxIndex = indb[0][-1]
1316 1316 except:
1317 1317 maxIndex = len(heights)
1318 1318
1319 1319 if (minIndex < 0) or (minIndex > maxIndex):
1320 1320 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
1321 1321
1322 1322 if (maxIndex >= self.dataOut.nHeights):
1323 1323 maxIndex = self.dataOut.nHeights-1
1324 1324
1325 1325 # seleccion de indices para velocidades
1326 1326 indminvel = numpy.where(velrange >= minVel)
1327 1327 indmaxvel = numpy.where(velrange <= maxVel)
1328 1328 try:
1329 1329 minIndexVel = indminvel[0][0]
1330 1330 except:
1331 1331 minIndexVel = 0
1332 1332
1333 1333 try:
1334 1334 maxIndexVel = indmaxvel[0][-1]
1335 1335 except:
1336 1336 maxIndexVel = len(velrange)
1337 1337
1338 1338 #seleccion del espectro
1339 1339 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
1340 1340 #estimacion de ruido
1341 1341 noise = numpy.zeros(self.dataOut.nChannels)
1342 1342
1343 1343 for channel in range(self.dataOut.nChannels):
1344 1344 daux = data_spc[channel,:,:]
1345 1345 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
1346 1346
1347 1347 self.dataOut.noise = noise.copy()
1348 1348
1349 1349 return 1
1350 1350
1351 1351
1352 1352 class IncohInt(Operation):
1353 1353
1354 1354
1355 1355 __profIndex = 0
1356 1356 __withOverapping = False
1357 1357
1358 1358 __byTime = False
1359 1359 __initime = None
1360 1360 __lastdatatime = None
1361 1361 __integrationtime = None
1362 1362
1363 1363 __buffer_spc = None
1364 1364 __buffer_cspc = None
1365 1365 __buffer_dc = None
1366 1366
1367 1367 __dataReady = False
1368 1368
1369 1369 __timeInterval = None
1370 1370
1371 1371 n = None
1372 1372
1373 1373
1374 1374
1375 1375 def __init__(self):
1376 1376
1377 1377 self.__isConfig = False
1378 1378
1379 1379 def setup(self, n=None, timeInterval=None, overlapping=False):
1380 1380 """
1381 1381 Set the parameters of the integration class.
1382 1382
1383 1383 Inputs:
1384 1384
1385 1385 n : Number of coherent integrations
1386 1386 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1387 1387 overlapping :
1388 1388
1389 1389 """
1390 1390
1391 1391 self.__initime = None
1392 1392 self.__lastdatatime = 0
1393 1393 self.__buffer_spc = None
1394 1394 self.__buffer_cspc = None
1395 1395 self.__buffer_dc = None
1396 1396 self.__dataReady = False
1397 1397
1398 1398
1399 1399 if n == None and timeInterval == None:
1400 1400 raise ValueError, "n or timeInterval should be specified ..."
1401 1401
1402 1402 if n != None:
1403 1403 self.n = n
1404 1404 self.__byTime = False
1405 1405 else:
1406 1406 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
1407 1407 self.n = 9999
1408 1408 self.__byTime = True
1409 1409
1410 1410 if overlapping:
1411 1411 self.__withOverapping = True
1412 1412 else:
1413 1413 self.__withOverapping = False
1414 1414 self.__buffer_spc = 0
1415 1415 self.__buffer_cspc = 0
1416 1416 self.__buffer_dc = 0
1417 1417
1418 1418 self.__profIndex = 0
1419 1419
1420 1420 def putData(self, data_spc, data_cspc, data_dc):
1421 1421
1422 1422 """
1423 1423 Add a profile to the __buffer_spc and increase in one the __profileIndex
1424 1424
1425 1425 """
1426 1426
1427 1427 if not self.__withOverapping:
1428 1428 self.__buffer_spc += data_spc
1429 1429
1430 1430 if data_cspc == None:
1431 1431 self.__buffer_cspc = None
1432 1432 else:
1433 1433 self.__buffer_cspc += data_cspc
1434 1434
1435 1435 if data_dc == None:
1436 1436 self.__buffer_dc = None
1437 1437 else:
1438 1438 self.__buffer_dc += data_dc
1439 1439
1440 1440 self.__profIndex += 1
1441 1441 return
1442 1442
1443 1443 #Overlapping data
1444 1444 nChannels, nFFTPoints, nHeis = data_spc.shape
1445 1445 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1446 1446 if data_cspc != None:
1447 1447 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1448 1448 if data_dc != None:
1449 1449 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1450 1450
1451 1451 #If the buffer is empty then it takes the data value
1452 1452 if self.__buffer_spc == None:
1453 1453 self.__buffer_spc = data_spc
1454 1454
1455 1455 if data_cspc == None:
1456 1456 self.__buffer_cspc = None
1457 1457 else:
1458 1458 self.__buffer_cspc += data_cspc
1459 1459
1460 1460 if data_dc == None:
1461 1461 self.__buffer_dc = None
1462 1462 else:
1463 1463 self.__buffer_dc += data_dc
1464 1464
1465 1465 self.__profIndex += 1
1466 1466 return
1467 1467
1468 1468 #If the buffer length is lower than n then stakcing the data value
1469 1469 if self.__profIndex < self.n:
1470 1470 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1471 1471
1472 1472 if data_cspc != None:
1473 1473 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1474 1474
1475 1475 if data_dc != None:
1476 1476 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1477 1477
1478 1478 self.__profIndex += 1
1479 1479 return
1480 1480
1481 1481 #If the buffer length is equal to n then replacing the last buffer value with the data value
1482 1482 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1483 1483 self.__buffer_spc[self.n-1] = data_spc
1484 1484
1485 1485 if data_cspc != None:
1486 1486 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1487 1487 self.__buffer_cspc[self.n-1] = data_cspc
1488 1488
1489 1489 if data_dc != None:
1490 1490 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1491 1491 self.__buffer_dc[self.n-1] = data_dc
1492 1492
1493 1493 self.__profIndex = self.n
1494 1494 return
1495 1495
1496 1496
1497 1497 def pushData(self):
1498 1498 """
1499 1499 Return the sum of the last profiles and the profiles used in the sum.
1500 1500
1501 1501 Affected:
1502 1502
1503 1503 self.__profileIndex
1504 1504
1505 1505 """
1506 1506 data_spc = None
1507 1507 data_cspc = None
1508 1508 data_dc = None
1509 1509
1510 1510 if not self.__withOverapping:
1511 1511 data_spc = self.__buffer_spc
1512 1512 data_cspc = self.__buffer_cspc
1513 1513 data_dc = self.__buffer_dc
1514 1514
1515 1515 n = self.__profIndex
1516 1516
1517 1517 self.__buffer_spc = 0
1518 1518 self.__buffer_cspc = 0
1519 1519 self.__buffer_dc = 0
1520 1520 self.__profIndex = 0
1521 1521
1522 1522 return data_spc, data_cspc, data_dc, n
1523 1523
1524 1524 #Integration with Overlapping
1525 1525 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1526 1526
1527 1527 if self.__buffer_cspc != None:
1528 1528 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1529 1529
1530 1530 if self.__buffer_dc != None:
1531 1531 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1532 1532
1533 1533 n = self.__profIndex
1534 1534
1535 1535 return data_spc, data_cspc, data_dc, n
1536 1536
1537 1537 def byProfiles(self, *args):
1538 1538
1539 1539 self.__dataReady = False
1540 1540 avgdata_spc = None
1541 1541 avgdata_cspc = None
1542 1542 avgdata_dc = None
1543 1543 n = None
1544 1544
1545 1545 self.putData(*args)
1546 1546
1547 1547 if self.__profIndex == self.n:
1548 1548
1549 1549 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1550 1550 self.__dataReady = True
1551 1551
1552 1552 return avgdata_spc, avgdata_cspc, avgdata_dc
1553 1553
1554 1554 def byTime(self, datatime, *args):
1555 1555
1556 1556 self.__dataReady = False
1557 1557 avgdata_spc = None
1558 1558 avgdata_cspc = None
1559 1559 avgdata_dc = None
1560 1560 n = None
1561 1561
1562 1562 self.putData(*args)
1563 1563
1564 1564 if (datatime - self.__initime) >= self.__integrationtime:
1565 1565 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1566 1566 self.n = n
1567 1567 self.__dataReady = True
1568 1568
1569 1569 return avgdata_spc, avgdata_cspc, avgdata_dc
1570 1570
1571 1571 def integrate(self, datatime, *args):
1572 1572
1573 1573 if self.__initime == None:
1574 1574 self.__initime = datatime
1575 1575
1576 1576 if self.__byTime:
1577 1577 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1578 1578 else:
1579 1579 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1580 1580
1581 1581 self.__lastdatatime = datatime
1582 1582
1583 1583 if avgdata_spc == None:
1584 1584 return None, None, None, None
1585 1585
1586 1586 avgdatatime = self.__initime
1587 1587 try:
1588 1588 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1589 1589 except:
1590 1590 self.__timeInterval = self.__lastdatatime - self.__initime
1591 1591
1592 1592 deltatime = datatime -self.__lastdatatime
1593 1593
1594 1594 if not self.__withOverapping:
1595 1595 self.__initime = datatime
1596 1596 else:
1597 1597 self.__initime += deltatime
1598 1598
1599 1599 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1600 1600
1601 1601 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1602 1602
1603 1603 if n==1:
1604 1604 dataOut.flagNoData = False
1605 1605 return
1606 1606
1607 1607 if not self.__isConfig:
1608 1608 self.setup(n, timeInterval, overlapping)
1609 1609 self.__isConfig = True
1610 1610
1611 1611 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1612 1612 dataOut.data_spc,
1613 1613 dataOut.data_cspc,
1614 1614 dataOut.data_dc)
1615 1615
1616 1616 # dataOut.timeInterval *= n
1617 1617 dataOut.flagNoData = True
1618 1618
1619 1619 if self.__dataReady:
1620 1620
1621 1621 dataOut.data_spc = avgdata_spc
1622 1622 dataOut.data_cspc = avgdata_cspc
1623 1623 dataOut.data_dc = avgdata_dc
1624 1624
1625 1625 dataOut.nIncohInt *= self.n
1626 1626 dataOut.utctime = avgdatatime
1627 1627 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1628 1628 dataOut.timeInterval = self.__timeInterval*self.n
1629 1629 dataOut.flagNoData = False
1630 1630
1631 1631 class ProfileConcat(Operation):
1632 1632
1633 1633 __isConfig = False
1634 1634 buffer = None
1635 1635
1636 1636 def __init__(self):
1637 1637
1638 1638 self.profileIndex = 0
1639 1639
1640 1640 def reset(self):
1641 1641 self.buffer = numpy.zeros_like(self.buffer)
1642 1642 self.start_index = 0
1643 1643 self.times = 1
1644 1644
1645 1645 def setup(self, data, m, n=1):
1646 1646 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
1647 1647 self.profiles = data.shape[1]
1648 1648 self.start_index = 0
1649 1649 self.times = 1
1650 1650
1651 1651 def concat(self, data):
1652 1652
1653 1653 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
1654 1654 self.start_index = self.start_index + self.profiles
1655 1655
1656 1656 def run(self, dataOut, m):
1657 1657
1658 1658 dataOut.flagNoData = True
1659 1659
1660 1660 if not self.__isConfig:
1661 1661 self.setup(dataOut.data, m, 1)
1662 1662 self.__isConfig = True
1663 1663
1664 1664 self.concat(dataOut.data)
1665 1665 self.times += 1
1666 1666 if self.times > m:
1667 1667 dataOut.data = self.buffer
1668 1668 self.reset()
1669 1669 dataOut.flagNoData = False
1670 1670 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
1671 1671 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1672 1672 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
1673 1673 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
1674 1674
1675 1675
1676 1676
1677 1677 class ProfileSelector(Operation):
1678 1678
1679 1679 profileIndex = None
1680 1680 # Tamanho total de los perfiles
1681 1681 nProfiles = None
1682 1682
1683 1683 def __init__(self):
1684 1684
1685 1685 self.profileIndex = 0
1686 1686
1687 1687 def incIndex(self):
1688 1688 self.profileIndex += 1
1689 1689
1690 1690 if self.profileIndex >= self.nProfiles:
1691 1691 self.profileIndex = 0
1692 1692
1693 1693 def isProfileInRange(self, minIndex, maxIndex):
1694 1694
1695 1695 if self.profileIndex < minIndex:
1696 1696 return False
1697 1697
1698 1698 if self.profileIndex > maxIndex:
1699 1699 return False
1700 1700
1701 1701 return True
1702 1702
1703 1703 def isProfileInList(self, profileList):
1704 1704
1705 1705 if self.profileIndex not in profileList:
1706 1706 return False
1707 1707
1708 1708 return True
1709 1709
1710 def run(self, dataOut, profileList=None, profileRangeList=None):
1710 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None):
1711 1711
1712 1712 dataOut.flagNoData = True
1713 1713 self.nProfiles = dataOut.nProfiles
1714 1714
1715 1715 if profileList != None:
1716 1716 if self.isProfileInList(profileList):
1717 1717 dataOut.flagNoData = False
1718 1718
1719 1719 self.incIndex()
1720 1720 return 1
1721 1721
1722 1722
1723 1723 elif profileRangeList != None:
1724 1724 minIndex = profileRangeList[0]
1725 1725 maxIndex = profileRangeList[1]
1726 1726 if self.isProfileInRange(minIndex, maxIndex):
1727 1727 dataOut.flagNoData = False
1728 1728
1729 1729 self.incIndex()
1730 1730 return 1
1731 elif beam != None:
1732 if self.isProfileInList(dataOut.beamRangeDict[beam]):
1733 dataOut.flagNoData = False
1734
1735 self.incIndex()
1736 return 1
1731 1737
1732 1738 else:
1733 1739 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1734 1740
1735 1741 return 0
1736 1742
1737 1743 class SpectraHeisProc(ProcessingUnit):
1738 1744 def __init__(self):
1739 1745 self.objectDict = {}
1740 1746 # self.buffer = None
1741 1747 # self.firstdatatime = None
1742 1748 # self.profIndex = 0
1743 1749 self.dataOut = SpectraHeis()
1744 1750
1745 1751 def __updateObjFromInput(self):
1746 1752 self.dataOut.timeZone = self.dataIn.timeZone
1747 1753 self.dataOut.dstFlag = self.dataIn.dstFlag
1748 1754 self.dataOut.errorCount = self.dataIn.errorCount
1749 1755 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1750 1756
1751 1757 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1752 1758 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1753 1759 self.dataOut.channelList = self.dataIn.channelList
1754 1760 self.dataOut.heightList = self.dataIn.heightList
1755 1761 # self.dataOut.dtype = self.dataIn.dtype
1756 1762 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1757 1763 # self.dataOut.nHeights = self.dataIn.nHeights
1758 1764 # self.dataOut.nChannels = self.dataIn.nChannels
1759 1765 self.dataOut.nBaud = self.dataIn.nBaud
1760 1766 self.dataOut.nCode = self.dataIn.nCode
1761 1767 self.dataOut.code = self.dataIn.code
1762 1768 # self.dataOut.nProfiles = 1
1763 1769 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1764 1770 self.dataOut.nFFTPoints = self.dataIn.nHeights
1765 1771 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1766 1772 # self.dataOut.flagNoData = self.dataIn.flagNoData
1767 1773 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1768 1774 self.dataOut.utctime = self.dataIn.utctime
1769 1775 # self.dataOut.utctime = self.firstdatatime
1770 1776 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1771 1777 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1772 1778 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1773 1779 self.dataOut.nCohInt = self.dataIn.nCohInt
1774 1780 self.dataOut.nIncohInt = 1
1775 1781 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1776 1782 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1777 1783
1778 1784 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1779 1785 # self.dataOut.set=self.dataIn.set
1780 1786 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1781 1787
1782 1788
1783 1789 def __updateObjFromFits(self):
1784 1790 self.dataOut.utctime = self.dataIn.utctime
1785 1791 self.dataOut.channelIndexList = self.dataIn.channelIndexList
1786 1792
1787 1793 self.dataOut.channelList = self.dataIn.channelList
1788 1794 self.dataOut.heightList = self.dataIn.heightList
1789 1795 self.dataOut.data_spc = self.dataIn.data
1790 1796 self.dataOut.timeInterval = self.dataIn.timeInterval
1791 1797 self.dataOut.timeZone = self.dataIn.timeZone
1792 1798 self.dataOut.useLocalTime = True
1793 1799 # self.dataOut.
1794 1800 # self.dataOut.
1795 1801
1796 1802 def __getFft(self):
1797 1803
1798 1804 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1799 1805 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1800 1806 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1801 1807 self.dataOut.data_spc = spc
1802 1808
1803 1809 def init(self):
1804 1810
1805 1811 self.dataOut.flagNoData = True
1806 1812
1807 1813 if self.dataIn.type == "Fits":
1808 1814 self.__updateObjFromFits()
1809 1815 self.dataOut.flagNoData = False
1810 1816 return
1811 1817
1812 1818 if self.dataIn.type == "SpectraHeis":
1813 1819 self.dataOut.copy(self.dataIn)
1814 1820 return
1815 1821
1816 1822 if self.dataIn.type == "Voltage":
1817 1823 self.__updateObjFromInput()
1818 1824 self.__getFft()
1819 1825 self.dataOut.flagNoData = False
1820 1826
1821 1827 return
1822 1828
1823 1829 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
1824 1830
1825 1831
1826 1832 def selectChannels(self, channelList):
1827 1833
1828 1834 channelIndexList = []
1829 1835
1830 1836 for channel in channelList:
1831 1837 index = self.dataOut.channelList.index(channel)
1832 1838 channelIndexList.append(index)
1833 1839
1834 1840 self.selectChannelsByIndex(channelIndexList)
1835 1841
1836 1842 def selectChannelsByIndex(self, channelIndexList):
1837 1843 """
1838 1844 Selecciona un bloque de datos en base a canales segun el channelIndexList
1839 1845
1840 1846 Input:
1841 1847 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1842 1848
1843 1849 Affected:
1844 1850 self.dataOut.data
1845 1851 self.dataOut.channelIndexList
1846 1852 self.dataOut.nChannels
1847 1853 self.dataOut.m_ProcessingHeader.totalSpectra
1848 1854 self.dataOut.systemHeaderObj.numChannels
1849 1855 self.dataOut.m_ProcessingHeader.blockSize
1850 1856
1851 1857 Return:
1852 1858 None
1853 1859 """
1854 1860
1855 1861 for channelIndex in channelIndexList:
1856 1862 if channelIndex not in self.dataOut.channelIndexList:
1857 1863 print channelIndexList
1858 1864 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1859 1865
1860 1866 nChannels = len(channelIndexList)
1861 1867
1862 1868 data_spc = self.dataOut.data_spc[channelIndexList,:]
1863 1869
1864 1870 self.dataOut.data_spc = data_spc
1865 1871 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1866 1872
1867 1873 return 1
1868 1874
1869 1875 class IncohInt4SpectraHeis(Operation):
1870 1876
1871 1877 __isConfig = False
1872 1878
1873 1879 __profIndex = 0
1874 1880 __withOverapping = False
1875 1881
1876 1882 __byTime = False
1877 1883 __initime = None
1878 1884 __lastdatatime = None
1879 1885 __integrationtime = None
1880 1886
1881 1887 __buffer = None
1882 1888
1883 1889 __dataReady = False
1884 1890
1885 1891 n = None
1886 1892
1887 1893
1888 1894 def __init__(self):
1889 1895
1890 1896 self.__isConfig = False
1891 1897
1892 1898 def setup(self, n=None, timeInterval=None, overlapping=False):
1893 1899 """
1894 1900 Set the parameters of the integration class.
1895 1901
1896 1902 Inputs:
1897 1903
1898 1904 n : Number of coherent integrations
1899 1905 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1900 1906 overlapping :
1901 1907
1902 1908 """
1903 1909
1904 1910 self.__initime = None
1905 1911 self.__lastdatatime = 0
1906 1912 self.__buffer = None
1907 1913 self.__dataReady = False
1908 1914
1909 1915
1910 1916 if n == None and timeInterval == None:
1911 1917 raise ValueError, "n or timeInterval should be specified ..."
1912 1918
1913 1919 if n != None:
1914 1920 self.n = n
1915 1921 self.__byTime = False
1916 1922 else:
1917 1923 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1918 1924 self.n = 9999
1919 1925 self.__byTime = True
1920 1926
1921 1927 if overlapping:
1922 1928 self.__withOverapping = True
1923 1929 self.__buffer = None
1924 1930 else:
1925 1931 self.__withOverapping = False
1926 1932 self.__buffer = 0
1927 1933
1928 1934 self.__profIndex = 0
1929 1935
1930 1936 def putData(self, data):
1931 1937
1932 1938 """
1933 1939 Add a profile to the __buffer and increase in one the __profileIndex
1934 1940
1935 1941 """
1936 1942
1937 1943 if not self.__withOverapping:
1938 1944 self.__buffer += data.copy()
1939 1945 self.__profIndex += 1
1940 1946 return
1941 1947
1942 1948 #Overlapping data
1943 1949 nChannels, nHeis = data.shape
1944 1950 data = numpy.reshape(data, (1, nChannels, nHeis))
1945 1951
1946 1952 #If the buffer is empty then it takes the data value
1947 1953 if self.__buffer == None:
1948 1954 self.__buffer = data
1949 1955 self.__profIndex += 1
1950 1956 return
1951 1957
1952 1958 #If the buffer length is lower than n then stakcing the data value
1953 1959 if self.__profIndex < self.n:
1954 1960 self.__buffer = numpy.vstack((self.__buffer, data))
1955 1961 self.__profIndex += 1
1956 1962 return
1957 1963
1958 1964 #If the buffer length is equal to n then replacing the last buffer value with the data value
1959 1965 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1960 1966 self.__buffer[self.n-1] = data
1961 1967 self.__profIndex = self.n
1962 1968 return
1963 1969
1964 1970
1965 1971 def pushData(self):
1966 1972 """
1967 1973 Return the sum of the last profiles and the profiles used in the sum.
1968 1974
1969 1975 Affected:
1970 1976
1971 1977 self.__profileIndex
1972 1978
1973 1979 """
1974 1980
1975 1981 if not self.__withOverapping:
1976 1982 data = self.__buffer
1977 1983 n = self.__profIndex
1978 1984
1979 1985 self.__buffer = 0
1980 1986 self.__profIndex = 0
1981 1987
1982 1988 return data, n
1983 1989
1984 1990 #Integration with Overlapping
1985 1991 data = numpy.sum(self.__buffer, axis=0)
1986 1992 n = self.__profIndex
1987 1993
1988 1994 return data, n
1989 1995
1990 1996 def byProfiles(self, data):
1991 1997
1992 1998 self.__dataReady = False
1993 1999 avgdata = None
1994 2000 n = None
1995 2001
1996 2002 self.putData(data)
1997 2003
1998 2004 if self.__profIndex == self.n:
1999 2005
2000 2006 avgdata, n = self.pushData()
2001 2007 self.__dataReady = True
2002 2008
2003 2009 return avgdata
2004 2010
2005 2011 def byTime(self, data, datatime):
2006 2012
2007 2013 self.__dataReady = False
2008 2014 avgdata = None
2009 2015 n = None
2010 2016
2011 2017 self.putData(data)
2012 2018
2013 2019 if (datatime - self.__initime) >= self.__integrationtime:
2014 2020 avgdata, n = self.pushData()
2015 2021 self.n = n
2016 2022 self.__dataReady = True
2017 2023
2018 2024 return avgdata
2019 2025
2020 2026 def integrate(self, data, datatime=None):
2021 2027
2022 2028 if self.__initime == None:
2023 2029 self.__initime = datatime
2024 2030
2025 2031 if self.__byTime:
2026 2032 avgdata = self.byTime(data, datatime)
2027 2033 else:
2028 2034 avgdata = self.byProfiles(data)
2029 2035
2030 2036
2031 2037 self.__lastdatatime = datatime
2032 2038
2033 2039 if avgdata == None:
2034 2040 return None, None
2035 2041
2036 2042 avgdatatime = self.__initime
2037 2043
2038 2044 deltatime = datatime -self.__lastdatatime
2039 2045
2040 2046 if not self.__withOverapping:
2041 2047 self.__initime = datatime
2042 2048 else:
2043 2049 self.__initime += deltatime
2044 2050
2045 2051 return avgdata, avgdatatime
2046 2052
2047 2053 def run(self, dataOut, **kwargs):
2048 2054
2049 2055 if not self.__isConfig:
2050 2056 self.setup(**kwargs)
2051 2057 self.__isConfig = True
2052 2058
2053 2059 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
2054 2060
2055 2061 # dataOut.timeInterval *= n
2056 2062 dataOut.flagNoData = True
2057 2063
2058 2064 if self.__dataReady:
2059 2065 dataOut.data_spc = avgdata
2060 2066 dataOut.nIncohInt *= self.n
2061 2067 # dataOut.nCohInt *= self.n
2062 2068 dataOut.utctime = avgdatatime
2063 2069 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
2064 2070 # dataOut.timeInterval = self.__timeInterval*self.n
2065 2071 dataOut.flagNoData = False
2066 2072
2067 2073
2068 2074
2069 2075
2076 class AMISRProc(ProcessingUnit):
2077 def __init__(self):
2078 self.objectDict = {}
2079 self.dataOut = AMISR()
2080
2081 def init(self):
2082 if self.dataIn.type == 'AMISR':
2083 self.dataOut.copy(self.dataIn)
2084
2085 class BeamSelector(Operation):
2086 profileIndex = None
2087 # Tamanho total de los perfiles
2088 nProfiles = None
2070 2089
2090 def __init__(self):
2091
2092 self.profileIndex = 0
2093
2094 def incIndex(self):
2095 self.profileIndex += 1
2096
2097 if self.profileIndex >= self.nProfiles:
2098 self.profileIndex = 0
2099
2100 def isProfileInRange(self, minIndex, maxIndex):
2101
2102 if self.profileIndex < minIndex:
2103 return False
2104
2105 if self.profileIndex > maxIndex:
2106 return False
2107
2108 return True
2109
2110 def isProfileInList(self, profileList):
2111
2112 if self.profileIndex not in profileList:
2113 return False
2114
2115 return True
2116
2117 def run(self, dataOut, beam=None):
2118
2119 dataOut.flagNoData = True
2120 self.nProfiles = dataOut.nProfiles
2121
2122 if beam != None:
2123 if self.isProfileInList(dataOut.beamRangeDict[beam]):
2124 dataOut.flagNoData = False
2125
2126 self.incIndex()
2127 return 1
2128
2129 else:
2130 raise ValueError, "BeamSelector needs beam value"
2131
2132 return 0 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now