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