##// END OF EJS Templates
Inicia nueva version de graficos
Miguel Valdez -
r129:b3b2528ac950
parent child
Show More
@@ -0,0 +1,213
1
2 import numpy
3 import schainPlplotLib
4
5 class Figure:
6
7 __driverObj = None
8 __isDriverOpen = False
9 __isFigureOpen = False
10 __isConfig = False
11 __width = None
12 __height = None
13
14 idfigure = None
15 nframes = None
16 wintitle = wintitle
17 colormap = None
18 driver = None
19 overplot = None
20
21 frameObjList = []
22
23 def __init__(self, idfigure, nframes, wintitle, width=600, height=800, overplot=0, driver='xwin', colormap='br_green', *showGraphs):
24
25 self.idfigure = idfigure
26 self.nframes = nframes
27 self.wintitle = wintitle
28 self.colormap = colormap
29 self.driver = driver
30 self.overplot = overplot
31
32 self.showGraphs = showGraphs
33
34 self.__driverObj = Driver(driver)
35
36 def __createFrames(self):
37
38 for frame in range(self.nframes):
39 frameObj = Frame(idFrame = frame,
40 showGraph1 = self.showGraph1,
41 showGraph2 = self.showGraph2
42 )
43
44 self.frameObjList.append(frameObj)
45
46 def __openDriver(self):
47
48 self.__driverObj.openDriver(self.idfigure, self.wintitle, self.width, self.height)
49
50 def __openFigure(self):
51
52 self.__createFrames()
53 nrows, ncolumns = self.getSubplots()
54
55 self.__driverObj.openFigure()
56 self.__driverObj.setSubPlots(nrows, ncolumns)
57
58
59 def __verifyXRange(self, x):
60 pass
61
62 def __updateXRange(self, x):
63 pass
64
65 def plot1DArray(self, data1D, x=None, xmin=None, xmax=None, minvalue=None, maxvlaue=None, save=False, gpath='./'):
66
67 if not(self.__isDriverOpen):
68 self.__openDriver()
69 self.__isDriverOpen = True
70
71 if not(self.__isConfig):
72 if x == None: x = numpy.arange(data1D.size)
73 if xmin == None: xmin = numpy.min(x)
74 if xmax == None: xmax = numpy.max(x)
75 if minvalue == None: minvalue = numpy.min(data1D)
76 if maxvalue == None: maxvalue = numpy.max(data1D)
77
78 self.setRange(xmin=xmin, xmax=xmax, minvalue=minvalue, maxvalue=maxvalue)
79 self.__isConfig = True
80
81 if not(self.__verifyXRange(x)):
82 self.__updateXRange(x)
83 if self.__isFigureOpen:
84 close_figure()
85 self.__isFigureOpen = False
86
87 if not(self.__isFigureOpen):
88 self.__openFigure()
89 self.__isFigureOpen = True
90
91 for frame in channelList:
92 dataCh = data1D[channel]
93 frameObj = frameObjList[channel]
94 frameObj.plotBox()
95
96 for channel in channelList:
97 dataCh = dataArray[channel]
98 frameObj = frameObjList[channel]
99 frameObj.plot(dataCh)
100
101 if not(self.overplot):
102 close_figure()
103 self.__isFigureOpen = False
104
105
106 def plot2DArray(self, x, y, data2D, xmin=None, xmax=None, ymin=None, ymax=None, minvalue=None, maxvalue=None, save=False, gpath='./'):
107
108 if not(self.__isCOpen):
109 self.__createFrames()
110 self.__openFigure()
111 self.__isOpen = True
112
113 if not(self.__isConfig):
114 self.setRange(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, minvalue=minvalue, maxvalue=maxvalue)
115
116 self.__isConfig = True
117
118 for channel in channelList:
119 dataCh = dataArray[channel]
120 frameObj = frameObjList[channel]
121 frameObj.plot(dataCh)
122
123 def saveFigure(self, filename):
124 pass
125
126
127 def getSubplots(self):
128
129 raise ValueError, ''
130
131 class Frame:
132
133 plotObjList = []
134
135 def __init__(self, idFrame, showGraph1=False, showGraph2=False):
136
137 self.idFrame = idFrame
138 self.showGraph1 = showGraph1
139 self.showGraph2 = showGraph2
140
141 self.nPlots = 2
142 self.createPlots()
143
144 def __getScreenPosMain(self):
145 left = 1.2
146 bottom = 2.3
147 width = 2.0
148 height = 1.4
149
150 return left, bottom, width, height
151
152 def __getScreenPosGraph1(self):
153 left = 1.2
154 bottom = 2.3
155 width = 2.0
156 height = 1.4
157
158 return left, bottom, width, height
159
160 def __getScreenPosGraph2(self):
161 left = 1.2
162 bottom = 2.3
163 width = 2.0
164 height = 1.4
165
166 return left, bottom, width, height
167
168 def __getScreenPos(self, nplot):
169
170 if nplot == 0:
171 left, bottom, width, height = self.__getScreenPosMain()
172 if nplot == 1:
173 left, bottom, width, height = self.__getScreenPosMain()
174 if nplot == 2:
175 left, bottom, width, height = self.__getScreenPosMain()
176
177 return left, bottom, width, height
178
179 def createPlots(self):
180
181 for nplot in range(self.nPlots):
182 left, bottom, width, height = self.__getScreenPos(nplot)
183 plotObj = Plot(left, bottom, width, height)
184
185 self.plotObjList.append(plotObj)
186
187 def setup(self):
188 pass
189
190 def plot(self, data):
191 pass
192
193 class Plot:
194
195 def __init__(self, left, bottom, width, height):
196
197 self.left = left
198 self.bottom = bottom
199 self.width = width
200 self.height = height
201
202 def setRange(self, xrange, yrange, zrange):
203 pass
204
205 def setLabels(self, xlabel, ylabel, zlabel):
206 pass
207
208 def plotBox(self):
209 pass
210
211 def plotData(self):
212 pass
213
@@ -0,0 +1,68
1 import numpy
2 from schainPlot import *
3
4
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
15
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)
20
21
22 def __createFrames(self):
23 for frame in range(self.nFrames):
24 frameObj = RTIFrame(idFrame = frame,
25 showGraph1 = self.showGraph1,
26 showGraph2 = self.showGraph2
27 )
28
29 self.frameObjList.append(frameObj)
30
31
32
33
34
35
36 class RTIFrame(Frame):
37 def __init__(self,idFrame, showColorbar, showPowerProfile):
38 self.idFrame = idFrame
39 self.showGraph1 = showColorbar
40 self.showGraph2 = showPowerProfile
41
42 def setXYPos
43
44
45 class SelfSpcFigure(Figure):
46 def __init__(self):
47 pass
48
49 class SelfSpcFrame(Frame):
50 def __init__(self):
51 pass
52
53 class CrossSpcFigure(Figure):
54 def __init__(self):
55 pass
56
57 class CrossSpcFrame(Frame):
58 def __init__(self):
59 pass
60
61 class ScopeFigure(Figure):
62 def __init__(self):
63 pass
64
65 class ScopeFrame(Frame):
66 def __init__(self):
67 pass
68
@@ -0,0 +1,468
1 import plplot
2 import numpy
3 import sys
4
5 class Driver:
6
7 __isDriverOpen = False
8
9 def __init__(self, driver=plplot):
10
11 self.idStream = idStream
12 self.nFrames = nFrames
13 self.winTitle = winTitle
14 self.colormap = colormap
15 self.driver = driver
16
17 self.showGraph1 = showGraph1
18 self.showGraph2 = showGraph2
19
20 self.overplot = overplot
21
22 def configDriver(self):
23
24 pass
25
26 def openDriver(self):
27
28 pass
29
30 def closeDriver(self):
31
32 pass
33
34 def openPage(self):
35 pass
36
37 def closePage(self):
38
39 pass
40
41 def setColorMap(self):
42
43 pass
44
45 def setBox(self):
46
47 pass
48
49 def refreshBox(self):
50
51 pass
52
53 def save(self):
54
55 pass
56
57 def show(self):
58
59 pass
60
61 def colorbarPlot(self):
62
63 pass
64
65 def linePlot(self):
66
67 pass
68
69 def pcolorPlot(self):
70
71 pass
72
73 def setLabels(self):
74
75 pass
76
77 def figure(self):
78
79 pass
80
81 def setSubPlots(self):
82
83 pass
84
85
86 def config_driver(idStream, wintitle, width, height):
87 plplot.plsstrm(idStream)
88 plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL)
89 plplot.plsetopt("geometry", "%dx%d"%(width,height))
90
91 def ini_driver(driver):
92 if sys.platform == "darwin":
93 plplot.plsdev("xwin")
94 if sys.platform == "linux":
95 plplot.plsdev("xcairo")
96 plplot.plscolbg(255,255,255)
97 plplot.plscol0(1,0,0,0)
98 plplot.plinit()
99 plplot.plspause(False)
100
101 def set_subpages(ncol,nrow):
102 plplot.plssub(ncol,nrow)
103
104 def cmap1_init(colormap="gray"):
105
106 if colormap == None:
107 return
108
109 ncolor = None
110 rgb_lvl = None
111
112 # Routine for defining a specific color map 1 in HLS space.
113 # if gray is true, use basic grayscale variation from half-dark to light.
114 # otherwise use false color variation from blue (240 deg) to red (360 deg).
115
116 # Independent variable of control points.
117 i = numpy.array((0., 1.))
118 if colormap=="gray":
119 ncolor = 256
120 # Hue for control points. Doesn't matter since saturation is zero.
121 h = numpy.array((0., 0.))
122 # Lightness ranging from half-dark (for interest) to light.
123 l = numpy.array((0.5, 1.))
124 # Gray scale has zero saturation
125 s = numpy.array((0., 0.))
126
127 # number of cmap1 colours is 256 in this case.
128 plplot.plscmap1n(ncolor)
129 # Interpolate between control points to set up cmap1.
130 plplot.plscmap1l(0, i, h, l, s)
131
132 return None
133
134 if colormap == 'jet':
135 ncolor = 256
136 pos = numpy.zeros((ncolor))
137 r = numpy.zeros((ncolor))
138 g = numpy.zeros((ncolor))
139 b = numpy.zeros((ncolor))
140
141 for i in range(ncolor):
142 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
143 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
144 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
145 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
146
147 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
148 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
149 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
150 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
151 else: gf = 0.0
152
153 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
154 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
155 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
156 else: bf = 0
157
158 r[i] = rf
159 g[i] = gf
160 b[i] = bf
161
162 pos[i] = float(i)/float(ncolor-1)
163
164
165 plplot.plscmap1n(ncolor)
166 plplot.plscmap1l(1, pos, r, g, b)
167
168
169
170 if colormap=="br_green":
171 ncolor = 256
172 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
173 h = numpy.array((240., 0.))
174 # Lightness and saturation are constant (values taken from C example).
175 l = numpy.array((0.6, 0.6))
176 s = numpy.array((0.8, 0.8))
177
178 # number of cmap1 colours is 256 in this case.
179 plplot.plscmap1n(ncolor)
180 # Interpolate between control points to set up cmap1.
181 plplot.plscmap1l(0, i, h, l, s)
182
183 return None
184
185 if colormap=="tricolor":
186 ncolor = 3
187 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
188 h = numpy.array((240., 0.))
189 # Lightness and saturation are constant (values taken from C example).
190 l = numpy.array((0.6, 0.6))
191 s = numpy.array((0.8, 0.8))
192
193 # number of cmap1 colours is 256 in this case.
194 plplot.plscmap1n(ncolor)
195 # Interpolate between control points to set up cmap1.
196 plplot.plscmap1l(0, i, h, l, s)
197
198 return None
199
200 if colormap == 'rgb' or colormap == 'rgb666':
201
202 color_sz = 6
203 ncolor = color_sz*color_sz*color_sz
204 pos = numpy.zeros((ncolor))
205 r = numpy.zeros((ncolor))
206 g = numpy.zeros((ncolor))
207 b = numpy.zeros((ncolor))
208 ind = 0
209 for ri in range(color_sz):
210 for gi in range(color_sz):
211 for bi in range(color_sz):
212 r[ind] = ri/(color_sz-1.0)
213 g[ind] = gi/(color_sz-1.0)
214 b[ind] = bi/(color_sz-1.0)
215 pos[ind] = ind/(ncolor-1.0)
216 ind += 1
217 rgb_lvl = [6,6,6] #Levels for RGB colors
218
219 if colormap == 'rgb676':
220 ncolor = 6*7*6
221 pos = numpy.zeros((ncolor))
222 r = numpy.zeros((ncolor))
223 g = numpy.zeros((ncolor))
224 b = numpy.zeros((ncolor))
225 ind = 0
226 for ri in range(8):
227 for gi in range(8):
228 for bi in range(4):
229 r[ind] = ri/(6-1.0)
230 g[ind] = gi/(7-1.0)
231 b[ind] = bi/(6-1.0)
232 pos[ind] = ind/(ncolor-1.0)
233 ind += 1
234 rgb_lvl = [6,7,6] #Levels for RGB colors
235
236 if colormap == 'rgb685':
237 ncolor = 6*8*5
238 pos = numpy.zeros((ncolor))
239 r = numpy.zeros((ncolor))
240 g = numpy.zeros((ncolor))
241 b = numpy.zeros((ncolor))
242 ind = 0
243 for ri in range(8):
244 for gi in range(8):
245 for bi in range(4):
246 r[ind] = ri/(6-1.0)
247 g[ind] = gi/(8-1.0)
248 b[ind] = bi/(5-1.0)
249 pos[ind] = ind/(ncolor-1.0)
250 ind += 1
251 rgb_lvl = [6,8,5] #Levels for RGB colors
252
253 if colormap == 'rgb884':
254 ncolor = 8*8*4
255 pos = numpy.zeros((ncolor))
256 r = numpy.zeros((ncolor))
257 g = numpy.zeros((ncolor))
258 b = numpy.zeros((ncolor))
259 ind = 0
260 for ri in range(8):
261 for gi in range(8):
262 for bi in range(4):
263 r[ind] = ri/(8-1.0)
264 g[ind] = gi/(8-1.0)
265 b[ind] = bi/(4-1.0)
266 pos[ind] = ind/(ncolor-1.0)
267 ind += 1
268 rgb_lvl = [8,8,4] #Levels for RGB colors
269
270 if ncolor == None:
271 raise ValueError, "The colormap selected is not valid"
272
273 plplot.plscmap1n(ncolor)
274 plplot.plscmap1l(1, pos, r, g, b)
275
276 return rgb_lvl
277
278 def set_colormap(colormap="jet"):
279 cmap1_init(colormap)
280
281 def save_figure(filename,width,height):
282 curr_strm = plplot.plgstrm()
283 save_strm = plplot.plmkstrm()
284 plplot.plsetopt("geometry", "%dx%d"%(width,height))
285 if sys.platform == "darwin":
286 plplot.plsdev("png")
287 if sys.platform == "linux":
288 plplot.plsdev("pngcairo")
289 plplot.plsfnam(filename)
290 plplot.plcpstrm(curr_strm,0)
291 plplot.plreplot()
292 plplot.plend1()
293 plplot.plsstrm(curr_strm)
294
295 def set_new_figure():
296 plplot.plbop()
297 plplot.pladv(0)
298
299 def close_figure():
300 plplot.pleop()
301
302 def set_strm(indexPlot):
303 plplot.plsstrm(indexPlot)
304
305 def refresh():
306 plplot.plflush()
307
308 def show():
309 plplot.plspause(True)
310 plplot.plend()
311
312 def set_title(pltitle,color, szchar=0.7):
313 setSubpages(1, 0)
314 plplot.pladv(0)
315 plplot.plvpor(0., 1., 0., 1.)
316
317 if color == "black":
318 plplot.plcol0(1)
319 if color == "white":
320 plplot.plcol0(15)
321
322 plplot.plschr(0.0,szchar)
323 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
324
325 def set_line_style(style):
326 plplot.pllsty(style)
327
328 def set_color(color):
329 plplot.plcol0(color)
330
331 def set_labels(xlabel, ylabel, title):
332 plplot.pllab(xlabel, ylabel, title)
333
334 def box(subplot, xpos, ypos, xmin, xmax, ymin, ymax, xopt, yopt, szchar, xaxisastime, timefmt="%H:%M"):
335 plplot.pladv(subplot)
336 plplot.plschr(0.0,szchar-0.05)
337 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
338 plplot.plwind(float(xmin),
339 float(xmax),
340 float(ymin),
341 float(ymax)
342 )
343 if xaxisastime:
344 plplot.pltimefmt(timefmt)
345 timedelta = (xmax - xmin + 1)/8.
346 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
347 else:
348 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
349
350 def colorbar(xmin=0., xmax=1., ymin=0., ymax=1.):
351 data = numpy.arange(256)
352 data = numpy.reshape(data, (1,-1))
353
354 plplot.plimage(data,
355 float(xmin),
356 float(xmax),
357 float(ymin),
358 float(ymax),
359 0.,
360 255.,
361 float(xmin),
362 float(xmax),
363 float(ymin),
364 float(ymax))
365
366 def basicline_timeplot(x, y,colline=1):
367 plplot.plcol0(colline)
368 plplot.plline(x, y)
369 plplot.plcol0(1)
370
371 def basic_xy_plot(x, y):
372 plplot.plline(x, y)
373
374 def basic_pcolor_plot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
375 """
376 """
377 if xmin == None: xmin = x[0]
378 if xmax == None: xmax = x[-1]
379 if ymin == None: ymin = y[0]
380 if ymax == None: ymax = y[-1]
381 if zmin == None: zmin = numpy.nanmin(data)
382 if zmax == None: zmax = numpy.nanmax(data)
383
384 plplot.plimage(data,
385 float(x[0]),
386 float(x[-1]),
387 float(y[0]),
388 float(y[-1]),
389 float(zmin),
390 float(zmax),
391 float(xmin),
392 float(xmax),
393 float(ymin),
394 float(ymax)
395 )
396
397 def image_plot(self,x,y,z,xrange,yrange,zrange):
398 xi = x[0]
399 xf = x[-1]
400 yi = y[0]
401 yf = y[-1]
402
403 plplot.plimage(z,
404 float(xi),
405 float(xf),
406 float(yi),
407 float(yf),
408 float(zrange[0]),
409 float(zrange[1]),
410 float(xi),
411 float(xf),
412 float(yrange[0]),
413 yrange[1])
414
415 def adv_pcolor_plot(data, x, y, xg, yg, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0.):
416 plplot.plimagefr(data,
417 float(xmin),
418 float(xmax),
419 float(ymin),
420 float(ymax),
421 0.,
422 0.,
423 float(zmin),
424 float(zmax),
425 plplot.pltr2,
426 xg,
427 yg)
428
429 #------------------------------------
430
431 #def get_grid(x, y, deltax=None, deltay=None):
432 #
433 # if not(len(x)>0 and len(y)>0):
434 # raise ValueError, "x axis and y axis are empty"
435 #
436 # if deltax == None: deltax = x[-1] - x[-2]
437 # if deltay == None: deltay = y[-1] - y[-2]
438 #
439 # x1 = numpy.append(x, x[-1] + deltax)
440 # y1 = numpy.append(y, y[-1] + deltay)
441 #
442 # xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
443 # yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
444 #
445 # self.__xg = xg
446 # self.__yg = yg
447 #
448 # return xg, yg
449 #
450 #def advPcolorPlot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
451 # if getGrid:
452 # xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
453 # else:
454 # xg = self.__xg
455 # yg = self.__yg
456 #
457 # plplot.plimagefr(data,
458 # float(xmin),
459 # float(xmax),
460 # float(ymin),
461 # float(ymax),
462 # 0.,
463 # 0.,
464 # float(zmin),
465 # float(zmax),
466 # plplot.pltr2,
467 # xg,
468 # yg)
General Comments 0
You need to be logged in to leave comments. Login now