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