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