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