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