The requested changes are too big and content was truncated. Show full diff
@@ -1,1363 +1,1353 | |||
|
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 | from schainpy.utils import log |
|
13 | 13 | from .jroheaderIO import SystemHeader, RadarControllerHeader |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | def getNumpyDtype(dataTypeCode): |
|
17 | 17 | |
|
18 | 18 | if dataTypeCode == 0: |
|
19 | 19 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
20 | 20 | elif dataTypeCode == 1: |
|
21 | 21 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
22 | 22 | elif dataTypeCode == 2: |
|
23 | 23 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
24 | 24 | elif dataTypeCode == 3: |
|
25 | 25 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
26 | 26 | elif dataTypeCode == 4: |
|
27 | 27 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
28 | 28 | elif dataTypeCode == 5: |
|
29 | 29 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
30 | 30 | else: |
|
31 | 31 | raise ValueError('dataTypeCode was not defined') |
|
32 | 32 | |
|
33 | 33 | return numpyDtype |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | def getDataTypeCode(numpyDtype): |
|
37 | 37 | |
|
38 | 38 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): |
|
39 | 39 | datatype = 0 |
|
40 | 40 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): |
|
41 | 41 | datatype = 1 |
|
42 | 42 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): |
|
43 | 43 | datatype = 2 |
|
44 | 44 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): |
|
45 | 45 | datatype = 3 |
|
46 | 46 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): |
|
47 | 47 | datatype = 4 |
|
48 | 48 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): |
|
49 | 49 | datatype = 5 |
|
50 | 50 | else: |
|
51 | 51 | datatype = None |
|
52 | 52 | |
|
53 | 53 | return datatype |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | def hildebrand_sekhon(data, navg): |
|
57 | 57 | """ |
|
58 | 58 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
59 | 59 | implementation technique is based on the fact that the standard deviation of the spectral |
|
60 | 60 | densities is equal to the mean spectral density for white Gaussian noise |
|
61 | 61 | |
|
62 | 62 | Inputs: |
|
63 | 63 | Data : heights |
|
64 | 64 | navg : numbers of averages |
|
65 | 65 | |
|
66 | 66 | Return: |
|
67 | 67 | mean : noise's level |
|
68 | 68 | """ |
|
69 | 69 | |
|
70 | 70 | sortdata = numpy.sort(data, axis=None) |
|
71 | 71 | lenOfData = len(sortdata) |
|
72 | 72 | nums_min = lenOfData*0.2 |
|
73 | 73 | |
|
74 | 74 | if nums_min <= 5: |
|
75 | 75 | |
|
76 | 76 | nums_min = 5 |
|
77 | 77 | |
|
78 | 78 | sump = 0. |
|
79 | 79 | sumq = 0. |
|
80 | 80 | |
|
81 | 81 | j = 0 |
|
82 | 82 | cont = 1 |
|
83 | 83 | |
|
84 | 84 | while((cont == 1)and(j < lenOfData)): |
|
85 | 85 | |
|
86 | 86 | sump += sortdata[j] |
|
87 | 87 | sumq += sortdata[j]**2 |
|
88 | 88 | |
|
89 | 89 | if j > nums_min: |
|
90 | 90 | rtest = float(j)/(j-1) + 1.0/navg |
|
91 | 91 | if ((sumq*j) > (rtest*sump**2)): |
|
92 | 92 | j = j - 1 |
|
93 | 93 | sump = sump - sortdata[j] |
|
94 | 94 | sumq = sumq - sortdata[j]**2 |
|
95 | 95 | cont = 0 |
|
96 | 96 | |
|
97 | 97 | j += 1 |
|
98 | 98 | |
|
99 | 99 | lnoise = sump / j |
|
100 | 100 | |
|
101 | 101 | return lnoise |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | class Beam: |
|
105 | 105 | |
|
106 | 106 | def __init__(self): |
|
107 | 107 | self.codeList = [] |
|
108 | 108 | self.azimuthList = [] |
|
109 | 109 | self.zenithList = [] |
|
110 | 110 | |
|
111 | 111 | |
|
112 | 112 | class GenericData(object): |
|
113 | 113 | |
|
114 | 114 | flagNoData = True |
|
115 | 115 | |
|
116 | 116 | def copy(self, inputObj=None): |
|
117 | 117 | |
|
118 | 118 | if inputObj == None: |
|
119 | 119 | return copy.deepcopy(self) |
|
120 | 120 | |
|
121 | 121 | for key in list(inputObj.__dict__.keys()): |
|
122 | 122 | |
|
123 | 123 | attribute = inputObj.__dict__[key] |
|
124 | 124 | |
|
125 | 125 | # If this attribute is a tuple or list |
|
126 | 126 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
127 | 127 | self.__dict__[key] = attribute[:] |
|
128 | 128 | continue |
|
129 | 129 | |
|
130 | 130 | # If this attribute is another object or instance |
|
131 | 131 | if hasattr(attribute, '__dict__'): |
|
132 | 132 | self.__dict__[key] = attribute.copy() |
|
133 | 133 | continue |
|
134 | 134 | |
|
135 | 135 | self.__dict__[key] = inputObj.__dict__[key] |
|
136 | 136 | |
|
137 | 137 | def deepcopy(self): |
|
138 | 138 | |
|
139 | 139 | return copy.deepcopy(self) |
|
140 | 140 | |
|
141 | 141 | def isEmpty(self): |
|
142 | 142 | |
|
143 | 143 | return self.flagNoData |
|
144 | 144 | |
|
145 | 145 | |
|
146 | 146 | class JROData(GenericData): |
|
147 | 147 | |
|
148 | 148 | # m_BasicHeader = BasicHeader() |
|
149 | 149 | # m_ProcessingHeader = ProcessingHeader() |
|
150 | 150 | |
|
151 | 151 | systemHeaderObj = SystemHeader() |
|
152 | 152 | radarControllerHeaderObj = RadarControllerHeader() |
|
153 | 153 | # data = None |
|
154 | 154 | type = None |
|
155 | 155 | datatype = None # dtype but in string |
|
156 | 156 | # dtype = None |
|
157 | 157 | # nChannels = None |
|
158 | 158 | # nHeights = None |
|
159 | 159 | nProfiles = None |
|
160 | 160 | heightList = None |
|
161 | 161 | channelList = None |
|
162 | 162 | flagDiscontinuousBlock = False |
|
163 | 163 | useLocalTime = False |
|
164 | 164 | utctime = None |
|
165 | 165 | timeZone = None |
|
166 | 166 | dstFlag = None |
|
167 | 167 | errorCount = None |
|
168 | 168 | blocksize = None |
|
169 | 169 | # nCode = None |
|
170 | 170 | # nBaud = None |
|
171 | 171 | # code = None |
|
172 | 172 | flagDecodeData = False # asumo q la data no esta decodificada |
|
173 | 173 | flagDeflipData = False # asumo q la data no esta sin flip |
|
174 | 174 | flagShiftFFT = False |
|
175 | 175 | # ippSeconds = None |
|
176 | 176 | # timeInterval = None |
|
177 | 177 | nCohInt = None |
|
178 | 178 | # noise = None |
|
179 | 179 | windowOfFilter = 1 |
|
180 | 180 | # Speed of ligth |
|
181 | 181 | C = 3e8 |
|
182 | 182 | frequency = 49.92e6 |
|
183 | 183 | realtime = False |
|
184 | 184 | beacon_heiIndexList = None |
|
185 | 185 | last_block = None |
|
186 | 186 | blocknow = None |
|
187 | 187 | azimuth = None |
|
188 | 188 | zenith = None |
|
189 | 189 | beam = Beam() |
|
190 | 190 | profileIndex = None |
|
191 | 191 | error = None |
|
192 | 192 | data = None |
|
193 | 193 | nmodes = None |
|
194 | 194 | |
|
195 | 195 | def __str__(self): |
|
196 | 196 | |
|
197 | 197 | return '{} - {}'.format(self.type, self.getDatatime()) |
|
198 | 198 | |
|
199 | 199 | def getNoise(self): |
|
200 | 200 | |
|
201 | 201 | raise NotImplementedError |
|
202 | 202 | |
|
203 | 203 | def getNChannels(self): |
|
204 | 204 | |
|
205 | 205 | return len(self.channelList) |
|
206 | 206 | |
|
207 | 207 | def getChannelIndexList(self): |
|
208 | 208 | |
|
209 | 209 | return list(range(self.nChannels)) |
|
210 | 210 | |
|
211 | 211 | def getNHeights(self): |
|
212 | 212 | |
|
213 | 213 | return len(self.heightList) |
|
214 | 214 | |
|
215 | 215 | def getHeiRange(self, extrapoints=0): |
|
216 | 216 | |
|
217 | 217 | heis = self.heightList |
|
218 | 218 | # deltah = self.heightList[1] - self.heightList[0] |
|
219 | 219 | # |
|
220 | 220 | # heis.append(self.heightList[-1]) |
|
221 | 221 | |
|
222 | 222 | return heis |
|
223 | 223 | |
|
224 | 224 | def getDeltaH(self): |
|
225 | 225 | |
|
226 | 226 | delta = self.heightList[1] - self.heightList[0] |
|
227 | 227 | |
|
228 | 228 | return delta |
|
229 | 229 | |
|
230 | 230 | def getltctime(self): |
|
231 | 231 | |
|
232 | 232 | if self.useLocalTime: |
|
233 | 233 | return self.utctime - self.timeZone * 60 |
|
234 | 234 | |
|
235 | 235 | return self.utctime |
|
236 | 236 | |
|
237 | 237 | def getDatatime(self): |
|
238 | 238 | |
|
239 | 239 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
240 | 240 | return datatimeValue |
|
241 | 241 | |
|
242 | 242 | def getTimeRange(self): |
|
243 | 243 | |
|
244 | 244 | datatime = [] |
|
245 | 245 | |
|
246 | 246 | datatime.append(self.ltctime) |
|
247 | 247 | datatime.append(self.ltctime + self.timeInterval + 1) |
|
248 | 248 | |
|
249 | 249 | datatime = numpy.array(datatime) |
|
250 | 250 | |
|
251 | 251 | return datatime |
|
252 | 252 | |
|
253 | 253 | def getFmaxTimeResponse(self): |
|
254 | 254 | |
|
255 | 255 | period = (10**-6) * self.getDeltaH() / (0.15) |
|
256 | 256 | |
|
257 | 257 | PRF = 1. / (period * self.nCohInt) |
|
258 | 258 | |
|
259 | 259 | fmax = PRF |
|
260 | 260 | |
|
261 | 261 | return fmax |
|
262 | 262 | |
|
263 | 263 | def getFmax(self): |
|
264 | 264 | PRF = 1. / (self.ippSeconds * self.nCohInt) |
|
265 | 265 | |
|
266 | 266 | fmax = PRF |
|
267 | 267 | return fmax |
|
268 | 268 | |
|
269 | 269 | def getVmax(self): |
|
270 | 270 | |
|
271 | 271 | _lambda = self.C / self.frequency |
|
272 | 272 | |
|
273 | 273 | vmax = self.getFmax() * _lambda / 2 |
|
274 | 274 | |
|
275 | 275 | return vmax |
|
276 | 276 | |
|
277 | 277 | def get_ippSeconds(self): |
|
278 | 278 | ''' |
|
279 | 279 | ''' |
|
280 | 280 | return self.radarControllerHeaderObj.ippSeconds |
|
281 | 281 | |
|
282 | 282 | def set_ippSeconds(self, ippSeconds): |
|
283 | 283 | ''' |
|
284 | 284 | ''' |
|
285 | 285 | |
|
286 | 286 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
287 | 287 | |
|
288 | 288 | return |
|
289 | 289 | |
|
290 | 290 | def get_dtype(self): |
|
291 | 291 | ''' |
|
292 | 292 | ''' |
|
293 | 293 | return getNumpyDtype(self.datatype) |
|
294 | 294 | |
|
295 | 295 | def set_dtype(self, numpyDtype): |
|
296 | 296 | ''' |
|
297 | 297 | ''' |
|
298 | 298 | |
|
299 | 299 | self.datatype = getDataTypeCode(numpyDtype) |
|
300 | 300 | |
|
301 | 301 | def get_code(self): |
|
302 | 302 | ''' |
|
303 | 303 | ''' |
|
304 | 304 | return self.radarControllerHeaderObj.code |
|
305 | 305 | |
|
306 | 306 | def set_code(self, code): |
|
307 | 307 | ''' |
|
308 | 308 | ''' |
|
309 | 309 | self.radarControllerHeaderObj.code = code |
|
310 | 310 | |
|
311 | 311 | return |
|
312 | 312 | |
|
313 | 313 | def get_ncode(self): |
|
314 | 314 | ''' |
|
315 | 315 | ''' |
|
316 | 316 | return self.radarControllerHeaderObj.nCode |
|
317 | 317 | |
|
318 | 318 | def set_ncode(self, nCode): |
|
319 | 319 | ''' |
|
320 | 320 | ''' |
|
321 | 321 | self.radarControllerHeaderObj.nCode = nCode |
|
322 | 322 | |
|
323 | 323 | return |
|
324 | 324 | |
|
325 | 325 | def get_nbaud(self): |
|
326 | 326 | ''' |
|
327 | 327 | ''' |
|
328 | 328 | return self.radarControllerHeaderObj.nBaud |
|
329 | 329 | |
|
330 | 330 | def set_nbaud(self, nBaud): |
|
331 | 331 | ''' |
|
332 | 332 | ''' |
|
333 | 333 | self.radarControllerHeaderObj.nBaud = nBaud |
|
334 | 334 | |
|
335 | 335 | return |
|
336 | 336 | |
|
337 | 337 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
338 | 338 | channelIndexList = property( |
|
339 | 339 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
340 | 340 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
341 | 341 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
342 | 342 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
343 | 343 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
344 | 344 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
345 | 345 | dtype = property(get_dtype, set_dtype) |
|
346 | 346 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
347 | 347 | code = property(get_code, set_code) |
|
348 | 348 | nCode = property(get_ncode, set_ncode) |
|
349 | 349 | nBaud = property(get_nbaud, set_nbaud) |
|
350 | 350 | |
|
351 | 351 | |
|
352 | 352 | class Voltage(JROData): |
|
353 | 353 | |
|
354 | 354 | # data es un numpy array de 2 dmensiones (canales, alturas) |
|
355 | 355 | data = None |
|
356 | 356 | |
|
357 | 357 | def __init__(self): |
|
358 | 358 | ''' |
|
359 | 359 | Constructor |
|
360 | 360 | ''' |
|
361 | 361 | |
|
362 | 362 | self.useLocalTime = True |
|
363 | 363 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
364 | 364 | self.systemHeaderObj = SystemHeader() |
|
365 | 365 | self.type = "Voltage" |
|
366 | 366 | self.data = None |
|
367 | 367 | # self.dtype = None |
|
368 | 368 | # self.nChannels = 0 |
|
369 | 369 | # self.nHeights = 0 |
|
370 | 370 | self.nProfiles = None |
|
371 | 371 | self.heightList = None |
|
372 | 372 | self.channelList = None |
|
373 | 373 | # self.channelIndexList = None |
|
374 | 374 | self.flagNoData = True |
|
375 | 375 | self.flagDiscontinuousBlock = False |
|
376 | 376 | self.utctime = None |
|
377 | 377 | self.timeZone = None |
|
378 | 378 | self.dstFlag = None |
|
379 | 379 | self.errorCount = None |
|
380 | 380 | self.nCohInt = None |
|
381 | 381 | self.blocksize = None |
|
382 | 382 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
383 | 383 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
384 | 384 | self.flagShiftFFT = False |
|
385 | 385 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil |
|
386 | 386 | self.profileIndex = 0 |
|
387 | 387 | |
|
388 | 388 | def getNoisebyHildebrand(self, channel=None): |
|
389 | 389 | """ |
|
390 | 390 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
391 | 391 | |
|
392 | 392 | Return: |
|
393 | 393 | noiselevel |
|
394 | 394 | """ |
|
395 | 395 | |
|
396 | 396 | if channel != None: |
|
397 | 397 | data = self.data[channel] |
|
398 | 398 | nChannels = 1 |
|
399 | 399 | else: |
|
400 | 400 | data = self.data |
|
401 | 401 | nChannels = self.nChannels |
|
402 | 402 | |
|
403 | 403 | noise = numpy.zeros(nChannels) |
|
404 | 404 | power = data * numpy.conjugate(data) |
|
405 | 405 | |
|
406 | 406 | for thisChannel in range(nChannels): |
|
407 | 407 | if nChannels == 1: |
|
408 | 408 | daux = power[:].real |
|
409 | 409 | else: |
|
410 | 410 | daux = power[thisChannel, :].real |
|
411 | 411 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
412 | 412 | |
|
413 | 413 | return noise |
|
414 | 414 | |
|
415 | 415 | def getNoise(self, type=1, channel=None): |
|
416 | 416 | |
|
417 | 417 | if type == 1: |
|
418 | 418 | noise = self.getNoisebyHildebrand(channel) |
|
419 | 419 | |
|
420 | 420 | return noise |
|
421 | 421 | |
|
422 | 422 | def getPower(self, channel=None): |
|
423 | 423 | |
|
424 | 424 | if channel != None: |
|
425 | 425 | data = self.data[channel] |
|
426 | 426 | else: |
|
427 | 427 | data = self.data |
|
428 | 428 | |
|
429 | 429 | power = data * numpy.conjugate(data) |
|
430 | 430 | powerdB = 10 * numpy.log10(power.real) |
|
431 | 431 | powerdB = numpy.squeeze(powerdB) |
|
432 | 432 | |
|
433 | 433 | return powerdB |
|
434 | 434 | |
|
435 | 435 | def getTimeInterval(self): |
|
436 | 436 | |
|
437 | 437 | timeInterval = self.ippSeconds * self.nCohInt |
|
438 | 438 | |
|
439 | 439 | return timeInterval |
|
440 | 440 | |
|
441 | 441 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
442 | 442 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
443 | 443 | |
|
444 | 444 | |
|
445 | 445 | class Spectra(JROData): |
|
446 | 446 | |
|
447 | 447 | # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
448 | 448 | data_spc = None |
|
449 | 449 | # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
450 | 450 | data_cspc = None |
|
451 | 451 | # data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
452 | 452 | data_dc = None |
|
453 | 453 | # data power |
|
454 | 454 | data_pwr = None |
|
455 | 455 | nFFTPoints = None |
|
456 | 456 | # nPairs = None |
|
457 | 457 | pairsList = None |
|
458 | 458 | nIncohInt = None |
|
459 | 459 | wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia |
|
460 | 460 | nCohInt = None # se requiere para determinar el valor de timeInterval |
|
461 | 461 | ippFactor = None |
|
462 | 462 | profileIndex = 0 |
|
463 | 463 | plotting = "spectra" |
|
464 | 464 | |
|
465 | 465 | def __init__(self): |
|
466 | 466 | ''' |
|
467 | 467 | Constructor |
|
468 | 468 | ''' |
|
469 | 469 | |
|
470 | 470 | self.useLocalTime = True |
|
471 | 471 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
472 | 472 | self.systemHeaderObj = SystemHeader() |
|
473 | 473 | self.type = "Spectra" |
|
474 | 474 | # self.data = None |
|
475 | 475 | # self.dtype = None |
|
476 | 476 | # self.nChannels = 0 |
|
477 | 477 | # self.nHeights = 0 |
|
478 | 478 | self.nProfiles = None |
|
479 | 479 | self.heightList = None |
|
480 | 480 | self.channelList = None |
|
481 | 481 | # self.channelIndexList = None |
|
482 | 482 | self.pairsList = None |
|
483 | 483 | self.flagNoData = True |
|
484 | 484 | self.flagDiscontinuousBlock = False |
|
485 | 485 | self.utctime = None |
|
486 | 486 | self.nCohInt = None |
|
487 | 487 | self.nIncohInt = None |
|
488 | 488 | self.blocksize = None |
|
489 | 489 | self.nFFTPoints = None |
|
490 | 490 | self.wavelength = None |
|
491 | 491 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
492 | 492 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
493 | 493 | self.flagShiftFFT = False |
|
494 | 494 | self.ippFactor = 1 |
|
495 | 495 | #self.noise = None |
|
496 | 496 | self.beacon_heiIndexList = [] |
|
497 | 497 | self.noise_estimation = None |
|
498 | 498 | |
|
499 | 499 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
500 | 500 | """ |
|
501 | 501 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
502 | 502 | |
|
503 | 503 | Return: |
|
504 | 504 | noiselevel |
|
505 | 505 | """ |
|
506 | 506 | |
|
507 | 507 | noise = numpy.zeros(self.nChannels) |
|
508 | 508 | |
|
509 | 509 | for channel in range(self.nChannels): |
|
510 | 510 | daux = self.data_spc[channel, |
|
511 | 511 | xmin_index:xmax_index, ymin_index:ymax_index] |
|
512 | 512 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
513 | 513 | |
|
514 | 514 | return noise |
|
515 | 515 | |
|
516 | 516 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
517 | 517 | |
|
518 | 518 | if self.noise_estimation is not None: |
|
519 | 519 | # this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
520 | 520 | return self.noise_estimation |
|
521 | 521 | else: |
|
522 | 522 | noise = self.getNoisebyHildebrand( |
|
523 | 523 | xmin_index, xmax_index, ymin_index, ymax_index) |
|
524 | 524 | return noise |
|
525 | 525 | |
|
526 | 526 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
527 | 527 | |
|
528 | 528 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) |
|
529 | freqrange = deltafreq * \ | |
|
530 | (numpy.arange(self.nFFTPoints + extrapoints) - | |
|
531 | self.nFFTPoints / 2.) - deltafreq / 2 | |
|
529 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 | |
|
532 | 530 | |
|
533 | 531 | return freqrange |
|
534 | 532 | |
|
535 | 533 | def getAcfRange(self, extrapoints=0): |
|
536 | 534 | |
|
537 | 535 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) |
|
538 | freqrange = deltafreq * \ | |
|
539 | (numpy.arange(self.nFFTPoints + extrapoints) - | |
|
540 | self.nFFTPoints / 2.) - deltafreq / 2 | |
|
536 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 | |
|
541 | 537 | |
|
542 | 538 | return freqrange |
|
543 | 539 | |
|
544 | 540 | def getFreqRange(self, extrapoints=0): |
|
545 | 541 | |
|
546 | 542 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) |
|
547 | freqrange = deltafreq * \ | |
|
548 | (numpy.arange(self.nFFTPoints + extrapoints) - | |
|
549 | self.nFFTPoints / 2.) - deltafreq / 2 | |
|
543 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 | |
|
550 | 544 | |
|
551 | 545 | return freqrange |
|
552 | 546 | |
|
553 | 547 | def getVelRange(self, extrapoints=0): |
|
554 | 548 | |
|
555 | 549 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) |
|
556 | velrange = deltav * (numpy.arange(self.nFFTPoints + | |
|
557 | extrapoints) - self.nFFTPoints / 2.) | |
|
550 | velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) | |
|
558 | 551 | |
|
559 | 552 | if self.nmodes: |
|
560 | 553 | return velrange/self.nmodes |
|
561 | 554 | else: |
|
562 | 555 | return velrange |
|
563 | 556 | |
|
564 | 557 | def getNPairs(self): |
|
565 | 558 | |
|
566 | 559 | return len(self.pairsList) |
|
567 | 560 | |
|
568 | 561 | def getPairsIndexList(self): |
|
569 | 562 | |
|
570 | 563 | return list(range(self.nPairs)) |
|
571 | 564 | |
|
572 | 565 | def getNormFactor(self): |
|
573 | 566 | |
|
574 | 567 | pwcode = 1 |
|
575 | 568 | |
|
576 | 569 | if self.flagDecodeData: |
|
577 | 570 | pwcode = numpy.sum(self.code[0]**2) |
|
578 | 571 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
579 |
normFactor = self.nProfiles * self.nIncohInt * |
|
|
580 | self.nCohInt * pwcode * self.windowOfFilter | |
|
572 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter | |
|
581 | 573 | |
|
582 | 574 | return normFactor |
|
583 | 575 | |
|
584 | 576 | def getFlagCspc(self): |
|
585 | 577 | |
|
586 | 578 | if self.data_cspc is None: |
|
587 | 579 | return True |
|
588 | 580 | |
|
589 | 581 | return False |
|
590 | 582 | |
|
591 | 583 | def getFlagDc(self): |
|
592 | 584 | |
|
593 | 585 | if self.data_dc is None: |
|
594 | 586 | return True |
|
595 | 587 | |
|
596 | 588 | return False |
|
597 | 589 | |
|
598 | 590 | def getTimeInterval(self): |
|
599 | 591 | |
|
600 |
timeInterval = self.ippSeconds * self.nCohInt * |
|
|
601 | self.nIncohInt * self.nProfiles * self.ippFactor | |
|
592 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor | |
|
602 | 593 | |
|
603 | 594 | return timeInterval |
|
604 | 595 | |
|
605 | 596 | def getPower(self): |
|
606 | 597 | |
|
607 | 598 | factor = self.normFactor |
|
608 | 599 | z = self.data_spc / factor |
|
609 | 600 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
610 | 601 | avg = numpy.average(z, axis=1) |
|
611 | 602 | |
|
612 | 603 | return 10 * numpy.log10(avg) |
|
613 | 604 | |
|
614 | 605 | def getCoherence(self, pairsList=None, phase=False): |
|
615 | 606 | |
|
616 | 607 | z = [] |
|
617 | 608 | if pairsList is None: |
|
618 | 609 | pairsIndexList = self.pairsIndexList |
|
619 | 610 | else: |
|
620 | 611 | pairsIndexList = [] |
|
621 | 612 | for pair in pairsList: |
|
622 | 613 | if pair not in self.pairsList: |
|
623 | 614 | raise ValueError("Pair %s is not in dataOut.pairsList" % ( |
|
624 | 615 | pair)) |
|
625 | 616 | pairsIndexList.append(self.pairsList.index(pair)) |
|
626 | 617 | for i in range(len(pairsIndexList)): |
|
627 | 618 | pair = self.pairsList[pairsIndexList[i]] |
|
628 | ccf = numpy.average( | |
|
629 | self.data_cspc[pairsIndexList[i], :, :], axis=0) | |
|
619 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) | |
|
630 | 620 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
631 | 621 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
632 | 622 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
633 | 623 | if phase: |
|
634 | 624 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
635 | 625 | avgcoherenceComplex.real) * 180 / numpy.pi |
|
636 | 626 | else: |
|
637 | 627 | data = numpy.abs(avgcoherenceComplex) |
|
638 | 628 | |
|
639 | 629 | z.append(data) |
|
640 | 630 | |
|
641 | 631 | return numpy.array(z) |
|
642 | 632 | |
|
643 | 633 | def setValue(self, value): |
|
644 | 634 | |
|
645 | 635 | print("This property should not be initialized") |
|
646 | 636 | |
|
647 | 637 | return |
|
648 | 638 | |
|
649 | 639 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
650 | 640 | pairsIndexList = property( |
|
651 | 641 | getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
652 | 642 | normFactor = property(getNormFactor, setValue, |
|
653 | 643 | "I'm the 'getNormFactor' property.") |
|
654 | 644 | flag_cspc = property(getFlagCspc, setValue) |
|
655 | 645 | flag_dc = property(getFlagDc, setValue) |
|
656 | 646 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
657 | 647 | timeInterval = property(getTimeInterval, setValue, |
|
658 | 648 | "I'm the 'timeInterval' property") |
|
659 | 649 | |
|
660 | 650 | |
|
661 | 651 | class SpectraHeis(Spectra): |
|
662 | 652 | |
|
663 | 653 | data_spc = None |
|
664 | 654 | data_cspc = None |
|
665 | 655 | data_dc = None |
|
666 | 656 | nFFTPoints = None |
|
667 | 657 | # nPairs = None |
|
668 | 658 | pairsList = None |
|
669 | 659 | nCohInt = None |
|
670 | 660 | nIncohInt = None |
|
671 | 661 | |
|
672 | 662 | def __init__(self): |
|
673 | 663 | |
|
674 | 664 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
675 | 665 | |
|
676 | 666 | self.systemHeaderObj = SystemHeader() |
|
677 | 667 | |
|
678 | 668 | self.type = "SpectraHeis" |
|
679 | 669 | |
|
680 | 670 | # self.dtype = None |
|
681 | 671 | |
|
682 | 672 | # self.nChannels = 0 |
|
683 | 673 | |
|
684 | 674 | # self.nHeights = 0 |
|
685 | 675 | |
|
686 | 676 | self.nProfiles = None |
|
687 | 677 | |
|
688 | 678 | self.heightList = None |
|
689 | 679 | |
|
690 | 680 | self.channelList = None |
|
691 | 681 | |
|
692 | 682 | # self.channelIndexList = None |
|
693 | 683 | |
|
694 | 684 | self.flagNoData = True |
|
695 | 685 | |
|
696 | 686 | self.flagDiscontinuousBlock = False |
|
697 | 687 | |
|
698 | 688 | # self.nPairs = 0 |
|
699 | 689 | |
|
700 | 690 | self.utctime = None |
|
701 | 691 | |
|
702 | 692 | self.blocksize = None |
|
703 | 693 | |
|
704 | 694 | self.profileIndex = 0 |
|
705 | 695 | |
|
706 | 696 | self.nCohInt = 1 |
|
707 | 697 | |
|
708 | 698 | self.nIncohInt = 1 |
|
709 | 699 | |
|
710 | 700 | def getNormFactor(self): |
|
711 | 701 | pwcode = 1 |
|
712 | 702 | if self.flagDecodeData: |
|
713 | 703 | pwcode = numpy.sum(self.code[0]**2) |
|
714 | 704 | |
|
715 | 705 | normFactor = self.nIncohInt * self.nCohInt * pwcode |
|
716 | 706 | |
|
717 | 707 | return normFactor |
|
718 | 708 | |
|
719 | 709 | def getTimeInterval(self): |
|
720 | 710 | |
|
721 | 711 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
722 | 712 | |
|
723 | 713 | return timeInterval |
|
724 | 714 | |
|
725 | 715 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
726 | 716 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
727 | 717 | |
|
728 | 718 | |
|
729 | 719 | class Fits(JROData): |
|
730 | 720 | |
|
731 | 721 | heightList = None |
|
732 | 722 | channelList = None |
|
733 | 723 | flagNoData = True |
|
734 | 724 | flagDiscontinuousBlock = False |
|
735 | 725 | useLocalTime = False |
|
736 | 726 | utctime = None |
|
737 | 727 | timeZone = None |
|
738 | 728 | # ippSeconds = None |
|
739 | 729 | # timeInterval = None |
|
740 | 730 | nCohInt = None |
|
741 | 731 | nIncohInt = None |
|
742 | 732 | noise = None |
|
743 | 733 | windowOfFilter = 1 |
|
744 | 734 | # Speed of ligth |
|
745 | 735 | C = 3e8 |
|
746 | 736 | frequency = 49.92e6 |
|
747 | 737 | realtime = False |
|
748 | 738 | |
|
749 | 739 | def __init__(self): |
|
750 | 740 | |
|
751 | 741 | self.type = "Fits" |
|
752 | 742 | |
|
753 | 743 | self.nProfiles = None |
|
754 | 744 | |
|
755 | 745 | self.heightList = None |
|
756 | 746 | |
|
757 | 747 | self.channelList = None |
|
758 | 748 | |
|
759 | 749 | # self.channelIndexList = None |
|
760 | 750 | |
|
761 | 751 | self.flagNoData = True |
|
762 | 752 | |
|
763 | 753 | self.utctime = None |
|
764 | 754 | |
|
765 | 755 | self.nCohInt = 1 |
|
766 | 756 | |
|
767 | 757 | self.nIncohInt = 1 |
|
768 | 758 | |
|
769 | 759 | self.useLocalTime = True |
|
770 | 760 | |
|
771 | 761 | self.profileIndex = 0 |
|
772 | 762 | |
|
773 | 763 | # self.utctime = None |
|
774 | 764 | # self.timeZone = None |
|
775 | 765 | # self.ltctime = None |
|
776 | 766 | # self.timeInterval = None |
|
777 | 767 | # self.header = None |
|
778 | 768 | # self.data_header = None |
|
779 | 769 | # self.data = None |
|
780 | 770 | # self.datatime = None |
|
781 | 771 | # self.flagNoData = False |
|
782 | 772 | # self.expName = '' |
|
783 | 773 | # self.nChannels = None |
|
784 | 774 | # self.nSamples = None |
|
785 | 775 | # self.dataBlocksPerFile = None |
|
786 | 776 | # self.comments = '' |
|
787 | 777 | # |
|
788 | 778 | |
|
789 | 779 | def getltctime(self): |
|
790 | 780 | |
|
791 | 781 | if self.useLocalTime: |
|
792 | 782 | return self.utctime - self.timeZone * 60 |
|
793 | 783 | |
|
794 | 784 | return self.utctime |
|
795 | 785 | |
|
796 | 786 | def getDatatime(self): |
|
797 | 787 | |
|
798 | 788 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
799 | 789 | return datatime |
|
800 | 790 | |
|
801 | 791 | def getTimeRange(self): |
|
802 | 792 | |
|
803 | 793 | datatime = [] |
|
804 | 794 | |
|
805 | 795 | datatime.append(self.ltctime) |
|
806 | 796 | datatime.append(self.ltctime + self.timeInterval) |
|
807 | 797 | |
|
808 | 798 | datatime = numpy.array(datatime) |
|
809 | 799 | |
|
810 | 800 | return datatime |
|
811 | 801 | |
|
812 | 802 | def getHeiRange(self): |
|
813 | 803 | |
|
814 | 804 | heis = self.heightList |
|
815 | 805 | |
|
816 | 806 | return heis |
|
817 | 807 | |
|
818 | 808 | def getNHeights(self): |
|
819 | 809 | |
|
820 | 810 | return len(self.heightList) |
|
821 | 811 | |
|
822 | 812 | def getNChannels(self): |
|
823 | 813 | |
|
824 | 814 | return len(self.channelList) |
|
825 | 815 | |
|
826 | 816 | def getChannelIndexList(self): |
|
827 | 817 | |
|
828 | 818 | return list(range(self.nChannels)) |
|
829 | 819 | |
|
830 | 820 | def getNoise(self, type=1): |
|
831 | 821 | |
|
832 | 822 | #noise = numpy.zeros(self.nChannels) |
|
833 | 823 | |
|
834 | 824 | if type == 1: |
|
835 | 825 | noise = self.getNoisebyHildebrand() |
|
836 | 826 | |
|
837 | 827 | if type == 2: |
|
838 | 828 | noise = self.getNoisebySort() |
|
839 | 829 | |
|
840 | 830 | if type == 3: |
|
841 | 831 | noise = self.getNoisebyWindow() |
|
842 | 832 | |
|
843 | 833 | return noise |
|
844 | 834 | |
|
845 | 835 | def getTimeInterval(self): |
|
846 | 836 | |
|
847 | 837 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
848 | 838 | |
|
849 | 839 | return timeInterval |
|
850 | 840 | |
|
851 | 841 | def get_ippSeconds(self): |
|
852 | 842 | ''' |
|
853 | 843 | ''' |
|
854 | 844 | return self.ipp_sec |
|
855 | 845 | |
|
856 | 846 | |
|
857 | 847 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
858 | 848 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
859 | 849 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
860 | 850 | channelIndexList = property( |
|
861 | 851 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
862 | 852 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
863 | 853 | |
|
864 | 854 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
865 | 855 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
866 | 856 | ippSeconds = property(get_ippSeconds, '') |
|
867 | 857 | |
|
868 | 858 | class Correlation(JROData): |
|
869 | 859 | |
|
870 | 860 | noise = None |
|
871 | 861 | SNR = None |
|
872 | 862 | #-------------------------------------------------- |
|
873 | 863 | mode = None |
|
874 | 864 | split = False |
|
875 | 865 | data_cf = None |
|
876 | 866 | lags = None |
|
877 | 867 | lagRange = None |
|
878 | 868 | pairsList = None |
|
879 | 869 | normFactor = None |
|
880 | 870 | #-------------------------------------------------- |
|
881 | 871 | # calculateVelocity = None |
|
882 | 872 | nLags = None |
|
883 | 873 | nPairs = None |
|
884 | 874 | nAvg = None |
|
885 | 875 | |
|
886 | 876 | def __init__(self): |
|
887 | 877 | ''' |
|
888 | 878 | Constructor |
|
889 | 879 | ''' |
|
890 | 880 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
891 | 881 | |
|
892 | 882 | self.systemHeaderObj = SystemHeader() |
|
893 | 883 | |
|
894 | 884 | self.type = "Correlation" |
|
895 | 885 | |
|
896 | 886 | self.data = None |
|
897 | 887 | |
|
898 | 888 | self.dtype = None |
|
899 | 889 | |
|
900 | 890 | self.nProfiles = None |
|
901 | 891 | |
|
902 | 892 | self.heightList = None |
|
903 | 893 | |
|
904 | 894 | self.channelList = None |
|
905 | 895 | |
|
906 | 896 | self.flagNoData = True |
|
907 | 897 | |
|
908 | 898 | self.flagDiscontinuousBlock = False |
|
909 | 899 | |
|
910 | 900 | self.utctime = None |
|
911 | 901 | |
|
912 | 902 | self.timeZone = None |
|
913 | 903 | |
|
914 | 904 | self.dstFlag = None |
|
915 | 905 | |
|
916 | 906 | self.errorCount = None |
|
917 | 907 | |
|
918 | 908 | self.blocksize = None |
|
919 | 909 | |
|
920 | 910 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
921 | 911 | |
|
922 | 912 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
923 | 913 | |
|
924 | 914 | self.pairsList = None |
|
925 | 915 | |
|
926 | 916 | self.nPoints = None |
|
927 | 917 | |
|
928 | 918 | def getPairsList(self): |
|
929 | 919 | |
|
930 | 920 | return self.pairsList |
|
931 | 921 | |
|
932 | 922 | def getNoise(self, mode=2): |
|
933 | 923 | |
|
934 | 924 | indR = numpy.where(self.lagR == 0)[0][0] |
|
935 | 925 | indT = numpy.where(self.lagT == 0)[0][0] |
|
936 | 926 | |
|
937 | 927 | jspectra0 = self.data_corr[:, :, indR, :] |
|
938 | 928 | jspectra = copy.copy(jspectra0) |
|
939 | 929 | |
|
940 | 930 | num_chan = jspectra.shape[0] |
|
941 | 931 | num_hei = jspectra.shape[2] |
|
942 | 932 | |
|
943 | 933 | freq_dc = jspectra.shape[1] / 2 |
|
944 | 934 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
945 | 935 | |
|
946 | 936 | if ind_vel[0] < 0: |
|
947 | 937 | ind_vel[list(range(0, 1))] = ind_vel[list( |
|
948 | 938 | range(0, 1))] + self.num_prof |
|
949 | 939 | |
|
950 | 940 | if mode == 1: |
|
951 | 941 | jspectra[:, freq_dc, :] = ( |
|
952 | 942 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
953 | 943 | |
|
954 | 944 | if mode == 2: |
|
955 | 945 | |
|
956 | 946 | vel = numpy.array([-2, -1, 1, 2]) |
|
957 | 947 | xx = numpy.zeros([4, 4]) |
|
958 | 948 | |
|
959 | 949 | for fil in range(4): |
|
960 | 950 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
961 | 951 | |
|
962 | 952 | xx_inv = numpy.linalg.inv(xx) |
|
963 | 953 | xx_aux = xx_inv[0, :] |
|
964 | 954 | |
|
965 | 955 | for ich in range(num_chan): |
|
966 | 956 | yy = jspectra[ich, ind_vel, :] |
|
967 | 957 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
968 | 958 | |
|
969 | 959 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
970 | 960 | cjunkid = sum(junkid) |
|
971 | 961 | |
|
972 | 962 | if cjunkid.any(): |
|
973 | 963 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
974 | 964 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
975 | 965 | |
|
976 | 966 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] |
|
977 | 967 | |
|
978 | 968 | return noise |
|
979 | 969 | |
|
980 | 970 | def getTimeInterval(self): |
|
981 | 971 | |
|
982 | 972 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
983 | 973 | |
|
984 | 974 | return timeInterval |
|
985 | 975 | |
|
986 | 976 | def splitFunctions(self): |
|
987 | 977 | |
|
988 | 978 | pairsList = self.pairsList |
|
989 | 979 | ccf_pairs = [] |
|
990 | 980 | acf_pairs = [] |
|
991 | 981 | ccf_ind = [] |
|
992 | 982 | acf_ind = [] |
|
993 | 983 | for l in range(len(pairsList)): |
|
994 | 984 | chan0 = pairsList[l][0] |
|
995 | 985 | chan1 = pairsList[l][1] |
|
996 | 986 | |
|
997 | 987 | # Obteniendo pares de Autocorrelacion |
|
998 | 988 | if chan0 == chan1: |
|
999 | 989 | acf_pairs.append(chan0) |
|
1000 | 990 | acf_ind.append(l) |
|
1001 | 991 | else: |
|
1002 | 992 | ccf_pairs.append(pairsList[l]) |
|
1003 | 993 | ccf_ind.append(l) |
|
1004 | 994 | |
|
1005 | 995 | data_acf = self.data_cf[acf_ind] |
|
1006 | 996 | data_ccf = self.data_cf[ccf_ind] |
|
1007 | 997 | |
|
1008 | 998 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1009 | 999 | |
|
1010 | 1000 | def getNormFactor(self): |
|
1011 | 1001 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1012 | 1002 | acf_pairs = numpy.array(acf_pairs) |
|
1013 | 1003 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) |
|
1014 | 1004 | |
|
1015 | 1005 | for p in range(self.nPairs): |
|
1016 | 1006 | pair = self.pairsList[p] |
|
1017 | 1007 | |
|
1018 | 1008 | ch0 = pair[0] |
|
1019 | 1009 | ch1 = pair[1] |
|
1020 | 1010 | |
|
1021 | 1011 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) |
|
1022 | 1012 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) |
|
1023 | 1013 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) |
|
1024 | 1014 | |
|
1025 | 1015 | return normFactor |
|
1026 | 1016 | |
|
1027 | 1017 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1028 | 1018 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1029 | 1019 | |
|
1030 | 1020 | |
|
1031 | 1021 | class Parameters(Spectra): |
|
1032 | 1022 | |
|
1033 | 1023 | experimentInfo = None # Information about the experiment |
|
1034 | 1024 | # Information from previous data |
|
1035 | 1025 | inputUnit = None # Type of data to be processed |
|
1036 | 1026 | operation = None # Type of operation to parametrize |
|
1037 | 1027 | # normFactor = None #Normalization Factor |
|
1038 | 1028 | groupList = None # List of Pairs, Groups, etc |
|
1039 | 1029 | # Parameters |
|
1040 | 1030 | data_param = None # Parameters obtained |
|
1041 | 1031 | data_pre = None # Data Pre Parametrization |
|
1042 | 1032 | data_SNR = None # Signal to Noise Ratio |
|
1043 | 1033 | # heightRange = None #Heights |
|
1044 | 1034 | abscissaList = None # Abscissa, can be velocities, lags or time |
|
1045 | 1035 | # noise = None #Noise Potency |
|
1046 | 1036 | utctimeInit = None # Initial UTC time |
|
1047 | 1037 | paramInterval = None # Time interval to calculate Parameters in seconds |
|
1048 | 1038 | useLocalTime = True |
|
1049 | 1039 | # Fitting |
|
1050 | 1040 | data_error = None # Error of the estimation |
|
1051 | 1041 | constants = None |
|
1052 | 1042 | library = None |
|
1053 | 1043 | # Output signal |
|
1054 | 1044 | outputInterval = None # Time interval to calculate output signal in seconds |
|
1055 | 1045 | data_output = None # Out signal |
|
1056 | 1046 | nAvg = None |
|
1057 | 1047 | noise_estimation = None |
|
1058 | 1048 | GauSPC = None # Fit gaussian SPC |
|
1059 | 1049 | |
|
1060 | 1050 | def __init__(self): |
|
1061 | 1051 | ''' |
|
1062 | 1052 | Constructor |
|
1063 | 1053 | ''' |
|
1064 | 1054 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1065 | 1055 | |
|
1066 | 1056 | self.systemHeaderObj = SystemHeader() |
|
1067 | 1057 | |
|
1068 | 1058 | self.type = "Parameters" |
|
1069 | 1059 | |
|
1070 | 1060 | def getTimeRange1(self, interval): |
|
1071 | 1061 | |
|
1072 | 1062 | datatime = [] |
|
1073 | 1063 | |
|
1074 | 1064 | if self.useLocalTime: |
|
1075 | 1065 | time1 = self.utctimeInit - self.timeZone * 60 |
|
1076 | 1066 | else: |
|
1077 | 1067 | time1 = self.utctimeInit |
|
1078 | 1068 | |
|
1079 | 1069 | datatime.append(time1) |
|
1080 | 1070 | datatime.append(time1 + interval) |
|
1081 | 1071 | datatime = numpy.array(datatime) |
|
1082 | 1072 | |
|
1083 | 1073 | return datatime |
|
1084 | 1074 | |
|
1085 | 1075 | def getTimeInterval(self): |
|
1086 | 1076 | |
|
1087 | 1077 | if hasattr(self, 'timeInterval1'): |
|
1088 | 1078 | return self.timeInterval1 |
|
1089 | 1079 | else: |
|
1090 | 1080 | return self.paramInterval |
|
1091 | 1081 | |
|
1092 | 1082 | def setValue(self, value): |
|
1093 | 1083 | |
|
1094 | 1084 | print("This property should not be initialized") |
|
1095 | 1085 | |
|
1096 | 1086 | return |
|
1097 | 1087 | |
|
1098 | 1088 | def getNoise(self): |
|
1099 | 1089 | |
|
1100 | 1090 | return self.spc_noise |
|
1101 | 1091 | |
|
1102 | 1092 | timeInterval = property(getTimeInterval) |
|
1103 | 1093 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") |
|
1104 | 1094 | |
|
1105 | 1095 | |
|
1106 | 1096 | class PlotterData(object): |
|
1107 | 1097 | ''' |
|
1108 | 1098 | Object to hold data to be plotted |
|
1109 | 1099 | ''' |
|
1110 | 1100 | |
|
1111 | 1101 | MAXNUMX = 100 |
|
1112 | 1102 | MAXNUMY = 100 |
|
1113 | 1103 | |
|
1114 | 1104 | def __init__(self, code, throttle_value, exp_code, buffering=True): |
|
1115 | 1105 | |
|
1116 | 1106 | self.throttle = throttle_value |
|
1117 | 1107 | self.exp_code = exp_code |
|
1118 | 1108 | self.buffering = buffering |
|
1119 | 1109 | self.ready = False |
|
1120 | 1110 | self.localtime = False |
|
1121 | 1111 | self.data = {} |
|
1122 | 1112 | self.meta = {} |
|
1123 | 1113 | self.__times = [] |
|
1124 | 1114 | self.__heights = [] |
|
1125 | 1115 | |
|
1126 | 1116 | if 'snr' in code: |
|
1127 | 1117 | self.plottypes = ['snr'] |
|
1128 | 1118 | elif code == 'spc': |
|
1129 | 1119 | self.plottypes = ['spc', 'noise', 'rti'] |
|
1130 | 1120 | elif code == 'rti': |
|
1131 | 1121 | self.plottypes = ['noise', 'rti'] |
|
1132 | 1122 | else: |
|
1133 | 1123 | self.plottypes = [code] |
|
1134 | 1124 | |
|
1135 | 1125 | for plot in self.plottypes: |
|
1136 | 1126 | self.data[plot] = {} |
|
1137 | 1127 | |
|
1138 | 1128 | def __str__(self): |
|
1139 | 1129 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] |
|
1140 | 1130 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) |
|
1141 | 1131 | |
|
1142 | 1132 | def __len__(self): |
|
1143 | 1133 | return len(self.__times) |
|
1144 | 1134 | |
|
1145 | 1135 | def __getitem__(self, key): |
|
1146 | 1136 | |
|
1147 | 1137 | if key not in self.data: |
|
1148 | 1138 | raise KeyError(log.error('Missing key: {}'.format(key))) |
|
1149 | 1139 | if 'spc' in key or not self.buffering: |
|
1150 | 1140 | ret = self.data[key] |
|
1151 | 1141 | elif 'scope' in key: |
|
1152 | 1142 | ret = numpy.array(self.data[key][float(self.tm)]) |
|
1153 | 1143 | else: |
|
1154 | 1144 | ret = numpy.array([self.data[key][x] for x in self.times]) |
|
1155 | 1145 | if ret.ndim > 1: |
|
1156 | 1146 | ret = numpy.swapaxes(ret, 0, 1) |
|
1157 | 1147 | return ret |
|
1158 | 1148 | |
|
1159 | 1149 | def __contains__(self, key): |
|
1160 | 1150 | return key in self.data |
|
1161 | 1151 | |
|
1162 | 1152 | def setup(self): |
|
1163 | 1153 | ''' |
|
1164 | 1154 | Configure object |
|
1165 | 1155 | ''' |
|
1166 | 1156 | |
|
1167 | 1157 | self.type = '' |
|
1168 | 1158 | self.ready = False |
|
1169 | 1159 | self.data = {} |
|
1170 | 1160 | self.__times = [] |
|
1171 | 1161 | self.__heights = [] |
|
1172 | 1162 | self.__all_heights = set() |
|
1173 | 1163 | for plot in self.plottypes: |
|
1174 | 1164 | if 'snr' in plot: |
|
1175 | 1165 | plot = 'snr' |
|
1176 | 1166 | self.data[plot] = {} |
|
1177 | 1167 | |
|
1178 | 1168 | if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data: |
|
1179 | 1169 | self.data['noise'] = {} |
|
1180 | 1170 | if 'noise' not in self.plottypes: |
|
1181 | 1171 | self.plottypes.append('noise') |
|
1182 | 1172 | |
|
1183 | 1173 | def shape(self, key): |
|
1184 | 1174 | ''' |
|
1185 | 1175 | Get the shape of the one-element data for the given key |
|
1186 | 1176 | ''' |
|
1187 | 1177 | |
|
1188 | 1178 | if len(self.data[key]): |
|
1189 | 1179 | if 'spc' in key or not self.buffering: |
|
1190 | 1180 | return self.data[key].shape |
|
1191 | 1181 | return self.data[key][self.__times[0]].shape |
|
1192 | 1182 | return (0,) |
|
1193 | 1183 | |
|
1194 | 1184 | def update(self, dataOut, tm): |
|
1195 | 1185 | ''' |
|
1196 | 1186 | Update data object with new dataOut |
|
1197 | 1187 | ''' |
|
1198 | 1188 | |
|
1199 | 1189 | if tm in self.__times: |
|
1200 | 1190 | return |
|
1201 | 1191 | self.profileIndex = dataOut.profileIndex |
|
1202 | 1192 | self.tm = tm |
|
1203 | 1193 | self.type = dataOut.type |
|
1204 | 1194 | self.parameters = getattr(dataOut, 'parameters', []) |
|
1205 | 1195 | if hasattr(dataOut, 'pairsList'): |
|
1206 | 1196 | self.pairs = dataOut.pairsList |
|
1207 | 1197 | if hasattr(dataOut, 'meta'): |
|
1208 | 1198 | self.meta = dataOut.meta |
|
1209 | 1199 | self.channels = dataOut.channelList |
|
1210 | 1200 | self.interval = dataOut.getTimeInterval() |
|
1211 | 1201 | self.localtime = dataOut.useLocalTime |
|
1212 | 1202 | if 'spc' in self.plottypes or 'cspc' in self.plottypes: |
|
1213 | 1203 | self.xrange = (dataOut.getFreqRange(1)/1000., |
|
1214 | 1204 | dataOut.getAcfRange(1), dataOut.getVelRange(1)) |
|
1215 | 1205 | self.factor = dataOut.normFactor |
|
1216 | 1206 | self.__heights.append(dataOut.heightList) |
|
1217 | 1207 | self.__all_heights.update(dataOut.heightList) |
|
1218 | 1208 | self.__times.append(tm) |
|
1219 | 1209 | |
|
1220 | 1210 | for plot in self.plottypes: |
|
1221 | 1211 | if plot == 'spc': |
|
1222 | 1212 | z = dataOut.data_spc/dataOut.normFactor |
|
1223 | 1213 | buffer = 10*numpy.log10(z) |
|
1224 | 1214 | if plot == 'cspc': |
|
1225 | 1215 | z = dataOut.data_spc/dataOut.normFactor |
|
1226 | 1216 | buffer = (dataOut.data_spc, dataOut.data_cspc) |
|
1227 | 1217 | if plot == 'noise': |
|
1228 | 1218 | buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) |
|
1229 | 1219 | if plot == 'rti': |
|
1230 | 1220 | buffer = dataOut.getPower() |
|
1231 | 1221 | if plot == 'snr_db': |
|
1232 | 1222 | buffer = dataOut.data_SNR |
|
1233 | 1223 | if plot == 'snr': |
|
1234 | 1224 | buffer = 10*numpy.log10(dataOut.data_SNR) |
|
1235 | 1225 | if plot == 'dop': |
|
1236 | 1226 | buffer = 10*numpy.log10(dataOut.data_DOP) |
|
1237 | 1227 | if plot == 'mean': |
|
1238 | 1228 | buffer = dataOut.data_MEAN |
|
1239 | 1229 | if plot == 'std': |
|
1240 | 1230 | buffer = dataOut.data_STD |
|
1241 | 1231 | if plot == 'coh': |
|
1242 | 1232 | buffer = dataOut.getCoherence() |
|
1243 | 1233 | if plot == 'phase': |
|
1244 | 1234 | buffer = dataOut.getCoherence(phase=True) |
|
1245 | 1235 | if plot == 'output': |
|
1246 | 1236 | buffer = dataOut.data_output |
|
1247 | 1237 | if plot == 'param': |
|
1248 | 1238 | buffer = dataOut.data_param |
|
1249 | 1239 | if plot == 'scope': |
|
1250 | 1240 | buffer = dataOut.data |
|
1251 | 1241 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
1252 | 1242 | self.nProfiles = dataOut.nProfiles |
|
1253 | 1243 | |
|
1254 | 1244 | if plot == 'spc': |
|
1255 | 1245 | self.data[plot] = buffer |
|
1256 | 1246 | elif plot == 'cspc': |
|
1257 | 1247 | self.data['spc'] = buffer[0] |
|
1258 | 1248 | self.data['cspc'] = buffer[1] |
|
1259 | 1249 | else: |
|
1260 | 1250 | if self.buffering: |
|
1261 | 1251 | self.data[plot][tm] = buffer |
|
1262 | 1252 | else: |
|
1263 | 1253 | self.data[plot] = buffer |
|
1264 | 1254 | |
|
1265 | 1255 | def normalize_heights(self): |
|
1266 | 1256 | ''' |
|
1267 | 1257 | Ensure same-dimension of the data for different heighList |
|
1268 | 1258 | ''' |
|
1269 | 1259 | |
|
1270 | 1260 | H = numpy.array(list(self.__all_heights)) |
|
1271 | 1261 | H.sort() |
|
1272 | 1262 | for key in self.data: |
|
1273 | 1263 | shape = self.shape(key)[:-1] + H.shape |
|
1274 | 1264 | for tm, obj in list(self.data[key].items()): |
|
1275 | 1265 | h = self.__heights[self.__times.index(tm)] |
|
1276 | 1266 | if H.size == h.size: |
|
1277 | 1267 | continue |
|
1278 | 1268 | index = numpy.where(numpy.in1d(H, h))[0] |
|
1279 | 1269 | dummy = numpy.zeros(shape) + numpy.nan |
|
1280 | 1270 | if len(shape) == 2: |
|
1281 | 1271 | dummy[:, index] = obj |
|
1282 | 1272 | else: |
|
1283 | 1273 | dummy[index] = obj |
|
1284 | 1274 | self.data[key][tm] = dummy |
|
1285 | 1275 | |
|
1286 | 1276 | self.__heights = [H for tm in self.__times] |
|
1287 | 1277 | |
|
1288 | 1278 | def jsonify(self, decimate=False): |
|
1289 | 1279 | ''' |
|
1290 | 1280 | Convert data to json |
|
1291 | 1281 | ''' |
|
1292 | 1282 | |
|
1293 | 1283 | data = {} |
|
1294 | 1284 | tm = self.times[-1] |
|
1295 | 1285 | dy = int(self.heights.size/self.MAXNUMY) + 1 |
|
1296 | 1286 | for key in self.data: |
|
1297 | 1287 | if key in ('spc', 'cspc') or not self.buffering: |
|
1298 | 1288 | dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1 |
|
1299 | 1289 | data[key] = self.roundFloats( |
|
1300 | 1290 | self.data[key][::, ::dx, ::dy].tolist()) |
|
1301 | 1291 | else: |
|
1302 | 1292 | data[key] = self.roundFloats(self.data[key][tm].tolist()) |
|
1303 | 1293 | |
|
1304 | 1294 | ret = {'data': data} |
|
1305 | 1295 | ret['exp_code'] = self.exp_code |
|
1306 | 1296 | ret['time'] = float(tm) |
|
1307 | 1297 | ret['interval'] = float(self.interval) |
|
1308 | 1298 | ret['localtime'] = self.localtime |
|
1309 | 1299 | ret['yrange'] = self.roundFloats(self.heights[::dy].tolist()) |
|
1310 | 1300 | if 'spc' in self.data or 'cspc' in self.data: |
|
1311 | 1301 | ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) |
|
1312 | 1302 | else: |
|
1313 | 1303 | ret['xrange'] = [] |
|
1314 | 1304 | if hasattr(self, 'pairs'): |
|
1315 | 1305 | ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs] |
|
1316 | 1306 | else: |
|
1317 | 1307 | ret['pairs'] = [] |
|
1318 | 1308 | |
|
1319 | 1309 | for key, value in list(self.meta.items()): |
|
1320 | 1310 | ret[key] = value |
|
1321 | 1311 | |
|
1322 | 1312 | return json.dumps(ret) |
|
1323 | 1313 | |
|
1324 | 1314 | @property |
|
1325 | 1315 | def times(self): |
|
1326 | 1316 | ''' |
|
1327 | 1317 | Return the list of times of the current data |
|
1328 | 1318 | ''' |
|
1329 | 1319 | |
|
1330 | 1320 | ret = numpy.array(self.__times) |
|
1331 | 1321 | ret.sort() |
|
1332 | 1322 | return ret |
|
1333 | 1323 | |
|
1334 | 1324 | @property |
|
1335 | 1325 | def min_time(self): |
|
1336 | 1326 | ''' |
|
1337 | 1327 | Return the minimun time value |
|
1338 | 1328 | ''' |
|
1339 | 1329 | |
|
1340 | 1330 | return self.times[0] |
|
1341 | 1331 | |
|
1342 | 1332 | @property |
|
1343 | 1333 | def max_time(self): |
|
1344 | 1334 | ''' |
|
1345 | 1335 | Return the maximun time value |
|
1346 | 1336 | ''' |
|
1347 | 1337 | |
|
1348 | 1338 | return self.times[-1] |
|
1349 | 1339 | |
|
1350 | 1340 | @property |
|
1351 | 1341 | def heights(self): |
|
1352 | 1342 | ''' |
|
1353 | 1343 | Return the list of heights of the current data |
|
1354 | 1344 | ''' |
|
1355 | 1345 | |
|
1356 | 1346 | return numpy.array(self.__heights[-1]) |
|
1357 | 1347 | |
|
1358 | 1348 | @staticmethod |
|
1359 | 1349 | def roundFloats(obj): |
|
1360 | 1350 | if isinstance(obj, list): |
|
1361 | 1351 | return list(map(PlotterData.roundFloats, obj)) |
|
1362 | 1352 | elif isinstance(obj, float): |
|
1363 | 1353 | return round(obj, 2) |
@@ -1,2389 +1,2394 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | import inspect |
|
5 | 5 | from .figure import Figure, isRealtime, isTimeInHourRange |
|
6 | 6 | from .plotting_codes import * |
|
7 | 7 | from schainpy.model.proc.jroproc_base import MPDecorator |
|
8 | 8 | from schainpy.utils import log |
|
9 | 9 | |
|
10 | 10 | class ParamLine_(Figure): |
|
11 | 11 | |
|
12 | 12 | isConfig = None |
|
13 | 13 | |
|
14 | 14 | def __init__(self): |
|
15 | 15 | |
|
16 | 16 | self.isConfig = False |
|
17 | 17 | self.WIDTH = 300 |
|
18 | 18 | self.HEIGHT = 200 |
|
19 | 19 | self.counter_imagwr = 0 |
|
20 | 20 | |
|
21 | 21 | def getSubplots(self): |
|
22 | 22 | |
|
23 | 23 | nrow = self.nplots |
|
24 | 24 | ncol = 3 |
|
25 | 25 | return nrow, ncol |
|
26 | 26 | |
|
27 | 27 | def setup(self, id, nplots, wintitle, show): |
|
28 | 28 | |
|
29 | 29 | self.nplots = nplots |
|
30 | 30 | |
|
31 | 31 | self.createFigure(id=id, |
|
32 | 32 | wintitle=wintitle, |
|
33 | 33 | show=show) |
|
34 | 34 | |
|
35 | 35 | nrow,ncol = self.getSubplots() |
|
36 | 36 | colspan = 3 |
|
37 | 37 | rowspan = 1 |
|
38 | 38 | |
|
39 | 39 | for i in range(nplots): |
|
40 | 40 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
41 | 41 | |
|
42 | 42 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
43 | 43 | yreal = y[channelIndexList,:].real |
|
44 | 44 | yimag = y[channelIndexList,:].imag |
|
45 | 45 | |
|
46 | 46 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
47 | 47 | xlabel = "Range (Km)" |
|
48 | 48 | ylabel = "Intensity - IQ" |
|
49 | 49 | |
|
50 | 50 | if not self.isConfig: |
|
51 | 51 | nplots = len(channelIndexList) |
|
52 | 52 | |
|
53 | 53 | self.setup(id=id, |
|
54 | 54 | nplots=nplots, |
|
55 | 55 | wintitle='', |
|
56 | 56 | show=show) |
|
57 | 57 | |
|
58 | 58 | if xmin == None: xmin = numpy.nanmin(x) |
|
59 | 59 | if xmax == None: xmax = numpy.nanmax(x) |
|
60 | 60 | if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) |
|
61 | 61 | if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) |
|
62 | 62 | |
|
63 | 63 | self.isConfig = True |
|
64 | 64 | |
|
65 | 65 | self.setWinTitle(title) |
|
66 | 66 | |
|
67 | 67 | for i in range(len(self.axesList)): |
|
68 | 68 | title = "Channel %d" %(i) |
|
69 | 69 | axes = self.axesList[i] |
|
70 | 70 | |
|
71 | 71 | axes.pline(x, yreal[i,:], |
|
72 | 72 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
73 | 73 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
74 | 74 | |
|
75 | 75 | axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) |
|
76 | 76 | |
|
77 | 77 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
78 | 78 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
79 | 79 | yreal = y.real |
|
80 | 80 | |
|
81 | 81 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
82 | 82 | xlabel = "Range (Km)" |
|
83 | 83 | ylabel = "Intensity" |
|
84 | 84 | |
|
85 | 85 | if not self.isConfig: |
|
86 | 86 | nplots = len(channelIndexList) |
|
87 | 87 | |
|
88 | 88 | self.setup(id=id, |
|
89 | 89 | nplots=nplots, |
|
90 | 90 | wintitle='', |
|
91 | 91 | show=show) |
|
92 | 92 | |
|
93 | 93 | if xmin == None: xmin = numpy.nanmin(x) |
|
94 | 94 | if xmax == None: xmax = numpy.nanmax(x) |
|
95 | 95 | if ymin == None: ymin = numpy.nanmin(yreal) |
|
96 | 96 | if ymax == None: ymax = numpy.nanmax(yreal) |
|
97 | 97 | |
|
98 | 98 | self.isConfig = True |
|
99 | 99 | |
|
100 | 100 | self.setWinTitle(title) |
|
101 | 101 | |
|
102 | 102 | for i in range(len(self.axesList)): |
|
103 | 103 | title = "Channel %d" %(i) |
|
104 | 104 | axes = self.axesList[i] |
|
105 | 105 | ychannel = yreal[i,:] |
|
106 | 106 | axes.pline(x, ychannel, |
|
107 | 107 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
108 | 108 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
109 | 109 | |
|
110 | 110 | |
|
111 | 111 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
112 | 112 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
113 | 113 | figpath='./', figfile=None, show=True, wr_period=1, |
|
114 | 114 | ftp=False, server=None, folder=None, username=None, password=None): |
|
115 | 115 | |
|
116 | 116 | """ |
|
117 | 117 | |
|
118 | 118 | Input: |
|
119 | 119 | dataOut : |
|
120 | 120 | id : |
|
121 | 121 | wintitle : |
|
122 | 122 | channelList : |
|
123 | 123 | xmin : None, |
|
124 | 124 | xmax : None, |
|
125 | 125 | ymin : None, |
|
126 | 126 | ymax : None, |
|
127 | 127 | """ |
|
128 | 128 | |
|
129 | 129 | if channelList == None: |
|
130 | 130 | channelIndexList = dataOut.channelIndexList |
|
131 | 131 | else: |
|
132 | 132 | channelIndexList = [] |
|
133 | 133 | for channel in channelList: |
|
134 | 134 | if channel not in dataOut.channelList: |
|
135 | 135 | raise ValueError("Channel %d is not in dataOut.channelList" % channel) |
|
136 | 136 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
137 | 137 | |
|
138 | 138 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
139 | 139 | |
|
140 | 140 | y = dataOut.RR |
|
141 | 141 | |
|
142 | 142 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
143 | 143 | xlabel = "Range (Km)" |
|
144 | 144 | ylabel = "Intensity" |
|
145 | 145 | |
|
146 | 146 | if not self.isConfig: |
|
147 | 147 | nplots = len(channelIndexList) |
|
148 | 148 | |
|
149 | 149 | self.setup(id=id, |
|
150 | 150 | nplots=nplots, |
|
151 | 151 | wintitle='', |
|
152 | 152 | show=show) |
|
153 | 153 | |
|
154 | 154 | if xmin == None: xmin = numpy.nanmin(x) |
|
155 | 155 | if xmax == None: xmax = numpy.nanmax(x) |
|
156 | 156 | if ymin == None: ymin = numpy.nanmin(y) |
|
157 | 157 | if ymax == None: ymax = numpy.nanmax(y) |
|
158 | 158 | |
|
159 | 159 | self.isConfig = True |
|
160 | 160 | |
|
161 | 161 | self.setWinTitle(title) |
|
162 | 162 | |
|
163 | 163 | for i in range(len(self.axesList)): |
|
164 | 164 | title = "Channel %d" %(i) |
|
165 | 165 | axes = self.axesList[i] |
|
166 | 166 | ychannel = y[i,:] |
|
167 | 167 | axes.pline(x, ychannel, |
|
168 | 168 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
169 | 169 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
170 | 170 | |
|
171 | 171 | |
|
172 | 172 | self.draw() |
|
173 | 173 | |
|
174 | 174 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex) |
|
175 | 175 | figfile = self.getFilename(name = str_datetime) |
|
176 | 176 | |
|
177 | 177 | self.save(figpath=figpath, |
|
178 | 178 | figfile=figfile, |
|
179 | 179 | save=save, |
|
180 | 180 | ftp=ftp, |
|
181 | 181 | wr_period=wr_period, |
|
182 | 182 | thisDatetime=thisDatetime) |
|
183 | 183 | |
|
184 | 184 | |
|
185 | 185 | |
|
186 | 186 | class SpcParamPlot_(Figure): |
|
187 | 187 | |
|
188 | 188 | isConfig = None |
|
189 | 189 | __nsubplots = None |
|
190 | 190 | |
|
191 | 191 | WIDTHPROF = None |
|
192 | 192 | HEIGHTPROF = None |
|
193 | 193 | PREFIX = 'SpcParam' |
|
194 | 194 | |
|
195 | 195 | def __init__(self, **kwargs): |
|
196 | 196 | Figure.__init__(self, **kwargs) |
|
197 | 197 | self.isConfig = False |
|
198 | 198 | self.__nsubplots = 1 |
|
199 | 199 | |
|
200 | 200 | self.WIDTH = 250 |
|
201 | 201 | self.HEIGHT = 250 |
|
202 | 202 | self.WIDTHPROF = 120 |
|
203 | 203 | self.HEIGHTPROF = 0 |
|
204 | 204 | self.counter_imagwr = 0 |
|
205 | 205 | |
|
206 | 206 | self.PLOT_CODE = SPEC_CODE |
|
207 | 207 | |
|
208 | 208 | self.FTP_WEI = None |
|
209 | 209 | self.EXP_CODE = None |
|
210 | 210 | self.SUB_EXP_CODE = None |
|
211 | 211 | self.PLOT_POS = None |
|
212 | 212 | |
|
213 | 213 | self.__xfilter_ena = False |
|
214 | 214 | self.__yfilter_ena = False |
|
215 | 215 | |
|
216 | 216 | def getSubplots(self): |
|
217 | 217 | |
|
218 | 218 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
219 | 219 | nrow = int(self.nplots*1./ncol + 0.9) |
|
220 | 220 | |
|
221 | 221 | return nrow, ncol |
|
222 | 222 | |
|
223 | 223 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
224 | 224 | |
|
225 | 225 | self.__showprofile = showprofile |
|
226 | 226 | self.nplots = nplots |
|
227 | 227 | |
|
228 | 228 | ncolspan = 1 |
|
229 | 229 | colspan = 1 |
|
230 | 230 | if showprofile: |
|
231 | 231 | ncolspan = 3 |
|
232 | 232 | colspan = 2 |
|
233 | 233 | self.__nsubplots = 2 |
|
234 | 234 | |
|
235 | 235 | self.createFigure(id = id, |
|
236 | 236 | wintitle = wintitle, |
|
237 | 237 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
238 | 238 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
239 | 239 | show=show) |
|
240 | 240 | |
|
241 | 241 | nrow, ncol = self.getSubplots() |
|
242 | 242 | |
|
243 | 243 | counter = 0 |
|
244 | 244 | for y in range(nrow): |
|
245 | 245 | for x in range(ncol): |
|
246 | 246 | |
|
247 | 247 | if counter >= self.nplots: |
|
248 | 248 | break |
|
249 | 249 | |
|
250 | 250 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
251 | 251 | |
|
252 | 252 | if showprofile: |
|
253 | 253 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
254 | 254 | |
|
255 | 255 | counter += 1 |
|
256 | 256 | |
|
257 | 257 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
258 | 258 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
259 | 259 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
260 | 260 | server=None, folder=None, username=None, password=None, |
|
261 | 261 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
262 | 262 | xaxis="frequency", colormap='jet', normFactor=None , Selector = 0): |
|
263 | 263 | |
|
264 | 264 | """ |
|
265 | 265 | |
|
266 | 266 | Input: |
|
267 | 267 | dataOut : |
|
268 | 268 | id : |
|
269 | 269 | wintitle : |
|
270 | 270 | channelList : |
|
271 | 271 | showProfile : |
|
272 | 272 | xmin : None, |
|
273 | 273 | xmax : None, |
|
274 | 274 | ymin : None, |
|
275 | 275 | ymax : None, |
|
276 | 276 | zmin : None, |
|
277 | 277 | zmax : None |
|
278 | 278 | """ |
|
279 | 279 | if realtime: |
|
280 | 280 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
281 | 281 | print('Skipping this plot function') |
|
282 | 282 | return |
|
283 | 283 | |
|
284 | 284 | if channelList == None: |
|
285 | 285 | channelIndexList = dataOut.channelIndexList |
|
286 | 286 | else: |
|
287 | 287 | channelIndexList = [] |
|
288 | 288 | for channel in channelList: |
|
289 | 289 | if channel not in dataOut.channelList: |
|
290 | 290 | raise ValueError("Channel %d is not in dataOut.channelList" %channel) |
|
291 | 291 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
292 | 292 | |
|
293 | 293 | # if normFactor is None: |
|
294 | 294 | # factor = dataOut.normFactor |
|
295 | 295 | # else: |
|
296 | 296 | # factor = normFactor |
|
297 | 297 | if xaxis == "frequency": |
|
298 | 298 | x = dataOut.spcparam_range[0] |
|
299 | 299 | xlabel = "Frequency (kHz)" |
|
300 | 300 | |
|
301 | 301 | elif xaxis == "time": |
|
302 | 302 | x = dataOut.spcparam_range[1] |
|
303 | 303 | xlabel = "Time (ms)" |
|
304 | 304 | |
|
305 | 305 | else: |
|
306 | 306 | x = dataOut.spcparam_range[2] |
|
307 | 307 | xlabel = "Velocity (m/s)" |
|
308 | 308 | |
|
309 | 309 | ylabel = "Range (km)" |
|
310 | 310 | |
|
311 | 311 | y = dataOut.getHeiRange() |
|
312 | 312 | |
|
313 | 313 | z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor |
|
314 | 314 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
315 | 315 | zdB = 10*numpy.log10(z) |
|
316 | 316 | |
|
317 | 317 | avg = numpy.average(z, axis=1) |
|
318 | 318 | avgdB = 10*numpy.log10(avg) |
|
319 | 319 | |
|
320 | 320 | noise = dataOut.spc_noise |
|
321 | 321 | noisedB = 10*numpy.log10(noise) |
|
322 | 322 | |
|
323 | 323 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
324 | 324 | title = wintitle + " Spectra" |
|
325 | 325 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
326 | 326 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
327 | 327 | |
|
328 | 328 | if not self.isConfig: |
|
329 | 329 | |
|
330 | 330 | nplots = len(channelIndexList) |
|
331 | 331 | |
|
332 | 332 | self.setup(id=id, |
|
333 | 333 | nplots=nplots, |
|
334 | 334 | wintitle=wintitle, |
|
335 | 335 | showprofile=showprofile, |
|
336 | 336 | show=show) |
|
337 | 337 | |
|
338 | 338 | if xmin == None: xmin = numpy.nanmin(x) |
|
339 | 339 | if xmax == None: xmax = numpy.nanmax(x) |
|
340 | 340 | if ymin == None: ymin = numpy.nanmin(y) |
|
341 | 341 | if ymax == None: ymax = numpy.nanmax(y) |
|
342 | 342 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
343 | 343 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
344 | 344 | |
|
345 | 345 | self.FTP_WEI = ftp_wei |
|
346 | 346 | self.EXP_CODE = exp_code |
|
347 | 347 | self.SUB_EXP_CODE = sub_exp_code |
|
348 | 348 | self.PLOT_POS = plot_pos |
|
349 | 349 | |
|
350 | 350 | self.isConfig = True |
|
351 | 351 | |
|
352 | 352 | self.setWinTitle(title) |
|
353 | 353 | |
|
354 | 354 | for i in range(self.nplots): |
|
355 | 355 | index = channelIndexList[i] |
|
356 | 356 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
357 | 357 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
358 | 358 | if len(dataOut.beam.codeList) != 0: |
|
359 | 359 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
360 | 360 | |
|
361 | 361 | axes = self.axesList[i*self.__nsubplots] |
|
362 | 362 | axes.pcolor(x, y, zdB[index,:,:], |
|
363 | 363 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
364 | 364 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
365 | 365 | ticksize=9, cblabel='') |
|
366 | 366 | |
|
367 | 367 | if self.__showprofile: |
|
368 | 368 | axes = self.axesList[i*self.__nsubplots +1] |
|
369 | 369 | axes.pline(avgdB[index,:], y, |
|
370 | 370 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
371 | 371 | xlabel='dB', ylabel='', title='', |
|
372 | 372 | ytick_visible=False, |
|
373 | 373 | grid='x') |
|
374 | 374 | |
|
375 | 375 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
376 | 376 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
377 | 377 | |
|
378 | 378 | self.draw() |
|
379 | 379 | |
|
380 | 380 | if figfile == None: |
|
381 | 381 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
382 | 382 | name = str_datetime |
|
383 | 383 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
384 | 384 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
385 | 385 | figfile = self.getFilename(name) |
|
386 | 386 | |
|
387 | 387 | self.save(figpath=figpath, |
|
388 | 388 | figfile=figfile, |
|
389 | 389 | save=save, |
|
390 | 390 | ftp=ftp, |
|
391 | 391 | wr_period=wr_period, |
|
392 | 392 | thisDatetime=thisDatetime) |
|
393 | 393 | |
|
394 | 394 | |
|
395 | 395 | |
|
396 | 396 | class MomentsPlot_(Figure): |
|
397 | 397 | |
|
398 | 398 | isConfig = None |
|
399 | 399 | __nsubplots = None |
|
400 | 400 | |
|
401 | 401 | WIDTHPROF = None |
|
402 | 402 | HEIGHTPROF = None |
|
403 | 403 | PREFIX = 'prm' |
|
404 | 404 | def __init__(self): |
|
405 | 405 | Figure.__init__(self) |
|
406 | 406 | self.isConfig = False |
|
407 | 407 | self.__nsubplots = 1 |
|
408 | 408 | |
|
409 | 409 | self.WIDTH = 280 |
|
410 | 410 | self.HEIGHT = 250 |
|
411 | 411 | self.WIDTHPROF = 120 |
|
412 | 412 | self.HEIGHTPROF = 0 |
|
413 | 413 | self.counter_imagwr = 0 |
|
414 | 414 | |
|
415 | 415 | self.PLOT_CODE = MOMENTS_CODE |
|
416 | 416 | |
|
417 | 417 | self.FTP_WEI = None |
|
418 | 418 | self.EXP_CODE = None |
|
419 | 419 | self.SUB_EXP_CODE = None |
|
420 | 420 | self.PLOT_POS = None |
|
421 | 421 | |
|
422 | 422 | def getSubplots(self): |
|
423 | 423 | |
|
424 | 424 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
425 | 425 | nrow = int(self.nplots*1./ncol + 0.9) |
|
426 | 426 | |
|
427 | 427 | return nrow, ncol |
|
428 | 428 | |
|
429 | 429 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
430 | 430 | |
|
431 | 431 | self.__showprofile = showprofile |
|
432 | 432 | self.nplots = nplots |
|
433 | 433 | |
|
434 | 434 | ncolspan = 1 |
|
435 | 435 | colspan = 1 |
|
436 | 436 | if showprofile: |
|
437 | 437 | ncolspan = 3 |
|
438 | 438 | colspan = 2 |
|
439 | 439 | self.__nsubplots = 2 |
|
440 | 440 | |
|
441 | 441 | self.createFigure(id = id, |
|
442 | 442 | wintitle = wintitle, |
|
443 | 443 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
444 | 444 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
445 | 445 | show=show) |
|
446 | 446 | |
|
447 | 447 | nrow, ncol = self.getSubplots() |
|
448 | 448 | |
|
449 | 449 | counter = 0 |
|
450 | 450 | for y in range(nrow): |
|
451 | 451 | for x in range(ncol): |
|
452 | 452 | |
|
453 | 453 | if counter >= self.nplots: |
|
454 | 454 | break |
|
455 | 455 | |
|
456 | 456 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
457 | 457 | |
|
458 | 458 | if showprofile: |
|
459 | 459 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
460 | 460 | |
|
461 | 461 | counter += 1 |
|
462 | 462 | |
|
463 | 463 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
464 | 464 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
465 | 465 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
466 | 466 | server=None, folder=None, username=None, password=None, |
|
467 | 467 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
468 | 468 | |
|
469 | 469 | """ |
|
470 | 470 | |
|
471 | 471 | Input: |
|
472 | 472 | dataOut : |
|
473 | 473 | id : |
|
474 | 474 | wintitle : |
|
475 | 475 | channelList : |
|
476 | 476 | showProfile : |
|
477 | 477 | xmin : None, |
|
478 | 478 | xmax : None, |
|
479 | 479 | ymin : None, |
|
480 | 480 | ymax : None, |
|
481 | 481 | zmin : None, |
|
482 | 482 | zmax : None |
|
483 | 483 | """ |
|
484 | 484 | |
|
485 | 485 | if dataOut.flagNoData: |
|
486 | 486 | return None |
|
487 | 487 | |
|
488 | 488 | if realtime: |
|
489 | 489 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
490 | 490 | print('Skipping this plot function') |
|
491 | 491 | return |
|
492 | 492 | |
|
493 | 493 | if channelList == None: |
|
494 | 494 | channelIndexList = dataOut.channelIndexList |
|
495 | 495 | else: |
|
496 | 496 | channelIndexList = [] |
|
497 | 497 | for channel in channelList: |
|
498 | 498 | if channel not in dataOut.channelList: |
|
499 | 499 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
500 | 500 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
501 | 501 | |
|
502 | 502 | factor = dataOut.normFactor |
|
503 | 503 | x = dataOut.abscissaList |
|
504 | 504 | y = dataOut.heightList |
|
505 | 505 | |
|
506 | 506 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
507 | 507 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
508 | 508 | avg = numpy.average(z, axis=1) |
|
509 | 509 | noise = dataOut.noise/factor |
|
510 | 510 | |
|
511 | 511 | zdB = 10*numpy.log10(z) |
|
512 | 512 | avgdB = 10*numpy.log10(avg) |
|
513 | 513 | noisedB = 10*numpy.log10(noise) |
|
514 | 514 | |
|
515 | 515 | #thisDatetime = dataOut.datatime |
|
516 | 516 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
517 | 517 | title = wintitle + " Parameters" |
|
518 | 518 | xlabel = "Velocity (m/s)" |
|
519 | 519 | ylabel = "Range (Km)" |
|
520 | 520 | |
|
521 | 521 | update_figfile = False |
|
522 | 522 | |
|
523 | 523 | if not self.isConfig: |
|
524 | 524 | |
|
525 | 525 | nplots = len(channelIndexList) |
|
526 | 526 | |
|
527 | 527 | self.setup(id=id, |
|
528 | 528 | nplots=nplots, |
|
529 | 529 | wintitle=wintitle, |
|
530 | 530 | showprofile=showprofile, |
|
531 | 531 | show=show) |
|
532 | 532 | |
|
533 | 533 | if xmin == None: xmin = numpy.nanmin(x) |
|
534 | 534 | if xmax == None: xmax = numpy.nanmax(x) |
|
535 | 535 | if ymin == None: ymin = numpy.nanmin(y) |
|
536 | 536 | if ymax == None: ymax = numpy.nanmax(y) |
|
537 | 537 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
538 | 538 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
539 | 539 | |
|
540 | 540 | self.FTP_WEI = ftp_wei |
|
541 | 541 | self.EXP_CODE = exp_code |
|
542 | 542 | self.SUB_EXP_CODE = sub_exp_code |
|
543 | 543 | self.PLOT_POS = plot_pos |
|
544 | 544 | |
|
545 | 545 | self.isConfig = True |
|
546 | 546 | update_figfile = True |
|
547 | 547 | |
|
548 | 548 | self.setWinTitle(title) |
|
549 | 549 | |
|
550 | 550 | for i in range(self.nplots): |
|
551 | 551 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
552 | 552 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime) |
|
553 | 553 | axes = self.axesList[i*self.__nsubplots] |
|
554 | 554 | axes.pcolor(x, y, zdB[i,:,:], |
|
555 | 555 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
556 | 556 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
557 | 557 | ticksize=9, cblabel='') |
|
558 | 558 | #Mean Line |
|
559 | 559 | mean = dataOut.data_param[i, 1, :] |
|
560 | 560 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
561 | 561 | |
|
562 | 562 | if self.__showprofile: |
|
563 | 563 | axes = self.axesList[i*self.__nsubplots +1] |
|
564 | 564 | axes.pline(avgdB[i], y, |
|
565 | 565 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
566 | 566 | xlabel='dB', ylabel='', title='', |
|
567 | 567 | ytick_visible=False, |
|
568 | 568 | grid='x') |
|
569 | 569 | |
|
570 | 570 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
571 | 571 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
572 | 572 | |
|
573 | 573 | self.draw() |
|
574 | 574 | |
|
575 | 575 | self.save(figpath=figpath, |
|
576 | 576 | figfile=figfile, |
|
577 | 577 | save=save, |
|
578 | 578 | ftp=ftp, |
|
579 | 579 | wr_period=wr_period, |
|
580 | 580 | thisDatetime=thisDatetime) |
|
581 | 581 | |
|
582 | 582 | |
|
583 | 583 | class SkyMapPlot_(Figure): |
|
584 | 584 | |
|
585 | 585 | __isConfig = None |
|
586 | 586 | __nsubplots = None |
|
587 | 587 | |
|
588 | 588 | WIDTHPROF = None |
|
589 | 589 | HEIGHTPROF = None |
|
590 | 590 | PREFIX = 'mmap' |
|
591 | 591 | |
|
592 | 592 | def __init__(self, **kwargs): |
|
593 | 593 | Figure.__init__(self, **kwargs) |
|
594 | 594 | self.isConfig = False |
|
595 | 595 | self.__nsubplots = 1 |
|
596 | 596 | |
|
597 | 597 | # self.WIDTH = 280 |
|
598 | 598 | # self.HEIGHT = 250 |
|
599 | 599 | self.WIDTH = 600 |
|
600 | 600 | self.HEIGHT = 600 |
|
601 | 601 | self.WIDTHPROF = 120 |
|
602 | 602 | self.HEIGHTPROF = 0 |
|
603 | 603 | self.counter_imagwr = 0 |
|
604 | 604 | |
|
605 | 605 | self.PLOT_CODE = MSKYMAP_CODE |
|
606 | 606 | |
|
607 | 607 | self.FTP_WEI = None |
|
608 | 608 | self.EXP_CODE = None |
|
609 | 609 | self.SUB_EXP_CODE = None |
|
610 | 610 | self.PLOT_POS = None |
|
611 | 611 | |
|
612 | 612 | def getSubplots(self): |
|
613 | 613 | |
|
614 | 614 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
615 | 615 | nrow = int(self.nplots*1./ncol + 0.9) |
|
616 | 616 | |
|
617 | 617 | return nrow, ncol |
|
618 | 618 | |
|
619 | 619 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
620 | 620 | |
|
621 | 621 | self.__showprofile = showprofile |
|
622 | 622 | self.nplots = nplots |
|
623 | 623 | |
|
624 | 624 | ncolspan = 1 |
|
625 | 625 | colspan = 1 |
|
626 | 626 | |
|
627 | 627 | self.createFigure(id = id, |
|
628 | 628 | wintitle = wintitle, |
|
629 | 629 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
630 | 630 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
631 | 631 | show=show) |
|
632 | 632 | |
|
633 | 633 | nrow, ncol = 1,1 |
|
634 | 634 | counter = 0 |
|
635 | 635 | x = 0 |
|
636 | 636 | y = 0 |
|
637 | 637 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
638 | 638 | |
|
639 | 639 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
640 | 640 | tmin=0, tmax=24, timerange=None, |
|
641 | 641 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
642 | 642 | server=None, folder=None, username=None, password=None, |
|
643 | 643 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
644 | 644 | |
|
645 | 645 | """ |
|
646 | 646 | |
|
647 | 647 | Input: |
|
648 | 648 | dataOut : |
|
649 | 649 | id : |
|
650 | 650 | wintitle : |
|
651 | 651 | channelList : |
|
652 | 652 | showProfile : |
|
653 | 653 | xmin : None, |
|
654 | 654 | xmax : None, |
|
655 | 655 | ymin : None, |
|
656 | 656 | ymax : None, |
|
657 | 657 | zmin : None, |
|
658 | 658 | zmax : None |
|
659 | 659 | """ |
|
660 | 660 | |
|
661 | 661 | arrayParameters = dataOut.data_param |
|
662 | 662 | error = arrayParameters[:,-1] |
|
663 | 663 | indValid = numpy.where(error == 0)[0] |
|
664 | 664 | finalMeteor = arrayParameters[indValid,:] |
|
665 | 665 | finalAzimuth = finalMeteor[:,3] |
|
666 | 666 | finalZenith = finalMeteor[:,4] |
|
667 | 667 | |
|
668 | 668 | x = finalAzimuth*numpy.pi/180 |
|
669 | 669 | y = finalZenith |
|
670 | 670 | x1 = [dataOut.ltctime, dataOut.ltctime] |
|
671 | 671 | |
|
672 | 672 | #thisDatetime = dataOut.datatime |
|
673 | 673 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
674 | 674 | title = wintitle + " Parameters" |
|
675 | 675 | xlabel = "Zonal Zenith Angle (deg) " |
|
676 | 676 | ylabel = "Meridional Zenith Angle (deg)" |
|
677 | 677 | update_figfile = False |
|
678 | 678 | |
|
679 | 679 | if not self.isConfig: |
|
680 | 680 | |
|
681 | 681 | nplots = 1 |
|
682 | 682 | |
|
683 | 683 | self.setup(id=id, |
|
684 | 684 | nplots=nplots, |
|
685 | 685 | wintitle=wintitle, |
|
686 | 686 | showprofile=showprofile, |
|
687 | 687 | show=show) |
|
688 | 688 | |
|
689 | 689 | if self.xmin is None and self.xmax is None: |
|
690 | 690 | self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange) |
|
691 | 691 | |
|
692 | 692 | if timerange != None: |
|
693 | 693 | self.timerange = timerange |
|
694 | 694 | else: |
|
695 | 695 | self.timerange = self.xmax - self.xmin |
|
696 | 696 | |
|
697 | 697 | self.FTP_WEI = ftp_wei |
|
698 | 698 | self.EXP_CODE = exp_code |
|
699 | 699 | self.SUB_EXP_CODE = sub_exp_code |
|
700 | 700 | self.PLOT_POS = plot_pos |
|
701 | 701 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
702 | 702 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
703 | 703 | self.isConfig = True |
|
704 | 704 | update_figfile = True |
|
705 | 705 | |
|
706 | 706 | self.setWinTitle(title) |
|
707 | 707 | |
|
708 | 708 | i = 0 |
|
709 | 709 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
710 | 710 | |
|
711 | 711 | axes = self.axesList[i*self.__nsubplots] |
|
712 | 712 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
713 | 713 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
714 | 714 | axes.polar(x, y, |
|
715 | 715 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
716 | 716 | ticksize=9, cblabel='') |
|
717 | 717 | |
|
718 | 718 | self.draw() |
|
719 | 719 | |
|
720 | 720 | self.save(figpath=figpath, |
|
721 | 721 | figfile=figfile, |
|
722 | 722 | save=save, |
|
723 | 723 | ftp=ftp, |
|
724 | 724 | wr_period=wr_period, |
|
725 | 725 | thisDatetime=thisDatetime, |
|
726 | 726 | update_figfile=update_figfile) |
|
727 | 727 | |
|
728 | 728 | if dataOut.ltctime >= self.xmax: |
|
729 | 729 | self.isConfigmagwr = wr_period |
|
730 | 730 | self.isConfig = False |
|
731 | 731 | update_figfile = True |
|
732 | 732 | axes.__firsttime = True |
|
733 | 733 | self.xmin += self.timerange |
|
734 | 734 | self.xmax += self.timerange |
|
735 | 735 | |
|
736 | 736 | |
|
737 | 737 | |
|
738 | ||
|
738 | @MPDecorator | |
|
739 | 739 | class WindProfilerPlot_(Figure): |
|
740 | 740 | |
|
741 | 741 | __isConfig = None |
|
742 | 742 | __nsubplots = None |
|
743 | 743 | |
|
744 | 744 | WIDTHPROF = None |
|
745 | 745 | HEIGHTPROF = None |
|
746 | 746 | PREFIX = 'wind' |
|
747 | 747 | |
|
748 |
def __init__(self |
|
|
749 |
Figure.__init__(self |
|
|
748 | def __init__(self): | |
|
749 | Figure.__init__(self) | |
|
750 | 750 | self.timerange = None |
|
751 | 751 | self.isConfig = False |
|
752 | 752 | self.__nsubplots = 1 |
|
753 | 753 | |
|
754 | 754 | self.WIDTH = 800 |
|
755 | 755 | self.HEIGHT = 300 |
|
756 | 756 | self.WIDTHPROF = 120 |
|
757 | 757 | self.HEIGHTPROF = 0 |
|
758 | 758 | self.counter_imagwr = 0 |
|
759 | 759 | |
|
760 | 760 | self.PLOT_CODE = WIND_CODE |
|
761 | 761 | |
|
762 | 762 | self.FTP_WEI = None |
|
763 | 763 | self.EXP_CODE = None |
|
764 | 764 | self.SUB_EXP_CODE = None |
|
765 | 765 | self.PLOT_POS = None |
|
766 | 766 | self.tmin = None |
|
767 | 767 | self.tmax = None |
|
768 | 768 | |
|
769 | 769 | self.xmin = None |
|
770 | 770 | self.xmax = None |
|
771 | 771 | |
|
772 | 772 | self.figfile = None |
|
773 | 773 | |
|
774 | 774 | def getSubplots(self): |
|
775 | 775 | |
|
776 | 776 | ncol = 1 |
|
777 | 777 | nrow = self.nplots |
|
778 | 778 | |
|
779 | 779 | return nrow, ncol |
|
780 | 780 | |
|
781 | 781 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
782 | 782 | |
|
783 | 783 | self.__showprofile = showprofile |
|
784 | 784 | self.nplots = nplots |
|
785 | 785 | |
|
786 | 786 | ncolspan = 1 |
|
787 | 787 | colspan = 1 |
|
788 | 788 | |
|
789 | 789 | self.createFigure(id = id, |
|
790 | 790 | wintitle = wintitle, |
|
791 | 791 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
792 | 792 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
793 | 793 | show=show) |
|
794 | 794 | |
|
795 | 795 | nrow, ncol = self.getSubplots() |
|
796 | 796 | |
|
797 | 797 | counter = 0 |
|
798 | 798 | for y in range(nrow): |
|
799 | 799 | if counter >= self.nplots: |
|
800 | 800 | break |
|
801 | 801 | |
|
802 | 802 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
803 | 803 | counter += 1 |
|
804 | 804 | |
|
805 | 805 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', |
|
806 | 806 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
807 | 807 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
808 | 808 | timerange=None, SNRthresh = None, |
|
809 | 809 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
810 | 810 | server=None, folder=None, username=None, password=None, |
|
811 | 811 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
812 | 812 | """ |
|
813 | 813 | |
|
814 | 814 | Input: |
|
815 | 815 | dataOut : |
|
816 | 816 | id : |
|
817 | 817 | wintitle : |
|
818 | 818 | channelList : |
|
819 | 819 | showProfile : |
|
820 | 820 | xmin : None, |
|
821 | 821 | xmax : None, |
|
822 | 822 | ymin : None, |
|
823 | 823 | ymax : None, |
|
824 | 824 | zmin : None, |
|
825 | 825 | zmax : None |
|
826 | 826 | """ |
|
827 | 827 | |
|
828 | if dataOut.flagNoData: | |
|
829 | return dataOut | |
|
830 | ||
|
828 | 831 | # if timerange is not None: |
|
829 | 832 | # self.timerange = timerange |
|
830 | 833 | # |
|
831 | 834 | # tmin = None |
|
832 | 835 | # tmax = None |
|
833 | 836 | |
|
834 | 837 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
835 | 838 | y = dataOut.heightList |
|
836 | 839 | z = dataOut.data_output.copy() |
|
837 | 840 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
838 | 841 | nplotsw = nplots |
|
839 | 842 | |
|
840 | 843 | |
|
841 | 844 | #If there is a SNR function defined |
|
842 | 845 | if dataOut.data_SNR is not None: |
|
843 | 846 | nplots += 1 |
|
844 | 847 | SNR = dataOut.data_SNR[0] |
|
845 | 848 | SNRavg = SNR#numpy.average(SNR, axis=0) |
|
846 | 849 | |
|
847 | 850 | SNRdB = 10*numpy.log10(SNR) |
|
848 | 851 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
849 | 852 | |
|
850 | 853 | if SNRthresh == None: |
|
851 | 854 | SNRthresh = -5.0 |
|
852 | 855 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
853 | 856 | |
|
854 | 857 | for i in range(nplotsw): |
|
855 | 858 | z[i,ind] = numpy.nan |
|
856 | 859 | |
|
857 | 860 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
858 | 861 | #thisDatetime = datetime.datetime.now() |
|
859 | 862 | title = wintitle + "Wind" |
|
860 | 863 | xlabel = "" |
|
861 | 864 | ylabel = "Height (km)" |
|
862 | 865 | update_figfile = False |
|
863 | 866 | |
|
864 | 867 | if not self.isConfig: |
|
865 | 868 | |
|
866 | 869 | self.setup(id=id, |
|
867 | 870 | nplots=nplots, |
|
868 | 871 | wintitle=wintitle, |
|
869 | 872 | showprofile=showprofile, |
|
870 | 873 | show=show) |
|
871 | 874 | |
|
872 | 875 | if timerange is not None: |
|
873 | 876 | self.timerange = timerange |
|
874 | 877 | |
|
875 | 878 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
876 | 879 | |
|
877 | 880 | if ymin == None: ymin = numpy.nanmin(y) |
|
878 | 881 | if ymax == None: ymax = numpy.nanmax(y) |
|
879 | 882 | |
|
880 | 883 | if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:])) |
|
881 | 884 | #if numpy.isnan(zmax): zmax = 50 |
|
882 | 885 | if zmin == None: zmin = -zmax |
|
883 | 886 | |
|
884 | 887 | if nplotsw == 3: |
|
885 | 888 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
886 | 889 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
887 | 890 | |
|
888 | 891 | if dataOut.data_SNR is not None: |
|
889 | 892 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
890 | 893 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
891 | 894 | |
|
892 | 895 | |
|
893 | 896 | self.FTP_WEI = ftp_wei |
|
894 | 897 | self.EXP_CODE = exp_code |
|
895 | 898 | self.SUB_EXP_CODE = sub_exp_code |
|
896 | 899 | self.PLOT_POS = plot_pos |
|
897 | 900 | |
|
898 | 901 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
899 | 902 | self.isConfig = True |
|
900 | 903 | self.figfile = figfile |
|
901 | 904 | update_figfile = True |
|
902 | 905 | |
|
903 | 906 | self.setWinTitle(title) |
|
904 | 907 | |
|
905 | 908 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
906 | 909 | x[1] = self.xmax |
|
907 | 910 | |
|
908 | 911 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
909 | 912 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
910 | 913 | zmaxVector = [zmax, zmax, zmax_ver] |
|
911 | 914 | zminVector = [zmin, zmin, zmin_ver] |
|
912 | 915 | windFactor = [1,1,100] |
|
913 | 916 | |
|
914 | 917 | for i in range(nplotsw): |
|
915 | 918 | |
|
916 | 919 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
917 | 920 | axes = self.axesList[i*self.__nsubplots] |
|
918 | 921 | |
|
919 | 922 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
920 | 923 | |
|
921 | 924 | axes.pcolorbuffer(x, y, z1, |
|
922 | 925 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
923 | 926 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
924 | 927 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" ) |
|
925 | 928 | |
|
926 | 929 | if dataOut.data_SNR is not None: |
|
927 | 930 | i += 1 |
|
928 | 931 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
929 | 932 | axes = self.axesList[i*self.__nsubplots] |
|
930 | 933 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
931 | 934 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
932 | 935 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
933 | 936 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
934 | 937 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
935 | 938 | |
|
936 | 939 | self.draw() |
|
937 | 940 | |
|
938 | 941 | self.save(figpath=figpath, |
|
939 | 942 | figfile=figfile, |
|
940 | 943 | save=save, |
|
941 | 944 | ftp=ftp, |
|
942 | 945 | wr_period=wr_period, |
|
943 | 946 | thisDatetime=thisDatetime, |
|
944 | 947 | update_figfile=update_figfile) |
|
945 | 948 | |
|
946 | 949 | if dataOut.ltctime + dataOut.paramInterval >= self.xmax: |
|
947 | 950 | self.counter_imagwr = wr_period |
|
948 | 951 | self.isConfig = False |
|
949 | 952 | update_figfile = True |
|
950 | 953 | |
|
954 | return dataOut | |
|
955 | ||
|
951 | 956 | @MPDecorator |
|
952 | 957 | class ParametersPlot_(Figure): |
|
953 | 958 | |
|
954 | 959 | __isConfig = None |
|
955 | 960 | __nsubplots = None |
|
956 | 961 | |
|
957 | 962 | WIDTHPROF = None |
|
958 | 963 | HEIGHTPROF = None |
|
959 | 964 | PREFIX = 'param' |
|
960 | 965 | |
|
961 | 966 | nplots = None |
|
962 | 967 | nchan = None |
|
963 | 968 | |
|
964 | 969 | def __init__(self):#, **kwargs): |
|
965 | 970 | Figure.__init__(self)#, **kwargs) |
|
966 | 971 | self.timerange = None |
|
967 | 972 | self.isConfig = False |
|
968 | 973 | self.__nsubplots = 1 |
|
969 | 974 | |
|
970 | 975 | self.WIDTH = 300 |
|
971 | 976 | self.HEIGHT = 550 |
|
972 | 977 | self.WIDTHPROF = 120 |
|
973 | 978 | self.HEIGHTPROF = 0 |
|
974 | 979 | self.counter_imagwr = 0 |
|
975 | 980 | |
|
976 | 981 | self.PLOT_CODE = RTI_CODE |
|
977 | 982 | |
|
978 | 983 | self.FTP_WEI = None |
|
979 | 984 | self.EXP_CODE = None |
|
980 | 985 | self.SUB_EXP_CODE = None |
|
981 | 986 | self.PLOT_POS = None |
|
982 | 987 | self.tmin = None |
|
983 | 988 | self.tmax = None |
|
984 | 989 | |
|
985 | 990 | self.xmin = None |
|
986 | 991 | self.xmax = None |
|
987 | 992 | |
|
988 | 993 | self.figfile = None |
|
989 | 994 | |
|
990 | 995 | def getSubplots(self): |
|
991 | 996 | |
|
992 | 997 | ncol = 1 |
|
993 | 998 | nrow = self.nplots |
|
994 | 999 | |
|
995 | 1000 | return nrow, ncol |
|
996 | 1001 | |
|
997 | 1002 | def setup(self, id, nplots, wintitle, show=True): |
|
998 | 1003 | |
|
999 | 1004 | self.nplots = nplots |
|
1000 | 1005 | |
|
1001 | 1006 | ncolspan = 1 |
|
1002 | 1007 | colspan = 1 |
|
1003 | 1008 | |
|
1004 | 1009 | self.createFigure(id = id, |
|
1005 | 1010 | wintitle = wintitle, |
|
1006 | 1011 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1007 | 1012 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1008 | 1013 | show=show) |
|
1009 | 1014 | |
|
1010 | 1015 | nrow, ncol = self.getSubplots() |
|
1011 | 1016 | |
|
1012 | 1017 | counter = 0 |
|
1013 | 1018 | for y in range(nrow): |
|
1014 | 1019 | for x in range(ncol): |
|
1015 | 1020 | |
|
1016 | 1021 | if counter >= self.nplots: |
|
1017 | 1022 | break |
|
1018 | 1023 | |
|
1019 | 1024 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1020 | 1025 | |
|
1021 | 1026 | counter += 1 |
|
1022 | 1027 | |
|
1023 | 1028 | def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet", |
|
1024 | 1029 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None, |
|
1025 | 1030 | showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None, |
|
1026 | 1031 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1027 | 1032 | server=None, folder=None, username=None, password=None, |
|
1028 | 1033 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None): |
|
1029 | 1034 | """ |
|
1030 | 1035 | |
|
1031 | 1036 | Input: |
|
1032 | 1037 | dataOut : |
|
1033 | 1038 | id : |
|
1034 | 1039 | wintitle : |
|
1035 | 1040 | channelList : |
|
1036 | 1041 | showProfile : |
|
1037 | 1042 | xmin : None, |
|
1038 | 1043 | xmax : None, |
|
1039 | 1044 | ymin : None, |
|
1040 | 1045 | ymax : None, |
|
1041 | 1046 | zmin : None, |
|
1042 | 1047 | zmax : None |
|
1043 | 1048 | """ |
|
1044 | 1049 | if dataOut.flagNoData: |
|
1045 | 1050 | return dataOut |
|
1046 | 1051 | |
|
1047 | 1052 | |
|
1048 | 1053 | if HEIGHT is not None: |
|
1049 | 1054 | self.HEIGHT = HEIGHT |
|
1050 | 1055 | |
|
1051 | 1056 | |
|
1052 | 1057 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1053 | 1058 | return |
|
1054 | 1059 | |
|
1055 | 1060 | if channelList == None: |
|
1056 | 1061 | channelIndexList = list(range(dataOut.data_param.shape[0])) |
|
1057 | 1062 | else: |
|
1058 | 1063 | channelIndexList = [] |
|
1059 | 1064 | for channel in channelList: |
|
1060 | 1065 | if channel not in dataOut.channelList: |
|
1061 | 1066 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
1062 | 1067 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1063 | 1068 | |
|
1064 | 1069 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
1065 | 1070 | y = dataOut.getHeiRange() |
|
1066 | 1071 | |
|
1067 | 1072 | if dataOut.data_param.ndim == 3: |
|
1068 | 1073 | z = dataOut.data_param[channelIndexList,paramIndex,:] |
|
1069 | 1074 | else: |
|
1070 | 1075 | z = dataOut.data_param[channelIndexList,:] |
|
1071 | 1076 | |
|
1072 | 1077 | if showSNR: |
|
1073 | 1078 | #SNR data |
|
1074 | 1079 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
1075 | 1080 | SNRdB = 10*numpy.log10(SNRarray) |
|
1076 | 1081 | ind = numpy.where(SNRdB < SNRthresh) |
|
1077 | 1082 | z[ind] = numpy.nan |
|
1078 | 1083 | |
|
1079 | 1084 | thisDatetime = dataOut.datatime |
|
1080 | 1085 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1081 | 1086 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1082 | 1087 | xlabel = "" |
|
1083 | 1088 | ylabel = "Range (km)" |
|
1084 | 1089 | |
|
1085 | 1090 | update_figfile = False |
|
1086 | 1091 | |
|
1087 | 1092 | if not self.isConfig: |
|
1088 | 1093 | |
|
1089 | 1094 | nchan = len(channelIndexList) |
|
1090 | 1095 | self.nchan = nchan |
|
1091 | 1096 | self.plotFact = 1 |
|
1092 | 1097 | nplots = nchan |
|
1093 | 1098 | |
|
1094 | 1099 | if showSNR: |
|
1095 | 1100 | nplots = nchan*2 |
|
1096 | 1101 | self.plotFact = 2 |
|
1097 | 1102 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
1098 | 1103 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
1099 | 1104 | |
|
1100 | 1105 | self.setup(id=id, |
|
1101 | 1106 | nplots=nplots, |
|
1102 | 1107 | wintitle=wintitle, |
|
1103 | 1108 | show=show) |
|
1104 | 1109 | |
|
1105 | 1110 | if timerange != None: |
|
1106 | 1111 | self.timerange = timerange |
|
1107 | 1112 | |
|
1108 | 1113 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1109 | 1114 | |
|
1110 | 1115 | if ymin == None: ymin = numpy.nanmin(y) |
|
1111 | 1116 | if ymax == None: ymax = numpy.nanmax(y) |
|
1112 | 1117 | if zmin == None: zmin = numpy.nanmin(z) |
|
1113 | 1118 | if zmax == None: zmax = numpy.nanmax(z) |
|
1114 | 1119 | |
|
1115 | 1120 | self.FTP_WEI = ftp_wei |
|
1116 | 1121 | self.EXP_CODE = exp_code |
|
1117 | 1122 | self.SUB_EXP_CODE = sub_exp_code |
|
1118 | 1123 | self.PLOT_POS = plot_pos |
|
1119 | 1124 | |
|
1120 | 1125 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1121 | 1126 | self.isConfig = True |
|
1122 | 1127 | self.figfile = figfile |
|
1123 | 1128 | update_figfile = True |
|
1124 | 1129 | |
|
1125 | 1130 | self.setWinTitle(title) |
|
1126 | 1131 | |
|
1127 | 1132 | # for i in range(self.nchan): |
|
1128 | 1133 | # index = channelIndexList[i] |
|
1129 | 1134 | # title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1130 | 1135 | # axes = self.axesList[i*self.plotFact] |
|
1131 | 1136 | # z1 = z[i,:].reshape((1,-1)) |
|
1132 | 1137 | # axes.pcolorbuffer(x, y, z1, |
|
1133 | 1138 | # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1134 | 1139 | # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1135 | 1140 | # ticksize=9, cblabel='', cbsize="1%",colormap=colormap) |
|
1136 | 1141 | # |
|
1137 | 1142 | # if showSNR: |
|
1138 | 1143 | # title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1139 | 1144 | # axes = self.axesList[i*self.plotFact + 1] |
|
1140 | 1145 | # SNRdB1 = SNRdB[i,:].reshape((1,-1)) |
|
1141 | 1146 | # axes.pcolorbuffer(x, y, SNRdB1, |
|
1142 | 1147 | # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1143 | 1148 | # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1144 | 1149 | # ticksize=9, cblabel='', cbsize="1%",colormap='jet') |
|
1145 | 1150 | |
|
1146 | 1151 | i=0 |
|
1147 | 1152 | index = channelIndexList[i] |
|
1148 | 1153 | title = "Factor de reflectividad Z [dBZ]" |
|
1149 | 1154 | axes = self.axesList[i*self.plotFact] |
|
1150 | 1155 | z1 = z[i,:].reshape((1,-1)) |
|
1151 | 1156 | axes.pcolorbuffer(x, y, z1, |
|
1152 | 1157 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1153 | 1158 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1154 | 1159 | ticksize=9, cblabel='', cbsize="1%",colormap=colormap) |
|
1155 | 1160 | |
|
1156 | 1161 | if showSNR: |
|
1157 | 1162 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1158 | 1163 | axes = self.axesList[i*self.plotFact + 1] |
|
1159 | 1164 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) |
|
1160 | 1165 | axes.pcolorbuffer(x, y, SNRdB1, |
|
1161 | 1166 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1162 | 1167 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1163 | 1168 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') |
|
1164 | 1169 | |
|
1165 | 1170 | i=1 |
|
1166 | 1171 | index = channelIndexList[i] |
|
1167 | 1172 | title = "Velocidad vertical Doppler [m/s]" |
|
1168 | 1173 | axes = self.axesList[i*self.plotFact] |
|
1169 | 1174 | z1 = z[i,:].reshape((1,-1)) |
|
1170 | 1175 | axes.pcolorbuffer(x, y, z1, |
|
1171 | 1176 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-10, zmax=10, |
|
1172 | 1177 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1173 | 1178 | ticksize=9, cblabel='', cbsize="1%",colormap='seismic_r') |
|
1174 | 1179 | |
|
1175 | 1180 | if showSNR: |
|
1176 | 1181 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1177 | 1182 | axes = self.axesList[i*self.plotFact + 1] |
|
1178 | 1183 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) |
|
1179 | 1184 | axes.pcolorbuffer(x, y, SNRdB1, |
|
1180 | 1185 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1181 | 1186 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1182 | 1187 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') |
|
1183 | 1188 | |
|
1184 | 1189 | i=2 |
|
1185 | 1190 | index = channelIndexList[i] |
|
1186 | 1191 | title = "Intensidad de lluvia [mm/h]" |
|
1187 | 1192 | axes = self.axesList[i*self.plotFact] |
|
1188 | 1193 | z1 = z[i,:].reshape((1,-1)) |
|
1189 | 1194 | axes.pcolorbuffer(x, y, z1, |
|
1190 | 1195 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=40, |
|
1191 | 1196 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1192 | 1197 | ticksize=9, cblabel='', cbsize="1%",colormap='ocean_r') |
|
1193 | 1198 | |
|
1194 | 1199 | if showSNR: |
|
1195 | 1200 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1196 | 1201 | axes = self.axesList[i*self.plotFact + 1] |
|
1197 | 1202 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) |
|
1198 | 1203 | axes.pcolorbuffer(x, y, SNRdB1, |
|
1199 | 1204 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1200 | 1205 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1201 | 1206 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') |
|
1202 | 1207 | |
|
1203 | 1208 | |
|
1204 | 1209 | self.draw() |
|
1205 | 1210 | |
|
1206 | 1211 | if dataOut.ltctime >= self.xmax: |
|
1207 | 1212 | self.counter_imagwr = wr_period |
|
1208 | 1213 | self.isConfig = False |
|
1209 | 1214 | update_figfile = True |
|
1210 | 1215 | |
|
1211 | 1216 | self.save(figpath=figpath, |
|
1212 | 1217 | figfile=figfile, |
|
1213 | 1218 | save=save, |
|
1214 | 1219 | ftp=ftp, |
|
1215 | 1220 | wr_period=wr_period, |
|
1216 | 1221 | thisDatetime=thisDatetime, |
|
1217 | 1222 | update_figfile=update_figfile) |
|
1218 | 1223 | |
|
1219 | 1224 | return dataOut |
|
1220 | 1225 | @MPDecorator |
|
1221 | 1226 | class Parameters1Plot_(Figure): |
|
1222 | 1227 | |
|
1223 | 1228 | __isConfig = None |
|
1224 | 1229 | __nsubplots = None |
|
1225 | 1230 | |
|
1226 | 1231 | WIDTHPROF = None |
|
1227 | 1232 | HEIGHTPROF = None |
|
1228 | 1233 | PREFIX = 'prm' |
|
1229 | 1234 | |
|
1230 | 1235 | def __init__(self): |
|
1231 | 1236 | Figure.__init__(self) |
|
1232 | 1237 | self.timerange = 2*60*60 |
|
1233 | 1238 | self.isConfig = False |
|
1234 | 1239 | self.__nsubplots = 1 |
|
1235 | 1240 | |
|
1236 | 1241 | self.WIDTH = 800 |
|
1237 | 1242 | self.HEIGHT = 180 |
|
1238 | 1243 | self.WIDTHPROF = 120 |
|
1239 | 1244 | self.HEIGHTPROF = 0 |
|
1240 | 1245 | self.counter_imagwr = 0 |
|
1241 | 1246 | |
|
1242 | 1247 | self.PLOT_CODE = PARMS_CODE |
|
1243 | 1248 | |
|
1244 | 1249 | self.FTP_WEI = None |
|
1245 | 1250 | self.EXP_CODE = None |
|
1246 | 1251 | self.SUB_EXP_CODE = None |
|
1247 | 1252 | self.PLOT_POS = None |
|
1248 | 1253 | self.tmin = None |
|
1249 | 1254 | self.tmax = None |
|
1250 | 1255 | |
|
1251 | 1256 | self.xmin = None |
|
1252 | 1257 | self.xmax = None |
|
1253 | 1258 | |
|
1254 | 1259 | self.figfile = None |
|
1255 | 1260 | |
|
1256 | 1261 | def getSubplots(self): |
|
1257 | 1262 | |
|
1258 | 1263 | ncol = 1 |
|
1259 | 1264 | nrow = self.nplots |
|
1260 | 1265 | |
|
1261 | 1266 | return nrow, ncol |
|
1262 | 1267 | |
|
1263 | 1268 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1264 | 1269 | |
|
1265 | 1270 | self.__showprofile = showprofile |
|
1266 | 1271 | self.nplots = nplots |
|
1267 | 1272 | |
|
1268 | 1273 | ncolspan = 1 |
|
1269 | 1274 | colspan = 1 |
|
1270 | 1275 | |
|
1271 | 1276 | self.createFigure(id = id, |
|
1272 | 1277 | wintitle = wintitle, |
|
1273 | 1278 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1274 | 1279 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1275 | 1280 | show=show) |
|
1276 | 1281 | |
|
1277 | 1282 | nrow, ncol = self.getSubplots() |
|
1278 | 1283 | |
|
1279 | 1284 | counter = 0 |
|
1280 | 1285 | for y in range(nrow): |
|
1281 | 1286 | for x in range(ncol): |
|
1282 | 1287 | |
|
1283 | 1288 | if counter >= self.nplots: |
|
1284 | 1289 | break |
|
1285 | 1290 | |
|
1286 | 1291 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1287 | 1292 | |
|
1288 | 1293 | if showprofile: |
|
1289 | 1294 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1290 | 1295 | |
|
1291 | 1296 | counter += 1 |
|
1292 | 1297 | |
|
1293 | 1298 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
1294 | 1299 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
1295 | 1300 | parameterIndex = None, onlyPositive = False, |
|
1296 | 1301 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, |
|
1297 | 1302 | DOP = True, |
|
1298 | 1303 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
1299 | 1304 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1300 | 1305 | server=None, folder=None, username=None, password=None, |
|
1301 | 1306 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1302 | 1307 | |
|
1303 | 1308 | """ |
|
1304 | 1309 | Input: |
|
1305 | 1310 | dataOut : |
|
1306 | 1311 | id : |
|
1307 | 1312 | wintitle : |
|
1308 | 1313 | channelList : |
|
1309 | 1314 | showProfile : |
|
1310 | 1315 | xmin : None, |
|
1311 | 1316 | xmax : None, |
|
1312 | 1317 | ymin : None, |
|
1313 | 1318 | ymax : None, |
|
1314 | 1319 | zmin : None, |
|
1315 | 1320 | zmax : None |
|
1316 | 1321 | """ |
|
1317 | 1322 | if dataOut.flagNoData: |
|
1318 | 1323 | return dataOut |
|
1319 | 1324 | |
|
1320 | 1325 | data_param = getattr(dataOut, parameterObject) |
|
1321 | 1326 | |
|
1322 | 1327 | if channelList == None: |
|
1323 | 1328 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
1324 | 1329 | else: |
|
1325 | 1330 | channelIndexList = numpy.array(channelList) |
|
1326 | 1331 | |
|
1327 | 1332 | nchan = len(channelIndexList) #Number of channels being plotted |
|
1328 | 1333 | |
|
1329 | 1334 | if nchan < 1: |
|
1330 | 1335 | return |
|
1331 | 1336 | |
|
1332 | 1337 | nGraphsByChannel = 0 |
|
1333 | 1338 | |
|
1334 | 1339 | if SNR: |
|
1335 | 1340 | nGraphsByChannel += 1 |
|
1336 | 1341 | if DOP: |
|
1337 | 1342 | nGraphsByChannel += 1 |
|
1338 | 1343 | |
|
1339 | 1344 | if nGraphsByChannel < 1: |
|
1340 | 1345 | return |
|
1341 | 1346 | |
|
1342 | 1347 | nplots = nGraphsByChannel*nchan |
|
1343 | 1348 | |
|
1344 | 1349 | if timerange is not None: |
|
1345 | 1350 | self.timerange = timerange |
|
1346 | 1351 | |
|
1347 | 1352 | #tmin = None |
|
1348 | 1353 | #tmax = None |
|
1349 | 1354 | if parameterIndex == None: |
|
1350 | 1355 | parameterIndex = 1 |
|
1351 | 1356 | |
|
1352 | 1357 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
1353 | 1358 | y = dataOut.heightList |
|
1354 | 1359 | |
|
1355 | 1360 | if dataOut.data_param.ndim == 3: |
|
1356 | 1361 | z = dataOut.data_param[channelIndexList,parameterIndex,:] |
|
1357 | 1362 | else: |
|
1358 | 1363 | z = dataOut.data_param[channelIndexList,:] |
|
1359 | 1364 | |
|
1360 | 1365 | if dataOut.data_SNR is not None: |
|
1361 | 1366 | if dataOut.data_SNR.ndim == 2: |
|
1362 | 1367 | SNRavg = numpy.average(dataOut.data_SNR, axis=0) |
|
1363 | 1368 | else: |
|
1364 | 1369 | SNRavg = dataOut.data_SNR |
|
1365 | 1370 | SNRdB = 10*numpy.log10(SNRavg) |
|
1366 | 1371 | |
|
1367 | 1372 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1368 | 1373 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1369 | 1374 | xlabel = "" |
|
1370 | 1375 | ylabel = "Range (Km)" |
|
1371 | 1376 | |
|
1372 | 1377 | if onlyPositive: |
|
1373 | 1378 | colormap = "jet" |
|
1374 | 1379 | zmin = 0 |
|
1375 | 1380 | else: colormap = "RdBu_r" |
|
1376 | 1381 | |
|
1377 | 1382 | if not self.isConfig: |
|
1378 | 1383 | |
|
1379 | 1384 | self.setup(id=id, |
|
1380 | 1385 | nplots=nplots, |
|
1381 | 1386 | wintitle=wintitle, |
|
1382 | 1387 | showprofile=showprofile, |
|
1383 | 1388 | show=show) |
|
1384 | 1389 | |
|
1385 | 1390 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1386 | 1391 | |
|
1387 | 1392 | if ymin == None: ymin = numpy.nanmin(y) |
|
1388 | 1393 | if ymax == None: ymax = numpy.nanmax(y) |
|
1389 | 1394 | if zmin == None: zmin = numpy.nanmin(z) |
|
1390 | 1395 | if zmax == None: zmax = numpy.nanmax(z) |
|
1391 | 1396 | |
|
1392 | 1397 | if SNR: |
|
1393 | 1398 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
1394 | 1399 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
1395 | 1400 | |
|
1396 | 1401 | self.FTP_WEI = ftp_wei |
|
1397 | 1402 | self.EXP_CODE = exp_code |
|
1398 | 1403 | self.SUB_EXP_CODE = sub_exp_code |
|
1399 | 1404 | self.PLOT_POS = plot_pos |
|
1400 | 1405 | |
|
1401 | 1406 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1402 | 1407 | self.isConfig = True |
|
1403 | 1408 | self.figfile = figfile |
|
1404 | 1409 | |
|
1405 | 1410 | self.setWinTitle(title) |
|
1406 | 1411 | |
|
1407 | 1412 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1408 | 1413 | x[1] = self.xmax |
|
1409 | 1414 | |
|
1410 | 1415 | for i in range(nchan): |
|
1411 | 1416 | |
|
1412 | 1417 | if (SNR and not onlySNR): j = 2*i |
|
1413 | 1418 | else: j = i |
|
1414 | 1419 | |
|
1415 | 1420 | j = nGraphsByChannel*i |
|
1416 | 1421 | |
|
1417 | 1422 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1418 | 1423 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1419 | 1424 | |
|
1420 | 1425 | if not onlySNR: |
|
1421 | 1426 | axes = self.axesList[j*self.__nsubplots] |
|
1422 | 1427 | z1 = z[i,:].reshape((1,-1)) |
|
1423 | 1428 | axes.pcolorbuffer(x, y, z1, |
|
1424 | 1429 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1425 | 1430 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1426 | 1431 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1427 | 1432 | |
|
1428 | 1433 | if DOP: |
|
1429 | 1434 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1430 | 1435 | |
|
1431 | 1436 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1432 | 1437 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1433 | 1438 | axes = self.axesList[j] |
|
1434 | 1439 | z1 = z[i,:].reshape((1,-1)) |
|
1435 | 1440 | axes.pcolorbuffer(x, y, z1, |
|
1436 | 1441 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1437 | 1442 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1438 | 1443 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1439 | 1444 | |
|
1440 | 1445 | if SNR: |
|
1441 | 1446 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1442 | 1447 | axes = self.axesList[(j)*self.__nsubplots] |
|
1443 | 1448 | if not onlySNR: |
|
1444 | 1449 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
1445 | 1450 | |
|
1446 | 1451 | axes = self.axesList[(j + nGraphsByChannel-1)] |
|
1447 | 1452 | z1 = SNRdB.reshape((1,-1)) |
|
1448 | 1453 | axes.pcolorbuffer(x, y, z1, |
|
1449 | 1454 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1450 | 1455 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
1451 | 1456 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1452 | 1457 | |
|
1453 | 1458 | |
|
1454 | 1459 | |
|
1455 | 1460 | self.draw() |
|
1456 | 1461 | |
|
1457 | 1462 | if x[1] >= self.axesList[0].xmax: |
|
1458 | 1463 | self.counter_imagwr = wr_period |
|
1459 | 1464 | self.isConfig = False |
|
1460 | 1465 | self.figfile = None |
|
1461 | 1466 | |
|
1462 | 1467 | self.save(figpath=figpath, |
|
1463 | 1468 | figfile=figfile, |
|
1464 | 1469 | save=save, |
|
1465 | 1470 | ftp=ftp, |
|
1466 | 1471 | wr_period=wr_period, |
|
1467 | 1472 | thisDatetime=thisDatetime, |
|
1468 | 1473 | update_figfile=False) |
|
1469 | 1474 | return dataOut |
|
1470 | 1475 | |
|
1471 | 1476 | class SpectralFittingPlot_(Figure): |
|
1472 | 1477 | |
|
1473 | 1478 | __isConfig = None |
|
1474 | 1479 | __nsubplots = None |
|
1475 | 1480 | |
|
1476 | 1481 | WIDTHPROF = None |
|
1477 | 1482 | HEIGHTPROF = None |
|
1478 | 1483 | PREFIX = 'prm' |
|
1479 | 1484 | |
|
1480 | 1485 | |
|
1481 | 1486 | N = None |
|
1482 | 1487 | ippSeconds = None |
|
1483 | 1488 | |
|
1484 | 1489 | def __init__(self, **kwargs): |
|
1485 | 1490 | Figure.__init__(self, **kwargs) |
|
1486 | 1491 | self.isConfig = False |
|
1487 | 1492 | self.__nsubplots = 1 |
|
1488 | 1493 | |
|
1489 | 1494 | self.PLOT_CODE = SPECFIT_CODE |
|
1490 | 1495 | |
|
1491 | 1496 | self.WIDTH = 450 |
|
1492 | 1497 | self.HEIGHT = 250 |
|
1493 | 1498 | self.WIDTHPROF = 0 |
|
1494 | 1499 | self.HEIGHTPROF = 0 |
|
1495 | 1500 | |
|
1496 | 1501 | def getSubplots(self): |
|
1497 | 1502 | |
|
1498 | 1503 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1499 | 1504 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1500 | 1505 | |
|
1501 | 1506 | return nrow, ncol |
|
1502 | 1507 | |
|
1503 | 1508 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
1504 | 1509 | |
|
1505 | 1510 | showprofile = False |
|
1506 | 1511 | self.__showprofile = showprofile |
|
1507 | 1512 | self.nplots = nplots |
|
1508 | 1513 | |
|
1509 | 1514 | ncolspan = 5 |
|
1510 | 1515 | colspan = 4 |
|
1511 | 1516 | if showprofile: |
|
1512 | 1517 | ncolspan = 5 |
|
1513 | 1518 | colspan = 4 |
|
1514 | 1519 | self.__nsubplots = 2 |
|
1515 | 1520 | |
|
1516 | 1521 | self.createFigure(id = id, |
|
1517 | 1522 | wintitle = wintitle, |
|
1518 | 1523 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1519 | 1524 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1520 | 1525 | show=show) |
|
1521 | 1526 | |
|
1522 | 1527 | nrow, ncol = self.getSubplots() |
|
1523 | 1528 | |
|
1524 | 1529 | counter = 0 |
|
1525 | 1530 | for y in range(nrow): |
|
1526 | 1531 | for x in range(ncol): |
|
1527 | 1532 | |
|
1528 | 1533 | if counter >= self.nplots: |
|
1529 | 1534 | break |
|
1530 | 1535 | |
|
1531 | 1536 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1532 | 1537 | |
|
1533 | 1538 | if showprofile: |
|
1534 | 1539 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1535 | 1540 | |
|
1536 | 1541 | counter += 1 |
|
1537 | 1542 | |
|
1538 | 1543 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
1539 | 1544 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1540 | 1545 | save=False, figpath='./', figfile=None, show=True): |
|
1541 | 1546 | |
|
1542 | 1547 | """ |
|
1543 | 1548 | |
|
1544 | 1549 | Input: |
|
1545 | 1550 | dataOut : |
|
1546 | 1551 | id : |
|
1547 | 1552 | wintitle : |
|
1548 | 1553 | channelList : |
|
1549 | 1554 | showProfile : |
|
1550 | 1555 | xmin : None, |
|
1551 | 1556 | xmax : None, |
|
1552 | 1557 | zmin : None, |
|
1553 | 1558 | zmax : None |
|
1554 | 1559 | """ |
|
1555 | 1560 | |
|
1556 | 1561 | if cutHeight==None: |
|
1557 | 1562 | h=270 |
|
1558 | 1563 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
1559 | 1564 | cutHeight = dataOut.heightList[heightindex] |
|
1560 | 1565 | |
|
1561 | 1566 | factor = dataOut.normFactor |
|
1562 | 1567 | x = dataOut.abscissaList[:-1] |
|
1563 | 1568 | #y = dataOut.getHeiRange() |
|
1564 | 1569 | |
|
1565 | 1570 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
1566 | 1571 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1567 | 1572 | avg = numpy.average(z, axis=1) |
|
1568 | 1573 | listChannels = z.shape[0] |
|
1569 | 1574 | |
|
1570 | 1575 | #Reconstruct Function |
|
1571 | 1576 | if fit==True: |
|
1572 | 1577 | groupArray = dataOut.groupList |
|
1573 | 1578 | listChannels = groupArray.reshape((groupArray.size)) |
|
1574 | 1579 | listChannels.sort() |
|
1575 | 1580 | spcFitLine = numpy.zeros(z.shape) |
|
1576 | 1581 | constants = dataOut.constants |
|
1577 | 1582 | |
|
1578 | 1583 | nGroups = groupArray.shape[0] |
|
1579 | 1584 | nChannels = groupArray.shape[1] |
|
1580 | 1585 | nProfiles = z.shape[1] |
|
1581 | 1586 | |
|
1582 | 1587 | for f in range(nGroups): |
|
1583 | 1588 | groupChann = groupArray[f,:] |
|
1584 | 1589 | p = dataOut.data_param[f,:,heightindex] |
|
1585 | 1590 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
1586 | 1591 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
1587 | 1592 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
1588 | 1593 | spcFitLine[groupChann,:] = fitLineAux |
|
1589 | 1594 | # spcFitLine = spcFitLine/factor |
|
1590 | 1595 | |
|
1591 | 1596 | z = z[listChannels,:] |
|
1592 | 1597 | spcFitLine = spcFitLine[listChannels,:] |
|
1593 | 1598 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
1594 | 1599 | |
|
1595 | 1600 | zdB = 10*numpy.log10(z) |
|
1596 | 1601 | #thisDatetime = dataOut.datatime |
|
1597 | 1602 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1598 | 1603 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1599 | 1604 | xlabel = "Velocity (m/s)" |
|
1600 | 1605 | ylabel = "Spectrum" |
|
1601 | 1606 | |
|
1602 | 1607 | if not self.isConfig: |
|
1603 | 1608 | |
|
1604 | 1609 | nplots = listChannels.size |
|
1605 | 1610 | |
|
1606 | 1611 | self.setup(id=id, |
|
1607 | 1612 | nplots=nplots, |
|
1608 | 1613 | wintitle=wintitle, |
|
1609 | 1614 | showprofile=showprofile, |
|
1610 | 1615 | show=show) |
|
1611 | 1616 | |
|
1612 | 1617 | if xmin == None: xmin = numpy.nanmin(x) |
|
1613 | 1618 | if xmax == None: xmax = numpy.nanmax(x) |
|
1614 | 1619 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1615 | 1620 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
1616 | 1621 | |
|
1617 | 1622 | self.isConfig = True |
|
1618 | 1623 | |
|
1619 | 1624 | self.setWinTitle(title) |
|
1620 | 1625 | for i in range(self.nplots): |
|
1621 | 1626 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
1622 | 1627 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]) |
|
1623 | 1628 | axes = self.axesList[i*self.__nsubplots] |
|
1624 | 1629 | if fit == False: |
|
1625 | 1630 | axes.pline(x, zdB[i,:], |
|
1626 | 1631 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1627 | 1632 | xlabel=xlabel, ylabel=ylabel, title=title |
|
1628 | 1633 | ) |
|
1629 | 1634 | if fit == True: |
|
1630 | 1635 | fitline=spcFitLinedB[i,:] |
|
1631 | 1636 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
1632 | 1637 | legendlabels=['Data','Fitting'] |
|
1633 | 1638 | axes.pmultilineyaxis(x, y, |
|
1634 | 1639 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1635 | 1640 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
1636 | 1641 | legendlabels=legendlabels, marker=None, |
|
1637 | 1642 | linestyle='solid', grid='both') |
|
1638 | 1643 | |
|
1639 | 1644 | self.draw() |
|
1640 | 1645 | |
|
1641 | 1646 | self.save(figpath=figpath, |
|
1642 | 1647 | figfile=figfile, |
|
1643 | 1648 | save=save, |
|
1644 | 1649 | ftp=ftp, |
|
1645 | 1650 | wr_period=wr_period, |
|
1646 | 1651 | thisDatetime=thisDatetime) |
|
1647 | 1652 | |
|
1648 | 1653 | |
|
1649 | 1654 | class EWDriftsPlot_(Figure): |
|
1650 | 1655 | |
|
1651 | 1656 | __isConfig = None |
|
1652 | 1657 | __nsubplots = None |
|
1653 | 1658 | |
|
1654 | 1659 | WIDTHPROF = None |
|
1655 | 1660 | HEIGHTPROF = None |
|
1656 | 1661 | PREFIX = 'drift' |
|
1657 | 1662 | |
|
1658 | 1663 | def __init__(self, **kwargs): |
|
1659 | 1664 | Figure.__init__(self, **kwargs) |
|
1660 | 1665 | self.timerange = 2*60*60 |
|
1661 | 1666 | self.isConfig = False |
|
1662 | 1667 | self.__nsubplots = 1 |
|
1663 | 1668 | |
|
1664 | 1669 | self.WIDTH = 800 |
|
1665 | 1670 | self.HEIGHT = 150 |
|
1666 | 1671 | self.WIDTHPROF = 120 |
|
1667 | 1672 | self.HEIGHTPROF = 0 |
|
1668 | 1673 | self.counter_imagwr = 0 |
|
1669 | 1674 | |
|
1670 | 1675 | self.PLOT_CODE = EWDRIFT_CODE |
|
1671 | 1676 | |
|
1672 | 1677 | self.FTP_WEI = None |
|
1673 | 1678 | self.EXP_CODE = None |
|
1674 | 1679 | self.SUB_EXP_CODE = None |
|
1675 | 1680 | self.PLOT_POS = None |
|
1676 | 1681 | self.tmin = None |
|
1677 | 1682 | self.tmax = None |
|
1678 | 1683 | |
|
1679 | 1684 | self.xmin = None |
|
1680 | 1685 | self.xmax = None |
|
1681 | 1686 | |
|
1682 | 1687 | self.figfile = None |
|
1683 | 1688 | |
|
1684 | 1689 | def getSubplots(self): |
|
1685 | 1690 | |
|
1686 | 1691 | ncol = 1 |
|
1687 | 1692 | nrow = self.nplots |
|
1688 | 1693 | |
|
1689 | 1694 | return nrow, ncol |
|
1690 | 1695 | |
|
1691 | 1696 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1692 | 1697 | |
|
1693 | 1698 | self.__showprofile = showprofile |
|
1694 | 1699 | self.nplots = nplots |
|
1695 | 1700 | |
|
1696 | 1701 | ncolspan = 1 |
|
1697 | 1702 | colspan = 1 |
|
1698 | 1703 | |
|
1699 | 1704 | self.createFigure(id = id, |
|
1700 | 1705 | wintitle = wintitle, |
|
1701 | 1706 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1702 | 1707 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1703 | 1708 | show=show) |
|
1704 | 1709 | |
|
1705 | 1710 | nrow, ncol = self.getSubplots() |
|
1706 | 1711 | |
|
1707 | 1712 | counter = 0 |
|
1708 | 1713 | for y in range(nrow): |
|
1709 | 1714 | if counter >= self.nplots: |
|
1710 | 1715 | break |
|
1711 | 1716 | |
|
1712 | 1717 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1713 | 1718 | counter += 1 |
|
1714 | 1719 | |
|
1715 | 1720 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1716 | 1721 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1717 | 1722 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1718 | 1723 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1719 | 1724 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1720 | 1725 | server=None, folder=None, username=None, password=None, |
|
1721 | 1726 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1722 | 1727 | """ |
|
1723 | 1728 | |
|
1724 | 1729 | Input: |
|
1725 | 1730 | dataOut : |
|
1726 | 1731 | id : |
|
1727 | 1732 | wintitle : |
|
1728 | 1733 | channelList : |
|
1729 | 1734 | showProfile : |
|
1730 | 1735 | xmin : None, |
|
1731 | 1736 | xmax : None, |
|
1732 | 1737 | ymin : None, |
|
1733 | 1738 | ymax : None, |
|
1734 | 1739 | zmin : None, |
|
1735 | 1740 | zmax : None |
|
1736 | 1741 | """ |
|
1737 | 1742 | |
|
1738 | 1743 | if timerange is not None: |
|
1739 | 1744 | self.timerange = timerange |
|
1740 | 1745 | |
|
1741 | 1746 | tmin = None |
|
1742 | 1747 | tmax = None |
|
1743 | 1748 | |
|
1744 | 1749 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1745 | 1750 | # y = dataOut.heightList |
|
1746 | 1751 | y = dataOut.heightList |
|
1747 | 1752 | |
|
1748 | 1753 | z = dataOut.data_output |
|
1749 | 1754 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1750 | 1755 | nplotsw = nplots |
|
1751 | 1756 | |
|
1752 | 1757 | #If there is a SNR function defined |
|
1753 | 1758 | if dataOut.data_SNR is not None: |
|
1754 | 1759 | nplots += 1 |
|
1755 | 1760 | SNR = dataOut.data_SNR |
|
1756 | 1761 | |
|
1757 | 1762 | if SNR_1: |
|
1758 | 1763 | SNR += 1 |
|
1759 | 1764 | |
|
1760 | 1765 | SNRavg = numpy.average(SNR, axis=0) |
|
1761 | 1766 | |
|
1762 | 1767 | SNRdB = 10*numpy.log10(SNR) |
|
1763 | 1768 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1764 | 1769 | |
|
1765 | 1770 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1766 | 1771 | |
|
1767 | 1772 | for i in range(nplotsw): |
|
1768 | 1773 | z[i,ind] = numpy.nan |
|
1769 | 1774 | |
|
1770 | 1775 | |
|
1771 | 1776 | showprofile = False |
|
1772 | 1777 | # thisDatetime = dataOut.datatime |
|
1773 | 1778 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1774 | 1779 | title = wintitle + " EW Drifts" |
|
1775 | 1780 | xlabel = "" |
|
1776 | 1781 | ylabel = "Height (Km)" |
|
1777 | 1782 | |
|
1778 | 1783 | if not self.isConfig: |
|
1779 | 1784 | |
|
1780 | 1785 | self.setup(id=id, |
|
1781 | 1786 | nplots=nplots, |
|
1782 | 1787 | wintitle=wintitle, |
|
1783 | 1788 | showprofile=showprofile, |
|
1784 | 1789 | show=show) |
|
1785 | 1790 | |
|
1786 | 1791 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1787 | 1792 | |
|
1788 | 1793 | if ymin == None: ymin = numpy.nanmin(y) |
|
1789 | 1794 | if ymax == None: ymax = numpy.nanmax(y) |
|
1790 | 1795 | |
|
1791 | 1796 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1792 | 1797 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1793 | 1798 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1794 | 1799 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1795 | 1800 | |
|
1796 | 1801 | if dataOut.data_SNR is not None: |
|
1797 | 1802 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1798 | 1803 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1799 | 1804 | |
|
1800 | 1805 | self.FTP_WEI = ftp_wei |
|
1801 | 1806 | self.EXP_CODE = exp_code |
|
1802 | 1807 | self.SUB_EXP_CODE = sub_exp_code |
|
1803 | 1808 | self.PLOT_POS = plot_pos |
|
1804 | 1809 | |
|
1805 | 1810 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1806 | 1811 | self.isConfig = True |
|
1807 | 1812 | |
|
1808 | 1813 | |
|
1809 | 1814 | self.setWinTitle(title) |
|
1810 | 1815 | |
|
1811 | 1816 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1812 | 1817 | x[1] = self.xmax |
|
1813 | 1818 | |
|
1814 | 1819 | strWind = ['Zonal','Vertical'] |
|
1815 | 1820 | strCb = 'Velocity (m/s)' |
|
1816 | 1821 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1817 | 1822 | zminVector = [zminZonal, zminVertical] |
|
1818 | 1823 | |
|
1819 | 1824 | for i in range(nplotsw): |
|
1820 | 1825 | |
|
1821 | 1826 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1822 | 1827 | axes = self.axesList[i*self.__nsubplots] |
|
1823 | 1828 | |
|
1824 | 1829 | z1 = z[i,:].reshape((1,-1)) |
|
1825 | 1830 | |
|
1826 | 1831 | axes.pcolorbuffer(x, y, z1, |
|
1827 | 1832 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1828 | 1833 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1829 | 1834 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1830 | 1835 | |
|
1831 | 1836 | if dataOut.data_SNR is not None: |
|
1832 | 1837 | i += 1 |
|
1833 | 1838 | if SNR_1: |
|
1834 | 1839 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1835 | 1840 | else: |
|
1836 | 1841 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1837 | 1842 | axes = self.axesList[i*self.__nsubplots] |
|
1838 | 1843 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1839 | 1844 | |
|
1840 | 1845 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1841 | 1846 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1842 | 1847 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1843 | 1848 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1844 | 1849 | |
|
1845 | 1850 | self.draw() |
|
1846 | 1851 | |
|
1847 | 1852 | if x[1] >= self.axesList[0].xmax: |
|
1848 | 1853 | self.counter_imagwr = wr_period |
|
1849 | 1854 | self.isConfig = False |
|
1850 | 1855 | self.figfile = None |
|
1851 | 1856 | |
|
1852 | 1857 | |
|
1853 | 1858 | |
|
1854 | 1859 | |
|
1855 | 1860 | class PhasePlot_(Figure): |
|
1856 | 1861 | |
|
1857 | 1862 | __isConfig = None |
|
1858 | 1863 | __nsubplots = None |
|
1859 | 1864 | |
|
1860 | 1865 | PREFIX = 'mphase' |
|
1861 | 1866 | |
|
1862 | 1867 | |
|
1863 | 1868 | def __init__(self, **kwargs): |
|
1864 | 1869 | Figure.__init__(self, **kwargs) |
|
1865 | 1870 | self.timerange = 24*60*60 |
|
1866 | 1871 | self.isConfig = False |
|
1867 | 1872 | self.__nsubplots = 1 |
|
1868 | 1873 | self.counter_imagwr = 0 |
|
1869 | 1874 | self.WIDTH = 600 |
|
1870 | 1875 | self.HEIGHT = 300 |
|
1871 | 1876 | self.WIDTHPROF = 120 |
|
1872 | 1877 | self.HEIGHTPROF = 0 |
|
1873 | 1878 | self.xdata = None |
|
1874 | 1879 | self.ydata = None |
|
1875 | 1880 | |
|
1876 | 1881 | self.PLOT_CODE = MPHASE_CODE |
|
1877 | 1882 | |
|
1878 | 1883 | self.FTP_WEI = None |
|
1879 | 1884 | self.EXP_CODE = None |
|
1880 | 1885 | self.SUB_EXP_CODE = None |
|
1881 | 1886 | self.PLOT_POS = None |
|
1882 | 1887 | |
|
1883 | 1888 | |
|
1884 | 1889 | self.filename_phase = None |
|
1885 | 1890 | |
|
1886 | 1891 | self.figfile = None |
|
1887 | 1892 | |
|
1888 | 1893 | def getSubplots(self): |
|
1889 | 1894 | |
|
1890 | 1895 | ncol = 1 |
|
1891 | 1896 | nrow = 1 |
|
1892 | 1897 | |
|
1893 | 1898 | return nrow, ncol |
|
1894 | 1899 | |
|
1895 | 1900 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1896 | 1901 | |
|
1897 | 1902 | self.__showprofile = showprofile |
|
1898 | 1903 | self.nplots = nplots |
|
1899 | 1904 | |
|
1900 | 1905 | ncolspan = 7 |
|
1901 | 1906 | colspan = 6 |
|
1902 | 1907 | self.__nsubplots = 2 |
|
1903 | 1908 | |
|
1904 | 1909 | self.createFigure(id = id, |
|
1905 | 1910 | wintitle = wintitle, |
|
1906 | 1911 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1907 | 1912 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1908 | 1913 | show=show) |
|
1909 | 1914 | |
|
1910 | 1915 | nrow, ncol = self.getSubplots() |
|
1911 | 1916 | |
|
1912 | 1917 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1913 | 1918 | |
|
1914 | 1919 | |
|
1915 | 1920 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1916 | 1921 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1917 | 1922 | timerange=None, |
|
1918 | 1923 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1919 | 1924 | server=None, folder=None, username=None, password=None, |
|
1920 | 1925 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1921 | 1926 | |
|
1922 | 1927 | |
|
1923 | 1928 | tmin = None |
|
1924 | 1929 | tmax = None |
|
1925 | 1930 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1926 | 1931 | y = dataOut.getHeiRange() |
|
1927 | 1932 | |
|
1928 | 1933 | |
|
1929 | 1934 | #thisDatetime = dataOut.datatime |
|
1930 | 1935 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
1931 | 1936 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1932 | 1937 | xlabel = "Local Time" |
|
1933 | 1938 | ylabel = "Phase" |
|
1934 | 1939 | |
|
1935 | 1940 | |
|
1936 | 1941 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1937 | 1942 | phase_beacon = dataOut.data_output |
|
1938 | 1943 | update_figfile = False |
|
1939 | 1944 | |
|
1940 | 1945 | if not self.isConfig: |
|
1941 | 1946 | |
|
1942 | 1947 | self.nplots = phase_beacon.size |
|
1943 | 1948 | |
|
1944 | 1949 | self.setup(id=id, |
|
1945 | 1950 | nplots=self.nplots, |
|
1946 | 1951 | wintitle=wintitle, |
|
1947 | 1952 | showprofile=showprofile, |
|
1948 | 1953 | show=show) |
|
1949 | 1954 | |
|
1950 | 1955 | if timerange is not None: |
|
1951 | 1956 | self.timerange = timerange |
|
1952 | 1957 | |
|
1953 | 1958 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1954 | 1959 | |
|
1955 | 1960 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1956 | 1961 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1957 | 1962 | |
|
1958 | 1963 | self.FTP_WEI = ftp_wei |
|
1959 | 1964 | self.EXP_CODE = exp_code |
|
1960 | 1965 | self.SUB_EXP_CODE = sub_exp_code |
|
1961 | 1966 | self.PLOT_POS = plot_pos |
|
1962 | 1967 | |
|
1963 | 1968 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1964 | 1969 | self.isConfig = True |
|
1965 | 1970 | self.figfile = figfile |
|
1966 | 1971 | self.xdata = numpy.array([]) |
|
1967 | 1972 | self.ydata = numpy.array([]) |
|
1968 | 1973 | |
|
1969 | 1974 | #open file beacon phase |
|
1970 | 1975 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1971 | 1976 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1972 | 1977 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1973 | 1978 | update_figfile = True |
|
1974 | 1979 | |
|
1975 | 1980 | |
|
1976 | 1981 | #store data beacon phase |
|
1977 | 1982 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1978 | 1983 | |
|
1979 | 1984 | self.setWinTitle(title) |
|
1980 | 1985 | |
|
1981 | 1986 | |
|
1982 | 1987 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1983 | 1988 | |
|
1984 | 1989 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] |
|
1985 | 1990 | |
|
1986 | 1991 | axes = self.axesList[0] |
|
1987 | 1992 | |
|
1988 | 1993 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1989 | 1994 | |
|
1990 | 1995 | if len(self.ydata)==0: |
|
1991 | 1996 | self.ydata = phase_beacon.reshape(-1,1) |
|
1992 | 1997 | else: |
|
1993 | 1998 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1994 | 1999 | |
|
1995 | 2000 | |
|
1996 | 2001 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1997 | 2002 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1998 | 2003 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1999 | 2004 | XAxisAsTime=True, grid='both' |
|
2000 | 2005 | ) |
|
2001 | 2006 | |
|
2002 | 2007 | self.draw() |
|
2003 | 2008 | |
|
2004 | 2009 | self.save(figpath=figpath, |
|
2005 | 2010 | figfile=figfile, |
|
2006 | 2011 | save=save, |
|
2007 | 2012 | ftp=ftp, |
|
2008 | 2013 | wr_period=wr_period, |
|
2009 | 2014 | thisDatetime=thisDatetime, |
|
2010 | 2015 | update_figfile=update_figfile) |
|
2011 | 2016 | |
|
2012 | 2017 | if dataOut.ltctime + dataOut.outputInterval >= self.xmax: |
|
2013 | 2018 | self.counter_imagwr = wr_period |
|
2014 | 2019 | self.isConfig = False |
|
2015 | 2020 | update_figfile = True |
|
2016 | 2021 | |
|
2017 | 2022 | |
|
2018 | 2023 | |
|
2019 | 2024 | class NSMeteorDetection1Plot_(Figure): |
|
2020 | 2025 | |
|
2021 | 2026 | isConfig = None |
|
2022 | 2027 | __nsubplots = None |
|
2023 | 2028 | |
|
2024 | 2029 | WIDTHPROF = None |
|
2025 | 2030 | HEIGHTPROF = None |
|
2026 | 2031 | PREFIX = 'nsm' |
|
2027 | 2032 | |
|
2028 | 2033 | zminList = None |
|
2029 | 2034 | zmaxList = None |
|
2030 | 2035 | cmapList = None |
|
2031 | 2036 | titleList = None |
|
2032 | 2037 | nPairs = None |
|
2033 | 2038 | nChannels = None |
|
2034 | 2039 | nParam = None |
|
2035 | 2040 | |
|
2036 | 2041 | def __init__(self, **kwargs): |
|
2037 | 2042 | Figure.__init__(self, **kwargs) |
|
2038 | 2043 | self.isConfig = False |
|
2039 | 2044 | self.__nsubplots = 1 |
|
2040 | 2045 | |
|
2041 | 2046 | self.WIDTH = 750 |
|
2042 | 2047 | self.HEIGHT = 250 |
|
2043 | 2048 | self.WIDTHPROF = 120 |
|
2044 | 2049 | self.HEIGHTPROF = 0 |
|
2045 | 2050 | self.counter_imagwr = 0 |
|
2046 | 2051 | |
|
2047 | 2052 | self.PLOT_CODE = SPEC_CODE |
|
2048 | 2053 | |
|
2049 | 2054 | self.FTP_WEI = None |
|
2050 | 2055 | self.EXP_CODE = None |
|
2051 | 2056 | self.SUB_EXP_CODE = None |
|
2052 | 2057 | self.PLOT_POS = None |
|
2053 | 2058 | |
|
2054 | 2059 | self.__xfilter_ena = False |
|
2055 | 2060 | self.__yfilter_ena = False |
|
2056 | 2061 | |
|
2057 | 2062 | def getSubplots(self): |
|
2058 | 2063 | |
|
2059 | 2064 | ncol = 3 |
|
2060 | 2065 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
2061 | 2066 | |
|
2062 | 2067 | return nrow, ncol |
|
2063 | 2068 | |
|
2064 | 2069 | def setup(self, id, nplots, wintitle, show=True): |
|
2065 | 2070 | |
|
2066 | 2071 | self.nplots = nplots |
|
2067 | 2072 | |
|
2068 | 2073 | ncolspan = 1 |
|
2069 | 2074 | colspan = 1 |
|
2070 | 2075 | |
|
2071 | 2076 | self.createFigure(id = id, |
|
2072 | 2077 | wintitle = wintitle, |
|
2073 | 2078 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
2074 | 2079 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
2075 | 2080 | show=show) |
|
2076 | 2081 | |
|
2077 | 2082 | nrow, ncol = self.getSubplots() |
|
2078 | 2083 | |
|
2079 | 2084 | counter = 0 |
|
2080 | 2085 | for y in range(nrow): |
|
2081 | 2086 | for x in range(ncol): |
|
2082 | 2087 | |
|
2083 | 2088 | if counter >= self.nplots: |
|
2084 | 2089 | break |
|
2085 | 2090 | |
|
2086 | 2091 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
2087 | 2092 | |
|
2088 | 2093 | counter += 1 |
|
2089 | 2094 | |
|
2090 | 2095 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
2091 | 2096 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
2092 | 2097 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
2093 | 2098 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
2094 | 2099 | server=None, folder=None, username=None, password=None, |
|
2095 | 2100 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
2096 | 2101 | xaxis="frequency"): |
|
2097 | 2102 | |
|
2098 | 2103 | """ |
|
2099 | 2104 | |
|
2100 | 2105 | Input: |
|
2101 | 2106 | dataOut : |
|
2102 | 2107 | id : |
|
2103 | 2108 | wintitle : |
|
2104 | 2109 | channelList : |
|
2105 | 2110 | showProfile : |
|
2106 | 2111 | xmin : None, |
|
2107 | 2112 | xmax : None, |
|
2108 | 2113 | ymin : None, |
|
2109 | 2114 | ymax : None, |
|
2110 | 2115 | zmin : None, |
|
2111 | 2116 | zmax : None |
|
2112 | 2117 | """ |
|
2113 | 2118 | #SEPARAR EN DOS PLOTS |
|
2114 | 2119 | nParam = dataOut.data_param.shape[1] - 3 |
|
2115 | 2120 | |
|
2116 | 2121 | utctime = dataOut.data_param[0,0] |
|
2117 | 2122 | tmet = dataOut.data_param[:,1].astype(int) |
|
2118 | 2123 | hmet = dataOut.data_param[:,2].astype(int) |
|
2119 | 2124 | |
|
2120 | 2125 | x = dataOut.abscissaList |
|
2121 | 2126 | y = dataOut.heightList |
|
2122 | 2127 | |
|
2123 | 2128 | z = numpy.zeros((nParam, y.size, x.size - 1)) |
|
2124 | 2129 | z[:,:] = numpy.nan |
|
2125 | 2130 | z[:,hmet,tmet] = dataOut.data_param[:,3:].T |
|
2126 | 2131 | z[0,:,:] = 10*numpy.log10(z[0,:,:]) |
|
2127 | 2132 | |
|
2128 | 2133 | xlabel = "Time (s)" |
|
2129 | 2134 | ylabel = "Range (km)" |
|
2130 | 2135 | |
|
2131 | 2136 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
2132 | 2137 | |
|
2133 | 2138 | if not self.isConfig: |
|
2134 | 2139 | |
|
2135 | 2140 | nplots = nParam |
|
2136 | 2141 | |
|
2137 | 2142 | self.setup(id=id, |
|
2138 | 2143 | nplots=nplots, |
|
2139 | 2144 | wintitle=wintitle, |
|
2140 | 2145 | show=show) |
|
2141 | 2146 | |
|
2142 | 2147 | if xmin is None: xmin = numpy.nanmin(x) |
|
2143 | 2148 | if xmax is None: xmax = numpy.nanmax(x) |
|
2144 | 2149 | if ymin is None: ymin = numpy.nanmin(y) |
|
2145 | 2150 | if ymax is None: ymax = numpy.nanmax(y) |
|
2146 | 2151 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
2147 | 2152 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
2148 | 2153 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
2149 | 2154 | if vmin is None: vmin = -vmax |
|
2150 | 2155 | if wmin is None: wmin = 0 |
|
2151 | 2156 | if wmax is None: wmax = 50 |
|
2152 | 2157 | |
|
2153 | 2158 | pairsList = dataOut.groupList |
|
2154 | 2159 | self.nPairs = len(dataOut.groupList) |
|
2155 | 2160 | |
|
2156 | 2161 | zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs |
|
2157 | 2162 | zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs |
|
2158 | 2163 | titleList = ["SNR","Radial Velocity","Coherence"] |
|
2159 | 2164 | cmapList = ["jet","RdBu_r","jet"] |
|
2160 | 2165 | |
|
2161 | 2166 | for i in range(self.nPairs): |
|
2162 | 2167 | strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1]) |
|
2163 | 2168 | titleList = titleList + [strAux1] |
|
2164 | 2169 | cmapList = cmapList + ["RdBu_r"] |
|
2165 | 2170 | |
|
2166 | 2171 | self.zminList = zminList |
|
2167 | 2172 | self.zmaxList = zmaxList |
|
2168 | 2173 | self.cmapList = cmapList |
|
2169 | 2174 | self.titleList = titleList |
|
2170 | 2175 | |
|
2171 | 2176 | self.FTP_WEI = ftp_wei |
|
2172 | 2177 | self.EXP_CODE = exp_code |
|
2173 | 2178 | self.SUB_EXP_CODE = sub_exp_code |
|
2174 | 2179 | self.PLOT_POS = plot_pos |
|
2175 | 2180 | |
|
2176 | 2181 | self.isConfig = True |
|
2177 | 2182 | |
|
2178 | 2183 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
2179 | 2184 | |
|
2180 | 2185 | for i in range(nParam): |
|
2181 | 2186 | title = self.titleList[i] + ": " +str_datetime |
|
2182 | 2187 | axes = self.axesList[i] |
|
2183 | 2188 | axes.pcolor(x, y, z[i,:].T, |
|
2184 | 2189 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
2185 | 2190 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
2186 | 2191 | self.draw() |
|
2187 | 2192 | |
|
2188 | 2193 | if figfile == None: |
|
2189 | 2194 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
2190 | 2195 | name = str_datetime |
|
2191 | 2196 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
2192 | 2197 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
2193 | 2198 | figfile = self.getFilename(name) |
|
2194 | 2199 | |
|
2195 | 2200 | self.save(figpath=figpath, |
|
2196 | 2201 | figfile=figfile, |
|
2197 | 2202 | save=save, |
|
2198 | 2203 | ftp=ftp, |
|
2199 | 2204 | wr_period=wr_period, |
|
2200 | 2205 | thisDatetime=thisDatetime) |
|
2201 | 2206 | |
|
2202 | 2207 | |
|
2203 | 2208 | class NSMeteorDetection2Plot_(Figure): |
|
2204 | 2209 | |
|
2205 | 2210 | isConfig = None |
|
2206 | 2211 | __nsubplots = None |
|
2207 | 2212 | |
|
2208 | 2213 | WIDTHPROF = None |
|
2209 | 2214 | HEIGHTPROF = None |
|
2210 | 2215 | PREFIX = 'nsm' |
|
2211 | 2216 | |
|
2212 | 2217 | zminList = None |
|
2213 | 2218 | zmaxList = None |
|
2214 | 2219 | cmapList = None |
|
2215 | 2220 | titleList = None |
|
2216 | 2221 | nPairs = None |
|
2217 | 2222 | nChannels = None |
|
2218 | 2223 | nParam = None |
|
2219 | 2224 | |
|
2220 | 2225 | def __init__(self, **kwargs): |
|
2221 | 2226 | Figure.__init__(self, **kwargs) |
|
2222 | 2227 | self.isConfig = False |
|
2223 | 2228 | self.__nsubplots = 1 |
|
2224 | 2229 | |
|
2225 | 2230 | self.WIDTH = 750 |
|
2226 | 2231 | self.HEIGHT = 250 |
|
2227 | 2232 | self.WIDTHPROF = 120 |
|
2228 | 2233 | self.HEIGHTPROF = 0 |
|
2229 | 2234 | self.counter_imagwr = 0 |
|
2230 | 2235 | |
|
2231 | 2236 | self.PLOT_CODE = SPEC_CODE |
|
2232 | 2237 | |
|
2233 | 2238 | self.FTP_WEI = None |
|
2234 | 2239 | self.EXP_CODE = None |
|
2235 | 2240 | self.SUB_EXP_CODE = None |
|
2236 | 2241 | self.PLOT_POS = None |
|
2237 | 2242 | |
|
2238 | 2243 | self.__xfilter_ena = False |
|
2239 | 2244 | self.__yfilter_ena = False |
|
2240 | 2245 | |
|
2241 | 2246 | def getSubplots(self): |
|
2242 | 2247 | |
|
2243 | 2248 | ncol = 3 |
|
2244 | 2249 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
2245 | 2250 | |
|
2246 | 2251 | return nrow, ncol |
|
2247 | 2252 | |
|
2248 | 2253 | def setup(self, id, nplots, wintitle, show=True): |
|
2249 | 2254 | |
|
2250 | 2255 | self.nplots = nplots |
|
2251 | 2256 | |
|
2252 | 2257 | ncolspan = 1 |
|
2253 | 2258 | colspan = 1 |
|
2254 | 2259 | |
|
2255 | 2260 | self.createFigure(id = id, |
|
2256 | 2261 | wintitle = wintitle, |
|
2257 | 2262 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
2258 | 2263 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
2259 | 2264 | show=show) |
|
2260 | 2265 | |
|
2261 | 2266 | nrow, ncol = self.getSubplots() |
|
2262 | 2267 | |
|
2263 | 2268 | counter = 0 |
|
2264 | 2269 | for y in range(nrow): |
|
2265 | 2270 | for x in range(ncol): |
|
2266 | 2271 | |
|
2267 | 2272 | if counter >= self.nplots: |
|
2268 | 2273 | break |
|
2269 | 2274 | |
|
2270 | 2275 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
2271 | 2276 | |
|
2272 | 2277 | counter += 1 |
|
2273 | 2278 | |
|
2274 | 2279 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
2275 | 2280 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
2276 | 2281 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
2277 | 2282 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
2278 | 2283 | server=None, folder=None, username=None, password=None, |
|
2279 | 2284 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
2280 | 2285 | xaxis="frequency"): |
|
2281 | 2286 | |
|
2282 | 2287 | """ |
|
2283 | 2288 | |
|
2284 | 2289 | Input: |
|
2285 | 2290 | dataOut : |
|
2286 | 2291 | id : |
|
2287 | 2292 | wintitle : |
|
2288 | 2293 | channelList : |
|
2289 | 2294 | showProfile : |
|
2290 | 2295 | xmin : None, |
|
2291 | 2296 | xmax : None, |
|
2292 | 2297 | ymin : None, |
|
2293 | 2298 | ymax : None, |
|
2294 | 2299 | zmin : None, |
|
2295 | 2300 | zmax : None |
|
2296 | 2301 | """ |
|
2297 | 2302 | #Rebuild matrix |
|
2298 | 2303 | utctime = dataOut.data_param[0,0] |
|
2299 | 2304 | cmet = dataOut.data_param[:,1].astype(int) |
|
2300 | 2305 | tmet = dataOut.data_param[:,2].astype(int) |
|
2301 | 2306 | hmet = dataOut.data_param[:,3].astype(int) |
|
2302 | 2307 | |
|
2303 | 2308 | nParam = 3 |
|
2304 | 2309 | nChan = len(dataOut.groupList) |
|
2305 | 2310 | x = dataOut.abscissaList |
|
2306 | 2311 | y = dataOut.heightList |
|
2307 | 2312 | |
|
2308 | 2313 | z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan) |
|
2309 | 2314 | z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:] |
|
2310 | 2315 | z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale |
|
2311 | 2316 | z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1)) |
|
2312 | 2317 | |
|
2313 | 2318 | xlabel = "Time (s)" |
|
2314 | 2319 | ylabel = "Range (km)" |
|
2315 | 2320 | |
|
2316 | 2321 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
2317 | 2322 | |
|
2318 | 2323 | if not self.isConfig: |
|
2319 | 2324 | |
|
2320 | 2325 | nplots = nParam*nChan |
|
2321 | 2326 | |
|
2322 | 2327 | self.setup(id=id, |
|
2323 | 2328 | nplots=nplots, |
|
2324 | 2329 | wintitle=wintitle, |
|
2325 | 2330 | show=show) |
|
2326 | 2331 | |
|
2327 | 2332 | if xmin is None: xmin = numpy.nanmin(x) |
|
2328 | 2333 | if xmax is None: xmax = numpy.nanmax(x) |
|
2329 | 2334 | if ymin is None: ymin = numpy.nanmin(y) |
|
2330 | 2335 | if ymax is None: ymax = numpy.nanmax(y) |
|
2331 | 2336 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
2332 | 2337 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
2333 | 2338 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
2334 | 2339 | if vmin is None: vmin = -vmax |
|
2335 | 2340 | if wmin is None: wmin = 0 |
|
2336 | 2341 | if wmax is None: wmax = 50 |
|
2337 | 2342 | |
|
2338 | 2343 | self.nChannels = nChan |
|
2339 | 2344 | |
|
2340 | 2345 | zminList = [] |
|
2341 | 2346 | zmaxList = [] |
|
2342 | 2347 | titleList = [] |
|
2343 | 2348 | cmapList = [] |
|
2344 | 2349 | for i in range(self.nChannels): |
|
2345 | 2350 | strAux1 = "SNR Channel "+ str(i) |
|
2346 | 2351 | strAux2 = "Radial Velocity Channel "+ str(i) |
|
2347 | 2352 | strAux3 = "Spectral Width Channel "+ str(i) |
|
2348 | 2353 | |
|
2349 | 2354 | titleList = titleList + [strAux1,strAux2,strAux3] |
|
2350 | 2355 | cmapList = cmapList + ["jet","RdBu_r","jet"] |
|
2351 | 2356 | zminList = zminList + [SNRmin,vmin,wmin] |
|
2352 | 2357 | zmaxList = zmaxList + [SNRmax,vmax,wmax] |
|
2353 | 2358 | |
|
2354 | 2359 | self.zminList = zminList |
|
2355 | 2360 | self.zmaxList = zmaxList |
|
2356 | 2361 | self.cmapList = cmapList |
|
2357 | 2362 | self.titleList = titleList |
|
2358 | 2363 | |
|
2359 | 2364 | self.FTP_WEI = ftp_wei |
|
2360 | 2365 | self.EXP_CODE = exp_code |
|
2361 | 2366 | self.SUB_EXP_CODE = sub_exp_code |
|
2362 | 2367 | self.PLOT_POS = plot_pos |
|
2363 | 2368 | |
|
2364 | 2369 | self.isConfig = True |
|
2365 | 2370 | |
|
2366 | 2371 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
2367 | 2372 | |
|
2368 | 2373 | for i in range(self.nplots): |
|
2369 | 2374 | title = self.titleList[i] + ": " +str_datetime |
|
2370 | 2375 | axes = self.axesList[i] |
|
2371 | 2376 | axes.pcolor(x, y, z[i,:].T, |
|
2372 | 2377 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
2373 | 2378 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
2374 | 2379 | self.draw() |
|
2375 | 2380 | |
|
2376 | 2381 | if figfile == None: |
|
2377 | 2382 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
2378 | 2383 | name = str_datetime |
|
2379 | 2384 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
2380 | 2385 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
2381 | 2386 | figfile = self.getFilename(name) |
|
2382 | 2387 | |
|
2383 | 2388 | self.save(figpath=figpath, |
|
2384 | 2389 | figfile=figfile, |
|
2385 | 2390 | save=save, |
|
2386 | 2391 | ftp=ftp, |
|
2387 | 2392 | wr_period=wr_period, |
|
2388 | 2393 | thisDatetime=thisDatetime) |
|
2389 | 2394 | No newline at end of file |
@@ -1,500 +1,500 | |||
|
1 | 1 | import os |
|
2 | 2 | import sys |
|
3 | 3 | import datetime |
|
4 | 4 | import numpy |
|
5 | 5 | import matplotlib |
|
6 | 6 | |
|
7 | 7 | if 'BACKEND' in os.environ: |
|
8 | 8 | matplotlib.use(os.environ['BACKEND']) |
|
9 | 9 | elif 'linux' in sys.platform: |
|
10 | 10 | matplotlib.use("TkAgg") |
|
11 | 11 | elif 'darwin' in sys.platform: |
|
12 | 12 | matplotlib.use('TkAgg') |
|
13 | 13 | else: |
|
14 | 14 | from schainpy.utils import log |
|
15 | 15 | log.warning('Using default Backend="Agg"', 'INFO') |
|
16 | 16 | matplotlib.use('Agg') |
|
17 | 17 | # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' |
|
18 | 18 | import matplotlib.pyplot |
|
19 | 19 | |
|
20 | 20 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
21 | 21 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
22 | 22 | |
|
23 | 23 | ########################################### |
|
24 | 24 | # Actualizacion de las funciones del driver |
|
25 | 25 | ########################################### |
|
26 | 26 | |
|
27 | 27 | # create jro colormap |
|
28 | 28 | |
|
29 | 29 | jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] |
|
30 | 30 | blu_values = matplotlib.pyplot.get_cmap( |
|
31 | 31 | "seismic_r", 20)(numpy.arange(20))[10:15] |
|
32 | 32 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( |
|
33 | 33 | "jro", numpy.vstack((blu_values, jet_values))) |
|
34 | 34 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80): |
|
38 | 38 | |
|
39 | 39 | matplotlib.pyplot.ioff() |
|
40 | 40 | |
|
41 | 41 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=( |
|
42 | 42 | 1.0 * width / dpi, 1.0 * height / dpi)) |
|
43 | 43 | fig.canvas.manager.set_window_title(wintitle) |
|
44 | 44 | # fig.canvas.manager.resize(width, height) |
|
45 | 45 | matplotlib.pyplot.ion() |
|
46 | 46 | |
|
47 | 47 | if show: |
|
48 | 48 | matplotlib.pyplot.show() |
|
49 | 49 | |
|
50 | 50 | return fig |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | def closeFigure(show=False, fig=None): |
|
54 | 54 | |
|
55 | 55 | # matplotlib.pyplot.ioff() |
|
56 | 56 | # matplotlib.pyplot.pause(0) |
|
57 | 57 | |
|
58 | 58 | if show: |
|
59 | 59 | matplotlib.pyplot.show() |
|
60 | 60 | |
|
61 | 61 | if fig != None: |
|
62 | 62 | matplotlib.pyplot.close(fig) |
|
63 | 63 | # matplotlib.pyplot.pause(0) |
|
64 | 64 | # matplotlib.pyplot.ion() |
|
65 | 65 | |
|
66 | 66 | return |
|
67 | 67 | |
|
68 | 68 | matplotlib.pyplot.close("all") |
|
69 | 69 | # matplotlib.pyplot.pause(0) |
|
70 | 70 | # matplotlib.pyplot.ion() |
|
71 | 71 | |
|
72 | 72 | return |
|
73 | 73 | |
|
74 | 74 | |
|
75 | 75 | def saveFigure(fig, filename): |
|
76 | 76 | |
|
77 | 77 | # matplotlib.pyplot.ioff() |
|
78 | 78 | fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi) |
|
79 | 79 | # matplotlib.pyplot.ion() |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | def clearFigure(fig): |
|
83 | 83 | |
|
84 | 84 | fig.clf() |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | def setWinTitle(fig, title): |
|
88 | 88 | |
|
89 | 89 | fig.canvas.manager.set_window_title(title) |
|
90 | 90 | |
|
91 | 91 | |
|
92 | 92 | def setTitle(fig, title): |
|
93 | 93 | |
|
94 | 94 | fig.suptitle(title) |
|
95 | 95 | |
|
96 | 96 | |
|
97 | 97 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): |
|
98 | 98 | |
|
99 | 99 | matplotlib.pyplot.ioff() |
|
100 | 100 | matplotlib.pyplot.figure(fig.number) |
|
101 | 101 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
102 | 102 | (xpos, ypos), |
|
103 | 103 | colspan=colspan, |
|
104 | 104 | rowspan=rowspan, |
|
105 | 105 | polar=polar) |
|
106 | 106 | |
|
107 | 107 | matplotlib.pyplot.ion() |
|
108 | 108 | return axes |
|
109 | 109 | |
|
110 | 110 | |
|
111 | 111 | def setAxesText(ax, text): |
|
112 | 112 | |
|
113 | 113 | ax.annotate(text, |
|
114 | 114 | xy=(.1, .99), |
|
115 | 115 | xycoords='figure fraction', |
|
116 | 116 | horizontalalignment='left', |
|
117 | 117 | verticalalignment='top', |
|
118 | 118 | fontsize=10) |
|
119 | 119 | |
|
120 | 120 | |
|
121 | 121 | def printLabels(ax, xlabel, ylabel, title): |
|
122 | 122 | |
|
123 | 123 | ax.set_xlabel(xlabel, size=11) |
|
124 | 124 | ax.set_ylabel(ylabel, size=11) |
|
125 | 125 | ax.set_title(title, size=8) |
|
126 | 126 | |
|
127 | 127 | |
|
128 | 128 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
129 | 129 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
130 | 130 | nxticks=4, nyticks=10, |
|
131 | 131 | grid=None, color='blue'): |
|
132 | 132 | """ |
|
133 | 133 | |
|
134 | 134 | Input: |
|
135 | 135 | grid : None, 'both', 'x', 'y' |
|
136 | 136 | """ |
|
137 | 137 | |
|
138 | 138 | matplotlib.pyplot.ioff() |
|
139 | 139 | |
|
140 | 140 | ax.set_xlim([xmin, xmax]) |
|
141 | 141 | ax.set_ylim([ymin, ymax]) |
|
142 | 142 | |
|
143 | 143 | printLabels(ax, xlabel, ylabel, title) |
|
144 | 144 | |
|
145 | 145 | ###################################################### |
|
146 | 146 | if (xmax - xmin) <= 1: |
|
147 | 147 | xtickspos = numpy.linspace(xmin, xmax, nxticks) |
|
148 | 148 | xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos]) |
|
149 | 149 | ax.set_xticks(xtickspos) |
|
150 | 150 | else: |
|
151 | 151 | xtickspos = numpy.arange(nxticks) * \ |
|
152 | 152 | int((xmax - xmin) / (nxticks)) + int(xmin) |
|
153 | 153 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
154 | 154 | ax.set_xticks(xtickspos) |
|
155 | 155 | |
|
156 | 156 | for tick in ax.get_xticklabels(): |
|
157 | 157 | tick.set_visible(xtick_visible) |
|
158 | 158 | |
|
159 | 159 | for tick in ax.xaxis.get_major_ticks(): |
|
160 | 160 | tick.label.set_fontsize(ticksize) |
|
161 | 161 | |
|
162 | 162 | ###################################################### |
|
163 | 163 | for tick in ax.get_yticklabels(): |
|
164 | 164 | tick.set_visible(ytick_visible) |
|
165 | 165 | |
|
166 | 166 | for tick in ax.yaxis.get_major_ticks(): |
|
167 | 167 | tick.label.set_fontsize(ticksize) |
|
168 | 168 | |
|
169 | 169 | ax.plot(x, y, color=color) |
|
170 | 170 | iplot = ax.lines[-1] |
|
171 | 171 | |
|
172 | 172 | ###################################################### |
|
173 | 173 | if '0.' in matplotlib.__version__[0:2]: |
|
174 | 174 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
175 | 175 | return iplot |
|
176 | 176 | |
|
177 | 177 | if '1.0.' in matplotlib.__version__[0:4]: |
|
178 | 178 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
179 | 179 | return iplot |
|
180 | 180 | |
|
181 | 181 | if grid != None: |
|
182 | 182 | ax.grid(b=True, which='major', axis=grid) |
|
183 | 183 | |
|
184 | 184 | matplotlib.pyplot.tight_layout() |
|
185 | 185 | |
|
186 | 186 | matplotlib.pyplot.ion() |
|
187 | 187 | |
|
188 | 188 | return iplot |
|
189 | 189 | |
|
190 | 190 | |
|
191 | 191 | def set_linedata(ax, x, y, idline): |
|
192 | 192 | |
|
193 | 193 | ax.lines[idline].set_data(x, y) |
|
194 | 194 | |
|
195 | 195 | |
|
196 | 196 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
197 | 197 | |
|
198 | 198 | ax = iplot.axes |
|
199 | 199 | |
|
200 | 200 | printLabels(ax, xlabel, ylabel, title) |
|
201 | 201 | |
|
202 | 202 | set_linedata(ax, x, y, idline=0) |
|
203 | 203 | |
|
204 | 204 | |
|
205 | 205 | def addpline(ax, x, y, color, linestyle, lw): |
|
206 | 206 | |
|
207 | 207 | ax.plot(x, y, color=color, linestyle=linestyle, lw=lw) |
|
208 | 208 | |
|
209 | 209 | |
|
210 | 210 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
211 | 211 | xlabel='', ylabel='', title='', ticksize=9, |
|
212 | 212 | colormap='jet', cblabel='', cbsize="5%", |
|
213 | 213 | XAxisAsTime=False): |
|
214 | 214 | |
|
215 | 215 | matplotlib.pyplot.ioff() |
|
216 | 216 | |
|
217 | 217 | divider = make_axes_locatable(ax) |
|
218 | 218 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
219 | 219 | fig = ax.get_figure() |
|
220 | 220 | fig.add_axes(ax_cb) |
|
221 | 221 | |
|
222 | 222 | ax.set_xlim([xmin, xmax]) |
|
223 | 223 | ax.set_ylim([ymin, ymax]) |
|
224 | 224 | |
|
225 | 225 | printLabels(ax, xlabel, ylabel, title) |
|
226 | 226 | |
|
227 | 227 | z = numpy.ma.masked_invalid(z) |
|
228 | 228 | cmap = matplotlib.pyplot.get_cmap(colormap) |
|
229 |
cmap.set_bad(' |
|
|
229 | cmap.set_bad('white', 1.) | |
|
230 | 230 | imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap) |
|
231 | 231 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
232 | 232 | cb.set_label(cblabel) |
|
233 | 233 | |
|
234 | 234 | # for tl in ax_cb.get_yticklabels(): |
|
235 | 235 | # tl.set_visible(True) |
|
236 | 236 | |
|
237 | 237 | for tick in ax.yaxis.get_major_ticks(): |
|
238 | 238 | tick.label.set_fontsize(ticksize) |
|
239 | 239 | |
|
240 | 240 | for tick in ax.xaxis.get_major_ticks(): |
|
241 | 241 | tick.label.set_fontsize(ticksize) |
|
242 | 242 | |
|
243 | 243 | for tick in cb.ax.get_yticklabels(): |
|
244 | 244 | tick.set_fontsize(ticksize) |
|
245 | 245 | |
|
246 | 246 | ax_cb.yaxis.tick_right() |
|
247 | 247 | |
|
248 | 248 | if '0.' in matplotlib.__version__[0:2]: |
|
249 | 249 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
250 | 250 | return imesh |
|
251 | 251 | |
|
252 | 252 | if '1.0.' in matplotlib.__version__[0:4]: |
|
253 | 253 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
254 | 254 | return imesh |
|
255 | 255 | |
|
256 | 256 | matplotlib.pyplot.tight_layout() |
|
257 | 257 | |
|
258 | 258 | if XAxisAsTime: |
|
259 | 259 | |
|
260 | 260 | def func(x, pos): return ('%s') % ( |
|
261 | 261 | datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
262 | 262 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
263 | 263 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
264 | 264 | |
|
265 | 265 | matplotlib.pyplot.ion() |
|
266 | 266 | return imesh |
|
267 | 267 | |
|
268 | 268 | |
|
269 | 269 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
270 | 270 | |
|
271 | 271 | z = z.T |
|
272 | 272 | ax = imesh.axes |
|
273 | 273 | printLabels(ax, xlabel, ylabel, title) |
|
274 | 274 | imesh.set_array(z.ravel()) |
|
275 | 275 | |
|
276 | 276 | |
|
277 | 277 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
278 | 278 | |
|
279 | 279 | printLabels(ax, xlabel, ylabel, title) |
|
280 | 280 | |
|
281 | 281 | ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, |
|
282 | 282 | cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
283 | 283 | |
|
284 | 284 | |
|
285 | 285 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
286 | 286 | |
|
287 | 287 | printLabels(ax, xlabel, ylabel, title) |
|
288 | 288 | |
|
289 | 289 | ax.collections.remove(ax.collections[0]) |
|
290 | 290 | |
|
291 | 291 | z = numpy.ma.masked_invalid(z) |
|
292 | 292 | |
|
293 | 293 | cmap = matplotlib.pyplot.get_cmap(colormap) |
|
294 |
cmap.set_bad(' |
|
|
294 | cmap.set_bad('white', 1.) | |
|
295 | 295 | |
|
296 | 296 | ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap) |
|
297 | 297 | |
|
298 | 298 | |
|
299 | 299 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
300 | 300 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
301 | 301 | nxticks=4, nyticks=10, |
|
302 | 302 | grid=None): |
|
303 | 303 | """ |
|
304 | 304 | |
|
305 | 305 | Input: |
|
306 | 306 | grid : None, 'both', 'x', 'y' |
|
307 | 307 | """ |
|
308 | 308 | |
|
309 | 309 | matplotlib.pyplot.ioff() |
|
310 | 310 | |
|
311 | 311 | lines = ax.plot(x.T, y) |
|
312 | 312 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
313 | 313 | leg.get_frame().set_alpha(0.5) |
|
314 | 314 | ax.set_xlim([xmin, xmax]) |
|
315 | 315 | ax.set_ylim([ymin, ymax]) |
|
316 | 316 | printLabels(ax, xlabel, ylabel, title) |
|
317 | 317 | |
|
318 | 318 | xtickspos = numpy.arange(nxticks) * \ |
|
319 | 319 | int((xmax - xmin) / (nxticks)) + int(xmin) |
|
320 | 320 | ax.set_xticks(xtickspos) |
|
321 | 321 | |
|
322 | 322 | for tick in ax.get_xticklabels(): |
|
323 | 323 | tick.set_visible(xtick_visible) |
|
324 | 324 | |
|
325 | 325 | for tick in ax.xaxis.get_major_ticks(): |
|
326 | 326 | tick.label.set_fontsize(ticksize) |
|
327 | 327 | |
|
328 | 328 | for tick in ax.get_yticklabels(): |
|
329 | 329 | tick.set_visible(ytick_visible) |
|
330 | 330 | |
|
331 | 331 | for tick in ax.yaxis.get_major_ticks(): |
|
332 | 332 | tick.label.set_fontsize(ticksize) |
|
333 | 333 | |
|
334 | 334 | iplot = ax.lines[-1] |
|
335 | 335 | |
|
336 | 336 | if '0.' in matplotlib.__version__[0:2]: |
|
337 | 337 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
338 | 338 | return iplot |
|
339 | 339 | |
|
340 | 340 | if '1.0.' in matplotlib.__version__[0:4]: |
|
341 | 341 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
342 | 342 | return iplot |
|
343 | 343 | |
|
344 | 344 | if grid != None: |
|
345 | 345 | ax.grid(b=True, which='major', axis=grid) |
|
346 | 346 | |
|
347 | 347 | matplotlib.pyplot.tight_layout() |
|
348 | 348 | |
|
349 | 349 | matplotlib.pyplot.ion() |
|
350 | 350 | |
|
351 | 351 | return iplot |
|
352 | 352 | |
|
353 | 353 | |
|
354 | 354 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
355 | 355 | |
|
356 | 356 | ax = iplot.axes |
|
357 | 357 | |
|
358 | 358 | printLabels(ax, xlabel, ylabel, title) |
|
359 | 359 | |
|
360 | 360 | for i in range(len(ax.lines)): |
|
361 | 361 | line = ax.lines[i] |
|
362 | 362 | line.set_data(x[i, :], y) |
|
363 | 363 | |
|
364 | 364 | |
|
365 | 365 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
366 | 366 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
367 | 367 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
368 | 368 | grid=None, XAxisAsTime=False): |
|
369 | 369 | """ |
|
370 | 370 | |
|
371 | 371 | Input: |
|
372 | 372 | grid : None, 'both', 'x', 'y' |
|
373 | 373 | """ |
|
374 | 374 | |
|
375 | 375 | matplotlib.pyplot.ioff() |
|
376 | 376 | |
|
377 | 377 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
378 | 378 | lines = ax.plot(x, y.T) |
|
379 | 379 | # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
380 | 380 | # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
381 | 381 | |
|
382 | 382 | leg = ax.legend(lines, legendlabels, |
|
383 | 383 | loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0) |
|
384 | 384 | |
|
385 | 385 | for label in leg.get_texts(): |
|
386 | 386 | label.set_fontsize(9) |
|
387 | 387 | |
|
388 | 388 | ax.set_xlim([xmin, xmax]) |
|
389 | 389 | ax.set_ylim([ymin, ymax]) |
|
390 | 390 | printLabels(ax, xlabel, ylabel, title) |
|
391 | 391 | |
|
392 | 392 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
393 | 393 | # ax.set_xticks(xtickspos) |
|
394 | 394 | |
|
395 | 395 | for tick in ax.get_xticklabels(): |
|
396 | 396 | tick.set_visible(xtick_visible) |
|
397 | 397 | |
|
398 | 398 | for tick in ax.xaxis.get_major_ticks(): |
|
399 | 399 | tick.label.set_fontsize(ticksize) |
|
400 | 400 | |
|
401 | 401 | for tick in ax.get_yticklabels(): |
|
402 | 402 | tick.set_visible(ytick_visible) |
|
403 | 403 | |
|
404 | 404 | for tick in ax.yaxis.get_major_ticks(): |
|
405 | 405 | tick.label.set_fontsize(ticksize) |
|
406 | 406 | |
|
407 | 407 | iplot = ax.lines[-1] |
|
408 | 408 | |
|
409 | 409 | if '0.' in matplotlib.__version__[0:2]: |
|
410 | 410 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
411 | 411 | return iplot |
|
412 | 412 | |
|
413 | 413 | if '1.0.' in matplotlib.__version__[0:4]: |
|
414 | 414 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
415 | 415 | return iplot |
|
416 | 416 | |
|
417 | 417 | if grid != None: |
|
418 | 418 | ax.grid(b=True, which='major', axis=grid) |
|
419 | 419 | |
|
420 | 420 | matplotlib.pyplot.tight_layout() |
|
421 | 421 | |
|
422 | 422 | if XAxisAsTime: |
|
423 | 423 | |
|
424 | 424 | def func(x, pos): return ('%s') % ( |
|
425 | 425 | datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
426 | 426 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
427 | 427 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
428 | 428 | |
|
429 | 429 | matplotlib.pyplot.ion() |
|
430 | 430 | |
|
431 | 431 | return iplot |
|
432 | 432 | |
|
433 | 433 | |
|
434 | 434 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
435 | 435 | |
|
436 | 436 | ax = iplot.axes |
|
437 | 437 | printLabels(ax, xlabel, ylabel, title) |
|
438 | 438 | |
|
439 | 439 | for i in range(len(ax.lines)): |
|
440 | 440 | line = ax.lines[i] |
|
441 | 441 | line.set_data(x, y[i, :]) |
|
442 | 442 | |
|
443 | 443 | |
|
444 | 444 | def createPolar(ax, x, y, |
|
445 | 445 | xlabel='', ylabel='', title='', ticksize=9, |
|
446 | 446 | colormap='jet', cblabel='', cbsize="5%", |
|
447 | 447 | XAxisAsTime=False): |
|
448 | 448 | |
|
449 | 449 | matplotlib.pyplot.ioff() |
|
450 | 450 | |
|
451 | 451 | ax.plot(x, y, 'bo', markersize=5) |
|
452 | 452 | # ax.set_rmax(90) |
|
453 | 453 | ax.set_ylim(0, 90) |
|
454 | 454 | ax.set_yticks(numpy.arange(0, 90, 20)) |
|
455 | 455 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') |
|
456 | 456 | # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11') |
|
457 | 457 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') |
|
458 | 458 | ax.yaxis.labelpad = 40 |
|
459 | 459 | printLabels(ax, xlabel, ylabel, title) |
|
460 | 460 | iplot = ax.lines[-1] |
|
461 | 461 | |
|
462 | 462 | if '0.' in matplotlib.__version__[0:2]: |
|
463 | 463 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
464 | 464 | return iplot |
|
465 | 465 | |
|
466 | 466 | if '1.0.' in matplotlib.__version__[0:4]: |
|
467 | 467 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
468 | 468 | return iplot |
|
469 | 469 | |
|
470 | 470 | # if grid != None: |
|
471 | 471 | # ax.grid(b=True, which='major', axis=grid) |
|
472 | 472 | |
|
473 | 473 | matplotlib.pyplot.tight_layout() |
|
474 | 474 | |
|
475 | 475 | matplotlib.pyplot.ion() |
|
476 | 476 | |
|
477 | 477 | return iplot |
|
478 | 478 | |
|
479 | 479 | |
|
480 | 480 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): |
|
481 | 481 | |
|
482 | 482 | ax = iplot.axes |
|
483 | 483 | |
|
484 | 484 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') |
|
485 | 485 | printLabels(ax, xlabel, ylabel, title) |
|
486 | 486 | |
|
487 | 487 | set_linedata(ax, x, y, idline=0) |
|
488 | 488 | |
|
489 | 489 | |
|
490 | 490 | def draw(fig): |
|
491 | 491 | |
|
492 | 492 | if type(fig) == 'int': |
|
493 | 493 | raise ValueError("Error drawing: Fig parameter should be a matplotlib figure object figure") |
|
494 | 494 | |
|
495 | 495 | fig.canvas.draw() |
|
496 | 496 | |
|
497 | 497 | |
|
498 | 498 | def pause(interval=0.000001): |
|
499 | 499 | |
|
500 | 500 | matplotlib.pyplot.pause(interval) No newline at end of file |
@@ -1,642 +1,642 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Aug 1, 2017 |
|
3 | 3 | |
|
4 | 4 | @author: Juan C. Espinoza |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os |
|
8 | 8 | import sys |
|
9 | 9 | import time |
|
10 | 10 | import json |
|
11 | 11 | import glob |
|
12 | 12 | import datetime |
|
13 | 13 | |
|
14 | 14 | import numpy |
|
15 | 15 | import h5py |
|
16 | 16 | |
|
17 | 17 | from schainpy.model.io.jroIO_base import JRODataReader |
|
18 | 18 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
19 | 19 | from schainpy.model.data.jrodata import Parameters |
|
20 | 20 | from schainpy.utils import log |
|
21 | 21 | |
|
22 | 22 | try: |
|
23 | 23 | import madrigal.cedar |
|
24 | 24 | except: |
|
25 | 25 | log.warning( |
|
26 | 26 | 'You should install "madrigal library" module if you want to read/write Madrigal data' |
|
27 | 27 | ) |
|
28 | 28 | |
|
29 | 29 | DEF_CATALOG = { |
|
30 | 30 | 'principleInvestigator': 'Marco Milla', |
|
31 | 31 | 'expPurpose': None, |
|
32 | 32 | 'cycleTime': None, |
|
33 | 33 | 'correlativeExp': None, |
|
34 | 34 | 'sciRemarks': None, |
|
35 | 35 | 'instRemarks': None |
|
36 | 36 | } |
|
37 | 37 | DEF_HEADER = { |
|
38 | 38 | 'kindatDesc': None, |
|
39 | 39 | 'analyst': 'Jicamarca User', |
|
40 | 40 | 'comments': None, |
|
41 | 41 | 'history': None |
|
42 | 42 | } |
|
43 | 43 | MNEMONICS = { |
|
44 | 44 | 10: 'jro', |
|
45 | 45 | 11: 'jbr', |
|
46 | 46 | 840: 'jul', |
|
47 | 47 | 13: 'jas', |
|
48 | 48 | 1000: 'pbr', |
|
49 | 49 | 1001: 'hbr', |
|
50 | 50 | 1002: 'obr', |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | UT1970 = datetime.datetime(1970, 1, 1) - datetime.timedelta(seconds=time.timezone) |
|
54 | 54 | |
|
55 | 55 | def load_json(obj): |
|
56 | 56 | ''' |
|
57 | 57 | Parse json as string instead of unicode |
|
58 | 58 | ''' |
|
59 | 59 | |
|
60 | 60 | if isinstance(obj, str): |
|
61 | 61 | iterable = json.loads(obj) |
|
62 | 62 | else: |
|
63 | 63 | iterable = obj |
|
64 | 64 | |
|
65 | 65 | if isinstance(iterable, dict): |
|
66 | 66 | return {str(k): load_json(v) if isinstance(v, dict) else str(v) if isinstance(v, str) else v |
|
67 | 67 | for k, v in list(iterable.items())} |
|
68 | 68 | elif isinstance(iterable, (list, tuple)): |
|
69 | 69 | return [str(v) if isinstance(v, str) else v for v in iterable] |
|
70 | 70 | |
|
71 | 71 | return iterable |
|
72 | 72 | |
|
73 | 73 | @MPDecorator |
|
74 | 74 | class MADReader(JRODataReader, ProcessingUnit): |
|
75 | 75 | |
|
76 | 76 | def __init__(self): |
|
77 | 77 | |
|
78 | 78 | ProcessingUnit.__init__(self) |
|
79 | 79 | |
|
80 | 80 | self.dataOut = Parameters() |
|
81 | 81 | self.counter_records = 0 |
|
82 | 82 | self.nrecords = None |
|
83 | 83 | self.flagNoMoreFiles = 0 |
|
84 | 84 | self.isConfig = False |
|
85 | 85 | self.filename = None |
|
86 | 86 | self.intervals = set() |
|
87 | 87 | |
|
88 | 88 | def setup(self, |
|
89 | 89 | path=None, |
|
90 | 90 | startDate=None, |
|
91 | 91 | endDate=None, |
|
92 | 92 | format=None, |
|
93 | 93 | startTime=datetime.time(0, 0, 0), |
|
94 | 94 | endTime=datetime.time(23, 59, 59), |
|
95 | 95 | **kwargs): |
|
96 | 96 | |
|
97 | 97 | self.path = path |
|
98 | 98 | self.startDate = startDate |
|
99 | 99 | self.endDate = endDate |
|
100 | 100 | self.startTime = startTime |
|
101 | 101 | self.endTime = endTime |
|
102 | 102 | self.datatime = datetime.datetime(1900,1,1) |
|
103 | 103 | self.oneDDict = load_json(kwargs.get('oneDDict', |
|
104 | 104 | "{\"GDLATR\":\"lat\", \"GDLONR\":\"lon\"}")) |
|
105 | 105 | self.twoDDict = load_json(kwargs.get('twoDDict', |
|
106 | 106 | "{\"GDALT\": \"heightList\"}")) |
|
107 | 107 | self.ind2DList = load_json(kwargs.get('ind2DList', |
|
108 | 108 | "[\"GDALT\"]")) |
|
109 | 109 | if self.path is None: |
|
110 | 110 | raise ValueError('The path is not valid') |
|
111 | 111 | |
|
112 | 112 | if format is None: |
|
113 | 113 | raise ValueError('The format is not valid choose simple or hdf5') |
|
114 | 114 | elif format.lower() in ('simple', 'txt'): |
|
115 | 115 | self.ext = '.txt' |
|
116 | 116 | elif format.lower() in ('cedar',): |
|
117 | 117 | self.ext = '.001' |
|
118 | 118 | else: |
|
119 | 119 | self.ext = '.hdf5' |
|
120 | 120 | |
|
121 | 121 | self.search_files(self.path) |
|
122 | 122 | self.fileId = 0 |
|
123 | 123 | |
|
124 | 124 | if not self.fileList: |
|
125 | 125 | raise Warning('There is no files matching these date in the folder: {}. \n Check startDate and endDate'.format(path)) |
|
126 | 126 | |
|
127 | 127 | self.setNextFile() |
|
128 | 128 | |
|
129 | 129 | def search_files(self, path): |
|
130 | 130 | ''' |
|
131 | 131 | Searching for madrigal files in path |
|
132 | 132 | Creating a list of files to procces included in [startDate,endDate] |
|
133 | 133 | |
|
134 | 134 | Input: |
|
135 | 135 | path - Path to find files |
|
136 | 136 | ''' |
|
137 | 137 | |
|
138 | 138 | log.log('Searching files {} in {} '.format(self.ext, path), 'MADReader') |
|
139 | 139 | foldercounter = 0 |
|
140 | 140 | fileList0 = glob.glob1(path, '*{}'.format(self.ext)) |
|
141 | 141 | fileList0.sort() |
|
142 | 142 | |
|
143 | 143 | self.fileList = [] |
|
144 | 144 | self.dateFileList = [] |
|
145 | 145 | |
|
146 | 146 | startDate = self.startDate - datetime.timedelta(1) |
|
147 | 147 | endDate = self.endDate + datetime.timedelta(1) |
|
148 | 148 | |
|
149 | 149 | for thisFile in fileList0: |
|
150 | 150 | year = thisFile[3:7] |
|
151 | 151 | if not year.isdigit(): |
|
152 | 152 | continue |
|
153 | 153 | |
|
154 | 154 | month = thisFile[7:9] |
|
155 | 155 | if not month.isdigit(): |
|
156 | 156 | continue |
|
157 | 157 | |
|
158 | 158 | day = thisFile[9:11] |
|
159 | 159 | if not day.isdigit(): |
|
160 | 160 | continue |
|
161 | 161 | |
|
162 | 162 | year, month, day = int(year), int(month), int(day) |
|
163 | 163 | dateFile = datetime.date(year, month, day) |
|
164 | 164 | |
|
165 | 165 | if (startDate > dateFile) or (endDate < dateFile): |
|
166 | 166 | continue |
|
167 | 167 | |
|
168 | 168 | self.fileList.append(thisFile) |
|
169 | 169 | self.dateFileList.append(dateFile) |
|
170 | 170 | |
|
171 | 171 | return |
|
172 | 172 | |
|
173 | 173 | def parseHeader(self): |
|
174 | 174 | ''' |
|
175 | 175 | ''' |
|
176 | 176 | |
|
177 | 177 | self.output = {} |
|
178 | 178 | self.version = '2' |
|
179 | 179 | s_parameters = None |
|
180 | 180 | if self.ext == '.txt': |
|
181 | 181 | self.parameters = [s.strip().lower() for s in self.fp.readline().strip().split(' ') if s] |
|
182 | 182 | elif self.ext == '.hdf5': |
|
183 | 183 | metadata = self.fp['Metadata'] |
|
184 | 184 | data = self.fp['Data']['Array Layout'] |
|
185 | 185 | if 'Independent Spatial Parameters' in metadata: |
|
186 | 186 | s_parameters = [s[0].lower() for s in metadata['Independent Spatial Parameters']] |
|
187 | 187 | self.version = '3' |
|
188 | 188 | one = [s[0].lower() for s in data['1D Parameters']['Data Parameters']] |
|
189 | 189 | one_d = [1 for s in one] |
|
190 | 190 | two = [s[0].lower() for s in data['2D Parameters']['Data Parameters']] |
|
191 | 191 | two_d = [2 for s in two] |
|
192 | 192 | self.parameters = one + two |
|
193 | 193 | self.parameters_d = one_d + two_d |
|
194 | 194 | |
|
195 | log.success('Parameters found: {}'.format(','.join(self.parameters)), | |
|
195 | log.success('Parameters found: {}'.format(','.join(str(self.parameters))), | |
|
196 | 196 | 'MADReader') |
|
197 | 197 | if s_parameters: |
|
198 | log.success('Spatial parameters: {}'.format(','.join(s_parameters)), | |
|
198 | log.success('Spatial parameters: {}'.format(','.join(str(s_parameters))), | |
|
199 | 199 | 'MADReader') |
|
200 | 200 | |
|
201 | 201 | for param in list(self.oneDDict.keys()): |
|
202 | 202 | if param.lower() not in self.parameters: |
|
203 | 203 | log.warning( |
|
204 | 204 | 'Parameter {} not found will be ignored'.format( |
|
205 | 205 | param), |
|
206 | 206 | 'MADReader') |
|
207 | 207 | self.oneDDict.pop(param, None) |
|
208 | 208 | |
|
209 | 209 | for param, value in list(self.twoDDict.items()): |
|
210 | 210 | if param.lower() not in self.parameters: |
|
211 | 211 | log.warning( |
|
212 | 212 | 'Parameter {} not found, it will be ignored'.format( |
|
213 | 213 | param), |
|
214 | 214 | 'MADReader') |
|
215 | 215 | self.twoDDict.pop(param, None) |
|
216 | 216 | continue |
|
217 | 217 | if isinstance(value, list): |
|
218 | 218 | if value[0] not in self.output: |
|
219 | 219 | self.output[value[0]] = [] |
|
220 | 220 | self.output[value[0]].append(None) |
|
221 | 221 | |
|
222 | 222 | def parseData(self): |
|
223 | 223 | ''' |
|
224 | 224 | ''' |
|
225 | 225 | |
|
226 | 226 | if self.ext == '.txt': |
|
227 | 227 | self.data = numpy.genfromtxt(self.fp, missing_values=('missing')) |
|
228 | 228 | self.nrecords = self.data.shape[0] |
|
229 | 229 | self.ranges = numpy.unique(self.data[:,self.parameters.index(self.ind2DList[0].lower())]) |
|
230 | 230 | elif self.ext == '.hdf5': |
|
231 | 231 | self.data = self.fp['Data']['Array Layout'] |
|
232 | 232 | self.nrecords = len(self.data['timestamps'].value) |
|
233 | 233 | self.ranges = self.data['range'].value |
|
234 | 234 | |
|
235 | 235 | def setNextFile(self): |
|
236 | 236 | ''' |
|
237 | 237 | ''' |
|
238 | 238 | |
|
239 | 239 | file_id = self.fileId |
|
240 | 240 | |
|
241 | 241 | if file_id == len(self.fileList): |
|
242 | 242 | log.success('No more files', 'MADReader') |
|
243 | 243 | self.flagNoMoreFiles = 1 |
|
244 | 244 | return 0 |
|
245 | 245 | |
|
246 | 246 | log.success( |
|
247 | 247 | 'Opening: {}'.format(self.fileList[file_id]), |
|
248 | 248 | 'MADReader' |
|
249 | 249 | ) |
|
250 | 250 | |
|
251 | 251 | filename = os.path.join(self.path, self.fileList[file_id]) |
|
252 | 252 | |
|
253 | 253 | if self.filename is not None: |
|
254 | 254 | self.fp.close() |
|
255 | 255 | |
|
256 | 256 | self.filename = filename |
|
257 | 257 | self.filedate = self.dateFileList[file_id] |
|
258 | 258 | |
|
259 | 259 | if self.ext=='.hdf5': |
|
260 | 260 | self.fp = h5py.File(self.filename, 'r') |
|
261 | 261 | else: |
|
262 | 262 | self.fp = open(self.filename, 'rb') |
|
263 | 263 | |
|
264 | 264 | self.parseHeader() |
|
265 | 265 | self.parseData() |
|
266 | 266 | self.sizeOfFile = os.path.getsize(self.filename) |
|
267 | 267 | self.counter_records = 0 |
|
268 | 268 | self.flagIsNewFile = 0 |
|
269 | 269 | self.fileId += 1 |
|
270 | 270 | |
|
271 | 271 | return 1 |
|
272 | 272 | |
|
273 | 273 | def readNextBlock(self): |
|
274 | 274 | |
|
275 | 275 | while True: |
|
276 | 276 | self.flagDiscontinuousBlock = 0 |
|
277 | 277 | if self.flagIsNewFile: |
|
278 | 278 | if not self.setNextFile(): |
|
279 | 279 | return 0 |
|
280 | 280 | |
|
281 | 281 | self.readBlock() |
|
282 | 282 | |
|
283 | 283 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ |
|
284 | 284 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
285 | 285 | log.warning( |
|
286 | 286 | 'Reading Record No. {}/{} -> {} [Skipping]'.format( |
|
287 | 287 | self.counter_records, |
|
288 | 288 | self.nrecords, |
|
289 | 289 | self.datatime.ctime()), |
|
290 | 290 | 'MADReader') |
|
291 | 291 | continue |
|
292 | 292 | break |
|
293 | 293 | |
|
294 | 294 | log.log( |
|
295 | 295 | 'Reading Record No. {}/{} -> {}'.format( |
|
296 | 296 | self.counter_records, |
|
297 | 297 | self.nrecords, |
|
298 | 298 | self.datatime.ctime()), |
|
299 | 299 | 'MADReader') |
|
300 | 300 | |
|
301 | 301 | return 1 |
|
302 | 302 | |
|
303 | 303 | def readBlock(self): |
|
304 | 304 | ''' |
|
305 | 305 | ''' |
|
306 | 306 | dum = [] |
|
307 | 307 | if self.ext == '.txt': |
|
308 | 308 | dt = self.data[self.counter_records][:6].astype(int) |
|
309 | 309 | if datetime.datetime(dt[0], dt[1], dt[2], dt[3], dt[4], dt[5]).date() > self.datatime.date(): |
|
310 | 310 | self.flagDiscontinuousBlock = 1 |
|
311 | 311 | self.datatime = datetime.datetime(dt[0], dt[1], dt[2], dt[3], dt[4], dt[5]) |
|
312 | 312 | while True: |
|
313 | 313 | dt = self.data[self.counter_records][:6].astype(int) |
|
314 | 314 | datatime = datetime.datetime(dt[0], dt[1], dt[2], dt[3], dt[4], dt[5]) |
|
315 | 315 | if datatime == self.datatime: |
|
316 | 316 | dum.append(self.data[self.counter_records]) |
|
317 | 317 | self.counter_records += 1 |
|
318 | 318 | if self.counter_records == self.nrecords: |
|
319 | 319 | self.flagIsNewFile = True |
|
320 | 320 | break |
|
321 | 321 | continue |
|
322 | 322 | self.intervals.add((datatime-self.datatime).seconds) |
|
323 | 323 | break |
|
324 | 324 | elif self.ext == '.hdf5': |
|
325 | 325 | datatime = datetime.datetime.utcfromtimestamp( |
|
326 | 326 | self.data['timestamps'][self.counter_records]) |
|
327 | 327 | nHeights = len(self.ranges) |
|
328 | 328 | for n, param in enumerate(self.parameters): |
|
329 | 329 | if self.parameters_d[n] == 1: |
|
330 | 330 | dum.append(numpy.ones(nHeights)*self.data['1D Parameters'][param][self.counter_records]) |
|
331 | 331 | else: |
|
332 | 332 | if self.version == '2': |
|
333 | 333 | dum.append(self.data['2D Parameters'][param][self.counter_records]) |
|
334 | 334 | else: |
|
335 | 335 | tmp = self.data['2D Parameters'][param].value.T |
|
336 | 336 | dum.append(tmp[self.counter_records]) |
|
337 | 337 | self.intervals.add((datatime-self.datatime).seconds) |
|
338 | 338 | if datatime.date()>self.datatime.date(): |
|
339 | 339 | self.flagDiscontinuousBlock = 1 |
|
340 | 340 | self.datatime = datatime |
|
341 | 341 | self.counter_records += 1 |
|
342 | 342 | if self.counter_records == self.nrecords: |
|
343 | 343 | self.flagIsNewFile = True |
|
344 | 344 | |
|
345 | 345 | self.buffer = numpy.array(dum) |
|
346 | 346 | return |
|
347 | 347 | |
|
348 | 348 | def set_output(self): |
|
349 | 349 | ''' |
|
350 | 350 | Storing data from buffer to dataOut object |
|
351 | 351 | ''' |
|
352 | 352 | |
|
353 | 353 | parameters = [None for __ in self.parameters] |
|
354 | 354 | |
|
355 | 355 | for param, attr in list(self.oneDDict.items()): |
|
356 | 356 | x = self.parameters.index(param.lower()) |
|
357 | 357 | setattr(self.dataOut, attr, self.buffer[0][x]) |
|
358 | 358 | |
|
359 | 359 | for param, value in list(self.twoDDict.items()): |
|
360 | 360 | x = self.parameters.index(param.lower()) |
|
361 | 361 | if self.ext == '.txt': |
|
362 | 362 | y = self.parameters.index(self.ind2DList[0].lower()) |
|
363 | 363 | ranges = self.buffer[:,y] |
|
364 | 364 | if self.ranges.size == ranges.size: |
|
365 | 365 | continue |
|
366 | 366 | index = numpy.where(numpy.in1d(self.ranges, ranges))[0] |
|
367 | 367 | dummy = numpy.zeros(self.ranges.shape) + numpy.nan |
|
368 | 368 | dummy[index] = self.buffer[:,x] |
|
369 | 369 | else: |
|
370 | 370 | dummy = self.buffer[x] |
|
371 | 371 | |
|
372 | 372 | if isinstance(value, str): |
|
373 | 373 | if value not in self.ind2DList: |
|
374 | 374 | setattr(self.dataOut, value, dummy.reshape(1,-1)) |
|
375 | 375 | elif isinstance(value, list): |
|
376 | 376 | self.output[value[0]][value[1]] = dummy |
|
377 | 377 | parameters[value[1]] = param |
|
378 | 378 | |
|
379 | 379 | for key, value in list(self.output.items()): |
|
380 | 380 | setattr(self.dataOut, key, numpy.array(value)) |
|
381 | 381 | |
|
382 | 382 | self.dataOut.parameters = [s for s in parameters if s] |
|
383 | 383 | self.dataOut.heightList = self.ranges |
|
384 | 384 | self.dataOut.utctime = (self.datatime - datetime.datetime(1970, 1, 1)).total_seconds() |
|
385 | 385 | self.dataOut.utctimeInit = self.dataOut.utctime |
|
386 | 386 | self.dataOut.paramInterval = min(self.intervals) |
|
387 | 387 | self.dataOut.useLocalTime = False |
|
388 | 388 | self.dataOut.flagNoData = False |
|
389 | 389 | self.dataOut.nrecords = self.nrecords |
|
390 | 390 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
391 | 391 | |
|
392 | 392 | def getData(self): |
|
393 | 393 | ''' |
|
394 | 394 | Storing data from databuffer to dataOut object |
|
395 | 395 | ''' |
|
396 | 396 | if self.flagNoMoreFiles: |
|
397 | 397 | self.dataOut.flagNoData = True |
|
398 | 398 | self.dataOut.error = 'No file left to process' |
|
399 | 399 | return 0 |
|
400 | 400 | |
|
401 | 401 | if not self.readNextBlock(): |
|
402 | 402 | self.dataOut.flagNoData = True |
|
403 | 403 | return 0 |
|
404 | 404 | |
|
405 | 405 | self.set_output() |
|
406 | 406 | |
|
407 | 407 | return 1 |
|
408 | 408 | |
|
409 | 409 | |
|
410 | 410 | class MADWriter(Operation): |
|
411 | 411 | |
|
412 | 412 | missing = -32767 |
|
413 | 413 | |
|
414 | 414 | def __init__(self, **kwargs): |
|
415 | 415 | |
|
416 | 416 | Operation.__init__(self, **kwargs) |
|
417 | 417 | self.dataOut = Parameters() |
|
418 | 418 | self.counter = 0 |
|
419 | 419 | self.path = None |
|
420 | 420 | self.fp = None |
|
421 | 421 | |
|
422 | 422 | def run(self, dataOut, path, oneDDict, ind2DList='[]', twoDDict='{}', |
|
423 | 423 | metadata='{}', format='cedar', **kwargs): |
|
424 | 424 | ''' |
|
425 | 425 | Inputs: |
|
426 | 426 | path - path where files will be created |
|
427 | 427 | oneDDict - json of one-dimensional parameters in record where keys |
|
428 | 428 | are Madrigal codes (integers or mnemonics) and values the corresponding |
|
429 | 429 | dataOut attribute e.g: { |
|
430 | 430 | 'gdlatr': 'lat', |
|
431 | 431 | 'gdlonr': 'lon', |
|
432 | 432 | 'gdlat2':'lat', |
|
433 | 433 | 'glon2':'lon'} |
|
434 | 434 | ind2DList - list of independent spatial two-dimensional parameters e.g: |
|
435 | 435 | ['heighList'] |
|
436 | 436 | twoDDict - json of two-dimensional parameters in record where keys |
|
437 | 437 | are Madrigal codes (integers or mnemonics) and values the corresponding |
|
438 | 438 | dataOut attribute if multidimensional array specify as tupple |
|
439 | 439 | ('attr', pos) e.g: { |
|
440 | 440 | 'gdalt': 'heightList', |
|
441 | 441 | 'vn1p2': ('data_output', 0), |
|
442 | 442 | 'vn2p2': ('data_output', 1), |
|
443 | 443 | 'vn3': ('data_output', 2), |
|
444 | 444 | 'snl': ('data_SNR', 'db') |
|
445 | 445 | } |
|
446 | 446 | metadata - json of madrigal metadata (kinst, kindat, catalog and header) |
|
447 | 447 | ''' |
|
448 | 448 | if not self.isConfig: |
|
449 | 449 | self.setup(path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs) |
|
450 | 450 | self.isConfig = True |
|
451 | 451 | |
|
452 | 452 | self.dataOut = dataOut |
|
453 | 453 | self.putData() |
|
454 | 454 | return |
|
455 | 455 | |
|
456 | 456 | def setup(self, path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs): |
|
457 | 457 | ''' |
|
458 | 458 | Configure Operation |
|
459 | 459 | ''' |
|
460 | 460 | |
|
461 | 461 | self.path = path |
|
462 | 462 | self.blocks = kwargs.get('blocks', None) |
|
463 | 463 | self.counter = 0 |
|
464 | 464 | self.oneDDict = load_json(oneDDict) |
|
465 | 465 | self.twoDDict = load_json(twoDDict) |
|
466 | 466 | self.ind2DList = load_json(ind2DList) |
|
467 | 467 | meta = load_json(metadata) |
|
468 | 468 | self.kinst = meta.get('kinst') |
|
469 | 469 | self.kindat = meta.get('kindat') |
|
470 | 470 | self.catalog = meta.get('catalog', DEF_CATALOG) |
|
471 | 471 | self.header = meta.get('header', DEF_HEADER) |
|
472 | 472 | if format == 'cedar': |
|
473 | 473 | self.ext = '.dat' |
|
474 | 474 | self.extra_args = {} |
|
475 | 475 | elif format == 'hdf5': |
|
476 | 476 | self.ext = '.hdf5' |
|
477 | 477 | self.extra_args = {'ind2DList': self.ind2DList} |
|
478 | 478 | |
|
479 | 479 | self.keys = [k.lower() for k in self.twoDDict] |
|
480 | 480 | if 'range' in self.keys: |
|
481 | 481 | self.keys.remove('range') |
|
482 | 482 | if 'gdalt' in self.keys: |
|
483 | 483 | self.keys.remove('gdalt') |
|
484 | 484 | |
|
485 | 485 | def setFile(self): |
|
486 | 486 | ''' |
|
487 | 487 | Create new cedar file object |
|
488 | 488 | ''' |
|
489 | 489 | |
|
490 | 490 | self.mnemonic = MNEMONICS[self.kinst] #TODO get mnemonic from madrigal |
|
491 | 491 | date = datetime.datetime.utcfromtimestamp(self.dataOut.utctime) |
|
492 | 492 | |
|
493 | 493 | filename = '{}{}{}'.format(self.mnemonic, |
|
494 | 494 | date.strftime('%Y%m%d_%H%M%S'), |
|
495 | 495 | self.ext) |
|
496 | 496 | |
|
497 | 497 | self.fullname = os.path.join(self.path, filename) |
|
498 | 498 | |
|
499 | 499 | if os.path.isfile(self.fullname) : |
|
500 | 500 | log.warning( |
|
501 | 501 | 'Destination file {} already exists, previous file deleted.'.format( |
|
502 | 502 | self.fullname), |
|
503 | 503 | 'MADWriter') |
|
504 | 504 | os.remove(self.fullname) |
|
505 | 505 | |
|
506 | 506 | try: |
|
507 | 507 | log.success( |
|
508 | 508 | 'Creating file: {}'.format(self.fullname), |
|
509 | 509 | 'MADWriter') |
|
510 | 510 | self.fp = madrigal.cedar.MadrigalCedarFile(self.fullname, True) |
|
511 | 511 | except ValueError as e: |
|
512 | 512 | log.error( |
|
513 | 513 | 'Impossible to create a cedar object with "madrigal.cedar.MadrigalCedarFile"', |
|
514 | 514 | 'MADWriter') |
|
515 | 515 | return |
|
516 | 516 | |
|
517 | 517 | return 1 |
|
518 | 518 | |
|
519 | 519 | def writeBlock(self): |
|
520 | 520 | ''' |
|
521 | 521 | Add data records to cedar file taking data from oneDDict and twoDDict |
|
522 | 522 | attributes. |
|
523 | 523 | Allowed parameters in: parcodes.tab |
|
524 | 524 | ''' |
|
525 | 525 | |
|
526 | 526 | startTime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime) |
|
527 | 527 | endTime = startTime + datetime.timedelta(seconds=self.dataOut.paramInterval) |
|
528 | 528 | heights = self.dataOut.heightList |
|
529 | 529 | |
|
530 | 530 | if self.ext == '.dat': |
|
531 | 531 | for key, value in list(self.twoDDict.items()): |
|
532 | 532 | if isinstance(value, str): |
|
533 | 533 | data = getattr(self.dataOut, value) |
|
534 | 534 | invalid = numpy.isnan(data) |
|
535 | 535 | data[invalid] = self.missing |
|
536 | 536 | elif isinstance(value, (tuple, list)): |
|
537 | 537 | attr, key = value |
|
538 | 538 | data = getattr(self.dataOut, attr) |
|
539 | 539 | invalid = numpy.isnan(data) |
|
540 | 540 | data[invalid] = self.missing |
|
541 | 541 | |
|
542 | 542 | out = {} |
|
543 | 543 | for key, value in list(self.twoDDict.items()): |
|
544 | 544 | key = key.lower() |
|
545 | 545 | if isinstance(value, str): |
|
546 | 546 | if 'db' in value.lower(): |
|
547 | 547 | tmp = getattr(self.dataOut, value.replace('_db', '')) |
|
548 | 548 | SNRavg = numpy.average(tmp, axis=0) |
|
549 | 549 | tmp = 10*numpy.log10(SNRavg) |
|
550 | 550 | else: |
|
551 | 551 | tmp = getattr(self.dataOut, value) |
|
552 | 552 | out[key] = tmp.flatten() |
|
553 | 553 | elif isinstance(value, (tuple, list)): |
|
554 | 554 | attr, x = value |
|
555 | 555 | data = getattr(self.dataOut, attr) |
|
556 | 556 | out[key] = data[int(x)] |
|
557 | 557 | |
|
558 | 558 | a = numpy.array([out[k] for k in self.keys]) |
|
559 | 559 | nrows = numpy.array([numpy.isnan(a[:, x]).all() for x in range(len(heights))]) |
|
560 | 560 | index = numpy.where(nrows == False)[0] |
|
561 | 561 | |
|
562 | 562 | rec = madrigal.cedar.MadrigalDataRecord( |
|
563 | 563 | self.kinst, |
|
564 | 564 | self.kindat, |
|
565 | 565 | startTime.year, |
|
566 | 566 | startTime.month, |
|
567 | 567 | startTime.day, |
|
568 | 568 | startTime.hour, |
|
569 | 569 | startTime.minute, |
|
570 | 570 | startTime.second, |
|
571 | 571 | startTime.microsecond/10000, |
|
572 | 572 | endTime.year, |
|
573 | 573 | endTime.month, |
|
574 | 574 | endTime.day, |
|
575 | 575 | endTime.hour, |
|
576 | 576 | endTime.minute, |
|
577 | 577 | endTime.second, |
|
578 | 578 | endTime.microsecond/10000, |
|
579 | 579 | list(self.oneDDict.keys()), |
|
580 | 580 | list(self.twoDDict.keys()), |
|
581 | 581 | len(index), |
|
582 | 582 | **self.extra_args |
|
583 | 583 | ) |
|
584 | 584 | |
|
585 | 585 | # Setting 1d values |
|
586 | 586 | for key in self.oneDDict: |
|
587 | 587 | rec.set1D(key, getattr(self.dataOut, self.oneDDict[key])) |
|
588 | 588 | |
|
589 | 589 | # Setting 2d values |
|
590 | 590 | nrec = 0 |
|
591 | 591 | for n in index: |
|
592 | 592 | for key in out: |
|
593 | 593 | rec.set2D(key, nrec, out[key][n]) |
|
594 | 594 | nrec += 1 |
|
595 | 595 | |
|
596 | 596 | self.fp.append(rec) |
|
597 | 597 | if self.ext == '.hdf5' and self.counter % 500 == 0 and self.counter > 0: |
|
598 | 598 | self.fp.dump() |
|
599 | 599 | if self.counter % 100 == 0 and self.counter > 0: |
|
600 | 600 | log.log( |
|
601 | 601 | 'Writing {} records'.format( |
|
602 | 602 | self.counter), |
|
603 | 603 | 'MADWriter') |
|
604 | 604 | |
|
605 | 605 | def setHeader(self): |
|
606 | 606 | ''' |
|
607 | 607 | Create an add catalog and header to cedar file |
|
608 | 608 | ''' |
|
609 | 609 | |
|
610 | 610 | log.success('Closing file {}'.format(self.fullname), 'MADWriter') |
|
611 | 611 | |
|
612 | 612 | if self.ext == '.dat': |
|
613 | 613 | self.fp.write() |
|
614 | 614 | else: |
|
615 | 615 | self.fp.dump() |
|
616 | 616 | self.fp.close() |
|
617 | 617 | |
|
618 | 618 | header = madrigal.cedar.CatalogHeaderCreator(self.fullname) |
|
619 | 619 | header.createCatalog(**self.catalog) |
|
620 | 620 | header.createHeader(**self.header) |
|
621 | 621 | header.write() |
|
622 | 622 | |
|
623 | 623 | def putData(self): |
|
624 | 624 | |
|
625 | 625 | if self.dataOut.flagNoData: |
|
626 | 626 | return 0 |
|
627 | 627 | |
|
628 | 628 | if self.dataOut.flagDiscontinuousBlock or self.counter == self.blocks: |
|
629 | 629 | if self.counter > 0: |
|
630 | 630 | self.setHeader() |
|
631 | 631 | self.counter = 0 |
|
632 | 632 | |
|
633 | 633 | if self.counter == 0: |
|
634 | 634 | self.setFile() |
|
635 | 635 | |
|
636 | 636 | self.writeBlock() |
|
637 | 637 | self.counter += 1 |
|
638 | 638 | |
|
639 | 639 | def close(self): |
|
640 | 640 | |
|
641 | 641 | if self.counter > 0: |
|
642 | 642 | self.setHeader() No newline at end of file |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now