##// END OF EJS Templates
Fixing PNG File Storage...
Daniel Valdez -
r494:fec49901e99a
parent child
Show More
@@ -1,641 +1,590
1 1 import os
2 2 import numpy
3 3 import time, datetime
4 4 import mpldriver
5 5 from customftp import *
6 6
7 7 import Queue
8 8 import threading
9 9
10 10 def isRealtime(utcdatatime):
11 11 utcnow = time.mktime(time.localtime())
12 12 delta = abs(utcnow - utcdatatime) # abs
13 13 if delta >= 30.:
14 14 return False
15 15 return True
16 16
17 17
18 class FTP_Thread (threading.Thread):
19 def __init__(self):
20 threading.Thread.__init__(self)
21 self.exitFlag = 0
22 self.queueLock = threading.Lock()
23 self.workQueue = Queue.Queue()
24
25 def run(self):
26 self.send_data()
27
28 def fin(self):
29 self.exitFlag = 1
30
31 def put_data(self, data):
32 # Fill the queue
33 self.queueLock.acquire()
34 self.workQueue.put(data)
35 self.queueLock.release()
36
37 def send_data(self):
38 while not self.exitFlag:
39 if self.workQueue.qsize():
40
41 data = self.workQueue.get(True)
42
43 try:
44 ftpObj = Ftp(host=data['server'],
45 username=data['username'],
46 passw=data['password'],
47 remotefolder=data['folder'])
48
49 ftpObj.upload(data['figfilename'])
50 ftpObj.close()
51 except:
52 print ValueError, 'Error FTP'
53 print "don't worry still running the program"
54 18
55 19
56 20 class Figure:
57 21
58 22 __driver = mpldriver
59 23 __isConfigThread = False
60 24 fig = None
61 25
62 26 id = None
63 27 wintitle = None
64 28 width = None
65 29 height = None
66 30 nplots = None
67 31 timerange = None
68 32
69 33 axesObjList = []
70 34
71 35 WIDTH = None
72 36 HEIGHT = None
73 37 PREFIX = 'fig'
74 38
75 39 xmin = None
76 40 xmax = None
77 41
78 42 def __init__(self):
79 43
80 44 raise ValueError, "This method is not implemented"
81 45
82 46 def __del__(self):
83 47
84 48 self.__driver.closeFigure()
85 49
86 50 def getFilename(self, name, ext='.png'):
87 51
88 52 path = '%s%03d' %(self.PREFIX, self.id)
89 53 filename = '%s_%s%s' %(self.PREFIX, name, ext)
90 54 return os.path.join(path, filename)
91 55
92 56 def getAxesObjList(self):
93 57
94 58 return self.axesObjList
95 59
96 60 def getSubplots(self):
97 61
98 62 raise ValueError, "Abstract method: This method should be defined"
99 63
100 64 def getScreenDim(self, widthplot, heightplot):
101 65
102 66 nrow, ncol = self.getSubplots()
103 67
104 68 widthscreen = widthplot*ncol
105 69 heightscreen = heightplot*nrow
106 70
107 71 return widthscreen, heightscreen
108 72
109 73 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
110 74
111 75 if self.xmin != None and self.xmax != None:
112 76 if timerange == None:
113 77 timerange = self.xmax - self.xmin
114 78 xmin = self.xmin + timerange
115 79 xmax = self.xmax + timerange
116 80
117 81 return xmin, xmax
118 82
119 83
120 84 if timerange != None and self.xmin == None and self.xmax == None:
121 85 txmin = x[0] - x[0]%timerange
122 86 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
123 87 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
124 88 xmin = (thisdatetime - thisdate).seconds/(60*60.)
125 89 xmax = xmin + timerange/(60*60.)
126 90
127 91
128 92 if timerange == None:
129 93 txmin = numpy.min(x)
130 94 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
131 95 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
132 96
133 97 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
134 98 xmin_sec = time.mktime(mindt.timetuple())
135 99
136 100 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
137 101 xmax_sec = time.mktime(maxdt.timetuple())
138 102
139 103 return xmin_sec, xmax_sec
140 104
141 105
142 106
143 107
144 108
145 109 # if timerange != None:
146 110 # txmin = x[0] - x[0]%timerange
147 111 # else:
148 112 # txmin = numpy.min(x)
149 113 #
150 114 # thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
151 115 # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
152 116 #
153 117 # ####################################################
154 118 # #If the x is out of xrange
155 119 # if xmax != None:
156 120 # if xmax < (thisdatetime - thisdate).seconds/(60*60.):
157 121 # xmin = None
158 122 # xmax = None
159 123 #
160 124 # if xmin == None:
161 125 # td = thisdatetime - thisdate
162 126 # xmin = td.seconds/(60*60.)
163 127 #
164 128 # if xmax == None:
165 129 # xmax = xmin + self.timerange/(60*60.)
166 130 #
167 131 # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
168 132 # tmin = time.mktime(mindt.timetuple())
169 133 #
170 134 # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
171 135 # tmax = time.mktime(maxdt.timetuple())
172 136 #
173 137 # #self.timerange = tmax - tmin
174 138 #
175 139 # return tmin, tmax
176 140
177 141 def init(self, id, nplots, wintitle):
178 142
179 143 raise ValueError, "This method has been replaced with createFigure"
180 144
181 145 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
182 146
183 147 """
184 148 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
185 149 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
186 150 y self.HEIGHT y el numero de subplots (nrow, ncol)
187 151
188 152 Input:
189 153 id : Los parametros necesarios son
190 154 wintitle :
191 155
192 156 """
193 157
194 158 if widthplot == None:
195 159 widthplot = self.WIDTH
196 160
197 161 if heightplot == None:
198 162 heightplot = self.HEIGHT
199 163
200 164 self.id = id
201 165
202 166 self.wintitle = wintitle
203 167
204 168 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
205 169
206 170 self.fig = self.__driver.createFigure(id=self.id,
207 171 wintitle=self.wintitle,
208 172 width=self.widthscreen,
209 173 height=self.heightscreen,
210 174 show=show)
211 175
212 176 self.axesObjList = []
213 177
214 178
215 179 def setDriver(self, driver=mpldriver):
216 180
217 181 self.__driver = driver
218 182
219 183 def setTitle(self, title):
220 184
221 185 self.__driver.setTitle(self.fig, title)
222 186
223 187 def setWinTitle(self, title):
224 188
225 189 self.__driver.setWinTitle(self.fig, title=title)
226 190
227 191 def setTextFromAxes(self, text):
228 192
229 193 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
230 194
231 195 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
232 196
233 197 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
234 198
235 199 def addAxes(self, *args):
236 200 """
237 201
238 202 Input:
239 203 *args : Los parametros necesarios son
240 204 nrow, ncol, xpos, ypos, colspan, rowspan
241 205 """
242 206
243 207 axesObj = Axes(self.fig, *args)
244 208 self.axesObjList.append(axesObj)
245 209
246 210 def saveFigure(self, figpath, figfile, *args):
247 211
248 212 filename = os.path.join(figpath, figfile)
249 213
250 214 fullpath = os.path.split(filename)[0]
251 215
252 216 if not os.path.exists(fullpath):
253 217 subpath = os.path.split(fullpath)[0]
254 218
255 219 if not os.path.exists(subpath):
256 220 os.mkdir(subpath)
257 221
258 222 os.mkdir(fullpath)
259 223
260 224 self.__driver.saveFigure(self.fig, filename, *args)
261 225
262 def sendByFTP(self, figfilename, server, folder, username, password):
263 ftpObj = Ftp(host=server, username=username, passw=password, remotefolder=folder)
264 ftpObj.upload(figfilename)
265 ftpObj.close()
266
267 def sendByFTP_Thread(self, figfilename, server, folder, username, password):
268 data = {'figfilename':figfilename,'server':server,'folder':folder,'username':username,'password':password}
269 226
270 if not(self.__isConfigThread):
271
272 self.thread = FTP_Thread()
273 self.thread.start()
274 self.__isConfigThread = True
275
276 self.thread.put_data(data)
277 #print 'thread.isAlive()', self.thread.isAlive()
278 227
279 228
280 229 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
281 230 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
282 231 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
283 232 FTP_WEI = '%2.2d'%FTP_WEI
284 233 EXP_CODE = '%3.3d'%EXP_CODE
285 234 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
286 235 PLOT_CODE = '%2.2d'%PLOT_CODE
287 236 PLOT_POS = '%2.2d'%PLOT_POS
288 237 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
289 238 return name
290 239
291 240 def draw(self):
292 241
293 242 self.__driver.draw(self.fig)
294 243
295 244 def run(self):
296 245
297 246 raise ValueError, "This method is not implemented"
298 247
299 248 def close(self):
300 249
301 250 self.__driver.show(True)
302 251
303 252 axesList = property(getAxesObjList)
304 253
305 254
306 255 class Axes:
307 256
308 257 __driver = mpldriver
309 258 fig = None
310 259 ax = None
311 260 plot = None
312 261 __missing = 1E30
313 262 __firsttime = None
314 263
315 264 __showprofile = False
316 265
317 266 xmin = None
318 267 xmax = None
319 268 ymin = None
320 269 ymax = None
321 270 zmin = None
322 271 zmax = None
323 272
324 273 x_buffer = None
325 274 z_buffer = None
326 275
327 276 decimationx = None
328 277 decimationy = None
329 278
330 279 __MAXNUMX = 300
331 280 __MAXNUMY = 150
332 281
333 282 def __init__(self, *args):
334 283
335 284 """
336 285
337 286 Input:
338 287 *args : Los parametros necesarios son
339 288 fig, nrow, ncol, xpos, ypos, colspan, rowspan
340 289 """
341 290
342 291 ax = self.__driver.createAxes(*args)
343 292 self.fig = args[0]
344 293 self.ax = ax
345 294 self.plot = None
346 295
347 296 self.__firsttime = True
348 297 self.idlineList = []
349 298
350 299 self.x_buffer = numpy.array([])
351 300 self.z_buffer = numpy.array([])
352 301
353 302 def setText(self, text):
354 303
355 304 self.__driver.setAxesText(self.ax, text)
356 305
357 306 def setXAxisAsTime(self):
358 307 pass
359 308
360 309 def pline(self, x, y,
361 310 xmin=None, xmax=None,
362 311 ymin=None, ymax=None,
363 312 xlabel='', ylabel='',
364 313 title='',
365 314 **kwargs):
366 315
367 316 """
368 317
369 318 Input:
370 319 x :
371 320 y :
372 321 xmin :
373 322 xmax :
374 323 ymin :
375 324 ymax :
376 325 xlabel :
377 326 ylabel :
378 327 title :
379 328 **kwargs : Los parametros aceptados son
380 329
381 330 ticksize
382 331 ytick_visible
383 332 """
384 333
385 334 if self.__firsttime:
386 335
387 336 if xmin == None: xmin = numpy.nanmin(x)
388 337 if xmax == None: xmax = numpy.nanmax(x)
389 338 if ymin == None: ymin = numpy.nanmin(y)
390 339 if ymax == None: ymax = numpy.nanmax(y)
391 340
392 341 self.plot = self.__driver.createPline(self.ax, x, y,
393 342 xmin, xmax,
394 343 ymin, ymax,
395 344 xlabel=xlabel,
396 345 ylabel=ylabel,
397 346 title=title,
398 347 **kwargs)
399 348
400 349 self.idlineList.append(0)
401 350 self.__firsttime = False
402 351 return
403 352
404 353 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
405 354 ylabel=ylabel,
406 355 title=title)
407 356
408 357 def addpline(self, x, y, idline, **kwargs):
409 358 lines = self.ax.lines
410 359
411 360 if idline in self.idlineList:
412 361 self.__driver.set_linedata(self.ax, x, y, idline)
413 362
414 363 if idline not in(self.idlineList):
415 364 self.__driver.addpline(self.ax, x, y, **kwargs)
416 365 self.idlineList.append(idline)
417 366
418 367 return
419 368
420 369 def pmultiline(self, x, y,
421 370 xmin=None, xmax=None,
422 371 ymin=None, ymax=None,
423 372 xlabel='', ylabel='',
424 373 title='',
425 374 **kwargs):
426 375
427 376 if self.__firsttime:
428 377
429 378 if xmin == None: xmin = numpy.nanmin(x)
430 379 if xmax == None: xmax = numpy.nanmax(x)
431 380 if ymin == None: ymin = numpy.nanmin(y)
432 381 if ymax == None: ymax = numpy.nanmax(y)
433 382
434 383 self.plot = self.__driver.createPmultiline(self.ax, x, y,
435 384 xmin, xmax,
436 385 ymin, ymax,
437 386 xlabel=xlabel,
438 387 ylabel=ylabel,
439 388 title=title,
440 389 **kwargs)
441 390 self.__firsttime = False
442 391 return
443 392
444 393 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
445 394 ylabel=ylabel,
446 395 title=title)
447 396
448 397 def pmultilineyaxis(self, x, y,
449 398 xmin=None, xmax=None,
450 399 ymin=None, ymax=None,
451 400 xlabel='', ylabel='',
452 401 title='',
453 402 **kwargs):
454 403
455 404 if self.__firsttime:
456 405
457 406 if xmin == None: xmin = numpy.nanmin(x)
458 407 if xmax == None: xmax = numpy.nanmax(x)
459 408 if ymin == None: ymin = numpy.nanmin(y)
460 409 if ymax == None: ymax = numpy.nanmax(y)
461 410
462 411 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
463 412 xmin, xmax,
464 413 ymin, ymax,
465 414 xlabel=xlabel,
466 415 ylabel=ylabel,
467 416 title=title,
468 417 **kwargs)
469 418 if self.xmin == None: self.xmin = xmin
470 419 if self.xmax == None: self.xmax = xmax
471 420 if self.ymin == None: self.ymin = ymin
472 421 if self.ymax == None: self.ymax = ymax
473 422
474 423 self.__firsttime = False
475 424 return
476 425
477 426 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
478 427 ylabel=ylabel,
479 428 title=title)
480 429
481 430 def pcolor(self, x, y, z,
482 431 xmin=None, xmax=None,
483 432 ymin=None, ymax=None,
484 433 zmin=None, zmax=None,
485 434 xlabel='', ylabel='',
486 435 title='', rti = False, colormap='jet',
487 436 **kwargs):
488 437
489 438 """
490 439 Input:
491 440 x :
492 441 y :
493 442 x :
494 443 xmin :
495 444 xmax :
496 445 ymin :
497 446 ymax :
498 447 zmin :
499 448 zmax :
500 449 xlabel :
501 450 ylabel :
502 451 title :
503 452 **kwargs : Los parametros aceptados son
504 453 ticksize=9,
505 454 cblabel=''
506 455 rti = True or False
507 456 """
508 457
509 458 if self.__firsttime:
510 459
511 460 if xmin == None: xmin = numpy.nanmin(x)
512 461 if xmax == None: xmax = numpy.nanmax(x)
513 462 if ymin == None: ymin = numpy.nanmin(y)
514 463 if ymax == None: ymax = numpy.nanmax(y)
515 464 if zmin == None: zmin = numpy.nanmin(z)
516 465 if zmax == None: zmax = numpy.nanmax(z)
517 466
518 467
519 468 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
520 469 xmin, xmax,
521 470 ymin, ymax,
522 471 zmin, zmax,
523 472 xlabel=xlabel,
524 473 ylabel=ylabel,
525 474 title=title,
526 475 colormap=colormap,
527 476 **kwargs)
528 477
529 478 if self.xmin == None: self.xmin = xmin
530 479 if self.xmax == None: self.xmax = xmax
531 480 if self.ymin == None: self.ymin = ymin
532 481 if self.ymax == None: self.ymax = ymax
533 482 if self.zmin == None: self.zmin = zmin
534 483 if self.zmax == None: self.zmax = zmax
535 484
536 485 self.__firsttime = False
537 486 return
538 487
539 488 if rti:
540 489 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
541 490 xlabel=xlabel,
542 491 ylabel=ylabel,
543 492 title=title,
544 493 colormap=colormap)
545 494 return
546 495
547 496 self.__driver.pcolor(self.plot, z,
548 497 xlabel=xlabel,
549 498 ylabel=ylabel,
550 499 title=title)
551 500
552 501 def pcolorbuffer(self, x, y, z,
553 502 xmin=None, xmax=None,
554 503 ymin=None, ymax=None,
555 504 zmin=None, zmax=None,
556 505 xlabel='', ylabel='',
557 506 title='', rti = True, colormap='jet',
558 507 maxNumX = None, maxNumY = None,
559 508 **kwargs):
560 509
561 510 if maxNumX == None:
562 511 maxNumX = self.__MAXNUMX
563 512
564 513 if maxNumY == None:
565 514 maxNumY = self.__MAXNUMY
566 515
567 516 if self.__firsttime:
568 517 self.z_buffer = z
569 518 self.x_buffer = numpy.hstack((self.x_buffer, x))
570 519
571 520 if xmin == None: xmin = numpy.nanmin(x)
572 521 if xmax == None: xmax = numpy.nanmax(x)
573 522 if ymin == None: ymin = numpy.nanmin(y)
574 523 if ymax == None: ymax = numpy.nanmax(y)
575 524 if zmin == None: zmin = numpy.nanmin(z)
576 525 if zmax == None: zmax = numpy.nanmax(z)
577 526
578 527
579 528 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
580 529 xmin, xmax,
581 530 ymin, ymax,
582 531 zmin, zmax,
583 532 xlabel=xlabel,
584 533 ylabel=ylabel,
585 534 title=title,
586 535 colormap=colormap,
587 536 **kwargs)
588 537
589 538 if self.xmin == None: self.xmin = xmin
590 539 if self.xmax == None: self.xmax = xmax
591 540 if self.ymin == None: self.ymin = ymin
592 541 if self.ymax == None: self.ymax = ymax
593 542 if self.zmin == None: self.zmin = zmin
594 543 if self.zmax == None: self.zmax = zmax
595 544
596 545 self.__firsttime = False
597 546 return
598 547
599 548 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
600 549 self.z_buffer = numpy.hstack((self.z_buffer, z))
601 550
602 551 if self.decimationx == None:
603 552 deltax = float(self.xmax - self.xmin)/maxNumX
604 553 deltay = float(self.ymax - self.ymin)/maxNumY
605 554
606 555 resolutionx = self.x_buffer[2]-self.x_buffer[0]
607 556 resolutiony = y[1]-y[0]
608 557
609 558 self.decimationx = numpy.ceil(deltax / resolutionx)
610 559 self.decimationy = numpy.ceil(deltay / resolutiony)
611 560
612 561 z_buffer = self.z_buffer.reshape(-1,len(y))
613 562
614 563 x_buffer = self.x_buffer[::self.decimationx]
615 564 y_buffer = y[::self.decimationy]
616 565 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
617 566 #===================================================
618 567
619 568 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
620 569
621 570 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
622 571 xlabel=xlabel,
623 572 ylabel=ylabel,
624 573 title=title,
625 574 colormap=colormap)
626 575 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
627 576
628 577 deltas = x_buffer[1:] - x_buffer[0:-1]
629 578 x_median = numpy.median(deltas)
630 579
631 580 index = numpy.where(deltas >= 2*x_median)
632 581
633 582 if len(index[0]) != 0:
634 583 z_buffer[index[0],::] = self.__missing
635 584 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
636 585
637 586 return x_buffer, y_buffer, z_buffer
638 587
639 588
640 589
641 590 No newline at end of file
@@ -1,318 +1,324
1 1 '''
2 2
3 3 @author: Daniel Suarez
4 4 '''
5 5
6 6 import os
7 7 import datetime
8 8 import numpy
9 9
10 10 from figure import Figure, isRealtime
11 11
12 12 class SpectraHeisScope(Figure):
13 13
14 14
15 15 isConfig = None
16 16 __nsubplots = None
17 17
18 18 WIDTHPROF = None
19 19 HEIGHTPROF = None
20 20 PREFIX = 'spc'
21 21
22 22 def __init__(self):
23 23
24 24 self.isConfig = False
25 25 self.__nsubplots = 1
26 26
27 27 self.WIDTH = 230
28 28 self.HEIGHT = 250
29 29 self.WIDTHPROF = 120
30 30 self.HEIGHTPROF = 0
31 31 self.counter_imagwr = 0
32 32
33 33 def getSubplots(self):
34 34
35 35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 36 nrow = int(self.nplots*1./ncol + 0.9)
37 37
38 38 return nrow, ncol
39 39
40 40 def setup(self, id, nplots, wintitle, show):
41 41
42 42 showprofile = False
43 43 self.__showprofile = showprofile
44 44 self.nplots = nplots
45 45
46 46 ncolspan = 1
47 47 colspan = 1
48 48 if showprofile:
49 49 ncolspan = 3
50 50 colspan = 2
51 51 self.__nsubplots = 2
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 = show)
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
65 65 if counter >= self.nplots:
66 66 break
67 67
68 68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69 69
70 70 if showprofile:
71 71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72 72
73 73 counter += 1
74 74
75 75
76 76 def run(self, dataOut, id, wintitle="", channelList=None,
77 77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
78 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
78 figpath='', figfile=None, ftp=False, wr_period=1, show=True,
79 79 server=None, folder=None, username=None, password=None):
80 80
81 81 """
82 82
83 83 Input:
84 84 dataOut :
85 85 id :
86 86 wintitle :
87 87 channelList :
88 88 xmin : None,
89 89 xmax : None,
90 90 ymin : None,
91 91 ymax : None,
92 92 """
93 93
94 94 if dataOut.realtime:
95 95 if not(isRealtime(utcdatatime = dataOut.utctime)):
96 96 print 'Skipping this plot function'
97 97 return
98 98
99 99 if channelList == None:
100 100 channelIndexList = dataOut.channelIndexList
101 101 else:
102 102 channelIndexList = []
103 103 for channel in channelList:
104 104 if channel not in dataOut.channelList:
105 105 raise ValueError, "Channel %d is not in dataOut.channelList"
106 106 channelIndexList.append(dataOut.channelList.index(channel))
107 107
108 108 # x = dataOut.heightList
109 109 c = 3E8
110 110 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
111 111 #deberia cambiar para el caso de 1Mhz y 100KHz
112 112 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
113 113 #para 1Mhz descomentar la siguiente linea
114 114 #x= x/(10000.0)
115 115 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
116 116 # y = y.real
117 117 datadB = 10.*numpy.log10(dataOut.data_spc)
118 118 y = datadB
119 119
120 120 #thisDatetime = dataOut.datatime
121 121 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
122 122 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
123 123 xlabel = ""
124 124 #para 1Mhz descomentar la siguiente linea
125 125 #xlabel = "Frequency x 10000"
126 126 ylabel = "Intensity (dB)"
127 127
128 128 if not self.isConfig:
129 129 nplots = len(channelIndexList)
130 130
131 131 self.setup(id=id,
132 132 nplots=nplots,
133 133 wintitle=wintitle,
134 134 show=show)
135 135
136 136 if xmin == None: xmin = numpy.nanmin(x)
137 137 if xmax == None: xmax = numpy.nanmax(x)
138 138 if ymin == None: ymin = numpy.nanmin(y)
139 139 if ymax == None: ymax = numpy.nanmax(y)
140 140
141 141 self.isConfig = True
142 142
143 143 self.setWinTitle(title)
144 144
145 145 for i in range(len(self.axesList)):
146 146 ychannel = y[i,:]
147 147 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
148 148 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
149 149 axes = self.axesList[i]
150 150 axes.pline(x, ychannel,
151 151 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
152 152 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
153 153
154 154
155 155 self.draw()
156
157 if save:
158 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
159 if figfile == None:
160 figfile = self.getFilename(name = date)
161
162 self.saveFigure(figpath, figfile)
163
156
157 if figfile == None:
158 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
159 figfile = self.getFilename(name = str_datetime)
160
161 if figpath != '':
164 162 self.counter_imagwr += 1
165 if (ftp and (self.counter_imagwr==wr_period)):
166 ftp_filename = os.path.join(figpath,figfile)
167 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
163 if (self.counter_imagwr>=wr_period):
164 # store png plot to local folder
165 self.saveFigure(figpath, figfile)
166 # store png plot to FTP server according to RT-Web format
167 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
168 #ftp_filename = os.path.join(figpath, name)
169 #self.saveFigure(figpath, ftp_filename)
168 170 self.counter_imagwr = 0
169 171
170 172 class RTIfromSpectraHeis(Figure):
171 173
172 174 isConfig = None
173 175 __nsubplots = None
174 176
175 177 PREFIX = 'rtinoise'
176 178
177 179 def __init__(self):
178 180
179 181 self.timerange = 24*60*60
180 182 self.isConfig = False
181 183 self.__nsubplots = 1
182 184
183 185 self.WIDTH = 820
184 186 self.HEIGHT = 200
185 187 self.WIDTHPROF = 120
186 188 self.HEIGHTPROF = 0
187 189 self.counter_imagwr = 0
188 190 self.xdata = None
189 191 self.ydata = None
192 self.figfile = None
190 193
191 194 def getSubplots(self):
192 195
193 196 ncol = 1
194 197 nrow = 1
195 198
196 199 return nrow, ncol
197 200
198 201 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
199 202
200 203 self.__showprofile = showprofile
201 204 self.nplots = nplots
202 205
203 206 ncolspan = 7
204 207 colspan = 6
205 208 self.__nsubplots = 2
206 209
207 210 self.createFigure(id = id,
208 211 wintitle = wintitle,
209 212 widthplot = self.WIDTH+self.WIDTHPROF,
210 213 heightplot = self.HEIGHT+self.HEIGHTPROF,
211 214 show = show)
212 215
213 216 nrow, ncol = self.getSubplots()
214 217
215 218 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
216 219
217 220
218 221 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
219 222 xmin=None, xmax=None, ymin=None, ymax=None,
220 223 timerange=None,
221 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
224 save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True,
222 225 server=None, folder=None, username=None, password=None):
223 226
224 227 if channelList == None:
225 228 channelIndexList = dataOut.channelIndexList
226 229 channelList = dataOut.channelList
227 230 else:
228 231 channelIndexList = []
229 232 for channel in channelList:
230 233 if channel not in dataOut.channelList:
231 234 raise ValueError, "Channel %d is not in dataOut.channelList"
232 235 channelIndexList.append(dataOut.channelList.index(channel))
233 236
234 237 if timerange != None:
235 238 self.timerange = timerange
236 239
237 240 tmin = None
238 241 tmax = None
239 242 x = dataOut.getTimeRange()
240 243 y = dataOut.getHeiRange()
241 244
242 245
243 246 data = dataOut.data_spc
244 247 data = numpy.average(data,axis=1)
245 248 datadB = 10*numpy.log10(data)
246 249
247 250 # factor = dataOut.normFactor
248 251 # noise = dataOut.getNoise()/factor
249 252 # noisedB = 10*numpy.log10(noise)
250 253
251 254 #thisDatetime = dataOut.datatime
252 255 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
253 256 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
254 257 xlabel = "Local Time"
255 258 ylabel = "Intensity (dB)"
256 259
257 260 if not self.isConfig:
258 261
259 262 nplots = 1
260 263
261 264 self.setup(id=id,
262 265 nplots=nplots,
263 266 wintitle=wintitle,
264 267 showprofile=showprofile,
265 268 show=show)
266 269
267 270 tmin, tmax = self.getTimeLim(x, xmin, xmax)
268 271 if ymin == None: ymin = numpy.nanmin(datadB)
269 272 if ymax == None: ymax = numpy.nanmax(datadB)
270 273
271 274 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
272 275 self.isConfig = True
273
276 self.figfile = figfile
274 277 self.xdata = numpy.array([])
275 278 self.ydata = numpy.array([])
276 279
277 280 self.setWinTitle(title)
278 281
279 282
280 283 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
281 284 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
282 285
283 286 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
284 287 axes = self.axesList[0]
285 288
286 289 self.xdata = numpy.hstack((self.xdata, x[0:1]))
287 290
288 291 if len(self.ydata)==0:
289 292 self.ydata = datadB[channelIndexList].reshape(-1,1)
290 293 else:
291 294 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
292 295
293 296
294 297 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
295 298 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
296 299 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
297 300 XAxisAsTime=True
298 301 )
299 302
300 303 self.draw()
301 304
302 if save:
303
304 if figfile == None:
305 figfile = self.getFilename(name = self.name)
306
307 self.saveFigure(figpath, figfile)
308
309 self.counter_imagwr += 1
310 if (ftp and (self.counter_imagwr==wr_period)):
311 ftp_filename = os.path.join(figpath,figfile)
312 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
313 self.counter_imagwr = 0
314
315 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
316 self.isConfig = False
305 if x[1] >= self.axesList[0].xmax:
306 self.counter_imagwr = wr_period
317 307 del self.xdata
318 308 del self.ydata
309 self.__isConfig = False
310
311 if self.figfile == None:
312 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
313 self.figfile = self.getFilename(name = str_datetime)
314
315 if figpath != '':
316 self.counter_imagwr += 1
317 if (self.counter_imagwr>=wr_period):
318 # store png plot to local folder
319 self.saveFigure(figpath, self.figfile)
320 # store png plot to FTP server according to RT-Web format
321 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
322 #ftp_filename = os.path.join(figpath, name)
323 #self.saveFigure(figpath, ftp_filename)
324 self.counter_imagwr = 0
@@ -1,1151 +1,1346
1 1 '''
2 2 @author: Daniel Suarez
3 3 '''
4 4 import os
5 5 import datetime
6 6 import numpy
7 7
8 8 from figure import Figure, isRealtime
9 9
10 10 class SpectraPlot(Figure):
11 11
12 12 isConfig = None
13 13 __nsubplots = None
14 14
15 15 WIDTHPROF = None
16 16 HEIGHTPROF = None
17 17 PREFIX = 'spc'
18 18
19 19 def __init__(self):
20 20
21 21 self.isConfig = False
22 22 self.__nsubplots = 1
23 23
24 24 self.WIDTH = 280
25 25 self.HEIGHT = 250
26 26 self.WIDTHPROF = 120
27 27 self.HEIGHTPROF = 0
28 28 self.counter_imagwr = 0
29 29
30 30 self.PLOT_CODE = 1
31 31 self.FTP_WEI = None
32 32 self.EXP_CODE = None
33 33 self.SUB_EXP_CODE = None
34 34 self.PLOT_POS = None
35 35
36 36 def getSubplots(self):
37 37
38 38 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 39 nrow = int(self.nplots*1./ncol + 0.9)
40 40
41 41 return nrow, ncol
42 42
43 43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44 44
45 45 self.__showprofile = showprofile
46 46 self.nplots = nplots
47 47
48 48 ncolspan = 1
49 49 colspan = 1
50 50 if showprofile:
51 51 ncolspan = 3
52 52 colspan = 2
53 53 self.__nsubplots = 2
54 54
55 55 self.createFigure(id = id,
56 56 wintitle = wintitle,
57 57 widthplot = self.WIDTH + self.WIDTHPROF,
58 58 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 59 show=show)
60 60
61 61 nrow, ncol = self.getSubplots()
62 62
63 63 counter = 0
64 64 for y in range(nrow):
65 65 for x in range(ncol):
66 66
67 67 if counter >= self.nplots:
68 68 break
69 69
70 70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71 71
72 72 if showprofile:
73 73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74 74
75 75 counter += 1
76 76
77 77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 79 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
80 80 server=None, folder=None, username=None, password=None,
81 81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82 82
83 83 """
84 84
85 85 Input:
86 86 dataOut :
87 87 id :
88 88 wintitle :
89 89 channelList :
90 90 showProfile :
91 91 xmin : None,
92 92 xmax : None,
93 93 ymin : None,
94 94 ymax : None,
95 95 zmin : None,
96 96 zmax : None
97 97 """
98 98
99 99 if dataOut.flagNoData:
100 100 return None
101 101
102 102 if realtime:
103 103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 104 print 'Skipping this plot function'
105 105 return
106 106
107 107 if channelList == None:
108 108 channelIndexList = dataOut.channelIndexList
109 109 else:
110 110 channelIndexList = []
111 111 for channel in channelList:
112 112 if channel not in dataOut.channelList:
113 113 raise ValueError, "Channel %d is not in dataOut.channelList"
114 114 channelIndexList.append(dataOut.channelList.index(channel))
115 115
116 116 factor = dataOut.normFactor
117 117
118 118 x = dataOut.getVelRange(1)
119 119 y = dataOut.getHeiRange()
120 120
121 121 z = dataOut.data_spc[channelIndexList,:,:]/factor
122 122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
123 123 avg = numpy.average(z, axis=1)
124 124 avg = numpy.nanmean(z, axis=1)
125 125 noise = dataOut.noise/factor
126 126
127 127 zdB = 10*numpy.log10(z)
128 128 avgdB = 10*numpy.log10(avg)
129 129 noisedB = 10*numpy.log10(noise)
130 130
131 131 #thisDatetime = dataOut.datatime
132 132 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
133 133 title = wintitle + " Spectra"
134 134 xlabel = "Velocity (m/s)"
135 135 ylabel = "Range (Km)"
136 136
137 137 if not self.isConfig:
138 138
139 139 nplots = len(channelIndexList)
140 140
141 141 self.setup(id=id,
142 142 nplots=nplots,
143 143 wintitle=wintitle,
144 144 showprofile=showprofile,
145 145 show=show)
146 146
147 147 if xmin == None: xmin = numpy.nanmin(x)
148 148 if xmax == None: xmax = numpy.nanmax(x)
149 149 if ymin == None: ymin = numpy.nanmin(y)
150 150 if ymax == None: ymax = numpy.nanmax(y)
151 151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153 153
154 154 self.FTP_WEI = ftp_wei
155 155 self.EXP_CODE = exp_code
156 156 self.SUB_EXP_CODE = sub_exp_code
157 157 self.PLOT_POS = plot_pos
158 158
159 159 self.isConfig = True
160 160
161 161 self.setWinTitle(title)
162 162
163 163 for i in range(self.nplots):
164 164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
165 165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
166 166 axes = self.axesList[i*self.__nsubplots]
167 167 axes.pcolor(x, y, zdB[i,:,:],
168 168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
169 169 xlabel=xlabel, ylabel=ylabel, title=title,
170 170 ticksize=9, cblabel='')
171 171
172 172 if self.__showprofile:
173 173 axes = self.axesList[i*self.__nsubplots +1]
174 174 axes.pline(avgdB[i], y,
175 175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 176 xlabel='dB', ylabel='', title='',
177 177 ytick_visible=False,
178 178 grid='x')
179 179
180 180 noiseline = numpy.repeat(noisedB[i], len(y))
181 181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182 182
183 183 self.draw()
184 184
185 185 if figfile == None:
186 186 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
187 187 figfile = self.getFilename(name = str_datetime)
188 188
189 189 if figpath != '':
190 190 self.counter_imagwr += 1
191 191 if (self.counter_imagwr>=wr_period):
192 192 # store png plot to local folder
193 193 self.saveFigure(figpath, figfile)
194 194 # store png plot to FTP server according to RT-Web format
195 195 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
196 196 ftp_filename = os.path.join(figpath, name)
197 197 self.saveFigure(figpath, ftp_filename)
198 198 self.counter_imagwr = 0
199 199
200 200
201 201 class CrossSpectraPlot(Figure):
202 202
203 203 isConfig = None
204 204 __nsubplots = None
205 205
206 206 WIDTH = None
207 207 HEIGHT = None
208 208 WIDTHPROF = None
209 209 HEIGHTPROF = None
210 210 PREFIX = 'cspc'
211 211
212 212 def __init__(self):
213 213
214 214 self.isConfig = False
215 215 self.__nsubplots = 4
216 216 self.counter_imagwr = 0
217 217 self.WIDTH = 250
218 218 self.HEIGHT = 250
219 219 self.WIDTHPROF = 0
220 220 self.HEIGHTPROF = 0
221 221
222 222 self.PLOT_CODE = 1
223 223 self.FTP_WEI = None
224 224 self.EXP_CODE = None
225 225 self.SUB_EXP_CODE = None
226 226 self.PLOT_POS = None
227 227
228 228 def getSubplots(self):
229 229
230 230 ncol = 4
231 231 nrow = self.nplots
232 232
233 233 return nrow, ncol
234 234
235 235 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
236 236
237 237 self.__showprofile = showprofile
238 238 self.nplots = nplots
239 239
240 240 ncolspan = 1
241 241 colspan = 1
242 242
243 243 self.createFigure(id = id,
244 244 wintitle = wintitle,
245 245 widthplot = self.WIDTH + self.WIDTHPROF,
246 246 heightplot = self.HEIGHT + self.HEIGHTPROF,
247 247 show=True)
248 248
249 249 nrow, ncol = self.getSubplots()
250 250
251 251 counter = 0
252 252 for y in range(nrow):
253 253 for x in range(ncol):
254 254 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
255 255
256 256 counter += 1
257 257
258 258 def run(self, dataOut, id, wintitle="", pairsList=None,
259 259 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
260 260 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
261 261 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
262 262 server=None, folder=None, username=None, password=None,
263 263 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
264 264
265 265 """
266 266
267 267 Input:
268 268 dataOut :
269 269 id :
270 270 wintitle :
271 271 channelList :
272 272 showProfile :
273 273 xmin : None,
274 274 xmax : None,
275 275 ymin : None,
276 276 ymax : None,
277 277 zmin : None,
278 278 zmax : None
279 279 """
280 280
281 281 if pairsList == None:
282 282 pairsIndexList = dataOut.pairsIndexList
283 283 else:
284 284 pairsIndexList = []
285 285 for pair in pairsList:
286 286 if pair not in dataOut.pairsList:
287 287 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
288 288 pairsIndexList.append(dataOut.pairsList.index(pair))
289 289
290 290 if pairsIndexList == []:
291 291 return
292 292
293 293 if len(pairsIndexList) > 4:
294 294 pairsIndexList = pairsIndexList[0:4]
295 295 factor = dataOut.normFactor
296 296 x = dataOut.getVelRange(1)
297 297 y = dataOut.getHeiRange()
298 298 z = dataOut.data_spc[:,:,:]/factor
299 299 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
300 300 avg = numpy.abs(numpy.average(z, axis=1))
301 301 noise = dataOut.noise()/factor
302 302
303 303 zdB = 10*numpy.log10(z)
304 304 avgdB = 10*numpy.log10(avg)
305 305 noisedB = 10*numpy.log10(noise)
306 306
307 307
308 308 #thisDatetime = dataOut.datatime
309 309 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
310 310 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
311 311 xlabel = "Velocity (m/s)"
312 312 ylabel = "Range (Km)"
313 313
314 314 if not self.isConfig:
315 315
316 316 nplots = len(pairsIndexList)
317 317
318 318 self.setup(id=id,
319 319 nplots=nplots,
320 320 wintitle=wintitle,
321 321 showprofile=False,
322 322 show=show)
323 323
324 324 if xmin == None: xmin = numpy.nanmin(x)
325 325 if xmax == None: xmax = numpy.nanmax(x)
326 326 if ymin == None: ymin = numpy.nanmin(y)
327 327 if ymax == None: ymax = numpy.nanmax(y)
328 328 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
329 329 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
330 330
331 331 self.FTP_WEI = ftp_wei
332 332 self.EXP_CODE = exp_code
333 333 self.SUB_EXP_CODE = sub_exp_code
334 334 self.PLOT_POS = plot_pos
335 335
336 336 self.isConfig = True
337 337
338 338 self.setWinTitle(title)
339 339
340 340 for i in range(self.nplots):
341 341 pair = dataOut.pairsList[pairsIndexList[i]]
342 342 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
343 343 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
344 344 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
345 345 axes0 = self.axesList[i*self.__nsubplots]
346 346 axes0.pcolor(x, y, zdB,
347 347 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
348 348 xlabel=xlabel, ylabel=ylabel, title=title,
349 349 ticksize=9, colormap=power_cmap, cblabel='')
350 350
351 351 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
352 352 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
353 353 axes0 = self.axesList[i*self.__nsubplots+1]
354 354 axes0.pcolor(x, y, zdB,
355 355 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
356 356 xlabel=xlabel, ylabel=ylabel, title=title,
357 357 ticksize=9, colormap=power_cmap, cblabel='')
358 358
359 359 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
360 360 coherence = numpy.abs(coherenceComplex)
361 361 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
362 362 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
363 363
364 364 title = "Coherence %d%d" %(pair[0], pair[1])
365 365 axes0 = self.axesList[i*self.__nsubplots+2]
366 366 axes0.pcolor(x, y, coherence,
367 367 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
368 368 xlabel=xlabel, ylabel=ylabel, title=title,
369 369 ticksize=9, colormap=coherence_cmap, cblabel='')
370 370
371 371 title = "Phase %d%d" %(pair[0], pair[1])
372 372 axes0 = self.axesList[i*self.__nsubplots+3]
373 373 axes0.pcolor(x, y, phase,
374 374 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
375 375 xlabel=xlabel, ylabel=ylabel, title=title,
376 376 ticksize=9, colormap=phase_cmap, cblabel='')
377 377
378 378
379 379
380 380 self.draw()
381 381
382 if save:
383
382 if figfile == None:
383 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
384 figfile = self.getFilename(name = str_datetime)
385
386 if figpath != '':
384 387 self.counter_imagwr += 1
385 if (self.counter_imagwr==wr_period):
386 if figfile == None:
387 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
388 figfile = self.getFilename(name = str_datetime)
389
388 if (self.counter_imagwr>=wr_period):
389 # store png plot to local folder
390 390 self.saveFigure(figpath, figfile)
391
392 if ftp:
393 #provisionalmente envia archivos en el formato de la web en tiempo real
394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
395 path = '%s%03d' %(self.PREFIX, self.id)
396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
397 self.saveFigure(figpath, ftp_file)
398 ftp_filename = os.path.join(figpath,ftp_file)
399
400 try:
401 self.sendByFTP(ftp_filename, server, folder, username, password)
402 except:
403 self.counter_imagwr = 0
404 print ValueError, 'Error FTP'
405
391 # store png plot to FTP server according to RT-Web format
392 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
393 ftp_filename = os.path.join(figpath, name)
394 self.saveFigure(figpath, ftp_filename)
406 395 self.counter_imagwr = 0
407 396
397
408 398 class RTIPlot(Figure):
409 399
410 400 isConfig = None
411 401 __nsubplots = None
412 402
413 403 WIDTHPROF = None
414 404 HEIGHTPROF = None
415 405 PREFIX = 'rti'
416 406
417 407 def __init__(self):
418 408
419 409 self.timerange = 2*60*60
420 410 self.isConfig = False
421 411 self.__nsubplots = 1
422 412
423 413 self.WIDTH = 800
424 414 self.HEIGHT = 150
425 415 self.WIDTHPROF = 120
426 416 self.HEIGHTPROF = 0
427 417 self.counter_imagwr = 0
428 418
429 419 self.PLOT_CODE = 0
430 420 self.FTP_WEI = None
431 421 self.EXP_CODE = None
432 422 self.SUB_EXP_CODE = None
433 423 self.PLOT_POS = None
434 424 self.tmin = None
435 425 self.tmax = None
436 426
437 427 self.xmin = None
438 428 self.xmax = None
439 429
440 430 self.figfile = None
441 431
442 432 def getSubplots(self):
443 433
444 434 ncol = 1
445 435 nrow = self.nplots
446 436
447 437 return nrow, ncol
448 438
449 439 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
450 440
451 441 self.__showprofile = showprofile
452 442 self.nplots = nplots
453 443
454 444 ncolspan = 1
455 445 colspan = 1
456 446 if showprofile:
457 447 ncolspan = 7
458 448 colspan = 6
459 449 self.__nsubplots = 2
460 450
461 451 self.createFigure(id = id,
462 452 wintitle = wintitle,
463 453 widthplot = self.WIDTH + self.WIDTHPROF,
464 454 heightplot = self.HEIGHT + self.HEIGHTPROF,
465 455 show=show)
466 456
467 457 nrow, ncol = self.getSubplots()
468 458
469 459 counter = 0
470 460 for y in range(nrow):
471 461 for x in range(ncol):
472 462
473 463 if counter >= self.nplots:
474 464 break
475 465
476 466 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
477 467
478 468 if showprofile:
479 469 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
480 470
481 471 counter += 1
482 472
483 473 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
484 474 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
485 475 timerange=None,
486 476 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
487 477 server=None, folder=None, username=None, password=None,
488 478 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
489 479
490 480 """
491 481
492 482 Input:
493 483 dataOut :
494 484 id :
495 485 wintitle :
496 486 channelList :
497 487 showProfile :
498 488 xmin : None,
499 489 xmax : None,
500 490 ymin : None,
501 491 ymax : None,
502 492 zmin : None,
503 493 zmax : None
504 494 """
505 495
506 496 if channelList == None:
507 497 channelIndexList = dataOut.channelIndexList
508 498 else:
509 499 channelIndexList = []
510 500 for channel in channelList:
511 501 if channel not in dataOut.channelList:
512 502 raise ValueError, "Channel %d is not in dataOut.channelList"
513 503 channelIndexList.append(dataOut.channelList.index(channel))
514 504
515 505 if timerange != None:
516 506 self.timerange = timerange
517 507
518 508 #tmin = None
519 509 #tmax = None
520 510 factor = dataOut.normFactor
521 511 x = dataOut.getTimeRange()
522 512 y = dataOut.getHeiRange()
523 513
524 514 z = dataOut.data_spc[channelIndexList,:,:]/factor
525 515 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
526 516 avg = numpy.average(z, axis=1)
527 517
528 518 avgdB = 10.*numpy.log10(avg)
529 519
530 520
531 521 # thisDatetime = dataOut.datatime
532 522 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
533 523 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
534 524 xlabel = ""
535 525 ylabel = "Range (Km)"
536 526
537 527 if not self.isConfig:
538 528
539 529 nplots = len(channelIndexList)
540 530
541 531 self.setup(id=id,
542 532 nplots=nplots,
543 533 wintitle=wintitle,
544 534 showprofile=showprofile,
545 535 show=show)
546 536
547 537 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
548 538
549 539 # if timerange != None:
550 540 # self.timerange = timerange
551 541 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
552 542
553 543
554 544
555 545 if ymin == None: ymin = numpy.nanmin(y)
556 546 if ymax == None: ymax = numpy.nanmax(y)
557 547 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
558 548 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
559 549
560 550 self.FTP_WEI = ftp_wei
561 551 self.EXP_CODE = exp_code
562 552 self.SUB_EXP_CODE = sub_exp_code
563 553 self.PLOT_POS = plot_pos
564 554
565 555 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
566 556 self.isConfig = True
567 557 self.figfile = figfile
568 558
569 559 self.setWinTitle(title)
570 560
571 561 if ((self.xmax - x[1]) < (x[1]-x[0])):
572 562 x[1] = self.xmax
573 563
574 564 for i in range(self.nplots):
575 565 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
576 566 axes = self.axesList[i*self.__nsubplots]
577 567 zdB = avgdB[i].reshape((1,-1))
578 568 axes.pcolorbuffer(x, y, zdB,
579 569 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
580 570 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
581 571 ticksize=9, cblabel='', cbsize="1%")
582 572
583 573 if self.__showprofile:
584 574 axes = self.axesList[i*self.__nsubplots +1]
585 575 axes.pline(avgdB[i], y,
586 576 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
587 577 xlabel='dB', ylabel='', title='',
588 578 ytick_visible=False,
589 579 grid='x')
590 580
591 581 self.draw()
592 582
593 583 if x[1] >= self.axesList[0].xmax:
594 584 self.counter_imagwr = wr_period
595 585 self.__isConfig = False
596 586
597 587
598 588 if self.figfile == None:
599 589 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
600 590 self.figfile = self.getFilename(name = str_datetime)
601 591
602 592 if figpath != '':
603 593
604 594 self.counter_imagwr += 1
605 595 if (self.counter_imagwr>=wr_period):
606 596 # store png plot to local folder
607 597 self.saveFigure(figpath, self.figfile)
608 598 # store png plot to FTP server according to RT-Web format
609 599 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
610 600 ftp_filename = os.path.join(figpath, name)
611 601 self.saveFigure(figpath, ftp_filename)
612 602
613 603 self.counter_imagwr = 0
614 604
615 605
616 606 class CoherenceMap(Figure):
617 607 isConfig = None
618 608 __nsubplots = None
619 609
620 610 WIDTHPROF = None
621 611 HEIGHTPROF = None
622 612 PREFIX = 'cmap'
623 613
624 614 def __init__(self):
625 615 self.timerange = 2*60*60
626 616 self.isConfig = False
627 617 self.__nsubplots = 1
628 618
629 619 self.WIDTH = 800
630 620 self.HEIGHT = 150
631 621 self.WIDTHPROF = 120
632 622 self.HEIGHTPROF = 0
633 623 self.counter_imagwr = 0
634 624
635 625 self.PLOT_CODE = 3
636 626 self.FTP_WEI = None
637 627 self.EXP_CODE = None
638 628 self.SUB_EXP_CODE = None
639 629 self.PLOT_POS = None
640 630 self.counter_imagwr = 0
641 631
642 632 self.xmin = None
643 633 self.xmax = None
644 634
645 635 def getSubplots(self):
646 636 ncol = 1
647 637 nrow = self.nplots*2
648 638
649 639 return nrow, ncol
650 640
651 641 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
652 642 self.__showprofile = showprofile
653 643 self.nplots = nplots
654 644
655 645 ncolspan = 1
656 646 colspan = 1
657 647 if showprofile:
658 648 ncolspan = 7
659 649 colspan = 6
660 650 self.__nsubplots = 2
661 651
662 652 self.createFigure(id = id,
663 653 wintitle = wintitle,
664 654 widthplot = self.WIDTH + self.WIDTHPROF,
665 655 heightplot = self.HEIGHT + self.HEIGHTPROF,
666 656 show=True)
667 657
668 658 nrow, ncol = self.getSubplots()
669 659
670 660 for y in range(nrow):
671 661 for x in range(ncol):
672 662
673 663 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
674 664
675 665 if showprofile:
676 666 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
677 667
678 668 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
679 669 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
680 670 timerange=None,
681 671 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
682 672 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
683 673 server=None, folder=None, username=None, password=None,
684 674 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
685 675
686 676 if pairsList == None:
687 677 pairsIndexList = dataOut.pairsIndexList
688 678 else:
689 679 pairsIndexList = []
690 680 for pair in pairsList:
691 681 if pair not in dataOut.pairsList:
692 682 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
693 683 pairsIndexList.append(dataOut.pairsList.index(pair))
694 684
695 685 if timerange != None:
696 686 self.timerange = timerange
697 687
698 688 if pairsIndexList == []:
699 689 return
700 690
701 691 if len(pairsIndexList) > 4:
702 692 pairsIndexList = pairsIndexList[0:4]
703 693
704 694 # tmin = None
705 695 # tmax = None
706 696 x = dataOut.getTimeRange()
707 697 y = dataOut.getHeiRange()
708 698
709 699 #thisDatetime = dataOut.datatime
710 700 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
711 701 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
712 702 xlabel = ""
713 703 ylabel = "Range (Km)"
714 704
715 705 if not self.isConfig:
716 706 nplots = len(pairsIndexList)
717 707 self.setup(id=id,
718 708 nplots=nplots,
719 709 wintitle=wintitle,
720 710 showprofile=showprofile,
721 711 show=show)
722 712
723 713 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
724 714
725 715 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
726 716
727 717 if ymin == None: ymin = numpy.nanmin(y)
728 718 if ymax == None: ymax = numpy.nanmax(y)
729 719 if zmin == None: zmin = 0.
730 720 if zmax == None: zmax = 1.
731 721
732 722 self.FTP_WEI = ftp_wei
733 723 self.EXP_CODE = exp_code
734 724 self.SUB_EXP_CODE = sub_exp_code
735 725 self.PLOT_POS = plot_pos
736 726
737 727 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
738 728
739 729 self.isConfig = True
740 730
741 731 self.setWinTitle(title)
742 732
743 733 if ((self.xmax - x[1]) < (x[1]-x[0])):
744 734 x[1] = self.xmax
745 735
746 736 for i in range(self.nplots):
747 737
748 738 pair = dataOut.pairsList[pairsIndexList[i]]
749 739
750 740 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
751 741 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
752 742 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
753 743
754 744
755 745 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
756 746 coherence = numpy.abs(avgcoherenceComplex)
757 747
758 748 z = coherence.reshape((1,-1))
759 749
760 750 counter = 0
761 751
762 752 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
763 753 axes = self.axesList[i*self.__nsubplots*2]
764 754 axes.pcolorbuffer(x, y, z,
765 755 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
766 756 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
767 757 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
768 758
769 759 if self.__showprofile:
770 760 counter += 1
771 761 axes = self.axesList[i*self.__nsubplots*2 + counter]
772 762 axes.pline(coherence, y,
773 763 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
774 764 xlabel='', ylabel='', title='', ticksize=7,
775 765 ytick_visible=False, nxticks=5,
776 766 grid='x')
777 767
778 768 counter += 1
779 769
780 770 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
781 771
782 772 z = phase.reshape((1,-1))
783 773
784 774 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
785 775 axes = self.axesList[i*self.__nsubplots*2 + counter]
786 776 axes.pcolorbuffer(x, y, z,
787 777 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
788 778 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
789 779 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
790 780
791 781 if self.__showprofile:
792 782 counter += 1
793 783 axes = self.axesList[i*self.__nsubplots*2 + counter]
794 784 axes.pline(phase, y,
795 785 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
796 786 xlabel='', ylabel='', title='', ticksize=7,
797 787 ytick_visible=False, nxticks=4,
798 788 grid='x')
799 789
800 790 self.draw()
801 791
802 792 if x[1] >= self.axesList[0].xmax:
803 793 self.counter_imagwr = wr_period
804 794 self.__isConfig = False
805 795
806 796 if figfile == None:
807 797 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
808 798 figfile = self.getFilename(name = str_datetime)
809 799
810 800 if figpath != '':
811 801
812 802 self.counter_imagwr += 1
813 803 if (self.counter_imagwr>=wr_period):
814 804 # store png plot to local folder
815 805 self.saveFigure(figpath, figfile)
816 806 # store png plot to FTP server according to RT-Web format
817 807 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
818 808 ftp_filename = os.path.join(figpath, name)
819 809 self.saveFigure(figpath, ftp_filename)
820 810
821 811 self.counter_imagwr = 0
822 812
823 813 class PowerProfile(Figure):
824 814 isConfig = None
825 815 __nsubplots = None
826 816
827 817 WIDTHPROF = None
828 818 HEIGHTPROF = None
829 819 PREFIX = 'spcprofile'
830 820
831 821 def __init__(self):
832 822 self.isConfig = False
833 823 self.__nsubplots = 1
834 824
835 825 self.WIDTH = 300
836 826 self.HEIGHT = 500
837 827 self.counter_imagwr = 0
838 828
839 829 def getSubplots(self):
840 830 ncol = 1
841 831 nrow = 1
842 832
843 833 return nrow, ncol
844 834
845 835 def setup(self, id, nplots, wintitle, show):
846 836
847 837 self.nplots = nplots
848 838
849 839 ncolspan = 1
850 840 colspan = 1
851 841
852 842 self.createFigure(id = id,
853 843 wintitle = wintitle,
854 844 widthplot = self.WIDTH,
855 845 heightplot = self.HEIGHT,
856 846 show=show)
857 847
858 848 nrow, ncol = self.getSubplots()
859 849
860 850 counter = 0
861 851 for y in range(nrow):
862 852 for x in range(ncol):
863 853 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
864 854
865 855 def run(self, dataOut, id, wintitle="", channelList=None,
866 856 xmin=None, xmax=None, ymin=None, ymax=None,
867 857 save=False, figpath='', figfile=None, show=True, wr_period=1,
868 858 server=None, folder=None, username=None, password=None,):
869 859
870 860 if dataOut.flagNoData:
871 861 return None
872 862
873 863 if channelList == None:
874 864 channelIndexList = dataOut.channelIndexList
875 865 channelList = dataOut.channelList
876 866 else:
877 867 channelIndexList = []
878 868 for channel in channelList:
879 869 if channel not in dataOut.channelList:
880 870 raise ValueError, "Channel %d is not in dataOut.channelList"
881 871 channelIndexList.append(dataOut.channelList.index(channel))
882 872
883 873 try:
884 874 factor = dataOut.normFactor
885 875 except:
886 876 factor = 1
887 877
888 878 y = dataOut.getHeiRange()
889 879
890 880 #for voltage
891 881 if dataOut.type == 'Voltage':
892 882 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
893 883 x = x.real
894 884 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
895 885
896 886 #for spectra
897 887 if dataOut.type == 'Spectra':
898 888 x = dataOut.data_spc[channelIndexList,:,:]/factor
899 889 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
900 890 x = numpy.average(x, axis=1)
901 891
902 892
903 893 xdB = 10*numpy.log10(x)
904 894
905 895 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
906 896 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
907 897 xlabel = "dB"
908 898 ylabel = "Range (Km)"
909 899
910 900 if not self.isConfig:
911 901
912 902 nplots = 1
913 903
914 904 self.setup(id=id,
915 905 nplots=nplots,
916 906 wintitle=wintitle,
917 907 show=show)
918 908
919 909 if ymin == None: ymin = numpy.nanmin(y)
920 910 if ymax == None: ymax = numpy.nanmax(y)
921 911 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
922 912 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
923 913
924 914 self.__isConfig = True
925 915
926 916 self.setWinTitle(title)
927 917
928 918 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
929 919 axes = self.axesList[0]
930 920
931 921 legendlabels = ["channel %d"%x for x in channelList]
932 922 axes.pmultiline(xdB, y,
933 923 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
934 924 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
935 925 ytick_visible=True, nxticks=5,
936 926 grid='x')
937 927
938 928 self.draw()
939 929
940 if save:
941 date = thisDatetime.strftime("%Y%m%d")
942 if figfile == None:
943 figfile = self.getFilename(name = date)
944
945 self.saveFigure(figpath, figfile)
946
930 if figfile == None:
931 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
932 figfile = self.getFilename(name = str_datetime)
933
934 if figpath != '':
947 935 self.counter_imagwr += 1
948 if (ftp and (self.counter_imagwr==wr_period)):
949 ftp_filename = os.path.join(figpath,figfile)
950 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
936 if (self.counter_imagwr>=wr_period):
937 # store png plot to local folder
938 self.saveFigure(figpath, figfile)
939 # store png plot to FTP server according to RT-Web format
940 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
941 #ftp_filename = os.path.join(figpath, name)
942 #self.saveFigure(figpath, ftp_filename)
951 943 self.counter_imagwr = 0
952 944
945
946
953 947 class Noise(Figure):
954 948
955 949 isConfig = None
956 950 __nsubplots = None
957 951
958 952 PREFIX = 'noise'
959 953
960 954 def __init__(self):
961 955
962 956 self.timerange = 24*60*60
963 957 self.isConfig = False
964 958 self.__nsubplots = 1
965 959 self.counter_imagwr = 0
966 960 self.WIDTH = 600
967 961 self.HEIGHT = 300
968 962 self.WIDTHPROF = 120
969 963 self.HEIGHTPROF = 0
970 964 self.xdata = None
971 965 self.ydata = None
972 966
973 self.PLOT_CODE = 77
967 self.PLOT_CODE = 17
974 968 self.FTP_WEI = None
975 969 self.EXP_CODE = None
976 970 self.SUB_EXP_CODE = None
977 971 self.PLOT_POS = None
972 self.figfile = None
978 973
979 974 def getSubplots(self):
980 975
981 976 ncol = 1
982 977 nrow = 1
983 978
984 979 return nrow, ncol
985 980
986 981 def openfile(self, filename):
987 982 f = open(filename,'w+')
988 983 f.write('\n\n')
989 984 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
990 985 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
991 986 f.close()
992 987
993 988 def save_data(self, filename_phase, data, data_datetime):
994 989 f=open(filename_phase,'a')
995 990 timetuple_data = data_datetime.timetuple()
996 991 day = str(timetuple_data.tm_mday)
997 992 month = str(timetuple_data.tm_mon)
998 993 year = str(timetuple_data.tm_year)
999 994 hour = str(timetuple_data.tm_hour)
1000 995 minute = str(timetuple_data.tm_min)
1001 996 second = str(timetuple_data.tm_sec)
1002 997 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1003 998 f.close()
1004 999
1005 1000
1006 1001 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1007 1002
1008 1003 self.__showprofile = showprofile
1009 1004 self.nplots = nplots
1010 1005
1011 1006 ncolspan = 7
1012 1007 colspan = 6
1013 1008 self.__nsubplots = 2
1014 1009
1015 1010 self.createFigure(id = id,
1016 1011 wintitle = wintitle,
1017 1012 widthplot = self.WIDTH+self.WIDTHPROF,
1018 1013 heightplot = self.HEIGHT+self.HEIGHTPROF,
1019 1014 show=show)
1020 1015
1021 1016 nrow, ncol = self.getSubplots()
1022 1017
1023 1018 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1024 1019
1025 1020
1026 1021 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1027 1022 xmin=None, xmax=None, ymin=None, ymax=None,
1028 1023 timerange=None,
1029 1024 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1030 1025 server=None, folder=None, username=None, password=None,
1031 1026 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1032 1027
1033 1028 if channelList == None:
1034 1029 channelIndexList = dataOut.channelIndexList
1035 1030 channelList = dataOut.channelList
1036 1031 else:
1037 1032 channelIndexList = []
1038 1033 for channel in channelList:
1039 1034 if channel not in dataOut.channelList:
1040 1035 raise ValueError, "Channel %d is not in dataOut.channelList"
1041 1036 channelIndexList.append(dataOut.channelList.index(channel))
1042 1037
1043 1038 if timerange != None:
1044 1039 self.timerange = timerange
1045 1040
1046 1041 tmin = None
1047 1042 tmax = None
1048 1043 x = dataOut.getTimeRange()
1049 1044 y = dataOut.getHeiRange()
1050 1045 factor = dataOut.normFactor
1051 1046 noise = dataOut.noise()/factor
1052 1047 noisedB = 10*numpy.log10(noise)
1053 1048
1054 1049 #thisDatetime = dataOut.datatime
1055 1050 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1056 1051 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1057 1052 xlabel = ""
1058 1053 ylabel = "Intensity (dB)"
1059 1054
1060 1055 if not self.isConfig:
1061 1056
1062 1057 nplots = 1
1063 1058
1064 1059 self.setup(id=id,
1065 1060 nplots=nplots,
1066 1061 wintitle=wintitle,
1067 1062 showprofile=showprofile,
1068 1063 show=show)
1069 1064
1070 1065 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1071 1066 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1072 1067 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1073 1068
1074 1069 self.FTP_WEI = ftp_wei
1075 1070 self.EXP_CODE = exp_code
1076 1071 self.SUB_EXP_CODE = sub_exp_code
1077 1072 self.PLOT_POS = plot_pos
1078 1073
1079 1074
1080 1075 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1081 1076 self.isConfig = True
1082
1077 self.figfile = figfile
1083 1078 self.xdata = numpy.array([])
1084 1079 self.ydata = numpy.array([])
1085 1080
1086 1081 #open file beacon phase
1087 1082 path = '%s%03d' %(self.PREFIX, self.id)
1088 1083 noise_file = os.path.join(path,'%s.txt'%self.name)
1089 1084 self.filename_noise = os.path.join(figpath,noise_file)
1090 1085 self.openfile(self.filename_noise)
1091 1086
1092 1087
1093 1088 #store data beacon phase
1094 1089 self.save_data(self.filename_noise, noisedB, thisDatetime)
1095 1090
1096 1091
1097 1092 self.setWinTitle(title)
1098 1093
1099 1094
1100 1095 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1101 1096
1102 1097 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1103 1098 axes = self.axesList[0]
1104 1099
1105 1100 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1106 1101
1107 1102 if len(self.ydata)==0:
1108 1103 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1109 1104 else:
1110 1105 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1111 1106
1112 1107
1113 1108 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1114 1109 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1115 1110 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1116 1111 XAxisAsTime=True, grid='both'
1117 1112 )
1118 1113
1119 1114 self.draw()
1120 1115
1121 # if save:
1122 #
1123 # if figfile == None:
1124 # figfile = self.getFilename(name = self.name)
1125 #
1126 # self.saveFigure(figpath, figfile)
1116 if x[1] >= self.axesList[0].xmax:
1117 self.counter_imagwr = wr_period
1118 del self.xdata
1119 del self.ydata
1120 self.__isConfig = False
1127 1121
1128 if save:
1129
1122 if self.figfile == None:
1123 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1124 self.figfile = self.getFilename(name = str_datetime)
1125
1126 if figpath != '':
1130 1127 self.counter_imagwr += 1
1131 if (self.counter_imagwr==wr_period):
1132 if figfile == None:
1133 figfile = self.getFilename(name = self.name)
1134 self.saveFigure(figpath, figfile)
1135
1136 if ftp:
1137 #provisionalmente envia archivos en el formato de la web en tiempo real
1138 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1139 path = '%s%03d' %(self.PREFIX, self.id)
1140 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1141 self.saveFigure(figpath, ftp_file)
1142 ftp_filename = os.path.join(figpath,ftp_file)
1143 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1144 self.counter_imagwr = 0
1145
1128 if (self.counter_imagwr>=wr_period):
1129 # store png plot to local folder
1130 self.saveFigure(figpath, self.figfile)
1131 # store png plot to FTP server according to RT-Web format
1132 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1133 ftp_filename = os.path.join(figpath, name)
1134 self.saveFigure(figpath, ftp_filename)
1146 1135 self.counter_imagwr = 0
1147
1148 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1149 self.isConfig = False
1136
1137
1138 class BeaconPhase(Figure):
1139
1140 __isConfig = None
1141 __nsubplots = None
1142
1143 PREFIX = 'beacon_phase'
1144
1145 def __init__(self):
1146
1147 self.timerange = 24*60*60
1148 self.__isConfig = False
1149 self.__nsubplots = 1
1150 self.counter_imagwr = 0
1151 self.WIDTH = 600
1152 self.HEIGHT = 300
1153 self.WIDTHPROF = 120
1154 self.HEIGHTPROF = 0
1155 self.xdata = None
1156 self.ydata = None
1157
1158 self.PLOT_CODE = 18
1159 self.FTP_WEI = None
1160 self.EXP_CODE = None
1161 self.SUB_EXP_CODE = None
1162 self.PLOT_POS = None
1163
1164 self.filename_phase = None
1165
1166 self.figfile = None
1167
1168 def getSubplots(self):
1169
1170 ncol = 1
1171 nrow = 1
1172
1173 return nrow, ncol
1174
1175 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1176
1177 self.__showprofile = showprofile
1178 self.nplots = nplots
1179
1180 ncolspan = 7
1181 colspan = 6
1182 self.__nsubplots = 2
1183
1184 self.createFigure(id = id,
1185 wintitle = wintitle,
1186 widthplot = self.WIDTH+self.WIDTHPROF,
1187 heightplot = self.HEIGHT+self.HEIGHTPROF,
1188 show=show)
1189
1190 nrow, ncol = self.getSubplots()
1191
1192 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1193
1194 def save_phase(self, filename_phase):
1195 f = open(filename_phase,'w+')
1196 f.write('\n\n')
1197 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1198 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1199 f.close()
1200
1201 def save_data(self, filename_phase, data, data_datetime):
1202 f=open(filename_phase,'a')
1203 timetuple_data = data_datetime.timetuple()
1204 day = str(timetuple_data.tm_mday)
1205 month = str(timetuple_data.tm_mon)
1206 year = str(timetuple_data.tm_year)
1207 hour = str(timetuple_data.tm_hour)
1208 minute = str(timetuple_data.tm_min)
1209 second = str(timetuple_data.tm_sec)
1210 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1211 f.close()
1212
1213
1214 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1215 xmin=None, xmax=None, ymin=None, ymax=None,
1216 timerange=None,
1217 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1218 server=None, folder=None, username=None, password=None,
1219 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1220
1221 if pairsList == None:
1222 pairsIndexList = dataOut.pairsIndexList
1223 else:
1224 pairsIndexList = []
1225 for pair in pairsList:
1226 if pair not in dataOut.pairsList:
1227 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1228 pairsIndexList.append(dataOut.pairsList.index(pair))
1229
1230 if pairsIndexList == []:
1231 return
1232
1233 # if len(pairsIndexList) > 4:
1234 # pairsIndexList = pairsIndexList[0:4]
1235
1236 if timerange != None:
1237 self.timerange = timerange
1238
1239 tmin = None
1240 tmax = None
1241 x = dataOut.getTimeRange()
1242 y = dataOut.getHeiRange()
1243
1244
1245 #thisDatetime = dataOut.datatime
1246 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1247 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1248 xlabel = "Local Time"
1249 ylabel = "Phase"
1250
1251 nplots = len(pairsIndexList)
1252 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1253 phase_beacon = numpy.zeros(len(pairsIndexList))
1254 for i in range(nplots):
1255 pair = dataOut.pairsList[pairsIndexList[i]]
1256 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1257 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1258 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1259 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1260 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1261
1262 #print "Phase %d%d" %(pair[0], pair[1])
1263 #print phase[dataOut.beacon_heiIndexList]
1264
1265 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1266
1267 if not self.__isConfig:
1268
1269 nplots = len(pairsIndexList)
1270
1271 self.setup(id=id,
1272 nplots=nplots,
1273 wintitle=wintitle,
1274 showprofile=showprofile,
1275 show=show)
1276
1277 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1278 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1279 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1280
1281 self.FTP_WEI = ftp_wei
1282 self.EXP_CODE = exp_code
1283 self.SUB_EXP_CODE = sub_exp_code
1284 self.PLOT_POS = plot_pos
1285
1286 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1287 self.__isConfig = True
1288 self.figfile = figfile
1289 self.xdata = numpy.array([])
1290 self.ydata = numpy.array([])
1291
1292 #open file beacon phase
1293 path = '%s%03d' %(self.PREFIX, self.id)
1294 beacon_file = os.path.join(path,'%s.txt'%self.name)
1295 self.filename_phase = os.path.join(figpath,beacon_file)
1296 #self.save_phase(self.filename_phase)
1297
1298
1299 #store data beacon phase
1300 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1301
1302 self.setWinTitle(title)
1303
1304
1305 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1306
1307 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1308
1309 axes = self.axesList[0]
1310
1311 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1312
1313 if len(self.ydata)==0:
1314 self.ydata = phase_beacon.reshape(-1,1)
1315 else:
1316 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1317
1318
1319 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1320 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1321 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1322 XAxisAsTime=True, grid='both'
1323 )
1324
1325 self.draw()
1326
1327 if x[1] >= self.axesList[0].xmax:
1328 self.counter_imagwr = wr_period
1150 1329 del self.xdata
1151 1330 del self.ydata
1331 self.__isConfig = False
1332
1333 if self.figfile == None:
1334 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1335 self.figfile = self.getFilename(name = str_datetime)
1336
1337 if figpath != '':
1338 self.counter_imagwr += 1
1339 if (self.counter_imagwr>=wr_period):
1340 # store png plot to local folder
1341 self.saveFigure(figpath, self.figfile)
1342 # store png plot to FTP server according to RT-Web format
1343 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1344 ftp_filename = os.path.join(figpath, name)
1345 self.saveFigure(figpath, ftp_filename)
1346 self.counter_imagwr = 0
General Comments 0
You need to be logged in to leave comments. Login now