##// END OF EJS Templates
El grafico de la fase del Beacon se guarda en el disco y envia por ftp
Daniel Valdez -
r454:e7f2b9ab0e3c
parent child
Show More
@@ -1,1675 +1,1698
1 1 import numpy
2 2 import time, datetime, os
3 3 from graphics.figure import *
4 4 def isRealtime(utcdatatime):
5 5 utcnow = time.mktime(time.localtime())
6 6 delta = abs(utcnow - utcdatatime) # abs
7 7 if delta >= 30.:
8 8 return False
9 9 return True
10 10
11 11 class CrossSpectraPlot(Figure):
12 12
13 13 __isConfig = None
14 14 __nsubplots = None
15 15
16 16 WIDTH = None
17 17 HEIGHT = None
18 18 WIDTHPROF = None
19 19 HEIGHTPROF = None
20 20 PREFIX = 'cspc'
21 21
22 22 def __init__(self):
23 23
24 24 self.__isConfig = False
25 25 self.__nsubplots = 4
26 26 self.counter_imagwr = 0
27 27 self.WIDTH = 250
28 28 self.HEIGHT = 250
29 29 self.WIDTHPROF = 0
30 30 self.HEIGHTPROF = 0
31 31
32 32 self.PLOT_CODE = 1
33 33 self.FTP_WEI = None
34 34 self.EXP_CODE = None
35 35 self.SUB_EXP_CODE = None
36 36 self.PLOT_POS = None
37 37
38 38 def getSubplots(self):
39 39
40 40 ncol = 4
41 41 nrow = self.nplots
42 42
43 43 return nrow, ncol
44 44
45 45 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
46 46
47 47 self.__showprofile = showprofile
48 48 self.nplots = nplots
49 49
50 50 ncolspan = 1
51 51 colspan = 1
52 52
53 53 self.createFigure(id = id,
54 54 wintitle = wintitle,
55 55 widthplot = self.WIDTH + self.WIDTHPROF,
56 56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 57 show=True)
58 58
59 59 nrow, ncol = self.getSubplots()
60 60
61 61 counter = 0
62 62 for y in range(nrow):
63 63 for x in range(ncol):
64 64 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
65 65
66 66 counter += 1
67 67
68 68 def run(self, dataOut, id, wintitle="", pairsList=None,
69 69 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
70 70 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
71 71 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
72 72 server=None, folder=None, username=None, password=None,
73 73 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
74 74
75 75 """
76 76
77 77 Input:
78 78 dataOut :
79 79 id :
80 80 wintitle :
81 81 channelList :
82 82 showProfile :
83 83 xmin : None,
84 84 xmax : None,
85 85 ymin : None,
86 86 ymax : None,
87 87 zmin : None,
88 88 zmax : None
89 89 """
90 90
91 91 if pairsList == None:
92 92 pairsIndexList = dataOut.pairsIndexList
93 93 else:
94 94 pairsIndexList = []
95 95 for pair in pairsList:
96 96 if pair not in dataOut.pairsList:
97 97 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
98 98 pairsIndexList.append(dataOut.pairsList.index(pair))
99 99
100 100 if pairsIndexList == []:
101 101 return
102 102
103 103 if len(pairsIndexList) > 4:
104 104 pairsIndexList = pairsIndexList[0:4]
105 105 #factor = dataOut.normFactor
106 106 x = dataOut.getVelRange(1)
107 107 y = dataOut.getHeiRange()
108 108 z = dataOut.data_spc[:,:,:]#/factor
109 109 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
110 110 avg = numpy.abs(numpy.average(z, axis=1))
111 111 noise = dataOut.getNoise()#/factor
112 112
113 113 zdB = 10*numpy.log10(z)
114 114 avgdB = 10*numpy.log10(avg)
115 115 noisedB = 10*numpy.log10(noise)
116 116
117 117
118 118 #thisDatetime = dataOut.datatime
119 119 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
120 120 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
121 121 xlabel = "Velocity (m/s)"
122 122 ylabel = "Range (Km)"
123 123
124 124 if not self.__isConfig:
125 125
126 126 nplots = len(pairsIndexList)
127 127
128 128 self.setup(id=id,
129 129 nplots=nplots,
130 130 wintitle=wintitle,
131 131 showprofile=False,
132 132 show=show)
133 133
134 134 if xmin == None: xmin = numpy.nanmin(x)
135 135 if xmax == None: xmax = numpy.nanmax(x)
136 136 if ymin == None: ymin = numpy.nanmin(y)
137 137 if ymax == None: ymax = numpy.nanmax(y)
138 138 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
139 139 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
140 140
141 141 self.FTP_WEI = ftp_wei
142 142 self.EXP_CODE = exp_code
143 143 self.SUB_EXP_CODE = sub_exp_code
144 144 self.PLOT_POS = plot_pos
145 145
146 146 self.__isConfig = True
147 147
148 148 self.setWinTitle(title)
149 149
150 150 for i in range(self.nplots):
151 151 pair = dataOut.pairsList[pairsIndexList[i]]
152 152 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
153 153 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
154 154 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
155 155 axes0 = self.axesList[i*self.__nsubplots]
156 156 axes0.pcolor(x, y, zdB,
157 157 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
158 158 xlabel=xlabel, ylabel=ylabel, title=title,
159 159 ticksize=9, colormap=power_cmap, cblabel='')
160 160
161 161 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
162 162 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
163 163 axes0 = self.axesList[i*self.__nsubplots+1]
164 164 axes0.pcolor(x, y, zdB,
165 165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 166 xlabel=xlabel, ylabel=ylabel, title=title,
167 167 ticksize=9, colormap=power_cmap, cblabel='')
168 168
169 169 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
170 170 coherence = numpy.abs(coherenceComplex)
171 171 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
172 172 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
173 173
174 174 title = "Coherence %d%d" %(pair[0], pair[1])
175 175 axes0 = self.axesList[i*self.__nsubplots+2]
176 176 axes0.pcolor(x, y, coherence,
177 177 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
178 178 xlabel=xlabel, ylabel=ylabel, title=title,
179 179 ticksize=9, colormap=coherence_cmap, cblabel='')
180 180
181 181 title = "Phase %d%d" %(pair[0], pair[1])
182 182 axes0 = self.axesList[i*self.__nsubplots+3]
183 183 axes0.pcolor(x, y, phase,
184 184 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
185 185 xlabel=xlabel, ylabel=ylabel, title=title,
186 186 ticksize=9, colormap=phase_cmap, cblabel='')
187 187
188 188
189 189
190 190 self.draw()
191 191
192 192 if save:
193 193
194 194 self.counter_imagwr += 1
195 195 if (self.counter_imagwr==wr_period):
196 196 if figfile == None:
197 197 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
198 198 figfile = self.getFilename(name = str_datetime)
199 199
200 200 self.saveFigure(figpath, figfile)
201 201
202 202 if ftp:
203 203 #provisionalmente envia archivos en el formato de la web en tiempo real
204 204 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
205 205 path = '%s%03d' %(self.PREFIX, self.id)
206 206 ftp_file = os.path.join(path,'ftp','%s.png'%name)
207 207 self.saveFigure(figpath, ftp_file)
208 208 ftp_filename = os.path.join(figpath,ftp_file)
209 209
210 210 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
211 211 self.counter_imagwr = 0
212 212
213 213 self.counter_imagwr = 0
214 214
215 215
216 216 class RTIPlot(Figure):
217 217
218 218 __isConfig = None
219 219 __nsubplots = None
220 220
221 221 WIDTHPROF = None
222 222 HEIGHTPROF = None
223 223 PREFIX = 'rti'
224 224
225 225 def __init__(self):
226 226
227 227 self.timerange = 2*60*60
228 228 self.__isConfig = False
229 229 self.__nsubplots = 1
230 230
231 231 self.WIDTH = 800
232 232 self.HEIGHT = 150
233 233 self.WIDTHPROF = 120
234 234 self.HEIGHTPROF = 0
235 235 self.counter_imagwr = 0
236 236
237 237 self.PLOT_CODE = 0
238 238 self.FTP_WEI = None
239 239 self.EXP_CODE = None
240 240 self.SUB_EXP_CODE = None
241 241 self.PLOT_POS = None
242 242
243 243 def getSubplots(self):
244 244
245 245 ncol = 1
246 246 nrow = self.nplots
247 247
248 248 return nrow, ncol
249 249
250 250 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
251 251
252 252 self.__showprofile = showprofile
253 253 self.nplots = nplots
254 254
255 255 ncolspan = 1
256 256 colspan = 1
257 257 if showprofile:
258 258 ncolspan = 7
259 259 colspan = 6
260 260 self.__nsubplots = 2
261 261
262 262 self.createFigure(id = id,
263 263 wintitle = wintitle,
264 264 widthplot = self.WIDTH + self.WIDTHPROF,
265 265 heightplot = self.HEIGHT + self.HEIGHTPROF,
266 266 show=show)
267 267
268 268 nrow, ncol = self.getSubplots()
269 269
270 270 counter = 0
271 271 for y in range(nrow):
272 272 for x in range(ncol):
273 273
274 274 if counter >= self.nplots:
275 275 break
276 276
277 277 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
278 278
279 279 if showprofile:
280 280 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
281 281
282 282 counter += 1
283 283
284 284 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
285 285 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
286 286 timerange=None,
287 287 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
288 288 server=None, folder=None, username=None, password=None,
289 289 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
290 290
291 291 """
292 292
293 293 Input:
294 294 dataOut :
295 295 id :
296 296 wintitle :
297 297 channelList :
298 298 showProfile :
299 299 xmin : None,
300 300 xmax : None,
301 301 ymin : None,
302 302 ymax : None,
303 303 zmin : None,
304 304 zmax : None
305 305 """
306 306
307 307 if channelList == None:
308 308 channelIndexList = dataOut.channelIndexList
309 309 else:
310 310 channelIndexList = []
311 311 for channel in channelList:
312 312 if channel not in dataOut.channelList:
313 313 raise ValueError, "Channel %d is not in dataOut.channelList"
314 314 channelIndexList.append(dataOut.channelList.index(channel))
315 315
316 316 if timerange != None:
317 317 self.timerange = timerange
318 318
319 319 tmin = None
320 320 tmax = None
321 321 #factor = dataOut.normFactor
322 322 x = dataOut.getTimeRange()
323 323 y = dataOut.getHeiRange()
324 324
325 325 z = dataOut.data_spc[channelIndexList,:,:]#/factor
326 326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
327 327 avg = numpy.average(z, axis=1)
328 328
329 329 avgdB = 10.*numpy.log10(avg)
330 330
331 331
332 332 # thisDatetime = dataOut.datatime
333 333 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
334 334 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
335 335 xlabel = ""
336 336 ylabel = "Range (Km)"
337 337
338 338 if not self.__isConfig:
339 339
340 340 nplots = len(channelIndexList)
341 341
342 342 self.setup(id=id,
343 343 nplots=nplots,
344 344 wintitle=wintitle,
345 345 showprofile=showprofile,
346 346 show=show)
347 347
348 348 tmin, tmax = self.getTimeLim(x, xmin, xmax)
349 349 if ymin == None: ymin = numpy.nanmin(y)
350 350 if ymax == None: ymax = numpy.nanmax(y)
351 351 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
352 352 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
353 353
354 354 self.FTP_WEI = ftp_wei
355 355 self.EXP_CODE = exp_code
356 356 self.SUB_EXP_CODE = sub_exp_code
357 357 self.PLOT_POS = plot_pos
358 358
359 359 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
360 360 self.__isConfig = True
361 361
362 362
363 363 self.setWinTitle(title)
364 364
365 365 for i in range(self.nplots):
366 366 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
367 367 axes = self.axesList[i*self.__nsubplots]
368 368 zdB = avgdB[i].reshape((1,-1))
369 369 axes.pcolorbuffer(x, y, zdB,
370 370 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
371 371 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
372 372 ticksize=9, cblabel='', cbsize="1%")
373 373
374 374 if self.__showprofile:
375 375 axes = self.axesList[i*self.__nsubplots +1]
376 376 axes.pline(avgdB[i], y,
377 377 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
378 378 xlabel='dB', ylabel='', title='',
379 379 ytick_visible=False,
380 380 grid='x')
381 381
382 382 self.draw()
383 383
384 384 if save:
385 385
386 386 self.counter_imagwr += 1
387 387 if (self.counter_imagwr==wr_period):
388 388 if figfile == None:
389 389 figfile = self.getFilename(name = self.name)
390 390 self.saveFigure(figpath, figfile)
391 391
392 392 if ftp:
393 393 #provisionalmente envia archivos en el formato de la web en tiempo real
394 394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
395 395 path = '%s%03d' %(self.PREFIX, self.id)
396 396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
397 397 self.saveFigure(figpath, ftp_file)
398 398 ftp_filename = os.path.join(figpath,ftp_file)
399 399 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
400 400 self.counter_imagwr = 0
401 401
402 402 self.counter_imagwr = 0
403 403
404 404 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
405 405 self.__isConfig = False
406 406
407 407 class SpectraPlot(Figure):
408 408
409 409 __isConfig = None
410 410 __nsubplots = None
411 411
412 412 WIDTHPROF = None
413 413 HEIGHTPROF = None
414 414 PREFIX = 'spc'
415 415
416 416 def __init__(self):
417 417
418 418 self.__isConfig = False
419 419 self.__nsubplots = 1
420 420
421 421 self.WIDTH = 280
422 422 self.HEIGHT = 250
423 423 self.WIDTHPROF = 120
424 424 self.HEIGHTPROF = 0
425 425 self.counter_imagwr = 0
426 426
427 427 self.PLOT_CODE = 1
428 428 self.FTP_WEI = None
429 429 self.EXP_CODE = None
430 430 self.SUB_EXP_CODE = None
431 431 self.PLOT_POS = None
432 432
433 433 def getSubplots(self):
434 434
435 435 ncol = int(numpy.sqrt(self.nplots)+0.9)
436 436 nrow = int(self.nplots*1./ncol + 0.9)
437 437
438 438 return nrow, ncol
439 439
440 440 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
441 441
442 442 self.__showprofile = showprofile
443 443 self.nplots = nplots
444 444
445 445 ncolspan = 1
446 446 colspan = 1
447 447 if showprofile:
448 448 ncolspan = 3
449 449 colspan = 2
450 450 self.__nsubplots = 2
451 451
452 452 self.createFigure(id = id,
453 453 wintitle = wintitle,
454 454 widthplot = self.WIDTH + self.WIDTHPROF,
455 455 heightplot = self.HEIGHT + self.HEIGHTPROF,
456 456 show=show)
457 457
458 458 nrow, ncol = self.getSubplots()
459 459
460 460 counter = 0
461 461 for y in range(nrow):
462 462 for x in range(ncol):
463 463
464 464 if counter >= self.nplots:
465 465 break
466 466
467 467 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
468 468
469 469 if showprofile:
470 470 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
471 471
472 472 counter += 1
473 473
474 474 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
475 475 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
476 476 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
477 477 server=None, folder=None, username=None, password=None,
478 478 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
479 479
480 480 """
481 481
482 482 Input:
483 483 dataOut :
484 484 id :
485 485 wintitle :
486 486 channelList :
487 487 showProfile :
488 488 xmin : None,
489 489 xmax : None,
490 490 ymin : None,
491 491 ymax : None,
492 492 zmin : None,
493 493 zmax : None
494 494 """
495 495
496 496 if realtime:
497 497 if not(isRealtime(utcdatatime = dataOut.utctime)):
498 498 print 'Skipping this plot function'
499 499 return
500 500
501 501 if channelList == None:
502 502 channelIndexList = dataOut.channelIndexList
503 503 else:
504 504 channelIndexList = []
505 505 for channel in channelList:
506 506 if channel not in dataOut.channelList:
507 507 raise ValueError, "Channel %d is not in dataOut.channelList"
508 508 channelIndexList.append(dataOut.channelList.index(channel))
509 509 #factor = dataOut.normFactor
510 510 x = dataOut.getVelRange(1)
511 511 y = dataOut.getHeiRange()
512 512
513 513 z = dataOut.data_spc[channelIndexList,:,:]#/factor
514 514 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
515 515 avg = numpy.average(z, axis=1)
516 516 noise = dataOut.getNoise()#/factor
517 517
518 518 zdB = 10*numpy.log10(z)
519 519 avgdB = 10*numpy.log10(avg)
520 520 noisedB = 10*numpy.log10(noise)
521 521
522 522 #thisDatetime = dataOut.datatime
523 523 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
524 524 title = wintitle + " Spectra"
525 525 xlabel = "Velocity (m/s)"
526 526 ylabel = "Range (Km)"
527 527
528 528 if not self.__isConfig:
529 529
530 530 nplots = len(channelIndexList)
531 531
532 532 self.setup(id=id,
533 533 nplots=nplots,
534 534 wintitle=wintitle,
535 535 showprofile=showprofile,
536 536 show=show)
537 537
538 538 if xmin == None: xmin = numpy.nanmin(x)
539 539 if xmax == None: xmax = numpy.nanmax(x)
540 540 if ymin == None: ymin = numpy.nanmin(y)
541 541 if ymax == None: ymax = numpy.nanmax(y)
542 542 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
543 543 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
544 544
545 545 self.FTP_WEI = ftp_wei
546 546 self.EXP_CODE = exp_code
547 547 self.SUB_EXP_CODE = sub_exp_code
548 548 self.PLOT_POS = plot_pos
549 549
550 550 self.__isConfig = True
551 551
552 552 self.setWinTitle(title)
553 553
554 554 for i in range(self.nplots):
555 555 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
556 556 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
557 557 axes = self.axesList[i*self.__nsubplots]
558 558 axes.pcolor(x, y, zdB[i,:,:],
559 559 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
560 560 xlabel=xlabel, ylabel=ylabel, title=title,
561 561 ticksize=9, cblabel='')
562 562
563 563 if self.__showprofile:
564 564 axes = self.axesList[i*self.__nsubplots +1]
565 565 axes.pline(avgdB[i], y,
566 566 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
567 567 xlabel='dB', ylabel='', title='',
568 568 ytick_visible=False,
569 569 grid='x')
570 570
571 571 noiseline = numpy.repeat(noisedB[i], len(y))
572 572 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
573 573
574 574 self.draw()
575 575
576 576 if save:
577 577
578 578 self.counter_imagwr += 1
579 579 if (self.counter_imagwr==wr_period):
580 580 if figfile == None:
581 581 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
582 582 figfile = self.getFilename(name = str_datetime)
583 583
584 584 self.saveFigure(figpath, figfile)
585 585
586 586 if ftp:
587 587 #provisionalmente envia archivos en el formato de la web en tiempo real
588 588 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
589 589 path = '%s%03d' %(self.PREFIX, self.id)
590 590 ftp_file = os.path.join(path,'ftp','%s.png'%name)
591 591 self.saveFigure(figpath, ftp_file)
592 592 ftp_filename = os.path.join(figpath,ftp_file)
593 593 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
594 594 self.counter_imagwr = 0
595 595
596 596
597 597 self.counter_imagwr = 0
598 598
599 599
600 600 class Scope(Figure):
601 601
602 602 __isConfig = None
603 603
604 604 def __init__(self):
605 605
606 606 self.__isConfig = False
607 607 self.WIDTH = 600
608 608 self.HEIGHT = 200
609 609 self.counter_imagwr = 0
610 610
611 611 def getSubplots(self):
612 612
613 613 nrow = self.nplots
614 614 ncol = 3
615 615 return nrow, ncol
616 616
617 617 def setup(self, id, nplots, wintitle, show):
618 618
619 619 self.nplots = nplots
620 620
621 621 self.createFigure(id=id,
622 622 wintitle=wintitle,
623 623 show=show)
624 624
625 625 nrow,ncol = self.getSubplots()
626 626 colspan = 3
627 627 rowspan = 1
628 628
629 629 for i in range(nplots):
630 630 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
631 631
632 632
633 633
634 634 def run(self, dataOut, id, wintitle="", channelList=None,
635 635 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
636 636 figpath='./', figfile=None, show=True, wr_period=1,
637 637 server=None, folder=None, username=None, password=None):
638 638
639 639 """
640 640
641 641 Input:
642 642 dataOut :
643 643 id :
644 644 wintitle :
645 645 channelList :
646 646 xmin : None,
647 647 xmax : None,
648 648 ymin : None,
649 649 ymax : None,
650 650 """
651 651
652 652 if channelList == None:
653 653 channelIndexList = dataOut.channelIndexList
654 654 else:
655 655 channelIndexList = []
656 656 for channel in channelList:
657 657 if channel not in dataOut.channelList:
658 658 raise ValueError, "Channel %d is not in dataOut.channelList"
659 659 channelIndexList.append(dataOut.channelList.index(channel))
660 660
661 661 x = dataOut.heightList
662 662 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
663 663 y = y.real
664 664
665 665 #thisDatetime = dataOut.datatime
666 666 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
667 667 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
668 668 xlabel = "Range (Km)"
669 669 ylabel = "Intensity"
670 670
671 671 if not self.__isConfig:
672 672 nplots = len(channelIndexList)
673 673
674 674 self.setup(id=id,
675 675 nplots=nplots,
676 676 wintitle=wintitle,
677 677 show=show)
678 678
679 679 if xmin == None: xmin = numpy.nanmin(x)
680 680 if xmax == None: xmax = numpy.nanmax(x)
681 681 if ymin == None: ymin = numpy.nanmin(y)
682 682 if ymax == None: ymax = numpy.nanmax(y)
683 683
684 684 self.__isConfig = True
685 685
686 686 self.setWinTitle(title)
687 687
688 688 for i in range(len(self.axesList)):
689 689 title = "Channel %d" %(i)
690 690 axes = self.axesList[i]
691 691 ychannel = y[i,:]
692 692 axes.pline(x, ychannel,
693 693 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
694 694 xlabel=xlabel, ylabel=ylabel, title=title)
695 695
696 696 self.draw()
697 697
698 698 if save:
699 699 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
700 700 if figfile == None:
701 701 figfile = self.getFilename(name = date)
702 702
703 703 self.saveFigure(figpath, figfile)
704 704
705 705 self.counter_imagwr += 1
706 706 if (ftp and (self.counter_imagwr==wr_period)):
707 707 ftp_filename = os.path.join(figpath,figfile)
708 708 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
709 709 self.counter_imagwr = 0
710 710
711 711 class PowerProfilePlot(Figure):
712 712 __isConfig = None
713 713 __nsubplots = None
714 714
715 715 WIDTHPROF = None
716 716 HEIGHTPROF = None
717 717 PREFIX = 'spcprofile'
718 718
719 719 def __init__(self):
720 720 self.__isConfig = False
721 721 self.__nsubplots = 1
722 722
723 723 self.WIDTH = 300
724 724 self.HEIGHT = 500
725 725 self.counter_imagwr = 0
726 726
727 727 def getSubplots(self):
728 728 ncol = 1
729 729 nrow = 1
730 730
731 731 return nrow, ncol
732 732
733 733 def setup(self, id, nplots, wintitle, show):
734 734
735 735 self.nplots = nplots
736 736
737 737 ncolspan = 1
738 738 colspan = 1
739 739
740 740 self.createFigure(id = id,
741 741 wintitle = wintitle,
742 742 widthplot = self.WIDTH,
743 743 heightplot = self.HEIGHT,
744 744 show=show)
745 745
746 746 nrow, ncol = self.getSubplots()
747 747
748 748 counter = 0
749 749 for y in range(nrow):
750 750 for x in range(ncol):
751 751 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
752 752
753 753 def run(self, dataOut, id, wintitle="", channelList=None,
754 754 xmin=None, xmax=None, ymin=None, ymax=None,
755 755 save=False, figpath='./', figfile=None, show=True, wr_period=1,
756 756 server=None, folder=None, username=None, password=None,):
757 757
758 758 if channelList == None:
759 759 channelIndexList = dataOut.channelIndexList
760 760 channelList = dataOut.channelList
761 761 else:
762 762 channelIndexList = []
763 763 for channel in channelList:
764 764 if channel not in dataOut.channelList:
765 765 raise ValueError, "Channel %d is not in dataOut.channelList"
766 766 channelIndexList.append(dataOut.channelList.index(channel))
767 767
768 768 #factor = dataOut.normFactor
769 769 y = dataOut.getHeiRange()
770 770 x = dataOut.data_spc[channelIndexList,:,:]#/factor
771 771 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
772 772 avg = numpy.average(x, axis=1)
773 773
774 774 avgdB = 10*numpy.log10(avg)
775 775
776 776 #thisDatetime = dataOut.datatime
777 777 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
778 778 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
779 779 xlabel = "dB"
780 780 ylabel = "Range (Km)"
781 781
782 782 if not self.__isConfig:
783 783
784 784 nplots = 1
785 785
786 786 self.setup(id=id,
787 787 nplots=nplots,
788 788 wintitle=wintitle,
789 789 show=show)
790 790
791 791 if ymin == None: ymin = numpy.nanmin(y)
792 792 if ymax == None: ymax = numpy.nanmax(y)
793 793 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
794 794 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
795 795
796 796 self.__isConfig = True
797 797
798 798 self.setWinTitle(title)
799 799
800 800
801 801 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
802 802 axes = self.axesList[0]
803 803
804 804 legendlabels = ["channel %d"%x for x in channelList]
805 805 axes.pmultiline(avgdB, y,
806 806 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
807 807 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
808 808 ytick_visible=True, nxticks=5,
809 809 grid='x')
810 810
811 811 self.draw()
812 812
813 813 if save:
814 814 date = thisDatetime.strftime("%Y%m%d")
815 815 if figfile == None:
816 816 figfile = self.getFilename(name = date)
817 817
818 818 self.saveFigure(figpath, figfile)
819 819
820 820 self.counter_imagwr += 1
821 821 if (ftp and (self.counter_imagwr==wr_period)):
822 822 ftp_filename = os.path.join(figpath,figfile)
823 823 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
824 824 self.counter_imagwr = 0
825 825
826 826 class CoherenceMap(Figure):
827 827 __isConfig = None
828 828 __nsubplots = None
829 829
830 830 WIDTHPROF = None
831 831 HEIGHTPROF = None
832 832 PREFIX = 'cmap'
833 833
834 834 def __init__(self):
835 835 self.timerange = 2*60*60
836 836 self.__isConfig = False
837 837 self.__nsubplots = 1
838 838
839 839 self.WIDTH = 800
840 840 self.HEIGHT = 150
841 841 self.WIDTHPROF = 120
842 842 self.HEIGHTPROF = 0
843 843 self.counter_imagwr = 0
844 844
845 845 self.PLOT_CODE = 3
846 846 self.FTP_WEI = None
847 847 self.EXP_CODE = None
848 848 self.SUB_EXP_CODE = None
849 849 self.PLOT_POS = None
850 850 self.counter_imagwr = 0
851 851
852 852 def getSubplots(self):
853 853 ncol = 1
854 854 nrow = self.nplots*2
855 855
856 856 return nrow, ncol
857 857
858 858 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
859 859 self.__showprofile = showprofile
860 860 self.nplots = nplots
861 861
862 862 ncolspan = 1
863 863 colspan = 1
864 864 if showprofile:
865 865 ncolspan = 7
866 866 colspan = 6
867 867 self.__nsubplots = 2
868 868
869 869 self.createFigure(id = id,
870 870 wintitle = wintitle,
871 871 widthplot = self.WIDTH + self.WIDTHPROF,
872 872 heightplot = self.HEIGHT + self.HEIGHTPROF,
873 873 show=True)
874 874
875 875 nrow, ncol = self.getSubplots()
876 876
877 877 for y in range(nrow):
878 878 for x in range(ncol):
879 879
880 880 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
881 881
882 882 if showprofile:
883 883 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
884 884
885 885 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
886 886 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
887 887 timerange=None,
888 888 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
889 889 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
890 890 server=None, folder=None, username=None, password=None,
891 891 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
892 892
893 893 if pairsList == None:
894 894 pairsIndexList = dataOut.pairsIndexList
895 895 else:
896 896 pairsIndexList = []
897 897 for pair in pairsList:
898 898 if pair not in dataOut.pairsList:
899 899 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
900 900 pairsIndexList.append(dataOut.pairsList.index(pair))
901 901
902 902 if timerange != None:
903 903 self.timerange = timerange
904 904
905 905 if pairsIndexList == []:
906 906 return
907 907
908 908 if len(pairsIndexList) > 4:
909 909 pairsIndexList = pairsIndexList[0:4]
910 910
911 911 tmin = None
912 912 tmax = None
913 913 x = dataOut.getTimeRange()
914 914 y = dataOut.getHeiRange()
915 915
916 916 #thisDatetime = dataOut.datatime
917 917 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
918 918 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
919 919 xlabel = ""
920 920 ylabel = "Range (Km)"
921 921
922 922 if not self.__isConfig:
923 923 nplots = len(pairsIndexList)
924 924 self.setup(id=id,
925 925 nplots=nplots,
926 926 wintitle=wintitle,
927 927 showprofile=showprofile,
928 928 show=show)
929 929
930 930 tmin, tmax = self.getTimeLim(x, xmin, xmax)
931 931 if ymin == None: ymin = numpy.nanmin(y)
932 932 if ymax == None: ymax = numpy.nanmax(y)
933 933 if zmin == None: zmin = 0.
934 934 if zmax == None: zmax = 1.
935 935
936 936 self.FTP_WEI = ftp_wei
937 937 self.EXP_CODE = exp_code
938 938 self.SUB_EXP_CODE = sub_exp_code
939 939 self.PLOT_POS = plot_pos
940 940
941 941 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
942 942
943 943 self.__isConfig = True
944 944
945 945 self.setWinTitle(title)
946 946
947 947 for i in range(self.nplots):
948 948
949 949 pair = dataOut.pairsList[pairsIndexList[i]]
950 950 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
951 951 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
952 952 # coherence = numpy.abs(avgcoherenceComplex)
953 953
954 954 ## coherence = numpy.abs(coherenceComplex)
955 955 ## avg = numpy.average(coherence, axis=0)
956 956
957 957 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
958 958 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
959 959 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
960 960
961 961
962 962 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
963 963 coherence = numpy.abs(avgcoherenceComplex)
964 964
965 965 z = coherence.reshape((1,-1))
966 966
967 967 counter = 0
968 968
969 969 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
970 970 axes = self.axesList[i*self.__nsubplots*2]
971 971 axes.pcolorbuffer(x, y, z,
972 972 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
973 973 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
974 974 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
975 975
976 976 if self.__showprofile:
977 977 counter += 1
978 978 axes = self.axesList[i*self.__nsubplots*2 + counter]
979 979 axes.pline(coherence, y,
980 980 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
981 981 xlabel='', ylabel='', title='', ticksize=7,
982 982 ytick_visible=False, nxticks=5,
983 983 grid='x')
984 984
985 985 counter += 1
986 986 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
987 987 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
988 988 # avg = numpy.average(phase, axis=0)
989 989 z = phase.reshape((1,-1))
990 990
991 991 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
992 992 axes = self.axesList[i*self.__nsubplots*2 + counter]
993 993 axes.pcolorbuffer(x, y, z,
994 994 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
995 995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
996 996 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
997 997
998 998 if self.__showprofile:
999 999 counter += 1
1000 1000 axes = self.axesList[i*self.__nsubplots*2 + counter]
1001 1001 axes.pline(phase, y,
1002 1002 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
1003 1003 xlabel='', ylabel='', title='', ticksize=7,
1004 1004 ytick_visible=False, nxticks=4,
1005 1005 grid='x')
1006 1006
1007 1007 self.draw()
1008 1008
1009 1009 if save:
1010 1010
1011 1011 self.counter_imagwr += 1
1012 1012 if (self.counter_imagwr==wr_period):
1013 1013 if figfile == None:
1014 1014 figfile = self.getFilename(name = self.name)
1015 1015 self.saveFigure(figpath, figfile)
1016 1016
1017 1017 if ftp:
1018 1018 #provisionalmente envia archivos en el formato de la web en tiempo real
1019 1019 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1020 1020 path = '%s%03d' %(self.PREFIX, self.id)
1021 1021 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1022 1022 self.saveFigure(figpath, ftp_file)
1023 1023 ftp_filename = os.path.join(figpath,ftp_file)
1024 1024 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1025 1025 self.counter_imagwr = 0
1026 1026
1027 1027 self.counter_imagwr = 0
1028 1028
1029 1029
1030 1030 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1031 1031 self.__isConfig = False
1032 1032
1033 1033 class BeaconPhase(Figure):
1034 1034
1035 1035 __isConfig = None
1036 1036 __nsubplots = None
1037 1037
1038 1038 PREFIX = 'beacon_phase'
1039 1039
1040 1040 def __init__(self):
1041 1041
1042 1042 self.timerange = 24*60*60
1043 1043 self.__isConfig = False
1044 1044 self.__nsubplots = 1
1045 1045 self.counter_imagwr = 0
1046 1046 self.WIDTH = 600
1047 1047 self.HEIGHT = 300
1048 1048 self.WIDTHPROF = 120
1049 1049 self.HEIGHTPROF = 0
1050 1050 self.xdata = None
1051 1051 self.ydata = None
1052 1052
1053 self.PLOT_CODE = 999999
1053 self.PLOT_CODE = 18
1054 1054 self.FTP_WEI = None
1055 1055 self.EXP_CODE = None
1056 1056 self.SUB_EXP_CODE = None
1057 1057 self.PLOT_POS = None
1058 1058
1059 1059 def getSubplots(self):
1060 1060
1061 1061 ncol = 1
1062 1062 nrow = 1
1063 1063
1064 1064 return nrow, ncol
1065 1065
1066 1066 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1067 1067
1068 1068 self.__showprofile = showprofile
1069 1069 self.nplots = nplots
1070 1070
1071 1071 ncolspan = 7
1072 1072 colspan = 6
1073 1073 self.__nsubplots = 2
1074 1074
1075 1075 self.createFigure(id = id,
1076 1076 wintitle = wintitle,
1077 1077 widthplot = self.WIDTH+self.WIDTHPROF,
1078 1078 heightplot = self.HEIGHT+self.HEIGHTPROF,
1079 1079 show=show)
1080 1080
1081 1081 nrow, ncol = self.getSubplots()
1082 1082
1083 1083 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1084 1084
1085 1085
1086 1086 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1087 1087 xmin=None, xmax=None, ymin=None, ymax=None,
1088 1088 timerange=None,
1089 1089 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1090 1090 server=None, folder=None, username=None, password=None,
1091 1091 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1092 1092
1093 1093 if pairsList == None:
1094 1094 pairsIndexList = dataOut.pairsIndexList
1095 1095 else:
1096 1096 pairsIndexList = []
1097 1097 for pair in pairsList:
1098 1098 if pair not in dataOut.pairsList:
1099 1099 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1100 1100 pairsIndexList.append(dataOut.pairsList.index(pair))
1101 1101
1102 1102 if pairsIndexList == []:
1103 1103 return
1104 1104
1105 if len(pairsIndexList) > 4:
1106 pairsIndexList = pairsIndexList[0:4]
1105 # if len(pairsIndexList) > 4:
1106 # pairsIndexList = pairsIndexList[0:4]
1107 1107
1108 1108 if timerange != None:
1109 1109 self.timerange = timerange
1110 1110
1111 1111 tmin = None
1112 1112 tmax = None
1113 1113 x = dataOut.getTimeRange()
1114 1114 y = dataOut.getHeiRange()
1115 1115
1116 1116
1117 1117 #thisDatetime = dataOut.datatime
1118 1118 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1119 1119 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1120 1120 xlabel = "Local Time"
1121 1121 ylabel = "Phase"
1122 1122
1123 1123 nplots = len(pairsIndexList)
1124 1124 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1125 1125 phase_beacon = numpy.zeros(len(pairsIndexList))
1126 1126 for i in range(nplots):
1127 1127 pair = dataOut.pairsList[pairsIndexList[i]]
1128 1128 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1129 1129 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1130 1130 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1131 1131 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1132 1132 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1133 1133
1134 1134 #print "Phase %d%d" %(pair[0], pair[1])
1135 1135 #print phase[dataOut.beacon_heiIndexList]
1136 1136
1137 1137 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1138 1138
1139 1139 if not self.__isConfig:
1140 1140
1141 1141 nplots = len(pairsIndexList)
1142 1142
1143 1143 self.setup(id=id,
1144 1144 nplots=nplots,
1145 1145 wintitle=wintitle,
1146 1146 showprofile=showprofile,
1147 1147 show=show)
1148 1148
1149 1149 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1150 1150 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1151 1151 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1152 1152
1153 1153 self.FTP_WEI = ftp_wei
1154 1154 self.EXP_CODE = exp_code
1155 1155 self.SUB_EXP_CODE = sub_exp_code
1156 1156 self.PLOT_POS = plot_pos
1157 1157
1158 1158 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1159
1160
1161 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1162 1159 self.__isConfig = True
1163 1160
1164 1161 self.xdata = numpy.array([])
1165 1162 self.ydata = numpy.array([])
1166 1163
1167 1164 self.setWinTitle(title)
1168 1165
1169 1166
1170 1167 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1171 1168
1172 1169 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1173 1170
1174 1171 axes = self.axesList[0]
1175 1172
1176 1173 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1177 1174
1178 1175 if len(self.ydata)==0:
1179 1176 self.ydata = phase_beacon.reshape(-1,1)
1180 1177 else:
1181 1178 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1182 1179
1183 1180
1184 1181 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1185 1182 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1186 1183 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1187 1184 XAxisAsTime=True, grid='both'
1188 1185 )
1189 1186
1190 1187 self.draw()
1188
1189 if save:
1190
1191 self.counter_imagwr += 1
1192 if (self.counter_imagwr==wr_period):
1193 if figfile == None:
1194 figfile = self.getFilename(name = self.name)
1195 self.saveFigure(figpath, figfile)
1196
1197 if ftp:
1198 #provisionalmente envia archivos en el formato de la web en tiempo real
1199 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1200 path = '%s%03d' %(self.PREFIX, self.id)
1201 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1202 self.saveFigure(figpath, ftp_file)
1203 ftp_filename = os.path.join(figpath,ftp_file)
1204 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1205
1206 self.counter_imagwr = 0
1207
1208 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1209 self.__isConfig = False
1210 del self.xdata
1211 del self.ydata
1212
1213
1191 1214
1192 1215
1193 1216 class Noise(Figure):
1194 1217
1195 1218 __isConfig = None
1196 1219 __nsubplots = None
1197 1220
1198 1221 PREFIX = 'noise'
1199 1222
1200 1223 def __init__(self):
1201 1224
1202 1225 self.timerange = 24*60*60
1203 1226 self.__isConfig = False
1204 1227 self.__nsubplots = 1
1205 1228 self.counter_imagwr = 0
1206 1229 self.WIDTH = 600
1207 1230 self.HEIGHT = 300
1208 1231 self.WIDTHPROF = 120
1209 1232 self.HEIGHTPROF = 0
1210 1233 self.xdata = None
1211 1234 self.ydata = None
1212 1235
1213 1236 self.PLOT_CODE = 77
1214 1237 self.FTP_WEI = None
1215 1238 self.EXP_CODE = None
1216 1239 self.SUB_EXP_CODE = None
1217 1240 self.PLOT_POS = None
1218 1241
1219 1242 def getSubplots(self):
1220 1243
1221 1244 ncol = 1
1222 1245 nrow = 1
1223 1246
1224 1247 return nrow, ncol
1225 1248
1226 1249 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1227 1250
1228 1251 self.__showprofile = showprofile
1229 1252 self.nplots = nplots
1230 1253
1231 1254 ncolspan = 7
1232 1255 colspan = 6
1233 1256 self.__nsubplots = 2
1234 1257
1235 1258 self.createFigure(id = id,
1236 1259 wintitle = wintitle,
1237 1260 widthplot = self.WIDTH+self.WIDTHPROF,
1238 1261 heightplot = self.HEIGHT+self.HEIGHTPROF,
1239 1262 show=show)
1240 1263
1241 1264 nrow, ncol = self.getSubplots()
1242 1265
1243 1266 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1244 1267
1245 1268
1246 1269 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1247 1270 xmin=None, xmax=None, ymin=None, ymax=None,
1248 1271 timerange=None,
1249 1272 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1250 1273 server=None, folder=None, username=None, password=None,
1251 1274 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1252 1275
1253 1276 if channelList == None:
1254 1277 channelIndexList = dataOut.channelIndexList
1255 1278 channelList = dataOut.channelList
1256 1279 else:
1257 1280 channelIndexList = []
1258 1281 for channel in channelList:
1259 1282 if channel not in dataOut.channelList:
1260 1283 raise ValueError, "Channel %d is not in dataOut.channelList"
1261 1284 channelIndexList.append(dataOut.channelList.index(channel))
1262 1285
1263 1286 if timerange != None:
1264 1287 self.timerange = timerange
1265 1288
1266 1289 tmin = None
1267 1290 tmax = None
1268 1291 x = dataOut.getTimeRange()
1269 1292 y = dataOut.getHeiRange()
1270 1293 #factor = dataOut.normFactor
1271 1294 noise = dataOut.getNoise()#/factor
1272 1295 noisedB = 10*numpy.log10(noise)
1273 1296
1274 1297 #thisDatetime = dataOut.datatime
1275 1298 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1276 1299 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1277 1300 xlabel = ""
1278 1301 ylabel = "Intensity (dB)"
1279 1302
1280 1303 if not self.__isConfig:
1281 1304
1282 1305 nplots = 1
1283 1306
1284 1307 self.setup(id=id,
1285 1308 nplots=nplots,
1286 1309 wintitle=wintitle,
1287 1310 showprofile=showprofile,
1288 1311 show=show)
1289 1312
1290 1313 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1291 1314 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1292 1315 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1293 1316
1294 1317 self.FTP_WEI = ftp_wei
1295 1318 self.EXP_CODE = exp_code
1296 1319 self.SUB_EXP_CODE = sub_exp_code
1297 1320 self.PLOT_POS = plot_pos
1298 1321
1299 1322 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1300 1323
1301 1324
1302 1325 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1303 1326 self.__isConfig = True
1304 1327
1305 1328 self.xdata = numpy.array([])
1306 1329 self.ydata = numpy.array([])
1307 1330
1308 1331 self.setWinTitle(title)
1309 1332
1310 1333
1311 1334 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1312 1335
1313 1336 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1314 1337 axes = self.axesList[0]
1315 1338
1316 1339 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1317 1340
1318 1341 if len(self.ydata)==0:
1319 1342 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1320 1343 else:
1321 1344 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1322 1345
1323 1346
1324 1347 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1325 1348 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1326 1349 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1327 1350 XAxisAsTime=True, grid='both'
1328 1351 )
1329 1352
1330 1353 self.draw()
1331 1354
1332 1355 # if save:
1333 1356 #
1334 1357 # if figfile == None:
1335 1358 # figfile = self.getFilename(name = self.name)
1336 1359 #
1337 1360 # self.saveFigure(figpath, figfile)
1338 1361
1339 1362 if save:
1340 1363
1341 1364 self.counter_imagwr += 1
1342 1365 if (self.counter_imagwr==wr_period):
1343 1366 if figfile == None:
1344 1367 figfile = self.getFilename(name = self.name)
1345 1368 self.saveFigure(figpath, figfile)
1346 1369
1347 1370 if ftp:
1348 1371 #provisionalmente envia archivos en el formato de la web en tiempo real
1349 1372 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1350 1373 path = '%s%03d' %(self.PREFIX, self.id)
1351 1374 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1352 1375 self.saveFigure(figpath, ftp_file)
1353 1376 ftp_filename = os.path.join(figpath,ftp_file)
1354 1377 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1355 1378 self.counter_imagwr = 0
1356 1379
1357 1380 self.counter_imagwr = 0
1358 1381
1359 1382 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1360 1383 self.__isConfig = False
1361 1384 del self.xdata
1362 1385 del self.ydata
1363 1386
1364 1387
1365 1388 class SpectraHeisScope(Figure):
1366 1389
1367 1390
1368 1391 __isConfig = None
1369 1392 __nsubplots = None
1370 1393
1371 1394 WIDTHPROF = None
1372 1395 HEIGHTPROF = None
1373 1396 PREFIX = 'spc'
1374 1397
1375 1398 def __init__(self):
1376 1399
1377 1400 self.__isConfig = False
1378 1401 self.__nsubplots = 1
1379 1402
1380 1403 self.WIDTH = 230
1381 1404 self.HEIGHT = 250
1382 1405 self.WIDTHPROF = 120
1383 1406 self.HEIGHTPROF = 0
1384 1407 self.counter_imagwr = 0
1385 1408
1386 1409 def getSubplots(self):
1387 1410
1388 1411 ncol = int(numpy.sqrt(self.nplots)+0.9)
1389 1412 nrow = int(self.nplots*1./ncol + 0.9)
1390 1413
1391 1414 return nrow, ncol
1392 1415
1393 1416 def setup(self, id, nplots, wintitle, show):
1394 1417
1395 1418 showprofile = False
1396 1419 self.__showprofile = showprofile
1397 1420 self.nplots = nplots
1398 1421
1399 1422 ncolspan = 1
1400 1423 colspan = 1
1401 1424 if showprofile:
1402 1425 ncolspan = 3
1403 1426 colspan = 2
1404 1427 self.__nsubplots = 2
1405 1428
1406 1429 self.createFigure(id = id,
1407 1430 wintitle = wintitle,
1408 1431 widthplot = self.WIDTH + self.WIDTHPROF,
1409 1432 heightplot = self.HEIGHT + self.HEIGHTPROF,
1410 1433 show = show)
1411 1434
1412 1435 nrow, ncol = self.getSubplots()
1413 1436
1414 1437 counter = 0
1415 1438 for y in range(nrow):
1416 1439 for x in range(ncol):
1417 1440
1418 1441 if counter >= self.nplots:
1419 1442 break
1420 1443
1421 1444 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1422 1445
1423 1446 if showprofile:
1424 1447 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1425 1448
1426 1449 counter += 1
1427 1450
1428 1451
1429 1452 def run(self, dataOut, id, wintitle="", channelList=None,
1430 1453 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1431 1454 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1432 1455 server=None, folder=None, username=None, password=None):
1433 1456
1434 1457 """
1435 1458
1436 1459 Input:
1437 1460 dataOut :
1438 1461 id :
1439 1462 wintitle :
1440 1463 channelList :
1441 1464 xmin : None,
1442 1465 xmax : None,
1443 1466 ymin : None,
1444 1467 ymax : None,
1445 1468 """
1446 1469
1447 1470 if dataOut.realtime:
1448 1471 if not(isRealtime(utcdatatime = dataOut.utctime)):
1449 1472 print 'Skipping this plot function'
1450 1473 return
1451 1474
1452 1475 if channelList == None:
1453 1476 channelIndexList = dataOut.channelIndexList
1454 1477 else:
1455 1478 channelIndexList = []
1456 1479 for channel in channelList:
1457 1480 if channel not in dataOut.channelList:
1458 1481 raise ValueError, "Channel %d is not in dataOut.channelList"
1459 1482 channelIndexList.append(dataOut.channelList.index(channel))
1460 1483
1461 1484 # x = dataOut.heightList
1462 1485 c = 3E8
1463 1486 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1464 1487 #deberia cambiar para el caso de 1Mhz y 100KHz
1465 1488 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1466 1489 #para 1Mhz descomentar la siguiente linea
1467 1490 #x= x/(10000.0)
1468 1491 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1469 1492 # y = y.real
1470 1493 datadB = 10.*numpy.log10(dataOut.data_spc)
1471 1494 y = datadB
1472 1495
1473 1496 #thisDatetime = dataOut.datatime
1474 1497 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1475 1498 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1476 1499 xlabel = ""
1477 1500 #para 1Mhz descomentar la siguiente linea
1478 1501 #xlabel = "Frequency x 10000"
1479 1502 ylabel = "Intensity (dB)"
1480 1503
1481 1504 if not self.__isConfig:
1482 1505 nplots = len(channelIndexList)
1483 1506
1484 1507 self.setup(id=id,
1485 1508 nplots=nplots,
1486 1509 wintitle=wintitle,
1487 1510 show=show)
1488 1511
1489 1512 if xmin == None: xmin = numpy.nanmin(x)
1490 1513 if xmax == None: xmax = numpy.nanmax(x)
1491 1514 if ymin == None: ymin = numpy.nanmin(y)
1492 1515 if ymax == None: ymax = numpy.nanmax(y)
1493 1516
1494 1517 self.__isConfig = True
1495 1518
1496 1519 self.setWinTitle(title)
1497 1520
1498 1521 for i in range(len(self.axesList)):
1499 1522 ychannel = y[i,:]
1500 1523 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1501 1524 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
1502 1525 axes = self.axesList[i]
1503 1526 axes.pline(x, ychannel,
1504 1527 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1505 1528 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1506 1529
1507 1530
1508 1531 self.draw()
1509 1532
1510 1533 if save:
1511 1534 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1512 1535 if figfile == None:
1513 1536 figfile = self.getFilename(name = date)
1514 1537
1515 1538 self.saveFigure(figpath, figfile)
1516 1539
1517 1540 self.counter_imagwr += 1
1518 1541 if (ftp and (self.counter_imagwr==wr_period)):
1519 1542 ftp_filename = os.path.join(figpath,figfile)
1520 1543 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1521 1544 self.counter_imagwr = 0
1522 1545
1523 1546
1524 1547 class RTIfromSpectraHeis(Figure):
1525 1548
1526 1549 __isConfig = None
1527 1550 __nsubplots = None
1528 1551
1529 1552 PREFIX = 'rtinoise'
1530 1553
1531 1554 def __init__(self):
1532 1555
1533 1556 self.timerange = 24*60*60
1534 1557 self.__isConfig = False
1535 1558 self.__nsubplots = 1
1536 1559
1537 1560 self.WIDTH = 820
1538 1561 self.HEIGHT = 200
1539 1562 self.WIDTHPROF = 120
1540 1563 self.HEIGHTPROF = 0
1541 1564 self.counter_imagwr = 0
1542 1565 self.xdata = None
1543 1566 self.ydata = None
1544 1567
1545 1568 def getSubplots(self):
1546 1569
1547 1570 ncol = 1
1548 1571 nrow = 1
1549 1572
1550 1573 return nrow, ncol
1551 1574
1552 1575 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1553 1576
1554 1577 self.__showprofile = showprofile
1555 1578 self.nplots = nplots
1556 1579
1557 1580 ncolspan = 7
1558 1581 colspan = 6
1559 1582 self.__nsubplots = 2
1560 1583
1561 1584 self.createFigure(id = id,
1562 1585 wintitle = wintitle,
1563 1586 widthplot = self.WIDTH+self.WIDTHPROF,
1564 1587 heightplot = self.HEIGHT+self.HEIGHTPROF,
1565 1588 show = show)
1566 1589
1567 1590 nrow, ncol = self.getSubplots()
1568 1591
1569 1592 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1570 1593
1571 1594
1572 1595 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1573 1596 xmin=None, xmax=None, ymin=None, ymax=None,
1574 1597 timerange=None,
1575 1598 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1576 1599 server=None, folder=None, username=None, password=None):
1577 1600
1578 1601 if channelList == None:
1579 1602 channelIndexList = dataOut.channelIndexList
1580 1603 channelList = dataOut.channelList
1581 1604 else:
1582 1605 channelIndexList = []
1583 1606 for channel in channelList:
1584 1607 if channel not in dataOut.channelList:
1585 1608 raise ValueError, "Channel %d is not in dataOut.channelList"
1586 1609 channelIndexList.append(dataOut.channelList.index(channel))
1587 1610
1588 1611 if timerange != None:
1589 1612 self.timerange = timerange
1590 1613
1591 1614 tmin = None
1592 1615 tmax = None
1593 1616 x = dataOut.getTimeRange()
1594 1617 y = dataOut.getHeiRange()
1595 1618
1596 1619 #factor = 1
1597 1620 data = dataOut.data_spc#/factor
1598 1621 data = numpy.average(data,axis=1)
1599 1622 datadB = 10*numpy.log10(data)
1600 1623
1601 1624 # factor = dataOut.normFactor
1602 1625 # noise = dataOut.getNoise()/factor
1603 1626 # noisedB = 10*numpy.log10(noise)
1604 1627
1605 1628 #thisDatetime = dataOut.datatime
1606 1629 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1607 1630 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1608 1631 xlabel = "Local Time"
1609 1632 ylabel = "Intensity (dB)"
1610 1633
1611 1634 if not self.__isConfig:
1612 1635
1613 1636 nplots = 1
1614 1637
1615 1638 self.setup(id=id,
1616 1639 nplots=nplots,
1617 1640 wintitle=wintitle,
1618 1641 showprofile=showprofile,
1619 1642 show=show)
1620 1643
1621 1644 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1622 1645 if ymin == None: ymin = numpy.nanmin(datadB)
1623 1646 if ymax == None: ymax = numpy.nanmax(datadB)
1624 1647
1625 1648 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1626 1649 self.__isConfig = True
1627 1650
1628 1651 self.xdata = numpy.array([])
1629 1652 self.ydata = numpy.array([])
1630 1653
1631 1654 self.setWinTitle(title)
1632 1655
1633 1656
1634 1657 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1635 1658 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1636 1659
1637 1660 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1638 1661 axes = self.axesList[0]
1639 1662
1640 1663 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1641 1664
1642 1665 if len(self.ydata)==0:
1643 1666 self.ydata = datadB[channelIndexList].reshape(-1,1)
1644 1667 else:
1645 1668 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1646 1669
1647 1670
1648 1671 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1649 1672 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1650 1673 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1651 1674 XAxisAsTime=True
1652 1675 )
1653 1676
1654 1677 self.draw()
1655 1678
1656 1679 if save:
1657 1680
1658 1681 if figfile == None:
1659 1682 figfile = self.getFilename(name = self.name)
1660 1683
1661 1684 self.saveFigure(figpath, figfile)
1662 1685
1663 1686 self.counter_imagwr += 1
1664 1687 if (ftp and (self.counter_imagwr==wr_period)):
1665 1688 ftp_filename = os.path.join(figpath,figfile)
1666 1689 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1667 1690 self.counter_imagwr = 0
1668 1691
1669 1692 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1670 1693 self.__isConfig = False
1671 1694 del self.xdata
1672 1695 del self.ydata
1673 1696
1674 1697
1675 1698 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now