##// END OF EJS Templates
El metodo y la clase selector de perfiles han sido añadidos
Miguel Valdez -
r92:bd7a5985b381
parent child
Show More
@@ -1,396 +1,452
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 def __init__(self, voltageInObj, voltageOutObj=None):
24 24 '''
25 25 Constructor
26 26 '''
27 27
28 28 self.voltageInObj = voltageInObj
29 29
30 30 if voltageOutObj == None:
31 31 self.voltageOutObj = Voltage()
32 32 else:
33 33 self.voltageOutObj = voltageOutObj
34 34
35 35 self.integratorIndex = None
36 36 self.decoderIndex = None
37 self.profSelectorIndex = None
37 38 self.writerIndex = None
38 39 self.plotterIndex = None
39 40
40 41 self.integratorList = []
41 42 self.decoderList = []
43 self.profileSelectorList = []
42 44 self.writerList = []
43 45 self.plotterList = []
44 46
45 47 def init(self):
48
46 49 self.integratorIndex = 0
47 50 self.decoderIndex = 0
51 self.profSelectorIndex = 0
48 52 self.writerIndex = 0
49 53 self.plotterIndex = 0
50 54 self.voltageOutObj.copy(self.voltageInObj)
51 55
52 def addWriter(self,wrpath):
56 def addWriter(self, wrpath):
53 57 objWriter = VoltageWriter(self.voltageOutObj)
54 58 objWriter.setup(wrpath)
55 59 self.writerList.append(objWriter)
56 60
57 61 def addPlotter(self):
58 62
59 63 plotObj = Osciloscope(self.voltageOutObj,self.plotterIndex)
60 64 self.plotterList.append(plotObj)
61 65
62 def addIntegrator(self,N):
66 def addIntegrator(self, nCohInt):
63 67
64 objCohInt = CoherentIntegrator(N)
68 objCohInt = CoherentIntegrator(nCohInt)
65 69 self.integratorList.append(objCohInt)
66 70
67 def addDecoder(self,code,ncode,nbaud):
71 def addDecoder(self, code, ncode, nbaud):
68 72
69 73 objDecoder = Decoder(code,ncode,nbaud)
70 74 self.decoderList.append(objDecoder)
71 75
76 def addProfileSelector(self, nProfiles):
77
78 objProfSelector = ProfileSelector(nProfiles)
79 self.profileSelectorList.append(objProfSelector)
80
72 81 def writeData(self,wrpath):
82
73 83 if self.voltageOutObj.flagNoData:
74 return 0
84 return 0
75 85
76 86 if len(self.writerList) <= self.writerIndex:
77 87 self.addWriter(wrpath)
78 88
79 89 self.writerList[self.writerIndex].putData()
80 90
81 91 # myWrObj = self.writerList[self.writerIndex]
82 92 # myWrObj.putData()
83 93
84 94 self.writerIndex += 1
85 95
86 96 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
87 97 if self.voltageOutObj.flagNoData:
88 return 0
98 return 0
89 99
90 100 if len(self.plotterList) <= self.plotterIndex:
91 101 self.addPlotter()
92 102
93 103 self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
94 104
95 105 self.plotterIndex += 1
96 106
97 107 def integrator(self, N):
108
98 109 if self.voltageOutObj.flagNoData:
99 return 0
110 return 0
100 111
101 112 if len(self.integratorList) <= self.integratorIndex:
102 113 self.addIntegrator(N)
103 114
104 115 myCohIntObj = self.integratorList[self.integratorIndex]
105 116 myCohIntObj.exe(self.voltageOutObj.data)
106 117
107 118 if myCohIntObj.flag:
108 119 self.voltageOutObj.data = myCohIntObj.data
109 120 self.voltageOutObj.m_ProcessingHeader.coherentInt *= N
110 121 self.voltageOutObj.flagNoData = False
111 122
112 123 else:
113 124 self.voltageOutObj.flagNoData = True
114 125
115 126 self.integratorIndex += 1
116 127
117 128 def decoder(self,code=None,type = 0):
129
118 130 if self.voltageOutObj.flagNoData:
119 return 0
131 return 0
132
120 133 if code == None:
121 134 code = self.voltageOutObj.m_RadarControllerHeader.code
122 135 ncode, nbaud = code.shape
123 136
124 137 if len(self.decoderList) <= self.decoderIndex:
125 138 self.addDecoder(code,ncode,nbaud)
126 139
127 140 myDecodObj = self.decoderList[self.decoderIndex]
128 141 myDecodObj.exe(data=self.voltageOutObj.data,type=type)
129 142
130 143 if myDecodObj.flag:
131 144 self.voltageOutObj.data = myDecodObj.data
132 145 self.voltageOutObj.flagNoData = False
133 146 else:
134 147 self.voltageOutObj.flagNoData = True
135 148
136 149 self.decoderIndex += 1
137 150
138 151
139 152 def filterByHei(self, window):
140 153 pass
141 154
142 155
143 156 def selectChannels(self, channelList):
144 157 """
145 158 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
146 159
147 160 Input:
148 161 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
149 162 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
150 163
151 164 Affected:
152 165 self.dataOutObj.datablock
153 166 self.dataOutObj.nChannels
154 167 self.dataOutObj.m_SystemHeader.numChannels
155 168 self.voltageOutObj.m_ProcessingHeader.blockSize
156 169
157 170 Return:
158 171 None
159 172 """
160 173 if not(channelList):
161 174 return
162 175
163 176 channels = 0
164 177 profiles = self.voltageOutObj.nProfiles
165 178 heights = self.voltageOutObj.m_ProcessingHeader.numHeights
166 179
167 180 #self spectra
168 181 channels = len(channelList)
169 182 data = numpy.zeros( (channels,profiles,heights), dtype='complex' )
170 183 for index,channel in enumerate(channelList):
171 184 data[index,:,:] = self.voltageOutObj.data_spc[channel,:,:]
172 185
173 186 self.voltageOutObj.datablock = data
174 187
175 188 #fill the m_ProcessingHeader.spectraComb up
176 189 channels = len(channelList)
177 190
178 191 self.voltageOutObj.channelList = channelList
179 192 self.voltageOutObj.nChannels = nchannels
180 193 self.voltageOutObj.m_ProcessingHeader.totalSpectra = nchannels
181 194 self.voltageOutObj.m_SystemHeader.numChannels = nchannels
182 195 self.voltageOutObj.m_ProcessingHeader.blockSize = data.size
183 196
184 197
185 198 def selectHeightsByValue(self, minHei, maxHei):
186 199 """
187 200 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
188 201 minHei <= height <= maxHei
189 202
190 203 Input:
191 204 minHei : valor minimo de altura a considerar
192 205 maxHei : valor maximo de altura a considerar
193 206
194 207 Affected:
195 208 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
196 209
197 210 Return:
198 211 None
199 212 """
200 213 minIndex = 0
201 214 maxIndex = 0
202 215 data = self.dataOutObj.heightList
203 216
204 217 for i,val in enumerate(data):
205 218 if val < minHei:
206 219 continue
207 220 else:
208 221 minIndex = i;
209 222 break
210 223
211 224 for i,val in enumerate(data):
212 225 if val <= maxHei:
213 226 maxIndex = i;
214 227 else:
215 228 break
216 229
217 230 self.selectHeightsByIndex(minIndex, maxIndex)
218 231
219 232
220 233 def selectHeightsByIndex(self, minIndex, maxIndex):
221 234 """
222 235 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
223 236 minIndex <= index <= maxIndex
224 237
225 238 Input:
226 239 minIndex : valor minimo de altura a considerar
227 240 maxIndex : valor maximo de altura a considerar
228 241
229 242 Affected:
230 243 self.voltageOutObj.datablock
231 244 self.voltageOutObj.m_ProcessingHeader.numHeights
232 245 self.voltageOutObj.m_ProcessingHeader.blockSize
233 246 self.voltageOutObj.heightList
234 247 self.voltageOutObj.nHeights
235 248 self.voltageOutObj.m_RadarControllerHeader.numHeights
236 249
237 250 Return:
238 251 None
239 252 """
240 253 channels = self.voltageOutObj.nChannels
241 254 profiles = self.voltageOutObj.nProfiles
242 255 newheis = maxIndex - minIndex + 1
243 256 firstHeight = 0
244 257
245 258 #voltage
246 259 data = numpy.zeros( (channels,profiles,newheis), dtype='complex' )
247 260 for i in range(channels):
248 261 data[i] = self.voltageOutObj.data_spc[i,:,minIndex:maxIndex+1]
249 262
250 263 self.voltageOutObj.datablock = data
251 264
252 265 firstHeight = self.dataOutObj.heightList[minIndex]
253 266
254 267 self.voltageOutObj.nHeights = newheis
255 268 self.voltageOutObj.m_ProcessingHeader.blockSize = data.size
256 269 self.voltageOutObj.m_ProcessingHeader.numHeights = newheis
257 270 self.voltageOutObj.m_ProcessingHeader.firstHeight = firstHeight
258 271 self.voltageOutObj.m_RadarControllerHeader = newheis
259 272
260 273 xi = firstHeight
261 274 step = self.voltageOutObj.m_ProcessingHeader.deltaHeight
262 275 xf = xi + newheis * step
263 276 self.voltageOutObj.heightList = numpy.arange(xi, xf, step)
264 277
265 278
266 def selectProfiles(self, minIndex, maxIndex):
279 def selectProfiles(self, minIndex, maxIndex, nProfiles):
267 280 """
268 281 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
269 282 minIndex <= index <= maxIndex
270 283
271 284 Input:
272 285 minIndex : valor minimo de altura a considerar
273 286 maxIndex : valor maximo de altura a considerar
274 287
275 288 Affected:
276 289 self.voltageOutObj.datablock
277 290 self.voltageOutObj.m_ProcessingHeader.numHeights
278 291 self.voltageOutObj.heightList
279 292
280 293 Return:
281 294 None
282 295 """
283 channels = self.voltageOutObj.nChannels
284 heights = self.voltageOutObj.m_ProcessingHeader.numHeights
285 newprofiles = maxIndex - minIndex + 1
286
287 #voltage
288 data = numpy.zeros( (channels,newprofiles,heights), dtype='complex' )
289 for i in range(channels):
290 data[i,:,:] = self.voltageOutObj.data_spc[i,minIndex:maxIndex+1,:]
291
292 self.voltageOutObj.datablock = data
293
294 self.voltageOutObj.m_ProcessingHeader.blockSize = data.size
295 self.voltageOutObj.nProfiles = newprofiles
296 self.voltageOutObj.m_SystemHeader.numProfiles = newprofiles
297
296
297 if self.voltageOutObj.flagNoData:
298 return 0
299
300 if self.profSelectorIndex >= len(self.profileSelectorList):
301 self.addProfileSelector(nProfiles)
302
303 profileSelectorObj = self.profileSelectorList[self.profSelectorIndex]
304
305 if profileSelectorObj.isProfileInRange(minIndex, maxIndex):
306 self.voltageOutObj.flagNoData = False
307 self.profSelectorIndex += 1
308 return 1
309
310 self.voltageOutObj.flagNoData = True
311 self.profSelectorIndex += 1
312
313 return 0
298 314
299 315 def selectNtxs(self, ntx):
300 316 pass
301 317
302 318
303 319 class Decoder:
320
304 321 def __init__(self,code, ncode, nbaud):
322
305 323 self.buffer = None
306 324 self.profCounter = 1
307 325 self.nCode = ncode
308 326 self.nBaud = nbaud
309 327 self.codeIndex = 0
310 328 self.code = code #this is a List
311 329 self.fft_code = None
312 330 self.flag = False
313 331 self.setCodeFft = False
314 332
315 333 def exe(self, data, ndata=None, type = 0):
334
316 335 if ndata == None: ndata = data.shape[1]
317 336
318 337 if type == 0:
319 338 self.convolutionInFreq(data,ndata)
320 339
321 340 if type == 1:
322 341 self.convolutionInTime(data, ndata)
323 342
324 def convolutionInFreq(self,data,ndata):
343 def convolutionInFreq(self,data, ndata):
325 344
326 345 newcode = numpy.zeros(ndata)
327 346 newcode[0:self.nBaud] = self.code[self.codeIndex]
328 347
329 348 self.codeIndex += 1
330 349
331 350 fft_data = numpy.fft.fft(data, axis=1)
332 351 fft_code = numpy.conj(numpy.fft.fft(newcode))
333 352 fft_code = fft_code.reshape(1,len(fft_code))
334 353
335 354 conv = fft_data.copy()
336 355 conv.fill(0)
337 356
338 357 conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays
339 358 # for i in range(ndata):
340 359 # conv[i,:] = fft_data[i,:]*fft_code[i]
341 360
342 361 self.data = numpy.fft.ifft(conv,axis=1)
343 362 self.flag = True
344 363
345 364 if self.profCounter == self.nCode:
346 365 self.profCounter = 0
347 366 self.codeIndex = 0
348 367
349 368 self.profCounter += 1
350 369
351 370 def convolutionInTime(self, data, ndata):
352 371
353 372 nchannel = data.shape[1]
354 373 newcode = self.code[self.codeIndex]
355 374 self.codeIndex += 1
356 375 conv = data.copy()
357 376 for i in range(nchannel):
358 377 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
359 378
360 379 self.data = conv
361 380 self.flag = True
362 381
363 382 if self.profCounter == self.nCode:
364 383 self.profCounter = 0
365 384 self.codeIndex = 0
366 385
367 386 self.profCounter += 1
368 387
369 388
370 389 class CoherentIntegrator:
390
371 391 def __init__(self, N):
392
372 393 self.profCounter = 1
373 394 self.data = None
374 395 self.buffer = None
375 396 self.flag = False
376 397 self.nCohInt = N
377 398
378 def exe(self,data):
399 def exe(self, data):
379 400
380 401 if self.buffer == None:
381 402 self.buffer = data
382 403 else:
383 404 self.buffer = self.buffer + data
384 405
385 406 if self.profCounter == self.nCohInt:
386 407 self.data = self.buffer
387 408 self.buffer = None
388 409 self.profCounter = 0
389 410 self.flag = True
390 411 else:
391 412 self.flag = False
392 413
393 414 self.profCounter += 1
394 415
395
416 class ProfileSelector():
417
418 indexProfile = None
419 # Tamaño total de los perfiles
420 nProfiles = None
421
422 def __init__(self, nProfiles):
423
424 self.indexProfile = 0
425 self.nProfiles = nProfiles
426
427 def isProfileInRange(self, minIndex, maxIndex):
428
429 if minIndex < self.indexProfile:
430 self.indexProfile += 1
431 return False
432
433 if maxIndex > self.indexProfile:
434 self.indexProfile += 1
435 return False
436
437 self.indexProfile += 1
438
439 return True
440
441 def isProfileInList(self, profileList):
442
443 if self.indexProfile not in profileList:
444 self.indexProfile += 1
445 return False
446
447 self.indexProfile += 1
448
449 return True
450
451
396 452 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now