##// END OF EJS Templates
se agregan variables para salvar graficos en disco para el ultimo bloque de datos o cuando se actualiza el eje x
Daniel Valdez -
r458:f4edc9ada2c8
parent child
Show More
@@ -1,1698 +1,1720
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 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
287 save=False, figpath='./', lastone=0,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 if save:
384 if lastone:
385 if dataOut.blocknow >= dataOut.last_block:
386 if figfile == None:
387 figfile = self.getFilename(name = self.name)
388 self.saveFigure(figpath, figfile)
389
390 if (save and not(lastone)):
385 391
386 392 self.counter_imagwr += 1
387 393 if (self.counter_imagwr==wr_period):
388 394 if figfile == None:
389 395 figfile = self.getFilename(name = self.name)
390 396 self.saveFigure(figpath, figfile)
391 397
392 398 if ftp:
393 399 #provisionalmente envia archivos en el formato de la web en tiempo real
394 400 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
395 401 path = '%s%03d' %(self.PREFIX, self.id)
396 402 ftp_file = os.path.join(path,'ftp','%s.png'%name)
397 403 self.saveFigure(figpath, ftp_file)
398 404 ftp_filename = os.path.join(figpath,ftp_file)
399 405 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
400 406 self.counter_imagwr = 0
401 407
402 408 self.counter_imagwr = 0
403 409
404 410 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
411
405 412 self.__isConfig = False
413
414 if lastone:
415 if figfile == None:
416 figfile = self.getFilename(name = self.name)
417 self.saveFigure(figpath, figfile)
418
419 if ftp:
420 #provisionalmente envia archivos en el formato de la web en tiempo real
421 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
422 path = '%s%03d' %(self.PREFIX, self.id)
423 ftp_file = os.path.join(path,'ftp','%s.png'%name)
424 self.saveFigure(figpath, ftp_file)
425 ftp_filename = os.path.join(figpath,ftp_file)
426 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
427
406 428
407 429 class SpectraPlot(Figure):
408 430
409 431 __isConfig = None
410 432 __nsubplots = None
411 433
412 434 WIDTHPROF = None
413 435 HEIGHTPROF = None
414 436 PREFIX = 'spc'
415 437
416 438 def __init__(self):
417 439
418 440 self.__isConfig = False
419 441 self.__nsubplots = 1
420 442
421 443 self.WIDTH = 280
422 444 self.HEIGHT = 250
423 445 self.WIDTHPROF = 120
424 446 self.HEIGHTPROF = 0
425 447 self.counter_imagwr = 0
426 448
427 449 self.PLOT_CODE = 1
428 450 self.FTP_WEI = None
429 451 self.EXP_CODE = None
430 452 self.SUB_EXP_CODE = None
431 453 self.PLOT_POS = None
432 454
433 455 def getSubplots(self):
434 456
435 457 ncol = int(numpy.sqrt(self.nplots)+0.9)
436 458 nrow = int(self.nplots*1./ncol + 0.9)
437 459
438 460 return nrow, ncol
439 461
440 462 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
441 463
442 464 self.__showprofile = showprofile
443 465 self.nplots = nplots
444 466
445 467 ncolspan = 1
446 468 colspan = 1
447 469 if showprofile:
448 470 ncolspan = 3
449 471 colspan = 2
450 472 self.__nsubplots = 2
451 473
452 474 self.createFigure(id = id,
453 475 wintitle = wintitle,
454 476 widthplot = self.WIDTH + self.WIDTHPROF,
455 477 heightplot = self.HEIGHT + self.HEIGHTPROF,
456 478 show=show)
457 479
458 480 nrow, ncol = self.getSubplots()
459 481
460 482 counter = 0
461 483 for y in range(nrow):
462 484 for x in range(ncol):
463 485
464 486 if counter >= self.nplots:
465 487 break
466 488
467 489 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
468 490
469 491 if showprofile:
470 492 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
471 493
472 494 counter += 1
473 495
474 496 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
475 497 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
476 498 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
477 499 server=None, folder=None, username=None, password=None,
478 500 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
479 501
480 502 """
481 503
482 504 Input:
483 505 dataOut :
484 506 id :
485 507 wintitle :
486 508 channelList :
487 509 showProfile :
488 510 xmin : None,
489 511 xmax : None,
490 512 ymin : None,
491 513 ymax : None,
492 514 zmin : None,
493 515 zmax : None
494 516 """
495 517
496 518 if realtime:
497 519 if not(isRealtime(utcdatatime = dataOut.utctime)):
498 520 print 'Skipping this plot function'
499 521 return
500 522
501 523 if channelList == None:
502 524 channelIndexList = dataOut.channelIndexList
503 525 else:
504 526 channelIndexList = []
505 527 for channel in channelList:
506 528 if channel not in dataOut.channelList:
507 529 raise ValueError, "Channel %d is not in dataOut.channelList"
508 530 channelIndexList.append(dataOut.channelList.index(channel))
509 531 #factor = dataOut.normFactor
510 532 x = dataOut.getVelRange(1)
511 533 y = dataOut.getHeiRange()
512 534
513 535 z = dataOut.data_spc[channelIndexList,:,:]#/factor
514 536 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
515 537 avg = numpy.average(z, axis=1)
516 538 noise = dataOut.getNoise()#/factor
517 539
518 540 zdB = 10*numpy.log10(z)
519 541 avgdB = 10*numpy.log10(avg)
520 542 noisedB = 10*numpy.log10(noise)
521 543
522 544 #thisDatetime = dataOut.datatime
523 545 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
524 546 title = wintitle + " Spectra"
525 547 xlabel = "Velocity (m/s)"
526 548 ylabel = "Range (Km)"
527 549
528 550 if not self.__isConfig:
529 551
530 552 nplots = len(channelIndexList)
531 553
532 554 self.setup(id=id,
533 555 nplots=nplots,
534 556 wintitle=wintitle,
535 557 showprofile=showprofile,
536 558 show=show)
537 559
538 560 if xmin == None: xmin = numpy.nanmin(x)
539 561 if xmax == None: xmax = numpy.nanmax(x)
540 562 if ymin == None: ymin = numpy.nanmin(y)
541 563 if ymax == None: ymax = numpy.nanmax(y)
542 564 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
543 565 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
544 566
545 567 self.FTP_WEI = ftp_wei
546 568 self.EXP_CODE = exp_code
547 569 self.SUB_EXP_CODE = sub_exp_code
548 570 self.PLOT_POS = plot_pos
549 571
550 572 self.__isConfig = True
551 573
552 574 self.setWinTitle(title)
553 575
554 576 for i in range(self.nplots):
555 577 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
556 578 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
557 579 axes = self.axesList[i*self.__nsubplots]
558 580 axes.pcolor(x, y, zdB[i,:,:],
559 581 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
560 582 xlabel=xlabel, ylabel=ylabel, title=title,
561 583 ticksize=9, cblabel='')
562 584
563 585 if self.__showprofile:
564 586 axes = self.axesList[i*self.__nsubplots +1]
565 587 axes.pline(avgdB[i], y,
566 588 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
567 589 xlabel='dB', ylabel='', title='',
568 590 ytick_visible=False,
569 591 grid='x')
570 592
571 593 noiseline = numpy.repeat(noisedB[i], len(y))
572 594 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
573 595
574 596 self.draw()
575 597
576 598 if save:
577 599
578 600 self.counter_imagwr += 1
579 601 if (self.counter_imagwr==wr_period):
580 602 if figfile == None:
581 603 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
582 604 figfile = self.getFilename(name = str_datetime)
583 605
584 606 self.saveFigure(figpath, figfile)
585 607
586 608 if ftp:
587 609 #provisionalmente envia archivos en el formato de la web en tiempo real
588 610 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
589 611 path = '%s%03d' %(self.PREFIX, self.id)
590 612 ftp_file = os.path.join(path,'ftp','%s.png'%name)
591 613 self.saveFigure(figpath, ftp_file)
592 614 ftp_filename = os.path.join(figpath,ftp_file)
593 615 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
594 616 self.counter_imagwr = 0
595 617
596 618
597 619 self.counter_imagwr = 0
598 620
599 621
600 622 class Scope(Figure):
601 623
602 624 __isConfig = None
603 625
604 626 def __init__(self):
605 627
606 628 self.__isConfig = False
607 629 self.WIDTH = 600
608 630 self.HEIGHT = 200
609 631 self.counter_imagwr = 0
610 632
611 633 def getSubplots(self):
612 634
613 635 nrow = self.nplots
614 636 ncol = 3
615 637 return nrow, ncol
616 638
617 639 def setup(self, id, nplots, wintitle, show):
618 640
619 641 self.nplots = nplots
620 642
621 643 self.createFigure(id=id,
622 644 wintitle=wintitle,
623 645 show=show)
624 646
625 647 nrow,ncol = self.getSubplots()
626 648 colspan = 3
627 649 rowspan = 1
628 650
629 651 for i in range(nplots):
630 652 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
631 653
632 654
633 655
634 656 def run(self, dataOut, id, wintitle="", channelList=None,
635 657 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
636 658 figpath='./', figfile=None, show=True, wr_period=1,
637 659 server=None, folder=None, username=None, password=None):
638 660
639 661 """
640 662
641 663 Input:
642 664 dataOut :
643 665 id :
644 666 wintitle :
645 667 channelList :
646 668 xmin : None,
647 669 xmax : None,
648 670 ymin : None,
649 671 ymax : None,
650 672 """
651 673
652 674 if channelList == None:
653 675 channelIndexList = dataOut.channelIndexList
654 676 else:
655 677 channelIndexList = []
656 678 for channel in channelList:
657 679 if channel not in dataOut.channelList:
658 680 raise ValueError, "Channel %d is not in dataOut.channelList"
659 681 channelIndexList.append(dataOut.channelList.index(channel))
660 682
661 683 x = dataOut.heightList
662 684 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
663 685 y = y.real
664 686
665 687 #thisDatetime = dataOut.datatime
666 688 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
667 689 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
668 690 xlabel = "Range (Km)"
669 691 ylabel = "Intensity"
670 692
671 693 if not self.__isConfig:
672 694 nplots = len(channelIndexList)
673 695
674 696 self.setup(id=id,
675 697 nplots=nplots,
676 698 wintitle=wintitle,
677 699 show=show)
678 700
679 701 if xmin == None: xmin = numpy.nanmin(x)
680 702 if xmax == None: xmax = numpy.nanmax(x)
681 703 if ymin == None: ymin = numpy.nanmin(y)
682 704 if ymax == None: ymax = numpy.nanmax(y)
683 705
684 706 self.__isConfig = True
685 707
686 708 self.setWinTitle(title)
687 709
688 710 for i in range(len(self.axesList)):
689 711 title = "Channel %d" %(i)
690 712 axes = self.axesList[i]
691 713 ychannel = y[i,:]
692 714 axes.pline(x, ychannel,
693 715 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
694 716 xlabel=xlabel, ylabel=ylabel, title=title)
695 717
696 718 self.draw()
697 719
698 720 if save:
699 721 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
700 722 if figfile == None:
701 723 figfile = self.getFilename(name = date)
702 724
703 725 self.saveFigure(figpath, figfile)
704 726
705 727 self.counter_imagwr += 1
706 728 if (ftp and (self.counter_imagwr==wr_period)):
707 729 ftp_filename = os.path.join(figpath,figfile)
708 730 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
709 731 self.counter_imagwr = 0
710 732
711 733 class PowerProfilePlot(Figure):
712 734 __isConfig = None
713 735 __nsubplots = None
714 736
715 737 WIDTHPROF = None
716 738 HEIGHTPROF = None
717 739 PREFIX = 'spcprofile'
718 740
719 741 def __init__(self):
720 742 self.__isConfig = False
721 743 self.__nsubplots = 1
722 744
723 745 self.WIDTH = 300
724 746 self.HEIGHT = 500
725 747 self.counter_imagwr = 0
726 748
727 749 def getSubplots(self):
728 750 ncol = 1
729 751 nrow = 1
730 752
731 753 return nrow, ncol
732 754
733 755 def setup(self, id, nplots, wintitle, show):
734 756
735 757 self.nplots = nplots
736 758
737 759 ncolspan = 1
738 760 colspan = 1
739 761
740 762 self.createFigure(id = id,
741 763 wintitle = wintitle,
742 764 widthplot = self.WIDTH,
743 765 heightplot = self.HEIGHT,
744 766 show=show)
745 767
746 768 nrow, ncol = self.getSubplots()
747 769
748 770 counter = 0
749 771 for y in range(nrow):
750 772 for x in range(ncol):
751 773 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
752 774
753 775 def run(self, dataOut, id, wintitle="", channelList=None,
754 776 xmin=None, xmax=None, ymin=None, ymax=None,
755 777 save=False, figpath='./', figfile=None, show=True, wr_period=1,
756 778 server=None, folder=None, username=None, password=None,):
757 779
758 780 if channelList == None:
759 781 channelIndexList = dataOut.channelIndexList
760 782 channelList = dataOut.channelList
761 783 else:
762 784 channelIndexList = []
763 785 for channel in channelList:
764 786 if channel not in dataOut.channelList:
765 787 raise ValueError, "Channel %d is not in dataOut.channelList"
766 788 channelIndexList.append(dataOut.channelList.index(channel))
767 789
768 790 #factor = dataOut.normFactor
769 791 y = dataOut.getHeiRange()
770 792 x = dataOut.data_spc[channelIndexList,:,:]#/factor
771 793 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
772 794 avg = numpy.average(x, axis=1)
773 795
774 796 avgdB = 10*numpy.log10(avg)
775 797
776 798 #thisDatetime = dataOut.datatime
777 799 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
778 800 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
779 801 xlabel = "dB"
780 802 ylabel = "Range (Km)"
781 803
782 804 if not self.__isConfig:
783 805
784 806 nplots = 1
785 807
786 808 self.setup(id=id,
787 809 nplots=nplots,
788 810 wintitle=wintitle,
789 811 show=show)
790 812
791 813 if ymin == None: ymin = numpy.nanmin(y)
792 814 if ymax == None: ymax = numpy.nanmax(y)
793 815 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
794 816 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
795 817
796 818 self.__isConfig = True
797 819
798 820 self.setWinTitle(title)
799 821
800 822
801 823 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
802 824 axes = self.axesList[0]
803 825
804 826 legendlabels = ["channel %d"%x for x in channelList]
805 827 axes.pmultiline(avgdB, y,
806 828 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
807 829 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
808 830 ytick_visible=True, nxticks=5,
809 831 grid='x')
810 832
811 833 self.draw()
812 834
813 835 if save:
814 836 date = thisDatetime.strftime("%Y%m%d")
815 837 if figfile == None:
816 838 figfile = self.getFilename(name = date)
817 839
818 840 self.saveFigure(figpath, figfile)
819 841
820 842 self.counter_imagwr += 1
821 843 if (ftp and (self.counter_imagwr==wr_period)):
822 844 ftp_filename = os.path.join(figpath,figfile)
823 845 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
824 846 self.counter_imagwr = 0
825 847
826 848 class CoherenceMap(Figure):
827 849 __isConfig = None
828 850 __nsubplots = None
829 851
830 852 WIDTHPROF = None
831 853 HEIGHTPROF = None
832 854 PREFIX = 'cmap'
833 855
834 856 def __init__(self):
835 857 self.timerange = 2*60*60
836 858 self.__isConfig = False
837 859 self.__nsubplots = 1
838 860
839 861 self.WIDTH = 800
840 862 self.HEIGHT = 150
841 863 self.WIDTHPROF = 120
842 864 self.HEIGHTPROF = 0
843 865 self.counter_imagwr = 0
844 866
845 867 self.PLOT_CODE = 3
846 868 self.FTP_WEI = None
847 869 self.EXP_CODE = None
848 870 self.SUB_EXP_CODE = None
849 871 self.PLOT_POS = None
850 872 self.counter_imagwr = 0
851 873
852 874 def getSubplots(self):
853 875 ncol = 1
854 876 nrow = self.nplots*2
855 877
856 878 return nrow, ncol
857 879
858 880 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
859 881 self.__showprofile = showprofile
860 882 self.nplots = nplots
861 883
862 884 ncolspan = 1
863 885 colspan = 1
864 886 if showprofile:
865 887 ncolspan = 7
866 888 colspan = 6
867 889 self.__nsubplots = 2
868 890
869 891 self.createFigure(id = id,
870 892 wintitle = wintitle,
871 893 widthplot = self.WIDTH + self.WIDTHPROF,
872 894 heightplot = self.HEIGHT + self.HEIGHTPROF,
873 895 show=True)
874 896
875 897 nrow, ncol = self.getSubplots()
876 898
877 899 for y in range(nrow):
878 900 for x in range(ncol):
879 901
880 902 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
881 903
882 904 if showprofile:
883 905 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
884 906
885 907 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
886 908 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
887 909 timerange=None,
888 910 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
889 911 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
890 912 server=None, folder=None, username=None, password=None,
891 913 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
892 914
893 915 if pairsList == None:
894 916 pairsIndexList = dataOut.pairsIndexList
895 917 else:
896 918 pairsIndexList = []
897 919 for pair in pairsList:
898 920 if pair not in dataOut.pairsList:
899 921 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
900 922 pairsIndexList.append(dataOut.pairsList.index(pair))
901 923
902 924 if timerange != None:
903 925 self.timerange = timerange
904 926
905 927 if pairsIndexList == []:
906 928 return
907 929
908 930 if len(pairsIndexList) > 4:
909 931 pairsIndexList = pairsIndexList[0:4]
910 932
911 933 tmin = None
912 934 tmax = None
913 935 x = dataOut.getTimeRange()
914 936 y = dataOut.getHeiRange()
915 937
916 938 #thisDatetime = dataOut.datatime
917 939 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
918 940 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
919 941 xlabel = ""
920 942 ylabel = "Range (Km)"
921 943
922 944 if not self.__isConfig:
923 945 nplots = len(pairsIndexList)
924 946 self.setup(id=id,
925 947 nplots=nplots,
926 948 wintitle=wintitle,
927 949 showprofile=showprofile,
928 950 show=show)
929 951
930 952 tmin, tmax = self.getTimeLim(x, xmin, xmax)
931 953 if ymin == None: ymin = numpy.nanmin(y)
932 954 if ymax == None: ymax = numpy.nanmax(y)
933 955 if zmin == None: zmin = 0.
934 956 if zmax == None: zmax = 1.
935 957
936 958 self.FTP_WEI = ftp_wei
937 959 self.EXP_CODE = exp_code
938 960 self.SUB_EXP_CODE = sub_exp_code
939 961 self.PLOT_POS = plot_pos
940 962
941 963 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
942 964
943 965 self.__isConfig = True
944 966
945 967 self.setWinTitle(title)
946 968
947 969 for i in range(self.nplots):
948 970
949 971 pair = dataOut.pairsList[pairsIndexList[i]]
950 972 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
951 973 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
952 974 # coherence = numpy.abs(avgcoherenceComplex)
953 975
954 976 ## coherence = numpy.abs(coherenceComplex)
955 977 ## avg = numpy.average(coherence, axis=0)
956 978
957 979 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
958 980 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
959 981 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
960 982
961 983
962 984 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
963 985 coherence = numpy.abs(avgcoherenceComplex)
964 986
965 987 z = coherence.reshape((1,-1))
966 988
967 989 counter = 0
968 990
969 991 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
970 992 axes = self.axesList[i*self.__nsubplots*2]
971 993 axes.pcolorbuffer(x, y, z,
972 994 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
973 995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
974 996 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
975 997
976 998 if self.__showprofile:
977 999 counter += 1
978 1000 axes = self.axesList[i*self.__nsubplots*2 + counter]
979 1001 axes.pline(coherence, y,
980 1002 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
981 1003 xlabel='', ylabel='', title='', ticksize=7,
982 1004 ytick_visible=False, nxticks=5,
983 1005 grid='x')
984 1006
985 1007 counter += 1
986 1008 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
987 1009 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
988 1010 # avg = numpy.average(phase, axis=0)
989 1011 z = phase.reshape((1,-1))
990 1012
991 1013 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
992 1014 axes = self.axesList[i*self.__nsubplots*2 + counter]
993 1015 axes.pcolorbuffer(x, y, z,
994 1016 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
995 1017 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
996 1018 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
997 1019
998 1020 if self.__showprofile:
999 1021 counter += 1
1000 1022 axes = self.axesList[i*self.__nsubplots*2 + counter]
1001 1023 axes.pline(phase, y,
1002 1024 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
1003 1025 xlabel='', ylabel='', title='', ticksize=7,
1004 1026 ytick_visible=False, nxticks=4,
1005 1027 grid='x')
1006 1028
1007 1029 self.draw()
1008 1030
1009 1031 if save:
1010 1032
1011 1033 self.counter_imagwr += 1
1012 1034 if (self.counter_imagwr==wr_period):
1013 1035 if figfile == None:
1014 1036 figfile = self.getFilename(name = self.name)
1015 1037 self.saveFigure(figpath, figfile)
1016 1038
1017 1039 if ftp:
1018 1040 #provisionalmente envia archivos en el formato de la web en tiempo real
1019 1041 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1020 1042 path = '%s%03d' %(self.PREFIX, self.id)
1021 1043 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1022 1044 self.saveFigure(figpath, ftp_file)
1023 1045 ftp_filename = os.path.join(figpath,ftp_file)
1024 1046 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1025 1047 self.counter_imagwr = 0
1026 1048
1027 1049 self.counter_imagwr = 0
1028 1050
1029 1051
1030 1052 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1031 1053 self.__isConfig = False
1032 1054
1033 1055 class BeaconPhase(Figure):
1034 1056
1035 1057 __isConfig = None
1036 1058 __nsubplots = None
1037 1059
1038 1060 PREFIX = 'beacon_phase'
1039 1061
1040 1062 def __init__(self):
1041 1063
1042 1064 self.timerange = 24*60*60
1043 1065 self.__isConfig = False
1044 1066 self.__nsubplots = 1
1045 1067 self.counter_imagwr = 0
1046 1068 self.WIDTH = 600
1047 1069 self.HEIGHT = 300
1048 1070 self.WIDTHPROF = 120
1049 1071 self.HEIGHTPROF = 0
1050 1072 self.xdata = None
1051 1073 self.ydata = None
1052 1074
1053 1075 self.PLOT_CODE = 18
1054 1076 self.FTP_WEI = None
1055 1077 self.EXP_CODE = None
1056 1078 self.SUB_EXP_CODE = None
1057 1079 self.PLOT_POS = None
1058 1080
1059 1081 def getSubplots(self):
1060 1082
1061 1083 ncol = 1
1062 1084 nrow = 1
1063 1085
1064 1086 return nrow, ncol
1065 1087
1066 1088 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1067 1089
1068 1090 self.__showprofile = showprofile
1069 1091 self.nplots = nplots
1070 1092
1071 1093 ncolspan = 7
1072 1094 colspan = 6
1073 1095 self.__nsubplots = 2
1074 1096
1075 1097 self.createFigure(id = id,
1076 1098 wintitle = wintitle,
1077 1099 widthplot = self.WIDTH+self.WIDTHPROF,
1078 1100 heightplot = self.HEIGHT+self.HEIGHTPROF,
1079 1101 show=show)
1080 1102
1081 1103 nrow, ncol = self.getSubplots()
1082 1104
1083 1105 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1084 1106
1085 1107
1086 1108 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1087 1109 xmin=None, xmax=None, ymin=None, ymax=None,
1088 1110 timerange=None,
1089 1111 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1090 1112 server=None, folder=None, username=None, password=None,
1091 1113 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1092 1114
1093 1115 if pairsList == None:
1094 1116 pairsIndexList = dataOut.pairsIndexList
1095 1117 else:
1096 1118 pairsIndexList = []
1097 1119 for pair in pairsList:
1098 1120 if pair not in dataOut.pairsList:
1099 1121 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1100 1122 pairsIndexList.append(dataOut.pairsList.index(pair))
1101 1123
1102 1124 if pairsIndexList == []:
1103 1125 return
1104 1126
1105 1127 # if len(pairsIndexList) > 4:
1106 1128 # pairsIndexList = pairsIndexList[0:4]
1107 1129
1108 1130 if timerange != None:
1109 1131 self.timerange = timerange
1110 1132
1111 1133 tmin = None
1112 1134 tmax = None
1113 1135 x = dataOut.getTimeRange()
1114 1136 y = dataOut.getHeiRange()
1115 1137
1116 1138
1117 1139 #thisDatetime = dataOut.datatime
1118 1140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1119 1141 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1120 1142 xlabel = "Local Time"
1121 1143 ylabel = "Phase"
1122 1144
1123 1145 nplots = len(pairsIndexList)
1124 1146 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1125 1147 phase_beacon = numpy.zeros(len(pairsIndexList))
1126 1148 for i in range(nplots):
1127 1149 pair = dataOut.pairsList[pairsIndexList[i]]
1128 1150 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1129 1151 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1130 1152 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1131 1153 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1132 1154 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1133 1155
1134 1156 #print "Phase %d%d" %(pair[0], pair[1])
1135 1157 #print phase[dataOut.beacon_heiIndexList]
1136 1158
1137 1159 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1138 1160
1139 1161 if not self.__isConfig:
1140 1162
1141 1163 nplots = len(pairsIndexList)
1142 1164
1143 1165 self.setup(id=id,
1144 1166 nplots=nplots,
1145 1167 wintitle=wintitle,
1146 1168 showprofile=showprofile,
1147 1169 show=show)
1148 1170
1149 1171 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1150 1172 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1151 1173 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1152 1174
1153 1175 self.FTP_WEI = ftp_wei
1154 1176 self.EXP_CODE = exp_code
1155 1177 self.SUB_EXP_CODE = sub_exp_code
1156 1178 self.PLOT_POS = plot_pos
1157 1179
1158 1180 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1159 1181 self.__isConfig = True
1160 1182
1161 1183 self.xdata = numpy.array([])
1162 1184 self.ydata = numpy.array([])
1163 1185
1164 1186 self.setWinTitle(title)
1165 1187
1166 1188
1167 1189 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1168 1190
1169 1191 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1170 1192
1171 1193 axes = self.axesList[0]
1172 1194
1173 1195 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1174 1196
1175 1197 if len(self.ydata)==0:
1176 1198 self.ydata = phase_beacon.reshape(-1,1)
1177 1199 else:
1178 1200 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1179 1201
1180 1202
1181 1203 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1182 1204 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1183 1205 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1184 1206 XAxisAsTime=True, grid='both'
1185 1207 )
1186 1208
1187 1209 self.draw()
1188 1210
1189 1211 if save:
1190 1212
1191 1213 self.counter_imagwr += 1
1192 1214 if (self.counter_imagwr==wr_period):
1193 1215 if figfile == None:
1194 1216 figfile = self.getFilename(name = self.name)
1195 1217 self.saveFigure(figpath, figfile)
1196 1218
1197 1219 if ftp:
1198 1220 #provisionalmente envia archivos en el formato de la web en tiempo real
1199 1221 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1200 1222 path = '%s%03d' %(self.PREFIX, self.id)
1201 1223 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1202 1224 self.saveFigure(figpath, ftp_file)
1203 1225 ftp_filename = os.path.join(figpath,ftp_file)
1204 1226 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1205 1227
1206 1228 self.counter_imagwr = 0
1207 1229
1208 1230 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1209 1231 self.__isConfig = False
1210 1232 del self.xdata
1211 1233 del self.ydata
1212 1234
1213 1235
1214 1236
1215 1237
1216 1238 class Noise(Figure):
1217 1239
1218 1240 __isConfig = None
1219 1241 __nsubplots = None
1220 1242
1221 1243 PREFIX = 'noise'
1222 1244
1223 1245 def __init__(self):
1224 1246
1225 1247 self.timerange = 24*60*60
1226 1248 self.__isConfig = False
1227 1249 self.__nsubplots = 1
1228 1250 self.counter_imagwr = 0
1229 1251 self.WIDTH = 600
1230 1252 self.HEIGHT = 300
1231 1253 self.WIDTHPROF = 120
1232 1254 self.HEIGHTPROF = 0
1233 1255 self.xdata = None
1234 1256 self.ydata = None
1235 1257
1236 1258 self.PLOT_CODE = 77
1237 1259 self.FTP_WEI = None
1238 1260 self.EXP_CODE = None
1239 1261 self.SUB_EXP_CODE = None
1240 1262 self.PLOT_POS = None
1241 1263
1242 1264 def getSubplots(self):
1243 1265
1244 1266 ncol = 1
1245 1267 nrow = 1
1246 1268
1247 1269 return nrow, ncol
1248 1270
1249 1271 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1250 1272
1251 1273 self.__showprofile = showprofile
1252 1274 self.nplots = nplots
1253 1275
1254 1276 ncolspan = 7
1255 1277 colspan = 6
1256 1278 self.__nsubplots = 2
1257 1279
1258 1280 self.createFigure(id = id,
1259 1281 wintitle = wintitle,
1260 1282 widthplot = self.WIDTH+self.WIDTHPROF,
1261 1283 heightplot = self.HEIGHT+self.HEIGHTPROF,
1262 1284 show=show)
1263 1285
1264 1286 nrow, ncol = self.getSubplots()
1265 1287
1266 1288 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1267 1289
1268 1290
1269 1291 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1270 1292 xmin=None, xmax=None, ymin=None, ymax=None,
1271 1293 timerange=None,
1272 1294 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1273 1295 server=None, folder=None, username=None, password=None,
1274 1296 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1275 1297
1276 1298 if channelList == None:
1277 1299 channelIndexList = dataOut.channelIndexList
1278 1300 channelList = dataOut.channelList
1279 1301 else:
1280 1302 channelIndexList = []
1281 1303 for channel in channelList:
1282 1304 if channel not in dataOut.channelList:
1283 1305 raise ValueError, "Channel %d is not in dataOut.channelList"
1284 1306 channelIndexList.append(dataOut.channelList.index(channel))
1285 1307
1286 1308 if timerange != None:
1287 1309 self.timerange = timerange
1288 1310
1289 1311 tmin = None
1290 1312 tmax = None
1291 1313 x = dataOut.getTimeRange()
1292 1314 y = dataOut.getHeiRange()
1293 1315 #factor = dataOut.normFactor
1294 1316 noise = dataOut.getNoise()#/factor
1295 1317 noisedB = 10*numpy.log10(noise)
1296 1318
1297 1319 #thisDatetime = dataOut.datatime
1298 1320 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1299 1321 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1300 1322 xlabel = ""
1301 1323 ylabel = "Intensity (dB)"
1302 1324
1303 1325 if not self.__isConfig:
1304 1326
1305 1327 nplots = 1
1306 1328
1307 1329 self.setup(id=id,
1308 1330 nplots=nplots,
1309 1331 wintitle=wintitle,
1310 1332 showprofile=showprofile,
1311 1333 show=show)
1312 1334
1313 1335 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1314 1336 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1315 1337 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1316 1338
1317 1339 self.FTP_WEI = ftp_wei
1318 1340 self.EXP_CODE = exp_code
1319 1341 self.SUB_EXP_CODE = sub_exp_code
1320 1342 self.PLOT_POS = plot_pos
1321 1343
1322 1344 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1323 1345
1324 1346
1325 1347 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1326 1348 self.__isConfig = True
1327 1349
1328 1350 self.xdata = numpy.array([])
1329 1351 self.ydata = numpy.array([])
1330 1352
1331 1353 self.setWinTitle(title)
1332 1354
1333 1355
1334 1356 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1335 1357
1336 1358 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1337 1359 axes = self.axesList[0]
1338 1360
1339 1361 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1340 1362
1341 1363 if len(self.ydata)==0:
1342 1364 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1343 1365 else:
1344 1366 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1345 1367
1346 1368
1347 1369 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1348 1370 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1349 1371 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1350 1372 XAxisAsTime=True, grid='both'
1351 1373 )
1352 1374
1353 1375 self.draw()
1354 1376
1355 1377 # if save:
1356 1378 #
1357 1379 # if figfile == None:
1358 1380 # figfile = self.getFilename(name = self.name)
1359 1381 #
1360 1382 # self.saveFigure(figpath, figfile)
1361 1383
1362 1384 if save:
1363 1385
1364 1386 self.counter_imagwr += 1
1365 1387 if (self.counter_imagwr==wr_period):
1366 1388 if figfile == None:
1367 1389 figfile = self.getFilename(name = self.name)
1368 1390 self.saveFigure(figpath, figfile)
1369 1391
1370 1392 if ftp:
1371 1393 #provisionalmente envia archivos en el formato de la web en tiempo real
1372 1394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1373 1395 path = '%s%03d' %(self.PREFIX, self.id)
1374 1396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1375 1397 self.saveFigure(figpath, ftp_file)
1376 1398 ftp_filename = os.path.join(figpath,ftp_file)
1377 1399 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1378 1400 self.counter_imagwr = 0
1379 1401
1380 1402 self.counter_imagwr = 0
1381 1403
1382 1404 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1383 1405 self.__isConfig = False
1384 1406 del self.xdata
1385 1407 del self.ydata
1386 1408
1387 1409
1388 1410 class SpectraHeisScope(Figure):
1389 1411
1390 1412
1391 1413 __isConfig = None
1392 1414 __nsubplots = None
1393 1415
1394 1416 WIDTHPROF = None
1395 1417 HEIGHTPROF = None
1396 1418 PREFIX = 'spc'
1397 1419
1398 1420 def __init__(self):
1399 1421
1400 1422 self.__isConfig = False
1401 1423 self.__nsubplots = 1
1402 1424
1403 1425 self.WIDTH = 230
1404 1426 self.HEIGHT = 250
1405 1427 self.WIDTHPROF = 120
1406 1428 self.HEIGHTPROF = 0
1407 1429 self.counter_imagwr = 0
1408 1430
1409 1431 def getSubplots(self):
1410 1432
1411 1433 ncol = int(numpy.sqrt(self.nplots)+0.9)
1412 1434 nrow = int(self.nplots*1./ncol + 0.9)
1413 1435
1414 1436 return nrow, ncol
1415 1437
1416 1438 def setup(self, id, nplots, wintitle, show):
1417 1439
1418 1440 showprofile = False
1419 1441 self.__showprofile = showprofile
1420 1442 self.nplots = nplots
1421 1443
1422 1444 ncolspan = 1
1423 1445 colspan = 1
1424 1446 if showprofile:
1425 1447 ncolspan = 3
1426 1448 colspan = 2
1427 1449 self.__nsubplots = 2
1428 1450
1429 1451 self.createFigure(id = id,
1430 1452 wintitle = wintitle,
1431 1453 widthplot = self.WIDTH + self.WIDTHPROF,
1432 1454 heightplot = self.HEIGHT + self.HEIGHTPROF,
1433 1455 show = show)
1434 1456
1435 1457 nrow, ncol = self.getSubplots()
1436 1458
1437 1459 counter = 0
1438 1460 for y in range(nrow):
1439 1461 for x in range(ncol):
1440 1462
1441 1463 if counter >= self.nplots:
1442 1464 break
1443 1465
1444 1466 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1445 1467
1446 1468 if showprofile:
1447 1469 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1448 1470
1449 1471 counter += 1
1450 1472
1451 1473
1452 1474 def run(self, dataOut, id, wintitle="", channelList=None,
1453 1475 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1454 1476 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1455 1477 server=None, folder=None, username=None, password=None):
1456 1478
1457 1479 """
1458 1480
1459 1481 Input:
1460 1482 dataOut :
1461 1483 id :
1462 1484 wintitle :
1463 1485 channelList :
1464 1486 xmin : None,
1465 1487 xmax : None,
1466 1488 ymin : None,
1467 1489 ymax : None,
1468 1490 """
1469 1491
1470 1492 if dataOut.realtime:
1471 1493 if not(isRealtime(utcdatatime = dataOut.utctime)):
1472 1494 print 'Skipping this plot function'
1473 1495 return
1474 1496
1475 1497 if channelList == None:
1476 1498 channelIndexList = dataOut.channelIndexList
1477 1499 else:
1478 1500 channelIndexList = []
1479 1501 for channel in channelList:
1480 1502 if channel not in dataOut.channelList:
1481 1503 raise ValueError, "Channel %d is not in dataOut.channelList"
1482 1504 channelIndexList.append(dataOut.channelList.index(channel))
1483 1505
1484 1506 # x = dataOut.heightList
1485 1507 c = 3E8
1486 1508 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1487 1509 #deberia cambiar para el caso de 1Mhz y 100KHz
1488 1510 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1489 1511 #para 1Mhz descomentar la siguiente linea
1490 1512 #x= x/(10000.0)
1491 1513 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1492 1514 # y = y.real
1493 1515 datadB = 10.*numpy.log10(dataOut.data_spc)
1494 1516 y = datadB
1495 1517
1496 1518 #thisDatetime = dataOut.datatime
1497 1519 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1498 1520 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1499 1521 xlabel = ""
1500 1522 #para 1Mhz descomentar la siguiente linea
1501 1523 #xlabel = "Frequency x 10000"
1502 1524 ylabel = "Intensity (dB)"
1503 1525
1504 1526 if not self.__isConfig:
1505 1527 nplots = len(channelIndexList)
1506 1528
1507 1529 self.setup(id=id,
1508 1530 nplots=nplots,
1509 1531 wintitle=wintitle,
1510 1532 show=show)
1511 1533
1512 1534 if xmin == None: xmin = numpy.nanmin(x)
1513 1535 if xmax == None: xmax = numpy.nanmax(x)
1514 1536 if ymin == None: ymin = numpy.nanmin(y)
1515 1537 if ymax == None: ymax = numpy.nanmax(y)
1516 1538
1517 1539 self.__isConfig = True
1518 1540
1519 1541 self.setWinTitle(title)
1520 1542
1521 1543 for i in range(len(self.axesList)):
1522 1544 ychannel = y[i,:]
1523 1545 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1524 1546 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
1525 1547 axes = self.axesList[i]
1526 1548 axes.pline(x, ychannel,
1527 1549 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1528 1550 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1529 1551
1530 1552
1531 1553 self.draw()
1532 1554
1533 1555 if save:
1534 1556 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1535 1557 if figfile == None:
1536 1558 figfile = self.getFilename(name = date)
1537 1559
1538 1560 self.saveFigure(figpath, figfile)
1539 1561
1540 1562 self.counter_imagwr += 1
1541 1563 if (ftp and (self.counter_imagwr==wr_period)):
1542 1564 ftp_filename = os.path.join(figpath,figfile)
1543 1565 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1544 1566 self.counter_imagwr = 0
1545 1567
1546 1568
1547 1569 class RTIfromSpectraHeis(Figure):
1548 1570
1549 1571 __isConfig = None
1550 1572 __nsubplots = None
1551 1573
1552 1574 PREFIX = 'rtinoise'
1553 1575
1554 1576 def __init__(self):
1555 1577
1556 1578 self.timerange = 24*60*60
1557 1579 self.__isConfig = False
1558 1580 self.__nsubplots = 1
1559 1581
1560 1582 self.WIDTH = 820
1561 1583 self.HEIGHT = 200
1562 1584 self.WIDTHPROF = 120
1563 1585 self.HEIGHTPROF = 0
1564 1586 self.counter_imagwr = 0
1565 1587 self.xdata = None
1566 1588 self.ydata = None
1567 1589
1568 1590 def getSubplots(self):
1569 1591
1570 1592 ncol = 1
1571 1593 nrow = 1
1572 1594
1573 1595 return nrow, ncol
1574 1596
1575 1597 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1576 1598
1577 1599 self.__showprofile = showprofile
1578 1600 self.nplots = nplots
1579 1601
1580 1602 ncolspan = 7
1581 1603 colspan = 6
1582 1604 self.__nsubplots = 2
1583 1605
1584 1606 self.createFigure(id = id,
1585 1607 wintitle = wintitle,
1586 1608 widthplot = self.WIDTH+self.WIDTHPROF,
1587 1609 heightplot = self.HEIGHT+self.HEIGHTPROF,
1588 1610 show = show)
1589 1611
1590 1612 nrow, ncol = self.getSubplots()
1591 1613
1592 1614 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1593 1615
1594 1616
1595 1617 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1596 1618 xmin=None, xmax=None, ymin=None, ymax=None,
1597 1619 timerange=None,
1598 1620 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1599 1621 server=None, folder=None, username=None, password=None):
1600 1622
1601 1623 if channelList == None:
1602 1624 channelIndexList = dataOut.channelIndexList
1603 1625 channelList = dataOut.channelList
1604 1626 else:
1605 1627 channelIndexList = []
1606 1628 for channel in channelList:
1607 1629 if channel not in dataOut.channelList:
1608 1630 raise ValueError, "Channel %d is not in dataOut.channelList"
1609 1631 channelIndexList.append(dataOut.channelList.index(channel))
1610 1632
1611 1633 if timerange != None:
1612 1634 self.timerange = timerange
1613 1635
1614 1636 tmin = None
1615 1637 tmax = None
1616 1638 x = dataOut.getTimeRange()
1617 1639 y = dataOut.getHeiRange()
1618 1640
1619 1641 #factor = 1
1620 1642 data = dataOut.data_spc#/factor
1621 1643 data = numpy.average(data,axis=1)
1622 1644 datadB = 10*numpy.log10(data)
1623 1645
1624 1646 # factor = dataOut.normFactor
1625 1647 # noise = dataOut.getNoise()/factor
1626 1648 # noisedB = 10*numpy.log10(noise)
1627 1649
1628 1650 #thisDatetime = dataOut.datatime
1629 1651 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1630 1652 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1631 1653 xlabel = "Local Time"
1632 1654 ylabel = "Intensity (dB)"
1633 1655
1634 1656 if not self.__isConfig:
1635 1657
1636 1658 nplots = 1
1637 1659
1638 1660 self.setup(id=id,
1639 1661 nplots=nplots,
1640 1662 wintitle=wintitle,
1641 1663 showprofile=showprofile,
1642 1664 show=show)
1643 1665
1644 1666 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1645 1667 if ymin == None: ymin = numpy.nanmin(datadB)
1646 1668 if ymax == None: ymax = numpy.nanmax(datadB)
1647 1669
1648 1670 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1649 1671 self.__isConfig = True
1650 1672
1651 1673 self.xdata = numpy.array([])
1652 1674 self.ydata = numpy.array([])
1653 1675
1654 1676 self.setWinTitle(title)
1655 1677
1656 1678
1657 1679 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1658 1680 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1659 1681
1660 1682 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1661 1683 axes = self.axesList[0]
1662 1684
1663 1685 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1664 1686
1665 1687 if len(self.ydata)==0:
1666 1688 self.ydata = datadB[channelIndexList].reshape(-1,1)
1667 1689 else:
1668 1690 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1669 1691
1670 1692
1671 1693 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1672 1694 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1673 1695 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1674 1696 XAxisAsTime=True
1675 1697 )
1676 1698
1677 1699 self.draw()
1678 1700
1679 1701 if save:
1680 1702
1681 1703 if figfile == None:
1682 1704 figfile = self.getFilename(name = self.name)
1683 1705
1684 1706 self.saveFigure(figpath, figfile)
1685 1707
1686 1708 self.counter_imagwr += 1
1687 1709 if (ftp and (self.counter_imagwr==wr_period)):
1688 1710 ftp_filename = os.path.join(figpath,figfile)
1689 1711 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1690 1712 self.counter_imagwr = 0
1691 1713
1692 1714 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1693 1715 self.__isConfig = False
1694 1716 del self.xdata
1695 1717 del self.ydata
1696 1718
1697 1719
1698 1720 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now