##// END OF EJS Templates
Daniel Valdez -
r132:4909be0baad2
parent child
Show More
@@ -1,263 +1,270
1 1
2 2 import numpy
3 3 import schainPlplotLib
4 4
5 5 class Figure:
6 6
7 7 __driverObj = None
8 8 __isDriverOpen = False
9 9 __isFigureOpen = False
10 10 __isConfig = False
11 11 __xw = None
12 12 __yw = None
13 13
14 14 xmin = None
15 15 xmax = None
16 16 minvalue = None
17 17 maxvalue = None
18 18
19 19 idfigure = None
20 20 nframes = None
21 21 wintitle = wintitle
22 22 colormap = None
23 23 driver = None
24 24 overplot = None
25 25
26 26 frameObjList = []
27 27
28 def __init__(self, idfigure, wintitle, xw=600, yw=800, overplot=0, driver='xwin', colormap='br_green', *showGraphs):
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 31 self.idfigure = idfigure
32 self.nframes = nframes
31 33 self.wintitle = wintitle
32 self.colormap = colormap
33 self.driver = driver
34 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 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 51 def __openFigure(self):
45 52
46 53 nrows, ncolumns = self.getSubplots()
47 54
48 self.__driverObj.openFigure()
49 self.__driverObj.setSubPlots(nrows, ncolumns)
55 self.__driverObj.driver.openFigure()
56 self.__driverObj.driver.setSubPlots(nrows, ncolumns)
50 57
51 58
52 59 def __isOutOfXRange(self, x):
53 60 pass
54 61
55 62 def __changeXRange(self, x):
56 63 pass
57 64
58 65 def __createFrames(self):
59 66
60 67 for frame in range(self.nframes):
61 68 frameObj = Frame(idframe = frame,
62 69 showGraph1 = self.showGraph1,
63 70 showGraph2 = self.showGraph2
64 71 )
65 72
66 73 self.frameObjList.append(frameObj)
67 74
68 75 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvlaue=None, save=False, gpath='./'):
69 76
70 77 nx, ny = data1D.shape
71 78
72 79 if channelList == None:
73 80 chanellList = range(nx)
74 81
75 82 if x == None:
76 83 x = numpy.arange(data1D.size)
77 84
78 85
79 86
80 87
81 88 if not(self.__isDriverOpen):
82 89 self.__openDriver()
83 90 self.__isDriverOpen = True
84 91
85 92 if not(self.__isConfig):
86 93 if self.xmin == None: xmin = numpy.min(x)
87 94 if self.xmax == None: xmax = numpy.max(x)
88 95 if self.minvalue == None: minvalue = numpy.min(data1D)
89 96 if self.maxvalue == None: maxvalue = numpy.max(data1D)
90 97
91 98 self.__createFrames()
92 99 self.__isConfig = True
93 100
94 101
95 102 if not(self.__isOutOfXRange(x)):
96 103 self.__changeXRange(x)
97 104
98 105 if self.__isFigureOpen:
99 106 self.__driverObj.closePage()
100 107 self.__isFigureOpen = False
101 108
102 109 if not(self.__isFigureOpen):
103 110 self.__openFigure()
104 111
105 112 for channel in channelList:
106 113 frameObj = self.frameObjList[channel]
107 114 frameObj.init(xmin=xmin,
108 115 xmax=xmax,
109 116 minvalue=minvalue,
110 117 maxvalue=maxvalue)
111 118
112 119 self.__isFigureOpen = True
113 120
114 121
115 122 for channel in channelList:
116 123 dataCh = data1D[channel]
117 124 frameObj = self.frameObjList[channel]
118 125
119 126 frameObj.clearData()
120 127 frameObj.plot(dataCh)
121 128
122 129 frameObj.refresh()
123 130
124 131 if not(self.overplot):
125 132 self.__driverObj.closeFigure()
126 133 self.__isFigureOpen = False
127 134
128 135
129 136 def plot2DArray(self, x, y, data2D, xmin=None, xmax=None, ymin=None, ymax=None, minvalue=None, maxvalue=None, save=False, gpath='./'):
130 137
131 138 if not(self.__isCOpen):
132 139 self.__createFrames()
133 140 self.__openFigure()
134 141 self.__isOpen = True
135 142
136 143 if not(self.__isConfig):
137 144 self.setRange(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, minvalue=minvalue, maxvalue=maxvalue)
138 145
139 146 self.__isConfig = True
140 147
141 148 for channel in channelList:
142 149 dataCh = dataArray[channel]
143 150 frameObj = frameObjList[channel]
144 151 frameObj.plot(dataCh)
145 152
146 153 def saveFigure(self, filename):
147 154 pass
148 155
149 156
150 157 def getSubplots(self):
151
152 raise ValueError, ''
158
159 raise ValueError, "No implemented"
153 160
154 161 class Frame:
155 162
156 163 """
157 164 subplots
158 165 """
159 166
160 167 plotObjList = []
161 168
162 169 def __init__(self, idframe, showGraph1=False, showGraph2=False):
163 170
164 171 self.idframe = idframe
165 172 self.showGraph1 = showGraph1
166 173 self.showGraph2 = showGraph2
167 174
168 175 self.nplots = 1 + showGraph1 + showGraph2
169 176 self.__createPlots()
170 177
171 178 def __createPlots(self):
172 179
173 180 for nplot in range(self.nplots):
174 181 xi, yi, xw, yw = self.__getScreenPos(nplot)
175 182 plotObj = Plot(xi, yi, xw, yw)
176 183
177 184 self.plotObjList.append(plotObj)
178 185
179 186 def __getScreenPosMainPlot(self):
180 187
181 188 """
182 189 Calcula las coordenadas asociadas al plot principal.
183 190 """
184 191
185 192 xi = 1.2
186 193 yi = 2.3
187 194 xw = 2.0
188 195 yw = 1.4
189 196
190 197 return xi, yi, xw, yw
191 198
192 199 def __getScreenPosGraph1(self):
193 200 xi = 1.2
194 201 yi = 2.3
195 202 xw = 2.0
196 203 yw = 1.4
197 204
198 205 return xi, yi, xw, yw
199 206
200 207 def __getScreenPosGraph2(self):
201 208 xi = 1.2
202 209 yi = 2.3
203 210 xw = 2.0
204 211 yw = 1.4
205 212
206 213 return xi, yi, xw, yw
207 214
208 215 def __getScreenPos(self, nplot):
209 216
210 217 if nplot == 0:
211 218 xi, yi, xw, yw = self.__getScreenPosMain()
212 219 if nplot == 1:
213 220 xi, yi, xw, yw = self.__getScreenPosMain()
214 221 if nplot == 2:
215 222 xi, yi, xw, yw = self.__getScreenPosMain()
216 223
217 224 return xi, yi, xw, yw
218 225
219 226
220 227 def init(self, xmin, xmax, ymin, yamx, minvalue, maxvalue):
221 228
222 229 """
223 230 """
224 231
225 232 for plotObj in self.plotObjList:
226 233 plotObj.plotBox(xmin, xmax, ymin, yamx, minvalue, maxvalue)
227 234
228 235 def clearData(self):
229 236 pass
230 237
231 238 def plot(self, data):
232 239
233 240 for plotObj in self.plotObjList:
234 241 plotObj.plotData(data)
235 242
236 243 def refresh(self):
237 244 pass
238 245
239 246
240 247
241 248 class Plot:
242 249
243 250 def __init__(self, xi, yi, xw, yw):
244 251
245 252 self.xi = xi
246 253 self.yi = yi
247 254 self.xw = xw
248 255 self.yw = yw
249 256
250 257 def __setRange(self, xrange, yrange, zrange):
251 258 pass
252 259
253 260 def __setLabels(self, xlabel, ylabel, zlabel):
254 261 pass
255 262
256 263
257 264 def plotBox(self,xmin, xmax, ymin, yamx, minvalue, maxvalue):
258 265 pass
259 266
260 267 def plotData(self):
261 268
262 269 raise ValueError, ""
263 270
@@ -1,487 +1,680
1 1 import plplot
2 2 import numpy
3 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 15 class PlplotDriver:
6 16
7 17 __isDriverOpen = False
8
9 def __init__(self, id=None, driver=None, wintitle, overplot, colormap, showGraph1, showGraph2):
10
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
18 pldriver = None
19
20 def __init__(self, idfigure=None, xw, yw, wintitle, overplot, colormap, *showGraphs):
24 21
22 if idfigure == None:
23 raise ValueError, 'idfigure input must be defined'
25 24
26 self.nFrames = nFrames
25 self.idfigure = idfigure
26 self.xw = xw
27 self.yw = yw
27 28 self.wintitle = wintitle
28 self.colormap = colormap
29 self.showGraph1 = showGraph1
30 self.showGraph2 = showGraph2
31
32 29 self.overplot = overplot
30 self.colormap = colormap
31 self.showGraph1 = showGraphs[0]
32 self.showGraph2 = showGraphs[1]
33 33
34 34 def configDriver(self):
35 if self.driver == "":
36 import plplot
37
38 pass
39
40 def openDriver(self):
41
42 pass
35 """
36 previous configuration to open(init) the plplot driver
37 """
38 plplot.plsstrm(self.idfigure)
39 plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL)
40 plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw))
41
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 62 def closeDriver(self):
45
46 63 pass
47 64
48 65 def openPage(self):
49 pass
66 plplot.plbop()
67 plplot.pladv(0)
50 68
51 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 258 def setBox(self):
60 259
61 260 pass
62 261
63 262 def refreshBox(self):
64 263
65 264 pass
66 265
67 266 def save(self):
68 267
69 268 pass
70 269
71 270 def show(self):
72 271
73 272 pass
74 273
75 274 def colorbarPlot(self):
76 275
77 276 pass
78 277
79 278 def linePlot(self):
80 279
81 280 pass
82 281
83 282 def pcolorPlot(self):
84 283
85 284 pass
86 285
87 286 def setLabels(self):
88 287
89 288 pass
90 289
91 def figure(self):
92
93 pass
94
95 def setSubPlots(self):
96
97 pass
290
98 291
99 292
100 293
101 294 class MplDriver:
102 295 def __init__(self):
103 296 pass
104 297
105 def config_driver(id, wintitle, width, height):
106 plplot.plsstrm(id)
298 def config_driver(idfigure, wintitle, width, height):
299 plplot.plsstrm(idfigure)
107 300 plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL)
108 301 plplot.plsetopt("geometry", "%dx%d"%(width,height))
109 302
110 303 def ini_driver(driver):
111 304 if sys.platform == "darwin":
112 305 plplot.plsdev("xwin")
113 306 if sys.platform == "linux":
114 307 plplot.plsdev("xcairo")
115 308 plplot.plscolbg(255,255,255)
116 309 plplot.plscol0(1,0,0,0)
117 310 plplot.plinit()
118 311 plplot.plspause(False)
119 312
120 313 def set_subpages(ncol,nrow):
121 314 plplot.plssub(ncol,nrow)
122 315
123 316 def cmap1_init(colormap="gray"):
124 317
125 318 if colormap == None:
126 319 return
127 320
128 321 ncolor = None
129 322 rgb_lvl = None
130 323
131 324 # Routine for defining a specific color map 1 in HLS space.
132 325 # if gray is true, use basic grayscale variation from half-dark to light.
133 326 # otherwise use false color variation from blue (240 deg) to red (360 deg).
134 327
135 328 # Independent variable of control points.
136 329 i = numpy.array((0., 1.))
137 330 if colormap=="gray":
138 331 ncolor = 256
139 332 # Hue for control points. Doesn't matter since saturation is zero.
140 333 h = numpy.array((0., 0.))
141 334 # Lightness ranging from half-dark (for interest) to light.
142 335 l = numpy.array((0.5, 1.))
143 336 # Gray scale has zero saturation
144 337 s = numpy.array((0., 0.))
145 338
146 339 # number of cmap1 colours is 256 in this case.
147 340 plplot.plscmap1n(ncolor)
148 341 # Interpolate between control points to set up cmap1.
149 342 plplot.plscmap1l(0, i, h, l, s)
150 343
151 344 return None
152 345
153 346 if colormap == 'jet':
154 347 ncolor = 256
155 348 pos = numpy.zeros((ncolor))
156 349 r = numpy.zeros((ncolor))
157 350 g = numpy.zeros((ncolor))
158 351 b = numpy.zeros((ncolor))
159 352
160 353 for i in range(ncolor):
161 354 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
162 355 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
163 356 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
164 357 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
165 358
166 359 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
167 360 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
168 361 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
169 362 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
170 363 else: gf = 0.0
171 364
172 365 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
173 366 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
174 367 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
175 368 else: bf = 0
176 369
177 370 r[i] = rf
178 371 g[i] = gf
179 372 b[i] = bf
180 373
181 374 pos[i] = float(i)/float(ncolor-1)
182 375
183 376
184 377 plplot.plscmap1n(ncolor)
185 378 plplot.plscmap1l(1, pos, r, g, b)
186 379
187 380
188 381
189 382 if colormap=="br_green":
190 383 ncolor = 256
191 384 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
192 385 h = numpy.array((240., 0.))
193 386 # Lightness and saturation are constant (values taken from C example).
194 387 l = numpy.array((0.6, 0.6))
195 388 s = numpy.array((0.8, 0.8))
196 389
197 390 # number of cmap1 colours is 256 in this case.
198 391 plplot.plscmap1n(ncolor)
199 392 # Interpolate between control points to set up cmap1.
200 393 plplot.plscmap1l(0, i, h, l, s)
201 394
202 395 return None
203 396
204 397 if colormap=="tricolor":
205 398 ncolor = 3
206 399 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
207 400 h = numpy.array((240., 0.))
208 401 # Lightness and saturation are constant (values taken from C example).
209 402 l = numpy.array((0.6, 0.6))
210 403 s = numpy.array((0.8, 0.8))
211 404
212 405 # number of cmap1 colours is 256 in this case.
213 406 plplot.plscmap1n(ncolor)
214 407 # Interpolate between control points to set up cmap1.
215 408 plplot.plscmap1l(0, i, h, l, s)
216 409
217 410 return None
218 411
219 412 if colormap == 'rgb' or colormap == 'rgb666':
220 413
221 414 color_sz = 6
222 415 ncolor = color_sz*color_sz*color_sz
223 416 pos = numpy.zeros((ncolor))
224 417 r = numpy.zeros((ncolor))
225 418 g = numpy.zeros((ncolor))
226 419 b = numpy.zeros((ncolor))
227 420 ind = 0
228 421 for ri in range(color_sz):
229 422 for gi in range(color_sz):
230 423 for bi in range(color_sz):
231 424 r[ind] = ri/(color_sz-1.0)
232 425 g[ind] = gi/(color_sz-1.0)
233 426 b[ind] = bi/(color_sz-1.0)
234 427 pos[ind] = ind/(ncolor-1.0)
235 428 ind += 1
236 429 rgb_lvl = [6,6,6] #Levels for RGB colors
237 430
238 431 if colormap == 'rgb676':
239 432 ncolor = 6*7*6
240 433 pos = numpy.zeros((ncolor))
241 434 r = numpy.zeros((ncolor))
242 435 g = numpy.zeros((ncolor))
243 436 b = numpy.zeros((ncolor))
244 437 ind = 0
245 438 for ri in range(8):
246 439 for gi in range(8):
247 440 for bi in range(4):
248 441 r[ind] = ri/(6-1.0)
249 442 g[ind] = gi/(7-1.0)
250 443 b[ind] = bi/(6-1.0)
251 444 pos[ind] = ind/(ncolor-1.0)
252 445 ind += 1
253 446 rgb_lvl = [6,7,6] #Levels for RGB colors
254 447
255 448 if colormap == 'rgb685':
256 449 ncolor = 6*8*5
257 450 pos = numpy.zeros((ncolor))
258 451 r = numpy.zeros((ncolor))
259 452 g = numpy.zeros((ncolor))
260 453 b = numpy.zeros((ncolor))
261 454 ind = 0
262 455 for ri in range(8):
263 456 for gi in range(8):
264 457 for bi in range(4):
265 458 r[ind] = ri/(6-1.0)
266 459 g[ind] = gi/(8-1.0)
267 460 b[ind] = bi/(5-1.0)
268 461 pos[ind] = ind/(ncolor-1.0)
269 462 ind += 1
270 463 rgb_lvl = [6,8,5] #Levels for RGB colors
271 464
272 465 if colormap == 'rgb884':
273 466 ncolor = 8*8*4
274 467 pos = numpy.zeros((ncolor))
275 468 r = numpy.zeros((ncolor))
276 469 g = numpy.zeros((ncolor))
277 470 b = numpy.zeros((ncolor))
278 471 ind = 0
279 472 for ri in range(8):
280 473 for gi in range(8):
281 474 for bi in range(4):
282 475 r[ind] = ri/(8-1.0)
283 476 g[ind] = gi/(8-1.0)
284 477 b[ind] = bi/(4-1.0)
285 478 pos[ind] = ind/(ncolor-1.0)
286 479 ind += 1
287 480 rgb_lvl = [8,8,4] #Levels for RGB colors
288 481
289 482 if ncolor == None:
290 483 raise ValueError, "The colormap selected is not valid"
291 484
292 485 plplot.plscmap1n(ncolor)
293 486 plplot.plscmap1l(1, pos, r, g, b)
294 487
295 488 return rgb_lvl
296 489
297 490 def set_colormap(colormap="jet"):
298 491 cmap1_init(colormap)
299 492
300 493 def save_figure(filename,width,height):
301 494 curr_strm = plplot.plgstrm()
302 495 save_strm = plplot.plmkstrm()
303 496 plplot.plsetopt("geometry", "%dx%d"%(width,height))
304 497 if sys.platform == "darwin":
305 498 plplot.plsdev("png")
306 499 if sys.platform == "linux":
307 500 plplot.plsdev("pngcairo")
308 501 plplot.plsfnam(filename)
309 502 plplot.plcpstrm(curr_strm,0)
310 503 plplot.plreplot()
311 504 plplot.plend1()
312 505 plplot.plsstrm(curr_strm)
313 506
314 507 def set_new_figure():
315 508 plplot.plbop()
316 509 plplot.pladv(0)
317 510
318 511 def close_figure():
319 512 plplot.pleop()
320 513
321 514 def set_strm(indexPlot):
322 515 plplot.plsstrm(indexPlot)
323 516
324 517 def refresh():
325 518 plplot.plflush()
326 519
327 520 def show():
328 521 plplot.plspause(True)
329 522 plplot.plend()
330 523
331 524 def set_title(pltitle,color, szchar=0.7):
332 525 setSubpages(1, 0)
333 526 plplot.pladv(0)
334 527 plplot.plvpor(0., 1., 0., 1.)
335 528
336 529 if color == "black":
337 530 plplot.plcol0(1)
338 531 if color == "white":
339 532 plplot.plcol0(15)
340 533
341 534 plplot.plschr(0.0,szchar)
342 535 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
343 536
344 537 def set_line_style(style):
345 538 plplot.pllsty(style)
346 539
347 540 def set_color(color):
348 541 plplot.plcol0(color)
349 542
350 543 def set_labels(xlabel, ylabel, title):
351 544 plplot.pllab(xlabel, ylabel, title)
352 545
353 546 def box(subplot, xpos, ypos, xmin, xmax, ymin, ymax, xopt, yopt, szchar, xaxisastime, timefmt="%H:%M"):
354 547 plplot.pladv(subplot)
355 548 plplot.plschr(0.0,szchar-0.05)
356 549 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
357 550 plplot.plwind(float(xmin),
358 551 float(xmax),
359 552 float(ymin),
360 553 float(ymax)
361 554 )
362 555 if xaxisastime:
363 556 plplot.pltimefmt(timefmt)
364 557 timedelta = (xmax - xmin + 1)/8.
365 558 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
366 559 else:
367 560 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
368 561
369 562 def colorbar(xmin=0., xmax=1., ymin=0., ymax=1.):
370 563 data = numpy.arange(256)
371 564 data = numpy.reshape(data, (1,-1))
372 565
373 566 plplot.plimage(data,
374 567 float(xmin),
375 568 float(xmax),
376 569 float(ymin),
377 570 float(ymax),
378 571 0.,
379 572 255.,
380 573 float(xmin),
381 574 float(xmax),
382 575 float(ymin),
383 576 float(ymax))
384 577
385 578 def basicline_timeplot(x, y,colline=1):
386 579 plplot.plcol0(colline)
387 580 plplot.plline(x, y)
388 581 plplot.plcol0(1)
389 582
390 583 def basic_xy_plot(x, y):
391 584 plplot.plline(x, y)
392 585
393 586 def basic_pcolor_plot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
394 587 """
395 588 """
396 589 if xmin == None: xmin = x[0]
397 590 if xmax == None: xmax = x[-1]
398 591 if ymin == None: ymin = y[0]
399 592 if ymax == None: ymax = y[-1]
400 593 if zmin == None: zmin = numpy.nanmin(data)
401 594 if zmax == None: zmax = numpy.nanmax(data)
402 595
403 596 plplot.plimage(data,
404 597 float(x[0]),
405 598 float(x[-1]),
406 599 float(y[0]),
407 600 float(y[-1]),
408 601 float(zmin),
409 602 float(zmax),
410 603 float(xmin),
411 604 float(xmax),
412 605 float(ymin),
413 606 float(ymax)
414 607 )
415 608
416 609 def image_plot(self,x,y,z,xrange,yrange,zrange):
417 610 xi = x[0]
418 611 xf = x[-1]
419 612 yi = y[0]
420 613 yf = y[-1]
421 614
422 615 plplot.plimage(z,
423 616 float(xi),
424 617 float(xf),
425 618 float(yi),
426 619 float(yf),
427 620 float(zrange[0]),
428 621 float(zrange[1]),
429 622 float(xi),
430 623 float(xf),
431 624 float(yrange[0]),
432 625 yrange[1])
433 626
434 627 def adv_pcolor_plot(data, x, y, xg, yg, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0.):
435 628 plplot.plimagefr(data,
436 629 float(xmin),
437 630 float(xmax),
438 631 float(ymin),
439 632 float(ymax),
440 633 0.,
441 634 0.,
442 635 float(zmin),
443 636 float(zmax),
444 637 plplot.pltr2,
445 638 xg,
446 639 yg)
447 640
448 641 #------------------------------------
449 642
450 643 #def get_grid(x, y, deltax=None, deltay=None):
451 644 #
452 645 # if not(len(x)>0 and len(y)>0):
453 646 # raise ValueError, "x axis and y axis are empty"
454 647 #
455 648 # if deltax == None: deltax = x[-1] - x[-2]
456 649 # if deltay == None: deltay = y[-1] - y[-2]
457 650 #
458 651 # x1 = numpy.append(x, x[-1] + deltax)
459 652 # y1 = numpy.append(y, y[-1] + deltay)
460 653 #
461 654 # xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
462 655 # yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
463 656 #
464 657 # self.__xg = xg
465 658 # self.__yg = yg
466 659 #
467 660 # return xg, yg
468 661 #
469 662 #def advPcolorPlot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
470 663 # if getGrid:
471 664 # xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
472 665 # else:
473 666 # xg = self.__xg
474 667 # yg = self.__yg
475 668 #
476 669 # plplot.plimagefr(data,
477 670 # float(xmin),
478 671 # float(xmax),
479 672 # float(ymin),
480 673 # float(ymax),
481 674 # 0.,
482 675 # 0.,
483 676 # float(zmin),
484 677 # float(zmax),
485 678 # plplot.pltr2,
486 679 # xg,
487 680 # yg)
@@ -1,68 +1,79
1 1 import numpy
2 2 from schainPlot import *
3 3
4 4
5 5 class RTIFigure(Figure):
6 def __init__(self, idstream, nframe, wintitle, colormap, driver, showColorbar, showPowerProfile):
7 self.idStream = idStream
8 self.nFrames = nFrames
9 self.winTitle = winTitle
10 self.colormap = colormap
11 self.driver = driver
12 self.showGraph1 = showColorbar
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
6
7 overplot = 1 # igual a 1 porque el grafico es RTI, para el caso de Spectra(Spc,CrossSpc) overplot = 0
8 xw = 700
9 yw = 150
10 nframes = None
11
12 def __init__(self, idfigure, nframes, wintitle, colormap, driver, showColorbar, showPowerProfile):
15 13
16 self.width = 700
17 self.height = 150
18 self.ncol = int(numpy.sqrt(self.nFrames)+0.9)
19 self.nrow = int(self.nFrames*1./ncol + 0.9)
14 showGraphs = (showColorbar, showPowerProfile)
15
16 Figure.__init__(self,
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 37 def __createFrames(self):
23 for frame in range(self.nFrames):
38 for frame in range(self.nframes):
24 39 frameObj = RTIFrame(idFrame = frame,
25 showGraph1 = self.showGraph1,
26 showGraph2 = self.showGraph2
40 showGraph1 = self.showColorbar,
41 showGraph2 = self.showPowerProfile
27 42 )
28 43
29 44 self.frameObjList.append(frameObj)
30
31
32
33
34
45
35 46
36 47 class RTIFrame(Frame):
37 48 def __init__(self,idFrame, showColorbar, showPowerProfile):
38 49 self.idFrame = idFrame
39 50 self.showGraph1 = showColorbar
40 51 self.showGraph2 = showPowerProfile
41 52
42 53 def setXYPos(self):
43 54 pass
44 55
45 56 class SelfSpcFigure(Figure):
46 57 def __init__(self):
47 58 pass
48 59
49 60 class SelfSpcFrame(Frame):
50 61 def __init__(self):
51 62 pass
52 63
53 64 class CrossSpcFigure(Figure):
54 65 def __init__(self):
55 66 pass
56 67
57 68 class CrossSpcFrame(Frame):
58 69 def __init__(self):
59 70 pass
60 71
61 72 class ScopeFigure(Figure):
62 73 def __init__(self):
63 74 pass
64 75
65 76 class ScopeFrame(Frame):
66 77 def __init__(self):
67 78 pass
68 79
General Comments 0
You need to be logged in to leave comments. Login now