@@ -9,6 +9,7 import numpy | |||
|
9 | 9 | |
|
10 | 10 | def cmap1_init(colormap="gray"): |
|
11 | 11 | |
|
12 | ncolor = None | |
|
12 | 13 | rgb_lvl = None |
|
13 | 14 | |
|
14 | 15 | # Routine for defining a specific color map 1 in HLS space. |
@@ -18,6 +19,7 def cmap1_init(colormap="gray"): | |||
|
18 | 19 | # Independent variable of control points. |
|
19 | 20 | i = numpy.array((0., 1.)) |
|
20 | 21 | if colormap=="gray": |
|
22 | ncolor = 256 | |
|
21 | 23 | # Hue for control points. Doesn't matter since saturation is zero. |
|
22 | 24 | h = numpy.array((0., 0.)) |
|
23 | 25 | # Lightness ranging from half-dark (for interest) to light. |
@@ -26,13 +28,14 def cmap1_init(colormap="gray"): | |||
|
26 | 28 | s = numpy.array((0., 0.)) |
|
27 | 29 | |
|
28 | 30 | # number of cmap1 colours is 256 in this case. |
|
29 |
plplot.plscmap1n( |
|
|
31 | plplot.plscmap1n(ncolor) | |
|
30 | 32 | # Interpolate between control points to set up cmap1. |
|
31 | 33 | plplot.plscmap1l(0, i, h, l, s) |
|
32 | 34 | |
|
33 | 35 | return None |
|
34 | 36 | |
|
35 | 37 | if colormap=="br_black": |
|
38 | ncolor = 256 | |
|
36 | 39 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
37 | 40 | h = numpy.array((240., 0.)) |
|
38 | 41 | # Lightness and saturation are constant (values taken from C example). |
@@ -40,13 +43,14 def cmap1_init(colormap="gray"): | |||
|
40 | 43 | s = numpy.array((0.8, 0.8)) |
|
41 | 44 | |
|
42 | 45 | # number of cmap1 colours is 256 in this case. |
|
43 |
plplot.plscmap1n( |
|
|
46 | plplot.plscmap1n(ncolor) | |
|
44 | 47 | # Interpolate between control points to set up cmap1. |
|
45 | 48 | plplot.plscmap1l(0, i, h, l, s) |
|
46 | 49 | |
|
47 | 50 | return None |
|
48 | 51 | |
|
49 | 52 | if colormap=="tricolor": |
|
53 | ncolor = 3 | |
|
50 | 54 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
51 | 55 | h = numpy.array((240., 0.)) |
|
52 | 56 | # Lightness and saturation are constant (values taken from C example). |
@@ -54,7 +58,7 def cmap1_init(colormap="gray"): | |||
|
54 | 58 | s = numpy.array((0.8, 0.8)) |
|
55 | 59 | |
|
56 | 60 | # number of cmap1 colours is 256 in this case. |
|
57 |
plplot.plscmap1n( |
|
|
61 | plplot.plscmap1n(ncolor) | |
|
58 | 62 | # Interpolate between control points to set up cmap1. |
|
59 | 63 | plplot.plscmap1l(0, i, h, l, s) |
|
60 | 64 | |
@@ -129,7 +133,10 def cmap1_init(colormap="gray"): | |||
|
129 | 133 | pos[ind] = ind/(ncolor-1.0) |
|
130 | 134 | ind += 1 |
|
131 | 135 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
132 |
|
|
|
136 | ||
|
137 | if ncolor == None: | |
|
138 | raise ValueError, "The colormap selected is not valid" | |
|
139 | ||
|
133 | 140 | plplot.plscmap1n(ncolor) |
|
134 | 141 | plplot.plscmap1l(1, pos, r, g, b) |
|
135 | 142 | |
@@ -139,6 +146,9 class BasicGraph(): | |||
|
139 | 146 | """ |
|
140 | 147 | |
|
141 | 148 | """ |
|
149 | ||
|
150 | hasRange = False | |
|
151 | ||
|
142 | 152 | xrange = None |
|
143 | 153 | yrange = None |
|
144 | 154 | zrange = None |
@@ -177,7 +187,27 class BasicGraph(): | |||
|
177 | 187 | |
|
178 | 188 | """ |
|
179 | 189 | pass |
|
180 | ||
|
190 | ||
|
191 | def hasNotXrange(self): | |
|
192 | ||
|
193 | if self.xrange == None: | |
|
194 | return 1 | |
|
195 | ||
|
196 | return 0 | |
|
197 | ||
|
198 | def hasNotYrange(self): | |
|
199 | ||
|
200 | if self.yrange == None: | |
|
201 | return 1 | |
|
202 | ||
|
203 | return 0 | |
|
204 | ||
|
205 | def hasNotZrange(self): | |
|
206 | ||
|
207 | if self.zrange == None: | |
|
208 | return 1 | |
|
209 | ||
|
210 | return 0 | |
|
181 | 211 | def setName(self, name): |
|
182 | 212 | self.__name = name |
|
183 | 213 | |
@@ -185,28 +215,38 class BasicGraph(): | |||
|
185 | 215 | self.__xpos = xpos |
|
186 | 216 | self.__ypos = ypos |
|
187 | 217 | |
|
188 | def setScreenPos(self, xoff, yoff, xw, yw): | |
|
218 | def setScreenPosbyWidth(self, xoff, yoff, xw, yw): | |
|
189 | 219 | self.__xpos = [xoff, xoff + xw] |
|
190 | 220 | self.__ypos = [yoff, yoff + yw] |
|
191 | 221 | |
|
192 | 222 | def setSubpage(self, subpage): |
|
193 | 223 | self.__subpage = subpage |
|
224 | ||
|
225 | def setSzchar(self, szchar): | |
|
226 | self.__szchar = szchar | |
|
227 | ||
|
228 | def setOpt(self, xopt, yopt): | |
|
229 | self.__xopt = xopt | |
|
230 | self.__yopt = yopt | |
|
194 | 231 | |
|
195 | def setRanges(self, xrange, yrange, zrange): | |
|
232 | def setRanges(self, xrange, yrange, zrange=None): | |
|
196 | 233 | """ |
|
197 | 234 | """ |
|
198 | 235 | self.xrange = xrange |
|
236 | ||
|
199 | 237 | self.yrange = yrange |
|
200 | self.zrange = zrange | |
|
238 | ||
|
239 | if zrange != None: | |
|
240 | self.zrange = zrange | |
|
201 | 241 | |
|
202 |
def |
|
|
242 | def setColormap(self, colormap=None): | |
|
203 | 243 | |
|
204 | 244 | if colormap == None: |
|
205 | 245 | colormap = self.__colormap |
|
206 | 246 | |
|
207 | 247 | cmap1_init(colormap) |
|
208 | 248 | |
|
209 |
def |
|
|
249 | def plotBox(self): | |
|
210 | 250 | """ |
|
211 | 251 | |
|
212 | 252 | """ |
@@ -221,30 +261,62 class BasicGraph(): | |||
|
221 | 261 | self.title = title |
|
222 | 262 | self.xlabel = xlabel |
|
223 | 263 | self.ylabel = ylabel |
|
224 | self.colormap = colormap | |
|
264 | self.__colormap = colormap | |
|
225 | 265 | |
|
226 | 266 | def initSubpage(self): |
|
267 | ||
|
268 | if plplot.plgdev() == '': | |
|
269 | raise ValueError, "Plot device has not been initialize" | |
|
270 | ||
|
227 | 271 | plplot.pladv(self.__subpage) |
|
228 | 272 | plplot.plschr(0.0, self.__szchar) |
|
229 | 273 | |
|
230 | 274 | if self.__xrangeIsTime: |
|
231 | 275 | plplot.pltimefmt("%H:%M") |
|
232 | 276 | |
|
233 |
self. |
|
|
277 | self.setColormap() | |
|
234 | 278 | self.initPlot() |
|
235 | 279 | |
|
236 | 280 | def initPlot(self): |
|
237 | 281 | """ |
|
238 | 282 | |
|
239 | 283 | """ |
|
284 | if plplot.plgdev() == '': | |
|
285 | raise ValueError, "Plot device has not been initialize" | |
|
286 | ||
|
287 | xrange = self.xrange | |
|
288 | if xrange == None: | |
|
289 | xrange = [0., 1.] | |
|
290 | ||
|
291 | yrange = self.yrange | |
|
292 | if yrange == None: | |
|
293 | yrange = [0., 1.] | |
|
294 | ||
|
240 | 295 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) |
|
241 |
plplot.plwind( |
|
|
296 | plplot.plwind(xrange[0], xrange[1], yrange[0], yrange[1]) | |
|
242 | 297 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) |
|
243 | 298 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
244 |
|
|
|
245 | ||
|
246 | def basicXYPlot(self): | |
|
247 | pass | |
|
299 | ||
|
300 | def colorbarPlot(self): | |
|
301 | data = numpy.arange(256) | |
|
302 | data = numpy.reshape(data, (1,-1)) | |
|
303 | ||
|
304 | self.plotBox() | |
|
305 | plplot.plimage(data, | |
|
306 | self.xrange[0], | |
|
307 | self.xrange[1], | |
|
308 | self.yrange[0], | |
|
309 | self.yrange[1], | |
|
310 | 0., | |
|
311 | 255., | |
|
312 | self.xrange[0], | |
|
313 | self.xrange[1], | |
|
314 | self.yrange[0], | |
|
315 | self.yrange[1],) | |
|
316 | ||
|
317 | def basicXYPlot(self, x, y): | |
|
318 | self.plotBox() | |
|
319 | plplot.plline(x, y) | |
|
248 | 320 | |
|
249 | 321 | def basicXYwithErrorPlot(self): |
|
250 | 322 | pass |
@@ -256,7 +328,7 class BasicGraph(): | |||
|
256 | 328 | """ |
|
257 | 329 | """ |
|
258 | 330 | |
|
259 |
self. |
|
|
331 | self.plotBox() | |
|
260 | 332 | plplot.plimage(data, xmin, xmax, ymin, ymax, zmin, zmax, xmin, xmax, ymin, ymax) |
|
261 | 333 | |
|
262 | 334 | |
@@ -295,18 +367,14 class Graph(): | |||
|
295 | 367 | |
|
296 | 368 | def __init__(self): |
|
297 | 369 | raise |
|
298 | ||
|
299 | def setup(self): | |
|
300 | raise | |
|
301 | ||
|
302 | def plotData(self): | |
|
303 | raise | |
|
304 | 370 | |
|
305 | 371 | class Spectrum(Graph): |
|
306 | 372 | |
|
373 | ||
|
307 | 374 | showColorbar = False |
|
308 | 375 | showPowerProfile = True |
|
309 | 376 | |
|
377 | __szchar = 0.7 | |
|
310 | 378 | |
|
311 | 379 | def __init__(self): |
|
312 | 380 | |
@@ -318,20 +386,20 class Spectrum(Graph): | |||
|
318 | 386 | self.graphObjDict[key] = specObj |
|
319 | 387 | |
|
320 | 388 | |
|
321 | def setup(self, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False): | |
|
322 | ||
|
323 | xi = 0.12 | |
|
324 | xw = 0.86 | |
|
325 | xf = xi + xw | |
|
389 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False): | |
|
390 | """ | |
|
391 | """ | |
|
326 | 392 | |
|
327 | yi = 0.14 | |
|
328 | yw = 0.80 | |
|
329 | yf = yi + yw | |
|
393 | xi = 0.12; xw = 0.78; xf = xi + xw | |
|
394 | yi = 0.14; yw = 0.80; yf = yi + yw | |
|
330 | 395 | |
|
331 | xcmapi = xcmapf = 0. | |
|
332 | xpowi = xpowf = 0. | |
|
396 | xcmapi = xcmapf = 0.; xpowi = xpowf = 0. | |
|
333 | 397 | |
|
334 | specObj = self.graphObjDict[0] | |
|
398 | key = "spec" | |
|
399 | specObj = self.graphObjDict[key] | |
|
400 | specObj.setSubpage(subpage) | |
|
401 | specObj.setSzchar(self.__szchar) | |
|
402 | specObj.setOpt("bcnts","bcnts") | |
|
335 | 403 | specObj.setup(title, |
|
336 | 404 | xlabel, |
|
337 | 405 | ylabel, |
@@ -342,15 +410,18 class Spectrum(Graph): | |||
|
342 | 410 | |
|
343 | 411 | cmapObj = BasicGraph() |
|
344 | 412 | cmapObj.setName(key) |
|
413 | cmapObj.setSubpage(subpage) | |
|
414 | cmapObj.setSzchar(self.__szchar) | |
|
415 | cmapObj.setOpt("bc","bcmt") | |
|
345 | 416 | cmapObj.setup(title="dBs", |
|
346 | 417 | xlabel="", |
|
347 | 418 | ylabel="", |
|
348 | 419 | colormap=colormap) |
|
349 | 420 | |
|
350 |
self.graphObjDict[key] = cmapObj |
|
|
421 | self.graphObjDict[key] = cmapObj | |
|
351 | 422 | |
|
352 | 423 | xcmapi = 0. |
|
353 |
xcmapw = 0. |
|
|
424 | xcmapw = 0.05 | |
|
354 | 425 | xw -= xcmapw |
|
355 | 426 | |
|
356 | 427 | if showPowerProfile: |
@@ -358,45 +429,50 class Spectrum(Graph): | |||
|
358 | 429 | |
|
359 | 430 | powObj = BasicGraph() |
|
360 | 431 | powObj.setName(key) |
|
432 | powObj.setSubpage(subpage) | |
|
433 | powObj.setSzchar(self.__szchar) | |
|
434 | plplot.pllsty(2) | |
|
435 | powObj.setOpt("bcntg","bc") | |
|
436 | plplot.pllsty(1) | |
|
361 | 437 | powObj.setup(title="Power Profile", |
|
362 | 438 | xlabel="dBs", |
|
363 | 439 | ylabel="") |
|
364 | 440 | |
|
365 |
self.graphObjDict[key] = powObj |
|
|
441 | self.graphObjDict[key] = powObj | |
|
366 | 442 | |
|
367 | 443 | xpowi = 0. |
|
368 |
xpoww = 0.2 |
|
|
444 | xpoww = 0.24 | |
|
369 | 445 | xw -= xpoww |
|
370 | 446 | |
|
371 | 447 | xf = xi + xw |
|
372 | 448 | yf = yi + yw |
|
373 | 449 | xcmapf = xf |
|
374 | 450 | |
|
375 |
specObj.setScreenPos([xi, |
|
|
451 | specObj.setScreenPos([xi, xf], [yi, yf]) | |
|
376 | 452 | |
|
377 | 453 | if showColorbar: |
|
378 | xcmapi = xf + 0.2 | |
|
454 | xcmapi = xf + 0.02 | |
|
379 | 455 | xcmapf = xcmapi + xcmapw |
|
380 |
cmapObj.setScreenPos([xcmapi, |
|
|
456 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |
|
381 | 457 | |
|
382 | 458 | if showPowerProfile: |
|
383 |
xpowi = xcmapf + 0. |
|
|
459 | xpowi = xcmapf + 0.06 | |
|
384 | 460 | xpowf = xpowi + xpoww |
|
385 |
powObj.setScreenPos([xpowi, |
|
|
461 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |
|
386 | 462 | |
|
387 | 463 | |
|
388 | specObj.initSubpage() | |
|
389 | ||
|
390 | if showColorbar: | |
|
391 | cmapObj.initPlot() | |
|
392 | ||
|
393 | if showPowerProfile: | |
|
394 | powObj.initPlot() | |
|
464 | # specObj.initSubpage() | |
|
465 | # | |
|
466 | # if showColorbar: | |
|
467 | # cmapObj.initPlot() | |
|
468 | # | |
|
469 | # if showPowerProfile: | |
|
470 | # powObj.initPlot() | |
|
395 | 471 | |
|
396 | 472 | self.showColorbar = showColorbar |
|
397 | 473 | self.showPowerProfile = showPowerProfile |
|
398 | 474 | |
|
399 |
def setRanges(self, xrange |
|
|
475 | def setRanges(self, xrange, yrange, zrange): | |
|
400 | 476 | |
|
401 | 477 | key = "spec" |
|
402 | 478 | specObj = self.graphObjDict[key] |
@@ -407,17 +483,57 class Spectrum(Graph): | |||
|
407 | 483 | key = "colorbar" |
|
408 | 484 | if key in keyList: |
|
409 | 485 | cmapObj = self.graphObjDict[key] |
|
410 |
cmapObj.setRanges([0., 1.], zrange |
|
|
486 | cmapObj.setRanges([0., 1.], zrange) | |
|
411 | 487 | |
|
412 | 488 | key = "powerprof" |
|
413 | 489 | if key in keyList: |
|
414 | 490 | powObj = self.graphObjDict[key] |
|
415 | 491 | powObj.setRanges(zrange, yrange) |
|
416 | 492 | |
|
417 | def plotData(self, data , xmin, xmax, ymin, ymax): | |
|
493 | def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
|
418 | 494 | |
|
419 | pass | |
|
495 | key = "spec" | |
|
496 | specObj = self.graphObjDict[key] | |
|
497 | specObj.initSubpage() | |
|
498 | ||
|
499 | if xmin == None: | |
|
500 | xmin = 0. | |
|
501 | ||
|
502 | if xmax == None: | |
|
503 | xmax = 1. | |
|
420 | 504 | |
|
505 | if ymin == None: | |
|
506 | ymin = 0. | |
|
507 | ||
|
508 | if ymax == None: | |
|
509 | ymax = 1. | |
|
510 | ||
|
511 | if zmin == None: | |
|
512 | zmin = numpy.nanmin(data) | |
|
513 | ||
|
514 | if zmax == None: | |
|
515 | zmax = numpy.nanmax(data) | |
|
516 | ||
|
517 | if not(specObj.hasRange): | |
|
518 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) | |
|
519 | ||
|
520 | specObj.basicPcolorPlot(data, xmin, xmax, ymin, ymax, specObj.zrange[0], specObj.zrange[1]) | |
|
521 | ||
|
522 | if self.showColorbar: | |
|
523 | key = "colorbar" | |
|
524 | cmapObj = self.graphObjDict[key] | |
|
525 | cmapObj.colorbarPlot() | |
|
526 | ||
|
527 | if self.showPowerProfile: | |
|
528 | power = numpy.average(data, axis=1) | |
|
529 | ||
|
530 | step = (ymax - ymin)/(power.shape[0]-1) | |
|
531 | heis = numpy.arange(ymin, ymax + step, step) | |
|
532 | ||
|
533 | key = "powerprof" | |
|
534 | powObj = self.graphObjDict[key] | |
|
535 | powObj.basicXYPlot(power, heis) | |
|
536 | ||
|
421 | 537 | class CrossSpectrum(Graph): |
|
422 | 538 | |
|
423 | 539 | def __init__(self): |
@@ -968,7 +1084,30 class PlotData(): | |||
|
968 | 1084 | if __name__ == '__main__': |
|
969 | 1085 | |
|
970 | 1086 | import numpy |
|
971 | data = numpy.random.uniform(-50,50,(150,250)) | |
|
1087 | plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) | |
|
1088 | plplot.plsdev("xcairo") | |
|
1089 | plplot.plscolbg(255,255,255) | |
|
1090 | plplot.plscol0(1,0,0,0) | |
|
1091 | plplot.plinit() | |
|
1092 | plplot.plssub(2, 2) | |
|
1093 | ||
|
1094 | nx = 64 | |
|
1095 | ny = 100 | |
|
1096 | ||
|
1097 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
|
1098 | ||
|
1099 | specObj = Spectrum() | |
|
1100 | specObj.setup(1, "Spectrum", "Frequency", "Range", "br_black", True, True) | |
|
1101 | specObj.plotData(data) | |
|
1102 | ||
|
1103 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
|
1104 | ||
|
1105 | spec2Obj = Spectrum() | |
|
1106 | spec2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_black", True, True) | |
|
1107 | spec2Obj.plotData(data) | |
|
1108 | ||
|
1109 | plplot.plend() | |
|
1110 | exit(0) | |
|
972 | 1111 | |
|
973 | 1112 | objPlot = PlotData() |
|
974 | 1113 | objPlot.addGraph(1, "Frequency", "Height", "Channel A") |
General Comments 0
You need to be logged in to leave comments.
Login now