##// END OF EJS Templates
Miguel Valdez -
r814:a59f12dc9ae4
parent child
Show More
@@ -1,659 +1,661
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
5
6 from schainpy.model.proc.jroproc_base import Operation
6 from schainpy.model.proc.jroproc_base import Operation
7
7
8 def isTimeInHourRange(datatime, xmin, xmax):
8 def isTimeInHourRange(datatime, xmin, xmax):
9
9
10 if xmin == None or xmax == None:
10 if xmin == None or xmax == None:
11 return 1
11 return 1
12 hour = datatime.hour + datatime.minute/60.0
12 hour = datatime.hour + datatime.minute/60.0
13
13
14 if xmin < (xmax % 24):
14 if xmin < (xmax % 24):
15
15
16 if hour >= xmin and hour <= xmax:
16 if hour >= xmin and hour <= xmax:
17 return 1
17 return 1
18 else:
18 else:
19 return 0
19 return 0
20
20
21 else:
21 else:
22
22
23 if hour >= xmin or hour <= (xmax % 24):
23 if hour >= xmin or hour <= (xmax % 24):
24 return 1
24 return 1
25 else:
25 else:
26 return 0
26 return 0
27
27
28 return 0
28 return 0
29
29
30 def isRealtime(utcdatatime):
30 def isRealtime(utcdatatime):
31
31
32 utcnow = time.mktime(time.localtime())
32 utcnow = time.mktime(time.localtime())
33 delta = abs(utcnow - utcdatatime) # abs
33 delta = abs(utcnow - utcdatatime) # abs
34 if delta >= 30.:
34 if delta >= 30.:
35 return False
35 return False
36 return True
36 return True
37
37
38 class Figure(Operation):
38 class Figure(Operation):
39
39
40 __driver = mpldriver
40 __driver = mpldriver
41 fig = None
41 fig = None
42
42
43 id = None
43 id = None
44 wintitle = None
44 wintitle = None
45 width = None
45 width = None
46 height = None
46 height = None
47 nplots = None
47 nplots = None
48 timerange = None
48 timerange = None
49
49
50 axesObjList = []
50 axesObjList = []
51
51
52 WIDTH = 300
52 WIDTH = 300
53 HEIGHT = 200
53 HEIGHT = 200
54 PREFIX = 'fig'
54 PREFIX = 'fig'
55
55
56 xmin = None
56 xmin = None
57 xmax = None
57 xmax = None
58
58
59 counter_imagwr = 0
59 counter_imagwr = 0
60
60
61 figfile = None
61 figfile = None
62
62
63 created = False
63 created = False
64
64
65 def __init__(self):
65 def __init__(self):
66
66
67 raise NotImplementedError
67 raise NotImplementedError
68
68
69 def __del__(self):
69 def __del__(self):
70
70
71 self.__driver.closeFigure()
71 self.__driver.closeFigure()
72
72
73 def getFilename(self, name, ext='.png'):
73 def getFilename(self, name, ext='.png'):
74
74
75 path = '%s%03d' %(self.PREFIX, self.id)
75 path = '%s%03d' %(self.PREFIX, self.id)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
77 return os.path.join(path, filename)
77 return os.path.join(path, filename)
78
78
79 def getAxesObjList(self):
79 def getAxesObjList(self):
80
80
81 return self.axesObjList
81 return self.axesObjList
82
82
83 def getSubplots(self):
83 def getSubplots(self):
84
84
85 raise NotImplementedError
85 raise NotImplementedError
86
86
87 def getScreenDim(self, widthplot, heightplot):
87 def getScreenDim(self, widthplot, heightplot):
88
88
89 nrow, ncol = self.getSubplots()
89 nrow, ncol = self.getSubplots()
90
90
91 widthscreen = widthplot*ncol
91 widthscreen = widthplot*ncol
92 heightscreen = heightplot*nrow
92 heightscreen = heightplot*nrow
93
93
94 return widthscreen, heightscreen
94 return widthscreen, heightscreen
95
95
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
97
97
98 # if self.xmin != None and self.xmax != None:
98 # if self.xmin != None and self.xmax != None:
99 # if timerange == None:
99 # if timerange == None:
100 # timerange = self.xmax - self.xmin
100 # timerange = self.xmax - self.xmin
101 # xmin = self.xmin + timerange
101 # xmin = self.xmin + timerange
102 # xmax = self.xmax + timerange
102 # xmax = self.xmax + timerange
103 #
103 #
104 # return xmin, xmax
104 # return xmin, xmax
105
105
106 if timerange == None and (xmin==None or xmax==None):
106 if timerange == None and (xmin==None or xmax==None):
107 timerange = 14400 #seconds
107 timerange = 14400 #seconds
108
108
109 if timerange != None:
109 if timerange != None:
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
111 else:
111 else:
112 txmin = x[0] #- x[0] % 10*60
112 txmin = x[0] #- x[0] % 10*60
113
113
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116
116
117 if timerange != None:
117 if timerange != None:
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
119 xmax = xmin + timerange/(60*60.)
119 xmax = xmin + timerange/(60*60.)
120
120
121 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
121 d1970 = datetime.datetime(1970,1,1)
122 xmin_sec = time.mktime(mindt.timetuple())
123
122
124 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
125 xmax_sec = time.mktime(maxdt.timetuple())
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
125
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
126
128
127 return xmin_sec, xmax_sec
129 return xmin_sec, xmax_sec
128
130
129 def init(self, id, nplots, wintitle):
131 def init(self, id, nplots, wintitle):
130
132
131 raise NotImplementedError, "This method has been replaced with createFigure"
133 raise NotImplementedError, "This method has been replaced with createFigure"
132
134
133 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
134
136
135 """
137 """
136 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
137 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
138 y self.HEIGHT y el numero de subplots (nrow, ncol)
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
139
141
140 Input:
142 Input:
141 id : Los parametros necesarios son
143 id : Los parametros necesarios son
142 wintitle :
144 wintitle :
143
145
144 """
146 """
145
147
146 if widthplot == None:
148 if widthplot == None:
147 widthplot = self.WIDTH
149 widthplot = self.WIDTH
148
150
149 if heightplot == None:
151 if heightplot == None:
150 heightplot = self.HEIGHT
152 heightplot = self.HEIGHT
151
153
152 self.id = id
154 self.id = id
153
155
154 self.wintitle = wintitle
156 self.wintitle = wintitle
155
157
156 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
157
159
158 # if self.created:
160 # if self.created:
159 # self.__driver.closeFigure(self.fig)
161 # self.__driver.closeFigure(self.fig)
160
162
161 if not self.created:
163 if not self.created:
162 self.fig = self.__driver.createFigure(id=self.id,
164 self.fig = self.__driver.createFigure(id=self.id,
163 wintitle=self.wintitle,
165 wintitle=self.wintitle,
164 width=self.widthscreen,
166 width=self.widthscreen,
165 height=self.heightscreen,
167 height=self.heightscreen,
166 show=show)
168 show=show)
167 else:
169 else:
168 self.__driver.clearFigure(self.fig)
170 self.__driver.clearFigure(self.fig)
169
171
170 self.axesObjList = []
172 self.axesObjList = []
171 self.counter_imagwr = 0
173 self.counter_imagwr = 0
172
174
173 self.created = True
175 self.created = True
174
176
175 def setDriver(self, driver=mpldriver):
177 def setDriver(self, driver=mpldriver):
176
178
177 self.__driver = driver
179 self.__driver = driver
178
180
179 def setTitle(self, title):
181 def setTitle(self, title):
180
182
181 self.__driver.setTitle(self.fig, title)
183 self.__driver.setTitle(self.fig, title)
182
184
183 def setWinTitle(self, title):
185 def setWinTitle(self, title):
184
186
185 self.__driver.setWinTitle(self.fig, title=title)
187 self.__driver.setWinTitle(self.fig, title=title)
186
188
187 def setTextFromAxes(self, text):
189 def setTextFromAxes(self, text):
188
190
189 raise NotImplementedError, "This method has been replaced with Axes.setText"
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
190
192
191 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
192
194
193 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
194
196
195 def addAxes(self, *args):
197 def addAxes(self, *args):
196 """
198 """
197
199
198 Input:
200 Input:
199 *args : Los parametros necesarios son
201 *args : Los parametros necesarios son
200 nrow, ncol, xpos, ypos, colspan, rowspan
202 nrow, ncol, xpos, ypos, colspan, rowspan
201 """
203 """
202
204
203 axesObj = Axes(self.fig, *args)
205 axesObj = Axes(self.fig, *args)
204 self.axesObjList.append(axesObj)
206 self.axesObjList.append(axesObj)
205
207
206 def saveFigure(self, figpath, figfile, *args):
208 def saveFigure(self, figpath, figfile, *args):
207
209
208 filename = os.path.join(figpath, figfile)
210 filename = os.path.join(figpath, figfile)
209
211
210 fullpath = os.path.split(filename)[0]
212 fullpath = os.path.split(filename)[0]
211
213
212 if not os.path.exists(fullpath):
214 if not os.path.exists(fullpath):
213 subpath = os.path.split(fullpath)[0]
215 subpath = os.path.split(fullpath)[0]
214
216
215 if not os.path.exists(subpath):
217 if not os.path.exists(subpath):
216 os.mkdir(subpath)
218 os.mkdir(subpath)
217
219
218 os.mkdir(fullpath)
220 os.mkdir(fullpath)
219
221
220 self.__driver.saveFigure(self.fig, filename, *args)
222 self.__driver.saveFigure(self.fig, filename, *args)
221
223
222 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
223
225
224 self.counter_imagwr += 1
226 self.counter_imagwr += 1
225 if self.counter_imagwr < wr_period:
227 if self.counter_imagwr < wr_period:
226 return
228 return
227
229
228 self.counter_imagwr = 0
230 self.counter_imagwr = 0
229
231
230 if save:
232 if save:
231
233
232 if not figfile:
234 if not figfile:
233
235
234 if not thisDatetime:
236 if not thisDatetime:
235 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
236 return
238 return
237
239
238 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
239 figfile = self.getFilename(name = str_datetime)
241 figfile = self.getFilename(name = str_datetime)
240
242
241 if self.figfile == None:
243 if self.figfile == None:
242 self.figfile = figfile
244 self.figfile = figfile
243
245
244 if update_figfile:
246 if update_figfile:
245 self.figfile = figfile
247 self.figfile = figfile
246
248
247 # store png plot to local folder
249 # store png plot to local folder
248 self.saveFigure(figpath, self.figfile)
250 self.saveFigure(figpath, self.figfile)
249
251
250
252
251 if not ftp:
253 if not ftp:
252 return
254 return
253
255
254 if not thisDatetime:
256 if not thisDatetime:
255 return
257 return
256
258
257 # store png plot to FTP server according to RT-Web format
259 # store png plot to FTP server according to RT-Web format
258 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
259 # ftp_filename = os.path.join(figpath, name)
261 # ftp_filename = os.path.join(figpath, name)
260 self.saveFigure(figpath, ftp_filename)
262 self.saveFigure(figpath, ftp_filename)
261
263
262 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
263 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
264 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
265 FTP_WEI = '%2.2d'%FTP_WEI
267 FTP_WEI = '%2.2d'%FTP_WEI
266 EXP_CODE = '%3.3d'%EXP_CODE
268 EXP_CODE = '%3.3d'%EXP_CODE
267 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
268 PLOT_CODE = '%2.2d'%PLOT_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
269 PLOT_POS = '%2.2d'%PLOT_POS
271 PLOT_POS = '%2.2d'%PLOT_POS
270 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
271 return name
273 return name
272
274
273 def draw(self):
275 def draw(self):
274
276
275 self.__driver.draw(self.fig)
277 self.__driver.draw(self.fig)
276
278
277 def run(self):
279 def run(self):
278
280
279 raise NotImplementedError
281 raise NotImplementedError
280
282
281 def close(self, show=False):
283 def close(self, show=False):
282
284
283 self.__driver.closeFigure(show=show, fig=self.fig)
285 self.__driver.closeFigure(show=show, fig=self.fig)
284
286
285 axesList = property(getAxesObjList)
287 axesList = property(getAxesObjList)
286
288
287
289
288 class Axes:
290 class Axes:
289
291
290 __driver = mpldriver
292 __driver = mpldriver
291 fig = None
293 fig = None
292 ax = None
294 ax = None
293 plot = None
295 plot = None
294 __missing = 1E30
296 __missing = 1E30
295 __firsttime = None
297 __firsttime = None
296
298
297 __showprofile = False
299 __showprofile = False
298
300
299 xmin = None
301 xmin = None
300 xmax = None
302 xmax = None
301 ymin = None
303 ymin = None
302 ymax = None
304 ymax = None
303 zmin = None
305 zmin = None
304 zmax = None
306 zmax = None
305
307
306 x_buffer = None
308 x_buffer = None
307 z_buffer = None
309 z_buffer = None
308
310
309 decimationx = None
311 decimationx = None
310 decimationy = None
312 decimationy = None
311
313
312 __MAXNUMX = 200
314 __MAXNUMX = 200
313 __MAXNUMY = 400
315 __MAXNUMY = 400
314
316
315 __MAXNUMTIME = 500
317 __MAXNUMTIME = 500
316
318
317 def __init__(self, *args):
319 def __init__(self, *args):
318
320
319 """
321 """
320
322
321 Input:
323 Input:
322 *args : Los parametros necesarios son
324 *args : Los parametros necesarios son
323 fig, nrow, ncol, xpos, ypos, colspan, rowspan
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
324 """
326 """
325
327
326 ax = self.__driver.createAxes(*args)
328 ax = self.__driver.createAxes(*args)
327 self.fig = args[0]
329 self.fig = args[0]
328 self.ax = ax
330 self.ax = ax
329 self.plot = None
331 self.plot = None
330
332
331 self.__firsttime = True
333 self.__firsttime = True
332 self.idlineList = []
334 self.idlineList = []
333
335
334 self.x_buffer = numpy.array([])
336 self.x_buffer = numpy.array([])
335 self.z_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
336
338
337 def setText(self, text):
339 def setText(self, text):
338
340
339 self.__driver.setAxesText(self.ax, text)
341 self.__driver.setAxesText(self.ax, text)
340
342
341 def setXAxisAsTime(self):
343 def setXAxisAsTime(self):
342 pass
344 pass
343
345
344 def pline(self, x, y,
346 def pline(self, x, y,
345 xmin=None, xmax=None,
347 xmin=None, xmax=None,
346 ymin=None, ymax=None,
348 ymin=None, ymax=None,
347 xlabel='', ylabel='',
349 xlabel='', ylabel='',
348 title='',
350 title='',
349 **kwargs):
351 **kwargs):
350
352
351 """
353 """
352
354
353 Input:
355 Input:
354 x :
356 x :
355 y :
357 y :
356 xmin :
358 xmin :
357 xmax :
359 xmax :
358 ymin :
360 ymin :
359 ymax :
361 ymax :
360 xlabel :
362 xlabel :
361 ylabel :
363 ylabel :
362 title :
364 title :
363 **kwargs : Los parametros aceptados son
365 **kwargs : Los parametros aceptados son
364
366
365 ticksize
367 ticksize
366 ytick_visible
368 ytick_visible
367 """
369 """
368
370
369 if self.__firsttime:
371 if self.__firsttime:
370
372
371 if xmin == None: xmin = numpy.nanmin(x)
373 if xmin == None: xmin = numpy.nanmin(x)
372 if xmax == None: xmax = numpy.nanmax(x)
374 if xmax == None: xmax = numpy.nanmax(x)
373 if ymin == None: ymin = numpy.nanmin(y)
375 if ymin == None: ymin = numpy.nanmin(y)
374 if ymax == None: ymax = numpy.nanmax(y)
376 if ymax == None: ymax = numpy.nanmax(y)
375
377
376 self.plot = self.__driver.createPline(self.ax, x, y,
378 self.plot = self.__driver.createPline(self.ax, x, y,
377 xmin, xmax,
379 xmin, xmax,
378 ymin, ymax,
380 ymin, ymax,
379 xlabel=xlabel,
381 xlabel=xlabel,
380 ylabel=ylabel,
382 ylabel=ylabel,
381 title=title,
383 title=title,
382 **kwargs)
384 **kwargs)
383
385
384 self.idlineList.append(0)
386 self.idlineList.append(0)
385 self.__firsttime = False
387 self.__firsttime = False
386 return
388 return
387
389
388 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
389 ylabel=ylabel,
391 ylabel=ylabel,
390 title=title)
392 title=title)
391
393
392 # self.__driver.pause()
394 # self.__driver.pause()
393
395
394 def addpline(self, x, y, idline, **kwargs):
396 def addpline(self, x, y, idline, **kwargs):
395 lines = self.ax.lines
397 lines = self.ax.lines
396
398
397 if idline in self.idlineList:
399 if idline in self.idlineList:
398 self.__driver.set_linedata(self.ax, x, y, idline)
400 self.__driver.set_linedata(self.ax, x, y, idline)
399
401
400 if idline not in(self.idlineList):
402 if idline not in(self.idlineList):
401 self.__driver.addpline(self.ax, x, y, **kwargs)
403 self.__driver.addpline(self.ax, x, y, **kwargs)
402 self.idlineList.append(idline)
404 self.idlineList.append(idline)
403
405
404 return
406 return
405
407
406 def pmultiline(self, x, y,
408 def pmultiline(self, x, y,
407 xmin=None, xmax=None,
409 xmin=None, xmax=None,
408 ymin=None, ymax=None,
410 ymin=None, ymax=None,
409 xlabel='', ylabel='',
411 xlabel='', ylabel='',
410 title='',
412 title='',
411 **kwargs):
413 **kwargs):
412
414
413 if self.__firsttime:
415 if self.__firsttime:
414
416
415 if xmin == None: xmin = numpy.nanmin(x)
417 if xmin == None: xmin = numpy.nanmin(x)
416 if xmax == None: xmax = numpy.nanmax(x)
418 if xmax == None: xmax = numpy.nanmax(x)
417 if ymin == None: ymin = numpy.nanmin(y)
419 if ymin == None: ymin = numpy.nanmin(y)
418 if ymax == None: ymax = numpy.nanmax(y)
420 if ymax == None: ymax = numpy.nanmax(y)
419
421
420 self.plot = self.__driver.createPmultiline(self.ax, x, y,
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
421 xmin, xmax,
423 xmin, xmax,
422 ymin, ymax,
424 ymin, ymax,
423 xlabel=xlabel,
425 xlabel=xlabel,
424 ylabel=ylabel,
426 ylabel=ylabel,
425 title=title,
427 title=title,
426 **kwargs)
428 **kwargs)
427 self.__firsttime = False
429 self.__firsttime = False
428 return
430 return
429
431
430 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
431 ylabel=ylabel,
433 ylabel=ylabel,
432 title=title)
434 title=title)
433
435
434 # self.__driver.pause()
436 # self.__driver.pause()
435
437
436 def pmultilineyaxis(self, x, y,
438 def pmultilineyaxis(self, x, y,
437 xmin=None, xmax=None,
439 xmin=None, xmax=None,
438 ymin=None, ymax=None,
440 ymin=None, ymax=None,
439 xlabel='', ylabel='',
441 xlabel='', ylabel='',
440 title='',
442 title='',
441 **kwargs):
443 **kwargs):
442
444
443 if self.__firsttime:
445 if self.__firsttime:
444
446
445 if xmin == None: xmin = numpy.nanmin(x)
447 if xmin == None: xmin = numpy.nanmin(x)
446 if xmax == None: xmax = numpy.nanmax(x)
448 if xmax == None: xmax = numpy.nanmax(x)
447 if ymin == None: ymin = numpy.nanmin(y)
449 if ymin == None: ymin = numpy.nanmin(y)
448 if ymax == None: ymax = numpy.nanmax(y)
450 if ymax == None: ymax = numpy.nanmax(y)
449
451
450 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
451 xmin, xmax,
453 xmin, xmax,
452 ymin, ymax,
454 ymin, ymax,
453 xlabel=xlabel,
455 xlabel=xlabel,
454 ylabel=ylabel,
456 ylabel=ylabel,
455 title=title,
457 title=title,
456 **kwargs)
458 **kwargs)
457 if self.xmin == None: self.xmin = xmin
459 if self.xmin == None: self.xmin = xmin
458 if self.xmax == None: self.xmax = xmax
460 if self.xmax == None: self.xmax = xmax
459 if self.ymin == None: self.ymin = ymin
461 if self.ymin == None: self.ymin = ymin
460 if self.ymax == None: self.ymax = ymax
462 if self.ymax == None: self.ymax = ymax
461
463
462 self.__firsttime = False
464 self.__firsttime = False
463 return
465 return
464
466
465 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
466 ylabel=ylabel,
468 ylabel=ylabel,
467 title=title)
469 title=title)
468
470
469 # self.__driver.pause()
471 # self.__driver.pause()
470
472
471 def pcolor(self, x, y, z,
473 def pcolor(self, x, y, z,
472 xmin=None, xmax=None,
474 xmin=None, xmax=None,
473 ymin=None, ymax=None,
475 ymin=None, ymax=None,
474 zmin=None, zmax=None,
476 zmin=None, zmax=None,
475 xlabel='', ylabel='',
477 xlabel='', ylabel='',
476 title='', colormap='jet',
478 title='', colormap='jet',
477 **kwargs):
479 **kwargs):
478
480
479 """
481 """
480 Input:
482 Input:
481 x :
483 x :
482 y :
484 y :
483 x :
485 x :
484 xmin :
486 xmin :
485 xmax :
487 xmax :
486 ymin :
488 ymin :
487 ymax :
489 ymax :
488 zmin :
490 zmin :
489 zmax :
491 zmax :
490 xlabel :
492 xlabel :
491 ylabel :
493 ylabel :
492 title :
494 title :
493 **kwargs : Los parametros aceptados son
495 **kwargs : Los parametros aceptados son
494 ticksize=9,
496 ticksize=9,
495 cblabel=''
497 cblabel=''
496 """
498 """
497
499
498 #Decimating data
500 #Decimating data
499 xlen = len(x)
501 xlen = len(x)
500 ylen = len(y)
502 ylen = len(y)
501
503
502 decimationx = numpy.floor(xlen/self.__MAXNUMX) + 1
504 decimationx = numpy.floor(xlen/self.__MAXNUMX) + 1
503 decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1
505 decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1
504
506
505 x_buffer = x[::decimationx]
507 x_buffer = x[::decimationx]
506 y_buffer = y[::decimationy]
508 y_buffer = y[::decimationy]
507 z_buffer = z[::decimationx, ::decimationy]
509 z_buffer = z[::decimationx, ::decimationy]
508 #===================================================
510 #===================================================
509
511
510 if self.__firsttime:
512 if self.__firsttime:
511
513
512 if xmin == None: xmin = numpy.nanmin(x)
514 if xmin == None: xmin = numpy.nanmin(x)
513 if xmax == None: xmax = numpy.nanmax(x)
515 if xmax == None: xmax = numpy.nanmax(x)
514 if ymin == None: ymin = numpy.nanmin(y)
516 if ymin == None: ymin = numpy.nanmin(y)
515 if ymax == None: ymax = numpy.nanmax(y)
517 if ymax == None: ymax = numpy.nanmax(y)
516 if zmin == None: zmin = numpy.nanmin(z)
518 if zmin == None: zmin = numpy.nanmin(z)
517 if zmax == None: zmax = numpy.nanmax(z)
519 if zmax == None: zmax = numpy.nanmax(z)
518
520
519
521
520 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
522 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
521 y_buffer,
523 y_buffer,
522 z_buffer,
524 z_buffer,
523 xmin, xmax,
525 xmin, xmax,
524 ymin, ymax,
526 ymin, ymax,
525 zmin, zmax,
527 zmin, zmax,
526 xlabel=xlabel,
528 xlabel=xlabel,
527 ylabel=ylabel,
529 ylabel=ylabel,
528 title=title,
530 title=title,
529 colormap=colormap,
531 colormap=colormap,
530 **kwargs)
532 **kwargs)
531
533
532 if self.xmin == None: self.xmin = xmin
534 if self.xmin == None: self.xmin = xmin
533 if self.xmax == None: self.xmax = xmax
535 if self.xmax == None: self.xmax = xmax
534 if self.ymin == None: self.ymin = ymin
536 if self.ymin == None: self.ymin = ymin
535 if self.ymax == None: self.ymax = ymax
537 if self.ymax == None: self.ymax = ymax
536 if self.zmin == None: self.zmin = zmin
538 if self.zmin == None: self.zmin = zmin
537 if self.zmax == None: self.zmax = zmax
539 if self.zmax == None: self.zmax = zmax
538
540
539 self.__firsttime = False
541 self.__firsttime = False
540 return
542 return
541
543
542 self.__driver.pcolor(self.plot,
544 self.__driver.pcolor(self.plot,
543 z_buffer,
545 z_buffer,
544 xlabel=xlabel,
546 xlabel=xlabel,
545 ylabel=ylabel,
547 ylabel=ylabel,
546 title=title)
548 title=title)
547
549
548 # self.__driver.pause()
550 # self.__driver.pause()
549
551
550 def pcolorbuffer(self, x, y, z,
552 def pcolorbuffer(self, x, y, z,
551 xmin=None, xmax=None,
553 xmin=None, xmax=None,
552 ymin=None, ymax=None,
554 ymin=None, ymax=None,
553 zmin=None, zmax=None,
555 zmin=None, zmax=None,
554 xlabel='', ylabel='',
556 xlabel='', ylabel='',
555 title='', rti = True, colormap='jet',
557 title='', rti = True, colormap='jet',
556 maxNumX = None, maxNumY = None,
558 maxNumX = None, maxNumY = None,
557 **kwargs):
559 **kwargs):
558
560
559 if maxNumX == None:
561 if maxNumX == None:
560 maxNumX = self.__MAXNUMTIME
562 maxNumX = self.__MAXNUMTIME
561
563
562 if maxNumY == None:
564 if maxNumY == None:
563 maxNumY = self.__MAXNUMY
565 maxNumY = self.__MAXNUMY
564
566
565 if self.__firsttime:
567 if self.__firsttime:
566 self.z_buffer = z
568 self.z_buffer = z
567 self.x_buffer = numpy.hstack((self.x_buffer, x))
569 self.x_buffer = numpy.hstack((self.x_buffer, x))
568
570
569 if xmin == None: xmin = numpy.nanmin(x)
571 if xmin == None: xmin = numpy.nanmin(x)
570 if xmax == None: xmax = numpy.nanmax(x)
572 if xmax == None: xmax = numpy.nanmax(x)
571 if ymin == None: ymin = numpy.nanmin(y)
573 if ymin == None: ymin = numpy.nanmin(y)
572 if ymax == None: ymax = numpy.nanmax(y)
574 if ymax == None: ymax = numpy.nanmax(y)
573 if zmin == None: zmin = numpy.nanmin(z)
575 if zmin == None: zmin = numpy.nanmin(z)
574 if zmax == None: zmax = numpy.nanmax(z)
576 if zmax == None: zmax = numpy.nanmax(z)
575
577
576
578
577 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
578 xmin, xmax,
580 xmin, xmax,
579 ymin, ymax,
581 ymin, ymax,
580 zmin, zmax,
582 zmin, zmax,
581 xlabel=xlabel,
583 xlabel=xlabel,
582 ylabel=ylabel,
584 ylabel=ylabel,
583 title=title,
585 title=title,
584 colormap=colormap,
586 colormap=colormap,
585 **kwargs)
587 **kwargs)
586
588
587 if self.xmin == None: self.xmin = xmin
589 if self.xmin == None: self.xmin = xmin
588 if self.xmax == None: self.xmax = xmax
590 if self.xmax == None: self.xmax = xmax
589 if self.ymin == None: self.ymin = ymin
591 if self.ymin == None: self.ymin = ymin
590 if self.ymax == None: self.ymax = ymax
592 if self.ymax == None: self.ymax = ymax
591 if self.zmin == None: self.zmin = zmin
593 if self.zmin == None: self.zmin = zmin
592 if self.zmax == None: self.zmax = zmax
594 if self.zmax == None: self.zmax = zmax
593
595
594 self.__firsttime = False
596 self.__firsttime = False
595 return
597 return
596
598
597 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
598 self.z_buffer = numpy.hstack((self.z_buffer, z))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
599 z_buffer = self.z_buffer.reshape(-1,len(y))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
600
602
601 #Decimating data
603 #Decimating data
602 xlen = len(self.x_buffer)
604 xlen = len(self.x_buffer)
603 ylen = len(y)
605 ylen = len(y)
604
606
605 decimationx = numpy.floor(xlen/maxNumX) + 1
607 decimationx = numpy.floor(xlen/maxNumX) + 1
606 decimationy = numpy.floor(ylen/maxNumY) + 1
608 decimationy = numpy.floor(ylen/maxNumY) + 1
607
609
608 x_buffer = self.x_buffer[::decimationx]
610 x_buffer = self.x_buffer[::decimationx]
609 y_buffer = y[::decimationy]
611 y_buffer = y[::decimationy]
610 z_buffer = z_buffer[::decimationx, ::decimationy]
612 z_buffer = z_buffer[::decimationx, ::decimationy]
611 #===================================================
613 #===================================================
612
614
613 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
614
616
615 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
616 xlabel=xlabel,
618 xlabel=xlabel,
617 ylabel=ylabel,
619 ylabel=ylabel,
618 title=title,
620 title=title,
619 colormap=colormap)
621 colormap=colormap)
620
622
621 # self.__driver.pause()
623 # self.__driver.pause()
622
624
623 def polar(self, x, y,
625 def polar(self, x, y,
624 title='', xlabel='',ylabel='',**kwargs):
626 title='', xlabel='',ylabel='',**kwargs):
625
627
626 if self.__firsttime:
628 if self.__firsttime:
627 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
628 self.__firsttime = False
630 self.__firsttime = False
629 self.x_buffer = x
631 self.x_buffer = x
630 self.y_buffer = y
632 self.y_buffer = y
631 return
633 return
632
634
633 self.x_buffer = numpy.hstack((self.x_buffer,x))
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
634 self.y_buffer = numpy.hstack((self.y_buffer,y))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
635 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
636 ylabel=ylabel,
638 ylabel=ylabel,
637 title=title)
639 title=title)
638
640
639 # self.__driver.pause()
641 # self.__driver.pause()
640
642
641 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
642
644
643 if x_buffer.shape[0] < 2:
645 if x_buffer.shape[0] < 2:
644 return x_buffer, y_buffer, z_buffer
646 return x_buffer, y_buffer, z_buffer
645
647
646 deltas = x_buffer[1:] - x_buffer[0:-1]
648 deltas = x_buffer[1:] - x_buffer[0:-1]
647 x_median = numpy.median(deltas)
649 x_median = numpy.median(deltas)
648
650
649 index = numpy.where(deltas > 5*x_median)
651 index = numpy.where(deltas > 5*x_median)
650
652
651 if len(index[0]) != 0:
653 if len(index[0]) != 0:
652 z_buffer[index[0],::] = self.__missing
654 z_buffer[index[0],::] = self.__missing
653 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
654
656
655 return x_buffer, y_buffer, z_buffer
657 return x_buffer, y_buffer, z_buffer
656
658
657
659
658
660
659 No newline at end of file
661
General Comments 0
You need to be logged in to leave comments. Login now