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