This diff has been collapsed as it changes many lines, (990 lines changed) Show them Hide them | |||||
@@ -0,0 +1,990 | |||||
|
1 | ''' | |||
|
2 | Created on Jan 25, 2012 | |||
|
3 | ||||
|
4 | @author: Miguel Urco | |||
|
5 | ''' | |||
|
6 | ||||
|
7 | import plplot | |||
|
8 | import numpy | |||
|
9 | ||||
|
10 | def cmap1_init(colormap="gray"): | |||
|
11 | ||||
|
12 | rgb_lvl = None | |||
|
13 | ||||
|
14 | # Routine for defining a specific color map 1 in HLS space. | |||
|
15 | # if gray is true, use basic grayscale variation from half-dark to light. | |||
|
16 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |||
|
17 | ||||
|
18 | # Independent variable of control points. | |||
|
19 | i = numpy.array((0., 1.)) | |||
|
20 | if colormap=="gray": | |||
|
21 | # Hue for control points. Doesn't matter since saturation is zero. | |||
|
22 | h = numpy.array((0., 0.)) | |||
|
23 | # Lightness ranging from half-dark (for interest) to light. | |||
|
24 | l = numpy.array((0.5, 1.)) | |||
|
25 | # Gray scale has zero saturation | |||
|
26 | s = numpy.array((0., 0.)) | |||
|
27 | ||||
|
28 | # number of cmap1 colours is 256 in this case. | |||
|
29 | plplot.plscmap1n(256) | |||
|
30 | # Interpolate between control points to set up cmap1. | |||
|
31 | plplot.plscmap1l(0, i, h, l, s) | |||
|
32 | ||||
|
33 | return None | |||
|
34 | ||||
|
35 | if colormap=="br_black": | |||
|
36 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
37 | h = numpy.array((240., 0.)) | |||
|
38 | # Lightness and saturation are constant (values taken from C example). | |||
|
39 | l = numpy.array((0.6, 0.6)) | |||
|
40 | s = numpy.array((0.8, 0.8)) | |||
|
41 | ||||
|
42 | # number of cmap1 colours is 256 in this case. | |||
|
43 | plplot.plscmap1n(256) | |||
|
44 | # Interpolate between control points to set up cmap1. | |||
|
45 | plplot.plscmap1l(0, i, h, l, s) | |||
|
46 | ||||
|
47 | return None | |||
|
48 | ||||
|
49 | if colormap=="tricolor": | |||
|
50 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
51 | h = numpy.array((240., 0.)) | |||
|
52 | # Lightness and saturation are constant (values taken from C example). | |||
|
53 | l = numpy.array((0.6, 0.6)) | |||
|
54 | s = numpy.array((0.8, 0.8)) | |||
|
55 | ||||
|
56 | # number of cmap1 colours is 256 in this case. | |||
|
57 | plplot.plscmap1n(3) | |||
|
58 | # Interpolate between control points to set up cmap1. | |||
|
59 | plplot.plscmap1l(0, i, h, l, s) | |||
|
60 | ||||
|
61 | return None | |||
|
62 | ||||
|
63 | if colormap == 'rgb' or colormap == 'rgb666': | |||
|
64 | ||||
|
65 | color_sz = 6 | |||
|
66 | ncolor = color_sz*color_sz*color_sz | |||
|
67 | pos = numpy.zeros((ncolor)) | |||
|
68 | r = numpy.zeros((ncolor)) | |||
|
69 | g = numpy.zeros((ncolor)) | |||
|
70 | b = numpy.zeros((ncolor)) | |||
|
71 | ind = 0 | |||
|
72 | for ri in range(color_sz): | |||
|
73 | for gi in range(color_sz): | |||
|
74 | for bi in range(color_sz): | |||
|
75 | r[ind] = ri/(color_sz-1.0) | |||
|
76 | g[ind] = gi/(color_sz-1.0) | |||
|
77 | b[ind] = bi/(color_sz-1.0) | |||
|
78 | pos[ind] = ind/(ncolor-1.0) | |||
|
79 | ind += 1 | |||
|
80 | rgb_lvl = [6,6,6] #Levels for RGB colors | |||
|
81 | ||||
|
82 | if colormap == 'rgb676': | |||
|
83 | ncolor = 6*7*6 | |||
|
84 | pos = numpy.zeros((ncolor)) | |||
|
85 | r = numpy.zeros((ncolor)) | |||
|
86 | g = numpy.zeros((ncolor)) | |||
|
87 | b = numpy.zeros((ncolor)) | |||
|
88 | ind = 0 | |||
|
89 | for ri in range(8): | |||
|
90 | for gi in range(8): | |||
|
91 | for bi in range(4): | |||
|
92 | r[ind] = ri/(6-1.0) | |||
|
93 | g[ind] = gi/(7-1.0) | |||
|
94 | b[ind] = bi/(6-1.0) | |||
|
95 | pos[ind] = ind/(ncolor-1.0) | |||
|
96 | ind += 1 | |||
|
97 | rgb_lvl = [6,7,6] #Levels for RGB colors | |||
|
98 | ||||
|
99 | if colormap == 'rgb685': | |||
|
100 | ncolor = 6*8*5 | |||
|
101 | pos = numpy.zeros((ncolor)) | |||
|
102 | r = numpy.zeros((ncolor)) | |||
|
103 | g = numpy.zeros((ncolor)) | |||
|
104 | b = numpy.zeros((ncolor)) | |||
|
105 | ind = 0 | |||
|
106 | for ri in range(8): | |||
|
107 | for gi in range(8): | |||
|
108 | for bi in range(4): | |||
|
109 | r[ind] = ri/(6-1.0) | |||
|
110 | g[ind] = gi/(8-1.0) | |||
|
111 | b[ind] = bi/(5-1.0) | |||
|
112 | pos[ind] = ind/(ncolor-1.0) | |||
|
113 | ind += 1 | |||
|
114 | rgb_lvl = [6,8,5] #Levels for RGB colors | |||
|
115 | ||||
|
116 | if colormap == 'rgb884': | |||
|
117 | ncolor = 8*8*4 | |||
|
118 | pos = numpy.zeros((ncolor)) | |||
|
119 | r = numpy.zeros((ncolor)) | |||
|
120 | g = numpy.zeros((ncolor)) | |||
|
121 | b = numpy.zeros((ncolor)) | |||
|
122 | ind = 0 | |||
|
123 | for ri in range(8): | |||
|
124 | for gi in range(8): | |||
|
125 | for bi in range(4): | |||
|
126 | r[ind] = ri/(8-1.0) | |||
|
127 | g[ind] = gi/(8-1.0) | |||
|
128 | b[ind] = bi/(4-1.0) | |||
|
129 | pos[ind] = ind/(ncolor-1.0) | |||
|
130 | ind += 1 | |||
|
131 | rgb_lvl = [8,8,4] #Levels for RGB colors | |||
|
132 | ||||
|
133 | plplot.plscmap1n(ncolor) | |||
|
134 | plplot.plscmap1l(1, pos, r, g, b) | |||
|
135 | ||||
|
136 | return rgb_lvl | |||
|
137 | ||||
|
138 | class BasicGraph(): | |||
|
139 | """ | |||
|
140 | ||||
|
141 | """ | |||
|
142 | xrange = None | |||
|
143 | yrange = None | |||
|
144 | zrange = None | |||
|
145 | ||||
|
146 | xlabel = None | |||
|
147 | ylabel = None | |||
|
148 | title = None | |||
|
149 | ||||
|
150 | legends = None | |||
|
151 | ||||
|
152 | __name = None | |||
|
153 | __subpage = None | |||
|
154 | __szchar = None | |||
|
155 | ||||
|
156 | __colormap = None | |||
|
157 | __colbox = None | |||
|
158 | __colleg = None | |||
|
159 | ||||
|
160 | __xpos = None | |||
|
161 | __ypos = None | |||
|
162 | ||||
|
163 | __xopt = None #"bcnst" | |||
|
164 | __yopt = None #"bcnstv" | |||
|
165 | ||||
|
166 | __xlpos = None | |||
|
167 | __ylpos = None | |||
|
168 | ||||
|
169 | __xrangeIsTime = None | |||
|
170 | ||||
|
171 | #Advanced | |||
|
172 | __xg = None | |||
|
173 | __yg = None | |||
|
174 | ||||
|
175 | def __init__(self): | |||
|
176 | """ | |||
|
177 | ||||
|
178 | """ | |||
|
179 | pass | |||
|
180 | ||||
|
181 | def setName(self, name): | |||
|
182 | self.__name = name | |||
|
183 | ||||
|
184 | def setScreenPos(self, xpos, ypos): | |||
|
185 | self.__xpos = xpos | |||
|
186 | self.__ypos = ypos | |||
|
187 | ||||
|
188 | def setScreenPos(self, xoff, yoff, xw, yw): | |||
|
189 | self.__xpos = [xoff, xoff + xw] | |||
|
190 | self.__ypos = [yoff, yoff + yw] | |||
|
191 | ||||
|
192 | def setSubpage(self, subpage): | |||
|
193 | self.__subpage = subpage | |||
|
194 | ||||
|
195 | def setRanges(self, xrange, yrange, zrange): | |||
|
196 | """ | |||
|
197 | """ | |||
|
198 | self.xrange = xrange | |||
|
199 | self.yrange = yrange | |||
|
200 | self.zrange = zrange | |||
|
201 | ||||
|
202 | def __setColormap(self, colormap=None): | |||
|
203 | ||||
|
204 | if colormap == None: | |||
|
205 | colormap = self.__colormap | |||
|
206 | ||||
|
207 | cmap1_init(colormap) | |||
|
208 | ||||
|
209 | def __setBox(self): | |||
|
210 | """ | |||
|
211 | ||||
|
212 | """ | |||
|
213 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |||
|
214 | plplot.plwind(self.xrange[0], self.xrange[1], self.yrange[0], self.yrange[1]) | |||
|
215 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) | |||
|
216 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |||
|
217 | ||||
|
218 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): | |||
|
219 | """ | |||
|
220 | """ | |||
|
221 | self.title = title | |||
|
222 | self.xlabel = xlabel | |||
|
223 | self.ylabel = ylabel | |||
|
224 | self.colormap = colormap | |||
|
225 | ||||
|
226 | def initSubpage(self): | |||
|
227 | plplot.pladv(self.__subpage) | |||
|
228 | plplot.plschr(0.0, self.__szchar) | |||
|
229 | ||||
|
230 | if self.__xrangeIsTime: | |||
|
231 | plplot.pltimefmt("%H:%M") | |||
|
232 | ||||
|
233 | self.__setColormap() | |||
|
234 | self.initPlot() | |||
|
235 | ||||
|
236 | def initPlot(self): | |||
|
237 | """ | |||
|
238 | ||||
|
239 | """ | |||
|
240 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |||
|
241 | plplot.plwind(self.xrange[0], self.xrange[1], self.yrange[0], self.yrange[1]) | |||
|
242 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) | |||
|
243 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |||
|
244 | ||||
|
245 | ||||
|
246 | def basicXYPlot(self): | |||
|
247 | pass | |||
|
248 | ||||
|
249 | def basicXYwithErrorPlot(self): | |||
|
250 | pass | |||
|
251 | ||||
|
252 | def basicLineTimePlot(self): | |||
|
253 | pass | |||
|
254 | ||||
|
255 | def basicPcolorPlot(self, data, xmin, xmax, ymin, ymax, zmin, zmax): | |||
|
256 | """ | |||
|
257 | """ | |||
|
258 | ||||
|
259 | self.__setBox() | |||
|
260 | plplot.plimage(data, xmin, xmax, ymin, ymax, zmin, zmax, xmin, xmax, ymin, ymax) | |||
|
261 | ||||
|
262 | ||||
|
263 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): | |||
|
264 | ||||
|
265 | if not(len(x)>1 and len(y)>1): | |||
|
266 | raise ValueError, "x axis and y axis are empty" | |||
|
267 | ||||
|
268 | if deltax == None: deltax = x[-1] - x[-2] | |||
|
269 | if deltay == None: deltay = y[-1] - y[-2] | |||
|
270 | ||||
|
271 | x1 = numpy.append(x, x[-1] + deltax) | |||
|
272 | y1 = numpy.append(y, y[-1] + deltay) | |||
|
273 | ||||
|
274 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |||
|
275 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |||
|
276 | ||||
|
277 | self.__xg = xg | |||
|
278 | self.__yg = yg | |||
|
279 | ||||
|
280 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): | |||
|
281 | """ | |||
|
282 | """ | |||
|
283 | ||||
|
284 | if self.__xg == None and self.__yg == None: | |||
|
285 | self.__getBoxpltr(x, y) | |||
|
286 | ||||
|
287 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) | |||
|
288 | ||||
|
289 | ||||
|
290 | class Graph(): | |||
|
291 | """ | |||
|
292 | """ | |||
|
293 | ||||
|
294 | graphObjDict = {} | |||
|
295 | ||||
|
296 | def __init__(self): | |||
|
297 | raise | |||
|
298 | ||||
|
299 | def setup(self): | |||
|
300 | raise | |||
|
301 | ||||
|
302 | def plotData(self): | |||
|
303 | raise | |||
|
304 | ||||
|
305 | class Spectrum(Graph): | |||
|
306 | ||||
|
307 | showColorbar = False | |||
|
308 | showPowerProfile = True | |||
|
309 | ||||
|
310 | ||||
|
311 | def __init__(self): | |||
|
312 | ||||
|
313 | key = "spec" | |||
|
314 | ||||
|
315 | specObj = BasicGraph() | |||
|
316 | specObj.setName(key) | |||
|
317 | ||||
|
318 | self.graphObjDict[key] = specObj | |||
|
319 | ||||
|
320 | ||||
|
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 | |||
|
326 | ||||
|
327 | yi = 0.14 | |||
|
328 | yw = 0.80 | |||
|
329 | yf = yi + yw | |||
|
330 | ||||
|
331 | xcmapi = xcmapf = 0. | |||
|
332 | xpowi = xpowf = 0. | |||
|
333 | ||||
|
334 | specObj = self.graphObjDict[0] | |||
|
335 | specObj.setup(title, | |||
|
336 | xlabel, | |||
|
337 | ylabel, | |||
|
338 | colormap) | |||
|
339 | ||||
|
340 | if showColorbar: | |||
|
341 | key = "colorbar" | |||
|
342 | ||||
|
343 | cmapObj = BasicGraph() | |||
|
344 | cmapObj.setName(key) | |||
|
345 | cmapObj.setup(title="dBs", | |||
|
346 | xlabel="", | |||
|
347 | ylabel="", | |||
|
348 | colormap=colormap) | |||
|
349 | ||||
|
350 | self.graphObjDict[key] = cmapObject | |||
|
351 | ||||
|
352 | xcmapi = 0. | |||
|
353 | xcmapw = 0.16 | |||
|
354 | xw -= xcmapw | |||
|
355 | ||||
|
356 | if showPowerProfile: | |||
|
357 | key = "powerprof" | |||
|
358 | ||||
|
359 | powObj = BasicGraph() | |||
|
360 | powObj.setName(key) | |||
|
361 | powObj.setup(title="Power Profile", | |||
|
362 | xlabel="dBs", | |||
|
363 | ylabel="") | |||
|
364 | ||||
|
365 | self.graphObjDict[key] = powObject | |||
|
366 | ||||
|
367 | xpowi = 0. | |||
|
368 | xpoww = 0.23 | |||
|
369 | xw -= xpoww | |||
|
370 | ||||
|
371 | xf = xi + xw | |||
|
372 | yf = yi + yw | |||
|
373 | xcmapf = xf | |||
|
374 | ||||
|
375 | specObj.setScreenPos([xi, yf], [yi, yf]) | |||
|
376 | ||||
|
377 | if showColorbar: | |||
|
378 | xcmapi = xf + 0.2 | |||
|
379 | xcmapf = xcmapi + xcmapw | |||
|
380 | cmapObj.setScreenPos([xcmapi, ycmapf], [ycmapi, ycmapf]) | |||
|
381 | ||||
|
382 | if showPowerProfile: | |||
|
383 | xpowi = xcmapf + 0.3 | |||
|
384 | xpowf = xpowi + xpoww | |||
|
385 | powObj.setScreenPos([xpowi, ypowf], [ypowi, ypowf]) | |||
|
386 | ||||
|
387 | ||||
|
388 | specObj.initSubpage() | |||
|
389 | ||||
|
390 | if showColorbar: | |||
|
391 | cmapObj.initPlot() | |||
|
392 | ||||
|
393 | if showPowerProfile: | |||
|
394 | powObj.initPlot() | |||
|
395 | ||||
|
396 | self.showColorbar = showColorbar | |||
|
397 | self.showPowerProfile = showPowerProfile | |||
|
398 | ||||
|
399 | def setRanges(self, xrange=None, yrange=None, zrange=None): | |||
|
400 | ||||
|
401 | key = "spec" | |||
|
402 | specObj = self.graphObjDict[key] | |||
|
403 | specObj.setRanges(xrange, yrange, zrange) | |||
|
404 | ||||
|
405 | keyList = self.graphObjDict.keys() | |||
|
406 | ||||
|
407 | key = "colorbar" | |||
|
408 | if key in keyList: | |||
|
409 | cmapObj = self.graphObjDict[key] | |||
|
410 | cmapObj.setRanges([0., 1.], zrange, [0., 1.]) | |||
|
411 | ||||
|
412 | key = "powerprof" | |||
|
413 | if key in keyList: | |||
|
414 | powObj = self.graphObjDict[key] | |||
|
415 | powObj.setRanges(zrange, yrange) | |||
|
416 | ||||
|
417 | def plotData(self, data , xmin, xmax, ymin, ymax): | |||
|
418 | ||||
|
419 | pass | |||
|
420 | ||||
|
421 | class CrossSpectrum(Graph): | |||
|
422 | ||||
|
423 | def __init__(self): | |||
|
424 | pass | |||
|
425 | ||||
|
426 | def setup(self): | |||
|
427 | pass | |||
|
428 | ||||
|
429 | def plotData(self): | |||
|
430 | pass | |||
|
431 | ||||
|
432 | class Graph2(): | |||
|
433 | ||||
|
434 | def __init__(self): | |||
|
435 | """ | |||
|
436 | Initiation of variables | |||
|
437 | ||||
|
438 | Variables: | |||
|
439 | ||||
|
440 | type: | |||
|
441 | windowsize: | |||
|
442 | cmap: colormap | |||
|
443 | showcmap: show the colormap selected on the graphic | |||
|
444 | ||||
|
445 | """ | |||
|
446 | ||||
|
447 | self.id = None | |||
|
448 | self.subpage = None | |||
|
449 | self.type = None | |||
|
450 | self.windowsize = None | |||
|
451 | ||||
|
452 | self.szchar = 0.6 | |||
|
453 | self.title = None | |||
|
454 | self.xlabel = None | |||
|
455 | self.ylabel = None | |||
|
456 | ||||
|
457 | self.showGraph2 = None | |||
|
458 | self.cmap = None | |||
|
459 | self.showcmap = None | |||
|
460 | ||||
|
461 | self.xrangeIsTime = False | |||
|
462 | ||||
|
463 | self.xrange = () | |||
|
464 | self.yrange = () | |||
|
465 | self.zrange = () | |||
|
466 | ||||
|
467 | self.xscreen = () | |||
|
468 | self.yscreen = () | |||
|
469 | ||||
|
470 | self.xcmapscreen = () | |||
|
471 | self.ycmapscreen = () | |||
|
472 | ||||
|
473 | self.x2screen = () | |||
|
474 | self.y2screen = () | |||
|
475 | ||||
|
476 | ||||
|
477 | def setup(self, id, type=0, windowsize=1., title="", xlabel="", ylabel="", showGraph2=None, cmap="jet", showcmap=False, xrangeIsTime=False): | |||
|
478 | """ | |||
|
479 | Inputs: | |||
|
480 | type: This variable indicates the kind of graphic. Instantaneous data or background data | |||
|
481 | ||||
|
482 | 0: real instantaneous data, like spectrum | |||
|
483 | 1: background data, like spectrogram (RTI) | |||
|
484 | 2: complex instantaneous data, like cross-spectrum | |||
|
485 | ||||
|
486 | windowsize : Float. Size of window. It can be full window (1), half window (0.5) or 1 1/2 window (1.5) | |||
|
487 | cmap : Set the colormap to use | |||
|
488 | showcmap : Show the colormap used on the graphic. | |||
|
489 | ||||
|
490 | ||||
|
491 | Variables affected: | |||
|
492 | ||||
|
493 | """ | |||
|
494 | ||||
|
495 | # if windowsize == 1.: | |||
|
496 | # self.xscreen = (0.12, 0.96) | |||
|
497 | # self.yscreen = (0.14, 0.94) | |||
|
498 | # | |||
|
499 | # elif windowsize == 0.5: | |||
|
500 | # self.xscreen = (0.12, 0.52) | |||
|
501 | # self.yscreen = (0.14, 0.94) | |||
|
502 | # | |||
|
503 | # elif windowsize == 1.5: | |||
|
504 | # self.xscreen = (-0.44, 0.96) | |||
|
505 | # self.yscreen = (0.14, 0.94) | |||
|
506 | # | |||
|
507 | # else: | |||
|
508 | # raise ValueError, "type of graphic has not been properly set" | |||
|
509 | ||||
|
510 | if showGraph2 == None: | |||
|
511 | if type == 0: | |||
|
512 | showGraph2 = True | |||
|
513 | ||||
|
514 | if type == 1: | |||
|
515 | showGraph2 = True | |||
|
516 | ||||
|
517 | if type == 2: | |||
|
518 | showGraph2 = True | |||
|
519 | ||||
|
520 | xscreen = (0.12, 0.98) | |||
|
521 | yscreen = (0.14, 0.94) | |||
|
522 | xcmapscreen = (0., 0.) | |||
|
523 | ycmapscreen = (0.14, 0.94) | |||
|
524 | x2screen = (0., 0.) | |||
|
525 | y2screen = (0.14, 0.94) | |||
|
526 | ||||
|
527 | if type == 0: | |||
|
528 | ||||
|
529 | #showGraph2 <> PowerProfile | |||
|
530 | if showGraph2 and showcmap: | |||
|
531 | xscreen = (0.12, 0.62) | |||
|
532 | xcmapscreen = (0.64, 0.70) | |||
|
533 | x2screen = (0.75, 0.98) | |||
|
534 | ||||
|
535 | elif showGraph2: | |||
|
536 | xscreen = (0.12, 0.67) | |||
|
537 | xcmapscreen = (0., 0.) | |||
|
538 | x2screen = (0.7, 0.98) | |||
|
539 | ||||
|
540 | elif showcmap: | |||
|
541 | xscreen = (0.12, 0.85) | |||
|
542 | xcmapscreen = (0.87, 0.93) | |||
|
543 | x2screen = (0., 0.) | |||
|
544 | ||||
|
545 | if type == 1: | |||
|
546 | xscreen = (0.06, 0.98) | |||
|
547 | yscreen = (0.16, 0.84) | |||
|
548 | #showGraph2 <> Phase | |||
|
549 | if showGraph2 and showcmap: | |||
|
550 | xscreen = (0.06, 0.75) | |||
|
551 | xcmapscreen = (0.76, 0.80) | |||
|
552 | x2screen = (0.82, 0.98) | |||
|
553 | ||||
|
554 | elif showGraph2: | |||
|
555 | xscreen = (0.06, 0.80) | |||
|
556 | xcmapscreen = (0., 0.) | |||
|
557 | x2screen = (0.82, 0.98) | |||
|
558 | ||||
|
559 | elif showcmap: | |||
|
560 | xscreen = (0.06, 0.92) | |||
|
561 | xcmapscreen = (0.93, 0.96) | |||
|
562 | x2screen = (0., 0.) | |||
|
563 | ||||
|
564 | if type == 2: | |||
|
565 | if showGraph2 and showcmap: | |||
|
566 | xscreen = (0.12, 0.46) | |||
|
567 | xcmapscreen = (0.48, 0.54) | |||
|
568 | x2screen = (0.56, 0.98) | |||
|
569 | ||||
|
570 | elif showGraph2: | |||
|
571 | xscreen = (0.12, 0.54) | |||
|
572 | xcmapscreen = (0., 0.) | |||
|
573 | x2screen = (0.56, 0.98) | |||
|
574 | ||||
|
575 | elif showcmap: | |||
|
576 | xscreen = (0.12, 0.85) | |||
|
577 | xcmapscreen = (0.87, 0.93) | |||
|
578 | x2screen = (0., 0.) | |||
|
579 | ||||
|
580 | if type == 3: | |||
|
581 | xscreen = (0.12, 0.52) | |||
|
582 | x2screen = (0.76, 0.96) | |||
|
583 | ||||
|
584 | if type == 4: | |||
|
585 | xscreen = (-0.44, 0.96) | |||
|
586 | x2screen = (0.76, 0.96) | |||
|
587 | ||||
|
588 | ||||
|
589 | self.id = id | |||
|
590 | self.subpage = id + 1 | |||
|
591 | self.type = type | |||
|
592 | self.windowsize = windowsize | |||
|
593 | self.title = title | |||
|
594 | self.xlabel = xlabel | |||
|
595 | self.ylabel = ylabel | |||
|
596 | self.showGraph2 = showGraph2 | |||
|
597 | self.cmap = cmap | |||
|
598 | self.showcmap = showcmap | |||
|
599 | self.xrangeIsTime = xrangeIsTime | |||
|
600 | ||||
|
601 | self.xscreen = xscreen | |||
|
602 | self.yscreen = yscreen | |||
|
603 | self.x2screen = x2screen | |||
|
604 | self.y2screen = y2screen | |||
|
605 | self.xcmapscreen = xcmapscreen | |||
|
606 | self.ycmapscreen = ycmapscreen | |||
|
607 | ||||
|
608 | def setRanges(self, xrange=(), yrange=(), zrange=()): | |||
|
609 | """ | |||
|
610 | Inputs: | |||
|
611 | xrange | |||
|
612 | yrange | |||
|
613 | zrange | |||
|
614 | ||||
|
615 | Variables affected: | |||
|
616 | self.xrange | |||
|
617 | self.yrange | |||
|
618 | self.zrange | |||
|
619 | ||||
|
620 | """ | |||
|
621 | ||||
|
622 | self.xrange = xrange | |||
|
623 | self.yrange = yrange | |||
|
624 | self.zrange = zrange | |||
|
625 | ||||
|
626 | def setsubPage(self, subpage): | |||
|
627 | """ | |||
|
628 | """ | |||
|
629 | self.subpage = subpage | |||
|
630 | ||||
|
631 | def plotColorbar(self): | |||
|
632 | ||||
|
633 | if not(self.showcmap): | |||
|
634 | return 0 | |||
|
635 | ||||
|
636 | colors = numpy.arange(255) | |||
|
637 | colors = numpy.reshape(colors, (1,255)) | |||
|
638 | ||||
|
639 | plplot.plvpor(self.xcmapscreen[0], self.xcmapscreen[1], self.ycmapscreen[0], self.ycmapscreen[1]) | |||
|
640 | plplot.plwind(0., 1., self.zrange[0], self.zrange[1]) | |||
|
641 | plplot.plbox("bc",0.0,0,"bc",0.0,0) | |||
|
642 | plplot.pllab("", "", "dBs") | |||
|
643 | plplot.plimage(colors, 0., 1., self.zrange[0], self.zrange[1], 0., 255., 0., 1., self.zrange[0], self.zrange[1]) | |||
|
644 | ||||
|
645 | return 1 | |||
|
646 | ||||
|
647 | def plotPowerProfile(self, power, ymin, ymax): | |||
|
648 | ||||
|
649 | if not(self.showGraph2): | |||
|
650 | return 0 | |||
|
651 | ||||
|
652 | ny = power.shape[0] | |||
|
653 | yscale = (ymax - ymin) / ny | |||
|
654 | y = ymin + yscale*numpy.arange(ny) | |||
|
655 | ||||
|
656 | plplot.plvpor(self.x2screen[0], self.x2screen[1], self.y2screen[0], self.y2screen[1]) | |||
|
657 | plplot.plwind(self.zrange[0], self.zrange[1], self.yrange[0], self.yrange[1]) | |||
|
658 | plplot.plbox("bcnst",0.0,0,"bc",0.0,0) | |||
|
659 | plplot.pllsty(2) | |||
|
660 | plplot.plbox("bcnstg",0.0,0,"bc",0.0,0) | |||
|
661 | plplot.pllsty(1) | |||
|
662 | plplot.pllab("dB", "", "Power Profile") | |||
|
663 | plplot.plline(power, y) | |||
|
664 | #plplot.plflush() | |||
|
665 | ||||
|
666 | return 1 | |||
|
667 | ||||
|
668 | def plotSpectrum(self, data, xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0, zmin=None, zmax=None): | |||
|
669 | """ | |||
|
670 | ||||
|
671 | """ | |||
|
672 | if zmin == None: zmin = numpy.nanmin(data) | |||
|
673 | if zmax == None: zmax = numpy.nanmax(data) | |||
|
674 | ||||
|
675 | if self.xrange == (): self.xrange = (xmin, xmax) | |||
|
676 | if self.yrange == (): self.yrange = (ymin, ymax) | |||
|
677 | if self.zrange == (): self.zrange = (zmin, zmax) | |||
|
678 | ||||
|
679 | plplot.pladv(self.subpage) | |||
|
680 | plplot.plschr(0.0,self.szchar) | |||
|
681 | ||||
|
682 | power = numpy.average(data, axis=0) | |||
|
683 | ||||
|
684 | self.plotPowerProfile(power, ymin, ymax) | |||
|
685 | self.plotColorbar() | |||
|
686 | ||||
|
687 | if self.xrangeIsTime: | |||
|
688 | plplot.pltimefmt("%H:%M") | |||
|
689 | ||||
|
690 | plplot.plvpor(self.xscreen[0], self.xscreen[1], self.yscreen[0], self.yscreen[1]) | |||
|
691 | plplot.plwind(self.xrange[0], self.xrange[1], self.yrange[0], self.yrange[1]) | |||
|
692 | plplot.plbox("bcnst",0.0,0,"bcnstv",0.0,0) | |||
|
693 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |||
|
694 | plplot.plimage(data, xmin, xmax, ymin, ymax, zmin, zmax, xmin, xmax, ymin, ymax) | |||
|
695 | #plplot.plflush() | |||
|
696 | ||||
|
697 | def plotSpectrogram(self, data, xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0, zmin=0.0, zmax=1.0): | |||
|
698 | """ | |||
|
699 | ||||
|
700 | """ | |||
|
701 | ||||
|
702 | if zmin == None: zmin = numpy.nanmin(data) | |||
|
703 | if zmax == None: zmax = numpy.nanmax(data) | |||
|
704 | ||||
|
705 | if self.xrange == (): self.xrange = (xmin, xmax) | |||
|
706 | if self.yrange == (): self.yrange = (ymin, ymax) | |||
|
707 | if self.zrange == (): self.zrange = (zmin, zmax) | |||
|
708 | ||||
|
709 | plplot.pladv(self.subpage) | |||
|
710 | ||||
|
711 | plplot.plschr(0.0,self.szchar+0.3) | |||
|
712 | ||||
|
713 | power = numpy.average(data, axis=0) | |||
|
714 | ||||
|
715 | self.plotPowerProfile(power, ymin, ymax) | |||
|
716 | self.plotColorbar() | |||
|
717 | ||||
|
718 | if self.xrangeIsTime: | |||
|
719 | plplot.pltimefmt("%H:%M") | |||
|
720 | ||||
|
721 | plplot.plvpor(self.xscreen[0], self.xscreen[1], self.yscreen[0], self.yscreen[1]) | |||
|
722 | plplot.plwind(self.xrange[0], self.xrange[1], self.yrange[0], self.yrange[1]) | |||
|
723 | plplot.plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0) | |||
|
724 | ||||
|
725 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |||
|
726 | plplot.plimage(data, xmin, xmax, ymin, ymax, zmin, zmax, xmin, xmax, ymin, ymax) | |||
|
727 | #plplot.plflush() | |||
|
728 | ||||
|
729 | ||||
|
730 | class PlotData(): | |||
|
731 | ''' | |||
|
732 | classdocs | |||
|
733 | ''' | |||
|
734 | ||||
|
735 | __INST_XSIZE = 300 | |||
|
736 | __INST_YSIZE = 280 | |||
|
737 | __BACKGR_XSIZE = 900 | |||
|
738 | __BACKGR_YSIZE = 150 | |||
|
739 | __SPACE = 100 | |||
|
740 | ||||
|
741 | def __init__(self): | |||
|
742 | ''' | |||
|
743 | Constructor | |||
|
744 | ''' | |||
|
745 | ||||
|
746 | self.nx = None | |||
|
747 | self.ny = None | |||
|
748 | self.xsize = None | |||
|
749 | self.ysize = None | |||
|
750 | ||||
|
751 | self.objGraphList = [] | |||
|
752 | ||||
|
753 | def getNumSubPages(self): | |||
|
754 | ||||
|
755 | nT0 = 0 | |||
|
756 | nT1 = 0 | |||
|
757 | nT2 = 0 | |||
|
758 | nT10 = 0 | |||
|
759 | nT11 = 0 | |||
|
760 | ||||
|
761 | for thisObj in self.objGraphList: | |||
|
762 | if thisObj.type == 0: | |||
|
763 | nT0 += 1 | |||
|
764 | continue | |||
|
765 | ||||
|
766 | if thisObj.type == 1: | |||
|
767 | nT1 += 1 | |||
|
768 | continue | |||
|
769 | ||||
|
770 | if thisObj.type == 2: | |||
|
771 | nT2 += 1 | |||
|
772 | continue | |||
|
773 | ||||
|
774 | if thisObj.type == 10: | |||
|
775 | nT10 += 1 | |||
|
776 | continue | |||
|
777 | ||||
|
778 | if thisObj.type == 11: | |||
|
779 | nT11 += 1 | |||
|
780 | continue | |||
|
781 | ||||
|
782 | nSpectrum = nT0 + nT2 | |||
|
783 | ||||
|
784 | if (nSpectrum > 0) and nT1*nT10*nT11 == 0: | |||
|
785 | ||||
|
786 | if nSpectrum in [1,2]: nx = 1 | |||
|
787 | elif nSpectrum in [3,4,5,6]: nx = 2 | |||
|
788 | else: nx = 3 | |||
|
789 | ||||
|
790 | if nSpectrum in [1]: ny = 1 | |||
|
791 | elif nSpectrum in [2,3,4]: ny = 2 | |||
|
792 | else: ny = 3 | |||
|
793 | ||||
|
794 | elif nT1 > 0 and nT0*nT10*nT11 == 0: | |||
|
795 | nx = 1 | |||
|
796 | ny = nT1 | |||
|
797 | ||||
|
798 | elif nT10 == nT11 and nT0*nT1 == 0: | |||
|
799 | nx = nT10 | |||
|
800 | ny = 2 | |||
|
801 | ||||
|
802 | else: | |||
|
803 | raise ValueError, "number of instantaneous and background graphics are not consistent" | |||
|
804 | ||||
|
805 | self.nx = nx | |||
|
806 | self.ny = ny | |||
|
807 | ||||
|
808 | return nx, ny | |||
|
809 | ||||
|
810 | def getSizeScreen(self): | |||
|
811 | ||||
|
812 | nx, ny = self.nx, self.ny | |||
|
813 | ||||
|
814 | if nx == None or ny == None: | |||
|
815 | raise ValueError, "The number of subpages have been set yet, please use the getNumSubPages method for this." | |||
|
816 | ||||
|
817 | nT0 = 0 | |||
|
818 | nT1 = 0 | |||
|
819 | nT2 = 0 | |||
|
820 | nT10 = 0 | |||
|
821 | nT11 = 0 | |||
|
822 | ||||
|
823 | for thisObj in self.objGraphList: | |||
|
824 | if thisObj.type == 0: | |||
|
825 | nT0 += 1 | |||
|
826 | continue | |||
|
827 | ||||
|
828 | if thisObj.type == 1: | |||
|
829 | nT1 += 1 | |||
|
830 | continue | |||
|
831 | ||||
|
832 | if thisObj.type == 2: | |||
|
833 | nT2 += 1 | |||
|
834 | continue | |||
|
835 | ||||
|
836 | if thisObj.type == 10: | |||
|
837 | nT10 += 1 | |||
|
838 | continue | |||
|
839 | ||||
|
840 | if thisObj.type == 11: | |||
|
841 | nT11 += 1 | |||
|
842 | continue | |||
|
843 | ||||
|
844 | if (nT0 > 0 or nT2 > 0) and nT1 > 0: | |||
|
845 | raise ValueError, "Different type of graphics have been selected" | |||
|
846 | ||||
|
847 | if nT0 > 0 or nT2 > 0: | |||
|
848 | xsize = ny*self.__INST_XSIZE | |||
|
849 | ysize = nx*self.__INST_YSIZE | |||
|
850 | ||||
|
851 | elif nT1 > 0: | |||
|
852 | xsize = nx*self.__BACKGR_XSIZE | |||
|
853 | ysize = ny*self.__BACKGR_YSIZE | |||
|
854 | ||||
|
855 | elif nT10 == nT11: | |||
|
856 | xsize = self.__INST_XSIZE + self.__BACKGR_XSIZE + self.__SPACE | |||
|
857 | ysize = nx*self.__BACKGR_YSIZE | |||
|
858 | else: | |||
|
859 | raise ValueError, "number of instantaneous and background graphics are not consistent" | |||
|
860 | ||||
|
861 | self.xsize = xsize | |||
|
862 | self.ysize = ysize | |||
|
863 | ||||
|
864 | return xsize, ysize | |||
|
865 | ||||
|
866 | def setup(self, sizescreen="800x600", save=False, gpath="", filename=""): | |||
|
867 | """ | |||
|
868 | """ | |||
|
869 | ||||
|
870 | self.sizecreen = sizescreen | |||
|
871 | self.save = save | |||
|
872 | self.gpath = gpath | |||
|
873 | self.filename = filename | |||
|
874 | ||||
|
875 | def addGraph(self, type=0, xlabel="", ylabel="", title="", showGraph2=False, showcmap=False, cmap="jet", windowsize=1.): | |||
|
876 | """ | |||
|
877 | type: This variable indicates the kind of graphics. Instantaneous data or background data | |||
|
878 | ||||
|
879 | 0: real instantaneous data, like a spectrum | |||
|
880 | 1: background data, like a spectrogram (RTI) | |||
|
881 | 2: complex instantaneous data, like cross-spectrum | |||
|
882 | ||||
|
883 | ||||
|
884 | windowsize: Float. Size of window. It can be:: | |||
|
885 | 1.0: full window (1) | |||
|
886 | 0.5: half window | |||
|
887 | 1.5: 1 1/2 window (1.5) | |||
|
888 | ||||
|
889 | If some graps have already been set with one graphic type the next ones should be of the same type | |||
|
890 | """ | |||
|
891 | ||||
|
892 | id = len(self.objGraphList) | |||
|
893 | ||||
|
894 | objGraph = Graph2() | |||
|
895 | objGraph.setup(id, type, windowsize, title, xlabel, ylabel, showGraph2, cmap, showcmap) | |||
|
896 | ||||
|
897 | self.objGraphList.append(objGraph) | |||
|
898 | ||||
|
899 | return id | |||
|
900 | ||||
|
901 | def getGraphFromId(self, id): | |||
|
902 | """ | |||
|
903 | ||||
|
904 | """ | |||
|
905 | if id >= len(self.objGraphList): | |||
|
906 | return None | |||
|
907 | ||||
|
908 | return self.objGraphList[id] | |||
|
909 | ||||
|
910 | def setRanges(self, id=0, xrange=(), yrange=(), zrange=()): | |||
|
911 | """ | |||
|
912 | ||||
|
913 | """ | |||
|
914 | thisGraphObj = self.getGraphFromId(id) | |||
|
915 | thisGraphObj.setmargins(xrange, yrange, zrange) | |||
|
916 | ||||
|
917 | ||||
|
918 | def addText(self, id, xpos=0, ypos=0, text=""): | |||
|
919 | """ | |||
|
920 | ||||
|
921 | """ | |||
|
922 | thisGraphObj = self.getGraphFromId(id) | |||
|
923 | ||||
|
924 | plplot.pladv(thisGraphObj.subpage) | |||
|
925 | plplot.plmtex("b", 5, xpos, ypos, text) | |||
|
926 | ||||
|
927 | def plotData(self, id, data, xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0, zmin=None, zmax=None): | |||
|
928 | ||||
|
929 | thisGraphObj = self.getGraphFromId(id) | |||
|
930 | ||||
|
931 | if thisGraphObj == None: | |||
|
932 | return 0 | |||
|
933 | ||||
|
934 | plplot.plcol0(1) | |||
|
935 | if thisGraphObj.type in [0,2]: | |||
|
936 | thisGraphObj.plotSpectrum(data, xmin, xmax, ymin, ymax, zmin, zmax) | |||
|
937 | return 1 | |||
|
938 | ||||
|
939 | if thisGraphObj.type in [1]: | |||
|
940 | thisGraphObj.plotSpectrogram(data, xmin, xmax, ymin, ymax, zmin, zmax) | |||
|
941 | return 1 | |||
|
942 | ||||
|
943 | return 0 | |||
|
944 | ||||
|
945 | def iniPlot(self, nx=None, ny=None): | |||
|
946 | """ | |||
|
947 | ||||
|
948 | """ | |||
|
949 | if nx == None or ny == None: | |||
|
950 | nx, ny = self.getNumSubPages() | |||
|
951 | ||||
|
952 | self.getSizeScreen() | |||
|
953 | ||||
|
954 | plplot.plsetopt("geometry", "%dx%d" %(self.xsize, self.ysize)) | |||
|
955 | plplot.plsdev("xcairo") | |||
|
956 | plplot.plscolbg(255,255,255) | |||
|
957 | plplot.plscol0(1,0,0,0) | |||
|
958 | plplot.plinit() | |||
|
959 | plplot.plssub(nx, ny) | |||
|
960 | plplot.pladv(0) | |||
|
961 | ||||
|
962 | #plplot.plspause(0) | |||
|
963 | ||||
|
964 | def end(self): | |||
|
965 | plplot.plflush() | |||
|
966 | plplot.plend() | |||
|
967 | ||||
|
968 | if __name__ == '__main__': | |||
|
969 | ||||
|
970 | import numpy | |||
|
971 | data = numpy.random.uniform(-50,50,(150,250)) | |||
|
972 | ||||
|
973 | objPlot = PlotData() | |||
|
974 | objPlot.addGraph(1, "Frequency", "Height", "Channel A") | |||
|
975 | objPlot.addGraph(1, "Frequency", "Height", "Channel B", showGraph2=True) | |||
|
976 | objPlot.addGraph(1, "Frequency", "Height", "Channel C", showcmap=True) | |||
|
977 | # | |||
|
978 | # objPlot.addGraph(1, "Frequency", "Height", "Cross A-B") | |||
|
979 | # objPlot.addGraph(1, "Frequency", "Height", "Cross A-C", showGraph2=True) | |||
|
980 | # objPlot.addGraph(1, "Frequency", "Height", "Cross A-D", showcmap=True) | |||
|
981 | # | |||
|
982 | objPlot.addGraph(1, "Frequency", "Height", "Channel D", showcmap=True, showGraph2=True) | |||
|
983 | objPlot.addGraph(1, "Frequency", "Height", "Cross A-E", showcmap=True, showGraph2=True) | |||
|
984 | ||||
|
985 | objPlot.iniPlot() | |||
|
986 | ||||
|
987 | for id in range(10): | |||
|
988 | objPlot.plotData(id, data) | |||
|
989 | ||||
|
990 | objPlot.end() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now