##// END OF EJS Templates
bug txmin
Daniel Valdez -
r413:79f811a1a183
parent child
Show More
@@ -1,537 +1,537
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 class Figure:
8 8
9 9 __driver = mpldriver
10 10 fig = None
11 11
12 12 id = 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.id)
36 36 filename = '%s_%s%s' %(self.PREFIX, name, ext)
37 37 return os.path.join(path, filename)
38 38
39 39 def getAxesObjList(self):
40 40
41 41 return self.axesObjList
42 42
43 43 def getSubplots(self):
44 44
45 45 raise ValueError, "Abstract method: This method should be defined"
46 46
47 47 def getScreenDim(self, widthplot, heightplot):
48 48
49 49 nrow, ncol = self.getSubplots()
50 50
51 51 widthscreen = widthplot*ncol
52 52 heightscreen = heightplot*nrow
53 53
54 54 return widthscreen, heightscreen
55 55
56 56 def getTimeLim(self, x, xmin, xmax):
57 57
58 58 if self.timerange != None:
59 59 txmin = x[0] - x[0]%self.timerange
60 60 else:
61 61 txmin = numpy.min(x)
62 62
63 thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x))
63 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
64 64 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
65 65
66 66 ####################################################
67 67 #If the x is out of xrange
68 68 if xmax != None:
69 69 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
70 70 xmin = None
71 71 xmax = None
72 72
73 73 if xmin == None:
74 74 td = thisdatetime - thisdate
75 75 xmin = td.seconds/(60*60.)
76 76
77 77 if xmax == None:
78 78 xmax = xmin + self.timerange/(60*60.)
79 79
80 80 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
81 81 tmin = time.mktime(mindt.timetuple())
82 82
83 83 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
84 84 tmax = time.mktime(maxdt.timetuple())
85 85
86 86 self.timerange = tmax - tmin
87 87
88 88 return tmin, tmax
89 89
90 90 def init(self, id, nplots, wintitle):
91 91
92 92 raise ValueError, "This method has been replaced with createFigure"
93 93
94 94 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
95 95
96 96 """
97 97 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
98 98 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
99 99 y self.HEIGHT y el numero de subplots (nrow, ncol)
100 100
101 101 Input:
102 102 id : Los parametros necesarios son
103 103 wintitle :
104 104
105 105 """
106 106
107 107 if widthplot == None:
108 108 widthplot = self.WIDTH
109 109
110 110 if heightplot == None:
111 111 heightplot = self.HEIGHT
112 112
113 113 self.id = id
114 114
115 115 self.wintitle = wintitle
116 116
117 117 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
118 118
119 119 self.fig = self.__driver.createFigure(id=self.id,
120 120 wintitle=self.wintitle,
121 121 width=self.widthscreen,
122 122 height=self.heightscreen,
123 123 show=show)
124 124
125 125 self.axesObjList = []
126 126
127 127
128 128 def setDriver(self, driver=mpldriver):
129 129
130 130 self.__driver = driver
131 131
132 132 def setTitle(self, title):
133 133
134 134 self.__driver.setTitle(self.fig, title)
135 135
136 136 def setWinTitle(self, title):
137 137
138 138 self.__driver.setWinTitle(self.fig, title=title)
139 139
140 140 def setTextFromAxes(self, text):
141 141
142 142 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
143 143
144 144 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
145 145
146 146 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
147 147
148 148 def addAxes(self, *args):
149 149 """
150 150
151 151 Input:
152 152 *args : Los parametros necesarios son
153 153 nrow, ncol, xpos, ypos, colspan, rowspan
154 154 """
155 155
156 156 axesObj = Axes(self.fig, *args)
157 157 self.axesObjList.append(axesObj)
158 158
159 159 def saveFigure(self, figpath, figfile, *args):
160 160
161 161 filename = os.path.join(figpath, figfile)
162 162
163 163 fullpath = os.path.split(filename)[0]
164 164
165 165 if not os.path.exists(fullpath):
166 166 subpath = os.path.split(fullpath)[0]
167 167
168 168 if not os.path.exists(subpath):
169 169 os.mkdir(subpath)
170 170
171 171 os.mkdir(fullpath)
172 172
173 173 self.__driver.saveFigure(self.fig, filename, *args)
174 174
175 175 def sendByFTP(self, figfilename, server, folder, username, password):
176 176 ftpObj = Ftp(host=server, username=username, passw=password, remotefolder=folder)
177 177 ftpObj.upload(figfilename)
178 178 ftpObj.close()
179 179
180 180 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
181 181 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
182 182 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
183 183 FTP_WEI = '%2.2d'%FTP_WEI
184 184 EXP_CODE = '%3.3d'%EXP_CODE
185 185 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
186 186 PLOT_CODE = '%2.2d'%PLOT_CODE
187 187 PLOT_POS = '%2.2d'%PLOT_POS
188 188 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
189 189 return name
190 190
191 191 def draw(self):
192 192
193 193 self.__driver.draw(self.fig)
194 194
195 195 def run(self):
196 196
197 197 raise ValueError, "This method is not implemented"
198 198
199 199 axesList = property(getAxesObjList)
200 200
201 201
202 202 class Axes:
203 203
204 204 __driver = mpldriver
205 205 fig = None
206 206 ax = None
207 207 plot = None
208 208 __missing = 1E30
209 209 __firsttime = None
210 210
211 211 __showprofile = False
212 212
213 213 xmin = None
214 214 xmax = None
215 215 ymin = None
216 216 ymax = None
217 217 zmin = None
218 218 zmax = None
219 219
220 220 x_buffer = None
221 221 z_buffer = None
222 222
223 223 decimationx = None
224 224 decimationy = None
225 225
226 226 __MAXNUMX = 1000
227 227 __MAXNUMY = 500
228 228
229 229 def __init__(self, *args):
230 230
231 231 """
232 232
233 233 Input:
234 234 *args : Los parametros necesarios son
235 235 fig, nrow, ncol, xpos, ypos, colspan, rowspan
236 236 """
237 237
238 238 ax = self.__driver.createAxes(*args)
239 239 self.fig = args[0]
240 240 self.ax = ax
241 241 self.plot = None
242 242
243 243 self.__firsttime = True
244 244 self.idlineList = []
245 245
246 246 self.x_buffer = numpy.array([])
247 247 self.z_buffer = numpy.array([])
248 248
249 249 def setText(self, text):
250 250
251 251 self.__driver.setAxesText(self.ax, text)
252 252
253 253 def setXAxisAsTime(self):
254 254 pass
255 255
256 256 def pline(self, x, y,
257 257 xmin=None, xmax=None,
258 258 ymin=None, ymax=None,
259 259 xlabel='', ylabel='',
260 260 title='',
261 261 **kwargs):
262 262
263 263 """
264 264
265 265 Input:
266 266 x :
267 267 y :
268 268 xmin :
269 269 xmax :
270 270 ymin :
271 271 ymax :
272 272 xlabel :
273 273 ylabel :
274 274 title :
275 275 **kwargs : Los parametros aceptados son
276 276
277 277 ticksize
278 278 ytick_visible
279 279 """
280 280
281 281 if self.__firsttime:
282 282
283 283 if xmin == None: xmin = numpy.nanmin(x)
284 284 if xmax == None: xmax = numpy.nanmax(x)
285 285 if ymin == None: ymin = numpy.nanmin(y)
286 286 if ymax == None: ymax = numpy.nanmax(y)
287 287
288 288 self.plot = self.__driver.createPline(self.ax, x, y,
289 289 xmin, xmax,
290 290 ymin, ymax,
291 291 xlabel=xlabel,
292 292 ylabel=ylabel,
293 293 title=title,
294 294 **kwargs)
295 295
296 296 self.idlineList.append(0)
297 297 self.__firsttime = False
298 298 return
299 299
300 300 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
301 301 ylabel=ylabel,
302 302 title=title)
303 303
304 304 def addpline(self, x, y, idline, **kwargs):
305 305 lines = self.ax.lines
306 306
307 307 if idline in self.idlineList:
308 308 self.__driver.set_linedata(self.ax, x, y, idline)
309 309
310 310 if idline not in(self.idlineList):
311 311 self.__driver.addpline(self.ax, x, y, **kwargs)
312 312 self.idlineList.append(idline)
313 313
314 314 return
315 315
316 316 def pmultiline(self, x, y,
317 317 xmin=None, xmax=None,
318 318 ymin=None, ymax=None,
319 319 xlabel='', ylabel='',
320 320 title='',
321 321 **kwargs):
322 322
323 323 if self.__firsttime:
324 324
325 325 if xmin == None: xmin = numpy.nanmin(x)
326 326 if xmax == None: xmax = numpy.nanmax(x)
327 327 if ymin == None: ymin = numpy.nanmin(y)
328 328 if ymax == None: ymax = numpy.nanmax(y)
329 329
330 330 self.plot = self.__driver.createPmultiline(self.ax, x, y,
331 331 xmin, xmax,
332 332 ymin, ymax,
333 333 xlabel=xlabel,
334 334 ylabel=ylabel,
335 335 title=title,
336 336 **kwargs)
337 337 self.__firsttime = False
338 338 return
339 339
340 340 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
341 341 ylabel=ylabel,
342 342 title=title)
343 343
344 344 def pmultilineyaxis(self, x, y,
345 345 xmin=None, xmax=None,
346 346 ymin=None, ymax=None,
347 347 xlabel='', ylabel='',
348 348 title='',
349 349 **kwargs):
350 350
351 351 if self.__firsttime:
352 352
353 353 if xmin == None: xmin = numpy.nanmin(x)
354 354 if xmax == None: xmax = numpy.nanmax(x)
355 355 if ymin == None: ymin = numpy.nanmin(y)
356 356 if ymax == None: ymax = numpy.nanmax(y)
357 357
358 358 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
359 359 xmin, xmax,
360 360 ymin, ymax,
361 361 xlabel=xlabel,
362 362 ylabel=ylabel,
363 363 title=title,
364 364 **kwargs)
365 365 if self.xmin == None: self.xmin = xmin
366 366 if self.xmax == None: self.xmax = xmax
367 367 if self.ymin == None: self.ymin = ymin
368 368 if self.ymax == None: self.ymax = ymax
369 369
370 370 self.__firsttime = False
371 371 return
372 372
373 373 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
374 374 ylabel=ylabel,
375 375 title=title)
376 376
377 377 def pcolor(self, x, y, z,
378 378 xmin=None, xmax=None,
379 379 ymin=None, ymax=None,
380 380 zmin=None, zmax=None,
381 381 xlabel='', ylabel='',
382 382 title='', rti = False, colormap='jet',
383 383 **kwargs):
384 384
385 385 """
386 386 Input:
387 387 x :
388 388 y :
389 389 x :
390 390 xmin :
391 391 xmax :
392 392 ymin :
393 393 ymax :
394 394 zmin :
395 395 zmax :
396 396 xlabel :
397 397 ylabel :
398 398 title :
399 399 **kwargs : Los parametros aceptados son
400 400 ticksize=9,
401 401 cblabel=''
402 402 rti = True or False
403 403 """
404 404
405 405 if self.__firsttime:
406 406
407 407 if xmin == None: xmin = numpy.nanmin(x)
408 408 if xmax == None: xmax = numpy.nanmax(x)
409 409 if ymin == None: ymin = numpy.nanmin(y)
410 410 if ymax == None: ymax = numpy.nanmax(y)
411 411 if zmin == None: zmin = numpy.nanmin(z)
412 412 if zmax == None: zmax = numpy.nanmax(z)
413 413
414 414
415 415 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
416 416 xmin, xmax,
417 417 ymin, ymax,
418 418 zmin, zmax,
419 419 xlabel=xlabel,
420 420 ylabel=ylabel,
421 421 title=title,
422 422 colormap=colormap,
423 423 **kwargs)
424 424
425 425 if self.xmin == None: self.xmin = xmin
426 426 if self.xmax == None: self.xmax = xmax
427 427 if self.ymin == None: self.ymin = ymin
428 428 if self.ymax == None: self.ymax = ymax
429 429 if self.zmin == None: self.zmin = zmin
430 430 if self.zmax == None: self.zmax = zmax
431 431
432 432 self.__firsttime = False
433 433 return
434 434
435 435 if rti:
436 436 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
437 437 xlabel=xlabel,
438 438 ylabel=ylabel,
439 439 title=title,
440 440 colormap=colormap)
441 441 return
442 442
443 443 self.__driver.pcolor(self.plot, z,
444 444 xlabel=xlabel,
445 445 ylabel=ylabel,
446 446 title=title)
447 447
448 448 def pcolorbuffer(self, x, y, z,
449 449 xmin=None, xmax=None,
450 450 ymin=None, ymax=None,
451 451 zmin=None, zmax=None,
452 452 xlabel='', ylabel='',
453 453 title='', rti = True, colormap='jet',
454 454 maxNumX = None, maxNumY = None,
455 455 **kwargs):
456 456
457 457 if maxNumX == None:
458 458 maxNumX = self.__MAXNUMX
459 459
460 460 if maxNumY == None:
461 461 maxNumY = self.__MAXNUMY
462 462
463 463 if self.__firsttime:
464 464 self.z_buffer = z
465 465 self.x_buffer = numpy.hstack((self.x_buffer, x))
466 466
467 467 if xmin == None: xmin = numpy.nanmin(x)
468 468 if xmax == None: xmax = numpy.nanmax(x)
469 469 if ymin == None: ymin = numpy.nanmin(y)
470 470 if ymax == None: ymax = numpy.nanmax(y)
471 471 if zmin == None: zmin = numpy.nanmin(z)
472 472 if zmax == None: zmax = numpy.nanmax(z)
473 473
474 474
475 475 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
476 476 xmin, xmax,
477 477 ymin, ymax,
478 478 zmin, zmax,
479 479 xlabel=xlabel,
480 480 ylabel=ylabel,
481 481 title=title,
482 482 colormap=colormap,
483 483 **kwargs)
484 484
485 485 if self.xmin == None: self.xmin = xmin
486 486 if self.xmax == None: self.xmax = xmax
487 487 if self.ymin == None: self.ymin = ymin
488 488 if self.ymax == None: self.ymax = ymax
489 489 if self.zmin == None: self.zmin = zmin
490 490 if self.zmax == None: self.zmax = zmax
491 491
492 492 self.__firsttime = False
493 493 return
494 494
495 495 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
496 496 self.z_buffer = numpy.hstack((self.z_buffer, z))
497 497
498 498 if self.decimationx == None:
499 499 deltax = (self.xmax - self.xmin)/maxNumX
500 500 deltay = (self.ymax - self.ymin)/maxNumY
501 501
502 502 resolutionx = self.x_buffer[2]-self.x_buffer[0]
503 503 resolutiony = y[1]-y[0]
504 504
505 505 self.decimationx = numpy.ceil(deltax / resolutionx)
506 506 self.decimationy = numpy.ceil(deltay / resolutiony)
507 507
508 508 z_buffer = self.z_buffer.reshape(-1,len(y))
509 509
510 510 x_buffer = self.x_buffer[::self.decimationx]
511 511 y_buffer = y[::self.decimationy]
512 512 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
513 513 #===================================================
514 514
515 515 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
516 516
517 517 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
518 518 xlabel=xlabel,
519 519 ylabel=ylabel,
520 520 title=title,
521 521 colormap=colormap)
522 522 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
523 523
524 524 deltas = x_buffer[1:] - x_buffer[0:-1]
525 525 x_median = numpy.median(deltas)
526 526
527 527 index = numpy.where(deltas >= 2*x_median)
528 528
529 529 if len(index[0]) != 0:
530 530 z_buffer[index[0],::] = self.__missing
531 531 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
532 532
533 533 return x_buffer, y_buffer, z_buffer
534 534
535 535
536 536
537 537 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now