@@ -1,883 +1,883 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 |
@autor $Author |
|
|
5 | @version $Id: BaseGraph.py 117 2012-09-04 21:16:59Z dsuarez $ | |
|
4 | @autor $Author$ | |
|
5 | @version $Id$ | |
|
6 | 6 | |
|
7 | 7 | ''' |
|
8 | 8 | |
|
9 | 9 | import numpy |
|
10 | 10 | |
|
11 | 11 | import time |
|
12 | 12 | import datetime |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | import matplotlib as mpl |
|
16 | 16 | mpl.use('TKAgg') |
|
17 | 17 | import matplotlib.pyplot as plt |
|
18 | 18 | |
|
19 | 19 | import scitools.numpyutils as sn |
|
20 | 20 | |
|
21 | 21 | def cmap1_init(colormap='gray'): |
|
22 | 22 | pass |
|
23 | 23 | |
|
24 | 24 | def setColormap(colormap='jet'): |
|
25 | 25 | pass |
|
26 | 26 | |
|
27 | 27 | def savePlplot(filename,width,height): |
|
28 | 28 | pass |
|
29 | 29 | |
|
30 | 30 | def initMatplotlib(indexFig,ncol,nrow,winTitle,width,height): |
|
31 | 31 | |
|
32 | 32 | plt.ioff() |
|
33 | 33 | fig = plt.figure(indexFig) |
|
34 | 34 | fig.canvas.manager.set_window_title(winTitle) |
|
35 | 35 | fig.canvas.manager.resize(width,height) |
|
36 | 36 | # fig.add_subplot(nrow,ncol,1) |
|
37 | 37 | plt.ion() |
|
38 | 38 | |
|
39 | 39 | def setNewPage(): |
|
40 | 40 | plt.clf() |
|
41 | 41 | |
|
42 | 42 | def closePage(): |
|
43 | 43 | pass |
|
44 | 44 | |
|
45 | 45 | def clearData(objGraph): |
|
46 | 46 | objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bc', 'bc') |
|
47 | 47 | |
|
48 | 48 | objGraph.setColor(15) #Setting Line Color to White |
|
49 | 49 | |
|
50 | 50 | if objGraph.datatype == 'complex': |
|
51 | 51 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real) |
|
52 | 52 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag) |
|
53 | 53 | |
|
54 | 54 | if objGraph.datatype == 'real': |
|
55 | 55 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata) |
|
56 | 56 | |
|
57 | 57 | objGraph.setColor(1) |
|
58 | 58 | |
|
59 | 59 | def setFigure(indexFig): |
|
60 | 60 | plt.figure(indexFig) |
|
61 | 61 | |
|
62 | 62 | def refresh(): |
|
63 | 63 | plt.draw() |
|
64 | 64 | |
|
65 | 65 | def show(): |
|
66 | 66 | plt.ioff() |
|
67 | 67 | plt.show() |
|
68 | 68 | plt.ion() |
|
69 | 69 | |
|
70 | 70 | def setPlTitle(pltitle,color, szchar=0.7): |
|
71 | 71 | pass |
|
72 | 72 | |
|
73 | 73 | def setSubpages(ncol,nrow): |
|
74 | 74 | pass |
|
75 | 75 | |
|
76 | 76 | class BaseGraph: |
|
77 | 77 | |
|
78 | 78 | __name = None |
|
79 | 79 | __xpos = None |
|
80 | 80 | __ypos = None |
|
81 | 81 | __subplot = None |
|
82 | 82 | __xg = None |
|
83 | 83 | __yg = None |
|
84 | 84 | __axesId = None |
|
85 | 85 | xdata = None |
|
86 | 86 | ydata = None |
|
87 | 87 | getGrid = True |
|
88 | 88 | xaxisIsTime = False |
|
89 | 89 | deltax = None |
|
90 | 90 | xmin = None |
|
91 | 91 | xmax = None |
|
92 | 92 | |
|
93 | 93 | def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0): |
|
94 | 94 | |
|
95 | 95 | self.setName(name) |
|
96 | 96 | self.setScreenPos(xpos, ypos) |
|
97 | 97 | self.setSubPlot(subplot) |
|
98 | 98 | self.setXYZrange(xrange,yrange,zrange) |
|
99 | 99 | self.setSizeOfChar(szchar) |
|
100 | 100 | self.setLabels(xlabel,ylabel,title) |
|
101 | 101 | self.getGrid = True |
|
102 | 102 | self.xaxisIsTime = False |
|
103 | 103 | self.deltax = deltax |
|
104 | 104 | pass |
|
105 | 105 | |
|
106 | 106 | def makeAxes(self,indexFig,nrow,ncol,subplot): |
|
107 | 107 | fig = plt.figure(indexFig) |
|
108 | 108 | self.__axesId = fig.add_subplot(nrow,ncol,subplot) |
|
109 | 109 | |
|
110 | 110 | def setParentAxesId(self,parent): |
|
111 | 111 | self.__axesId = parent.__axesId |
|
112 | 112 | |
|
113 | 113 | def setName(self, name): |
|
114 | 114 | self.__name = name |
|
115 | 115 | |
|
116 | 116 | def setScreenPos(self,xpos,ypos): |
|
117 | 117 | self.__xpos = xpos |
|
118 | 118 | self.__ypos = ypos |
|
119 | 119 | |
|
120 | 120 | def setSubPlot(self,subplot): |
|
121 | 121 | self.__subplot = subplot |
|
122 | 122 | |
|
123 | 123 | def setXYZrange(self,xrange,yrange,zrange): |
|
124 | 124 | self.xrange = xrange |
|
125 | 125 | self.yrange = yrange |
|
126 | 126 | self.zrange = zrange |
|
127 | 127 | |
|
128 | 128 | def setSizeOfChar(self,szchar): |
|
129 | 129 | self.__szchar = szchar |
|
130 | 130 | |
|
131 | 131 | def setLabels(self,xlabel=None,ylabel=None,title=None): |
|
132 | 132 | if xlabel != None: self.xlabel = xlabel |
|
133 | 133 | if ylabel != None: self.ylabel = ylabel |
|
134 | 134 | if title != None: self.title = title |
|
135 | 135 | |
|
136 | 136 | def setXYData(self,xdata=None,ydata=None,datatype='real'): |
|
137 | 137 | if ((xdata != None) and (ydata != None)): |
|
138 | 138 | self.xdata = xdata |
|
139 | 139 | self.ydata = ydata |
|
140 | 140 | self.datatype = datatype |
|
141 | 141 | if ((self.xdata == None) and (self.ydata == None)): |
|
142 | 142 | return None |
|
143 | 143 | return 1 |
|
144 | 144 | |
|
145 | 145 | def setLineStyle(self, style): |
|
146 | 146 | pass |
|
147 | 147 | |
|
148 | 148 | def setColor(self, color): |
|
149 | 149 | pass |
|
150 | 150 | |
|
151 | 151 | def setXAxisAsTime(self, value=False): |
|
152 | 152 | self.xaxisIsTime = value |
|
153 | 153 | |
|
154 | 154 | def basicLineTimePlot(self, x, y, colline=1): |
|
155 | 155 | ax = self.__axesId |
|
156 | 156 | if self.setXYData() == None: |
|
157 | 157 | ax.plot(x,y) |
|
158 | 158 | plt.tight_layout() |
|
159 | 159 | else: |
|
160 | 160 | ax.lines[0].set_data(x,y) |
|
161 | 161 | |
|
162 | 162 | def basicXYPlot(self, x, y): |
|
163 | 163 | ax = self.__axesId |
|
164 | 164 | if self.setXYData() == None: |
|
165 | 165 | ax.plot(x,y) |
|
166 | 166 | else: |
|
167 | 167 | ax.lines[0].set_data(x,y) |
|
168 | 168 | |
|
169 | 169 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
170 | 170 | pass |
|
171 | 171 | |
|
172 | 172 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
173 | 173 | pass |
|
174 | 174 | |
|
175 | 175 | def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True): |
|
176 | 176 | ax = self.__axesId |
|
177 | 177 | ax.pcolormesh(x,y,data.T,vmin=zmin,vmax=zmax) |
|
178 | 178 | |
|
179 | 179 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): |
|
180 | 180 | ax = self.__axesId |
|
181 | 181 | cax, kw = mpl.colorbar.make_axes(ax) |
|
182 | 182 | norm = mpl.colors.Normalize(vmin=ymin, vmax=ymax) |
|
183 | 183 | cb = mpl.colorbar.ColorbarBase(cax,norm=norm,**kw) |
|
184 | 184 | self.__colorbarId = cb |
|
185 | 185 | cb.set_label(self.title) |
|
186 | 186 | |
|
187 | 187 | def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False): |
|
188 | 188 | ax = self.__axesId |
|
189 | 189 | ax.set_xlim([xmin,xmax]) |
|
190 | 190 | ax.set_ylim([ymin,ymax]) |
|
191 | 191 | |
|
192 | 192 | if not(nolabels): |
|
193 | 193 | ax.set_xlabel(self.xlabel) |
|
194 | 194 | ax.set_ylabel(self.ylabel) |
|
195 | 195 | ax.set_title(self.title) |
|
196 | 196 | |
|
197 | 197 | def delLabels(self): |
|
198 | 198 | pass |
|
199 | 199 | |
|
200 | 200 | def plotImage(self,x,y,z,xrange,yrange,zrange): |
|
201 | 201 | pass |
|
202 | 202 | |
|
203 | 203 | |
|
204 | 204 | class LinearPlot(): |
|
205 | 205 | linearObjDic = {} |
|
206 | 206 | __xpos = None |
|
207 | 207 | __ypos = None |
|
208 | 208 | isPlotIni = None |
|
209 | 209 | |
|
210 | 210 | def __init__(self, indexFig,nsubplot,winTitle): |
|
211 | 211 | self.width = 700 |
|
212 | 212 | self.height = 150 |
|
213 | 213 | self.indexFig = indexFig |
|
214 | 214 | self.ncol = 1 |
|
215 | 215 | self.nrow = nsubplot |
|
216 | 216 | initMatplotlib(indexFig,self.ncol,self.nrow,winTitle,self.width,self.height) |
|
217 | 217 | |
|
218 | 218 | self.isPlotIni = False |
|
219 | 219 | |
|
220 | 220 | |
|
221 | 221 | def setFigure(self,indexFig): |
|
222 | 222 | setFigure(indexFig) |
|
223 | 223 | |
|
224 | 224 | def setNewPage(self, pltitle='No title'): |
|
225 | 225 | szchar = 0.7 |
|
226 | 226 | # setNewPage() |
|
227 | 227 | setPlTitle(pltitle,'black', szchar=szchar) |
|
228 | 228 | setSubpages(self.ncol, self.nrow) |
|
229 | 229 | |
|
230 | 230 | def setPosition(self): |
|
231 | 231 | xi = 0.07; xf = 0.9 |
|
232 | 232 | yi = 0.15; yf = 0.8 |
|
233 | 233 | |
|
234 | 234 | xpos = [xi,xf] |
|
235 | 235 | ypos = [yi,yf] |
|
236 | 236 | |
|
237 | 237 | self.__xpos = xpos |
|
238 | 238 | self.__ypos = ypos |
|
239 | 239 | |
|
240 | 240 | return xpos,ypos |
|
241 | 241 | |
|
242 | 242 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel): |
|
243 | 243 | szchar = 0.7 |
|
244 | 244 | name = 'linear' |
|
245 | 245 | key = name + '%d'%subplot |
|
246 | 246 | xrange = [xmin,xmax] |
|
247 | 247 | yrange = [ymin,ymax] |
|
248 | 248 | |
|
249 | 249 | xpos,ypos = self.setPosition() |
|
250 | 250 | linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange) |
|
251 | 251 | self.linearObjDic[key] = linearObj |
|
252 | 252 | |
|
253 | 253 | def iniPlot(self,subplot): |
|
254 | 254 | name = 'linear' |
|
255 | 255 | key = name + '%d'%subplot |
|
256 | 256 | |
|
257 | 257 | linearObj = self.linearObjDic[key] |
|
258 | 258 | linearObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
259 | 259 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcnst', 'bcnstv') |
|
260 | 260 | |
|
261 | 261 | |
|
262 | 262 | def plot(self,subplot,x,y,type='abs'): |
|
263 | 263 | name = 'linear' |
|
264 | 264 | key = name + '%d'%subplot |
|
265 | 265 | |
|
266 | 266 | linearObj = self.linearObjDic[key] |
|
267 | 267 | |
|
268 | 268 | if type.lower() == 'simple': |
|
269 | 269 | colline = 9 |
|
270 | 270 | linearObj.basicLineTimePlot(x, y) |
|
271 | 271 | linearObj.setXYData(x,y,'real') |
|
272 | 272 | |
|
273 | 273 | def refresh(self): |
|
274 | 274 | refresh() |
|
275 | 275 | |
|
276 | 276 | def show(self): |
|
277 | 277 | show() |
|
278 | 278 | |
|
279 | 279 | class PcolorPlot: |
|
280 | 280 | |
|
281 | 281 | pcolorObjDic = {} |
|
282 | 282 | colorbarObjDic = {} |
|
283 | 283 | pwprofileObjDic = {} |
|
284 | 284 | showColorbar = None |
|
285 | 285 | showPowerProfile = None |
|
286 | 286 | XAxisAsTime = None |
|
287 | 287 | width = None |
|
288 | 288 | height = None |
|
289 | 289 | __spcxpos = None |
|
290 | 290 | __spcypos = None |
|
291 | 291 | __cmapxpos = None |
|
292 | 292 | __cmapypos = None |
|
293 | 293 | __profxpos = None |
|
294 | 294 | __profypos = None |
|
295 | 295 | __lastTitle = None |
|
296 | 296 | |
|
297 | 297 | def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
298 | 298 | |
|
299 | 299 | self.width = 460 |
|
300 | 300 | self.height = 300 |
|
301 | 301 | self.showColorbar = showColorbar |
|
302 | 302 | self.showPowerProfile = showPowerProfile |
|
303 | 303 | self.XAxisAsTime = XAxisAsTime |
|
304 | 304 | |
|
305 | 305 | ncol = int(numpy.sqrt(nsubplot)+0.9) |
|
306 | 306 | nrow = int(nsubplot*1./ncol + 0.9) |
|
307 | 307 | |
|
308 | 308 | self.ncol = ncol |
|
309 | 309 | self.nrow = nrow |
|
310 | 310 | self.indexFig = indexFig |
|
311 | 311 | |
|
312 | 312 | initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height) |
|
313 | 313 | setColormap(colormap) |
|
314 | 314 | |
|
315 | 315 | def setFigure(self,indexFig): |
|
316 | 316 | setFigure(indexFig) |
|
317 | 317 | |
|
318 | 318 | def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile |
|
319 | 319 | if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075 |
|
320 | 320 | else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5 |
|
321 | 321 | yi = 0.15; yf = 0.80 |
|
322 | 322 | |
|
323 | 323 | xpos = [xi,xf] |
|
324 | 324 | ypos = [yi,yf] |
|
325 | 325 | |
|
326 | 326 | self.__spcxpos = xpos |
|
327 | 327 | self.__spcypos = ypos |
|
328 | 328 | |
|
329 | 329 | return xpos,ypos |
|
330 | 330 | |
|
331 | 331 | def setColorbarScreenPos(self): |
|
332 | 332 | |
|
333 | 333 | xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03 |
|
334 | 334 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
335 | 335 | |
|
336 | 336 | xpos = [xi,xf] |
|
337 | 337 | ypos = [yi,yf] |
|
338 | 338 | |
|
339 | 339 | self.__cmapxpos = xpos |
|
340 | 340 | self.__cmapypos = ypos |
|
341 | 341 | |
|
342 | 342 | return xpos,ypos |
|
343 | 343 | |
|
344 | 344 | def setPowerprofileScreenPos(self): |
|
345 | 345 | |
|
346 | 346 | xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25 |
|
347 | 347 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
348 | 348 | |
|
349 | 349 | xpos = [xi,xf] |
|
350 | 350 | ypos = [yi,yf] |
|
351 | 351 | |
|
352 | 352 | self.__profxpos = [xi,xf] |
|
353 | 353 | self.__profypos = [yi,yf] |
|
354 | 354 | |
|
355 | 355 | return xpos,ypos |
|
356 | 356 | |
|
357 | 357 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel): |
|
358 | 358 | |
|
359 | 359 | ''' |
|
360 | 360 | Crea los objetos necesarios para un subplot |
|
361 | 361 | ''' |
|
362 | 362 | |
|
363 | 363 | # Config Spectra plot |
|
364 | 364 | |
|
365 | 365 | szchar = 0.7 |
|
366 | 366 | name = 'spc' |
|
367 | 367 | key = name + '%d'%subplot |
|
368 | 368 | xrange = [xmin,xmax] |
|
369 | 369 | yrange = [ymin,ymax] |
|
370 | 370 | zrange = [zmin,zmax] |
|
371 | 371 | |
|
372 | 372 | xpos,ypos = self.setSpectraPos() |
|
373 | 373 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange) |
|
374 | 374 | #pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
375 | 375 | self.pcolorObjDic[key] = pcolorObj |
|
376 | 376 | |
|
377 | 377 | # Config Colorbar |
|
378 | 378 | if self.showColorbar: |
|
379 | 379 | szchar = 0.65 |
|
380 | 380 | name = 'colorbar' |
|
381 | 381 | key = name + '%d'%subplot |
|
382 | 382 | |
|
383 | 383 | xpos,ypos = self.setColorbarScreenPos() |
|
384 | 384 | xrange = [0.,1.] |
|
385 | 385 | yrange = [zmin,zmax] |
|
386 | 386 | cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange) |
|
387 | 387 | self.colorbarObjDic[key] = cmapObj |
|
388 | 388 | |
|
389 | 389 | # Config Power profile |
|
390 | 390 | if self.showPowerProfile: |
|
391 | 391 | szchar = 0.55 |
|
392 | 392 | name = 'pwprofile' |
|
393 | 393 | key = name + '%d'%subplot |
|
394 | 394 | |
|
395 | 395 | xpos,ypos = self.setPowerprofileScreenPos() |
|
396 | 396 | xrange = [zmin,zmax] |
|
397 | 397 | yrange = [ymin,ymax] |
|
398 | 398 | powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange) |
|
399 | 399 | #powObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
400 | 400 | self.pwprofileObjDic[key] = powObj |
|
401 | 401 | |
|
402 | 402 | def setNewPage(self, pltitle='No title'): |
|
403 | 403 | szchar = 0.7 |
|
404 | 404 | setNewPage() |
|
405 | 405 | setPlTitle(pltitle,'black', szchar=szchar) |
|
406 | 406 | setSubpages(self.ncol, self.nrow) |
|
407 | 407 | |
|
408 | 408 | def closePage(self): |
|
409 | 409 | closePage() |
|
410 | 410 | |
|
411 | 411 | def show(self): |
|
412 | 412 | show() |
|
413 | 413 | |
|
414 | 414 | def iniPlot(self,subplot): |
|
415 | 415 | ''' |
|
416 | 416 | Inicializa los subplots con su frame, titulo, etc |
|
417 | 417 | ''' |
|
418 | 418 | |
|
419 | 419 | # Config Spectra plot |
|
420 | 420 | name = 'spc' |
|
421 | 421 | key = name + '%d'%subplot |
|
422 | 422 | |
|
423 | 423 | pcolorObj = self.pcolorObjDic[key] |
|
424 | 424 | pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
425 | 425 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcnst', 'bcnstv') |
|
426 | 426 | |
|
427 | 427 | # Config Colorbar |
|
428 | 428 | if self.showColorbar: |
|
429 | 429 | name = 'colorbar' |
|
430 | 430 | key = name + '%d'%subplot |
|
431 | 431 | |
|
432 | 432 | cmapObj = self.colorbarObjDic[key] |
|
433 | 433 | cmapObj.setParentAxesId(pcolorObj) |
|
434 | 434 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') |
|
435 | 435 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
436 | 436 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') |
|
437 | 437 | |
|
438 | 438 | # Config Power profile |
|
439 | 439 | if self.showPowerProfile: |
|
440 | 440 | name = 'pwprofile' |
|
441 | 441 | key = name + '%d'%subplot |
|
442 | 442 | |
|
443 | 443 | powObj = self.pwprofileObjDic[key] |
|
444 | 444 | powObj.setLineStyle(2) |
|
445 | 445 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
446 | 446 | powObj.setLineStyle(1) |
|
447 | 447 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
448 | 448 | |
|
449 | 449 | def printTitle(self,pltitle): |
|
450 | 450 | |
|
451 | 451 | setPlTitle(pltitle,'black') |
|
452 | 452 | |
|
453 | 453 | def plot(self,subplot,x,y,z,subtitle=''): |
|
454 | 454 | # Spectra plot |
|
455 | 455 | |
|
456 | 456 | name = 'spc' |
|
457 | 457 | key = name + '%d'%subplot |
|
458 | 458 | |
|
459 | 459 | # newx = [x[0],x[-1]] |
|
460 | 460 | pcolorObj = self.pcolorObjDic[key] |
|
461 | 461 | # pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst') |
|
462 | 462 | |
|
463 | 463 | #pcolorObj.delLabels() |
|
464 | 464 | pcolorObj.setLabels(title=subtitle) |
|
465 | 465 | |
|
466 | 466 | deltax = None; deltay = None |
|
467 | 467 | |
|
468 | 468 | pcolorObj.advPcolorPlot(z, |
|
469 | 469 | x, |
|
470 | 470 | y, |
|
471 | 471 | xmin=pcolorObj.xrange[0], |
|
472 | 472 | xmax=pcolorObj.xrange[1], |
|
473 | 473 | ymin=pcolorObj.yrange[0], |
|
474 | 474 | ymax=pcolorObj.yrange[1], |
|
475 | 475 | zmin=pcolorObj.zrange[0], |
|
476 | 476 | zmax=pcolorObj.zrange[1], |
|
477 | 477 | deltax=deltax, |
|
478 | 478 | deltay=deltay, |
|
479 | 479 | getGrid=pcolorObj.getGrid) |
|
480 | 480 | |
|
481 | 481 | #Solo se calcula la primera vez que se ingresa a la funcion |
|
482 | 482 | pcolorObj.getGrid = False |
|
483 | 483 | |
|
484 | 484 | #pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst', nolabels=True) |
|
485 | 485 | |
|
486 | 486 | # Power Profile |
|
487 | 487 | if self.showPowerProfile: |
|
488 | 488 | power = numpy.average(z, axis=0) |
|
489 | 489 | name = 'pwprofile' |
|
490 | 490 | key = name + '%d'%subplot |
|
491 | 491 | powObj = self.pwprofileObjDic[key] |
|
492 | 492 | |
|
493 | 493 | if powObj.setXYData() != None: |
|
494 | 494 | #clearData(powObj) |
|
495 | 495 | powObj.setLineStyle(2) |
|
496 | 496 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
497 | 497 | powObj.setLineStyle(1) |
|
498 | 498 | else: |
|
499 | 499 | powObj.setXYData(power,y) |
|
500 | 500 | |
|
501 | 501 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
502 | 502 | powObj.basicXYPlot(power,y) |
|
503 | 503 | powObj.setXYData(power,y) |
|
504 | 504 | |
|
505 | 505 | def savePlot(self,indexFig,filename): |
|
506 | 506 | |
|
507 | 507 | width = self.width*self.ncol |
|
508 | 508 | hei = self.height*self.nrow |
|
509 | 509 | savePlplot(filename,width,hei) |
|
510 | 510 | |
|
511 | 511 | def refresh(self): |
|
512 | 512 | refresh() |
|
513 | 513 | |
|
514 | 514 | class RtiPlot: |
|
515 | 515 | |
|
516 | 516 | pcolorObjDic = {} |
|
517 | 517 | colorbarObjDic = {} |
|
518 | 518 | pwprofileObjDic = {} |
|
519 | 519 | showColorbar = None |
|
520 | 520 | showPowerProfile = None |
|
521 | 521 | XAxisAsTime = None |
|
522 | 522 | widht = None |
|
523 | 523 | height = None |
|
524 | 524 | __rtixpos = None |
|
525 | 525 | __rtiypos = None |
|
526 | 526 | __cmapxpos = None |
|
527 | 527 | __cmapypos = None |
|
528 | 528 | __profxpos = None |
|
529 | 529 | __profypos = None |
|
530 | 530 | |
|
531 | 531 | def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
532 | 532 | self.width = 700 |
|
533 | 533 | self.height = 150 |
|
534 | 534 | self.showColorbar = showColorbar |
|
535 | 535 | self.showPowerProfile = showPowerProfile |
|
536 | 536 | self.XAxisAsTime = XAxisAsTime |
|
537 | 537 | |
|
538 | 538 | ncol = 1 |
|
539 | 539 | nrow = nsubplot |
|
540 | 540 | initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height) |
|
541 | 541 | setColormap(colormap) |
|
542 | 542 | self.ncol = ncol |
|
543 | 543 | self.nrow = nrow |
|
544 | 544 | |
|
545 | 545 | def setFigure(self,indexFig): |
|
546 | 546 | setFigure(indexFig) |
|
547 | 547 | |
|
548 | 548 | def setRtiScreenPos(self): |
|
549 | 549 | |
|
550 | 550 | if self.showPowerProfile: xi = 0.07; xf = 0.65 |
|
551 | 551 | else: xi = 0.07; xf = 0.9 |
|
552 | 552 | yi = 0.15; yf = 0.80 |
|
553 | 553 | |
|
554 | 554 | xpos = [xi,xf] |
|
555 | 555 | ypos = [yi,yf] |
|
556 | 556 | |
|
557 | 557 | self.__rtixpos = xpos |
|
558 | 558 | self.__rtiypos = ypos |
|
559 | 559 | |
|
560 | 560 | return xpos,ypos |
|
561 | 561 | |
|
562 | 562 | def setColorbarScreenPos(self): |
|
563 | 563 | |
|
564 | 564 | xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03 |
|
565 | 565 | |
|
566 | 566 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
567 | 567 | |
|
568 | 568 | xpos = [xi,xf] |
|
569 | 569 | ypos = [yi,yf] |
|
570 | 570 | |
|
571 | 571 | self.__cmapxpos = xpos |
|
572 | 572 | self.__cmapypos = ypos |
|
573 | 573 | |
|
574 | 574 | return xpos,ypos |
|
575 | 575 | |
|
576 | 576 | def setPowerprofileScreenPos(self): |
|
577 | 577 | |
|
578 | 578 | xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20 |
|
579 | 579 | |
|
580 | 580 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
581 | 581 | |
|
582 | 582 | xpos = [xi,xf] |
|
583 | 583 | ypos = [yi,yf] |
|
584 | 584 | |
|
585 | 585 | self.__profxpos = [xi,xf] |
|
586 | 586 | self.__profypos = [yi,yf] |
|
587 | 587 | |
|
588 | 588 | return xpos,ypos |
|
589 | 589 | |
|
590 | 590 | def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone='lt',npoints=100): |
|
591 | 591 | # Config Rti plot |
|
592 | 592 | szchar = 1.10 |
|
593 | 593 | name = 'rti' |
|
594 | 594 | key = name + '%d'%subplot |
|
595 | 595 | |
|
596 | 596 | # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal] |
|
597 | 597 | thisDateTime = datetime.datetime.fromtimestamp(timedata) |
|
598 | 598 | startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0) |
|
599 | 599 | endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59) |
|
600 | 600 | deltaTime = 0 |
|
601 | 601 | if timezone == 'lt': |
|
602 | 602 | deltaTime = time.timezone |
|
603 | 603 | startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime |
|
604 | 604 | endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime |
|
605 | 605 | |
|
606 | 606 | xrange = [startTimeInSecs,endTimeInSecs] |
|
607 | 607 | totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1. |
|
608 | 608 | deltax = totalTimeInXrange / npoints |
|
609 | 609 | |
|
610 | 610 | yrange = [ymin,ymax] |
|
611 | 611 | zrange = [zmin,zmax] |
|
612 | 612 | |
|
613 | 613 | xpos,ypos = self.setRtiScreenPos() |
|
614 | 614 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax) |
|
615 | 615 | if self.XAxisAsTime: |
|
616 | 616 | pcolorObj.setXAxisAsTime(self.XAxisAsTime) |
|
617 | 617 | xopt = 'bcnstd' |
|
618 | 618 | yopt = 'bcnstv' |
|
619 | 619 | else: |
|
620 | 620 | xopt = 'bcnst' |
|
621 | 621 | yopt = 'bcnstv' |
|
622 | 622 | |
|
623 | 623 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
624 | 624 | self.pcolorObjDic[key] = pcolorObj |
|
625 | 625 | |
|
626 | 626 | |
|
627 | 627 | # Config Colorbar |
|
628 | 628 | if self.showColorbar: |
|
629 | 629 | szchar = 0.9 |
|
630 | 630 | name = 'colorbar' |
|
631 | 631 | key = name + '%d'%subplot |
|
632 | 632 | |
|
633 | 633 | xpos,ypos = self.setColorbarScreenPos() |
|
634 | 634 | xrange = [0.,1.] |
|
635 | 635 | yrange = [zmin,zmax] |
|
636 | 636 | cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange) |
|
637 | 637 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcm') |
|
638 | 638 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
639 | 639 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') |
|
640 | 640 | self.colorbarObjDic[key] = cmapObj |
|
641 | 641 | |
|
642 | 642 | |
|
643 | 643 | # Config Power profile |
|
644 | 644 | if self.showPowerProfile: |
|
645 | 645 | szchar = 0.8 |
|
646 | 646 | name = 'pwprofile' |
|
647 | 647 | key = name + '%d'%subplot |
|
648 | 648 | |
|
649 | 649 | xpos,ypos = self.setPowerprofileScreenPos() |
|
650 | 650 | xrange = [zmin,zmax] |
|
651 | 651 | yrange = [ymin,ymax] |
|
652 | 652 | powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange) |
|
653 | 653 | powObj.setLineStyle(2) |
|
654 | 654 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
655 | 655 | powObj.setLineStyle(1) |
|
656 | 656 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
657 | 657 | self.pwprofileObjDic[key] = powObj |
|
658 | 658 | |
|
659 | 659 | |
|
660 | 660 | def plot(self,subplot,x,y,z): |
|
661 | 661 | # RTI plot |
|
662 | 662 | name = 'rti' |
|
663 | 663 | key = name + '%d'%subplot |
|
664 | 664 | |
|
665 | 665 | data = numpy.reshape(z, (1,-1)) |
|
666 | 666 | data = numpy.abs(data) |
|
667 | 667 | data = 10*numpy.log10(data) |
|
668 | 668 | newx = [x,x+1] |
|
669 | 669 | |
|
670 | 670 | pcolorObj = self.pcolorObjDic[key] |
|
671 | 671 | |
|
672 | 672 | if pcolorObj.xaxisIsTime: |
|
673 | 673 | xopt = 'bcstd' |
|
674 | 674 | yopt = 'bcst' |
|
675 | 675 | else: |
|
676 | 676 | xopt = 'bcst' |
|
677 | 677 | yopt = 'bcst' |
|
678 | 678 | |
|
679 | 679 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
680 | 680 | |
|
681 | 681 | deltax = pcolorObj.deltax |
|
682 | 682 | deltay = None |
|
683 | 683 | |
|
684 | 684 | if pcolorObj.xmin == None and pcolorObj.xmax == None: |
|
685 | 685 | pcolorObj.xmin = x |
|
686 | 686 | pcolorObj.xmax = x |
|
687 | 687 | |
|
688 | 688 | if x >= pcolorObj.xmax: |
|
689 | 689 | xmin = x |
|
690 | 690 | xmax = x + deltax |
|
691 | 691 | x = [x] |
|
692 | 692 | pcolorObj.advPcolorPlot(data, |
|
693 | 693 | x, |
|
694 | 694 | y, |
|
695 | 695 | xmin=xmin, |
|
696 | 696 | xmax=xmax, |
|
697 | 697 | ymin=pcolorObj.yrange[0], |
|
698 | 698 | ymax=pcolorObj.yrange[1], |
|
699 | 699 | zmin=pcolorObj.zrange[0], |
|
700 | 700 | zmax=pcolorObj.zrange[1], |
|
701 | 701 | deltax=deltax, |
|
702 | 702 | deltay=deltay, |
|
703 | 703 | getGrid=pcolorObj.getGrid) |
|
704 | 704 | |
|
705 | 705 | pcolorObj.xmin = xmin |
|
706 | 706 | pcolorObj.xmax = xmax |
|
707 | 707 | |
|
708 | 708 | |
|
709 | 709 | # Power Profile |
|
710 | 710 | if self.showPowerProfile: |
|
711 | 711 | data = numpy.reshape(data,(numpy.size(data))) |
|
712 | 712 | name = 'pwprofile' |
|
713 | 713 | key = name + '%d'%subplot |
|
714 | 714 | powObj = self.pwprofileObjDic[key] |
|
715 | 715 | |
|
716 | 716 | if powObj.setXYData() != None: |
|
717 | 717 | clearData(powObj) |
|
718 | 718 | powObj.setLineStyle(2) |
|
719 | 719 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
720 | 720 | powObj.setLineStyle(1) |
|
721 | 721 | else: |
|
722 | 722 | powObj.setXYData(data,y) |
|
723 | 723 | |
|
724 | 724 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
725 | 725 | powObj.basicXYPlot(data,y) |
|
726 | 726 | powObj.setXYData(data,y) |
|
727 | 727 | |
|
728 | 728 | def savePlot(self,indexFig,filename): |
|
729 | 729 | |
|
730 | 730 | width = self.width*self.ncol |
|
731 | 731 | hei = self.height*self.nrow |
|
732 | 732 | savePlplot(filename,width,hei) |
|
733 | 733 | |
|
734 | 734 | def refresh(self): |
|
735 | 735 | refresh() |
|
736 | 736 | |
|
737 | 737 | |
|
738 | 738 | if __name__ == '__main__': |
|
739 | 739 | |
|
740 | 740 | """ |
|
741 | 741 | Ejemplo1 |
|
742 | 742 | """ |
|
743 | 743 | #Setting the signal |
|
744 | 744 | fs = 8000 |
|
745 | 745 | f0 = 200 |
|
746 | 746 | f1 = 400 |
|
747 | 747 | T = 1./fs |
|
748 | 748 | x = numpy.arange(160) |
|
749 | 749 | y1 = numpy.sin(2*numpy.pi*f0*x*T) |
|
750 | 750 | y2 = numpy.sin(2*numpy.pi*f1*x*T) |
|
751 | 751 | signalList = [y1,y2] |
|
752 | 752 | |
|
753 | 753 | xmin = numpy.min(x) |
|
754 | 754 | xmax = numpy.max(x) |
|
755 | 755 | ymin = numpy.min(y1) - 10 |
|
756 | 756 | ymax = numpy.max(y1) + 10 |
|
757 | 757 | |
|
758 | 758 | subplotTitle = "subplot no. " |
|
759 | 759 | xlabel = "" |
|
760 | 760 | ylabel = "" |
|
761 | 761 | |
|
762 | 762 | indexFig = 1 |
|
763 | 763 | nsubplot = 2 |
|
764 | 764 | winTitle = "figura" |
|
765 | 765 | |
|
766 | 766 | isPlotIni = False |
|
767 | 767 | isPlotConfig = False |
|
768 | 768 | ntimes = 10 |
|
769 | 769 | |
|
770 | 770 | |
|
771 | 771 | # Instancia del objeto |
|
772 | 772 | linearObj = LinearPlot(indexFig,nsubplot,winTitle) |
|
773 | 773 | |
|
774 | 774 | |
|
775 | 775 | for i in range(ntimes): |
|
776 | 776 | # Crea los subplots |
|
777 | 777 | if not(linearObj.isPlotIni): |
|
778 | 778 | for index in range(nsubplot): |
|
779 | 779 | indexplot = index + 1 |
|
780 | 780 | title = subplotTitle + '%d'%indexplot |
|
781 | 781 | linearObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel) |
|
782 | 782 | linearObj.isPlotIni = True |
|
783 | 783 | |
|
784 | 784 | # Inicializa el grafico en cada iteracion |
|
785 | 785 | linearObj.setFigure(indexFig) |
|
786 | 786 | linearObj.setNewPage("") |
|
787 | 787 | |
|
788 | 788 | for index in range(nsubplot): |
|
789 | 789 | subplot = index |
|
790 | 790 | linearObj.iniPlot(subplot+1) |
|
791 | 791 | |
|
792 | 792 | #plotea los datos |
|
793 | 793 | for channel in range(nsubplot): |
|
794 | 794 | data = y1 + numpy.random.rand(len(y1)) |
|
795 | 795 | linearObj.plot(channel+1, x, data, type='simple') |
|
796 | 796 | |
|
797 | 797 | linearObj.refresh() |
|
798 | 798 | |
|
799 | 799 | # linearObj.closePage() #descomentar esta linea para mas iteraciones |
|
800 | 800 | |
|
801 | 801 | time.sleep(0.05) |
|
802 | 802 | |
|
803 | 803 | linearObj.show() |
|
804 | 804 | |
|
805 | 805 | print "example 1 completed" |
|
806 | 806 | |
|
807 | 807 | |
|
808 | 808 | |
|
809 | 809 | """ |
|
810 | 810 | Ejemplo2 |
|
811 | 811 | """ |
|
812 | 812 | |
|
813 | 813 | # make these smaller to increase the resolution |
|
814 | 814 | dx, dy = 0.05, 0.05 |
|
815 | 815 | x = numpy.arange(-3.0, 3.0001, dx) |
|
816 | 816 | y = numpy.arange(-2.0, 2.0001, dy) |
|
817 | 817 | # X,Y = numpy.meshgrid(x, y) |
|
818 | 818 | X,Y = sn.ndgrid(x, y) |
|
819 | 819 | Z = (1- X/2 + X**5 + Y**3)*numpy.exp(-X**2-Y**2) |
|
820 | 820 | |
|
821 | 821 | # Creating Object |
|
822 | 822 | indexPlot = 2 |
|
823 | 823 | nsubplot = 1 |
|
824 | 824 | winTitle = "mi grafico pcolor" |
|
825 | 825 | colormap = "br_green" |
|
826 | 826 | showColorbar = True |
|
827 | 827 | showPowerProfile = False |
|
828 | 828 | XAxisAsTime = False |
|
829 | 829 | |
|
830 | 830 | subplotTitle = "subplot no. " |
|
831 | 831 | xlabel = "" |
|
832 | 832 | ylabel = "" |
|
833 | 833 | |
|
834 | 834 | xmin = -3.0 |
|
835 | 835 | xmax = 3.0 |
|
836 | 836 | ymin = -2.0 |
|
837 | 837 | ymax = 2.0 |
|
838 | 838 | zmin = -0.3 |
|
839 | 839 | zmax = 1.0 |
|
840 | 840 | |
|
841 | 841 | isPlotIni = False |
|
842 | 842 | isPlotConfig = False |
|
843 | 843 | ntimes = 10 |
|
844 | 844 | |
|
845 | 845 | |
|
846 | 846 | for i in range(ntimes): |
|
847 | 847 | |
|
848 | 848 | # Instancia del objeto |
|
849 | 849 | if not(isPlotConfig): |
|
850 | 850 | pcolorObj = PcolorPlot(indexPlot, nsubplot, winTitle, colormap, showColorbar, showPowerProfile, XAxisAsTime) |
|
851 | 851 | isPlotConfig = True |
|
852 | 852 | |
|
853 | 853 | # Crea los subplots |
|
854 | 854 | if not(isPlotIni): |
|
855 | 855 | for index in range(nsubplot): |
|
856 | 856 | indexplot = index + 1 |
|
857 | 857 | title = subplotTitle + '%d'%indexplot |
|
858 | 858 | subplot = index |
|
859 | 859 | pcolorObj.createObjects(indexplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel) |
|
860 | 860 | isPlotIni = True |
|
861 | 861 | |
|
862 | 862 | # Inicializa el grafico en cada iteracion |
|
863 | 863 | pcolorObj.setFigure(indexPlot) |
|
864 | 864 | pcolorObj.setNewPage("") |
|
865 | 865 | |
|
866 | 866 | for index in range(nsubplot): |
|
867 | 867 | subplot = index |
|
868 | 868 | pcolorObj.iniPlot(subplot+1) |
|
869 | 869 | |
|
870 | 870 | #plotea los datos |
|
871 | 871 | for channel in range(nsubplot): |
|
872 | 872 | data = Z+0.1*numpy.random.randn(len(x),len(y)) |
|
873 | 873 | pcolorObj.plot(channel+1, x, y, data) |
|
874 | 874 | |
|
875 | 875 | pcolorObj.refresh() |
|
876 | 876 | |
|
877 | 877 | # pcolorObj.closePage() #descomentar esta linea para mas iteraciones |
|
878 | 878 | |
|
879 | 879 | time.sleep(1) |
|
880 | 880 | |
|
881 | 881 | pcolorObj.show() |
|
882 | 882 | |
|
883 | 883 | print "example 2 completed" No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now