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