##// END OF EJS Templates
Miguel Valdez -
r102:0886b164077e
parent child
Show More
@@ -1,553 +1,548
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import numpy
9 9
10 10 path = os.path.split(os.getcwd())[0]
11 11 sys.path.append(path)
12 12
13 13 from Model.Spectra import Spectra
14 14 from IO.SpectraIO import SpectraWriter
15 15 from Graphics.SpectraPlot import Spectrum
16 16
17 17
18 18 class SpectraProcessor:
19 19 '''
20 20 classdocs
21 21 '''
22 22
23 23 dataInObj = None
24 24
25 25 dataOutObj = None
26 26
27 27 integratorObjIndex = None
28 28
29 29 decoderObjIndex = None
30 30
31 31 writerObjIndex = None
32 32
33 33 plotterObjIndex = None
34 34
35 35 integratorObjList = []
36 36
37 37 decoderObjList = []
38 38
39 39 writerObjList = []
40 40
41 41 plotterObjList = []
42 42
43 43 buffer = None
44 44
45 45 ptsId = 0
46 46
47 47 nFFTPoints = None
48 48
49 49 pairList = None
50 m_Spectra= Spectra()
51
52 m_Voltage= Voltage()
53
54 m_IncoherentIntegration= IncoherentIntegration()
55 50
56 51
57 52 def __init__(self, dataInObj, dataOutObj=None):
58 53 '''
59 54 Constructor
60 55 '''
61 56 self.dataInObj = dataInObj
62 57
63 58 if dataOutObj == None:
64 59 self.dataOutObj = Spectra()
65 60 else:
66 61 self.dataOutObj = dataOutObj
67 62
68 63 self.integratorObjIndex = None
69 64 self.decoderObjIndex = None
70 65 self.writerObjIndex = None
71 66 self.plotterObjIndex = None
72 67
73 68 self.integratorObjList = []
74 69 self.decoderObjList = []
75 70 self.writerObjList = []
76 71 self.plotterObjList = []
77 72
78 73 self.buffer = None
79 74 self.ptsId = 0
80 75
81 76 def init(self, nFFTPoints, pairList=None):
82 77
83 78 self.integratorObjIndex = 0
84 79 self.decoderObjIndex = 0
85 80 self.writerObjIndex = 0
86 81 self.plotterObjIndex = 0
87 82
88 83 if nFFTPoints == None:
89 84 nFFTPoints = self.dataOutObj.nFFTPoints
90 85
91 86 self.nFFTPoints = nFFTPoints
92 87 self.pairList = pairList
93 88
94 89 if not( isinstance(self.dataInObj, Spectra) ):
95 90 self.__getFft()
96 91 else:
97 92 self.dataOutObj.copy(self.dataInObj)
98 93
99 94
100 95 def __getFft(self):
101 96 """
102 97 Convierte valores de Voltaje a Spectra
103 98
104 99 Affected:
105 100 self.dataOutObj.data_spc
106 101 self.dataOutObj.data_cspc
107 102 self.dataOutObj.data_dc
108 103 self.dataOutObj.heightList
109 104 self.dataOutObj.m_BasicHeader
110 105 self.dataOutObj.m_ProcessingHeader
111 106 self.dataOutObj.m_RadarControllerHeader
112 107 self.dataOutObj.m_SystemHeader
113 108 self.ptsId
114 109 self.buffer
115 110 self.dataOutObj.flagNoData
116 111 self.dataOutObj.dataType
117 112 self.dataOutObj.nPairs
118 113 self.dataOutObj.nChannels
119 114 self.dataOutObj.nProfiles
120 115 self.dataOutObj.m_SystemHeader.numChannels
121 116 self.dataOutObj.m_ProcessingHeader.totalSpectra
122 117 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
123 118 self.dataOutObj.m_ProcessingHeader.numHeights
124 119 self.dataOutObj.m_ProcessingHeader.spectraComb
125 120 self.dataOutObj.m_ProcessingHeader.shif_fft
126 121 """
127 122 blocksize = 0
128 123 nFFTPoints = self.nFFTPoints
129 124 nChannels, nheis = self.dataInObj.data.shape
130 125
131 126 if self.buffer == None:
132 127 self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex')
133 128
134 129 self.buffer[:,self.ptsId,:] = self.dataInObj.data
135 130 self.ptsId += 1
136 131
137 132 if self.ptsId < self.dataOutObj.nFFTPoints:
138 133 self.dataOutObj.flagNoData = True
139 134 return
140 135
141 136 fft_volt = numpy.fft.fft(self.buffer,axis=1)
142 137 dc = fft_volt[:,0,:]
143 138
144 139 #calculo de self-spectra
145 140 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
146 141 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
147 142
148 143 blocksize += dc.size
149 144 blocksize += spc.size
150 145
151 146 cspc = None
152 147 nPair = 0
153 148 if self.pairList != None:
154 149 #calculo de cross-spectra
155 150 nPairs = len(self.pairList)
156 151 cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex')
157 152 for pair in self.pairList:
158 153 cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
159 154 nPair += 1
160 155 blocksize += cspc.size
161 156
162 157 self.dataOutObj.data_spc = spc
163 158 self.dataOutObj.data_cspc = cspc
164 159 self.dataOutObj.data_dc = dc
165 160
166 161 self.ptsId = 0
167 162 self.buffer = None
168 163 self.dataOutObj.flagNoData = False
169 164
170 165 self.dataOutObj.heightList = self.dataInObj.heightList
171 166 self.dataOutObj.channelList = self.dataInObj.channelList
172 167 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
173 168 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
174 169 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
175 170 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
176 171
177 172 self.dataOutObj.dataType = self.dataInObj.dataType
178 173 self.dataOutObj.nPairs = nPair
179 174 self.dataOutObj.nChannels = nChannels
180 175 self.dataOutObj.nProfiles = nFFTPoints
181 176 self.dataOutObj.nHeights = nheis
182 177 self.dataOutObj.nFFTPoints = nFFTPoints
183 178 #self.dataOutObj.data = None
184 179
185 180 self.dataOutObj.m_SystemHeader.numChannels = nChannels
186 181 self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints
187 182
188 183 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
189 184 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair
190 185 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints
191 186 self.dataOutObj.m_ProcessingHeader.numHeights = nheis
192 187 self.dataOutObj.m_ProcessingHeader.shif_fft = True
193 188
194 189 spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1'))
195 190 k = 0
196 191 for i in range( 0,nChannels*2,2 ):
197 192 spectraComb[i] = k
198 193 spectraComb[i+1] = k
199 194 k += 1
200 195
201 196 k *= 2
202 197
203 198 if self.pairList != None:
204 199
205 200 for pair in self.pairList:
206 201 spectraComb[k] = pair[0]
207 202 spectraComb[k+1] = pair[1]
208 203 k += 2
209 204
210 205 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
211 206
212 207
213 208 def addWriter(self,wrpath):
214 209 objWriter = SpectraWriter(self.dataOutObj)
215 210 objWriter.setup(wrpath)
216 211 self.writerObjList.append(objWriter)
217 212
218 213
219 214 def addPlotter(self, index=None):
220 215
221 216 if index==None:
222 217 index = self.plotterObjIndex
223 218
224 219 plotObj = Spectrum(self.dataOutObj, index)
225 220 self.plotterObjList.append(plotObj)
226 221
227 222
228 223 def addIntegrator(self,N):
229 224
230 225 objIncohInt = IncoherentIntegration(N)
231 226 self.integratorObjList.append(objIncohInt)
232 227
233 228
234 229 def writeData(self, wrpath):
235 230 if self.dataOutObj.flagNoData:
236 231 return 0
237 232
238 233 if len(self.writerObjList) <= self.writerObjIndex:
239 234 self.addWriter(wrpath)
240 235
241 236 self.writerObjList[self.writerObjIndex].putData()
242 237
243 238 self.writerObjIndex += 1
244 239
245 240 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
246 241 if self.dataOutObj.flagNoData:
247 242 return 0
248 243
249 244 if len(self.plotterObjList) <= self.plotterObjIndex:
250 245 self.addPlotter(index)
251 246
252 247 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
253 248
254 249 self.plotterObjIndex += 1
255 250
256 251 def integrator(self, N):
257 252 if self.dataOutObj.flagNoData:
258 253 return 0
259 254
260 255 if len(self.integratorObjList) <= self.integratorObjIndex:
261 256 self.addIntegrator(N)
262 257
263 258 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
264 259 myCohIntObj.exe(self.dataOutObj.data_spc)
265 260
266 261 if myCohIntObj.flag:
267 262 self.dataOutObj.data_spc = myCohIntObj.data
268 263 self.dataOutObj.m_ProcessingHeader.incoherentInt *= N
269 264 self.dataOutObj.flagNoData = False
270 265
271 266 else:
272 267 self.dataOutObj.flagNoData = True
273 268
274 269 self.integratorObjIndex += 1
275 270
276 271 def removeDC(self, type):
277 272
278 273 if self.dataOutObj.flagNoData:
279 274 return 0
280 275 pass
281 276
282 277 def removeInterference(self):
283 278
284 279 if self.dataOutObj.flagNoData:
285 280 return 0
286 281 pass
287 282
288 283 def removeSatellites(self):
289 284
290 285 if self.dataOutObj.flagNoData:
291 286 return 0
292 287 pass
293 288
294 289 def selectChannels(self, channelList, pairList=None):
295 290 """
296 291 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
297 292
298 293 Input:
299 294 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
300 295 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
301 296
302 297 Affected:
303 298 self.dataOutObj.data_spc
304 299 self.dataOutObj.data_cspc
305 300 self.dataOutObj.data_dc
306 301 self.dataOutObj.nChannels
307 302 self.dataOutObj.nPairs
308 303 self.dataOutObj.m_ProcessingHeader.spectraComb
309 304 self.dataOutObj.m_SystemHeader.numChannels
310 305
311 306 Return:
312 307 None
313 308 """
314 309
315 310 if self.dataOutObj.flagNoData:
316 311 return 0
317 312
318 313 channelIndexList = []
319 314 for channel in channelList:
320 315 if channel in self.dataOutObj.channelList:
321 316 index = self.dataOutObj.channelList.index(channel)
322 317 channelIndexList.append(index)
323 318 continue
324 319
325 320 raise ValueError, "The value %d in channelList is not valid" %channel
326 321
327 322 nProfiles = self.dataOutObj.nProfiles
328 323 #dataType = self.dataOutObj.dataType
329 324 nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights
330 325 blocksize = 0
331 326
332 327 #self spectra
333 328 nChannels = len(channelIndexList)
334 329 spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] )
335 330
336 331 for index, channel in enumerate(channelIndexList):
337 332 spc[index,:,:] = self.dataOutObj.data_spc[index,:,:]
338 333
339 334 #DC channel
340 335 dc = numpy.zeros( (nChannels,nHeights), dtype='complex' )
341 336 for index, channel in enumerate(channelIndexList):
342 337 dc[index,:] = self.dataOutObj.data_dc[channel,:]
343 338
344 339 blocksize += dc.size
345 340 blocksize += spc.size
346 341
347 342 nPairs = 0
348 343 cspc = None
349 344
350 345 if pairList == None:
351 346 pairList = self.pairList
352 347
353 348 if (pairList != None) and (self.dataOutObj.data_cspc != None):
354 349 #cross spectra
355 350 nPairs = len(pairList)
356 351 cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' )
357 352
358 353 spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb
359 354 totalSpectra = len(spectraComb)
360 355 nchan = self.dataOutObj.nChannels
361 356 pairIndexList = []
362 357
363 358 for pair in pairList: #busco el par en la lista de pares del Spectra Combinations
364 359 for index in range(0,totalSpectra,2):
365 360 if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]:
366 361 pairIndexList.append( index/2 - nchan )
367 362
368 363 for index, pair in enumerate(pairIndexList):
369 364 cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:]
370 365 blocksize += cspc.size
371 366
372 367 else:
373 368 pairList = self.pairList
374 369 cspc = self.dataOutObj.data_cspc
375 370 if cspc != None:
376 371 blocksize += cspc.size
377 372
378 373 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
379 374 i = 0
380 375 for val in channelList:
381 376 spectraComb[i] = val
382 377 spectraComb[i+1] = val
383 378 i += 2
384 379
385 380 if pairList != None:
386 381 for pair in pairList:
387 382 spectraComb[i] = pair[0]
388 383 spectraComb[i+1] = pair[1]
389 384 i += 2
390 385
391 386 self.dataOutObj.data_spc = spc
392 387 self.dataOutObj.data_cspc = cspc
393 388 self.dataOutObj.data_dc = dc
394 389 self.dataOutObj.nChannels = nChannels
395 390 self.dataOutObj.nPairs = nPairs
396 391
397 392 self.dataOutObj.channelList = channelList
398 393
399 394 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
400 395 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
401 396 self.dataOutObj.m_SystemHeader.numChannels = nChannels
402 397 self.dataOutObj.nChannels = nChannels
403 398 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
404 399
405 400
406 401 def selectHeightsByValue(self, minHei, maxHei):
407 402 """
408 403 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
409 404 minHei <= height <= maxHei
410 405
411 406 Input:
412 407 minHei : valor minimo de altura a considerar
413 408 maxHei : valor maximo de altura a considerar
414 409
415 410 Affected:
416 411 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
417 412
418 413 Return:
419 414 None
420 415 """
421 416
422 417 if self.dataOutObj.flagNoData:
423 418 return 0
424 419
425 420 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
426 421 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
427 422
428 423 if (maxHei > self.dataOutObj.heightList[-1]):
429 424 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
430 425
431 426 minIndex = 0
432 427 maxIndex = 0
433 428 data = self.dataOutObj.heightList
434 429
435 430 for i,val in enumerate(data):
436 431 if val < minHei:
437 432 continue
438 433 else:
439 434 minIndex = i;
440 435 break
441 436
442 437 for i,val in enumerate(data):
443 438 if val <= maxHei:
444 439 maxIndex = i;
445 440 else:
446 441 break
447 442
448 443 self.selectHeightsByIndex(minIndex, maxIndex)
449 444
450 445
451 446 def selectHeightsByIndex(self, minIndex, maxIndex):
452 447 """
453 448 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
454 449 minIndex <= index <= maxIndex
455 450
456 451 Input:
457 452 minIndex : valor minimo de altura a considerar
458 453 maxIndex : valor maximo de altura a considerar
459 454
460 455 Affected:
461 456 self.dataOutObj.data_spc
462 457 self.dataOutObj.data_cspc
463 458 self.dataOutObj.data_dc
464 459 self.dataOutObj.heightList
465 460 self.dataOutObj.nHeights
466 461 self.dataOutObj.m_ProcessingHeader.numHeights
467 462 self.dataOutObj.m_ProcessingHeader.blockSize
468 463 self.dataOutObj.m_ProcessingHeader.firstHeight
469 464 self.dataOutObj.m_RadarControllerHeader.numHeights
470 465
471 466 Return:
472 467 None
473 468 """
474 469
475 470 if self.dataOutObj.flagNoData:
476 471 return 0
477 472
478 473 if (minIndex < 0) or (minIndex > maxIndex):
479 474 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
480 475
481 476 if (maxIndex >= self.dataOutObj.nHeights):
482 477 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
483 478
484 479 nChannels = self.dataOutObj.nChannels
485 480 nPairs = self.dataOutObj.nPairs
486 481 nProfiles = self.dataOutObj.nProfiles
487 482 dataType = self.dataOutObj.dataType
488 483 nHeights = maxIndex - minIndex + 1
489 484 blockSize = 0
490 485
491 486 #self spectra
492 487 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
493 488 blockSize += spc.size
494 489
495 490 #cross spectra
496 491 cspc = None
497 492 if self.dataOutObj.data_cspc != None:
498 493 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
499 494 blockSize += cspc.size
500 495
501 496 #DC channel
502 497 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
503 498 blockSize += dc.size
504 499
505 500 self.dataOutObj.data_spc = spc
506 501 if cspc != None:
507 502 self.dataOutObj.data_cspc = cspc
508 503 self.dataOutObj.data_dc = dc
509 504
510 505 firstHeight = self.dataOutObj.heightList[minIndex]
511 506
512 507 self.dataOutObj.nHeights = nHeights
513 508 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
514 509 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
515 510 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
516 511 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
517 512
518 513 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
519 514
520 515
521 516 class IncoherentIntegration:
522 517
523 518 profCounter = 1
524 519 data = None
525 520 buffer = None
526 521 flag = False
527 522 nIncohInt = None
528 523
529 524 def __init__(self, N):
530 525
531 526 self.profCounter = 1
532 527 self.data = None
533 528 self.buffer = None
534 529 self.flag = False
535 530 self.nIncohInt = N
536 531
537 532 def exe(self,data):
538 533
539 534 if self.buffer == None:
540 535 self.buffer = data
541 536 else:
542 537 self.buffer = self.buffer + data
543 538
544 539 if self.profCounter == self.nIncohInt:
545 540 self.data = self.buffer
546 541 self.buffer = None
547 542 self.profCounter = 0
548 543 self.flag = True
549 544 else:
550 545 self.flag = False
551 546
552 547 self.profCounter += 1
553 548
@@ -1,537 +1,531
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 import os, sys
9 9 import numpy
10 10
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from Model.Voltage import Voltage
15 15 from IO.VoltageIO import VoltageWriter
16 16 from Graphics.VoltagePlot import Osciloscope
17 17
18 18 class VoltageProcessor:
19 19 '''
20 20 classdocs
21 21 '''
22 22
23 23 dataInObj = None
24 24 dataOutObj = None
25 25
26 26 integratorObjIndex = None
27 27 decoderObjIndex = None
28 28 profSelectorObjIndex = None
29 29 writerObjIndex = None
30 30 plotterObjIndex = None
31 31 flipIndex = None
32 32
33 33 integratorObjList = []
34 34 decoderObjList = []
35 35 profileSelectorObjList = []
36 36 writerObjList = []
37 37 plotterObjList = []
38 38 m_Voltage= Voltage()
39
40 m_ProfileSelector = ProfileSelector()
41
42 m_Decoder = Decoder()
43
44 m_CoherentIntegrator = CoherentIntegrator()
45 39
46 40 def __init__(self, dataInObj, dataOutObj=None):
47 41 '''
48 42 Constructor
49 43 '''
50 44
51 45 self.dataInObj = dataInObj
52 46
53 47 if dataOutObj == None:
54 48 self.dataOutObj = Voltage()
55 49 else:
56 50 self.dataOutObj = dataOutObj
57 51
58 52 self.integratorObjIndex = None
59 53 self.decoderObjIndex = None
60 54 self.profSelectorObjIndex = None
61 55 self.writerObjIndex = None
62 56 self.plotterObjIndex = None
63 57 self.flipIndex = 1
64 58 self.integratorObjList = []
65 59 self.decoderObjList = []
66 60 self.profileSelectorObjList = []
67 61 self.writerObjList = []
68 62 self.plotterObjList = []
69 63
70 64 def init(self):
71 65
72 66 self.integratorObjIndex = 0
73 67 self.decoderObjIndex = 0
74 68 self.profSelectorObjIndex = 0
75 69 self.writerObjIndex = 0
76 70 self.plotterObjIndex = 0
77 71 self.dataOutObj.copy(self.dataInObj)
78 72
79 73 if self.profSelectorObjIndex != None:
80 74 for profSelObj in self.profileSelectorObjList:
81 75 profSelObj.incIndex()
82 76
83 77 def addWriter(self, wrpath):
84 78 objWriter = VoltageWriter(self.dataOutObj)
85 79 objWriter.setup(wrpath)
86 80 self.writerObjList.append(objWriter)
87 81
88 82 def addPlotter(self):
89 83
90 84 plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex)
91 85 self.plotterObjList.append(plotObj)
92 86
93 87 def addIntegrator(self, nCohInt):
94 88
95 89 objCohInt = CoherentIntegrator(nCohInt)
96 90 self.integratorObjList.append(objCohInt)
97 91
98 92 def addDecoder(self, code, ncode, nbaud):
99 93
100 94 objDecoder = Decoder(code,ncode,nbaud)
101 95 self.decoderObjList.append(objDecoder)
102 96
103 97 def addProfileSelector(self, nProfiles):
104 98
105 99 objProfSelector = ProfileSelector(nProfiles)
106 100 self.profileSelectorObjList.append(objProfSelector)
107 101
108 102 def writeData(self,wrpath):
109 103
110 104 if self.dataOutObj.flagNoData:
111 105 return 0
112 106
113 107 if len(self.writerObjList) <= self.writerObjIndex:
114 108 self.addWriter(wrpath)
115 109
116 110 self.writerObjList[self.writerObjIndex].putData()
117 111
118 112 # myWrObj = self.writerObjList[self.writerObjIndex]
119 113 # myWrObj.putData()
120 114
121 115 self.writerObjIndex += 1
122 116
123 117 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
124 118 if self.dataOutObj.flagNoData:
125 119 return 0
126 120
127 121 if len(self.plotterObjList) <= self.plotterObjIndex:
128 122 self.addPlotter()
129 123
130 124 self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
131 125
132 126 self.plotterObjIndex += 1
133 127
134 128 def integrator(self, N):
135 129
136 130 if self.dataOutObj.flagNoData:
137 131 return 0
138 132
139 133 if len(self.integratorObjList) <= self.integratorObjIndex:
140 134 self.addIntegrator(N)
141 135
142 136 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
143 137 myCohIntObj.exe(self.dataOutObj.data)
144 138
145 139 if myCohIntObj.flag:
146 140 self.dataOutObj.data = myCohIntObj.data
147 141 self.dataOutObj.m_ProcessingHeader.coherentInt *= N
148 142 self.dataOutObj.flagNoData = False
149 143
150 144 else:
151 145 self.dataOutObj.flagNoData = True
152 146
153 147 self.integratorObjIndex += 1
154 148
155 149 def decoder(self,code=None,type = 0):
156 150
157 151 if self.dataOutObj.flagNoData:
158 152 return 0
159 153
160 154 if code == None:
161 155 code = self.dataOutObj.m_RadarControllerHeader.code
162 156 ncode, nbaud = code.shape
163 157
164 158 if len(self.decoderObjList) <= self.decoderObjIndex:
165 159 self.addDecoder(code,ncode,nbaud)
166 160
167 161 myDecodObj = self.decoderObjList[self.decoderObjIndex]
168 162 myDecodObj.exe(data=self.dataOutObj.data,type=type)
169 163
170 164 if myDecodObj.flag:
171 165 self.dataOutObj.data = myDecodObj.data
172 166 self.dataOutObj.flagNoData = False
173 167 else:
174 168 self.dataOutObj.flagNoData = True
175 169
176 170 self.decoderObjIndex += 1
177 171
178 172
179 173 def filterByHei(self, window):
180 174 if window == None:
181 175 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
182 176
183 177 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
184 178 dim1 = self.dataOutObj.data.shape[0]
185 179 dim2 = self.dataOutObj.data.shape[1]
186 180 r = dim2 % window
187 181
188 182 buffer = self.dataOutObj.data[:,0:dim2-r]
189 183 buffer = buffer.reshape(dim1,dim2/window,window)
190 184 buffer = numpy.sum(buffer,2)
191 185 self.dataOutObj.data = buffer
192 186
193 187 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
194 188 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
195 189
196 190 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
197 191
198 192 #self.dataOutObj.heightList es un numpy.array
199 193 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
200 194
201 195 def deFlip(self):
202 196 self.dataOutObj.data *= self.flipIndex
203 197 self.flipIndex *= -1.
204 198
205 199 def selectChannels(self, channelList):
206 200 """
207 201 Selecciona un bloque de datos en base a canales segun el channelList
208 202
209 203 Input:
210 204 channelList : lista sencilla de canales a seleccionar por ej. [2,3,7]
211 205
212 206 Affected:
213 207 self.dataOutObj.data
214 208 self.dataOutObj.channelList
215 209 self.dataOutObj.nChannels
216 210 self.dataOutObj.m_ProcessingHeader.totalSpectra
217 211 self.dataOutObj.m_SystemHeader.numChannels
218 212 self.dataOutObj.m_ProcessingHeader.blockSize
219 213
220 214 Return:
221 215 None
222 216 """
223 217 if self.dataOutObj.flagNoData:
224 218 return 0
225 219
226 220 for channel in channelList:
227 221 if channel not in self.dataOutObj.channelList:
228 222 raise ValueError, "The value %d in channelList is not valid" %channel
229 223
230 224 nChannels = len(channelList)
231 225
232 226 data = self.dataOutObj.data[channelList,:]
233 227
234 228 self.dataOutObj.data = data
235 229 self.dataOutObj.channelList = channelList
236 230 self.dataOutObj.nChannels = nChannels
237 231
238 232 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels
239 233 self.dataOutObj.m_SystemHeader.numChannels = nChannels
240 234 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
241 235 return 1
242 236
243 237
244 238 def selectHeightsByValue(self, minHei, maxHei):
245 239 """
246 240 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
247 241 minHei <= height <= maxHei
248 242
249 243 Input:
250 244 minHei : valor minimo de altura a considerar
251 245 maxHei : valor maximo de altura a considerar
252 246
253 247 Affected:
254 248 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
255 249
256 250 Return:
257 251 1 si el metodo se ejecuto con exito caso contrario devuelve 0
258 252 """
259 253 if self.dataOutObj.flagNoData:
260 254 return 0
261 255
262 256 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
263 257 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
264 258
265 259 if (maxHei > self.dataOutObj.heightList[-1]):
266 260 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
267 261
268 262 minIndex = 0
269 263 maxIndex = 0
270 264 data = self.dataOutObj.heightList
271 265
272 266 for i,val in enumerate(data):
273 267 if val < minHei:
274 268 continue
275 269 else:
276 270 minIndex = i;
277 271 break
278 272
279 273 for i,val in enumerate(data):
280 274 if val <= maxHei:
281 275 maxIndex = i;
282 276 else:
283 277 break
284 278
285 279 self.selectHeightsByIndex(minIndex, maxIndex)
286 280 return 1
287 281
288 282
289 283 def selectHeightsByIndex(self, minIndex, maxIndex):
290 284 """
291 285 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
292 286 minIndex <= index <= maxIndex
293 287
294 288 Input:
295 289 minIndex : valor de indice minimo de altura a considerar
296 290 maxIndex : valor de indice maximo de altura a considerar
297 291
298 292 Affected:
299 293 self.dataOutObj.data
300 294 self.dataOutObj.heightList
301 295 self.dataOutObj.nHeights
302 296 self.dataOutObj.m_ProcessingHeader.blockSize
303 297 self.dataOutObj.m_ProcessingHeader.numHeights
304 298 self.dataOutObj.m_ProcessingHeader.firstHeight
305 299 self.dataOutObj.m_RadarControllerHeader
306 300
307 301 Return:
308 302 1 si el metodo se ejecuto con exito caso contrario devuelve 0
309 303 """
310 304 if self.dataOutObj.flagNoData:
311 305 return 0
312 306
313 307 if (minIndex < 0) or (minIndex > maxIndex):
314 308 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
315 309
316 310 if (maxIndex >= self.dataOutObj.nHeights):
317 311 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
318 312
319 313 nHeights = maxIndex - minIndex + 1
320 314
321 315 #voltage
322 316 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
323 317
324 318 firstHeight = self.dataOutObj.heightList[minIndex]
325 319
326 320 self.dataOutObj.data = data
327 321 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
328 322 self.dataOutObj.nHeights = nHeights
329 323 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
330 324 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
331 325 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
332 326 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
333 327 return 1
334 328
335 329 def selectProfilesByValue(self,indexList, nProfiles):
336 330 if self.dataOutObj.flagNoData:
337 331 return 0
338 332
339 333 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
340 334 self.addProfileSelector(nProfiles)
341 335
342 336 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
343 337
344 338 if not(profileSelectorObj.isProfileInList(indexList)):
345 339 self.dataOutObj.flagNoData = True
346 340 self.profSelectorObjIndex += 1
347 341 return 0
348 342
349 343 self.dataOutObj.flagNoData = False
350 344 self.profSelectorObjIndex += 1
351 345
352 346 return 1
353 347
354 348
355 349 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
356 350 """
357 351 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
358 352 minIndex <= index <= maxIndex
359 353
360 354 Input:
361 355 minIndex : valor de indice minimo de perfil a considerar
362 356 maxIndex : valor de indice maximo de perfil a considerar
363 357 nProfiles : numero de profiles
364 358
365 359 Affected:
366 360 self.dataOutObj.flagNoData
367 361 self.profSelectorObjIndex
368 362
369 363 Return:
370 364 1 si el metodo se ejecuto con exito caso contrario devuelve 0
371 365 """
372 366
373 367 if self.dataOutObj.flagNoData:
374 368 return 0
375 369
376 370 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
377 371 self.addProfileSelector(nProfiles)
378 372
379 373 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
380 374
381 375 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
382 376 self.dataOutObj.flagNoData = True
383 377 self.profSelectorObjIndex += 1
384 378 return 0
385 379
386 380 self.dataOutObj.flagNoData = False
387 381 self.profSelectorObjIndex += 1
388 382
389 383 return 1
390 384
391 385 def selectNtxs(self, ntx):
392 386 pass
393 387
394 388
395 389 class Decoder:
396 390
397 391 data = None
398 392 profCounter = 1
399 393 nCode = None
400 394 nBaud = None
401 395 codeIndex = 0
402 396 code = None
403 397 flag = False
404 398
405 399 def __init__(self,code, ncode, nbaud):
406 400
407 401 self.data = None
408 402 self.profCounter = 1
409 403 self.nCode = ncode
410 404 self.nBaud = nbaud
411 405 self.codeIndex = 0
412 406 self.code = code #this is a List
413 407 self.flag = False
414 408
415 409 def exe(self, data, ndata=None, type = 0):
416 410
417 411 if ndata == None: ndata = data.shape[1]
418 412
419 413 if type == 0:
420 414 self.convolutionInFreq(data,ndata)
421 415
422 416 if type == 1:
423 417 self.convolutionInTime(data, ndata)
424 418
425 419 def convolutionInFreq(self,data, ndata):
426 420
427 421 newcode = numpy.zeros(ndata)
428 422 newcode[0:self.nBaud] = self.code[self.codeIndex]
429 423
430 424 self.codeIndex += 1
431 425
432 426 fft_data = numpy.fft.fft(data, axis=1)
433 427 fft_code = numpy.conj(numpy.fft.fft(newcode))
434 428 fft_code = fft_code.reshape(1,len(fft_code))
435 429
436 430 conv = fft_data.copy()
437 431 conv.fill(0)
438 432
439 433 conv = fft_data*fft_code
440 434
441 435 self.data = numpy.fft.ifft(conv,axis=1)
442 436 self.flag = True
443 437
444 438 if self.profCounter == self.nCode:
445 439 self.profCounter = 0
446 440 self.codeIndex = 0
447 441
448 442 self.profCounter += 1
449 443
450 444 def convolutionInTime(self, data, ndata):
451 445
452 446 nchannel = data.shape[1]
453 447 newcode = self.code[self.codeIndex]
454 448 self.codeIndex += 1
455 449 conv = data.copy()
456 450 for i in range(nchannel):
457 451 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
458 452
459 453 self.data = conv
460 454 self.flag = True
461 455
462 456 if self.profCounter == self.nCode:
463 457 self.profCounter = 0
464 458 self.codeIndex = 0
465 459
466 460 self.profCounter += 1
467 461
468 462
469 463 class CoherentIntegrator:
470 464
471 465 profCounter = 1
472 466 data = None
473 467 buffer = None
474 468 flag = False
475 469 nCohInt = None
476 470
477 471 def __init__(self, N):
478 472
479 473 self.profCounter = 1
480 474 self.data = None
481 475 self.buffer = None
482 476 self.flag = False
483 477 self.nCohInt = N
484 478
485 479 def exe(self, data):
486 480
487 481 if self.buffer == None:
488 482 self.buffer = data
489 483 else:
490 484 self.buffer = self.buffer + data
491 485
492 486 if self.profCounter == self.nCohInt:
493 487 self.data = self.buffer
494 488 self.buffer = None
495 489 self.profCounter = 0
496 490 self.flag = True
497 491 else:
498 492 self.flag = False
499 493
500 494 self.profCounter += 1
501 495
502 496 class ProfileSelector:
503 497
504 498 profileIndex = None
505 499 # Tamanho total de los perfiles
506 500 nProfiles = None
507 501
508 502 def __init__(self, nProfiles):
509 503
510 504 self.profileIndex = 0
511 505 self.nProfiles = nProfiles
512 506
513 507 def incIndex(self):
514 508 self.profileIndex += 1
515 509
516 510 if self.profileIndex >= self.nProfiles:
517 511 self.profileIndex = 0
518 512
519 513 def isProfileInRange(self, minIndex, maxIndex):
520 514
521 515 if self.profileIndex < minIndex:
522 516 return False
523 517
524 518 if self.profileIndex > maxIndex:
525 519 return False
526 520
527 521 return True
528 522
529 523 def isProfileInList(self, profileList):
530 524
531 525 if self.profileIndex not in profileList:
532 526 return False
533 527
534 528 return True
535 529
536 530
537 531 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now