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