##// END OF EJS Templates
Signal Chain GUI: pause added to every plot routine
Miguel Valdez -
r617:6684feaba495
parent child
Show More
@@ -1,94 +1,94
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Form implementation generated from reading ui file '/home/roj-idl71/SignalChain/initwindowv2.ui'
4 4 #
5 5 # Created: Wed Mar 6 15:32:39 2013
6 6 # by: PyQt4 UI code generator 4.8.6
7 7 #
8 8 # WARNING! All changes made in this file will be lost!
9 9
10 10 from PyQt4 import QtCore, QtGui
11 11
12 12 try:
13 13 _fromUtf8 = QtCore.QString.fromUtf8
14 14 except AttributeError:
15 15 _fromUtf8 = lambda s: s
16 16
17 17 import os
18 18 from schainpy.gui.figures import tools
19 19
20 INITIAL_MSG = "Signal Chain GUI - v2.1.2"
20 INITIAL_MSG = "Signal Chain GUI - v2.1.3"
21 21 FIGURES_PATH = tools.get_path()
22 22
23 23 class Ui_InitWindow(object):
24 24 def setupUi(self, Dialog):
25 25 Dialog.setObjectName(_fromUtf8("Dialog"))
26 26 Dialog.resize(652, 496)
27 27 Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
28 28 self.gridLayout = QtGui.QGridLayout(Dialog)
29 29 self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
30 30 self.verticalLayout_3 = QtGui.QVBoxLayout()
31 31 self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
32 32 self.verticalLayout_4 = QtGui.QVBoxLayout()
33 33 self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
34 34 self.label_3 = QtGui.QLabel(Dialog)
35 35 font = QtGui.QFont()
36 36 font.setFamily(_fromUtf8("Cambria"))
37 37 font.setPointSize(22)
38 38 font.setBold(False)
39 39 font.setWeight(50)
40 40 self.label_3.setFont(font)
41 41 self.label_3.setText(QtGui.QApplication.translate("Dialog", INITIAL_MSG, None, QtGui.QApplication.UnicodeUTF8))
42 42 self.label_3.setObjectName(_fromUtf8("label_3"))
43 43 self.verticalLayout_4.addWidget(self.label_3)
44 44 self.line_2 = QtGui.QFrame(Dialog)
45 45 self.line_2.setFrameShape(QtGui.QFrame.HLine)
46 46 self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
47 47 self.line_2.setObjectName(_fromUtf8("line_2"))
48 48 self.verticalLayout_4.addWidget(self.line_2)
49 49 self.label_4 = QtGui.QLabel(Dialog)
50 50 self.label_4.setText(_fromUtf8(""))
51 51 self.label_4.setPixmap(QtGui.QPixmap(_fromUtf8( os.path.join(FIGURES_PATH,"w.jpg") )))
52 52 self.label_4.setScaledContents(True)
53 53 self.label_4.setObjectName(_fromUtf8("label_4"))
54 54 self.verticalLayout_4.addWidget(self.label_4)
55 55 self.verticalLayout_3.addLayout(self.verticalLayout_4)
56 56 self.horizontalLayout_3 = QtGui.QHBoxLayout()
57 57 self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
58 58 self.horizontalLayout_4 = QtGui.QHBoxLayout()
59 59 self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
60 60 spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
61 61 self.horizontalLayout_4.addItem(spacerItem)
62 62 self.ExitBtn = QtGui.QPushButton(Dialog)
63 63 self.ExitBtn.setText(QtGui.QApplication.translate("Dialog", "Exit", None, QtGui.QApplication.UnicodeUTF8))
64 64 self.ExitBtn.setObjectName(_fromUtf8("ExitBtn"))
65 65 self.horizontalLayout_4.addWidget(self.ExitBtn)
66 66 self.ContinueBtn = QtGui.QPushButton(Dialog)
67 67 self.ContinueBtn.setText(QtGui.QApplication.translate("Dialog", "Continue", None, QtGui.QApplication.UnicodeUTF8))
68 68 self.ContinueBtn.setObjectName(_fromUtf8("ContinueBtn"))
69 69 self.horizontalLayout_4.addWidget(self.ContinueBtn)
70 70 spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
71 71 self.horizontalLayout_4.addItem(spacerItem1)
72 72 self.horizontalLayout_3.addLayout(self.horizontalLayout_4)
73 73 self.verticalLayout_3.addLayout(self.horizontalLayout_3)
74 74 self.gridLayout.addLayout(self.verticalLayout_3, 0, 0, 1, 1)
75 75
76 76 self.retranslateUi(Dialog)
77 77 QtCore.QMetaObject.connectSlotsByName(Dialog)
78 78
79 79 def retranslateUi(self, Dialog):
80 80 pass
81 81
82 82
83 83 if __name__ == "__main__":
84 84 import sys
85 85 app = QtGui.QApplication(sys.argv)
86 86 Dialog = QtGui.QDialog()
87 87 ui = Ui_InitWindow()
88 88 ui.setupUi(Dialog)
89 89 Dialog.show()
90 90 sys.exit(app.exec_())
91 91
92 92
93 93
94 94
@@ -1,610 +1,622
1 1 import os
2 2 import numpy
3 3 import time, datetime
4 4 import mpldriver
5 5
6 6 from schainpy.model.proc.jroproc_base import Operation
7 7
8 8 def isRealtime(utcdatatime):
9 9 utcnow = time.mktime(time.localtime())
10 10 delta = abs(utcnow - utcdatatime) # abs
11 11 if delta >= 30.:
12 12 return False
13 13 return True
14 14
15 15 class Figure(Operation):
16 16
17 17 __driver = mpldriver
18 18 __isConfigThread = False
19 19 fig = None
20 20
21 21 id = None
22 22 wintitle = None
23 23 width = None
24 24 height = None
25 25 nplots = None
26 26 timerange = None
27 27
28 28 axesObjList = []
29 29
30 30 WIDTH = None
31 31 HEIGHT = None
32 32 PREFIX = 'fig'
33 33
34 34 xmin = None
35 35 xmax = None
36 36
37 37 counter_imagwr = 0
38 38
39 39 figfile = None
40 40
41 41 def __init__(self):
42 42
43 43 raise ValueError, "This method is not implemented"
44 44
45 45 def __del__(self):
46 46
47 47 self.__driver.closeFigure()
48 48
49 49 def getFilename(self, name, ext='.png'):
50 50
51 51 path = '%s%03d' %(self.PREFIX, self.id)
52 52 filename = '%s_%s%s' %(self.PREFIX, name, ext)
53 53 return os.path.join(path, filename)
54 54
55 55 def getAxesObjList(self):
56 56
57 57 return self.axesObjList
58 58
59 59 def getSubplots(self):
60 60
61 61 raise ValueError, "Abstract method: This method should be defined"
62 62
63 63 def getScreenDim(self, widthplot, heightplot):
64 64
65 65 nrow, ncol = self.getSubplots()
66 66
67 67 widthscreen = widthplot*ncol
68 68 heightscreen = heightplot*nrow
69 69
70 70 return widthscreen, heightscreen
71 71
72 72 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
73 73
74 74 if self.xmin != None and self.xmax != None:
75 75 if timerange == None:
76 76 timerange = self.xmax - self.xmin
77 77 xmin = self.xmin + timerange
78 78 xmax = self.xmax + timerange
79 79
80 80 return xmin, xmax
81 81
82 82 if timerange == None and (xmin==None or xmax==None):
83 83 timerange = 14400 #seconds
84 84 #raise ValueError, "(timerange) or (xmin & xmax) should be defined"
85 85
86 86 if timerange != None:
87 87 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
88 88 else:
89 89 txmin = x[0] #- x[0] % 10*60
90 90
91 91 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
92 92 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
93 93
94 94 if timerange != None:
95 95 xmin = (thisdatetime - thisdate).seconds/(60*60.)
96 96 xmax = xmin + timerange/(60*60.)
97 97
98 98 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
99 99 xmin_sec = time.mktime(mindt.timetuple())
100 100
101 101 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
102 102 xmax_sec = time.mktime(maxdt.timetuple())
103 103
104 104 return xmin_sec, xmax_sec
105 105
106 106 def init(self, id, nplots, wintitle):
107 107
108 108 raise ValueError, "This method has been replaced with createFigure"
109 109
110 110 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
111 111
112 112 """
113 113 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
114 114 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
115 115 y self.HEIGHT y el numero de subplots (nrow, ncol)
116 116
117 117 Input:
118 118 id : Los parametros necesarios son
119 119 wintitle :
120 120
121 121 """
122 122
123 123 if widthplot == None:
124 124 widthplot = self.WIDTH
125 125
126 126 if heightplot == None:
127 127 heightplot = self.HEIGHT
128 128
129 129 self.id = id
130 130
131 131 self.wintitle = wintitle
132 132
133 133 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
134 134
135 135 self.fig = self.__driver.createFigure(id=self.id,
136 136 wintitle=self.wintitle,
137 137 width=self.widthscreen,
138 138 height=self.heightscreen,
139 139 show=show)
140 140
141 141 self.axesObjList = []
142 142 self.counter_imagwr = 0
143 143
144 144
145 145 def setDriver(self, driver=mpldriver):
146 146
147 147 self.__driver = driver
148 148
149 149 def setTitle(self, title):
150 150
151 151 self.__driver.setTitle(self.fig, title)
152 152
153 153 def setWinTitle(self, title):
154 154
155 155 self.__driver.setWinTitle(self.fig, title=title)
156 156
157 157 def setTextFromAxes(self, text):
158 158
159 159 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
160 160
161 161 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
162 162
163 163 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
164 164
165 165 def addAxes(self, *args):
166 166 """
167 167
168 168 Input:
169 169 *args : Los parametros necesarios son
170 170 nrow, ncol, xpos, ypos, colspan, rowspan
171 171 """
172 172
173 173 axesObj = Axes(self.fig, *args)
174 174 self.axesObjList.append(axesObj)
175 175
176 176 def saveFigure(self, figpath, figfile, *args):
177 177
178 178 filename = os.path.join(figpath, figfile)
179 179
180 180 fullpath = os.path.split(filename)[0]
181 181
182 182 if not os.path.exists(fullpath):
183 183 subpath = os.path.split(fullpath)[0]
184 184
185 185 if not os.path.exists(subpath):
186 186 os.mkdir(subpath)
187 187
188 188 os.mkdir(fullpath)
189 189
190 190 self.__driver.saveFigure(self.fig, filename, *args)
191 191
192 192 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
193 193
194 194 self.counter_imagwr += 1
195 195 if self.counter_imagwr < wr_period:
196 196 return
197 197
198 198 self.counter_imagwr = 0
199 199
200 200 if save:
201 201
202 202 if not figfile:
203 203
204 204 if not thisDatetime:
205 205 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
206 206 return
207 207
208 208 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
209 209 figfile = self.getFilename(name = str_datetime)
210 210
211 211 if self.figfile == None:
212 212 self.figfile = figfile
213 213
214 214 if update_figfile:
215 215 self.figfile = figfile
216 216
217 217 # store png plot to local folder
218 218 self.saveFigure(figpath, self.figfile)
219 219
220 220
221 221 if not ftp:
222 222 return
223 223
224 224 if not thisDatetime:
225 225 return
226 226
227 227 # store png plot to FTP server according to RT-Web format
228 228 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
229 229 # ftp_filename = os.path.join(figpath, name)
230 230 self.saveFigure(figpath, ftp_filename)
231 231
232 232 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
233 233 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
234 234 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
235 235 FTP_WEI = '%2.2d'%FTP_WEI
236 236 EXP_CODE = '%3.3d'%EXP_CODE
237 237 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
238 238 PLOT_CODE = '%2.2d'%PLOT_CODE
239 239 PLOT_POS = '%2.2d'%PLOT_POS
240 240 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
241 241 return name
242 242
243 243 def draw(self):
244 244
245 245 self.__driver.draw(self.fig)
246 246
247 247 def run(self):
248 248
249 249 raise ValueError, "This method is not implemented"
250 250
251 251 def close(self, show=False):
252 252
253 253 self.__driver.closeFigure(show=show, fig=self.fig)
254 254
255 255 axesList = property(getAxesObjList)
256 256
257 257
258 258 class Axes:
259 259
260 260 __driver = mpldriver
261 261 fig = None
262 262 ax = None
263 263 plot = None
264 264 __missing = 1E30
265 265 __firsttime = None
266 266
267 267 __showprofile = False
268 268
269 269 xmin = None
270 270 xmax = None
271 271 ymin = None
272 272 ymax = None
273 273 zmin = None
274 274 zmax = None
275 275
276 276 x_buffer = None
277 277 z_buffer = None
278 278
279 279 decimationx = None
280 280 decimationy = None
281 281
282 282 __MAXNUMX = 300
283 283 __MAXNUMY = 150
284 284
285 285 def __init__(self, *args):
286 286
287 287 """
288 288
289 289 Input:
290 290 *args : Los parametros necesarios son
291 291 fig, nrow, ncol, xpos, ypos, colspan, rowspan
292 292 """
293 293
294 294 ax = self.__driver.createAxes(*args)
295 295 self.fig = args[0]
296 296 self.ax = ax
297 297 self.plot = None
298 298
299 299 self.__firsttime = True
300 300 self.idlineList = []
301 301
302 302 self.x_buffer = numpy.array([])
303 303 self.z_buffer = numpy.array([])
304 304
305 305 def setText(self, text):
306 306
307 307 self.__driver.setAxesText(self.ax, text)
308 308
309 309 def setXAxisAsTime(self):
310 310 pass
311 311
312 312 def pline(self, x, y,
313 313 xmin=None, xmax=None,
314 314 ymin=None, ymax=None,
315 315 xlabel='', ylabel='',
316 316 title='',
317 317 **kwargs):
318 318
319 319 """
320 320
321 321 Input:
322 322 x :
323 323 y :
324 324 xmin :
325 325 xmax :
326 326 ymin :
327 327 ymax :
328 328 xlabel :
329 329 ylabel :
330 330 title :
331 331 **kwargs : Los parametros aceptados son
332 332
333 333 ticksize
334 334 ytick_visible
335 335 """
336 336
337 337 if self.__firsttime:
338 338
339 339 if xmin == None: xmin = numpy.nanmin(x)
340 340 if xmax == None: xmax = numpy.nanmax(x)
341 341 if ymin == None: ymin = numpy.nanmin(y)
342 342 if ymax == None: ymax = numpy.nanmax(y)
343 343
344 344 self.plot = self.__driver.createPline(self.ax, x, y,
345 345 xmin, xmax,
346 346 ymin, ymax,
347 347 xlabel=xlabel,
348 348 ylabel=ylabel,
349 349 title=title,
350 350 **kwargs)
351 351
352 352 self.idlineList.append(0)
353 353 self.__firsttime = False
354 354 return
355 355
356 356 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
357 357 ylabel=ylabel,
358 358 title=title)
359 359
360 self.__driver.pause()
361
360 362 def addpline(self, x, y, idline, **kwargs):
361 363 lines = self.ax.lines
362 364
363 365 if idline in self.idlineList:
364 366 self.__driver.set_linedata(self.ax, x, y, idline)
365 367
366 368 if idline not in(self.idlineList):
367 369 self.__driver.addpline(self.ax, x, y, **kwargs)
368 370 self.idlineList.append(idline)
369 371
370 372 return
371 373
372 374 def pmultiline(self, x, y,
373 375 xmin=None, xmax=None,
374 376 ymin=None, ymax=None,
375 377 xlabel='', ylabel='',
376 378 title='',
377 379 **kwargs):
378 380
379 381 if self.__firsttime:
380 382
381 383 if xmin == None: xmin = numpy.nanmin(x)
382 384 if xmax == None: xmax = numpy.nanmax(x)
383 385 if ymin == None: ymin = numpy.nanmin(y)
384 386 if ymax == None: ymax = numpy.nanmax(y)
385 387
386 388 self.plot = self.__driver.createPmultiline(self.ax, x, y,
387 389 xmin, xmax,
388 390 ymin, ymax,
389 391 xlabel=xlabel,
390 392 ylabel=ylabel,
391 393 title=title,
392 394 **kwargs)
393 395 self.__firsttime = False
394 396 return
395 397
396 398 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
397 399 ylabel=ylabel,
398 400 title=title)
399
401
402 self.__driver.pause()
403
400 404 def pmultilineyaxis(self, x, y,
401 405 xmin=None, xmax=None,
402 406 ymin=None, ymax=None,
403 407 xlabel='', ylabel='',
404 408 title='',
405 409 **kwargs):
406 410
407 411 if self.__firsttime:
408 412
409 413 if xmin == None: xmin = numpy.nanmin(x)
410 414 if xmax == None: xmax = numpy.nanmax(x)
411 415 if ymin == None: ymin = numpy.nanmin(y)
412 416 if ymax == None: ymax = numpy.nanmax(y)
413 417
414 418 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
415 419 xmin, xmax,
416 420 ymin, ymax,
417 421 xlabel=xlabel,
418 422 ylabel=ylabel,
419 423 title=title,
420 424 **kwargs)
421 425 if self.xmin == None: self.xmin = xmin
422 426 if self.xmax == None: self.xmax = xmax
423 427 if self.ymin == None: self.ymin = ymin
424 428 if self.ymax == None: self.ymax = ymax
425 429
426 430 self.__firsttime = False
427 431 return
428 432
429 433 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
430 434 ylabel=ylabel,
431 435 title=title)
432
436
437 self.__driver.pause()
438
433 439 def pcolor(self, x, y, z,
434 440 xmin=None, xmax=None,
435 441 ymin=None, ymax=None,
436 442 zmin=None, zmax=None,
437 443 xlabel='', ylabel='',
438 444 title='', rti = False, colormap='jet',
439 445 **kwargs):
440 446
441 447 """
442 448 Input:
443 449 x :
444 450 y :
445 451 x :
446 452 xmin :
447 453 xmax :
448 454 ymin :
449 455 ymax :
450 456 zmin :
451 457 zmax :
452 458 xlabel :
453 459 ylabel :
454 460 title :
455 461 **kwargs : Los parametros aceptados son
456 462 ticksize=9,
457 463 cblabel=''
458 464 rti = True or False
459 465 """
460 466
461 467 if self.__firsttime:
462 468
463 469 if xmin == None: xmin = numpy.nanmin(x)
464 470 if xmax == None: xmax = numpy.nanmax(x)
465 471 if ymin == None: ymin = numpy.nanmin(y)
466 472 if ymax == None: ymax = numpy.nanmax(y)
467 473 if zmin == None: zmin = numpy.nanmin(z)
468 474 if zmax == None: zmax = numpy.nanmax(z)
469 475
470 476
471 477 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
472 478 xmin, xmax,
473 479 ymin, ymax,
474 480 zmin, zmax,
475 481 xlabel=xlabel,
476 482 ylabel=ylabel,
477 483 title=title,
478 484 colormap=colormap,
479 485 **kwargs)
480 486
481 487 if self.xmin == None: self.xmin = xmin
482 488 if self.xmax == None: self.xmax = xmax
483 489 if self.ymin == None: self.ymin = ymin
484 490 if self.ymax == None: self.ymax = ymax
485 491 if self.zmin == None: self.zmin = zmin
486 492 if self.zmax == None: self.zmax = zmax
487 493
488 494 self.__firsttime = False
489 495 return
490 496
491 497 if rti:
492 498 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
493 499 xlabel=xlabel,
494 500 ylabel=ylabel,
495 501 title=title,
496 502 colormap=colormap)
497 503 return
498 504
499 505 self.__driver.pcolor(self.plot, z,
500 506 xlabel=xlabel,
501 507 ylabel=ylabel,
502 508 title=title)
503 509
510 self.__driver.pause()
511
504 512 def pcolorbuffer(self, x, y, z,
505 513 xmin=None, xmax=None,
506 514 ymin=None, ymax=None,
507 515 zmin=None, zmax=None,
508 516 xlabel='', ylabel='',
509 517 title='', rti = True, colormap='jet',
510 518 maxNumX = None, maxNumY = None,
511 519 **kwargs):
512 520
513 521 if maxNumX == None:
514 522 maxNumX = self.__MAXNUMX
515 523
516 524 if maxNumY == None:
517 525 maxNumY = self.__MAXNUMY
518 526
519 527 if self.__firsttime:
520 528 self.z_buffer = z
521 529 self.x_buffer = numpy.hstack((self.x_buffer, x))
522 530
523 531 if xmin == None: xmin = numpy.nanmin(x)
524 532 if xmax == None: xmax = numpy.nanmax(x)
525 533 if ymin == None: ymin = numpy.nanmin(y)
526 534 if ymax == None: ymax = numpy.nanmax(y)
527 535 if zmin == None: zmin = numpy.nanmin(z)
528 536 if zmax == None: zmax = numpy.nanmax(z)
529 537
530 538
531 539 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
532 540 xmin, xmax,
533 541 ymin, ymax,
534 542 zmin, zmax,
535 543 xlabel=xlabel,
536 544 ylabel=ylabel,
537 545 title=title,
538 546 colormap=colormap,
539 547 **kwargs)
540 548
541 549 if self.xmin == None: self.xmin = xmin
542 550 if self.xmax == None: self.xmax = xmax
543 551 if self.ymin == None: self.ymin = ymin
544 552 if self.ymax == None: self.ymax = ymax
545 553 if self.zmin == None: self.zmin = zmin
546 554 if self.zmax == None: self.zmax = zmax
547 555
548 556 self.__firsttime = False
549 557 return
550 558
551 559 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
552 560 self.z_buffer = numpy.hstack((self.z_buffer, z))
553 561
554 562 if self.decimationx == None:
555 563 deltax = float(self.xmax - self.xmin)/maxNumX
556 564 deltay = float(self.ymax - self.ymin)/maxNumY
557 565
558 566 resolutionx = self.x_buffer[2]-self.x_buffer[0]
559 567 resolutiony = y[1]-y[0]
560 568
561 569 self.decimationx = numpy.ceil(deltax / resolutionx)
562 570 self.decimationy = numpy.ceil(deltay / resolutiony)
563 571
564 572 z_buffer = self.z_buffer.reshape(-1,len(y))
565 573
566 574 x_buffer = self.x_buffer[::self.decimationx]
567 575 y_buffer = y[::self.decimationy]
568 576 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
569 577 #===================================================
570 578
571 579 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
572 580
573 581 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
574 582 xlabel=xlabel,
575 583 ylabel=ylabel,
576 584 title=title,
577 585 colormap=colormap)
578
586
587 self.__driver.pause()
588
579 589 def polar(self, x, y,
580 590 title='', xlabel='',ylabel='',**kwargs):
581 591
582 592 if self.__firsttime:
583 593 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
584 594 self.__firsttime = False
585 595 self.x_buffer = x
586 596 self.y_buffer = y
587 597 return
588 598
589 599 self.x_buffer = numpy.hstack((self.x_buffer,x))
590 600 self.y_buffer = numpy.hstack((self.y_buffer,y))
591 601 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
592 602 ylabel=ylabel,
593 603 title=title)
594 604
605 self.__driver.pause()
606
595 607 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
596 608
597 609 deltas = x_buffer[1:] - x_buffer[0:-1]
598 610 x_median = numpy.median(deltas)
599 611
600 612 index = numpy.where(deltas >= 2*x_median)
601 613
602 614 if len(index[0]) != 0:
603 615 z_buffer[index[0],::] = self.__missing
604 616 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
605 617
606 618 return x_buffer, y_buffer, z_buffer
607 619
608 620
609 621
610 622 No newline at end of file
@@ -1,437 +1,442
1 1 import numpy
2 2 import datetime
3 3 import sys
4 4 import matplotlib
5 5
6 6 if 'linux' in sys.platform:
7 7 matplotlib.use("TKAgg")
8 8
9 9 if 'darwin' in sys.platform:
10 10 matplotlib.use("WXAgg")
11 11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 12 import matplotlib.pyplot
13 13
14 14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 15 from matplotlib.ticker import *
16 16
17 17 ###########################################
18 18 #Actualizacion de las funciones del driver
19 19 ###########################################
20 20
21 21 def createFigure(id, wintitle, width, height, facecolor="w", show=True):
22 22
23 23 matplotlib.pyplot.ioff()
24 24 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor)
25 25 fig.canvas.manager.set_window_title(wintitle)
26 26 fig.canvas.manager.resize(width, height)
27 27 matplotlib.pyplot.ion()
28 28 if show:
29 29 matplotlib.pyplot.show()
30 30
31 31 return fig
32 32
33 33 def closeFigure(show=False, fig=None):
34 34
35 35 matplotlib.pyplot.ioff()
36 36 matplotlib.pyplot.pause(0.1)
37 37
38 38 if show:
39 39 matplotlib.pyplot.show()
40 40
41 41 if fig != None:
42 42 matplotlib.pyplot.close(fig)
43 43 matplotlib.pyplot.pause(0.1)
44 44 matplotlib.pyplot.ion()
45 45 return
46 46
47 47 matplotlib.pyplot.close("all")
48 48 matplotlib.pyplot.pause(0.1)
49 49 matplotlib.pyplot.ion()
50 50 return
51 51
52 52 def saveFigure(fig, filename):
53 53
54 54 matplotlib.pyplot.ioff()
55 55 fig.savefig(filename)
56 56 matplotlib.pyplot.ion()
57 57
58 58 def setWinTitle(fig, title):
59 59
60 60 fig.canvas.manager.set_window_title(title)
61 61
62 62 def setTitle(fig, title):
63 63
64 64 fig.suptitle(title)
65 65
66 66 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
67 67
68 68 matplotlib.pyplot.ioff()
69 69 matplotlib.pyplot.figure(fig.number)
70 70 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
71 71 (xpos, ypos),
72 72 colspan=colspan,
73 73 rowspan=rowspan,
74 74 polar=polar)
75 75
76 76 matplotlib.pyplot.ion()
77 77 return axes
78 78
79 79 def setAxesText(ax, text):
80 80
81 81 ax.annotate(text,
82 82 xy = (.1, .99),
83 83 xycoords = 'figure fraction',
84 84 horizontalalignment = 'left',
85 85 verticalalignment = 'top',
86 86 fontsize = 10)
87 87
88 88 def printLabels(ax, xlabel, ylabel, title):
89 89
90 90 ax.set_xlabel(xlabel, size=11)
91 91 ax.set_ylabel(ylabel, size=11)
92 92 ax.set_title(title, size=8)
93 93
94 94 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
95 95 ticksize=9, xtick_visible=True, ytick_visible=True,
96 96 nxticks=4, nyticks=10,
97 97 grid=None,color='blue'):
98 98
99 99 """
100 100
101 101 Input:
102 102 grid : None, 'both', 'x', 'y'
103 103 """
104 104
105 105 matplotlib.pyplot.ioff()
106 106
107 107 ax.set_xlim([xmin,xmax])
108 108 ax.set_ylim([ymin,ymax])
109 109
110 110 printLabels(ax, xlabel, ylabel, title)
111 111
112 112 ######################################################
113 113 if (xmax-xmin)<=1:
114 114 xtickspos = numpy.linspace(xmin,xmax,nxticks)
115 115 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
116 116 ax.set_xticks(xtickspos)
117 117 else:
118 118 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
119 119 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
120 120 ax.set_xticks(xtickspos)
121 121
122 122 for tick in ax.get_xticklabels():
123 123 tick.set_visible(xtick_visible)
124 124
125 125 for tick in ax.xaxis.get_major_ticks():
126 126 tick.label.set_fontsize(ticksize)
127 127
128 128 ######################################################
129 129 for tick in ax.get_yticklabels():
130 130 tick.set_visible(ytick_visible)
131 131
132 132 for tick in ax.yaxis.get_major_ticks():
133 133 tick.label.set_fontsize(ticksize)
134 134
135 135 ax.plot(x, y, color=color)
136 136 iplot = ax.lines[-1]
137 137
138 138 ######################################################
139 139 if '0.' in matplotlib.__version__[0:2]:
140 140 print "The matplotlib version has to be updated to 1.1 or newer"
141 141 return iplot
142 142
143 143 if '1.0.' in matplotlib.__version__[0:4]:
144 144 print "The matplotlib version has to be updated to 1.1 or newer"
145 145 return iplot
146 146
147 147 if grid != None:
148 148 ax.grid(b=True, which='major', axis=grid)
149 149
150 150 matplotlib.pyplot.tight_layout()
151 151
152 152 matplotlib.pyplot.ion()
153 153
154 154 return iplot
155 155
156 156 def set_linedata(ax, x, y, idline):
157 157
158 158 ax.lines[idline].set_data(x,y)
159 159
160 160 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
161 161
162 162 ax = iplot.get_axes()
163 163
164 164 printLabels(ax, xlabel, ylabel, title)
165 165
166 166 set_linedata(ax, x, y, idline=0)
167 167
168 168 def addpline(ax, x, y, color, linestyle, lw):
169 169
170 170 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
171 171
172 172
173 173 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
174 174 xlabel='', ylabel='', title='', ticksize = 9,
175 175 colormap='jet',cblabel='', cbsize="5%",
176 176 XAxisAsTime=False):
177 177
178 178 matplotlib.pyplot.ioff()
179 179
180 180 divider = make_axes_locatable(ax)
181 181 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
182 182 fig = ax.get_figure()
183 183 fig.add_axes(ax_cb)
184 184
185 185 ax.set_xlim([xmin,xmax])
186 186 ax.set_ylim([ymin,ymax])
187 187
188 188 printLabels(ax, xlabel, ylabel, title)
189 189
190 190 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
191 191 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
192 192 cb.set_label(cblabel)
193 193
194 194 # for tl in ax_cb.get_yticklabels():
195 195 # tl.set_visible(True)
196 196
197 197 for tick in ax.yaxis.get_major_ticks():
198 198 tick.label.set_fontsize(ticksize)
199 199
200 200 for tick in ax.xaxis.get_major_ticks():
201 201 tick.label.set_fontsize(ticksize)
202 202
203 203 for tick in cb.ax.get_yticklabels():
204 204 tick.set_fontsize(ticksize)
205 205
206 206 ax_cb.yaxis.tick_right()
207 207
208 208 if '0.' in matplotlib.__version__[0:2]:
209 209 print "The matplotlib version has to be updated to 1.1 or newer"
210 210 return imesh
211 211
212 212 if '1.0.' in matplotlib.__version__[0:4]:
213 213 print "The matplotlib version has to be updated to 1.1 or newer"
214 214 return imesh
215 215
216 216 matplotlib.pyplot.tight_layout()
217 217
218 218 if XAxisAsTime:
219 219
220 220 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
221 221 ax.xaxis.set_major_formatter(FuncFormatter(func))
222 222 ax.xaxis.set_major_locator(LinearLocator(7))
223 223
224 224 matplotlib.pyplot.ion()
225 225 return imesh
226 226
227 227 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
228 228
229 229 z = z.T
230 230 ax = imesh.get_axes()
231 231 printLabels(ax, xlabel, ylabel, title)
232 232 imesh.set_array(z.ravel())
233 233
234 234 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
235 235
236 236 printLabels(ax, xlabel, ylabel, title)
237 237
238 238 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
239 239
240 240 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
241 241
242 242 printLabels(ax, xlabel, ylabel, title)
243 243
244 244 ax.collections.remove(ax.collections[0])
245 245
246 246 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
247 247
248 248 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
249 249 ticksize=9, xtick_visible=True, ytick_visible=True,
250 250 nxticks=4, nyticks=10,
251 251 grid=None):
252 252
253 253 """
254 254
255 255 Input:
256 256 grid : None, 'both', 'x', 'y'
257 257 """
258 258
259 259 matplotlib.pyplot.ioff()
260 260
261 261 lines = ax.plot(x.T, y)
262 262 leg = ax.legend(lines, legendlabels, loc='upper right')
263 263 leg.get_frame().set_alpha(0.5)
264 264 ax.set_xlim([xmin,xmax])
265 265 ax.set_ylim([ymin,ymax])
266 266 printLabels(ax, xlabel, ylabel, title)
267 267
268 268 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
269 269 ax.set_xticks(xtickspos)
270 270
271 271 for tick in ax.get_xticklabels():
272 272 tick.set_visible(xtick_visible)
273 273
274 274 for tick in ax.xaxis.get_major_ticks():
275 275 tick.label.set_fontsize(ticksize)
276 276
277 277 for tick in ax.get_yticklabels():
278 278 tick.set_visible(ytick_visible)
279 279
280 280 for tick in ax.yaxis.get_major_ticks():
281 281 tick.label.set_fontsize(ticksize)
282 282
283 283 iplot = ax.lines[-1]
284 284
285 285 if '0.' in matplotlib.__version__[0:2]:
286 286 print "The matplotlib version has to be updated to 1.1 or newer"
287 287 return iplot
288 288
289 289 if '1.0.' in matplotlib.__version__[0:4]:
290 290 print "The matplotlib version has to be updated to 1.1 or newer"
291 291 return iplot
292 292
293 293 if grid != None:
294 294 ax.grid(b=True, which='major', axis=grid)
295 295
296 296 matplotlib.pyplot.tight_layout()
297 297
298 298 matplotlib.pyplot.ion()
299 299
300 300 return iplot
301 301
302 302
303 303 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
304 304
305 305 ax = iplot.get_axes()
306 306
307 307 printLabels(ax, xlabel, ylabel, title)
308 308
309 309 for i in range(len(ax.lines)):
310 310 line = ax.lines[i]
311 311 line.set_data(x[i,:],y)
312 312
313 313 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
314 314 ticksize=9, xtick_visible=True, ytick_visible=True,
315 315 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
316 316 grid=None, XAxisAsTime=False):
317 317
318 318 """
319 319
320 320 Input:
321 321 grid : None, 'both', 'x', 'y'
322 322 """
323 323
324 324 matplotlib.pyplot.ioff()
325 325
326 326 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
327 327 lines = ax.plot(x, y.T, linestyle=linestyle, marker=marker, markersize=markersize)
328 328 leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
329 329 handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
330 330
331 331 for label in leg.get_texts(): label.set_fontsize(9)
332 332
333 333 ax.set_xlim([xmin,xmax])
334 334 ax.set_ylim([ymin,ymax])
335 335 printLabels(ax, xlabel, ylabel, title)
336 336
337 337 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
338 338 # ax.set_xticks(xtickspos)
339 339
340 340 for tick in ax.get_xticklabels():
341 341 tick.set_visible(xtick_visible)
342 342
343 343 for tick in ax.xaxis.get_major_ticks():
344 344 tick.label.set_fontsize(ticksize)
345 345
346 346 for tick in ax.get_yticklabels():
347 347 tick.set_visible(ytick_visible)
348 348
349 349 for tick in ax.yaxis.get_major_ticks():
350 350 tick.label.set_fontsize(ticksize)
351 351
352 352 iplot = ax.lines[-1]
353 353
354 354 if '0.' in matplotlib.__version__[0:2]:
355 355 print "The matplotlib version has to be updated to 1.1 or newer"
356 356 return iplot
357 357
358 358 if '1.0.' in matplotlib.__version__[0:4]:
359 359 print "The matplotlib version has to be updated to 1.1 or newer"
360 360 return iplot
361 361
362 362 if grid != None:
363 363 ax.grid(b=True, which='major', axis=grid)
364 364
365 365 matplotlib.pyplot.tight_layout()
366 366
367 367 if XAxisAsTime:
368 368
369 369 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
370 370 ax.xaxis.set_major_formatter(FuncFormatter(func))
371 371 ax.xaxis.set_major_locator(LinearLocator(7))
372 372
373 373 matplotlib.pyplot.ion()
374 374
375 375 return iplot
376 376
377 377 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
378 378
379 379 ax = iplot.get_axes()
380 380
381 381 printLabels(ax, xlabel, ylabel, title)
382 382
383 383 for i in range(len(ax.lines)):
384 384 line = ax.lines[i]
385 385 line.set_data(x,y[i,:])
386 386
387 387 def createPolar(ax, x, y,
388 388 xlabel='', ylabel='', title='', ticksize = 9,
389 389 colormap='jet',cblabel='', cbsize="5%",
390 390 XAxisAsTime=False):
391 391
392 392 matplotlib.pyplot.ioff()
393 393
394 394 ax.plot(x,y,'bo', markersize=5)
395 395 # ax.set_rmax(90)
396 396 ax.set_ylim(0,90)
397 397 ax.set_yticks(numpy.arange(0,90,20))
398 398 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
399 399 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
400 400 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
401 401 ax.yaxis.labelpad = 230
402 402 printLabels(ax, xlabel, ylabel, title)
403 403 iplot = ax.lines[-1]
404 404
405 405 if '0.' in matplotlib.__version__[0:2]:
406 406 print "The matplotlib version has to be updated to 1.1 or newer"
407 407 return iplot
408 408
409 409 if '1.0.' in matplotlib.__version__[0:4]:
410 410 print "The matplotlib version has to be updated to 1.1 or newer"
411 411 return iplot
412 412
413 413 # if grid != None:
414 414 # ax.grid(b=True, which='major', axis=grid)
415 415
416 416 matplotlib.pyplot.tight_layout()
417 417
418 418 matplotlib.pyplot.ion()
419 419
420 420
421 421 return iplot
422 422
423 423 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
424 424
425 425 ax = iplot.get_axes()
426 426
427 427 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
428 428 printLabels(ax, xlabel, ylabel, title)
429 429
430 430 set_linedata(ax, x, y, idline=0)
431 431
432 432 def draw(fig):
433 433
434 434 if type(fig) == 'int':
435 435 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
436 436
437 437 fig.canvas.draw()
438
439 def pause(interval=0.000001):
440
441 matplotlib.pyplot.pause(interval)
442 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now