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