##// END OF EJS Templates
Grafico de espectros actualizado
Miguel Valdez -
r27:fb9ede38dd50
parent child
Show More
@@ -1,852 +1,863
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
9 9 import numpy
10 10 import plplot
11 11
12 12 def cmap1_init(colormap="gray"):
13 13
14 14 ncolor = None
15 15 rgb_lvl = None
16 16
17 17 # Routine for defining a specific color map 1 in HLS space.
18 18 # if gray is true, use basic grayscale variation from half-dark to light.
19 19 # otherwise use false color variation from blue (240 deg) to red (360 deg).
20 20
21 21 # Independent variable of control points.
22 22 i = numpy.array((0., 1.))
23 23 if colormap=="gray":
24 24 ncolor = 256
25 25 # Hue for control points. Doesn't matter since saturation is zero.
26 26 h = numpy.array((0., 0.))
27 27 # Lightness ranging from half-dark (for interest) to light.
28 28 l = numpy.array((0.5, 1.))
29 29 # Gray scale has zero saturation
30 30 s = numpy.array((0., 0.))
31 31
32 32 # number of cmap1 colours is 256 in this case.
33 33 plplot.plscmap1n(ncolor)
34 34 # Interpolate between control points to set up cmap1.
35 35 plplot.plscmap1l(0, i, h, l, s)
36 36
37 37 return None
38 38
39 39 if colormap=="br_green":
40 40 ncolor = 256
41 41 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
42 42 h = numpy.array((240., 0.))
43 43 # Lightness and saturation are constant (values taken from C example).
44 44 l = numpy.array((0.6, 0.6))
45 45 s = numpy.array((0.8, 0.8))
46 46
47 47 # number of cmap1 colours is 256 in this case.
48 48 plplot.plscmap1n(ncolor)
49 49 # Interpolate between control points to set up cmap1.
50 50 plplot.plscmap1l(0, i, h, l, s)
51 51
52 52 return None
53 53
54 54 if colormap=="tricolor":
55 55 ncolor = 3
56 56 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
57 57 h = numpy.array((240., 0.))
58 58 # Lightness and saturation are constant (values taken from C example).
59 59 l = numpy.array((0.6, 0.6))
60 60 s = numpy.array((0.8, 0.8))
61 61
62 62 # number of cmap1 colours is 256 in this case.
63 63 plplot.plscmap1n(ncolor)
64 64 # Interpolate between control points to set up cmap1.
65 65 plplot.plscmap1l(0, i, h, l, s)
66 66
67 67 return None
68 68
69 69 if colormap == 'rgb' or colormap == 'rgb666':
70 70
71 71 color_sz = 6
72 72 ncolor = color_sz*color_sz*color_sz
73 73 pos = numpy.zeros((ncolor))
74 74 r = numpy.zeros((ncolor))
75 75 g = numpy.zeros((ncolor))
76 76 b = numpy.zeros((ncolor))
77 77 ind = 0
78 78 for ri in range(color_sz):
79 79 for gi in range(color_sz):
80 80 for bi in range(color_sz):
81 81 r[ind] = ri/(color_sz-1.0)
82 82 g[ind] = gi/(color_sz-1.0)
83 83 b[ind] = bi/(color_sz-1.0)
84 84 pos[ind] = ind/(ncolor-1.0)
85 85 ind += 1
86 86 rgb_lvl = [6,6,6] #Levels for RGB colors
87 87
88 88 if colormap == 'rgb676':
89 89 ncolor = 6*7*6
90 90 pos = numpy.zeros((ncolor))
91 91 r = numpy.zeros((ncolor))
92 92 g = numpy.zeros((ncolor))
93 93 b = numpy.zeros((ncolor))
94 94 ind = 0
95 95 for ri in range(8):
96 96 for gi in range(8):
97 97 for bi in range(4):
98 98 r[ind] = ri/(6-1.0)
99 99 g[ind] = gi/(7-1.0)
100 100 b[ind] = bi/(6-1.0)
101 101 pos[ind] = ind/(ncolor-1.0)
102 102 ind += 1
103 103 rgb_lvl = [6,7,6] #Levels for RGB colors
104 104
105 105 if colormap == 'rgb685':
106 106 ncolor = 6*8*5
107 107 pos = numpy.zeros((ncolor))
108 108 r = numpy.zeros((ncolor))
109 109 g = numpy.zeros((ncolor))
110 110 b = numpy.zeros((ncolor))
111 111 ind = 0
112 112 for ri in range(8):
113 113 for gi in range(8):
114 114 for bi in range(4):
115 115 r[ind] = ri/(6-1.0)
116 116 g[ind] = gi/(8-1.0)
117 117 b[ind] = bi/(5-1.0)
118 118 pos[ind] = ind/(ncolor-1.0)
119 119 ind += 1
120 120 rgb_lvl = [6,8,5] #Levels for RGB colors
121 121
122 122 if colormap == 'rgb884':
123 123 ncolor = 8*8*4
124 124 pos = numpy.zeros((ncolor))
125 125 r = numpy.zeros((ncolor))
126 126 g = numpy.zeros((ncolor))
127 127 b = numpy.zeros((ncolor))
128 128 ind = 0
129 129 for ri in range(8):
130 130 for gi in range(8):
131 131 for bi in range(4):
132 132 r[ind] = ri/(8-1.0)
133 133 g[ind] = gi/(8-1.0)
134 134 b[ind] = bi/(4-1.0)
135 135 pos[ind] = ind/(ncolor-1.0)
136 136 ind += 1
137 137 rgb_lvl = [8,8,4] #Levels for RGB colors
138 138
139 139 if ncolor == None:
140 140 raise ValueError, "The colormap selected is not valid"
141 141
142 142 plplot.plscmap1n(ncolor)
143 143 plplot.plscmap1l(1, pos, r, g, b)
144 144
145 145 return rgb_lvl
146 146
147 147 class BaseGraph:
148 148 """
149 149
150 150 """
151 151
152 152
153 153
154 154 def __init__(self):
155 155 """
156 156
157 157 """
158 158 self.hasNotRange = True
159 159
160 160 self.xrange = None
161 161 self.yrange = None
162 162 self.zrange = None
163 163
164 164 self.xlabel = None
165 165 self.ylabel = None
166 166 self.title = None
167 167
168 168 self.legends = None
169 169
170 170 self.__name = None
171 171
172 172 self.__colormap = None
173 173 self.__colbox = None
174 174 self.__colleg = None
175 175
176 176 self.__xpos = None
177 177 self.__ypos = None
178 178
179 179 self.__xopt = None #"bcnst"
180 180 self.__yopt = None #"bcnstv"
181 181
182 182 self.__xlpos = None
183 183 self.__ylpos = None
184 184
185 185 self.__xrangeIsTime = False
186 186
187 187 #Advanced
188 188 self.__xg = None
189 189 self.__yg = None
190 190
191 191 def setName(self, name):
192 192 self.__name = name
193 193
194 194 def setScreenPos(self, xpos, ypos):
195 195 self.__xpos = xpos
196 196 self.__ypos = ypos
197 197
198 198 def setOpt(self, xopt, yopt):
199 199 self.__xopt = xopt
200 200 self.__yopt = yopt
201 201
202 202 def setXAxisAsTime(self):
203 203 self.__xrangeIsTime = True
204 204
205 205
206 206 def setup(self, title=None, xlabel=None, ylabel=None, colormap=None):
207 207 """
208 208 """
209 209 self.title = title
210 210 self.xlabel = xlabel
211 211 self.ylabel = ylabel
212 212 self.__colormap = colormap
213 213
214 def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None):
214 def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False):
215 215 """
216 216
217 217 """
218 218 if self.__xrangeIsTime:
219 219 plplot.pltimefmt("%H:%M")
220 220
221 221 plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
222 222 plplot.plwind(float(xmin),
223 223 float(xmax),
224 224 float(ymin),
225 225 float(ymax)
226 226 )
227 227
228 228 if xopt == None: xopt = self.__xopt
229 229 if yopt == None: yopt = self.__yopt
230 230
231 231 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
232 232
233 plplot.pllab(self.xlabel, self.ylabel, self.title)
233 if not(nolabels):
234 plplot.pllab(self.xlabel, self.ylabel, self.title)
234 235
235 236
236 237 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
237 238 data = numpy.arange(256)
238 239 data = numpy.reshape(data, (1,-1))
239 240
240 241 plplot.plimage(data,
241 242 float(xmin),
242 243 float(xmax),
243 244 float(ymin),
244 245 float(ymax),
245 246 0.,
246 247 255.,
247 248 float(xmin),
248 249 float(xmax),
249 250 float(ymin),
250 251 float(ymax))
251 252
252 253 def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None):
253 254
254 255 if xmin == None: xmin = x[0]
255 256 if xmax == None: xmax = x[-1]
256 257 if ymin == None: ymin = y[0]
257 258 if ymax == None: ymax = y[-1]
258 259
259 260 plplot.plline(x, y)
260 261
261 262 def basicXYwithErrorPlot(self):
262 263 pass
263 264
264 265 def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
265 266
266 267 if xmin == None: xmin = x[0]
267 268 if xmax == None: xmax = x[-1]
268 269 if ymin == None: ymin = y[0]
269 270 if ymax == None: ymax = y[-1]
270 271
271 272 plplot.plcol0(colline)
272 273 plplot.plline(x, y)
273 274 plplot.plcol0(1)
274 275
275 276 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
276 277 """
277 278 """
278 279 if xmin == None: xmin = x[0]
279 280 if xmax == None: xmax = x[-1]
280 281 if ymin == None: ymin = y[0]
281 282 if ymax == None: ymax = y[-1]
282 283 if zmin == None: zmin = numpy.nanmin(data)
283 284 if zmax == None: zmax = numpy.nanmax(data)
284 285
285 286 plplot.plimage(data,
286 287 float(x[0]),
287 288 float(x[-1]),
288 289 float(y[0]),
289 290 float(y[-1]),
290 291 float(zmin),
291 292 float(zmax),
292 293 float(xmin),
293 294 float(xmax),
294 295 float(ymin),
295 296 float(ymax)
296 297 )
297 298
298 299 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
299 300
300 301 if not(len(x)>1 and len(y)>1):
301 302 raise ValueError, "x axis and y axis are empty"
302 303
303 304 if deltax == None: deltax = x[-1] - x[-2]
304 305 if deltay == None: deltay = y[-1] - y[-2]
305 306
306 307 x1 = numpy.append(x, x[-1] + deltax)
307 308 y1 = numpy.append(y, y[-1] + deltay)
308 309
309 310 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
310 311 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
311 312
312 313 self.__xg = xg
313 314 self.__yg = yg
314 315
315 316 def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.):
316 317 """
317 318 """
318 319
319 320 if self.__xg == None and self.__yg == None:
320 321 self.__getBoxpltr(x, y)
321 322
322 323 plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg)
323 324
324 325
325 326 class LinearPlot():
326 327
327 328 __szchar = 1.0
328 329 __xrange = None
329 330 __yrange = None
330 331
331 332 m_BaseGraph = None
332 333
333 334 def __init__(self):
334 335
335 336
336 337 key = "linearplot"
337 338 self.m_BaseGraph = BaseGraph()
338 339 self.m_BaseGraph.setName(key)
339 340
340 341 self.__subpage = 0
341 342
342 343 def setColormap(self, colormap="br_green"):
343 344
344 345 if colormap == None:
345 346 colormap = self.__colormap
346 347
347 348 cmap1_init(colormap)
348 349
349 350 def iniSubpage(self):
350 351
351 352 if plplot.plgdev() == '':
352 353 raise ValueError, "Plot device has not been initialize"
353 354
354 355 plplot.pladv(self.__subpage)
355 356 plplot.plschr(0.0, self.__szchar)
356 357
357 358 self.setColormap()
358 359
359 360 def setScreenPos(self, width='small'):
360 361
361 362 if width == 'small':
362 363 xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80
363 364
364 365 if width == 'medium':
365 366 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60
366 367
367 368 xf = xi + xw
368 369 yf = yi + yw
369 370
370 371 self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf])
371 372
372 373 def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False):
373 374 """
374 375 """
375 376
376 377 self.m_BaseGraph.setOpt("bcnts","bcntsv")
377 378 self.m_BaseGraph.setup(title,
378 379 xlabel,
379 380 ylabel
380 381 )
381 382
382 383 self.setScreenPos(width='medium')
383 384
384 385 if XAxisAsTime:
385 386 self.m_BaseGraph.setXAxisAsTime()
386 387
387 388 self.__subpage = subpage
388 389 # def setRanges(self, xrange, yrange, zrange):
389 390 #
390 391 # self.m_BaseGraph.setRanges(xrange, yrange, zrange)
391 392
392 393 def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
393 394 """
394 395 Inputs:
395 396
396 397 x : Numpy array of dimension 1
397 398 y : Numpy array of dimension 1
398 399
399 400 """
400 401
401 402 try:
402 403 nX = numpy.shape(x)
403 404 except:
404 405 raise ValueError, "x is not a numpy array"
405 406
406 407 if y == None: y = numpy.arange(nX)
407 408
408 409 if xmin == None: xmin = x[0]
409 410 if xmax == None: xmax = x[-1]
410 411 if ymin == None: ymin = y[0]
411 412 if ymax == None: ymax = y[-1]
412 413
413 414 self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax)
414 415 self.m_BaseGraph.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline)
415 416
416 417 def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'):
417 418 """
418 419 Inputs:
419 420
420 421 x : Numpy array of dimension 1
421 422 y : Complex numpy array of dimension 1
422 423
423 424 """
424 425
425 426 try:
426 427 nX = numpy.shape(x)
427 428 except:
428 429 raise ValueError, "x is not a numpy array"
429 430
430 431 try:
431 432 nY = numpy.shape(y)
432 433 except:
433 434 raise ValueError, "y is not a numpy array"
434 435
435 436 if xmin == None: xmin = x[0]
436 437 if xmax == None: xmax = x[-1]
437 438 if ymin == None: ymin = y[0]
438 439 if ymax == None: ymax = y[-1]
439 440
440 441 self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax)
441 442
442 443 if type.lower() == 'power':
443 444 self.m_BaseGraph.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline)
444 445
445 446 if type.lower() == 'iq':
446 447
447 448 self.m_BaseGraph.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline)
448 449 self.m_BaseGraph.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1)
449 450
450 451 class ColorPlot():
451 452
452 453 def __init__(self):
453 454
454 455 self.graphObjDict = {}
455 456
456 457 self.__subpage = 0
457 458 self.__showColorbar = False
458 459 self.__showPowerProfile = True
459 460
460 self.__szchar = 0.7
461 self.__szchar = 0.65
461 462 self.__xrange = None
462 463 self.__yrange = None
463 464 self.__zrange = None
464 465
465 466 key = "colorplot"
466 467 self.m_BaseGraph = BaseGraph()
467 468 self.m_BaseGraph.setName(key)
468 469
469 470 def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
470 471 """
471 472 """
472 473
473 474 self.m_BaseGraph.setOpt("bcnts","bcntsv")
474 475 self.m_BaseGraph.setup(title,
475 476 xlabel,
476 477 ylabel
477 478 )
478 479
479 480 self.__subpage = subpage
480 481 self.__colormap = colormap
481 482 self.__showColorbar = showColorbar
482 483 self.__showPowerProfile = showPowerProfile
483 484
484 485 if showColorbar:
485 486 key = "colorbar"
486 487
487 488 cmapObj = BaseGraph()
488 489 cmapObj.setName(key)
489 cmapObj.setOpt("bc","bcmt")
490 cmapObj.setOpt("bc","bcmtv")
490 491 cmapObj.setup(title="dBs",
491 492 xlabel="",
492 493 ylabel="",
493 494 colormap=colormap)
494 495
495 496 self.graphObjDict[key] = cmapObj
496 497
497 498
498 499 if showPowerProfile:
499 500 key = "powerprof"
500 501
501 502 powObj = BaseGraph()
502 503 powObj.setName(key)
503 504 powObj.setOpt("bcntg","bc")
504 505 powObj.setup(title="Power Profile",
505 506 xlabel="dB",
506 507 ylabel="")
507 508
508 509 self.graphObjDict[key] = powObj
509 510
510 511 self.setScreenPos(width='small')
511 512
512 513 if XAxisAsTime:
513 514 self.m_BaseGraph.setXAxisAsTime()
514 515
515 516
516 517
517 518 def setColormap(self, colormap="br_green"):
518 519
519 520 if colormap == None:
520 521 colormap = self.__colormap
521 522
522 523 cmap1_init(colormap)
523 524
524 525 def iniSubpage(self):
525 526
526 527 if plplot.plgdev() == '':
527 528 raise ValueError, "Plot device has not been initialize"
528 529
529 530 plplot.pladv(self.__subpage)
530 531 plplot.plschr(0.0, self.__szchar)
531 532
532 533 self.setColormap()
533 534
534 535 def setScreenPos(self, width='small'):
535 536
536 537 if width == 'small':
537 xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.05; xpoww = 0.26; deltaxcmap = 0.02; deltaxpow = 0.05
538 xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.04; xpoww = 0.25; deltaxcmap = 0.02; deltaxpow = 0.06
538 539
539 540 if width == 'medium':
540 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.05; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06
541 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.04; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06
541 542
542 543 if self.__showColorbar:
543 544 xw -= xcmapw + deltaxcmap
544 545
545 546 if self.__showPowerProfile:
546 547 xw -= xpoww + deltaxpow
547 548
548 549 xf = xi + xw
549 550 yf = yi + yw
550 551 xcmapf = xf
551 552
552 553 self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf])
553 554
554 555 if self.__showColorbar:
555 556 xcmapi = xf + deltaxcmap
556 557 xcmapf = xcmapi + xcmapw
557 558
558 559 key = "colorbar"
559 560 cmapObj = self.graphObjDict[key]
560 561 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
561 562
562 563 if self.__showPowerProfile:
563 564
564 565 xpowi = xcmapf + deltaxpow
565 566 xpowf = xpowi + xpoww
566 567
567 568 key = "powerprof"
568 569 powObj = self.graphObjDict[key]
569 570 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
570 571
571 572
572 573
573 574 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
574 575 """
575 576 Inputs:
576 577
577 578 x : Numpy array of dimension 1
578 579 y : Numpy array of dimension 1
579 580
580 581 """
581 582
582 583 try:
583 584 nX, nY = numpy.shape(data)
584 585 except:
585 586 raise ValueError, "data is not a numpy array"
586 587
587 588 if x == None: x = numpy.arange(nX)
588 589 if y == None: y = numpy.arange(nY)
589 590
590 591 if xmin == None: xmin = x[0]
591 592 if xmax == None: xmax = x[-1]
592 593 if ymin == None: ymin = y[0]
593 594 if ymax == None: ymax = y[-1]
594 595 if zmin == None: zmin = numpy.nanmin(data)
595 596 if zmax == None: zmax = numpy.nanmax(data)
596 597
598 plplot.plschr(0.0, self.__szchar)
599
597 600 self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax)
598 601 self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax)
599 602
600 603 if self.__showColorbar:
604
605
601 606 key = "colorbar"
602 607 cmapObj = self.graphObjDict[key]
608
609 plplot.plschr(0.0, self.__szchar-0.05)
603 610 cmapObj.plotBox(0., 1., zmin, zmax)
604 611 cmapObj.colorbarPlot(0., 1., zmin, zmax)
605 612
606 613 if self.__showPowerProfile:
607 614 power = numpy.max(data, axis=0)
608 615
609 616 step = (ymax - ymin)/(nY-1)
610 617 heis = numpy.arange(ymin, ymax + step, step)
611 618
612 619 key = "powerprof"
613 620 powObj = self.graphObjDict[key]
614 621
615 622 plplot.pllsty(2)
616 powObj.plotBox(zmin, zmax, ymin, ymax)
623 plplot.plschr(0.0, self.__szchar-0.05)
624 powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True)
625
617 626 plplot.pllsty(1)
627 plplot.plschr(0.0, self.__szchar)
618 628 powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc')
629
619 630 plplot.plcol0(9)
620 631 powObj.basicXYPlot(power, heis)
621 632 plplot.plcol0(1)
622 633
623 634
624 635 class ColorPlotX():
625 636
626 637
627 638 graphObjDict = {}
628 639 showColorbar = False
629 640 showPowerProfile = True
630 641
631 642 __szchar = 0.7
632 643 __xrange = None
633 644 __yrange = None
634 645 __zrange = None
635 646
636 647 m_BaseGraph = BaseGraph()
637 648
638 649 def __init__(self):
639 650
640 651 key = "colorplot"
641 652 self.m_BaseGraph.setName(key)
642 653
643 654 self.__subpage = 0
644 655
645 656 self.graphObjDict[key] = self.m_BaseGraph
646 657
647 658 def setColormap(self, colormap="br_green"):
648 659
649 660 if colormap == None:
650 661 colormap = self.__colormap
651 662
652 663 cmap1_init(colormap)
653 664
654 665 def iniSubpage(self):
655 666
656 667 if plplot.plgdev() == '':
657 668 raise ValueError, "Plot device has not been initialize"
658 669
659 670 plplot.pladv(self.__subpage)
660 671 plplot.plschr(0.0, self.__szchar)
661 672
662 673 self.setColormap()
663 674
664 675 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
665 676 """
666 677 """
667 678
668 679 self.m_BaseGraph.setSubpage(subpage)
669 680 self.m_BaseGraph.setSzchar(self.__szchar)
670 681 self.m_BaseGraph.setOpt("bcnts","bcntsv")
671 682 self.m_BaseGraph.setup(title,
672 683 xlabel,
673 684 ylabel,
674 685 colormap)
675 686
676 687 if showColorbar:
677 688 key = "colorbar"
678 689
679 690 cmapObj = BaseGraph()
680 691 cmapObj.setName(key)
681 692 cmapObj.setSubpage(subpage)
682 693 cmapObj.setSzchar(self.__szchar)
683 694 cmapObj.setOpt("bc","bcmt")
684 695 cmapObj.setup(title="dBs",
685 696 xlabel="",
686 697 ylabel="",
687 698 colormap=colormap)
688 699
689 700 self.graphObjDict[key] = cmapObj
690 701
691 702
692 703 if showPowerProfile:
693 704 key = "powerprof"
694 705
695 706 powObj = BaseGraph()
696 707 powObj.setName(key)
697 708 powObj.setSubpage(subpage)
698 709 powObj.setSzchar(self.__szchar)
699 710 plplot.pllsty(2)
700 711 powObj.setOpt("bcntg","bc")
701 712 plplot.pllsty(1)
702 713 powObj.setup(title="Power Profile",
703 714 xlabel="dBs",
704 715 ylabel="")
705 716
706 717 self.graphObjDict[key] = powObj
707 718
708 719 self.showColorbar = showColorbar
709 720 self.showPowerProfile = showPowerProfile
710 721 self.setScreenPos()
711 722
712 723 if XAxisAsTime:
713 724 self.m_BaseGraph.setXAxisAsTime()
714 725 #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02)
715 726
716 727
717 728 def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06):
718 729
719 730 if self.showColorbar:
720 731 xw -= xcmapw + deltaxcmap
721 732
722 733 if self.showPowerProfile:
723 734 xw -= xpoww + deltaxpow
724 735
725 736 xf = xi + xw
726 737 yf = yi + yw
727 738 xcmapf = xf
728 739
729 740 self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf])
730 741
731 742 if self.showColorbar:
732 743 xcmapi = xf + deltaxcmap
733 744 xcmapf = xcmapi + xcmapw
734 745
735 746 key = "colorbar"
736 747 cmapObj = self.graphObjDict[key]
737 748 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
738 749
739 750 if self.showPowerProfile:
740 751
741 752 xpowi = xcmapf + deltaxpow
742 753 xpowf = xpowi + xpoww
743 754
744 755 key = "powerprof"
745 756 powObj = self.graphObjDict[key]
746 757 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
747 758
748 759 def setRanges(self, xrange, yrange, zrange):
749 760
750 761 self.m_BaseGraph.setRanges(xrange, yrange, zrange)
751 762
752 763 keyList = self.graphObjDict.keys()
753 764
754 765 key = "colorbar"
755 766 if key in keyList:
756 767 cmapObj = self.graphObjDict[key]
757 768 cmapObj.setRanges([0., 1.], zrange)
758 769
759 770 key = "powerprof"
760 771 if key in keyList:
761 772 powObj = self.graphObjDict[key]
762 773 powObj.setRanges(zrange, yrange)
763 774
764 775 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
765 776 """
766 777 """
767 778
768 779 try:
769 780 nX, nY = numpy.shape(data)
770 781 except:
771 782 raise ValueError, "data is not a numpy array"
772 783
773 784 if x == None: x = numpy.arange(nX)
774 785 if y == None: y = numpy.arange(nY)
775 786
776 787 if xmin == None: xmin = x[0]
777 788 if xmax == None: xmax = x[-1]
778 789 if ymin == None: ymin = y[0]
779 790 if ymax == None: ymax = y[-1]
780 791 if zmin == None: zmin = numpy.nanmin(data)
781 792 if zmax == None: zmax = numpy.nanmax(data)
782 793
783 794 if self.m_BaseGraph.hasNotRange:
784 795 self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax])
785 796
786 797 self.m_BaseGraph.initSubpage()
787 798 self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.m_BaseGraph.zrange[0], self.m_BaseGraph.zrange[1])
788 799
789 800 if self.showColorbar:
790 801 key = "colorbar"
791 802 cmapObj = self.graphObjDict[key]
792 803 cmapObj.colorbarPlot()
793 804
794 805 if self.showPowerProfile:
795 806 power = numpy.average(data, axis=1)
796 807
797 808 step = (ymax - ymin)/(nY-1)
798 809 heis = numpy.arange(ymin, ymax + step, step)
799 810
800 811 key = "powerprof"
801 812 powObj = self.graphObjDict[key]
802 813 powObj.basicXYPlot(power, heis)
803 814
804 815 if __name__ == '__main__':
805 816
806 817 import numpy
807 818 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
808 819 plplot.plsdev("xwin")
809 820 plplot.plscolbg(255,255,255)
810 821 plplot.plscol0(1,0,0,0)
811 822 plplot.plspause(False)
812 823 plplot.plinit()
813 824 plplot.plssub(2, 2)
814 825
815 826 nx = 64
816 827 ny = 100
817 828
818 829 data = numpy.random.uniform(-50,50,(nx,ny))
819 830
820 831 baseObj = ColorPlot()
821 832 specObj = ColorPlot()
822 833 baseObj1 = ColorPlot()
823 834 specObj1 = ColorPlot()
824 835
825 836 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True)
826 837 specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True)
827 838
828 839 baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True)
829 840 specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True)
830 841
831 842 data = numpy.random.uniform(-50,50,(nx,ny))
832 843
833 844 plplot.plbop()
834 845 baseObj.iniSubpage()
835 846 baseObj.plotData(data)
836 847
837 848 specObj.iniSubpage()
838 849 specObj.plotData(data)
839 850
840 851 baseObj1.iniSubpage()
841 852 baseObj1.plotData(data)
842 853
843 854 specObj1.iniSubpage()
844 855 specObj1.plotData(data)
845 856
846 857 plplot.plflush()
847 858
848 859 plplot.plspause(1)
849 860 plplot.plend()
850 861 exit(0)
851 862
852 863
@@ -1,156 +1,168
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 import os, sys
9 9 import numpy
10 import datetime
10 11 import plplot
11 12
12 13 path = os.path.split(os.getcwd())[0]
13 14 sys.path.append(path)
14 15
15 16 from Graphics.BaseGraph import *
16 17 from Model.Spectra import Spectra
17 18
18 19 class Spectrum():
19 20
20 21 def __init__(self, Spectra):
21 22
22 23 """
23 24
24 25 Inputs:
25 26
26 27 type: "power" ->> Potencia
27 28 "iq" ->> Real + Imaginario
28 29 """
29 30
30 31 self.__isPlotConfig = False
31 32
32 33 self.__isPlotIni = False
33 34
34 35 self.__xrange = None
35 36
36 37 self.__yrange = None
37 38
38 39 self.nGraphs = 0
39 40
40 41 self.graphObjList = []
41 42
42 43 self.m_Spectra = Spectra
43 44
44 45
45 46 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
46 47
47 48 graphObj = ColorPlot()
48 49 graphObj.setup(subpage,
49 50 title,
50 51 xlabel,
51 52 ylabel,
52 53 showColorbar=showColorbar,
53 54 showPowerProfile=showPowerProfile,
54 55 XAxisAsTime=XAxisAsTime)
55 56
56 57 self.graphObjList.append(graphObj)
57 58
58 59
59 60 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
60 61
61 62 nChan = int(self.m_Spectra.m_SystemHeader.numChannels)
62 63 channels = range(nChan)
63 64
64 65 myXlabel = "Radial Velocity (m/s)"
65 66 myYlabel = "Range (km)"
66 67
67 68 for i in channels:
68 69 if titleList != None:
69 70 myTitle = titleList[i]
70 71 myXlabel = xlabelList[i]
71 72 myYlabel = ylabelList[i]
72 73
73 74 if self.m_Spectra.noise != None:
74 75 noise = '%4.2fdB' %(self.m_Spectra.noise[i])
75 76 else:
76 77 noise = '--'
77 78
78 79 myTitle = "Channel: %d - Noise: %s" %(i, noise)
79 80
80 81 self.__addGraph(i+1,
81 82 title=myTitle,
82 83 xlabel=myXlabel,
83 84 ylabel=myYlabel,
84 85 showColorbar=showColorbar,
85 86 showPowerProfile=showPowerProfile,
86 87 XAxisAsTime=XAxisAsTime)
87 88
88 89 self.nGraphs = nChan
89 90 self.__isPlotConfig = True
90 91
91 92 def iniPlot(self):
92 93
93 94 nx = int(numpy.sqrt(self.nGraphs)+1)
94 95 #ny = int(self.nGraphs/nx)
95 96
96 97 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
97 98 plplot.plsdev("xcairo")
98 99 plplot.plscolbg(255,255,255)
99 100 plplot.plscol0(1,0,0,0)
100 101 plplot.plinit()
101 102 plplot.plspause(False)
102 103 plplot.pladv(0)
103 104 plplot.plssub(nx, nx)
104 105
105 self.__isPlotIni = True
106 self.__nx = nx
107 self.__ny = nx
108 self.__isPlotIni = True
109
106 110
107 111 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
108 112
109 113 if not(self.__isPlotConfig):
110 114 self.setup(titleList,
111 115 xlabelList,
112 116 ylabelList,
113 117 showColorbar,
114 118 showPowerProfile,
115 119 XAxisAsTime)
116 120
117 121 if not(self.__isPlotIni):
118 122 self.iniPlot()
119 123
120 124 data = 10.*numpy.log10(self.m_Spectra.data_spc)
121 125
122 126 nX, nY, nChan = numpy.shape(data)
123 127
124 128 x = numpy.arange(nX)
125 129 y = self.m_Spectra.heights
126 130
131 thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc)
132 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
133
127 134 if xmin == None: xmin = x[0]
128 135 if xmax == None: xmax = x[-1]
129 136 if ymin == None: ymin = y[0]
130 137 if ymax == None: ymax = y[-1]
131 138 if zmin == None: zmin = numpy.nanmin(abs(data))
132 139 if zmax == None: zmax = numpy.nanmax(abs(data))
133 140
134 141 plplot.plbop()
142
143 plplot.plssub(self.__nx, self.__ny)
135 144 for i in range(self.nGraphs):
136 145 self.graphObjList[i].iniSubpage()
137 146 self.graphObjList[i].plotData(data[i,:,:],
138 147 x,
139 148 y,
140 149 xmin=xmin,
141 150 xmax=xmax,
142 151 ymin=ymin,
143 152 ymax=ymax,
144 153 zmin=zmin,
145 154 zmax=zmax)
146
147 155
156 plplot.plssub(1,0)
157 plplot.pladv(0)
158 plplot.plvpor(0., 1., 0., 1.)
159 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
148 160 plplot.plflush()
149 161 plplot.pleop()
150 162
151 163 def end(self):
152 164 plplot.plend()
153 165
154 166
155 167 if __name__ == '__main__':
156 168 pass No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now