##// END OF EJS Templates
-jrodata, parameters class bug fixed...
Julio Valdez -
r550:5ffe99434b98
parent child
Show More
@@ -1,1025 +1,1025
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import copy
7 import copy
8 import numpy
8 import numpy
9 import datetime
9 import datetime
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
11 from jroheaderIO import SystemHeader, RadarControllerHeader
12
12
13 def getNumpyDtype(dataTypeCode):
13 def getNumpyDtype(dataTypeCode):
14
14
15 if dataTypeCode == 0:
15 if dataTypeCode == 0:
16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
17 elif dataTypeCode == 1:
17 elif dataTypeCode == 1:
18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
19 elif dataTypeCode == 2:
19 elif dataTypeCode == 2:
20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
21 elif dataTypeCode == 3:
21 elif dataTypeCode == 3:
22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
23 elif dataTypeCode == 4:
23 elif dataTypeCode == 4:
24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
25 elif dataTypeCode == 5:
25 elif dataTypeCode == 5:
26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
27 else:
27 else:
28 raise ValueError, 'dataTypeCode was not defined'
28 raise ValueError, 'dataTypeCode was not defined'
29
29
30 return numpyDtype
30 return numpyDtype
31
31
32 def getDataTypeCode(numpyDtype):
32 def getDataTypeCode(numpyDtype):
33
33
34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
35 datatype = 0
35 datatype = 0
36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
37 datatype = 1
37 datatype = 1
38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
39 datatype = 2
39 datatype = 2
40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
41 datatype = 3
41 datatype = 3
42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
43 datatype = 4
43 datatype = 4
44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
45 datatype = 5
45 datatype = 5
46 else:
46 else:
47 datatype = None
47 datatype = None
48
48
49 return datatype
49 return datatype
50
50
51 def hildebrand_sekhon(data, navg):
51 def hildebrand_sekhon(data, navg):
52
52
53 data = data.copy()
53 data = data.copy()
54
54
55 sortdata = numpy.sort(data,axis=None)
55 sortdata = numpy.sort(data,axis=None)
56 lenOfData = len(sortdata)
56 lenOfData = len(sortdata)
57 nums_min = lenOfData/10
57 nums_min = lenOfData/10
58
58
59 if (lenOfData/10) > 2:
59 if (lenOfData/10) > 2:
60 nums_min = lenOfData/10
60 nums_min = lenOfData/10
61 else:
61 else:
62 nums_min = 2
62 nums_min = 2
63
63
64 sump = 0.
64 sump = 0.
65
65
66 sumq = 0.
66 sumq = 0.
67
67
68 j = 0
68 j = 0
69
69
70 cont = 1
70 cont = 1
71
71
72 while((cont==1)and(j<lenOfData)):
72 while((cont==1)and(j<lenOfData)):
73
73
74 sump += sortdata[j]
74 sump += sortdata[j]
75
75
76 sumq += sortdata[j]**2
76 sumq += sortdata[j]**2
77
77
78 j += 1
78 j += 1
79
79
80 if j > nums_min:
80 if j > nums_min:
81 rtest = float(j)/(j-1) + 1.0/navg
81 rtest = float(j)/(j-1) + 1.0/navg
82 if ((sumq*j) > (rtest*sump**2)):
82 if ((sumq*j) > (rtest*sump**2)):
83 j = j - 1
83 j = j - 1
84 sump = sump - sortdata[j]
84 sump = sump - sortdata[j]
85 sumq = sumq - sortdata[j]**2
85 sumq = sumq - sortdata[j]**2
86 cont = 0
86 cont = 0
87
87
88 lnoise = sump /j
88 lnoise = sump /j
89 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
89 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
90 return lnoise
90 return lnoise
91
91
92 class Beam:
92 class Beam:
93 def __init__(self):
93 def __init__(self):
94 self.codeList = []
94 self.codeList = []
95 self.azimuthList = []
95 self.azimuthList = []
96 self.zenithList = []
96 self.zenithList = []
97
97
98 class GenericData(object):
98 class GenericData(object):
99
99
100 flagNoData = True
100 flagNoData = True
101
101
102 def __init__(self):
102 def __init__(self):
103
103
104 raise ValueError, "This class has not been implemented"
104 raise ValueError, "This class has not been implemented"
105
105
106 def copy(self, inputObj=None):
106 def copy(self, inputObj=None):
107
107
108 if inputObj == None:
108 if inputObj == None:
109 return copy.deepcopy(self)
109 return copy.deepcopy(self)
110
110
111 for key in inputObj.__dict__.keys():
111 for key in inputObj.__dict__.keys():
112 self.__dict__[key] = inputObj.__dict__[key]
112 self.__dict__[key] = inputObj.__dict__[key]
113
113
114 def deepcopy(self):
114 def deepcopy(self):
115
115
116 return copy.deepcopy(self)
116 return copy.deepcopy(self)
117
117
118 def isEmpty(self):
118 def isEmpty(self):
119
119
120 return self.flagNoData
120 return self.flagNoData
121
121
122 class JROData(GenericData):
122 class JROData(GenericData):
123
123
124 # m_BasicHeader = BasicHeader()
124 # m_BasicHeader = BasicHeader()
125 # m_ProcessingHeader = ProcessingHeader()
125 # m_ProcessingHeader = ProcessingHeader()
126
126
127 systemHeaderObj = SystemHeader()
127 systemHeaderObj = SystemHeader()
128
128
129 radarControllerHeaderObj = RadarControllerHeader()
129 radarControllerHeaderObj = RadarControllerHeader()
130
130
131 # data = None
131 # data = None
132
132
133 type = None
133 type = None
134
134
135 datatype = None #dtype but in string
135 datatype = None #dtype but in string
136
136
137 # dtype = None
137 # dtype = None
138
138
139 # nChannels = None
139 # nChannels = None
140
140
141 # nHeights = None
141 # nHeights = None
142
142
143 nProfiles = None
143 nProfiles = None
144
144
145 heightList = None
145 heightList = None
146
146
147 channelList = None
147 channelList = None
148
148
149 flagTimeBlock = False
149 flagTimeBlock = False
150
150
151 useLocalTime = False
151 useLocalTime = False
152
152
153 utctime = None
153 utctime = None
154
154
155 timeZone = None
155 timeZone = None
156
156
157 dstFlag = None
157 dstFlag = None
158
158
159 errorCount = None
159 errorCount = None
160
160
161 blocksize = None
161 blocksize = None
162
162
163 nCode = None
163 nCode = None
164
164
165 nBaud = None
165 nBaud = None
166
166
167 code = None
167 code = None
168
168
169 flagDecodeData = False #asumo q la data no esta decodificada
169 flagDecodeData = False #asumo q la data no esta decodificada
170
170
171 flagDeflipData = False #asumo q la data no esta sin flip
171 flagDeflipData = False #asumo q la data no esta sin flip
172
172
173 flagShiftFFT = False
173 flagShiftFFT = False
174
174
175 # ippSeconds = None
175 # ippSeconds = None
176
176
177 # timeInterval = None
177 # timeInterval = None
178
178
179 nCohInt = None
179 nCohInt = None
180
180
181 noise = None
181 noise = None
182
182
183 windowOfFilter = 1
183 windowOfFilter = 1
184
184
185 #Speed of ligth
185 #Speed of ligth
186 C = 3e8
186 C = 3e8
187
187
188 frequency = 49.92e6
188 frequency = 49.92e6
189
189
190 realtime = False
190 realtime = False
191
191
192 beacon_heiIndexList = None
192 beacon_heiIndexList = None
193
193
194 last_block = None
194 last_block = None
195
195
196 blocknow = None
196 blocknow = None
197
197
198 azimuth = None
198 azimuth = None
199
199
200 zenith = None
200 zenith = None
201
201
202 beam = Beam()
202 beam = Beam()
203
203
204 profileIndex = None
204 profileIndex = None
205
205
206 def __init__(self):
206 def __init__(self):
207
207
208 raise ValueError, "This class has not been implemented"
208 raise ValueError, "This class has not been implemented"
209
209
210 def getNoise(self):
210 def getNoise(self):
211
211
212 raise ValueError, "Not implemented"
212 raise ValueError, "Not implemented"
213
213
214 def getNChannels(self):
214 def getNChannels(self):
215
215
216 return len(self.channelList)
216 return len(self.channelList)
217
217
218 def getChannelIndexList(self):
218 def getChannelIndexList(self):
219
219
220 return range(self.nChannels)
220 return range(self.nChannels)
221
221
222 def getNHeights(self):
222 def getNHeights(self):
223
223
224 return len(self.heightList)
224 return len(self.heightList)
225
225
226 def getHeiRange(self, extrapoints=0):
226 def getHeiRange(self, extrapoints=0):
227
227
228 heis = self.heightList
228 heis = self.heightList
229 # deltah = self.heightList[1] - self.heightList[0]
229 # deltah = self.heightList[1] - self.heightList[0]
230 #
230 #
231 # heis.append(self.heightList[-1])
231 # heis.append(self.heightList[-1])
232
232
233 return heis
233 return heis
234
234
235 def getltctime(self):
235 def getltctime(self):
236
236
237 if self.useLocalTime:
237 if self.useLocalTime:
238 return self.utctime - self.timeZone*60
238 return self.utctime - self.timeZone*60
239
239
240 return self.utctime
240 return self.utctime
241
241
242 def getDatatime(self):
242 def getDatatime(self):
243
243
244 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
244 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
245 return datatimeValue
245 return datatimeValue
246
246
247 def getTimeRange(self):
247 def getTimeRange(self):
248
248
249 datatime = []
249 datatime = []
250
250
251 datatime.append(self.ltctime)
251 datatime.append(self.ltctime)
252 datatime.append(self.ltctime + self.timeInterval)
252 datatime.append(self.ltctime + self.timeInterval)
253
253
254 datatime = numpy.array(datatime)
254 datatime = numpy.array(datatime)
255
255
256 return datatime
256 return datatime
257
257
258 def getFmax(self):
258 def getFmax(self):
259
259
260 PRF = 1./(self.ippSeconds * self.nCohInt)
260 PRF = 1./(self.ippSeconds * self.nCohInt)
261
261
262 fmax = PRF/2.
262 fmax = PRF/2.
263
263
264 return fmax
264 return fmax
265
265
266 def getVmax(self):
266 def getVmax(self):
267
267
268 _lambda = self.C/self.frequency
268 _lambda = self.C/self.frequency
269
269
270 vmax = self.getFmax() * _lambda
270 vmax = self.getFmax() * _lambda
271
271
272 return vmax
272 return vmax
273
273
274 def get_ippSeconds(self):
274 def get_ippSeconds(self):
275 '''
275 '''
276 '''
276 '''
277 return self.radarControllerHeaderObj.ippSeconds
277 return self.radarControllerHeaderObj.ippSeconds
278
278
279 def set_ippSeconds(self, ippSeconds):
279 def set_ippSeconds(self, ippSeconds):
280 '''
280 '''
281 '''
281 '''
282
282
283 self.radarControllerHeaderObj.ippSeconds = ippSeconds
283 self.radarControllerHeaderObj.ippSeconds = ippSeconds
284
284
285 return
285 return
286
286
287 def get_dtype(self):
287 def get_dtype(self):
288 '''
288 '''
289 '''
289 '''
290 return getNumpyDtype(self.datatype)
290 return getNumpyDtype(self.datatype)
291
291
292 def set_dtype(self, numpyDtype):
292 def set_dtype(self, numpyDtype):
293 '''
293 '''
294 '''
294 '''
295
295
296 self.datatype = getDataTypeCode(numpyDtype)
296 self.datatype = getDataTypeCode(numpyDtype)
297
297
298 # def getTimeInterval(self):
298 # def getTimeInterval(self):
299 #
299 #
300 # raise IOError, "This method should be implemented inside each Class"
300 # raise IOError, "This method should be implemented inside each Class"
301
301
302 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
302 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
303 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
303 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
304 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
304 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
305 #noise = property(getNoise, "I'm the 'nHeights' property.")
305 #noise = property(getNoise, "I'm the 'nHeights' property.")
306 datatime = property(getDatatime, "I'm the 'datatime' property")
306 datatime = property(getDatatime, "I'm the 'datatime' property")
307 ltctime = property(getltctime, "I'm the 'ltctime' property")
307 ltctime = property(getltctime, "I'm the 'ltctime' property")
308 ippSeconds = property(get_ippSeconds, set_ippSeconds)
308 ippSeconds = property(get_ippSeconds, set_ippSeconds)
309 dtype = property(get_dtype, set_dtype)
309 dtype = property(get_dtype, set_dtype)
310 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
310 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
311
311
312 class Voltage(JROData):
312 class Voltage(JROData):
313
313
314 #data es un numpy array de 2 dmensiones (canales, alturas)
314 #data es un numpy array de 2 dmensiones (canales, alturas)
315 data = None
315 data = None
316
316
317 def __init__(self):
317 def __init__(self):
318 '''
318 '''
319 Constructor
319 Constructor
320 '''
320 '''
321
321
322 self.radarControllerHeaderObj = RadarControllerHeader()
322 self.radarControllerHeaderObj = RadarControllerHeader()
323
323
324 self.systemHeaderObj = SystemHeader()
324 self.systemHeaderObj = SystemHeader()
325
325
326 self.type = "Voltage"
326 self.type = "Voltage"
327
327
328 self.data = None
328 self.data = None
329
329
330 # self.dtype = None
330 # self.dtype = None
331
331
332 # self.nChannels = 0
332 # self.nChannels = 0
333
333
334 # self.nHeights = 0
334 # self.nHeights = 0
335
335
336 self.nProfiles = None
336 self.nProfiles = None
337
337
338 self.heightList = None
338 self.heightList = None
339
339
340 self.channelList = None
340 self.channelList = None
341
341
342 # self.channelIndexList = None
342 # self.channelIndexList = None
343
343
344 self.flagNoData = True
344 self.flagNoData = True
345
345
346 self.flagTimeBlock = False
346 self.flagTimeBlock = False
347
347
348 self.utctime = None
348 self.utctime = None
349
349
350 self.timeZone = None
350 self.timeZone = None
351
351
352 self.dstFlag = None
352 self.dstFlag = None
353
353
354 self.errorCount = None
354 self.errorCount = None
355
355
356 self.nCohInt = None
356 self.nCohInt = None
357
357
358 self.blocksize = None
358 self.blocksize = None
359
359
360 self.flagDecodeData = False #asumo q la data no esta decodificada
360 self.flagDecodeData = False #asumo q la data no esta decodificada
361
361
362 self.flagDeflipData = False #asumo q la data no esta sin flip
362 self.flagDeflipData = False #asumo q la data no esta sin flip
363
363
364 self.flagShiftFFT = False
364 self.flagShiftFFT = False
365
365
366 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
366 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
367
367
368 self.profileIndex = 0
368 self.profileIndex = 0
369
369
370 def getNoisebyHildebrand(self):
370 def getNoisebyHildebrand(self):
371 """
371 """
372 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
372 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
373
373
374 Return:
374 Return:
375 noiselevel
375 noiselevel
376 """
376 """
377
377
378 for channel in range(self.nChannels):
378 for channel in range(self.nChannels):
379 daux = self.data_spc[channel,:,:]
379 daux = self.data_spc[channel,:,:]
380 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
380 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
381
381
382 return self.noise
382 return self.noise
383
383
384 def getNoise(self, type = 1):
384 def getNoise(self, type = 1):
385
385
386 self.noise = numpy.zeros(self.nChannels)
386 self.noise = numpy.zeros(self.nChannels)
387
387
388 if type == 1:
388 if type == 1:
389 noise = self.getNoisebyHildebrand()
389 noise = self.getNoisebyHildebrand()
390
390
391 return 10*numpy.log10(noise)
391 return 10*numpy.log10(noise)
392
392
393 def getTimeInterval(self):
393 def getTimeInterval(self):
394
394
395 timeInterval = self.ippSeconds * self.nCohInt
395 timeInterval = self.ippSeconds * self.nCohInt
396
396
397 return timeInterval
397 return timeInterval
398
398
399 noise = property(getNoise, "I'm the 'nHeights' property.")
399 noise = property(getNoise, "I'm the 'nHeights' property.")
400 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
400 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
401
401
402 class Spectra(JROData):
402 class Spectra(JROData):
403
403
404 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
404 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
405 data_spc = None
405 data_spc = None
406
406
407 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
407 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
408 data_cspc = None
408 data_cspc = None
409
409
410 #data es un numpy array de 2 dmensiones (canales, alturas)
410 #data es un numpy array de 2 dmensiones (canales, alturas)
411 data_dc = None
411 data_dc = None
412
412
413 nFFTPoints = None
413 nFFTPoints = None
414
414
415 # nPairs = None
415 # nPairs = None
416
416
417 pairsList = None
417 pairsList = None
418
418
419 nIncohInt = None
419 nIncohInt = None
420
420
421 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
421 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
422
422
423 nCohInt = None #se requiere para determinar el valor de timeInterval
423 nCohInt = None #se requiere para determinar el valor de timeInterval
424
424
425 ippFactor = None
425 ippFactor = None
426
426
427 profileIndex = 0
427 profileIndex = 0
428
428
429 def __init__(self):
429 def __init__(self):
430 '''
430 '''
431 Constructor
431 Constructor
432 '''
432 '''
433
433
434 self.radarControllerHeaderObj = RadarControllerHeader()
434 self.radarControllerHeaderObj = RadarControllerHeader()
435
435
436 self.systemHeaderObj = SystemHeader()
436 self.systemHeaderObj = SystemHeader()
437
437
438 self.type = "Spectra"
438 self.type = "Spectra"
439
439
440 # self.data = None
440 # self.data = None
441
441
442 # self.dtype = None
442 # self.dtype = None
443
443
444 # self.nChannels = 0
444 # self.nChannels = 0
445
445
446 # self.nHeights = 0
446 # self.nHeights = 0
447
447
448 self.nProfiles = None
448 self.nProfiles = None
449
449
450 self.heightList = None
450 self.heightList = None
451
451
452 self.channelList = None
452 self.channelList = None
453
453
454 # self.channelIndexList = None
454 # self.channelIndexList = None
455
455
456 self.pairsList = None
456 self.pairsList = None
457
457
458 self.flagNoData = True
458 self.flagNoData = True
459
459
460 self.flagTimeBlock = False
460 self.flagTimeBlock = False
461
461
462 self.utctime = None
462 self.utctime = None
463
463
464 self.nCohInt = None
464 self.nCohInt = None
465
465
466 self.nIncohInt = None
466 self.nIncohInt = None
467
467
468 self.blocksize = None
468 self.blocksize = None
469
469
470 self.nFFTPoints = None
470 self.nFFTPoints = None
471
471
472 self.wavelength = None
472 self.wavelength = None
473
473
474 self.flagDecodeData = False #asumo q la data no esta decodificada
474 self.flagDecodeData = False #asumo q la data no esta decodificada
475
475
476 self.flagDeflipData = False #asumo q la data no esta sin flip
476 self.flagDeflipData = False #asumo q la data no esta sin flip
477
477
478 self.flagShiftFFT = False
478 self.flagShiftFFT = False
479
479
480 self.ippFactor = 1
480 self.ippFactor = 1
481
481
482 #self.noise = None
482 #self.noise = None
483
483
484 self.beacon_heiIndexList = []
484 self.beacon_heiIndexList = []
485
485
486 self.noise_estimation = None
486 self.noise_estimation = None
487
487
488
488
489 def getNoisebyHildebrand(self):
489 def getNoisebyHildebrand(self):
490 """
490 """
491 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
491 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
492
492
493 Return:
493 Return:
494 noiselevel
494 noiselevel
495 """
495 """
496
496
497 noise = numpy.zeros(self.nChannels)
497 noise = numpy.zeros(self.nChannels)
498 for channel in range(self.nChannels):
498 for channel in range(self.nChannels):
499 daux = self.data_spc[channel,:,:]
499 daux = self.data_spc[channel,:,:]
500 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
500 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
501
501
502 return noise
502 return noise
503
503
504 def getNoise(self):
504 def getNoise(self):
505 if self.noise_estimation != None:
505 if self.noise_estimation != None:
506 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
506 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
507 else:
507 else:
508 noise = self.getNoisebyHildebrand()
508 noise = self.getNoisebyHildebrand()
509 return noise
509 return noise
510
510
511
511
512 def getFreqRange(self, extrapoints=0):
512 def getFreqRange(self, extrapoints=0):
513
513
514 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
514 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
515 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
515 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
516
516
517 return freqrange
517 return freqrange
518
518
519 def getVelRange(self, extrapoints=0):
519 def getVelRange(self, extrapoints=0):
520
520
521 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
521 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
522 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
522 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
523
523
524 return velrange
524 return velrange
525
525
526 def getNPairs(self):
526 def getNPairs(self):
527
527
528 return len(self.pairsList)
528 return len(self.pairsList)
529
529
530 def getPairsIndexList(self):
530 def getPairsIndexList(self):
531
531
532 return range(self.nPairs)
532 return range(self.nPairs)
533
533
534 def getNormFactor(self):
534 def getNormFactor(self):
535 pwcode = 1
535 pwcode = 1
536 if self.flagDecodeData:
536 if self.flagDecodeData:
537 pwcode = numpy.sum(self.code[0]**2)
537 pwcode = numpy.sum(self.code[0]**2)
538 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
538 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
539 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
539 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
540
540
541 return normFactor
541 return normFactor
542
542
543 def getFlagCspc(self):
543 def getFlagCspc(self):
544
544
545 if self.data_cspc == None:
545 if self.data_cspc == None:
546 return True
546 return True
547
547
548 return False
548 return False
549
549
550 def getFlagDc(self):
550 def getFlagDc(self):
551
551
552 if self.data_dc == None:
552 if self.data_dc == None:
553 return True
553 return True
554
554
555 return False
555 return False
556
556
557 def getTimeInterval(self):
557 def getTimeInterval(self):
558
558
559 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
559 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
560
560
561 return timeInterval
561 return timeInterval
562
562
563 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
563 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
564 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
564 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
565 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
565 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
566 flag_cspc = property(getFlagCspc)
566 flag_cspc = property(getFlagCspc)
567 flag_dc = property(getFlagDc)
567 flag_dc = property(getFlagDc)
568 noise = property(getNoise, "I'm the 'nHeights' property.")
568 noise = property(getNoise, "I'm the 'nHeights' property.")
569 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
569 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
570
570
571 class SpectraHeis(Spectra):
571 class SpectraHeis(Spectra):
572
572
573 data_spc = None
573 data_spc = None
574
574
575 data_cspc = None
575 data_cspc = None
576
576
577 data_dc = None
577 data_dc = None
578
578
579 nFFTPoints = None
579 nFFTPoints = None
580
580
581 # nPairs = None
581 # nPairs = None
582
582
583 pairsList = None
583 pairsList = None
584
584
585 nIncohInt = None
585 nIncohInt = None
586
586
587 def __init__(self):
587 def __init__(self):
588
588
589 self.radarControllerHeaderObj = RadarControllerHeader()
589 self.radarControllerHeaderObj = RadarControllerHeader()
590
590
591 self.systemHeaderObj = SystemHeader()
591 self.systemHeaderObj = SystemHeader()
592
592
593 self.type = "SpectraHeis"
593 self.type = "SpectraHeis"
594
594
595 # self.dtype = None
595 # self.dtype = None
596
596
597 # self.nChannels = 0
597 # self.nChannels = 0
598
598
599 # self.nHeights = 0
599 # self.nHeights = 0
600
600
601 self.nProfiles = None
601 self.nProfiles = None
602
602
603 self.heightList = None
603 self.heightList = None
604
604
605 self.channelList = None
605 self.channelList = None
606
606
607 # self.channelIndexList = None
607 # self.channelIndexList = None
608
608
609 self.flagNoData = True
609 self.flagNoData = True
610
610
611 self.flagTimeBlock = False
611 self.flagTimeBlock = False
612
612
613 # self.nPairs = 0
613 # self.nPairs = 0
614
614
615 self.utctime = None
615 self.utctime = None
616
616
617 self.blocksize = None
617 self.blocksize = None
618
618
619 self.profileIndex = 0
619 self.profileIndex = 0
620
620
621 def getNormFactor(self):
621 def getNormFactor(self):
622 pwcode = 1
622 pwcode = 1
623 if self.flagDecodeData:
623 if self.flagDecodeData:
624 pwcode = numpy.sum(self.code[0]**2)
624 pwcode = numpy.sum(self.code[0]**2)
625
625
626 normFactor = self.nIncohInt*self.nCohInt*pwcode
626 normFactor = self.nIncohInt*self.nCohInt*pwcode
627
627
628 return normFactor
628 return normFactor
629
629
630 def getTimeInterval(self):
630 def getTimeInterval(self):
631
631
632 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
632 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
633
633
634 return timeInterval
634 return timeInterval
635
635
636 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
636 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
637 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
637 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
638
638
639 class Fits:
639 class Fits:
640
640
641 heightList = None
641 heightList = None
642
642
643 channelList = None
643 channelList = None
644
644
645 flagNoData = True
645 flagNoData = True
646
646
647 flagTimeBlock = False
647 flagTimeBlock = False
648
648
649 useLocalTime = False
649 useLocalTime = False
650
650
651 utctime = None
651 utctime = None
652
652
653 timeZone = None
653 timeZone = None
654
654
655 # ippSeconds = None
655 # ippSeconds = None
656
656
657 # timeInterval = None
657 # timeInterval = None
658
658
659 nCohInt = None
659 nCohInt = None
660
660
661 nIncohInt = None
661 nIncohInt = None
662
662
663 noise = None
663 noise = None
664
664
665 windowOfFilter = 1
665 windowOfFilter = 1
666
666
667 #Speed of ligth
667 #Speed of ligth
668 C = 3e8
668 C = 3e8
669
669
670 frequency = 49.92e6
670 frequency = 49.92e6
671
671
672 realtime = False
672 realtime = False
673
673
674
674
675 def __init__(self):
675 def __init__(self):
676
676
677 self.type = "Fits"
677 self.type = "Fits"
678
678
679 self.nProfiles = None
679 self.nProfiles = None
680
680
681 self.heightList = None
681 self.heightList = None
682
682
683 self.channelList = None
683 self.channelList = None
684
684
685 # self.channelIndexList = None
685 # self.channelIndexList = None
686
686
687 self.flagNoData = True
687 self.flagNoData = True
688
688
689 self.utctime = None
689 self.utctime = None
690
690
691 self.nCohInt = None
691 self.nCohInt = None
692
692
693 self.nIncohInt = None
693 self.nIncohInt = None
694
694
695 self.useLocalTime = True
695 self.useLocalTime = True
696
696
697 self.profileIndex = 0
697 self.profileIndex = 0
698
698
699 # self.utctime = None
699 # self.utctime = None
700 # self.timeZone = None
700 # self.timeZone = None
701 # self.ltctime = None
701 # self.ltctime = None
702 # self.timeInterval = None
702 # self.timeInterval = None
703 # self.header = None
703 # self.header = None
704 # self.data_header = None
704 # self.data_header = None
705 # self.data = None
705 # self.data = None
706 # self.datatime = None
706 # self.datatime = None
707 # self.flagNoData = False
707 # self.flagNoData = False
708 # self.expName = ''
708 # self.expName = ''
709 # self.nChannels = None
709 # self.nChannels = None
710 # self.nSamples = None
710 # self.nSamples = None
711 # self.dataBlocksPerFile = None
711 # self.dataBlocksPerFile = None
712 # self.comments = ''
712 # self.comments = ''
713 #
713 #
714
714
715
715
716 def getltctime(self):
716 def getltctime(self):
717
717
718 if self.useLocalTime:
718 if self.useLocalTime:
719 return self.utctime - self.timeZone*60
719 return self.utctime - self.timeZone*60
720
720
721 return self.utctime
721 return self.utctime
722
722
723 def getDatatime(self):
723 def getDatatime(self):
724
724
725 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
725 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
726 return datatime
726 return datatime
727
727
728 def getTimeRange(self):
728 def getTimeRange(self):
729
729
730 datatime = []
730 datatime = []
731
731
732 datatime.append(self.ltctime)
732 datatime.append(self.ltctime)
733 datatime.append(self.ltctime + self.timeInterval)
733 datatime.append(self.ltctime + self.timeInterval)
734
734
735 datatime = numpy.array(datatime)
735 datatime = numpy.array(datatime)
736
736
737 return datatime
737 return datatime
738
738
739 def getHeiRange(self):
739 def getHeiRange(self):
740
740
741 heis = self.heightList
741 heis = self.heightList
742
742
743 return heis
743 return heis
744
744
745 def isEmpty(self):
745 def isEmpty(self):
746
746
747 return self.flagNoData
747 return self.flagNoData
748
748
749 def getNHeights(self):
749 def getNHeights(self):
750
750
751 return len(self.heightList)
751 return len(self.heightList)
752
752
753 def getNChannels(self):
753 def getNChannels(self):
754
754
755 return len(self.channelList)
755 return len(self.channelList)
756
756
757 def getChannelIndexList(self):
757 def getChannelIndexList(self):
758
758
759 return range(self.nChannels)
759 return range(self.nChannels)
760
760
761 def getNoise(self, type = 1):
761 def getNoise(self, type = 1):
762
762
763 self.noise = numpy.zeros(self.nChannels)
763 self.noise = numpy.zeros(self.nChannels)
764
764
765 if type == 1:
765 if type == 1:
766 noise = self.getNoisebyHildebrand()
766 noise = self.getNoisebyHildebrand()
767
767
768 if type == 2:
768 if type == 2:
769 noise = self.getNoisebySort()
769 noise = self.getNoisebySort()
770
770
771 if type == 3:
771 if type == 3:
772 noise = self.getNoisebyWindow()
772 noise = self.getNoisebyWindow()
773
773
774 return noise
774 return noise
775
775
776 def getTimeInterval(self):
776 def getTimeInterval(self):
777
777
778 raise ValueError, "This method is not implemented yet"
778 raise ValueError, "This method is not implemented yet"
779
779
780 datatime = property(getDatatime, "I'm the 'datatime' property")
780 datatime = property(getDatatime, "I'm the 'datatime' property")
781 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
781 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
782 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
782 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
783 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
783 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
784 noise = property(getNoise, "I'm the 'nHeights' property.")
784 noise = property(getNoise, "I'm the 'nHeights' property.")
785 datatime = property(getDatatime, "I'm the 'datatime' property")
785 datatime = property(getDatatime, "I'm the 'datatime' property")
786 ltctime = property(getltctime, "I'm the 'ltctime' property")
786 ltctime = property(getltctime, "I'm the 'ltctime' property")
787 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
787 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
788
788
789 class Correlation(JROData):
789 class Correlation(JROData):
790
790
791 noise = None
791 noise = None
792
792
793 SNR = None
793 SNR = None
794
794
795 pairsAutoCorr = None #Pairs of Autocorrelation
795 pairsAutoCorr = None #Pairs of Autocorrelation
796
796
797 #--------------------------------------------------
797 #--------------------------------------------------
798
798
799 data_corr = None
799 data_corr = None
800
800
801 data_volt = None
801 data_volt = None
802
802
803 lagT = None # each element value is a profileIndex
803 lagT = None # each element value is a profileIndex
804
804
805 lagR = None # each element value is in km
805 lagR = None # each element value is in km
806
806
807 pairsList = None
807 pairsList = None
808
808
809 calculateVelocity = None
809 calculateVelocity = None
810
810
811 nPoints = None
811 nPoints = None
812
812
813 nAvg = None
813 nAvg = None
814
814
815 bufferSize = None
815 bufferSize = None
816
816
817 def __init__(self):
817 def __init__(self):
818 '''
818 '''
819 Constructor
819 Constructor
820 '''
820 '''
821 self.radarControllerHeaderObj = RadarControllerHeader()
821 self.radarControllerHeaderObj = RadarControllerHeader()
822
822
823 self.systemHeaderObj = SystemHeader()
823 self.systemHeaderObj = SystemHeader()
824
824
825 self.type = "Correlation"
825 self.type = "Correlation"
826
826
827 self.data = None
827 self.data = None
828
828
829 self.dtype = None
829 self.dtype = None
830
830
831 self.nProfiles = None
831 self.nProfiles = None
832
832
833 self.heightList = None
833 self.heightList = None
834
834
835 self.channelList = None
835 self.channelList = None
836
836
837 self.flagNoData = True
837 self.flagNoData = True
838
838
839 self.flagTimeBlock = False
839 self.flagTimeBlock = False
840
840
841 self.utctime = None
841 self.utctime = None
842
842
843 self.timeZone = None
843 self.timeZone = None
844
844
845 self.dstFlag = None
845 self.dstFlag = None
846
846
847 self.errorCount = None
847 self.errorCount = None
848
848
849 self.blocksize = None
849 self.blocksize = None
850
850
851 self.flagDecodeData = False #asumo q la data no esta decodificada
851 self.flagDecodeData = False #asumo q la data no esta decodificada
852
852
853 self.flagDeflipData = False #asumo q la data no esta sin flip
853 self.flagDeflipData = False #asumo q la data no esta sin flip
854
854
855 self.pairsList = None
855 self.pairsList = None
856
856
857 self.nPoints = None
857 self.nPoints = None
858
858
859 def getLagTRange(self, extrapoints=0):
859 def getLagTRange(self, extrapoints=0):
860
860
861 lagTRange = self.lagT
861 lagTRange = self.lagT
862 diff = lagTRange[1] - lagTRange[0]
862 diff = lagTRange[1] - lagTRange[0]
863 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
863 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
864 lagTRange = numpy.hstack((lagTRange, extra))
864 lagTRange = numpy.hstack((lagTRange, extra))
865
865
866 return lagTRange
866 return lagTRange
867
867
868 def getLagRRange(self, extrapoints=0):
868 def getLagRRange(self, extrapoints=0):
869
869
870 return self.lagR
870 return self.lagR
871
871
872 def getPairsList(self):
872 def getPairsList(self):
873
873
874 return self.pairsList
874 return self.pairsList
875
875
876 def getCalculateVelocity(self):
876 def getCalculateVelocity(self):
877
877
878 return self.calculateVelocity
878 return self.calculateVelocity
879
879
880 def getNPoints(self):
880 def getNPoints(self):
881
881
882 return self.nPoints
882 return self.nPoints
883
883
884 def getNAvg(self):
884 def getNAvg(self):
885
885
886 return self.nAvg
886 return self.nAvg
887
887
888 def getBufferSize(self):
888 def getBufferSize(self):
889
889
890 return self.bufferSize
890 return self.bufferSize
891
891
892 def getPairsAutoCorr(self):
892 def getPairsAutoCorr(self):
893 pairsList = self.pairsList
893 pairsList = self.pairsList
894 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
894 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
895
895
896 for l in range(len(pairsList)):
896 for l in range(len(pairsList)):
897 firstChannel = pairsList[l][0]
897 firstChannel = pairsList[l][0]
898 secondChannel = pairsList[l][1]
898 secondChannel = pairsList[l][1]
899
899
900 #Obteniendo pares de Autocorrelacion
900 #Obteniendo pares de Autocorrelacion
901 if firstChannel == secondChannel:
901 if firstChannel == secondChannel:
902 pairsAutoCorr[firstChannel] = int(l)
902 pairsAutoCorr[firstChannel] = int(l)
903
903
904 pairsAutoCorr = pairsAutoCorr.astype(int)
904 pairsAutoCorr = pairsAutoCorr.astype(int)
905
905
906 return pairsAutoCorr
906 return pairsAutoCorr
907
907
908 def getNoise(self, mode = 2):
908 def getNoise(self, mode = 2):
909
909
910 indR = numpy.where(self.lagR == 0)[0][0]
910 indR = numpy.where(self.lagR == 0)[0][0]
911 indT = numpy.where(self.lagT == 0)[0][0]
911 indT = numpy.where(self.lagT == 0)[0][0]
912
912
913 jspectra0 = self.data_corr[:,:,indR,:]
913 jspectra0 = self.data_corr[:,:,indR,:]
914 jspectra = copy.copy(jspectra0)
914 jspectra = copy.copy(jspectra0)
915
915
916 num_chan = jspectra.shape[0]
916 num_chan = jspectra.shape[0]
917 num_hei = jspectra.shape[2]
917 num_hei = jspectra.shape[2]
918
918
919 freq_dc = jspectra.shape[1]/2
919 freq_dc = jspectra.shape[1]/2
920 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
920 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
921
921
922 if ind_vel[0]<0:
922 if ind_vel[0]<0:
923 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
923 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
924
924
925 if mode == 1:
925 if mode == 1:
926 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
926 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
927
927
928 if mode == 2:
928 if mode == 2:
929
929
930 vel = numpy.array([-2,-1,1,2])
930 vel = numpy.array([-2,-1,1,2])
931 xx = numpy.zeros([4,4])
931 xx = numpy.zeros([4,4])
932
932
933 for fil in range(4):
933 for fil in range(4):
934 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
934 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
935
935
936 xx_inv = numpy.linalg.inv(xx)
936 xx_inv = numpy.linalg.inv(xx)
937 xx_aux = xx_inv[0,:]
937 xx_aux = xx_inv[0,:]
938
938
939 for ich in range(num_chan):
939 for ich in range(num_chan):
940 yy = jspectra[ich,ind_vel,:]
940 yy = jspectra[ich,ind_vel,:]
941 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
941 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
942
942
943 junkid = jspectra[ich,freq_dc,:]<=0
943 junkid = jspectra[ich,freq_dc,:]<=0
944 cjunkid = sum(junkid)
944 cjunkid = sum(junkid)
945
945
946 if cjunkid.any():
946 if cjunkid.any():
947 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
947 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
948
948
949 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
949 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
950
950
951 return noise
951 return noise
952
952
953 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
953 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
954 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
954 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
955 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
955 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
956 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
956 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
957 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
957 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
958
958
959
959
960 class Parameters(JROData):
960 class Parameters(JROData):
961
961
962 #Information from previous data
962 #Information from previous data
963
963
964 inputUnit = None #Type of data to be processed
964 inputUnit = None #Type of data to be processed
965
965
966 operation = None #Type of operation to parametrize
966 operation = None #Type of operation to parametrize
967
967
968 normFactor = None #Normalization Factor
968 normFactor = None #Normalization Factor
969
969
970 groupList = None #List of Pairs, Groups, etc
970 groupList = None #List of Pairs, Groups, etc
971
971
972 #Parameters
972 #Parameters
973
973
974 data_param = None #Parameters obtained
974 data_param = None #Parameters obtained
975
975
976 data_pre = None #Data Pre Parametrization
976 data_pre = None #Data Pre Parametrization
977
977
978 data_SNR = None #Signal to Noise Ratio
978 data_SNR = None #Signal to Noise Ratio
979
979
980 heightRange = None #Heights
980 heightRange = None #Heights
981
981
982 abscissaRange = None #Abscissa, can be velocities, lags or time
982 abscissaRange = None #Abscissa, can be velocities, lags or time
983
983
984 noise = None #Noise Potency
984 noise = None #Noise Potency
985
985
986 initUtcTime = None #Initial UTC time
986 utctimeInit = None #Initial UTC time
987
987
988 paramInterval = None #Time interval to calculate Parameters in seconds
988 paramInterval = None #Time interval to calculate Parameters in seconds
989
989
990 #Fitting
990 #Fitting
991
991
992 data_error = None #Error of the estimation
992 data_error = None #Error of the estimation
993
993
994 constants = None
994 constants = None
995
995
996 library = None
996 library = None
997
997
998 #Output signal
998 #Output signal
999
999
1000 outputInterval = None #Time interval to calculate output signal in seconds
1000 outputInterval = None #Time interval to calculate output signal in seconds
1001
1001
1002 data_output = None #Out signal
1002 data_output = None #Out signal
1003
1003
1004
1004
1005
1005
1006 def __init__(self):
1006 def __init__(self):
1007 '''
1007 '''
1008 Constructor
1008 Constructor
1009 '''
1009 '''
1010 self.radarControllerHeaderObj = RadarControllerHeader()
1010 self.radarControllerHeaderObj = RadarControllerHeader()
1011
1011
1012 self.systemHeaderObj = SystemHeader()
1012 self.systemHeaderObj = SystemHeader()
1013
1013
1014 self.type = "Parameters"
1014 self.type = "Parameters"
1015
1015
1016 def getTimeRange1(self):
1016 def getTimeRange1(self):
1017
1017
1018 datatime = []
1018 datatime = []
1019
1019
1020 datatime.append(self.initUtcTime)
1020 datatime.append(self.utctimeInit)
1021 datatime.append(self.initUtcTime + self.outputInterval - 1)
1021 datatime.append(self.utctimeInit + self.outputInterval - 1)
1022
1022
1023 datatime = numpy.array(datatime)
1023 datatime = numpy.array(datatime)
1024
1024
1025 return datatime
1025 return datatime
@@ -1,1195 +1,1195
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4
4
5 from figure import Figure, isRealtime
5 from figure import Figure, isRealtime
6
6
7 class MomentsPlot(Figure):
7 class MomentsPlot(Figure):
8
8
9 isConfig = None
9 isConfig = None
10 __nsubplots = None
10 __nsubplots = None
11
11
12 WIDTHPROF = None
12 WIDTHPROF = None
13 HEIGHTPROF = None
13 HEIGHTPROF = None
14 PREFIX = 'prm'
14 PREFIX = 'prm'
15
15
16 def __init__(self):
16 def __init__(self):
17
17
18 self.isConfig = False
18 self.isConfig = False
19 self.__nsubplots = 1
19 self.__nsubplots = 1
20
20
21 self.WIDTH = 280
21 self.WIDTH = 280
22 self.HEIGHT = 250
22 self.HEIGHT = 250
23 self.WIDTHPROF = 120
23 self.WIDTHPROF = 120
24 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
25 self.counter_imagwr = 0
25 self.counter_imagwr = 0
26
26
27 self.PLOT_CODE = 1
27 self.PLOT_CODE = 1
28 self.FTP_WEI = None
28 self.FTP_WEI = None
29 self.EXP_CODE = None
29 self.EXP_CODE = None
30 self.SUB_EXP_CODE = None
30 self.SUB_EXP_CODE = None
31 self.PLOT_POS = None
31 self.PLOT_POS = None
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
37
37
38 return nrow, ncol
38 return nrow, ncol
39
39
40 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
40 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
41
41
42 self.__showprofile = showprofile
42 self.__showprofile = showprofile
43 self.nplots = nplots
43 self.nplots = nplots
44
44
45 ncolspan = 1
45 ncolspan = 1
46 colspan = 1
46 colspan = 1
47 if showprofile:
47 if showprofile:
48 ncolspan = 3
48 ncolspan = 3
49 colspan = 2
49 colspan = 2
50 self.__nsubplots = 2
50 self.__nsubplots = 2
51
51
52 self.createFigure(id = id,
52 self.createFigure(id = id,
53 wintitle = wintitle,
53 wintitle = wintitle,
54 widthplot = self.WIDTH + self.WIDTHPROF,
54 widthplot = self.WIDTH + self.WIDTHPROF,
55 heightplot = self.HEIGHT + self.HEIGHTPROF,
55 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 show=show)
56 show=show)
57
57
58 nrow, ncol = self.getSubplots()
58 nrow, ncol = self.getSubplots()
59
59
60 counter = 0
60 counter = 0
61 for y in range(nrow):
61 for y in range(nrow):
62 for x in range(ncol):
62 for x in range(ncol):
63
63
64 if counter >= self.nplots:
64 if counter >= self.nplots:
65 break
65 break
66
66
67 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
67 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68
68
69 if showprofile:
69 if showprofile:
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71
71
72 counter += 1
72 counter += 1
73
73
74 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
74 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
75 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
75 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
76 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
76 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
77 server=None, folder=None, username=None, password=None,
77 server=None, folder=None, username=None, password=None,
78 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
78 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
79
79
80 """
80 """
81
81
82 Input:
82 Input:
83 dataOut :
83 dataOut :
84 id :
84 id :
85 wintitle :
85 wintitle :
86 channelList :
86 channelList :
87 showProfile :
87 showProfile :
88 xmin : None,
88 xmin : None,
89 xmax : None,
89 xmax : None,
90 ymin : None,
90 ymin : None,
91 ymax : None,
91 ymax : None,
92 zmin : None,
92 zmin : None,
93 zmax : None
93 zmax : None
94 """
94 """
95
95
96 if dataOut.flagNoData:
96 if dataOut.flagNoData:
97 return None
97 return None
98
98
99 if realtime:
99 if realtime:
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 print 'Skipping this plot function'
101 print 'Skipping this plot function'
102 return
102 return
103
103
104 if channelList == None:
104 if channelList == None:
105 channelIndexList = dataOut.channelIndexList
105 channelIndexList = dataOut.channelIndexList
106 else:
106 else:
107 channelIndexList = []
107 channelIndexList = []
108 for channel in channelList:
108 for channel in channelList:
109 if channel not in dataOut.channelList:
109 if channel not in dataOut.channelList:
110 raise ValueError, "Channel %d is not in dataOut.channelList"
110 raise ValueError, "Channel %d is not in dataOut.channelList"
111 channelIndexList.append(dataOut.channelList.index(channel))
111 channelIndexList.append(dataOut.channelList.index(channel))
112
112
113 factor = dataOut.normFactor
113 factor = dataOut.normFactor
114 x = dataOut.abscissaList
114 x = dataOut.abscissaList
115 y = dataOut.heightList
115 y = dataOut.heightList
116
116
117 z = dataOut.data_pre[channelIndexList,:,:]/factor
117 z = dataOut.data_pre[channelIndexList,:,:]/factor
118 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
118 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
119 avg = numpy.average(z, axis=1)
119 avg = numpy.average(z, axis=1)
120 noise = dataOut.noise/factor
120 noise = dataOut.noise/factor
121
121
122 zdB = 10*numpy.log10(z)
122 zdB = 10*numpy.log10(z)
123 avgdB = 10*numpy.log10(avg)
123 avgdB = 10*numpy.log10(avg)
124 noisedB = 10*numpy.log10(noise)
124 noisedB = 10*numpy.log10(noise)
125
125
126 #thisDatetime = dataOut.datatime
126 #thisDatetime = dataOut.datatime
127 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
127 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
128 title = wintitle + " Parameters"
128 title = wintitle + " Parameters"
129 xlabel = "Velocity (m/s)"
129 xlabel = "Velocity (m/s)"
130 ylabel = "Range (Km)"
130 ylabel = "Range (Km)"
131
131
132 if not self.isConfig:
132 if not self.isConfig:
133
133
134 nplots = len(channelIndexList)
134 nplots = len(channelIndexList)
135
135
136 self.setup(id=id,
136 self.setup(id=id,
137 nplots=nplots,
137 nplots=nplots,
138 wintitle=wintitle,
138 wintitle=wintitle,
139 showprofile=showprofile,
139 showprofile=showprofile,
140 show=show)
140 show=show)
141
141
142 if xmin == None: xmin = numpy.nanmin(x)
142 if xmin == None: xmin = numpy.nanmin(x)
143 if xmax == None: xmax = numpy.nanmax(x)
143 if xmax == None: xmax = numpy.nanmax(x)
144 if ymin == None: ymin = numpy.nanmin(y)
144 if ymin == None: ymin = numpy.nanmin(y)
145 if ymax == None: ymax = numpy.nanmax(y)
145 if ymax == None: ymax = numpy.nanmax(y)
146 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
146 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
147 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
147 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
148
148
149 self.FTP_WEI = ftp_wei
149 self.FTP_WEI = ftp_wei
150 self.EXP_CODE = exp_code
150 self.EXP_CODE = exp_code
151 self.SUB_EXP_CODE = sub_exp_code
151 self.SUB_EXP_CODE = sub_exp_code
152 self.PLOT_POS = plot_pos
152 self.PLOT_POS = plot_pos
153
153
154 self.isConfig = True
154 self.isConfig = True
155
155
156 self.setWinTitle(title)
156 self.setWinTitle(title)
157
157
158 for i in range(self.nplots):
158 for i in range(self.nplots):
159 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
159 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
160 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
160 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
161 axes = self.axesList[i*self.__nsubplots]
161 axes = self.axesList[i*self.__nsubplots]
162 axes.pcolor(x, y, zdB[i,:,:],
162 axes.pcolor(x, y, zdB[i,:,:],
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
164 xlabel=xlabel, ylabel=ylabel, title=title,
164 xlabel=xlabel, ylabel=ylabel, title=title,
165 ticksize=9, cblabel='')
165 ticksize=9, cblabel='')
166 #Mean Line
166 #Mean Line
167 mean = dataOut.data_param[i, 1, :]
167 mean = dataOut.data_param[i, 1, :]
168 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
168 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
169
169
170 if self.__showprofile:
170 if self.__showprofile:
171 axes = self.axesList[i*self.__nsubplots +1]
171 axes = self.axesList[i*self.__nsubplots +1]
172 axes.pline(avgdB[i], y,
172 axes.pline(avgdB[i], y,
173 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
173 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
174 xlabel='dB', ylabel='', title='',
174 xlabel='dB', ylabel='', title='',
175 ytick_visible=False,
175 ytick_visible=False,
176 grid='x')
176 grid='x')
177
177
178 noiseline = numpy.repeat(noisedB[i], len(y))
178 noiseline = numpy.repeat(noisedB[i], len(y))
179 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
179 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
180
180
181 self.draw()
181 self.draw()
182
182
183 if figfile == None:
183 if figfile == None:
184 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
184 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
185 figfile = self.getFilename(name = str_datetime)
185 figfile = self.getFilename(name = str_datetime)
186
186
187 if figpath != '':
187 if figpath != '':
188 self.counter_imagwr += 1
188 self.counter_imagwr += 1
189 if (self.counter_imagwr>=wr_period):
189 if (self.counter_imagwr>=wr_period):
190 # store png plot to local folder
190 # store png plot to local folder
191 self.saveFigure(figpath, figfile)
191 self.saveFigure(figpath, figfile)
192 # store png plot to FTP server according to RT-Web format
192 # store png plot to FTP server according to RT-Web format
193 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
193 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
194 ftp_filename = os.path.join(figpath, name)
194 ftp_filename = os.path.join(figpath, name)
195 self.saveFigure(figpath, ftp_filename)
195 self.saveFigure(figpath, ftp_filename)
196 self.counter_imagwr = 0
196 self.counter_imagwr = 0
197
197
198 class SkyMapPlot(Figure):
198 class SkyMapPlot(Figure):
199
199
200 __isConfig = None
200 __isConfig = None
201 __nsubplots = None
201 __nsubplots = None
202
202
203 WIDTHPROF = None
203 WIDTHPROF = None
204 HEIGHTPROF = None
204 HEIGHTPROF = None
205 PREFIX = 'prm'
205 PREFIX = 'prm'
206
206
207 def __init__(self):
207 def __init__(self):
208
208
209 self.__isConfig = False
209 self.__isConfig = False
210 self.__nsubplots = 1
210 self.__nsubplots = 1
211
211
212 # self.WIDTH = 280
212 # self.WIDTH = 280
213 # self.HEIGHT = 250
213 # self.HEIGHT = 250
214 self.WIDTH = 600
214 self.WIDTH = 600
215 self.HEIGHT = 600
215 self.HEIGHT = 600
216 self.WIDTHPROF = 120
216 self.WIDTHPROF = 120
217 self.HEIGHTPROF = 0
217 self.HEIGHTPROF = 0
218 self.counter_imagwr = 0
218 self.counter_imagwr = 0
219
219
220 self.PLOT_CODE = 1
220 self.PLOT_CODE = 1
221 self.FTP_WEI = None
221 self.FTP_WEI = None
222 self.EXP_CODE = None
222 self.EXP_CODE = None
223 self.SUB_EXP_CODE = None
223 self.SUB_EXP_CODE = None
224 self.PLOT_POS = None
224 self.PLOT_POS = None
225
225
226 def getSubplots(self):
226 def getSubplots(self):
227
227
228 ncol = int(numpy.sqrt(self.nplots)+0.9)
228 ncol = int(numpy.sqrt(self.nplots)+0.9)
229 nrow = int(self.nplots*1./ncol + 0.9)
229 nrow = int(self.nplots*1./ncol + 0.9)
230
230
231 return nrow, ncol
231 return nrow, ncol
232
232
233 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
233 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
234
234
235 self.__showprofile = showprofile
235 self.__showprofile = showprofile
236 self.nplots = nplots
236 self.nplots = nplots
237
237
238 ncolspan = 1
238 ncolspan = 1
239 colspan = 1
239 colspan = 1
240
240
241 self.createFigure(id = id,
241 self.createFigure(id = id,
242 wintitle = wintitle,
242 wintitle = wintitle,
243 widthplot = self.WIDTH, #+ self.WIDTHPROF,
243 widthplot = self.WIDTH, #+ self.WIDTHPROF,
244 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
244 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
245 show=show)
245 show=show)
246
246
247 nrow, ncol = 1,1
247 nrow, ncol = 1,1
248 counter = 0
248 counter = 0
249 x = 0
249 x = 0
250 y = 0
250 y = 0
251 self.addAxes(1, 1, 0, 0, 1, 1, True)
251 self.addAxes(1, 1, 0, 0, 1, 1, True)
252
252
253 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
253 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
254 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
254 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
255 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
255 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
256 server=None, folder=None, username=None, password=None,
256 server=None, folder=None, username=None, password=None,
257 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
257 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
258
258
259 """
259 """
260
260
261 Input:
261 Input:
262 dataOut :
262 dataOut :
263 id :
263 id :
264 wintitle :
264 wintitle :
265 channelList :
265 channelList :
266 showProfile :
266 showProfile :
267 xmin : None,
267 xmin : None,
268 xmax : None,
268 xmax : None,
269 ymin : None,
269 ymin : None,
270 ymax : None,
270 ymax : None,
271 zmin : None,
271 zmin : None,
272 zmax : None
272 zmax : None
273 """
273 """
274
274
275 arrayParameters = dataOut.data_param
275 arrayParameters = dataOut.data_param
276 error = arrayParameters[:,-1]
276 error = arrayParameters[:,-1]
277 indValid = numpy.where(error == 0)[0]
277 indValid = numpy.where(error == 0)[0]
278 finalMeteor = arrayParameters[indValid,:]
278 finalMeteor = arrayParameters[indValid,:]
279 finalAzimuth = finalMeteor[:,4]
279 finalAzimuth = finalMeteor[:,4]
280 finalZenith = finalMeteor[:,5]
280 finalZenith = finalMeteor[:,5]
281
281
282 x = finalAzimuth*numpy.pi/180
282 x = finalAzimuth*numpy.pi/180
283 y = finalZenith
283 y = finalZenith
284
284
285
285
286 #thisDatetime = dataOut.datatime
286 #thisDatetime = dataOut.datatime
287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
288 title = wintitle + " Parameters"
288 title = wintitle + " Parameters"
289 xlabel = "Zonal Zenith Angle (deg) "
289 xlabel = "Zonal Zenith Angle (deg) "
290 ylabel = "Meridional Zenith Angle (deg)"
290 ylabel = "Meridional Zenith Angle (deg)"
291
291
292 if not self.__isConfig:
292 if not self.__isConfig:
293
293
294 nplots = 1
294 nplots = 1
295
295
296 self.setup(id=id,
296 self.setup(id=id,
297 nplots=nplots,
297 nplots=nplots,
298 wintitle=wintitle,
298 wintitle=wintitle,
299 showprofile=showprofile,
299 showprofile=showprofile,
300 show=show)
300 show=show)
301
301
302 self.FTP_WEI = ftp_wei
302 self.FTP_WEI = ftp_wei
303 self.EXP_CODE = exp_code
303 self.EXP_CODE = exp_code
304 self.SUB_EXP_CODE = sub_exp_code
304 self.SUB_EXP_CODE = sub_exp_code
305 self.PLOT_POS = plot_pos
305 self.PLOT_POS = plot_pos
306 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
306 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
307 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
307 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
308 self.__isConfig = True
308 self.__isConfig = True
309
309
310 self.setWinTitle(title)
310 self.setWinTitle(title)
311
311
312 i = 0
312 i = 0
313 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
313 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
314
314
315 axes = self.axesList[i*self.__nsubplots]
315 axes = self.axesList[i*self.__nsubplots]
316 nevents = axes.x_buffer.shape[0] + x.shape[0]
316 nevents = axes.x_buffer.shape[0] + x.shape[0]
317 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
317 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
318 axes.polar(x, y,
318 axes.polar(x, y,
319 title=title, xlabel=xlabel, ylabel=ylabel,
319 title=title, xlabel=xlabel, ylabel=ylabel,
320 ticksize=9, cblabel='')
320 ticksize=9, cblabel='')
321
321
322 self.draw()
322 self.draw()
323
323
324 if save:
324 if save:
325
325
326 self.counter_imagwr += 1
326 self.counter_imagwr += 1
327 if (self.counter_imagwr==wr_period):
327 if (self.counter_imagwr==wr_period):
328
328
329 if figfile == None:
329 if figfile == None:
330 figfile = self.getFilename(name = self.name)
330 figfile = self.getFilename(name = self.name)
331 self.saveFigure(figpath, figfile)
331 self.saveFigure(figpath, figfile)
332
332
333 if ftp:
333 if ftp:
334 #provisionalmente envia archivos en el formato de la web en tiempo real
334 #provisionalmente envia archivos en el formato de la web en tiempo real
335 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
335 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
336 path = '%s%03d' %(self.PREFIX, self.id)
336 path = '%s%03d' %(self.PREFIX, self.id)
337 ftp_file = os.path.join(path,'ftp','%s.png'%name)
337 ftp_file = os.path.join(path,'ftp','%s.png'%name)
338 self.saveFigure(figpath, ftp_file)
338 self.saveFigure(figpath, ftp_file)
339 ftp_filename = os.path.join(figpath,ftp_file)
339 ftp_filename = os.path.join(figpath,ftp_file)
340
340
341
341
342 try:
342 try:
343 self.sendByFTP(ftp_filename, server, folder, username, password)
343 self.sendByFTP(ftp_filename, server, folder, username, password)
344 except:
344 except:
345 self.counter_imagwr = 0
345 self.counter_imagwr = 0
346 raise ValueError, 'Error FTP'
346 raise ValueError, 'Error FTP'
347
347
348 self.counter_imagwr = 0
348 self.counter_imagwr = 0
349
349
350
350
351 class WindProfilerPlot(Figure):
351 class WindProfilerPlot(Figure):
352
352
353 __isConfig = None
353 __isConfig = None
354 __nsubplots = None
354 __nsubplots = None
355
355
356 WIDTHPROF = None
356 WIDTHPROF = None
357 HEIGHTPROF = None
357 HEIGHTPROF = None
358 PREFIX = 'wind'
358 PREFIX = 'wind'
359
359
360 def __init__(self):
360 def __init__(self):
361
361
362 self.timerange = 2*60*60
362 self.timerange = 2*60*60
363 self.__isConfig = False
363 self.__isConfig = False
364 self.__nsubplots = 1
364 self.__nsubplots = 1
365
365
366 self.WIDTH = 800
366 self.WIDTH = 800
367 self.HEIGHT = 150
367 self.HEIGHT = 150
368 self.WIDTHPROF = 120
368 self.WIDTHPROF = 120
369 self.HEIGHTPROF = 0
369 self.HEIGHTPROF = 0
370 self.counter_imagwr = 0
370 self.counter_imagwr = 0
371
371
372 self.PLOT_CODE = 0
372 self.PLOT_CODE = 0
373 self.FTP_WEI = None
373 self.FTP_WEI = None
374 self.EXP_CODE = None
374 self.EXP_CODE = None
375 self.SUB_EXP_CODE = None
375 self.SUB_EXP_CODE = None
376 self.PLOT_POS = None
376 self.PLOT_POS = None
377 self.tmin = None
377 self.tmin = None
378 self.tmax = None
378 self.tmax = None
379
379
380 self.xmin = None
380 self.xmin = None
381 self.xmax = None
381 self.xmax = None
382
382
383 self.figfile = None
383 self.figfile = None
384
384
385 def getSubplots(self):
385 def getSubplots(self):
386
386
387 ncol = 1
387 ncol = 1
388 nrow = self.nplots
388 nrow = self.nplots
389
389
390 return nrow, ncol
390 return nrow, ncol
391
391
392 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
392 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
393
393
394 self.__showprofile = showprofile
394 self.__showprofile = showprofile
395 self.nplots = nplots
395 self.nplots = nplots
396
396
397 ncolspan = 1
397 ncolspan = 1
398 colspan = 1
398 colspan = 1
399
399
400 self.createFigure(id = id,
400 self.createFigure(id = id,
401 wintitle = wintitle,
401 wintitle = wintitle,
402 widthplot = self.WIDTH + self.WIDTHPROF,
402 widthplot = self.WIDTH + self.WIDTHPROF,
403 heightplot = self.HEIGHT + self.HEIGHTPROF,
403 heightplot = self.HEIGHT + self.HEIGHTPROF,
404 show=show)
404 show=show)
405
405
406 nrow, ncol = self.getSubplots()
406 nrow, ncol = self.getSubplots()
407
407
408 counter = 0
408 counter = 0
409 for y in range(nrow):
409 for y in range(nrow):
410 if counter >= self.nplots:
410 if counter >= self.nplots:
411 break
411 break
412
412
413 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
413 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
414 counter += 1
414 counter += 1
415
415
416 def run(self, dataOut, id, wintitle="", channelList=None,
416 def run(self, dataOut, id, wintitle="", channelList=None,
417 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
417 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
418 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
418 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
419 timerange=None, SNRthresh = None,
419 timerange=None, SNRthresh = None,
420 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
420 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
421 server=None, folder=None, username=None, password=None,
421 server=None, folder=None, username=None, password=None,
422 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
422 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
423 """
423 """
424
424
425 Input:
425 Input:
426 dataOut :
426 dataOut :
427 id :
427 id :
428 wintitle :
428 wintitle :
429 channelList :
429 channelList :
430 showProfile :
430 showProfile :
431 xmin : None,
431 xmin : None,
432 xmax : None,
432 xmax : None,
433 ymin : None,
433 ymin : None,
434 ymax : None,
434 ymax : None,
435 zmin : None,
435 zmin : None,
436 zmax : None
436 zmax : None
437 """
437 """
438
438
439 if channelList == None:
439 if channelList == None:
440 channelIndexList = dataOut.channelIndexList
440 channelIndexList = dataOut.channelIndexList
441 else:
441 else:
442 channelIndexList = []
442 channelIndexList = []
443 for channel in channelList:
443 for channel in channelList:
444 if channel not in dataOut.channelList:
444 if channel not in dataOut.channelList:
445 raise ValueError, "Channel %d is not in dataOut.channelList"
445 raise ValueError, "Channel %d is not in dataOut.channelList"
446 channelIndexList.append(dataOut.channelList.index(channel))
446 channelIndexList.append(dataOut.channelList.index(channel))
447
447
448 if timerange != None:
448 if timerange != None:
449 self.timerange = timerange
449 self.timerange = timerange
450
450
451 tmin = None
451 tmin = None
452 tmax = None
452 tmax = None
453
453
454 x = dataOut.getTimeRange1()
454 x = dataOut.getTimeRange1()
455 # y = dataOut.heightList
455 # y = dataOut.heightList
456 y = dataOut.heightList
456 y = dataOut.heightList
457
457
458 z = dataOut.data_output.copy()
458 z = dataOut.data_output.copy()
459 nplots = z.shape[0] #Number of wind dimensions estimated
459 nplots = z.shape[0] #Number of wind dimensions estimated
460 nplotsw = nplots
460 nplotsw = nplots
461
461
462 #If there is a SNR function defined
462 #If there is a SNR function defined
463 if dataOut.data_SNR != None:
463 if dataOut.data_SNR != None:
464 nplots += 1
464 nplots += 1
465 SNR = dataOut.data_SNR
465 SNR = dataOut.data_SNR
466 SNRavg = numpy.average(SNR, axis=0)
466 SNRavg = numpy.average(SNR, axis=0)
467
467
468 SNRdB = 10*numpy.log10(SNR)
468 SNRdB = 10*numpy.log10(SNR)
469 SNRavgdB = 10*numpy.log10(SNRavg)
469 SNRavgdB = 10*numpy.log10(SNRavg)
470
470
471 if SNRthresh == None: SNRthresh = -5.0
471 if SNRthresh == None: SNRthresh = -5.0
472 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
472 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
473
473
474 for i in range(nplotsw):
474 for i in range(nplotsw):
475 z[i,ind] = numpy.nan
475 z[i,ind] = numpy.nan
476
476
477
477
478 showprofile = False
478 showprofile = False
479 # thisDatetime = dataOut.datatime
479 # thisDatetime = dataOut.datatime
480 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
480 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
481 title = wintitle + "Wind"
481 title = wintitle + "Wind"
482 xlabel = ""
482 xlabel = ""
483 ylabel = "Range (Km)"
483 ylabel = "Range (Km)"
484
484
485 if not self.__isConfig:
485 if not self.__isConfig:
486
486
487 self.setup(id=id,
487 self.setup(id=id,
488 nplots=nplots,
488 nplots=nplots,
489 wintitle=wintitle,
489 wintitle=wintitle,
490 showprofile=showprofile,
490 showprofile=showprofile,
491 show=show)
491 show=show)
492
492
493 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
493 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
494
494
495 if ymin == None: ymin = numpy.nanmin(y)
495 if ymin == None: ymin = numpy.nanmin(y)
496 if ymax == None: ymax = numpy.nanmax(y)
496 if ymax == None: ymax = numpy.nanmax(y)
497
497
498 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
498 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
499 #if numpy.isnan(zmax): zmax = 50
499 #if numpy.isnan(zmax): zmax = 50
500 if zmin == None: zmin = -zmax
500 if zmin == None: zmin = -zmax
501
501
502 if nplotsw == 3:
502 if nplotsw == 3:
503 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
503 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
504 if zmin_ver == None: zmin_ver = -zmax_ver
504 if zmin_ver == None: zmin_ver = -zmax_ver
505
505
506 if dataOut.data_SNR != None:
506 if dataOut.data_SNR != None:
507 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
507 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
508 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
508 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
509
509
510 self.FTP_WEI = ftp_wei
510 self.FTP_WEI = ftp_wei
511 self.EXP_CODE = exp_code
511 self.EXP_CODE = exp_code
512 self.SUB_EXP_CODE = sub_exp_code
512 self.SUB_EXP_CODE = sub_exp_code
513 self.PLOT_POS = plot_pos
513 self.PLOT_POS = plot_pos
514
514
515 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
515 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
516 self.__isConfig = True
516 self.__isConfig = True
517
517
518
518
519 self.setWinTitle(title)
519 self.setWinTitle(title)
520
520
521 if ((self.xmax - x[1]) < (x[1]-x[0])):
521 if ((self.xmax - x[1]) < (x[1]-x[0])):
522 x[1] = self.xmax
522 x[1] = self.xmax
523
523
524 strWind = ['Zonal', 'Meridional', 'Vertical']
524 strWind = ['Zonal', 'Meridional', 'Vertical']
525 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
525 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
526 zmaxVector = [zmax, zmax, zmax_ver]
526 zmaxVector = [zmax, zmax, zmax_ver]
527 zminVector = [zmin, zmin, zmin_ver]
527 zminVector = [zmin, zmin, zmin_ver]
528 windFactor = [1,1,100]
528 windFactor = [1,1,100]
529
529
530 for i in range(nplotsw):
530 for i in range(nplotsw):
531
531
532 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
532 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
533 axes = self.axesList[i*self.__nsubplots]
533 axes = self.axesList[i*self.__nsubplots]
534
534
535 z1 = z[i,:].reshape((1,-1))*windFactor[i]
535 z1 = z[i,:].reshape((1,-1))*windFactor[i]
536
536
537 axes.pcolorbuffer(x, y, z1,
537 axes.pcolorbuffer(x, y, z1,
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
541
541
542 if dataOut.data_SNR != None:
542 if dataOut.data_SNR != None:
543 i += 1
543 i += 1
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 axes = self.axesList[i*self.__nsubplots]
545 axes = self.axesList[i*self.__nsubplots]
546
546
547 SNRavgdB = SNRavgdB.reshape((1,-1))
547 SNRavgdB = SNRavgdB.reshape((1,-1))
548
548
549 axes.pcolorbuffer(x, y, SNRavgdB,
549 axes.pcolorbuffer(x, y, SNRavgdB,
550 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
550 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
551 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
551 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
552 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
552 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
553
553
554 self.draw()
554 self.draw()
555
555
556 if self.figfile == None:
556 if self.figfile == None:
557 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
557 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
558 self.figfile = self.getFilename(name = str_datetime)
558 self.figfile = self.getFilename(name = str_datetime)
559
559
560 if figpath != '':
560 if figpath != '':
561
561
562 self.counter_imagwr += 1
562 self.counter_imagwr += 1
563 if (self.counter_imagwr>=wr_period):
563 if (self.counter_imagwr>=wr_period):
564 # store png plot to local folder
564 # store png plot to local folder
565 self.saveFigure(figpath, self.figfile)
565 self.saveFigure(figpath, self.figfile)
566 # store png plot to FTP server according to RT-Web format
566 # store png plot to FTP server according to RT-Web format
567 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
567 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
568 ftp_filename = os.path.join(figpath, name)
568 ftp_filename = os.path.join(figpath, name)
569 self.saveFigure(figpath, ftp_filename)
569 self.saveFigure(figpath, ftp_filename)
570
570
571 self.counter_imagwr = 0
571 self.counter_imagwr = 0
572
572
573 if x[1] >= self.axesList[0].xmax:
573 if x[1] >= self.axesList[0].xmax:
574 self.counter_imagwr = wr_period
574 self.counter_imagwr = wr_period
575 self.__isConfig = False
575 self.__isConfig = False
576 self.figfile = None
576 self.figfile = None
577
577
578
578
579 class ParametersPlot(Figure):
579 class ParametersPlot(Figure):
580
580
581 __isConfig = None
581 __isConfig = None
582 __nsubplots = None
582 __nsubplots = None
583
583
584 WIDTHPROF = None
584 WIDTHPROF = None
585 HEIGHTPROF = None
585 HEIGHTPROF = None
586 PREFIX = 'prm'
586 PREFIX = 'prm'
587
587
588 def __init__(self):
588 def __init__(self):
589
589
590 self.timerange = 2*60*60
590 self.timerange = 2*60*60
591 self.__isConfig = False
591 self.__isConfig = False
592 self.__nsubplots = 1
592 self.__nsubplots = 1
593
593
594 self.WIDTH = 800
594 self.WIDTH = 800
595 self.HEIGHT = 150
595 self.HEIGHT = 150
596 self.WIDTHPROF = 120
596 self.WIDTHPROF = 120
597 self.HEIGHTPROF = 0
597 self.HEIGHTPROF = 0
598 self.counter_imagwr = 0
598 self.counter_imagwr = 0
599
599
600 self.PLOT_CODE = 0
600 self.PLOT_CODE = 0
601 self.FTP_WEI = None
601 self.FTP_WEI = None
602 self.EXP_CODE = None
602 self.EXP_CODE = None
603 self.SUB_EXP_CODE = None
603 self.SUB_EXP_CODE = None
604 self.PLOT_POS = None
604 self.PLOT_POS = None
605 self.tmin = None
605 self.tmin = None
606 self.tmax = None
606 self.tmax = None
607
607
608 self.xmin = None
608 self.xmin = None
609 self.xmax = None
609 self.xmax = None
610
610
611 self.figfile = None
611 self.figfile = None
612
612
613 def getSubplots(self):
613 def getSubplots(self):
614
614
615 ncol = 1
615 ncol = 1
616 nrow = self.nplots
616 nrow = self.nplots
617
617
618 return nrow, ncol
618 return nrow, ncol
619
619
620 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
620 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
621
621
622 self.__showprofile = showprofile
622 self.__showprofile = showprofile
623 self.nplots = nplots
623 self.nplots = nplots
624
624
625 ncolspan = 1
625 ncolspan = 1
626 colspan = 1
626 colspan = 1
627
627
628 self.createFigure(id = id,
628 self.createFigure(id = id,
629 wintitle = wintitle,
629 wintitle = wintitle,
630 widthplot = self.WIDTH + self.WIDTHPROF,
630 widthplot = self.WIDTH + self.WIDTHPROF,
631 heightplot = self.HEIGHT + self.HEIGHTPROF,
631 heightplot = self.HEIGHT + self.HEIGHTPROF,
632 show=show)
632 show=show)
633
633
634 nrow, ncol = self.getSubplots()
634 nrow, ncol = self.getSubplots()
635
635
636 counter = 0
636 counter = 0
637 for y in range(nrow):
637 for y in range(nrow):
638 for x in range(ncol):
638 for x in range(ncol):
639
639
640 if counter >= self.nplots:
640 if counter >= self.nplots:
641 break
641 break
642
642
643 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
643 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
644
644
645 if showprofile:
645 if showprofile:
646 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
646 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
647
647
648 counter += 1
648 counter += 1
649
649
650 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
650 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
651 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
651 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
652 parameterIndex = None, onlyPositive = False,
652 parameterIndex = None, onlyPositive = False,
653 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None,
653 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None,
654
654
655 zlabel = "", parameterName = "", parameterObject = "data_param",
655 zlabel = "", parameterName = "", parameterObject = "data_param",
656 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
656 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
657 server=None, folder=None, username=None, password=None,
657 server=None, folder=None, username=None, password=None,
658 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
658 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
659
659
660 """
660 """
661
661
662 Input:
662 Input:
663 dataOut :
663 dataOut :
664 id :
664 id :
665 wintitle :
665 wintitle :
666 channelList :
666 channelList :
667 showProfile :
667 showProfile :
668 xmin : None,
668 xmin : None,
669 xmax : None,
669 xmax : None,
670 ymin : None,
670 ymin : None,
671 ymax : None,
671 ymax : None,
672 zmin : None,
672 zmin : None,
673 zmax : None
673 zmax : None
674 """
674 """
675
675
676 data_param = getattr(dataOut, parameterObject)
676 data_param = getattr(dataOut, parameterObject)
677
677
678 if channelList == None:
678 if channelList == None:
679 channelIndexList = numpy.arange(data_param.shape[0])
679 channelIndexList = numpy.arange(data_param.shape[0])
680 else:
680 else:
681 channelIndexList = numpy.array(channelIndexList)
681 channelIndexList = numpy.array(channelList)
682
682
683 nchan = len(channelIndexList) #Number of channels being plotted
683 nchan = len(channelIndexList) #Number of channels being plotted
684
684
685 if timerange != None:
685 if timerange != None:
686 self.timerange = timerange
686 self.timerange = timerange
687
687
688 #tmin = None
688 #tmin = None
689 #tmax = None
689 #tmax = None
690 if parameterIndex == None:
690 if parameterIndex == None:
691 parameterIndex = 1
691 parameterIndex = 1
692 x = dataOut.getTimeRange1()
692 x = dataOut.getTimeRange1()
693 y = dataOut.heightList
693 y = dataOut.heightList
694 z = data_param[channelIndexList,parameterIndex,:].copy()
694 z = data_param[channelIndexList,parameterIndex,:].copy()
695
695
696 zRange = dataOut.abscissaList
696 zRange = dataOut.abscissaList
697 nplots = z.shape[0] #Number of wind dimensions estimated
697 nplots = z.shape[0] #Number of wind dimensions estimated
698 # thisDatetime = dataOut.datatime
698 # thisDatetime = dataOut.datatime
699
699
700 if dataOut.data_SNR != None:
700 if dataOut.data_SNR != None:
701 SNRarray = dataOut.data_SNR
701 SNRarray = dataOut.data_SNR[channelIndexList,:]
702 SNRdB = 10*numpy.log10(SNRarray)
702 SNRdB = 10*numpy.log10(SNRarray)
703 # SNRavgdB = 10*numpy.log10(SNRavg)
703 # SNRavgdB = 10*numpy.log10(SNRavg)
704 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
704 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
705 z[ind] = numpy.nan
705 z[ind] = numpy.nan
706
706
707 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
707 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
708 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
708 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
709 xlabel = ""
709 xlabel = ""
710 ylabel = "Range (Km)"
710 ylabel = "Range (Km)"
711
711
712 if SNR: nplots = 2*nplots
712 if SNR: nplots = 2*nplots
713
713
714 if onlyPositive:
714 if onlyPositive:
715 colormap = "jet"
715 colormap = "jet"
716 zmin = 0
716 zmin = 0
717 else: colormap = "RdBu_r"
717 else: colormap = "RdBu_r"
718
718
719 if not self.__isConfig:
719 if not self.__isConfig:
720
720
721 self.setup(id=id,
721 self.setup(id=id,
722 nplots=nplots,
722 nplots=nplots,
723 wintitle=wintitle,
723 wintitle=wintitle,
724 showprofile=showprofile,
724 showprofile=showprofile,
725 show=show)
725 show=show)
726
726
727 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
727 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
728
728
729 if ymin == None: ymin = numpy.nanmin(y)
729 if ymin == None: ymin = numpy.nanmin(y)
730 if ymax == None: ymax = numpy.nanmax(y)
730 if ymax == None: ymax = numpy.nanmax(y)
731 if zmin == None: zmin = numpy.nanmin(zRange)
731 if zmin == None: zmin = numpy.nanmin(zRange)
732 if zmax == None: zmax = numpy.nanmax(zRange)
732 if zmax == None: zmax = numpy.nanmax(zRange)
733
733
734 if SNR != None:
734 if SNR != None:
735 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
735 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
736 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
736 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
737
737
738 self.FTP_WEI = ftp_wei
738 self.FTP_WEI = ftp_wei
739 self.EXP_CODE = exp_code
739 self.EXP_CODE = exp_code
740 self.SUB_EXP_CODE = sub_exp_code
740 self.SUB_EXP_CODE = sub_exp_code
741 self.PLOT_POS = plot_pos
741 self.PLOT_POS = plot_pos
742
742
743 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
743 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
744 self.__isConfig = True
744 self.__isConfig = True
745 self.figfile = figfile
745 self.figfile = figfile
746
746
747 self.setWinTitle(title)
747 self.setWinTitle(title)
748
748
749 if ((self.xmax - x[1]) < (x[1]-x[0])):
749 if ((self.xmax - x[1]) < (x[1]-x[0])):
750 x[1] = self.xmax
750 x[1] = self.xmax
751
751
752 for i in range(nchan):
752 for i in range(nchan):
753 if SNR: j = 2*i
753 if SNR: j = 2*i
754 else: j = i
754 else: j = i
755
755
756 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
756 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
757
757
758 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
758 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
759 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
759 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
760 axes = self.axesList[j*self.__nsubplots]
760 axes = self.axesList[j*self.__nsubplots]
761 z1 = z[i,:].reshape((1,-1))
761 z1 = z[i,:].reshape((1,-1))
762 axes.pcolorbuffer(x, y, z1,
762 axes.pcolorbuffer(x, y, z1,
763 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
763 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
764 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
764 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
765 ticksize=9, cblabel=zlabel, cbsize="1%")
765 ticksize=9, cblabel=zlabel, cbsize="1%")
766
766
767 if SNR:
767 if SNR:
768 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
768 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
769 axes = self.axesList[(j + 1)*self.__nsubplots]
769 axes = self.axesList[(j + 1)*self.__nsubplots]
770 z1 = SNRdB[i,:].reshape((1,-1))
770 z1 = SNRdB[i,:].reshape((1,-1))
771 axes.pcolorbuffer(x, y, z1,
771 axes.pcolorbuffer(x, y, z1,
772 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
772 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
773 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
773 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
774 ticksize=9, cblabel=zlabel, cbsize="1%")
774 ticksize=9, cblabel=zlabel, cbsize="1%")
775
775
776
776
777
777
778 self.draw()
778 self.draw()
779
779
780 if self.figfile == None:
780 if self.figfile == None:
781 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
781 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
782 self.figfile = self.getFilename(name = str_datetime)
782 self.figfile = self.getFilename(name = str_datetime)
783
783
784 if figpath != '':
784 if figpath != '':
785
785
786 self.counter_imagwr += 1
786 self.counter_imagwr += 1
787 if (self.counter_imagwr>=wr_period):
787 if (self.counter_imagwr>=wr_period):
788 # store png plot to local folder
788 # store png plot to local folder
789 self.saveFigure(figpath, self.figfile)
789 self.saveFigure(figpath, self.figfile)
790 # store png plot to FTP server according to RT-Web format
790 # store png plot to FTP server according to RT-Web format
791 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
791 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
792 ftp_filename = os.path.join(figpath, name)
792 ftp_filename = os.path.join(figpath, name)
793 self.saveFigure(figpath, ftp_filename)
793 self.saveFigure(figpath, ftp_filename)
794
794
795 self.counter_imagwr = 0
795 self.counter_imagwr = 0
796
796
797 if x[1] >= self.axesList[0].xmax:
797 if x[1] >= self.axesList[0].xmax:
798 self.counter_imagwr = wr_period
798 self.counter_imagwr = wr_period
799 self.__isConfig = False
799 self.__isConfig = False
800 self.figfile = None
800 self.figfile = None
801
801
802
802
803 class SpectralFittingPlot(Figure):
803 class SpectralFittingPlot(Figure):
804
804
805 __isConfig = None
805 __isConfig = None
806 __nsubplots = None
806 __nsubplots = None
807
807
808 WIDTHPROF = None
808 WIDTHPROF = None
809 HEIGHTPROF = None
809 HEIGHTPROF = None
810 PREFIX = 'prm'
810 PREFIX = 'prm'
811
811
812
812
813 N = None
813 N = None
814 ippSeconds = None
814 ippSeconds = None
815
815
816 def __init__(self):
816 def __init__(self):
817 self.__isConfig = False
817 self.__isConfig = False
818 self.__nsubplots = 1
818 self.__nsubplots = 1
819
819
820 self.WIDTH = 450
820 self.WIDTH = 450
821 self.HEIGHT = 250
821 self.HEIGHT = 250
822 self.WIDTHPROF = 0
822 self.WIDTHPROF = 0
823 self.HEIGHTPROF = 0
823 self.HEIGHTPROF = 0
824
824
825 def getSubplots(self):
825 def getSubplots(self):
826
826
827 ncol = int(numpy.sqrt(self.nplots)+0.9)
827 ncol = int(numpy.sqrt(self.nplots)+0.9)
828 nrow = int(self.nplots*1./ncol + 0.9)
828 nrow = int(self.nplots*1./ncol + 0.9)
829
829
830 return nrow, ncol
830 return nrow, ncol
831
831
832 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
832 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
833
833
834 showprofile = False
834 showprofile = False
835 self.__showprofile = showprofile
835 self.__showprofile = showprofile
836 self.nplots = nplots
836 self.nplots = nplots
837
837
838 ncolspan = 5
838 ncolspan = 5
839 colspan = 4
839 colspan = 4
840 if showprofile:
840 if showprofile:
841 ncolspan = 5
841 ncolspan = 5
842 colspan = 4
842 colspan = 4
843 self.__nsubplots = 2
843 self.__nsubplots = 2
844
844
845 self.createFigure(id = id,
845 self.createFigure(id = id,
846 wintitle = wintitle,
846 wintitle = wintitle,
847 widthplot = self.WIDTH + self.WIDTHPROF,
847 widthplot = self.WIDTH + self.WIDTHPROF,
848 heightplot = self.HEIGHT + self.HEIGHTPROF,
848 heightplot = self.HEIGHT + self.HEIGHTPROF,
849 show=show)
849 show=show)
850
850
851 nrow, ncol = self.getSubplots()
851 nrow, ncol = self.getSubplots()
852
852
853 counter = 0
853 counter = 0
854 for y in range(nrow):
854 for y in range(nrow):
855 for x in range(ncol):
855 for x in range(ncol):
856
856
857 if counter >= self.nplots:
857 if counter >= self.nplots:
858 break
858 break
859
859
860 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
860 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
861
861
862 if showprofile:
862 if showprofile:
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
864
864
865 counter += 1
865 counter += 1
866
866
867 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
867 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
868 xmin=None, xmax=None, ymin=None, ymax=None,
868 xmin=None, xmax=None, ymin=None, ymax=None,
869 save=False, figpath='./', figfile=None, show=True):
869 save=False, figpath='./', figfile=None, show=True):
870
870
871 """
871 """
872
872
873 Input:
873 Input:
874 dataOut :
874 dataOut :
875 id :
875 id :
876 wintitle :
876 wintitle :
877 channelList :
877 channelList :
878 showProfile :
878 showProfile :
879 xmin : None,
879 xmin : None,
880 xmax : None,
880 xmax : None,
881 zmin : None,
881 zmin : None,
882 zmax : None
882 zmax : None
883 """
883 """
884
884
885 if cutHeight==None:
885 if cutHeight==None:
886 h=270
886 h=270
887 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
887 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
888 cutHeight = dataOut.heightList[heightindex]
888 cutHeight = dataOut.heightList[heightindex]
889
889
890 factor = dataOut.normFactor
890 factor = dataOut.normFactor
891 x = dataOut.abscissaList[:-1]
891 x = dataOut.abscissaList[:-1]
892 #y = dataOut.getHeiRange()
892 #y = dataOut.getHeiRange()
893
893
894 z = dataOut.data_pre[:,:,heightindex]/factor
894 z = dataOut.data_pre[:,:,heightindex]/factor
895 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
895 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
896 avg = numpy.average(z, axis=1)
896 avg = numpy.average(z, axis=1)
897 listChannels = z.shape[0]
897 listChannels = z.shape[0]
898
898
899 #Reconstruct Function
899 #Reconstruct Function
900 if fit==True:
900 if fit==True:
901 groupArray = dataOut.groupList
901 groupArray = dataOut.groupList
902 listChannels = groupArray.reshape((groupArray.size))
902 listChannels = groupArray.reshape((groupArray.size))
903 listChannels.sort()
903 listChannels.sort()
904 spcFitLine = numpy.zeros(z.shape)
904 spcFitLine = numpy.zeros(z.shape)
905 constants = dataOut.constants
905 constants = dataOut.constants
906
906
907 nGroups = groupArray.shape[0]
907 nGroups = groupArray.shape[0]
908 nChannels = groupArray.shape[1]
908 nChannels = groupArray.shape[1]
909 nProfiles = z.shape[1]
909 nProfiles = z.shape[1]
910
910
911 for f in range(nGroups):
911 for f in range(nGroups):
912 groupChann = groupArray[f,:]
912 groupChann = groupArray[f,:]
913 p = dataOut.data_param[f,:,heightindex]
913 p = dataOut.data_param[f,:,heightindex]
914 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
914 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
915 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
915 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
916 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
916 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
917 spcFitLine[groupChann,:] = fitLineAux
917 spcFitLine[groupChann,:] = fitLineAux
918 # spcFitLine = spcFitLine/factor
918 # spcFitLine = spcFitLine/factor
919
919
920 z = z[listChannels,:]
920 z = z[listChannels,:]
921 spcFitLine = spcFitLine[listChannels,:]
921 spcFitLine = spcFitLine[listChannels,:]
922 spcFitLinedB = 10*numpy.log10(spcFitLine)
922 spcFitLinedB = 10*numpy.log10(spcFitLine)
923
923
924 zdB = 10*numpy.log10(z)
924 zdB = 10*numpy.log10(z)
925 #thisDatetime = dataOut.datatime
925 #thisDatetime = dataOut.datatime
926 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
926 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
927 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
927 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
928 xlabel = "Velocity (m/s)"
928 xlabel = "Velocity (m/s)"
929 ylabel = "Spectrum"
929 ylabel = "Spectrum"
930
930
931 if not self.__isConfig:
931 if not self.__isConfig:
932
932
933 nplots = listChannels.size
933 nplots = listChannels.size
934
934
935 self.setup(id=id,
935 self.setup(id=id,
936 nplots=nplots,
936 nplots=nplots,
937 wintitle=wintitle,
937 wintitle=wintitle,
938 showprofile=showprofile,
938 showprofile=showprofile,
939 show=show)
939 show=show)
940
940
941 if xmin == None: xmin = numpy.nanmin(x)
941 if xmin == None: xmin = numpy.nanmin(x)
942 if xmax == None: xmax = numpy.nanmax(x)
942 if xmax == None: xmax = numpy.nanmax(x)
943 if ymin == None: ymin = numpy.nanmin(zdB)
943 if ymin == None: ymin = numpy.nanmin(zdB)
944 if ymax == None: ymax = numpy.nanmax(zdB)+2
944 if ymax == None: ymax = numpy.nanmax(zdB)+2
945
945
946 self.__isConfig = True
946 self.__isConfig = True
947
947
948 self.setWinTitle(title)
948 self.setWinTitle(title)
949 for i in range(self.nplots):
949 for i in range(self.nplots):
950 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
950 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
951 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
951 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
952 axes = self.axesList[i*self.__nsubplots]
952 axes = self.axesList[i*self.__nsubplots]
953 if fit == False:
953 if fit == False:
954 axes.pline(x, zdB[i,:],
954 axes.pline(x, zdB[i,:],
955 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
955 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
956 xlabel=xlabel, ylabel=ylabel, title=title
956 xlabel=xlabel, ylabel=ylabel, title=title
957 )
957 )
958 if fit == True:
958 if fit == True:
959 fitline=spcFitLinedB[i,:]
959 fitline=spcFitLinedB[i,:]
960 y=numpy.vstack([zdB[i,:],fitline] )
960 y=numpy.vstack([zdB[i,:],fitline] )
961 legendlabels=['Data','Fitting']
961 legendlabels=['Data','Fitting']
962 axes.pmultilineyaxis(x, y,
962 axes.pmultilineyaxis(x, y,
963 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
963 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
964 xlabel=xlabel, ylabel=ylabel, title=title,
964 xlabel=xlabel, ylabel=ylabel, title=title,
965 legendlabels=legendlabels, marker=None,
965 legendlabels=legendlabels, marker=None,
966 linestyle='solid', grid='both')
966 linestyle='solid', grid='both')
967
967
968 self.draw()
968 self.draw()
969
969
970 if save:
970 if save:
971 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
971 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
972 if figfile == None:
972 if figfile == None:
973 figfile = self.getFilename(name = date)
973 figfile = self.getFilename(name = date)
974
974
975 self.saveFigure(figpath, figfile)
975 self.saveFigure(figpath, figfile)
976
976
977
977
978 class EWDriftsPlot(Figure):
978 class EWDriftsPlot(Figure):
979
979
980 __isConfig = None
980 __isConfig = None
981 __nsubplots = None
981 __nsubplots = None
982
982
983 WIDTHPROF = None
983 WIDTHPROF = None
984 HEIGHTPROF = None
984 HEIGHTPROF = None
985 PREFIX = 'drift'
985 PREFIX = 'drift'
986
986
987 def __init__(self):
987 def __init__(self):
988
988
989 self.timerange = 2*60*60
989 self.timerange = 2*60*60
990 self.isConfig = False
990 self.isConfig = False
991 self.__nsubplots = 1
991 self.__nsubplots = 1
992
992
993 self.WIDTH = 800
993 self.WIDTH = 800
994 self.HEIGHT = 150
994 self.HEIGHT = 150
995 self.WIDTHPROF = 120
995 self.WIDTHPROF = 120
996 self.HEIGHTPROF = 0
996 self.HEIGHTPROF = 0
997 self.counter_imagwr = 0
997 self.counter_imagwr = 0
998
998
999 self.PLOT_CODE = 0
999 self.PLOT_CODE = 0
1000 self.FTP_WEI = None
1000 self.FTP_WEI = None
1001 self.EXP_CODE = None
1001 self.EXP_CODE = None
1002 self.SUB_EXP_CODE = None
1002 self.SUB_EXP_CODE = None
1003 self.PLOT_POS = None
1003 self.PLOT_POS = None
1004 self.tmin = None
1004 self.tmin = None
1005 self.tmax = None
1005 self.tmax = None
1006
1006
1007 self.xmin = None
1007 self.xmin = None
1008 self.xmax = None
1008 self.xmax = None
1009
1009
1010 self.figfile = None
1010 self.figfile = None
1011
1011
1012 def getSubplots(self):
1012 def getSubplots(self):
1013
1013
1014 ncol = 1
1014 ncol = 1
1015 nrow = self.nplots
1015 nrow = self.nplots
1016
1016
1017 return nrow, ncol
1017 return nrow, ncol
1018
1018
1019 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1019 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1020
1020
1021 self.__showprofile = showprofile
1021 self.__showprofile = showprofile
1022 self.nplots = nplots
1022 self.nplots = nplots
1023
1023
1024 ncolspan = 1
1024 ncolspan = 1
1025 colspan = 1
1025 colspan = 1
1026
1026
1027 self.createFigure(id = id,
1027 self.createFigure(id = id,
1028 wintitle = wintitle,
1028 wintitle = wintitle,
1029 widthplot = self.WIDTH + self.WIDTHPROF,
1029 widthplot = self.WIDTH + self.WIDTHPROF,
1030 heightplot = self.HEIGHT + self.HEIGHTPROF,
1030 heightplot = self.HEIGHT + self.HEIGHTPROF,
1031 show=show)
1031 show=show)
1032
1032
1033 nrow, ncol = self.getSubplots()
1033 nrow, ncol = self.getSubplots()
1034
1034
1035 counter = 0
1035 counter = 0
1036 for y in range(nrow):
1036 for y in range(nrow):
1037 if counter >= self.nplots:
1037 if counter >= self.nplots:
1038 break
1038 break
1039
1039
1040 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1040 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1041 counter += 1
1041 counter += 1
1042
1042
1043 def run(self, dataOut, id, wintitle="", channelList=None,
1043 def run(self, dataOut, id, wintitle="", channelList=None,
1044 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1044 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1045 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1045 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1046 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1046 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1047 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1047 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1048 server=None, folder=None, username=None, password=None,
1048 server=None, folder=None, username=None, password=None,
1049 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1049 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1050 """
1050 """
1051
1051
1052 Input:
1052 Input:
1053 dataOut :
1053 dataOut :
1054 id :
1054 id :
1055 wintitle :
1055 wintitle :
1056 channelList :
1056 channelList :
1057 showProfile :
1057 showProfile :
1058 xmin : None,
1058 xmin : None,
1059 xmax : None,
1059 xmax : None,
1060 ymin : None,
1060 ymin : None,
1061 ymax : None,
1061 ymax : None,
1062 zmin : None,
1062 zmin : None,
1063 zmax : None
1063 zmax : None
1064 """
1064 """
1065
1065
1066 if timerange != None:
1066 if timerange != None:
1067 self.timerange = timerange
1067 self.timerange = timerange
1068
1068
1069 tmin = None
1069 tmin = None
1070 tmax = None
1070 tmax = None
1071
1071
1072 x = dataOut.getTimeRange1()
1072 x = dataOut.getTimeRange1()
1073 # y = dataOut.heightList
1073 # y = dataOut.heightList
1074 y = dataOut.heightList
1074 y = dataOut.heightList
1075
1075
1076 z = dataOut.data_output
1076 z = dataOut.data_output
1077 nplots = z.shape[0] #Number of wind dimensions estimated
1077 nplots = z.shape[0] #Number of wind dimensions estimated
1078 nplotsw = nplots
1078 nplotsw = nplots
1079
1079
1080 #If there is a SNR function defined
1080 #If there is a SNR function defined
1081 if dataOut.data_SNR != None:
1081 if dataOut.data_SNR != None:
1082 nplots += 1
1082 nplots += 1
1083 SNR = dataOut.data_SNR
1083 SNR = dataOut.data_SNR
1084
1084
1085 if SNR_1:
1085 if SNR_1:
1086 SNR += 1
1086 SNR += 1
1087
1087
1088 SNRavg = numpy.average(SNR, axis=0)
1088 SNRavg = numpy.average(SNR, axis=0)
1089
1089
1090 SNRdB = 10*numpy.log10(SNR)
1090 SNRdB = 10*numpy.log10(SNR)
1091 SNRavgdB = 10*numpy.log10(SNRavg)
1091 SNRavgdB = 10*numpy.log10(SNRavg)
1092
1092
1093 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1093 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1094
1094
1095 for i in range(nplotsw):
1095 for i in range(nplotsw):
1096 z[i,ind] = numpy.nan
1096 z[i,ind] = numpy.nan
1097
1097
1098
1098
1099 showprofile = False
1099 showprofile = False
1100 # thisDatetime = dataOut.datatime
1100 # thisDatetime = dataOut.datatime
1101 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1101 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1102 title = wintitle + " EW Drifts"
1102 title = wintitle + " EW Drifts"
1103 xlabel = ""
1103 xlabel = ""
1104 ylabel = "Height (Km)"
1104 ylabel = "Height (Km)"
1105
1105
1106 if not self.__isConfig:
1106 if not self.__isConfig:
1107
1107
1108 self.setup(id=id,
1108 self.setup(id=id,
1109 nplots=nplots,
1109 nplots=nplots,
1110 wintitle=wintitle,
1110 wintitle=wintitle,
1111 showprofile=showprofile,
1111 showprofile=showprofile,
1112 show=show)
1112 show=show)
1113
1113
1114 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1114 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1115
1115
1116 if ymin == None: ymin = numpy.nanmin(y)
1116 if ymin == None: ymin = numpy.nanmin(y)
1117 if ymax == None: ymax = numpy.nanmax(y)
1117 if ymax == None: ymax = numpy.nanmax(y)
1118
1118
1119 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1119 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1120 if zminZonal == None: zminZonal = -zmaxZonal
1120 if zminZonal == None: zminZonal = -zmaxZonal
1121 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1121 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1122 if zminVertical == None: zminVertical = -zmaxVertical
1122 if zminVertical == None: zminVertical = -zmaxVertical
1123
1123
1124 if dataOut.data_SNR != None:
1124 if dataOut.data_SNR != None:
1125 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1125 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1126 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1126 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1127
1127
1128 self.FTP_WEI = ftp_wei
1128 self.FTP_WEI = ftp_wei
1129 self.EXP_CODE = exp_code
1129 self.EXP_CODE = exp_code
1130 self.SUB_EXP_CODE = sub_exp_code
1130 self.SUB_EXP_CODE = sub_exp_code
1131 self.PLOT_POS = plot_pos
1131 self.PLOT_POS = plot_pos
1132
1132
1133 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1133 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1134 self.__isConfig = True
1134 self.__isConfig = True
1135
1135
1136
1136
1137 self.setWinTitle(title)
1137 self.setWinTitle(title)
1138
1138
1139 if ((self.xmax - x[1]) < (x[1]-x[0])):
1139 if ((self.xmax - x[1]) < (x[1]-x[0])):
1140 x[1] = self.xmax
1140 x[1] = self.xmax
1141
1141
1142 strWind = ['Zonal','Vertical']
1142 strWind = ['Zonal','Vertical']
1143 strCb = 'Velocity (m/s)'
1143 strCb = 'Velocity (m/s)'
1144 zmaxVector = [zmaxZonal, zmaxVertical]
1144 zmaxVector = [zmaxZonal, zmaxVertical]
1145 zminVector = [zminZonal, zminVertical]
1145 zminVector = [zminZonal, zminVertical]
1146
1146
1147 for i in range(nplotsw):
1147 for i in range(nplotsw):
1148
1148
1149 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1149 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1150 axes = self.axesList[i*self.__nsubplots]
1150 axes = self.axesList[i*self.__nsubplots]
1151
1151
1152 z1 = z[i,:].reshape((1,-1))
1152 z1 = z[i,:].reshape((1,-1))
1153
1153
1154 axes.pcolorbuffer(x, y, z1,
1154 axes.pcolorbuffer(x, y, z1,
1155 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1155 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1156 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1156 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1157 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1157 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1158
1158
1159 if dataOut.data_SNR != None:
1159 if dataOut.data_SNR != None:
1160 i += 1
1160 i += 1
1161 if SNR_1:
1161 if SNR_1:
1162 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1162 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1163 else:
1163 else:
1164 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1164 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1165 axes = self.axesList[i*self.__nsubplots]
1165 axes = self.axesList[i*self.__nsubplots]
1166 SNRavgdB = SNRavgdB.reshape((1,-1))
1166 SNRavgdB = SNRavgdB.reshape((1,-1))
1167
1167
1168 axes.pcolorbuffer(x, y, SNRavgdB,
1168 axes.pcolorbuffer(x, y, SNRavgdB,
1169 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1169 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1170 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1170 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1171 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1171 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1172
1172
1173 self.draw()
1173 self.draw()
1174
1174
1175 if self.figfile == None:
1175 if self.figfile == None:
1176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1177 self.figfile = self.getFilename(name = str_datetime)
1177 self.figfile = self.getFilename(name = str_datetime)
1178
1178
1179 if figpath != '':
1179 if figpath != '':
1180
1180
1181 self.counter_imagwr += 1
1181 self.counter_imagwr += 1
1182 if (self.counter_imagwr>=wr_period):
1182 if (self.counter_imagwr>=wr_period):
1183 # store png plot to local folder
1183 # store png plot to local folder
1184 self.saveFigure(figpath, self.figfile)
1184 self.saveFigure(figpath, self.figfile)
1185 # store png plot to FTP server according to RT-Web format
1185 # store png plot to FTP server according to RT-Web format
1186 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1186 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1187 ftp_filename = os.path.join(figpath, name)
1187 ftp_filename = os.path.join(figpath, name)
1188 self.saveFigure(figpath, ftp_filename)
1188 self.saveFigure(figpath, ftp_filename)
1189
1189
1190 self.counter_imagwr = 0
1190 self.counter_imagwr = 0
1191
1191
1192 if x[1] >= self.axesList[0].xmax:
1192 if x[1] >= self.axesList[0].xmax:
1193 self.counter_imagwr = wr_period
1193 self.counter_imagwr = wr_period
1194 self.__isConfig = False
1194 self.__isConfig = False
1195 self.figfile = None No newline at end of file
1195 self.figfile = None
General Comments 0
You need to be logged in to leave comments. Login now