The requested changes are too big and content was truncated. Show full diff
@@ -1,1399 +1,1434 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import copy |
|
8 | 8 | import numpy |
|
9 | 9 | import datetime |
|
10 | 10 | import json |
|
11 | 11 | |
|
12 | 12 | import schainpy.admin |
|
13 | 13 | from schainpy.utils import log |
|
14 | 14 | from .jroheaderIO import SystemHeader, RadarControllerHeader |
|
15 | 15 | from schainpy.model.data import _noise |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | def getNumpyDtype(dataTypeCode): |
|
19 | 19 | |
|
20 | 20 | if dataTypeCode == 0: |
|
21 | 21 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
22 | 22 | elif dataTypeCode == 1: |
|
23 | 23 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
24 | 24 | elif dataTypeCode == 2: |
|
25 | 25 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
26 | 26 | elif dataTypeCode == 3: |
|
27 | 27 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
28 | 28 | elif dataTypeCode == 4: |
|
29 | 29 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
30 | 30 | elif dataTypeCode == 5: |
|
31 | 31 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
32 | 32 | else: |
|
33 | 33 | raise ValueError('dataTypeCode was not defined') |
|
34 | 34 | |
|
35 | 35 | return numpyDtype |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | def getDataTypeCode(numpyDtype): |
|
39 | 39 | |
|
40 | 40 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): |
|
41 | 41 | datatype = 0 |
|
42 | 42 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): |
|
43 | 43 | datatype = 1 |
|
44 | 44 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): |
|
45 | 45 | datatype = 2 |
|
46 | 46 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): |
|
47 | 47 | datatype = 3 |
|
48 | 48 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): |
|
49 | 49 | datatype = 4 |
|
50 | 50 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): |
|
51 | 51 | datatype = 5 |
|
52 | 52 | else: |
|
53 | 53 | datatype = None |
|
54 | 54 | |
|
55 | 55 | return datatype |
|
56 | 56 | |
|
57 | 57 | |
|
58 | 58 | def hildebrand_sekhon(data, navg): |
|
59 | 59 | """ |
|
60 | 60 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
61 | 61 | implementation technique is based on the fact that the standard deviation of the spectral |
|
62 | 62 | densities is equal to the mean spectral density for white Gaussian noise |
|
63 | 63 | |
|
64 | 64 | Inputs: |
|
65 | 65 | Data : heights |
|
66 | 66 | navg : numbers of averages |
|
67 | 67 | |
|
68 | 68 | Return: |
|
69 | 69 | mean : noise's level |
|
70 | 70 | """ |
|
71 | 71 | |
|
72 | 72 | sortdata = numpy.sort(data, axis=None) |
|
73 | 73 | ''' |
|
74 | 74 | lenOfData = len(sortdata) |
|
75 | 75 | nums_min = lenOfData*0.2 |
|
76 | 76 | |
|
77 | 77 | if nums_min <= 5: |
|
78 | 78 | |
|
79 | 79 | nums_min = 5 |
|
80 | 80 | |
|
81 | 81 | sump = 0. |
|
82 | 82 | sumq = 0. |
|
83 | 83 | |
|
84 | 84 | j = 0 |
|
85 | 85 | cont = 1 |
|
86 | 86 | |
|
87 | 87 | while((cont == 1)and(j < lenOfData)): |
|
88 | 88 | |
|
89 | 89 | sump += sortdata[j] |
|
90 | 90 | sumq += sortdata[j]**2 |
|
91 | 91 | |
|
92 | 92 | if j > nums_min: |
|
93 | 93 | rtest = float(j)/(j-1) + 1.0/navg |
|
94 | 94 | if ((sumq*j) > (rtest*sump**2)): |
|
95 | 95 | j = j - 1 |
|
96 | 96 | sump = sump - sortdata[j] |
|
97 | 97 | sumq = sumq - sortdata[j]**2 |
|
98 | 98 | cont = 0 |
|
99 | 99 | |
|
100 | 100 | j += 1 |
|
101 | 101 | |
|
102 | 102 | lnoise = sump / j |
|
103 | 103 | ''' |
|
104 | 104 | return _noise.hildebrand_sekhon(sortdata, navg) |
|
105 | 105 | |
|
106 | 106 | |
|
107 | 107 | class Beam: |
|
108 | 108 | |
|
109 | 109 | def __init__(self): |
|
110 | 110 | self.codeList = [] |
|
111 | 111 | self.azimuthList = [] |
|
112 | 112 | self.zenithList = [] |
|
113 | 113 | |
|
114 | 114 | |
|
115 | 115 | class GenericData(object): |
|
116 | 116 | |
|
117 | 117 | flagNoData = True |
|
118 | 118 | |
|
119 | 119 | def copy(self, inputObj=None): |
|
120 | 120 | |
|
121 | 121 | if inputObj == None: |
|
122 | 122 | return copy.deepcopy(self) |
|
123 | 123 | |
|
124 | 124 | for key in list(inputObj.__dict__.keys()): |
|
125 | 125 | |
|
126 | 126 | attribute = inputObj.__dict__[key] |
|
127 | 127 | |
|
128 | 128 | # If this attribute is a tuple or list |
|
129 | 129 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
130 | 130 | self.__dict__[key] = attribute[:] |
|
131 | 131 | continue |
|
132 | 132 | |
|
133 | 133 | # If this attribute is another object or instance |
|
134 | 134 | if hasattr(attribute, '__dict__'): |
|
135 | 135 | self.__dict__[key] = attribute.copy() |
|
136 | 136 | continue |
|
137 | 137 | |
|
138 | 138 | self.__dict__[key] = inputObj.__dict__[key] |
|
139 | 139 | |
|
140 | 140 | def deepcopy(self): |
|
141 | 141 | |
|
142 | 142 | return copy.deepcopy(self) |
|
143 | 143 | |
|
144 | 144 | def isEmpty(self): |
|
145 | 145 | |
|
146 | 146 | return self.flagNoData |
|
147 | 147 | |
|
148 | 148 | def isReady(self): |
|
149 | 149 | |
|
150 | 150 | return not self.flagNoData |
|
151 | 151 | |
|
152 | 152 | |
|
153 | 153 | class JROData(GenericData): |
|
154 | 154 | |
|
155 | 155 | # m_BasicHeader = BasicHeader() |
|
156 | 156 | # m_ProcessingHeader = ProcessingHeader() |
|
157 | 157 | |
|
158 | 158 | systemHeaderObj = SystemHeader() |
|
159 | 159 | radarControllerHeaderObj = RadarControllerHeader() |
|
160 | 160 | # data = None |
|
161 | 161 | type = None |
|
162 | 162 | datatype = None # dtype but in string |
|
163 | 163 | # dtype = None |
|
164 | 164 | # nChannels = None |
|
165 | 165 | # nHeights = None |
|
166 | 166 | nProfiles = None |
|
167 | 167 | heightList = None |
|
168 | 168 | channelList = None |
|
169 | 169 | flagDiscontinuousBlock = False |
|
170 | 170 | useLocalTime = False |
|
171 | 171 | utctime = None |
|
172 | 172 | timeZone = None |
|
173 | 173 | dstFlag = None |
|
174 | 174 | errorCount = None |
|
175 | 175 | blocksize = None |
|
176 | 176 | # nCode = None |
|
177 | 177 | # nBaud = None |
|
178 | 178 | # code = None |
|
179 | 179 | flagDecodeData = False # asumo q la data no esta decodificada |
|
180 | 180 | flagDeflipData = False # asumo q la data no esta sin flip |
|
181 | 181 | flagShiftFFT = False |
|
182 | 182 | # ippSeconds = None |
|
183 | 183 | # timeInterval = None |
|
184 | 184 | nCohInt = None |
|
185 | 185 | # noise = None |
|
186 | 186 | windowOfFilter = 1 |
|
187 | 187 | # Speed of ligth |
|
188 | 188 | C = 3e8 |
|
189 | 189 | frequency = 49.92e6 |
|
190 | 190 | realtime = False |
|
191 | 191 | beacon_heiIndexList = None |
|
192 | 192 | last_block = None |
|
193 | 193 | blocknow = None |
|
194 | 194 | azimuth = None |
|
195 | 195 | zenith = None |
|
196 | 196 | beam = Beam() |
|
197 | 197 | profileIndex = None |
|
198 | 198 | error = None |
|
199 | 199 | data = None |
|
200 | 200 | nmodes = None |
|
201 | 201 | |
|
202 | 202 | def __str__(self): |
|
203 | 203 | |
|
204 | 204 | return '{} - {}'.format(self.type, self.getDatatime()) |
|
205 | 205 | |
|
206 | 206 | def getNoise(self): |
|
207 | 207 | |
|
208 | 208 | raise NotImplementedError |
|
209 | 209 | |
|
210 | 210 | def getNChannels(self): |
|
211 | 211 | |
|
212 | 212 | return len(self.channelList) |
|
213 | 213 | |
|
214 | 214 | def getChannelIndexList(self): |
|
215 | 215 | |
|
216 | 216 | return list(range(self.nChannels)) |
|
217 | 217 | |
|
218 | 218 | def getNHeights(self): |
|
219 | 219 | |
|
220 | 220 | return len(self.heightList) |
|
221 | 221 | |
|
222 | 222 | def getHeiRange(self, extrapoints=0): |
|
223 | 223 | |
|
224 | 224 | heis = self.heightList |
|
225 | 225 | # deltah = self.heightList[1] - self.heightList[0] |
|
226 | 226 | # |
|
227 | 227 | # heis.append(self.heightList[-1]) |
|
228 | 228 | |
|
229 | 229 | return heis |
|
230 | 230 | |
|
231 | 231 | def getDeltaH(self): |
|
232 | 232 | |
|
233 | 233 | delta = self.heightList[1] - self.heightList[0] |
|
234 | 234 | |
|
235 | 235 | return delta |
|
236 | 236 | |
|
237 | 237 | def getltctime(self): |
|
238 | 238 | |
|
239 | 239 | if self.useLocalTime: |
|
240 | 240 | return self.utctime - self.timeZone * 60 |
|
241 | 241 | |
|
242 | 242 | return self.utctime |
|
243 | 243 | |
|
244 | 244 | def getDatatime(self): |
|
245 | 245 | |
|
246 | 246 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
247 | 247 | return datatimeValue |
|
248 | 248 | |
|
249 | 249 | def getTimeRange(self): |
|
250 | 250 | |
|
251 | 251 | datatime = [] |
|
252 | 252 | |
|
253 | 253 | datatime.append(self.ltctime) |
|
254 | 254 | datatime.append(self.ltctime + self.timeInterval + 1) |
|
255 | 255 | |
|
256 | 256 | datatime = numpy.array(datatime) |
|
257 | 257 | |
|
258 | 258 | return datatime |
|
259 | 259 | |
|
260 | 260 | def getFmaxTimeResponse(self): |
|
261 | 261 | |
|
262 | 262 | period = (10**-6) * self.getDeltaH() / (0.15) |
|
263 | 263 | |
|
264 | 264 | PRF = 1. / (period * self.nCohInt) |
|
265 | 265 | |
|
266 | 266 | fmax = PRF |
|
267 | 267 | |
|
268 | 268 | return fmax |
|
269 | 269 | |
|
270 | 270 | def getFmax(self): |
|
271 | 271 | PRF = 1. / (self.ippSeconds * self.nCohInt) |
|
272 | 272 | |
|
273 | 273 | fmax = PRF |
|
274 | 274 | return fmax |
|
275 | 275 | |
|
276 | 276 | def getVmax(self): |
|
277 | 277 | |
|
278 | 278 | _lambda = self.C / self.frequency |
|
279 | 279 | |
|
280 | 280 | vmax = self.getFmax() * _lambda / 2 |
|
281 | 281 | |
|
282 | 282 | return vmax |
|
283 | 283 | |
|
284 | 284 | def get_ippSeconds(self): |
|
285 | 285 | ''' |
|
286 | 286 | ''' |
|
287 | 287 | return self.radarControllerHeaderObj.ippSeconds |
|
288 | 288 | |
|
289 | 289 | def set_ippSeconds(self, ippSeconds): |
|
290 | 290 | ''' |
|
291 | 291 | ''' |
|
292 | 292 | |
|
293 | 293 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
294 | 294 | |
|
295 | 295 | return |
|
296 | 296 | |
|
297 | 297 | def get_dtype(self): |
|
298 | 298 | ''' |
|
299 | 299 | ''' |
|
300 | 300 | return getNumpyDtype(self.datatype) |
|
301 | 301 | |
|
302 | 302 | def set_dtype(self, numpyDtype): |
|
303 | 303 | ''' |
|
304 | 304 | ''' |
|
305 | 305 | |
|
306 | 306 | self.datatype = getDataTypeCode(numpyDtype) |
|
307 | 307 | |
|
308 | 308 | def get_code(self): |
|
309 | 309 | ''' |
|
310 | 310 | ''' |
|
311 | 311 | return self.radarControllerHeaderObj.code |
|
312 | 312 | |
|
313 | 313 | def set_code(self, code): |
|
314 | 314 | ''' |
|
315 | 315 | ''' |
|
316 | 316 | self.radarControllerHeaderObj.code = code |
|
317 | 317 | |
|
318 | 318 | return |
|
319 | 319 | |
|
320 | 320 | def get_ncode(self): |
|
321 | 321 | ''' |
|
322 | 322 | ''' |
|
323 | 323 | return self.radarControllerHeaderObj.nCode |
|
324 | 324 | |
|
325 | 325 | def set_ncode(self, nCode): |
|
326 | 326 | ''' |
|
327 | 327 | ''' |
|
328 | 328 | self.radarControllerHeaderObj.nCode = nCode |
|
329 | 329 | |
|
330 | 330 | return |
|
331 | 331 | |
|
332 | 332 | def get_nbaud(self): |
|
333 | 333 | ''' |
|
334 | 334 | ''' |
|
335 | 335 | return self.radarControllerHeaderObj.nBaud |
|
336 | 336 | |
|
337 | 337 | def set_nbaud(self, nBaud): |
|
338 | 338 | ''' |
|
339 | 339 | ''' |
|
340 | 340 | self.radarControllerHeaderObj.nBaud = nBaud |
|
341 | 341 | |
|
342 | 342 | return |
|
343 | 343 | |
|
344 | 344 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
345 | 345 | channelIndexList = property( |
|
346 | 346 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
347 | 347 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
348 | 348 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
349 | 349 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
350 | 350 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
351 | 351 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
352 | 352 | dtype = property(get_dtype, set_dtype) |
|
353 | 353 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
354 | 354 | code = property(get_code, set_code) |
|
355 | 355 | nCode = property(get_ncode, set_ncode) |
|
356 | 356 | nBaud = property(get_nbaud, set_nbaud) |
|
357 | 357 | |
|
358 | 358 | |
|
359 | 359 | class Voltage(JROData): |
|
360 | 360 | |
|
361 | 361 | # data es un numpy array de 2 dmensiones (canales, alturas) |
|
362 | 362 | data = None |
|
363 |
data |
|
|
364 |
data |
|
|
365 |
data |
|
|
363 | dataPP_POW = None | |
|
364 | dataPP_DOP = None | |
|
365 | dataPP_WIDTH = None | |
|
366 | dataPP_SNR = None | |
|
367 | ||
|
366 | 368 | def __init__(self): |
|
367 | 369 | ''' |
|
368 | 370 | Constructor |
|
369 | 371 | ''' |
|
370 | 372 | |
|
371 | 373 | self.useLocalTime = True |
|
372 | 374 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
373 | 375 | self.systemHeaderObj = SystemHeader() |
|
374 | 376 | self.type = "Voltage" |
|
375 | 377 | self.data = None |
|
376 | 378 | # self.dtype = None |
|
377 | 379 | # self.nChannels = 0 |
|
378 | 380 | # self.nHeights = 0 |
|
379 | 381 | self.nProfiles = None |
|
380 | 382 | self.heightList = None |
|
381 | 383 | self.channelList = None |
|
382 | 384 | # self.channelIndexList = None |
|
383 | 385 | self.flagNoData = True |
|
384 | 386 | self.flagDiscontinuousBlock = False |
|
385 | 387 | self.utctime = None |
|
386 | 388 | self.timeZone = None |
|
387 | 389 | self.dstFlag = None |
|
388 | 390 | self.errorCount = None |
|
389 | 391 | self.nCohInt = None |
|
390 | 392 | self.blocksize = None |
|
391 | 393 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
392 | 394 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
393 | 395 | self.flagShiftFFT = False |
|
394 | 396 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil |
|
395 | 397 | self.profileIndex = 0 |
|
396 | 398 | |
|
397 | 399 | def getNoisebyHildebrand(self, channel=None): |
|
398 | 400 | """ |
|
399 | 401 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
400 | 402 | |
|
401 | 403 | Return: |
|
402 | 404 | noiselevel |
|
403 | 405 | """ |
|
404 | 406 | |
|
405 | 407 | if channel != None: |
|
406 | 408 | data = self.data[channel] |
|
407 | 409 | nChannels = 1 |
|
408 | 410 | else: |
|
409 | 411 | data = self.data |
|
410 | 412 | nChannels = self.nChannels |
|
411 | 413 | |
|
412 | 414 | noise = numpy.zeros(nChannels) |
|
413 | 415 | power = data * numpy.conjugate(data) |
|
414 | 416 | |
|
415 | 417 | for thisChannel in range(nChannels): |
|
416 | 418 | if nChannels == 1: |
|
417 | 419 | daux = power[:].real |
|
418 | 420 | else: |
|
419 | 421 | daux = power[thisChannel, :].real |
|
420 | 422 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
421 | 423 | |
|
422 | 424 | return noise |
|
423 | 425 | |
|
426 | def getNoisebyHildebrandDC(self, channel=None,DC=0): | |
|
427 | """ | |
|
428 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
|
429 | ||
|
430 | Return: | |
|
431 | noiselevel | |
|
432 | """ | |
|
433 | ||
|
434 | if channel != None: | |
|
435 | data = self.data[channel]-DC | |
|
436 | nChannels = 1 | |
|
437 | else: | |
|
438 | data = self.data | |
|
439 | nChannels = self.nChannels | |
|
440 | ||
|
441 | noise = numpy.zeros(nChannels) | |
|
442 | power = data * numpy.conjugate(data) | |
|
443 | ||
|
444 | for thisChannel in range(nChannels): | |
|
445 | if nChannels == 1: | |
|
446 | daux = power[:].real | |
|
447 | else: | |
|
448 | daux = power[thisChannel, :].real | |
|
449 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
|
450 | ||
|
451 | return noise | |
|
452 | ||
|
453 | ||
|
454 | ||
|
424 | 455 | def getNoise(self, type=1, channel=None): |
|
425 | 456 | |
|
426 | 457 | if type == 1: |
|
427 | 458 | noise = self.getNoisebyHildebrand(channel) |
|
428 | 459 | |
|
429 | 460 | return noise |
|
430 | 461 | |
|
431 | 462 | def getPower(self, channel=None): |
|
432 | 463 | |
|
433 | 464 | if channel != None: |
|
434 | 465 | data = self.data[channel] |
|
435 | 466 | else: |
|
436 | 467 | data = self.data |
|
437 | 468 | |
|
438 | 469 | power = data * numpy.conjugate(data) |
|
439 | 470 | powerdB = 10 * numpy.log10(power.real) |
|
440 | 471 | powerdB = numpy.squeeze(powerdB) |
|
441 | 472 | |
|
442 | 473 | return powerdB |
|
443 | 474 | |
|
444 | 475 | def getTimeInterval(self): |
|
445 | 476 | |
|
446 | 477 | timeInterval = self.ippSeconds * self.nCohInt |
|
447 | 478 | |
|
448 | 479 | return timeInterval |
|
449 | 480 | |
|
450 | 481 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
451 | 482 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
452 | 483 | |
|
453 | 484 | |
|
454 | 485 | class Spectra(JROData): |
|
455 | 486 | |
|
456 | 487 | # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
457 | 488 | data_spc = None |
|
458 | 489 | # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
459 | 490 | data_cspc = None |
|
460 | 491 | # data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
461 | 492 | data_dc = None |
|
462 | 493 | # data power |
|
463 | 494 | data_pwr = None |
|
464 | 495 | nFFTPoints = None |
|
465 | 496 | # nPairs = None |
|
466 | 497 | pairsList = None |
|
467 | 498 | nIncohInt = None |
|
468 | 499 | wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia |
|
469 | 500 | nCohInt = None # se requiere para determinar el valor de timeInterval |
|
470 | 501 | ippFactor = None |
|
471 | 502 | profileIndex = 0 |
|
472 | 503 | plotting = "spectra" |
|
473 | 504 | |
|
474 | 505 | def __init__(self): |
|
475 | 506 | ''' |
|
476 | 507 | Constructor |
|
477 | 508 | ''' |
|
478 | 509 | |
|
479 | 510 | self.useLocalTime = True |
|
480 | 511 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
481 | 512 | self.systemHeaderObj = SystemHeader() |
|
482 | 513 | self.type = "Spectra" |
|
483 | 514 | # self.data = None |
|
484 | 515 | # self.dtype = None |
|
485 | 516 | # self.nChannels = 0 |
|
486 | 517 | # self.nHeights = 0 |
|
487 | 518 | self.nProfiles = None |
|
488 | 519 | self.heightList = None |
|
489 | 520 | self.channelList = None |
|
490 | 521 | # self.channelIndexList = None |
|
491 | 522 | self.pairsList = None |
|
492 | 523 | self.flagNoData = True |
|
493 | 524 | self.flagDiscontinuousBlock = False |
|
494 | 525 | self.utctime = None |
|
495 | 526 | self.nCohInt = None |
|
496 | 527 | self.nIncohInt = None |
|
497 | 528 | self.blocksize = None |
|
498 | 529 | self.nFFTPoints = None |
|
499 | 530 | self.wavelength = None |
|
500 | 531 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
501 | 532 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
502 | 533 | self.flagShiftFFT = False |
|
503 | 534 | self.ippFactor = 1 |
|
504 | 535 | #self.noise = None |
|
505 | 536 | self.beacon_heiIndexList = [] |
|
506 | 537 | self.noise_estimation = None |
|
507 | 538 | |
|
508 | 539 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
509 | 540 | """ |
|
510 | 541 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
511 | 542 | |
|
512 | 543 | Return: |
|
513 | 544 | noiselevel |
|
514 | 545 | """ |
|
515 | 546 | |
|
516 | 547 | noise = numpy.zeros(self.nChannels) |
|
517 | 548 | |
|
518 | 549 | for channel in range(self.nChannels): |
|
519 | 550 | daux = self.data_spc[channel, |
|
520 | 551 | xmin_index:xmax_index, ymin_index:ymax_index] |
|
521 | 552 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
522 | 553 | |
|
523 | 554 | return noise |
|
524 | 555 | |
|
525 | 556 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
526 | 557 | |
|
527 | 558 | if self.noise_estimation is not None: |
|
528 | 559 | # this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
529 | 560 | return self.noise_estimation |
|
530 | 561 | else: |
|
531 | 562 | noise = self.getNoisebyHildebrand( |
|
532 | 563 | xmin_index, xmax_index, ymin_index, ymax_index) |
|
533 | 564 | return noise |
|
534 | 565 | |
|
535 | 566 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
536 | 567 | |
|
537 | 568 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) |
|
538 | 569 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2 |
|
539 | 570 | |
|
540 | 571 | return freqrange |
|
541 | 572 | |
|
542 | 573 | def getAcfRange(self, extrapoints=0): |
|
543 | 574 | |
|
544 | 575 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) |
|
545 | 576 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 |
|
546 | 577 | |
|
547 | 578 | return freqrange |
|
548 | 579 | |
|
549 | 580 | def getFreqRange(self, extrapoints=0): |
|
550 | 581 | |
|
551 | 582 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) |
|
552 | 583 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 |
|
553 | 584 | |
|
554 | 585 | return freqrange |
|
555 | 586 | |
|
556 | 587 | def getVelRange(self, extrapoints=0): |
|
557 | 588 | |
|
558 | 589 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) |
|
559 | 590 | velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) |
|
560 | 591 | |
|
561 | 592 | if self.nmodes: |
|
562 | 593 | return velrange/self.nmodes |
|
563 | 594 | else: |
|
564 | 595 | return velrange |
|
565 | 596 | |
|
566 | 597 | def getNPairs(self): |
|
567 | 598 | |
|
568 | 599 | return len(self.pairsList) |
|
569 | 600 | |
|
570 | 601 | def getPairsIndexList(self): |
|
571 | 602 | |
|
572 | 603 | return list(range(self.nPairs)) |
|
573 | 604 | |
|
574 | 605 | def getNormFactor(self): |
|
575 | 606 | |
|
576 | 607 | pwcode = 1 |
|
577 | 608 | |
|
578 | 609 | if self.flagDecodeData: |
|
579 | 610 | pwcode = numpy.sum(self.code[0]**2) |
|
580 | 611 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
581 | 612 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter |
|
582 | 613 | |
|
583 | 614 | return normFactor |
|
584 | 615 | |
|
585 | 616 | def getFlagCspc(self): |
|
586 | 617 | |
|
587 | 618 | if self.data_cspc is None: |
|
588 | 619 | return True |
|
589 | 620 | |
|
590 | 621 | return False |
|
591 | 622 | |
|
592 | 623 | def getFlagDc(self): |
|
593 | 624 | |
|
594 | 625 | if self.data_dc is None: |
|
595 | 626 | return True |
|
596 | 627 | |
|
597 | 628 | return False |
|
598 | 629 | |
|
599 | 630 | def getTimeInterval(self): |
|
600 | 631 | |
|
601 | 632 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor |
|
602 | 633 | if self.nmodes: |
|
603 | 634 | return self.nmodes*timeInterval |
|
604 | 635 | else: |
|
605 | 636 | return timeInterval |
|
606 | 637 | |
|
607 | 638 | def getPower(self): |
|
608 | 639 | |
|
609 | 640 | factor = self.normFactor |
|
610 | 641 | z = self.data_spc / factor |
|
611 | 642 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
612 | 643 | avg = numpy.average(z, axis=1) |
|
613 | 644 | |
|
614 | 645 | return 10 * numpy.log10(avg) |
|
615 | 646 | |
|
616 | 647 | def getCoherence(self, pairsList=None, phase=False): |
|
617 | 648 | |
|
618 | 649 | z = [] |
|
619 | 650 | if pairsList is None: |
|
620 | 651 | pairsIndexList = self.pairsIndexList |
|
621 | 652 | else: |
|
622 | 653 | pairsIndexList = [] |
|
623 | 654 | for pair in pairsList: |
|
624 | 655 | if pair not in self.pairsList: |
|
625 | 656 | raise ValueError("Pair %s is not in dataOut.pairsList" % ( |
|
626 | 657 | pair)) |
|
627 | 658 | pairsIndexList.append(self.pairsList.index(pair)) |
|
628 | 659 | for i in range(len(pairsIndexList)): |
|
629 | 660 | pair = self.pairsList[pairsIndexList[i]] |
|
630 | 661 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
631 | 662 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
632 | 663 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
633 | 664 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
634 | 665 | if phase: |
|
635 | 666 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
636 | 667 | avgcoherenceComplex.real) * 180 / numpy.pi |
|
637 | 668 | else: |
|
638 | 669 | data = numpy.abs(avgcoherenceComplex) |
|
639 | 670 | |
|
640 | 671 | z.append(data) |
|
641 | 672 | |
|
642 | 673 | return numpy.array(z) |
|
643 | 674 | |
|
644 | 675 | def setValue(self, value): |
|
645 | 676 | |
|
646 | 677 | print("This property should not be initialized") |
|
647 | 678 | |
|
648 | 679 | return |
|
649 | 680 | |
|
650 | 681 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
651 | 682 | pairsIndexList = property( |
|
652 | 683 | getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
653 | 684 | normFactor = property(getNormFactor, setValue, |
|
654 | 685 | "I'm the 'getNormFactor' property.") |
|
655 | 686 | flag_cspc = property(getFlagCspc, setValue) |
|
656 | 687 | flag_dc = property(getFlagDc, setValue) |
|
657 | 688 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
658 | 689 | timeInterval = property(getTimeInterval, setValue, |
|
659 | 690 | "I'm the 'timeInterval' property") |
|
660 | 691 | |
|
661 | 692 | |
|
662 | 693 | class SpectraHeis(Spectra): |
|
663 | 694 | |
|
664 | 695 | data_spc = None |
|
665 | 696 | data_cspc = None |
|
666 | 697 | data_dc = None |
|
667 | 698 | nFFTPoints = None |
|
668 | 699 | # nPairs = None |
|
669 | 700 | pairsList = None |
|
670 | 701 | nCohInt = None |
|
671 | 702 | nIncohInt = None |
|
672 | 703 | |
|
673 | 704 | def __init__(self): |
|
674 | 705 | |
|
675 | 706 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
676 | 707 | |
|
677 | 708 | self.systemHeaderObj = SystemHeader() |
|
678 | 709 | |
|
679 | 710 | self.type = "SpectraHeis" |
|
680 | 711 | |
|
681 | 712 | # self.dtype = None |
|
682 | 713 | |
|
683 | 714 | # self.nChannels = 0 |
|
684 | 715 | |
|
685 | 716 | # self.nHeights = 0 |
|
686 | 717 | |
|
687 | 718 | self.nProfiles = None |
|
688 | 719 | |
|
689 | 720 | self.heightList = None |
|
690 | 721 | |
|
691 | 722 | self.channelList = None |
|
692 | 723 | |
|
693 | 724 | # self.channelIndexList = None |
|
694 | 725 | |
|
695 | 726 | self.flagNoData = True |
|
696 | 727 | |
|
697 | 728 | self.flagDiscontinuousBlock = False |
|
698 | 729 | |
|
699 | 730 | # self.nPairs = 0 |
|
700 | 731 | |
|
701 | 732 | self.utctime = None |
|
702 | 733 | |
|
703 | 734 | self.blocksize = None |
|
704 | 735 | |
|
705 | 736 | self.profileIndex = 0 |
|
706 | 737 | |
|
707 | 738 | self.nCohInt = 1 |
|
708 | 739 | |
|
709 | 740 | self.nIncohInt = 1 |
|
710 | 741 | |
|
711 | 742 | def getNormFactor(self): |
|
712 | 743 | pwcode = 1 |
|
713 | 744 | if self.flagDecodeData: |
|
714 | 745 | pwcode = numpy.sum(self.code[0]**2) |
|
715 | 746 | |
|
716 | 747 | normFactor = self.nIncohInt * self.nCohInt * pwcode |
|
717 | 748 | |
|
718 | 749 | return normFactor |
|
719 | 750 | |
|
720 | 751 | def getTimeInterval(self): |
|
721 | 752 | |
|
722 | 753 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
723 | 754 | |
|
724 | 755 | return timeInterval |
|
725 | 756 | |
|
726 | 757 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
727 | 758 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
728 | 759 | |
|
729 | 760 | |
|
730 | 761 | class Fits(JROData): |
|
731 | 762 | |
|
732 | 763 | heightList = None |
|
733 | 764 | channelList = None |
|
734 | 765 | flagNoData = True |
|
735 | 766 | flagDiscontinuousBlock = False |
|
736 | 767 | useLocalTime = False |
|
737 | 768 | utctime = None |
|
738 | 769 | timeZone = None |
|
739 | 770 | # ippSeconds = None |
|
740 | 771 | # timeInterval = None |
|
741 | 772 | nCohInt = None |
|
742 | 773 | nIncohInt = None |
|
743 | 774 | noise = None |
|
744 | 775 | windowOfFilter = 1 |
|
745 | 776 | # Speed of ligth |
|
746 | 777 | C = 3e8 |
|
747 | 778 | frequency = 49.92e6 |
|
748 | 779 | realtime = False |
|
749 | 780 | |
|
750 | 781 | def __init__(self): |
|
751 | 782 | |
|
752 | 783 | self.type = "Fits" |
|
753 | 784 | |
|
754 | 785 | self.nProfiles = None |
|
755 | 786 | |
|
756 | 787 | self.heightList = None |
|
757 | 788 | |
|
758 | 789 | self.channelList = None |
|
759 | 790 | |
|
760 | 791 | # self.channelIndexList = None |
|
761 | 792 | |
|
762 | 793 | self.flagNoData = True |
|
763 | 794 | |
|
764 | 795 | self.utctime = None |
|
765 | 796 | |
|
766 | 797 | self.nCohInt = 1 |
|
767 | 798 | |
|
768 | 799 | self.nIncohInt = 1 |
|
769 | 800 | |
|
770 | 801 | self.useLocalTime = True |
|
771 | 802 | |
|
772 | 803 | self.profileIndex = 0 |
|
773 | 804 | |
|
774 | 805 | # self.utctime = None |
|
775 | 806 | # self.timeZone = None |
|
776 | 807 | # self.ltctime = None |
|
777 | 808 | # self.timeInterval = None |
|
778 | 809 | # self.header = None |
|
779 | 810 | # self.data_header = None |
|
780 | 811 | # self.data = None |
|
781 | 812 | # self.datatime = None |
|
782 | 813 | # self.flagNoData = False |
|
783 | 814 | # self.expName = '' |
|
784 | 815 | # self.nChannels = None |
|
785 | 816 | # self.nSamples = None |
|
786 | 817 | # self.dataBlocksPerFile = None |
|
787 | 818 | # self.comments = '' |
|
788 | 819 | # |
|
789 | 820 | |
|
790 | 821 | def getltctime(self): |
|
791 | 822 | |
|
792 | 823 | if self.useLocalTime: |
|
793 | 824 | return self.utctime - self.timeZone * 60 |
|
794 | 825 | |
|
795 | 826 | return self.utctime |
|
796 | 827 | |
|
797 | 828 | def getDatatime(self): |
|
798 | 829 | |
|
799 | 830 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
800 | 831 | return datatime |
|
801 | 832 | |
|
802 | 833 | def getTimeRange(self): |
|
803 | 834 | |
|
804 | 835 | datatime = [] |
|
805 | 836 | |
|
806 | 837 | datatime.append(self.ltctime) |
|
807 | 838 | datatime.append(self.ltctime + self.timeInterval) |
|
808 | 839 | |
|
809 | 840 | datatime = numpy.array(datatime) |
|
810 | 841 | |
|
811 | 842 | return datatime |
|
812 | 843 | |
|
813 | 844 | def getHeiRange(self): |
|
814 | 845 | |
|
815 | 846 | heis = self.heightList |
|
816 | 847 | |
|
817 | 848 | return heis |
|
818 | 849 | |
|
819 | 850 | def getNHeights(self): |
|
820 | 851 | |
|
821 | 852 | return len(self.heightList) |
|
822 | 853 | |
|
823 | 854 | def getNChannels(self): |
|
824 | 855 | |
|
825 | 856 | return len(self.channelList) |
|
826 | 857 | |
|
827 | 858 | def getChannelIndexList(self): |
|
828 | 859 | |
|
829 | 860 | return list(range(self.nChannels)) |
|
830 | 861 | |
|
831 | 862 | def getNoise(self, type=1): |
|
832 | 863 | |
|
833 | 864 | #noise = numpy.zeros(self.nChannels) |
|
834 | 865 | |
|
835 | 866 | if type == 1: |
|
836 | 867 | noise = self.getNoisebyHildebrand() |
|
837 | 868 | |
|
838 | 869 | if type == 2: |
|
839 | 870 | noise = self.getNoisebySort() |
|
840 | 871 | |
|
841 | 872 | if type == 3: |
|
842 | 873 | noise = self.getNoisebyWindow() |
|
843 | 874 | |
|
844 | 875 | return noise |
|
845 | 876 | |
|
846 | 877 | def getTimeInterval(self): |
|
847 | 878 | |
|
848 | 879 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
849 | 880 | |
|
850 | 881 | return timeInterval |
|
851 | 882 | |
|
852 | 883 | def get_ippSeconds(self): |
|
853 | 884 | ''' |
|
854 | 885 | ''' |
|
855 | 886 | return self.ipp_sec |
|
856 | 887 | |
|
857 | 888 | |
|
858 | 889 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
859 | 890 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
860 | 891 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
861 | 892 | channelIndexList = property( |
|
862 | 893 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
863 | 894 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
864 | 895 | |
|
865 | 896 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
866 | 897 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
867 | 898 | ippSeconds = property(get_ippSeconds, '') |
|
868 | 899 | |
|
869 | 900 | class Correlation(JROData): |
|
870 | 901 | |
|
871 | 902 | noise = None |
|
872 | 903 | SNR = None |
|
873 | 904 | #-------------------------------------------------- |
|
874 | 905 | mode = None |
|
875 | 906 | split = False |
|
876 | 907 | data_cf = None |
|
877 | 908 | lags = None |
|
878 | 909 | lagRange = None |
|
879 | 910 | pairsList = None |
|
880 | 911 | normFactor = None |
|
881 | 912 | #-------------------------------------------------- |
|
882 | 913 | # calculateVelocity = None |
|
883 | 914 | nLags = None |
|
884 | 915 | nPairs = None |
|
885 | 916 | nAvg = None |
|
886 | 917 | |
|
887 | 918 | def __init__(self): |
|
888 | 919 | ''' |
|
889 | 920 | Constructor |
|
890 | 921 | ''' |
|
891 | 922 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
892 | 923 | |
|
893 | 924 | self.systemHeaderObj = SystemHeader() |
|
894 | 925 | |
|
895 | 926 | self.type = "Correlation" |
|
896 | 927 | |
|
897 | 928 | self.data = None |
|
898 | 929 | |
|
899 | 930 | self.dtype = None |
|
900 | 931 | |
|
901 | 932 | self.nProfiles = None |
|
902 | 933 | |
|
903 | 934 | self.heightList = None |
|
904 | 935 | |
|
905 | 936 | self.channelList = None |
|
906 | 937 | |
|
907 | 938 | self.flagNoData = True |
|
908 | 939 | |
|
909 | 940 | self.flagDiscontinuousBlock = False |
|
910 | 941 | |
|
911 | 942 | self.utctime = None |
|
912 | 943 | |
|
913 | 944 | self.timeZone = None |
|
914 | 945 | |
|
915 | 946 | self.dstFlag = None |
|
916 | 947 | |
|
917 | 948 | self.errorCount = None |
|
918 | 949 | |
|
919 | 950 | self.blocksize = None |
|
920 | 951 | |
|
921 | 952 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
922 | 953 | |
|
923 | 954 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
924 | 955 | |
|
925 | 956 | self.pairsList = None |
|
926 | 957 | |
|
927 | 958 | self.nPoints = None |
|
928 | 959 | |
|
929 | 960 | def getPairsList(self): |
|
930 | 961 | |
|
931 | 962 | return self.pairsList |
|
932 | 963 | |
|
933 | 964 | def getNoise(self, mode=2): |
|
934 | 965 | |
|
935 | 966 | indR = numpy.where(self.lagR == 0)[0][0] |
|
936 | 967 | indT = numpy.where(self.lagT == 0)[0][0] |
|
937 | 968 | |
|
938 | 969 | jspectra0 = self.data_corr[:, :, indR, :] |
|
939 | 970 | jspectra = copy.copy(jspectra0) |
|
940 | 971 | |
|
941 | 972 | num_chan = jspectra.shape[0] |
|
942 | 973 | num_hei = jspectra.shape[2] |
|
943 | 974 | |
|
944 | 975 | freq_dc = jspectra.shape[1] / 2 |
|
945 | 976 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
946 | 977 | |
|
947 | 978 | if ind_vel[0] < 0: |
|
948 | 979 | ind_vel[list(range(0, 1))] = ind_vel[list( |
|
949 | 980 | range(0, 1))] + self.num_prof |
|
950 | 981 | |
|
951 | 982 | if mode == 1: |
|
952 | 983 | jspectra[:, freq_dc, :] = ( |
|
953 | 984 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
954 | 985 | |
|
955 | 986 | if mode == 2: |
|
956 | 987 | |
|
957 | 988 | vel = numpy.array([-2, -1, 1, 2]) |
|
958 | 989 | xx = numpy.zeros([4, 4]) |
|
959 | 990 | |
|
960 | 991 | for fil in range(4): |
|
961 | 992 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
962 | 993 | |
|
963 | 994 | xx_inv = numpy.linalg.inv(xx) |
|
964 | 995 | xx_aux = xx_inv[0, :] |
|
965 | 996 | |
|
966 | 997 | for ich in range(num_chan): |
|
967 | 998 | yy = jspectra[ich, ind_vel, :] |
|
968 | 999 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
969 | 1000 | |
|
970 | 1001 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
971 | 1002 | cjunkid = sum(junkid) |
|
972 | 1003 | |
|
973 | 1004 | if cjunkid.any(): |
|
974 | 1005 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
975 | 1006 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
976 | 1007 | |
|
977 | 1008 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] |
|
978 | 1009 | |
|
979 | 1010 | return noise |
|
980 | 1011 | |
|
981 | 1012 | def getTimeInterval(self): |
|
982 | 1013 | |
|
983 | 1014 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
984 | 1015 | |
|
985 | 1016 | return timeInterval |
|
986 | 1017 | |
|
987 | 1018 | def splitFunctions(self): |
|
988 | 1019 | |
|
989 | 1020 | pairsList = self.pairsList |
|
990 | 1021 | ccf_pairs = [] |
|
991 | 1022 | acf_pairs = [] |
|
992 | 1023 | ccf_ind = [] |
|
993 | 1024 | acf_ind = [] |
|
994 | 1025 | for l in range(len(pairsList)): |
|
995 | 1026 | chan0 = pairsList[l][0] |
|
996 | 1027 | chan1 = pairsList[l][1] |
|
997 | 1028 | |
|
998 | 1029 | # Obteniendo pares de Autocorrelacion |
|
999 | 1030 | if chan0 == chan1: |
|
1000 | 1031 | acf_pairs.append(chan0) |
|
1001 | 1032 | acf_ind.append(l) |
|
1002 | 1033 | else: |
|
1003 | 1034 | ccf_pairs.append(pairsList[l]) |
|
1004 | 1035 | ccf_ind.append(l) |
|
1005 | 1036 | |
|
1006 | 1037 | data_acf = self.data_cf[acf_ind] |
|
1007 | 1038 | data_ccf = self.data_cf[ccf_ind] |
|
1008 | 1039 | |
|
1009 | 1040 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1010 | 1041 | |
|
1011 | 1042 | def getNormFactor(self): |
|
1012 | 1043 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1013 | 1044 | acf_pairs = numpy.array(acf_pairs) |
|
1014 | 1045 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) |
|
1015 | 1046 | |
|
1016 | 1047 | for p in range(self.nPairs): |
|
1017 | 1048 | pair = self.pairsList[p] |
|
1018 | 1049 | |
|
1019 | 1050 | ch0 = pair[0] |
|
1020 | 1051 | ch1 = pair[1] |
|
1021 | 1052 | |
|
1022 | 1053 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) |
|
1023 | 1054 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) |
|
1024 | 1055 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) |
|
1025 | 1056 | |
|
1026 | 1057 | return normFactor |
|
1027 | 1058 | |
|
1028 | 1059 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1029 | 1060 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1030 | 1061 | |
|
1031 | 1062 | |
|
1032 | 1063 | class Parameters(Spectra): |
|
1033 | 1064 | |
|
1034 | 1065 | experimentInfo = None # Information about the experiment |
|
1035 | 1066 | # Information from previous data |
|
1036 | 1067 | inputUnit = None # Type of data to be processed |
|
1037 | 1068 | operation = None # Type of operation to parametrize |
|
1038 | 1069 | # normFactor = None #Normalization Factor |
|
1039 | 1070 | groupList = None # List of Pairs, Groups, etc |
|
1040 | 1071 | # Parameters |
|
1041 | 1072 | data_param = None # Parameters obtained |
|
1042 | 1073 | data_pre = None # Data Pre Parametrization |
|
1043 | 1074 | data_SNR = None # Signal to Noise Ratio |
|
1044 | 1075 | # heightRange = None #Heights |
|
1045 | 1076 | abscissaList = None # Abscissa, can be velocities, lags or time |
|
1046 | 1077 | # noise = None #Noise Potency |
|
1047 | 1078 | utctimeInit = None # Initial UTC time |
|
1048 | 1079 | paramInterval = None # Time interval to calculate Parameters in seconds |
|
1049 | 1080 | useLocalTime = True |
|
1050 | 1081 | # Fitting |
|
1051 | 1082 | data_error = None # Error of the estimation |
|
1052 | 1083 | constants = None |
|
1053 | 1084 | library = None |
|
1054 | 1085 | # Output signal |
|
1055 | 1086 | outputInterval = None # Time interval to calculate output signal in seconds |
|
1056 | 1087 | data_output = None # Out signal |
|
1057 | 1088 | nAvg = None |
|
1058 | 1089 | noise_estimation = None |
|
1059 | 1090 | GauSPC = None # Fit gaussian SPC |
|
1060 | 1091 | |
|
1061 | 1092 | def __init__(self): |
|
1062 | 1093 | ''' |
|
1063 | 1094 | Constructor |
|
1064 | 1095 | ''' |
|
1065 | 1096 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1066 | 1097 | |
|
1067 | 1098 | self.systemHeaderObj = SystemHeader() |
|
1068 | 1099 | |
|
1069 | 1100 | self.type = "Parameters" |
|
1070 | 1101 | |
|
1071 | 1102 | def getTimeRange1(self, interval): |
|
1072 | 1103 | |
|
1073 | 1104 | datatime = [] |
|
1074 | 1105 | |
|
1075 | 1106 | if self.useLocalTime: |
|
1076 | 1107 | time1 = self.utctimeInit - self.timeZone * 60 |
|
1077 | 1108 | else: |
|
1078 | 1109 | time1 = self.utctimeInit |
|
1079 | 1110 | |
|
1080 | 1111 | datatime.append(time1) |
|
1081 | 1112 | datatime.append(time1 + interval) |
|
1082 | 1113 | datatime = numpy.array(datatime) |
|
1083 | 1114 | |
|
1084 | 1115 | return datatime |
|
1085 | 1116 | |
|
1086 | 1117 | def getTimeInterval(self): |
|
1087 | 1118 | |
|
1088 | 1119 | if hasattr(self, 'timeInterval1'): |
|
1089 | 1120 | return self.timeInterval1 |
|
1090 | 1121 | else: |
|
1091 | 1122 | return self.paramInterval |
|
1092 | 1123 | |
|
1093 | 1124 | def setValue(self, value): |
|
1094 | 1125 | |
|
1095 | 1126 | print("This property should not be initialized") |
|
1096 | 1127 | |
|
1097 | 1128 | return |
|
1098 | 1129 | |
|
1099 | 1130 | def getNoise(self): |
|
1100 | 1131 | |
|
1101 | 1132 | return self.spc_noise |
|
1102 | 1133 | |
|
1103 | 1134 | timeInterval = property(getTimeInterval) |
|
1104 | 1135 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") |
|
1105 | 1136 | |
|
1106 | 1137 | |
|
1107 | 1138 | class PlotterData(object): |
|
1108 | 1139 | ''' |
|
1109 | 1140 | Object to hold data to be plotted |
|
1110 | 1141 | ''' |
|
1111 | 1142 | |
|
1112 | 1143 | MAXNUMX = 200 |
|
1113 | 1144 | MAXNUMY = 200 |
|
1114 | 1145 | |
|
1115 | 1146 | def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False): |
|
1116 | 1147 | |
|
1117 | 1148 | self.key = code |
|
1118 | 1149 | self.throttle = throttle_value |
|
1119 | 1150 | self.exp_code = exp_code |
|
1120 | 1151 | self.buffering = buffering |
|
1121 | 1152 | self.ready = False |
|
1122 | 1153 | self.flagNoData = False |
|
1123 | 1154 | self.localtime = False |
|
1124 | 1155 | self.data = {} |
|
1125 | 1156 | self.meta = {} |
|
1126 | 1157 | self.__times = [] |
|
1127 | 1158 | self.__heights = [] |
|
1128 | 1159 | |
|
1129 | 1160 | if 'snr' in code: |
|
1130 | 1161 | self.plottypes = ['snr'] |
|
1131 | 1162 | elif code == 'spc': |
|
1132 | 1163 | self.plottypes = ['spc', 'noise', 'rti'] |
|
1133 | 1164 | elif code == 'rti': |
|
1134 | 1165 | self.plottypes = ['noise', 'rti'] |
|
1135 | 1166 | else: |
|
1136 | 1167 | self.plottypes = [code] |
|
1137 | 1168 | |
|
1138 | 1169 | if 'snr' not in self.plottypes and snr: |
|
1139 | 1170 | self.plottypes.append('snr') |
|
1140 | 1171 | |
|
1141 | 1172 | for plot in self.plottypes: |
|
1142 | 1173 | self.data[plot] = {} |
|
1143 | 1174 | |
|
1144 | 1175 | |
|
1145 | 1176 | def __str__(self): |
|
1146 | 1177 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] |
|
1147 | 1178 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) |
|
1148 | 1179 | |
|
1149 | 1180 | def __len__(self): |
|
1150 | 1181 | return len(self.__times) |
|
1151 | 1182 | |
|
1152 | 1183 | def __getitem__(self, key): |
|
1153 | 1184 | |
|
1154 | 1185 | if key not in self.data: |
|
1155 | 1186 | raise KeyError(log.error('Missing key: {}'.format(key))) |
|
1156 | 1187 | if 'spc' in key or not self.buffering: |
|
1157 | 1188 | ret = self.data[key] |
|
1158 | 1189 | elif 'scope' in key: |
|
1159 | 1190 | ret = numpy.array(self.data[key][float(self.tm)]) |
|
1160 | 1191 | else: |
|
1161 | 1192 | ret = numpy.array([self.data[key][x] for x in self.times]) |
|
1162 | 1193 | if ret.ndim > 1: |
|
1163 | 1194 | ret = numpy.swapaxes(ret, 0, 1) |
|
1164 | 1195 | return ret |
|
1165 | 1196 | |
|
1166 | 1197 | def __contains__(self, key): |
|
1167 | 1198 | return key in self.data |
|
1168 | 1199 | |
|
1169 | 1200 | def setup(self): |
|
1170 | 1201 | ''' |
|
1171 | 1202 | Configure object |
|
1172 | 1203 | ''' |
|
1173 | 1204 | self.type = '' |
|
1174 | 1205 | self.ready = False |
|
1175 | 1206 | self.data = {} |
|
1176 | 1207 | self.__times = [] |
|
1177 | 1208 | self.__heights = [] |
|
1178 | 1209 | self.__all_heights = set() |
|
1179 | 1210 | for plot in self.plottypes: |
|
1180 | 1211 | if 'snr' in plot: |
|
1181 | 1212 | plot = 'snr' |
|
1182 | 1213 | elif 'spc_moments' == plot: |
|
1183 | 1214 | plot = 'moments' |
|
1184 | 1215 | self.data[plot] = {} |
|
1185 | 1216 | |
|
1186 | 1217 | if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data: |
|
1187 | 1218 | self.data['noise'] = {} |
|
1188 | 1219 | self.data['rti'] = {} |
|
1189 | 1220 | if 'noise' not in self.plottypes: |
|
1190 | 1221 | self.plottypes.append('noise') |
|
1191 | 1222 | if 'rti' not in self.plottypes: |
|
1192 | 1223 | self.plottypes.append('rti') |
|
1193 | 1224 | |
|
1194 | 1225 | def shape(self, key): |
|
1195 | 1226 | ''' |
|
1196 | 1227 | Get the shape of the one-element data for the given key |
|
1197 | 1228 | ''' |
|
1198 | 1229 | |
|
1199 | 1230 | if len(self.data[key]): |
|
1200 | 1231 | if 'spc' in key or not self.buffering: |
|
1201 | 1232 | return self.data[key].shape |
|
1202 | 1233 | return self.data[key][self.__times[0]].shape |
|
1203 | 1234 | return (0,) |
|
1204 | 1235 | |
|
1205 | 1236 | def update(self, dataOut, tm): |
|
1206 | 1237 | ''' |
|
1207 | 1238 | Update data object with new dataOut |
|
1208 | 1239 | ''' |
|
1209 | 1240 | if tm in self.__times: |
|
1210 | 1241 | return |
|
1211 | 1242 | self.profileIndex = dataOut.profileIndex |
|
1212 | 1243 | self.tm = tm |
|
1213 | 1244 | self.type = dataOut.type |
|
1214 | 1245 | self.parameters = getattr(dataOut, 'parameters', []) |
|
1215 | 1246 | |
|
1216 | 1247 | if hasattr(dataOut, 'meta'): |
|
1217 | 1248 | self.meta.update(dataOut.meta) |
|
1218 | 1249 | |
|
1219 | 1250 | if hasattr(dataOut, 'pairsList'): |
|
1220 | 1251 | self.pairs = dataOut.pairsList |
|
1221 | 1252 | |
|
1222 | 1253 | self.interval = dataOut.getTimeInterval() |
|
1223 | 1254 | self.localtime = dataOut.useLocalTime |
|
1224 | 1255 | if True in ['spc' in ptype for ptype in self.plottypes]: |
|
1225 | 1256 | self.xrange = (dataOut.getFreqRange(1)/1000., |
|
1226 | 1257 | dataOut.getAcfRange(1), dataOut.getVelRange(1)) |
|
1227 | 1258 | self.factor = dataOut.normFactor |
|
1228 | 1259 | self.__heights.append(dataOut.heightList) |
|
1229 | 1260 | self.__all_heights.update(dataOut.heightList) |
|
1230 | 1261 | self.__times.append(tm) |
|
1231 | 1262 | for plot in self.plottypes: |
|
1232 | 1263 | if plot in ('spc', 'spc_moments', 'spc_cut'): |
|
1233 | 1264 | z = dataOut.data_spc/dataOut.normFactor |
|
1234 | 1265 | buffer = 10*numpy.log10(z) |
|
1235 | 1266 | if plot == 'cspc': |
|
1236 | 1267 | z = dataOut.data_spc/dataOut.normFactor |
|
1237 | 1268 | buffer = (dataOut.data_spc, dataOut.data_cspc) |
|
1238 | 1269 | if plot == 'noise': |
|
1239 | 1270 | buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) |
|
1240 | 1271 | if plot in ('rti', 'spcprofile'): |
|
1241 | 1272 | buffer = dataOut.getPower() |
|
1242 | 1273 | if plot == 'snr_db': |
|
1243 | 1274 | buffer = dataOut.data_SNR |
|
1244 | 1275 | if plot == 'snr': |
|
1245 | 1276 | buffer = 10*numpy.log10(dataOut.data_SNR) |
|
1246 | 1277 | if plot == 'dop': |
|
1247 | 1278 | buffer = dataOut.data_DOP |
|
1248 | 1279 | if plot == 'pow': |
|
1249 | 1280 | buffer = 10*numpy.log10(dataOut.data_POW) |
|
1250 | 1281 | if plot == 'width': |
|
1251 | 1282 | buffer = dataOut.data_WIDTH |
|
1252 | 1283 | if plot == 'coh': |
|
1253 | 1284 | buffer = dataOut.getCoherence() |
|
1254 | 1285 | if plot == 'phase': |
|
1255 | 1286 | buffer = dataOut.getCoherence(phase=True) |
|
1256 | 1287 | if plot == 'output': |
|
1257 | 1288 | buffer = dataOut.data_output |
|
1258 | 1289 | if plot == 'param': |
|
1259 | 1290 | buffer = dataOut.data_param |
|
1260 | 1291 | if plot == 'scope': |
|
1261 | 1292 | buffer = dataOut.data |
|
1262 | 1293 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
1263 | 1294 | self.nProfiles = dataOut.nProfiles |
|
1264 | 1295 | if plot == 'pp_power': |
|
1265 |
buffer = dataOut.data |
|
|
1296 | buffer = dataOut.dataPP_POWER | |
|
1297 | self.flagDataAsBlock = dataOut.flagDataAsBlock | |
|
1298 | self.nProfiles = dataOut.nProfiles | |
|
1299 | if plot == 'pp_signal': | |
|
1300 | buffer = dataOut.dataPP_POW | |
|
1266 | 1301 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
1267 | 1302 | self.nProfiles = dataOut.nProfiles |
|
1268 | 1303 | if plot == 'pp_velocity': |
|
1269 |
buffer = dataOut.data |
|
|
1304 | buffer = dataOut.dataPP_DOP | |
|
1270 | 1305 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
1271 | 1306 | self.nProfiles = dataOut.nProfiles |
|
1272 | 1307 | if plot == 'pp_specwidth': |
|
1273 |
buffer = dataOut.data |
|
|
1308 | buffer = dataOut.dataPP_WIDTH | |
|
1274 | 1309 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
1275 | 1310 | self.nProfiles = dataOut.nProfiles |
|
1276 | 1311 | |
|
1277 | 1312 | if plot == 'spc': |
|
1278 | 1313 | self.data['spc'] = buffer |
|
1279 | 1314 | elif plot == 'cspc': |
|
1280 | 1315 | self.data['spc'] = buffer[0] |
|
1281 | 1316 | self.data['cspc'] = buffer[1] |
|
1282 | 1317 | elif plot == 'spc_moments': |
|
1283 | 1318 | self.data['spc'] = buffer |
|
1284 | 1319 | self.data['moments'][tm] = dataOut.moments |
|
1285 | 1320 | else: |
|
1286 | 1321 | if self.buffering: |
|
1287 | 1322 | self.data[plot][tm] = buffer |
|
1288 | 1323 | else: |
|
1289 | 1324 | self.data[plot] = buffer |
|
1290 | 1325 | |
|
1291 | 1326 | if dataOut.channelList is None: |
|
1292 | 1327 | self.channels = range(buffer.shape[0]) |
|
1293 | 1328 | else: |
|
1294 | 1329 | self.channels = dataOut.channelList |
|
1295 | 1330 | |
|
1296 | 1331 | if buffer is None: |
|
1297 | 1332 | self.flagNoData = True |
|
1298 | 1333 | raise schainpy.admin.SchainWarning('Attribute data_{} is empty'.format(self.key)) |
|
1299 | 1334 | |
|
1300 | 1335 | def normalize_heights(self): |
|
1301 | 1336 | ''' |
|
1302 | 1337 | Ensure same-dimension of the data for different heighList |
|
1303 | 1338 | ''' |
|
1304 | 1339 | |
|
1305 | 1340 | H = numpy.array(list(self.__all_heights)) |
|
1306 | 1341 | H.sort() |
|
1307 | 1342 | for key in self.data: |
|
1308 | 1343 | shape = self.shape(key)[:-1] + H.shape |
|
1309 | 1344 | for tm, obj in list(self.data[key].items()): |
|
1310 | 1345 | h = self.__heights[self.__times.index(tm)] |
|
1311 | 1346 | if H.size == h.size: |
|
1312 | 1347 | continue |
|
1313 | 1348 | index = numpy.where(numpy.in1d(H, h))[0] |
|
1314 | 1349 | dummy = numpy.zeros(shape) + numpy.nan |
|
1315 | 1350 | if len(shape) == 2: |
|
1316 | 1351 | dummy[:, index] = obj |
|
1317 | 1352 | else: |
|
1318 | 1353 | dummy[index] = obj |
|
1319 | 1354 | self.data[key][tm] = dummy |
|
1320 | 1355 | |
|
1321 | 1356 | self.__heights = [H for tm in self.__times] |
|
1322 | 1357 | |
|
1323 | 1358 | def jsonify(self, plot_name, plot_type, decimate=False): |
|
1324 | 1359 | ''' |
|
1325 | 1360 | Convert data to json |
|
1326 | 1361 | ''' |
|
1327 | 1362 | |
|
1328 | 1363 | tm = self.times[-1] |
|
1329 | 1364 | dy = int(self.heights.size/self.MAXNUMY) + 1 |
|
1330 | 1365 | if self.key in ('spc', 'cspc') or not self.buffering: |
|
1331 | 1366 | dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1 |
|
1332 | 1367 | data = self.roundFloats( |
|
1333 | 1368 | self.data[self.key][::, ::dx, ::dy].tolist()) |
|
1334 | 1369 | else: |
|
1335 | 1370 | if self.key is 'noise': |
|
1336 | 1371 | data = [[x] for x in self.roundFloats(self.data[self.key][tm].tolist())] |
|
1337 | 1372 | else: |
|
1338 | 1373 | data = self.roundFloats(self.data[self.key][tm][::, ::dy].tolist()) |
|
1339 | 1374 | |
|
1340 | 1375 | meta = {} |
|
1341 | 1376 | ret = { |
|
1342 | 1377 | 'plot': plot_name, |
|
1343 | 1378 | 'code': self.exp_code, |
|
1344 | 1379 | 'time': float(tm), |
|
1345 | 1380 | 'data': data, |
|
1346 | 1381 | } |
|
1347 | 1382 | meta['type'] = plot_type |
|
1348 | 1383 | meta['interval'] = float(self.interval) |
|
1349 | 1384 | meta['localtime'] = self.localtime |
|
1350 | 1385 | meta['yrange'] = self.roundFloats(self.heights[::dy].tolist()) |
|
1351 | 1386 | if 'spc' in self.data or 'cspc' in self.data: |
|
1352 | 1387 | meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) |
|
1353 | 1388 | else: |
|
1354 | 1389 | meta['xrange'] = [] |
|
1355 | 1390 | |
|
1356 | 1391 | meta.update(self.meta) |
|
1357 | 1392 | ret['metadata'] = meta |
|
1358 | 1393 | return json.dumps(ret) |
|
1359 | 1394 | |
|
1360 | 1395 | @property |
|
1361 | 1396 | def times(self): |
|
1362 | 1397 | ''' |
|
1363 | 1398 | Return the list of times of the current data |
|
1364 | 1399 | ''' |
|
1365 | 1400 | |
|
1366 | 1401 | ret = numpy.array(self.__times) |
|
1367 | 1402 | ret.sort() |
|
1368 | 1403 | return ret |
|
1369 | 1404 | |
|
1370 | 1405 | @property |
|
1371 | 1406 | def min_time(self): |
|
1372 | 1407 | ''' |
|
1373 | 1408 | Return the minimun time value |
|
1374 | 1409 | ''' |
|
1375 | 1410 | |
|
1376 | 1411 | return self.times[0] |
|
1377 | 1412 | |
|
1378 | 1413 | @property |
|
1379 | 1414 | def max_time(self): |
|
1380 | 1415 | ''' |
|
1381 | 1416 | Return the maximun time value |
|
1382 | 1417 | ''' |
|
1383 | 1418 | |
|
1384 | 1419 | return self.times[-1] |
|
1385 | 1420 | |
|
1386 | 1421 | @property |
|
1387 | 1422 | def heights(self): |
|
1388 | 1423 | ''' |
|
1389 | 1424 | Return the list of heights of the current data |
|
1390 | 1425 | ''' |
|
1391 | 1426 | |
|
1392 | 1427 | return numpy.array(self.__heights[-1]) |
|
1393 | 1428 | |
|
1394 | 1429 | @staticmethod |
|
1395 | 1430 | def roundFloats(obj): |
|
1396 | 1431 | if isinstance(obj, list): |
|
1397 | 1432 | return list(map(PlotterData.roundFloats, obj)) |
|
1398 | 1433 | elif isinstance(obj, float): |
|
1399 | 1434 | return round(obj, 2) |
@@ -1,276 +1,302 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | class ScopePlot(Plot): |
|
14 | 14 | |
|
15 | 15 | ''' |
|
16 | 16 | Plot for Scope |
|
17 | 17 | ''' |
|
18 | 18 | |
|
19 | 19 | CODE = 'scope' |
|
20 | 20 | plot_name = 'Scope' |
|
21 | 21 | plot_type = 'scatter' |
|
22 | 22 | |
|
23 | 23 | def setup(self): |
|
24 | 24 | |
|
25 | 25 | self.xaxis = 'Range (Km)' |
|
26 | 26 | self.ncols = 1 |
|
27 | 27 | self.nrows = 1 |
|
28 | 28 | self.nplots = 1 |
|
29 | 29 | self.ylabel = 'Intensity [dB]' |
|
30 | 30 | self.titles = ['Scope'] |
|
31 | 31 | self.colorbar = False |
|
32 | 32 | self.width = 6 |
|
33 | 33 | self.height = 4 |
|
34 | 34 | |
|
35 | 35 | def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
36 | 36 | |
|
37 | 37 | yreal = y[channelIndexList,:].real |
|
38 | 38 | yimag = y[channelIndexList,:].imag |
|
39 | 39 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
40 | 40 | self.xlabel = "Range (Km)" |
|
41 | 41 | self.ylabel = "Intensity - IQ" |
|
42 | 42 | |
|
43 | 43 | self.y = yreal |
|
44 | 44 | self.x = x |
|
45 | 45 | self.xmin = min(x) |
|
46 | 46 | self.xmax = max(x) |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | self.titles[0] = title |
|
50 | 50 | |
|
51 | 51 | for i,ax in enumerate(self.axes): |
|
52 | 52 | title = "Channel %d" %(i) |
|
53 | 53 | if ax.firsttime: |
|
54 | 54 | ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] |
|
55 | 55 | ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] |
|
56 | 56 | else: |
|
57 | 57 | ax.plt_r.set_data(x, yreal[i,:]) |
|
58 | 58 | ax.plt_i.set_data(x, yimag[i,:]) |
|
59 | 59 | |
|
60 | 60 | def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
61 | 61 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
62 | 62 | yreal = y.real |
|
63 | 63 | yreal = 10*numpy.log10(yreal) |
|
64 | 64 | self.y = yreal |
|
65 | 65 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
66 | 66 | self.xlabel = "Range (Km)" |
|
67 | 67 | self.ylabel = "Intensity" |
|
68 | 68 | self.xmin = min(x) |
|
69 | 69 | self.xmax = max(x) |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | self.titles[0] = title |
|
73 | 73 | |
|
74 | 74 | for i,ax in enumerate(self.axes): |
|
75 | 75 | title = "Channel %d" %(i) |
|
76 | 76 | |
|
77 | 77 | ychannel = yreal[i,:] |
|
78 | 78 | |
|
79 | 79 | if ax.firsttime: |
|
80 | 80 | ax.plt_r = ax.plot(x, ychannel)[0] |
|
81 | 81 | else: |
|
82 | 82 | #pass |
|
83 | 83 | ax.plt_r.set_data(x, ychannel) |
|
84 | 84 | |
|
85 | 85 | def plot_weatherpower(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
86 | 86 | |
|
87 | 87 | |
|
88 | 88 | y = y[channelIndexList,:] |
|
89 | 89 | yreal = y.real |
|
90 | 90 | yreal = 10*numpy.log10(yreal) |
|
91 | 91 | self.y = yreal |
|
92 | 92 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
93 | 93 | self.xlabel = "Range (Km)" |
|
94 | 94 | self.ylabel = "Intensity" |
|
95 | 95 | self.xmin = min(x) |
|
96 | 96 | self.xmax = max(x) |
|
97 | 97 | |
|
98 | 98 | self.titles[0] =title |
|
99 | 99 | for i,ax in enumerate(self.axes): |
|
100 | 100 | title = "Channel %d" %(i) |
|
101 | 101 | |
|
102 | 102 | ychannel = yreal[i,:] |
|
103 | 103 | |
|
104 | 104 | if ax.firsttime: |
|
105 | 105 | ax.plt_r = ax.plot(x, ychannel)[0] |
|
106 | 106 | else: |
|
107 | 107 | #pass |
|
108 | 108 | ax.plt_r.set_data(x, ychannel) |
|
109 | 109 | |
|
110 | 110 | def plot_weathervelocity(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
111 | 111 | |
|
112 | 112 | x = x[channelIndexList,:] |
|
113 | 113 | yreal = y |
|
114 | 114 | self.y = yreal |
|
115 | 115 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
116 | 116 | self.xlabel = "Velocity (m/s)" |
|
117 | 117 | self.ylabel = "Range (Km)" |
|
118 | 118 | self.xmin = numpy.min(x) |
|
119 | 119 | self.xmax = numpy.max(x) |
|
120 | 120 | self.titles[0] =title |
|
121 | 121 | for i,ax in enumerate(self.axes): |
|
122 | 122 | title = "Channel %d" %(i) |
|
123 | 123 | xchannel = x[i,:] |
|
124 | 124 | if ax.firsttime: |
|
125 | 125 | ax.plt_r = ax.plot(xchannel, yreal)[0] |
|
126 | 126 | else: |
|
127 | 127 | #pass |
|
128 | 128 | ax.plt_r.set_data(xchannel, yreal) |
|
129 | 129 | |
|
130 | 130 | def plot_weatherspecwidth(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
131 | 131 | |
|
132 | 132 | x = x[channelIndexList,:] |
|
133 | 133 | yreal = y |
|
134 | 134 | self.y = yreal |
|
135 | 135 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
136 | 136 | self.xlabel = "width " |
|
137 | 137 | self.ylabel = "Range (Km)" |
|
138 | 138 | self.xmin = numpy.min(x) |
|
139 | 139 | self.xmax = numpy.max(x) |
|
140 | 140 | self.titles[0] =title |
|
141 | 141 | for i,ax in enumerate(self.axes): |
|
142 | 142 | title = "Channel %d" %(i) |
|
143 | 143 | xchannel = x[i,:] |
|
144 | 144 | if ax.firsttime: |
|
145 | 145 | ax.plt_r = ax.plot(xchannel, yreal)[0] |
|
146 | 146 | else: |
|
147 | 147 | #pass |
|
148 | 148 | ax.plt_r.set_data(xchannel, yreal) |
|
149 | 149 | |
|
150 | 150 | def plot(self): |
|
151 | 151 | if self.channels: |
|
152 | 152 | channels = self.channels |
|
153 | 153 | else: |
|
154 | 154 | channels = self.data.channels |
|
155 | 155 | |
|
156 | 156 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) |
|
157 | 157 | if self.CODE == "pp_power": |
|
158 | 158 | scope = self.data['pp_power'] |
|
159 | elif self.CODE == "pp_signal": | |
|
160 | scope = self.data["pp_signal"] | |
|
159 | 161 | elif self.CODE == "pp_velocity": |
|
160 | 162 | scope = self.data["pp_velocity"] |
|
161 | 163 | elif self.CODE == "pp_specwidth": |
|
162 | 164 | scope = self.data["pp_specwidth"] |
|
163 | 165 | else: |
|
164 | 166 | scope =self.data["scope"] |
|
165 | 167 | |
|
166 | 168 | if self.data.flagDataAsBlock: |
|
167 | 169 | |
|
168 | 170 | for i in range(self.data.nProfiles): |
|
169 | 171 | |
|
170 | 172 | wintitle1 = " [Profile = %d] " %i |
|
171 | 173 | if self.CODE =="scope": |
|
172 | 174 | if self.type == "power": |
|
173 | 175 | self.plot_power(self.data.heights, |
|
174 | 176 | scope[:,i,:], |
|
175 | 177 | channels, |
|
176 | 178 | thisDatetime, |
|
177 | 179 | wintitle1 |
|
178 | 180 | ) |
|
179 | 181 | |
|
180 | 182 | if self.type == "iq": |
|
181 | 183 | self.plot_iq(self.data.heights, |
|
182 | 184 | scope[:,i,:], |
|
183 | 185 | channels, |
|
184 | 186 | thisDatetime, |
|
185 | 187 | wintitle1 |
|
186 | 188 | ) |
|
187 | 189 | if self.CODE=="pp_power": |
|
188 | 190 | self.plot_weatherpower(self.data.heights, |
|
189 | 191 | scope[:,i,:], |
|
190 | 192 | channels, |
|
191 | 193 | thisDatetime, |
|
192 | 194 | wintitle |
|
193 | 195 | ) |
|
196 | if self.CODE=="pp_signal": | |
|
197 | self.plot_weatherpower(self.data.heights, | |
|
198 | scope[:,i,:], | |
|
199 | channels, | |
|
200 | thisDatetime, | |
|
201 | wintitle | |
|
202 | ) | |
|
194 | 203 | if self.CODE=="pp_velocity": |
|
195 | 204 | self.plot_weathervelocity(scope[:,i,:], |
|
196 | 205 | self.data.heights, |
|
197 | 206 | channels, |
|
198 | 207 | thisDatetime, |
|
199 | 208 | wintitle |
|
200 | 209 | ) |
|
201 | 210 | if self.CODE=="pp_spcwidth": |
|
202 | 211 | self.plot_weatherspecwidth(scope[:,i,:], |
|
203 | 212 | self.data.heights, |
|
204 | 213 | channels, |
|
205 | 214 | thisDatetime, |
|
206 | 215 | wintitle |
|
207 | 216 | ) |
|
208 | 217 | else: |
|
209 | 218 | wintitle = " [Profile = %d] " %self.data.profileIndex |
|
210 | 219 | if self.CODE== "scope": |
|
211 | 220 | if self.type == "power": |
|
212 | 221 | self.plot_power(self.data.heights, |
|
213 | 222 | scope, |
|
214 | 223 | channels, |
|
215 | 224 | thisDatetime, |
|
216 | 225 | wintitle |
|
217 | 226 | ) |
|
218 | 227 | |
|
219 | 228 | if self.type == "iq": |
|
220 | 229 | self.plot_iq(self.data.heights, |
|
221 | 230 | scope, |
|
222 | 231 | channels, |
|
223 | 232 | thisDatetime, |
|
224 | 233 | wintitle |
|
225 | 234 | ) |
|
226 | 235 | if self.CODE=="pp_power": |
|
227 | 236 | self.plot_weatherpower(self.data.heights, |
|
228 | 237 | scope, |
|
229 | 238 | channels, |
|
230 | 239 | thisDatetime, |
|
231 | 240 | wintitle |
|
232 | 241 | ) |
|
242 | if self.CODE=="pp_signal": | |
|
243 | self.plot_weatherpower(self.data.heights, | |
|
244 | scope, | |
|
245 | channels, | |
|
246 | thisDatetime, | |
|
247 | wintitle | |
|
248 | ) | |
|
233 | 249 | if self.CODE=="pp_velocity": |
|
234 | 250 | self.plot_weathervelocity(scope, |
|
235 | 251 | self.data.heights, |
|
236 | 252 | channels, |
|
237 | 253 | thisDatetime, |
|
238 | 254 | wintitle |
|
239 | 255 | ) |
|
240 | 256 | if self.CODE=="pp_specwidth": |
|
241 | 257 | self.plot_weatherspecwidth(scope, |
|
242 | 258 | self.data.heights, |
|
243 | 259 | channels, |
|
244 | 260 | thisDatetime, |
|
245 | 261 | wintitle |
|
246 | 262 | ) |
|
247 | 263 | |
|
248 | 264 | |
|
249 | 265 | |
|
250 | 266 | class PulsepairPowerPlot(ScopePlot): |
|
251 | 267 | ''' |
|
252 | Plot for | |
|
268 | Plot for P= S+N | |
|
253 | 269 | ''' |
|
254 | 270 | |
|
255 | 271 | CODE = 'pp_power' |
|
256 | 272 | plot_name = 'PulsepairPower' |
|
257 | 273 | plot_type = 'scatter' |
|
258 | 274 | buffering = False |
|
259 | 275 | |
|
260 | 276 | class PulsepairVelocityPlot(ScopePlot): |
|
261 | 277 | ''' |
|
262 | Plot for | |
|
278 | Plot for VELOCITY | |
|
263 | 279 | ''' |
|
264 | 280 | CODE = 'pp_velocity' |
|
265 | 281 | plot_name = 'PulsepairVelocity' |
|
266 | 282 | plot_type = 'scatter' |
|
267 | 283 | buffering = False |
|
268 | 284 | |
|
269 | 285 | class PulsepairSpecwidthPlot(ScopePlot): |
|
270 | 286 | ''' |
|
271 | Plot for | |
|
287 | Plot for WIDTH | |
|
272 | 288 | ''' |
|
273 | 289 | CODE = 'pp_specwidth' |
|
274 | 290 | plot_name = 'PulsepairSpecwidth' |
|
275 | 291 | plot_type = 'scatter' |
|
276 | 292 | buffering = False |
|
293 | ||
|
294 | class PulsepairSignalPlot(ScopePlot): | |
|
295 | ''' | |
|
296 | Plot for S | |
|
297 | ''' | |
|
298 | ||
|
299 | CODE = 'pp_signal' | |
|
300 | plot_name = 'PulsepairSignal' | |
|
301 | plot_type = 'scatter' | |
|
302 | buffering = False |
@@ -1,512 +1,519 | |||
|
1 | 1 | import numpy,math,random,time |
|
2 | 2 | #---------------1 Heredamos JRODatareader |
|
3 | 3 | from schainpy.model.io.jroIO_base import * |
|
4 | 4 | #---------------2 Heredamos las propiedades de ProcessingUnit |
|
5 | 5 | from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator |
|
6 | 6 | #---------------3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader |
|
7 | 7 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader |
|
8 | 8 | #---------------4 Importaremos el objeto Voltge |
|
9 | 9 | from schainpy.model.data.jrodata import Voltage |
|
10 | 10 | |
|
11 | 11 | class SimulatorReader(JRODataReader, ProcessingUnit): |
|
12 | 12 | incIntFactor = 1 |
|
13 | 13 | nFFTPoints = 0 |
|
14 | 14 | FixPP_IncInt = 1 |
|
15 | 15 | FixRCP_IPP = 1000 |
|
16 | 16 | FixPP_CohInt = 1 |
|
17 | 17 | Tau_0 = 250 |
|
18 | 18 | AcqH0_0 = 70 |
|
19 | 19 | H0 = AcqH0_0 |
|
20 | 20 | AcqDH_0 = 1.25 |
|
21 | 21 | DH0 = AcqDH_0 |
|
22 | 22 | Bauds = 32 |
|
23 | 23 | BaudWidth = None |
|
24 | 24 | FixRCP_TXA = 40 |
|
25 | 25 | FixRCP_TXB = 70 |
|
26 | 26 | fAngle = 2.0*math.pi*(1/16) |
|
27 | 27 | DC_level = 500 |
|
28 | 28 | stdev = 8 |
|
29 | 29 | Num_Codes = 2 |
|
30 | 30 | #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1]) |
|
31 | 31 | #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0]) |
|
32 | 32 | #Dyn_snCode = numpy.array([Num_Codes,Bauds]) |
|
33 | 33 | Dyn_snCode = None |
|
34 | 34 | Samples = 200 |
|
35 | 35 | channels = 2 |
|
36 | 36 | pulses = None |
|
37 | 37 | Reference = None |
|
38 | 38 | pulse_size = None |
|
39 | 39 | prof_gen = None |
|
40 | 40 | Fdoppler = 100 |
|
41 | 41 | Hdoppler = 36 |
|
42 | 42 | Adoppler = 300 |
|
43 | 43 | frequency = 9345 |
|
44 | 44 | nTotalReadFiles = 1000 |
|
45 | 45 | |
|
46 | 46 | def __init__(self): |
|
47 | 47 | """ |
|
48 | 48 | Inicializador de la clases SimulatorReader para |
|
49 | 49 | generar datos de voltage simulados. |
|
50 | 50 | Input: |
|
51 | 51 | dataOut: Objeto de la clase Voltage. |
|
52 | 52 | Este Objeto sera utilizado apra almacenar |
|
53 | 53 | un perfil de datos cada vez qe se haga |
|
54 | 54 | un requerimiento (getData) |
|
55 | 55 | """ |
|
56 | 56 | ProcessingUnit.__init__(self) |
|
57 | 57 | print(" [ START ] init - Metodo Simulator Reader") |
|
58 | 58 | |
|
59 | 59 | self.isConfig = False |
|
60 | 60 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
61 | 61 | self.systemHeaderObj = SystemHeader() |
|
62 | 62 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
63 | 63 | self.processingHeaderObj = ProcessingHeader() |
|
64 | 64 | self.profileIndex = 2**32-1 |
|
65 | 65 | self.dataOut = Voltage() |
|
66 | 66 | #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1]) |
|
67 | 67 | code0 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1]) |
|
68 | 68 | #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0]) |
|
69 | 69 | code1 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1,-1,-1,1,-1]) |
|
70 | 70 | #self.Dyn_snCode = numpy.array([code0,code1]) |
|
71 | 71 | self.Dyn_snCode = None |
|
72 | 72 | |
|
73 | 73 | def set_kwargs(self, **kwargs): |
|
74 | 74 | for key, value in kwargs.items(): |
|
75 | 75 | setattr(self, key, value) |
|
76 | 76 | |
|
77 | 77 | def __hasNotDataInBuffer(self): |
|
78 | 78 | |
|
79 | 79 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs: |
|
80 | 80 | if self.nReadBlocks>0: |
|
81 | 81 | tmp = self.dataOut.utctime |
|
82 | 82 | tmp_utc = int(self.dataOut.utctime) |
|
83 | 83 | tmp_milisecond = int((tmp-tmp_utc)*1000) |
|
84 | 84 | self.basicHeaderObj.utc = tmp_utc |
|
85 | 85 | self.basicHeaderObj.miliSecond= tmp_milisecond |
|
86 | 86 | return 1 |
|
87 | 87 | return 0 |
|
88 | 88 | |
|
89 | 89 | def setNextFile(self): |
|
90 | 90 | """Set the next file to be readed open it and parse de file header""" |
|
91 | 91 | |
|
92 | 92 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
93 | 93 | self.nReadFiles=self.nReadFiles+1 |
|
94 | 94 | if self.nReadFiles > self.nTotalReadFiles: |
|
95 | 95 | self.flagNoMoreFiles=1 |
|
96 | 96 | raise schainpy.admin.SchainWarning('No more files to read') |
|
97 | 97 | |
|
98 | 98 | print('------------------- [Opening file] ------------------------------',self.nReadFiles) |
|
99 | 99 | self.nReadBlocks = 0 |
|
100 | 100 | #if self.nReadBlocks==0: |
|
101 | 101 | # self.readFirstHeader() |
|
102 | 102 | |
|
103 | 103 | def __setNewBlock(self): |
|
104 | 104 | self.setNextFile() |
|
105 | 105 | if self.flagIsNewFile: |
|
106 | 106 | return 1 |
|
107 | 107 | |
|
108 | 108 | def readNextBlock(self): |
|
109 | 109 | while True: |
|
110 | 110 | self.__setNewBlock() |
|
111 | 111 | if not(self.readBlock()): |
|
112 | 112 | return 0 |
|
113 | 113 | self.getBasicHeader() |
|
114 | 114 | break |
|
115 | 115 | if self.verbose: |
|
116 | 116 | print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, |
|
117 | 117 | self.processingHeaderObj.dataBlocksPerFile, |
|
118 | 118 | self.dataOut.datatime.ctime()) ) |
|
119 | 119 | return 1 |
|
120 | 120 | |
|
121 | 121 | def getFirstHeader(self): |
|
122 | 122 | self.getBasicHeader() |
|
123 | 123 | self.dataOut.processingHeaderObj = self.processingHeaderObj.copy() |
|
124 | 124 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
125 | 125 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
126 | 126 | self.dataOut.dtype = self.dtype |
|
127 | 127 | |
|
128 | 128 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
129 | 129 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight |
|
130 | 130 | self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels)) |
|
131 | 131 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
132 | 132 | # asumo q la data no esta decodificada |
|
133 | 133 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode |
|
134 | 134 | # asumo q la data no esta sin flip |
|
135 | 135 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip |
|
136 | 136 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
137 | 137 | self.dataOut.frequency = self.frequency |
|
138 | 138 | |
|
139 | 139 | def getBasicHeader(self): |
|
140 | 140 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ |
|
141 | 141 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds |
|
142 | 142 | |
|
143 | 143 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
144 | 144 | self.dataOut.timeZone = self.basicHeaderObj.timeZone |
|
145 | 145 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag |
|
146 | 146 | self.dataOut.errorCount = self.basicHeaderObj.errorCount |
|
147 | 147 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
148 | 148 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs |
|
149 | 149 | |
|
150 | 150 | def readFirstHeader(self): |
|
151 | 151 | |
|
152 | 152 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & |
|
153 | 153 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
154 | 154 | if datatype == 0: |
|
155 | 155 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
156 | 156 | elif datatype == 1: |
|
157 | 157 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
158 | 158 | elif datatype == 2: |
|
159 | 159 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
160 | 160 | elif datatype == 3: |
|
161 | 161 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
162 | 162 | elif datatype == 4: |
|
163 | 163 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
164 | 164 | elif datatype == 5: |
|
165 | 165 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
166 | 166 | else: |
|
167 | 167 | raise ValueError('Data type was not defined') |
|
168 | 168 | |
|
169 | 169 | self.dtype = datatype_str |
|
170 | 170 | |
|
171 | 171 | |
|
172 | 172 | def set_RCH(self, expType=2, nTx=1,ipp=None, txA=0, txB=0, |
|
173 | 173 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, |
|
174 | 174 | numTaus=0, line6Function=0, line5Function=0, fClock=None, |
|
175 | 175 | prePulseBefore=0, prePulseAfter=0, |
|
176 | 176 | codeType=0, nCode=0, nBaud=0, code=None, |
|
177 | 177 | flip1=0, flip2=0,Taus=0): |
|
178 | 178 | self.radarControllerHeaderObj.expType = expType |
|
179 | 179 | self.radarControllerHeaderObj.nTx = nTx |
|
180 | 180 | self.radarControllerHeaderObj.ipp = float(ipp) |
|
181 | 181 | self.radarControllerHeaderObj.txA = float(txA) |
|
182 | 182 | self.radarControllerHeaderObj.txB = float(txB) |
|
183 | 183 | self.radarControllerHeaderObj.rangeIpp = b'A\n'#ipp |
|
184 | 184 | self.radarControllerHeaderObj.rangeTxA = b'' |
|
185 | 185 | self.radarControllerHeaderObj.rangeTxB = b'' |
|
186 | 186 | |
|
187 | 187 | self.radarControllerHeaderObj.nHeights = int(nHeights) |
|
188 | 188 | self.radarControllerHeaderObj.firstHeight = numpy.array([firstHeight]) |
|
189 | 189 | self.radarControllerHeaderObj.deltaHeight = numpy.array([deltaHeight]) |
|
190 | 190 | self.radarControllerHeaderObj.samplesWin = numpy.array([nHeights]) |
|
191 | 191 | |
|
192 | 192 | |
|
193 | 193 | self.radarControllerHeaderObj.nWindows = nWindows |
|
194 | 194 | self.radarControllerHeaderObj.numTaus = numTaus |
|
195 | 195 | self.radarControllerHeaderObj.codeType = codeType |
|
196 | 196 | self.radarControllerHeaderObj.line6Function = line6Function |
|
197 | 197 | self.radarControllerHeaderObj.line5Function = line5Function |
|
198 | 198 | #self.radarControllerHeaderObj.fClock = fClock |
|
199 | 199 | self.radarControllerHeaderObj.prePulseBefore= prePulseBefore |
|
200 | 200 | self.radarControllerHeaderObj.prePulseAfter = prePulseAfter |
|
201 | 201 | |
|
202 | 202 | self.radarControllerHeaderObj.flip1 = flip1 |
|
203 | 203 | self.radarControllerHeaderObj.flip2 = flip2 |
|
204 | 204 | |
|
205 | 205 | self.radarControllerHeaderObj.code_size = 0 |
|
206 | 206 | if self.radarControllerHeaderObj.codeType != 0: |
|
207 | 207 | self.radarControllerHeaderObj.nCode = nCode |
|
208 | 208 | self.radarControllerHeaderObj.nBaud = nBaud |
|
209 | 209 | self.radarControllerHeaderObj.code = code |
|
210 | 210 | self.radarControllerHeaderObj.code_size = int(numpy.ceil(nBaud / 32.)) * nCode * 4 |
|
211 | 211 | |
|
212 | 212 | if fClock is None and deltaHeight is not None: |
|
213 | 213 | self.fClock = 0.15 / (deltaHeight * 1e-6) |
|
214 | 214 | self.radarControllerHeaderObj.fClock = self.fClock |
|
215 | 215 | if numTaus==0: |
|
216 | 216 | self.radarControllerHeaderObj.Taus = numpy.array(0,'<f4') |
|
217 | 217 | else: |
|
218 | 218 | self.radarControllerHeaderObj.Taus = numpy.array(Taus,'<f4') |
|
219 | 219 | |
|
220 | 220 | def set_PH(self, dtype=0, blockSize=0, profilesPerBlock=0, |
|
221 | 221 | dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0, |
|
222 | 222 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, |
|
223 | 223 | deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, |
|
224 | 224 | code=0, nBaud=None, shif_fft=False, flag_dc=False, |
|
225 | 225 | flag_cspc=False, flag_decode=False, flag_deflip=False): |
|
226 | 226 | |
|
227 | 227 | self.processingHeaderObj.dtype = dtype |
|
228 | 228 | self.processingHeaderObj.profilesPerBlock = profilesPerBlock |
|
229 | 229 | self.processingHeaderObj.dataBlocksPerFile = dataBlocksPerFile |
|
230 | 230 | self.processingHeaderObj.nWindows = nWindows |
|
231 | 231 | self.processingHeaderObj.processFlags = processFlags |
|
232 | 232 | self.processingHeaderObj.nCohInt = nCohInt |
|
233 | 233 | self.processingHeaderObj.nIncohInt = nIncohInt |
|
234 | 234 | self.processingHeaderObj.totalSpectra = totalSpectra |
|
235 | 235 | |
|
236 | 236 | self.processingHeaderObj.nHeights = int(nHeights) |
|
237 | 237 | self.processingHeaderObj.firstHeight = firstHeight#numpy.array([firstHeight])#firstHeight |
|
238 | 238 | self.processingHeaderObj.deltaHeight = deltaHeight#numpy.array([deltaHeight])#deltaHeight |
|
239 | 239 | self.processingHeaderObj.samplesWin = nHeights#numpy.array([nHeights])#nHeights |
|
240 | 240 | |
|
241 | 241 | def set_BH(self, utc = 0, miliSecond = 0, timeZone = 0): |
|
242 | 242 | self.basicHeaderObj.utc = utc |
|
243 | 243 | self.basicHeaderObj.miliSecond = miliSecond |
|
244 | 244 | self.basicHeaderObj.timeZone = timeZone |
|
245 | 245 | |
|
246 | 246 | def set_SH(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=32): |
|
247 | 247 | #self.systemHeaderObj.size = size |
|
248 | 248 | self.systemHeaderObj.nSamples = nSamples |
|
249 | 249 | self.systemHeaderObj.nProfiles = nProfiles |
|
250 | 250 | self.systemHeaderObj.nChannels = nChannels |
|
251 | 251 | self.systemHeaderObj.adcResolution = adcResolution |
|
252 | 252 | self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth |
|
253 | 253 | |
|
254 | 254 | def init_acquisition(self): |
|
255 | 255 | |
|
256 | 256 | if self.nFFTPoints != 0: |
|
257 | 257 | self.incIntFactor = m_nProfilesperBlock/self.nFFTPoints |
|
258 | 258 | if (self.FixPP_IncInt > self.incIntFactor): |
|
259 | 259 | self.incIntFactor = self.FixPP_IncInt/ self.incIntFactor |
|
260 | 260 | elif(self.FixPP_IncInt< self.incIntFactor): |
|
261 | 261 | print("False alert...") |
|
262 | 262 | |
|
263 | 263 | ProfilesperBlock = self.processingHeaderObj.profilesPerBlock |
|
264 | 264 | |
|
265 | 265 | self.timeperblock =int(((self.FixRCP_IPP |
|
266 | 266 | *ProfilesperBlock |
|
267 | 267 | *self.FixPP_CohInt |
|
268 | 268 | *self.incIntFactor) |
|
269 | 269 | /150.0) |
|
270 | 270 | *0.9 |
|
271 | 271 | +0.5) |
|
272 | 272 | # para cada canal |
|
273 | 273 | self.profiles = ProfilesperBlock*self.FixPP_CohInt |
|
274 | 274 | self.profiles = ProfilesperBlock |
|
275 | 275 | self.Reference = int((self.Tau_0-self.AcqH0_0)/(self.AcqDH_0)+0.5) |
|
276 | 276 | self.BaudWidth = int((self.FixRCP_TXA/self.AcqDH_0)/self.Bauds + 0.5 ) |
|
277 | 277 | |
|
278 | 278 | if (self.BaudWidth==0): |
|
279 | 279 | self.BaudWidth=1 |
|
280 | 280 | |
|
281 | 281 | def init_pulse(self,Num_Codes=Num_Codes,Bauds=Bauds,BaudWidth=BaudWidth,Dyn_snCode=Dyn_snCode): |
|
282 | 282 | |
|
283 | 283 | Num_Codes = Num_Codes |
|
284 | 284 | Bauds = Bauds |
|
285 | 285 | BaudWidth = BaudWidth |
|
286 | 286 | Dyn_snCode = Dyn_snCode |
|
287 | 287 | |
|
288 | 288 | if Dyn_snCode: |
|
289 | 289 | print("EXISTE") |
|
290 | 290 | else: |
|
291 | 291 | print("No existe") |
|
292 | 292 | |
|
293 | 293 | if Dyn_snCode: # if Bauds: |
|
294 | 294 | pulses = list(range(0,Num_Codes)) |
|
295 | 295 | num_codes = Num_Codes |
|
296 | 296 | for i in range(num_codes): |
|
297 | 297 | pulse_size = Bauds*BaudWidth |
|
298 | 298 | pulses[i] = numpy.zeros(pulse_size) |
|
299 | 299 | for j in range(Bauds): |
|
300 | 300 | for k in range(BaudWidth): |
|
301 | 301 | pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600) |
|
302 | 302 | else: |
|
303 | 303 | print("sin code") |
|
304 | 304 | pulses = list(range(1)) |
|
305 | 305 | if self.AcqDH_0>0.149: |
|
306 | 306 | pulse_size = int(self.FixRCP_TXB/0.15+0.5) |
|
307 | 307 | else: |
|
308 | 308 | pulse_size = int((self.FixRCP_TXB/self.AcqDH_0)+0.5) #0.0375 |
|
309 | 309 | pulses[0] = numpy.ones(pulse_size) |
|
310 | 310 | pulses = 600*pulses[0] |
|
311 | 311 | |
|
312 | 312 | return pulses,pulse_size |
|
313 | 313 | |
|
314 | 314 | def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev, |
|
315 | 315 | Reference= Reference,pulses= pulses, |
|
316 | 316 | Num_Codes= Num_Codes,pulse_size=pulse_size, |
|
317 | 317 | prof_gen= prof_gen,H0 = H0,DH0=DH0, |
|
318 | 318 | Adoppler=Adoppler,Fdoppler= Fdoppler,Hdoppler=Hdoppler): |
|
319 | 319 | Samples = Samples |
|
320 | 320 | DC_level = DC_level |
|
321 | 321 | stdev = stdev |
|
322 | 322 | m_nR = Reference |
|
323 | 323 | pulses = pulses |
|
324 | 324 | num_codes = Num_Codes |
|
325 | 325 | ps = pulse_size |
|
326 | 326 | prof_gen = prof_gen |
|
327 | 327 | channels = self.channels |
|
328 | 328 | H0 = H0 |
|
329 | 329 | DH0 = DH0 |
|
330 | 330 | ippSec = self.radarControllerHeaderObj.ippSeconds |
|
331 | 331 | Fdoppler = self.Fdoppler |
|
332 | 332 | Hdoppler = self.Hdoppler |
|
333 | 333 | Adoppler = self.Adoppler |
|
334 | 334 | |
|
335 | 335 | self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64) |
|
336 | 336 | for i in range(channels): |
|
337 | 337 | for k in range(prof_gen): |
|
338 | 338 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
339 | 339 | Noise_r = numpy.random.normal(DC_level,stdev,Samples) |
|
340 | 340 | Noise_i = numpy.random.normal(DC_level,stdev,Samples) |
|
341 | 341 | Noise = numpy.zeros(Samples,dtype=complex) |
|
342 | 342 | Noise.real = Noise_r |
|
343 | 343 | Noise.imag = Noise_i |
|
344 | 344 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·PULSOSΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
345 | 345 | Pulso = numpy.zeros(pulse_size,dtype=complex) |
|
346 | 346 | Pulso.real = pulses[k%num_codes] |
|
347 | 347 | Pulso.imag = pulses[k%num_codes] |
|
348 | 348 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· PULSES+NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
349 | 349 | InBuffer = numpy.zeros(Samples,dtype=complex) |
|
350 | 350 | InBuffer[m_nR:m_nR+ps] = Pulso |
|
351 | 351 | InBuffer = InBuffer+Noise |
|
352 | 352 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· ANGLE Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
353 | 353 | InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( self.fAngle)*5) |
|
354 | 354 | InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5) |
|
355 | 355 | InBuffer=InBuffer |
|
356 | 356 | self.datablock[i][k]= InBuffer |
|
357 | 357 | |
|
358 | 358 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·DOPPLER SIGNAL............................................... |
|
359 | 359 | time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen+(self.nReadFiles-1)*ippSec*prof_gen |
|
360 | 360 | fd = Fdoppler #+(600.0/120)*self.nReadBlocks |
|
361 | 361 | d_signal = Adoppler*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64) |
|
362 | 362 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·SeΓ±al con ancho espectralΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
363 | #specw_sig = numpy.linspace(-149,150,300) | |
|
364 | #w = 8 | |
|
365 | #A = 20 | |
|
366 | #specw_sig = specw_sig/w | |
|
367 | #specw_sig = numpy.sinc(specw_sig) | |
|
368 | #specw_sig = A*numpy.array(specw_sig,dtype=numpy.complex64) | |
|
363 | if prof_gen%2==0: | |
|
364 | min = int(prof_gen/2.0-1.0) | |
|
365 | max = int(prof_gen/2.0) | |
|
366 | else: | |
|
367 | min = int(prof_gen/2.0) | |
|
368 | max = int(prof_gen/2.0) | |
|
369 | specw_sig = numpy.linspace(-min,max,prof_gen) | |
|
370 | w = 4 | |
|
371 | A = 20 | |
|
372 | specw_sig = specw_sig/w | |
|
373 | specw_sig = numpy.sinc(specw_sig) | |
|
374 | specw_sig = A*numpy.array(specw_sig,dtype=numpy.complex64) | |
|
369 | 375 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLERΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
370 | 376 | HD=int(Hdoppler/self.AcqDH_0) |
|
371 | 377 | for i in range(12): |
|
372 | 378 | self.datablock[0,:,HD+i]=self.datablock[0,:,HD+i]+ d_signal# RESULT |
|
373 | 379 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLER*Sinc(x)Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
380 | HD=int(Hdoppler/self.AcqDH_0) | |
|
381 | HD=int(HD/2) | |
|
382 | for i in range(12): | |
|
383 | self.datablock[0,:,HD+i]=self.datablock[0,:,HD+i]+ specw_sig*d_signal# RESULT | |
|
378 | 384 | |
|
379 | 385 | def readBlock(self): |
|
380 | 386 | |
|
381 | 387 | self.jro_GenerateBlockOfData(Samples= self.samples,DC_level=self.DC_level, |
|
382 | 388 | stdev=self.stdev,Reference= self.Reference, |
|
383 | 389 | pulses = self.pulses,Num_Codes=self.Num_Codes, |
|
384 | 390 | pulse_size=self.pulse_size,prof_gen=self.profiles, |
|
385 | 391 | H0=self.H0,DH0=self.DH0) |
|
386 | 392 | |
|
387 | 393 | self.profileIndex = 0 |
|
388 | 394 | self.flagIsNewFile = 0 |
|
389 | 395 | self.flagIsNewBlock = 1 |
|
390 | 396 | self.nTotalBlocks += 1 |
|
391 | 397 | self.nReadBlocks += 1 |
|
392 | 398 | |
|
393 | 399 | return 1 |
|
394 | 400 | |
|
395 | 401 | |
|
396 | 402 | def getData(self): |
|
397 | 403 | if self.flagNoMoreFiles: |
|
398 | 404 | self.dataOut.flagNodata = True |
|
399 | 405 | return 0 |
|
400 | 406 | self.flagDiscontinuousBlock = 0 |
|
401 | 407 | self.flagIsNewBlock = 0 |
|
402 | 408 | if self.__hasNotDataInBuffer(): # aqui es verdad |
|
403 | 409 | if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header |
|
404 | 410 | return 0 |
|
405 | 411 | self.getFirstHeader() # atributo |
|
406 | 412 | |
|
407 | 413 | if not self.getByBlock: |
|
408 | 414 | self.dataOut.flagDataAsBlock = False |
|
409 | 415 | self.dataOut.data = self.datablock[:, self.profileIndex, :] |
|
410 | 416 | self.dataOut.profileIndex = self.profileIndex |
|
411 | 417 | self.profileIndex += 1 |
|
412 | 418 | else: |
|
413 | 419 | pass |
|
414 | 420 | self.dataOut.flagNoData = False |
|
415 | 421 | self.getBasicHeader() |
|
416 | 422 | self.dataOut.realtime = self.online |
|
417 | 423 | return self.dataOut.data |
|
418 | 424 | |
|
419 | 425 | |
|
420 | 426 | def setup(self,frequency=49.92e6,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000, |
|
421 | 427 | FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32, |
|
422 | 428 | FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 50, |
|
423 | 429 | stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200, |
|
424 |
channels=2,Fdoppler=20,Hdoppler=36,Adoppler=500, |
|
|
430 | channels=2,Fdoppler=20,Hdoppler=36,Adoppler=500, | |
|
431 | profilesPerBlock=300,dataBlocksPerFile=120,nTotalReadFiles=10000, | |
|
425 | 432 | **kwargs): |
|
426 | 433 | |
|
427 | 434 | self.set_kwargs(**kwargs) |
|
428 | 435 | self.nReadBlocks = 0 |
|
429 | 436 | self.nReadFiles = 1 |
|
430 | 437 | print('------------------- [Opening file: ] ------------------------------',self.nReadFiles) |
|
431 | 438 | |
|
432 | 439 | tmp = time.time() |
|
433 | 440 | tmp_utc = int(tmp) |
|
434 | 441 | tmp_milisecond = int((tmp-tmp_utc)*1000) |
|
435 | 442 | print(" SETUP -basicHeaderObj.utc",datetime.datetime.utcfromtimestamp(tmp)) |
|
436 | 443 | if Dyn_snCode is None: |
|
437 | 444 | Num_Codes=1 |
|
438 | 445 | Bauds =1 |
|
439 | 446 | |
|
440 | 447 | |
|
441 | 448 | |
|
442 | 449 | self.set_BH(utc= tmp_utc,miliSecond= tmp_milisecond,timeZone=300 ) |
|
443 | 450 | self.set_RCH( expType=0, nTx=150,ipp=FixRCP_IPP, txA=FixRCP_TXA, txB= FixRCP_TXB, |
|
444 | 451 | nWindows=1 , nHeights=samples, firstHeight=AcqH0_0, deltaHeight=AcqDH_0, |
|
445 | 452 | numTaus=1, line6Function=0, line5Function=0, fClock=None, |
|
446 | 453 | prePulseBefore=0, prePulseAfter=0, |
|
447 | 454 | codeType=0, nCode=Num_Codes, nBaud=32, code=Dyn_snCode, |
|
448 | 455 | flip1=0, flip2=0,Taus=Tau_0) |
|
449 | 456 | |
|
450 |
self.set_PH(dtype=0, blockSize=0, profilesPerBlock= |
|
|
451 |
dataBlocksPerFile= |
|
|
457 | self.set_PH(dtype=0, blockSize=0, profilesPerBlock=profilesPerBlock, | |
|
458 | dataBlocksPerFile=dataBlocksPerFile, nWindows=1, processFlags=numpy.array([1024]), nCohInt=1, | |
|
452 | 459 | nIncohInt=1, totalSpectra=0, nHeights=samples, firstHeight=AcqH0_0, |
|
453 | 460 | deltaHeight=AcqDH_0, samplesWin=samples, spectraComb=0, nCode=0, |
|
454 | 461 | code=0, nBaud=None, shif_fft=False, flag_dc=False, |
|
455 | 462 | flag_cspc=False, flag_decode=False, flag_deflip=False) |
|
456 | 463 | |
|
457 |
self.set_SH(nSamples=samples, nProfiles= |
|
|
464 | self.set_SH(nSamples=samples, nProfiles=profilesPerBlock, nChannels=channels) | |
|
458 | 465 | |
|
459 | 466 | self.readFirstHeader() |
|
460 | 467 | |
|
461 | 468 | self.frequency = frequency |
|
462 | 469 | self.incIntFactor = incIntFactor |
|
463 | 470 | self.nFFTPoints = nFFTPoints |
|
464 | 471 | self.FixPP_IncInt = FixPP_IncInt |
|
465 | 472 | self.FixRCP_IPP = FixRCP_IPP |
|
466 | 473 | self.FixPP_CohInt = FixPP_CohInt |
|
467 | 474 | self.Tau_0 = Tau_0 |
|
468 | 475 | self.AcqH0_0 = AcqH0_0 |
|
469 | 476 | self.H0 = AcqH0_0 |
|
470 | 477 | self.AcqDH_0 = AcqDH_0 |
|
471 | 478 | self.DH0 = AcqDH_0 |
|
472 | 479 | self.Bauds = Bauds |
|
473 | 480 | self.FixRCP_TXA = FixRCP_TXA |
|
474 | 481 | self.FixRCP_TXB = FixRCP_TXB |
|
475 | 482 | self.fAngle = fAngle |
|
476 | 483 | self.DC_level = DC_level |
|
477 | 484 | self.stdev = stdev |
|
478 | 485 | self.Num_Codes = Num_Codes |
|
479 | 486 | self.Dyn_snCode = Dyn_snCode |
|
480 | 487 | self.samples = samples |
|
481 | 488 | self.channels = channels |
|
482 | 489 | self.profiles = None |
|
483 | 490 | self.m_nReference = None |
|
484 | 491 | self.Baudwidth = None |
|
485 | 492 | self.Fdoppler = Fdoppler |
|
486 | 493 | self.Hdoppler = Hdoppler |
|
487 | 494 | self.Adoppler = Adoppler |
|
488 | 495 | self.nTotalReadFiles = int(nTotalReadFiles) |
|
489 | 496 | |
|
490 | 497 | print("IPP ", self.FixRCP_IPP) |
|
491 | 498 | print("Tau_0 ",self.Tau_0) |
|
492 | 499 | print("AcqH0_0",self.AcqH0_0) |
|
493 | 500 | print("samples,window ",self.samples) |
|
494 | 501 | print("AcqDH_0",AcqDH_0) |
|
495 | 502 | print("FixRCP_TXA",self.FixRCP_TXA) |
|
496 | 503 | print("FixRCP_TXB",self.FixRCP_TXB) |
|
497 | 504 | print("Dyn_snCode",Dyn_snCode) |
|
498 | 505 | print("Fdoppler", Fdoppler) |
|
499 | 506 | print("Hdoppler",Hdoppler) |
|
500 | 507 | print("Vdopplermax",Fdoppler*(3.0e8/self.frequency)/2.0) |
|
501 | 508 | print("nTotalReadFiles", nTotalReadFiles) |
|
502 | 509 | |
|
503 | 510 | self.init_acquisition() |
|
504 | 511 | self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode) |
|
505 | 512 | print(" [ END ] - SETUP metodo") |
|
506 | 513 | return |
|
507 | 514 | |
|
508 | 515 | def run(self,**kwargs): # metodo propio |
|
509 | 516 | if not(self.isConfig): |
|
510 | 517 | self.setup(**kwargs) |
|
511 | 518 | self.isConfig = True |
|
512 | 519 | self.getData() |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,1587 +1,1608 | |||
|
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 | from schainpy.model.data import _noise | |
|
6 | 7 | from schainpy.utils import log |
|
7 | 8 | from time import time |
|
8 | 9 | |
|
9 | 10 | |
|
10 | 11 | |
|
11 | 12 | class VoltageProc(ProcessingUnit): |
|
12 | 13 | |
|
13 | 14 | def __init__(self): |
|
14 | 15 | |
|
15 | 16 | ProcessingUnit.__init__(self) |
|
16 | 17 | |
|
17 | 18 | self.dataOut = Voltage() |
|
18 | 19 | self.flip = 1 |
|
19 | 20 | self.setupReq = False |
|
20 | 21 | |
|
21 | 22 | def run(self): |
|
22 | 23 | |
|
23 | 24 | if self.dataIn.type == 'AMISR': |
|
24 | 25 | self.__updateObjFromAmisrInput() |
|
25 | 26 | |
|
26 | 27 | if self.dataIn.type == 'Voltage': |
|
27 | 28 | self.dataOut.copy(self.dataIn) |
|
28 | 29 | |
|
29 | 30 | def __updateObjFromAmisrInput(self): |
|
30 | 31 | |
|
31 | 32 | self.dataOut.timeZone = self.dataIn.timeZone |
|
32 | 33 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
33 | 34 | self.dataOut.errorCount = self.dataIn.errorCount |
|
34 | 35 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
35 | 36 | |
|
36 | 37 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
37 | 38 | self.dataOut.data = self.dataIn.data |
|
38 | 39 | self.dataOut.utctime = self.dataIn.utctime |
|
39 | 40 | self.dataOut.channelList = self.dataIn.channelList |
|
40 | 41 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
41 | 42 | self.dataOut.heightList = self.dataIn.heightList |
|
42 | 43 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
43 | 44 | |
|
44 | 45 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
45 | 46 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
46 | 47 | self.dataOut.frequency = self.dataIn.frequency |
|
47 | 48 | |
|
48 | 49 | self.dataOut.azimuth = self.dataIn.azimuth |
|
49 | 50 | self.dataOut.zenith = self.dataIn.zenith |
|
50 | 51 | |
|
51 | 52 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
52 | 53 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
53 | 54 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
54 | 55 | |
|
55 | 56 | |
|
56 | 57 | class selectChannels(Operation): |
|
57 | 58 | |
|
58 | 59 | def run(self, dataOut, channelList): |
|
59 | 60 | |
|
60 | 61 | channelIndexList = [] |
|
61 | 62 | self.dataOut = dataOut |
|
62 | 63 | for channel in channelList: |
|
63 | 64 | if channel not in self.dataOut.channelList: |
|
64 | 65 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) |
|
65 | 66 | |
|
66 | 67 | index = self.dataOut.channelList.index(channel) |
|
67 | 68 | channelIndexList.append(index) |
|
68 | 69 | self.selectChannelsByIndex(channelIndexList) |
|
69 | 70 | return self.dataOut |
|
70 | 71 | |
|
71 | 72 | def selectChannelsByIndex(self, channelIndexList): |
|
72 | 73 | """ |
|
73 | 74 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
74 | 75 | |
|
75 | 76 | Input: |
|
76 | 77 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
77 | 78 | |
|
78 | 79 | Affected: |
|
79 | 80 | self.dataOut.data |
|
80 | 81 | self.dataOut.channelIndexList |
|
81 | 82 | self.dataOut.nChannels |
|
82 | 83 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
83 | 84 | self.dataOut.systemHeaderObj.numChannels |
|
84 | 85 | self.dataOut.m_ProcessingHeader.blockSize |
|
85 | 86 | |
|
86 | 87 | Return: |
|
87 | 88 | None |
|
88 | 89 | """ |
|
89 | 90 | |
|
90 | 91 | for channelIndex in channelIndexList: |
|
91 | 92 | if channelIndex not in self.dataOut.channelIndexList: |
|
92 | 93 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
93 | 94 | |
|
94 | 95 | if self.dataOut.type == 'Voltage': |
|
95 | 96 | if self.dataOut.flagDataAsBlock: |
|
96 | 97 | """ |
|
97 | 98 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
98 | 99 | """ |
|
99 | 100 | data = self.dataOut.data[channelIndexList,:,:] |
|
100 | 101 | else: |
|
101 | 102 | data = self.dataOut.data[channelIndexList,:] |
|
102 | 103 | |
|
103 | 104 | self.dataOut.data = data |
|
104 | 105 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
105 | 106 | self.dataOut.channelList = range(len(channelIndexList)) |
|
106 | 107 | |
|
107 | 108 | elif self.dataOut.type == 'Spectra': |
|
108 | 109 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
109 | 110 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
110 | 111 | |
|
111 | 112 | self.dataOut.data_spc = data_spc |
|
112 | 113 | self.dataOut.data_dc = data_dc |
|
113 | 114 | |
|
114 | 115 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
115 | 116 | self.dataOut.channelList = range(len(channelIndexList)) |
|
116 | 117 | self.__selectPairsByChannel(channelIndexList) |
|
117 | 118 | |
|
118 | 119 | return 1 |
|
119 | 120 | |
|
120 | 121 | def __selectPairsByChannel(self, channelList=None): |
|
121 | 122 | |
|
122 | 123 | if channelList == None: |
|
123 | 124 | return |
|
124 | 125 | |
|
125 | 126 | pairsIndexListSelected = [] |
|
126 | 127 | for pairIndex in self.dataOut.pairsIndexList: |
|
127 | 128 | # First pair |
|
128 | 129 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
129 | 130 | continue |
|
130 | 131 | # Second pair |
|
131 | 132 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
132 | 133 | continue |
|
133 | 134 | |
|
134 | 135 | pairsIndexListSelected.append(pairIndex) |
|
135 | 136 | |
|
136 | 137 | if not pairsIndexListSelected: |
|
137 | 138 | self.dataOut.data_cspc = None |
|
138 | 139 | self.dataOut.pairsList = [] |
|
139 | 140 | return |
|
140 | 141 | |
|
141 | 142 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
142 | 143 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
143 | 144 | for i in pairsIndexListSelected] |
|
144 | 145 | |
|
145 | 146 | return |
|
146 | 147 | |
|
147 | 148 | class selectHeights(Operation): |
|
148 | 149 | |
|
149 | 150 | def run(self, dataOut, minHei=None, maxHei=None): |
|
150 | 151 | """ |
|
151 | 152 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
152 | 153 | minHei <= height <= maxHei |
|
153 | 154 | |
|
154 | 155 | Input: |
|
155 | 156 | minHei : valor minimo de altura a considerar |
|
156 | 157 | maxHei : valor maximo de altura a considerar |
|
157 | 158 | |
|
158 | 159 | Affected: |
|
159 | 160 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
160 | 161 | |
|
161 | 162 | Return: |
|
162 | 163 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
163 | 164 | """ |
|
164 | 165 | |
|
165 | 166 | self.dataOut = dataOut |
|
166 | 167 | |
|
167 | 168 | if minHei == None: |
|
168 | 169 | minHei = self.dataOut.heightList[0] |
|
169 | 170 | |
|
170 | 171 | if maxHei == None: |
|
171 | 172 | maxHei = self.dataOut.heightList[-1] |
|
172 | 173 | |
|
173 | 174 | if (minHei < self.dataOut.heightList[0]): |
|
174 | 175 | minHei = self.dataOut.heightList[0] |
|
175 | 176 | |
|
176 | 177 | if (maxHei > self.dataOut.heightList[-1]): |
|
177 | 178 | maxHei = self.dataOut.heightList[-1] |
|
178 | 179 | |
|
179 | 180 | minIndex = 0 |
|
180 | 181 | maxIndex = 0 |
|
181 | 182 | heights = self.dataOut.heightList |
|
182 | 183 | |
|
183 | 184 | inda = numpy.where(heights >= minHei) |
|
184 | 185 | indb = numpy.where(heights <= maxHei) |
|
185 | 186 | |
|
186 | 187 | try: |
|
187 | 188 | minIndex = inda[0][0] |
|
188 | 189 | except: |
|
189 | 190 | minIndex = 0 |
|
190 | 191 | |
|
191 | 192 | try: |
|
192 | 193 | maxIndex = indb[0][-1] |
|
193 | 194 | except: |
|
194 | 195 | maxIndex = len(heights) |
|
195 | 196 | |
|
196 | 197 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
197 | 198 | |
|
198 | 199 | return self.dataOut |
|
199 | 200 | |
|
200 | 201 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
201 | 202 | """ |
|
202 | 203 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
203 | 204 | minIndex <= index <= maxIndex |
|
204 | 205 | |
|
205 | 206 | Input: |
|
206 | 207 | minIndex : valor de indice minimo de altura a considerar |
|
207 | 208 | maxIndex : valor de indice maximo de altura a considerar |
|
208 | 209 | |
|
209 | 210 | Affected: |
|
210 | 211 | self.dataOut.data |
|
211 | 212 | self.dataOut.heightList |
|
212 | 213 | |
|
213 | 214 | Return: |
|
214 | 215 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
215 | 216 | """ |
|
216 | 217 | |
|
217 | 218 | if self.dataOut.type == 'Voltage': |
|
218 | 219 | if (minIndex < 0) or (minIndex > maxIndex): |
|
219 | 220 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
220 | 221 | |
|
221 | 222 | if (maxIndex >= self.dataOut.nHeights): |
|
222 | 223 | maxIndex = self.dataOut.nHeights |
|
223 | 224 | |
|
224 | 225 | #voltage |
|
225 | 226 | if self.dataOut.flagDataAsBlock: |
|
226 | 227 | """ |
|
227 | 228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
228 | 229 | """ |
|
229 | 230 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
230 | 231 | else: |
|
231 | 232 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
232 | 233 | |
|
233 | 234 | # firstHeight = self.dataOut.heightList[minIndex] |
|
234 | 235 | |
|
235 | 236 | self.dataOut.data = data |
|
236 | 237 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
237 | 238 | |
|
238 | 239 | if self.dataOut.nHeights <= 1: |
|
239 | 240 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
240 | 241 | elif self.dataOut.type == 'Spectra': |
|
241 | 242 | if (minIndex < 0) or (minIndex > maxIndex): |
|
242 | 243 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
243 | 244 | minIndex, maxIndex)) |
|
244 | 245 | |
|
245 | 246 | if (maxIndex >= self.dataOut.nHeights): |
|
246 | 247 | maxIndex = self.dataOut.nHeights - 1 |
|
247 | 248 | |
|
248 | 249 | # Spectra |
|
249 | 250 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
250 | 251 | |
|
251 | 252 | data_cspc = None |
|
252 | 253 | if self.dataOut.data_cspc is not None: |
|
253 | 254 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
254 | 255 | |
|
255 | 256 | data_dc = None |
|
256 | 257 | if self.dataOut.data_dc is not None: |
|
257 | 258 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
258 | 259 | |
|
259 | 260 | self.dataOut.data_spc = data_spc |
|
260 | 261 | self.dataOut.data_cspc = data_cspc |
|
261 | 262 | self.dataOut.data_dc = data_dc |
|
262 | 263 | |
|
263 | 264 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
264 | 265 | |
|
265 | 266 | return 1 |
|
266 | 267 | |
|
267 | 268 | |
|
268 | 269 | class filterByHeights(Operation): |
|
269 | 270 | |
|
270 | 271 | def run(self, dataOut, window): |
|
271 | 272 | |
|
272 | 273 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
273 | 274 | |
|
274 | 275 | if window == None: |
|
275 | 276 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
276 | 277 | |
|
277 | 278 | newdelta = deltaHeight * window |
|
278 | 279 | r = dataOut.nHeights % window |
|
279 | 280 | newheights = (dataOut.nHeights-r)/window |
|
280 | 281 | |
|
281 | 282 | if newheights <= 1: |
|
282 | 283 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
283 | 284 | |
|
284 | 285 | if dataOut.flagDataAsBlock: |
|
285 | 286 | """ |
|
286 | 287 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
287 | 288 | """ |
|
288 | 289 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] |
|
289 | 290 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) |
|
290 | 291 | buffer = numpy.sum(buffer,3) |
|
291 | 292 | |
|
292 | 293 | else: |
|
293 | 294 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] |
|
294 | 295 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) |
|
295 | 296 | buffer = numpy.sum(buffer,2) |
|
296 | 297 | |
|
297 | 298 | dataOut.data = buffer |
|
298 | 299 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
299 | 300 | dataOut.windowOfFilter = window |
|
300 | 301 | |
|
301 | 302 | return dataOut |
|
302 | 303 | |
|
303 | 304 | |
|
304 | 305 | class setH0(Operation): |
|
305 | 306 | |
|
306 | 307 | def run(self, dataOut, h0, deltaHeight = None): |
|
307 | 308 | |
|
308 | 309 | if not deltaHeight: |
|
309 | 310 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
310 | 311 | |
|
311 | 312 | nHeights = dataOut.nHeights |
|
312 | 313 | |
|
313 | 314 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
314 | 315 | |
|
315 | 316 | dataOut.heightList = newHeiRange |
|
316 | 317 | |
|
317 | 318 | return dataOut |
|
318 | 319 | |
|
319 | 320 | |
|
320 | 321 | class deFlip(Operation): |
|
321 | 322 | |
|
322 | 323 | def run(self, dataOut, channelList = []): |
|
323 | 324 | |
|
324 | 325 | data = dataOut.data.copy() |
|
325 | 326 | |
|
326 | 327 | if dataOut.flagDataAsBlock: |
|
327 | 328 | flip = self.flip |
|
328 | 329 | profileList = list(range(dataOut.nProfiles)) |
|
329 | 330 | |
|
330 | 331 | if not channelList: |
|
331 | 332 | for thisProfile in profileList: |
|
332 | 333 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
333 | 334 | flip *= -1.0 |
|
334 | 335 | else: |
|
335 | 336 | for thisChannel in channelList: |
|
336 | 337 | if thisChannel not in dataOut.channelList: |
|
337 | 338 | continue |
|
338 | 339 | |
|
339 | 340 | for thisProfile in profileList: |
|
340 | 341 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
341 | 342 | flip *= -1.0 |
|
342 | 343 | |
|
343 | 344 | self.flip = flip |
|
344 | 345 | |
|
345 | 346 | else: |
|
346 | 347 | if not channelList: |
|
347 | 348 | data[:,:] = data[:,:]*self.flip |
|
348 | 349 | else: |
|
349 | 350 | for thisChannel in channelList: |
|
350 | 351 | if thisChannel not in dataOut.channelList: |
|
351 | 352 | continue |
|
352 | 353 | |
|
353 | 354 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
354 | 355 | |
|
355 | 356 | self.flip *= -1. |
|
356 | 357 | |
|
357 | 358 | dataOut.data = data |
|
358 | 359 | |
|
359 | 360 | return dataOut |
|
360 | 361 | |
|
361 | 362 | |
|
362 | 363 | class setAttribute(Operation): |
|
363 | 364 | ''' |
|
364 | 365 | Set an arbitrary attribute(s) to dataOut |
|
365 | 366 | ''' |
|
366 | 367 | |
|
367 | 368 | def __init__(self): |
|
368 | 369 | |
|
369 | 370 | Operation.__init__(self) |
|
370 | 371 | self._ready = False |
|
371 | 372 | |
|
372 | 373 | def run(self, dataOut, **kwargs): |
|
373 | 374 | |
|
374 | 375 | for key, value in kwargs.items(): |
|
375 | 376 | setattr(dataOut, key, value) |
|
376 | 377 | |
|
377 | 378 | return dataOut |
|
378 | 379 | |
|
379 | 380 | |
|
380 | 381 | class interpolateHeights(Operation): |
|
381 | 382 | |
|
382 | 383 | def run(self, dataOut, topLim, botLim): |
|
383 | 384 | #69 al 72 para julia |
|
384 | 385 | #82-84 para meteoros |
|
385 | 386 | if len(numpy.shape(dataOut.data))==2: |
|
386 | 387 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
387 | 388 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
388 | 389 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
389 | 390 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
390 | 391 | else: |
|
391 | 392 | nHeights = dataOut.data.shape[2] |
|
392 | 393 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
393 | 394 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
394 | 395 | f = interpolate.interp1d(x, y, axis = 2) |
|
395 | 396 | xnew = numpy.arange(botLim,topLim+1) |
|
396 | 397 | ynew = f(xnew) |
|
397 | 398 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
398 | 399 | |
|
399 | 400 | return dataOut |
|
400 | 401 | |
|
401 | 402 | |
|
402 | 403 | class CohInt(Operation): |
|
403 | 404 | |
|
404 | 405 | isConfig = False |
|
405 | 406 | __profIndex = 0 |
|
406 | 407 | __byTime = False |
|
407 | 408 | __initime = None |
|
408 | 409 | __lastdatatime = None |
|
409 | 410 | __integrationtime = None |
|
410 | 411 | __buffer = None |
|
411 | 412 | __bufferStride = [] |
|
412 | 413 | __dataReady = False |
|
413 | 414 | __profIndexStride = 0 |
|
414 | 415 | __dataToPutStride = False |
|
415 | 416 | n = None |
|
416 | 417 | |
|
417 | 418 | def __init__(self, **kwargs): |
|
418 | 419 | |
|
419 | 420 | Operation.__init__(self, **kwargs) |
|
420 | 421 | |
|
421 | 422 | # self.isConfig = False |
|
422 | 423 | |
|
423 | 424 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
424 | 425 | """ |
|
425 | 426 | Set the parameters of the integration class. |
|
426 | 427 | |
|
427 | 428 | Inputs: |
|
428 | 429 | |
|
429 | 430 | n : Number of coherent integrations |
|
430 | 431 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
431 | 432 | overlapping : |
|
432 | 433 | """ |
|
433 | 434 | |
|
434 | 435 | self.__initime = None |
|
435 | 436 | self.__lastdatatime = 0 |
|
436 | 437 | self.__buffer = None |
|
437 | 438 | self.__dataReady = False |
|
438 | 439 | self.byblock = byblock |
|
439 | 440 | self.stride = stride |
|
440 | 441 | |
|
441 | 442 | if n == None and timeInterval == None: |
|
442 | 443 | raise ValueError("n or timeInterval should be specified ...") |
|
443 | 444 | |
|
444 | 445 | if n != None: |
|
445 | 446 | self.n = n |
|
446 | 447 | self.__byTime = False |
|
447 | 448 | else: |
|
448 | 449 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
449 | 450 | self.n = 9999 |
|
450 | 451 | self.__byTime = True |
|
451 | 452 | |
|
452 | 453 | if overlapping: |
|
453 | 454 | self.__withOverlapping = True |
|
454 | 455 | self.__buffer = None |
|
455 | 456 | else: |
|
456 | 457 | self.__withOverlapping = False |
|
457 | 458 | self.__buffer = 0 |
|
458 | 459 | |
|
459 | 460 | self.__profIndex = 0 |
|
460 | 461 | |
|
461 | 462 | def putData(self, data): |
|
462 | 463 | |
|
463 | 464 | """ |
|
464 | 465 | Add a profile to the __buffer and increase in one the __profileIndex |
|
465 | 466 | |
|
466 | 467 | """ |
|
467 | 468 | |
|
468 | 469 | if not self.__withOverlapping: |
|
469 | 470 | self.__buffer += data.copy() |
|
470 | 471 | self.__profIndex += 1 |
|
471 | 472 | return |
|
472 | 473 | |
|
473 | 474 | #Overlapping data |
|
474 | 475 | nChannels, nHeis = data.shape |
|
475 | 476 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
476 | 477 | |
|
477 | 478 | #If the buffer is empty then it takes the data value |
|
478 | 479 | if self.__buffer is None: |
|
479 | 480 | self.__buffer = data |
|
480 | 481 | self.__profIndex += 1 |
|
481 | 482 | return |
|
482 | 483 | |
|
483 | 484 | #If the buffer length is lower than n then stakcing the data value |
|
484 | 485 | if self.__profIndex < self.n: |
|
485 | 486 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
486 | 487 | self.__profIndex += 1 |
|
487 | 488 | return |
|
488 | 489 | |
|
489 | 490 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
490 | 491 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
491 | 492 | self.__buffer[self.n-1] = data |
|
492 | 493 | self.__profIndex = self.n |
|
493 | 494 | return |
|
494 | 495 | |
|
495 | 496 | |
|
496 | 497 | def pushData(self): |
|
497 | 498 | """ |
|
498 | 499 | Return the sum of the last profiles and the profiles used in the sum. |
|
499 | 500 | |
|
500 | 501 | Affected: |
|
501 | 502 | |
|
502 | 503 | self.__profileIndex |
|
503 | 504 | |
|
504 | 505 | """ |
|
505 | 506 | |
|
506 | 507 | if not self.__withOverlapping: |
|
507 | 508 | data = self.__buffer |
|
508 | 509 | n = self.__profIndex |
|
509 | 510 | |
|
510 | 511 | self.__buffer = 0 |
|
511 | 512 | self.__profIndex = 0 |
|
512 | 513 | |
|
513 | 514 | return data, n |
|
514 | 515 | |
|
515 | 516 | #Integration with Overlapping |
|
516 | 517 | data = numpy.sum(self.__buffer, axis=0) |
|
517 | 518 | # print data |
|
518 | 519 | # raise |
|
519 | 520 | n = self.__profIndex |
|
520 | 521 | |
|
521 | 522 | return data, n |
|
522 | 523 | |
|
523 | 524 | def byProfiles(self, data): |
|
524 | 525 | |
|
525 | 526 | self.__dataReady = False |
|
526 | 527 | avgdata = None |
|
527 | 528 | # n = None |
|
528 | 529 | # print data |
|
529 | 530 | # raise |
|
530 | 531 | self.putData(data) |
|
531 | 532 | |
|
532 | 533 | if self.__profIndex == self.n: |
|
533 | 534 | avgdata, n = self.pushData() |
|
534 | 535 | self.__dataReady = True |
|
535 | 536 | |
|
536 | 537 | return avgdata |
|
537 | 538 | |
|
538 | 539 | def byTime(self, data, datatime): |
|
539 | 540 | |
|
540 | 541 | self.__dataReady = False |
|
541 | 542 | avgdata = None |
|
542 | 543 | n = None |
|
543 | 544 | |
|
544 | 545 | self.putData(data) |
|
545 | 546 | |
|
546 | 547 | if (datatime - self.__initime) >= self.__integrationtime: |
|
547 | 548 | avgdata, n = self.pushData() |
|
548 | 549 | self.n = n |
|
549 | 550 | self.__dataReady = True |
|
550 | 551 | |
|
551 | 552 | return avgdata |
|
552 | 553 | |
|
553 | 554 | def integrateByStride(self, data, datatime): |
|
554 | 555 | # print data |
|
555 | 556 | if self.__profIndex == 0: |
|
556 | 557 | self.__buffer = [[data.copy(), datatime]] |
|
557 | 558 | else: |
|
558 | 559 | self.__buffer.append([data.copy(),datatime]) |
|
559 | 560 | self.__profIndex += 1 |
|
560 | 561 | self.__dataReady = False |
|
561 | 562 | |
|
562 | 563 | if self.__profIndex == self.n * self.stride : |
|
563 | 564 | self.__dataToPutStride = True |
|
564 | 565 | self.__profIndexStride = 0 |
|
565 | 566 | self.__profIndex = 0 |
|
566 | 567 | self.__bufferStride = [] |
|
567 | 568 | for i in range(self.stride): |
|
568 | 569 | current = self.__buffer[i::self.stride] |
|
569 | 570 | data = numpy.sum([t[0] for t in current], axis=0) |
|
570 | 571 | avgdatatime = numpy.average([t[1] for t in current]) |
|
571 | 572 | # print data |
|
572 | 573 | self.__bufferStride.append((data, avgdatatime)) |
|
573 | 574 | |
|
574 | 575 | if self.__dataToPutStride: |
|
575 | 576 | self.__dataReady = True |
|
576 | 577 | self.__profIndexStride += 1 |
|
577 | 578 | if self.__profIndexStride == self.stride: |
|
578 | 579 | self.__dataToPutStride = False |
|
579 | 580 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
580 | 581 | # raise |
|
581 | 582 | return self.__bufferStride[self.__profIndexStride - 1] |
|
582 | 583 | |
|
583 | 584 | |
|
584 | 585 | return None, None |
|
585 | 586 | |
|
586 | 587 | def integrate(self, data, datatime=None): |
|
587 | 588 | |
|
588 | 589 | if self.__initime == None: |
|
589 | 590 | self.__initime = datatime |
|
590 | 591 | |
|
591 | 592 | if self.__byTime: |
|
592 | 593 | avgdata = self.byTime(data, datatime) |
|
593 | 594 | else: |
|
594 | 595 | avgdata = self.byProfiles(data) |
|
595 | 596 | |
|
596 | 597 | |
|
597 | 598 | self.__lastdatatime = datatime |
|
598 | 599 | |
|
599 | 600 | if avgdata is None: |
|
600 | 601 | return None, None |
|
601 | 602 | |
|
602 | 603 | avgdatatime = self.__initime |
|
603 | 604 | |
|
604 | 605 | deltatime = datatime - self.__lastdatatime |
|
605 | 606 | |
|
606 | 607 | if not self.__withOverlapping: |
|
607 | 608 | self.__initime = datatime |
|
608 | 609 | else: |
|
609 | 610 | self.__initime += deltatime |
|
610 | 611 | |
|
611 | 612 | return avgdata, avgdatatime |
|
612 | 613 | |
|
613 | 614 | def integrateByBlock(self, dataOut): |
|
614 | 615 | |
|
615 | 616 | times = int(dataOut.data.shape[1]/self.n) |
|
616 | 617 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
617 | 618 | |
|
618 | 619 | id_min = 0 |
|
619 | 620 | id_max = self.n |
|
620 | 621 | |
|
621 | 622 | for i in range(times): |
|
622 | 623 | junk = dataOut.data[:,id_min:id_max,:] |
|
623 | 624 | avgdata[:,i,:] = junk.sum(axis=1) |
|
624 | 625 | id_min += self.n |
|
625 | 626 | id_max += self.n |
|
626 | 627 | |
|
627 | 628 | timeInterval = dataOut.ippSeconds*self.n |
|
628 | 629 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
629 | 630 | self.__dataReady = True |
|
630 | 631 | return avgdata, avgdatatime |
|
631 | 632 | |
|
632 | 633 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
633 | 634 | |
|
634 | 635 | if not self.isConfig: |
|
635 | 636 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
636 | 637 | self.isConfig = True |
|
637 | 638 | |
|
638 | 639 | if dataOut.flagDataAsBlock: |
|
639 | 640 | """ |
|
640 | 641 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
641 | 642 | """ |
|
642 | 643 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
643 | 644 | dataOut.nProfiles /= self.n |
|
644 | 645 | else: |
|
645 | 646 | if stride is None: |
|
646 | 647 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
647 | 648 | else: |
|
648 | 649 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
649 | 650 | |
|
650 | 651 | |
|
651 | 652 | # dataOut.timeInterval *= n |
|
652 | 653 | dataOut.flagNoData = True |
|
653 | 654 | |
|
654 | 655 | if self.__dataReady: |
|
655 | 656 | dataOut.data = avgdata |
|
656 | 657 | dataOut.nCohInt *= self.n |
|
657 | 658 | dataOut.utctime = avgdatatime |
|
658 | 659 | # print avgdata, avgdatatime |
|
659 | 660 | # raise |
|
660 | 661 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
661 | 662 | dataOut.flagNoData = False |
|
662 | 663 | return dataOut |
|
663 | 664 | |
|
664 | 665 | class Decoder(Operation): |
|
665 | 666 | |
|
666 | 667 | isConfig = False |
|
667 | 668 | __profIndex = 0 |
|
668 | 669 | |
|
669 | 670 | code = None |
|
670 | 671 | |
|
671 | 672 | nCode = None |
|
672 | 673 | nBaud = None |
|
673 | 674 | |
|
674 | 675 | def __init__(self, **kwargs): |
|
675 | 676 | |
|
676 | 677 | Operation.__init__(self, **kwargs) |
|
677 | 678 | |
|
678 | 679 | self.times = None |
|
679 | 680 | self.osamp = None |
|
680 | 681 | # self.__setValues = False |
|
681 | 682 | self.isConfig = False |
|
682 | 683 | self.setupReq = False |
|
683 | 684 | def setup(self, code, osamp, dataOut): |
|
684 | 685 | |
|
685 | 686 | self.__profIndex = 0 |
|
686 | 687 | |
|
687 | 688 | self.code = code |
|
688 | 689 | |
|
689 | 690 | self.nCode = len(code) |
|
690 | 691 | self.nBaud = len(code[0]) |
|
691 | 692 | |
|
692 | 693 | if (osamp != None) and (osamp >1): |
|
693 | 694 | self.osamp = osamp |
|
694 | 695 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
695 | 696 | self.nBaud = self.nBaud*self.osamp |
|
696 | 697 | |
|
697 | 698 | self.__nChannels = dataOut.nChannels |
|
698 | 699 | self.__nProfiles = dataOut.nProfiles |
|
699 | 700 | self.__nHeis = dataOut.nHeights |
|
700 | 701 | |
|
701 | 702 | if self.__nHeis < self.nBaud: |
|
702 | 703 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
703 | 704 | |
|
704 | 705 | #Frequency |
|
705 | 706 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
706 | 707 | |
|
707 | 708 | __codeBuffer[:,0:self.nBaud] = self.code |
|
708 | 709 | |
|
709 | 710 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
710 | 711 | |
|
711 | 712 | if dataOut.flagDataAsBlock: |
|
712 | 713 | |
|
713 | 714 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
714 | 715 | |
|
715 | 716 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
716 | 717 | |
|
717 | 718 | else: |
|
718 | 719 | |
|
719 | 720 | #Time |
|
720 | 721 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
721 | 722 | |
|
722 | 723 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
723 | 724 | |
|
724 | 725 | def __convolutionInFreq(self, data): |
|
725 | 726 | |
|
726 | 727 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
727 | 728 | |
|
728 | 729 | fft_data = numpy.fft.fft(data, axis=1) |
|
729 | 730 | |
|
730 | 731 | conv = fft_data*fft_code |
|
731 | 732 | |
|
732 | 733 | data = numpy.fft.ifft(conv,axis=1) |
|
733 | 734 | |
|
734 | 735 | return data |
|
735 | 736 | |
|
736 | 737 | def __convolutionInFreqOpt(self, data): |
|
737 | 738 | |
|
738 | 739 | raise NotImplementedError |
|
739 | 740 | |
|
740 | 741 | def __convolutionInTime(self, data): |
|
741 | 742 | |
|
742 | 743 | code = self.code[self.__profIndex] |
|
743 | 744 | for i in range(self.__nChannels): |
|
744 | 745 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
745 | 746 | |
|
746 | 747 | return self.datadecTime |
|
747 | 748 | |
|
748 | 749 | def __convolutionByBlockInTime(self, data): |
|
749 | 750 | |
|
750 | 751 | repetitions = int(self.__nProfiles / self.nCode) |
|
751 | 752 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
752 | 753 | junk = junk.flatten() |
|
753 | 754 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
754 | 755 | profilesList = range(self.__nProfiles) |
|
755 | 756 | |
|
756 | 757 | for i in range(self.__nChannels): |
|
757 | 758 | for j in profilesList: |
|
758 | 759 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
759 | 760 | return self.datadecTime |
|
760 | 761 | |
|
761 | 762 | def __convolutionByBlockInFreq(self, data): |
|
762 | 763 | |
|
763 | 764 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
764 | 765 | |
|
765 | 766 | |
|
766 | 767 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
767 | 768 | |
|
768 | 769 | fft_data = numpy.fft.fft(data, axis=2) |
|
769 | 770 | |
|
770 | 771 | conv = fft_data*fft_code |
|
771 | 772 | |
|
772 | 773 | data = numpy.fft.ifft(conv,axis=2) |
|
773 | 774 | |
|
774 | 775 | return data |
|
775 | 776 | |
|
776 | 777 | |
|
777 | 778 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
778 | 779 | |
|
779 | 780 | if dataOut.flagDecodeData: |
|
780 | 781 | print("This data is already decoded, recoding again ...") |
|
781 | 782 | |
|
782 | 783 | if not self.isConfig: |
|
783 | 784 | |
|
784 | 785 | if code is None: |
|
785 | 786 | if dataOut.code is None: |
|
786 | 787 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
787 | 788 | |
|
788 | 789 | code = dataOut.code |
|
789 | 790 | else: |
|
790 | 791 | code = numpy.array(code).reshape(nCode,nBaud) |
|
791 | 792 | self.setup(code, osamp, dataOut) |
|
792 | 793 | |
|
793 | 794 | self.isConfig = True |
|
794 | 795 | |
|
795 | 796 | if mode == 3: |
|
796 | 797 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
797 | 798 | |
|
798 | 799 | if times != None: |
|
799 | 800 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
800 | 801 | |
|
801 | 802 | if self.code is None: |
|
802 | 803 | print("Fail decoding: Code is not defined.") |
|
803 | 804 | return |
|
804 | 805 | |
|
805 | 806 | self.__nProfiles = dataOut.nProfiles |
|
806 | 807 | datadec = None |
|
807 | 808 | |
|
808 | 809 | if mode == 3: |
|
809 | 810 | mode = 0 |
|
810 | 811 | |
|
811 | 812 | if dataOut.flagDataAsBlock: |
|
812 | 813 | """ |
|
813 | 814 | Decoding when data have been read as block, |
|
814 | 815 | """ |
|
815 | 816 | |
|
816 | 817 | if mode == 0: |
|
817 | 818 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
818 | 819 | if mode == 1: |
|
819 | 820 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
820 | 821 | else: |
|
821 | 822 | """ |
|
822 | 823 | Decoding when data have been read profile by profile |
|
823 | 824 | """ |
|
824 | 825 | if mode == 0: |
|
825 | 826 | datadec = self.__convolutionInTime(dataOut.data) |
|
826 | 827 | |
|
827 | 828 | if mode == 1: |
|
828 | 829 | datadec = self.__convolutionInFreq(dataOut.data) |
|
829 | 830 | |
|
830 | 831 | if mode == 2: |
|
831 | 832 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
832 | 833 | |
|
833 | 834 | if datadec is None: |
|
834 | 835 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
835 | 836 | |
|
836 | 837 | dataOut.code = self.code |
|
837 | 838 | dataOut.nCode = self.nCode |
|
838 | 839 | dataOut.nBaud = self.nBaud |
|
839 | 840 | |
|
840 | 841 | dataOut.data = datadec |
|
841 | 842 | |
|
842 | 843 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
843 | 844 | |
|
844 | 845 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
845 | 846 | |
|
846 | 847 | if self.__profIndex == self.nCode-1: |
|
847 | 848 | self.__profIndex = 0 |
|
848 | 849 | return dataOut |
|
849 | 850 | |
|
850 | 851 | self.__profIndex += 1 |
|
851 | 852 | |
|
852 | 853 | return dataOut |
|
853 | 854 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
854 | 855 | |
|
855 | 856 | |
|
856 | 857 | class ProfileConcat(Operation): |
|
857 | 858 | |
|
858 | 859 | isConfig = False |
|
859 | 860 | buffer = None |
|
860 | 861 | |
|
861 | 862 | def __init__(self, **kwargs): |
|
862 | 863 | |
|
863 | 864 | Operation.__init__(self, **kwargs) |
|
864 | 865 | self.profileIndex = 0 |
|
865 | 866 | |
|
866 | 867 | def reset(self): |
|
867 | 868 | self.buffer = numpy.zeros_like(self.buffer) |
|
868 | 869 | self.start_index = 0 |
|
869 | 870 | self.times = 1 |
|
870 | 871 | |
|
871 | 872 | def setup(self, data, m, n=1): |
|
872 | 873 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
873 | 874 | self.nHeights = data.shape[1]#.nHeights |
|
874 | 875 | self.start_index = 0 |
|
875 | 876 | self.times = 1 |
|
876 | 877 | |
|
877 | 878 | def concat(self, data): |
|
878 | 879 | |
|
879 | 880 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
880 | 881 | self.start_index = self.start_index + self.nHeights |
|
881 | 882 | |
|
882 | 883 | def run(self, dataOut, m): |
|
883 | 884 | dataOut.flagNoData = True |
|
884 | 885 | |
|
885 | 886 | if not self.isConfig: |
|
886 | 887 | self.setup(dataOut.data, m, 1) |
|
887 | 888 | self.isConfig = True |
|
888 | 889 | |
|
889 | 890 | if dataOut.flagDataAsBlock: |
|
890 | 891 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
891 | 892 | |
|
892 | 893 | else: |
|
893 | 894 | self.concat(dataOut.data) |
|
894 | 895 | self.times += 1 |
|
895 | 896 | if self.times > m: |
|
896 | 897 | dataOut.data = self.buffer |
|
897 | 898 | self.reset() |
|
898 | 899 | dataOut.flagNoData = False |
|
899 | 900 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
900 | 901 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
901 | 902 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
902 | 903 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
903 | 904 | dataOut.ippSeconds *= m |
|
904 | 905 | return dataOut |
|
905 | 906 | |
|
906 | 907 | class ProfileSelector(Operation): |
|
907 | 908 | |
|
908 | 909 | profileIndex = None |
|
909 | 910 | # Tamanho total de los perfiles |
|
910 | 911 | nProfiles = None |
|
911 | 912 | |
|
912 | 913 | def __init__(self, **kwargs): |
|
913 | 914 | |
|
914 | 915 | Operation.__init__(self, **kwargs) |
|
915 | 916 | self.profileIndex = 0 |
|
916 | 917 | |
|
917 | 918 | def incProfileIndex(self): |
|
918 | 919 | |
|
919 | 920 | self.profileIndex += 1 |
|
920 | 921 | |
|
921 | 922 | if self.profileIndex >= self.nProfiles: |
|
922 | 923 | self.profileIndex = 0 |
|
923 | 924 | |
|
924 | 925 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
925 | 926 | |
|
926 | 927 | if profileIndex < minIndex: |
|
927 | 928 | return False |
|
928 | 929 | |
|
929 | 930 | if profileIndex > maxIndex: |
|
930 | 931 | return False |
|
931 | 932 | |
|
932 | 933 | return True |
|
933 | 934 | |
|
934 | 935 | def isThisProfileInList(self, profileIndex, profileList): |
|
935 | 936 | |
|
936 | 937 | if profileIndex not in profileList: |
|
937 | 938 | return False |
|
938 | 939 | |
|
939 | 940 | return True |
|
940 | 941 | |
|
941 | 942 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
942 | 943 | |
|
943 | 944 | """ |
|
944 | 945 | ProfileSelector: |
|
945 | 946 | |
|
946 | 947 | Inputs: |
|
947 | 948 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
948 | 949 | |
|
949 | 950 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
950 | 951 | |
|
951 | 952 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
952 | 953 | |
|
953 | 954 | """ |
|
954 | 955 | |
|
955 | 956 | if rangeList is not None: |
|
956 | 957 | if type(rangeList[0]) not in (tuple, list): |
|
957 | 958 | rangeList = [rangeList] |
|
958 | 959 | |
|
959 | 960 | dataOut.flagNoData = True |
|
960 | 961 | |
|
961 | 962 | if dataOut.flagDataAsBlock: |
|
962 | 963 | """ |
|
963 | 964 | data dimension = [nChannels, nProfiles, nHeis] |
|
964 | 965 | """ |
|
965 | 966 | if profileList != None: |
|
966 | 967 | dataOut.data = dataOut.data[:,profileList,:] |
|
967 | 968 | |
|
968 | 969 | if profileRangeList != None: |
|
969 | 970 | minIndex = profileRangeList[0] |
|
970 | 971 | maxIndex = profileRangeList[1] |
|
971 | 972 | profileList = list(range(minIndex, maxIndex+1)) |
|
972 | 973 | |
|
973 | 974 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
974 | 975 | |
|
975 | 976 | if rangeList != None: |
|
976 | 977 | |
|
977 | 978 | profileList = [] |
|
978 | 979 | |
|
979 | 980 | for thisRange in rangeList: |
|
980 | 981 | minIndex = thisRange[0] |
|
981 | 982 | maxIndex = thisRange[1] |
|
982 | 983 | |
|
983 | 984 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
984 | 985 | |
|
985 | 986 | dataOut.data = dataOut.data[:,profileList,:] |
|
986 | 987 | |
|
987 | 988 | dataOut.nProfiles = len(profileList) |
|
988 | 989 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
989 | 990 | dataOut.flagNoData = False |
|
990 | 991 | |
|
991 | 992 | return dataOut |
|
992 | 993 | |
|
993 | 994 | """ |
|
994 | 995 | data dimension = [nChannels, nHeis] |
|
995 | 996 | """ |
|
996 | 997 | |
|
997 | 998 | if profileList != None: |
|
998 | 999 | |
|
999 | 1000 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
1000 | 1001 | |
|
1001 | 1002 | self.nProfiles = len(profileList) |
|
1002 | 1003 | dataOut.nProfiles = self.nProfiles |
|
1003 | 1004 | dataOut.profileIndex = self.profileIndex |
|
1004 | 1005 | dataOut.flagNoData = False |
|
1005 | 1006 | |
|
1006 | 1007 | self.incProfileIndex() |
|
1007 | 1008 | return dataOut |
|
1008 | 1009 | |
|
1009 | 1010 | if profileRangeList != None: |
|
1010 | 1011 | |
|
1011 | 1012 | minIndex = profileRangeList[0] |
|
1012 | 1013 | maxIndex = profileRangeList[1] |
|
1013 | 1014 | |
|
1014 | 1015 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1015 | 1016 | |
|
1016 | 1017 | self.nProfiles = maxIndex - minIndex + 1 |
|
1017 | 1018 | dataOut.nProfiles = self.nProfiles |
|
1018 | 1019 | dataOut.profileIndex = self.profileIndex |
|
1019 | 1020 | dataOut.flagNoData = False |
|
1020 | 1021 | |
|
1021 | 1022 | self.incProfileIndex() |
|
1022 | 1023 | return dataOut |
|
1023 | 1024 | |
|
1024 | 1025 | if rangeList != None: |
|
1025 | 1026 | |
|
1026 | 1027 | nProfiles = 0 |
|
1027 | 1028 | |
|
1028 | 1029 | for thisRange in rangeList: |
|
1029 | 1030 | minIndex = thisRange[0] |
|
1030 | 1031 | maxIndex = thisRange[1] |
|
1031 | 1032 | |
|
1032 | 1033 | nProfiles += maxIndex - minIndex + 1 |
|
1033 | 1034 | |
|
1034 | 1035 | for thisRange in rangeList: |
|
1035 | 1036 | |
|
1036 | 1037 | minIndex = thisRange[0] |
|
1037 | 1038 | maxIndex = thisRange[1] |
|
1038 | 1039 | |
|
1039 | 1040 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1040 | 1041 | |
|
1041 | 1042 | self.nProfiles = nProfiles |
|
1042 | 1043 | dataOut.nProfiles = self.nProfiles |
|
1043 | 1044 | dataOut.profileIndex = self.profileIndex |
|
1044 | 1045 | dataOut.flagNoData = False |
|
1045 | 1046 | |
|
1046 | 1047 | self.incProfileIndex() |
|
1047 | 1048 | |
|
1048 | 1049 | break |
|
1049 | 1050 | |
|
1050 | 1051 | return dataOut |
|
1051 | 1052 | |
|
1052 | 1053 | |
|
1053 | 1054 | if beam != None: #beam is only for AMISR data |
|
1054 | 1055 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1055 | 1056 | dataOut.flagNoData = False |
|
1056 | 1057 | dataOut.profileIndex = self.profileIndex |
|
1057 | 1058 | |
|
1058 | 1059 | self.incProfileIndex() |
|
1059 | 1060 | |
|
1060 | 1061 | return dataOut |
|
1061 | 1062 | |
|
1062 | 1063 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1063 | 1064 | |
|
1064 | 1065 | |
|
1065 | 1066 | class Reshaper(Operation): |
|
1066 | 1067 | |
|
1067 | 1068 | def __init__(self, **kwargs): |
|
1068 | 1069 | |
|
1069 | 1070 | Operation.__init__(self, **kwargs) |
|
1070 | 1071 | |
|
1071 | 1072 | self.__buffer = None |
|
1072 | 1073 | self.__nitems = 0 |
|
1073 | 1074 | |
|
1074 | 1075 | def __appendProfile(self, dataOut, nTxs): |
|
1075 | 1076 | |
|
1076 | 1077 | if self.__buffer is None: |
|
1077 | 1078 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1078 | 1079 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1079 | 1080 | |
|
1080 | 1081 | ini = dataOut.nHeights * self.__nitems |
|
1081 | 1082 | end = ini + dataOut.nHeights |
|
1082 | 1083 | |
|
1083 | 1084 | self.__buffer[:, ini:end] = dataOut.data |
|
1084 | 1085 | |
|
1085 | 1086 | self.__nitems += 1 |
|
1086 | 1087 | |
|
1087 | 1088 | return int(self.__nitems*nTxs) |
|
1088 | 1089 | |
|
1089 | 1090 | def __getBuffer(self): |
|
1090 | 1091 | |
|
1091 | 1092 | if self.__nitems == int(1./self.__nTxs): |
|
1092 | 1093 | |
|
1093 | 1094 | self.__nitems = 0 |
|
1094 | 1095 | |
|
1095 | 1096 | return self.__buffer.copy() |
|
1096 | 1097 | |
|
1097 | 1098 | return None |
|
1098 | 1099 | |
|
1099 | 1100 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1100 | 1101 | |
|
1101 | 1102 | if shape is None and nTxs is None: |
|
1102 | 1103 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1103 | 1104 | |
|
1104 | 1105 | if nTxs: |
|
1105 | 1106 | if nTxs < 0: |
|
1106 | 1107 | raise ValueError("nTxs should be greater than 0") |
|
1107 | 1108 | |
|
1108 | 1109 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1109 | 1110 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1110 | 1111 | |
|
1111 | 1112 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1112 | 1113 | |
|
1113 | 1114 | return shape, nTxs |
|
1114 | 1115 | |
|
1115 | 1116 | if len(shape) != 2 and len(shape) != 3: |
|
1116 | 1117 | 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)) |
|
1117 | 1118 | |
|
1118 | 1119 | if len(shape) == 2: |
|
1119 | 1120 | shape_tuple = [dataOut.nChannels] |
|
1120 | 1121 | shape_tuple.extend(shape) |
|
1121 | 1122 | else: |
|
1122 | 1123 | shape_tuple = list(shape) |
|
1123 | 1124 | |
|
1124 | 1125 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1125 | 1126 | |
|
1126 | 1127 | return shape_tuple, nTxs |
|
1127 | 1128 | |
|
1128 | 1129 | def run(self, dataOut, shape=None, nTxs=None): |
|
1129 | 1130 | |
|
1130 | 1131 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1131 | 1132 | |
|
1132 | 1133 | dataOut.flagNoData = True |
|
1133 | 1134 | profileIndex = None |
|
1134 | 1135 | |
|
1135 | 1136 | if dataOut.flagDataAsBlock: |
|
1136 | 1137 | |
|
1137 | 1138 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1138 | 1139 | dataOut.flagNoData = False |
|
1139 | 1140 | |
|
1140 | 1141 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1141 | 1142 | |
|
1142 | 1143 | else: |
|
1143 | 1144 | |
|
1144 | 1145 | if self.__nTxs < 1: |
|
1145 | 1146 | |
|
1146 | 1147 | self.__appendProfile(dataOut, self.__nTxs) |
|
1147 | 1148 | new_data = self.__getBuffer() |
|
1148 | 1149 | |
|
1149 | 1150 | if new_data is not None: |
|
1150 | 1151 | dataOut.data = new_data |
|
1151 | 1152 | dataOut.flagNoData = False |
|
1152 | 1153 | |
|
1153 | 1154 | profileIndex = dataOut.profileIndex*nTxs |
|
1154 | 1155 | |
|
1155 | 1156 | else: |
|
1156 | 1157 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1157 | 1158 | |
|
1158 | 1159 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1159 | 1160 | |
|
1160 | 1161 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1161 | 1162 | |
|
1162 | 1163 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1163 | 1164 | |
|
1164 | 1165 | dataOut.profileIndex = profileIndex |
|
1165 | 1166 | |
|
1166 | 1167 | dataOut.ippSeconds /= self.__nTxs |
|
1167 | 1168 | |
|
1168 | 1169 | return dataOut |
|
1169 | 1170 | |
|
1170 | 1171 | class SplitProfiles(Operation): |
|
1171 | 1172 | |
|
1172 | 1173 | def __init__(self, **kwargs): |
|
1173 | 1174 | |
|
1174 | 1175 | Operation.__init__(self, **kwargs) |
|
1175 | 1176 | |
|
1176 | 1177 | def run(self, dataOut, n): |
|
1177 | 1178 | |
|
1178 | 1179 | dataOut.flagNoData = True |
|
1179 | 1180 | profileIndex = None |
|
1180 | 1181 | |
|
1181 | 1182 | if dataOut.flagDataAsBlock: |
|
1182 | 1183 | |
|
1183 | 1184 | #nchannels, nprofiles, nsamples |
|
1184 | 1185 | shape = dataOut.data.shape |
|
1185 | 1186 | |
|
1186 | 1187 | if shape[2] % n != 0: |
|
1187 | 1188 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1188 | 1189 | |
|
1189 | 1190 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1190 | 1191 | |
|
1191 | 1192 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1192 | 1193 | dataOut.flagNoData = False |
|
1193 | 1194 | |
|
1194 | 1195 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1195 | 1196 | |
|
1196 | 1197 | else: |
|
1197 | 1198 | |
|
1198 | 1199 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1199 | 1200 | |
|
1200 | 1201 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1201 | 1202 | |
|
1202 | 1203 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1203 | 1204 | |
|
1204 | 1205 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1205 | 1206 | |
|
1206 | 1207 | dataOut.profileIndex = profileIndex |
|
1207 | 1208 | |
|
1208 | 1209 | dataOut.ippSeconds /= n |
|
1209 | 1210 | |
|
1210 | 1211 | return dataOut |
|
1211 | 1212 | |
|
1212 | 1213 | class CombineProfiles(Operation): |
|
1213 | 1214 | def __init__(self, **kwargs): |
|
1214 | 1215 | |
|
1215 | 1216 | Operation.__init__(self, **kwargs) |
|
1216 | 1217 | |
|
1217 | 1218 | self.__remData = None |
|
1218 | 1219 | self.__profileIndex = 0 |
|
1219 | 1220 | |
|
1220 | 1221 | def run(self, dataOut, n): |
|
1221 | 1222 | |
|
1222 | 1223 | dataOut.flagNoData = True |
|
1223 | 1224 | profileIndex = None |
|
1224 | 1225 | |
|
1225 | 1226 | if dataOut.flagDataAsBlock: |
|
1226 | 1227 | |
|
1227 | 1228 | #nchannels, nprofiles, nsamples |
|
1228 | 1229 | shape = dataOut.data.shape |
|
1229 | 1230 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1230 | 1231 | |
|
1231 | 1232 | if shape[1] % n != 0: |
|
1232 | 1233 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1233 | 1234 | |
|
1234 | 1235 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1235 | 1236 | dataOut.flagNoData = False |
|
1236 | 1237 | |
|
1237 | 1238 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1238 | 1239 | |
|
1239 | 1240 | else: |
|
1240 | 1241 | |
|
1241 | 1242 | #nchannels, nsamples |
|
1242 | 1243 | if self.__remData is None: |
|
1243 | 1244 | newData = dataOut.data |
|
1244 | 1245 | else: |
|
1245 | 1246 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1246 | 1247 | |
|
1247 | 1248 | self.__profileIndex += 1 |
|
1248 | 1249 | |
|
1249 | 1250 | if self.__profileIndex < n: |
|
1250 | 1251 | self.__remData = newData |
|
1251 | 1252 | #continue |
|
1252 | 1253 | return |
|
1253 | 1254 | |
|
1254 | 1255 | self.__profileIndex = 0 |
|
1255 | 1256 | self.__remData = None |
|
1256 | 1257 | |
|
1257 | 1258 | dataOut.data = newData |
|
1258 | 1259 | dataOut.flagNoData = False |
|
1259 | 1260 | |
|
1260 | 1261 | profileIndex = dataOut.profileIndex/n |
|
1261 | 1262 | |
|
1262 | 1263 | |
|
1263 | 1264 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1264 | 1265 | |
|
1265 | 1266 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1266 | 1267 | |
|
1267 | 1268 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1268 | 1269 | |
|
1269 | 1270 | dataOut.profileIndex = profileIndex |
|
1270 | 1271 | |
|
1271 | 1272 | dataOut.ippSeconds *= n |
|
1272 | 1273 | |
|
1273 | 1274 | return dataOut |
|
1274 | 1275 | |
|
1275 | 1276 | class PulsePairVoltage(Operation): |
|
1276 | 1277 | ''' |
|
1277 | 1278 | Function PulsePair(Signal Power, Velocity) |
|
1278 | 1279 | The real component of Lag[0] provides Intensity Information |
|
1279 | 1280 | The imag component of Lag[1] Phase provides Velocity Information |
|
1280 | 1281 | |
|
1281 | 1282 | Configuration Parameters: |
|
1282 | 1283 | nPRF = Number of Several PRF |
|
1283 | 1284 | theta = Degree Azimuth angel Boundaries |
|
1284 | 1285 | |
|
1285 | 1286 | Input: |
|
1286 | 1287 | self.dataOut |
|
1287 | 1288 | lag[N] |
|
1288 | 1289 | Affected: |
|
1289 | 1290 | self.dataOut.spc |
|
1290 | 1291 | ''' |
|
1291 | 1292 | isConfig = False |
|
1292 | 1293 | __profIndex = 0 |
|
1293 | 1294 | __initime = None |
|
1294 | 1295 | __lastdatatime = None |
|
1295 | 1296 | __buffer = None |
|
1296 | 1297 | noise = None |
|
1297 | 1298 | __dataReady = False |
|
1298 | 1299 | n = None |
|
1299 | 1300 | __nch = 0 |
|
1300 | 1301 | __nHeis = 0 |
|
1301 | 1302 | removeDC = False |
|
1302 | 1303 | ipp = None |
|
1303 | 1304 | lambda_ = 0 |
|
1304 | 1305 | |
|
1305 | 1306 | def __init__(self,**kwargs): |
|
1306 | 1307 | Operation.__init__(self,**kwargs) |
|
1307 | 1308 | |
|
1308 | 1309 | def setup(self, dataOut, n = None, removeDC=False): |
|
1309 | 1310 | ''' |
|
1310 | 1311 | n= Numero de PRF's de entrada |
|
1311 | 1312 | ''' |
|
1312 | 1313 | self.__initime = None |
|
1313 | 1314 | self.__lastdatatime = 0 |
|
1314 | 1315 | self.__dataReady = False |
|
1315 | 1316 | self.__buffer = 0 |
|
1316 | 1317 | self.__profIndex = 0 |
|
1317 | 1318 | self.noise = None |
|
1318 | 1319 | self.__nch = dataOut.nChannels |
|
1319 | 1320 | self.__nHeis = dataOut.nHeights |
|
1320 | 1321 | self.removeDC = removeDC |
|
1321 | 1322 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1322 | 1323 | self.ippSec = dataOut.ippSeconds |
|
1323 | 1324 | self.nCohInt = dataOut.nCohInt |
|
1324 | 1325 | print("IPPseconds",dataOut.ippSeconds) |
|
1325 | 1326 | |
|
1326 | 1327 | print("ELVALOR DE n es:", n) |
|
1327 | 1328 | if n == None: |
|
1328 | 1329 | raise ValueError("n should be specified.") |
|
1329 | 1330 | |
|
1330 | 1331 | if n != None: |
|
1331 | 1332 | if n<2: |
|
1332 | 1333 | raise ValueError("n should be greater than 2") |
|
1333 | 1334 | |
|
1334 | 1335 | self.n = n |
|
1335 | 1336 | self.__nProf = n |
|
1336 | 1337 | |
|
1337 | 1338 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1338 | 1339 | n, |
|
1339 | 1340 | dataOut.nHeights), |
|
1340 | 1341 | dtype='complex') |
|
1341 | #self.noise = numpy.zeros([self.__nch,self.__nHeis]) | |
|
1342 | #for i in range(self.__nch): | |
|
1343 | # self.noise[i]=dataOut.getNoise(channel=i) | |
|
1344 | 1342 | |
|
1345 | 1343 | def putData(self,data): |
|
1346 | 1344 | ''' |
|
1347 | 1345 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1348 | 1346 | ''' |
|
1349 | 1347 | self.__buffer[:,self.__profIndex,:]= data |
|
1350 | 1348 | self.__profIndex += 1 |
|
1351 | 1349 | return |
|
1352 | 1350 | |
|
1353 | 1351 | def pushData(self,dataOut): |
|
1354 | 1352 | ''' |
|
1355 | 1353 | Return the PULSEPAIR and the profiles used in the operation |
|
1356 | 1354 | Affected : self.__profileIndex |
|
1357 | 1355 | ''' |
|
1356 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1358 | 1357 | if self.removeDC==True: |
|
1359 | 1358 | mean = numpy.mean(self.__buffer,1) |
|
1360 | 1359 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1361 | 1360 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1362 | 1361 | self.__buffer = self.__buffer - dc |
|
1362 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Calculo de Potencia Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1363 | pair0 = self.__buffer*numpy.conj(self.__buffer) | |
|
1364 | pair0 = pair0.real | |
|
1365 | lag_0 = numpy.sum(pair0,1) | |
|
1366 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Calculo de Ruido x canalΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1367 | self.noise = numpy.zeros(self.__nch) | |
|
1368 | for i in range(self.__nch): | |
|
1369 | daux = numpy.sort(pair0[i,:,:],axis= None) | |
|
1370 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) | |
|
1371 | ||
|
1372 | self.noise = self.noise.reshape(self.__nch,1) | |
|
1373 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) | |
|
1374 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) | |
|
1375 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) | |
|
1376 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Potencia recibida= P , Potencia senal = S , Ruido= NΒ·Β· | |
|
1377 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· P= S+N ,P=lag_0/N Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1378 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Power Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1379 | data_power = lag_0/(self.n*self.nCohInt) | |
|
1380 | #------------------ Senal Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1381 | data_intensity = pair0 - noise_buffer | |
|
1382 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) | |
|
1383 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
|
1384 | for i in range(self.__nch): | |
|
1385 | for j in range(self.__nHeis): | |
|
1386 | if data_intensity[i][j] < 0: | |
|
1387 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
|
1363 | 1388 | |
|
1364 | lag_0 = numpy.sum(self.__buffer*numpy.conj(self.__buffer),1) | |
|
1365 | data_intensity = lag_0/(self.n*self.nCohInt)#*self.nCohInt) | |
|
1366 | ||
|
1389 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo de Frecuencia y Velocidad dopplerΒ·Β·Β·Β·Β·Β·Β·Β· | |
|
1367 | 1390 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1368 | 1391 | lag_1 = numpy.sum(pair1,1) |
|
1369 | #angle = numpy.angle(numpy.sum(pair1,1))*180/(math.pi) | |
|
1370 | data_velocity = (-1.0*self.lambda_/(4*math.pi*self.ippSec))*numpy.angle(lag_1)#self.ippSec*self.nCohInt | |
|
1392 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) | |
|
1393 | data_velocity = (self.lambda_/2.0)*data_freq | |
|
1371 | 1394 | |
|
1372 | self.noise = numpy.zeros([self.__nch,self.__nHeis]) | |
|
1373 | for i in range(self.__nch): | |
|
1374 | self.noise[i]=dataOut.getNoise(channel=i) | |
|
1395 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Potencia promedio estimada de la SenalΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1396 | lag_0 = lag_0/self.n | |
|
1397 | S = lag_0-self.noise | |
|
1375 | 1398 | |
|
1376 | lag_0 = lag_0.real/(self.n) | |
|
1399 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Frecuencia Doppler promedio Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1377 | 1400 | lag_1 = lag_1/(self.n-1) |
|
1378 | 1401 | R1 = numpy.abs(lag_1) |
|
1379 | S = (lag_0-self.noise) | |
|
1380 | 1402 | |
|
1403 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo del SNRΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1381 | 1404 | data_snrPP = S/self.noise |
|
1382 | data_snrPP = numpy.where(data_snrPP<0,1,data_snrPP) | |
|
1405 | for i in range(self.__nch): | |
|
1406 | for j in range(self.__nHeis): | |
|
1407 | if data_snrPP[i][j] < 1.e-20: | |
|
1408 | data_snrPP[i][j] = 1.e-20 | |
|
1383 | 1409 | |
|
1410 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo del ancho espectral Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
1384 | 1411 | L = S/R1 |
|
1385 | 1412 | L = numpy.where(L<0,1,L) |
|
1386 | 1413 | L = numpy.log(L) |
|
1387 | ||
|
1388 | 1414 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1389 | ||
|
1390 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*tmp*numpy.sign(L) | |
|
1391 | #data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*k | |
|
1415 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) | |
|
1392 | 1416 | n = self.__profIndex |
|
1393 | 1417 | |
|
1394 | 1418 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1395 | 1419 | self.__profIndex = 0 |
|
1396 | return data_intensity,data_velocity,data_snrPP,data_specwidth,n | |
|
1420 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n | |
|
1397 | 1421 | |
|
1398 | 1422 | def pulsePairbyProfiles(self,dataOut): |
|
1399 | 1423 | |
|
1400 | 1424 | self.__dataReady = False |
|
1425 | data_power = None | |
|
1401 | 1426 | data_intensity = None |
|
1402 | 1427 | data_velocity = None |
|
1403 | 1428 | data_specwidth = None |
|
1404 | 1429 | data_snrPP = None |
|
1405 | 1430 | self.putData(data=dataOut.data) |
|
1406 | 1431 | if self.__profIndex == self.n: |
|
1407 | #self.noise = numpy.zeros([self.__nch,self.__nHeis]) | |
|
1408 | #for i in range(self.__nch): | |
|
1409 | # self.noise[i]=data.getNoise(channel=i) | |
|
1410 | #print(self.noise.shape) | |
|
1411 | data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) | |
|
1432 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) | |
|
1412 | 1433 | self.__dataReady = True |
|
1413 | 1434 | |
|
1414 | return data_intensity, data_velocity,data_snrPP,data_specwidth | |
|
1435 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth | |
|
1415 | 1436 | |
|
1416 | 1437 | def pulsePairOp(self, dataOut, datatime= None): |
|
1417 | 1438 | |
|
1418 | 1439 | if self.__initime == None: |
|
1419 | 1440 | self.__initime = datatime |
|
1420 | #print("hola") | |
|
1421 | data_intensity, data_velocity,data_snrPP,data_specwidth = self.pulsePairbyProfiles(dataOut) | |
|
1441 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) | |
|
1422 | 1442 | self.__lastdatatime = datatime |
|
1423 | 1443 | |
|
1424 |
if data_ |
|
|
1425 | return None, None,None,None,None | |
|
1444 | if data_power is None: | |
|
1445 | return None, None, None,None,None,None | |
|
1426 | 1446 | |
|
1427 | 1447 | avgdatatime = self.__initime |
|
1428 | 1448 | deltatime = datatime - self.__lastdatatime |
|
1429 | 1449 | self.__initime = datatime |
|
1430 | 1450 | |
|
1431 | return data_intensity, data_velocity,data_snrPP,data_specwidth,avgdatatime | |
|
1451 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime | |
|
1432 | 1452 | |
|
1433 | 1453 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1434 | 1454 | |
|
1435 | 1455 | if not self.isConfig: |
|
1436 | 1456 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1437 | 1457 | self.isConfig = True |
|
1438 | data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
|
1458 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
|
1439 | 1459 | dataOut.flagNoData = True |
|
1440 | 1460 | |
|
1441 | 1461 | if self.__dataReady: |
|
1442 | 1462 | dataOut.nCohInt *= self.n |
|
1443 |
dataOut.data |
|
|
1444 |
dataOut.data |
|
|
1445 |
dataOut.data |
|
|
1446 |
dataOut.data |
|
|
1463 | dataOut.dataPP_POW = data_intensity # S | |
|
1464 | dataOut.dataPP_POWER = data_power # P | |
|
1465 | dataOut.dataPP_DOP = data_velocity | |
|
1466 | dataOut.dataPP_SNR = data_snrPP | |
|
1467 | dataOut.dataPP_WIDTH = data_specwidth | |
|
1447 | 1468 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1448 | 1469 | dataOut.utctime = avgdatatime |
|
1449 | 1470 | dataOut.flagNoData = False |
|
1450 | 1471 | return dataOut |
|
1451 | 1472 | |
|
1452 | 1473 | |
|
1453 | 1474 | # import collections |
|
1454 | 1475 | # from scipy.stats import mode |
|
1455 | 1476 | # |
|
1456 | 1477 | # class Synchronize(Operation): |
|
1457 | 1478 | # |
|
1458 | 1479 | # isConfig = False |
|
1459 | 1480 | # __profIndex = 0 |
|
1460 | 1481 | # |
|
1461 | 1482 | # def __init__(self, **kwargs): |
|
1462 | 1483 | # |
|
1463 | 1484 | # Operation.__init__(self, **kwargs) |
|
1464 | 1485 | # # self.isConfig = False |
|
1465 | 1486 | # self.__powBuffer = None |
|
1466 | 1487 | # self.__startIndex = 0 |
|
1467 | 1488 | # self.__pulseFound = False |
|
1468 | 1489 | # |
|
1469 | 1490 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1470 | 1491 | # |
|
1471 | 1492 | # #Read data |
|
1472 | 1493 | # |
|
1473 | 1494 | # powerdB = dataOut.getPower(channel = channel) |
|
1474 | 1495 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1475 | 1496 | # |
|
1476 | 1497 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1477 | 1498 | # |
|
1478 | 1499 | # dataArray = numpy.array(self.__powBuffer) |
|
1479 | 1500 | # |
|
1480 | 1501 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1481 | 1502 | # |
|
1482 | 1503 | # maxValue = numpy.nanmax(filteredPower) |
|
1483 | 1504 | # |
|
1484 | 1505 | # if maxValue < noisedB + 10: |
|
1485 | 1506 | # #No se encuentra ningun pulso de transmision |
|
1486 | 1507 | # return None |
|
1487 | 1508 | # |
|
1488 | 1509 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1489 | 1510 | # |
|
1490 | 1511 | # if len(maxValuesIndex) < 2: |
|
1491 | 1512 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1492 | 1513 | # return None |
|
1493 | 1514 | # |
|
1494 | 1515 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1495 | 1516 | # |
|
1496 | 1517 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1497 | 1518 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1498 | 1519 | # |
|
1499 | 1520 | # if len(pulseIndex) < 2: |
|
1500 | 1521 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1501 | 1522 | # return None |
|
1502 | 1523 | # |
|
1503 | 1524 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1504 | 1525 | # |
|
1505 | 1526 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1506 | 1527 | # #(No deberian existir IPP menor a 10 unidades) |
|
1507 | 1528 | # |
|
1508 | 1529 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1509 | 1530 | # |
|
1510 | 1531 | # if len(realIndex) < 2: |
|
1511 | 1532 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1512 | 1533 | # return None |
|
1513 | 1534 | # |
|
1514 | 1535 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1515 | 1536 | # realPulseIndex = pulseIndex[realIndex] |
|
1516 | 1537 | # |
|
1517 | 1538 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1518 | 1539 | # |
|
1519 | 1540 | # print "IPP = %d samples" %period |
|
1520 | 1541 | # |
|
1521 | 1542 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1522 | 1543 | # self.__startIndex = int(realPulseIndex[0]) |
|
1523 | 1544 | # |
|
1524 | 1545 | # return 1 |
|
1525 | 1546 | # |
|
1526 | 1547 | # |
|
1527 | 1548 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1528 | 1549 | # |
|
1529 | 1550 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1530 | 1551 | # maxlen = buffer_size*nSamples) |
|
1531 | 1552 | # |
|
1532 | 1553 | # bufferList = [] |
|
1533 | 1554 | # |
|
1534 | 1555 | # for i in range(nChannels): |
|
1535 | 1556 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1536 | 1557 | # maxlen = buffer_size*nSamples) |
|
1537 | 1558 | # |
|
1538 | 1559 | # bufferList.append(bufferByChannel) |
|
1539 | 1560 | # |
|
1540 | 1561 | # self.__nSamples = nSamples |
|
1541 | 1562 | # self.__nChannels = nChannels |
|
1542 | 1563 | # self.__bufferList = bufferList |
|
1543 | 1564 | # |
|
1544 | 1565 | # def run(self, dataOut, channel = 0): |
|
1545 | 1566 | # |
|
1546 | 1567 | # if not self.isConfig: |
|
1547 | 1568 | # nSamples = dataOut.nHeights |
|
1548 | 1569 | # nChannels = dataOut.nChannels |
|
1549 | 1570 | # self.setup(nSamples, nChannels) |
|
1550 | 1571 | # self.isConfig = True |
|
1551 | 1572 | # |
|
1552 | 1573 | # #Append new data to internal buffer |
|
1553 | 1574 | # for thisChannel in range(self.__nChannels): |
|
1554 | 1575 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1555 | 1576 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1556 | 1577 | # |
|
1557 | 1578 | # if self.__pulseFound: |
|
1558 | 1579 | # self.__startIndex -= self.__nSamples |
|
1559 | 1580 | # |
|
1560 | 1581 | # #Finding Tx Pulse |
|
1561 | 1582 | # if not self.__pulseFound: |
|
1562 | 1583 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1563 | 1584 | # |
|
1564 | 1585 | # if indexFound == None: |
|
1565 | 1586 | # dataOut.flagNoData = True |
|
1566 | 1587 | # return |
|
1567 | 1588 | # |
|
1568 | 1589 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1569 | 1590 | # self.__pulseFound = True |
|
1570 | 1591 | # self.__startIndex = indexFound |
|
1571 | 1592 | # |
|
1572 | 1593 | # #If pulse was found ... |
|
1573 | 1594 | # for thisChannel in range(self.__nChannels): |
|
1574 | 1595 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1575 | 1596 | # #print self.__startIndex |
|
1576 | 1597 | # x = numpy.array(bufferByChannel) |
|
1577 | 1598 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1578 | 1599 | # |
|
1579 | 1600 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1580 | 1601 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1581 | 1602 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1582 | 1603 | # |
|
1583 | 1604 | # dataOut.data = self.__arrayBuffer |
|
1584 | 1605 | # |
|
1585 | 1606 | # self.__startIndex += self.__newNSamples |
|
1586 | 1607 | # |
|
1587 | 1608 | # return |
@@ -1,49 +1,76 | |||
|
1 | 1 | import os,sys |
|
2 | 2 | import datetime |
|
3 | 3 | import time |
|
4 | 4 | from schainpy.controller import Project |
|
5 | path = '/home/alex/Downloads/NEW_WR2/spc16removeDC' | |
|
6 | figpath = path | |
|
5 | #path = '/home/alex/Downloads/NEW_WR2/spc16removeDC' | |
|
6 | #figpath = path | |
|
7 | ||
|
8 | path = '/home/alex/Downloads/test_rawdata' | |
|
9 | figpath = '/home/alex/Downloads/hdf5_testPP' | |
|
7 | 10 | desc = "Simulator Test" |
|
8 | 11 | |
|
9 | 12 | controllerObj = Project() |
|
10 | 13 | |
|
11 | 14 | controllerObj.setup(id='10',name='Test Simulator',description=desc) |
|
12 | 15 | |
|
13 | 16 | readUnitConfObj = controllerObj.addReadUnit(datatype='SimulatorReader', |
|
14 | 17 | frequency=9.345e9, |
|
15 | 18 | FixRCP_IPP= 60, |
|
16 | 19 | Tau_0 = 30, |
|
17 | 20 | AcqH0_0=0, |
|
18 | 21 | samples=330, |
|
19 | 22 | AcqDH_0=0.15, |
|
20 | 23 | FixRCP_TXA=0.15, |
|
21 | 24 | FixRCP_TXB=0.15, |
|
22 | 25 | Fdoppler=600.0, |
|
23 | 26 | Hdoppler=36, |
|
24 | 27 | Adoppler=300,#300 |
|
25 | 28 | delay=0, |
|
26 | 29 | online=0, |
|
27 | 30 | walk=0, |
|
28 |
|
|
|
29 | ||
|
30 | opObj11 = readUnitConfObj.addOperation(name='printInfo') | |
|
31 | profilesPerBlock=625, | |
|
32 | dataBlocksPerFile=100)#,#nTotalReadFiles=2) | |
|
31 | 33 | |
|
34 | ''' | |
|
35 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', | |
|
36 | path=path, | |
|
37 | startDate="2020/01/01", #"2020/01/01",#today, | |
|
38 | endDate= "2020/12/01", #"2020/12/30",#today, | |
|
39 | startTime='00:00:00', | |
|
40 | endTime='23:59:59', | |
|
41 | delay=0, | |
|
42 | #set=0, | |
|
43 | online=0, | |
|
44 | walk=1) | |
|
45 | ''' | |
|
46 | #opObj11 = readUnitConfObj.addOperation(name='printInfo') | |
|
32 | 47 | procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) |
|
33 | 48 | #opObj11 = procUnitConfObjA.addOperation(name='CohInt', optype='other') |
|
34 |
#opObj11.addParameter(name='n', value=' |
|
|
49 | #opObj11.addParameter(name='n', value='4', format='int') | |
|
35 | 50 | |
|
36 | 51 | #opObj10 = procUnitConfObjA.addOperation(name='selectChannels') |
|
37 | 52 | #opObj10.addParameter(name='channelList', value=[0]) |
|
38 | 53 | opObj11 = procUnitConfObjA.addOperation(name='PulsePairVoltage', optype='other') |
|
39 |
opObj11.addParameter(name='n', value=' |
|
|
54 | opObj11.addParameter(name='n', value='625', format='int')#10 | |
|
40 | 55 | opObj11.addParameter(name='removeDC', value=1, format='int') |
|
41 | 56 | |
|
42 | 57 | #opObj11 = procUnitConfObjA.addOperation(name='PulsepairPowerPlot', optype='other') |
|
58 | #opObj11 = procUnitConfObjA.addOperation(name='PulsepairSignalPlot', optype='other') | |
|
43 | 59 | |
|
44 | opObj11 = procUnitConfObjA.addOperation(name='PulsepairVelocityPlot', optype='other') | |
|
60 | ||
|
61 | #opObj11 = procUnitConfObjA.addOperation(name='PulsepairVelocityPlot', optype='other') | |
|
45 | 62 | #opObj11.addParameter(name='xmax', value=8) |
|
46 | 63 | |
|
47 | opObj11 = procUnitConfObjA.addOperation(name='PulsepairSpecwidthPlot', optype='other') | |
|
64 | #opObj11 = procUnitConfObjA.addOperation(name='PulsepairSpecwidthPlot', optype='other') | |
|
65 | ||
|
66 | procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId()) | |
|
67 | ||
|
68 | ||
|
69 | opObj10 = procUnitConfObjB.addOperation(name='ParameterWriter') | |
|
70 | opObj10.addParameter(name='path',value=figpath) | |
|
71 | #opObj10.addParameter(name='mode',value=0) | |
|
72 | opObj10.addParameter(name='blocksPerFile',value='100',format='int') | |
|
73 | opObj10.addParameter(name='metadataList',value='utctimeInit,timeInterval',format='list') | |
|
74 | opObj10.addParameter(name='dataList',value='dataPP_POW,dataPP_DOP,dataPP_SNR,dataPP_WIDTH')#,format='list' | |
|
48 | 75 | |
|
49 | 76 | controllerObj.start() |
General Comments 0
You need to be logged in to leave comments.
Login now