@@ -1,696 +1,696 | |||
|
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 | import time |
|
10 | 10 | |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Model.Spectra import Spectra |
|
15 | 15 | from IO.SpectraIO import SpectraWriter |
|
16 | 16 | from Graphics.SpectraPlot import Spectrum |
|
17 | 17 | from JRONoise import Noise |
|
18 | 18 | |
|
19 | 19 | class SpectraProcessor: |
|
20 | 20 | ''' |
|
21 | 21 | classdocs |
|
22 | 22 | ''' |
|
23 | 23 | |
|
24 | 24 | dataInObj = None |
|
25 | 25 | |
|
26 | 26 | dataOutObj = None |
|
27 | 27 | |
|
28 | 28 | noiseObj = None |
|
29 | 29 | |
|
30 | 30 | integratorObjList = [] |
|
31 | 31 | |
|
32 | 32 | decoderObjList = [] |
|
33 | 33 | |
|
34 | 34 | writerObjList = [] |
|
35 | 35 | |
|
36 | 36 | plotterObjList = [] |
|
37 | 37 | |
|
38 | 38 | integratorObjIndex = None |
|
39 | 39 | |
|
40 | 40 | decoderObjIndex = None |
|
41 | 41 | |
|
42 | 42 | writerObjIndex = None |
|
43 | 43 | |
|
44 | 44 | plotterObjIndex = None |
|
45 | 45 | |
|
46 | 46 | buffer = None |
|
47 | 47 | |
|
48 | 48 | profIndex = 0 |
|
49 | 49 | |
|
50 | 50 | nFFTPoints = None |
|
51 | 51 | |
|
52 | 52 | nChannels = None |
|
53 | 53 | |
|
54 | 54 | nHeights = None |
|
55 | 55 | |
|
56 | 56 | nPairs = None |
|
57 | 57 | |
|
58 | 58 | pairList = None |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | def __init__(self): |
|
62 | 62 | ''' |
|
63 | 63 | Constructor |
|
64 | 64 | ''' |
|
65 | 65 | |
|
66 | 66 | self.integratorObjIndex = None |
|
67 | 67 | self.decoderObjIndex = None |
|
68 | 68 | self.writerObjIndex = None |
|
69 | 69 | self.plotterObjIndex = None |
|
70 | 70 | |
|
71 | 71 | self.integratorObjList = [] |
|
72 | 72 | self.decoderObjList = [] |
|
73 | 73 | self.writerObjList = [] |
|
74 | 74 | self.plotterObjList = [] |
|
75 | 75 | |
|
76 |
self.noiseObj = No |
|
|
76 | self.noiseObj = None | |
|
77 | 77 | self.buffer = None |
|
78 | 78 | self.profIndex = 0 |
|
79 | 79 | |
|
80 | 80 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
81 | 81 | |
|
82 | 82 | if dataInObj == None: |
|
83 | 83 | raise ValueError, "" |
|
84 | 84 | |
|
85 | 85 | if nFFTPoints == None: |
|
86 | 86 | raise ValueError, "" |
|
87 | 87 | |
|
88 | 88 | self.dataInObj = dataInObj |
|
89 | 89 | |
|
90 | 90 | if dataOutObj == None: |
|
91 | 91 | dataOutObj = Spectra() |
|
92 | 92 | |
|
93 | 93 | self.dataOutObj = dataOutObj |
|
94 | 94 | self.noiseObj = Noise() |
|
95 | 95 | |
|
96 | 96 | ########################################## |
|
97 | 97 | self.nFFTPoints = nFFTPoints |
|
98 | 98 | self.nChannels = self.dataInObj.nChannels |
|
99 | 99 | self.nHeights = self.dataInObj.nHeights |
|
100 | 100 | self.pairList = pairList |
|
101 | 101 | if pairList != None: |
|
102 | 102 | self.nPairs = len(pairList) |
|
103 | 103 | else: |
|
104 | 104 | self.nPairs = 0 |
|
105 | 105 | |
|
106 | 106 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
107 | 107 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
108 | 108 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
109 | 109 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
110 | 110 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
111 | 111 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
112 | 112 | |
|
113 | 113 | self.dataOutObj.dataType = self.dataInObj.dataType |
|
114 | 114 | self.dataOutObj.nPairs = self.nPairs |
|
115 | 115 | self.dataOutObj.nChannels = self.nChannels |
|
116 | 116 | self.dataOutObj.nProfiles = self.nFFTPoints |
|
117 | 117 | self.dataOutObj.nHeights = self.nHeights |
|
118 | 118 | self.dataOutObj.nFFTPoints = self.nFFTPoints |
|
119 | 119 | #self.dataOutObj.data = None |
|
120 | 120 | |
|
121 | 121 | self.dataOutObj.m_SystemHeader.numChannels = self.nChannels |
|
122 | 122 | self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints |
|
123 | 123 | |
|
124 | 124 | self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs |
|
125 | 125 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints |
|
126 | 126 | self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights |
|
127 | 127 | self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
128 | 128 | |
|
129 | 129 | spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) |
|
130 | 130 | k = 0 |
|
131 | 131 | for i in range( 0,self.nChannels*2,2 ): |
|
132 | 132 | spectraComb[i] = k |
|
133 | 133 | spectraComb[i+1] = k |
|
134 | 134 | k += 1 |
|
135 | 135 | |
|
136 | 136 | k *= 2 |
|
137 | 137 | |
|
138 | 138 | if self.pairList != None: |
|
139 | 139 | |
|
140 | 140 | for pair in self.pairList: |
|
141 | 141 | spectraComb[k] = pair[0] |
|
142 | 142 | spectraComb[k+1] = pair[1] |
|
143 | 143 | k += 2 |
|
144 | 144 | |
|
145 | 145 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
146 | 146 | |
|
147 | 147 | return self.dataOutObj |
|
148 | 148 | |
|
149 | 149 | def init(self): |
|
150 | 150 | |
|
151 | 151 | self.integratorObjIndex = 0 |
|
152 | 152 | self.decoderObjIndex = 0 |
|
153 | 153 | self.writerObjIndex = 0 |
|
154 | 154 | self.plotterObjIndex = 0 |
|
155 | 155 | |
|
156 | 156 | if self.dataInObj.type == "Voltage": |
|
157 | 157 | |
|
158 | 158 | if self.buffer == None: |
|
159 | 159 | self.buffer = numpy.zeros((self.nChannels, |
|
160 | 160 | self.nFFTPoints, |
|
161 | 161 | self.nHeights), |
|
162 | 162 | dtype='complex') |
|
163 | 163 | |
|
164 | 164 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
165 | 165 | self.profIndex += 1 |
|
166 | 166 | |
|
167 | 167 | if self.profIndex == self.nFFTPoints: |
|
168 | 168 | self.__getFft() |
|
169 | 169 | self.dataOutObj.flagNoData = False |
|
170 | 170 | |
|
171 | 171 | self.buffer = None |
|
172 | 172 | self.profIndex = 0 |
|
173 | 173 | return |
|
174 | 174 | |
|
175 | 175 | self.dataOutObj.flagNoData = True |
|
176 | 176 | |
|
177 | 177 | return |
|
178 | 178 | |
|
179 | 179 | #Other kind of data |
|
180 | 180 | if self.dataInObj.type == "Spectra": |
|
181 | 181 | self.dataOutObj.copy(self.dataInObj) |
|
182 | 182 | self.dataOutObj.flagNoData = False |
|
183 | 183 | return |
|
184 | 184 | |
|
185 | 185 | raise ValueError, "The datatype is not valid" |
|
186 | 186 | |
|
187 | 187 | def __getFft(self): |
|
188 | 188 | """ |
|
189 | 189 | Convierte valores de Voltaje a Spectra |
|
190 | 190 | |
|
191 | 191 | Affected: |
|
192 | 192 | self.dataOutObj.data_spc |
|
193 | 193 | self.dataOutObj.data_cspc |
|
194 | 194 | self.dataOutObj.data_dc |
|
195 | 195 | self.dataOutObj.heightList |
|
196 | 196 | self.dataOutObj.m_BasicHeader |
|
197 | 197 | self.dataOutObj.m_ProcessingHeader |
|
198 | 198 | self.dataOutObj.m_RadarControllerHeader |
|
199 | 199 | self.dataOutObj.m_SystemHeader |
|
200 | 200 | self.profIndex |
|
201 | 201 | self.buffer |
|
202 | 202 | self.dataOutObj.flagNoData |
|
203 | 203 | self.dataOutObj.dataType |
|
204 | 204 | self.dataOutObj.nPairs |
|
205 | 205 | self.dataOutObj.nChannels |
|
206 | 206 | self.dataOutObj.nProfiles |
|
207 | 207 | self.dataOutObj.m_SystemHeader.numChannels |
|
208 | 208 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
209 | 209 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
210 | 210 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
211 | 211 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
212 | 212 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
213 | 213 | """ |
|
214 | 214 | |
|
215 | 215 | if self.dataInObj.flagNoData: |
|
216 | 216 | return 0 |
|
217 | 217 | |
|
218 | 218 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
219 | 219 | dc = fft_volt[:,0,:] |
|
220 | 220 | |
|
221 | 221 | #calculo de self-spectra |
|
222 | 222 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
223 | 223 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
224 | 224 | spc = spc.real |
|
225 | 225 | |
|
226 | 226 | blocksize = 0 |
|
227 | 227 | blocksize += dc.size |
|
228 | 228 | blocksize += spc.size |
|
229 | 229 | |
|
230 | 230 | cspc = None |
|
231 | 231 | pairIndex = 0 |
|
232 | 232 | if self.pairList != None: |
|
233 | 233 | #calculo de cross-spectra |
|
234 | 234 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') |
|
235 | 235 | for pair in self.pairList: |
|
236 | 236 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
237 | 237 | pairIndex += 1 |
|
238 | 238 | blocksize += cspc.size |
|
239 | 239 | |
|
240 | 240 | self.dataOutObj.data_spc = spc |
|
241 | 241 | self.dataOutObj.data_cspc = cspc |
|
242 | 242 | self.dataOutObj.data_dc = dc |
|
243 | 243 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
244 | 244 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc |
|
245 | 245 | |
|
246 | 246 | # self.getNoise() |
|
247 | 247 | |
|
248 | 248 | def addWriter(self,wrpath): |
|
249 | 249 | objWriter = SpectraWriter(self.dataOutObj) |
|
250 | 250 | objWriter.setup(wrpath) |
|
251 | 251 | self.writerObjList.append(objWriter) |
|
252 | 252 | |
|
253 | 253 | def addPlotter(self,index=None): |
|
254 | 254 | if index==None: |
|
255 | 255 | index = self.plotterObjIndex |
|
256 | 256 | |
|
257 | 257 | plotObj = Spectrum(self.dataOutObj, index) |
|
258 | 258 | self.plotterObjList.append(plotObj) |
|
259 | 259 | |
|
260 | 260 | def addIntegrator(self,N,timeInterval): |
|
261 | 261 | |
|
262 | 262 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
263 | 263 | self.integratorObjList.append(objIncohInt) |
|
264 | 264 | |
|
265 | 265 | def writeData(self, wrpath): |
|
266 | 266 | if self.dataOutObj.flagNoData: |
|
267 | 267 | return 0 |
|
268 | 268 | |
|
269 | 269 | if len(self.writerObjList) <= self.writerObjIndex: |
|
270 | 270 | self.addWriter(wrpath) |
|
271 | 271 | |
|
272 | 272 | self.writerObjList[self.writerObjIndex].putData() |
|
273 | 273 | |
|
274 | 274 | self.writerObjIndex += 1 |
|
275 | 275 | |
|
276 | 276 | def plotData(self, |
|
277 | 277 | xmin=None, |
|
278 | 278 | xmax=None, |
|
279 | 279 | ymin=None, |
|
280 | 280 | ymax=None, |
|
281 | 281 | zmin=None, |
|
282 | 282 | zmax=None, |
|
283 | 283 | titleList=None, |
|
284 | 284 | xlabelList=None, |
|
285 | 285 | ylabelList=None, |
|
286 | 286 | winTitle='', |
|
287 | 287 | colormap="br_green", |
|
288 | 288 | showColorbar=False, |
|
289 | 289 | showPowerProfile=False, |
|
290 | 290 | XAxisAsTime=False, |
|
291 | 291 | save=False, |
|
292 | 292 | index=None, |
|
293 | 293 | channelList=[]): |
|
294 | 294 | |
|
295 | 295 | if self.dataOutObj.flagNoData: |
|
296 | 296 | return 0 |
|
297 | 297 | |
|
298 | 298 | if len(self.plotterObjList) <= self.plotterObjIndex: |
|
299 | 299 | self.addPlotter(index) |
|
300 | 300 | |
|
301 | 301 | self.plotterObjList[self.plotterObjIndex].plotData(xmin, |
|
302 | 302 | xmax, |
|
303 | 303 | ymin, |
|
304 | 304 | ymax, |
|
305 | 305 | zmin, |
|
306 | 306 | zmax, |
|
307 | 307 | titleList, |
|
308 | 308 | xlabelList, |
|
309 | 309 | ylabelList, |
|
310 | 310 | winTitle, |
|
311 | 311 | colormap, |
|
312 | 312 | showColorbar, |
|
313 | 313 | showPowerProfile, |
|
314 | 314 | XAxisAsTime, |
|
315 | 315 | save, |
|
316 | 316 | channelList) |
|
317 | 317 | |
|
318 | 318 | self.plotterObjIndex += 1 |
|
319 | 319 | |
|
320 | 320 | def integrator(self, N=None, timeInterval=None): |
|
321 | 321 | |
|
322 | 322 | if self.dataOutObj.flagNoData: |
|
323 | 323 | return 0 |
|
324 | 324 | |
|
325 | 325 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
326 | 326 | self.addIntegrator(N,timeInterval) |
|
327 | 327 | |
|
328 | 328 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
329 | 329 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
330 | 330 | |
|
331 | 331 | if myIncohIntObj.isReady: |
|
332 | 332 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
333 | 333 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
334 |
self.dataOutObj.m_ProcessingHeader.incoherentInt |
|
|
334 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg | |
|
335 | 335 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg |
|
336 | 336 | self.dataOutObj.flagNoData = False |
|
337 | 337 | |
|
338 | 338 | """Calcular el ruido""" |
|
339 | 339 | self.getNoise() |
|
340 | 340 | else: |
|
341 | 341 | self.dataOutObj.flagNoData = True |
|
342 | 342 | |
|
343 | 343 | self.integratorObjIndex += 1 |
|
344 | 344 | |
|
345 | 345 | |
|
346 | 346 | |
|
347 | 347 | def removeDC(self, type): |
|
348 | 348 | |
|
349 | 349 | if self.dataOutObj.flagNoData: |
|
350 | 350 | return 0 |
|
351 | 351 | |
|
352 | 352 | def removeInterference(self): |
|
353 | 353 | |
|
354 | 354 | if self.dataOutObj.flagNoData: |
|
355 | 355 | return 0 |
|
356 | 356 | |
|
357 | 357 | def removeSatellites(self): |
|
358 | 358 | |
|
359 | 359 | if self.dataOutObj.flagNoData: |
|
360 | 360 | return 0 |
|
361 | 361 | |
|
362 | 362 | def getNoise(self, type="hildebrand", parm=None): |
|
363 | 363 | |
|
364 | 364 | if parm == None: |
|
365 | 365 | parm =self.dataOutObj.m_ProcessingHeader.incoherentInt |
|
366 | 366 | |
|
367 | 367 | self.noiseObj.setNoise(self.dataOutObj.data_spc) |
|
368 | 368 | |
|
369 | 369 | if type == "hildebrand": |
|
370 | 370 | noise = self.noiseObj.byHildebrand(parm) |
|
371 | 371 | |
|
372 | 372 | if type == "window": |
|
373 | 373 | noise = self.noiseObj.byWindow(parm) |
|
374 | 374 | |
|
375 | 375 | if type == "sort": |
|
376 | 376 | noise = self.noiseObj.bySort(parm) |
|
377 | 377 | |
|
378 | 378 | self.dataOutObj.noise = noise |
|
379 | 379 | # print 10*numpy.log10(noise) |
|
380 | 380 | |
|
381 | 381 | def selectChannels(self, channelList, pairList=[]): |
|
382 | 382 | |
|
383 | 383 | channelIndexList = [] |
|
384 | 384 | |
|
385 | 385 | for channel in channelList: |
|
386 | 386 | if channel in self.dataOutObj.channelList: |
|
387 | 387 | index = self.dataOutObj.channelList.index(channel) |
|
388 | 388 | channelIndexList.append(index) |
|
389 | 389 | |
|
390 | 390 | pairIndexList = [] |
|
391 | 391 | |
|
392 | 392 | for pair in pairList: |
|
393 | 393 | if pair in self.dataOutObj.pairList: |
|
394 | 394 | index = self.dataOutObj.pairList.index(pair) |
|
395 | 395 | pairIndexList.append(index) |
|
396 | 396 | |
|
397 | 397 | self.selectChannelsByIndex(channelIndexList, pairIndexList) |
|
398 | 398 | |
|
399 | 399 | def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]): |
|
400 | 400 | """ |
|
401 | 401 | Selecciona un bloque de datos en base a canales y pares segun el |
|
402 | 402 | channelIndexList y el pairIndexList |
|
403 | 403 | |
|
404 | 404 | Input: |
|
405 | 405 | channelIndexList : lista de indices de los canales a seleccionar por ej. |
|
406 | 406 | |
|
407 | 407 | Si tenemos los canales |
|
408 | 408 | |
|
409 | 409 | self.channelList = (2,3,5,7) |
|
410 | 410 | |
|
411 | 411 | y deseamos escoger los canales (3,7) |
|
412 | 412 | entonces colocaremos el parametro |
|
413 | 413 | |
|
414 | 414 | channelndexList = (1,3) |
|
415 | 415 | |
|
416 | 416 | pairIndexList : tupla de indice depares que se desea selecionar por ej. |
|
417 | 417 | |
|
418 | 418 | Si tenemos los pares : |
|
419 | 419 | |
|
420 | 420 | ( (0,1), (0,2), (1,3), (2,5) ) |
|
421 | 421 | |
|
422 | 422 | y deseamos seleccionar los pares ((0,2), (2,5)) |
|
423 | 423 | entonces colocaremos el parametro |
|
424 | 424 | |
|
425 | 425 | pairIndexList = (1,3) |
|
426 | 426 | |
|
427 | 427 | Affected: |
|
428 | 428 | self.dataOutObj.data_spc |
|
429 | 429 | self.dataOutObj.data_cspc |
|
430 | 430 | self.dataOutObj.data_dc |
|
431 | 431 | self.dataOutObj.nChannels |
|
432 | 432 | self.dataOutObj.nPairs |
|
433 | 433 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
434 | 434 | self.dataOutObj.m_SystemHeader.numChannels |
|
435 | 435 | |
|
436 | 436 | self.dataOutObj.noise |
|
437 | 437 | Return: |
|
438 | 438 | None |
|
439 | 439 | """ |
|
440 | 440 | |
|
441 | 441 | if self.dataOutObj.flagNoData: |
|
442 | 442 | return 0 |
|
443 | 443 | |
|
444 | 444 | if pairIndexList == []: |
|
445 | 445 | pairIndexList = numpy.arange(len(self.dataOutObj.pairList)) |
|
446 | 446 | |
|
447 | 447 | nChannels = len(channelIndexList) |
|
448 | 448 | nPairs = len(pairIndexList) |
|
449 | 449 | |
|
450 | 450 | blocksize = 0 |
|
451 | 451 | #self spectra |
|
452 | 452 | spc = self.dataOutObj.data_spc[channelIndexList,:,:] |
|
453 | 453 | blocksize += spc.size |
|
454 | 454 | |
|
455 | 455 | cspc = None |
|
456 | 456 | if pairIndexList != []: |
|
457 | 457 | cspc = self.dataOutObj.data_cspc[pairIndexList,:,:] |
|
458 | 458 | blocksize += cspc.size |
|
459 | 459 | |
|
460 | 460 | #DC channel |
|
461 | 461 | dc = None |
|
462 | 462 | if self.dataOutObj.m_ProcessingHeader.flag_dc: |
|
463 | 463 | dc = self.dataOutObj.data_dc[channelIndexList,:] |
|
464 | 464 | blocksize += dc.size |
|
465 | 465 | |
|
466 | 466 | #Almacenar las combinaciones de canales y cros espectros |
|
467 | 467 | |
|
468 | 468 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) |
|
469 | 469 | i = 0 |
|
470 | 470 | for spcChannel in channelIndexList: |
|
471 | 471 | spectraComb[i] = spcChannel |
|
472 | 472 | spectraComb[i+1] = spcChannel |
|
473 | 473 | i += 2 |
|
474 | 474 | |
|
475 | 475 | if pairList != None: |
|
476 | 476 | for pair in pairList: |
|
477 | 477 | spectraComb[i] = pair[0] |
|
478 | 478 | spectraComb[i+1] = pair[1] |
|
479 | 479 | i += 2 |
|
480 | 480 | |
|
481 | 481 | ####### |
|
482 | 482 | |
|
483 | 483 | self.dataOutObj.data_spc = spc |
|
484 | 484 | self.dataOutObj.data_cspc = cspc |
|
485 | 485 | self.dataOutObj.data_dc = dc |
|
486 | 486 | self.dataOutObj.nChannels = nChannels |
|
487 | 487 | self.dataOutObj.nPairs = nPairs |
|
488 | 488 | |
|
489 | 489 | self.dataOutObj.channelIndexList = channelIndexList |
|
490 | 490 | |
|
491 | 491 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
492 | 492 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs |
|
493 | 493 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
494 | 494 | self.dataOutObj.nChannels = nChannels |
|
495 | 495 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
496 | 496 | |
|
497 | 497 | if cspc == None: |
|
498 | 498 | self.dataOutObj.m_ProcessingHeader.flag_dc = False |
|
499 | 499 | if dc == None: |
|
500 | 500 | self.dataOutObj.m_ProcessingHeader.flag_cpsc = False |
|
501 | 501 | |
|
502 | 502 | def selectHeightsByValue(self, minHei, maxHei): |
|
503 | 503 | """ |
|
504 | 504 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
505 | 505 | minHei <= height <= maxHei |
|
506 | 506 | |
|
507 | 507 | Input: |
|
508 | 508 | minHei : valor minimo de altura a considerar |
|
509 | 509 | maxHei : valor maximo de altura a considerar |
|
510 | 510 | |
|
511 | 511 | Affected: |
|
512 | 512 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
513 | 513 | |
|
514 | 514 | Return: |
|
515 | 515 | None |
|
516 | 516 | """ |
|
517 | 517 | |
|
518 | 518 | if self.dataOutObj.flagNoData: |
|
519 | 519 | return 0 |
|
520 | 520 | |
|
521 | 521 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): |
|
522 | 522 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
523 | 523 | |
|
524 | 524 | if (maxHei > self.dataOutObj.heightList[-1]): |
|
525 | 525 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
526 | 526 | |
|
527 | 527 | minIndex = 0 |
|
528 | 528 | maxIndex = 0 |
|
529 | 529 | data = self.dataOutObj.heightList |
|
530 | 530 | |
|
531 | 531 | for i,val in enumerate(data): |
|
532 | 532 | if val < minHei: |
|
533 | 533 | continue |
|
534 | 534 | else: |
|
535 | 535 | minIndex = i; |
|
536 | 536 | break |
|
537 | 537 | |
|
538 | 538 | for i,val in enumerate(data): |
|
539 | 539 | if val <= maxHei: |
|
540 | 540 | maxIndex = i; |
|
541 | 541 | else: |
|
542 | 542 | break |
|
543 | 543 | |
|
544 | 544 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
545 | 545 | |
|
546 | 546 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
547 | 547 | """ |
|
548 | 548 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
549 | 549 | minIndex <= index <= maxIndex |
|
550 | 550 | |
|
551 | 551 | Input: |
|
552 | 552 | minIndex : valor minimo de altura a considerar |
|
553 | 553 | maxIndex : valor maximo de altura a considerar |
|
554 | 554 | |
|
555 | 555 | Affected: |
|
556 | 556 | self.dataOutObj.data_spc |
|
557 | 557 | self.dataOutObj.data_cspc |
|
558 | 558 | self.dataOutObj.data_dc |
|
559 | 559 | self.dataOutObj.heightList |
|
560 | 560 | self.dataOutObj.nHeights |
|
561 | 561 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
562 | 562 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
563 | 563 | self.dataOutObj.m_ProcessingHeader.firstHeight |
|
564 | 564 | self.dataOutObj.m_RadarControllerHeader.numHeights |
|
565 | 565 | |
|
566 | 566 | Return: |
|
567 | 567 | None |
|
568 | 568 | """ |
|
569 | 569 | |
|
570 | 570 | if self.dataOutObj.flagNoData: |
|
571 | 571 | return 0 |
|
572 | 572 | |
|
573 | 573 | if (minIndex < 0) or (minIndex > maxIndex): |
|
574 | 574 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
575 | 575 | |
|
576 | 576 | if (maxIndex >= self.dataOutObj.nHeights): |
|
577 | 577 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
578 | 578 | |
|
579 | 579 | nChannels = self.dataOutObj.nChannels |
|
580 | 580 | nPairs = self.dataOutObj.nPairs |
|
581 | 581 | nProfiles = self.dataOutObj.nProfiles |
|
582 | 582 | dataType = self.dataOutObj.dataType |
|
583 | 583 | nHeights = maxIndex - minIndex + 1 |
|
584 | 584 | blockSize = 0 |
|
585 | 585 | |
|
586 | 586 | #self spectra |
|
587 | 587 | spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1] |
|
588 | 588 | blockSize += spc.size |
|
589 | 589 | |
|
590 | 590 | #cross spectra |
|
591 | 591 | cspc = None |
|
592 | 592 | if self.dataOutObj.data_cspc != None: |
|
593 | 593 | cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1] |
|
594 | 594 | blockSize += cspc.size |
|
595 | 595 | |
|
596 | 596 | #DC channel |
|
597 | 597 | dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1] |
|
598 | 598 | blockSize += dc.size |
|
599 | 599 | |
|
600 | 600 | self.dataOutObj.data_spc = spc |
|
601 | 601 | if cspc != None: |
|
602 | 602 | self.dataOutObj.data_cspc = cspc |
|
603 | 603 | self.dataOutObj.data_dc = dc |
|
604 | 604 | |
|
605 | 605 | firstHeight = self.dataOutObj.heightList[minIndex] |
|
606 | 606 | |
|
607 | 607 | self.dataOutObj.nHeights = nHeights |
|
608 | 608 | self.dataOutObj.m_ProcessingHeader.blockSize = blockSize |
|
609 | 609 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights |
|
610 | 610 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight |
|
611 | 611 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights |
|
612 | 612 | |
|
613 | 613 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] |
|
614 | 614 | |
|
615 | 615 | |
|
616 | 616 | class IncoherentIntegration: |
|
617 | 617 | |
|
618 | 618 | integ_counter = None |
|
619 | 619 | data = None |
|
620 | 620 | navg = None |
|
621 | 621 | buffer = None |
|
622 | 622 | nIncohInt = None |
|
623 | 623 | |
|
624 | 624 | def __init__(self, N = None, timeInterval = None): |
|
625 | 625 | """ |
|
626 | 626 | N |
|
627 | 627 | timeInterval - interval time [min], integer value |
|
628 | 628 | """ |
|
629 | 629 | |
|
630 | 630 | self.data = None |
|
631 | 631 | self.navg = None |
|
632 | 632 | self.buffer = None |
|
633 | 633 | self.timeOut = None |
|
634 | 634 | self.exitCondition = False |
|
635 | 635 | self.isReady = False |
|
636 | 636 | self.nIncohInt = N |
|
637 | 637 | self.integ_counter = 0 |
|
638 | 638 | if timeInterval!=None: |
|
639 | 639 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
640 | 640 | |
|
641 | 641 | if ((timeInterval==None) and (N==None)): |
|
642 | 642 | print 'N = None ; timeInterval = None' |
|
643 | 643 | sys.exit(0) |
|
644 | 644 | elif timeInterval == None: |
|
645 | 645 | self.timeFlag = False |
|
646 | 646 | else: |
|
647 | 647 | self.timeFlag = True |
|
648 | 648 | |
|
649 | 649 | |
|
650 | 650 | def exe(self,data,timeOfData): |
|
651 | 651 | """ |
|
652 | 652 | data |
|
653 | 653 | |
|
654 | 654 | timeOfData [seconds] |
|
655 | 655 | """ |
|
656 | 656 | |
|
657 | 657 | if self.timeFlag: |
|
658 | 658 | if self.timeOut == None: |
|
659 | 659 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
660 | 660 | |
|
661 | 661 | if timeOfData < self.timeOut: |
|
662 | 662 | if self.buffer == None: |
|
663 | 663 | self.buffer = data |
|
664 | 664 | else: |
|
665 | 665 | self.buffer = self.buffer + data |
|
666 | 666 | self.integ_counter += 1 |
|
667 | 667 | else: |
|
668 | 668 | self.exitCondition = True |
|
669 | 669 | |
|
670 | 670 | else: |
|
671 | 671 | if self.integ_counter < self.nIncohInt: |
|
672 | 672 | if self.buffer == None: |
|
673 | 673 | self.buffer = data |
|
674 | 674 | else: |
|
675 | 675 | self.buffer = self.buffer + data |
|
676 | 676 | |
|
677 | 677 | self.integ_counter += 1 |
|
678 | 678 | |
|
679 | 679 | if self.integ_counter == self.nIncohInt: |
|
680 | 680 | self.exitCondition = True |
|
681 | 681 | |
|
682 | 682 | if self.exitCondition: |
|
683 | 683 | self.data = self.buffer |
|
684 | 684 | self.navg = self.integ_counter |
|
685 | 685 | self.isReady = True |
|
686 | 686 | self.buffer = None |
|
687 | 687 | self.timeOut = None |
|
688 | 688 | self.integ_counter = 0 |
|
689 | 689 | self.exitCondition = False |
|
690 | 690 | |
|
691 | 691 | if self.timeFlag: |
|
692 | 692 | self.buffer = data |
|
693 | 693 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
694 | 694 | else: |
|
695 | 695 | self.isReady = False |
|
696 | 696 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now