##// END OF EJS Templates
Se corrige bug en el rango de tiempo para la figura.
Daniel Valdez -
r250:f758028f845e
parent child
Show More
@@ -1,408 +1,408
1 1 import os
2 2 import numpy
3 3 import time, datetime
4 4 import mpldriver
5 5
6 6
7 7 class Figure:
8 8
9 9 __driver = mpldriver
10 10 fig = None
11 11
12 12 idfigure = None
13 13 wintitle = None
14 14 width = None
15 15 height = None
16 16 nplots = None
17 17 timerange = None
18 18
19 19 axesObjList = []
20 20
21 21 WIDTH = None
22 22 HEIGHT = None
23 23 PREFIX = 'fig'
24 24
25 25 def __init__(self):
26 26
27 27 raise ValueError, "This method is not implemented"
28 28
29 29 def __del__(self):
30 30
31 31 self.__driver.closeFigure()
32 32
33 33 def getFilename(self, name, ext='.png'):
34 34
35 35 path = '%s%03d' %(self.PREFIX, self.idfigure)
36 36 filename = '%s_%s%s' %(self.PREFIX, name, ext)
37 37
38 38 return os.path.join(path, filename)
39 39
40 40 def getAxesObjList(self):
41 41
42 42 return self.axesObjList
43 43
44 44 def getSubplots(self):
45 45
46 46 raise ValueError, "Abstract method: This method should be defined"
47 47
48 48 def getScreenDim(self, widthplot, heightplot):
49 49
50 50 nrow, ncol = self.getSubplots()
51 51
52 52 widthscreen = widthplot*ncol
53 53 heightscreen = heightplot*nrow
54 54
55 55 return widthscreen, heightscreen
56 56
57 57 def getTimeLim(self, x, xmin, xmax):
58 58
59 59 thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x))
60 60 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
61 61
62 62 ####################################################
63 63 #If the x is out of xrange
64 64 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
65 65 xmin = None
66 66 xmax = None
67 67
68 68 if xmin == None:
69 69 td = thisdatetime - thisdate
70 70 xmin = td.seconds/(60*60.)
71 71
72 72 if xmax == None:
73 73 xmax = xmin + self.timerange/(60*60.)
74 74
75 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) - datetime.timedelta(time.timezone)
75 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
76 76 tmin = time.mktime(mindt.timetuple())
77 77
78 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) - datetime.timedelta(time.timezone)
78 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
79 79 tmax = time.mktime(maxdt.timetuple())
80 80
81 81 self.timerange = tmax - tmin
82 82
83 83 return tmin, tmax
84 84
85 85 def init(self, idfigure, nplots, wintitle):
86 86
87 87 raise ValueError, "This method has been replaced with createFigure"
88 88
89 89 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
90 90
91 91 """
92 92 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
93 93 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
94 94 y self.HEIGHT y el numero de subplots (nrow, ncol)
95 95
96 96 Input:
97 97 idfigure : Los parametros necesarios son
98 98 wintitle :
99 99
100 100 """
101 101
102 102 if widthplot == None:
103 103 widthplot = self.WIDTH
104 104
105 105 if heightplot == None:
106 106 heightplot = self.HEIGHT
107 107
108 108 self.idfigure = idfigure
109 109
110 110 self.wintitle = wintitle
111 111
112 112 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
113 113
114 114 self.fig = self.__driver.createFigure(self.idfigure,
115 115 self.wintitle,
116 116 self.widthscreen,
117 117 self.heightscreen)
118 118
119 119 self.axesObjList = []
120 120
121 121 def setDriver(self, driver=mpldriver):
122 122
123 123 self.__driver = driver
124 124
125 125 def setTitle(self, title):
126 126
127 127 self.__driver.setTitle(self.fig, title)
128 128
129 129 def setWinTitle(self, title):
130 130
131 131 self.__driver.setWinTitle(self.fig, title=title)
132 132
133 133 def setTextFromAxes(self, text):
134 134
135 135 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
136 136
137 137 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
138 138
139 139 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
140 140
141 141 def addAxes(self, *args):
142 142 """
143 143
144 144 Input:
145 145 *args : Los parametros necesarios son
146 146 nrow, ncol, xpos, ypos, colspan, rowspan
147 147 """
148 148
149 149 axesObj = Axes(self.fig, *args)
150 150 self.axesObjList.append(axesObj)
151 151
152 152 def saveFigure(self, figpath, figfile, *args):
153 153
154 154 filename = os.path.join(figpath, figfile)
155 155
156 156 fullpath = os.path.split(filename)[0]
157 157
158 158 if not os.path.exists(fullpath):
159 159 os.mkdir(fullpath)
160 160
161 161 self.__driver.saveFigure(self.fig, filename, *args)
162 162
163 163 def draw(self):
164 164
165 165 self.__driver.draw(self.fig)
166 166
167 167 def run(self):
168 168
169 169 raise ValueError, "This method is not implemented"
170 170
171 171 axesList = property(getAxesObjList)
172 172
173 173
174 174 class Axes:
175 175
176 176 __driver = mpldriver
177 177 fig = None
178 178 ax = None
179 179 plot = None
180 180
181 181 __firsttime = None
182 182
183 183 __showprofile = False
184 184
185 185 xmin = None
186 186 xmax = None
187 187 ymin = None
188 188 ymax = None
189 189 zmin = None
190 190 zmax = None
191 191
192 192 def __init__(self, *args):
193 193
194 194 """
195 195
196 196 Input:
197 197 *args : Los parametros necesarios son
198 198 fig, nrow, ncol, xpos, ypos, colspan, rowspan
199 199 """
200 200
201 201 ax = self.__driver.createAxes(*args)
202 202 self.fig = args[0]
203 203 self.ax = ax
204 204 self.plot = None
205 205
206 206 self.__firsttime = True
207 207 self.idlineList = []
208 208
209 209 def setText(self, text):
210 210
211 211 self.__driver.setAxesText(self.ax, text)
212 212
213 213 def setXAxisAsTime(self):
214 214 pass
215 215
216 216 def pline(self, x, y,
217 217 xmin=None, xmax=None,
218 218 ymin=None, ymax=None,
219 219 xlabel='', ylabel='',
220 220 title='',
221 221 **kwargs):
222 222
223 223 """
224 224
225 225 Input:
226 226 x :
227 227 y :
228 228 xmin :
229 229 xmax :
230 230 ymin :
231 231 ymax :
232 232 xlabel :
233 233 ylabel :
234 234 title :
235 235 **kwargs : Los parametros aceptados son
236 236
237 237 ticksize
238 238 ytick_visible
239 239 """
240 240
241 241 if self.__firsttime:
242 242
243 243 if xmin == None: xmin = numpy.nanmin(x)
244 244 if xmax == None: xmax = numpy.nanmax(x)
245 245 if ymin == None: ymin = numpy.nanmin(y)
246 246 if ymax == None: ymax = numpy.nanmax(y)
247 247
248 248 self.plot = self.__driver.createPline(self.ax, x, y,
249 249 xmin, xmax,
250 250 ymin, ymax,
251 251 xlabel=xlabel,
252 252 ylabel=ylabel,
253 253 title=title,
254 254 **kwargs)
255 255
256 256 self.idlineList.append(0)
257 257 self.__firsttime = False
258 258 return
259 259
260 260 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
261 261 ylabel=ylabel,
262 262 title=title)
263 263
264 264 def addpline(self, x, y, idline, **kwargs):
265 265 lines = self.ax.lines
266 266
267 267 if idline in self.idlineList:
268 268 self.__driver.set_linedata(self.ax, x, y, idline)
269 269
270 270 if idline not in(self.idlineList):
271 271 self.__driver.addpline(self.ax, x, y, **kwargs)
272 272 self.idlineList.append(idline)
273 273
274 274 return
275 275
276 276 def pmultiline(self, x, y,
277 277 xmin=None, xmax=None,
278 278 ymin=None, ymax=None,
279 279 xlabel='', ylabel='',
280 280 title='',
281 281 **kwargs):
282 282
283 283 if self.__firsttime:
284 284
285 285 if xmin == None: xmin = numpy.nanmin(x)
286 286 if xmax == None: xmax = numpy.nanmax(x)
287 287 if ymin == None: ymin = numpy.nanmin(y)
288 288 if ymax == None: ymax = numpy.nanmax(y)
289 289
290 290 self.plot = self.__driver.createPmultiline(self.ax, x, y,
291 291 xmin, xmax,
292 292 ymin, ymax,
293 293 xlabel=xlabel,
294 294 ylabel=ylabel,
295 295 title=title,
296 296 **kwargs)
297 297 self.__firsttime = False
298 298 return
299 299
300 300 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
301 301 ylabel=ylabel,
302 302 title=title)
303 303
304 304 def pmultilineyaxis(self, x, y,
305 305 xmin=None, xmax=None,
306 306 ymin=None, ymax=None,
307 307 xlabel='', ylabel='',
308 308 title='',
309 309 **kwargs):
310 310
311 311 if self.__firsttime:
312 312
313 313 if xmin == None: xmin = numpy.nanmin(x)
314 314 if xmax == None: xmax = numpy.nanmax(x)
315 315 if ymin == None: ymin = numpy.nanmin(y)
316 316 if ymax == None: ymax = numpy.nanmax(y)
317 317
318 318 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
319 319 xmin, xmax,
320 320 ymin, ymax,
321 321 xlabel=xlabel,
322 322 ylabel=ylabel,
323 323 title=title,
324 324 **kwargs)
325 325 if self.xmin == None: self.xmin = xmin
326 326 if self.xmax == None: self.xmax = xmax
327 327 if self.ymin == None: self.ymin = ymin
328 328 if self.ymax == None: self.ymax = ymax
329 329
330 330 self.__firsttime = False
331 331 return
332 332
333 333 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
334 334 ylabel=ylabel,
335 335 title=title)
336 336
337 337 def pcolor(self, x, y, z,
338 338 xmin=None, xmax=None,
339 339 ymin=None, ymax=None,
340 340 zmin=None, zmax=None,
341 341 xlabel='', ylabel='',
342 342 title='', rti = False, colormap='jet',
343 343 **kwargs):
344 344
345 345 """
346 346 Input:
347 347 x :
348 348 y :
349 349 x :
350 350 xmin :
351 351 xmax :
352 352 ymin :
353 353 ymax :
354 354 zmin :
355 355 zmax :
356 356 xlabel :
357 357 ylabel :
358 358 title :
359 359 **kwargs : Los parametros aceptados son
360 360 ticksize=9,
361 361 cblabel=''
362 362 rti = True or False
363 363 """
364 364
365 365 if self.__firsttime:
366 366
367 367 if xmin == None: xmin = numpy.nanmin(x)
368 368 if xmax == None: xmax = numpy.nanmax(x)
369 369 if ymin == None: ymin = numpy.nanmin(y)
370 370 if ymax == None: ymax = numpy.nanmax(y)
371 371 if zmin == None: zmin = numpy.nanmin(z)
372 372 if zmax == None: zmax = numpy.nanmax(z)
373 373
374 374
375 375 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
376 376 xmin, xmax,
377 377 ymin, ymax,
378 378 zmin, zmax,
379 379 xlabel=xlabel,
380 380 ylabel=ylabel,
381 381 title=title,
382 382 colormap=colormap,
383 383 **kwargs)
384 384
385 385 if self.xmin == None: self.xmin = xmin
386 386 if self.xmax == None: self.xmax = xmax
387 387 if self.ymin == None: self.ymin = ymin
388 388 if self.ymax == None: self.ymax = ymax
389 389 if self.zmin == None: self.zmin = zmin
390 390 if self.zmax == None: self.zmax = zmax
391 391
392 392 self.__firsttime = False
393 393 return
394 394
395 395 if rti:
396 396 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
397 397 xlabel=xlabel,
398 398 ylabel=ylabel,
399 399 title=title,
400 400 colormap=colormap)
401 401 return
402 402
403 403 self.__driver.pcolor(self.plot, z,
404 404 xlabel=xlabel,
405 405 ylabel=ylabel,
406 406 title=title)
407 407
408 408 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now