@@ -1,1604 +1,1627 | |||
|
1 | 1 | import sys |
|
2 | 2 | import numpy,math |
|
3 | 3 | from scipy import interpolate |
|
4 | 4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
5 | from schainpy.model.data.jrodata import Voltage | |
|
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon | |
|
6 | 6 | from schainpy.utils import log |
|
7 | 7 | from time import time |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | class VoltageProc(ProcessingUnit): |
|
12 | 12 | |
|
13 | 13 | def __init__(self): |
|
14 | 14 | |
|
15 | 15 | ProcessingUnit.__init__(self) |
|
16 | 16 | |
|
17 | 17 | self.dataOut = Voltage() |
|
18 | 18 | self.flip = 1 |
|
19 | 19 | self.setupReq = False |
|
20 | 20 | |
|
21 | 21 | def run(self): |
|
22 | 22 | |
|
23 | 23 | if self.dataIn.type == 'AMISR': |
|
24 | 24 | self.__updateObjFromAmisrInput() |
|
25 | 25 | |
|
26 | 26 | if self.dataIn.type == 'Voltage': |
|
27 | 27 | self.dataOut.copy(self.dataIn) |
|
28 | 28 | |
|
29 | 29 | def __updateObjFromAmisrInput(self): |
|
30 | 30 | |
|
31 | 31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
32 | 32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
33 | 33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
34 | 34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
35 | 35 | |
|
36 | 36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
37 | 37 | self.dataOut.data = self.dataIn.data |
|
38 | 38 | self.dataOut.utctime = self.dataIn.utctime |
|
39 | 39 | self.dataOut.channelList = self.dataIn.channelList |
|
40 | 40 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
41 | 41 | self.dataOut.heightList = self.dataIn.heightList |
|
42 | 42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
43 | 43 | |
|
44 | 44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
45 | 45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
46 | 46 | self.dataOut.frequency = self.dataIn.frequency |
|
47 | 47 | |
|
48 | 48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
49 | 49 | self.dataOut.zenith = self.dataIn.zenith |
|
50 | 50 | |
|
51 | 51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
52 | 52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
53 | 53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | class selectChannels(Operation): |
|
57 | 57 | |
|
58 | 58 | def run(self, dataOut, channelList): |
|
59 | 59 | |
|
60 | 60 | channelIndexList = [] |
|
61 | 61 | self.dataOut = dataOut |
|
62 | 62 | for channel in channelList: |
|
63 | 63 | if channel not in self.dataOut.channelList: |
|
64 | 64 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) |
|
65 | 65 | |
|
66 | 66 | index = self.dataOut.channelList.index(channel) |
|
67 | 67 | channelIndexList.append(index) |
|
68 | 68 | self.selectChannelsByIndex(channelIndexList) |
|
69 | 69 | return self.dataOut |
|
70 | 70 | |
|
71 | 71 | def selectChannelsByIndex(self, channelIndexList): |
|
72 | 72 | """ |
|
73 | 73 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
74 | 74 | |
|
75 | 75 | Input: |
|
76 | 76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
77 | 77 | |
|
78 | 78 | Affected: |
|
79 | 79 | self.dataOut.data |
|
80 | 80 | self.dataOut.channelIndexList |
|
81 | 81 | self.dataOut.nChannels |
|
82 | 82 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
83 | 83 | self.dataOut.systemHeaderObj.numChannels |
|
84 | 84 | self.dataOut.m_ProcessingHeader.blockSize |
|
85 | 85 | |
|
86 | 86 | Return: |
|
87 | 87 | None |
|
88 | 88 | """ |
|
89 | 89 | |
|
90 | 90 | for channelIndex in channelIndexList: |
|
91 | 91 | if channelIndex not in self.dataOut.channelIndexList: |
|
92 | 92 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
93 | 93 | |
|
94 | 94 | if self.dataOut.type == 'Voltage': |
|
95 | 95 | if self.dataOut.flagDataAsBlock: |
|
96 | 96 | """ |
|
97 | 97 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
98 | 98 | """ |
|
99 | 99 | data = self.dataOut.data[channelIndexList,:,:] |
|
100 | 100 | else: |
|
101 | 101 | data = self.dataOut.data[channelIndexList,:] |
|
102 | 102 | |
|
103 | 103 | self.dataOut.data = data |
|
104 | 104 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
105 | 105 | self.dataOut.channelList = range(len(channelIndexList)) |
|
106 | 106 | |
|
107 | 107 | elif self.dataOut.type == 'Spectra': |
|
108 | 108 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
109 | 109 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
110 | 110 | |
|
111 | 111 | self.dataOut.data_spc = data_spc |
|
112 | 112 | self.dataOut.data_dc = data_dc |
|
113 | 113 | |
|
114 | 114 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
115 | 115 | self.dataOut.channelList = range(len(channelIndexList)) |
|
116 | 116 | self.__selectPairsByChannel(channelIndexList) |
|
117 | 117 | |
|
118 | 118 | return 1 |
|
119 | 119 | |
|
120 | 120 | def __selectPairsByChannel(self, channelList=None): |
|
121 | 121 | |
|
122 | 122 | if channelList == None: |
|
123 | 123 | return |
|
124 | 124 | |
|
125 | 125 | pairsIndexListSelected = [] |
|
126 | 126 | for pairIndex in self.dataOut.pairsIndexList: |
|
127 | 127 | # First pair |
|
128 | 128 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
129 | 129 | continue |
|
130 | 130 | # Second pair |
|
131 | 131 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
132 | 132 | continue |
|
133 | 133 | |
|
134 | 134 | pairsIndexListSelected.append(pairIndex) |
|
135 | 135 | |
|
136 | 136 | if not pairsIndexListSelected: |
|
137 | 137 | self.dataOut.data_cspc = None |
|
138 | 138 | self.dataOut.pairsList = [] |
|
139 | 139 | return |
|
140 | 140 | |
|
141 | 141 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
142 | 142 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
143 | 143 | for i in pairsIndexListSelected] |
|
144 | 144 | |
|
145 | 145 | return |
|
146 | 146 | |
|
147 | 147 | class selectHeights(Operation): |
|
148 | 148 | |
|
149 | 149 | def run(self, dataOut, minHei=None, maxHei=None): |
|
150 | 150 | """ |
|
151 | 151 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
152 | 152 | minHei <= height <= maxHei |
|
153 | 153 | |
|
154 | 154 | Input: |
|
155 | 155 | minHei : valor minimo de altura a considerar |
|
156 | 156 | maxHei : valor maximo de altura a considerar |
|
157 | 157 | |
|
158 | 158 | Affected: |
|
159 | 159 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
160 | 160 | |
|
161 | 161 | Return: |
|
162 | 162 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
163 | 163 | """ |
|
164 | 164 | |
|
165 | 165 | self.dataOut = dataOut |
|
166 | 166 | |
|
167 | 167 | if minHei == None: |
|
168 | 168 | minHei = self.dataOut.heightList[0] |
|
169 | 169 | |
|
170 | 170 | if maxHei == None: |
|
171 | 171 | maxHei = self.dataOut.heightList[-1] |
|
172 | 172 | |
|
173 | 173 | if (minHei < self.dataOut.heightList[0]): |
|
174 | 174 | minHei = self.dataOut.heightList[0] |
|
175 | 175 | |
|
176 | 176 | if (maxHei > self.dataOut.heightList[-1]): |
|
177 | 177 | maxHei = self.dataOut.heightList[-1] |
|
178 | 178 | |
|
179 | 179 | minIndex = 0 |
|
180 | 180 | maxIndex = 0 |
|
181 | 181 | heights = self.dataOut.heightList |
|
182 | 182 | |
|
183 | 183 | inda = numpy.where(heights >= minHei) |
|
184 | 184 | indb = numpy.where(heights <= maxHei) |
|
185 | 185 | |
|
186 | 186 | try: |
|
187 | 187 | minIndex = inda[0][0] |
|
188 | 188 | except: |
|
189 | 189 | minIndex = 0 |
|
190 | 190 | |
|
191 | 191 | try: |
|
192 | 192 | maxIndex = indb[0][-1] |
|
193 | 193 | except: |
|
194 | 194 | maxIndex = len(heights) |
|
195 | 195 | |
|
196 | 196 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
197 | 197 | |
|
198 | 198 | return self.dataOut |
|
199 | 199 | |
|
200 | 200 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
201 | 201 | """ |
|
202 | 202 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
203 | 203 | minIndex <= index <= maxIndex |
|
204 | 204 | |
|
205 | 205 | Input: |
|
206 | 206 | minIndex : valor de indice minimo de altura a considerar |
|
207 | 207 | maxIndex : valor de indice maximo de altura a considerar |
|
208 | 208 | |
|
209 | 209 | Affected: |
|
210 | 210 | self.dataOut.data |
|
211 | 211 | self.dataOut.heightList |
|
212 | 212 | |
|
213 | 213 | Return: |
|
214 | 214 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
215 | 215 | """ |
|
216 | 216 | |
|
217 | 217 | if self.dataOut.type == 'Voltage': |
|
218 | 218 | if (minIndex < 0) or (minIndex > maxIndex): |
|
219 | 219 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
220 | 220 | |
|
221 | 221 | if (maxIndex >= self.dataOut.nHeights): |
|
222 | 222 | maxIndex = self.dataOut.nHeights |
|
223 | 223 | |
|
224 | 224 | #voltage |
|
225 | 225 | if self.dataOut.flagDataAsBlock: |
|
226 | 226 | """ |
|
227 | 227 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
228 | 228 | """ |
|
229 | 229 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
230 | 230 | else: |
|
231 | 231 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
232 | 232 | |
|
233 | 233 | # firstHeight = self.dataOut.heightList[minIndex] |
|
234 | 234 | |
|
235 | 235 | self.dataOut.data = data |
|
236 | 236 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
237 | 237 | |
|
238 | 238 | if self.dataOut.nHeights <= 1: |
|
239 | 239 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
240 | 240 | elif self.dataOut.type == 'Spectra': |
|
241 | 241 | if (minIndex < 0) or (minIndex > maxIndex): |
|
242 | 242 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
243 | 243 | minIndex, maxIndex)) |
|
244 | 244 | |
|
245 | 245 | if (maxIndex >= self.dataOut.nHeights): |
|
246 | 246 | maxIndex = self.dataOut.nHeights - 1 |
|
247 | 247 | |
|
248 | 248 | # Spectra |
|
249 | 249 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
250 | 250 | |
|
251 | 251 | data_cspc = None |
|
252 | 252 | if self.dataOut.data_cspc is not None: |
|
253 | 253 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
254 | 254 | |
|
255 | 255 | data_dc = None |
|
256 | 256 | if self.dataOut.data_dc is not None: |
|
257 | 257 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
258 | 258 | |
|
259 | 259 | self.dataOut.data_spc = data_spc |
|
260 | 260 | self.dataOut.data_cspc = data_cspc |
|
261 | 261 | self.dataOut.data_dc = data_dc |
|
262 | 262 | |
|
263 | 263 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
264 | 264 | |
|
265 | 265 | return 1 |
|
266 | 266 | |
|
267 | 267 | |
|
268 | 268 | class filterByHeights(Operation): |
|
269 | 269 | |
|
270 | 270 | def run(self, dataOut, window): |
|
271 | 271 | |
|
272 | 272 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
273 | 273 | |
|
274 | 274 | if window == None: |
|
275 | 275 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
276 | 276 | |
|
277 | 277 | newdelta = deltaHeight * window |
|
278 | 278 | r = dataOut.nHeights % window |
|
279 | 279 | newheights = (dataOut.nHeights-r)/window |
|
280 | 280 | |
|
281 | 281 | if newheights <= 1: |
|
282 | 282 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
283 | 283 | |
|
284 | 284 | if dataOut.flagDataAsBlock: |
|
285 | 285 | """ |
|
286 | 286 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
287 | 287 | """ |
|
288 | 288 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] |
|
289 | 289 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) |
|
290 | 290 | buffer = numpy.sum(buffer,3) |
|
291 | 291 | |
|
292 | 292 | else: |
|
293 | 293 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] |
|
294 | 294 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) |
|
295 | 295 | buffer = numpy.sum(buffer,2) |
|
296 | 296 | |
|
297 | 297 | dataOut.data = buffer |
|
298 | 298 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
299 | 299 | dataOut.windowOfFilter = window |
|
300 | 300 | |
|
301 | 301 | return dataOut |
|
302 | 302 | |
|
303 | 303 | |
|
304 | 304 | class setH0(Operation): |
|
305 | 305 | |
|
306 | 306 | def run(self, dataOut, h0, deltaHeight = None): |
|
307 | 307 | |
|
308 | 308 | if not deltaHeight: |
|
309 | 309 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
310 | 310 | |
|
311 | 311 | nHeights = dataOut.nHeights |
|
312 | 312 | |
|
313 | 313 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
314 | 314 | |
|
315 | 315 | dataOut.heightList = newHeiRange |
|
316 | 316 | |
|
317 | 317 | return dataOut |
|
318 | 318 | |
|
319 | 319 | |
|
320 | 320 | class deFlip(Operation): |
|
321 | 321 | |
|
322 | 322 | def run(self, dataOut, channelList = []): |
|
323 | 323 | |
|
324 | 324 | data = dataOut.data.copy() |
|
325 | 325 | |
|
326 | 326 | if dataOut.flagDataAsBlock: |
|
327 | 327 | flip = self.flip |
|
328 | 328 | profileList = list(range(dataOut.nProfiles)) |
|
329 | 329 | |
|
330 | 330 | if not channelList: |
|
331 | 331 | for thisProfile in profileList: |
|
332 | 332 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
333 | 333 | flip *= -1.0 |
|
334 | 334 | else: |
|
335 | 335 | for thisChannel in channelList: |
|
336 | 336 | if thisChannel not in dataOut.channelList: |
|
337 | 337 | continue |
|
338 | 338 | |
|
339 | 339 | for thisProfile in profileList: |
|
340 | 340 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
341 | 341 | flip *= -1.0 |
|
342 | 342 | |
|
343 | 343 | self.flip = flip |
|
344 | 344 | |
|
345 | 345 | else: |
|
346 | 346 | if not channelList: |
|
347 | 347 | data[:,:] = data[:,:]*self.flip |
|
348 | 348 | else: |
|
349 | 349 | for thisChannel in channelList: |
|
350 | 350 | if thisChannel not in dataOut.channelList: |
|
351 | 351 | continue |
|
352 | 352 | |
|
353 | 353 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
354 | 354 | |
|
355 | 355 | self.flip *= -1. |
|
356 | 356 | |
|
357 | 357 | dataOut.data = data |
|
358 | 358 | |
|
359 | 359 | return dataOut |
|
360 | 360 | |
|
361 | 361 | |
|
362 | 362 | class setAttribute(Operation): |
|
363 | 363 | ''' |
|
364 | 364 | Set an arbitrary attribute(s) to dataOut |
|
365 | 365 | ''' |
|
366 | 366 | |
|
367 | 367 | def __init__(self): |
|
368 | 368 | |
|
369 | 369 | Operation.__init__(self) |
|
370 | 370 | self._ready = False |
|
371 | 371 | |
|
372 | 372 | def run(self, dataOut, **kwargs): |
|
373 | 373 | |
|
374 | 374 | for key, value in kwargs.items(): |
|
375 | 375 | setattr(dataOut, key, value) |
|
376 | 376 | |
|
377 | 377 | return dataOut |
|
378 | 378 | |
|
379 | 379 | |
|
380 | 380 | @MPDecorator |
|
381 | 381 | class printAttribute(Operation): |
|
382 | 382 | ''' |
|
383 | 383 | Print an arbitrary attribute of dataOut |
|
384 | 384 | ''' |
|
385 | 385 | |
|
386 | 386 | def __init__(self): |
|
387 | 387 | |
|
388 | 388 | Operation.__init__(self) |
|
389 | 389 | |
|
390 | 390 | def run(self, dataOut, attributes): |
|
391 | 391 | |
|
392 | 392 | for attr in attributes: |
|
393 | 393 | if hasattr(dataOut, attr): |
|
394 | 394 | log.log(getattr(dataOut, attr), attr) |
|
395 | 395 | |
|
396 | 396 | |
|
397 | 397 | class interpolateHeights(Operation): |
|
398 | 398 | |
|
399 | 399 | def run(self, dataOut, topLim, botLim): |
|
400 | 400 | #69 al 72 para julia |
|
401 | 401 | #82-84 para meteoros |
|
402 | 402 | if len(numpy.shape(dataOut.data))==2: |
|
403 | 403 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
404 | 404 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
405 | 405 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
406 | 406 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
407 | 407 | else: |
|
408 | 408 | nHeights = dataOut.data.shape[2] |
|
409 | 409 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
410 | 410 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
411 | 411 | f = interpolate.interp1d(x, y, axis = 2) |
|
412 | 412 | xnew = numpy.arange(botLim,topLim+1) |
|
413 | 413 | ynew = f(xnew) |
|
414 | 414 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
415 | 415 | |
|
416 | 416 | return dataOut |
|
417 | 417 | |
|
418 | 418 | |
|
419 | 419 | class CohInt(Operation): |
|
420 | 420 | |
|
421 | 421 | isConfig = False |
|
422 | 422 | __profIndex = 0 |
|
423 | 423 | __byTime = False |
|
424 | 424 | __initime = None |
|
425 | 425 | __lastdatatime = None |
|
426 | 426 | __integrationtime = None |
|
427 | 427 | __buffer = None |
|
428 | 428 | __bufferStride = [] |
|
429 | 429 | __dataReady = False |
|
430 | 430 | __profIndexStride = 0 |
|
431 | 431 | __dataToPutStride = False |
|
432 | 432 | n = None |
|
433 | 433 | |
|
434 | 434 | def __init__(self, **kwargs): |
|
435 | 435 | |
|
436 | 436 | Operation.__init__(self, **kwargs) |
|
437 | 437 | |
|
438 | 438 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
439 | 439 | """ |
|
440 | 440 | Set the parameters of the integration class. |
|
441 | 441 | |
|
442 | 442 | Inputs: |
|
443 | 443 | |
|
444 | 444 | n : Number of coherent integrations |
|
445 | 445 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
446 | 446 | overlapping : |
|
447 | 447 | """ |
|
448 | 448 | |
|
449 | 449 | self.__initime = None |
|
450 | 450 | self.__lastdatatime = 0 |
|
451 | 451 | self.__buffer = None |
|
452 | 452 | self.__dataReady = False |
|
453 | 453 | self.byblock = byblock |
|
454 | 454 | self.stride = stride |
|
455 | 455 | |
|
456 | 456 | if n == None and timeInterval == None: |
|
457 | 457 | raise ValueError("n or timeInterval should be specified ...") |
|
458 | 458 | |
|
459 | 459 | if n != None: |
|
460 | 460 | self.n = n |
|
461 | 461 | self.__byTime = False |
|
462 | 462 | else: |
|
463 | 463 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
464 | 464 | self.n = 9999 |
|
465 | 465 | self.__byTime = True |
|
466 | 466 | |
|
467 | 467 | if overlapping: |
|
468 | 468 | self.__withOverlapping = True |
|
469 | 469 | self.__buffer = None |
|
470 | 470 | else: |
|
471 | 471 | self.__withOverlapping = False |
|
472 | 472 | self.__buffer = 0 |
|
473 | 473 | |
|
474 | 474 | self.__profIndex = 0 |
|
475 | 475 | |
|
476 | 476 | def putData(self, data): |
|
477 | 477 | |
|
478 | 478 | """ |
|
479 | 479 | Add a profile to the __buffer and increase in one the __profileIndex |
|
480 | 480 | |
|
481 | 481 | """ |
|
482 | 482 | |
|
483 | 483 | if not self.__withOverlapping: |
|
484 | 484 | self.__buffer += data.copy() |
|
485 | 485 | self.__profIndex += 1 |
|
486 | 486 | return |
|
487 | 487 | |
|
488 | 488 | #Overlapping data |
|
489 | 489 | nChannels, nHeis = data.shape |
|
490 | 490 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
491 | 491 | |
|
492 | 492 | #If the buffer is empty then it takes the data value |
|
493 | 493 | if self.__buffer is None: |
|
494 | 494 | self.__buffer = data |
|
495 | 495 | self.__profIndex += 1 |
|
496 | 496 | return |
|
497 | 497 | |
|
498 | 498 | #If the buffer length is lower than n then stakcing the data value |
|
499 | 499 | if self.__profIndex < self.n: |
|
500 | 500 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
501 | 501 | self.__profIndex += 1 |
|
502 | 502 | return |
|
503 | 503 | |
|
504 | 504 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
505 | 505 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
506 | 506 | self.__buffer[self.n-1] = data |
|
507 | 507 | self.__profIndex = self.n |
|
508 | 508 | return |
|
509 | 509 | |
|
510 | 510 | |
|
511 | 511 | def pushData(self): |
|
512 | 512 | """ |
|
513 | 513 | Return the sum of the last profiles and the profiles used in the sum. |
|
514 | 514 | |
|
515 | 515 | Affected: |
|
516 | 516 | |
|
517 | 517 | self.__profileIndex |
|
518 | 518 | |
|
519 | 519 | """ |
|
520 | 520 | |
|
521 | 521 | if not self.__withOverlapping: |
|
522 | 522 | data = self.__buffer |
|
523 | 523 | n = self.__profIndex |
|
524 | 524 | |
|
525 | 525 | self.__buffer = 0 |
|
526 | 526 | self.__profIndex = 0 |
|
527 | 527 | |
|
528 | 528 | return data, n |
|
529 | 529 | |
|
530 | 530 | #Integration with Overlapping |
|
531 | 531 | data = numpy.sum(self.__buffer, axis=0) |
|
532 | 532 | # print data |
|
533 | 533 | # raise |
|
534 | 534 | n = self.__profIndex |
|
535 | 535 | |
|
536 | 536 | return data, n |
|
537 | 537 | |
|
538 | 538 | def byProfiles(self, data): |
|
539 | 539 | |
|
540 | 540 | self.__dataReady = False |
|
541 | 541 | avgdata = None |
|
542 | 542 | # n = None |
|
543 | 543 | # print data |
|
544 | 544 | # raise |
|
545 | 545 | self.putData(data) |
|
546 | 546 | |
|
547 | 547 | if self.__profIndex == self.n: |
|
548 | 548 | avgdata, n = self.pushData() |
|
549 | 549 | self.__dataReady = True |
|
550 | 550 | |
|
551 | 551 | return avgdata |
|
552 | 552 | |
|
553 | 553 | def byTime(self, data, datatime): |
|
554 | 554 | |
|
555 | 555 | self.__dataReady = False |
|
556 | 556 | avgdata = None |
|
557 | 557 | n = None |
|
558 | 558 | |
|
559 | 559 | self.putData(data) |
|
560 | 560 | |
|
561 | 561 | if (datatime - self.__initime) >= self.__integrationtime: |
|
562 | 562 | avgdata, n = self.pushData() |
|
563 | 563 | self.n = n |
|
564 | 564 | self.__dataReady = True |
|
565 | 565 | |
|
566 | 566 | return avgdata |
|
567 | 567 | |
|
568 | 568 | def integrateByStride(self, data, datatime): |
|
569 | 569 | # print data |
|
570 | 570 | if self.__profIndex == 0: |
|
571 | 571 | self.__buffer = [[data.copy(), datatime]] |
|
572 | 572 | else: |
|
573 | 573 | self.__buffer.append([data.copy(),datatime]) |
|
574 | 574 | self.__profIndex += 1 |
|
575 | 575 | self.__dataReady = False |
|
576 | 576 | |
|
577 | 577 | if self.__profIndex == self.n * self.stride : |
|
578 | 578 | self.__dataToPutStride = True |
|
579 | 579 | self.__profIndexStride = 0 |
|
580 | 580 | self.__profIndex = 0 |
|
581 | 581 | self.__bufferStride = [] |
|
582 | 582 | for i in range(self.stride): |
|
583 | 583 | current = self.__buffer[i::self.stride] |
|
584 | 584 | data = numpy.sum([t[0] for t in current], axis=0) |
|
585 | 585 | avgdatatime = numpy.average([t[1] for t in current]) |
|
586 | 586 | # print data |
|
587 | 587 | self.__bufferStride.append((data, avgdatatime)) |
|
588 | 588 | |
|
589 | 589 | if self.__dataToPutStride: |
|
590 | 590 | self.__dataReady = True |
|
591 | 591 | self.__profIndexStride += 1 |
|
592 | 592 | if self.__profIndexStride == self.stride: |
|
593 | 593 | self.__dataToPutStride = False |
|
594 | 594 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
595 | 595 | # raise |
|
596 | 596 | return self.__bufferStride[self.__profIndexStride - 1] |
|
597 | 597 | |
|
598 | 598 | |
|
599 | 599 | return None, None |
|
600 | 600 | |
|
601 | 601 | def integrate(self, data, datatime=None): |
|
602 | 602 | |
|
603 | 603 | if self.__initime == None: |
|
604 | 604 | self.__initime = datatime |
|
605 | 605 | |
|
606 | 606 | if self.__byTime: |
|
607 | 607 | avgdata = self.byTime(data, datatime) |
|
608 | 608 | else: |
|
609 | 609 | avgdata = self.byProfiles(data) |
|
610 | 610 | |
|
611 | 611 | |
|
612 | 612 | self.__lastdatatime = datatime |
|
613 | 613 | |
|
614 | 614 | if avgdata is None: |
|
615 | 615 | return None, None |
|
616 | 616 | |
|
617 | 617 | avgdatatime = self.__initime |
|
618 | 618 | |
|
619 | 619 | deltatime = datatime - self.__lastdatatime |
|
620 | 620 | |
|
621 | 621 | if not self.__withOverlapping: |
|
622 | 622 | self.__initime = datatime |
|
623 | 623 | else: |
|
624 | 624 | self.__initime += deltatime |
|
625 | 625 | |
|
626 | 626 | return avgdata, avgdatatime |
|
627 | 627 | |
|
628 | 628 | def integrateByBlock(self, dataOut): |
|
629 | 629 | |
|
630 | 630 | times = int(dataOut.data.shape[1]/self.n) |
|
631 | 631 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
632 | 632 | |
|
633 | 633 | id_min = 0 |
|
634 | 634 | id_max = self.n |
|
635 | 635 | |
|
636 | 636 | for i in range(times): |
|
637 | 637 | junk = dataOut.data[:,id_min:id_max,:] |
|
638 | 638 | avgdata[:,i,:] = junk.sum(axis=1) |
|
639 | 639 | id_min += self.n |
|
640 | 640 | id_max += self.n |
|
641 | 641 | |
|
642 | 642 | timeInterval = dataOut.ippSeconds*self.n |
|
643 | 643 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
644 | 644 | self.__dataReady = True |
|
645 | 645 | return avgdata, avgdatatime |
|
646 | 646 | |
|
647 | 647 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
648 | 648 | |
|
649 | 649 | if not self.isConfig: |
|
650 | 650 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
651 | 651 | self.isConfig = True |
|
652 | 652 | |
|
653 | 653 | if dataOut.flagDataAsBlock: |
|
654 | 654 | """ |
|
655 | 655 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
656 | 656 | """ |
|
657 | 657 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
658 | 658 | dataOut.nProfiles /= self.n |
|
659 | 659 | else: |
|
660 | 660 | if stride is None: |
|
661 | 661 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
662 | 662 | else: |
|
663 | 663 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
664 | 664 | |
|
665 | 665 | |
|
666 | 666 | # dataOut.timeInterval *= n |
|
667 | 667 | dataOut.flagNoData = True |
|
668 | 668 | |
|
669 | 669 | if self.__dataReady: |
|
670 | 670 | dataOut.data = avgdata |
|
671 | 671 | if not dataOut.flagCohInt: |
|
672 | 672 | dataOut.nCohInt *= self.n |
|
673 | 673 | dataOut.flagCohInt = True |
|
674 | 674 | dataOut.utctime = avgdatatime |
|
675 | 675 | # print avgdata, avgdatatime |
|
676 | 676 | # raise |
|
677 | 677 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
678 | 678 | dataOut.flagNoData = False |
|
679 | 679 | return dataOut |
|
680 | 680 | |
|
681 | 681 | class Decoder(Operation): |
|
682 | 682 | |
|
683 | 683 | isConfig = False |
|
684 | 684 | __profIndex = 0 |
|
685 | 685 | |
|
686 | 686 | code = None |
|
687 | 687 | |
|
688 | 688 | nCode = None |
|
689 | 689 | nBaud = None |
|
690 | 690 | |
|
691 | 691 | def __init__(self, **kwargs): |
|
692 | 692 | |
|
693 | 693 | Operation.__init__(self, **kwargs) |
|
694 | 694 | |
|
695 | 695 | self.times = None |
|
696 | 696 | self.osamp = None |
|
697 | 697 | # self.__setValues = False |
|
698 | 698 | self.isConfig = False |
|
699 | 699 | self.setupReq = False |
|
700 | 700 | def setup(self, code, osamp, dataOut): |
|
701 | 701 | |
|
702 | 702 | self.__profIndex = 0 |
|
703 | 703 | |
|
704 | 704 | self.code = code |
|
705 | 705 | |
|
706 | 706 | self.nCode = len(code) |
|
707 | 707 | self.nBaud = len(code[0]) |
|
708 | 708 | |
|
709 | 709 | if (osamp != None) and (osamp >1): |
|
710 | 710 | self.osamp = osamp |
|
711 | 711 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
712 | 712 | self.nBaud = self.nBaud*self.osamp |
|
713 | 713 | |
|
714 | 714 | self.__nChannels = dataOut.nChannels |
|
715 | 715 | self.__nProfiles = dataOut.nProfiles |
|
716 | 716 | self.__nHeis = dataOut.nHeights |
|
717 | 717 | |
|
718 | 718 | if self.__nHeis < self.nBaud: |
|
719 | 719 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
720 | 720 | |
|
721 | 721 | #Frequency |
|
722 | 722 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
723 | 723 | |
|
724 | 724 | __codeBuffer[:,0:self.nBaud] = self.code |
|
725 | 725 | |
|
726 | 726 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
727 | 727 | |
|
728 | 728 | if dataOut.flagDataAsBlock: |
|
729 | 729 | |
|
730 | 730 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
731 | 731 | |
|
732 | 732 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
733 | 733 | |
|
734 | 734 | else: |
|
735 | 735 | |
|
736 | 736 | #Time |
|
737 | 737 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
738 | 738 | |
|
739 | 739 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
740 | 740 | |
|
741 | 741 | def __convolutionInFreq(self, data): |
|
742 | 742 | |
|
743 | 743 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
744 | 744 | |
|
745 | 745 | fft_data = numpy.fft.fft(data, axis=1) |
|
746 | 746 | |
|
747 | 747 | conv = fft_data*fft_code |
|
748 | 748 | |
|
749 | 749 | data = numpy.fft.ifft(conv,axis=1) |
|
750 | 750 | |
|
751 | 751 | return data |
|
752 | 752 | |
|
753 | 753 | def __convolutionInFreqOpt(self, data): |
|
754 | 754 | |
|
755 | 755 | raise NotImplementedError |
|
756 | 756 | |
|
757 | 757 | def __convolutionInTime(self, data): |
|
758 | 758 | |
|
759 | 759 | code = self.code[self.__profIndex] |
|
760 | 760 | for i in range(self.__nChannels): |
|
761 | 761 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
762 | 762 | |
|
763 | 763 | return self.datadecTime |
|
764 | 764 | |
|
765 | 765 | def __convolutionByBlockInTime(self, data): |
|
766 | 766 | |
|
767 | 767 | repetitions = int(self.__nProfiles / self.nCode) |
|
768 | 768 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
769 | 769 | junk = junk.flatten() |
|
770 | 770 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
771 | 771 | profilesList = range(self.__nProfiles) |
|
772 | 772 | |
|
773 | 773 | for i in range(self.__nChannels): |
|
774 | 774 | for j in profilesList: |
|
775 | 775 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
776 | 776 | return self.datadecTime |
|
777 | 777 | |
|
778 | 778 | def __convolutionByBlockInFreq(self, data): |
|
779 | 779 | |
|
780 | 780 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
781 | 781 | |
|
782 | 782 | |
|
783 | 783 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
784 | 784 | |
|
785 | 785 | fft_data = numpy.fft.fft(data, axis=2) |
|
786 | 786 | |
|
787 | 787 | conv = fft_data*fft_code |
|
788 | 788 | |
|
789 | 789 | data = numpy.fft.ifft(conv,axis=2) |
|
790 | 790 | |
|
791 | 791 | return data |
|
792 | 792 | |
|
793 | 793 | |
|
794 | 794 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
795 | 795 | |
|
796 | 796 | if dataOut.flagDecodeData: |
|
797 | 797 | print("This data is already decoded, recoding again ...") |
|
798 | 798 | |
|
799 | 799 | if not self.isConfig: |
|
800 | 800 | |
|
801 | 801 | if code is None: |
|
802 | 802 | if dataOut.code is None: |
|
803 | 803 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
804 | 804 | |
|
805 | 805 | code = dataOut.code |
|
806 | 806 | else: |
|
807 | 807 | code = numpy.array(code).reshape(nCode,nBaud) |
|
808 | 808 | self.setup(code, osamp, dataOut) |
|
809 | 809 | |
|
810 | 810 | self.isConfig = True |
|
811 | 811 | |
|
812 | 812 | if mode == 3: |
|
813 | 813 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
814 | 814 | |
|
815 | 815 | if times != None: |
|
816 | 816 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
817 | 817 | |
|
818 | 818 | if self.code is None: |
|
819 | 819 | print("Fail decoding: Code is not defined.") |
|
820 | 820 | return |
|
821 | 821 | |
|
822 | 822 | self.__nProfiles = dataOut.nProfiles |
|
823 | 823 | datadec = None |
|
824 | 824 | |
|
825 | 825 | if mode == 3: |
|
826 | 826 | mode = 0 |
|
827 | 827 | |
|
828 | 828 | if dataOut.flagDataAsBlock: |
|
829 | 829 | """ |
|
830 | 830 | Decoding when data have been read as block, |
|
831 | 831 | """ |
|
832 | 832 | |
|
833 | 833 | if mode == 0: |
|
834 | 834 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
835 | 835 | if mode == 1: |
|
836 | 836 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
837 | 837 | else: |
|
838 | 838 | """ |
|
839 | 839 | Decoding when data have been read profile by profile |
|
840 | 840 | """ |
|
841 | 841 | if mode == 0: |
|
842 | 842 | datadec = self.__convolutionInTime(dataOut.data) |
|
843 | 843 | |
|
844 | 844 | if mode == 1: |
|
845 | 845 | datadec = self.__convolutionInFreq(dataOut.data) |
|
846 | 846 | |
|
847 | 847 | if mode == 2: |
|
848 | 848 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
849 | 849 | |
|
850 | 850 | if datadec is None: |
|
851 | 851 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
852 | 852 | |
|
853 | 853 | dataOut.code = self.code |
|
854 | 854 | dataOut.nCode = self.nCode |
|
855 | 855 | dataOut.nBaud = self.nBaud |
|
856 | 856 | |
|
857 | 857 | dataOut.data = datadec |
|
858 | 858 | |
|
859 | 859 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
860 | 860 | |
|
861 | 861 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
862 | 862 | |
|
863 | 863 | if self.__profIndex == self.nCode-1: |
|
864 | 864 | self.__profIndex = 0 |
|
865 | 865 | return dataOut |
|
866 | 866 | |
|
867 | 867 | self.__profIndex += 1 |
|
868 | 868 | |
|
869 | 869 | return dataOut |
|
870 | 870 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
871 | 871 | |
|
872 | 872 | |
|
873 | 873 | class ProfileConcat(Operation): |
|
874 | 874 | |
|
875 | 875 | isConfig = False |
|
876 | 876 | buffer = None |
|
877 | 877 | |
|
878 | 878 | def __init__(self, **kwargs): |
|
879 | 879 | |
|
880 | 880 | Operation.__init__(self, **kwargs) |
|
881 | 881 | self.profileIndex = 0 |
|
882 | 882 | |
|
883 | 883 | def reset(self): |
|
884 | 884 | self.buffer = numpy.zeros_like(self.buffer) |
|
885 | 885 | self.start_index = 0 |
|
886 | 886 | self.times = 1 |
|
887 | 887 | |
|
888 | 888 | def setup(self, data, m, n=1): |
|
889 | 889 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
890 | 890 | self.nHeights = data.shape[1]#.nHeights |
|
891 | 891 | self.start_index = 0 |
|
892 | 892 | self.times = 1 |
|
893 | 893 | |
|
894 | 894 | def concat(self, data): |
|
895 | 895 | |
|
896 | 896 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
897 | 897 | self.start_index = self.start_index + self.nHeights |
|
898 | 898 | |
|
899 | 899 | def run(self, dataOut, m): |
|
900 | 900 | dataOut.flagNoData = True |
|
901 | 901 | |
|
902 | 902 | if not self.isConfig: |
|
903 | 903 | self.setup(dataOut.data, m, 1) |
|
904 | 904 | self.isConfig = True |
|
905 | 905 | |
|
906 | 906 | if dataOut.flagDataAsBlock: |
|
907 | 907 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
908 | 908 | |
|
909 | 909 | else: |
|
910 | 910 | self.concat(dataOut.data) |
|
911 | 911 | self.times += 1 |
|
912 | 912 | if self.times > m: |
|
913 | 913 | dataOut.data = self.buffer |
|
914 | 914 | self.reset() |
|
915 | 915 | dataOut.flagNoData = False |
|
916 | 916 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
917 | 917 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
918 | 918 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
919 | 919 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
920 | 920 | dataOut.ippSeconds *= m |
|
921 | 921 | return dataOut |
|
922 | 922 | |
|
923 | 923 | class ProfileSelector(Operation): |
|
924 | 924 | |
|
925 | 925 | profileIndex = None |
|
926 | 926 | # Tamanho total de los perfiles |
|
927 | 927 | nProfiles = None |
|
928 | 928 | |
|
929 | 929 | def __init__(self, **kwargs): |
|
930 | 930 | |
|
931 | 931 | Operation.__init__(self, **kwargs) |
|
932 | 932 | self.profileIndex = 0 |
|
933 | 933 | |
|
934 | 934 | def incProfileIndex(self): |
|
935 | 935 | |
|
936 | 936 | self.profileIndex += 1 |
|
937 | 937 | |
|
938 | 938 | if self.profileIndex >= self.nProfiles: |
|
939 | 939 | self.profileIndex = 0 |
|
940 | 940 | |
|
941 | 941 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
942 | 942 | |
|
943 | 943 | if profileIndex < minIndex: |
|
944 | 944 | return False |
|
945 | 945 | |
|
946 | 946 | if profileIndex > maxIndex: |
|
947 | 947 | return False |
|
948 | 948 | |
|
949 | 949 | return True |
|
950 | 950 | |
|
951 | 951 | def isThisProfileInList(self, profileIndex, profileList): |
|
952 | 952 | |
|
953 | 953 | if profileIndex not in profileList: |
|
954 | 954 | return False |
|
955 | 955 | |
|
956 | 956 | return True |
|
957 | 957 | |
|
958 | 958 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
959 | 959 | |
|
960 | 960 | """ |
|
961 | 961 | ProfileSelector: |
|
962 | 962 | |
|
963 | 963 | Inputs: |
|
964 | 964 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
965 | 965 | |
|
966 | 966 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
967 | 967 | |
|
968 | 968 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
969 | 969 | |
|
970 | 970 | """ |
|
971 | 971 | |
|
972 | 972 | if rangeList is not None: |
|
973 | 973 | if type(rangeList[0]) not in (tuple, list): |
|
974 | 974 | rangeList = [rangeList] |
|
975 | 975 | |
|
976 | 976 | dataOut.flagNoData = True |
|
977 | 977 | |
|
978 | 978 | if dataOut.flagDataAsBlock: |
|
979 | 979 | """ |
|
980 | 980 | data dimension = [nChannels, nProfiles, nHeis] |
|
981 | 981 | """ |
|
982 | 982 | if profileList != None: |
|
983 | 983 | dataOut.data = dataOut.data[:,profileList,:] |
|
984 | 984 | |
|
985 | 985 | if profileRangeList != None: |
|
986 | 986 | minIndex = profileRangeList[0] |
|
987 | 987 | maxIndex = profileRangeList[1] |
|
988 | 988 | profileList = list(range(minIndex, maxIndex+1)) |
|
989 | 989 | |
|
990 | 990 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
991 | 991 | |
|
992 | 992 | if rangeList != None: |
|
993 | 993 | |
|
994 | 994 | profileList = [] |
|
995 | 995 | |
|
996 | 996 | for thisRange in rangeList: |
|
997 | 997 | minIndex = thisRange[0] |
|
998 | 998 | maxIndex = thisRange[1] |
|
999 | 999 | |
|
1000 | 1000 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
1001 | 1001 | |
|
1002 | 1002 | dataOut.data = dataOut.data[:,profileList,:] |
|
1003 | 1003 | |
|
1004 | 1004 | dataOut.nProfiles = len(profileList) |
|
1005 | 1005 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
1006 | 1006 | dataOut.flagNoData = False |
|
1007 | 1007 | |
|
1008 | 1008 | return dataOut |
|
1009 | 1009 | |
|
1010 | 1010 | """ |
|
1011 | 1011 | data dimension = [nChannels, nHeis] |
|
1012 | 1012 | """ |
|
1013 | 1013 | |
|
1014 | 1014 | if profileList != None: |
|
1015 | 1015 | |
|
1016 | 1016 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
1017 | 1017 | |
|
1018 | 1018 | self.nProfiles = len(profileList) |
|
1019 | 1019 | dataOut.nProfiles = self.nProfiles |
|
1020 | 1020 | dataOut.profileIndex = self.profileIndex |
|
1021 | 1021 | dataOut.flagNoData = False |
|
1022 | 1022 | |
|
1023 | 1023 | self.incProfileIndex() |
|
1024 | 1024 | return dataOut |
|
1025 | 1025 | |
|
1026 | 1026 | if profileRangeList != None: |
|
1027 | 1027 | |
|
1028 | 1028 | minIndex = profileRangeList[0] |
|
1029 | 1029 | maxIndex = profileRangeList[1] |
|
1030 | 1030 | |
|
1031 | 1031 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1032 | 1032 | |
|
1033 | 1033 | self.nProfiles = maxIndex - minIndex + 1 |
|
1034 | 1034 | dataOut.nProfiles = self.nProfiles |
|
1035 | 1035 | dataOut.profileIndex = self.profileIndex |
|
1036 | 1036 | dataOut.flagNoData = False |
|
1037 | 1037 | |
|
1038 | 1038 | self.incProfileIndex() |
|
1039 | 1039 | return dataOut |
|
1040 | 1040 | |
|
1041 | 1041 | if rangeList != None: |
|
1042 | 1042 | |
|
1043 | 1043 | nProfiles = 0 |
|
1044 | 1044 | |
|
1045 | 1045 | for thisRange in rangeList: |
|
1046 | 1046 | minIndex = thisRange[0] |
|
1047 | 1047 | maxIndex = thisRange[1] |
|
1048 | 1048 | |
|
1049 | 1049 | nProfiles += maxIndex - minIndex + 1 |
|
1050 | 1050 | |
|
1051 | 1051 | for thisRange in rangeList: |
|
1052 | 1052 | |
|
1053 | 1053 | minIndex = thisRange[0] |
|
1054 | 1054 | maxIndex = thisRange[1] |
|
1055 | 1055 | |
|
1056 | 1056 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1057 | 1057 | |
|
1058 | 1058 | self.nProfiles = nProfiles |
|
1059 | 1059 | dataOut.nProfiles = self.nProfiles |
|
1060 | 1060 | dataOut.profileIndex = self.profileIndex |
|
1061 | 1061 | dataOut.flagNoData = False |
|
1062 | 1062 | |
|
1063 | 1063 | self.incProfileIndex() |
|
1064 | 1064 | |
|
1065 | 1065 | break |
|
1066 | 1066 | |
|
1067 | 1067 | return dataOut |
|
1068 | 1068 | |
|
1069 | 1069 | |
|
1070 | 1070 | if beam != None: #beam is only for AMISR data |
|
1071 | 1071 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1072 | 1072 | dataOut.flagNoData = False |
|
1073 | 1073 | dataOut.profileIndex = self.profileIndex |
|
1074 | 1074 | |
|
1075 | 1075 | self.incProfileIndex() |
|
1076 | 1076 | |
|
1077 | 1077 | return dataOut |
|
1078 | 1078 | |
|
1079 | 1079 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1080 | 1080 | |
|
1081 | 1081 | |
|
1082 | 1082 | class Reshaper(Operation): |
|
1083 | 1083 | |
|
1084 | 1084 | def __init__(self, **kwargs): |
|
1085 | 1085 | |
|
1086 | 1086 | Operation.__init__(self, **kwargs) |
|
1087 | 1087 | |
|
1088 | 1088 | self.__buffer = None |
|
1089 | 1089 | self.__nitems = 0 |
|
1090 | 1090 | |
|
1091 | 1091 | def __appendProfile(self, dataOut, nTxs): |
|
1092 | 1092 | |
|
1093 | 1093 | if self.__buffer is None: |
|
1094 | 1094 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1095 | 1095 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1096 | 1096 | |
|
1097 | 1097 | ini = dataOut.nHeights * self.__nitems |
|
1098 | 1098 | end = ini + dataOut.nHeights |
|
1099 | 1099 | |
|
1100 | 1100 | self.__buffer[:, ini:end] = dataOut.data |
|
1101 | 1101 | |
|
1102 | 1102 | self.__nitems += 1 |
|
1103 | 1103 | |
|
1104 | 1104 | return int(self.__nitems*nTxs) |
|
1105 | 1105 | |
|
1106 | 1106 | def __getBuffer(self): |
|
1107 | 1107 | |
|
1108 | 1108 | if self.__nitems == int(1./self.__nTxs): |
|
1109 | 1109 | |
|
1110 | 1110 | self.__nitems = 0 |
|
1111 | 1111 | |
|
1112 | 1112 | return self.__buffer.copy() |
|
1113 | 1113 | |
|
1114 | 1114 | return None |
|
1115 | 1115 | |
|
1116 | 1116 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1117 | 1117 | |
|
1118 | 1118 | if shape is None and nTxs is None: |
|
1119 | 1119 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1120 | 1120 | |
|
1121 | 1121 | if nTxs: |
|
1122 | 1122 | if nTxs < 0: |
|
1123 | 1123 | raise ValueError("nTxs should be greater than 0") |
|
1124 | 1124 | |
|
1125 | 1125 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1126 | 1126 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1127 | 1127 | |
|
1128 | 1128 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1129 | 1129 | |
|
1130 | 1130 | return shape, nTxs |
|
1131 | 1131 | |
|
1132 | 1132 | if len(shape) != 2 and len(shape) != 3: |
|
1133 | 1133 | raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)) |
|
1134 | 1134 | |
|
1135 | 1135 | if len(shape) == 2: |
|
1136 | 1136 | shape_tuple = [dataOut.nChannels] |
|
1137 | 1137 | shape_tuple.extend(shape) |
|
1138 | 1138 | else: |
|
1139 | 1139 | shape_tuple = list(shape) |
|
1140 | 1140 | |
|
1141 | 1141 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1142 | 1142 | |
|
1143 | 1143 | return shape_tuple, nTxs |
|
1144 | 1144 | |
|
1145 | 1145 | def run(self, dataOut, shape=None, nTxs=None): |
|
1146 | 1146 | |
|
1147 | 1147 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1148 | 1148 | |
|
1149 | 1149 | dataOut.flagNoData = True |
|
1150 | 1150 | profileIndex = None |
|
1151 | 1151 | |
|
1152 | 1152 | if dataOut.flagDataAsBlock: |
|
1153 | 1153 | |
|
1154 | 1154 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1155 | 1155 | dataOut.flagNoData = False |
|
1156 | 1156 | |
|
1157 | 1157 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1158 | 1158 | |
|
1159 | 1159 | else: |
|
1160 | 1160 | |
|
1161 | 1161 | if self.__nTxs < 1: |
|
1162 | 1162 | |
|
1163 | 1163 | self.__appendProfile(dataOut, self.__nTxs) |
|
1164 | 1164 | new_data = self.__getBuffer() |
|
1165 | 1165 | |
|
1166 | 1166 | if new_data is not None: |
|
1167 | 1167 | dataOut.data = new_data |
|
1168 | 1168 | dataOut.flagNoData = False |
|
1169 | 1169 | |
|
1170 | 1170 | profileIndex = dataOut.profileIndex*nTxs |
|
1171 | 1171 | |
|
1172 | 1172 | else: |
|
1173 | 1173 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1174 | 1174 | |
|
1175 | 1175 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1176 | 1176 | |
|
1177 | 1177 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1178 | 1178 | |
|
1179 | 1179 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1180 | 1180 | |
|
1181 | 1181 | dataOut.profileIndex = profileIndex |
|
1182 | 1182 | |
|
1183 | 1183 | dataOut.ippSeconds /= self.__nTxs |
|
1184 | 1184 | |
|
1185 | 1185 | return dataOut |
|
1186 | 1186 | |
|
1187 | 1187 | class SplitProfiles(Operation): |
|
1188 | 1188 | |
|
1189 | 1189 | def __init__(self, **kwargs): |
|
1190 | 1190 | |
|
1191 | 1191 | Operation.__init__(self, **kwargs) |
|
1192 | 1192 | |
|
1193 | 1193 | def run(self, dataOut, n): |
|
1194 | 1194 | |
|
1195 | 1195 | dataOut.flagNoData = True |
|
1196 | 1196 | profileIndex = None |
|
1197 | 1197 | |
|
1198 | 1198 | if dataOut.flagDataAsBlock: |
|
1199 | 1199 | |
|
1200 | 1200 | #nchannels, nprofiles, nsamples |
|
1201 | 1201 | shape = dataOut.data.shape |
|
1202 | 1202 | |
|
1203 | 1203 | if shape[2] % n != 0: |
|
1204 | 1204 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1205 | 1205 | |
|
1206 | 1206 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1207 | 1207 | |
|
1208 | 1208 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1209 | 1209 | dataOut.flagNoData = False |
|
1210 | 1210 | |
|
1211 | 1211 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1212 | 1212 | |
|
1213 | 1213 | else: |
|
1214 | 1214 | |
|
1215 | 1215 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1216 | 1216 | |
|
1217 | 1217 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1218 | 1218 | |
|
1219 | 1219 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1220 | 1220 | |
|
1221 | 1221 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1222 | 1222 | |
|
1223 | 1223 | dataOut.profileIndex = profileIndex |
|
1224 | 1224 | |
|
1225 | 1225 | dataOut.ippSeconds /= n |
|
1226 | 1226 | |
|
1227 | 1227 | return dataOut |
|
1228 | 1228 | |
|
1229 | 1229 | class CombineProfiles(Operation): |
|
1230 | 1230 | def __init__(self, **kwargs): |
|
1231 | 1231 | |
|
1232 | 1232 | Operation.__init__(self, **kwargs) |
|
1233 | 1233 | |
|
1234 | 1234 | self.__remData = None |
|
1235 | 1235 | self.__profileIndex = 0 |
|
1236 | 1236 | |
|
1237 | 1237 | def run(self, dataOut, n): |
|
1238 | 1238 | |
|
1239 | 1239 | dataOut.flagNoData = True |
|
1240 | 1240 | profileIndex = None |
|
1241 | 1241 | |
|
1242 | 1242 | if dataOut.flagDataAsBlock: |
|
1243 | 1243 | |
|
1244 | 1244 | #nchannels, nprofiles, nsamples |
|
1245 | 1245 | shape = dataOut.data.shape |
|
1246 | 1246 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1247 | 1247 | |
|
1248 | 1248 | if shape[1] % n != 0: |
|
1249 | 1249 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1250 | 1250 | |
|
1251 | 1251 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1252 | 1252 | dataOut.flagNoData = False |
|
1253 | 1253 | |
|
1254 | 1254 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1255 | 1255 | |
|
1256 | 1256 | else: |
|
1257 | 1257 | |
|
1258 | 1258 | #nchannels, nsamples |
|
1259 | 1259 | if self.__remData is None: |
|
1260 | 1260 | newData = dataOut.data |
|
1261 | 1261 | else: |
|
1262 | 1262 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1263 | 1263 | |
|
1264 | 1264 | self.__profileIndex += 1 |
|
1265 | 1265 | |
|
1266 | 1266 | if self.__profileIndex < n: |
|
1267 | 1267 | self.__remData = newData |
|
1268 | 1268 | #continue |
|
1269 | 1269 | return |
|
1270 | 1270 | |
|
1271 | 1271 | self.__profileIndex = 0 |
|
1272 | 1272 | self.__remData = None |
|
1273 | 1273 | |
|
1274 | 1274 | dataOut.data = newData |
|
1275 | 1275 | dataOut.flagNoData = False |
|
1276 | 1276 | |
|
1277 | 1277 | profileIndex = dataOut.profileIndex/n |
|
1278 | 1278 | |
|
1279 | 1279 | |
|
1280 | 1280 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1281 | 1281 | |
|
1282 | 1282 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1283 | 1283 | |
|
1284 | 1284 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1285 | 1285 | |
|
1286 | 1286 | dataOut.profileIndex = profileIndex |
|
1287 | 1287 | |
|
1288 | 1288 | dataOut.ippSeconds *= n |
|
1289 | 1289 | |
|
1290 | 1290 | return dataOut |
|
1291 | 1291 | |
|
1292 | 1292 | class PulsePairVoltage(Operation): |
|
1293 | 1293 | ''' |
|
1294 | 1294 | Function PulsePair(Signal Power, Velocity) |
|
1295 | 1295 | The real component of Lag[0] provides Intensity Information |
|
1296 | 1296 | The imag component of Lag[1] Phase provides Velocity Information |
|
1297 | 1297 | |
|
1298 | 1298 | Configuration Parameters: |
|
1299 | 1299 | nPRF = Number of Several PRF |
|
1300 | 1300 | theta = Degree Azimuth angel Boundaries |
|
1301 | 1301 | |
|
1302 | 1302 | Input: |
|
1303 | 1303 | self.dataOut |
|
1304 | 1304 | lag[N] |
|
1305 | 1305 | Affected: |
|
1306 | 1306 | self.dataOut.spc |
|
1307 | 1307 | ''' |
|
1308 | 1308 | isConfig = False |
|
1309 | 1309 | __profIndex = 0 |
|
1310 | 1310 | __initime = None |
|
1311 | 1311 | __lastdatatime = None |
|
1312 | 1312 | __buffer = None |
|
1313 | 1313 | noise = None |
|
1314 | 1314 | __dataReady = False |
|
1315 | 1315 | n = None |
|
1316 | 1316 | __nch = 0 |
|
1317 | 1317 | __nHeis = 0 |
|
1318 | 1318 | removeDC = False |
|
1319 | 1319 | ipp = None |
|
1320 | 1320 | lambda_ = 0 |
|
1321 | 1321 | |
|
1322 | 1322 | def __init__(self,**kwargs): |
|
1323 | 1323 | Operation.__init__(self,**kwargs) |
|
1324 | 1324 | |
|
1325 | 1325 | def setup(self, dataOut, n = None, removeDC=False): |
|
1326 | 1326 | ''' |
|
1327 | 1327 | n= Numero de PRF's de entrada |
|
1328 | 1328 | ''' |
|
1329 | 1329 | self.__initime = None |
|
1330 | 1330 | self.__lastdatatime = 0 |
|
1331 | 1331 | self.__dataReady = False |
|
1332 | 1332 | self.__buffer = 0 |
|
1333 | 1333 | self.__profIndex = 0 |
|
1334 | 1334 | self.noise = None |
|
1335 | 1335 | self.__nch = dataOut.nChannels |
|
1336 | 1336 | self.__nHeis = dataOut.nHeights |
|
1337 | 1337 | self.removeDC = removeDC |
|
1338 | 1338 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1339 | 1339 | self.ippSec = dataOut.ippSeconds |
|
1340 | 1340 | self.nCohInt = dataOut.nCohInt |
|
1341 | 1341 | print("IPPseconds",dataOut.ippSeconds) |
|
1342 | 1342 | |
|
1343 | 1343 | print("ELVALOR DE n es:", n) |
|
1344 | 1344 | if n == None: |
|
1345 | 1345 | raise ValueError("n should be specified.") |
|
1346 | 1346 | |
|
1347 | 1347 | if n != None: |
|
1348 | 1348 | if n<2: |
|
1349 | 1349 | raise ValueError("n should be greater than 2") |
|
1350 | 1350 | |
|
1351 | 1351 | self.n = n |
|
1352 | 1352 | self.__nProf = n |
|
1353 | 1353 | |
|
1354 | 1354 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1355 | 1355 | n, |
|
1356 | 1356 | dataOut.nHeights), |
|
1357 | 1357 | dtype='complex') |
|
1358 | #self.noise = numpy.zeros([self.__nch,self.__nHeis]) | |
|
1359 | #for i in range(self.__nch): | |
|
1360 | # self.noise[i]=dataOut.getNoise(channel=i) | |
|
1361 | 1358 | |
|
1362 | 1359 | def putData(self,data): |
|
1363 | 1360 | ''' |
|
1364 | 1361 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1365 | 1362 | ''' |
|
1366 | 1363 | self.__buffer[:,self.__profIndex,:]= data |
|
1367 | 1364 | self.__profIndex += 1 |
|
1368 | 1365 | return |
|
1369 | 1366 | |
|
1370 | 1367 | def pushData(self,dataOut): |
|
1371 | 1368 | ''' |
|
1372 | 1369 | Return the PULSEPAIR and the profiles used in the operation |
|
1373 | 1370 | Affected : self.__profileIndex |
|
1374 | 1371 | ''' |
|
1372 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1375 | 1373 | if self.removeDC==True: |
|
1376 | 1374 | mean = numpy.mean(self.__buffer,1) |
|
1377 | 1375 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1378 | 1376 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1379 | 1377 | self.__buffer = self.__buffer - dc |
|
1378 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Calculo de Potencia Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1379 | pair0 = self.__buffer*numpy.conj(self.__buffer) | |
|
1380 | pair0 = pair0.real | |
|
1381 | lag_0 = numpy.sum(pair0,1) | |
|
1382 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Calculo de Ruido x canalΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1383 | self.noise = numpy.zeros(self.__nch) | |
|
1384 | for i in range(self.__nch): | |
|
1385 | daux = numpy.sort(pair0[i,:,:],axis= None) | |
|
1386 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) | |
|
1387 | ||
|
1388 | self.noise = self.noise.reshape(self.__nch,1) | |
|
1389 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) | |
|
1390 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) | |
|
1391 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) | |
|
1392 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Potencia recibida= P , Potencia senal = S , Ruido= NΒ·Β· | |
|
1393 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· P= S+N ,P=lag_0/N Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1394 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Power Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1395 | data_power = lag_0/(self.n*self.nCohInt) | |
|
1396 | #------------------ Senal Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1397 | data_intensity = pair0 - noise_buffer | |
|
1398 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) | |
|
1399 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
|
1400 | for i in range(self.__nch): | |
|
1401 | for j in range(self.__nHeis): | |
|
1402 | if data_intensity[i][j] < 0: | |
|
1403 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
|
1380 | 1404 | |
|
1381 | lag_0 = numpy.sum(self.__buffer*numpy.conj(self.__buffer),1) | |
|
1382 | data_intensity = lag_0/(self.n*self.nCohInt)#*self.nCohInt) | |
|
1383 | ||
|
1405 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo de Frecuencia y Velocidad dopplerΒ·Β·Β·Β·Β·Β·Β·Β· | |
|
1384 | 1406 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1385 | 1407 | lag_1 = numpy.sum(pair1,1) |
|
1386 | #angle = numpy.angle(numpy.sum(pair1,1))*180/(math.pi) | |
|
1387 | data_velocity = (-1.0*self.lambda_/(4*math.pi*self.ippSec))*numpy.angle(lag_1)#self.ippSec*self.nCohInt | |
|
1408 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) | |
|
1409 | data_velocity = (self.lambda_/2.0)*data_freq | |
|
1388 | 1410 | |
|
1389 | self.noise = numpy.zeros([self.__nch,self.__nHeis]) | |
|
1390 | for i in range(self.__nch): | |
|
1391 | self.noise[i]=dataOut.getNoise(channel=i) | |
|
1411 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Potencia promedio estimada de la SenalΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1412 | lag_0 = lag_0/self.n | |
|
1413 | S = lag_0-self.noise | |
|
1392 | 1414 | |
|
1393 | lag_0 = lag_0.real/(self.n) | |
|
1415 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Frecuencia Doppler promedio Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1394 | 1416 | lag_1 = lag_1/(self.n-1) |
|
1395 | 1417 | R1 = numpy.abs(lag_1) |
|
1396 | S = (lag_0-self.noise) | |
|
1397 | 1418 | |
|
1419 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo del SNRΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1398 | 1420 | data_snrPP = S/self.noise |
|
1399 | data_snrPP = numpy.where(data_snrPP<0,1,data_snrPP) | |
|
1421 | for i in range(self.__nch): | |
|
1422 | for j in range(self.__nHeis): | |
|
1423 | if data_snrPP[i][j] < 1.e-20: | |
|
1424 | data_snrPP[i][j] = 1.e-20 | |
|
1400 | 1425 | |
|
1426 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo del ancho espectral Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1401 | 1427 | L = S/R1 |
|
1402 | 1428 | L = numpy.where(L<0,1,L) |
|
1403 | 1429 | L = numpy.log(L) |
|
1404 | ||
|
1405 | 1430 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1406 | ||
|
1407 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*tmp*numpy.sign(L) | |
|
1408 | #data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*k | |
|
1431 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) | |
|
1409 | 1432 | n = self.__profIndex |
|
1410 | 1433 | |
|
1411 | 1434 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1412 | 1435 | self.__profIndex = 0 |
|
1413 | return data_intensity,data_velocity,data_snrPP,data_specwidth,n | |
|
1436 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n | |
|
1437 | ||
|
1414 | 1438 | |
|
1415 | 1439 | def pulsePairbyProfiles(self,dataOut): |
|
1416 | 1440 | |
|
1417 | 1441 | self.__dataReady = False |
|
1442 | data_power = None | |
|
1418 | 1443 | data_intensity = None |
|
1419 | 1444 | data_velocity = None |
|
1420 | 1445 | data_specwidth = None |
|
1421 | 1446 | data_snrPP = None |
|
1422 | 1447 | self.putData(data=dataOut.data) |
|
1423 | 1448 | if self.__profIndex == self.n: |
|
1424 | #self.noise = numpy.zeros([self.__nch,self.__nHeis]) | |
|
1425 | #for i in range(self.__nch): | |
|
1426 | # self.noise[i]=data.getNoise(channel=i) | |
|
1427 | #print(self.noise.shape) | |
|
1428 | data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) | |
|
1449 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) | |
|
1429 | 1450 | self.__dataReady = True |
|
1430 | 1451 | |
|
1431 | return data_intensity, data_velocity,data_snrPP,data_specwidth | |
|
1452 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth | |
|
1453 | ||
|
1432 | 1454 | |
|
1433 | 1455 | def pulsePairOp(self, dataOut, datatime= None): |
|
1434 | 1456 | |
|
1435 | 1457 | if self.__initime == None: |
|
1436 | 1458 | self.__initime = datatime |
|
1437 | #print("hola") | |
|
1438 | data_intensity, data_velocity,data_snrPP,data_specwidth = self.pulsePairbyProfiles(dataOut) | |
|
1459 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) | |
|
1439 | 1460 | self.__lastdatatime = datatime |
|
1440 | 1461 | |
|
1441 |
if data_ |
|
|
1442 | return None, None,None,None,None | |
|
1462 | if data_power is None: | |
|
1463 | return None, None, None,None,None,None | |
|
1443 | 1464 | |
|
1444 | 1465 | avgdatatime = self.__initime |
|
1445 | 1466 | deltatime = datatime - self.__lastdatatime |
|
1446 | 1467 | self.__initime = datatime |
|
1447 | 1468 | |
|
1448 | return data_intensity, data_velocity,data_snrPP,data_specwidth,avgdatatime | |
|
1469 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime | |
|
1449 | 1470 | |
|
1450 | 1471 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1451 | 1472 | |
|
1452 | 1473 | if not self.isConfig: |
|
1453 | 1474 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1454 | 1475 | self.isConfig = True |
|
1455 | data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
|
1476 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
|
1456 | 1477 | dataOut.flagNoData = True |
|
1457 | 1478 | |
|
1458 | 1479 | if self.__dataReady: |
|
1459 | 1480 | dataOut.nCohInt *= self.n |
|
1460 |
dataOut.data |
|
|
1461 |
dataOut.data |
|
|
1462 |
dataOut.data |
|
|
1463 |
dataOut.data |
|
|
1481 | dataOut.dataPP_POW = data_intensity # S | |
|
1482 | dataOut.dataPP_POWER = data_power # P | |
|
1483 | dataOut.dataPP_DOP = data_velocity | |
|
1484 | dataOut.dataPP_SNR = data_snrPP | |
|
1485 | dataOut.dataPP_WIDTH = data_specwidth | |
|
1464 | 1486 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1465 | 1487 | dataOut.utctime = avgdatatime |
|
1466 | 1488 | dataOut.flagNoData = False |
|
1467 | 1489 | return dataOut |
|
1468 | 1490 | |
|
1469 | 1491 | |
|
1492 | ||
|
1470 | 1493 | # import collections |
|
1471 | 1494 | # from scipy.stats import mode |
|
1472 | 1495 | # |
|
1473 | 1496 | # class Synchronize(Operation): |
|
1474 | 1497 | # |
|
1475 | 1498 | # isConfig = False |
|
1476 | 1499 | # __profIndex = 0 |
|
1477 | 1500 | # |
|
1478 | 1501 | # def __init__(self, **kwargs): |
|
1479 | 1502 | # |
|
1480 | 1503 | # Operation.__init__(self, **kwargs) |
|
1481 | 1504 | # # self.isConfig = False |
|
1482 | 1505 | # self.__powBuffer = None |
|
1483 | 1506 | # self.__startIndex = 0 |
|
1484 | 1507 | # self.__pulseFound = False |
|
1485 | 1508 | # |
|
1486 | 1509 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1487 | 1510 | # |
|
1488 | 1511 | # #Read data |
|
1489 | 1512 | # |
|
1490 | 1513 | # powerdB = dataOut.getPower(channel = channel) |
|
1491 | 1514 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1492 | 1515 | # |
|
1493 | 1516 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1494 | 1517 | # |
|
1495 | 1518 | # dataArray = numpy.array(self.__powBuffer) |
|
1496 | 1519 | # |
|
1497 | 1520 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1498 | 1521 | # |
|
1499 | 1522 | # maxValue = numpy.nanmax(filteredPower) |
|
1500 | 1523 | # |
|
1501 | 1524 | # if maxValue < noisedB + 10: |
|
1502 | 1525 | # #No se encuentra ningun pulso de transmision |
|
1503 | 1526 | # return None |
|
1504 | 1527 | # |
|
1505 | 1528 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1506 | 1529 | # |
|
1507 | 1530 | # if len(maxValuesIndex) < 2: |
|
1508 | 1531 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1509 | 1532 | # return None |
|
1510 | 1533 | # |
|
1511 | 1534 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1512 | 1535 | # |
|
1513 | 1536 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1514 | 1537 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1515 | 1538 | # |
|
1516 | 1539 | # if len(pulseIndex) < 2: |
|
1517 | 1540 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1518 | 1541 | # return None |
|
1519 | 1542 | # |
|
1520 | 1543 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1521 | 1544 | # |
|
1522 | 1545 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1523 | 1546 | # #(No deberian existir IPP menor a 10 unidades) |
|
1524 | 1547 | # |
|
1525 | 1548 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1526 | 1549 | # |
|
1527 | 1550 | # if len(realIndex) < 2: |
|
1528 | 1551 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1529 | 1552 | # return None |
|
1530 | 1553 | # |
|
1531 | 1554 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1532 | 1555 | # realPulseIndex = pulseIndex[realIndex] |
|
1533 | 1556 | # |
|
1534 | 1557 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1535 | 1558 | # |
|
1536 | 1559 | # print "IPP = %d samples" %period |
|
1537 | 1560 | # |
|
1538 | 1561 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1539 | 1562 | # self.__startIndex = int(realPulseIndex[0]) |
|
1540 | 1563 | # |
|
1541 | 1564 | # return 1 |
|
1542 | 1565 | # |
|
1543 | 1566 | # |
|
1544 | 1567 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1545 | 1568 | # |
|
1546 | 1569 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1547 | 1570 | # maxlen = buffer_size*nSamples) |
|
1548 | 1571 | # |
|
1549 | 1572 | # bufferList = [] |
|
1550 | 1573 | # |
|
1551 | 1574 | # for i in range(nChannels): |
|
1552 | 1575 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1553 | 1576 | # maxlen = buffer_size*nSamples) |
|
1554 | 1577 | # |
|
1555 | 1578 | # bufferList.append(bufferByChannel) |
|
1556 | 1579 | # |
|
1557 | 1580 | # self.__nSamples = nSamples |
|
1558 | 1581 | # self.__nChannels = nChannels |
|
1559 | 1582 | # self.__bufferList = bufferList |
|
1560 | 1583 | # |
|
1561 | 1584 | # def run(self, dataOut, channel = 0): |
|
1562 | 1585 | # |
|
1563 | 1586 | # if not self.isConfig: |
|
1564 | 1587 | # nSamples = dataOut.nHeights |
|
1565 | 1588 | # nChannels = dataOut.nChannels |
|
1566 | 1589 | # self.setup(nSamples, nChannels) |
|
1567 | 1590 | # self.isConfig = True |
|
1568 | 1591 | # |
|
1569 | 1592 | # #Append new data to internal buffer |
|
1570 | 1593 | # for thisChannel in range(self.__nChannels): |
|
1571 | 1594 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1572 | 1595 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1573 | 1596 | # |
|
1574 | 1597 | # if self.__pulseFound: |
|
1575 | 1598 | # self.__startIndex -= self.__nSamples |
|
1576 | 1599 | # |
|
1577 | 1600 | # #Finding Tx Pulse |
|
1578 | 1601 | # if not self.__pulseFound: |
|
1579 | 1602 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1580 | 1603 | # |
|
1581 | 1604 | # if indexFound == None: |
|
1582 | 1605 | # dataOut.flagNoData = True |
|
1583 | 1606 | # return |
|
1584 | 1607 | # |
|
1585 | 1608 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1586 | 1609 | # self.__pulseFound = True |
|
1587 | 1610 | # self.__startIndex = indexFound |
|
1588 | 1611 | # |
|
1589 | 1612 | # #If pulse was found ... |
|
1590 | 1613 | # for thisChannel in range(self.__nChannels): |
|
1591 | 1614 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1592 | 1615 | # #print self.__startIndex |
|
1593 | 1616 | # x = numpy.array(bufferByChannel) |
|
1594 | 1617 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1595 | 1618 | # |
|
1596 | 1619 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1597 | 1620 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1598 | 1621 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1599 | 1622 | # |
|
1600 | 1623 | # dataOut.data = self.__arrayBuffer |
|
1601 | 1624 | # |
|
1602 | 1625 | # self.__startIndex += self.__newNSamples |
|
1603 | 1626 | # |
|
1604 | 1627 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now