##// END OF EJS Templates
Bug fixed in reshape
Alexander Valdez -
r564:85e26bcbef30
parent child
Show More
@@ -1,890 +1,890
1 1 import numpy
2 2
3 3 from jroproc_base import ProcessingUnit, Operation
4 4 from model.data.jrodata import Voltage
5 5
6 6
7 7 class VoltageProc(ProcessingUnit):
8 8
9 9
10 10 def __init__(self):
11 11
12 12 ProcessingUnit.__init__(self)
13 13
14 14 # self.objectDict = {}
15 15 self.dataOut = Voltage()
16 16 self.flip = 1
17 17
18 18 def run(self):
19 19 if self.dataIn.type == 'AMISR':
20 20 self.__updateObjFromAmisrInput()
21 21
22 22 if self.dataIn.type == 'Voltage':
23 23 self.dataOut.copy(self.dataIn)
24 24
25 25 # self.dataOut.copy(self.dataIn)
26 26
27 27 def __updateObjFromAmisrInput(self):
28 28
29 29 self.dataOut.timeZone = self.dataIn.timeZone
30 30 self.dataOut.dstFlag = self.dataIn.dstFlag
31 31 self.dataOut.errorCount = self.dataIn.errorCount
32 32 self.dataOut.useLocalTime = self.dataIn.useLocalTime
33 33
34 34 self.dataOut.flagNoData = self.dataIn.flagNoData
35 35 self.dataOut.data = self.dataIn.data
36 36 self.dataOut.utctime = self.dataIn.utctime
37 37 self.dataOut.channelList = self.dataIn.channelList
38 38 self.dataOut.timeInterval = self.dataIn.timeInterval
39 39 self.dataOut.heightList = self.dataIn.heightList
40 40 self.dataOut.nProfiles = self.dataIn.nProfiles
41 41
42 42 self.dataOut.nCohInt = self.dataIn.nCohInt
43 43 self.dataOut.ippSeconds = self.dataIn.ippSeconds
44 44 self.dataOut.frequency = self.dataIn.frequency
45 45
46 46 self.dataOut.azimuth = self.dataIn.azimuth
47 47 self.dataOut.zenith = self.dataIn.zenith
48 48
49 49 self.dataOut.beam.codeList = self.dataIn.beam.codeList
50 50 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
51 51 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
52 52 #
53 53 # pass#
54 54 #
55 55 # def init(self):
56 56 #
57 57 #
58 58 # if self.dataIn.type == 'AMISR':
59 59 # self.__updateObjFromAmisrInput()
60 60 #
61 61 # if self.dataIn.type == 'Voltage':
62 62 # self.dataOut.copy(self.dataIn)
63 63 # # No necesita copiar en cada init() los atributos de dataIn
64 64 # # la copia deberia hacerse por cada nuevo bloque de datos
65 65
66 66 def selectChannels(self, channelList):
67 67
68 68 channelIndexList = []
69 69
70 70 for channel in channelList:
71 71 index = self.dataOut.channelList.index(channel)
72 72 channelIndexList.append(index)
73 73
74 74 self.selectChannelsByIndex(channelIndexList)
75 75
76 76 def selectChannelsByIndex(self, channelIndexList):
77 77 """
78 78 Selecciona un bloque de datos en base a canales segun el channelIndexList
79 79
80 80 Input:
81 81 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
82 82
83 83 Affected:
84 84 self.dataOut.data
85 85 self.dataOut.channelIndexList
86 86 self.dataOut.nChannels
87 87 self.dataOut.m_ProcessingHeader.totalSpectra
88 88 self.dataOut.systemHeaderObj.numChannels
89 89 self.dataOut.m_ProcessingHeader.blockSize
90 90
91 91 Return:
92 92 None
93 93 """
94 94
95 95 for channelIndex in channelIndexList:
96 96 if channelIndex not in self.dataOut.channelIndexList:
97 97 print channelIndexList
98 98 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
99 99
100 100 # nChannels = len(channelIndexList)
101 101 if self.dataOut.flagDataAsBlock:
102 102 """
103 103 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
104 104 """
105 105 data = self.dataOut.data[channelIndexList,:,:]
106 106 else:
107 107 data = self.dataOut.data[channelIndexList,:]
108 108
109 109 self.dataOut.data = data
110 110 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
111 111 # self.dataOut.nChannels = nChannels
112 112
113 113 return 1
114 114
115 115 def selectHeights(self, minHei=None, maxHei=None):
116 116 """
117 117 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
118 118 minHei <= height <= maxHei
119 119
120 120 Input:
121 121 minHei : valor minimo de altura a considerar
122 122 maxHei : valor maximo de altura a considerar
123 123
124 124 Affected:
125 125 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
126 126
127 127 Return:
128 128 1 si el metodo se ejecuto con exito caso contrario devuelve 0
129 129 """
130 130
131 131 if minHei == None:
132 132 minHei = self.dataOut.heightList[0]
133 133
134 134 if maxHei == None:
135 135 maxHei = self.dataOut.heightList[-1]
136 136
137 137 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
138 138 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
139 139
140 140
141 141 if (maxHei > self.dataOut.heightList[-1]):
142 142 maxHei = self.dataOut.heightList[-1]
143 143 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
144 144
145 145 minIndex = 0
146 146 maxIndex = 0
147 147 heights = self.dataOut.heightList
148 148
149 149 inda = numpy.where(heights >= minHei)
150 150 indb = numpy.where(heights <= maxHei)
151 151
152 152 try:
153 153 minIndex = inda[0][0]
154 154 except:
155 155 minIndex = 0
156 156
157 157 try:
158 158 maxIndex = indb[0][-1]
159 159 except:
160 160 maxIndex = len(heights)
161 161
162 162 self.selectHeightsByIndex(minIndex, maxIndex)
163 163
164 164 return 1
165 165
166 166
167 167 def selectHeightsByIndex(self, minIndex, maxIndex):
168 168 """
169 169 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
170 170 minIndex <= index <= maxIndex
171 171
172 172 Input:
173 173 minIndex : valor de indice minimo de altura a considerar
174 174 maxIndex : valor de indice maximo de altura a considerar
175 175
176 176 Affected:
177 177 self.dataOut.data
178 178 self.dataOut.heightList
179 179
180 180 Return:
181 181 1 si el metodo se ejecuto con exito caso contrario devuelve 0
182 182 """
183 183
184 184 if (minIndex < 0) or (minIndex > maxIndex):
185 185 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
186 186
187 187 if (maxIndex >= self.dataOut.nHeights):
188 188 maxIndex = self.dataOut.nHeights
189 189 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
190 190
191 191 # nHeights = maxIndex - minIndex + 1
192 192
193 193 #voltage
194 194 if self.dataOut.flagDataAsBlock:
195 195 """
196 196 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
197 197 """
198 198 data = self.dataOut.data[:,minIndex:maxIndex,:]
199 199 else:
200 200 data = self.dataOut.data[:,minIndex:maxIndex]
201 201
202 202 # firstHeight = self.dataOut.heightList[minIndex]
203 203
204 204 self.dataOut.data = data
205 205 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
206 206
207 207 return 1
208 208
209 209
210 def filterByHeights(self, window, axis=1):
210 def filterByHeights(self, window, axis=2):
211 211
212 212 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
213 213
214 214 if window == None:
215 215 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
216 216
217 217 newdelta = deltaHeight * window
218 218 r = self.dataOut.nHeights % window
219 219
220 220 if self.dataOut.flagDataAsBlock:
221 221 """
222 222 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
223 223 """
224 224 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
225 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights,self.dataOut.nHeights/window,window)
225 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
226 226 buffer = numpy.sum(buffer,3)
227 227
228 228 else:
229 229 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
230 230 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
231 231 buffer = numpy.sum(buffer,2)
232 232
233 233 self.dataOut.data = buffer.copy()
234 234 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
235 235 self.dataOut.windowOfFilter = window
236 236
237 237 return 1
238 238
239 239 def deFlip(self, channelList = []):
240 240
241 241 data = self.dataOut.data.copy()
242 242
243 243 if self.dataOut.flagDataAsBlock:
244 244 flip = self.flip
245 245 profileList = range(self.dataOut.nProfiles)
246 246
247 247 if channelList == []:
248 248 for thisProfile in profileList:
249 249 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
250 250 flip *= -1.0
251 251 else:
252 252 for thisChannel in channelList:
253 253 for thisProfile in profileList:
254 254 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
255 255 flip *= -1.0
256 256
257 257 self.flip = flip
258 258
259 259 else:
260 260 if channelList == []:
261 261 data[:,:] = data[:,:]*self.flip
262 262 else:
263 263 for thisChannel in channelList:
264 264 data[thisChannel,:] = data[thisChannel,:]*self.flip
265 265
266 266 self.flip *= -1.
267 267
268 268 self.dataOut.data = data
269 269
270 270
271 271
272 272 def setRadarFrequency(self, frequency=None):
273 273
274 274 if frequency != None:
275 275 self.dataOut.frequency = frequency
276 276
277 277 return 1
278 278
279 279 class CohInt(Operation):
280 280
281 281 isConfig = False
282 282
283 283 __profIndex = 0
284 284 __withOverapping = False
285 285
286 286 __byTime = False
287 287 __initime = None
288 288 __lastdatatime = None
289 289 __integrationtime = None
290 290
291 291 __buffer = None
292 292
293 293 __dataReady = False
294 294
295 295 n = None
296 296
297 297
298 298 def __init__(self):
299 299
300 300 Operation.__init__(self)
301 301
302 302 # self.isConfig = False
303 303
304 304 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
305 305 """
306 306 Set the parameters of the integration class.
307 307
308 308 Inputs:
309 309
310 310 n : Number of coherent integrations
311 311 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
312 312 overlapping :
313 313
314 314 """
315 315
316 316 self.__initime = None
317 317 self.__lastdatatime = 0
318 318 self.__buffer = None
319 319 self.__dataReady = False
320 320 self.byblock = byblock
321 321
322 322 if n == None and timeInterval == None:
323 323 raise ValueError, "n or timeInterval should be specified ..."
324 324
325 325 if n != None:
326 326 self.n = n
327 327 self.__byTime = False
328 328 else:
329 329 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
330 330 self.n = 9999
331 331 self.__byTime = True
332 332
333 333 if overlapping:
334 334 self.__withOverapping = True
335 335 self.__buffer = None
336 336 else:
337 337 self.__withOverapping = False
338 338 self.__buffer = 0
339 339
340 340 self.__profIndex = 0
341 341
342 342 def putData(self, data):
343 343
344 344 """
345 345 Add a profile to the __buffer and increase in one the __profileIndex
346 346
347 347 """
348 348
349 349 if not self.__withOverapping:
350 350 self.__buffer += data.copy()
351 351 self.__profIndex += 1
352 352 return
353 353
354 354 #Overlapping data
355 355 nChannels, nHeis = data.shape
356 356 data = numpy.reshape(data, (1, nChannels, nHeis))
357 357
358 358 #If the buffer is empty then it takes the data value
359 359 if self.__buffer == None:
360 360 self.__buffer = data
361 361 self.__profIndex += 1
362 362 return
363 363
364 364 #If the buffer length is lower than n then stakcing the data value
365 365 if self.__profIndex < self.n:
366 366 self.__buffer = numpy.vstack((self.__buffer, data))
367 367 self.__profIndex += 1
368 368 return
369 369
370 370 #If the buffer length is equal to n then replacing the last buffer value with the data value
371 371 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
372 372 self.__buffer[self.n-1] = data
373 373 self.__profIndex = self.n
374 374 return
375 375
376 376
377 377 def pushData(self):
378 378 """
379 379 Return the sum of the last profiles and the profiles used in the sum.
380 380
381 381 Affected:
382 382
383 383 self.__profileIndex
384 384
385 385 """
386 386
387 387 if not self.__withOverapping:
388 388 data = self.__buffer
389 389 n = self.__profIndex
390 390
391 391 self.__buffer = 0
392 392 self.__profIndex = 0
393 393
394 394 return data, n
395 395
396 396 #Integration with Overlapping
397 397 data = numpy.sum(self.__buffer, axis=0)
398 398 n = self.__profIndex
399 399
400 400 return data, n
401 401
402 402 def byProfiles(self, data):
403 403
404 404 self.__dataReady = False
405 405 avgdata = None
406 406 # n = None
407 407
408 408 self.putData(data)
409 409
410 410 if self.__profIndex == self.n:
411 411
412 412 avgdata, n = self.pushData()
413 413 self.__dataReady = True
414 414
415 415 return avgdata
416 416
417 417 def byTime(self, data, datatime):
418 418
419 419 self.__dataReady = False
420 420 avgdata = None
421 421 n = None
422 422
423 423 self.putData(data)
424 424
425 425 if (datatime - self.__initime) >= self.__integrationtime:
426 426 avgdata, n = self.pushData()
427 427 self.n = n
428 428 self.__dataReady = True
429 429
430 430 return avgdata
431 431
432 432 def integrate(self, data, datatime=None):
433 433
434 434 if self.__initime == None:
435 435 self.__initime = datatime
436 436
437 437 if self.__byTime:
438 438 avgdata = self.byTime(data, datatime)
439 439 else:
440 440 avgdata = self.byProfiles(data)
441 441
442 442
443 443 self.__lastdatatime = datatime
444 444
445 445 if avgdata == None:
446 446 return None, None
447 447
448 448 avgdatatime = self.__initime
449 449
450 450 deltatime = datatime -self.__lastdatatime
451 451
452 452 if not self.__withOverapping:
453 453 self.__initime = datatime
454 454 else:
455 455 self.__initime += deltatime
456 456
457 457 return avgdata, avgdatatime
458 458
459 459 def integrateByBlock(self, dataOut):
460 460
461 461 times = int(dataOut.data.shape[1]/self.n)
462 462 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
463 463
464 464 id_min = 0
465 465 id_max = self.n
466 466
467 467 for i in range(times):
468 468 junk = dataOut.data[:,id_min:id_max,:]
469 469 avgdata[:,i,:] = junk.sum(axis=1)
470 470 id_min += self.n
471 471 id_max += self.n
472 472
473 473 timeInterval = dataOut.ippSeconds*self.n
474 474 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
475 475 self.__dataReady = True
476 476 return avgdata, avgdatatime
477 477
478 478 def run(self, dataOut, **kwargs):
479 479
480 480 if not self.isConfig:
481 481 self.setup(**kwargs)
482 482 self.isConfig = True
483 483
484 484 if dataOut.flagDataAsBlock:
485 485 """
486 486 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
487 487 """
488 488 avgdata, avgdatatime = self.integrateByBlock(dataOut)
489 489 else:
490 490 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
491 491
492 492 # dataOut.timeInterval *= n
493 493 dataOut.flagNoData = True
494 494
495 495 if self.__dataReady:
496 496 dataOut.data = avgdata
497 497 dataOut.nCohInt *= self.n
498 498 dataOut.utctime = avgdatatime
499 499 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
500 500 dataOut.flagNoData = False
501 501
502 502 class Decoder(Operation):
503 503
504 504 isConfig = False
505 505 __profIndex = 0
506 506
507 507 code = None
508 508
509 509 nCode = None
510 510 nBaud = None
511 511
512 512
513 513 def __init__(self):
514 514
515 515 Operation.__init__(self)
516 516
517 517 self.times = None
518 518 self.osamp = None
519 519 # self.__setValues = False
520 520 self.isConfig = False
521 521
522 522 def setup(self, code, osamp, dataOut):
523 523
524 524 self.__profIndex = 0
525 525
526 526 self.code = code
527 527
528 528 self.nCode = len(code)
529 529 self.nBaud = len(code[0])
530 530
531 531 if (osamp != None) and (osamp >1):
532 532 self.osamp = osamp
533 533 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
534 534 self.nBaud = self.nBaud*self.osamp
535 535
536 536 self.__nChannels = dataOut.nChannels
537 537 self.__nProfiles = dataOut.nProfiles
538 538 self.__nHeis = dataOut.nHeights
539 539
540 540 if dataOut.flagDataAsBlock:
541 541
542 542 self.ndatadec = self.__nHeis #- self.nBaud + 1
543 543
544 544 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
545 545
546 546 else:
547 547
548 548 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
549 549
550 550 __codeBuffer[:,0:self.nBaud] = self.code
551 551
552 552 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
553 553
554 554 self.ndatadec = self.__nHeis #- self.nBaud + 1
555 555
556 556 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
557 557
558 558 def convolutionInFreq(self, data):
559 559
560 560 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
561 561
562 562 fft_data = numpy.fft.fft(data, axis=1)
563 563
564 564 conv = fft_data*fft_code
565 565
566 566 data = numpy.fft.ifft(conv,axis=1)
567 567
568 568 datadec = data#[:,:]
569 569
570 570 return datadec
571 571
572 572 def convolutionInFreqOpt(self, data):
573 573
574 574 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
575 575
576 576 data = cfunctions.decoder(fft_code, data)
577 577
578 578 datadec = data#[:,:]
579 579
580 580 return datadec
581 581
582 582 def convolutionInTime(self, data):
583 583
584 584 code = self.code[self.__profIndex]
585 585
586 586 for i in range(self.__nChannels):
587 587 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='same')
588 588
589 589 return self.datadecTime
590 590
591 591 def convolutionByBlockInTime(self, data):
592 592
593 593 repetitions = self.__nProfiles / self.nCode
594 594
595 595 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
596 596 junk = junk.flatten()
597 597 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
598 598
599 599 for i in range(self.__nChannels):
600 600 for j in range(self.__nProfiles):
601 601 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='same')
602 602
603 603 return self.datadecTime
604 604
605 605 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None):
606 606
607 607 if not self.isConfig:
608 608
609 609 if code == None:
610 610 code = dataOut.code
611 611 else:
612 612 code = numpy.array(code).reshape(nCode,nBaud)
613 613
614 614 self.setup(code, osamp, dataOut)
615 615
616 616 self.isConfig = True
617 617
618 618 if dataOut.flagDataAsBlock:
619 619 """
620 620 Decoding when data have been read as block,
621 621 """
622 622 datadec = self.convolutionByBlockInTime(dataOut.data)
623 623
624 624 else:
625 625 """
626 626 Decoding when data have been read profile by profile
627 627 """
628 628 if mode == 0:
629 629 datadec = self.convolutionInTime(dataOut.data)
630 630
631 631 if mode == 1:
632 632 datadec = self.convolutionInFreq(dataOut.data)
633 633
634 634 if mode == 2:
635 635 datadec = self.convolutionInFreqOpt(dataOut.data)
636 636
637 637 dataOut.code = self.code
638 638 dataOut.nCode = self.nCode
639 639 dataOut.nBaud = self.nBaud
640 640 dataOut.radarControllerHeaderObj.code = self.code
641 641 dataOut.radarControllerHeaderObj.nCode = self.nCode
642 642 dataOut.radarControllerHeaderObj.nBaud = self.nBaud
643 643
644 644 dataOut.data = datadec
645 645
646 646 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
647 647
648 648 dataOut.flagDecodeData = True #asumo q la data esta decodificada
649 649
650 650 if self.__profIndex == self.nCode-1:
651 651 self.__profIndex = 0
652 652 return 1
653 653
654 654 self.__profIndex += 1
655 655
656 656 return 1
657 657 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
658 658
659 659
660 660 class ProfileConcat(Operation):
661 661
662 662 isConfig = False
663 663 buffer = None
664 664
665 665 def __init__(self):
666 666
667 667 Operation.__init__(self)
668 668 self.profileIndex = 0
669 669
670 670 def reset(self):
671 671 self.buffer = numpy.zeros_like(self.buffer)
672 672 self.start_index = 0
673 673 self.times = 1
674 674
675 675 def setup(self, data, m, n=1):
676 676 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
677 677 self.nHeights = data.nHeights
678 678 self.start_index = 0
679 679 self.times = 1
680 680
681 681 def concat(self, data):
682 682
683 683 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
684 684 self.start_index = self.start_index + self.nHeights
685 685
686 686 def run(self, dataOut, m):
687 687
688 688 dataOut.flagNoData = True
689 689
690 690 if not self.isConfig:
691 691 self.setup(dataOut.data, m, 1)
692 692 self.isConfig = True
693 693
694 694 if dataOut.flagDataAsBlock:
695 695
696 696 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
697 697
698 698 else:
699 699 self.concat(dataOut.data)
700 700 self.times += 1
701 701 if self.times > m:
702 702 dataOut.data = self.buffer
703 703 self.reset()
704 704 dataOut.flagNoData = False
705 705 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
706 706 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
707 707 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
708 708 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
709 709 dataOut.ippSeconds *= m
710 710
711 711 class ProfileSelector(Operation):
712 712
713 713 profileIndex = None
714 714 # Tamanho total de los perfiles
715 715 nProfiles = None
716 716
717 717 def __init__(self):
718 718
719 719 Operation.__init__(self)
720 720 self.profileIndex = 0
721 721
722 722 def incIndex(self):
723 723
724 724 self.profileIndex += 1
725 725
726 726 if self.profileIndex >= self.nProfiles:
727 727 self.profileIndex = 0
728 728
729 729 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
730 730
731 731 if profileIndex < minIndex:
732 732 return False
733 733
734 734 if profileIndex > maxIndex:
735 735 return False
736 736
737 737 return True
738 738
739 739 def isThisProfileInList(self, profileIndex, profileList):
740 740
741 741 if profileIndex not in profileList:
742 742 return False
743 743
744 744 return True
745 745
746 746 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None):
747 747
748 748 """
749 749 ProfileSelector:
750 750
751 751 Inputs:
752 752 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
753 753
754 754 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
755 755
756 756 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
757 757
758 758 """
759 759
760 760 dataOut.flagNoData = True
761 761 self.nProfiles = dataOut.nProfiles
762 762
763 763 if dataOut.flagDataAsBlock:
764 764 """
765 765 data dimension = [nChannels, nProfiles, nHeis]
766 766 """
767 767 if profileList != None:
768 768 dataOut.data = dataOut.data[:,profileList,:]
769 769 dataOut.nProfiles = len(profileList)
770 770 dataOut.profileIndex = dataOut.nProfiles - 1
771 771 else:
772 772 minIndex = profileRangeList[0]
773 773 maxIndex = profileRangeList[1]
774 774
775 775 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
776 776 dataOut.nProfiles = maxIndex - minIndex + 1
777 777 dataOut.profileIndex = dataOut.nProfiles - 1
778 778
779 779 dataOut.flagNoData = False
780 780
781 781 return True
782 782
783 783 else:
784 784 """
785 785 data dimension = [nChannels, nHeis]
786 786
787 787 """
788 788 if profileList != None:
789 789
790 790 dataOut.nProfiles = len(profileList)
791 791
792 792 if self.isThisProfileInList(dataOut.profileIndex, profileList):
793 793 dataOut.flagNoData = False
794 794 dataOut.profileIndex = self.profileIndex
795 795
796 796 self.incIndex()
797 797 return True
798 798
799 799
800 800 if profileRangeList != None:
801 801
802 802 minIndex = profileRangeList[0]
803 803 maxIndex = profileRangeList[1]
804 804
805 805 dataOut.nProfiles = maxIndex - minIndex + 1
806 806
807 807 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
808 808 dataOut.flagNoData = False
809 809 dataOut.profileIndex = self.profileIndex
810 810
811 811 self.incIndex()
812 812 return True
813 813
814 814 if rangeList != None:
815 815
816 816 nProfiles = 0
817 817
818 818 for thisRange in rangeList:
819 819 minIndex = thisRange[0]
820 820 maxIndex = thisRange[1]
821 821
822 822 nProfiles += maxIndex - minIndex + 1
823 823
824 824 dataOut.nProfiles = nProfiles
825 825
826 826 for thisRange in rangeList:
827 827
828 828 minIndex = thisRange[0]
829 829 maxIndex = thisRange[1]
830 830
831 831 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
832 832
833 833 # print "profileIndex = ", dataOut.profileIndex
834 834
835 835 dataOut.flagNoData = False
836 836 dataOut.profileIndex = self.profileIndex
837 837
838 838 self.incIndex()
839 839 break
840 840 return True
841 841
842 842
843 843 if beam != None: #beam is only for AMISR data
844 844 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
845 845 dataOut.flagNoData = False
846 846 dataOut.profileIndex = self.profileIndex
847 847
848 848 self.incIndex()
849 849 return 1
850 850
851 851 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
852 852
853 853 return 0
854 854
855 855
856 856
857 857 class Reshaper(Operation):
858 858
859 859 def __init__(self):
860 860
861 861 Operation.__init__(self)
862 862 self.updateNewHeights = True
863 863
864 864 def run(self, dataOut, shape):
865 865
866 866 if not dataOut.flagDataAsBlock:
867 867 raise ValueError, "Reshaper can only be used when voltage have been read as Block, getBlock = True"
868 868
869 869 if len(shape) != 3:
870 870 raise ValueError, "shape len should be equal to 3, (nChannels, nProfiles, nHeis)"
871 871
872 872 shape_tuple = tuple(shape)
873 873 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
874 874 dataOut.flagNoData = False
875 875
876 876 if self.updateNewHeights:
877 877
878 878 old_nheights = dataOut.nHeights
879 879 new_nheights = dataOut.data.shape[2]
880 880 factor = 1.0*new_nheights / old_nheights
881 881
882 882 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
883 883
884 884 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor
885 885
886 886 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
887 887
888 888 dataOut.nProfiles = dataOut.data.shape[1]
889 889
890 890 dataOut.ippSeconds *= factor No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now