@@ -1,1018 +1,1078 | |||
|
1 | 1 | """ |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @autor $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | |
|
7 | 7 | """ |
|
8 | 8 | import os |
|
9 | 9 | import numpy |
|
10 | 10 | import sys |
|
11 | 11 | import time |
|
12 | 12 | import datetime |
|
13 | 13 | import time |
|
14 | 14 | import plplot |
|
15 | 15 | |
|
16 | 16 | |
|
17 | 17 | def cmap1_init(colormap="gray"): |
|
18 | 18 | |
|
19 | 19 | if colormap == None: |
|
20 | 20 | return |
|
21 | 21 | |
|
22 | 22 | ncolor = None |
|
23 | 23 | rgb_lvl = None |
|
24 | 24 | |
|
25 | 25 | # Routine for defining a specific color map 1 in HLS space. |
|
26 | 26 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
27 | 27 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
28 | 28 | |
|
29 | 29 | # Independent variable of control points. |
|
30 | 30 | i = numpy.array((0., 1.)) |
|
31 | 31 | if colormap=="gray": |
|
32 | 32 | ncolor = 256 |
|
33 | 33 | # Hue for control points. Doesn't matter since saturation is zero. |
|
34 | 34 | h = numpy.array((0., 0.)) |
|
35 | 35 | # Lightness ranging from half-dark (for interest) to light. |
|
36 | 36 | l = numpy.array((0.5, 1.)) |
|
37 | 37 | # Gray scale has zero saturation |
|
38 | 38 | s = numpy.array((0., 0.)) |
|
39 | 39 | |
|
40 | 40 | # number of cmap1 colours is 256 in this case. |
|
41 | 41 | plplot.plscmap1n(ncolor) |
|
42 | 42 | # Interpolate between control points to set up cmap1. |
|
43 | 43 | plplot.plscmap1l(0, i, h, l, s) |
|
44 | 44 | |
|
45 | 45 | return None |
|
46 | 46 | |
|
47 | 47 | if colormap == 'jet': |
|
48 | 48 | ncolor = 256 |
|
49 | 49 | pos = numpy.zeros((ncolor)) |
|
50 | 50 | r = numpy.zeros((ncolor)) |
|
51 | 51 | g = numpy.zeros((ncolor)) |
|
52 | 52 | b = numpy.zeros((ncolor)) |
|
53 | 53 | |
|
54 | 54 | for i in range(ncolor): |
|
55 | 55 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 |
|
56 | 56 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 |
|
57 | 57 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 |
|
58 | 58 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 |
|
59 | 59 | |
|
60 | 60 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 |
|
61 | 61 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 |
|
62 | 62 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 |
|
63 | 63 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 |
|
64 | 64 | else: gf = 0.0 |
|
65 | 65 | |
|
66 | 66 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 |
|
67 | 67 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 |
|
68 | 68 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 |
|
69 | 69 | else: bf = 0 |
|
70 | 70 | |
|
71 | 71 | r[i] = rf |
|
72 | 72 | g[i] = gf |
|
73 | 73 | b[i] = bf |
|
74 | 74 | |
|
75 | 75 | pos[i] = float(i)/float(ncolor-1) |
|
76 | 76 | |
|
77 | 77 | |
|
78 | 78 | plplot.plscmap1n(ncolor) |
|
79 | 79 | plplot.plscmap1l(1, pos, r, g, b) |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | |
|
83 | 83 | if colormap=="br_green": |
|
84 | 84 | ncolor = 256 |
|
85 | 85 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
86 | 86 | h = numpy.array((240., 0.)) |
|
87 | 87 | # Lightness and saturation are constant (values taken from C example). |
|
88 | 88 | l = numpy.array((0.6, 0.6)) |
|
89 | 89 | s = numpy.array((0.8, 0.8)) |
|
90 | 90 | |
|
91 | 91 | # number of cmap1 colours is 256 in this case. |
|
92 | 92 | plplot.plscmap1n(ncolor) |
|
93 | 93 | # Interpolate between control points to set up cmap1. |
|
94 | 94 | plplot.plscmap1l(0, i, h, l, s) |
|
95 | 95 | |
|
96 | 96 | return None |
|
97 | 97 | |
|
98 | 98 | if colormap=="tricolor": |
|
99 | 99 | ncolor = 3 |
|
100 | 100 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
101 | 101 | h = numpy.array((240., 0.)) |
|
102 | 102 | # Lightness and saturation are constant (values taken from C example). |
|
103 | 103 | l = numpy.array((0.6, 0.6)) |
|
104 | 104 | s = numpy.array((0.8, 0.8)) |
|
105 | 105 | |
|
106 | 106 | # number of cmap1 colours is 256 in this case. |
|
107 | 107 | plplot.plscmap1n(ncolor) |
|
108 | 108 | # Interpolate between control points to set up cmap1. |
|
109 | 109 | plplot.plscmap1l(0, i, h, l, s) |
|
110 | 110 | |
|
111 | 111 | return None |
|
112 | 112 | |
|
113 | 113 | if colormap == 'rgb' or colormap == 'rgb666': |
|
114 | 114 | |
|
115 | 115 | color_sz = 6 |
|
116 | 116 | ncolor = color_sz*color_sz*color_sz |
|
117 | 117 | pos = numpy.zeros((ncolor)) |
|
118 | 118 | r = numpy.zeros((ncolor)) |
|
119 | 119 | g = numpy.zeros((ncolor)) |
|
120 | 120 | b = numpy.zeros((ncolor)) |
|
121 | 121 | ind = 0 |
|
122 | 122 | for ri in range(color_sz): |
|
123 | 123 | for gi in range(color_sz): |
|
124 | 124 | for bi in range(color_sz): |
|
125 | 125 | r[ind] = ri/(color_sz-1.0) |
|
126 | 126 | g[ind] = gi/(color_sz-1.0) |
|
127 | 127 | b[ind] = bi/(color_sz-1.0) |
|
128 | 128 | pos[ind] = ind/(ncolor-1.0) |
|
129 | 129 | ind += 1 |
|
130 | 130 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
131 | 131 | |
|
132 | 132 | if colormap == 'rgb676': |
|
133 | 133 | ncolor = 6*7*6 |
|
134 | 134 | pos = numpy.zeros((ncolor)) |
|
135 | 135 | r = numpy.zeros((ncolor)) |
|
136 | 136 | g = numpy.zeros((ncolor)) |
|
137 | 137 | b = numpy.zeros((ncolor)) |
|
138 | 138 | ind = 0 |
|
139 | 139 | for ri in range(8): |
|
140 | 140 | for gi in range(8): |
|
141 | 141 | for bi in range(4): |
|
142 | 142 | r[ind] = ri/(6-1.0) |
|
143 | 143 | g[ind] = gi/(7-1.0) |
|
144 | 144 | b[ind] = bi/(6-1.0) |
|
145 | 145 | pos[ind] = ind/(ncolor-1.0) |
|
146 | 146 | ind += 1 |
|
147 | 147 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
148 | 148 | |
|
149 | 149 | if colormap == 'rgb685': |
|
150 | 150 | ncolor = 6*8*5 |
|
151 | 151 | pos = numpy.zeros((ncolor)) |
|
152 | 152 | r = numpy.zeros((ncolor)) |
|
153 | 153 | g = numpy.zeros((ncolor)) |
|
154 | 154 | b = numpy.zeros((ncolor)) |
|
155 | 155 | ind = 0 |
|
156 | 156 | for ri in range(8): |
|
157 | 157 | for gi in range(8): |
|
158 | 158 | for bi in range(4): |
|
159 | 159 | r[ind] = ri/(6-1.0) |
|
160 | 160 | g[ind] = gi/(8-1.0) |
|
161 | 161 | b[ind] = bi/(5-1.0) |
|
162 | 162 | pos[ind] = ind/(ncolor-1.0) |
|
163 | 163 | ind += 1 |
|
164 | 164 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
165 | 165 | |
|
166 | 166 | if colormap == 'rgb884': |
|
167 | 167 | ncolor = 8*8*4 |
|
168 | 168 | pos = numpy.zeros((ncolor)) |
|
169 | 169 | r = numpy.zeros((ncolor)) |
|
170 | 170 | g = numpy.zeros((ncolor)) |
|
171 | 171 | b = numpy.zeros((ncolor)) |
|
172 | 172 | ind = 0 |
|
173 | 173 | for ri in range(8): |
|
174 | 174 | for gi in range(8): |
|
175 | 175 | for bi in range(4): |
|
176 | 176 | r[ind] = ri/(8-1.0) |
|
177 | 177 | g[ind] = gi/(8-1.0) |
|
178 | 178 | b[ind] = bi/(4-1.0) |
|
179 | 179 | pos[ind] = ind/(ncolor-1.0) |
|
180 | 180 | ind += 1 |
|
181 | 181 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
182 | 182 | |
|
183 | 183 | if ncolor == None: |
|
184 | 184 | raise ValueError, "The colormap selected is not valid" |
|
185 | 185 | |
|
186 | 186 | plplot.plscmap1n(ncolor) |
|
187 | 187 | plplot.plscmap1l(1, pos, r, g, b) |
|
188 | 188 | |
|
189 | 189 | return rgb_lvl |
|
190 | 190 | |
|
191 | 191 | def setColormap(colormap="jet"): |
|
192 | 192 | cmap1_init(colormap) |
|
193 | 193 | |
|
194 | 194 | def savePlplot(filename,width,height): |
|
195 | 195 | curr_strm = plplot.plgstrm() |
|
196 | 196 | save_strm = plplot.plmkstrm() |
|
197 | 197 | plplot.plsetopt("geometry", "%dx%d"%(width,height)) |
|
198 | 198 | plplot.plsdev("png") |
|
199 | 199 | plplot.plsfnam(filename) |
|
200 | 200 | plplot.plcpstrm(curr_strm,0) |
|
201 | 201 | plplot.plreplot() |
|
202 | 202 | plplot.plend1() |
|
203 | 203 | plplot.plsstrm(curr_strm) |
|
204 | 204 | |
|
205 | 205 | |
|
206 | 206 | def initPlplot(indexPlot,ncol,nrow,winTitle,width,height): |
|
207 | 207 | plplot.plsstrm(indexPlot) |
|
208 | 208 | plplot.plparseopts([winTitle],plplot.PL_PARSE_FULL) |
|
209 | 209 | plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow)) |
|
210 | 210 | plplot.plsdev("xwin") |
|
211 | 211 | plplot.plscolbg(255,255,255) |
|
212 | 212 | plplot.plscol0(1,0,0,0) |
|
213 | 213 | plplot.plinit() |
|
214 | 214 | plplot.plspause(False) |
|
215 | 215 | plplot.plssub(ncol,nrow) |
|
216 | 216 | |
|
217 | 217 | def setNewPage(): |
|
218 | 218 | plplot.plbop() |
|
219 | 219 | plplot.pladv(0) |
|
220 | 220 | |
|
221 | 221 | def closePage(): |
|
222 | 222 | plplot.pleop() |
|
223 | 223 | |
|
224 | 224 | def clearData(objGraph): |
|
225 | 225 | objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc") |
|
226 | 226 | |
|
227 | 227 | objGraph.setColor(15) #Setting Line Color to White |
|
228 | 228 | |
|
229 | 229 | if objGraph.datatype == "complex": |
|
230 | 230 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real) |
|
231 | 231 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag) |
|
232 | 232 | |
|
233 | 233 | if objGraph.datatype == "real": |
|
234 | 234 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata) |
|
235 | 235 | |
|
236 | 236 | objGraph.setColor(1) #Setting Line Color to Black |
|
237 | 237 | # objGraph.setLineStyle(2) |
|
238 | 238 | # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bcntg", "bc") |
|
239 | 239 | # objGraph.setLineStyle(1) |
|
240 | 240 | |
|
241 | 241 | def setStrm(indexPlot): |
|
242 | 242 | plplot.plsstrm(indexPlot) |
|
243 | 243 | |
|
244 | 244 | def plFlush(): |
|
245 | 245 | plplot.plflush() |
|
246 | ||
|
247 | def plShow(): | |
|
248 | plplot.plspause(True) | |
|
249 | plplot.plend() | |
|
246 | 250 | |
|
247 | 251 | def setPlTitle(pltitle,color, szchar=0.7): |
|
248 | 252 | setSubpages(1, 0) |
|
249 | 253 | plplot.pladv(0) |
|
250 | 254 | plplot.plvpor(0., 1., 0., 1.) |
|
251 | 255 | |
|
252 | 256 | if color == "black": |
|
253 | 257 | plplot.plcol0(1) |
|
254 | 258 | if color == "white": |
|
255 | 259 | plplot.plcol0(15) |
|
256 | 260 | |
|
257 | 261 | plplot.plschr(0.0,szchar) |
|
258 | 262 | plplot.plmtex("t",-1., 0.5, 0.5, pltitle) |
|
259 | 263 | |
|
260 | 264 | def setSubpages(ncol,nrow): |
|
261 | 265 | plplot.plssub(ncol,nrow) |
|
262 | 266 | |
|
263 | 267 | class BaseGraph: |
|
264 | 268 | |
|
265 | 269 | __name = None |
|
266 | 270 | __xpos = None |
|
267 | 271 | __ypos = None |
|
268 | 272 | __subplot = None |
|
269 | 273 | __xg = None |
|
270 | 274 | __yg = None |
|
271 | 275 | xdata = None |
|
272 | 276 | ydata = None |
|
273 | 277 | getGrid = True |
|
274 | 278 | xaxisIsTime = False |
|
275 | 279 | deltax = None |
|
276 | 280 | xmin = None |
|
277 | 281 | xmax = None |
|
278 | 282 | |
|
279 | 283 | def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0): |
|
280 | 284 | |
|
281 | 285 | self.setName(name) |
|
282 | 286 | self.setScreenPos(xpos, ypos) |
|
283 | 287 | self.setLabels(xlabel,ylabel,title) |
|
284 | 288 | self.setSubPlot(subplot) |
|
285 | 289 | self.setSizeOfChar(szchar) |
|
286 | 290 | self.setXYZrange(xrange,yrange,zrange) |
|
287 | 291 | self.getGrid = True |
|
288 | 292 | self.xaxisIsTime = False |
|
289 | 293 | self.deltax = deltax |
|
290 | 294 | |
|
291 | 295 | def setXYZrange(self,xrange,yrange,zrange): |
|
292 | 296 | self.xrange = xrange |
|
293 | 297 | self.yrange = yrange |
|
294 | 298 | self.zrange = zrange |
|
295 | 299 | |
|
296 | 300 | def setName(self, name): |
|
297 | 301 | self.__name = name |
|
298 | 302 | |
|
299 | 303 | def setScreenPos(self,xpos,ypos): |
|
300 | 304 | self.__xpos = xpos |
|
301 | 305 | self.__ypos = ypos |
|
302 | 306 | |
|
303 | 307 | def setXYData(self,xdata=None,ydata=None,datatype="real"): |
|
304 | 308 | if((xdata != None) and (ydata != None)): |
|
305 | 309 | self.xdata = xdata |
|
306 | 310 | self.ydata = ydata |
|
307 | 311 | self.datatype = datatype |
|
308 | 312 | |
|
309 | 313 | if((self.xdata == None) and (self.ydata == None)): |
|
310 | 314 | return None |
|
311 | 315 | |
|
312 | 316 | return 1 |
|
313 | 317 | |
|
314 | 318 | |
|
315 | 319 | def setLabels(self,xlabel=None,ylabel=None,title=None): |
|
316 | 320 | if xlabel != None: self.xlabel = xlabel |
|
317 | 321 | if ylabel != None: self.ylabel = ylabel |
|
318 | 322 | if title != None: self.title = title |
|
319 | 323 | |
|
320 | 324 | def setSubPlot(self,subplot): |
|
321 | 325 | self.__subplot = subplot |
|
322 | 326 | |
|
323 | 327 | def setSizeOfChar(self,szchar): |
|
324 | 328 | self.__szchar = szchar |
|
325 | 329 | |
|
326 | 330 | def setLineStyle(self,style): |
|
327 | 331 | plplot.pllsty(style) |
|
328 | 332 | |
|
329 | 333 | def setColor(self,color): |
|
330 | 334 | plplot.plcol0(color) |
|
331 | 335 | |
|
332 | 336 | def setXAxisAsTime(self,value=False): |
|
333 | 337 | self.xaxisIsTime = value |
|
334 | 338 | |
|
335 | 339 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
336 | 340 | |
|
337 | 341 | if xmin == None: xmin = x[0] |
|
338 | 342 | if xmax == None: xmax = x[-1] |
|
339 | 343 | if ymin == None: ymin = y[0] |
|
340 | 344 | if ymax == None: ymax = y[-1] |
|
341 | 345 | |
|
342 | 346 | plplot.plcol0(colline) |
|
343 | 347 | plplot.plline(x, y) |
|
344 | 348 | plplot.plcol0(1) |
|
345 | 349 | |
|
346 | 350 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): |
|
347 | 351 | |
|
348 | 352 | if xmin == None: xmin = x[0] |
|
349 | 353 | if xmax == None: xmax = x[-1] |
|
350 | 354 | if ymin == None: ymin = y[0] |
|
351 | 355 | if ymax == None: ymax = y[-1] |
|
352 | 356 | |
|
353 | 357 | plplot.plline(x, y) |
|
354 | 358 | |
|
355 | 359 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
356 | 360 | """ |
|
357 | 361 | """ |
|
358 | 362 | if xmin == None: xmin = x[0] |
|
359 | 363 | if xmax == None: xmax = x[-1] |
|
360 | 364 | if ymin == None: ymin = y[0] |
|
361 | 365 | if ymax == None: ymax = y[-1] |
|
362 | 366 | if zmin == None: zmin = numpy.nanmin(data) |
|
363 | 367 | if zmax == None: zmax = numpy.nanmax(data) |
|
364 | 368 | |
|
365 | 369 | plplot.plimage(data, |
|
366 | 370 | float(x[0]), |
|
367 | 371 | float(x[-1]), |
|
368 | 372 | float(y[0]), |
|
369 | 373 | float(y[-1]), |
|
370 | 374 | float(zmin), |
|
371 | 375 | float(zmax), |
|
372 | 376 | float(xmin), |
|
373 | 377 | float(xmax), |
|
374 | 378 | float(ymin), |
|
375 | 379 | float(ymax) |
|
376 | 380 | ) |
|
377 | 381 | |
|
378 | 382 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
379 | 383 | |
|
380 | 384 | if not(len(x)>0 and len(y)>0): |
|
381 | 385 | raise ValueError, "x axis and y axis are empty" |
|
382 | 386 | |
|
383 | 387 | if deltax == None: deltax = x[-1] - x[-2] |
|
384 | 388 | if deltay == None: deltay = y[-1] - y[-2] |
|
385 | 389 | |
|
386 | 390 | x1 = numpy.append(x, x[-1] + deltax) |
|
387 | 391 | y1 = numpy.append(y, y[-1] + deltay) |
|
388 | 392 | |
|
389 | 393 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
390 | 394 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
391 | 395 | |
|
392 | 396 | self.__xg = xg |
|
393 | 397 | self.__yg = yg |
|
394 | 398 | |
|
395 | 399 | return xg, yg |
|
396 | 400 | |
|
397 | 401 | |
|
398 | 402 | 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): |
|
399 | 403 | if getGrid: |
|
400 | 404 | xg, yg = self.__getBoxpltr(x, y, deltax, deltay) |
|
401 | 405 | else: |
|
402 | 406 | xg = self.__xg |
|
403 | 407 | yg = self.__yg |
|
404 | 408 | |
|
405 | 409 | plplot.plimagefr(data, |
|
406 | 410 | float(xmin), |
|
407 | 411 | float(xmax), |
|
408 | 412 | float(ymin), |
|
409 | 413 | float(ymax), |
|
410 | 414 | 0., |
|
411 | 415 | 0., |
|
412 | 416 | float(zmin), |
|
413 | 417 | float(zmax), |
|
414 | 418 | plplot.pltr2, |
|
415 | 419 | xg, |
|
416 | 420 | yg) |
|
417 | 421 | |
|
418 | 422 | |
|
419 | 423 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): |
|
420 | 424 | data = numpy.arange(256) |
|
421 | 425 | data = numpy.reshape(data, (1,-1)) |
|
422 | 426 | |
|
423 | 427 | plplot.plimage(data, |
|
424 | 428 | float(xmin), |
|
425 | 429 | float(xmax), |
|
426 | 430 | float(ymin), |
|
427 | 431 | float(ymax), |
|
428 | 432 | 0., |
|
429 | 433 | 255., |
|
430 | 434 | float(xmin), |
|
431 | 435 | float(xmax), |
|
432 | 436 | float(ymin), |
|
433 | 437 | float(ymax)) |
|
434 | 438 | |
|
435 | 439 | def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False): |
|
436 | 440 | |
|
437 | 441 | plplot.plschr(0.0,self.__szchar-0.05) |
|
438 | 442 | plplot.pladv(self.__subplot) |
|
439 | 443 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) |
|
440 | 444 | plplot.plwind(float(xmin), # self.xrange[0] |
|
441 | 445 | float(xmax), # self.xrange[1] |
|
442 | 446 | float(ymin), # self.yrange[0] |
|
443 | 447 | float(ymax) # self.yrange[1] |
|
444 | 448 | ) |
|
445 | 449 | |
|
446 | 450 | |
|
447 | 451 | |
|
448 | 452 | if self.xaxisIsTime: |
|
449 | 453 | plplot.pltimefmt("%H:%M") |
|
450 | 454 | timedelta = (xmax - xmin + 1)/8. |
|
451 | 455 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) |
|
452 | 456 | else: |
|
453 | 457 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
454 | 458 | |
|
455 | 459 | |
|
456 | 460 | if not(nolabels): |
|
457 | 461 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
458 | 462 | |
|
459 | 463 | |
|
460 | 464 | def delLabels(self): |
|
461 | 465 | self.setColor(15) #Setting Line Color to White |
|
462 | 466 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
463 | 467 | self.setColor(1) #Setting Line Color to Black |
|
464 | 468 | |
|
465 | 469 | |
|
466 | 470 | |
|
467 | 471 | def plotImage(self,x,y,z,xrange,yrange,zrange): |
|
468 | 472 | xi = x[0] |
|
469 | 473 | xf = x[-1] |
|
470 | 474 | yi = y[0] |
|
471 | 475 | yf = y[-1] |
|
472 | 476 | |
|
473 | 477 | plplot.plimage(z, |
|
474 | 478 | float(xi), |
|
475 | 479 | float(xf), |
|
476 | 480 | float(yi), |
|
477 | 481 | float(yf), |
|
478 | 482 | float(zrange[0]), |
|
479 | 483 | float(zrange[1]), |
|
480 | 484 | float(xi), |
|
481 | 485 | float(xf), |
|
482 | 486 | float(yrange[0]), |
|
483 | 487 | yrange[1]) |
|
484 | 488 | |
|
485 | 489 | class LinearPlot: |
|
486 | 490 | linearObjDic = {} |
|
487 | 491 | __xpos = None |
|
488 | 492 | __ypos = None |
|
489 | 493 | def __init__(self,indexPlot,nsubplot,winTitle): |
|
490 | 494 | self.width = 700 |
|
491 | 495 | self.height = 150 |
|
492 | 496 | ncol = 1 |
|
493 | 497 | nrow = nsubplot |
|
494 | 498 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) |
|
495 | 499 | |
|
496 | 500 | |
|
497 | 501 | def setFigure(self,indexPlot): |
|
498 | 502 | setStrm(indexPlot) |
|
499 | 503 | |
|
500 | 504 | def setPosition(self): |
|
501 | 505 | |
|
502 | 506 | xi = 0.07; xf = 0.9 #0.8,0.7,0.5 |
|
503 | 507 | yi = 0.15; yf = 0.8 |
|
504 | 508 | |
|
505 | 509 | xpos = [xi,xf] |
|
506 | 510 | ypos = [yi,yf] |
|
507 | 511 | |
|
508 | 512 | self.__xpos = xpos |
|
509 | 513 | self.__ypos = ypos |
|
510 | 514 | |
|
511 | 515 | return xpos,ypos |
|
512 | 516 | |
|
517 | def show(self): | |
|
518 | plShow() | |
|
519 | ||
|
513 | 520 | def refresh(self): |
|
514 | 521 | plFlush() |
|
515 | 522 | |
|
516 | 523 | def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel): |
|
517 | 524 | szchar = 1.10 |
|
518 | 525 | name = "linear" |
|
519 | 526 | key = name + "%d"%subplot |
|
520 | 527 | xrange = [xmin,xmax] |
|
521 | 528 | yrange = [ymin,ymax] |
|
522 | 529 | |
|
523 | 530 | xpos,ypos = self.setPosition() |
|
524 | 531 | linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange) |
|
525 | 532 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcnst", "bcnstv") |
|
526 | 533 | self.linearObjDic[key] = linearObj |
|
527 | 534 | |
|
528 | 535 | def plot(self,subplot,x,y,type="power"): |
|
529 | 536 | name = "linear" |
|
530 | 537 | key = name + "%d"%subplot |
|
531 | 538 | |
|
532 | 539 | linearObj = self.linearObjDic[key] |
|
533 | 540 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") |
|
534 | 541 | |
|
535 | 542 | if linearObj.setXYData() != None: |
|
536 | 543 | clearData(linearObj) |
|
537 | 544 | |
|
538 | 545 | else: |
|
546 | if type.lower() == 'simple': | |
|
547 | linearObj.setXYData(x,y,"real") | |
|
539 | 548 | if type.lower() == 'power': |
|
540 | 549 | linearObj.setXYData(x,abs(y),"real") |
|
541 | 550 | if type.lower() == 'iq': |
|
542 | 551 | linearObj.setXYData(x,y,"complex") |
|
543 | 552 | |
|
553 | if type.lower() == 'simple': | |
|
554 | colline = 9 | |
|
555 | linearObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) | |
|
556 | linearObj.setXYData(x,y,"real") | |
|
557 | ||
|
544 | 558 | if type.lower() == 'power': |
|
545 | 559 | colline = 9 |
|
546 | 560 | linearObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) |
|
547 | 561 | linearObj.setXYData(x,abs(y),"real") |
|
548 | 562 | |
|
549 | 563 | if type.lower() == 'iq': |
|
550 | 564 | colline = 9 |
|
551 | 565 | linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline) |
|
552 | 566 | colline = 13 |
|
553 | 567 | linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline) |
|
554 | 568 | |
|
555 | 569 | linearObj.setXYData(x,y,"complex") |
|
556 | 570 | |
|
557 | 571 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") |
|
558 | 572 | |
|
559 | 573 | |
|
560 | 574 | # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bc", "bc") |
|
561 | 575 | # linearObj.basicXYPlot(data,y) |
|
562 | 576 | # linearObj.setXYData(data,y) |
|
563 | 577 | |
|
564 | 578 | |
|
565 | 579 | |
|
566 | 580 | class PcolorPlot: |
|
567 | 581 | pcolorObjDic = {} |
|
568 | 582 | colorbarObjDic = {} |
|
569 | 583 | pwprofileObjDic = {} |
|
570 | 584 | showColorbar = None |
|
571 | 585 | showPowerProfile = None |
|
572 | 586 | XAxisAsTime = None |
|
573 | 587 | width = None |
|
574 | 588 | height = None |
|
575 | 589 | __spcxpos = None |
|
576 | 590 | __spcypos = None |
|
577 | 591 | __cmapxpos = None |
|
578 | 592 | __cmapypos = None |
|
579 | 593 | __profxpos = None |
|
580 | 594 | __profypos = None |
|
581 | 595 | __lastTitle = None |
|
582 | 596 | |
|
583 | 597 | def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
584 | 598 | self.width = 460 |
|
585 | 599 | self.height = 300 |
|
586 | 600 | self.showColorbar = showColorbar |
|
587 | 601 | self.showPowerProfile = showPowerProfile |
|
588 | 602 | self.XAxisAsTime = XAxisAsTime |
|
589 | 603 | |
|
590 | 604 | |
|
591 | 605 | ncol = int(numpy.sqrt(nsubplot)+0.9) |
|
592 | 606 | nrow = int(nsubplot*1./ncol + 0.9) |
|
593 | 607 | |
|
594 | 608 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) |
|
595 | 609 | setColormap(colormap) |
|
596 | 610 | self.ncol = ncol |
|
597 | 611 | self.nrow = nrow |
|
598 | 612 | |
|
599 | 613 | def setFigure(self,indexPlot): |
|
600 | 614 | setStrm(indexPlot) |
|
601 | 615 | |
|
602 | 616 | def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile |
|
603 | 617 | if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075 |
|
604 | 618 | else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5 |
|
605 | 619 | yi = 0.15; yf = 0.80 |
|
606 | 620 | |
|
607 | 621 | xpos = [xi,xf] |
|
608 | 622 | ypos = [yi,yf] |
|
609 | 623 | |
|
610 | 624 | self.__spcxpos = xpos |
|
611 | 625 | self.__spcypos = ypos |
|
612 | 626 | |
|
613 | 627 | return xpos,ypos |
|
614 | 628 | |
|
615 | 629 | def setColorbarScreenPos(self): |
|
616 | 630 | |
|
617 | 631 | xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03 |
|
618 | 632 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
619 | 633 | |
|
620 | 634 | xpos = [xi,xf] |
|
621 | 635 | ypos = [yi,yf] |
|
622 | 636 | |
|
623 | 637 | self.__cmapxpos = xpos |
|
624 | 638 | self.__cmapypos = ypos |
|
625 | 639 | |
|
626 | 640 | return xpos,ypos |
|
627 | 641 | |
|
628 | 642 | def setPowerprofileScreenPos(self): |
|
629 | 643 | |
|
630 | 644 | xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25 |
|
631 | 645 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
632 | 646 | |
|
633 | 647 | xpos = [xi,xf] |
|
634 | 648 | ypos = [yi,yf] |
|
635 | 649 | |
|
636 | 650 | self.__profxpos = [xi,xf] |
|
637 | 651 | self.__profypos = [yi,yf] |
|
638 | 652 | |
|
639 | 653 | return xpos,ypos |
|
640 | 654 | |
|
641 | 655 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel): |
|
642 | 656 | """ |
|
643 | 657 | Crea los objetos necesarios para un subplot |
|
644 | 658 | """ |
|
645 | 659 | |
|
646 | 660 | # Config Spectra plot |
|
647 | 661 | |
|
648 | 662 | szchar = 0.7 |
|
649 | 663 | name = "spc" |
|
650 | 664 | key = name + "%d"%subplot |
|
651 | 665 | xrange = [xmin,xmax] |
|
652 | 666 | yrange = [ymin,ymax] |
|
653 | 667 | zrange = [zmin,zmax] |
|
654 | 668 | |
|
655 | 669 | xpos,ypos = self.setSpectraPos() |
|
656 | 670 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange) |
|
657 | 671 | self.pcolorObjDic[key] = pcolorObj |
|
658 | 672 | |
|
659 | 673 | # Config Colorbar |
|
660 | 674 | if self.showColorbar: |
|
661 | 675 | szchar = 0.65 |
|
662 | 676 | name = "colorbar" |
|
663 | 677 | key = name + "%d"%subplot |
|
664 | 678 | |
|
665 | 679 | xpos,ypos = self.setColorbarScreenPos() |
|
666 | 680 | xrange = [0.,1.] |
|
667 | 681 | yrange = [zmin,zmax] |
|
668 | 682 | cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) |
|
669 | 683 | self.colorbarObjDic[key] = cmapObj |
|
670 | 684 | |
|
671 | 685 | # Config Power profile |
|
672 | 686 | if self.showPowerProfile: |
|
673 | 687 | szchar = 0.55 |
|
674 | 688 | name = "pwprofile" |
|
675 | 689 | key = name + "%d"%subplot |
|
676 | 690 | |
|
677 | 691 | xpos,ypos = self.setPowerprofileScreenPos() |
|
678 | 692 | xrange = [zmin,zmax] |
|
679 | 693 | yrange = [ymin,ymax] |
|
680 | 694 | powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) |
|
681 | 695 | self.pwprofileObjDic[key] = powObj |
|
682 | 696 | |
|
683 | 697 | def setNewPage(self, pltitle='No title'): |
|
684 | 698 | szchar = 0.7 |
|
685 | 699 | setNewPage() |
|
686 | 700 | setPlTitle(pltitle,"black", szchar=szchar) |
|
687 | 701 | setSubpages(self.ncol, self.nrow) |
|
688 | 702 | |
|
689 | 703 | def closePage(self): |
|
690 | 704 | closePage() |
|
691 | 705 | |
|
692 | 706 | def iniPlot(self,subplot): |
|
693 | 707 | """ |
|
694 | 708 | Inicializa los subplots con su frame, titulo, etc |
|
695 | 709 | """ |
|
696 | 710 | |
|
697 | 711 | # Config Spectra plot |
|
698 | 712 | name = "spc" |
|
699 | 713 | key = name + "%d"%subplot |
|
700 | 714 | |
|
701 | 715 | pcolorObj = self.pcolorObjDic[key] |
|
702 | 716 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv") |
|
703 | 717 | |
|
704 | 718 | # Config Colorbar |
|
705 | 719 | if self.showColorbar: |
|
706 | 720 | name = "colorbar" |
|
707 | 721 | key = name + "%d"%subplot |
|
708 | 722 | |
|
709 | 723 | cmapObj = self.colorbarObjDic[key] |
|
710 | 724 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") |
|
711 | 725 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
712 | 726 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") |
|
713 | 727 | |
|
714 | 728 | # Config Power profile |
|
715 | 729 | if self.showPowerProfile: |
|
716 | 730 | name = "pwprofile" |
|
717 | 731 | key = name + "%d"%subplot |
|
718 | 732 | |
|
719 | 733 | powObj = self.pwprofileObjDic[key] |
|
720 | 734 | powObj.setLineStyle(2) |
|
721 | 735 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
722 | 736 | powObj.setLineStyle(1) |
|
723 | 737 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
724 | 738 | |
|
725 | 739 | def printTitle(self,pltitle): |
|
726 | 740 | # if self.__lastTitle != None: |
|
727 | 741 | # setPlTitle(self.__lastTitle,"white") |
|
728 | 742 | # |
|
729 | 743 | # self.__lastTitle = pltitle |
|
730 | 744 | |
|
731 | 745 | setPlTitle(pltitle,"black") |
|
732 | 746 | |
|
733 | 747 | # setSubpages(self.ncol,self.nrow) |
|
734 | 748 | |
|
735 | 749 | def plot(self,subplot,x,y,z,subtitle): |
|
736 | 750 | # Spectra plot |
|
737 | 751 | |
|
738 | 752 | name = "spc" |
|
739 | 753 | key = name + "%d"%subplot |
|
740 | 754 | |
|
741 | 755 | # newx = [x[0],x[-1]] |
|
742 | 756 | pcolorObj = self.pcolorObjDic[key] |
|
743 | 757 | |
|
744 | 758 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst") |
|
745 | 759 | |
|
746 | 760 | #pcolorObj.delLabels() |
|
747 | 761 | pcolorObj.setLabels(title=subtitle) |
|
748 | 762 | |
|
749 | 763 | deltax = None; deltay = None |
|
750 | 764 | |
|
751 | 765 | pcolorObj.advPcolorPlot(z, |
|
752 | 766 | x, |
|
753 | 767 | y, |
|
754 | 768 | xmin=pcolorObj.xrange[0], |
|
755 | 769 | xmax=pcolorObj.xrange[1], |
|
756 | 770 | ymin=pcolorObj.yrange[0], |
|
757 | 771 | ymax=pcolorObj.yrange[1], |
|
758 | 772 | zmin=pcolorObj.zrange[0], |
|
759 | 773 | zmax=pcolorObj.zrange[1], |
|
760 | 774 | deltax=deltax, |
|
761 | 775 | deltay=deltay, |
|
762 | 776 | getGrid=pcolorObj.getGrid) |
|
763 | 777 | |
|
764 | 778 | #Solo se calcula la primera vez que se ingresa a la funcion |
|
765 | 779 | pcolorObj.getGrid = False |
|
766 | 780 | |
|
767 | 781 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst", nolabels=True) |
|
768 | 782 | |
|
769 | 783 | # Power Profile |
|
770 | 784 | if self.showPowerProfile: |
|
771 | 785 | power = numpy.average(z, axis=0) |
|
772 | 786 | name = "pwprofile" |
|
773 | 787 | key = name + "%d"%subplot |
|
774 | 788 | powObj = self.pwprofileObjDic[key] |
|
775 | 789 | |
|
776 | 790 | if powObj.setXYData() != None: |
|
777 | 791 | #clearData(powObj) |
|
778 | 792 | powObj.setLineStyle(2) |
|
779 | 793 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
780 | 794 | powObj.setLineStyle(1) |
|
781 | 795 | else: |
|
782 | 796 | powObj.setXYData(power,y) |
|
783 | 797 | |
|
784 | 798 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
785 | 799 | powObj.basicXYPlot(power,y) |
|
786 | 800 | powObj.setXYData(power,y) |
|
787 | 801 | |
|
788 | 802 | def savePlot(self,indexPlot,filename): |
|
789 | 803 | |
|
790 | 804 | width = self.width*self.ncol |
|
791 | 805 | hei = self.height*self.nrow |
|
792 | 806 | savePlplot(filename,width,hei) |
|
793 | 807 | |
|
794 | 808 | def refresh(self): |
|
795 | 809 | plFlush() |
|
796 | 810 | |
|
797 | 811 | class RtiPlot: |
|
798 | 812 | |
|
799 | 813 | pcolorObjDic = {} |
|
800 | 814 | colorbarObjDic = {} |
|
801 | 815 | pwprofileObjDic = {} |
|
802 | 816 | showColorbar = None |
|
803 | 817 | showPowerProfile = None |
|
804 | 818 | XAxisAsTime = None |
|
805 | 819 | widht = None |
|
806 | 820 | height = None |
|
807 | 821 | __rtixpos = None |
|
808 | 822 | __rtiypos = None |
|
809 | 823 | __cmapxpos = None |
|
810 | 824 | __cmapypos = None |
|
811 | 825 | __profxpos = None |
|
812 | 826 | __profypos = None |
|
813 | 827 | |
|
814 | 828 | def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
815 | 829 | self.width = 700 |
|
816 | 830 | self.height = 150 |
|
817 | 831 | self.showColorbar = showColorbar |
|
818 | 832 | self.showPowerProfile = showPowerProfile |
|
819 | 833 | self.XAxisAsTime = XAxisAsTime |
|
820 | 834 | |
|
821 | 835 | ncol = 1 |
|
822 | 836 | nrow = nsubplot |
|
823 | 837 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) |
|
824 | 838 | setColormap(colormap) |
|
825 | 839 | self.ncol = ncol |
|
826 | 840 | self.nrow = nrow |
|
827 | 841 | |
|
828 | 842 | def setFigure(self,indexPlot): |
|
829 | 843 | setStrm(indexPlot) |
|
830 | 844 | |
|
831 | 845 | def setRtiScreenPos(self): |
|
832 | 846 | |
|
833 | 847 | if self.showPowerProfile: xi = 0.07; xf = 0.65 |
|
834 | 848 | else: xi = 0.07; xf = 0.9 |
|
835 | 849 | yi = 0.15; yf = 0.80 |
|
836 | 850 | |
|
837 | 851 | xpos = [xi,xf] |
|
838 | 852 | ypos = [yi,yf] |
|
839 | 853 | |
|
840 | 854 | self.__rtixpos = xpos |
|
841 | 855 | self.__rtiypos = ypos |
|
842 | 856 | |
|
843 | 857 | return xpos,ypos |
|
844 | 858 | |
|
845 | 859 | def setColorbarScreenPos(self): |
|
846 | 860 | |
|
847 | 861 | xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03 |
|
848 | 862 | |
|
849 | 863 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
850 | 864 | |
|
851 | 865 | xpos = [xi,xf] |
|
852 | 866 | ypos = [yi,yf] |
|
853 | 867 | |
|
854 | 868 | self.__cmapxpos = xpos |
|
855 | 869 | self.__cmapypos = ypos |
|
856 | 870 | |
|
857 | 871 | return xpos,ypos |
|
858 | 872 | |
|
859 | 873 | def setPowerprofileScreenPos(self): |
|
860 | 874 | |
|
861 | 875 | xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20 |
|
862 | 876 | |
|
863 | 877 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
864 | 878 | |
|
865 | 879 | xpos = [xi,xf] |
|
866 | 880 | ypos = [yi,yf] |
|
867 | 881 | |
|
868 | 882 | self.__profxpos = [xi,xf] |
|
869 | 883 | self.__profypos = [yi,yf] |
|
870 | 884 | |
|
871 | 885 | return xpos,ypos |
|
872 | 886 | |
|
873 | 887 | def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone="lt",npoints=100): |
|
874 | 888 | # Config Rti plot |
|
875 | 889 | szchar = 1.10 |
|
876 | 890 | name = "rti" |
|
877 | 891 | key = name + "%d"%subplot |
|
878 | 892 | |
|
879 | 893 | # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal] |
|
880 | 894 | thisDateTime = datetime.datetime.fromtimestamp(timedata) |
|
881 | 895 | startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0) |
|
882 | 896 | endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59) |
|
883 | 897 | deltaTime = 0 |
|
884 | 898 | if timezone == "lt": |
|
885 | 899 | deltaTime = time.timezone |
|
886 | 900 | startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime |
|
887 | 901 | endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime |
|
888 | 902 | |
|
889 | 903 | xrange = [startTimeInSecs,endTimeInSecs] |
|
890 | 904 | totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1. |
|
891 | 905 | deltax = totalTimeInXrange / npoints |
|
892 | 906 | |
|
893 | 907 | yrange = [ymin,ymax] |
|
894 | 908 | zrange = [zmin,zmax] |
|
895 | 909 | |
|
896 | 910 | xpos,ypos = self.setRtiScreenPos() |
|
897 | 911 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax) |
|
898 | 912 | if self.XAxisAsTime: |
|
899 | 913 | pcolorObj.setXAxisAsTime(self.XAxisAsTime) |
|
900 | 914 | xopt = "bcnstd" |
|
901 | 915 | yopt = "bcnstv" |
|
902 | 916 | else: |
|
903 | 917 | xopt = "bcnst" |
|
904 | 918 | yopt = "bcnstv" |
|
905 | 919 | |
|
906 | 920 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
907 | 921 | self.pcolorObjDic[key] = pcolorObj |
|
908 | 922 | |
|
909 | 923 | |
|
910 | 924 | # Config Colorbar |
|
911 | 925 | if self.showColorbar: |
|
912 | 926 | szchar = 0.9 |
|
913 | 927 | name = "colorbar" |
|
914 | 928 | key = name + "%d"%subplot |
|
915 | 929 | |
|
916 | 930 | xpos,ypos = self.setColorbarScreenPos() |
|
917 | 931 | xrange = [0.,1.] |
|
918 | 932 | yrange = [zmin,zmax] |
|
919 | 933 | cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) |
|
920 | 934 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm") |
|
921 | 935 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
922 | 936 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") |
|
923 | 937 | self.colorbarObjDic[key] = cmapObj |
|
924 | 938 | |
|
925 | 939 | |
|
926 | 940 | # Config Power profile |
|
927 | 941 | if self.showPowerProfile: |
|
928 | 942 | szchar = 0.8 |
|
929 | 943 | name = "pwprofile" |
|
930 | 944 | key = name + "%d"%subplot |
|
931 | 945 | |
|
932 | 946 | xpos,ypos = self.setPowerprofileScreenPos() |
|
933 | 947 | xrange = [zmin,zmax] |
|
934 | 948 | yrange = [ymin,ymax] |
|
935 | 949 | powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) |
|
936 | 950 | powObj.setLineStyle(2) |
|
937 | 951 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
938 | 952 | powObj.setLineStyle(1) |
|
939 | 953 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
940 | 954 | self.pwprofileObjDic[key] = powObj |
|
941 | 955 | |
|
942 | 956 | |
|
943 | 957 | def plot(self,subplot,x,y,z): |
|
944 | 958 | # RTI plot |
|
945 | 959 | name = "rti" |
|
946 | 960 | key = name + "%d"%subplot |
|
947 | 961 | |
|
948 | 962 | data = numpy.reshape(z, (1,-1)) |
|
949 | 963 | data = numpy.abs(data) |
|
950 | 964 | data = 10*numpy.log10(data) |
|
951 | 965 | newx = [x,x+1] |
|
952 | 966 | |
|
953 | 967 | pcolorObj = self.pcolorObjDic[key] |
|
954 | 968 | |
|
955 | 969 | if pcolorObj.xaxisIsTime: |
|
956 | 970 | xopt = "bcstd" |
|
957 | 971 | yopt = "bcst" |
|
958 | 972 | else: |
|
959 | 973 | xopt = "bcst" |
|
960 | 974 | yopt = "bcst" |
|
961 | 975 | |
|
962 | 976 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
963 | 977 | |
|
964 | 978 | deltax = pcolorObj.deltax |
|
965 | 979 | deltay = None |
|
966 | 980 | |
|
967 | 981 | if pcolorObj.xmin == None and pcolorObj.xmax == None: |
|
968 | 982 | pcolorObj.xmin = x |
|
969 | 983 | pcolorObj.xmax = x |
|
970 | 984 | |
|
971 | 985 | if x >= pcolorObj.xmax: |
|
972 | 986 | xmin = x |
|
973 | 987 | xmax = x + deltax |
|
974 | 988 | x = [x] |
|
975 | 989 | pcolorObj.advPcolorPlot(data, |
|
976 | 990 | x, |
|
977 | 991 | y, |
|
978 | 992 | xmin=xmin, |
|
979 | 993 | xmax=xmax, |
|
980 | 994 | ymin=pcolorObj.yrange[0], |
|
981 | 995 | ymax=pcolorObj.yrange[1], |
|
982 | 996 | zmin=pcolorObj.zrange[0], |
|
983 | 997 | zmax=pcolorObj.zrange[1], |
|
984 | 998 | deltax=deltax, |
|
985 | 999 | deltay=deltay, |
|
986 | 1000 | getGrid=pcolorObj.getGrid) |
|
987 | 1001 | |
|
988 | 1002 | pcolorObj.xmin = xmin |
|
989 | 1003 | pcolorObj.xmax = xmax |
|
990 | 1004 | |
|
991 | 1005 | |
|
992 | 1006 | # Power Profile |
|
993 | 1007 | if self.showPowerProfile: |
|
994 | 1008 | data = numpy.reshape(data,(numpy.size(data))) |
|
995 | 1009 | name = "pwprofile" |
|
996 | 1010 | key = name + "%d"%subplot |
|
997 | 1011 | powObj = self.pwprofileObjDic[key] |
|
998 | 1012 | |
|
999 | 1013 | if powObj.setXYData() != None: |
|
1000 | 1014 | clearData(powObj) |
|
1001 | 1015 | powObj.setLineStyle(2) |
|
1002 | 1016 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
1003 | 1017 | powObj.setLineStyle(1) |
|
1004 | 1018 | else: |
|
1005 | 1019 | powObj.setXYData(data,y) |
|
1006 | 1020 | |
|
1007 | 1021 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
1008 | 1022 | powObj.basicXYPlot(data,y) |
|
1009 | 1023 | powObj.setXYData(data,y) |
|
1010 | 1024 | |
|
1011 | 1025 | def savePlot(self,indexPlot,filename): |
|
1012 | 1026 | |
|
1013 | 1027 | width = self.width*self.ncol |
|
1014 | 1028 | hei = self.height*self.nrow |
|
1015 | 1029 | savePlplot(filename,width,hei) |
|
1016 | 1030 | |
|
1017 | 1031 | def refresh(self): |
|
1018 | plFlush() No newline at end of file | |
|
1032 | plFlush() | |
|
1033 | ||
|
1034 | if __name__ == '__main__': | |
|
1035 | ||
|
1036 | #Setting the signal | |
|
1037 | fs = 8000 | |
|
1038 | f0 = 200 | |
|
1039 | f1 = 400 | |
|
1040 | T = 1./fs | |
|
1041 | x = numpy.arange(160) | |
|
1042 | y1 = numpy.sin(2*numpy.pi*f0*x*T) | |
|
1043 | y2 = numpy.sin(2*numpy.pi*f1*x*T) | |
|
1044 | signalList = [y1,y2] | |
|
1045 | ||
|
1046 | xmin = numpy.min(x) | |
|
1047 | xmax = numpy.max(x) | |
|
1048 | ymin = numpy.min(y1) | |
|
1049 | ymax = numpy.max(y1) | |
|
1050 | ||
|
1051 | # Creating Object | |
|
1052 | indexPlot = 1 | |
|
1053 | nsubplot = 2 | |
|
1054 | winTitle = "mi grafico v1" | |
|
1055 | ||
|
1056 | subplotTitle = "subplot - No." | |
|
1057 | xlabel = "" | |
|
1058 | ylabel = "" | |
|
1059 | ||
|
1060 | linearObj = LinearPlot(indexPlot,nsubplot,winTitle) | |
|
1061 | ||
|
1062 | #Config SubPlots | |
|
1063 | for subplot in range(nsubplot): | |
|
1064 | indexplot = subplot + 1 | |
|
1065 | title = subplotTitle + '%d'%indexplot | |
|
1066 | linearObj.setup(indexplot, xmin, xmax, ymin, ymax, title, xlabel, ylabel) | |
|
1067 | ||
|
1068 | #Plotting | |
|
1069 | type = "simple" | |
|
1070 | for subplot in range(nsubplot): | |
|
1071 | indexplot = subplot + 1 | |
|
1072 | y = signalList[subplot] | |
|
1073 | linearObj.plot(indexplot, x, y, type) | |
|
1074 | ||
|
1075 | linearObj.refresh() | |
|
1076 | linearObj.show() | |
|
1077 | ||
|
1078 | print "end" No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now