@@ -1,339 +1,339 | |||
|
1 | 1 | import numpy |
|
2 | 2 | |
|
3 | 3 | from jroproc_base import ProcessingUnit, Operation |
|
4 | 4 | from model.data.jrodata import SpectraHeis |
|
5 | 5 | |
|
6 | 6 | class SpectraHeisProc(ProcessingUnit): |
|
7 | 7 | |
|
8 | 8 | def __init__(self): |
|
9 | 9 | |
|
10 | 10 | ProcessingUnit.__init__(self) |
|
11 | 11 | |
|
12 | 12 | # self.buffer = None |
|
13 | 13 | # self.firstdatatime = None |
|
14 | 14 | # self.profIndex = 0 |
|
15 | 15 | self.dataOut = SpectraHeis() |
|
16 | 16 | |
|
17 | 17 | def __updateObjFromInput(self): |
|
18 | 18 | |
|
19 | 19 | self.dataOut.timeZone = self.dataIn.timeZone |
|
20 | 20 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
21 | 21 | self.dataOut.errorCount = self.dataIn.errorCount |
|
22 | 22 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
23 | 23 | |
|
24 | 24 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
25 | 25 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
26 | 26 | self.dataOut.channelList = self.dataIn.channelList |
|
27 | 27 | self.dataOut.heightList = self.dataIn.heightList |
|
28 | 28 | # self.dataOut.dtype = self.dataIn.dtype |
|
29 | 29 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
30 | 30 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
31 | 31 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
32 | 32 | self.dataOut.nBaud = self.dataIn.nBaud |
|
33 | 33 | self.dataOut.nCode = self.dataIn.nCode |
|
34 | 34 | self.dataOut.code = self.dataIn.code |
|
35 | 35 | # self.dataOut.nProfiles = 1 |
|
36 | 36 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
37 | 37 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
38 | 38 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
39 | 39 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
40 | 40 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
41 | 41 | self.dataOut.utctime = self.dataIn.utctime |
|
42 | 42 | # self.dataOut.utctime = self.firstdatatime |
|
43 | 43 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
44 | 44 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
45 | 45 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
46 | 46 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
47 | 47 | self.dataOut.nIncohInt = 1 |
|
48 | 48 | # self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
49 | 49 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
50 | 50 | |
|
51 | 51 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
52 | 52 | # self.dataOut.set=self.dataIn.set |
|
53 | 53 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | def __updateObjFromFits(self): |
|
57 | 57 | self.dataOut.utctime = self.dataIn.utctime |
|
58 | 58 | self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
59 | 59 | |
|
60 | 60 | self.dataOut.channelList = self.dataIn.channelList |
|
61 | 61 | self.dataOut.heightList = self.dataIn.heightList |
|
62 | 62 | self.dataOut.data_spc = self.dataIn.data |
|
63 | 63 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
64 | 64 | self.dataOut.timeZone = self.dataIn.timeZone |
|
65 | 65 | self.dataOut.useLocalTime = True |
|
66 | 66 | # self.dataOut. |
|
67 | 67 | # self.dataOut. |
|
68 | 68 | |
|
69 | 69 | def __getFft(self): |
|
70 | 70 | |
|
71 | 71 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
72 | 72 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
73 | 73 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
74 | 74 | self.dataOut.data_spc = spc |
|
75 | 75 | |
|
76 | 76 | def run(self): |
|
77 | 77 | |
|
78 | 78 | self.dataOut.flagNoData = True |
|
79 | 79 | |
|
80 | 80 | if self.dataIn.type == "Fits": |
|
81 | 81 | self.__updateObjFromFits() |
|
82 | 82 | self.dataOut.flagNoData = False |
|
83 | 83 | return |
|
84 | 84 | |
|
85 | 85 | if self.dataIn.type == "SpectraHeis": |
|
86 | 86 | self.dataOut.copy(self.dataIn) |
|
87 | 87 | return |
|
88 | 88 | |
|
89 | 89 | if self.dataIn.type == "Voltage": |
|
90 | 90 | self.__updateObjFromInput() |
|
91 | 91 | self.__getFft() |
|
92 | 92 | self.dataOut.flagNoData = False |
|
93 | 93 | |
|
94 | 94 | return |
|
95 | 95 | |
|
96 | 96 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | def selectChannels(self, channelList): |
|
100 | 100 | |
|
101 | 101 | channelIndexList = [] |
|
102 | 102 | |
|
103 | 103 | for channel in channelList: |
|
104 | 104 | index = self.dataOut.channelList.index(channel) |
|
105 | 105 | channelIndexList.append(index) |
|
106 | 106 | |
|
107 | 107 | self.selectChannelsByIndex(channelIndexList) |
|
108 | 108 | |
|
109 | 109 | def selectChannelsByIndex(self, channelIndexList): |
|
110 | 110 | """ |
|
111 | 111 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
112 | 112 | |
|
113 | 113 | Input: |
|
114 | 114 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
115 | 115 | |
|
116 | 116 | Affected: |
|
117 | 117 | self.dataOut.data |
|
118 | 118 | self.dataOut.channelIndexList |
|
119 | 119 | self.dataOut.nChannels |
|
120 | 120 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
121 | 121 | self.dataOut.systemHeaderObj.numChannels |
|
122 | 122 | self.dataOut.m_ProcessingHeader.blockSize |
|
123 | 123 | |
|
124 | 124 | Return: |
|
125 | 125 | None |
|
126 | 126 | """ |
|
127 | 127 | |
|
128 | 128 | for channelIndex in channelIndexList: |
|
129 | 129 | if channelIndex not in self.dataOut.channelIndexList: |
|
130 | 130 | print channelIndexList |
|
131 | 131 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
132 | 132 | |
|
133 | 133 | # nChannels = len(channelIndexList) |
|
134 | 134 | |
|
135 | 135 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
136 | 136 | |
|
137 | 137 | self.dataOut.data_spc = data_spc |
|
138 | 138 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
139 | 139 | |
|
140 | 140 | return 1 |
|
141 | 141 | |
|
142 | 142 | class IncohInt4SpectraHeis(Operation): |
|
143 | 143 | |
|
144 | 144 | isConfig = False |
|
145 | 145 | |
|
146 | 146 | __profIndex = 0 |
|
147 | 147 | __withOverapping = False |
|
148 | 148 | |
|
149 | 149 | __byTime = False |
|
150 | 150 | __initime = None |
|
151 | 151 | __lastdatatime = None |
|
152 | 152 | __integrationtime = None |
|
153 | 153 | |
|
154 | 154 | __buffer = None |
|
155 | 155 | |
|
156 | 156 | __dataReady = False |
|
157 | 157 | |
|
158 | 158 | n = None |
|
159 | 159 | |
|
160 | 160 | |
|
161 | 161 | def __init__(self): |
|
162 | 162 | |
|
163 | 163 | Operation.__init__(self) |
|
164 | 164 | # self.isConfig = False |
|
165 | 165 | |
|
166 | 166 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
167 | 167 | """ |
|
168 | 168 | Set the parameters of the integration class. |
|
169 | 169 | |
|
170 | 170 | Inputs: |
|
171 | 171 | |
|
172 | 172 | n : Number of coherent integrations |
|
173 | 173 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
174 | 174 | overlapping : |
|
175 | 175 | |
|
176 | 176 | """ |
|
177 | 177 | |
|
178 | 178 | self.__initime = None |
|
179 | 179 | self.__lastdatatime = 0 |
|
180 | 180 | self.__buffer = None |
|
181 | 181 | self.__dataReady = False |
|
182 | 182 | |
|
183 | 183 | |
|
184 | 184 | if n == None and timeInterval == None: |
|
185 | 185 | raise ValueError, "n or timeInterval should be specified ..." |
|
186 | 186 | |
|
187 | 187 | if n != None: |
|
188 | 188 | self.n = n |
|
189 | 189 | self.__byTime = False |
|
190 | 190 | else: |
|
191 | 191 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
192 | 192 | self.n = 9999 |
|
193 | 193 | self.__byTime = True |
|
194 | 194 | |
|
195 | 195 | if overlapping: |
|
196 | 196 | self.__withOverapping = True |
|
197 | 197 | self.__buffer = None |
|
198 | 198 | else: |
|
199 | 199 | self.__withOverapping = False |
|
200 | 200 | self.__buffer = 0 |
|
201 | 201 | |
|
202 | 202 | self.__profIndex = 0 |
|
203 | 203 | |
|
204 | 204 | def putData(self, data): |
|
205 | 205 | |
|
206 | 206 | """ |
|
207 | 207 | Add a profile to the __buffer and increase in one the __profileIndex |
|
208 | 208 | |
|
209 | 209 | """ |
|
210 | 210 | |
|
211 | 211 | if not self.__withOverapping: |
|
212 | 212 | self.__buffer += data.copy() |
|
213 | 213 | self.__profIndex += 1 |
|
214 | 214 | return |
|
215 | 215 | |
|
216 | 216 | #Overlapping data |
|
217 | 217 | nChannels, nHeis = data.shape |
|
218 | 218 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
219 | 219 | |
|
220 | 220 | #If the buffer is empty then it takes the data value |
|
221 | 221 | if self.__buffer == None: |
|
222 | 222 | self.__buffer = data |
|
223 | 223 | self.__profIndex += 1 |
|
224 | 224 | return |
|
225 | 225 | |
|
226 | 226 | #If the buffer length is lower than n then stakcing the data value |
|
227 | 227 | if self.__profIndex < self.n: |
|
228 | 228 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
229 | 229 | self.__profIndex += 1 |
|
230 | 230 | return |
|
231 | 231 | |
|
232 | 232 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
233 | 233 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
234 | 234 | self.__buffer[self.n-1] = data |
|
235 | 235 | self.__profIndex = self.n |
|
236 | 236 | return |
|
237 | 237 | |
|
238 | 238 | |
|
239 | 239 | def pushData(self): |
|
240 | 240 | """ |
|
241 | 241 | Return the sum of the last profiles and the profiles used in the sum. |
|
242 | 242 | |
|
243 | 243 | Affected: |
|
244 | 244 | |
|
245 | 245 | self.__profileIndex |
|
246 | 246 | |
|
247 | 247 | """ |
|
248 | 248 | |
|
249 | 249 | if not self.__withOverapping: |
|
250 | 250 | data = self.__buffer |
|
251 | 251 | n = self.__profIndex |
|
252 | 252 | |
|
253 | 253 | self.__buffer = 0 |
|
254 | 254 | self.__profIndex = 0 |
|
255 | 255 | |
|
256 | 256 | return data, n |
|
257 | 257 | |
|
258 | 258 | #Integration with Overlapping |
|
259 | 259 | data = numpy.sum(self.__buffer, axis=0) |
|
260 | 260 | n = self.__profIndex |
|
261 | 261 | |
|
262 | 262 | return data, n |
|
263 | 263 | |
|
264 | 264 | def byProfiles(self, data): |
|
265 | 265 | |
|
266 | 266 | self.__dataReady = False |
|
267 | 267 | avgdata = None |
|
268 | 268 | # n = None |
|
269 | 269 | |
|
270 | 270 | self.putData(data) |
|
271 | 271 | |
|
272 | 272 | if self.__profIndex == self.n: |
|
273 | 273 | |
|
274 | 274 | avgdata, n = self.pushData() |
|
275 | 275 | self.__dataReady = True |
|
276 | 276 | |
|
277 | 277 | return avgdata |
|
278 | 278 | |
|
279 | 279 | def byTime(self, data, datatime): |
|
280 | 280 | |
|
281 | 281 | self.__dataReady = False |
|
282 | 282 | avgdata = None |
|
283 | 283 | n = None |
|
284 | 284 | |
|
285 | 285 | self.putData(data) |
|
286 | 286 | |
|
287 | 287 | if (datatime - self.__initime) >= self.__integrationtime: |
|
288 | 288 | avgdata, n = self.pushData() |
|
289 | 289 | self.n = n |
|
290 | 290 | self.__dataReady = True |
|
291 | 291 | |
|
292 | 292 | return avgdata |
|
293 | 293 | |
|
294 | 294 | def integrate(self, data, datatime=None): |
|
295 | 295 | |
|
296 | 296 | if self.__initime == None: |
|
297 | 297 | self.__initime = datatime |
|
298 | 298 | |
|
299 | 299 | if self.__byTime: |
|
300 | 300 | avgdata = self.byTime(data, datatime) |
|
301 | 301 | else: |
|
302 | 302 | avgdata = self.byProfiles(data) |
|
303 | 303 | |
|
304 | 304 | |
|
305 | 305 | self.__lastdatatime = datatime |
|
306 | 306 | |
|
307 | 307 | if avgdata == None: |
|
308 | 308 | return None, None |
|
309 | 309 | |
|
310 | 310 | avgdatatime = self.__initime |
|
311 | 311 | |
|
312 | 312 | deltatime = datatime -self.__lastdatatime |
|
313 | 313 | |
|
314 | 314 | if not self.__withOverapping: |
|
315 | 315 | self.__initime = datatime |
|
316 | 316 | else: |
|
317 | 317 | self.__initime += deltatime |
|
318 | 318 | |
|
319 | 319 | return avgdata, avgdatatime |
|
320 | 320 | |
|
321 | 321 | def run(self, dataOut, **kwargs): |
|
322 | 322 | |
|
323 | 323 | if not self.isConfig: |
|
324 | 324 | self.setup(**kwargs) |
|
325 | 325 | self.isConfig = True |
|
326 | 326 | |
|
327 | 327 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
328 | 328 | |
|
329 | 329 | # dataOut.timeInterval *= n |
|
330 | 330 | dataOut.flagNoData = True |
|
331 | 331 | |
|
332 | 332 | if self.__dataReady: |
|
333 | 333 | dataOut.data_spc = avgdata |
|
334 | 334 | dataOut.nIncohInt *= self.n |
|
335 | 335 | # dataOut.nCohInt *= self.n |
|
336 | 336 | dataOut.utctime = avgdatatime |
|
337 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt | |
|
337 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt | |
|
338 | 338 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
339 | 339 | dataOut.flagNoData = False No newline at end of file |
@@ -1,935 +1,935 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import math |
|
3 | 3 | |
|
4 | 4 | from jroproc_base import ProcessingUnit, Operation |
|
5 | 5 | from model.data.jrodata import Spectra |
|
6 | 6 | from model.data.jrodata import hildebrand_sekhon |
|
7 | 7 | |
|
8 | 8 | class SpectraProc(ProcessingUnit): |
|
9 | 9 | |
|
10 | 10 | def __init__(self): |
|
11 | 11 | |
|
12 | 12 | ProcessingUnit.__init__(self) |
|
13 | 13 | |
|
14 | 14 | self.buffer = None |
|
15 | 15 | self.firstdatatime = None |
|
16 | 16 | self.profIndex = 0 |
|
17 | 17 | self.dataOut = Spectra() |
|
18 | 18 | self.id_min = None |
|
19 | 19 | self.id_max = None |
|
20 | 20 | |
|
21 | 21 | def __updateObjFromInput(self): |
|
22 | 22 | |
|
23 | 23 | self.dataOut.timeZone = self.dataIn.timeZone |
|
24 | 24 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
25 | 25 | self.dataOut.errorCount = self.dataIn.errorCount |
|
26 | 26 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
27 | 27 | |
|
28 | 28 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
29 | 29 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
30 | 30 | self.dataOut.channelList = self.dataIn.channelList |
|
31 | 31 | self.dataOut.heightList = self.dataIn.heightList |
|
32 | 32 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
33 | 33 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
34 | 34 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
35 | 35 | self.dataOut.nBaud = self.dataIn.nBaud |
|
36 | 36 | self.dataOut.nCode = self.dataIn.nCode |
|
37 | 37 | self.dataOut.code = self.dataIn.code |
|
38 | 38 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
39 | 39 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
40 | 40 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
41 | 41 | self.dataOut.utctime = self.firstdatatime |
|
42 | 42 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
43 | 43 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
44 | 44 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
45 | 45 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
46 | 46 | self.dataOut.nIncohInt = 1 |
|
47 | 47 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
48 | 48 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
49 | 49 | |
|
50 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
|
50 | # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
|
51 | 51 | self.dataOut.frequency = self.dataIn.frequency |
|
52 | 52 | self.dataOut.realtime = self.dataIn.realtime |
|
53 | 53 | |
|
54 | 54 | self.dataOut.azimuth = self.dataIn.azimuth |
|
55 | 55 | self.dataOut.zenith = self.dataIn.zenith |
|
56 | 56 | |
|
57 | 57 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
58 | 58 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
59 | 59 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
60 | 60 | |
|
61 | 61 | def __getFft(self): |
|
62 | 62 | """ |
|
63 | 63 | Convierte valores de Voltaje a Spectra |
|
64 | 64 | |
|
65 | 65 | Affected: |
|
66 | 66 | self.dataOut.data_spc |
|
67 | 67 | self.dataOut.data_cspc |
|
68 | 68 | self.dataOut.data_dc |
|
69 | 69 | self.dataOut.heightList |
|
70 | 70 | self.profIndex |
|
71 | 71 | self.buffer |
|
72 | 72 | self.dataOut.flagNoData |
|
73 | 73 | """ |
|
74 | 74 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
75 | 75 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
76 | 76 | dc = fft_volt[:,0,:] |
|
77 | 77 | |
|
78 | 78 | #calculo de self-spectra |
|
79 | 79 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
80 | 80 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
81 | 81 | spc = spc.real |
|
82 | 82 | |
|
83 | 83 | blocksize = 0 |
|
84 | 84 | blocksize += dc.size |
|
85 | 85 | blocksize += spc.size |
|
86 | 86 | |
|
87 | 87 | cspc = None |
|
88 | 88 | pairIndex = 0 |
|
89 | 89 | if self.dataOut.pairsList != None: |
|
90 | 90 | #calculo de cross-spectra |
|
91 | 91 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
92 | 92 | for pair in self.dataOut.pairsList: |
|
93 | 93 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
94 | 94 | pairIndex += 1 |
|
95 | 95 | blocksize += cspc.size |
|
96 | 96 | |
|
97 | 97 | self.dataOut.data_spc = spc |
|
98 | 98 | self.dataOut.data_cspc = cspc |
|
99 | 99 | self.dataOut.data_dc = dc |
|
100 | 100 | self.dataOut.blockSize = blocksize |
|
101 | 101 | self.dataOut.flagShiftFFT = False |
|
102 | 102 | |
|
103 | 103 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None): |
|
104 | 104 | |
|
105 | 105 | self.dataOut.flagNoData = True |
|
106 | 106 | |
|
107 | 107 | if self.dataIn.type == "Spectra": |
|
108 | 108 | self.dataOut.copy(self.dataIn) |
|
109 | 109 | return True |
|
110 | 110 | |
|
111 | 111 | if self.dataIn.type == "Voltage": |
|
112 | 112 | |
|
113 | 113 | if nFFTPoints == None: |
|
114 | 114 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
115 | 115 | |
|
116 | 116 | if nProfiles == None: |
|
117 | 117 | raise ValueError, "This SpectraProc.run() need nProfiles input variable" |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | if ippFactor == None: |
|
121 | 121 | ippFactor = 1 |
|
122 | 122 | self.dataOut.ippFactor = ippFactor |
|
123 | 123 | |
|
124 | 124 | self.dataOut.nFFTPoints = nFFTPoints |
|
125 | 125 | self.dataOut.pairsList = pairsList |
|
126 | 126 | |
|
127 | 127 | if self.buffer == None: |
|
128 | 128 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
129 | 129 | nProfiles, |
|
130 | 130 | self.dataIn.nHeights), |
|
131 | 131 | dtype='complex') |
|
132 | 132 | self.id_min = 0 |
|
133 | 133 | self.id_max = self.dataIn.data.shape[1] |
|
134 | 134 | |
|
135 | 135 | if len(self.dataIn.data.shape) == 2: |
|
136 | 136 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
137 | 137 | self.profIndex += 1 |
|
138 | 138 | else: |
|
139 | 139 | if self.dataIn.data.shape[1] == nProfiles: |
|
140 | 140 | self.buffer = self.dataIn.data.copy() |
|
141 | 141 | self.profIndex = nProfiles |
|
142 | 142 | elif self.dataIn.data.shape[1] < nProfiles: |
|
143 | 143 | self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data |
|
144 | 144 | self.profIndex += self.dataIn.data.shape[1] |
|
145 | 145 | self.id_min += self.dataIn.data.shape[1] |
|
146 | 146 | self.id_max += self.dataIn.data.shape[1] |
|
147 | 147 | else: |
|
148 | 148 | raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles) |
|
149 | 149 | self.dataOut.flagNoData = True |
|
150 | 150 | return 0 |
|
151 | 151 | |
|
152 | 152 | |
|
153 | 153 | if self.firstdatatime == None: |
|
154 | 154 | self.firstdatatime = self.dataIn.utctime |
|
155 | 155 | |
|
156 | 156 | if self.profIndex == nProfiles: |
|
157 | 157 | self.__updateObjFromInput() |
|
158 | 158 | self.__getFft() |
|
159 | 159 | |
|
160 | 160 | self.dataOut.flagNoData = False |
|
161 | 161 | |
|
162 | 162 | self.buffer = None |
|
163 | 163 | self.firstdatatime = None |
|
164 | 164 | self.profIndex = 0 |
|
165 | 165 | |
|
166 | 166 | return True |
|
167 | 167 | |
|
168 | 168 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
169 | 169 | |
|
170 | 170 | def selectChannels(self, channelList): |
|
171 | 171 | |
|
172 | 172 | channelIndexList = [] |
|
173 | 173 | |
|
174 | 174 | for channel in channelList: |
|
175 | 175 | index = self.dataOut.channelList.index(channel) |
|
176 | 176 | channelIndexList.append(index) |
|
177 | 177 | |
|
178 | 178 | self.selectChannelsByIndex(channelIndexList) |
|
179 | 179 | |
|
180 | 180 | def selectChannelsByIndex(self, channelIndexList): |
|
181 | 181 | """ |
|
182 | 182 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
183 | 183 | |
|
184 | 184 | Input: |
|
185 | 185 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
186 | 186 | |
|
187 | 187 | Affected: |
|
188 | 188 | self.dataOut.data_spc |
|
189 | 189 | self.dataOut.channelIndexList |
|
190 | 190 | self.dataOut.nChannels |
|
191 | 191 | |
|
192 | 192 | Return: |
|
193 | 193 | None |
|
194 | 194 | """ |
|
195 | 195 | |
|
196 | 196 | for channelIndex in channelIndexList: |
|
197 | 197 | if channelIndex not in self.dataOut.channelIndexList: |
|
198 | 198 | print channelIndexList |
|
199 | 199 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
200 | 200 | |
|
201 | 201 | # nChannels = len(channelIndexList) |
|
202 | 202 | |
|
203 | 203 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
204 | 204 | |
|
205 | 205 | self.dataOut.data_spc = data_spc |
|
206 | 206 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
207 | 207 | # self.dataOut.nChannels = nChannels |
|
208 | 208 | |
|
209 | 209 | return 1 |
|
210 | 210 | |
|
211 | 211 | def selectHeights(self, minHei, maxHei): |
|
212 | 212 | """ |
|
213 | 213 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
214 | 214 | minHei <= height <= maxHei |
|
215 | 215 | |
|
216 | 216 | Input: |
|
217 | 217 | minHei : valor minimo de altura a considerar |
|
218 | 218 | maxHei : valor maximo de altura a considerar |
|
219 | 219 | |
|
220 | 220 | Affected: |
|
221 | 221 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
222 | 222 | |
|
223 | 223 | Return: |
|
224 | 224 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
225 | 225 | """ |
|
226 | 226 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
227 | 227 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
228 | 228 | |
|
229 | 229 | if (maxHei > self.dataOut.heightList[-1]): |
|
230 | 230 | maxHei = self.dataOut.heightList[-1] |
|
231 | 231 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
232 | 232 | |
|
233 | 233 | minIndex = 0 |
|
234 | 234 | maxIndex = 0 |
|
235 | 235 | heights = self.dataOut.heightList |
|
236 | 236 | |
|
237 | 237 | inda = numpy.where(heights >= minHei) |
|
238 | 238 | indb = numpy.where(heights <= maxHei) |
|
239 | 239 | |
|
240 | 240 | try: |
|
241 | 241 | minIndex = inda[0][0] |
|
242 | 242 | except: |
|
243 | 243 | minIndex = 0 |
|
244 | 244 | |
|
245 | 245 | try: |
|
246 | 246 | maxIndex = indb[0][-1] |
|
247 | 247 | except: |
|
248 | 248 | maxIndex = len(heights) |
|
249 | 249 | |
|
250 | 250 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
251 | 251 | |
|
252 | 252 | return 1 |
|
253 | 253 | |
|
254 | 254 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
255 | 255 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
256 | 256 | |
|
257 | 257 | if hei_ref != None: |
|
258 | 258 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
259 | 259 | |
|
260 | 260 | minIndex = min(newheis[0]) |
|
261 | 261 | maxIndex = max(newheis[0]) |
|
262 | 262 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
263 | 263 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
264 | 264 | |
|
265 | 265 | # determina indices |
|
266 | 266 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
267 | 267 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
268 | 268 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
269 | 269 | beacon_heiIndexList = [] |
|
270 | 270 | for val in avg_dB.tolist(): |
|
271 | 271 | if val >= beacon_dB[0]: |
|
272 | 272 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
273 | 273 | |
|
274 | 274 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
275 | 275 | data_cspc = None |
|
276 | 276 | if self.dataOut.data_cspc != None: |
|
277 | 277 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
278 | 278 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
279 | 279 | |
|
280 | 280 | data_dc = None |
|
281 | 281 | if self.dataOut.data_dc != None: |
|
282 | 282 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
283 | 283 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
284 | 284 | |
|
285 | 285 | self.dataOut.data_spc = data_spc |
|
286 | 286 | self.dataOut.data_cspc = data_cspc |
|
287 | 287 | self.dataOut.data_dc = data_dc |
|
288 | 288 | self.dataOut.heightList = heightList |
|
289 | 289 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
290 | 290 | |
|
291 | 291 | return 1 |
|
292 | 292 | |
|
293 | 293 | |
|
294 | 294 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
295 | 295 | """ |
|
296 | 296 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
297 | 297 | minIndex <= index <= maxIndex |
|
298 | 298 | |
|
299 | 299 | Input: |
|
300 | 300 | minIndex : valor de indice minimo de altura a considerar |
|
301 | 301 | maxIndex : valor de indice maximo de altura a considerar |
|
302 | 302 | |
|
303 | 303 | Affected: |
|
304 | 304 | self.dataOut.data_spc |
|
305 | 305 | self.dataOut.data_cspc |
|
306 | 306 | self.dataOut.data_dc |
|
307 | 307 | self.dataOut.heightList |
|
308 | 308 | |
|
309 | 309 | Return: |
|
310 | 310 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
311 | 311 | """ |
|
312 | 312 | |
|
313 | 313 | if (minIndex < 0) or (minIndex > maxIndex): |
|
314 | 314 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
315 | 315 | |
|
316 | 316 | if (maxIndex >= self.dataOut.nHeights): |
|
317 | 317 | maxIndex = self.dataOut.nHeights-1 |
|
318 | 318 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
319 | 319 | |
|
320 | 320 | # nHeights = maxIndex - minIndex + 1 |
|
321 | 321 | |
|
322 | 322 | #Spectra |
|
323 | 323 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
324 | 324 | |
|
325 | 325 | data_cspc = None |
|
326 | 326 | if self.dataOut.data_cspc != None: |
|
327 | 327 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
328 | 328 | |
|
329 | 329 | data_dc = None |
|
330 | 330 | if self.dataOut.data_dc != None: |
|
331 | 331 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
332 | 332 | |
|
333 | 333 | self.dataOut.data_spc = data_spc |
|
334 | 334 | self.dataOut.data_cspc = data_cspc |
|
335 | 335 | self.dataOut.data_dc = data_dc |
|
336 | 336 | |
|
337 | 337 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
338 | 338 | |
|
339 | 339 | return 1 |
|
340 | 340 | |
|
341 | 341 | def removeDC(self, mode = 2): |
|
342 | 342 | jspectra = self.dataOut.data_spc |
|
343 | 343 | jcspectra = self.dataOut.data_cspc |
|
344 | 344 | |
|
345 | 345 | |
|
346 | 346 | num_chan = jspectra.shape[0] |
|
347 | 347 | num_hei = jspectra.shape[2] |
|
348 | 348 | |
|
349 | 349 | if jcspectra != None: |
|
350 | 350 | jcspectraExist = True |
|
351 | 351 | num_pairs = jcspectra.shape[0] |
|
352 | 352 | else: jcspectraExist = False |
|
353 | 353 | |
|
354 | 354 | freq_dc = jspectra.shape[1]/2 |
|
355 | 355 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
356 | 356 | |
|
357 | 357 | if ind_vel[0]<0: |
|
358 | 358 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
359 | 359 | |
|
360 | 360 | if mode == 1: |
|
361 | 361 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
362 | 362 | |
|
363 | 363 | if jcspectraExist: |
|
364 | 364 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
365 | 365 | |
|
366 | 366 | if mode == 2: |
|
367 | 367 | |
|
368 | 368 | vel = numpy.array([-2,-1,1,2]) |
|
369 | 369 | xx = numpy.zeros([4,4]) |
|
370 | 370 | |
|
371 | 371 | for fil in range(4): |
|
372 | 372 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
373 | 373 | |
|
374 | 374 | xx_inv = numpy.linalg.inv(xx) |
|
375 | 375 | xx_aux = xx_inv[0,:] |
|
376 | 376 | |
|
377 | 377 | for ich in range(num_chan): |
|
378 | 378 | yy = jspectra[ich,ind_vel,:] |
|
379 | 379 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
380 | 380 | |
|
381 | 381 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
382 | 382 | cjunkid = sum(junkid) |
|
383 | 383 | |
|
384 | 384 | if cjunkid.any(): |
|
385 | 385 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
386 | 386 | |
|
387 | 387 | if jcspectraExist: |
|
388 | 388 | for ip in range(num_pairs): |
|
389 | 389 | yy = jcspectra[ip,ind_vel,:] |
|
390 | 390 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
391 | 391 | |
|
392 | 392 | |
|
393 | 393 | self.dataOut.data_spc = jspectra |
|
394 | 394 | self.dataOut.data_cspc = jcspectra |
|
395 | 395 | |
|
396 | 396 | return 1 |
|
397 | 397 | |
|
398 | 398 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
399 | 399 | |
|
400 | 400 | jspectra = self.dataOut.data_spc |
|
401 | 401 | jcspectra = self.dataOut.data_cspc |
|
402 | 402 | jnoise = self.dataOut.getNoise() |
|
403 | 403 | num_incoh = self.dataOut.nIncohInt |
|
404 | 404 | |
|
405 | 405 | num_channel = jspectra.shape[0] |
|
406 | 406 | num_prof = jspectra.shape[1] |
|
407 | 407 | num_hei = jspectra.shape[2] |
|
408 | 408 | |
|
409 | 409 | #hei_interf |
|
410 | 410 | if hei_interf == None: |
|
411 | 411 | count_hei = num_hei/2 #Como es entero no importa |
|
412 | 412 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
413 | 413 | hei_interf = numpy.asarray(hei_interf)[0] |
|
414 | 414 | #nhei_interf |
|
415 | 415 | if (nhei_interf == None): |
|
416 | 416 | nhei_interf = 5 |
|
417 | 417 | if (nhei_interf < 1): |
|
418 | 418 | nhei_interf = 1 |
|
419 | 419 | if (nhei_interf > count_hei): |
|
420 | 420 | nhei_interf = count_hei |
|
421 | 421 | if (offhei_interf == None): |
|
422 | 422 | offhei_interf = 0 |
|
423 | 423 | |
|
424 | 424 | ind_hei = range(num_hei) |
|
425 | 425 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
426 | 426 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
427 | 427 | mask_prof = numpy.asarray(range(num_prof)) |
|
428 | 428 | num_mask_prof = mask_prof.size |
|
429 | 429 | comp_mask_prof = [0, num_prof/2] |
|
430 | 430 | |
|
431 | 431 | |
|
432 | 432 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
433 | 433 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
434 | 434 | jnoise = numpy.nan |
|
435 | 435 | noise_exist = jnoise[0] < numpy.Inf |
|
436 | 436 | |
|
437 | 437 | #Subrutina de Remocion de la Interferencia |
|
438 | 438 | for ich in range(num_channel): |
|
439 | 439 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
440 | 440 | power = jspectra[ich,mask_prof,:] |
|
441 | 441 | power = power[:,hei_interf] |
|
442 | 442 | power = power.sum(axis = 0) |
|
443 | 443 | psort = power.ravel().argsort() |
|
444 | 444 | |
|
445 | 445 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
446 | 446 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
447 | 447 | |
|
448 | 448 | if noise_exist: |
|
449 | 449 | # tmp_noise = jnoise[ich] / num_prof |
|
450 | 450 | tmp_noise = jnoise[ich] |
|
451 | 451 | junkspc_interf = junkspc_interf - tmp_noise |
|
452 | 452 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
453 | 453 | |
|
454 | 454 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
455 | 455 | jspc_interf = jspc_interf.transpose() |
|
456 | 456 | #Calculando el espectro de interferencia promedio |
|
457 | 457 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
458 | 458 | noiseid = noiseid[0] |
|
459 | 459 | cnoiseid = noiseid.size |
|
460 | 460 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
461 | 461 | interfid = interfid[0] |
|
462 | 462 | cinterfid = interfid.size |
|
463 | 463 | |
|
464 | 464 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
465 | 465 | |
|
466 | 466 | #Expandiendo los perfiles a limpiar |
|
467 | 467 | if (cinterfid > 0): |
|
468 | 468 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
469 | 469 | new_interfid = numpy.asarray(new_interfid) |
|
470 | 470 | new_interfid = {x for x in new_interfid} |
|
471 | 471 | new_interfid = numpy.array(list(new_interfid)) |
|
472 | 472 | new_cinterfid = new_interfid.size |
|
473 | 473 | else: new_cinterfid = 0 |
|
474 | 474 | |
|
475 | 475 | for ip in range(new_cinterfid): |
|
476 | 476 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
477 | 477 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
478 | 478 | |
|
479 | 479 | |
|
480 | 480 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
481 | 481 | |
|
482 | 482 | #Removiendo la interferencia del punto de mayor interferencia |
|
483 | 483 | ListAux = jspc_interf[mask_prof].tolist() |
|
484 | 484 | maxid = ListAux.index(max(ListAux)) |
|
485 | 485 | |
|
486 | 486 | |
|
487 | 487 | if cinterfid > 0: |
|
488 | 488 | for ip in range(cinterfid*(interf == 2) - 1): |
|
489 | 489 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
490 | 490 | cind = len(ind) |
|
491 | 491 | |
|
492 | 492 | if (cind > 0): |
|
493 | 493 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
494 | 494 | |
|
495 | 495 | ind = numpy.array([-2,-1,1,2]) |
|
496 | 496 | xx = numpy.zeros([4,4]) |
|
497 | 497 | |
|
498 | 498 | for id1 in range(4): |
|
499 | 499 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
500 | 500 | |
|
501 | 501 | xx_inv = numpy.linalg.inv(xx) |
|
502 | 502 | xx = xx_inv[:,0] |
|
503 | 503 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
504 | 504 | yy = jspectra[ich,mask_prof[ind],:] |
|
505 | 505 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
506 | 506 | |
|
507 | 507 | |
|
508 | 508 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
509 | 509 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
510 | 510 | |
|
511 | 511 | #Remocion de Interferencia en el Cross Spectra |
|
512 | 512 | if jcspectra == None: return jspectra, jcspectra |
|
513 | 513 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
514 | 514 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
515 | 515 | |
|
516 | 516 | for ip in range(num_pairs): |
|
517 | 517 | |
|
518 | 518 | #------------------------------------------- |
|
519 | 519 | |
|
520 | 520 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
521 | 521 | cspower = cspower[:,hei_interf] |
|
522 | 522 | cspower = cspower.sum(axis = 0) |
|
523 | 523 | |
|
524 | 524 | cspsort = cspower.ravel().argsort() |
|
525 | 525 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
526 | 526 | junkcspc_interf = junkcspc_interf.transpose() |
|
527 | 527 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
528 | 528 | |
|
529 | 529 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
530 | 530 | |
|
531 | 531 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
532 | 532 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
533 | 533 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
534 | 534 | |
|
535 | 535 | for iprof in range(num_prof): |
|
536 | 536 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
537 | 537 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
538 | 538 | |
|
539 | 539 | #Removiendo la Interferencia |
|
540 | 540 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
541 | 541 | |
|
542 | 542 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
543 | 543 | maxid = ListAux.index(max(ListAux)) |
|
544 | 544 | |
|
545 | 545 | ind = numpy.array([-2,-1,1,2]) |
|
546 | 546 | xx = numpy.zeros([4,4]) |
|
547 | 547 | |
|
548 | 548 | for id1 in range(4): |
|
549 | 549 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
550 | 550 | |
|
551 | 551 | xx_inv = numpy.linalg.inv(xx) |
|
552 | 552 | xx = xx_inv[:,0] |
|
553 | 553 | |
|
554 | 554 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
555 | 555 | yy = jcspectra[ip,mask_prof[ind],:] |
|
556 | 556 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
557 | 557 | |
|
558 | 558 | #Guardar Resultados |
|
559 | 559 | self.dataOut.data_spc = jspectra |
|
560 | 560 | self.dataOut.data_cspc = jcspectra |
|
561 | 561 | |
|
562 | 562 | return 1 |
|
563 | 563 | |
|
564 | 564 | def setRadarFrequency(self, frequency=None): |
|
565 | 565 | if frequency != None: |
|
566 | 566 | self.dataOut.frequency = frequency |
|
567 | 567 | |
|
568 | 568 | return 1 |
|
569 | 569 | |
|
570 | 570 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
571 | 571 | #validacion de rango |
|
572 | 572 | if minHei == None: |
|
573 | 573 | minHei = self.dataOut.heightList[0] |
|
574 | 574 | |
|
575 | 575 | if maxHei == None: |
|
576 | 576 | maxHei = self.dataOut.heightList[-1] |
|
577 | 577 | |
|
578 | 578 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
579 | 579 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
580 | 580 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
581 | 581 | minHei = self.dataOut.heightList[0] |
|
582 | 582 | |
|
583 | 583 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
584 | 584 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
585 | 585 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
586 | 586 | maxHei = self.dataOut.heightList[-1] |
|
587 | 587 | |
|
588 | 588 | # validacion de velocidades |
|
589 | 589 | velrange = self.dataOut.getVelRange(1) |
|
590 | 590 | |
|
591 | 591 | if minVel == None: |
|
592 | 592 | minVel = velrange[0] |
|
593 | 593 | |
|
594 | 594 | if maxVel == None: |
|
595 | 595 | maxVel = velrange[-1] |
|
596 | 596 | |
|
597 | 597 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
598 | 598 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
599 | 599 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
600 | 600 | minVel = velrange[0] |
|
601 | 601 | |
|
602 | 602 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
603 | 603 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
604 | 604 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
605 | 605 | maxVel = velrange[-1] |
|
606 | 606 | |
|
607 | 607 | # seleccion de indices para rango |
|
608 | 608 | minIndex = 0 |
|
609 | 609 | maxIndex = 0 |
|
610 | 610 | heights = self.dataOut.heightList |
|
611 | 611 | |
|
612 | 612 | inda = numpy.where(heights >= minHei) |
|
613 | 613 | indb = numpy.where(heights <= maxHei) |
|
614 | 614 | |
|
615 | 615 | try: |
|
616 | 616 | minIndex = inda[0][0] |
|
617 | 617 | except: |
|
618 | 618 | minIndex = 0 |
|
619 | 619 | |
|
620 | 620 | try: |
|
621 | 621 | maxIndex = indb[0][-1] |
|
622 | 622 | except: |
|
623 | 623 | maxIndex = len(heights) |
|
624 | 624 | |
|
625 | 625 | if (minIndex < 0) or (minIndex > maxIndex): |
|
626 | 626 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
627 | 627 | |
|
628 | 628 | if (maxIndex >= self.dataOut.nHeights): |
|
629 | 629 | maxIndex = self.dataOut.nHeights-1 |
|
630 | 630 | |
|
631 | 631 | # seleccion de indices para velocidades |
|
632 | 632 | indminvel = numpy.where(velrange >= minVel) |
|
633 | 633 | indmaxvel = numpy.where(velrange <= maxVel) |
|
634 | 634 | try: |
|
635 | 635 | minIndexVel = indminvel[0][0] |
|
636 | 636 | except: |
|
637 | 637 | minIndexVel = 0 |
|
638 | 638 | |
|
639 | 639 | try: |
|
640 | 640 | maxIndexVel = indmaxvel[0][-1] |
|
641 | 641 | except: |
|
642 | 642 | maxIndexVel = len(velrange) |
|
643 | 643 | |
|
644 | 644 | #seleccion del espectro |
|
645 | 645 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
646 | 646 | #estimacion de ruido |
|
647 | 647 | noise = numpy.zeros(self.dataOut.nChannels) |
|
648 | 648 | |
|
649 | 649 | for channel in range(self.dataOut.nChannels): |
|
650 | 650 | daux = data_spc[channel,:,:] |
|
651 | 651 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
652 | 652 | |
|
653 | 653 | self.dataOut.noise_estimation = noise.copy() |
|
654 | 654 | |
|
655 | 655 | return 1 |
|
656 | 656 | |
|
657 | 657 | class IncohInt(Operation): |
|
658 | 658 | |
|
659 | 659 | |
|
660 | 660 | __profIndex = 0 |
|
661 | 661 | __withOverapping = False |
|
662 | 662 | |
|
663 | 663 | __byTime = False |
|
664 | 664 | __initime = None |
|
665 | 665 | __lastdatatime = None |
|
666 | 666 | __integrationtime = None |
|
667 | 667 | |
|
668 | 668 | __buffer_spc = None |
|
669 | 669 | __buffer_cspc = None |
|
670 | 670 | __buffer_dc = None |
|
671 | 671 | |
|
672 | 672 | __dataReady = False |
|
673 | 673 | |
|
674 | 674 | __timeInterval = None |
|
675 | 675 | |
|
676 | 676 | n = None |
|
677 | 677 | |
|
678 | 678 | |
|
679 | 679 | |
|
680 | 680 | def __init__(self): |
|
681 | 681 | |
|
682 | 682 | Operation.__init__(self) |
|
683 | 683 | # self.isConfig = False |
|
684 | 684 | |
|
685 | 685 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
686 | 686 | """ |
|
687 | 687 | Set the parameters of the integration class. |
|
688 | 688 | |
|
689 | 689 | Inputs: |
|
690 | 690 | |
|
691 | 691 | n : Number of coherent integrations |
|
692 | 692 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
693 | 693 | overlapping : |
|
694 | 694 | |
|
695 | 695 | """ |
|
696 | 696 | |
|
697 | 697 | self.__initime = None |
|
698 | 698 | self.__lastdatatime = 0 |
|
699 | 699 | self.__buffer_spc = None |
|
700 | 700 | self.__buffer_cspc = None |
|
701 | 701 | self.__buffer_dc = None |
|
702 | 702 | self.__dataReady = False |
|
703 | 703 | |
|
704 | 704 | |
|
705 | 705 | if n == None and timeInterval == None: |
|
706 | 706 | raise ValueError, "n or timeInterval should be specified ..." |
|
707 | 707 | |
|
708 | 708 | if n != None: |
|
709 | 709 | self.n = n |
|
710 | 710 | self.__byTime = False |
|
711 | 711 | else: |
|
712 | 712 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
713 | 713 | self.n = 9999 |
|
714 | 714 | self.__byTime = True |
|
715 | 715 | |
|
716 | 716 | if overlapping: |
|
717 | 717 | self.__withOverapping = True |
|
718 | 718 | else: |
|
719 | 719 | self.__withOverapping = False |
|
720 | 720 | self.__buffer_spc = 0 |
|
721 | 721 | self.__buffer_cspc = 0 |
|
722 | 722 | self.__buffer_dc = 0 |
|
723 | 723 | |
|
724 | 724 | self.__profIndex = 0 |
|
725 | 725 | |
|
726 | 726 | def putData(self, data_spc, data_cspc, data_dc): |
|
727 | 727 | |
|
728 | 728 | """ |
|
729 | 729 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
730 | 730 | |
|
731 | 731 | """ |
|
732 | 732 | |
|
733 | 733 | if not self.__withOverapping: |
|
734 | 734 | self.__buffer_spc += data_spc |
|
735 | 735 | |
|
736 | 736 | if data_cspc == None: |
|
737 | 737 | self.__buffer_cspc = None |
|
738 | 738 | else: |
|
739 | 739 | self.__buffer_cspc += data_cspc |
|
740 | 740 | |
|
741 | 741 | if data_dc == None: |
|
742 | 742 | self.__buffer_dc = None |
|
743 | 743 | else: |
|
744 | 744 | self.__buffer_dc += data_dc |
|
745 | 745 | |
|
746 | 746 | self.__profIndex += 1 |
|
747 | 747 | return |
|
748 | 748 | |
|
749 | 749 | #Overlapping data |
|
750 | 750 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
751 | 751 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
752 | 752 | if data_cspc != None: |
|
753 | 753 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
754 | 754 | if data_dc != None: |
|
755 | 755 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
756 | 756 | |
|
757 | 757 | #If the buffer is empty then it takes the data value |
|
758 | 758 | if self.__buffer_spc == None: |
|
759 | 759 | self.__buffer_spc = data_spc |
|
760 | 760 | |
|
761 | 761 | if data_cspc == None: |
|
762 | 762 | self.__buffer_cspc = None |
|
763 | 763 | else: |
|
764 | 764 | self.__buffer_cspc += data_cspc |
|
765 | 765 | |
|
766 | 766 | if data_dc == None: |
|
767 | 767 | self.__buffer_dc = None |
|
768 | 768 | else: |
|
769 | 769 | self.__buffer_dc += data_dc |
|
770 | 770 | |
|
771 | 771 | self.__profIndex += 1 |
|
772 | 772 | return |
|
773 | 773 | |
|
774 | 774 | #If the buffer length is lower than n then stakcing the data value |
|
775 | 775 | if self.__profIndex < self.n: |
|
776 | 776 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
777 | 777 | |
|
778 | 778 | if data_cspc != None: |
|
779 | 779 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
780 | 780 | |
|
781 | 781 | if data_dc != None: |
|
782 | 782 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
783 | 783 | |
|
784 | 784 | self.__profIndex += 1 |
|
785 | 785 | return |
|
786 | 786 | |
|
787 | 787 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
788 | 788 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
789 | 789 | self.__buffer_spc[self.n-1] = data_spc |
|
790 | 790 | |
|
791 | 791 | if data_cspc != None: |
|
792 | 792 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
793 | 793 | self.__buffer_cspc[self.n-1] = data_cspc |
|
794 | 794 | |
|
795 | 795 | if data_dc != None: |
|
796 | 796 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
797 | 797 | self.__buffer_dc[self.n-1] = data_dc |
|
798 | 798 | |
|
799 | 799 | self.__profIndex = self.n |
|
800 | 800 | return |
|
801 | 801 | |
|
802 | 802 | |
|
803 | 803 | def pushData(self): |
|
804 | 804 | """ |
|
805 | 805 | Return the sum of the last profiles and the profiles used in the sum. |
|
806 | 806 | |
|
807 | 807 | Affected: |
|
808 | 808 | |
|
809 | 809 | self.__profileIndex |
|
810 | 810 | |
|
811 | 811 | """ |
|
812 | 812 | data_spc = None |
|
813 | 813 | data_cspc = None |
|
814 | 814 | data_dc = None |
|
815 | 815 | |
|
816 | 816 | if not self.__withOverapping: |
|
817 | 817 | data_spc = self.__buffer_spc |
|
818 | 818 | data_cspc = self.__buffer_cspc |
|
819 | 819 | data_dc = self.__buffer_dc |
|
820 | 820 | |
|
821 | 821 | n = self.__profIndex |
|
822 | 822 | |
|
823 | 823 | self.__buffer_spc = 0 |
|
824 | 824 | self.__buffer_cspc = 0 |
|
825 | 825 | self.__buffer_dc = 0 |
|
826 | 826 | self.__profIndex = 0 |
|
827 | 827 | |
|
828 | 828 | return data_spc, data_cspc, data_dc, n |
|
829 | 829 | |
|
830 | 830 | #Integration with Overlapping |
|
831 | 831 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
832 | 832 | |
|
833 | 833 | if self.__buffer_cspc != None: |
|
834 | 834 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
835 | 835 | |
|
836 | 836 | if self.__buffer_dc != None: |
|
837 | 837 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
838 | 838 | |
|
839 | 839 | n = self.__profIndex |
|
840 | 840 | |
|
841 | 841 | return data_spc, data_cspc, data_dc, n |
|
842 | 842 | |
|
843 | 843 | def byProfiles(self, *args): |
|
844 | 844 | |
|
845 | 845 | self.__dataReady = False |
|
846 | 846 | avgdata_spc = None |
|
847 | 847 | avgdata_cspc = None |
|
848 | 848 | avgdata_dc = None |
|
849 | 849 | # n = None |
|
850 | 850 | |
|
851 | 851 | self.putData(*args) |
|
852 | 852 | |
|
853 | 853 | if self.__profIndex == self.n: |
|
854 | 854 | |
|
855 | 855 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
856 | 856 | self.__dataReady = True |
|
857 | 857 | |
|
858 | 858 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
859 | 859 | |
|
860 | 860 | def byTime(self, datatime, *args): |
|
861 | 861 | |
|
862 | 862 | self.__dataReady = False |
|
863 | 863 | avgdata_spc = None |
|
864 | 864 | avgdata_cspc = None |
|
865 | 865 | avgdata_dc = None |
|
866 | 866 | n = None |
|
867 | 867 | |
|
868 | 868 | self.putData(*args) |
|
869 | 869 | |
|
870 | 870 | if (datatime - self.__initime) >= self.__integrationtime: |
|
871 | 871 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
872 | 872 | self.n = n |
|
873 | 873 | self.__dataReady = True |
|
874 | 874 | |
|
875 | 875 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
876 | 876 | |
|
877 | 877 | def integrate(self, datatime, *args): |
|
878 | 878 | |
|
879 | 879 | if self.__initime == None: |
|
880 | 880 | self.__initime = datatime |
|
881 | 881 | |
|
882 | 882 | if self.__byTime: |
|
883 | 883 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
884 | 884 | else: |
|
885 | 885 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
886 | 886 | |
|
887 | 887 | self.__lastdatatime = datatime |
|
888 | 888 | |
|
889 | 889 | if avgdata_spc == None: |
|
890 | 890 | return None, None, None, None |
|
891 | 891 | |
|
892 | 892 | avgdatatime = self.__initime |
|
893 | 893 | try: |
|
894 | 894 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
895 | 895 | except: |
|
896 | 896 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
897 | 897 | |
|
898 | 898 | deltatime = datatime -self.__lastdatatime |
|
899 | 899 | |
|
900 | 900 | if not self.__withOverapping: |
|
901 | 901 | self.__initime = datatime |
|
902 | 902 | else: |
|
903 | 903 | self.__initime += deltatime |
|
904 | 904 | |
|
905 | 905 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
906 | 906 | |
|
907 | 907 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
908 | 908 | |
|
909 | 909 | if n==1: |
|
910 | 910 | dataOut.flagNoData = False |
|
911 | 911 | return |
|
912 | 912 | |
|
913 | 913 | if not self.isConfig: |
|
914 | 914 | self.setup(n, timeInterval, overlapping) |
|
915 | 915 | self.isConfig = True |
|
916 | 916 | |
|
917 | 917 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
918 | 918 | dataOut.data_spc, |
|
919 | 919 | dataOut.data_cspc, |
|
920 | 920 | dataOut.data_dc) |
|
921 | 921 | |
|
922 | 922 | # dataOut.timeInterval *= n |
|
923 | 923 | dataOut.flagNoData = True |
|
924 | 924 | |
|
925 | 925 | if self.__dataReady: |
|
926 | 926 | |
|
927 | 927 | dataOut.data_spc = avgdata_spc |
|
928 | 928 | dataOut.data_cspc = avgdata_cspc |
|
929 | 929 | dataOut.data_dc = avgdata_dc |
|
930 | 930 | |
|
931 | 931 | dataOut.nIncohInt *= self.n |
|
932 | 932 | dataOut.utctime = avgdatatime |
|
933 | 933 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
934 | dataOut.timeInterval = self.__timeInterval*self.n | |
|
934 | # dataOut.timeInterval = self.__timeInterval*self.n | |
|
935 | 935 | dataOut.flagNoData = False |
General Comments 0
You need to be logged in to leave comments.
Login now