This diff has been collapsed as it changes many lines, (736 lines changed) Show them Hide them | |||||
@@ -0,0 +1,736 | |||||
|
1 | import numpy | |||
|
2 | ||||
|
3 | from jroproc_base import ProcessingUnit, Operation | |||
|
4 | from schainpy.model.data.jrodata import Spectra | |||
|
5 | from schainpy.model.data.jrodata import hildebrand_sekhon | |||
|
6 | ||||
|
7 | class SpectraAFCProc(ProcessingUnit): | |||
|
8 | ||||
|
9 | def __init__(self): | |||
|
10 | ||||
|
11 | ProcessingUnit.__init__(self) | |||
|
12 | ||||
|
13 | self.buffer = None | |||
|
14 | self.firstdatatime = None | |||
|
15 | self.profIndex = 0 | |||
|
16 | self.dataOut = Spectra() | |||
|
17 | self.id_min = None | |||
|
18 | self.id_max = None | |||
|
19 | ||||
|
20 | def __updateSpecFromVoltage(self): | |||
|
21 | ||||
|
22 | self.dataOut.plotting = "spectra_acf" | |||
|
23 | ||||
|
24 | self.dataOut.timeZone = self.dataIn.timeZone | |||
|
25 | self.dataOut.dstFlag = self.dataIn.dstFlag | |||
|
26 | self.dataOut.errorCount = self.dataIn.errorCount | |||
|
27 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |||
|
28 | ||||
|
29 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |||
|
30 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |||
|
31 | self.dataOut.ippSeconds = self.dataIn.getDeltaH()*(10**-6)/0.15 | |||
|
32 | ||||
|
33 | self.dataOut.channelList = self.dataIn.channelList | |||
|
34 | self.dataOut.heightList = self.dataIn.heightList | |||
|
35 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |||
|
36 | ||||
|
37 | self.dataOut.nBaud = self.dataIn.nBaud | |||
|
38 | self.dataOut.nCode = self.dataIn.nCode | |||
|
39 | self.dataOut.code = self.dataIn.code | |||
|
40 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |||
|
41 | ||||
|
42 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |||
|
43 | self.dataOut.utctime = self.firstdatatime | |||
|
44 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |||
|
45 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |||
|
46 | self.dataOut.flagShiftFFT = False | |||
|
47 | ||||
|
48 | self.dataOut.nCohInt = self.dataIn.nCohInt | |||
|
49 | self.dataOut.nIncohInt = 1 | |||
|
50 | ||||
|
51 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |||
|
52 | ||||
|
53 | self.dataOut.frequency = self.dataIn.frequency | |||
|
54 | self.dataOut.realtime = self.dataIn.realtime | |||
|
55 | ||||
|
56 | self.dataOut.azimuth = self.dataIn.azimuth | |||
|
57 | self.dataOut.zenith = self.dataIn.zenith | |||
|
58 | ||||
|
59 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |||
|
60 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |||
|
61 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |||
|
62 | ||||
|
63 | def __decodeData(self, nProfiles, code): | |||
|
64 | ||||
|
65 | if code is None: | |||
|
66 | return | |||
|
67 | ||||
|
68 | for i in range(nProfiles): | |||
|
69 | self.buffer[:,i,:] = self.buffer[:,i,:]*code[0][i] | |||
|
70 | ||||
|
71 | def __getFft(self): | |||
|
72 | """ | |||
|
73 | Convierte valores de Voltaje a Spectra | |||
|
74 | ||||
|
75 | Affected: | |||
|
76 | self.dataOut.data_spc | |||
|
77 | self.dataOut.data_cspc | |||
|
78 | self.dataOut.data_dc | |||
|
79 | self.dataOut.heightList | |||
|
80 | self.profIndex | |||
|
81 | self.buffer | |||
|
82 | self.dataOut.flagNoData | |||
|
83 | """ | |||
|
84 | nsegments = self.dataOut.nHeights | |||
|
85 | ||||
|
86 | _fft_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, nsegments), dtype='complex') | |||
|
87 | ||||
|
88 | for i in range(nsegments): | |||
|
89 | try: | |||
|
90 | _fft_buffer[:,:,i] = self.buffer[:,i:i+self.dataOut.nProfiles] | |||
|
91 | ||||
|
92 | if self.code is not None: | |||
|
93 | _fft_buffer[:,:,i] = _fft_buffer[:,:,i]*self.code[0] | |||
|
94 | except: | |||
|
95 | pass | |||
|
96 | ||||
|
97 | fft_volt = numpy.fft.fft(_fft_buffer, n=self.dataOut.nFFTPoints, axis=1) | |||
|
98 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |||
|
99 | dc = fft_volt[:,0,:] | |||
|
100 | ||||
|
101 | #calculo de self-spectra | |||
|
102 | # fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) | |||
|
103 | spc = fft_volt * numpy.conjugate(fft_volt) | |||
|
104 | ||||
|
105 | data = numpy.fft.ifft(spc, axis=1) | |||
|
106 | data = numpy.fft.fftshift(data, axes=(1,)) | |||
|
107 | ||||
|
108 | spc = data | |||
|
109 | ||||
|
110 | blocksize = 0 | |||
|
111 | blocksize += dc.size | |||
|
112 | blocksize += spc.size | |||
|
113 | ||||
|
114 | cspc = None | |||
|
115 | pairIndex = 0 | |||
|
116 | ||||
|
117 | if self.dataOut.pairsList != None: | |||
|
118 | #calculo de cross-spectra | |||
|
119 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |||
|
120 | for pair in self.dataOut.pairsList: | |||
|
121 | if pair[0] not in self.dataOut.channelList: | |||
|
122 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) | |||
|
123 | if pair[1] not in self.dataOut.channelList: | |||
|
124 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) | |||
|
125 | ||||
|
126 | chan_index0 = self.dataOut.channelList.index(pair[0]) | |||
|
127 | chan_index1 = self.dataOut.channelList.index(pair[1]) | |||
|
128 | ||||
|
129 | cspc[pairIndex,:,:] = fft_volt[chan_index0,:,:] * numpy.conjugate(fft_volt[chan_index1,:,:]) | |||
|
130 | pairIndex += 1 | |||
|
131 | blocksize += cspc.size | |||
|
132 | ||||
|
133 | self.dataOut.data_spc = spc | |||
|
134 | self.dataOut.data_cspc = cspc | |||
|
135 | self.dataOut.data_dc = dc | |||
|
136 | self.dataOut.blockSize = blocksize | |||
|
137 | self.dataOut.flagShiftFFT = True | |||
|
138 | ||||
|
139 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=1, nBaud=1): | |||
|
140 | ||||
|
141 | self.dataOut.flagNoData = True | |||
|
142 | ||||
|
143 | if code is not None: | |||
|
144 | self.code = numpy.array(code).reshape(nCode,nBaud) | |||
|
145 | else: | |||
|
146 | self.code = None | |||
|
147 | ||||
|
148 | if self.dataIn.type == "Voltage": | |||
|
149 | ||||
|
150 | if nFFTPoints == None: | |||
|
151 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" | |||
|
152 | ||||
|
153 | if nProfiles == None: | |||
|
154 | nProfiles = nFFTPoints | |||
|
155 | ||||
|
156 | self.dataOut.ippFactor = 1 | |||
|
157 | ||||
|
158 | self.dataOut.nFFTPoints = nFFTPoints | |||
|
159 | self.dataOut.nProfiles = nProfiles | |||
|
160 | self.dataOut.pairsList = pairsList | |||
|
161 | ||||
|
162 | # if self.buffer is None: | |||
|
163 | # self.buffer = numpy.zeros( (self.dataIn.nChannels, nProfiles, self.dataIn.nHeights), | |||
|
164 | # dtype='complex') | |||
|
165 | ||||
|
166 | if not self.dataIn.flagDataAsBlock: | |||
|
167 | self.buffer = self.dataIn.data.copy() | |||
|
168 | ||||
|
169 | # for i in range(self.dataIn.nHeights): | |||
|
170 | # self.buffer[:, self.profIndex, self.profIndex:] = voltage_data[:,:self.dataIn.nHeights - self.profIndex] | |||
|
171 | # | |||
|
172 | # self.profIndex += 1 | |||
|
173 | ||||
|
174 | else: | |||
|
175 | raise ValueError, "" | |||
|
176 | ||||
|
177 | self.firstdatatime = self.dataIn.utctime | |||
|
178 | ||||
|
179 | self.profIndex == nProfiles | |||
|
180 | ||||
|
181 | self.__updateSpecFromVoltage() | |||
|
182 | ||||
|
183 | self.__getFft() | |||
|
184 | ||||
|
185 | self.dataOut.flagNoData = False | |||
|
186 | ||||
|
187 | return True | |||
|
188 | ||||
|
189 | raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) | |||
|
190 | ||||
|
191 | def __selectPairs(self, pairsList): | |||
|
192 | ||||
|
193 | if channelList == None: | |||
|
194 | return | |||
|
195 | ||||
|
196 | pairsIndexListSelected = [] | |||
|
197 | ||||
|
198 | for thisPair in pairsList: | |||
|
199 | ||||
|
200 | if thisPair not in self.dataOut.pairsList: | |||
|
201 | continue | |||
|
202 | ||||
|
203 | pairIndex = self.dataOut.pairsList.index(thisPair) | |||
|
204 | ||||
|
205 | pairsIndexListSelected.append(pairIndex) | |||
|
206 | ||||
|
207 | if not pairsIndexListSelected: | |||
|
208 | self.dataOut.data_cspc = None | |||
|
209 | self.dataOut.pairsList = [] | |||
|
210 | return | |||
|
211 | ||||
|
212 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |||
|
213 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |||
|
214 | ||||
|
215 | return | |||
|
216 | ||||
|
217 | def __selectPairsByChannel(self, channelList=None): | |||
|
218 | ||||
|
219 | if channelList == None: | |||
|
220 | return | |||
|
221 | ||||
|
222 | pairsIndexListSelected = [] | |||
|
223 | for pairIndex in self.dataOut.pairsIndexList: | |||
|
224 | #First pair | |||
|
225 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |||
|
226 | continue | |||
|
227 | #Second pair | |||
|
228 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |||
|
229 | continue | |||
|
230 | ||||
|
231 | pairsIndexListSelected.append(pairIndex) | |||
|
232 | ||||
|
233 | if not pairsIndexListSelected: | |||
|
234 | self.dataOut.data_cspc = None | |||
|
235 | self.dataOut.pairsList = [] | |||
|
236 | return | |||
|
237 | ||||
|
238 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |||
|
239 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |||
|
240 | ||||
|
241 | return | |||
|
242 | ||||
|
243 | def selectChannels(self, channelList): | |||
|
244 | ||||
|
245 | channelIndexList = [] | |||
|
246 | ||||
|
247 | for channel in channelList: | |||
|
248 | if channel not in self.dataOut.channelList: | |||
|
249 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) | |||
|
250 | ||||
|
251 | index = self.dataOut.channelList.index(channel) | |||
|
252 | channelIndexList.append(index) | |||
|
253 | ||||
|
254 | self.selectChannelsByIndex(channelIndexList) | |||
|
255 | ||||
|
256 | def selectChannelsByIndex(self, channelIndexList): | |||
|
257 | """ | |||
|
258 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |||
|
259 | ||||
|
260 | Input: | |||
|
261 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |||
|
262 | ||||
|
263 | Affected: | |||
|
264 | self.dataOut.data_spc | |||
|
265 | self.dataOut.channelIndexList | |||
|
266 | self.dataOut.nChannels | |||
|
267 | ||||
|
268 | Return: | |||
|
269 | None | |||
|
270 | """ | |||
|
271 | ||||
|
272 | for channelIndex in channelIndexList: | |||
|
273 | if channelIndex not in self.dataOut.channelIndexList: | |||
|
274 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) | |||
|
275 | ||||
|
276 | # nChannels = len(channelIndexList) | |||
|
277 | ||||
|
278 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |||
|
279 | data_dc = self.dataOut.data_dc[channelIndexList,:] | |||
|
280 | ||||
|
281 | self.dataOut.data_spc = data_spc | |||
|
282 | self.dataOut.data_dc = data_dc | |||
|
283 | ||||
|
284 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |||
|
285 | # self.dataOut.nChannels = nChannels | |||
|
286 | ||||
|
287 | self.__selectPairsByChannel(self.dataOut.channelList) | |||
|
288 | ||||
|
289 | return 1 | |||
|
290 | ||||
|
291 | def selectHeights(self, minHei, maxHei): | |||
|
292 | """ | |||
|
293 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |||
|
294 | minHei <= height <= maxHei | |||
|
295 | ||||
|
296 | Input: | |||
|
297 | minHei : valor minimo de altura a considerar | |||
|
298 | maxHei : valor maximo de altura a considerar | |||
|
299 | ||||
|
300 | Affected: | |||
|
301 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |||
|
302 | ||||
|
303 | Return: | |||
|
304 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |||
|
305 | """ | |||
|
306 | ||||
|
307 | if (minHei > maxHei): | |||
|
308 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) | |||
|
309 | ||||
|
310 | if (minHei < self.dataOut.heightList[0]): | |||
|
311 | minHei = self.dataOut.heightList[0] | |||
|
312 | ||||
|
313 | if (maxHei > self.dataOut.heightList[-1]): | |||
|
314 | maxHei = self.dataOut.heightList[-1] | |||
|
315 | ||||
|
316 | minIndex = 0 | |||
|
317 | maxIndex = 0 | |||
|
318 | heights = self.dataOut.heightList | |||
|
319 | ||||
|
320 | inda = numpy.where(heights >= minHei) | |||
|
321 | indb = numpy.where(heights <= maxHei) | |||
|
322 | ||||
|
323 | try: | |||
|
324 | minIndex = inda[0][0] | |||
|
325 | except: | |||
|
326 | minIndex = 0 | |||
|
327 | ||||
|
328 | try: | |||
|
329 | maxIndex = indb[0][-1] | |||
|
330 | except: | |||
|
331 | maxIndex = len(heights) | |||
|
332 | ||||
|
333 | self.selectHeightsByIndex(minIndex, maxIndex) | |||
|
334 | ||||
|
335 | return 1 | |||
|
336 | ||||
|
337 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): | |||
|
338 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |||
|
339 | ||||
|
340 | if hei_ref != None: | |||
|
341 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |||
|
342 | ||||
|
343 | minIndex = min(newheis[0]) | |||
|
344 | maxIndex = max(newheis[0]) | |||
|
345 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |||
|
346 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |||
|
347 | ||||
|
348 | # determina indices | |||
|
349 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) | |||
|
350 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) | |||
|
351 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |||
|
352 | beacon_heiIndexList = [] | |||
|
353 | for val in avg_dB.tolist(): | |||
|
354 | if val >= beacon_dB[0]: | |||
|
355 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |||
|
356 | ||||
|
357 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |||
|
358 | data_cspc = None | |||
|
359 | if self.dataOut.data_cspc is not None: | |||
|
360 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |||
|
361 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |||
|
362 | ||||
|
363 | data_dc = None | |||
|
364 | if self.dataOut.data_dc is not None: | |||
|
365 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |||
|
366 | #data_dc = data_dc[:,beacon_heiIndexList] | |||
|
367 | ||||
|
368 | self.dataOut.data_spc = data_spc | |||
|
369 | self.dataOut.data_cspc = data_cspc | |||
|
370 | self.dataOut.data_dc = data_dc | |||
|
371 | self.dataOut.heightList = heightList | |||
|
372 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |||
|
373 | ||||
|
374 | return 1 | |||
|
375 | ||||
|
376 | ||||
|
377 | def selectHeightsByIndex(self, minIndex, maxIndex): | |||
|
378 | """ | |||
|
379 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |||
|
380 | minIndex <= index <= maxIndex | |||
|
381 | ||||
|
382 | Input: | |||
|
383 | minIndex : valor de indice minimo de altura a considerar | |||
|
384 | maxIndex : valor de indice maximo de altura a considerar | |||
|
385 | ||||
|
386 | Affected: | |||
|
387 | self.dataOut.data_spc | |||
|
388 | self.dataOut.data_cspc | |||
|
389 | self.dataOut.data_dc | |||
|
390 | self.dataOut.heightList | |||
|
391 | ||||
|
392 | Return: | |||
|
393 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |||
|
394 | """ | |||
|
395 | ||||
|
396 | if (minIndex < 0) or (minIndex > maxIndex): | |||
|
397 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) | |||
|
398 | ||||
|
399 | if (maxIndex >= self.dataOut.nHeights): | |||
|
400 | maxIndex = self.dataOut.nHeights-1 | |||
|
401 | ||||
|
402 | #Spectra | |||
|
403 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |||
|
404 | ||||
|
405 | data_cspc = None | |||
|
406 | if self.dataOut.data_cspc is not None: | |||
|
407 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |||
|
408 | ||||
|
409 | data_dc = None | |||
|
410 | if self.dataOut.data_dc is not None: | |||
|
411 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |||
|
412 | ||||
|
413 | self.dataOut.data_spc = data_spc | |||
|
414 | self.dataOut.data_cspc = data_cspc | |||
|
415 | self.dataOut.data_dc = data_dc | |||
|
416 | ||||
|
417 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |||
|
418 | ||||
|
419 | return 1 | |||
|
420 | ||||
|
421 | def removeDC(self, mode = 2): | |||
|
422 | jspectra = self.dataOut.data_spc | |||
|
423 | jcspectra = self.dataOut.data_cspc | |||
|
424 | ||||
|
425 | ||||
|
426 | num_chan = jspectra.shape[0] | |||
|
427 | num_hei = jspectra.shape[2] | |||
|
428 | ||||
|
429 | if jcspectra is not None: | |||
|
430 | jcspectraExist = True | |||
|
431 | num_pairs = jcspectra.shape[0] | |||
|
432 | else: jcspectraExist = False | |||
|
433 | ||||
|
434 | freq_dc = jspectra.shape[1]/2 | |||
|
435 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |||
|
436 | ||||
|
437 | if ind_vel[0]<0: | |||
|
438 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |||
|
439 | ||||
|
440 | if mode == 1: | |||
|
441 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |||
|
442 | ||||
|
443 | if jcspectraExist: | |||
|
444 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 | |||
|
445 | ||||
|
446 | if mode == 2: | |||
|
447 | ||||
|
448 | vel = numpy.array([-2,-1,1,2]) | |||
|
449 | xx = numpy.zeros([4,4]) | |||
|
450 | ||||
|
451 | for fil in range(4): | |||
|
452 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |||
|
453 | ||||
|
454 | xx_inv = numpy.linalg.inv(xx) | |||
|
455 | xx_aux = xx_inv[0,:] | |||
|
456 | ||||
|
457 | for ich in range(num_chan): | |||
|
458 | yy = jspectra[ich,ind_vel,:] | |||
|
459 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |||
|
460 | ||||
|
461 | junkid = jspectra[ich,freq_dc,:]<=0 | |||
|
462 | cjunkid = sum(junkid) | |||
|
463 | ||||
|
464 | if cjunkid.any(): | |||
|
465 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |||
|
466 | ||||
|
467 | if jcspectraExist: | |||
|
468 | for ip in range(num_pairs): | |||
|
469 | yy = jcspectra[ip,ind_vel,:] | |||
|
470 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) | |||
|
471 | ||||
|
472 | ||||
|
473 | self.dataOut.data_spc = jspectra | |||
|
474 | self.dataOut.data_cspc = jcspectra | |||
|
475 | ||||
|
476 | return 1 | |||
|
477 | ||||
|
478 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |||
|
479 | ||||
|
480 | jspectra = self.dataOut.data_spc | |||
|
481 | jcspectra = self.dataOut.data_cspc | |||
|
482 | jnoise = self.dataOut.getNoise() | |||
|
483 | num_incoh = self.dataOut.nIncohInt | |||
|
484 | ||||
|
485 | num_channel = jspectra.shape[0] | |||
|
486 | num_prof = jspectra.shape[1] | |||
|
487 | num_hei = jspectra.shape[2] | |||
|
488 | ||||
|
489 | #hei_interf | |||
|
490 | if hei_interf is None: | |||
|
491 | count_hei = num_hei/2 #Como es entero no importa | |||
|
492 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |||
|
493 | hei_interf = numpy.asarray(hei_interf)[0] | |||
|
494 | #nhei_interf | |||
|
495 | if (nhei_interf == None): | |||
|
496 | nhei_interf = 5 | |||
|
497 | if (nhei_interf < 1): | |||
|
498 | nhei_interf = 1 | |||
|
499 | if (nhei_interf > count_hei): | |||
|
500 | nhei_interf = count_hei | |||
|
501 | if (offhei_interf == None): | |||
|
502 | offhei_interf = 0 | |||
|
503 | ||||
|
504 | ind_hei = range(num_hei) | |||
|
505 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |||
|
506 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |||
|
507 | mask_prof = numpy.asarray(range(num_prof)) | |||
|
508 | num_mask_prof = mask_prof.size | |||
|
509 | comp_mask_prof = [0, num_prof/2] | |||
|
510 | ||||
|
511 | ||||
|
512 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |||
|
513 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |||
|
514 | jnoise = numpy.nan | |||
|
515 | noise_exist = jnoise[0] < numpy.Inf | |||
|
516 | ||||
|
517 | #Subrutina de Remocion de la Interferencia | |||
|
518 | for ich in range(num_channel): | |||
|
519 | #Se ordena los espectros segun su potencia (menor a mayor) | |||
|
520 | power = jspectra[ich,mask_prof,:] | |||
|
521 | power = power[:,hei_interf] | |||
|
522 | power = power.sum(axis = 0) | |||
|
523 | psort = power.ravel().argsort() | |||
|
524 | ||||
|
525 | #Se estima la interferencia promedio en los Espectros de Potencia empleando | |||
|
526 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |||
|
527 | ||||
|
528 | if noise_exist: | |||
|
529 | # tmp_noise = jnoise[ich] / num_prof | |||
|
530 | tmp_noise = jnoise[ich] | |||
|
531 | junkspc_interf = junkspc_interf - tmp_noise | |||
|
532 | #junkspc_interf[:,comp_mask_prof] = 0 | |||
|
533 | ||||
|
534 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf | |||
|
535 | jspc_interf = jspc_interf.transpose() | |||
|
536 | #Calculando el espectro de interferencia promedio | |||
|
537 | noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) | |||
|
538 | noiseid = noiseid[0] | |||
|
539 | cnoiseid = noiseid.size | |||
|
540 | interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) | |||
|
541 | interfid = interfid[0] | |||
|
542 | cinterfid = interfid.size | |||
|
543 | ||||
|
544 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 | |||
|
545 | ||||
|
546 | #Expandiendo los perfiles a limpiar | |||
|
547 | if (cinterfid > 0): | |||
|
548 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof | |||
|
549 | new_interfid = numpy.asarray(new_interfid) | |||
|
550 | new_interfid = {x for x in new_interfid} | |||
|
551 | new_interfid = numpy.array(list(new_interfid)) | |||
|
552 | new_cinterfid = new_interfid.size | |||
|
553 | else: new_cinterfid = 0 | |||
|
554 | ||||
|
555 | for ip in range(new_cinterfid): | |||
|
556 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() | |||
|
557 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] | |||
|
558 | ||||
|
559 | ||||
|
560 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices | |||
|
561 | ||||
|
562 | #Removiendo la interferencia del punto de mayor interferencia | |||
|
563 | ListAux = jspc_interf[mask_prof].tolist() | |||
|
564 | maxid = ListAux.index(max(ListAux)) | |||
|
565 | ||||
|
566 | ||||
|
567 | if cinterfid > 0: | |||
|
568 | for ip in range(cinterfid*(interf == 2) - 1): | |||
|
569 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero() | |||
|
570 | cind = len(ind) | |||
|
571 | ||||
|
572 | if (cind > 0): | |||
|
573 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh)) | |||
|
574 | ||||
|
575 | ind = numpy.array([-2,-1,1,2]) | |||
|
576 | xx = numpy.zeros([4,4]) | |||
|
577 | ||||
|
578 | for id1 in range(4): | |||
|
579 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |||
|
580 | ||||
|
581 | xx_inv = numpy.linalg.inv(xx) | |||
|
582 | xx = xx_inv[:,0] | |||
|
583 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |||
|
584 | yy = jspectra[ich,mask_prof[ind],:] | |||
|
585 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |||
|
586 | ||||
|
587 | ||||
|
588 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero() | |||
|
589 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh)) | |||
|
590 | ||||
|
591 | #Remocion de Interferencia en el Cross Spectra | |||
|
592 | if jcspectra is None: return jspectra, jcspectra | |||
|
593 | num_pairs = jcspectra.size/(num_prof*num_hei) | |||
|
594 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |||
|
595 | ||||
|
596 | for ip in range(num_pairs): | |||
|
597 | ||||
|
598 | #------------------------------------------- | |||
|
599 | ||||
|
600 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) | |||
|
601 | cspower = cspower[:,hei_interf] | |||
|
602 | cspower = cspower.sum(axis = 0) | |||
|
603 | ||||
|
604 | cspsort = cspower.ravel().argsort() | |||
|
605 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |||
|
606 | junkcspc_interf = junkcspc_interf.transpose() | |||
|
607 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf | |||
|
608 | ||||
|
609 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |||
|
610 | ||||
|
611 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |||
|
612 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |||
|
613 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) | |||
|
614 | ||||
|
615 | for iprof in range(num_prof): | |||
|
616 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() | |||
|
617 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] | |||
|
618 | ||||
|
619 | #Removiendo la Interferencia | |||
|
620 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf | |||
|
621 | ||||
|
622 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |||
|
623 | maxid = ListAux.index(max(ListAux)) | |||
|
624 | ||||
|
625 | ind = numpy.array([-2,-1,1,2]) | |||
|
626 | xx = numpy.zeros([4,4]) | |||
|
627 | ||||
|
628 | for id1 in range(4): | |||
|
629 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |||
|
630 | ||||
|
631 | xx_inv = numpy.linalg.inv(xx) | |||
|
632 | xx = xx_inv[:,0] | |||
|
633 | ||||
|
634 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |||
|
635 | yy = jcspectra[ip,mask_prof[ind],:] | |||
|
636 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |||
|
637 | ||||
|
638 | #Guardar Resultados | |||
|
639 | self.dataOut.data_spc = jspectra | |||
|
640 | self.dataOut.data_cspc = jcspectra | |||
|
641 | ||||
|
642 | return 1 | |||
|
643 | ||||
|
644 | def setRadarFrequency(self, frequency=None): | |||
|
645 | ||||
|
646 | if frequency != None: | |||
|
647 | self.dataOut.frequency = frequency | |||
|
648 | ||||
|
649 | return 1 | |||
|
650 | ||||
|
651 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |||
|
652 | #validacion de rango | |||
|
653 | if minHei == None: | |||
|
654 | minHei = self.dataOut.heightList[0] | |||
|
655 | ||||
|
656 | if maxHei == None: | |||
|
657 | maxHei = self.dataOut.heightList[-1] | |||
|
658 | ||||
|
659 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |||
|
660 | print 'minHei: %.2f is out of the heights range'%(minHei) | |||
|
661 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) | |||
|
662 | minHei = self.dataOut.heightList[0] | |||
|
663 | ||||
|
664 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |||
|
665 | print 'maxHei: %.2f is out of the heights range'%(maxHei) | |||
|
666 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) | |||
|
667 | maxHei = self.dataOut.heightList[-1] | |||
|
668 | ||||
|
669 | # validacion de velocidades | |||
|
670 | velrange = self.dataOut.getVelRange(1) | |||
|
671 | ||||
|
672 | if minVel == None: | |||
|
673 | minVel = velrange[0] | |||
|
674 | ||||
|
675 | if maxVel == None: | |||
|
676 | maxVel = velrange[-1] | |||
|
677 | ||||
|
678 | if (minVel < velrange[0]) or (minVel > maxVel): | |||
|
679 | print 'minVel: %.2f is out of the velocity range'%(minVel) | |||
|
680 | print 'minVel is setting to %.2f'%(velrange[0]) | |||
|
681 | minVel = velrange[0] | |||
|
682 | ||||
|
683 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |||
|
684 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) | |||
|
685 | print 'maxVel is setting to %.2f'%(velrange[-1]) | |||
|
686 | maxVel = velrange[-1] | |||
|
687 | ||||
|
688 | # seleccion de indices para rango | |||
|
689 | minIndex = 0 | |||
|
690 | maxIndex = 0 | |||
|
691 | heights = self.dataOut.heightList | |||
|
692 | ||||
|
693 | inda = numpy.where(heights >= minHei) | |||
|
694 | indb = numpy.where(heights <= maxHei) | |||
|
695 | ||||
|
696 | try: | |||
|
697 | minIndex = inda[0][0] | |||
|
698 | except: | |||
|
699 | minIndex = 0 | |||
|
700 | ||||
|
701 | try: | |||
|
702 | maxIndex = indb[0][-1] | |||
|
703 | except: | |||
|
704 | maxIndex = len(heights) | |||
|
705 | ||||
|
706 | if (minIndex < 0) or (minIndex > maxIndex): | |||
|
707 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |||
|
708 | ||||
|
709 | if (maxIndex >= self.dataOut.nHeights): | |||
|
710 | maxIndex = self.dataOut.nHeights-1 | |||
|
711 | ||||
|
712 | # seleccion de indices para velocidades | |||
|
713 | indminvel = numpy.where(velrange >= minVel) | |||
|
714 | indmaxvel = numpy.where(velrange <= maxVel) | |||
|
715 | try: | |||
|
716 | minIndexVel = indminvel[0][0] | |||
|
717 | except: | |||
|
718 | minIndexVel = 0 | |||
|
719 | ||||
|
720 | try: | |||
|
721 | maxIndexVel = indmaxvel[0][-1] | |||
|
722 | except: | |||
|
723 | maxIndexVel = len(velrange) | |||
|
724 | ||||
|
725 | #seleccion del espectro | |||
|
726 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] | |||
|
727 | #estimacion de ruido | |||
|
728 | noise = numpy.zeros(self.dataOut.nChannels) | |||
|
729 | ||||
|
730 | for channel in range(self.dataOut.nChannels): | |||
|
731 | daux = data_spc[channel,:,:] | |||
|
732 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |||
|
733 | ||||
|
734 | self.dataOut.noise_estimation = noise.copy() | |||
|
735 | ||||
|
736 | return 1 No newline at end of file |
@@ -1,13 +1,14 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z murco $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | from jroproc_voltage import * |
|
7 | from jroproc_voltage import * | |
8 | from jroproc_spectra import * |
|
8 | from jroproc_spectra import * | |
9 | from jroproc_heispectra import * |
|
9 | from jroproc_heispectra import * | |
10 | from jroproc_amisr import * |
|
10 | from jroproc_amisr import * | |
11 | from jroproc_correlation import * |
|
11 | from jroproc_correlation import * | |
12 | from jroproc_parameters import * |
|
12 | from jroproc_parameters import * | |
13 | from jroproc_spectra_lags import * No newline at end of file |
|
13 | from jroproc_spectra_lags import * | |
|
14 | from jroproc_spectra_acf import * No newline at end of file |
@@ -1,739 +1,739 | |||||
1 | import numpy |
|
1 | import numpy | |
2 |
|
2 | |||
3 | from jroproc_base import ProcessingUnit, Operation |
|
3 | from jroproc_base import ProcessingUnit, Operation | |
4 | from schainpy.model.data.jrodata import Spectra |
|
4 | from schainpy.model.data.jrodata import Spectra | |
5 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
5 | from schainpy.model.data.jrodata import hildebrand_sekhon | |
6 |
|
6 | |||
7 | class SpectraLagsProc(ProcessingUnit): |
|
7 | class SpectraLagsProc(ProcessingUnit): | |
8 |
|
8 | |||
9 | def __init__(self): |
|
9 | def __init__(self): | |
10 |
|
10 | |||
11 | ProcessingUnit.__init__(self) |
|
11 | ProcessingUnit.__init__(self) | |
12 |
|
12 | |||
13 | self.__input_buffer = None |
|
13 | self.__input_buffer = None | |
14 | self.firstdatatime = None |
|
14 | self.firstdatatime = None | |
15 | self.profIndex = 0 |
|
15 | self.profIndex = 0 | |
16 | self.dataOut = Spectra() |
|
16 | self.dataOut = Spectra() | |
17 | self.id_min = None |
|
17 | self.id_min = None | |
18 | self.id_max = None |
|
18 | self.id_max = None | |
19 | self.__codeIndex = 0 |
|
19 | self.__codeIndex = 0 | |
20 |
|
20 | |||
21 | self.__lags_buffer = None |
|
21 | self.__lags_buffer = None | |
22 |
|
22 | |||
23 | def __updateSpecFromVoltage(self): |
|
23 | def __updateSpecFromVoltage(self): | |
24 |
|
24 | |||
25 | self.dataOut.plotting = "spectra_lags" |
|
25 | self.dataOut.plotting = "spectra_lags" | |
26 | self.dataOut.timeZone = self.dataIn.timeZone |
|
26 | self.dataOut.timeZone = self.dataIn.timeZone | |
27 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
27 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
28 | self.dataOut.errorCount = self.dataIn.errorCount |
|
28 | self.dataOut.errorCount = self.dataIn.errorCount | |
29 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
29 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
30 |
|
30 | |||
31 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
31 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
32 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
32 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
33 | self.dataOut.ippSeconds = self.dataIn.getDeltaH()*(10**-6)/0.15 |
|
33 | self.dataOut.ippSeconds = self.dataIn.getDeltaH()*(10**-6)/0.15 | |
34 |
|
34 | |||
35 | self.dataOut.channelList = self.dataIn.channelList |
|
35 | self.dataOut.channelList = self.dataIn.channelList | |
36 | self.dataOut.heightList = self.dataIn.heightList |
|
36 | self.dataOut.heightList = self.dataIn.heightList | |
37 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
37 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
38 |
|
38 | |||
39 | self.dataOut.nBaud = self.dataIn.nBaud |
|
39 | self.dataOut.nBaud = self.dataIn.nBaud | |
40 | self.dataOut.nCode = self.dataIn.nCode |
|
40 | self.dataOut.nCode = self.dataIn.nCode | |
41 | self.dataOut.code = self.dataIn.code |
|
41 | self.dataOut.code = self.dataIn.code | |
42 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
42 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
43 |
|
43 | |||
44 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
44 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
45 | self.dataOut.utctime = self.firstdatatime |
|
45 | self.dataOut.utctime = self.firstdatatime | |
46 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
46 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
47 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
47 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
48 | self.dataOut.flagShiftFFT = False |
|
48 | self.dataOut.flagShiftFFT = False | |
49 |
|
49 | |||
50 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
50 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
51 | self.dataOut.nIncohInt = 1 |
|
51 | self.dataOut.nIncohInt = 1 | |
52 |
|
52 | |||
53 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
53 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
54 |
|
54 | |||
55 | self.dataOut.frequency = self.dataIn.frequency |
|
55 | self.dataOut.frequency = self.dataIn.frequency | |
56 | self.dataOut.realtime = self.dataIn.realtime |
|
56 | self.dataOut.realtime = self.dataIn.realtime | |
57 |
|
57 | |||
58 | self.dataOut.azimuth = self.dataIn.azimuth |
|
58 | self.dataOut.azimuth = self.dataIn.azimuth | |
59 | self.dataOut.zenith = self.dataIn.zenith |
|
59 | self.dataOut.zenith = self.dataIn.zenith | |
60 |
|
60 | |||
61 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
61 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
62 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
62 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
63 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
63 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
64 |
|
64 | |||
65 | def __createLagsBlock(self, voltages): |
|
65 | def __createLagsBlock(self, voltages): | |
66 |
|
66 | |||
67 | if self.__lags_buffer is None: |
|
67 | if self.__lags_buffer is None: | |
68 | self.__lags_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, self.dataOut.nHeights), dtype='complex') |
|
68 | self.__lags_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, self.dataOut.nHeights), dtype='complex') | |
69 |
|
69 | |||
70 | nsegments = self.dataOut.nHeights - self.dataOut.nProfiles |
|
70 | nsegments = self.dataOut.nHeights - self.dataOut.nProfiles | |
71 |
|
71 | |||
72 | # codes = numpy.conjugate(self.__input_buffer[:,9:169])/10000 |
|
72 | # codes = numpy.conjugate(self.__input_buffer[:,9:169])/10000 | |
73 |
|
73 | |||
74 | for i in range(nsegments): |
|
74 | for i in range(nsegments): | |
75 | self.__lags_buffer[:,:,i] = voltages[:,i:i+self.dataOut.nProfiles]#*codes |
|
75 | self.__lags_buffer[:,:,i] = voltages[:,i:i+self.dataOut.nProfiles]#*codes | |
76 |
|
76 | |||
77 | return self.__lags_buffer |
|
77 | return self.__lags_buffer | |
78 |
|
78 | |||
79 | def __decodeData(self, volt_buffer, pulseIndex=None): |
|
79 | def __decodeData(self, volt_buffer, pulseIndex=None): | |
80 |
|
80 | |||
81 | if pulseIndex is None: |
|
81 | if pulseIndex is None: | |
82 | return volt_buffer |
|
82 | return volt_buffer | |
83 |
|
83 | |||
84 | codes = numpy.conjugate(self.__input_buffer[:,pulseIndex[0]:pulseIndex[1]])/10000 |
|
84 | codes = numpy.conjugate(self.__input_buffer[:,pulseIndex[0]:pulseIndex[1]])/10000 | |
85 |
|
85 | |||
86 | nsegments = self.dataOut.nHeights - self.dataOut.nProfiles |
|
86 | nsegments = self.dataOut.nHeights - self.dataOut.nProfiles | |
87 |
|
87 | |||
88 | for i in range(nsegments): |
|
88 | for i in range(nsegments): | |
89 | volt_buffer[:,:,i] = volt_buffer[:,:,i]*codes |
|
89 | volt_buffer[:,:,i] = volt_buffer[:,:,i]*codes | |
90 |
|
90 | |||
91 | return volt_buffer |
|
91 | return volt_buffer | |
92 |
|
92 | |||
93 | def __getFft(self, datablock): |
|
93 | def __getFft(self, datablock): | |
94 | """ |
|
94 | """ | |
95 | Convierte valores de Voltaje a Spectra |
|
95 | Convierte valores de Voltaje a Spectra | |
96 |
|
96 | |||
97 | Affected: |
|
97 | Affected: | |
98 | self.dataOut.data_spc |
|
98 | self.dataOut.data_spc | |
99 | self.dataOut.data_cspc |
|
99 | self.dataOut.data_cspc | |
100 | self.dataOut.data_dc |
|
100 | self.dataOut.data_dc | |
101 | self.dataOut.heightList |
|
101 | self.dataOut.heightList | |
102 | self.profIndex |
|
102 | self.profIndex | |
103 | self.__input_buffer |
|
103 | self.__input_buffer | |
104 | self.dataOut.flagNoData |
|
104 | self.dataOut.flagNoData | |
105 | """ |
|
105 | """ | |
106 |
|
106 | |||
107 | fft_volt = numpy.fft.fft(datablock, n=self.dataOut.nFFTPoints, axis=1) |
|
107 | fft_volt = numpy.fft.fft(datablock, n=self.dataOut.nFFTPoints, axis=1) | |
108 |
|
108 | |||
109 |
|
|
109 | dc = fft_volt[:,0,:] | |
110 |
|
110 | |||
111 | #calculo de self-spectra |
|
111 | #calculo de self-spectra | |
112 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) |
|
112 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) | |
113 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
113 | spc = fft_volt * numpy.conjugate(fft_volt) | |
114 | spc = spc.real |
|
114 | spc = spc.real | |
115 |
|
115 | |||
116 | blocksize = 0 |
|
116 | blocksize = 0 | |
117 |
|
|
117 | blocksize += dc.size | |
118 | blocksize += spc.size |
|
118 | blocksize += spc.size | |
119 |
|
119 | |||
120 | cspc = None |
|
120 | cspc = None | |
121 | pairIndex = 0 |
|
121 | pairIndex = 0 | |
122 |
|
122 | |||
123 |
if self.dataOut.pairsList != |
|
123 | if self.dataOut.pairsList != []: | |
124 | #calculo de cross-spectra |
|
124 | #calculo de cross-spectra | |
125 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
125 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
126 | for pair in self.dataOut.pairsList: |
|
126 | for pair in self.dataOut.pairsList: | |
127 | if pair[0] not in self.dataOut.channelList: |
|
127 | if pair[0] not in self.dataOut.channelList: | |
128 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
128 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) | |
129 | if pair[1] not in self.dataOut.channelList: |
|
129 | if pair[1] not in self.dataOut.channelList: | |
130 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
130 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) | |
131 |
|
131 | |||
132 | chan_index0 = self.dataOut.channelList.index(pair[0]) |
|
132 | chan_index0 = self.dataOut.channelList.index(pair[0]) | |
133 | chan_index1 = self.dataOut.channelList.index(pair[1]) |
|
133 | chan_index1 = self.dataOut.channelList.index(pair[1]) | |
134 |
|
134 | |||
135 | cspc[pairIndex,:,:] = fft_volt[chan_index0,:,:] * numpy.conjugate(fft_volt[chan_index1,:,:]) |
|
135 | cspc[pairIndex,:,:] = fft_volt[chan_index0,:,:] * numpy.conjugate(fft_volt[chan_index1,:,:]) | |
136 | pairIndex += 1 |
|
136 | pairIndex += 1 | |
137 | blocksize += cspc.size |
|
137 | blocksize += cspc.size | |
138 |
|
138 | |||
139 | self.dataOut.data_spc = spc |
|
139 | self.dataOut.data_spc = spc | |
140 | self.dataOut.data_cspc = cspc |
|
140 | self.dataOut.data_cspc = cspc | |
141 |
|
|
141 | self.dataOut.data_dc = dc | |
142 | self.dataOut.blockSize = blocksize |
|
142 | self.dataOut.blockSize = blocksize | |
143 | self.dataOut.flagShiftFFT = True |
|
143 | self.dataOut.flagShiftFFT = True | |
144 |
|
144 | |||
145 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=None, nBaud=None, codeFromHeader=False, pulseIndex=None): |
|
145 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=None, nBaud=None, codeFromHeader=False, pulseIndex=None): | |
146 |
|
146 | |||
147 | self.dataOut.flagNoData = True |
|
147 | self.dataOut.flagNoData = True | |
148 |
|
148 | |||
149 | self.code = None |
|
149 | self.code = None | |
150 |
|
150 | |||
151 | if codeFromHeader: |
|
151 | if codeFromHeader: | |
152 | if self.dataIn.code is not None: |
|
152 | if self.dataIn.code is not None: | |
153 | self.code = self.dataIn.code |
|
153 | self.code = self.dataIn.code | |
154 |
|
154 | |||
155 | if code is not None: |
|
155 | if code is not None: | |
156 | self.code = numpy.array(code).reshape(nCode,nBaud) |
|
156 | self.code = numpy.array(code).reshape(nCode,nBaud) | |
157 |
|
157 | |||
158 | if self.dataIn.type == "Voltage": |
|
158 | if self.dataIn.type == "Voltage": | |
159 |
|
159 | |||
160 | if nFFTPoints == None: |
|
160 | if nFFTPoints == None: | |
161 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
161 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" | |
162 |
|
162 | |||
163 | if nProfiles == None: |
|
163 | if nProfiles == None: | |
164 | nProfiles = nFFTPoints |
|
164 | nProfiles = nFFTPoints | |
165 |
|
165 | |||
166 | self.profIndex == nProfiles |
|
166 | self.profIndex == nProfiles | |
167 | self.firstdatatime = self.dataIn.utctime |
|
167 | self.firstdatatime = self.dataIn.utctime | |
168 |
|
168 | |||
169 | self.dataOut.ippFactor = 1 |
|
169 | self.dataOut.ippFactor = 1 | |
170 | self.dataOut.nFFTPoints = nFFTPoints |
|
170 | self.dataOut.nFFTPoints = nFFTPoints | |
171 | self.dataOut.nProfiles = nProfiles |
|
171 | self.dataOut.nProfiles = nProfiles | |
172 | self.dataOut.pairsList = pairsList |
|
172 | self.dataOut.pairsList = pairsList | |
173 |
|
173 | |||
174 | self.__updateSpecFromVoltage() |
|
174 | self.__updateSpecFromVoltage() | |
175 |
|
175 | |||
176 | if not self.dataIn.flagDataAsBlock: |
|
176 | if not self.dataIn.flagDataAsBlock: | |
177 | self.__input_buffer = self.dataIn.data.copy() |
|
177 | self.__input_buffer = self.dataIn.data.copy() | |
178 |
|
178 | |||
179 | lags_block = self.__createLagsBlock(self.__input_buffer) |
|
179 | lags_block = self.__createLagsBlock(self.__input_buffer) | |
180 |
|
180 | |||
181 | lags_block = self.__decodeData(lags_block, pulseIndex) |
|
181 | lags_block = self.__decodeData(lags_block, pulseIndex) | |
182 |
|
182 | |||
183 | else: |
|
183 | else: | |
184 | self.__input_buffer = self.dataIn.data.copy() |
|
184 | self.__input_buffer = self.dataIn.data.copy() | |
185 |
|
185 | |||
186 | self.__getFft(lags_block) |
|
186 | self.__getFft(lags_block) | |
187 |
|
187 | |||
188 | self.dataOut.flagNoData = False |
|
188 | self.dataOut.flagNoData = False | |
189 |
|
189 | |||
190 | return True |
|
190 | return True | |
191 |
|
191 | |||
192 | raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) |
|
192 | raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) | |
193 |
|
193 | |||
194 | def __selectPairs(self, pairsList): |
|
194 | def __selectPairs(self, pairsList): | |
195 |
|
195 | |||
196 | if channelList == None: |
|
196 | if channelList == None: | |
197 | return |
|
197 | return | |
198 |
|
198 | |||
199 | pairsIndexListSelected = [] |
|
199 | pairsIndexListSelected = [] | |
200 |
|
200 | |||
201 | for thisPair in pairsList: |
|
201 | for thisPair in pairsList: | |
202 |
|
202 | |||
203 | if thisPair not in self.dataOut.pairsList: |
|
203 | if thisPair not in self.dataOut.pairsList: | |
204 | continue |
|
204 | continue | |
205 |
|
205 | |||
206 | pairIndex = self.dataOut.pairsList.index(thisPair) |
|
206 | pairIndex = self.dataOut.pairsList.index(thisPair) | |
207 |
|
207 | |||
208 | pairsIndexListSelected.append(pairIndex) |
|
208 | pairsIndexListSelected.append(pairIndex) | |
209 |
|
209 | |||
210 | if not pairsIndexListSelected: |
|
210 | if not pairsIndexListSelected: | |
211 | self.dataOut.data_cspc = None |
|
211 | self.dataOut.data_cspc = None | |
212 | self.dataOut.pairsList = [] |
|
212 | self.dataOut.pairsList = [] | |
213 | return |
|
213 | return | |
214 |
|
214 | |||
215 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
215 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
216 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] |
|
216 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |
217 |
|
217 | |||
218 | return |
|
218 | return | |
219 |
|
219 | |||
220 | def __selectPairsByChannel(self, channelList=None): |
|
220 | def __selectPairsByChannel(self, channelList=None): | |
221 |
|
221 | |||
222 | if channelList == None: |
|
222 | if channelList == None: | |
223 | return |
|
223 | return | |
224 |
|
224 | |||
225 | pairsIndexListSelected = [] |
|
225 | pairsIndexListSelected = [] | |
226 | for pairIndex in self.dataOut.pairsIndexList: |
|
226 | for pairIndex in self.dataOut.pairsIndexList: | |
227 | #First pair |
|
227 | #First pair | |
228 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
228 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
229 | continue |
|
229 | continue | |
230 | #Second pair |
|
230 | #Second pair | |
231 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
231 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
232 | continue |
|
232 | continue | |
233 |
|
233 | |||
234 | pairsIndexListSelected.append(pairIndex) |
|
234 | pairsIndexListSelected.append(pairIndex) | |
235 |
|
235 | |||
236 | if not pairsIndexListSelected: |
|
236 | if not pairsIndexListSelected: | |
237 | self.dataOut.data_cspc = None |
|
237 | self.dataOut.data_cspc = None | |
238 | self.dataOut.pairsList = [] |
|
238 | self.dataOut.pairsList = [] | |
239 | return |
|
239 | return | |
240 |
|
240 | |||
241 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
241 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
242 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] |
|
242 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |
243 |
|
243 | |||
244 | return |
|
244 | return | |
245 |
|
245 | |||
246 | def selectChannels(self, channelList): |
|
246 | def selectChannels(self, channelList): | |
247 |
|
247 | |||
248 | channelIndexList = [] |
|
248 | channelIndexList = [] | |
249 |
|
249 | |||
250 | for channel in channelList: |
|
250 | for channel in channelList: | |
251 | if channel not in self.dataOut.channelList: |
|
251 | if channel not in self.dataOut.channelList: | |
252 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) |
|
252 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) | |
253 |
|
253 | |||
254 | index = self.dataOut.channelList.index(channel) |
|
254 | index = self.dataOut.channelList.index(channel) | |
255 | channelIndexList.append(index) |
|
255 | channelIndexList.append(index) | |
256 |
|
256 | |||
257 | self.selectChannelsByIndex(channelIndexList) |
|
257 | self.selectChannelsByIndex(channelIndexList) | |
258 |
|
258 | |||
259 | def selectChannelsByIndex(self, channelIndexList): |
|
259 | def selectChannelsByIndex(self, channelIndexList): | |
260 | """ |
|
260 | """ | |
261 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
261 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
262 |
|
262 | |||
263 | Input: |
|
263 | Input: | |
264 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
264 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
265 |
|
265 | |||
266 | Affected: |
|
266 | Affected: | |
267 | self.dataOut.data_spc |
|
267 | self.dataOut.data_spc | |
268 | self.dataOut.channelIndexList |
|
268 | self.dataOut.channelIndexList | |
269 | self.dataOut.nChannels |
|
269 | self.dataOut.nChannels | |
270 |
|
270 | |||
271 | Return: |
|
271 | Return: | |
272 | None |
|
272 | None | |
273 | """ |
|
273 | """ | |
274 |
|
274 | |||
275 | for channelIndex in channelIndexList: |
|
275 | for channelIndex in channelIndexList: | |
276 | if channelIndex not in self.dataOut.channelIndexList: |
|
276 | if channelIndex not in self.dataOut.channelIndexList: | |
277 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) |
|
277 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) | |
278 |
|
278 | |||
279 | # nChannels = len(channelIndexList) |
|
279 | # nChannels = len(channelIndexList) | |
280 |
|
280 | |||
281 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
281 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
282 | data_dc = self.dataOut.data_dc[channelIndexList,:] |
|
282 | data_dc = self.dataOut.data_dc[channelIndexList,:] | |
283 |
|
283 | |||
284 | self.dataOut.data_spc = data_spc |
|
284 | self.dataOut.data_spc = data_spc | |
285 | self.dataOut.data_dc = data_dc |
|
285 | self.dataOut.data_dc = data_dc | |
286 |
|
286 | |||
287 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
287 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
288 | # self.dataOut.nChannels = nChannels |
|
288 | # self.dataOut.nChannels = nChannels | |
289 |
|
289 | |||
290 | self.__selectPairsByChannel(self.dataOut.channelList) |
|
290 | self.__selectPairsByChannel(self.dataOut.channelList) | |
291 |
|
291 | |||
292 | return 1 |
|
292 | return 1 | |
293 |
|
293 | |||
294 | def selectHeights(self, minHei, maxHei): |
|
294 | def selectHeights(self, minHei, maxHei): | |
295 | """ |
|
295 | """ | |
296 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
296 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
297 | minHei <= height <= maxHei |
|
297 | minHei <= height <= maxHei | |
298 |
|
298 | |||
299 | Input: |
|
299 | Input: | |
300 | minHei : valor minimo de altura a considerar |
|
300 | minHei : valor minimo de altura a considerar | |
301 | maxHei : valor maximo de altura a considerar |
|
301 | maxHei : valor maximo de altura a considerar | |
302 |
|
302 | |||
303 | Affected: |
|
303 | Affected: | |
304 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
304 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
305 |
|
305 | |||
306 | Return: |
|
306 | Return: | |
307 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
307 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
308 | """ |
|
308 | """ | |
309 |
|
309 | |||
310 | if (minHei > maxHei): |
|
310 | if (minHei > maxHei): | |
311 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) |
|
311 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) | |
312 |
|
312 | |||
313 | if (minHei < self.dataOut.heightList[0]): |
|
313 | if (minHei < self.dataOut.heightList[0]): | |
314 | minHei = self.dataOut.heightList[0] |
|
314 | minHei = self.dataOut.heightList[0] | |
315 |
|
315 | |||
316 | if (maxHei > self.dataOut.heightList[-1]): |
|
316 | if (maxHei > self.dataOut.heightList[-1]): | |
317 | maxHei = self.dataOut.heightList[-1] |
|
317 | maxHei = self.dataOut.heightList[-1] | |
318 |
|
318 | |||
319 | minIndex = 0 |
|
319 | minIndex = 0 | |
320 | maxIndex = 0 |
|
320 | maxIndex = 0 | |
321 | heights = self.dataOut.heightList |
|
321 | heights = self.dataOut.heightList | |
322 |
|
322 | |||
323 | inda = numpy.where(heights >= minHei) |
|
323 | inda = numpy.where(heights >= minHei) | |
324 | indb = numpy.where(heights <= maxHei) |
|
324 | indb = numpy.where(heights <= maxHei) | |
325 |
|
325 | |||
326 | try: |
|
326 | try: | |
327 | minIndex = inda[0][0] |
|
327 | minIndex = inda[0][0] | |
328 | except: |
|
328 | except: | |
329 | minIndex = 0 |
|
329 | minIndex = 0 | |
330 |
|
330 | |||
331 | try: |
|
331 | try: | |
332 | maxIndex = indb[0][-1] |
|
332 | maxIndex = indb[0][-1] | |
333 | except: |
|
333 | except: | |
334 | maxIndex = len(heights) |
|
334 | maxIndex = len(heights) | |
335 |
|
335 | |||
336 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
336 | self.selectHeightsByIndex(minIndex, maxIndex) | |
337 |
|
337 | |||
338 | return 1 |
|
338 | return 1 | |
339 |
|
339 | |||
340 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
340 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): | |
341 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
341 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
342 |
|
342 | |||
343 | if hei_ref != None: |
|
343 | if hei_ref != None: | |
344 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
344 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
345 |
|
345 | |||
346 | minIndex = min(newheis[0]) |
|
346 | minIndex = min(newheis[0]) | |
347 | maxIndex = max(newheis[0]) |
|
347 | maxIndex = max(newheis[0]) | |
348 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
348 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
349 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
349 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
350 |
|
350 | |||
351 | # determina indices |
|
351 | # determina indices | |
352 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
352 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) | |
353 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
353 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) | |
354 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
354 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
355 | beacon_heiIndexList = [] |
|
355 | beacon_heiIndexList = [] | |
356 | for val in avg_dB.tolist(): |
|
356 | for val in avg_dB.tolist(): | |
357 | if val >= beacon_dB[0]: |
|
357 | if val >= beacon_dB[0]: | |
358 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
358 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
359 |
|
359 | |||
360 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
360 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
361 | data_cspc = None |
|
361 | data_cspc = None | |
362 | if self.dataOut.data_cspc is not None: |
|
362 | if self.dataOut.data_cspc is not None: | |
363 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
363 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
364 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
364 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
365 |
|
365 | |||
366 | data_dc = None |
|
366 | data_dc = None | |
367 | if self.dataOut.data_dc is not None: |
|
367 | if self.dataOut.data_dc is not None: | |
368 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
368 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
369 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
369 | #data_dc = data_dc[:,beacon_heiIndexList] | |
370 |
|
370 | |||
371 | self.dataOut.data_spc = data_spc |
|
371 | self.dataOut.data_spc = data_spc | |
372 | self.dataOut.data_cspc = data_cspc |
|
372 | self.dataOut.data_cspc = data_cspc | |
373 | self.dataOut.data_dc = data_dc |
|
373 | self.dataOut.data_dc = data_dc | |
374 | self.dataOut.heightList = heightList |
|
374 | self.dataOut.heightList = heightList | |
375 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
375 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
376 |
|
376 | |||
377 | return 1 |
|
377 | return 1 | |
378 |
|
378 | |||
379 |
|
379 | |||
380 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
380 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
381 | """ |
|
381 | """ | |
382 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
382 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
383 | minIndex <= index <= maxIndex |
|
383 | minIndex <= index <= maxIndex | |
384 |
|
384 | |||
385 | Input: |
|
385 | Input: | |
386 | minIndex : valor de indice minimo de altura a considerar |
|
386 | minIndex : valor de indice minimo de altura a considerar | |
387 | maxIndex : valor de indice maximo de altura a considerar |
|
387 | maxIndex : valor de indice maximo de altura a considerar | |
388 |
|
388 | |||
389 | Affected: |
|
389 | Affected: | |
390 | self.dataOut.data_spc |
|
390 | self.dataOut.data_spc | |
391 | self.dataOut.data_cspc |
|
391 | self.dataOut.data_cspc | |
392 | self.dataOut.data_dc |
|
392 | self.dataOut.data_dc | |
393 | self.dataOut.heightList |
|
393 | self.dataOut.heightList | |
394 |
|
394 | |||
395 | Return: |
|
395 | Return: | |
396 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
396 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
397 | """ |
|
397 | """ | |
398 |
|
398 | |||
399 | if (minIndex < 0) or (minIndex > maxIndex): |
|
399 | if (minIndex < 0) or (minIndex > maxIndex): | |
400 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
400 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) | |
401 |
|
401 | |||
402 | if (maxIndex >= self.dataOut.nHeights): |
|
402 | if (maxIndex >= self.dataOut.nHeights): | |
403 | maxIndex = self.dataOut.nHeights-1 |
|
403 | maxIndex = self.dataOut.nHeights-1 | |
404 |
|
404 | |||
405 | #Spectra |
|
405 | #Spectra | |
406 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
406 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
407 |
|
407 | |||
408 | data_cspc = None |
|
408 | data_cspc = None | |
409 | if self.dataOut.data_cspc is not None: |
|
409 | if self.dataOut.data_cspc is not None: | |
410 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
410 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
411 |
|
411 | |||
412 | data_dc = None |
|
412 | data_dc = None | |
413 | if self.dataOut.data_dc is not None: |
|
413 | if self.dataOut.data_dc is not None: | |
414 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
414 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
415 |
|
415 | |||
416 | self.dataOut.data_spc = data_spc |
|
416 | self.dataOut.data_spc = data_spc | |
417 | self.dataOut.data_cspc = data_cspc |
|
417 | self.dataOut.data_cspc = data_cspc | |
418 | self.dataOut.data_dc = data_dc |
|
418 | self.dataOut.data_dc = data_dc | |
419 |
|
419 | |||
420 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
420 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
421 |
|
421 | |||
422 | return 1 |
|
422 | return 1 | |
423 |
|
423 | |||
424 | def removeDC(self, mode = 2): |
|
424 | def removeDC(self, mode = 2): | |
425 | jspectra = self.dataOut.data_spc |
|
425 | jspectra = self.dataOut.data_spc | |
426 | jcspectra = self.dataOut.data_cspc |
|
426 | jcspectra = self.dataOut.data_cspc | |
427 |
|
427 | |||
428 |
|
428 | |||
429 | num_chan = jspectra.shape[0] |
|
429 | num_chan = jspectra.shape[0] | |
430 | num_hei = jspectra.shape[2] |
|
430 | num_hei = jspectra.shape[2] | |
431 |
|
431 | |||
432 | if jcspectra is not None: |
|
432 | if jcspectra is not None: | |
433 | jcspectraExist = True |
|
433 | jcspectraExist = True | |
434 | num_pairs = jcspectra.shape[0] |
|
434 | num_pairs = jcspectra.shape[0] | |
435 | else: jcspectraExist = False |
|
435 | else: jcspectraExist = False | |
436 |
|
436 | |||
437 | freq_dc = jspectra.shape[1]/2 |
|
437 | freq_dc = jspectra.shape[1]/2 | |
438 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
438 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
439 |
|
439 | |||
440 | if ind_vel[0]<0: |
|
440 | if ind_vel[0]<0: | |
441 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
441 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
442 |
|
442 | |||
443 | if mode == 1: |
|
443 | if mode == 1: | |
444 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
444 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
445 |
|
445 | |||
446 | if jcspectraExist: |
|
446 | if jcspectraExist: | |
447 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
447 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 | |
448 |
|
448 | |||
449 | if mode == 2: |
|
449 | if mode == 2: | |
450 |
|
450 | |||
451 | vel = numpy.array([-2,-1,1,2]) |
|
451 | vel = numpy.array([-2,-1,1,2]) | |
452 | xx = numpy.zeros([4,4]) |
|
452 | xx = numpy.zeros([4,4]) | |
453 |
|
453 | |||
454 | for fil in range(4): |
|
454 | for fil in range(4): | |
455 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
455 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
456 |
|
456 | |||
457 | xx_inv = numpy.linalg.inv(xx) |
|
457 | xx_inv = numpy.linalg.inv(xx) | |
458 | xx_aux = xx_inv[0,:] |
|
458 | xx_aux = xx_inv[0,:] | |
459 |
|
459 | |||
460 | for ich in range(num_chan): |
|
460 | for ich in range(num_chan): | |
461 | yy = jspectra[ich,ind_vel,:] |
|
461 | yy = jspectra[ich,ind_vel,:] | |
462 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
462 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
463 |
|
463 | |||
464 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
464 | junkid = jspectra[ich,freq_dc,:]<=0 | |
465 | cjunkid = sum(junkid) |
|
465 | cjunkid = sum(junkid) | |
466 |
|
466 | |||
467 | if cjunkid.any(): |
|
467 | if cjunkid.any(): | |
468 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
468 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
469 |
|
469 | |||
470 | if jcspectraExist: |
|
470 | if jcspectraExist: | |
471 | for ip in range(num_pairs): |
|
471 | for ip in range(num_pairs): | |
472 | yy = jcspectra[ip,ind_vel,:] |
|
472 | yy = jcspectra[ip,ind_vel,:] | |
473 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
473 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) | |
474 |
|
474 | |||
475 |
|
475 | |||
476 | self.dataOut.data_spc = jspectra |
|
476 | self.dataOut.data_spc = jspectra | |
477 | self.dataOut.data_cspc = jcspectra |
|
477 | self.dataOut.data_cspc = jcspectra | |
478 |
|
478 | |||
479 | return 1 |
|
479 | return 1 | |
480 |
|
480 | |||
481 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
481 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
482 |
|
482 | |||
483 | jspectra = self.dataOut.data_spc |
|
483 | jspectra = self.dataOut.data_spc | |
484 | jcspectra = self.dataOut.data_cspc |
|
484 | jcspectra = self.dataOut.data_cspc | |
485 | jnoise = self.dataOut.getNoise() |
|
485 | jnoise = self.dataOut.getNoise() | |
486 | num_incoh = self.dataOut.nIncohInt |
|
486 | num_incoh = self.dataOut.nIncohInt | |
487 |
|
487 | |||
488 | num_channel = jspectra.shape[0] |
|
488 | num_channel = jspectra.shape[0] | |
489 | num_prof = jspectra.shape[1] |
|
489 | num_prof = jspectra.shape[1] | |
490 | num_hei = jspectra.shape[2] |
|
490 | num_hei = jspectra.shape[2] | |
491 |
|
491 | |||
492 | #hei_interf |
|
492 | #hei_interf | |
493 | if hei_interf is None: |
|
493 | if hei_interf is None: | |
494 | count_hei = num_hei/2 #Como es entero no importa |
|
494 | count_hei = num_hei/2 #Como es entero no importa | |
495 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
495 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |
496 | hei_interf = numpy.asarray(hei_interf)[0] |
|
496 | hei_interf = numpy.asarray(hei_interf)[0] | |
497 | #nhei_interf |
|
497 | #nhei_interf | |
498 | if (nhei_interf == None): |
|
498 | if (nhei_interf == None): | |
499 | nhei_interf = 5 |
|
499 | nhei_interf = 5 | |
500 | if (nhei_interf < 1): |
|
500 | if (nhei_interf < 1): | |
501 | nhei_interf = 1 |
|
501 | nhei_interf = 1 | |
502 | if (nhei_interf > count_hei): |
|
502 | if (nhei_interf > count_hei): | |
503 | nhei_interf = count_hei |
|
503 | nhei_interf = count_hei | |
504 | if (offhei_interf == None): |
|
504 | if (offhei_interf == None): | |
505 | offhei_interf = 0 |
|
505 | offhei_interf = 0 | |
506 |
|
506 | |||
507 | ind_hei = range(num_hei) |
|
507 | ind_hei = range(num_hei) | |
508 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
508 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
509 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
509 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
510 | mask_prof = numpy.asarray(range(num_prof)) |
|
510 | mask_prof = numpy.asarray(range(num_prof)) | |
511 | num_mask_prof = mask_prof.size |
|
511 | num_mask_prof = mask_prof.size | |
512 | comp_mask_prof = [0, num_prof/2] |
|
512 | comp_mask_prof = [0, num_prof/2] | |
513 |
|
513 | |||
514 |
|
514 | |||
515 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
515 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
516 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
516 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
517 | jnoise = numpy.nan |
|
517 | jnoise = numpy.nan | |
518 | noise_exist = jnoise[0] < numpy.Inf |
|
518 | noise_exist = jnoise[0] < numpy.Inf | |
519 |
|
519 | |||
520 | #Subrutina de Remocion de la Interferencia |
|
520 | #Subrutina de Remocion de la Interferencia | |
521 | for ich in range(num_channel): |
|
521 | for ich in range(num_channel): | |
522 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
522 | #Se ordena los espectros segun su potencia (menor a mayor) | |
523 | power = jspectra[ich,mask_prof,:] |
|
523 | power = jspectra[ich,mask_prof,:] | |
524 | power = power[:,hei_interf] |
|
524 | power = power[:,hei_interf] | |
525 | power = power.sum(axis = 0) |
|
525 | power = power.sum(axis = 0) | |
526 | psort = power.ravel().argsort() |
|
526 | psort = power.ravel().argsort() | |
527 |
|
527 | |||
528 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
528 | #Se estima la interferencia promedio en los Espectros de Potencia empleando | |
529 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
529 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
530 |
|
530 | |||
531 | if noise_exist: |
|
531 | if noise_exist: | |
532 | # tmp_noise = jnoise[ich] / num_prof |
|
532 | # tmp_noise = jnoise[ich] / num_prof | |
533 | tmp_noise = jnoise[ich] |
|
533 | tmp_noise = jnoise[ich] | |
534 | junkspc_interf = junkspc_interf - tmp_noise |
|
534 | junkspc_interf = junkspc_interf - tmp_noise | |
535 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
535 | #junkspc_interf[:,comp_mask_prof] = 0 | |
536 |
|
536 | |||
537 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
537 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf | |
538 | jspc_interf = jspc_interf.transpose() |
|
538 | jspc_interf = jspc_interf.transpose() | |
539 | #Calculando el espectro de interferencia promedio |
|
539 | #Calculando el espectro de interferencia promedio | |
540 | noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) |
|
540 | noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) | |
541 | noiseid = noiseid[0] |
|
541 | noiseid = noiseid[0] | |
542 | cnoiseid = noiseid.size |
|
542 | cnoiseid = noiseid.size | |
543 | interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) |
|
543 | interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) | |
544 | interfid = interfid[0] |
|
544 | interfid = interfid[0] | |
545 | cinterfid = interfid.size |
|
545 | cinterfid = interfid.size | |
546 |
|
546 | |||
547 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
547 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 | |
548 |
|
548 | |||
549 | #Expandiendo los perfiles a limpiar |
|
549 | #Expandiendo los perfiles a limpiar | |
550 | if (cinterfid > 0): |
|
550 | if (cinterfid > 0): | |
551 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
551 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof | |
552 | new_interfid = numpy.asarray(new_interfid) |
|
552 | new_interfid = numpy.asarray(new_interfid) | |
553 | new_interfid = {x for x in new_interfid} |
|
553 | new_interfid = {x for x in new_interfid} | |
554 | new_interfid = numpy.array(list(new_interfid)) |
|
554 | new_interfid = numpy.array(list(new_interfid)) | |
555 | new_cinterfid = new_interfid.size |
|
555 | new_cinterfid = new_interfid.size | |
556 | else: new_cinterfid = 0 |
|
556 | else: new_cinterfid = 0 | |
557 |
|
557 | |||
558 | for ip in range(new_cinterfid): |
|
558 | for ip in range(new_cinterfid): | |
559 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
559 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() | |
560 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
560 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] | |
561 |
|
561 | |||
562 |
|
562 | |||
563 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
563 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices | |
564 |
|
564 | |||
565 | #Removiendo la interferencia del punto de mayor interferencia |
|
565 | #Removiendo la interferencia del punto de mayor interferencia | |
566 | ListAux = jspc_interf[mask_prof].tolist() |
|
566 | ListAux = jspc_interf[mask_prof].tolist() | |
567 | maxid = ListAux.index(max(ListAux)) |
|
567 | maxid = ListAux.index(max(ListAux)) | |
568 |
|
568 | |||
569 |
|
569 | |||
570 | if cinterfid > 0: |
|
570 | if cinterfid > 0: | |
571 | for ip in range(cinterfid*(interf == 2) - 1): |
|
571 | for ip in range(cinterfid*(interf == 2) - 1): | |
572 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero() |
|
572 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero() | |
573 | cind = len(ind) |
|
573 | cind = len(ind) | |
574 |
|
574 | |||
575 | if (cind > 0): |
|
575 | if (cind > 0): | |
576 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh)) |
|
576 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh)) | |
577 |
|
577 | |||
578 | ind = numpy.array([-2,-1,1,2]) |
|
578 | ind = numpy.array([-2,-1,1,2]) | |
579 | xx = numpy.zeros([4,4]) |
|
579 | xx = numpy.zeros([4,4]) | |
580 |
|
580 | |||
581 | for id1 in range(4): |
|
581 | for id1 in range(4): | |
582 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
582 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
583 |
|
583 | |||
584 | xx_inv = numpy.linalg.inv(xx) |
|
584 | xx_inv = numpy.linalg.inv(xx) | |
585 | xx = xx_inv[:,0] |
|
585 | xx = xx_inv[:,0] | |
586 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
586 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
587 | yy = jspectra[ich,mask_prof[ind],:] |
|
587 | yy = jspectra[ich,mask_prof[ind],:] | |
588 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
588 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
589 |
|
589 | |||
590 |
|
590 | |||
591 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero() |
|
591 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero() | |
592 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh)) |
|
592 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh)) | |
593 |
|
593 | |||
594 | #Remocion de Interferencia en el Cross Spectra |
|
594 | #Remocion de Interferencia en el Cross Spectra | |
595 | if jcspectra is None: return jspectra, jcspectra |
|
595 | if jcspectra is None: return jspectra, jcspectra | |
596 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
596 | num_pairs = jcspectra.size/(num_prof*num_hei) | |
597 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
597 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
598 |
|
598 | |||
599 | for ip in range(num_pairs): |
|
599 | for ip in range(num_pairs): | |
600 |
|
600 | |||
601 | #------------------------------------------- |
|
601 | #------------------------------------------- | |
602 |
|
602 | |||
603 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
603 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) | |
604 | cspower = cspower[:,hei_interf] |
|
604 | cspower = cspower[:,hei_interf] | |
605 | cspower = cspower.sum(axis = 0) |
|
605 | cspower = cspower.sum(axis = 0) | |
606 |
|
606 | |||
607 | cspsort = cspower.ravel().argsort() |
|
607 | cspsort = cspower.ravel().argsort() | |
608 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
608 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
609 | junkcspc_interf = junkcspc_interf.transpose() |
|
609 | junkcspc_interf = junkcspc_interf.transpose() | |
610 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
610 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf | |
611 |
|
611 | |||
612 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
612 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
613 |
|
613 | |||
614 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
614 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
615 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
615 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
616 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
616 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) | |
617 |
|
617 | |||
618 | for iprof in range(num_prof): |
|
618 | for iprof in range(num_prof): | |
619 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
619 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() | |
620 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
620 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] | |
621 |
|
621 | |||
622 | #Removiendo la Interferencia |
|
622 | #Removiendo la Interferencia | |
623 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
623 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf | |
624 |
|
624 | |||
625 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
625 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
626 | maxid = ListAux.index(max(ListAux)) |
|
626 | maxid = ListAux.index(max(ListAux)) | |
627 |
|
627 | |||
628 | ind = numpy.array([-2,-1,1,2]) |
|
628 | ind = numpy.array([-2,-1,1,2]) | |
629 | xx = numpy.zeros([4,4]) |
|
629 | xx = numpy.zeros([4,4]) | |
630 |
|
630 | |||
631 | for id1 in range(4): |
|
631 | for id1 in range(4): | |
632 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
632 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
633 |
|
633 | |||
634 | xx_inv = numpy.linalg.inv(xx) |
|
634 | xx_inv = numpy.linalg.inv(xx) | |
635 | xx = xx_inv[:,0] |
|
635 | xx = xx_inv[:,0] | |
636 |
|
636 | |||
637 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
637 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
638 | yy = jcspectra[ip,mask_prof[ind],:] |
|
638 | yy = jcspectra[ip,mask_prof[ind],:] | |
639 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
639 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
640 |
|
640 | |||
641 | #Guardar Resultados |
|
641 | #Guardar Resultados | |
642 | self.dataOut.data_spc = jspectra |
|
642 | self.dataOut.data_spc = jspectra | |
643 | self.dataOut.data_cspc = jcspectra |
|
643 | self.dataOut.data_cspc = jcspectra | |
644 |
|
644 | |||
645 | return 1 |
|
645 | return 1 | |
646 |
|
646 | |||
647 | def setRadarFrequency(self, frequency=None): |
|
647 | def setRadarFrequency(self, frequency=None): | |
648 |
|
648 | |||
649 | if frequency != None: |
|
649 | if frequency != None: | |
650 | self.dataOut.frequency = frequency |
|
650 | self.dataOut.frequency = frequency | |
651 |
|
651 | |||
652 | return 1 |
|
652 | return 1 | |
653 |
|
653 | |||
654 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
654 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
655 | #validacion de rango |
|
655 | #validacion de rango | |
656 | if minHei == None: |
|
656 | if minHei == None: | |
657 | minHei = self.dataOut.heightList[0] |
|
657 | minHei = self.dataOut.heightList[0] | |
658 |
|
658 | |||
659 | if maxHei == None: |
|
659 | if maxHei == None: | |
660 | maxHei = self.dataOut.heightList[-1] |
|
660 | maxHei = self.dataOut.heightList[-1] | |
661 |
|
661 | |||
662 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
662 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
663 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
663 | print 'minHei: %.2f is out of the heights range'%(minHei) | |
664 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
664 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) | |
665 | minHei = self.dataOut.heightList[0] |
|
665 | minHei = self.dataOut.heightList[0] | |
666 |
|
666 | |||
667 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
667 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
668 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
668 | print 'maxHei: %.2f is out of the heights range'%(maxHei) | |
669 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
669 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) | |
670 | maxHei = self.dataOut.heightList[-1] |
|
670 | maxHei = self.dataOut.heightList[-1] | |
671 |
|
671 | |||
672 | # validacion de velocidades |
|
672 | # validacion de velocidades | |
673 | velrange = self.dataOut.getVelRange(1) |
|
673 | velrange = self.dataOut.getVelRange(1) | |
674 |
|
674 | |||
675 | if minVel == None: |
|
675 | if minVel == None: | |
676 | minVel = velrange[0] |
|
676 | minVel = velrange[0] | |
677 |
|
677 | |||
678 | if maxVel == None: |
|
678 | if maxVel == None: | |
679 | maxVel = velrange[-1] |
|
679 | maxVel = velrange[-1] | |
680 |
|
680 | |||
681 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
681 | if (minVel < velrange[0]) or (minVel > maxVel): | |
682 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
682 | print 'minVel: %.2f is out of the velocity range'%(minVel) | |
683 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
683 | print 'minVel is setting to %.2f'%(velrange[0]) | |
684 | minVel = velrange[0] |
|
684 | minVel = velrange[0] | |
685 |
|
685 | |||
686 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
686 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
687 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
687 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) | |
688 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
688 | print 'maxVel is setting to %.2f'%(velrange[-1]) | |
689 | maxVel = velrange[-1] |
|
689 | maxVel = velrange[-1] | |
690 |
|
690 | |||
691 | # seleccion de indices para rango |
|
691 | # seleccion de indices para rango | |
692 | minIndex = 0 |
|
692 | minIndex = 0 | |
693 | maxIndex = 0 |
|
693 | maxIndex = 0 | |
694 | heights = self.dataOut.heightList |
|
694 | heights = self.dataOut.heightList | |
695 |
|
695 | |||
696 | inda = numpy.where(heights >= minHei) |
|
696 | inda = numpy.where(heights >= minHei) | |
697 | indb = numpy.where(heights <= maxHei) |
|
697 | indb = numpy.where(heights <= maxHei) | |
698 |
|
698 | |||
699 | try: |
|
699 | try: | |
700 | minIndex = inda[0][0] |
|
700 | minIndex = inda[0][0] | |
701 | except: |
|
701 | except: | |
702 | minIndex = 0 |
|
702 | minIndex = 0 | |
703 |
|
703 | |||
704 | try: |
|
704 | try: | |
705 | maxIndex = indb[0][-1] |
|
705 | maxIndex = indb[0][-1] | |
706 | except: |
|
706 | except: | |
707 | maxIndex = len(heights) |
|
707 | maxIndex = len(heights) | |
708 |
|
708 | |||
709 | if (minIndex < 0) or (minIndex > maxIndex): |
|
709 | if (minIndex < 0) or (minIndex > maxIndex): | |
710 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
710 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
711 |
|
711 | |||
712 | if (maxIndex >= self.dataOut.nHeights): |
|
712 | if (maxIndex >= self.dataOut.nHeights): | |
713 | maxIndex = self.dataOut.nHeights-1 |
|
713 | maxIndex = self.dataOut.nHeights-1 | |
714 |
|
714 | |||
715 | # seleccion de indices para velocidades |
|
715 | # seleccion de indices para velocidades | |
716 | indminvel = numpy.where(velrange >= minVel) |
|
716 | indminvel = numpy.where(velrange >= minVel) | |
717 | indmaxvel = numpy.where(velrange <= maxVel) |
|
717 | indmaxvel = numpy.where(velrange <= maxVel) | |
718 | try: |
|
718 | try: | |
719 | minIndexVel = indminvel[0][0] |
|
719 | minIndexVel = indminvel[0][0] | |
720 | except: |
|
720 | except: | |
721 | minIndexVel = 0 |
|
721 | minIndexVel = 0 | |
722 |
|
722 | |||
723 | try: |
|
723 | try: | |
724 | maxIndexVel = indmaxvel[0][-1] |
|
724 | maxIndexVel = indmaxvel[0][-1] | |
725 | except: |
|
725 | except: | |
726 | maxIndexVel = len(velrange) |
|
726 | maxIndexVel = len(velrange) | |
727 |
|
727 | |||
728 | #seleccion del espectro |
|
728 | #seleccion del espectro | |
729 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
729 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] | |
730 | #estimacion de ruido |
|
730 | #estimacion de ruido | |
731 | noise = numpy.zeros(self.dataOut.nChannels) |
|
731 | noise = numpy.zeros(self.dataOut.nChannels) | |
732 |
|
732 | |||
733 | for channel in range(self.dataOut.nChannels): |
|
733 | for channel in range(self.dataOut.nChannels): | |
734 | daux = data_spc[channel,:,:] |
|
734 | daux = data_spc[channel,:,:] | |
735 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
735 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
736 |
|
736 | |||
737 | self.dataOut.noise_estimation = noise.copy() |
|
737 | self.dataOut.noise_estimation = noise.copy() | |
738 |
|
738 | |||
739 | return 1 No newline at end of file |
|
739 | return 1 |
General Comments 0
You need to be logged in to leave comments.
Login now