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