##// END OF EJS Templates
El programa se terminaba cuando se produce un error de conexion al servidor de graficos en la web, ahora el progrma imprime el error de conexion pero continua en ejecucion.
Daniel Valdez -
r433:b3892de8fc3a
parent child
Show More
@@ -1,1532 +1,1532
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],:,:]/factor)
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],:,:]/factor)
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 try:
211 211 self.sendByFTP(ftp_filename, server, folder, username, password)
212 212 except:
213 213 self.counter_imagwr = 0
214 raise ValueError, 'Error FTP'
214 print ValueError, 'Error FTP'
215 215
216 216 self.counter_imagwr = 0
217 217
218 218
219 219 class RTIPlot(Figure):
220 220
221 221 __isConfig = None
222 222 __nsubplots = None
223 223
224 224 WIDTHPROF = None
225 225 HEIGHTPROF = None
226 226 PREFIX = 'rti'
227 227
228 228 def __init__(self):
229 229
230 230 self.timerange = 2*60*60
231 231 self.__isConfig = False
232 232 self.__nsubplots = 1
233 233
234 234 self.WIDTH = 800
235 235 self.HEIGHT = 150
236 236 self.WIDTHPROF = 120
237 237 self.HEIGHTPROF = 0
238 238 self.counter_imagwr = 0
239 239
240 240 self.PLOT_CODE = 0
241 241 self.FTP_WEI = None
242 242 self.EXP_CODE = None
243 243 self.SUB_EXP_CODE = None
244 244 self.PLOT_POS = None
245 245
246 246 def getSubplots(self):
247 247
248 248 ncol = 1
249 249 nrow = self.nplots
250 250
251 251 return nrow, ncol
252 252
253 253 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
254 254
255 255 self.__showprofile = showprofile
256 256 self.nplots = nplots
257 257
258 258 ncolspan = 1
259 259 colspan = 1
260 260 if showprofile:
261 261 ncolspan = 7
262 262 colspan = 6
263 263 self.__nsubplots = 2
264 264
265 265 self.createFigure(id = id,
266 266 wintitle = wintitle,
267 267 widthplot = self.WIDTH + self.WIDTHPROF,
268 268 heightplot = self.HEIGHT + self.HEIGHTPROF,
269 269 show=show)
270 270
271 271 nrow, ncol = self.getSubplots()
272 272
273 273 counter = 0
274 274 for y in range(nrow):
275 275 for x in range(ncol):
276 276
277 277 if counter >= self.nplots:
278 278 break
279 279
280 280 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
281 281
282 282 if showprofile:
283 283 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
284 284
285 285 counter += 1
286 286
287 287 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
288 288 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
289 289 timerange=None,
290 290 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
291 291 server=None, folder=None, username=None, password=None,
292 292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
293 293
294 294 """
295 295
296 296 Input:
297 297 dataOut :
298 298 id :
299 299 wintitle :
300 300 channelList :
301 301 showProfile :
302 302 xmin : None,
303 303 xmax : None,
304 304 ymin : None,
305 305 ymax : None,
306 306 zmin : None,
307 307 zmax : None
308 308 """
309 309
310 310 if channelList == None:
311 311 channelIndexList = dataOut.channelIndexList
312 312 else:
313 313 channelIndexList = []
314 314 for channel in channelList:
315 315 if channel not in dataOut.channelList:
316 316 raise ValueError, "Channel %d is not in dataOut.channelList"
317 317 channelIndexList.append(dataOut.channelList.index(channel))
318 318
319 319 if timerange != None:
320 320 self.timerange = timerange
321 321
322 322 tmin = None
323 323 tmax = None
324 324 factor = dataOut.normFactor
325 325 x = dataOut.getTimeRange()
326 326 y = dataOut.getHeiRange()
327 327
328 328 z = dataOut.data_spc[channelIndexList,:,:]/factor
329 329 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
330 330 avg = numpy.average(z, axis=1)
331 331
332 332 avgdB = 10.*numpy.log10(avg)
333 333
334 334
335 335 # thisDatetime = dataOut.datatime
336 336 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
337 337 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
338 338 xlabel = ""
339 339 ylabel = "Range (Km)"
340 340
341 341 if not self.__isConfig:
342 342
343 343 nplots = len(channelIndexList)
344 344
345 345 self.setup(id=id,
346 346 nplots=nplots,
347 347 wintitle=wintitle,
348 348 showprofile=showprofile,
349 349 show=show)
350 350
351 351 tmin, tmax = self.getTimeLim(x, xmin, xmax)
352 352 if ymin == None: ymin = numpy.nanmin(y)
353 353 if ymax == None: ymax = numpy.nanmax(y)
354 354 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
355 355 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
356 356
357 357 self.FTP_WEI = ftp_wei
358 358 self.EXP_CODE = exp_code
359 359 self.SUB_EXP_CODE = sub_exp_code
360 360 self.PLOT_POS = plot_pos
361 361
362 362 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
363 363 self.__isConfig = True
364 364
365 365
366 366 self.setWinTitle(title)
367 367
368 368 for i in range(self.nplots):
369 369 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
370 370 axes = self.axesList[i*self.__nsubplots]
371 371 zdB = avgdB[i].reshape((1,-1))
372 372 axes.pcolorbuffer(x, y, zdB,
373 373 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
374 374 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
375 375 ticksize=9, cblabel='', cbsize="1%")
376 376
377 377 if self.__showprofile:
378 378 axes = self.axesList[i*self.__nsubplots +1]
379 379 axes.pline(avgdB[i], y,
380 380 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
381 381 xlabel='dB', ylabel='', title='',
382 382 ytick_visible=False,
383 383 grid='x')
384 384
385 385 self.draw()
386 386
387 387 if save:
388 388
389 389 self.counter_imagwr += 1
390 390 if (self.counter_imagwr==wr_period):
391 391 if figfile == None:
392 392 figfile = self.getFilename(name = self.name)
393 393 self.saveFigure(figpath, figfile)
394 394
395 395 if ftp:
396 396 #provisionalmente envia archivos en el formato de la web en tiempo real
397 397 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
398 398 path = '%s%03d' %(self.PREFIX, self.id)
399 399 ftp_file = os.path.join(path,'ftp','%s.png'%name)
400 400 self.saveFigure(figpath, ftp_file)
401 401 ftp_filename = os.path.join(figpath,ftp_file)
402 402 try:
403 403 self.sendByFTP(ftp_filename, server, folder, username, password)
404 404 except:
405 405 self.counter_imagwr = 0
406 raise ValueError, 'Error FTP'
406 print ValueError, 'Error FTP'
407 407
408 408 self.counter_imagwr = 0
409 409
410 410 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
411 411 self.__isConfig = False
412 412
413 413 class SpectraPlot(Figure):
414 414
415 415 __isConfig = None
416 416 __nsubplots = None
417 417
418 418 WIDTHPROF = None
419 419 HEIGHTPROF = None
420 420 PREFIX = 'spc'
421 421
422 422 def __init__(self):
423 423
424 424 self.__isConfig = False
425 425 self.__nsubplots = 1
426 426
427 427 self.WIDTH = 280
428 428 self.HEIGHT = 250
429 429 self.WIDTHPROF = 120
430 430 self.HEIGHTPROF = 0
431 431 self.counter_imagwr = 0
432 432
433 433 self.PLOT_CODE = 1
434 434 self.FTP_WEI = None
435 435 self.EXP_CODE = None
436 436 self.SUB_EXP_CODE = None
437 437 self.PLOT_POS = None
438 438
439 439 def getSubplots(self):
440 440
441 441 ncol = int(numpy.sqrt(self.nplots)+0.9)
442 442 nrow = int(self.nplots*1./ncol + 0.9)
443 443
444 444 return nrow, ncol
445 445
446 446 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
447 447
448 448 self.__showprofile = showprofile
449 449 self.nplots = nplots
450 450
451 451 ncolspan = 1
452 452 colspan = 1
453 453 if showprofile:
454 454 ncolspan = 3
455 455 colspan = 2
456 456 self.__nsubplots = 2
457 457
458 458 self.createFigure(id = id,
459 459 wintitle = wintitle,
460 460 widthplot = self.WIDTH + self.WIDTHPROF,
461 461 heightplot = self.HEIGHT + self.HEIGHTPROF,
462 462 show=show)
463 463
464 464 nrow, ncol = self.getSubplots()
465 465
466 466 counter = 0
467 467 for y in range(nrow):
468 468 for x in range(ncol):
469 469
470 470 if counter >= self.nplots:
471 471 break
472 472
473 473 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
474 474
475 475 if showprofile:
476 476 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
477 477
478 478 counter += 1
479 479
480 480 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
481 481 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
482 482 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
483 483 server=None, folder=None, username=None, password=None,
484 484 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
485 485
486 486 """
487 487
488 488 Input:
489 489 dataOut :
490 490 id :
491 491 wintitle :
492 492 channelList :
493 493 showProfile :
494 494 xmin : None,
495 495 xmax : None,
496 496 ymin : None,
497 497 ymax : None,
498 498 zmin : None,
499 499 zmax : None
500 500 """
501 501
502 502 if realtime:
503 503 if not(isRealtime(utcdatatime = dataOut.utctime)):
504 504 print 'Skipping this plot function'
505 505 return
506 506
507 507 if channelList == None:
508 508 channelIndexList = dataOut.channelIndexList
509 509 else:
510 510 channelIndexList = []
511 511 for channel in channelList:
512 512 if channel not in dataOut.channelList:
513 513 raise ValueError, "Channel %d is not in dataOut.channelList"
514 514 channelIndexList.append(dataOut.channelList.index(channel))
515 515 factor = dataOut.normFactor
516 516 x = dataOut.getVelRange(1)
517 517 y = dataOut.getHeiRange()
518 518
519 519 z = dataOut.data_spc[channelIndexList,:,:]/factor
520 520 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
521 521 avg = numpy.average(z, axis=1)
522 522 noise = dataOut.getNoise()/factor
523 523
524 524 zdB = 10*numpy.log10(z)
525 525 avgdB = 10*numpy.log10(avg)
526 526 noisedB = 10*numpy.log10(noise)
527 527
528 528 #thisDatetime = dataOut.datatime
529 529 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
530 530 title = wintitle + " Spectra"
531 531 xlabel = "Velocity (m/s)"
532 532 ylabel = "Range (Km)"
533 533
534 534 if not self.__isConfig:
535 535
536 536 nplots = len(channelIndexList)
537 537
538 538 self.setup(id=id,
539 539 nplots=nplots,
540 540 wintitle=wintitle,
541 541 showprofile=showprofile,
542 542 show=show)
543 543
544 544 if xmin == None: xmin = numpy.nanmin(x)
545 545 if xmax == None: xmax = numpy.nanmax(x)
546 546 if ymin == None: ymin = numpy.nanmin(y)
547 547 if ymax == None: ymax = numpy.nanmax(y)
548 548 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
549 549 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
550 550
551 551 self.FTP_WEI = ftp_wei
552 552 self.EXP_CODE = exp_code
553 553 self.SUB_EXP_CODE = sub_exp_code
554 554 self.PLOT_POS = plot_pos
555 555
556 556 self.__isConfig = True
557 557
558 558 self.setWinTitle(title)
559 559
560 560 for i in range(self.nplots):
561 561 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
562 562 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
563 563 axes = self.axesList[i*self.__nsubplots]
564 564 axes.pcolor(x, y, zdB[i,:,:],
565 565 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
566 566 xlabel=xlabel, ylabel=ylabel, title=title,
567 567 ticksize=9, cblabel='')
568 568
569 569 if self.__showprofile:
570 570 axes = self.axesList[i*self.__nsubplots +1]
571 571 axes.pline(avgdB[i], y,
572 572 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
573 573 xlabel='dB', ylabel='', title='',
574 574 ytick_visible=False,
575 575 grid='x')
576 576
577 577 noiseline = numpy.repeat(noisedB[i], len(y))
578 578 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
579 579
580 580 self.draw()
581 581
582 582 if save:
583 583
584 584 self.counter_imagwr += 1
585 585 if (self.counter_imagwr==wr_period):
586 586 if figfile == None:
587 587 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
588 588 figfile = self.getFilename(name = str_datetime)
589 589
590 590 self.saveFigure(figpath, figfile)
591 591
592 592 if ftp:
593 593 #provisionalmente envia archivos en el formato de la web en tiempo real
594 594 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
595 595 path = '%s%03d' %(self.PREFIX, self.id)
596 596 ftp_file = os.path.join(path,'ftp','%s.png'%name)
597 597 self.saveFigure(figpath, ftp_file)
598 598 ftp_filename = os.path.join(figpath,ftp_file)
599 599 try:
600 600 self.sendByFTP(ftp_filename, server, folder, username, password)
601 601 except:
602 602 self.counter_imagwr = 0
603 raise ValueError, 'Error FTP'
603 print ValueError, 'Error FTP'
604 604
605 605 self.counter_imagwr = 0
606 606
607 607
608 608 class Scope(Figure):
609 609
610 610 __isConfig = None
611 611
612 612 def __init__(self):
613 613
614 614 self.__isConfig = False
615 615 self.WIDTH = 600
616 616 self.HEIGHT = 200
617 617
618 618 def getSubplots(self):
619 619
620 620 nrow = self.nplots
621 621 ncol = 3
622 622 return nrow, ncol
623 623
624 624 def setup(self, id, nplots, wintitle, show):
625 625
626 626 self.nplots = nplots
627 627
628 628 self.createFigure(id=id,
629 629 wintitle=wintitle,
630 630 show=show)
631 631
632 632 nrow,ncol = self.getSubplots()
633 633 colspan = 3
634 634 rowspan = 1
635 635
636 636 for i in range(nplots):
637 637 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
638 638
639 639
640 640
641 641 def run(self, dataOut, id, wintitle="", channelList=None,
642 642 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
643 643 figpath='./', figfile=None, show=True):
644 644
645 645 """
646 646
647 647 Input:
648 648 dataOut :
649 649 id :
650 650 wintitle :
651 651 channelList :
652 652 xmin : None,
653 653 xmax : None,
654 654 ymin : None,
655 655 ymax : None,
656 656 """
657 657
658 658 if channelList == None:
659 659 channelIndexList = dataOut.channelIndexList
660 660 else:
661 661 channelIndexList = []
662 662 for channel in channelList:
663 663 if channel not in dataOut.channelList:
664 664 raise ValueError, "Channel %d is not in dataOut.channelList"
665 665 channelIndexList.append(dataOut.channelList.index(channel))
666 666
667 667 x = dataOut.heightList
668 668 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
669 669 y = y.real
670 670
671 671 #thisDatetime = dataOut.datatime
672 672 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
673 673 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
674 674 xlabel = "Range (Km)"
675 675 ylabel = "Intensity"
676 676
677 677 if not self.__isConfig:
678 678 nplots = len(channelIndexList)
679 679
680 680 self.setup(id=id,
681 681 nplots=nplots,
682 682 wintitle=wintitle,
683 683 show=show)
684 684
685 685 if xmin == None: xmin = numpy.nanmin(x)
686 686 if xmax == None: xmax = numpy.nanmax(x)
687 687 if ymin == None: ymin = numpy.nanmin(y)
688 688 if ymax == None: ymax = numpy.nanmax(y)
689 689
690 690 self.__isConfig = True
691 691
692 692 self.setWinTitle(title)
693 693
694 694 for i in range(len(self.axesList)):
695 695 title = "Channel %d" %(i)
696 696 axes = self.axesList[i]
697 697 ychannel = y[i,:]
698 698 axes.pline(x, ychannel,
699 699 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
700 700 xlabel=xlabel, ylabel=ylabel, title=title)
701 701
702 702 self.draw()
703 703
704 704 if save:
705 705 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
706 706 if figfile == None:
707 707 figfile = self.getFilename(name = date)
708 708
709 709 self.saveFigure(figpath, figfile)
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
726 726 def getSubplots(self):
727 727 ncol = 1
728 728 nrow = 1
729 729
730 730 return nrow, ncol
731 731
732 732 def setup(self, id, nplots, wintitle, show):
733 733
734 734 self.nplots = nplots
735 735
736 736 ncolspan = 1
737 737 colspan = 1
738 738
739 739 self.createFigure(id = id,
740 740 wintitle = wintitle,
741 741 widthplot = self.WIDTH,
742 742 heightplot = self.HEIGHT,
743 743 show=show)
744 744
745 745 nrow, ncol = self.getSubplots()
746 746
747 747 counter = 0
748 748 for y in range(nrow):
749 749 for x in range(ncol):
750 750 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
751 751
752 752 def run(self, dataOut, id, wintitle="", channelList=None,
753 753 xmin=None, xmax=None, ymin=None, ymax=None,
754 754 save=False, figpath='./', figfile=None, show=True):
755 755
756 756 if channelList == None:
757 757 channelIndexList = dataOut.channelIndexList
758 758 channelList = dataOut.channelList
759 759 else:
760 760 channelIndexList = []
761 761 for channel in channelList:
762 762 if channel not in dataOut.channelList:
763 763 raise ValueError, "Channel %d is not in dataOut.channelList"
764 764 channelIndexList.append(dataOut.channelList.index(channel))
765 765
766 766 factor = dataOut.normFactor
767 767 y = dataOut.getHeiRange()
768 768 x = dataOut.data_spc[channelIndexList,:,:]/factor
769 769 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
770 770 avg = numpy.average(x, axis=1)
771 771
772 772 avgdB = 10*numpy.log10(avg)
773 773
774 774 #thisDatetime = dataOut.datatime
775 775 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
776 776 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
777 777 xlabel = "dB"
778 778 ylabel = "Range (Km)"
779 779
780 780 if not self.__isConfig:
781 781
782 782 nplots = 1
783 783
784 784 self.setup(id=id,
785 785 nplots=nplots,
786 786 wintitle=wintitle,
787 787 show=show)
788 788
789 789 if ymin == None: ymin = numpy.nanmin(y)
790 790 if ymax == None: ymax = numpy.nanmax(y)
791 791 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
792 792 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
793 793
794 794 self.__isConfig = True
795 795
796 796 self.setWinTitle(title)
797 797
798 798
799 799 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
800 800 axes = self.axesList[0]
801 801
802 802 legendlabels = ["channel %d"%x for x in channelList]
803 803 axes.pmultiline(avgdB, y,
804 804 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
805 805 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
806 806 ytick_visible=True, nxticks=5,
807 807 grid='x')
808 808
809 809 self.draw()
810 810
811 811 if save:
812 812 date = thisDatetime.strftime("%Y%m%d")
813 813 if figfile == None:
814 814 figfile = self.getFilename(name = date)
815 815
816 816 self.saveFigure(figpath, figfile)
817 817
818 818 class CoherenceMap(Figure):
819 819 __isConfig = None
820 820 __nsubplots = None
821 821
822 822 WIDTHPROF = None
823 823 HEIGHTPROF = None
824 824 PREFIX = 'cmap'
825 825
826 826 def __init__(self):
827 827 self.timerange = 2*60*60
828 828 self.__isConfig = False
829 829 self.__nsubplots = 1
830 830
831 831 self.WIDTH = 800
832 832 self.HEIGHT = 150
833 833 self.WIDTHPROF = 120
834 834 self.HEIGHTPROF = 0
835 835 self.counter_imagwr = 0
836 836
837 837 self.PLOT_CODE = 3
838 838 self.FTP_WEI = None
839 839 self.EXP_CODE = None
840 840 self.SUB_EXP_CODE = None
841 841 self.PLOT_POS = None
842 842 self.counter_imagwr = 0
843 843
844 844 def getSubplots(self):
845 845 ncol = 1
846 846 nrow = self.nplots*2
847 847
848 848 return nrow, ncol
849 849
850 850 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
851 851 self.__showprofile = showprofile
852 852 self.nplots = nplots
853 853
854 854 ncolspan = 1
855 855 colspan = 1
856 856 if showprofile:
857 857 ncolspan = 7
858 858 colspan = 6
859 859 self.__nsubplots = 2
860 860
861 861 self.createFigure(id = id,
862 862 wintitle = wintitle,
863 863 widthplot = self.WIDTH + self.WIDTHPROF,
864 864 heightplot = self.HEIGHT + self.HEIGHTPROF,
865 865 show=True)
866 866
867 867 nrow, ncol = self.getSubplots()
868 868
869 869 for y in range(nrow):
870 870 for x in range(ncol):
871 871
872 872 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
873 873
874 874 if showprofile:
875 875 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
876 876
877 877 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
878 878 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
879 879 timerange=None,
880 880 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
881 881 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
882 882 server=None, folder=None, username=None, password=None,
883 883 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
884 884
885 885 if pairsList == None:
886 886 pairsIndexList = dataOut.pairsIndexList
887 887 else:
888 888 pairsIndexList = []
889 889 for pair in pairsList:
890 890 if pair not in dataOut.pairsList:
891 891 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
892 892 pairsIndexList.append(dataOut.pairsList.index(pair))
893 893
894 894 if timerange != None:
895 895 self.timerange = timerange
896 896
897 897 if pairsIndexList == []:
898 898 return
899 899
900 900 if len(pairsIndexList) > 4:
901 901 pairsIndexList = pairsIndexList[0:4]
902 902
903 903 tmin = None
904 904 tmax = None
905 905 x = dataOut.getTimeRange()
906 906 y = dataOut.getHeiRange()
907 907
908 908 #thisDatetime = dataOut.datatime
909 909 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
910 910 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
911 911 xlabel = ""
912 912 ylabel = "Range (Km)"
913 913
914 914 if not self.__isConfig:
915 915 nplots = len(pairsIndexList)
916 916 self.setup(id=id,
917 917 nplots=nplots,
918 918 wintitle=wintitle,
919 919 showprofile=showprofile,
920 920 show=show)
921 921
922 922 tmin, tmax = self.getTimeLim(x, xmin, xmax)
923 923 if ymin == None: ymin = numpy.nanmin(y)
924 924 if ymax == None: ymax = numpy.nanmax(y)
925 925 if zmin == None: zmin = 0.
926 926 if zmax == None: zmax = 1.
927 927
928 928 self.FTP_WEI = ftp_wei
929 929 self.EXP_CODE = exp_code
930 930 self.SUB_EXP_CODE = sub_exp_code
931 931 self.PLOT_POS = plot_pos
932 932
933 933 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
934 934
935 935 self.__isConfig = True
936 936
937 937 self.setWinTitle(title)
938 938
939 939 for i in range(self.nplots):
940 940
941 941 pair = dataOut.pairsList[pairsIndexList[i]]
942 942 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
943 943 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
944 944 # coherence = numpy.abs(avgcoherenceComplex)
945 945
946 946 ## coherence = numpy.abs(coherenceComplex)
947 947 ## avg = numpy.average(coherence, axis=0)
948 948
949 949 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
950 950 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
951 951 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
952 952
953 953
954 954 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
955 955 coherence = numpy.abs(avgcoherenceComplex)
956 956
957 957 z = coherence.reshape((1,-1))
958 958
959 959 counter = 0
960 960
961 961 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
962 962 axes = self.axesList[i*self.__nsubplots*2]
963 963 axes.pcolorbuffer(x, y, z,
964 964 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
965 965 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
966 966 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
967 967
968 968 if self.__showprofile:
969 969 counter += 1
970 970 axes = self.axesList[i*self.__nsubplots*2 + counter]
971 971 axes.pline(coherence, y,
972 972 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
973 973 xlabel='', ylabel='', title='', ticksize=7,
974 974 ytick_visible=False, nxticks=5,
975 975 grid='x')
976 976
977 977 counter += 1
978 978 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
979 979 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
980 980 # avg = numpy.average(phase, axis=0)
981 981 z = phase.reshape((1,-1))
982 982
983 983 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
984 984 axes = self.axesList[i*self.__nsubplots*2 + counter]
985 985 axes.pcolorbuffer(x, y, z,
986 986 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
987 987 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
988 988 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
989 989
990 990 if self.__showprofile:
991 991 counter += 1
992 992 axes = self.axesList[i*self.__nsubplots*2 + counter]
993 993 axes.pline(phase, y,
994 994 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
995 995 xlabel='', ylabel='', title='', ticksize=7,
996 996 ytick_visible=False, nxticks=4,
997 997 grid='x')
998 998
999 999 self.draw()
1000 1000
1001 1001 if save:
1002 1002
1003 1003 self.counter_imagwr += 1
1004 1004 if (self.counter_imagwr==wr_period):
1005 1005 if figfile == None:
1006 1006 figfile = self.getFilename(name = self.name)
1007 1007 self.saveFigure(figpath, figfile)
1008 1008
1009 1009 if ftp:
1010 1010 #provisionalmente envia archivos en el formato de la web en tiempo real
1011 1011 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1012 1012 path = '%s%03d' %(self.PREFIX, self.id)
1013 1013 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1014 1014 self.saveFigure(figpath, ftp_file)
1015 1015 ftp_filename = os.path.join(figpath,ftp_file)
1016 1016 try:
1017 1017 self.sendByFTP(ftp_filename, server, folder, username, password)
1018 1018 except:
1019 1019 self.counter_imagwr = 0
1020 raise ValueError, 'Error FTP'
1020 print ValueError, 'Error FTP'
1021 1021
1022 1022 self.counter_imagwr = 0
1023 1023
1024 1024
1025 1025 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1026 1026 self.__isConfig = False
1027 1027
1028 1028 class Noise(Figure):
1029 1029
1030 1030 __isConfig = None
1031 1031 __nsubplots = None
1032 1032
1033 1033 PREFIX = 'noise'
1034 1034
1035 1035 def __init__(self):
1036 1036
1037 1037 self.timerange = 24*60*60
1038 1038 self.__isConfig = False
1039 1039 self.__nsubplots = 1
1040 1040 self.counter_imagwr = 0
1041 1041 self.WIDTH = 600
1042 1042 self.HEIGHT = 300
1043 1043 self.WIDTHPROF = 120
1044 1044 self.HEIGHTPROF = 0
1045 1045 self.xdata = None
1046 1046 self.ydata = None
1047 1047
1048 1048 self.PLOT_CODE = 77
1049 1049 self.FTP_WEI = None
1050 1050 self.EXP_CODE = None
1051 1051 self.SUB_EXP_CODE = None
1052 1052 self.PLOT_POS = None
1053 1053
1054 1054 def getSubplots(self):
1055 1055
1056 1056 ncol = 1
1057 1057 nrow = 1
1058 1058
1059 1059 return nrow, ncol
1060 1060
1061 1061 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1062 1062
1063 1063 self.__showprofile = showprofile
1064 1064 self.nplots = nplots
1065 1065
1066 1066 ncolspan = 7
1067 1067 colspan = 6
1068 1068 self.__nsubplots = 2
1069 1069
1070 1070 self.createFigure(id = id,
1071 1071 wintitle = wintitle,
1072 1072 widthplot = self.WIDTH+self.WIDTHPROF,
1073 1073 heightplot = self.HEIGHT+self.HEIGHTPROF,
1074 1074 show=show)
1075 1075
1076 1076 nrow, ncol = self.getSubplots()
1077 1077
1078 1078 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1079 1079
1080 1080
1081 1081 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1082 1082 xmin=None, xmax=None, ymin=None, ymax=None,
1083 1083 timerange=None,
1084 1084 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1085 1085 server=None, folder=None, username=None, password=None,
1086 1086 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1087 1087
1088 1088 if channelList == None:
1089 1089 channelIndexList = dataOut.channelIndexList
1090 1090 channelList = dataOut.channelList
1091 1091 else:
1092 1092 channelIndexList = []
1093 1093 for channel in channelList:
1094 1094 if channel not in dataOut.channelList:
1095 1095 raise ValueError, "Channel %d is not in dataOut.channelList"
1096 1096 channelIndexList.append(dataOut.channelList.index(channel))
1097 1097
1098 1098 if timerange != None:
1099 1099 self.timerange = timerange
1100 1100
1101 1101 tmin = None
1102 1102 tmax = None
1103 1103 x = dataOut.getTimeRange()
1104 1104 y = dataOut.getHeiRange()
1105 1105 factor = dataOut.normFactor
1106 1106 noise = dataOut.getNoise()/factor
1107 1107 noisedB = 10*numpy.log10(noise)
1108 1108
1109 1109 #thisDatetime = dataOut.datatime
1110 1110 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1111 1111 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1112 1112 xlabel = ""
1113 1113 ylabel = "Intensity (dB)"
1114 1114
1115 1115 if not self.__isConfig:
1116 1116
1117 1117 nplots = 1
1118 1118
1119 1119 self.setup(id=id,
1120 1120 nplots=nplots,
1121 1121 wintitle=wintitle,
1122 1122 showprofile=showprofile,
1123 1123 show=show)
1124 1124
1125 1125 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1126 1126 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1127 1127 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1128 1128
1129 1129 self.FTP_WEI = ftp_wei
1130 1130 self.EXP_CODE = exp_code
1131 1131 self.SUB_EXP_CODE = sub_exp_code
1132 1132 self.PLOT_POS = plot_pos
1133 1133
1134 1134 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1135 1135
1136 1136
1137 1137 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1138 1138 self.__isConfig = True
1139 1139
1140 1140 self.xdata = numpy.array([])
1141 1141 self.ydata = numpy.array([])
1142 1142
1143 1143 self.setWinTitle(title)
1144 1144
1145 1145
1146 1146 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1147 1147
1148 1148 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1149 1149 axes = self.axesList[0]
1150 1150
1151 1151 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1152 1152
1153 1153 if len(self.ydata)==0:
1154 1154 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1155 1155 else:
1156 1156 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1157 1157
1158 1158
1159 1159 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1160 1160 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1161 1161 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1162 1162 XAxisAsTime=True, grid='both'
1163 1163 )
1164 1164
1165 1165 self.draw()
1166 1166
1167 1167 # if save:
1168 1168 #
1169 1169 # if figfile == None:
1170 1170 # figfile = self.getFilename(name = self.name)
1171 1171 #
1172 1172 # self.saveFigure(figpath, figfile)
1173 1173
1174 1174 if save:
1175 1175
1176 1176 self.counter_imagwr += 1
1177 1177 if (self.counter_imagwr==wr_period):
1178 1178 if figfile == None:
1179 1179 figfile = self.getFilename(name = self.name)
1180 1180 self.saveFigure(figpath, figfile)
1181 1181
1182 1182 if ftp:
1183 1183 #provisionalmente envia archivos en el formato de la web en tiempo real
1184 1184 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1185 1185 path = '%s%03d' %(self.PREFIX, self.id)
1186 1186 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1187 1187 self.saveFigure(figpath, ftp_file)
1188 1188 ftp_filename = os.path.join(figpath,ftp_file)
1189 1189 try:
1190 1190 self.sendByFTP(ftp_filename, server, folder, username, password)
1191 1191 except:
1192 1192 self.counter_imagwr = 0
1193 raise ValueError, 'Error FTP'
1193 print ValueError, 'Error FTP'
1194 1194
1195 1195 self.counter_imagwr = 0
1196 1196
1197 1197 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1198 1198 self.__isConfig = False
1199 1199 del self.xdata
1200 1200 del self.ydata
1201 1201
1202 1202
1203 1203 class SpectraHeisScope(Figure):
1204 1204
1205 1205
1206 1206 __isConfig = None
1207 1207 __nsubplots = None
1208 1208
1209 1209 WIDTHPROF = None
1210 1210 HEIGHTPROF = None
1211 1211 PREFIX = 'spc'
1212 1212
1213 1213 def __init__(self):
1214 1214
1215 1215 self.__isConfig = False
1216 1216 self.__nsubplots = 1
1217 1217
1218 1218 self.WIDTH = 230
1219 1219 self.HEIGHT = 250
1220 1220 self.WIDTHPROF = 120
1221 1221 self.HEIGHTPROF = 0
1222 1222 self.counter_imagwr = 0
1223 1223
1224 1224 def getSubplots(self):
1225 1225
1226 1226 ncol = int(numpy.sqrt(self.nplots)+0.9)
1227 1227 nrow = int(self.nplots*1./ncol + 0.9)
1228 1228
1229 1229 return nrow, ncol
1230 1230
1231 1231 def setup(self, id, nplots, wintitle, show):
1232 1232
1233 1233 showprofile = False
1234 1234 self.__showprofile = showprofile
1235 1235 self.nplots = nplots
1236 1236
1237 1237 ncolspan = 1
1238 1238 colspan = 1
1239 1239 if showprofile:
1240 1240 ncolspan = 3
1241 1241 colspan = 2
1242 1242 self.__nsubplots = 2
1243 1243
1244 1244 self.createFigure(id = id,
1245 1245 wintitle = wintitle,
1246 1246 widthplot = self.WIDTH + self.WIDTHPROF,
1247 1247 heightplot = self.HEIGHT + self.HEIGHTPROF,
1248 1248 show = show)
1249 1249
1250 1250 nrow, ncol = self.getSubplots()
1251 1251
1252 1252 counter = 0
1253 1253 for y in range(nrow):
1254 1254 for x in range(ncol):
1255 1255
1256 1256 if counter >= self.nplots:
1257 1257 break
1258 1258
1259 1259 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1260 1260
1261 1261 if showprofile:
1262 1262 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1263 1263
1264 1264 counter += 1
1265 1265
1266 1266 # __isConfig = None
1267 1267 # def __init__(self):
1268 1268 #
1269 1269 # self.__isConfig = False
1270 1270 # self.WIDTH = 600
1271 1271 # self.HEIGHT = 200
1272 1272 #
1273 1273 # def getSubplots(self):
1274 1274 #
1275 1275 # nrow = self.nplots
1276 1276 # ncol = 3
1277 1277 # return nrow, ncol
1278 1278 #
1279 1279 # def setup(self, id, nplots, wintitle):
1280 1280 #
1281 1281 # self.nplots = nplots
1282 1282 #
1283 1283 # self.createFigure(id, wintitle)
1284 1284 #
1285 1285 # nrow,ncol = self.getSubplots()
1286 1286 # colspan = 3
1287 1287 # rowspan = 1
1288 1288 #
1289 1289 # for i in range(nplots):
1290 1290 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1291 1291
1292 1292 def run(self, dataOut, id, wintitle="", channelList=None,
1293 1293 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1294 1294 figpath='./', figfile=None, ftp=False, wr_period=1, show=True):
1295 1295
1296 1296 """
1297 1297
1298 1298 Input:
1299 1299 dataOut :
1300 1300 id :
1301 1301 wintitle :
1302 1302 channelList :
1303 1303 xmin : None,
1304 1304 xmax : None,
1305 1305 ymin : None,
1306 1306 ymax : None,
1307 1307 """
1308 1308
1309 1309 if dataOut.realtime:
1310 1310 if not(isRealtime(utcdatatime = dataOut.utctime)):
1311 1311 print 'Skipping this plot function'
1312 1312 return
1313 1313
1314 1314 if channelList == None:
1315 1315 channelIndexList = dataOut.channelIndexList
1316 1316 else:
1317 1317 channelIndexList = []
1318 1318 for channel in channelList:
1319 1319 if channel not in dataOut.channelList:
1320 1320 raise ValueError, "Channel %d is not in dataOut.channelList"
1321 1321 channelIndexList.append(dataOut.channelList.index(channel))
1322 1322
1323 1323 # x = dataOut.heightList
1324 1324 c = 3E8
1325 1325 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1326 1326 #deberia cambiar para el caso de 1Mhz y 100KHz
1327 1327 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1328 1328 x= x/(10000.0)
1329 1329 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1330 1330 # y = y.real
1331 1331 datadB = 10.*numpy.log10(dataOut.data_spc)
1332 1332 y = datadB
1333 1333
1334 1334 #thisDatetime = dataOut.datatime
1335 1335 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1336 1336 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1337 1337 xlabel = "Frequency x 10000"
1338 1338 ylabel = "Intensity (dB)"
1339 1339
1340 1340 if not self.__isConfig:
1341 1341 nplots = len(channelIndexList)
1342 1342
1343 1343 self.setup(id=id,
1344 1344 nplots=nplots,
1345 1345 wintitle=wintitle,
1346 1346 show=show)
1347 1347
1348 1348 if xmin == None: xmin = numpy.nanmin(x)
1349 1349 if xmax == None: xmax = numpy.nanmax(x)
1350 1350 if ymin == None: ymin = numpy.nanmin(y)
1351 1351 if ymax == None: ymax = numpy.nanmax(y)
1352 1352
1353 1353 self.__isConfig = True
1354 1354
1355 1355 self.setWinTitle(title)
1356 1356
1357 1357 for i in range(len(self.axesList)):
1358 1358 ychannel = y[i,:]
1359 1359 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1360 1360 axes = self.axesList[i]
1361 1361 axes.pline(x, ychannel,
1362 1362 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1363 1363 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1364 1364
1365 1365
1366 1366 self.draw()
1367 1367
1368 1368 if save:
1369 1369 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1370 1370 if figfile == None:
1371 1371 figfile = self.getFilename(name = date)
1372 1372
1373 1373 self.saveFigure(figpath, figfile)
1374 1374
1375 1375 self.counter_imagwr += 1
1376 1376 if (ftp and (self.counter_imagwr==wr_period)):
1377 1377 figfilename = os.path.join(figpath,figfile)
1378 1378 self.sendByFTP(figfilename)
1379 1379 self.counter_imagwr = 0
1380 1380
1381 1381
1382 1382 class RTIfromSpectraHeis(Figure):
1383 1383
1384 1384 __isConfig = None
1385 1385 __nsubplots = None
1386 1386
1387 1387 PREFIX = 'rtinoise'
1388 1388
1389 1389 def __init__(self):
1390 1390
1391 1391 self.timerange = 24*60*60
1392 1392 self.__isConfig = False
1393 1393 self.__nsubplots = 1
1394 1394
1395 1395 self.WIDTH = 820
1396 1396 self.HEIGHT = 200
1397 1397 self.WIDTHPROF = 120
1398 1398 self.HEIGHTPROF = 0
1399 1399 self.counter_imagwr = 0
1400 1400 self.xdata = None
1401 1401 self.ydata = None
1402 1402
1403 1403 def getSubplots(self):
1404 1404
1405 1405 ncol = 1
1406 1406 nrow = 1
1407 1407
1408 1408 return nrow, ncol
1409 1409
1410 1410 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1411 1411
1412 1412 self.__showprofile = showprofile
1413 1413 self.nplots = nplots
1414 1414
1415 1415 ncolspan = 7
1416 1416 colspan = 6
1417 1417 self.__nsubplots = 2
1418 1418
1419 1419 self.createFigure(id = id,
1420 1420 wintitle = wintitle,
1421 1421 widthplot = self.WIDTH+self.WIDTHPROF,
1422 1422 heightplot = self.HEIGHT+self.HEIGHTPROF,
1423 1423 show = show)
1424 1424
1425 1425 nrow, ncol = self.getSubplots()
1426 1426
1427 1427 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1428 1428
1429 1429
1430 1430 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1431 1431 xmin=None, xmax=None, ymin=None, ymax=None,
1432 1432 timerange=None,
1433 1433 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True):
1434 1434
1435 1435 if channelList == None:
1436 1436 channelIndexList = dataOut.channelIndexList
1437 1437 channelList = dataOut.channelList
1438 1438 else:
1439 1439 channelIndexList = []
1440 1440 for channel in channelList:
1441 1441 if channel not in dataOut.channelList:
1442 1442 raise ValueError, "Channel %d is not in dataOut.channelList"
1443 1443 channelIndexList.append(dataOut.channelList.index(channel))
1444 1444
1445 1445 if timerange != None:
1446 1446 self.timerange = timerange
1447 1447
1448 1448 tmin = None
1449 1449 tmax = None
1450 1450 x = dataOut.getTimeRange()
1451 1451 y = dataOut.getHeiRange()
1452 1452
1453 1453 factor = 1
1454 1454 data = dataOut.data_spc/factor
1455 1455 data = numpy.average(data,axis=1)
1456 1456 datadB = 10*numpy.log10(data)
1457 1457
1458 1458 # factor = dataOut.normFactor
1459 1459 # noise = dataOut.getNoise()/factor
1460 1460 # noisedB = 10*numpy.log10(noise)
1461 1461
1462 1462 #thisDatetime = dataOut.datatime
1463 1463 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1464 1464 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1465 1465 xlabel = "Local Time"
1466 1466 ylabel = "Intensity (dB)"
1467 1467
1468 1468 if not self.__isConfig:
1469 1469
1470 1470 nplots = 1
1471 1471
1472 1472 self.setup(id=id,
1473 1473 nplots=nplots,
1474 1474 wintitle=wintitle,
1475 1475 showprofile=showprofile,
1476 1476 show=show)
1477 1477
1478 1478 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1479 1479 if ymin == None: ymin = numpy.nanmin(datadB)
1480 1480 if ymax == None: ymax = numpy.nanmax(datadB)
1481 1481
1482 1482 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1483 1483 self.__isConfig = True
1484 1484
1485 1485 self.xdata = numpy.array([])
1486 1486 self.ydata = numpy.array([])
1487 1487
1488 1488 self.setWinTitle(title)
1489 1489
1490 1490
1491 1491 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1492 1492 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1493 1493
1494 1494 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1495 1495 axes = self.axesList[0]
1496 1496
1497 1497 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1498 1498
1499 1499 if len(self.ydata)==0:
1500 1500 self.ydata = datadB[channelIndexList].reshape(-1,1)
1501 1501 else:
1502 1502 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1503 1503
1504 1504
1505 1505 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1506 1506 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1507 1507 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1508 1508 XAxisAsTime=True
1509 1509 )
1510 1510
1511 1511 self.draw()
1512 1512
1513 1513 if save:
1514 1514
1515 1515 if figfile == None:
1516 1516 figfile = self.getFilename(name = self.name)
1517 1517
1518 1518 self.saveFigure(figpath, figfile)
1519 1519
1520 1520 self.counter_imagwr += 1
1521 1521 if (ftp and (self.counter_imagwr==wr_period)):
1522 1522 figfilename = os.path.join(figpath,figfile)
1523 1523 self.sendByFTP(figfilename)
1524 1524 self.counter_imagwr = 0
1525 1525
1526 1526 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1527 1527 self.__isConfig = False
1528 1528 del self.xdata
1529 1529 del self.ydata
1530 1530
1531 1531
1532 1532 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now