@@ -25,28 +25,35 class Figure: | |||||
25 |
|
25 | |||
26 | frameObjList = [] |
|
26 | frameObjList = [] | |
27 |
|
27 | |||
28 |
def __init__(self, idfigure, wintitle, xw=600, yw=800, overplot=0, driver=' |
|
28 | def __init__(self, idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap='br_green', *showGraphs): | |
29 |
|
29 | |||
|
30 | self.driver = driver | |||
30 | self.idfigure = idfigure |
|
31 | self.idfigure = idfigure | |
|
32 | self.nframes = nframes | |||
31 | self.wintitle = wintitle |
|
33 | self.wintitle = wintitle | |
32 | self.colormap = colormap |
|
|||
33 | self.driver = driver |
|
|||
34 | self.overplot = overplot |
|
34 | self.overplot = overplot | |
|
35 | self.colormap = colormap | |||
|
36 | ||||
|
37 | self.showGraph1 = showGraphs[0] | |||
|
38 | self.showGraph2 = showGraphs[1] | |||
|
39 | self.__xw = xw | |||
|
40 | self.__yw = yw | |||
|
41 | ||||
|
42 | self.__driverObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs) | |||
35 |
|
43 | |||
36 | self.showGraphs = showGraphs |
|
44 | self.__driverObj.driver.configDriver() | |
37 |
|
45 | |||
38 | self.__driverObj = Driver(driver) |
|
|||
39 |
|
46 | |||
40 | def __openDriver(self): |
|
47 | def __openDriver(self): | |
41 |
|
48 | |||
42 | self.__driverObj.openDriver(self.idfigure, self.wintitle, self.xw, self.yw) |
|
49 | self.__driverObj.driver.openDriver() | |
43 |
|
50 | |||
44 | def __openFigure(self): |
|
51 | def __openFigure(self): | |
45 |
|
52 | |||
46 | nrows, ncolumns = self.getSubplots() |
|
53 | nrows, ncolumns = self.getSubplots() | |
47 |
|
54 | |||
48 | self.__driverObj.openFigure() |
|
55 | self.__driverObj.driver.openFigure() | |
49 | self.__driverObj.setSubPlots(nrows, ncolumns) |
|
56 | self.__driverObj.driver.setSubPlots(nrows, ncolumns) | |
50 |
|
57 | |||
51 |
|
58 | |||
52 | def __isOutOfXRange(self, x): |
|
59 | def __isOutOfXRange(self, x): | |
@@ -148,8 +155,8 class Figure: | |||||
148 |
|
155 | |||
149 |
|
156 | |||
150 | def getSubplots(self): |
|
157 | def getSubplots(self): | |
151 |
|
158 | |||
152 |
raise ValueError, |
|
159 | raise ValueError, "No implemented" | |
153 |
|
160 | |||
154 | class Frame: |
|
161 | class Frame: | |
155 |
|
162 |
@@ -1,60 +1,259 | |||||
1 | import plplot |
|
1 | import plplot | |
2 | import numpy |
|
2 | import numpy | |
3 | import sys |
|
3 | import sys | |
|
4 | import plplot #condicional | |||
|
5 | ||||
|
6 | class Driver: | |||
|
7 | def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs): | |||
|
8 | if driver == "plplot": | |||
|
9 | self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs) | |||
|
10 | elif driver == "mpl": | |||
|
11 | self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs) | |||
|
12 | else: | |||
|
13 | raise ValueError, "The driver: %s is not defined"%driver | |||
4 |
|
14 | |||
5 | class PlplotDriver: |
|
15 | class PlplotDriver: | |
6 |
|
16 | |||
7 | __isDriverOpen = False |
|
17 | __isDriverOpen = False | |
8 |
|
18 | pldriver = None | ||
9 | def __init__(self, id=None, driver=None, wintitle, overplot, colormap, showGraph1, showGraph2): |
|
19 | ||
10 |
|
20 | def __init__(self, idfigure=None, xw, yw, wintitle, overplot, colormap, *showGraphs): | ||
11 | if id == None: |
|
|||
12 | raise ValueError, 'id input must be defined' |
|
|||
13 |
|
||||
14 | if driver == None: |
|
|||
15 | if sys.platform == "linux": |
|
|||
16 | driver = "" |
|
|||
17 | elif sys.platform == "darwin": |
|
|||
18 | driver = "" |
|
|||
19 | else: |
|
|||
20 | driver = "" |
|
|||
21 |
|
||||
22 | self.id = id |
|
|||
23 | self.driver = driver |
|
|||
24 |
|
21 | |||
|
22 | if idfigure == None: | |||
|
23 | raise ValueError, 'idfigure input must be defined' | |||
25 |
|
24 | |||
26 |
self. |
|
25 | self.idfigure = idfigure | |
|
26 | self.xw = xw | |||
|
27 | self.yw = yw | |||
27 | self.wintitle = wintitle |
|
28 | self.wintitle = wintitle | |
28 | self.colormap = colormap |
|
|||
29 | self.showGraph1 = showGraph1 |
|
|||
30 | self.showGraph2 = showGraph2 |
|
|||
31 |
|
||||
32 | self.overplot = overplot |
|
29 | self.overplot = overplot | |
|
30 | self.colormap = colormap | |||
|
31 | self.showGraph1 = showGraphs[0] | |||
|
32 | self.showGraph2 = showGraphs[1] | |||
33 |
|
33 | |||
34 | def configDriver(self): |
|
34 | def configDriver(self): | |
35 | if self.driver == "": |
|
35 | """ | |
36 | import plplot |
|
36 | previous configuration to open(init) the plplot driver | |
37 |
|
|
37 | """ | |
38 | pass |
|
38 | plplot.plsstrm(self.idfigure) | |
39 |
|
39 | plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL) | ||
40 | def openDriver(self): |
|
40 | plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw)) | |
41 |
|
41 | |||
42 | pass |
|
42 | plplot.plscolbg(255,255,255) | |
|
43 | plplot.plscol0(1,0,0,0) | |||
|
44 | ||||
|
45 | def openDriver(self, pldriver=None): | |||
|
46 | if pldriver == None: | |||
|
47 | if sys.platform == "linux": | |||
|
48 | pldriver = "xcairo" | |||
|
49 | ||||
|
50 | elif sys.platform == "darwin": | |||
|
51 | pldriver = "xwin" | |||
|
52 | ||||
|
53 | else: | |||
|
54 | pldriver = "" | |||
|
55 | ||||
|
56 | plplot.plsdev(pldriver) | |||
|
57 | plplot.plinit() | |||
|
58 | plplot.plspause(False) | |||
|
59 | ||||
|
60 | self.pldriver = pldriver | |||
43 |
|
61 | |||
44 | def closeDriver(self): |
|
62 | def closeDriver(self): | |
45 |
|
||||
46 | pass |
|
63 | pass | |
47 |
|
64 | |||
48 | def openPage(self): |
|
65 | def openPage(self): | |
49 | pass |
|
66 | plplot.plbop() | |
|
67 | plplot.pladv(0) | |||
50 |
|
68 | |||
51 | def closePage(self): |
|
69 | def closePage(self): | |
|
70 | plplot.pleop() | |||
|
71 | ||||
|
72 | def openFigure(self): | |||
|
73 | plplot.plbop() | |||
|
74 | plplot.pladv(0) | |||
|
75 | ||||
|
76 | def closeFigure(self): | |||
|
77 | plplot.pleop() | |||
|
78 | ||||
|
79 | def setSubPlots(self,nrows, ncolumns): | |||
|
80 | plplot.plssub(nrows, ncolumns) | |||
|
81 | ||||
|
82 | def setColorMap(self,colormap): | |||
52 |
|
83 | |||
53 | pass |
|
84 | if colormap == None: | |
|
85 | return | |||
|
86 | ||||
|
87 | ncolor = None | |||
|
88 | rgb_lvl = None | |||
|
89 | ||||
|
90 | # Routine for defining a specific color map 1 in HLS space. | |||
|
91 | # if gray is true, use basic grayscale variation from half-dark to light. | |||
|
92 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |||
54 |
|
93 | |||
55 | def setColorMap(self): |
|
94 | # Independent variable of control points. | |
56 |
|
95 | |||
57 | pass |
|
96 | i = numpy.array((0., 1.)) | |
|
97 | ||||
|
98 | if colormap=="gray": | |||
|
99 | ncolor = 256 | |||
|
100 | # Hue for control points. Doesn't matter since saturation is zero. | |||
|
101 | h = numpy.array((0., 0.)) | |||
|
102 | # Lightness ranging from half-dark (for interest) to light. | |||
|
103 | l = numpy.array((0.5, 1.)) | |||
|
104 | # Gray scale has zero saturation | |||
|
105 | s = numpy.array((0., 0.)) | |||
|
106 | ||||
|
107 | # number of cmap1 colours is 256 in this case. | |||
|
108 | plplot.plscmap1n(ncolor) | |||
|
109 | # Interpolate between control points to set up cmap1. | |||
|
110 | plplot.plscmap1l(0, i, h, l, s) | |||
|
111 | ||||
|
112 | return None | |||
|
113 | ||||
|
114 | if colormap == 'jet': | |||
|
115 | ncolor = 256 | |||
|
116 | pos = numpy.zeros((ncolor)) | |||
|
117 | r = numpy.zeros((ncolor)) | |||
|
118 | g = numpy.zeros((ncolor)) | |||
|
119 | b = numpy.zeros((ncolor)) | |||
|
120 | ||||
|
121 | for i in range(ncolor): | |||
|
122 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 | |||
|
123 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 | |||
|
124 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 | |||
|
125 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 | |||
|
126 | ||||
|
127 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 | |||
|
128 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 | |||
|
129 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 | |||
|
130 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 | |||
|
131 | else: gf = 0.0 | |||
|
132 | ||||
|
133 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 | |||
|
134 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 | |||
|
135 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 | |||
|
136 | else: bf = 0 | |||
|
137 | ||||
|
138 | r[i] = rf | |||
|
139 | g[i] = gf | |||
|
140 | b[i] = bf | |||
|
141 | ||||
|
142 | pos[i] = float(i)/float(ncolor-1) | |||
|
143 | ||||
|
144 | ||||
|
145 | plplot.plscmap1n(ncolor) | |||
|
146 | plplot.plscmap1l(1, pos, r, g, b) | |||
|
147 | ||||
|
148 | ||||
|
149 | ||||
|
150 | if colormap=="br_green": | |||
|
151 | ncolor = 256 | |||
|
152 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
153 | h = numpy.array((240., 0.)) | |||
|
154 | # Lightness and saturation are constant (values taken from C example). | |||
|
155 | l = numpy.array((0.6, 0.6)) | |||
|
156 | s = numpy.array((0.8, 0.8)) | |||
|
157 | ||||
|
158 | # number of cmap1 colours is 256 in this case. | |||
|
159 | plplot.plscmap1n(ncolor) | |||
|
160 | # Interpolate between control points to set up cmap1. | |||
|
161 | plplot.plscmap1l(0, i, h, l, s) | |||
|
162 | ||||
|
163 | return None | |||
|
164 | ||||
|
165 | if colormap=="tricolor": | |||
|
166 | ncolor = 3 | |||
|
167 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
168 | h = numpy.array((240., 0.)) | |||
|
169 | # Lightness and saturation are constant (values taken from C example). | |||
|
170 | l = numpy.array((0.6, 0.6)) | |||
|
171 | s = numpy.array((0.8, 0.8)) | |||
|
172 | ||||
|
173 | # number of cmap1 colours is 256 in this case. | |||
|
174 | plplot.plscmap1n(ncolor) | |||
|
175 | # Interpolate between control points to set up cmap1. | |||
|
176 | plplot.plscmap1l(0, i, h, l, s) | |||
|
177 | ||||
|
178 | return None | |||
|
179 | ||||
|
180 | if colormap == 'rgb' or colormap == 'rgb666': | |||
|
181 | ||||
|
182 | color_sz = 6 | |||
|
183 | ncolor = color_sz*color_sz*color_sz | |||
|
184 | pos = numpy.zeros((ncolor)) | |||
|
185 | r = numpy.zeros((ncolor)) | |||
|
186 | g = numpy.zeros((ncolor)) | |||
|
187 | b = numpy.zeros((ncolor)) | |||
|
188 | ind = 0 | |||
|
189 | for ri in range(color_sz): | |||
|
190 | for gi in range(color_sz): | |||
|
191 | for bi in range(color_sz): | |||
|
192 | r[ind] = ri/(color_sz-1.0) | |||
|
193 | g[ind] = gi/(color_sz-1.0) | |||
|
194 | b[ind] = bi/(color_sz-1.0) | |||
|
195 | pos[ind] = ind/(ncolor-1.0) | |||
|
196 | ind += 1 | |||
|
197 | rgb_lvl = [6,6,6] #Levels for RGB colors | |||
|
198 | ||||
|
199 | if colormap == 'rgb676': | |||
|
200 | ncolor = 6*7*6 | |||
|
201 | pos = numpy.zeros((ncolor)) | |||
|
202 | r = numpy.zeros((ncolor)) | |||
|
203 | g = numpy.zeros((ncolor)) | |||
|
204 | b = numpy.zeros((ncolor)) | |||
|
205 | ind = 0 | |||
|
206 | for ri in range(8): | |||
|
207 | for gi in range(8): | |||
|
208 | for bi in range(4): | |||
|
209 | r[ind] = ri/(6-1.0) | |||
|
210 | g[ind] = gi/(7-1.0) | |||
|
211 | b[ind] = bi/(6-1.0) | |||
|
212 | pos[ind] = ind/(ncolor-1.0) | |||
|
213 | ind += 1 | |||
|
214 | rgb_lvl = [6,7,6] #Levels for RGB colors | |||
|
215 | ||||
|
216 | if colormap == 'rgb685': | |||
|
217 | ncolor = 6*8*5 | |||
|
218 | pos = numpy.zeros((ncolor)) | |||
|
219 | r = numpy.zeros((ncolor)) | |||
|
220 | g = numpy.zeros((ncolor)) | |||
|
221 | b = numpy.zeros((ncolor)) | |||
|
222 | ind = 0 | |||
|
223 | for ri in range(8): | |||
|
224 | for gi in range(8): | |||
|
225 | for bi in range(4): | |||
|
226 | r[ind] = ri/(6-1.0) | |||
|
227 | g[ind] = gi/(8-1.0) | |||
|
228 | b[ind] = bi/(5-1.0) | |||
|
229 | pos[ind] = ind/(ncolor-1.0) | |||
|
230 | ind += 1 | |||
|
231 | rgb_lvl = [6,8,5] #Levels for RGB colors | |||
|
232 | ||||
|
233 | if colormap == 'rgb884': | |||
|
234 | ncolor = 8*8*4 | |||
|
235 | pos = numpy.zeros((ncolor)) | |||
|
236 | r = numpy.zeros((ncolor)) | |||
|
237 | g = numpy.zeros((ncolor)) | |||
|
238 | b = numpy.zeros((ncolor)) | |||
|
239 | ind = 0 | |||
|
240 | for ri in range(8): | |||
|
241 | for gi in range(8): | |||
|
242 | for bi in range(4): | |||
|
243 | r[ind] = ri/(8-1.0) | |||
|
244 | g[ind] = gi/(8-1.0) | |||
|
245 | b[ind] = bi/(4-1.0) | |||
|
246 | pos[ind] = ind/(ncolor-1.0) | |||
|
247 | ind += 1 | |||
|
248 | rgb_lvl = [8,8,4] #Levels for RGB colors | |||
|
249 | ||||
|
250 | if ncolor == None: | |||
|
251 | raise ValueError, "The colormap selected is not valid" | |||
|
252 | ||||
|
253 | plplot.plscmap1n(ncolor) | |||
|
254 | plplot.plscmap1l(1, pos, r, g, b) | |||
|
255 | ||||
|
256 | return rgb_lvl | |||
58 |
|
257 | |||
59 | def setBox(self): |
|
258 | def setBox(self): | |
60 |
|
259 | |||
@@ -88,13 +287,7 class PlplotDriver: | |||||
88 |
|
287 | |||
89 | pass |
|
288 | pass | |
90 |
|
289 | |||
91 | def figure(self): |
|
290 | ||
92 |
|
||||
93 | pass |
|
|||
94 |
|
||||
95 | def setSubPlots(self): |
|
|||
96 |
|
||||
97 | pass |
|
|||
98 |
|
291 | |||
99 |
|
292 | |||
100 |
|
293 | |||
@@ -102,8 +295,8 class MplDriver: | |||||
102 | def __init__(self): |
|
295 | def __init__(self): | |
103 | pass |
|
296 | pass | |
104 |
|
297 | |||
105 | def config_driver(id, wintitle, width, height): |
|
298 | def config_driver(idfigure, wintitle, width, height): | |
106 | plplot.plsstrm(id) |
|
299 | plplot.plsstrm(idfigure) | |
107 | plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL) |
|
300 | plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL) | |
108 | plplot.plsetopt("geometry", "%dx%d"%(width,height)) |
|
301 | plplot.plsetopt("geometry", "%dx%d"%(width,height)) | |
109 |
|
302 |
@@ -3,35 +3,46 from schainPlot import * | |||||
3 |
|
3 | |||
4 |
|
4 | |||
5 | class RTIFigure(Figure): |
|
5 | class RTIFigure(Figure): | |
6 | def __init__(self, idstream, nframe, wintitle, colormap, driver, showColorbar, showPowerProfile): |
|
6 | ||
7 | self.idStream = idStream |
|
7 | overplot = 1 # igual a 1 porque el grafico es RTI, para el caso de Spectra(Spc,CrossSpc) overplot = 0 | |
8 | self.nFrames = nFrames |
|
8 | xw = 700 | |
9 | self.winTitle = winTitle |
|
9 | yw = 150 | |
10 | self.colormap = colormap |
|
10 | nframes = None | |
11 | self.driver = driver |
|
11 | ||
12 | self.showGraph1 = showColorbar |
|
12 | def __init__(self, idfigure, nframes, wintitle, colormap, driver, showColorbar, showPowerProfile): | |
13 | self.showGraph2 = showPowerProfile |
|
|||
14 | self.overplot = 1 # igual a 1 porque el grafico es RTI, para el caso de Spectra(Spc,CrossSpc) overplot = 0 |
|
|||
15 |
|
13 | |||
16 | self.width = 700 |
|
14 | showGraphs = (showColorbar, showPowerProfile) | |
17 | self.height = 150 |
|
15 | ||
18 | self.ncol = int(numpy.sqrt(self.nFrames)+0.9) |
|
16 | Figure.__init__(self, | |
19 | self.nrow = int(self.nFrames*1./ncol + 0.9) |
|
17 | idfigure=idfigure, | |
|
18 | nframes = nframes, | |||
|
19 | wintitle=wintitle, | |||
|
20 | xw=self.xw, | |||
|
21 | yw=self.yw, | |||
|
22 | overplot=self.overplot, | |||
|
23 | driver=driver, | |||
|
24 | colormap=colormap, | |||
|
25 | *showGraphs) | |||
|
26 | ||||
|
27 | self.nframes = nframes | |||
|
28 | self.showColorbar = showColorbar | |||
|
29 | self.showPowerProfile = showPowerProfile | |||
|
30 | ||||
|
31 | def getSubplots(self): | |||
|
32 | nrows = self.nframes | |||
|
33 | ncolumns = 1 | |||
20 |
|
34 | |||
|
35 | return nrows, ncolumns | |||
21 |
|
36 | |||
22 | def __createFrames(self): |
|
37 | def __createFrames(self): | |
23 |
for frame in range(self.n |
|
38 | for frame in range(self.nframes): | |
24 | frameObj = RTIFrame(idFrame = frame, |
|
39 | frameObj = RTIFrame(idFrame = frame, | |
25 |
showGraph1 = self.show |
|
40 | showGraph1 = self.showColorbar, | |
26 |
showGraph2 = self.show |
|
41 | showGraph2 = self.showPowerProfile | |
27 | ) |
|
42 | ) | |
28 |
|
43 | |||
29 | self.frameObjList.append(frameObj) |
|
44 | self.frameObjList.append(frameObj) | |
30 |
|
45 | |||
31 |
|
||||
32 |
|
||||
33 |
|
||||
34 |
|
||||
35 |
|
46 | |||
36 | class RTIFrame(Frame): |
|
47 | class RTIFrame(Frame): | |
37 | def __init__(self,idFrame, showColorbar, showPowerProfile): |
|
48 | def __init__(self,idFrame, showColorbar, showPowerProfile): |
General Comments 0
You need to be logged in to leave comments.
Login now