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