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