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