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