##// END OF EJS Templates
Bug fixed in Sky Map and Phase Plots
Julio Valdez -
r786:aed163ca3230
parent child
Show More
@@ -1,1364 +1,1372
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 from plotting_codes import *
6 from plotting_codes import *
7
7
8 class MomentsPlot(Figure):
8 class MomentsPlot(Figure):
9
9
10 isConfig = None
10 isConfig = None
11 __nsubplots = None
11 __nsubplots = None
12
12
13 WIDTHPROF = None
13 WIDTHPROF = None
14 HEIGHTPROF = None
14 HEIGHTPROF = None
15 PREFIX = 'prm'
15 PREFIX = 'prm'
16
16
17 def __init__(self):
17 def __init__(self):
18
18
19 self.isConfig = False
19 self.isConfig = False
20 self.__nsubplots = 1
20 self.__nsubplots = 1
21
21
22 self.WIDTH = 280
22 self.WIDTH = 280
23 self.HEIGHT = 250
23 self.HEIGHT = 250
24 self.WIDTHPROF = 120
24 self.WIDTHPROF = 120
25 self.HEIGHTPROF = 0
25 self.HEIGHTPROF = 0
26 self.counter_imagwr = 0
26 self.counter_imagwr = 0
27
27
28 self.PLOT_CODE = MOMENTS_CODE
28 self.PLOT_CODE = MOMENTS_CODE
29
29
30 self.FTP_WEI = None
30 self.FTP_WEI = None
31 self.EXP_CODE = None
31 self.EXP_CODE = None
32 self.SUB_EXP_CODE = None
32 self.SUB_EXP_CODE = None
33 self.PLOT_POS = None
33 self.PLOT_POS = None
34
34
35 def getSubplots(self):
35 def getSubplots(self):
36
36
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
39
39
40 return nrow, ncol
40 return nrow, ncol
41
41
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43
43
44 self.__showprofile = showprofile
44 self.__showprofile = showprofile
45 self.nplots = nplots
45 self.nplots = nplots
46
46
47 ncolspan = 1
47 ncolspan = 1
48 colspan = 1
48 colspan = 1
49 if showprofile:
49 if showprofile:
50 ncolspan = 3
50 ncolspan = 3
51 colspan = 2
51 colspan = 2
52 self.__nsubplots = 2
52 self.__nsubplots = 2
53
53
54 self.createFigure(id = id,
54 self.createFigure(id = id,
55 wintitle = wintitle,
55 wintitle = wintitle,
56 widthplot = self.WIDTH + self.WIDTHPROF,
56 widthplot = self.WIDTH + self.WIDTHPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 show=show)
58 show=show)
59
59
60 nrow, ncol = self.getSubplots()
60 nrow, ncol = self.getSubplots()
61
61
62 counter = 0
62 counter = 0
63 for y in range(nrow):
63 for y in range(nrow):
64 for x in range(ncol):
64 for x in range(ncol):
65
65
66 if counter >= self.nplots:
66 if counter >= self.nplots:
67 break
67 break
68
68
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70
70
71 if showprofile:
71 if showprofile:
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73
73
74 counter += 1
74 counter += 1
75
75
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 server=None, folder=None, username=None, password=None,
79 server=None, folder=None, username=None, password=None,
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81
81
82 """
82 """
83
83
84 Input:
84 Input:
85 dataOut :
85 dataOut :
86 id :
86 id :
87 wintitle :
87 wintitle :
88 channelList :
88 channelList :
89 showProfile :
89 showProfile :
90 xmin : None,
90 xmin : None,
91 xmax : None,
91 xmax : None,
92 ymin : None,
92 ymin : None,
93 ymax : None,
93 ymax : None,
94 zmin : None,
94 zmin : None,
95 zmax : None
95 zmax : None
96 """
96 """
97
97
98 if dataOut.flagNoData:
98 if dataOut.flagNoData:
99 return None
99 return None
100
100
101 if realtime:
101 if realtime:
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 print 'Skipping this plot function'
103 print 'Skipping this plot function'
104 return
104 return
105
105
106 if channelList == None:
106 if channelList == None:
107 channelIndexList = dataOut.channelIndexList
107 channelIndexList = dataOut.channelIndexList
108 else:
108 else:
109 channelIndexList = []
109 channelIndexList = []
110 for channel in channelList:
110 for channel in channelList:
111 if channel not in dataOut.channelList:
111 if channel not in dataOut.channelList:
112 raise ValueError, "Channel %d is not in dataOut.channelList"
112 raise ValueError, "Channel %d is not in dataOut.channelList"
113 channelIndexList.append(dataOut.channelList.index(channel))
113 channelIndexList.append(dataOut.channelList.index(channel))
114
114
115 factor = dataOut.normFactor
115 factor = dataOut.normFactor
116 x = dataOut.abscissaList
116 x = dataOut.abscissaList
117 y = dataOut.heightList
117 y = dataOut.heightList
118
118
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
121 avg = numpy.average(z, axis=1)
121 avg = numpy.average(z, axis=1)
122 noise = dataOut.noise/factor
122 noise = dataOut.noise/factor
123
123
124 zdB = 10*numpy.log10(z)
124 zdB = 10*numpy.log10(z)
125 avgdB = 10*numpy.log10(avg)
125 avgdB = 10*numpy.log10(avg)
126 noisedB = 10*numpy.log10(noise)
126 noisedB = 10*numpy.log10(noise)
127
127
128 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 title = wintitle + " Parameters"
130 title = wintitle + " Parameters"
131 xlabel = "Velocity (m/s)"
131 xlabel = "Velocity (m/s)"
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 update_figfile = False
135
134 if not self.isConfig:
136 if not self.isConfig:
135
137
136 nplots = len(channelIndexList)
138 nplots = len(channelIndexList)
137
139
138 self.setup(id=id,
140 self.setup(id=id,
139 nplots=nplots,
141 nplots=nplots,
140 wintitle=wintitle,
142 wintitle=wintitle,
141 showprofile=showprofile,
143 showprofile=showprofile,
142 show=show)
144 show=show)
143
145
144 if xmin == None: xmin = numpy.nanmin(x)
146 if xmin == None: xmin = numpy.nanmin(x)
145 if xmax == None: xmax = numpy.nanmax(x)
147 if xmax == None: xmax = numpy.nanmax(x)
146 if ymin == None: ymin = numpy.nanmin(y)
148 if ymin == None: ymin = numpy.nanmin(y)
147 if ymax == None: ymax = numpy.nanmax(y)
149 if ymax == None: ymax = numpy.nanmax(y)
148 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
150 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
149 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
151 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
150
152
151 self.FTP_WEI = ftp_wei
153 self.FTP_WEI = ftp_wei
152 self.EXP_CODE = exp_code
154 self.EXP_CODE = exp_code
153 self.SUB_EXP_CODE = sub_exp_code
155 self.SUB_EXP_CODE = sub_exp_code
154 self.PLOT_POS = plot_pos
156 self.PLOT_POS = plot_pos
155
157
156 self.isConfig = True
158 self.isConfig = True
159 update_figfile = True
157
160
158 self.setWinTitle(title)
161 self.setWinTitle(title)
159
162
160 for i in range(self.nplots):
163 for i in range(self.nplots):
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
163 axes = self.axesList[i*self.__nsubplots]
166 axes = self.axesList[i*self.__nsubplots]
164 axes.pcolor(x, y, zdB[i,:,:],
167 axes.pcolor(x, y, zdB[i,:,:],
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xlabel=xlabel, ylabel=ylabel, title=title,
169 xlabel=xlabel, ylabel=ylabel, title=title,
167 ticksize=9, cblabel='')
170 ticksize=9, cblabel='')
168 #Mean Line
171 #Mean Line
169 mean = dataOut.data_param[i, 1, :]
172 mean = dataOut.data_param[i, 1, :]
170 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
173 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
171
174
172 if self.__showprofile:
175 if self.__showprofile:
173 axes = self.axesList[i*self.__nsubplots +1]
176 axes = self.axesList[i*self.__nsubplots +1]
174 axes.pline(avgdB[i], y,
177 axes.pline(avgdB[i], y,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
178 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 xlabel='dB', ylabel='', title='',
179 xlabel='dB', ylabel='', title='',
177 ytick_visible=False,
180 ytick_visible=False,
178 grid='x')
181 grid='x')
179
182
180 noiseline = numpy.repeat(noisedB[i], len(y))
183 noiseline = numpy.repeat(noisedB[i], len(y))
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
184 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182
185
183 self.draw()
186 self.draw()
184
187
185 self.save(figpath=figpath,
188 self.save(figpath=figpath,
186 figfile=figfile,
189 figfile=figfile,
187 save=save,
190 save=save,
188 ftp=ftp,
191 ftp=ftp,
189 wr_period=wr_period,
192 wr_period=wr_period,
190 thisDatetime=thisDatetime)
193 thisDatetime=thisDatetime)
191
194
192
195
193
196
194 class SkyMapPlot(Figure):
197 class SkyMapPlot(Figure):
195
198
196 __isConfig = None
199 __isConfig = None
197 __nsubplots = None
200 __nsubplots = None
198
201
199 WIDTHPROF = None
202 WIDTHPROF = None
200 HEIGHTPROF = None
203 HEIGHTPROF = None
201 PREFIX = 'mmap'
204 PREFIX = 'mmap'
202
205
203 def __init__(self):
206 def __init__(self):
204
207
205 self.__isConfig = False
208 self.__isConfig = False
206 self.__nsubplots = 1
209 self.__nsubplots = 1
207
210
208 # self.WIDTH = 280
211 # self.WIDTH = 280
209 # self.HEIGHT = 250
212 # self.HEIGHT = 250
210 self.WIDTH = 600
213 self.WIDTH = 600
211 self.HEIGHT = 600
214 self.HEIGHT = 600
212 self.WIDTHPROF = 120
215 self.WIDTHPROF = 120
213 self.HEIGHTPROF = 0
216 self.HEIGHTPROF = 0
214 self.counter_imagwr = 0
217 self.counter_imagwr = 0
215
218
216 self.PLOT_CODE = MSKYMAP_CODE
219 self.PLOT_CODE = MSKYMAP_CODE
217
220
218 self.FTP_WEI = None
221 self.FTP_WEI = None
219 self.EXP_CODE = None
222 self.EXP_CODE = None
220 self.SUB_EXP_CODE = None
223 self.SUB_EXP_CODE = None
221 self.PLOT_POS = None
224 self.PLOT_POS = None
222
225
223 def getSubplots(self):
226 def getSubplots(self):
224
227
225 ncol = int(numpy.sqrt(self.nplots)+0.9)
228 ncol = int(numpy.sqrt(self.nplots)+0.9)
226 nrow = int(self.nplots*1./ncol + 0.9)
229 nrow = int(self.nplots*1./ncol + 0.9)
227
230
228 return nrow, ncol
231 return nrow, ncol
229
232
230 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
233 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
231
234
232 self.__showprofile = showprofile
235 self.__showprofile = showprofile
233 self.nplots = nplots
236 self.nplots = nplots
234
237
235 ncolspan = 1
238 ncolspan = 1
236 colspan = 1
239 colspan = 1
237
240
238 self.createFigure(id = id,
241 self.createFigure(id = id,
239 wintitle = wintitle,
242 wintitle = wintitle,
240 widthplot = self.WIDTH, #+ self.WIDTHPROF,
243 widthplot = self.WIDTH, #+ self.WIDTHPROF,
241 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
244 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
242 show=show)
245 show=show)
243
246
244 nrow, ncol = 1,1
247 nrow, ncol = 1,1
245 counter = 0
248 counter = 0
246 x = 0
249 x = 0
247 y = 0
250 y = 0
248 self.addAxes(1, 1, 0, 0, 1, 1, True)
251 self.addAxes(1, 1, 0, 0, 1, 1, True)
249
252
250 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
253 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
251 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
254 tmin=None, tmax=None, timerange=None,
252 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,
253 server=None, folder=None, username=None, password=None,
256 server=None, folder=None, username=None, password=None,
254 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):
255
258
256 """
259 """
257
260
258 Input:
261 Input:
259 dataOut :
262 dataOut :
260 id :
263 id :
261 wintitle :
264 wintitle :
262 channelList :
265 channelList :
263 showProfile :
266 showProfile :
264 xmin : None,
267 xmin : None,
265 xmax : None,
268 xmax : None,
266 ymin : None,
269 ymin : None,
267 ymax : None,
270 ymax : None,
268 zmin : None,
271 zmin : None,
269 zmax : None
272 zmax : None
270 """
273 """
271
274
272 arrayParameters = dataOut.data_param[0,:]
275 arrayParameters = dataOut.data_param[0,:]
273 error = arrayParameters[:,-1]
276 error = arrayParameters[:,-1]
274 indValid = numpy.where(error == 0)[0]
277 indValid = numpy.where(error == 0)[0]
275 finalMeteor = arrayParameters[indValid,:]
278 finalMeteor = arrayParameters[indValid,:]
276 finalAzimuth = finalMeteor[:,4]
279 finalAzimuth = finalMeteor[:,4]
277 finalZenith = finalMeteor[:,5]
280 finalZenith = finalMeteor[:,5]
278
281
279 x = finalAzimuth*numpy.pi/180
282 x = finalAzimuth*numpy.pi/180
280 y = finalZenith
283 y = finalZenith
284 x1 = dataOut.getTimeRange()
281
285
282
283 #thisDatetime = dataOut.datatime
286 #thisDatetime = dataOut.datatime
284 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
285 title = wintitle + " Parameters"
288 title = wintitle + " Parameters"
286 xlabel = "Zonal Zenith Angle (deg) "
289 xlabel = "Zonal Zenith Angle (deg) "
287 ylabel = "Meridional Zenith Angle (deg)"
290 ylabel = "Meridional Zenith Angle (deg)"
291 update_figfile = False
288
292
289 if not self.__isConfig:
293 if not self.__isConfig:
290
294
291 nplots = 1
295 nplots = 1
292
296
293 self.setup(id=id,
297 self.setup(id=id,
294 nplots=nplots,
298 nplots=nplots,
295 wintitle=wintitle,
299 wintitle=wintitle,
296 showprofile=showprofile,
300 showprofile=showprofile,
297 show=show)
301 show=show)
298
302
303 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
304
305 if timerange != None:
306 self.timerange = timerange
307 else:
308 self.timerange = self.xmax - self.xmin
309
299 self.FTP_WEI = ftp_wei
310 self.FTP_WEI = ftp_wei
300 self.EXP_CODE = exp_code
311 self.EXP_CODE = exp_code
301 self.SUB_EXP_CODE = sub_exp_code
312 self.SUB_EXP_CODE = sub_exp_code
302 self.PLOT_POS = plot_pos
313 self.PLOT_POS = plot_pos
303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
314 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
304 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
315 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
305 self.__isConfig = True
316 self.__isConfig = True
317 update_figfile = True
306
318
307 self.setWinTitle(title)
319 self.setWinTitle(title)
308
320
309 i = 0
321 i = 0
310 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
322 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
311
323
312 axes = self.axesList[i*self.__nsubplots]
324 axes = self.axesList[i*self.__nsubplots]
313 nevents = axes.x_buffer.shape[0] + x.shape[0]
325 nevents = axes.x_buffer.shape[0] + x.shape[0]
314 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
326 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
315 axes.polar(x, y,
327 axes.polar(x, y,
316 title=title, xlabel=xlabel, ylabel=ylabel,
328 title=title, xlabel=xlabel, ylabel=ylabel,
317 ticksize=9, cblabel='')
329 ticksize=9, cblabel='')
318
330
319 self.draw()
331 self.draw()
320
332
321 self.save(figpath=figpath,
333 self.save(figpath=figpath,
322 figfile=figfile,
334 figfile=figfile,
323 save=save,
335 save=save,
324 ftp=ftp,
336 ftp=ftp,
325 wr_period=wr_period,
337 wr_period=wr_period,
326 thisDatetime=thisDatetime,
338 thisDatetime=thisDatetime,
327 update_figfile=False)
339 update_figfile=update_figfile)
340
341 if dataOut.ltctime >= self.xmax:
342 self.counter_imagwr = wr_period
343 self.__isConfig = False
344 update_figfile = True
345 axes.__firsttime = True
346 self.xmin += self.timerange
347 self.xmax += self.timerange
348
349
328
350
329
351
330 class WindProfilerPlot(Figure):
352 class WindProfilerPlot(Figure):
331
353
332 __isConfig = None
354 __isConfig = None
333 __nsubplots = None
355 __nsubplots = None
334
356
335 WIDTHPROF = None
357 WIDTHPROF = None
336 HEIGHTPROF = None
358 HEIGHTPROF = None
337 PREFIX = 'wind'
359 PREFIX = 'wind'
338
360
339 def __init__(self):
361 def __init__(self):
340
362
341 self.timerange = None
363 self.timerange = None
342 self.__isConfig = False
364 self.__isConfig = False
343 self.__nsubplots = 1
365 self.__nsubplots = 1
344
366
345 self.WIDTH = 800
367 self.WIDTH = 800
346 self.HEIGHT = 150
368 self.HEIGHT = 150
347 self.WIDTHPROF = 120
369 self.WIDTHPROF = 120
348 self.HEIGHTPROF = 0
370 self.HEIGHTPROF = 0
349 self.counter_imagwr = 0
371 self.counter_imagwr = 0
350
372
351 self.PLOT_CODE = WIND_CODE
373 self.PLOT_CODE = WIND_CODE
352
374
353 self.FTP_WEI = None
375 self.FTP_WEI = None
354 self.EXP_CODE = None
376 self.EXP_CODE = None
355 self.SUB_EXP_CODE = None
377 self.SUB_EXP_CODE = None
356 self.PLOT_POS = None
378 self.PLOT_POS = None
357 self.tmin = None
379 self.tmin = None
358 self.tmax = None
380 self.tmax = None
359
381
360 self.xmin = None
382 self.xmin = None
361 self.xmax = None
383 self.xmax = None
362
384
363 self.figfile = None
385 self.figfile = None
364
386
365 def getSubplots(self):
387 def getSubplots(self):
366
388
367 ncol = 1
389 ncol = 1
368 nrow = self.nplots
390 nrow = self.nplots
369
391
370 return nrow, ncol
392 return nrow, ncol
371
393
372 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
394 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
373
395
374 self.__showprofile = showprofile
396 self.__showprofile = showprofile
375 self.nplots = nplots
397 self.nplots = nplots
376
398
377 ncolspan = 1
399 ncolspan = 1
378 colspan = 1
400 colspan = 1
379
401
380 self.createFigure(id = id,
402 self.createFigure(id = id,
381 wintitle = wintitle,
403 wintitle = wintitle,
382 widthplot = self.WIDTH + self.WIDTHPROF,
404 widthplot = self.WIDTH + self.WIDTHPROF,
383 heightplot = self.HEIGHT + self.HEIGHTPROF,
405 heightplot = self.HEIGHT + self.HEIGHTPROF,
384 show=show)
406 show=show)
385
407
386 nrow, ncol = self.getSubplots()
408 nrow, ncol = self.getSubplots()
387
409
388 counter = 0
410 counter = 0
389 for y in range(nrow):
411 for y in range(nrow):
390 if counter >= self.nplots:
412 if counter >= self.nplots:
391 break
413 break
392
414
393 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
415 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
394 counter += 1
416 counter += 1
395
417
396 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
418 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
397 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
419 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
398 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
420 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
399 timerange=None, SNRthresh = None,
421 timerange=None, SNRthresh = None,
400 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
422 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
401 server=None, folder=None, username=None, password=None,
423 server=None, folder=None, username=None, password=None,
402 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
424 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
403 """
425 """
404
426
405 Input:
427 Input:
406 dataOut :
428 dataOut :
407 id :
429 id :
408 wintitle :
430 wintitle :
409 channelList :
431 channelList :
410 showProfile :
432 showProfile :
411 xmin : None,
433 xmin : None,
412 xmax : None,
434 xmax : None,
413 ymin : None,
435 ymin : None,
414 ymax : None,
436 ymax : None,
415 zmin : None,
437 zmin : None,
416 zmax : None
438 zmax : None
417 """
439 """
418
440
419 if channelList == None:
441 if channelList == None:
420 channelIndexList = dataOut.channelIndexList
442 channelIndexList = dataOut.channelIndexList
421 else:
443 else:
422 channelIndexList = []
444 channelIndexList = []
423 for channel in channelList:
445 for channel in channelList:
424 if channel not in dataOut.channelList:
446 if channel not in dataOut.channelList:
425 raise ValueError, "Channel %d is not in dataOut.channelList"
447 raise ValueError, "Channel %d is not in dataOut.channelList"
426 channelIndexList.append(dataOut.channelList.index(channel))
448 channelIndexList.append(dataOut.channelList.index(channel))
427
449
428 # if timerange is not None:
450 # if timerange is not None:
429 # self.timerange = timerange
451 # self.timerange = timerange
430 #
452 #
431 # tmin = None
453 # tmin = None
432 # tmax = None
454 # tmax = None
433
455
434 x = dataOut.getTimeRange1()
456 x = dataOut.getTimeRange1()
435 # y = dataOut.heightList
457 # y = dataOut.heightList
436 y = dataOut.heightList
458 y = dataOut.heightList
437
459
438 z = dataOut.data_output.copy()
460 z = dataOut.data_output.copy()
439 nplots = z.shape[0] #Number of wind dimensions estimated
461 nplots = z.shape[0] #Number of wind dimensions estimated
440 nplotsw = nplots
462 nplotsw = nplots
441
463
442 #If there is a SNR function defined
464 #If there is a SNR function defined
443 if dataOut.data_SNR is not None:
465 if dataOut.data_SNR is not None:
444 nplots += 1
466 nplots += 1
445 SNR = dataOut.data_SNR
467 SNR = dataOut.data_SNR
446 SNRavg = numpy.average(SNR, axis=0)
468 SNRavg = numpy.average(SNR, axis=0)
447
469
448 SNRdB = 10*numpy.log10(SNR)
470 SNRdB = 10*numpy.log10(SNR)
449 SNRavgdB = 10*numpy.log10(SNRavg)
471 SNRavgdB = 10*numpy.log10(SNRavg)
450
472
451 if SNRthresh == None: SNRthresh = -5.0
473 if SNRthresh == None: SNRthresh = -5.0
452 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
474 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
453
475
454 for i in range(nplotsw):
476 for i in range(nplotsw):
455 z[i,ind] = numpy.nan
477 z[i,ind] = numpy.nan
456
478
457
479
458 # showprofile = False
480 # showprofile = False
459 # thisDatetime = dataOut.datatime
481 # thisDatetime = dataOut.datatime
460 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
482 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
461 title = wintitle + "Wind"
483 title = wintitle + "Wind"
462 xlabel = ""
484 xlabel = ""
463 ylabel = "Range (Km)"
485 ylabel = "Range (Km)"
486 update_figfile = False
464
487
465 if not self.__isConfig:
488 if not self.__isConfig:
466
489
467 self.setup(id=id,
490 self.setup(id=id,
468 nplots=nplots,
491 nplots=nplots,
469 wintitle=wintitle,
492 wintitle=wintitle,
470 showprofile=showprofile,
493 showprofile=showprofile,
471 show=show)
494 show=show)
472
495
473 if timerange is not None:
496 if timerange is not None:
474 self.timerange = timerange
497 self.timerange = timerange
475
498
476 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
499 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
477
500
478 if ymin == None: ymin = numpy.nanmin(y)
501 if ymin == None: ymin = numpy.nanmin(y)
479 if ymax == None: ymax = numpy.nanmax(y)
502 if ymax == None: ymax = numpy.nanmax(y)
480
503
481 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
504 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
482 #if numpy.isnan(zmax): zmax = 50
505 #if numpy.isnan(zmax): zmax = 50
483 if zmin == None: zmin = -zmax
506 if zmin == None: zmin = -zmax
484
507
485 if nplotsw == 3:
508 if nplotsw == 3:
486 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
509 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
487 if zmin_ver == None: zmin_ver = -zmax_ver
510 if zmin_ver == None: zmin_ver = -zmax_ver
488
511
489 if dataOut.data_SNR is not None:
512 if dataOut.data_SNR is not None:
490 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
513 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
491 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
514 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
492
515
493
516
494 self.FTP_WEI = ftp_wei
517 self.FTP_WEI = ftp_wei
495 self.EXP_CODE = exp_code
518 self.EXP_CODE = exp_code
496 self.SUB_EXP_CODE = sub_exp_code
519 self.SUB_EXP_CODE = sub_exp_code
497 self.PLOT_POS = plot_pos
520 self.PLOT_POS = plot_pos
498
521
499 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
522 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
500 self.__isConfig = True
523 self.__isConfig = True
501 self.figfile = figfile
524 self.figfile = figfile
525 update_figfile = True
502
526
503 self.setWinTitle(title)
527 self.setWinTitle(title)
504
528
505 if ((self.xmax - x[1]) < (x[1]-x[0])):
529 if ((self.xmax - x[1]) < (x[1]-x[0])):
506 x[1] = self.xmax
530 x[1] = self.xmax
507
531
508 strWind = ['Zonal', 'Meridional', 'Vertical']
532 strWind = ['Zonal', 'Meridional', 'Vertical']
509 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
533 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
510 zmaxVector = [zmax, zmax, zmax_ver]
534 zmaxVector = [zmax, zmax, zmax_ver]
511 zminVector = [zmin, zmin, zmin_ver]
535 zminVector = [zmin, zmin, zmin_ver]
512 windFactor = [1,1,100]
536 windFactor = [1,1,100]
513
537
514 for i in range(nplotsw):
538 for i in range(nplotsw):
515
539
516 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
540 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
517 axes = self.axesList[i*self.__nsubplots]
541 axes = self.axesList[i*self.__nsubplots]
518
542
519 z1 = z[i,:].reshape((1,-1))*windFactor[i]
543 z1 = z[i,:].reshape((1,-1))*windFactor[i]
520
544
521 axes.pcolorbuffer(x, y, z1,
545 axes.pcolorbuffer(x, y, z1,
522 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
546 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
523 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
547 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
524 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
548 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
525
549
526 if dataOut.data_SNR is not None:
550 if dataOut.data_SNR is not None:
527 i += 1
551 i += 1
528 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
552 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
529 axes = self.axesList[i*self.__nsubplots]
553 axes = self.axesList[i*self.__nsubplots]
530
554
531 SNRavgdB = SNRavgdB.reshape((1,-1))
555 SNRavgdB = SNRavgdB.reshape((1,-1))
532
556
533 axes.pcolorbuffer(x, y, SNRavgdB,
557 axes.pcolorbuffer(x, y, SNRavgdB,
534 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
558 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
535 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
559 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
536 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
560 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
537
561
538 self.draw()
562 self.draw()
539
563
540 if x[1] >= self.axesList[0].xmax:
564 if dataOut.ltctime >= self.xmax:
541 self.counter_imagwr = wr_period
565 self.counter_imagwr = wr_period
542 self.__isConfig = False
566 self.__isConfig = False
543 self.figfile = None
567 update_figfile = True
544
568
545 self.save(figpath=figpath,
569 self.save(figpath=figpath,
546 figfile=figfile,
570 figfile=figfile,
547 save=save,
571 save=save,
548 ftp=ftp,
572 ftp=ftp,
549 wr_period=wr_period,
573 wr_period=wr_period,
550 thisDatetime=thisDatetime,
574 thisDatetime=thisDatetime,
551 update_figfile=False)
575 update_figfile=update_figfile)
576
552
577
553
578
554 class ParametersPlot(Figure):
579 class ParametersPlot(Figure):
555
580
556 __isConfig = None
581 __isConfig = None
557 __nsubplots = None
582 __nsubplots = None
558
583
559 WIDTHPROF = None
584 WIDTHPROF = None
560 HEIGHTPROF = None
585 HEIGHTPROF = None
561 PREFIX = 'prm'
586 PREFIX = 'prm'
562
587
563 def __init__(self):
588 def __init__(self):
564
589
565 self.timerange = 2*60*60
590 self.timerange = 2*60*60
566 self.__isConfig = False
591 self.__isConfig = False
567 self.__nsubplots = 1
592 self.__nsubplots = 1
568
593
569 self.WIDTH = 800
594 self.WIDTH = 800
570 self.HEIGHT = 150
595 self.HEIGHT = 150
571 self.WIDTHPROF = 120
596 self.WIDTHPROF = 120
572 self.HEIGHTPROF = 0
597 self.HEIGHTPROF = 0
573 self.counter_imagwr = 0
598 self.counter_imagwr = 0
574
599
575 self.PLOT_CODE = PARMS_CODE
600 self.PLOT_CODE = PARMS_CODE
576
601
577 self.FTP_WEI = None
602 self.FTP_WEI = None
578 self.EXP_CODE = None
603 self.EXP_CODE = None
579 self.SUB_EXP_CODE = None
604 self.SUB_EXP_CODE = None
580 self.PLOT_POS = None
605 self.PLOT_POS = None
581 self.tmin = None
606 self.tmin = None
582 self.tmax = None
607 self.tmax = None
583
608
584 self.xmin = None
609 self.xmin = None
585 self.xmax = None
610 self.xmax = None
586
611
587 self.figfile = None
612 self.figfile = None
588
613
589 def getSubplots(self):
614 def getSubplots(self):
590
615
591 ncol = 1
616 ncol = 1
592 nrow = self.nplots
617 nrow = self.nplots
593
618
594 return nrow, ncol
619 return nrow, ncol
595
620
596 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
621 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
597
622
598 self.__showprofile = showprofile
623 self.__showprofile = showprofile
599 self.nplots = nplots
624 self.nplots = nplots
600
625
601 ncolspan = 1
626 ncolspan = 1
602 colspan = 1
627 colspan = 1
603
628
604 self.createFigure(id = id,
629 self.createFigure(id = id,
605 wintitle = wintitle,
630 wintitle = wintitle,
606 widthplot = self.WIDTH + self.WIDTHPROF,
631 widthplot = self.WIDTH + self.WIDTHPROF,
607 heightplot = self.HEIGHT + self.HEIGHTPROF,
632 heightplot = self.HEIGHT + self.HEIGHTPROF,
608 show=show)
633 show=show)
609
634
610 nrow, ncol = self.getSubplots()
635 nrow, ncol = self.getSubplots()
611
636
612 counter = 0
637 counter = 0
613 for y in range(nrow):
638 for y in range(nrow):
614 for x in range(ncol):
639 for x in range(ncol):
615
640
616 if counter >= self.nplots:
641 if counter >= self.nplots:
617 break
642 break
618
643
619 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
644 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
620
645
621 if showprofile:
646 if showprofile:
622 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
647 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
623
648
624 counter += 1
649 counter += 1
625
650
626 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
651 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
627 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
652 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
628 parameterIndex = None, onlyPositive = False,
653 parameterIndex = None, onlyPositive = False,
629 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
654 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
630 DOP = True,
655 DOP = True,
631 zlabel = "", parameterName = "", parameterObject = "data_param",
656 zlabel = "", parameterName = "", parameterObject = "data_param",
632 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
657 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
633 server=None, folder=None, username=None, password=None,
658 server=None, folder=None, username=None, password=None,
634 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
659 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
635
660
636 """
661 """
637
662
638 Input:
663 Input:
639 dataOut :
664 dataOut :
640 id :
665 id :
641 wintitle :
666 wintitle :
642 channelList :
667 channelList :
643 showProfile :
668 showProfile :
644 xmin : None,
669 xmin : None,
645 xmax : None,
670 xmax : None,
646 ymin : None,
671 ymin : None,
647 ymax : None,
672 ymax : None,
648 zmin : None,
673 zmin : None,
649 zmax : None
674 zmax : None
650 """
675 """
651
676
652 data_param = getattr(dataOut, parameterObject)
677 data_param = getattr(dataOut, parameterObject)
653
678
654 if channelList == None:
679 if channelList == None:
655 channelIndexList = numpy.arange(data_param.shape[0])
680 channelIndexList = numpy.arange(data_param.shape[0])
656 else:
681 else:
657 channelIndexList = numpy.array(channelList)
682 channelIndexList = numpy.array(channelList)
658
683
659 nchan = len(channelIndexList) #Number of channels being plotted
684 nchan = len(channelIndexList) #Number of channels being plotted
660
685
661 if nchan < 1:
686 if nchan < 1:
662 return
687 return
663
688
664 nGraphsByChannel = 0
689 nGraphsByChannel = 0
665
690
666 if SNR:
691 if SNR:
667 nGraphsByChannel += 1
692 nGraphsByChannel += 1
668 if DOP:
693 if DOP:
669 nGraphsByChannel += 1
694 nGraphsByChannel += 1
670
695
671 if nGraphsByChannel < 1:
696 if nGraphsByChannel < 1:
672 return
697 return
673
698
674 nplots = nGraphsByChannel*nchan
699 nplots = nGraphsByChannel*nchan
675
700
676 if timerange is not None:
701 if timerange is not None:
677 self.timerange = timerange
702 self.timerange = timerange
678
703
679 #tmin = None
704 #tmin = None
680 #tmax = None
705 #tmax = None
681 if parameterIndex == None:
706 if parameterIndex == None:
682 parameterIndex = 1
707 parameterIndex = 1
683
708
684 x = dataOut.getTimeRange1()
709 x = dataOut.getTimeRange1()
685 y = dataOut.heightList
710 y = dataOut.heightList
686 z = data_param[channelIndexList,parameterIndex,:].copy()
711 z = data_param[channelIndexList,parameterIndex,:].copy()
687
712
688 zRange = dataOut.abscissaList
713 zRange = dataOut.abscissaList
689 # nChannels = z.shape[0] #Number of wind dimensions estimated
714 # nChannels = z.shape[0] #Number of wind dimensions estimated
690 # thisDatetime = dataOut.datatime
715 # thisDatetime = dataOut.datatime
691
716
692 if dataOut.data_SNR is not None:
717 if dataOut.data_SNR is not None:
693 SNRarray = dataOut.data_SNR[channelIndexList,:]
718 SNRarray = dataOut.data_SNR[channelIndexList,:]
694 SNRdB = 10*numpy.log10(SNRarray)
719 SNRdB = 10*numpy.log10(SNRarray)
695 # SNRavgdB = 10*numpy.log10(SNRavg)
720 # SNRavgdB = 10*numpy.log10(SNRavg)
696 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
721 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
697 z[ind] = numpy.nan
722 z[ind] = numpy.nan
698
723
699 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
724 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
700 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
725 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
701 xlabel = ""
726 xlabel = ""
702 ylabel = "Range (Km)"
727 ylabel = "Range (Km)"
703
728
704 if (SNR and not onlySNR): nplots = 2*nplots
729 if (SNR and not onlySNR): nplots = 2*nplots
705
730
706 if onlyPositive:
731 if onlyPositive:
707 colormap = "jet"
732 colormap = "jet"
708 zmin = 0
733 zmin = 0
709 else: colormap = "RdBu_r"
734 else: colormap = "RdBu_r"
710
735
711 if not self.__isConfig:
736 if not self.__isConfig:
712
737
713 self.setup(id=id,
738 self.setup(id=id,
714 nplots=nplots,
739 nplots=nplots,
715 wintitle=wintitle,
740 wintitle=wintitle,
716 showprofile=showprofile,
741 showprofile=showprofile,
717 show=show)
742 show=show)
718
743
719 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
744 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
720
745
721 if ymin == None: ymin = numpy.nanmin(y)
746 if ymin == None: ymin = numpy.nanmin(y)
722 if ymax == None: ymax = numpy.nanmax(y)
747 if ymax == None: ymax = numpy.nanmax(y)
723 if zmin == None: zmin = numpy.nanmin(zRange)
748 if zmin == None: zmin = numpy.nanmin(zRange)
724 if zmax == None: zmax = numpy.nanmax(zRange)
749 if zmax == None: zmax = numpy.nanmax(zRange)
725
750
726 if SNR:
751 if SNR:
727 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
752 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
728 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
753 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
729
754
730 self.FTP_WEI = ftp_wei
755 self.FTP_WEI = ftp_wei
731 self.EXP_CODE = exp_code
756 self.EXP_CODE = exp_code
732 self.SUB_EXP_CODE = sub_exp_code
757 self.SUB_EXP_CODE = sub_exp_code
733 self.PLOT_POS = plot_pos
758 self.PLOT_POS = plot_pos
734
759
735 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
760 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
736 self.__isConfig = True
761 self.__isConfig = True
737 self.figfile = figfile
762 self.figfile = figfile
738
763
739 self.setWinTitle(title)
764 self.setWinTitle(title)
740
765
741 if ((self.xmax - x[1]) < (x[1]-x[0])):
766 if ((self.xmax - x[1]) < (x[1]-x[0])):
742 x[1] = self.xmax
767 x[1] = self.xmax
743
768
744 for i in range(nchan):
769 for i in range(nchan):
745
770
746 if (SNR and not onlySNR): j = 2*i
771 if (SNR and not onlySNR): j = 2*i
747 else: j = i
772 else: j = i
748
773
749 j = nGraphsByChannel*i
774 j = nGraphsByChannel*i
750
775
751 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
776 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
752 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
777 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
753
778
754 if not onlySNR:
779 if not onlySNR:
755 axes = self.axesList[j*self.__nsubplots]
780 axes = self.axesList[j*self.__nsubplots]
756 z1 = z[i,:].reshape((1,-1))
781 z1 = z[i,:].reshape((1,-1))
757 axes.pcolorbuffer(x, y, z1,
782 axes.pcolorbuffer(x, y, z1,
758 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
783 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
759 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
784 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
760 ticksize=9, cblabel=zlabel, cbsize="1%")
785 ticksize=9, cblabel=zlabel, cbsize="1%")
761
786
762 if DOP:
787 if DOP:
763 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
788 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
764
789
765 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
790 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
766 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
791 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
767 axes = self.axesList[j]
792 axes = self.axesList[j]
768 z1 = z[i,:].reshape((1,-1))
793 z1 = z[i,:].reshape((1,-1))
769 axes.pcolorbuffer(x, y, z1,
794 axes.pcolorbuffer(x, y, z1,
770 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
795 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
771 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
796 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
772 ticksize=9, cblabel=zlabel, cbsize="1%")
797 ticksize=9, cblabel=zlabel, cbsize="1%")
773
798
774 if SNR:
799 if SNR:
775 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
800 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
776 axes = self.axesList[(j)*self.__nsubplots]
801 axes = self.axesList[(j)*self.__nsubplots]
777 if not onlySNR:
802 if not onlySNR:
778 axes = self.axesList[(j + 1)*self.__nsubplots]
803 axes = self.axesList[(j + 1)*self.__nsubplots]
779
804
780 axes = self.axesList[(j + nGraphsByChannel-1)]
805 axes = self.axesList[(j + nGraphsByChannel-1)]
781
806
782 z1 = SNRdB[i,:].reshape((1,-1))
807 z1 = SNRdB[i,:].reshape((1,-1))
783 axes.pcolorbuffer(x, y, z1,
808 axes.pcolorbuffer(x, y, z1,
784 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
809 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
785 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
810 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
786 ticksize=9, cblabel=zlabel, cbsize="1%")
811 ticksize=9, cblabel=zlabel, cbsize="1%")
787
812
788
813
789
814
790 self.draw()
815 self.draw()
791
816
792 if x[1] >= self.axesList[0].xmax:
817 if x[1] >= self.axesList[0].xmax:
793 self.counter_imagwr = wr_period
818 self.counter_imagwr = wr_period
794 self.__isConfig = False
819 self.__isConfig = False
795 self.figfile = None
820 self.figfile = None
796
821
797 self.save(figpath=figpath,
822 self.save(figpath=figpath,
798 figfile=figfile,
823 figfile=figfile,
799 save=save,
824 save=save,
800 ftp=ftp,
825 ftp=ftp,
801 wr_period=wr_period,
826 wr_period=wr_period,
802 thisDatetime=thisDatetime,
827 thisDatetime=thisDatetime,
803 update_figfile=False)
828 update_figfile=False)
804
829
805 class SpectralFittingPlot(Figure):
830 class SpectralFittingPlot(Figure):
806
831
807 __isConfig = None
832 __isConfig = None
808 __nsubplots = None
833 __nsubplots = None
809
834
810 WIDTHPROF = None
835 WIDTHPROF = None
811 HEIGHTPROF = None
836 HEIGHTPROF = None
812 PREFIX = 'prm'
837 PREFIX = 'prm'
813
838
814
839
815 N = None
840 N = None
816 ippSeconds = None
841 ippSeconds = None
817
842
818 def __init__(self):
843 def __init__(self):
819 self.__isConfig = False
844 self.__isConfig = False
820 self.__nsubplots = 1
845 self.__nsubplots = 1
821
846
822 self.PLOT_CODE = SPECFIT_CODE
847 self.PLOT_CODE = SPECFIT_CODE
823
848
824 self.WIDTH = 450
849 self.WIDTH = 450
825 self.HEIGHT = 250
850 self.HEIGHT = 250
826 self.WIDTHPROF = 0
851 self.WIDTHPROF = 0
827 self.HEIGHTPROF = 0
852 self.HEIGHTPROF = 0
828
853
829 def getSubplots(self):
854 def getSubplots(self):
830
855
831 ncol = int(numpy.sqrt(self.nplots)+0.9)
856 ncol = int(numpy.sqrt(self.nplots)+0.9)
832 nrow = int(self.nplots*1./ncol + 0.9)
857 nrow = int(self.nplots*1./ncol + 0.9)
833
858
834 return nrow, ncol
859 return nrow, ncol
835
860
836 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
861 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
837
862
838 showprofile = False
863 showprofile = False
839 self.__showprofile = showprofile
864 self.__showprofile = showprofile
840 self.nplots = nplots
865 self.nplots = nplots
841
866
842 ncolspan = 5
867 ncolspan = 5
843 colspan = 4
868 colspan = 4
844 if showprofile:
869 if showprofile:
845 ncolspan = 5
870 ncolspan = 5
846 colspan = 4
871 colspan = 4
847 self.__nsubplots = 2
872 self.__nsubplots = 2
848
873
849 self.createFigure(id = id,
874 self.createFigure(id = id,
850 wintitle = wintitle,
875 wintitle = wintitle,
851 widthplot = self.WIDTH + self.WIDTHPROF,
876 widthplot = self.WIDTH + self.WIDTHPROF,
852 heightplot = self.HEIGHT + self.HEIGHTPROF,
877 heightplot = self.HEIGHT + self.HEIGHTPROF,
853 show=show)
878 show=show)
854
879
855 nrow, ncol = self.getSubplots()
880 nrow, ncol = self.getSubplots()
856
881
857 counter = 0
882 counter = 0
858 for y in range(nrow):
883 for y in range(nrow):
859 for x in range(ncol):
884 for x in range(ncol):
860
885
861 if counter >= self.nplots:
886 if counter >= self.nplots:
862 break
887 break
863
888
864 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
889 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
865
890
866 if showprofile:
891 if showprofile:
867 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
892 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
868
893
869 counter += 1
894 counter += 1
870
895
871 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
896 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
872 xmin=None, xmax=None, ymin=None, ymax=None,
897 xmin=None, xmax=None, ymin=None, ymax=None,
873 save=False, figpath='./', figfile=None, show=True):
898 save=False, figpath='./', figfile=None, show=True):
874
899
875 """
900 """
876
901
877 Input:
902 Input:
878 dataOut :
903 dataOut :
879 id :
904 id :
880 wintitle :
905 wintitle :
881 channelList :
906 channelList :
882 showProfile :
907 showProfile :
883 xmin : None,
908 xmin : None,
884 xmax : None,
909 xmax : None,
885 zmin : None,
910 zmin : None,
886 zmax : None
911 zmax : None
887 """
912 """
888
913
889 if cutHeight==None:
914 if cutHeight==None:
890 h=270
915 h=270
891 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
916 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
892 cutHeight = dataOut.heightList[heightindex]
917 cutHeight = dataOut.heightList[heightindex]
893
918
894 factor = dataOut.normFactor
919 factor = dataOut.normFactor
895 x = dataOut.abscissaList[:-1]
920 x = dataOut.abscissaList[:-1]
896 #y = dataOut.getHeiRange()
921 #y = dataOut.getHeiRange()
897
922
898 z = dataOut.data_pre[:,:,heightindex]/factor
923 z = dataOut.data_pre[:,:,heightindex]/factor
899 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
924 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
900 avg = numpy.average(z, axis=1)
925 avg = numpy.average(z, axis=1)
901 listChannels = z.shape[0]
926 listChannels = z.shape[0]
902
927
903 #Reconstruct Function
928 #Reconstruct Function
904 if fit==True:
929 if fit==True:
905 groupArray = dataOut.groupList
930 groupArray = dataOut.groupList
906 listChannels = groupArray.reshape((groupArray.size))
931 listChannels = groupArray.reshape((groupArray.size))
907 listChannels.sort()
932 listChannels.sort()
908 spcFitLine = numpy.zeros(z.shape)
933 spcFitLine = numpy.zeros(z.shape)
909 constants = dataOut.constants
934 constants = dataOut.constants
910
935
911 nGroups = groupArray.shape[0]
936 nGroups = groupArray.shape[0]
912 nChannels = groupArray.shape[1]
937 nChannels = groupArray.shape[1]
913 nProfiles = z.shape[1]
938 nProfiles = z.shape[1]
914
939
915 for f in range(nGroups):
940 for f in range(nGroups):
916 groupChann = groupArray[f,:]
941 groupChann = groupArray[f,:]
917 p = dataOut.data_param[f,:,heightindex]
942 p = dataOut.data_param[f,:,heightindex]
918 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
943 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
919 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
944 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
920 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
945 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
921 spcFitLine[groupChann,:] = fitLineAux
946 spcFitLine[groupChann,:] = fitLineAux
922 # spcFitLine = spcFitLine/factor
947 # spcFitLine = spcFitLine/factor
923
948
924 z = z[listChannels,:]
949 z = z[listChannels,:]
925 spcFitLine = spcFitLine[listChannels,:]
950 spcFitLine = spcFitLine[listChannels,:]
926 spcFitLinedB = 10*numpy.log10(spcFitLine)
951 spcFitLinedB = 10*numpy.log10(spcFitLine)
927
952
928 zdB = 10*numpy.log10(z)
953 zdB = 10*numpy.log10(z)
929 #thisDatetime = dataOut.datatime
954 #thisDatetime = dataOut.datatime
930 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
955 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
931 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
956 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
932 xlabel = "Velocity (m/s)"
957 xlabel = "Velocity (m/s)"
933 ylabel = "Spectrum"
958 ylabel = "Spectrum"
934
959
935 if not self.__isConfig:
960 if not self.__isConfig:
936
961
937 nplots = listChannels.size
962 nplots = listChannels.size
938
963
939 self.setup(id=id,
964 self.setup(id=id,
940 nplots=nplots,
965 nplots=nplots,
941 wintitle=wintitle,
966 wintitle=wintitle,
942 showprofile=showprofile,
967 showprofile=showprofile,
943 show=show)
968 show=show)
944
969
945 if xmin == None: xmin = numpy.nanmin(x)
970 if xmin == None: xmin = numpy.nanmin(x)
946 if xmax == None: xmax = numpy.nanmax(x)
971 if xmax == None: xmax = numpy.nanmax(x)
947 if ymin == None: ymin = numpy.nanmin(zdB)
972 if ymin == None: ymin = numpy.nanmin(zdB)
948 if ymax == None: ymax = numpy.nanmax(zdB)+2
973 if ymax == None: ymax = numpy.nanmax(zdB)+2
949
974
950 self.__isConfig = True
975 self.__isConfig = True
951
976
952 self.setWinTitle(title)
977 self.setWinTitle(title)
953 for i in range(self.nplots):
978 for i in range(self.nplots):
954 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
979 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
955 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
980 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
956 axes = self.axesList[i*self.__nsubplots]
981 axes = self.axesList[i*self.__nsubplots]
957 if fit == False:
982 if fit == False:
958 axes.pline(x, zdB[i,:],
983 axes.pline(x, zdB[i,:],
959 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
984 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
960 xlabel=xlabel, ylabel=ylabel, title=title
985 xlabel=xlabel, ylabel=ylabel, title=title
961 )
986 )
962 if fit == True:
987 if fit == True:
963 fitline=spcFitLinedB[i,:]
988 fitline=spcFitLinedB[i,:]
964 y=numpy.vstack([zdB[i,:],fitline] )
989 y=numpy.vstack([zdB[i,:],fitline] )
965 legendlabels=['Data','Fitting']
990 legendlabels=['Data','Fitting']
966 axes.pmultilineyaxis(x, y,
991 axes.pmultilineyaxis(x, y,
967 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
992 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
968 xlabel=xlabel, ylabel=ylabel, title=title,
993 xlabel=xlabel, ylabel=ylabel, title=title,
969 legendlabels=legendlabels, marker=None,
994 legendlabels=legendlabels, marker=None,
970 linestyle='solid', grid='both')
995 linestyle='solid', grid='both')
971
996
972 self.draw()
997 self.draw()
973
998
974 self.save(figpath=figpath,
999 self.save(figpath=figpath,
975 figfile=figfile,
1000 figfile=figfile,
976 save=save,
1001 save=save,
977 ftp=ftp,
1002 ftp=ftp,
978 wr_period=wr_period,
1003 wr_period=wr_period,
979 thisDatetime=thisDatetime)
1004 thisDatetime=thisDatetime)
980
1005
981
1006
982 class EWDriftsPlot(Figure):
1007 class EWDriftsPlot(Figure):
983
1008
984 __isConfig = None
1009 __isConfig = None
985 __nsubplots = None
1010 __nsubplots = None
986
1011
987 WIDTHPROF = None
1012 WIDTHPROF = None
988 HEIGHTPROF = None
1013 HEIGHTPROF = None
989 PREFIX = 'drift'
1014 PREFIX = 'drift'
990
1015
991 def __init__(self):
1016 def __init__(self):
992
1017
993 self.timerange = 2*60*60
1018 self.timerange = 2*60*60
994 self.isConfig = False
1019 self.isConfig = False
995 self.__nsubplots = 1
1020 self.__nsubplots = 1
996
1021
997 self.WIDTH = 800
1022 self.WIDTH = 800
998 self.HEIGHT = 150
1023 self.HEIGHT = 150
999 self.WIDTHPROF = 120
1024 self.WIDTHPROF = 120
1000 self.HEIGHTPROF = 0
1025 self.HEIGHTPROF = 0
1001 self.counter_imagwr = 0
1026 self.counter_imagwr = 0
1002
1027
1003 self.PLOT_CODE = EWDRIFT_CODE
1028 self.PLOT_CODE = EWDRIFT_CODE
1004
1029
1005 self.FTP_WEI = None
1030 self.FTP_WEI = None
1006 self.EXP_CODE = None
1031 self.EXP_CODE = None
1007 self.SUB_EXP_CODE = None
1032 self.SUB_EXP_CODE = None
1008 self.PLOT_POS = None
1033 self.PLOT_POS = None
1009 self.tmin = None
1034 self.tmin = None
1010 self.tmax = None
1035 self.tmax = None
1011
1036
1012 self.xmin = None
1037 self.xmin = None
1013 self.xmax = None
1038 self.xmax = None
1014
1039
1015 self.figfile = None
1040 self.figfile = None
1016
1041
1017 def getSubplots(self):
1042 def getSubplots(self):
1018
1043
1019 ncol = 1
1044 ncol = 1
1020 nrow = self.nplots
1045 nrow = self.nplots
1021
1046
1022 return nrow, ncol
1047 return nrow, ncol
1023
1048
1024 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1049 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1025
1050
1026 self.__showprofile = showprofile
1051 self.__showprofile = showprofile
1027 self.nplots = nplots
1052 self.nplots = nplots
1028
1053
1029 ncolspan = 1
1054 ncolspan = 1
1030 colspan = 1
1055 colspan = 1
1031
1056
1032 self.createFigure(id = id,
1057 self.createFigure(id = id,
1033 wintitle = wintitle,
1058 wintitle = wintitle,
1034 widthplot = self.WIDTH + self.WIDTHPROF,
1059 widthplot = self.WIDTH + self.WIDTHPROF,
1035 heightplot = self.HEIGHT + self.HEIGHTPROF,
1060 heightplot = self.HEIGHT + self.HEIGHTPROF,
1036 show=show)
1061 show=show)
1037
1062
1038 nrow, ncol = self.getSubplots()
1063 nrow, ncol = self.getSubplots()
1039
1064
1040 counter = 0
1065 counter = 0
1041 for y in range(nrow):
1066 for y in range(nrow):
1042 if counter >= self.nplots:
1067 if counter >= self.nplots:
1043 break
1068 break
1044
1069
1045 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1070 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1046 counter += 1
1071 counter += 1
1047
1072
1048 def run(self, dataOut, id, wintitle="", channelList=None,
1073 def run(self, dataOut, id, wintitle="", channelList=None,
1049 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1074 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1050 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1075 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1051 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1076 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1052 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1077 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1053 server=None, folder=None, username=None, password=None,
1078 server=None, folder=None, username=None, password=None,
1054 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1079 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1055 """
1080 """
1056
1081
1057 Input:
1082 Input:
1058 dataOut :
1083 dataOut :
1059 id :
1084 id :
1060 wintitle :
1085 wintitle :
1061 channelList :
1086 channelList :
1062 showProfile :
1087 showProfile :
1063 xmin : None,
1088 xmin : None,
1064 xmax : None,
1089 xmax : None,
1065 ymin : None,
1090 ymin : None,
1066 ymax : None,
1091 ymax : None,
1067 zmin : None,
1092 zmin : None,
1068 zmax : None
1093 zmax : None
1069 """
1094 """
1070
1095
1071 if timerange is not None:
1096 if timerange is not None:
1072 self.timerange = timerange
1097 self.timerange = timerange
1073
1098
1074 tmin = None
1099 tmin = None
1075 tmax = None
1100 tmax = None
1076
1101
1077 x = dataOut.getTimeRange1()
1102 x = dataOut.getTimeRange1()
1078 # y = dataOut.heightList
1103 # y = dataOut.heightList
1079 y = dataOut.heightList
1104 y = dataOut.heightList
1080
1105
1081 z = dataOut.data_output
1106 z = dataOut.data_output
1082 nplots = z.shape[0] #Number of wind dimensions estimated
1107 nplots = z.shape[0] #Number of wind dimensions estimated
1083 nplotsw = nplots
1108 nplotsw = nplots
1084
1109
1085 #If there is a SNR function defined
1110 #If there is a SNR function defined
1086 if dataOut.data_SNR is not None:
1111 if dataOut.data_SNR is not None:
1087 nplots += 1
1112 nplots += 1
1088 SNR = dataOut.data_SNR
1113 SNR = dataOut.data_SNR
1089
1114
1090 if SNR_1:
1115 if SNR_1:
1091 SNR += 1
1116 SNR += 1
1092
1117
1093 SNRavg = numpy.average(SNR, axis=0)
1118 SNRavg = numpy.average(SNR, axis=0)
1094
1119
1095 SNRdB = 10*numpy.log10(SNR)
1120 SNRdB = 10*numpy.log10(SNR)
1096 SNRavgdB = 10*numpy.log10(SNRavg)
1121 SNRavgdB = 10*numpy.log10(SNRavg)
1097
1122
1098 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1123 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1099
1124
1100 for i in range(nplotsw):
1125 for i in range(nplotsw):
1101 z[i,ind] = numpy.nan
1126 z[i,ind] = numpy.nan
1102
1127
1103
1128
1104 showprofile = False
1129 showprofile = False
1105 # thisDatetime = dataOut.datatime
1130 # thisDatetime = dataOut.datatime
1106 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1131 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1107 title = wintitle + " EW Drifts"
1132 title = wintitle + " EW Drifts"
1108 xlabel = ""
1133 xlabel = ""
1109 ylabel = "Height (Km)"
1134 ylabel = "Height (Km)"
1110
1135
1111 if not self.__isConfig:
1136 if not self.__isConfig:
1112
1137
1113 self.setup(id=id,
1138 self.setup(id=id,
1114 nplots=nplots,
1139 nplots=nplots,
1115 wintitle=wintitle,
1140 wintitle=wintitle,
1116 showprofile=showprofile,
1141 showprofile=showprofile,
1117 show=show)
1142 show=show)
1118
1143
1119 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1144 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1120
1145
1121 if ymin == None: ymin = numpy.nanmin(y)
1146 if ymin == None: ymin = numpy.nanmin(y)
1122 if ymax == None: ymax = numpy.nanmax(y)
1147 if ymax == None: ymax = numpy.nanmax(y)
1123
1148
1124 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1149 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1125 if zminZonal == None: zminZonal = -zmaxZonal
1150 if zminZonal == None: zminZonal = -zmaxZonal
1126 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1151 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1127 if zminVertical == None: zminVertical = -zmaxVertical
1152 if zminVertical == None: zminVertical = -zmaxVertical
1128
1153
1129 if dataOut.data_SNR is not None:
1154 if dataOut.data_SNR is not None:
1130 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1155 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1131 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1156 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1132
1157
1133 self.FTP_WEI = ftp_wei
1158 self.FTP_WEI = ftp_wei
1134 self.EXP_CODE = exp_code
1159 self.EXP_CODE = exp_code
1135 self.SUB_EXP_CODE = sub_exp_code
1160 self.SUB_EXP_CODE = sub_exp_code
1136 self.PLOT_POS = plot_pos
1161 self.PLOT_POS = plot_pos
1137
1162
1138 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1163 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1139 self.__isConfig = True
1164 self.__isConfig = True
1140
1165
1141
1166
1142 self.setWinTitle(title)
1167 self.setWinTitle(title)
1143
1168
1144 if ((self.xmax - x[1]) < (x[1]-x[0])):
1169 if ((self.xmax - x[1]) < (x[1]-x[0])):
1145 x[1] = self.xmax
1170 x[1] = self.xmax
1146
1171
1147 strWind = ['Zonal','Vertical']
1172 strWind = ['Zonal','Vertical']
1148 strCb = 'Velocity (m/s)'
1173 strCb = 'Velocity (m/s)'
1149 zmaxVector = [zmaxZonal, zmaxVertical]
1174 zmaxVector = [zmaxZonal, zmaxVertical]
1150 zminVector = [zminZonal, zminVertical]
1175 zminVector = [zminZonal, zminVertical]
1151
1176
1152 for i in range(nplotsw):
1177 for i in range(nplotsw):
1153
1178
1154 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1179 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1155 axes = self.axesList[i*self.__nsubplots]
1180 axes = self.axesList[i*self.__nsubplots]
1156
1181
1157 z1 = z[i,:].reshape((1,-1))
1182 z1 = z[i,:].reshape((1,-1))
1158
1183
1159 axes.pcolorbuffer(x, y, z1,
1184 axes.pcolorbuffer(x, y, z1,
1160 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1185 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1161 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1186 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1162 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1187 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1163
1188
1164 if dataOut.data_SNR is not None:
1189 if dataOut.data_SNR is not None:
1165 i += 1
1190 i += 1
1166 if SNR_1:
1191 if SNR_1:
1167 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1192 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1168 else:
1193 else:
1169 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1194 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1170 axes = self.axesList[i*self.__nsubplots]
1195 axes = self.axesList[i*self.__nsubplots]
1171 SNRavgdB = SNRavgdB.reshape((1,-1))
1196 SNRavgdB = SNRavgdB.reshape((1,-1))
1172
1197
1173 axes.pcolorbuffer(x, y, SNRavgdB,
1198 axes.pcolorbuffer(x, y, SNRavgdB,
1174 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1199 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1175 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1200 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1176 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1201 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1177
1202
1178 self.draw()
1203 self.draw()
1179
1204
1180 if x[1] >= self.axesList[0].xmax:
1205 if x[1] >= self.axesList[0].xmax:
1181 self.counter_imagwr = wr_period
1206 self.counter_imagwr = wr_period
1182 self.__isConfig = False
1207 self.__isConfig = False
1183 self.figfile = None
1208 self.figfile = None
1184
1209
1185
1210
1186
1211
1187
1212
1188 class PhasePlot(Figure):
1213 class PhasePlot(Figure):
1189
1214
1190 __isConfig = None
1215 __isConfig = None
1191 __nsubplots = None
1216 __nsubplots = None
1192
1217
1193 PREFIX = 'mphase'
1218 PREFIX = 'mphase'
1194
1219
1195 def __init__(self):
1220 def __init__(self):
1196
1221
1197 self.timerange = 24*60*60
1222 self.timerange = 24*60*60
1198 self.__isConfig = False
1223 self.__isConfig = False
1199 self.__nsubplots = 1
1224 self.__nsubplots = 1
1200 self.counter_imagwr = 0
1225 self.counter_imagwr = 0
1201 self.WIDTH = 600
1226 self.WIDTH = 600
1202 self.HEIGHT = 300
1227 self.HEIGHT = 300
1203 self.WIDTHPROF = 120
1228 self.WIDTHPROF = 120
1204 self.HEIGHTPROF = 0
1229 self.HEIGHTPROF = 0
1205 self.xdata = None
1230 self.xdata = None
1206 self.ydata = None
1231 self.ydata = None
1207
1232
1208 self.PLOT_CODE = MPHASE_CODE
1233 self.PLOT_CODE = MPHASE_CODE
1209
1234
1210 self.FTP_WEI = None
1235 self.FTP_WEI = None
1211 self.EXP_CODE = None
1236 self.EXP_CODE = None
1212 self.SUB_EXP_CODE = None
1237 self.SUB_EXP_CODE = None
1213 self.PLOT_POS = None
1238 self.PLOT_POS = None
1214
1239
1215
1240
1216 self.filename_phase = None
1241 self.filename_phase = None
1217
1242
1218 self.figfile = None
1243 self.figfile = None
1219
1244
1220 def getSubplots(self):
1245 def getSubplots(self):
1221
1246
1222 ncol = 1
1247 ncol = 1
1223 nrow = 1
1248 nrow = 1
1224
1249
1225 return nrow, ncol
1250 return nrow, ncol
1226
1251
1227 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1252 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1228
1253
1229 self.__showprofile = showprofile
1254 self.__showprofile = showprofile
1230 self.nplots = nplots
1255 self.nplots = nplots
1231
1256
1232 ncolspan = 7
1257 ncolspan = 7
1233 colspan = 6
1258 colspan = 6
1234 self.__nsubplots = 2
1259 self.__nsubplots = 2
1235
1260
1236 self.createFigure(id = id,
1261 self.createFigure(id = id,
1237 wintitle = wintitle,
1262 wintitle = wintitle,
1238 widthplot = self.WIDTH+self.WIDTHPROF,
1263 widthplot = self.WIDTH+self.WIDTHPROF,
1239 heightplot = self.HEIGHT+self.HEIGHTPROF,
1264 heightplot = self.HEIGHT+self.HEIGHTPROF,
1240 show=show)
1265 show=show)
1241
1266
1242 nrow, ncol = self.getSubplots()
1267 nrow, ncol = self.getSubplots()
1243
1268
1244 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1269 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1245
1270
1246
1271
1247 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1272 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1248 xmin=None, xmax=None, ymin=None, ymax=None,
1273 xmin=None, xmax=None, ymin=None, ymax=None,
1249 timerange=None,
1274 timerange=None,
1250 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1275 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1251 server=None, folder=None, username=None, password=None,
1276 server=None, folder=None, username=None, password=None,
1252 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1277 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1253
1278
1254
1279
1255 tmin = None
1280 tmin = None
1256 tmax = None
1281 tmax = None
1257 x = dataOut.getTimeRange1()
1282 x = dataOut.getTimeRange1()
1258 y = dataOut.getHeiRange()
1283 y = dataOut.getHeiRange()
1259
1284
1260
1285
1261 #thisDatetime = dataOut.datatime
1286 #thisDatetime = dataOut.datatime
1262 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1287 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1263 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1288 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1264 xlabel = "Local Time"
1289 xlabel = "Local Time"
1265 ylabel = "Phase"
1290 ylabel = "Phase"
1266
1291
1267
1292
1268 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1293 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1269 phase_beacon = dataOut.data_output
1294 phase_beacon = dataOut.data_output
1270
1295 update_figfile = False
1271
1296
1272 if not self.__isConfig:
1297 if not self.__isConfig:
1273
1298
1274 self.nplots = phase_beacon.size
1299 self.nplots = phase_beacon.size
1275
1300
1276 self.setup(id=id,
1301 self.setup(id=id,
1277 nplots=self.nplots,
1302 nplots=self.nplots,
1278 wintitle=wintitle,
1303 wintitle=wintitle,
1279 showprofile=showprofile,
1304 showprofile=showprofile,
1280 show=show)
1305 show=show)
1281
1306
1282 if timerange is not None:
1307 if timerange is not None:
1283 self.timerange = timerange
1308 self.timerange = timerange
1284
1309
1285 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1310 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1286
1311
1287 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1312 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1288 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1313 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1289
1314
1290 self.FTP_WEI = ftp_wei
1315 self.FTP_WEI = ftp_wei
1291 self.EXP_CODE = exp_code
1316 self.EXP_CODE = exp_code
1292 self.SUB_EXP_CODE = sub_exp_code
1317 self.SUB_EXP_CODE = sub_exp_code
1293 self.PLOT_POS = plot_pos
1318 self.PLOT_POS = plot_pos
1294
1319
1295 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1320 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1296 self.__isConfig = True
1321 self.__isConfig = True
1297 self.figfile = figfile
1322 self.figfile = figfile
1298 self.xdata = numpy.array([])
1323 self.xdata = numpy.array([])
1299 self.ydata = numpy.array([])
1324 self.ydata = numpy.array([])
1300
1325
1301 #open file beacon phase
1326 #open file beacon phase
1302 path = '%s%03d' %(self.PREFIX, self.id)
1327 path = '%s%03d' %(self.PREFIX, self.id)
1303 beacon_file = os.path.join(path,'%s.txt'%self.name)
1328 beacon_file = os.path.join(path,'%s.txt'%self.name)
1304 self.filename_phase = os.path.join(figpath,beacon_file)
1329 self.filename_phase = os.path.join(figpath,beacon_file)
1305 #self.save_phase(self.filename_phase)
1330 update_figfile = True
1306
1331
1307
1332
1308 #store data beacon phase
1333 #store data beacon phase
1309 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1334 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1310
1335
1311 self.setWinTitle(title)
1336 self.setWinTitle(title)
1312
1337
1313
1338
1314 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1339 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1315
1340
1316 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1341 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1317
1342
1318 axes = self.axesList[0]
1343 axes = self.axesList[0]
1319
1344
1320 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1345 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1321
1346
1322 if len(self.ydata)==0:
1347 if len(self.ydata)==0:
1323 self.ydata = phase_beacon.reshape(-1,1)
1348 self.ydata = phase_beacon.reshape(-1,1)
1324 else:
1349 else:
1325 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1350 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1326
1351
1327
1352
1328 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1353 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1329 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1354 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1330 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1355 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1331 XAxisAsTime=True, grid='both'
1356 XAxisAsTime=True, grid='both'
1332 )
1357 )
1333
1358
1334 self.draw()
1359 self.draw()
1335
1360
1336 if x[1] >= self.axesList[0].xmax:
1361 if dataOut.ltctime >= self.xmax:
1337 self.counter_imagwr = wr_period
1362 self.counter_imagwr = wr_period
1338 del self.xdata
1339 del self.ydata
1340 self.__isConfig = False
1363 self.__isConfig = False
1341
1364 update_figfile = True
1342 # if self.figfile == None:
1343 # str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1344 # self.figfile = self.getFilename(name = str_datetime)
1345
1346 # if figpath != '':
1347 # self.counter_imagwr += 1
1348 # if (self.counter_imagwr>=wr_period):
1349 # # store png plot to local folder
1350 # self.saveFigure(figpath, self.figfile)
1351 # # store png plot to FTP server according to RT-Web format
1352 # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1353 # ftp_filename = os.path.join(figpath, name)
1354 # self.saveFigure(figpath, ftp_filename)
1355 # self.counter_imagwr = 0
1356 # self.figfile = None
1357
1365
1358 self.save(figpath=figpath,
1366 self.save(figpath=figpath,
1359 figfile=figfile,
1367 figfile=figfile,
1360 save=save,
1368 save=save,
1361 ftp=ftp,
1369 ftp=ftp,
1362 wr_period=wr_period,
1370 wr_period=wr_period,
1363 thisDatetime=thisDatetime,
1371 thisDatetime=thisDatetime,
1364 update_figfile=False)
1372 update_figfile=update_figfile)
General Comments 0
You need to be logged in to leave comments. Login now