##// END OF EJS Templates
fix data_intensity metodo PulsePair
avaldezp -
r1502:f43a77c271af
parent child
Show More
@@ -1,1891 +1,1891
1 1 import sys
2 2 import numpy,math
3 3 from scipy import interpolate
4 4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
6 6 from schainpy.utils import log
7 7 from time import time
8 8
9 9
10 10
11 11 class VoltageProc(ProcessingUnit):
12 12
13 13 def __init__(self):
14 14
15 15 ProcessingUnit.__init__(self)
16 16
17 17 self.dataOut = Voltage()
18 18 self.flip = 1
19 19 self.setupReq = False
20 20
21 21 def run(self):
22 22
23 23 if self.dataIn.type == 'AMISR':
24 24 self.__updateObjFromAmisrInput()
25 25
26 26 if self.dataIn.type == 'Voltage':
27 27 self.dataOut.copy(self.dataIn)
28 28
29 29 def __updateObjFromAmisrInput(self):
30 30
31 31 self.dataOut.timeZone = self.dataIn.timeZone
32 32 self.dataOut.dstFlag = self.dataIn.dstFlag
33 33 self.dataOut.errorCount = self.dataIn.errorCount
34 34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35 35
36 36 self.dataOut.flagNoData = self.dataIn.flagNoData
37 37 self.dataOut.data = self.dataIn.data
38 38 self.dataOut.utctime = self.dataIn.utctime
39 39 self.dataOut.channelList = self.dataIn.channelList
40 40 #self.dataOut.timeInterval = self.dataIn.timeInterval
41 41 self.dataOut.heightList = self.dataIn.heightList
42 42 self.dataOut.nProfiles = self.dataIn.nProfiles
43 43
44 44 self.dataOut.nCohInt = self.dataIn.nCohInt
45 45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 46 self.dataOut.frequency = self.dataIn.frequency
47 47
48 48 self.dataOut.azimuth = self.dataIn.azimuth
49 49 self.dataOut.zenith = self.dataIn.zenith
50 50
51 51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54 54
55 55
56 56 class selectChannels(Operation):
57 57
58 58 def run(self, dataOut, channelList):
59 59
60 60 channelIndexList = []
61 61 self.dataOut = dataOut
62 62 for channel in channelList:
63 63 if channel not in self.dataOut.channelList:
64 64 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
65 65
66 66 index = self.dataOut.channelList.index(channel)
67 67 channelIndexList.append(index)
68 68 self.selectChannelsByIndex(channelIndexList)
69 69 return self.dataOut
70 70
71 71 def selectChannelsByIndex(self, channelIndexList):
72 72 """
73 73 Selecciona un bloque de datos en base a canales segun el channelIndexList
74 74
75 75 Input:
76 76 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
77 77
78 78 Affected:
79 79 self.dataOut.data
80 80 self.dataOut.channelIndexList
81 81 self.dataOut.nChannels
82 82 self.dataOut.m_ProcessingHeader.totalSpectra
83 83 self.dataOut.systemHeaderObj.numChannels
84 84 self.dataOut.m_ProcessingHeader.blockSize
85 85
86 86 Return:
87 87 None
88 88 """
89 89
90 90 for channelIndex in channelIndexList:
91 91 if channelIndex not in self.dataOut.channelIndexList:
92 92 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
93 93
94 94 if self.dataOut.type == 'Voltage':
95 95 if self.dataOut.flagDataAsBlock:
96 96 """
97 97 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
98 98 """
99 99 data = self.dataOut.data[channelIndexList,:,:]
100 100 else:
101 101 data = self.dataOut.data[channelIndexList,:]
102 102
103 103 self.dataOut.data = data
104 104 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
105 105 self.dataOut.channelList = range(len(channelIndexList))
106 106
107 107 elif self.dataOut.type == 'Spectra':
108 108 data_spc = self.dataOut.data_spc[channelIndexList, :]
109 109 data_dc = self.dataOut.data_dc[channelIndexList, :]
110 110
111 111 self.dataOut.data_spc = data_spc
112 112 self.dataOut.data_dc = data_dc
113 113
114 114 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 115 self.dataOut.channelList = range(len(channelIndexList))
116 116 self.__selectPairsByChannel(channelIndexList)
117 117
118 118 return 1
119 119
120 120 def __selectPairsByChannel(self, channelList=None):
121 121
122 122 if channelList == None:
123 123 return
124 124
125 125 pairsIndexListSelected = []
126 126 for pairIndex in self.dataOut.pairsIndexList:
127 127 # First pair
128 128 if self.dataOut.pairsList[pairIndex][0] not in channelList:
129 129 continue
130 130 # Second pair
131 131 if self.dataOut.pairsList[pairIndex][1] not in channelList:
132 132 continue
133 133
134 134 pairsIndexListSelected.append(pairIndex)
135 135
136 136 if not pairsIndexListSelected:
137 137 self.dataOut.data_cspc = None
138 138 self.dataOut.pairsList = []
139 139 return
140 140
141 141 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
142 142 self.dataOut.pairsList = [self.dataOut.pairsList[i]
143 143 for i in pairsIndexListSelected]
144 144
145 145 return
146 146
147 147 class selectHeights(Operation):
148 148
149 149 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
150 150 """
151 151 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
152 152 minHei <= height <= maxHei
153 153
154 154 Input:
155 155 minHei : valor minimo de altura a considerar
156 156 maxHei : valor maximo de altura a considerar
157 157
158 158 Affected:
159 159 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
160 160
161 161 Return:
162 162 1 si el metodo se ejecuto con exito caso contrario devuelve 0
163 163 """
164 164
165 165 self.dataOut = dataOut
166 166
167 167 if minHei and maxHei:
168 168
169 169 if (minHei < self.dataOut.heightList[0]):
170 170 minHei = self.dataOut.heightList[0]
171 171
172 172 if (maxHei > self.dataOut.heightList[-1]):
173 173 maxHei = self.dataOut.heightList[-1]
174 174
175 175 minIndex = 0
176 176 maxIndex = 0
177 177 heights = self.dataOut.heightList
178 178
179 179 inda = numpy.where(heights >= minHei)
180 180 indb = numpy.where(heights <= maxHei)
181 181
182 182 try:
183 183 minIndex = inda[0][0]
184 184 except:
185 185 minIndex = 0
186 186
187 187 try:
188 188 maxIndex = indb[0][-1]
189 189 except:
190 190 maxIndex = len(heights)
191 191
192 192 self.selectHeightsByIndex(minIndex, maxIndex)
193 193
194 194 return self.dataOut
195 195
196 196 def selectHeightsByIndex(self, minIndex, maxIndex):
197 197 """
198 198 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
199 199 minIndex <= index <= maxIndex
200 200
201 201 Input:
202 202 minIndex : valor de indice minimo de altura a considerar
203 203 maxIndex : valor de indice maximo de altura a considerar
204 204
205 205 Affected:
206 206 self.dataOut.data
207 207 self.dataOut.heightList
208 208
209 209 Return:
210 210 1 si el metodo se ejecuto con exito caso contrario devuelve 0
211 211 """
212 212
213 213 if self.dataOut.type == 'Voltage':
214 214 if (minIndex < 0) or (minIndex > maxIndex):
215 215 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
216 216
217 217 if (maxIndex >= self.dataOut.nHeights):
218 218 maxIndex = self.dataOut.nHeights
219 219 #print("shapeeee",self.dataOut.data.shape)
220 220 #voltage
221 221 if self.dataOut.flagDataAsBlock:
222 222 """
223 223 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
224 224 """
225 225 data = self.dataOut.data[:,:, minIndex:maxIndex]
226 226 else:
227 227 data = self.dataOut.data[:, minIndex:maxIndex]
228 228
229 229 # firstHeight = self.dataOut.heightList[minIndex]
230 230
231 231 self.dataOut.data = data
232 232 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
233 233
234 234 if self.dataOut.nHeights <= 1:
235 235 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
236 236 elif self.dataOut.type == 'Spectra':
237 237 if (minIndex < 0) or (minIndex > maxIndex):
238 238 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
239 239 minIndex, maxIndex))
240 240
241 241 if (maxIndex >= self.dataOut.nHeights):
242 242 maxIndex = self.dataOut.nHeights - 1
243 243
244 244 # Spectra
245 245 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
246 246
247 247 data_cspc = None
248 248 if self.dataOut.data_cspc is not None:
249 249 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
250 250
251 251 data_dc = None
252 252 if self.dataOut.data_dc is not None:
253 253 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
254 254
255 255 self.dataOut.data_spc = data_spc
256 256 self.dataOut.data_cspc = data_cspc
257 257 self.dataOut.data_dc = data_dc
258 258
259 259 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
260 260
261 261 return 1
262 262
263 263
264 264 class filterByHeights(Operation):
265 265
266 266 def run(self, dataOut, window):
267 267
268 268 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
269 269
270 270 if window == None:
271 271 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
272 272
273 273 newdelta = deltaHeight * window
274 274 r = dataOut.nHeights % window
275 275 newheights = (dataOut.nHeights-r)/window
276 276
277 277 if newheights <= 1:
278 278 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
279 279
280 280 if dataOut.flagDataAsBlock:
281 281 """
282 282 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
283 283 """
284 284 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
285 285 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
286 286 buffer = numpy.sum(buffer,3)
287 287
288 288 else:
289 289 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
290 290 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
291 291 buffer = numpy.sum(buffer,2)
292 292
293 293 dataOut.data = buffer
294 294 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
295 295 dataOut.windowOfFilter = window
296 296
297 297 return dataOut
298 298
299 299
300 300 class setH0(Operation):
301 301
302 302 def run(self, dataOut, h0, deltaHeight = None):
303 303
304 304 if not deltaHeight:
305 305 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
306 306
307 307 nHeights = dataOut.nHeights
308 308
309 309 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
310 310
311 311 dataOut.heightList = newHeiRange
312 312 dataOut.h0 = h0
313 313
314 314 return dataOut
315 315
316 316
317 317 class deFlip(Operation):
318 318
319 319 def run(self, dataOut, channelList = []):
320 320
321 321 data = dataOut.data.copy()
322 322
323 323 if dataOut.flagDataAsBlock:
324 324 flip = self.flip
325 325 profileList = list(range(dataOut.nProfiles))
326 326
327 327 if not channelList:
328 328 for thisProfile in profileList:
329 329 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
330 330 flip *= -1.0
331 331 else:
332 332 for thisChannel in channelList:
333 333 if thisChannel not in dataOut.channelList:
334 334 continue
335 335
336 336 for thisProfile in profileList:
337 337 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
338 338 flip *= -1.0
339 339
340 340 self.flip = flip
341 341
342 342 else:
343 343 if not channelList:
344 344 data[:,:] = data[:,:]*self.flip
345 345 else:
346 346 for thisChannel in channelList:
347 347 if thisChannel not in dataOut.channelList:
348 348 continue
349 349
350 350 data[thisChannel,:] = data[thisChannel,:]*self.flip
351 351
352 352 self.flip *= -1.
353 353
354 354 dataOut.data = data
355 355
356 356 return dataOut
357 357
358 358
359 359 class setAttribute(Operation):
360 360 '''
361 361 Set an arbitrary attribute(s) to dataOut
362 362 '''
363 363
364 364 def __init__(self):
365 365
366 366 Operation.__init__(self)
367 367 self._ready = False
368 368
369 369 def run(self, dataOut, **kwargs):
370 370
371 371 for key, value in kwargs.items():
372 372 setattr(dataOut, key, value)
373 373
374 374 return dataOut
375 375
376 376
377 377 @MPDecorator
378 378 class printAttribute(Operation):
379 379 '''
380 380 Print an arbitrary attribute of dataOut
381 381 '''
382 382
383 383 def __init__(self):
384 384
385 385 Operation.__init__(self)
386 386
387 387 def run(self, dataOut, attributes):
388 388
389 389 if isinstance(attributes, str):
390 390 attributes = [attributes]
391 391 for attr in attributes:
392 392 if hasattr(dataOut, attr):
393 393 log.log(getattr(dataOut, attr), attr)
394 394
395 395
396 396 class interpolateHeights(Operation):
397 397
398 398 def run(self, dataOut, topLim, botLim):
399 399 #69 al 72 para julia
400 400 #82-84 para meteoros
401 401 if len(numpy.shape(dataOut.data))==2:
402 402 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
403 403 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
404 404 #dataOut.data[:,botLim:limSup+1] = sampInterp
405 405 dataOut.data[:,botLim:topLim+1] = sampInterp
406 406 else:
407 407 nHeights = dataOut.data.shape[2]
408 408 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
409 409 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
410 410 f = interpolate.interp1d(x, y, axis = 2)
411 411 xnew = numpy.arange(botLim,topLim+1)
412 412 ynew = f(xnew)
413 413 dataOut.data[:,:,botLim:topLim+1] = ynew
414 414
415 415 return dataOut
416 416
417 417
418 418 class CohInt(Operation):
419 419
420 420 isConfig = False
421 421 __profIndex = 0
422 422 __byTime = False
423 423 __initime = None
424 424 __lastdatatime = None
425 425 __integrationtime = None
426 426 __buffer = None
427 427 __bufferStride = []
428 428 __dataReady = False
429 429 __profIndexStride = 0
430 430 __dataToPutStride = False
431 431 n = None
432 432
433 433 def __init__(self, **kwargs):
434 434
435 435 Operation.__init__(self, **kwargs)
436 436
437 437 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
438 438 """
439 439 Set the parameters of the integration class.
440 440
441 441 Inputs:
442 442
443 443 n : Number of coherent integrations
444 444 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
445 445 overlapping :
446 446 """
447 447
448 448 self.__initime = None
449 449 self.__lastdatatime = 0
450 450 self.__buffer = None
451 451 self.__dataReady = False
452 452 self.byblock = byblock
453 453 self.stride = stride
454 454
455 455 if n == None and timeInterval == None:
456 456 raise ValueError("n or timeInterval should be specified ...")
457 457
458 458 if n != None:
459 459 self.n = n
460 460 self.__byTime = False
461 461 else:
462 462 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
463 463 self.n = 9999
464 464 self.__byTime = True
465 465
466 466 if overlapping:
467 467 self.__withOverlapping = True
468 468 self.__buffer = None
469 469 else:
470 470 self.__withOverlapping = False
471 471 self.__buffer = 0
472 472
473 473 self.__profIndex = 0
474 474
475 475 def putData(self, data):
476 476
477 477 """
478 478 Add a profile to the __buffer and increase in one the __profileIndex
479 479
480 480 """
481 481
482 482 if not self.__withOverlapping:
483 483 self.__buffer += data.copy()
484 484 self.__profIndex += 1
485 485 return
486 486
487 487 #Overlapping data
488 488 nChannels, nHeis = data.shape
489 489 data = numpy.reshape(data, (1, nChannels, nHeis))
490 490
491 491 #If the buffer is empty then it takes the data value
492 492 if self.__buffer is None:
493 493 self.__buffer = data
494 494 self.__profIndex += 1
495 495 return
496 496
497 497 #If the buffer length is lower than n then stakcing the data value
498 498 if self.__profIndex < self.n:
499 499 self.__buffer = numpy.vstack((self.__buffer, data))
500 500 self.__profIndex += 1
501 501 return
502 502
503 503 #If the buffer length is equal to n then replacing the last buffer value with the data value
504 504 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
505 505 self.__buffer[self.n-1] = data
506 506 self.__profIndex = self.n
507 507 return
508 508
509 509
510 510 def pushData(self):
511 511 """
512 512 Return the sum of the last profiles and the profiles used in the sum.
513 513
514 514 Affected:
515 515
516 516 self.__profileIndex
517 517
518 518 """
519 519
520 520 if not self.__withOverlapping:
521 521 data = self.__buffer
522 522 n = self.__profIndex
523 523
524 524 self.__buffer = 0
525 525 self.__profIndex = 0
526 526
527 527 return data, n
528 528
529 529 #Integration with Overlapping
530 530 data = numpy.sum(self.__buffer, axis=0)
531 531 # print data
532 532 # raise
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 # print data
543 543 # raise
544 544 self.putData(data)
545 545
546 546 if self.__profIndex == self.n:
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 integrateByStride(self, data, datatime):
568 568 # print data
569 569 if self.__profIndex == 0:
570 570 self.__buffer = [[data.copy(), datatime]]
571 571 else:
572 572 self.__buffer.append([data.copy(),datatime])
573 573 self.__profIndex += 1
574 574 self.__dataReady = False
575 575
576 576 if self.__profIndex == self.n * self.stride :
577 577 self.__dataToPutStride = True
578 578 self.__profIndexStride = 0
579 579 self.__profIndex = 0
580 580 self.__bufferStride = []
581 581 for i in range(self.stride):
582 582 current = self.__buffer[i::self.stride]
583 583 data = numpy.sum([t[0] for t in current], axis=0)
584 584 avgdatatime = numpy.average([t[1] for t in current])
585 585 # print data
586 586 self.__bufferStride.append((data, avgdatatime))
587 587
588 588 if self.__dataToPutStride:
589 589 self.__dataReady = True
590 590 self.__profIndexStride += 1
591 591 if self.__profIndexStride == self.stride:
592 592 self.__dataToPutStride = False
593 593 # print self.__bufferStride[self.__profIndexStride - 1]
594 594 # raise
595 595 return self.__bufferStride[self.__profIndexStride - 1]
596 596
597 597
598 598 return None, None
599 599
600 600 def integrate(self, data, datatime=None):
601 601
602 602 if self.__initime == None:
603 603 self.__initime = datatime
604 604
605 605 if self.__byTime:
606 606 avgdata = self.byTime(data, datatime)
607 607 else:
608 608 avgdata = self.byProfiles(data)
609 609
610 610
611 611 self.__lastdatatime = datatime
612 612
613 613 if avgdata is None:
614 614 return None, None
615 615
616 616 avgdatatime = self.__initime
617 617
618 618 deltatime = datatime - self.__lastdatatime
619 619
620 620 if not self.__withOverlapping:
621 621 self.__initime = datatime
622 622 else:
623 623 self.__initime += deltatime
624 624
625 625 return avgdata, avgdatatime
626 626
627 627 def integrateByBlock(self, dataOut):
628 628
629 629 times = int(dataOut.data.shape[1]/self.n)
630 630 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
631 631
632 632 id_min = 0
633 633 id_max = self.n
634 634
635 635 for i in range(times):
636 636 junk = dataOut.data[:,id_min:id_max,:]
637 637 avgdata[:,i,:] = junk.sum(axis=1)
638 638 id_min += self.n
639 639 id_max += self.n
640 640
641 641 timeInterval = dataOut.ippSeconds*self.n
642 642 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
643 643 self.__dataReady = True
644 644 return avgdata, avgdatatime
645 645
646 646 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
647 647
648 648 if not self.isConfig:
649 649 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
650 650 self.isConfig = True
651 651
652 652 if dataOut.flagDataAsBlock:
653 653 """
654 654 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
655 655 """
656 656 avgdata, avgdatatime = self.integrateByBlock(dataOut)
657 657 dataOut.nProfiles /= self.n
658 658 else:
659 659 if stride is None:
660 660 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
661 661 else:
662 662 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
663 663
664 664
665 665 # dataOut.timeInterval *= n
666 666 dataOut.flagNoData = True
667 667
668 668 if self.__dataReady:
669 669 dataOut.data = avgdata
670 670 if not dataOut.flagCohInt:
671 671 dataOut.nCohInt *= self.n
672 672 dataOut.flagCohInt = True
673 673 ####################################dataOut.utctime = avgdatatime
674 674 # print avgdata, avgdatatime
675 675 # raise
676 676 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
677 677 dataOut.flagNoData = False
678 678 return dataOut
679 679
680 680 class Decoder(Operation):
681 681
682 682 isConfig = False
683 683 __profIndex = 0
684 684
685 685 code = None
686 686
687 687 nCode = None
688 688 nBaud = None
689 689
690 690 def __init__(self, **kwargs):
691 691
692 692 Operation.__init__(self, **kwargs)
693 693
694 694 self.times = None
695 695 self.osamp = None
696 696 # self.__setValues = False
697 697 self.isConfig = False
698 698 self.setupReq = False
699 699 def setup(self, code, osamp, dataOut):
700 700
701 701 self.__profIndex = 0
702 702
703 703 self.code = code
704 704
705 705 self.nCode = len(code)
706 706 self.nBaud = len(code[0])
707 707
708 708 if (osamp != None) and (osamp >1):
709 709 self.osamp = osamp
710 710 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
711 711 self.nBaud = self.nBaud*self.osamp
712 712
713 713 self.__nChannels = dataOut.nChannels
714 714 self.__nProfiles = dataOut.nProfiles
715 715 self.__nHeis = dataOut.nHeights
716 716
717 717 if self.__nHeis < self.nBaud:
718 718 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
719 719
720 720 #Frequency
721 721 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
722 722
723 723 __codeBuffer[:,0:self.nBaud] = self.code
724 724
725 725 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
726 726
727 727 if dataOut.flagDataAsBlock:
728 728
729 729 self.ndatadec = self.__nHeis #- self.nBaud + 1
730 730
731 731 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
732 732
733 733 else:
734 734
735 735 #Time
736 736 self.ndatadec = self.__nHeis #- self.nBaud + 1
737 737
738 738 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
739 739
740 740 def __convolutionInFreq(self, data):
741 741
742 742 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
743 743
744 744 fft_data = numpy.fft.fft(data, axis=1)
745 745
746 746 conv = fft_data*fft_code
747 747
748 748 data = numpy.fft.ifft(conv,axis=1)
749 749
750 750 return data
751 751
752 752 def __convolutionInFreqOpt(self, data):
753 753
754 754 raise NotImplementedError
755 755
756 756 def __convolutionInTime(self, data):
757 757
758 758 code = self.code[self.__profIndex]
759 759 for i in range(self.__nChannels):
760 760 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
761 761
762 762 return self.datadecTime
763 763
764 764 def __convolutionByBlockInTime(self, data):
765 765
766 766 repetitions = int(self.__nProfiles / self.nCode)
767 767 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
768 768 junk = junk.flatten()
769 769 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
770 770 profilesList = range(self.__nProfiles)
771 771
772 772 for i in range(self.__nChannels):
773 773 for j in profilesList:
774 774 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
775 775 return self.datadecTime
776 776
777 777 def __convolutionByBlockInFreq(self, data):
778 778
779 779 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
780 780
781 781
782 782 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
783 783
784 784 fft_data = numpy.fft.fft(data, axis=2)
785 785
786 786 conv = fft_data*fft_code
787 787
788 788 data = numpy.fft.ifft(conv,axis=2)
789 789
790 790 return data
791 791
792 792
793 793 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
794 794
795 795 if dataOut.flagDecodeData:
796 796 print("This data is already decoded, recoding again ...")
797 797
798 798 if not self.isConfig:
799 799
800 800 if code is None:
801 801 if dataOut.code is None:
802 802 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
803 803
804 804 code = dataOut.code
805 805 else:
806 806 code = numpy.array(code).reshape(nCode,nBaud)
807 807 self.setup(code, osamp, dataOut)
808 808
809 809 self.isConfig = True
810 810
811 811 if mode == 3:
812 812 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
813 813
814 814 if times != None:
815 815 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
816 816
817 817 if self.code is None:
818 818 print("Fail decoding: Code is not defined.")
819 819 return
820 820
821 821 self.__nProfiles = dataOut.nProfiles
822 822 datadec = None
823 823
824 824 if mode == 3:
825 825 mode = 0
826 826
827 827 if dataOut.flagDataAsBlock:
828 828 """
829 829 Decoding when data have been read as block,
830 830 """
831 831
832 832 if mode == 0:
833 833 datadec = self.__convolutionByBlockInTime(dataOut.data)
834 834 if mode == 1:
835 835 datadec = self.__convolutionByBlockInFreq(dataOut.data)
836 836 else:
837 837 """
838 838 Decoding when data have been read profile by profile
839 839 """
840 840 if mode == 0:
841 841 datadec = self.__convolutionInTime(dataOut.data)
842 842
843 843 if mode == 1:
844 844 datadec = self.__convolutionInFreq(dataOut.data)
845 845
846 846 if mode == 2:
847 847 datadec = self.__convolutionInFreqOpt(dataOut.data)
848 848
849 849 if datadec is None:
850 850 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
851 851
852 852 dataOut.code = self.code
853 853 dataOut.nCode = self.nCode
854 854 dataOut.nBaud = self.nBaud
855 855
856 856 dataOut.data = datadec
857 857
858 858 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
859 859
860 860 dataOut.flagDecodeData = True #asumo q la data esta decodificada
861 861
862 862 if self.__profIndex == self.nCode-1:
863 863 self.__profIndex = 0
864 864 return dataOut
865 865
866 866 self.__profIndex += 1
867 867
868 868 return dataOut
869 869 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
870 870
871 871
872 872 class ProfileConcat(Operation):
873 873
874 874 isConfig = False
875 875 buffer = None
876 876
877 877 def __init__(self, **kwargs):
878 878
879 879 Operation.__init__(self, **kwargs)
880 880 self.profileIndex = 0
881 881
882 882 def reset(self):
883 883 self.buffer = numpy.zeros_like(self.buffer)
884 884 self.start_index = 0
885 885 self.times = 1
886 886
887 887 def setup(self, data, m, n=1):
888 888 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
889 889 self.nHeights = data.shape[1]#.nHeights
890 890 self.start_index = 0
891 891 self.times = 1
892 892
893 893 def concat(self, data):
894 894
895 895 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
896 896 self.start_index = self.start_index + self.nHeights
897 897
898 898 def run(self, dataOut, m):
899 899 dataOut.flagNoData = True
900 900
901 901 if not self.isConfig:
902 902 self.setup(dataOut.data, m, 1)
903 903 self.isConfig = True
904 904
905 905 if dataOut.flagDataAsBlock:
906 906 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
907 907
908 908 else:
909 909 self.concat(dataOut.data)
910 910 self.times += 1
911 911 if self.times > m:
912 912 dataOut.data = self.buffer
913 913 self.reset()
914 914 dataOut.flagNoData = False
915 915 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
916 916 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
917 917 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
918 918 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
919 919 dataOut.ippSeconds *= m
920 920 return dataOut
921 921
922 922 class ProfileSelector(Operation):
923 923
924 924 profileIndex = None
925 925 # Tamanho total de los perfiles
926 926 nProfiles = None
927 927
928 928 def __init__(self, **kwargs):
929 929
930 930 Operation.__init__(self, **kwargs)
931 931 self.profileIndex = 0
932 932
933 933 def incProfileIndex(self):
934 934
935 935 self.profileIndex += 1
936 936
937 937 if self.profileIndex >= self.nProfiles:
938 938 self.profileIndex = 0
939 939
940 940 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
941 941
942 942 if profileIndex < minIndex:
943 943 return False
944 944
945 945 if profileIndex > maxIndex:
946 946 return False
947 947
948 948 return True
949 949
950 950 def isThisProfileInList(self, profileIndex, profileList):
951 951
952 952 if profileIndex not in profileList:
953 953 return False
954 954
955 955 return True
956 956
957 957 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
958 958 #print("before",dataOut.data.shape)
959 959 """
960 960 ProfileSelector:
961 961
962 962 Inputs:
963 963 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
964 964
965 965 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
966 966
967 967 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
968 968
969 969 """
970 970
971 971 if rangeList is not None:
972 972 if type(rangeList[0]) not in (tuple, list):
973 973 rangeList = [rangeList]
974 974
975 975 dataOut.flagNoData = True
976 976
977 977 if dataOut.flagDataAsBlock:
978 978 """
979 979 data dimension = [nChannels, nProfiles, nHeis]
980 980 """
981 981 if profileList != None:
982 982 dataOut.data = dataOut.data[:,profileList,:]
983 983
984 984 if profileRangeList != None:
985 985 minIndex = profileRangeList[0]
986 986 maxIndex = profileRangeList[1]
987 987 profileList = list(range(minIndex, maxIndex+1))
988 988
989 989 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
990 990
991 991 if rangeList != None:
992 992
993 993 profileList = []
994 994
995 995 for thisRange in rangeList:
996 996 minIndex = thisRange[0]
997 997 maxIndex = thisRange[1]
998 998
999 999 profileList.extend(list(range(minIndex, maxIndex+1)))
1000 1000
1001 1001 dataOut.data = dataOut.data[:,profileList,:]
1002 1002
1003 1003 dataOut.nProfiles = len(profileList)
1004 1004 dataOut.profileIndex = dataOut.nProfiles - 1
1005 1005 dataOut.flagNoData = False
1006 1006 #print(dataOut.data.shape)
1007 1007 return dataOut
1008 1008
1009 1009 """
1010 1010 data dimension = [nChannels, nHeis]
1011 1011 """
1012 1012
1013 1013 if profileList != None:
1014 1014
1015 1015 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1016 1016
1017 1017 self.nProfiles = len(profileList)
1018 1018 dataOut.nProfiles = self.nProfiles
1019 1019 dataOut.profileIndex = self.profileIndex
1020 1020 dataOut.flagNoData = False
1021 1021
1022 1022 self.incProfileIndex()
1023 1023 return dataOut
1024 1024
1025 1025 if profileRangeList != None:
1026 1026
1027 1027 minIndex = profileRangeList[0]
1028 1028 maxIndex = profileRangeList[1]
1029 1029
1030 1030 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1031 1031
1032 1032 self.nProfiles = maxIndex - minIndex + 1
1033 1033 dataOut.nProfiles = self.nProfiles
1034 1034 dataOut.profileIndex = self.profileIndex
1035 1035 dataOut.flagNoData = False
1036 1036
1037 1037 self.incProfileIndex()
1038 1038 return dataOut
1039 1039
1040 1040 if rangeList != None:
1041 1041
1042 1042 nProfiles = 0
1043 1043
1044 1044 for thisRange in rangeList:
1045 1045 minIndex = thisRange[0]
1046 1046 maxIndex = thisRange[1]
1047 1047
1048 1048 nProfiles += maxIndex - minIndex + 1
1049 1049
1050 1050 for thisRange in rangeList:
1051 1051
1052 1052 minIndex = thisRange[0]
1053 1053 maxIndex = thisRange[1]
1054 1054
1055 1055 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1056 1056
1057 1057 self.nProfiles = nProfiles
1058 1058 dataOut.nProfiles = self.nProfiles
1059 1059 dataOut.profileIndex = self.profileIndex
1060 1060 dataOut.flagNoData = False
1061 1061
1062 1062 self.incProfileIndex()
1063 1063
1064 1064 break
1065 1065
1066 1066 return dataOut
1067 1067
1068 1068
1069 1069 if beam != None: #beam is only for AMISR data
1070 1070 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1071 1071 dataOut.flagNoData = False
1072 1072 dataOut.profileIndex = self.profileIndex
1073 1073
1074 1074 self.incProfileIndex()
1075 1075
1076 1076 return dataOut
1077 1077
1078 1078 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1079 1079
1080 1080
1081 1081 class Reshaper(Operation):
1082 1082
1083 1083 def __init__(self, **kwargs):
1084 1084
1085 1085 Operation.__init__(self, **kwargs)
1086 1086
1087 1087 self.__buffer = None
1088 1088 self.__nitems = 0
1089 1089
1090 1090 def __appendProfile(self, dataOut, nTxs):
1091 1091
1092 1092 if self.__buffer is None:
1093 1093 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1094 1094 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1095 1095
1096 1096 ini = dataOut.nHeights * self.__nitems
1097 1097 end = ini + dataOut.nHeights
1098 1098
1099 1099 self.__buffer[:, ini:end] = dataOut.data
1100 1100
1101 1101 self.__nitems += 1
1102 1102
1103 1103 return int(self.__nitems*nTxs)
1104 1104
1105 1105 def __getBuffer(self):
1106 1106
1107 1107 if self.__nitems == int(1./self.__nTxs):
1108 1108
1109 1109 self.__nitems = 0
1110 1110
1111 1111 return self.__buffer.copy()
1112 1112
1113 1113 return None
1114 1114
1115 1115 def __checkInputs(self, dataOut, shape, nTxs):
1116 1116
1117 1117 if shape is None and nTxs is None:
1118 1118 raise ValueError("Reshaper: shape of factor should be defined")
1119 1119
1120 1120 if nTxs:
1121 1121 if nTxs < 0:
1122 1122 raise ValueError("nTxs should be greater than 0")
1123 1123
1124 1124 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1125 1125 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1126 1126
1127 1127 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1128 1128
1129 1129 return shape, nTxs
1130 1130
1131 1131 if len(shape) != 2 and len(shape) != 3:
1132 1132 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1133 1133
1134 1134 if len(shape) == 2:
1135 1135 shape_tuple = [dataOut.nChannels]
1136 1136 shape_tuple.extend(shape)
1137 1137 else:
1138 1138 shape_tuple = list(shape)
1139 1139
1140 1140 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1141 1141
1142 1142 return shape_tuple, nTxs
1143 1143
1144 1144 def run(self, dataOut, shape=None, nTxs=None):
1145 1145
1146 1146 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1147 1147
1148 1148 dataOut.flagNoData = True
1149 1149 profileIndex = None
1150 1150
1151 1151 if dataOut.flagDataAsBlock:
1152 1152
1153 1153 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1154 1154 dataOut.flagNoData = False
1155 1155
1156 1156 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1157 1157
1158 1158 else:
1159 1159
1160 1160 if self.__nTxs < 1:
1161 1161
1162 1162 self.__appendProfile(dataOut, self.__nTxs)
1163 1163 new_data = self.__getBuffer()
1164 1164
1165 1165 if new_data is not None:
1166 1166 dataOut.data = new_data
1167 1167 dataOut.flagNoData = False
1168 1168
1169 1169 profileIndex = dataOut.profileIndex*nTxs
1170 1170
1171 1171 else:
1172 1172 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1173 1173
1174 1174 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1175 1175
1176 1176 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1177 1177
1178 1178 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1179 1179
1180 1180 dataOut.profileIndex = profileIndex
1181 1181
1182 1182 dataOut.ippSeconds /= self.__nTxs
1183 1183
1184 1184 return dataOut
1185 1185
1186 1186 class SplitProfiles(Operation):
1187 1187
1188 1188 def __init__(self, **kwargs):
1189 1189
1190 1190 Operation.__init__(self, **kwargs)
1191 1191
1192 1192 def run(self, dataOut, n):
1193 1193
1194 1194 dataOut.flagNoData = True
1195 1195 profileIndex = None
1196 1196
1197 1197 if dataOut.flagDataAsBlock:
1198 1198
1199 1199 #nchannels, nprofiles, nsamples
1200 1200 shape = dataOut.data.shape
1201 1201
1202 1202 if shape[2] % n != 0:
1203 1203 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1204 1204
1205 1205 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1206 1206
1207 1207 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1208 1208 dataOut.flagNoData = False
1209 1209
1210 1210 profileIndex = int(dataOut.nProfiles/n) - 1
1211 1211
1212 1212 else:
1213 1213
1214 1214 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1215 1215
1216 1216 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1217 1217
1218 1218 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1219 1219
1220 1220 dataOut.nProfiles = int(dataOut.nProfiles*n)
1221 1221
1222 1222 dataOut.profileIndex = profileIndex
1223 1223
1224 1224 dataOut.ippSeconds /= n
1225 1225
1226 1226 return dataOut
1227 1227
1228 1228 class CombineProfiles(Operation):
1229 1229 def __init__(self, **kwargs):
1230 1230
1231 1231 Operation.__init__(self, **kwargs)
1232 1232
1233 1233 self.__remData = None
1234 1234 self.__profileIndex = 0
1235 1235
1236 1236 def run(self, dataOut, n):
1237 1237
1238 1238 dataOut.flagNoData = True
1239 1239 profileIndex = None
1240 1240
1241 1241 if dataOut.flagDataAsBlock:
1242 1242
1243 1243 #nchannels, nprofiles, nsamples
1244 1244 shape = dataOut.data.shape
1245 1245 new_shape = shape[0], shape[1]/n, shape[2]*n
1246 1246
1247 1247 if shape[1] % n != 0:
1248 1248 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1249 1249
1250 1250 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1251 1251 dataOut.flagNoData = False
1252 1252
1253 1253 profileIndex = int(dataOut.nProfiles*n) - 1
1254 1254
1255 1255 else:
1256 1256
1257 1257 #nchannels, nsamples
1258 1258 if self.__remData is None:
1259 1259 newData = dataOut.data
1260 1260 else:
1261 1261 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1262 1262
1263 1263 self.__profileIndex += 1
1264 1264
1265 1265 if self.__profileIndex < n:
1266 1266 self.__remData = newData
1267 1267 #continue
1268 1268 return
1269 1269
1270 1270 self.__profileIndex = 0
1271 1271 self.__remData = None
1272 1272
1273 1273 dataOut.data = newData
1274 1274 dataOut.flagNoData = False
1275 1275
1276 1276 profileIndex = dataOut.profileIndex/n
1277 1277
1278 1278
1279 1279 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1280 1280
1281 1281 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1282 1282
1283 1283 dataOut.nProfiles = int(dataOut.nProfiles/n)
1284 1284
1285 1285 dataOut.profileIndex = profileIndex
1286 1286
1287 1287 dataOut.ippSeconds *= n
1288 1288
1289 1289 return dataOut
1290 1290
1291 1291 class PulsePair(Operation):
1292 1292 '''
1293 1293 Function PulsePair(Signal Power, Velocity)
1294 1294 The real component of Lag[0] provides Intensity Information
1295 1295 The imag component of Lag[1] Phase provides Velocity Information
1296 1296
1297 1297 Configuration Parameters:
1298 1298 nPRF = Number of Several PRF
1299 1299 theta = Degree Azimuth angel Boundaries
1300 1300
1301 1301 Input:
1302 1302 self.dataOut
1303 1303 lag[N]
1304 1304 Affected:
1305 1305 self.dataOut.spc
1306 1306 '''
1307 1307 isConfig = False
1308 1308 __profIndex = 0
1309 1309 __initime = None
1310 1310 __lastdatatime = None
1311 1311 __buffer = None
1312 1312 noise = None
1313 1313 __dataReady = False
1314 1314 n = None
1315 1315 __nch = 0
1316 1316 __nHeis = 0
1317 1317 removeDC = False
1318 1318 ipp = None
1319 1319 lambda_ = 0
1320 1320
1321 1321 def __init__(self,**kwargs):
1322 1322 Operation.__init__(self,**kwargs)
1323 1323
1324 1324 def setup(self, dataOut, n = None, removeDC=False):
1325 1325 '''
1326 1326 n= Numero de PRF's de entrada
1327 1327 '''
1328 1328 self.__initime = None
1329 1329 ####print("[INICIO]-setup del METODO PULSE PAIR")
1330 1330 self.__lastdatatime = 0
1331 1331 self.__dataReady = False
1332 1332 self.__buffer = 0
1333 1333 self.__profIndex = 0
1334 1334 self.noise = None
1335 1335 self.__nch = dataOut.nChannels
1336 1336 self.__nHeis = dataOut.nHeights
1337 1337 self.removeDC = removeDC
1338 1338 self.lambda_ = 3.0e8/(9345.0e6)
1339 1339 self.ippSec = dataOut.ippSeconds
1340 1340 self.nCohInt = dataOut.nCohInt
1341 1341 ####print("IPPseconds",dataOut.ippSeconds)
1342 1342 ####print("ELVALOR DE n es:", n)
1343 1343 if n == None:
1344 1344 raise ValueError("n should be specified.")
1345 1345
1346 1346 if n != None:
1347 1347 if n<2:
1348 1348 raise ValueError("n should be greater than 2")
1349 1349
1350 1350 self.n = n
1351 1351 self.__nProf = n
1352 1352
1353 1353 self.__buffer = numpy.zeros((dataOut.nChannels,
1354 1354 n,
1355 1355 dataOut.nHeights),
1356 1356 dtype='complex')
1357 1357
1358 1358 def putData(self,data):
1359 1359 '''
1360 1360 Add a profile to he __buffer and increase in one the __profiel Index
1361 1361 '''
1362 1362 self.__buffer[:,self.__profIndex,:]= data
1363 1363 self.__profIndex += 1
1364 1364 return
1365 1365
1366 1366 def pushData(self,dataOut):
1367 1367 '''
1368 1368 Return the PULSEPAIR and the profiles used in the operation
1369 1369 Affected : self.__profileIndex
1370 1370 '''
1371 1371 #----------------- Remove DC-----------------------------------
1372 1372 if self.removeDC==True:
1373 1373 mean = numpy.mean(self.__buffer,1)
1374 1374 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1375 1375 dc= numpy.tile(tmp,[1,self.__nProf,1])
1376 1376 self.__buffer = self.__buffer - dc
1377 1377 #------------------Calculo de Potencia ------------------------
1378 1378 pair0 = self.__buffer*numpy.conj(self.__buffer)
1379 1379 pair0 = pair0.real
1380 1380 lag_0 = numpy.sum(pair0,1)
1381 1381 #-----------------Calculo de Cscp------------------------------ New
1382 1382 cspc_pair01 = self.__buffer[0]*self.__buffer[1]
1383 1383 #------------------Calculo de Ruido x canal--------------------
1384 1384 self.noise = numpy.zeros(self.__nch)
1385 1385 for i in range(self.__nch):
1386 1386 daux = numpy.sort(pair0[i,:,:],axis= None)
1387 1387 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1388 1388
1389 1389 self.noise = self.noise.reshape(self.__nch,1)
1390 1390 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1391 1391 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1392 1392 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1393 1393 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1394 1394 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1395 1395 #-------------------- Power --------------------------------------------------
1396 1396 data_power = lag_0/(self.n*self.nCohInt)
1397 1397 #--------------------CCF------------------------------------------------------
1398 1398 data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt)
1399 1399 #------------------ Senal --------------------------------------------------
1400 1400 data_intensity = pair0 - noise_buffer
1401 1401 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1402 1402 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1403 1403 for i in range(self.__nch):
1404 1404 for j in range(self.__nHeis):
1405 1405 if data_intensity[i][j] < 0:
1406 1406 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1407 1407
1408 1408 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1409 1409 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1410 1410 lag_1 = numpy.sum(pair1,1)
1411 1411 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1412 1412 data_velocity = (self.lambda_/2.0)*data_freq
1413 1413
1414 1414 #---------------- Potencia promedio estimada de la Senal-----------
1415 1415 lag_0 = lag_0/self.n
1416 1416 S = lag_0-self.noise
1417 1417
1418 1418 #---------------- Frecuencia Doppler promedio ---------------------
1419 1419 lag_1 = lag_1/((self.n-1)*(pwcode))
1420 1420 R1 = numpy.abs(lag_1)
1421 1421
1422 1422 #---------------- Calculo del SNR----------------------------------
1423 1423 data_snrPP = S/self.noise
1424 1424 for i in range(self.__nch):
1425 1425 for j in range(self.__nHeis):
1426 1426 if data_snrPP[i][j] < 1.e-20:
1427 1427 data_snrPP[i][j] = 1.e-20
1428 1428
1429 1429 #----------------- Calculo del ancho espectral ----------------------
1430 1430 L = S/R1
1431 1431 L = numpy.where(L<0,1,L)
1432 1432 L = numpy.log(L)
1433 1433 tmp = numpy.sqrt(numpy.absolute(L))
1434 1434 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1435 1435 n = self.__profIndex
1436 1436
1437 1437 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1438 1438 self.__profIndex = 0
1439 1439 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n
1440 1440
1441 1441
1442 1442 def pulsePairbyProfiles(self,dataOut):
1443 1443
1444 1444 self.__dataReady = False
1445 1445 data_power = None
1446 1446 data_intensity = None
1447 1447 data_velocity = None
1448 1448 data_specwidth = None
1449 1449 data_snrPP = None
1450 1450 data_ccf = None
1451 1451 self.putData(data=dataOut.data)
1452 1452 if self.__profIndex == self.n:
1453 1453 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut)
1454 1454 self.__dataReady = True
1455 1455
1456 1456 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf
1457 1457
1458 1458
1459 1459 def pulsePairOp(self, dataOut, datatime= None):
1460 1460
1461 1461 if self.__initime == None:
1462 1462 self.__initime = datatime
1463 1463 data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut)
1464 1464 self.__lastdatatime = datatime
1465 1465
1466 1466 if data_power is None:
1467 1467 return None, None, None,None,None,None,None
1468 1468
1469 1469 avgdatatime = self.__initime
1470 1470 deltatime = datatime - self.__lastdatatime
1471 1471 self.__initime = datatime
1472 1472
1473 1473 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime
1474 1474
1475 1475 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1476 1476 #print("hey")
1477 1477 #print(dataOut.data.shape)
1478 1478 #exit(1)
1479 1479 #print(self.__profIndex)
1480 1480 if not self.isConfig:
1481 1481 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1482 1482 self.isConfig = True
1483 1483 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1484 1484 dataOut.flagNoData = True
1485 1485
1486 1486 if self.__dataReady:
1487 1487 ###print("READY ----------------------------------")
1488 1488 dataOut.nCohInt *= self.n
1489 1489 dataOut.dataPP_POW = data_intensity # S
1490 1490 dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO
1491 1491 dataOut.dataPP_DOP = data_velocity
1492 1492 dataOut.dataPP_SNR = data_snrPP
1493 1493 dataOut.dataPP_WIDTH = data_specwidth
1494 1494 dataOut.dataPP_CCF = data_ccf
1495 1495 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1496 1496 dataOut.nProfiles = int(dataOut.nProfiles/n)
1497 1497 dataOut.utctime = avgdatatime
1498 1498 dataOut.flagNoData = False
1499 1499 return dataOut
1500 1500
1501 1501 class PulsePair_vRF(Operation):
1502 1502 '''
1503 1503 Function PulsePair(Signal Power, Velocity)
1504 1504 The real component of Lag[0] provides Intensity Information
1505 1505 The imag component of Lag[1] Phase provides Velocity Information
1506 1506
1507 1507 Configuration Parameters:
1508 1508 nPRF = Number of Several PRF
1509 1509 theta = Degree Azimuth angel Boundaries
1510 1510
1511 1511 Input:
1512 1512 self.dataOut
1513 1513 lag[N]
1514 1514 Affected:
1515 1515 self.dataOut.spc
1516 1516 '''
1517 1517 isConfig = False
1518 1518 __profIndex = 0
1519 1519 __initime = None
1520 1520 __lastdatatime = None
1521 1521 __buffer = None
1522 1522 noise = None
1523 1523 __dataReady = False
1524 1524 n = None
1525 1525 __nch = 0
1526 1526 __nHeis = 0
1527 1527 removeDC = False
1528 1528 ipp = None
1529 1529 lambda_ = 0
1530 1530
1531 1531 def __init__(self,**kwargs):
1532 1532 Operation.__init__(self,**kwargs)
1533 1533
1534 1534 def setup(self, dataOut, n = None, removeDC=False):
1535 1535 '''
1536 1536 n= Numero de PRF's de entrada
1537 1537 '''
1538 1538 self.__initime = None
1539 1539 ####print("[INICIO]-setup del METODO PULSE PAIR")
1540 1540 self.__lastdatatime = 0
1541 1541 self.__dataReady = False
1542 1542 self.__buffer = 0
1543 1543 self.__profIndex = 0
1544 1544 self.noise = None
1545 1545 self.__nch = dataOut.nChannels
1546 1546 self.__nHeis = dataOut.nHeights
1547 1547 self.removeDC = removeDC
1548 1548 self.lambda_ = 3.0e8/(9345.0e6)
1549 1549 self.ippSec = dataOut.ippSeconds
1550 1550 self.nCohInt = dataOut.nCohInt
1551 1551 ####print("IPPseconds",dataOut.ippSeconds)
1552 1552 ####print("ELVALOR DE n es:", n)
1553 1553 if n == None:
1554 1554 raise ValueError("n should be specified.")
1555 1555
1556 1556 if n != None:
1557 1557 if n<2:
1558 1558 raise ValueError("n should be greater than 2")
1559 1559
1560 1560 self.n = n
1561 1561 self.__nProf = n
1562 1562
1563 1563 self.__buffer = numpy.zeros((dataOut.nChannels,
1564 1564 n,
1565 1565 dataOut.nHeights),
1566 1566 dtype='complex')
1567 1567
1568 1568 def putData(self,data):
1569 1569 '''
1570 1570 Add a profile to he __buffer and increase in one the __profiel Index
1571 1571 '''
1572 1572 self.__buffer[:,self.__profIndex,:]= data
1573 1573 self.__profIndex += 1
1574 1574 return
1575 1575
1576 1576 def putDataByBlock(self,data,n):
1577 1577 '''
1578 1578 Add a profile to he __buffer and increase in one the __profiel Index
1579 1579 '''
1580 1580 self.__buffer[:]= data
1581 1581 self.__profIndex = n
1582 1582 return
1583 1583
1584 1584 def pushData(self,dataOut):
1585 1585 '''
1586 1586 Return the PULSEPAIR and the profiles used in the operation
1587 1587 Affected : self.__profileIndex
1588 1588 NOTA:
1589 1589 1.) Calculo de Potencia
1590 1590 PdBm = 10 *log10(10*(I**2 + Q**2)) Unidades dBm
1591 1591 self.__buffer = I + Qj
1592 1592
1593 1593 2.) Data decodificada
1594 1594 Se toma como referencia el factor estimado en jrodata.py y se adiciona
1595 1595 en PulsePair solo pwcode.
1596 1596 if self.flagDecodeData:
1597 1597 pwcode = numpy.sum(self.code[0]**2)
1598 1598 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
1599 1599 3.) hildebrand_sekhon
1600 1600 Se pasa el arreglo de Potencia pair0 que contiene canales perfiles y altura dividiendole entre el
1601 1601 factor pwcode.
1602 1602 4.) data_power
1603 1603 Este parametro esta dividido por los factores: nro. perfiles, nro intCoh y pwcode
1604 1604 5.) lag_0
1605 1605 Este parametro esta dividido por los factores: nro. perfiles, nro intCoh y pwcode
1606 1606 Igual a data_power
1607 1607
1608 1608 '''
1609 1609 #----------------- Remove DC-----------------------------------
1610 1610 if self.removeDC==True:
1611 1611 mean = numpy.mean(self.__buffer,1)
1612 1612 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1613 1613 dc= numpy.tile(tmp,[1,self.__nProf,1])
1614 1614 self.__buffer = self.__buffer - dc
1615 1615 #------------------Calculo de Potencia ------------------------
1616 1616 pair0 = self.__buffer*numpy.conj(self.__buffer) * 10.0
1617 1617 pair0 = pair0.real
1618 1618 lag_0 = numpy.sum(pair0,1)
1619 1619 #-----------------Calculo de Cscp------------------------------ New
1620 1620 if len(self.__buffer)>1:
1621 1621 cspc_pair01 = self.__buffer[0]*self.__buffer[1]
1622 1622 #------------------ Data Decodificada------------------------
1623 1623 pwcode = 1
1624 1624 if dataOut.flagDecodeData == True:
1625 1625 pwcode = numpy.sum(dataOut.code[0]**2)
1626 1626 #------------------Calculo de Ruido x canal--------------------
1627 1627 self.noise = numpy.zeros(self.__nch)
1628 1628 for i in range(self.__nch):
1629 1629 daux = numpy.sort(pair0[i,:,:],axis= None)
1630 1630 self.noise[i]=hildebrand_sekhon( daux/pwcode ,self.nCohInt)
1631 1631
1632 1632 self.noise = self.noise.reshape(self.__nch,1)
1633 1633 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1634 1634 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1635 1635 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1636 1636 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1637 1637 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1638 1638 #-------------------- Power --------------------------------------------------
1639 1639 data_power = lag_0/(self.n*self.nCohInt*pwcode)
1640 1640 #--------------------CCF------------------------------------------------------
1641 1641
1642 1642 if len(self.__buffer)>1:
1643 1643 data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt)
1644 1644 else:
1645 1645 data_ccf = 0
1646 1646 #------------------ Senal --------------------------------------------------
1647 data_intensity = pair0 - noise_buffer
1647 data_intensity = pair0/pwcode - noise_buffer
1648 1648 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1649 1649 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1650 1650 for i in range(self.__nch):
1651 1651 for j in range(self.__nHeis):
1652 1652 if data_intensity[i][j] < 0:
1653 1653 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1654 1654
1655 1655 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1656 1656 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1657 1657 lag_1 = numpy.sum(pair1,1)
1658 1658 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1659 1659 data_velocity = (self.lambda_/2.0)*data_freq
1660 1660
1661 1661 #---------------- Potencia promedio estimada de la Senal-----------
1662 1662 lag_0 = data_power
1663 1663 S = lag_0-self.noise
1664 1664
1665 1665 #---------------- Frecuencia Doppler promedio ---------------------
1666 1666 lag_1 = lag_1/((self.n-1)*(pwcode))
1667 1667 R1 = numpy.abs(lag_1)
1668 1668
1669 1669 #---------------- Calculo del SNR----------------------------------
1670 1670 data_snrPP = S/self.noise
1671 1671 for i in range(self.__nch):
1672 1672 for j in range(self.__nHeis):
1673 1673 if data_snrPP[i][j] < 1.e-20:
1674 1674 data_snrPP[i][j] = 1.e-20
1675 1675
1676 1676 #----------------- Calculo del ancho espectral ----------------------
1677 1677 L = S/R1
1678 1678 L = numpy.where(L<0,1,L)
1679 1679 L = numpy.log(L)
1680 1680 tmp = numpy.sqrt(numpy.absolute(L))
1681 1681 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1682 1682 n = self.__profIndex
1683 1683
1684 1684 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1685 1685 self.__profIndex = 0
1686 1686 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n
1687 1687
1688 1688
1689 1689 def pulsePairbyProfiles(self,dataOut,n):
1690 1690
1691 1691 self.__dataReady = False
1692 1692 data_power = None
1693 1693 data_intensity = None
1694 1694 data_velocity = None
1695 1695 data_specwidth = None
1696 1696 data_snrPP = None
1697 1697 data_ccf = None
1698 1698
1699 1699 if dataOut.flagDataAsBlock:
1700 1700 self.putDataByBlock(data=dataOut.data,n=n)
1701 1701 else:
1702 1702 self.putData(data=dataOut.data)
1703 1703 if self.__profIndex == self.n:
1704 1704 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut)
1705 1705 self.__dataReady = True
1706 1706
1707 1707 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf
1708 1708
1709 1709
1710 1710 def pulsePairOp(self, dataOut, n, datatime= None):
1711 1711
1712 1712 if self.__initime == None:
1713 1713 self.__initime = datatime
1714 1714 data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut,n)
1715 1715 self.__lastdatatime = datatime
1716 1716
1717 1717 if data_power is None:
1718 1718 return None, None, None,None,None,None,None
1719 1719
1720 1720 avgdatatime = self.__initime
1721 1721 deltatime = datatime - self.__lastdatatime
1722 1722 self.__initime = datatime
1723 1723
1724 1724 return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime
1725 1725
1726 1726 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1727 1727
1728 1728 if dataOut.flagDataAsBlock:
1729 1729 n = int(dataOut.nProfiles)
1730 1730 #print("n",n)
1731 1731
1732 1732 if not self.isConfig:
1733 1733 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1734 1734 self.isConfig = True
1735 1735
1736 1736
1737 1737 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, n, dataOut.utctime)
1738 1738
1739 1739
1740 1740 dataOut.flagNoData = True
1741 1741
1742 1742 if self.__dataReady:
1743 1743 ###print("READY ----------------------------------")
1744 1744 dataOut.nCohInt *= self.n
1745 1745 dataOut.dataPP_POW = data_intensity # S
1746 1746 dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO
1747 1747 dataOut.dataPP_DOP = data_velocity
1748 1748 dataOut.dataPP_SNR = data_snrPP
1749 1749 dataOut.dataPP_WIDTH = data_specwidth
1750 1750 dataOut.dataPP_CCF = data_ccf
1751 1751 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1752 1752 dataOut.nProfiles = int(dataOut.nProfiles/n)
1753 1753 dataOut.utctime = avgdatatime
1754 1754 dataOut.flagNoData = False
1755 1755 return dataOut
1756 1756
1757 1757 # import collections
1758 1758 # from scipy.stats import mode
1759 1759 #
1760 1760 # class Synchronize(Operation):
1761 1761 #
1762 1762 # isConfig = False
1763 1763 # __profIndex = 0
1764 1764 #
1765 1765 # def __init__(self, **kwargs):
1766 1766 #
1767 1767 # Operation.__init__(self, **kwargs)
1768 1768 # # self.isConfig = False
1769 1769 # self.__powBuffer = None
1770 1770 # self.__startIndex = 0
1771 1771 # self.__pulseFound = False
1772 1772 #
1773 1773 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1774 1774 #
1775 1775 # #Read data
1776 1776 #
1777 1777 # powerdB = dataOut.getPower(channel = channel)
1778 1778 # noisedB = dataOut.getNoise(channel = channel)[0]
1779 1779 #
1780 1780 # self.__powBuffer.extend(powerdB.flatten())
1781 1781 #
1782 1782 # dataArray = numpy.array(self.__powBuffer)
1783 1783 #
1784 1784 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1785 1785 #
1786 1786 # maxValue = numpy.nanmax(filteredPower)
1787 1787 #
1788 1788 # if maxValue < noisedB + 10:
1789 1789 # #No se encuentra ningun pulso de transmision
1790 1790 # return None
1791 1791 #
1792 1792 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1793 1793 #
1794 1794 # if len(maxValuesIndex) < 2:
1795 1795 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1796 1796 # return None
1797 1797 #
1798 1798 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1799 1799 #
1800 1800 # #Seleccionar solo valores con un espaciamiento de nSamples
1801 1801 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1802 1802 #
1803 1803 # if len(pulseIndex) < 2:
1804 1804 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1805 1805 # return None
1806 1806 #
1807 1807 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1808 1808 #
1809 1809 # #remover senales que se distancien menos de 10 unidades o muestras
1810 1810 # #(No deberian existir IPP menor a 10 unidades)
1811 1811 #
1812 1812 # realIndex = numpy.where(spacing > 10 )[0]
1813 1813 #
1814 1814 # if len(realIndex) < 2:
1815 1815 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1816 1816 # return None
1817 1817 #
1818 1818 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1819 1819 # realPulseIndex = pulseIndex[realIndex]
1820 1820 #
1821 1821 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1822 1822 #
1823 1823 # print "IPP = %d samples" %period
1824 1824 #
1825 1825 # self.__newNSamples = dataOut.nHeights #int(period)
1826 1826 # self.__startIndex = int(realPulseIndex[0])
1827 1827 #
1828 1828 # return 1
1829 1829 #
1830 1830 #
1831 1831 # def setup(self, nSamples, nChannels, buffer_size = 4):
1832 1832 #
1833 1833 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1834 1834 # maxlen = buffer_size*nSamples)
1835 1835 #
1836 1836 # bufferList = []
1837 1837 #
1838 1838 # for i in range(nChannels):
1839 1839 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1840 1840 # maxlen = buffer_size*nSamples)
1841 1841 #
1842 1842 # bufferList.append(bufferByChannel)
1843 1843 #
1844 1844 # self.__nSamples = nSamples
1845 1845 # self.__nChannels = nChannels
1846 1846 # self.__bufferList = bufferList
1847 1847 #
1848 1848 # def run(self, dataOut, channel = 0):
1849 1849 #
1850 1850 # if not self.isConfig:
1851 1851 # nSamples = dataOut.nHeights
1852 1852 # nChannels = dataOut.nChannels
1853 1853 # self.setup(nSamples, nChannels)
1854 1854 # self.isConfig = True
1855 1855 #
1856 1856 # #Append new data to internal buffer
1857 1857 # for thisChannel in range(self.__nChannels):
1858 1858 # bufferByChannel = self.__bufferList[thisChannel]
1859 1859 # bufferByChannel.extend(dataOut.data[thisChannel])
1860 1860 #
1861 1861 # if self.__pulseFound:
1862 1862 # self.__startIndex -= self.__nSamples
1863 1863 #
1864 1864 # #Finding Tx Pulse
1865 1865 # if not self.__pulseFound:
1866 1866 # indexFound = self.__findTxPulse(dataOut, channel)
1867 1867 #
1868 1868 # if indexFound == None:
1869 1869 # dataOut.flagNoData = True
1870 1870 # return
1871 1871 #
1872 1872 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1873 1873 # self.__pulseFound = True
1874 1874 # self.__startIndex = indexFound
1875 1875 #
1876 1876 # #If pulse was found ...
1877 1877 # for thisChannel in range(self.__nChannels):
1878 1878 # bufferByChannel = self.__bufferList[thisChannel]
1879 1879 # #print self.__startIndex
1880 1880 # x = numpy.array(bufferByChannel)
1881 1881 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1882 1882 #
1883 1883 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1884 1884 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1885 1885 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1886 1886 #
1887 1887 # dataOut.data = self.__arrayBuffer
1888 1888 #
1889 1889 # self.__startIndex += self.__newNSamples
1890 1890 #
1891 1891 # return
General Comments 0
You need to be logged in to leave comments. Login now