@@ -1,793 +1,774 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | |
|
5 | 5 | from figure import Figure, isRealtime |
|
6 | 6 | |
|
7 | 7 | class MomentsPlot(Figure): |
|
8 | 8 | |
|
9 | 9 | isConfig = None |
|
10 | 10 | __nsubplots = None |
|
11 | 11 | |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'prm' |
|
15 | 15 | |
|
16 | 16 | def __init__(self): |
|
17 | 17 | |
|
18 | 18 | self.isConfig = False |
|
19 | 19 | self.__nsubplots = 1 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 280 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 120 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | self.counter_imagwr = 0 |
|
26 | 26 | |
|
27 | 27 | self.PLOT_CODE = 1 |
|
28 | 28 | self.FTP_WEI = None |
|
29 | 29 | self.EXP_CODE = None |
|
30 | 30 | self.SUB_EXP_CODE = None |
|
31 | 31 | self.PLOT_POS = None |
|
32 | 32 | |
|
33 | 33 | def getSubplots(self): |
|
34 | 34 | |
|
35 | 35 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
36 | 36 | nrow = int(self.nplots*1./ncol + 0.9) |
|
37 | 37 | |
|
38 | 38 | return nrow, ncol |
|
39 | 39 | |
|
40 | 40 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
41 | 41 | |
|
42 | 42 | self.__showprofile = showprofile |
|
43 | 43 | self.nplots = nplots |
|
44 | 44 | |
|
45 | 45 | ncolspan = 1 |
|
46 | 46 | colspan = 1 |
|
47 | 47 | if showprofile: |
|
48 | 48 | ncolspan = 3 |
|
49 | 49 | colspan = 2 |
|
50 | 50 | self.__nsubplots = 2 |
|
51 | 51 | |
|
52 | 52 | self.createFigure(id = id, |
|
53 | 53 | wintitle = wintitle, |
|
54 | 54 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
55 | 55 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
56 | 56 | show=show) |
|
57 | 57 | |
|
58 | 58 | nrow, ncol = self.getSubplots() |
|
59 | 59 | |
|
60 | 60 | counter = 0 |
|
61 | 61 | for y in range(nrow): |
|
62 | 62 | for x in range(ncol): |
|
63 | 63 | |
|
64 | 64 | if counter >= self.nplots: |
|
65 | 65 | break |
|
66 | 66 | |
|
67 | 67 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
68 | 68 | |
|
69 | 69 | if showprofile: |
|
70 | 70 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
71 | 71 | |
|
72 | 72 | counter += 1 |
|
73 | 73 | |
|
74 | 74 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
75 | 75 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
76 | 76 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
77 | 77 | server=None, folder=None, username=None, password=None, |
|
78 | 78 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
79 | 79 | |
|
80 | 80 | """ |
|
81 | 81 | |
|
82 | 82 | Input: |
|
83 | 83 | dataOut : |
|
84 | 84 | id : |
|
85 | 85 | wintitle : |
|
86 | 86 | channelList : |
|
87 | 87 | showProfile : |
|
88 | 88 | xmin : None, |
|
89 | 89 | xmax : None, |
|
90 | 90 | ymin : None, |
|
91 | 91 | ymax : None, |
|
92 | 92 | zmin : None, |
|
93 | 93 | zmax : None |
|
94 | 94 | """ |
|
95 | 95 | |
|
96 | 96 | if dataOut.flagNoData: |
|
97 | 97 | return None |
|
98 | 98 | |
|
99 | 99 | if realtime: |
|
100 | 100 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
101 | 101 | print 'Skipping this plot function' |
|
102 | 102 | return |
|
103 | 103 | |
|
104 | 104 | if channelList == None: |
|
105 | 105 | channelIndexList = dataOut.channelIndexList |
|
106 | 106 | else: |
|
107 | 107 | channelIndexList = [] |
|
108 | 108 | for channel in channelList: |
|
109 | 109 | if channel not in dataOut.channelList: |
|
110 | 110 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
111 | 111 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
112 | 112 | |
|
113 | 113 | factor = dataOut.normFactor |
|
114 | 114 | x = dataOut.abscissaRange |
|
115 | 115 | y = dataOut.heightRange |
|
116 | 116 | |
|
117 | 117 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
118 | 118 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
119 | 119 | avg = numpy.average(z, axis=1) |
|
120 | 120 | noise = dataOut.noise/factor |
|
121 | 121 | |
|
122 | 122 | zdB = 10*numpy.log10(z) |
|
123 | 123 | avgdB = 10*numpy.log10(avg) |
|
124 | 124 | noisedB = 10*numpy.log10(noise) |
|
125 | 125 | |
|
126 | 126 | #thisDatetime = dataOut.datatime |
|
127 | 127 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
128 | 128 | title = wintitle + " Parameters" |
|
129 | 129 | xlabel = "Velocity (m/s)" |
|
130 | 130 | ylabel = "Range (Km)" |
|
131 | 131 | |
|
132 | 132 | if not self.isConfig: |
|
133 | 133 | |
|
134 | 134 | nplots = len(channelIndexList) |
|
135 | 135 | |
|
136 | 136 | self.setup(id=id, |
|
137 | 137 | nplots=nplots, |
|
138 | 138 | wintitle=wintitle, |
|
139 | 139 | showprofile=showprofile, |
|
140 | 140 | show=show) |
|
141 | 141 | |
|
142 | 142 | if xmin == None: xmin = numpy.nanmin(x) |
|
143 | 143 | if xmax == None: xmax = numpy.nanmax(x) |
|
144 | 144 | if ymin == None: ymin = numpy.nanmin(y) |
|
145 | 145 | if ymax == None: ymax = numpy.nanmax(y) |
|
146 | 146 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
147 | 147 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
148 | 148 | |
|
149 | 149 | self.FTP_WEI = ftp_wei |
|
150 | 150 | self.EXP_CODE = exp_code |
|
151 | 151 | self.SUB_EXP_CODE = sub_exp_code |
|
152 | 152 | self.PLOT_POS = plot_pos |
|
153 | 153 | |
|
154 | 154 | self.isConfig = True |
|
155 | 155 | |
|
156 | 156 | self.setWinTitle(title) |
|
157 | 157 | |
|
158 | 158 | for i in range(self.nplots): |
|
159 | 159 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
160 | 160 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
161 | 161 | axes = self.axesList[i*self.__nsubplots] |
|
162 | 162 | axes.pcolor(x, y, zdB[i,:,:], |
|
163 | 163 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
164 | 164 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
165 | 165 | ticksize=9, cblabel='') |
|
166 | 166 | #Mean Line |
|
167 | 167 | mean = dataOut.data_param[i, 1, :] |
|
168 | 168 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
169 | 169 | |
|
170 | 170 | if self.__showprofile: |
|
171 | 171 | axes = self.axesList[i*self.__nsubplots +1] |
|
172 | 172 | axes.pline(avgdB[i], y, |
|
173 | 173 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
174 | 174 | xlabel='dB', ylabel='', title='', |
|
175 | 175 | ytick_visible=False, |
|
176 | 176 | grid='x') |
|
177 | 177 | |
|
178 | 178 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
179 | 179 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
180 | 180 | |
|
181 | 181 | self.draw() |
|
182 | 182 | |
|
183 | 183 | if figfile == None: |
|
184 | 184 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
185 | 185 | figfile = self.getFilename(name = str_datetime) |
|
186 | 186 | |
|
187 | 187 | if figpath != '': |
|
188 | 188 | self.counter_imagwr += 1 |
|
189 | 189 | if (self.counter_imagwr>=wr_period): |
|
190 | 190 | # store png plot to local folder |
|
191 | 191 | self.saveFigure(figpath, figfile) |
|
192 | 192 | # store png plot to FTP server according to RT-Web format |
|
193 | 193 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
194 | 194 | ftp_filename = os.path.join(figpath, name) |
|
195 | 195 | self.saveFigure(figpath, ftp_filename) |
|
196 | 196 | self.counter_imagwr = 0 |
|
197 | 197 | |
|
198 | 198 | class SkyMapPlot(Figure): |
|
199 | 199 | |
|
200 | 200 | __isConfig = None |
|
201 | 201 | __nsubplots = None |
|
202 | 202 | |
|
203 | 203 | WIDTHPROF = None |
|
204 | 204 | HEIGHTPROF = None |
|
205 | 205 | PREFIX = 'prm' |
|
206 | 206 | |
|
207 | 207 | def __init__(self): |
|
208 | 208 | |
|
209 | 209 | self.__isConfig = False |
|
210 | 210 | self.__nsubplots = 1 |
|
211 | 211 | |
|
212 | 212 | # self.WIDTH = 280 |
|
213 | 213 | # self.HEIGHT = 250 |
|
214 | 214 | self.WIDTH = 600 |
|
215 | 215 | self.HEIGHT = 600 |
|
216 | 216 | self.WIDTHPROF = 120 |
|
217 | 217 | self.HEIGHTPROF = 0 |
|
218 | 218 | self.counter_imagwr = 0 |
|
219 | 219 | |
|
220 | 220 | self.PLOT_CODE = 1 |
|
221 | 221 | self.FTP_WEI = None |
|
222 | 222 | self.EXP_CODE = None |
|
223 | 223 | self.SUB_EXP_CODE = None |
|
224 | 224 | self.PLOT_POS = None |
|
225 | 225 | |
|
226 | 226 | def getSubplots(self): |
|
227 | 227 | |
|
228 | 228 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
229 | 229 | nrow = int(self.nplots*1./ncol + 0.9) |
|
230 | 230 | |
|
231 | 231 | return nrow, ncol |
|
232 | 232 | |
|
233 | 233 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
234 | 234 | |
|
235 | 235 | self.__showprofile = showprofile |
|
236 | 236 | self.nplots = nplots |
|
237 | 237 | |
|
238 | 238 | ncolspan = 1 |
|
239 | 239 | colspan = 1 |
|
240 | 240 | |
|
241 | 241 | self.createFigure(id = id, |
|
242 | 242 | wintitle = wintitle, |
|
243 | 243 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
244 | 244 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
245 | 245 | show=show) |
|
246 | 246 | |
|
247 | 247 | nrow, ncol = 1,1 |
|
248 | 248 | counter = 0 |
|
249 | 249 | x = 0 |
|
250 | 250 | y = 0 |
|
251 | 251 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
252 | 252 | |
|
253 | 253 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
254 | 254 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
255 | 255 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
256 | 256 | server=None, folder=None, username=None, password=None, |
|
257 | 257 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
258 | 258 | |
|
259 | 259 | """ |
|
260 | 260 | |
|
261 | 261 | Input: |
|
262 | 262 | dataOut : |
|
263 | 263 | id : |
|
264 | 264 | wintitle : |
|
265 | 265 | channelList : |
|
266 | 266 | showProfile : |
|
267 | 267 | xmin : None, |
|
268 | 268 | xmax : None, |
|
269 | 269 | ymin : None, |
|
270 | 270 | ymax : None, |
|
271 | 271 | zmin : None, |
|
272 | 272 | zmax : None |
|
273 | 273 | """ |
|
274 | 274 | |
|
275 | 275 | arrayParameters = dataOut.data_param |
|
276 | 276 | error = arrayParameters[:,-1] |
|
277 | 277 | indValid = numpy.where(error == 0)[0] |
|
278 | 278 | finalMeteor = arrayParameters[indValid,:] |
|
279 | 279 | finalAzimuth = finalMeteor[:,4] |
|
280 | 280 | finalZenith = finalMeteor[:,5] |
|
281 | 281 | |
|
282 | 282 | x = finalAzimuth*numpy.pi/180 |
|
283 | 283 | y = finalZenith |
|
284 | 284 | |
|
285 | 285 | |
|
286 | 286 | #thisDatetime = dataOut.datatime |
|
287 | 287 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
288 | 288 | title = wintitle + " Parameters" |
|
289 | 289 | xlabel = "Zonal Zenith Angle (deg) " |
|
290 | 290 | ylabel = "Meridional Zenith Angle (deg)" |
|
291 | 291 | |
|
292 | 292 | if not self.__isConfig: |
|
293 | 293 | |
|
294 | 294 | nplots = 1 |
|
295 | 295 | |
|
296 | 296 | self.setup(id=id, |
|
297 | 297 | nplots=nplots, |
|
298 | 298 | wintitle=wintitle, |
|
299 | 299 | showprofile=showprofile, |
|
300 | 300 | show=show) |
|
301 | 301 | |
|
302 | 302 | self.FTP_WEI = ftp_wei |
|
303 | 303 | self.EXP_CODE = exp_code |
|
304 | 304 | self.SUB_EXP_CODE = sub_exp_code |
|
305 | 305 | self.PLOT_POS = plot_pos |
|
306 | 306 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
307 | 307 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
308 | 308 | self.__isConfig = True |
|
309 | 309 | |
|
310 | 310 | self.setWinTitle(title) |
|
311 | 311 | |
|
312 | 312 | i = 0 |
|
313 | 313 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
314 | 314 | |
|
315 | 315 | axes = self.axesList[i*self.__nsubplots] |
|
316 | 316 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
317 | 317 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
318 | 318 | axes.polar(x, y, |
|
319 | 319 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
320 | 320 | ticksize=9, cblabel='') |
|
321 | 321 | |
|
322 | 322 | self.draw() |
|
323 | 323 | |
|
324 | 324 | if save: |
|
325 | 325 | |
|
326 | 326 | self.counter_imagwr += 1 |
|
327 | 327 | if (self.counter_imagwr==wr_period): |
|
328 | 328 | |
|
329 | 329 | if figfile == None: |
|
330 | 330 | figfile = self.getFilename(name = self.name) |
|
331 | 331 | self.saveFigure(figpath, figfile) |
|
332 | 332 | |
|
333 | 333 | if ftp: |
|
334 | 334 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
335 | 335 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
336 | 336 | path = '%s%03d' %(self.PREFIX, self.id) |
|
337 | 337 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
338 | 338 | self.saveFigure(figpath, ftp_file) |
|
339 | 339 | ftp_filename = os.path.join(figpath,ftp_file) |
|
340 | 340 | |
|
341 | 341 | |
|
342 | 342 | try: |
|
343 | 343 | self.sendByFTP(ftp_filename, server, folder, username, password) |
|
344 | 344 | except: |
|
345 | 345 | self.counter_imagwr = 0 |
|
346 | 346 | raise ValueError, 'Error FTP' |
|
347 | 347 | |
|
348 | 348 | self.counter_imagwr = 0 |
|
349 | 349 | |
|
350 | 350 | |
|
351 | 351 | class WindProfilerPlot(Figure): |
|
352 | 352 | |
|
353 | 353 | __isConfig = None |
|
354 | 354 | __nsubplots = None |
|
355 | 355 | |
|
356 | 356 | WIDTHPROF = None |
|
357 | 357 | HEIGHTPROF = None |
|
358 | 358 | PREFIX = 'wind' |
|
359 | 359 | |
|
360 | 360 | def __init__(self): |
|
361 | 361 | |
|
362 | 362 | self.timerange = 2*60*60 |
|
363 | 363 | self.__isConfig = False |
|
364 | 364 | self.__nsubplots = 1 |
|
365 | 365 | |
|
366 | 366 | self.WIDTH = 800 |
|
367 | 367 | self.HEIGHT = 150 |
|
368 | 368 | self.WIDTHPROF = 120 |
|
369 | 369 | self.HEIGHTPROF = 0 |
|
370 | 370 | self.counter_imagwr = 0 |
|
371 | 371 | |
|
372 | 372 | self.PLOT_CODE = 0 |
|
373 | 373 | self.FTP_WEI = None |
|
374 | 374 | self.EXP_CODE = None |
|
375 | 375 | self.SUB_EXP_CODE = None |
|
376 | 376 | self.PLOT_POS = None |
|
377 | 377 | self.tmin = None |
|
378 | 378 | self.tmax = None |
|
379 | 379 | |
|
380 | 380 | self.xmin = None |
|
381 | 381 | self.xmax = None |
|
382 | 382 | |
|
383 | 383 | self.figfile = None |
|
384 | 384 | |
|
385 | 385 | def getSubplots(self): |
|
386 | 386 | |
|
387 | 387 | ncol = 1 |
|
388 | 388 | nrow = self.nplots |
|
389 | 389 | |
|
390 | 390 | return nrow, ncol |
|
391 | 391 | |
|
392 | 392 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
393 | 393 | |
|
394 | 394 | self.__showprofile = showprofile |
|
395 | 395 | self.nplots = nplots |
|
396 | 396 | |
|
397 | 397 | ncolspan = 1 |
|
398 | 398 | colspan = 1 |
|
399 | 399 | |
|
400 | 400 | self.createFigure(id = id, |
|
401 | 401 | wintitle = wintitle, |
|
402 | 402 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
403 | 403 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
404 | 404 | show=show) |
|
405 | 405 | |
|
406 | 406 | nrow, ncol = self.getSubplots() |
|
407 | 407 | |
|
408 | 408 | counter = 0 |
|
409 | 409 | for y in range(nrow): |
|
410 | 410 | if counter >= self.nplots: |
|
411 | 411 | break |
|
412 | 412 | |
|
413 | 413 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
414 | 414 | counter += 1 |
|
415 | 415 | |
|
416 | 416 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
417 | 417 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
418 | 418 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
419 | 419 | timerange=None, SNRthresh = None, |
|
420 | 420 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
421 | 421 | server=None, folder=None, username=None, password=None, |
|
422 | 422 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
423 | 423 | """ |
|
424 | 424 | |
|
425 | 425 | Input: |
|
426 | 426 | dataOut : |
|
427 | 427 | id : |
|
428 | 428 | wintitle : |
|
429 | 429 | channelList : |
|
430 | 430 | showProfile : |
|
431 | 431 | xmin : None, |
|
432 | 432 | xmax : None, |
|
433 | 433 | ymin : None, |
|
434 | 434 | ymax : None, |
|
435 | 435 | zmin : None, |
|
436 | 436 | zmax : None |
|
437 | 437 | """ |
|
438 | 438 | |
|
439 | 439 | if channelList == None: |
|
440 | 440 | channelIndexList = dataOut.channelIndexList |
|
441 | 441 | else: |
|
442 | 442 | channelIndexList = [] |
|
443 | 443 | for channel in channelList: |
|
444 | 444 | if channel not in dataOut.channelList: |
|
445 | 445 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
446 | 446 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
447 | 447 | |
|
448 | 448 | if timerange != None: |
|
449 | 449 | self.timerange = timerange |
|
450 | 450 | |
|
451 | 451 | tmin = None |
|
452 | 452 | tmax = None |
|
453 | 453 | |
|
454 | 454 | x = dataOut.getTimeRange1() |
|
455 | 455 | # y = dataOut.heightRange |
|
456 | 456 | y = dataOut.heightRange |
|
457 | 457 | |
|
458 | 458 | z = dataOut.winds.copy() |
|
459 | 459 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
460 | 460 | nplotsw = nplots |
|
461 | 461 | |
|
462 | 462 | #If there is a SNR function defined |
|
463 | 463 | if dataOut.SNR != None: |
|
464 | 464 | nplots += 1 |
|
465 | 465 | SNR = dataOut.SNR |
|
466 | 466 | SNRavg = numpy.average(SNR, axis=0) |
|
467 | 467 | |
|
468 | 468 | SNRdB = 10*numpy.log10(SNR) |
|
469 | 469 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
470 | 470 | |
|
471 | 471 | if SNRthresh == None: SNRthresh = -5.0 |
|
472 | 472 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
473 | 473 | |
|
474 | 474 | for i in range(nplotsw): |
|
475 | 475 | z[i,ind] = numpy.nan |
|
476 | 476 | |
|
477 | 477 | |
|
478 | 478 | showprofile = False |
|
479 | 479 | # thisDatetime = dataOut.datatime |
|
480 | 480 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
481 | 481 | title = wintitle + "Wind" |
|
482 | 482 | xlabel = "" |
|
483 | 483 | ylabel = "Range (Km)" |
|
484 | 484 | |
|
485 | 485 | if not self.__isConfig: |
|
486 | 486 | |
|
487 | 487 | self.setup(id=id, |
|
488 | 488 | nplots=nplots, |
|
489 | 489 | wintitle=wintitle, |
|
490 | 490 | showprofile=showprofile, |
|
491 | 491 | show=show) |
|
492 | 492 | |
|
493 | 493 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
494 | 494 | |
|
495 | 495 | if ymin == None: ymin = numpy.nanmin(y) |
|
496 | 496 | if ymax == None: ymax = numpy.nanmax(y) |
|
497 | 497 | |
|
498 | 498 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) |
|
499 | 499 | #if numpy.isnan(zmax): zmax = 50 |
|
500 | 500 | if zmin == None: zmin = -zmax |
|
501 | 501 | |
|
502 | 502 | if nplotsw == 3: |
|
503 | 503 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
504 | 504 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
505 | 505 | |
|
506 | 506 | if dataOut.SNR != None: |
|
507 | 507 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
508 | 508 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
509 | 509 | |
|
510 | 510 | self.FTP_WEI = ftp_wei |
|
511 | 511 | self.EXP_CODE = exp_code |
|
512 | 512 | self.SUB_EXP_CODE = sub_exp_code |
|
513 | 513 | self.PLOT_POS = plot_pos |
|
514 | 514 | |
|
515 | 515 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
516 | 516 | self.__isConfig = True |
|
517 | 517 | |
|
518 | 518 | |
|
519 | 519 | self.setWinTitle(title) |
|
520 | 520 | |
|
521 | 521 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
522 | 522 | x[1] = self.xmax |
|
523 | 523 | |
|
524 | 524 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
525 | 525 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
526 | 526 | zmaxVector = [zmax, zmax, zmax_ver] |
|
527 | 527 | zminVector = [zmin, zmin, zmin_ver] |
|
528 | 528 | windFactor = [1,1,100] |
|
529 | 529 | |
|
530 | 530 | for i in range(nplotsw): |
|
531 | 531 | |
|
532 | 532 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
533 | 533 | axes = self.axesList[i*self.__nsubplots] |
|
534 | 534 | |
|
535 | 535 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
536 | 536 | |
|
537 | 537 | axes.pcolorbuffer(x, y, z1, |
|
538 | 538 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
539 | 539 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
540 | 540 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" ) |
|
541 | 541 | |
|
542 | 542 | if dataOut.SNR != None: |
|
543 | 543 | i += 1 |
|
544 | 544 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
545 | 545 | axes = self.axesList[i*self.__nsubplots] |
|
546 | 546 | |
|
547 | 547 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
548 | 548 | |
|
549 | 549 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
550 | 550 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
551 | 551 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
552 | 552 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
553 | 553 | |
|
554 | 554 | self.draw() |
|
555 | 555 | |
|
556 | 556 | if self.figfile == None: |
|
557 | 557 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
558 | 558 | self.figfile = self.getFilename(name = str_datetime) |
|
559 | 559 | |
|
560 | 560 | if figpath != '': |
|
561 | 561 | |
|
562 | 562 | self.counter_imagwr += 1 |
|
563 | 563 | if (self.counter_imagwr>=wr_period): |
|
564 | 564 | # store png plot to local folder |
|
565 | 565 | self.saveFigure(figpath, self.figfile) |
|
566 | 566 | # store png plot to FTP server according to RT-Web format |
|
567 | 567 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
568 | 568 | ftp_filename = os.path.join(figpath, name) |
|
569 | 569 | self.saveFigure(figpath, ftp_filename) |
|
570 | 570 | |
|
571 | 571 | self.counter_imagwr = 0 |
|
572 | 572 | |
|
573 | 573 | if x[1] >= self.axesList[0].xmax: |
|
574 | 574 | self.counter_imagwr = wr_period |
|
575 | 575 | self.__isConfig = False |
|
576 | 576 | self.figfile = None |
|
577 | 577 | |
|
578 | 578 | |
|
579 |
class |
|
|
579 | class ParametersPlot(Figure): | |
|
580 | 580 | |
|
581 | 581 | __isConfig = None |
|
582 | 582 | __nsubplots = None |
|
583 | 583 | |
|
584 | 584 | WIDTHPROF = None |
|
585 | 585 | HEIGHTPROF = None |
|
586 |
PREFIX = ' |
|
|
586 | PREFIX = 'prm' | |
|
587 | 587 | |
|
588 | 588 | def __init__(self): |
|
589 | 589 | |
|
590 | 590 | self.timerange = 2*60*60 |
|
591 | 591 | self.__isConfig = False |
|
592 | 592 | self.__nsubplots = 1 |
|
593 | 593 | |
|
594 | 594 | self.WIDTH = 800 |
|
595 | 595 | self.HEIGHT = 150 |
|
596 | 596 | self.WIDTHPROF = 120 |
|
597 | 597 | self.HEIGHTPROF = 0 |
|
598 | 598 | self.counter_imagwr = 0 |
|
599 | 599 | |
|
600 | 600 | self.PLOT_CODE = 0 |
|
601 | 601 | self.FTP_WEI = None |
|
602 | 602 | self.EXP_CODE = None |
|
603 | 603 | self.SUB_EXP_CODE = None |
|
604 | 604 | self.PLOT_POS = None |
|
605 | 605 | self.tmin = None |
|
606 | 606 | self.tmax = None |
|
607 | 607 | |
|
608 | 608 | self.xmin = None |
|
609 | 609 | self.xmax = None |
|
610 | 610 | |
|
611 | 611 | self.figfile = None |
|
612 | 612 | |
|
613 | 613 | def getSubplots(self): |
|
614 | 614 | |
|
615 | 615 | ncol = 1 |
|
616 | 616 | nrow = self.nplots |
|
617 | 617 | |
|
618 | 618 | return nrow, ncol |
|
619 | 619 | |
|
620 | 620 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
621 | 621 | |
|
622 | 622 | self.__showprofile = showprofile |
|
623 | 623 | self.nplots = nplots |
|
624 | 624 | |
|
625 | 625 | ncolspan = 1 |
|
626 | 626 | colspan = 1 |
|
627 | 627 | |
|
628 | 628 | self.createFigure(id = id, |
|
629 | 629 | wintitle = wintitle, |
|
630 | 630 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
631 | 631 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
632 | 632 | show=show) |
|
633 | 633 | |
|
634 | 634 | nrow, ncol = self.getSubplots() |
|
635 | 635 | |
|
636 | 636 | counter = 0 |
|
637 | 637 | for y in range(nrow): |
|
638 | 638 | for x in range(ncol): |
|
639 | 639 | |
|
640 | 640 | if counter >= self.nplots: |
|
641 | 641 | break |
|
642 | 642 | |
|
643 | 643 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
644 | 644 | |
|
645 | 645 | if showprofile: |
|
646 | 646 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
647 | 647 | |
|
648 | 648 | counter += 1 |
|
649 | 649 | |
|
650 | 650 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
651 | 651 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
652 | SNRmin = None, SNRmax = None, SNRthresh = None, paramIndex = None, | |
|
652 | SNRmin = None, SNRmax = None, SNRthresh = None, paramIndex = None, onlyPositive = False, | |
|
653 | zlabel = "", parameterName = "", | |
|
653 | 654 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
654 | 655 | server=None, folder=None, username=None, password=None, |
|
655 | 656 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
656 | 657 | |
|
657 | 658 | """ |
|
658 | 659 | |
|
659 | 660 | Input: |
|
660 | 661 | dataOut : |
|
661 | 662 | id : |
|
662 | 663 | wintitle : |
|
663 | 664 | channelList : |
|
664 | 665 | showProfile : |
|
665 | 666 | xmin : None, |
|
666 | 667 | xmax : None, |
|
667 | 668 | ymin : None, |
|
668 | 669 | ymax : None, |
|
669 | 670 | zmin : None, |
|
670 | 671 | zmax : None |
|
671 | 672 | """ |
|
672 | 673 | |
|
673 | 674 | if channelList == None: |
|
674 | 675 | channelIndexList = dataOut.channelIndexList |
|
675 | 676 | else: |
|
676 | 677 | channelIndexList = [] |
|
677 | 678 | for channel in channelList: |
|
678 | 679 | if channel not in dataOut.channelList: |
|
679 | 680 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
680 | 681 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
681 | 682 | |
|
682 | 683 | if timerange != None: |
|
683 | 684 | self.timerange = timerange |
|
684 | 685 | |
|
685 | 686 | #tmin = None |
|
686 | 687 | #tmax = None |
|
687 | 688 | if paramIndex == None: |
|
688 | 689 | paramIndex = 1 |
|
689 | 690 | x = dataOut.getTimeRange1() |
|
690 | 691 | y = dataOut.heightRange |
|
691 | 692 | z = dataOut.data_param[channelIndexList,paramIndex,:].copy() |
|
692 | 693 | |
|
693 | 694 | zRange = dataOut.abscissaRange |
|
694 | 695 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
695 | nplotsw = nplots | |
|
696 | ||
|
697 | if dataOut.SNR != None: | |
|
698 | nplots += 1 | |
|
699 | SNR = dataOut.SNR | |
|
700 | SNRavg = numpy.average(SNR, axis=0) | |
|
701 | ||
|
702 | SNRdB = 10*numpy.log10(SNR) | |
|
703 | SNRavgdB = 10*numpy.log10(SNRavg) | |
|
704 | ||
|
705 | if SNRthresh == None: SNRthresh = -5.0 | |
|
706 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] | |
|
707 | ||
|
708 | for i in range(nplotsw): | |
|
709 | z[i,ind] = numpy.nan | |
|
710 | 696 | # thisDatetime = dataOut.datatime |
|
711 | 697 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
712 |
title = wintitle + " |
|
|
698 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
713 | 699 | xlabel = "" |
|
714 |
ylabel = " |
|
|
700 | ylabel = "Range (Km)" | |
|
701 | ||
|
702 | if onlyPositive: | |
|
703 | colormap = "jet" | |
|
704 | zmin = 0 | |
|
705 | else: colormap = "RdBu_r" | |
|
715 | 706 | |
|
716 | 707 | if not self.__isConfig: |
|
717 | 708 | |
|
718 | 709 | self.setup(id=id, |
|
719 | 710 | nplots=nplots, |
|
720 | 711 | wintitle=wintitle, |
|
721 | 712 | showprofile=showprofile, |
|
722 | 713 | show=show) |
|
723 | 714 | |
|
724 | 715 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
725 | 716 | |
|
726 | 717 | if ymin == None: ymin = numpy.nanmin(y) |
|
727 | 718 | if ymax == None: ymax = numpy.nanmax(y) |
|
728 | 719 | if zmin == None: zmin = numpy.nanmin(zRange) |
|
729 | 720 | if zmax == None: zmax = numpy.nanmax(zRange) |
|
721 | ||
|
730 | 722 | if dataOut.SNR != None: |
|
731 | 723 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
732 | 724 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
733 | 725 | |
|
734 | 726 | self.FTP_WEI = ftp_wei |
|
735 | 727 | self.EXP_CODE = exp_code |
|
736 | 728 | self.SUB_EXP_CODE = sub_exp_code |
|
737 | 729 | self.PLOT_POS = plot_pos |
|
738 | 730 | |
|
739 | 731 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
740 | 732 | self.__isConfig = True |
|
741 | 733 | self.figfile = figfile |
|
742 | 734 | |
|
743 | 735 | self.setWinTitle(title) |
|
744 | 736 | |
|
745 | 737 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
746 | 738 | x[1] = self.xmax |
|
747 | 739 | |
|
748 |
for i in range(nplots |
|
|
749 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
740 | for i in range(nplots): | |
|
741 | title = "%s Channel %d: %s" %(parameterName, dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
742 | ||
|
750 | 743 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
751 | 744 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
752 | 745 | axes = self.axesList[i*self.__nsubplots] |
|
753 | 746 | z1 = z[i,:].reshape((1,-1)) |
|
754 | 747 | axes.pcolorbuffer(x, y, z1, |
|
755 | 748 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
756 |
xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap= |
|
|
757 |
ticksize=9, cblabel= |
|
|
758 | ||
|
759 | if dataOut.SNR != None: | |
|
760 | i += 1 | |
|
761 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
762 | axes = self.axesList[i*self.__nsubplots] | |
|
763 | ||
|
764 | SNRavgdB = SNRavgdB.reshape((1,-1)) | |
|
765 | ||
|
766 | axes.pcolorbuffer(x, y, SNRavgdB, | |
|
767 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
|
768 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
769 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") | |
|
749 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, | |
|
750 | ticksize=9, cblabel=zlabel, cbsize="1%") | |
|
770 | 751 | |
|
771 | 752 | self.draw() |
|
772 | 753 | |
|
773 | 754 | if self.figfile == None: |
|
774 | 755 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
775 | 756 | self.figfile = self.getFilename(name = str_datetime) |
|
776 | 757 | |
|
777 | 758 | if figpath != '': |
|
778 | 759 | |
|
779 | 760 | self.counter_imagwr += 1 |
|
780 | 761 | if (self.counter_imagwr>=wr_period): |
|
781 | 762 | # store png plot to local folder |
|
782 | 763 | self.saveFigure(figpath, self.figfile) |
|
783 | 764 | # store png plot to FTP server according to RT-Web format |
|
784 | 765 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
785 | 766 | ftp_filename = os.path.join(figpath, name) |
|
786 | 767 | self.saveFigure(figpath, ftp_filename) |
|
787 | 768 | |
|
788 | 769 | self.counter_imagwr = 0 |
|
789 | 770 | |
|
790 | 771 | if x[1] >= self.axesList[0].xmax: |
|
791 | 772 | self.counter_imagwr = wr_period |
|
792 | 773 | self.__isConfig = False |
|
793 | 774 | self.figfile = None No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now