##// END OF EJS Templates
Daniel Valdez -
r138:e16175a3f22c
parent child
Show More
@@ -1,232 +1,294
1 import numpy
1 import numpy
2 from schainPlotLib import Driver
2 from schainPlotLib import Driver
3
3
4 class Figure:
4 class Figure:
5 __isDriverOpen = False
5 __isDriverOpen = False
6 __isFigureOpen = False
6 __isFigureOpen = False
7 __isConfig = False
7 __isConfig = False
8 drvObj = None
8 drvObj = None
9 idfigure = None
9 idfigure = None
10 nframes = None
10 nframes = None
11 wintitle = None
11 wintitle = None
12 colormap = None
12 colormap = None
13 driver = None
13 driver = None
14 overplot = None
14 overplot = None
15 xmin = None
15 xmin = None
16 xmax = None
16 xmax = None
17 minvalue = None
17 minvalue = None
18 maxvalue = None
18 maxvalue = None
19 frameObjList = []
19 frameObjList = []
20 figtitle = ""
20 figtitle = ""
21
21
22 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colorbar= True, colormap=None, *args):
22 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colorbar= True, colormap=None, *args):
23 self.idfigure = idfigure
23 self.idfigure = idfigure
24 self.nframes = nframes
24 self.nframes = nframes
25 self.wintitle = wintitle
25 self.wintitle = wintitle
26 self.xw = xw
26 self.xw = xw
27 self.yw = yw
27 self.yw = yw
28 self.overplot = overplot
28 self.overplot = overplot
29 self.colorbar = colorbar
29 self.colorbar = colorbar
30 self.colormap = colormap
30 self.colormap = colormap
31 #esta seccion deberia ser dinamica de acuerdo a len(args)
31 #esta seccion deberia ser dinamica de acuerdo a len(args)
32 self.showGraph1 = args[0]
32 self.showGraph1 = args[0]
33 self.showGraph2 = args[1]
33 self.showGraph2 = args[1]
34
34
35 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap)
35 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap)
36
36
37 self.drvObj.driver.setFigure()
37 self.drvObj.driver.setFigure()
38
38
39
39
40 def __openDriver(self):
40 def __openDriver(self):
41 self.drvObj.driver.openDriver()
41 self.drvObj.driver.openDriver()
42
42
43 # def __openFigure(self):
43 # def __openFigure(self):
44 # nrows, ncolumns = self.getSubplots()
44 # nrows, ncolumns = self.getSubplots()
45 # self.drvObj.driver.openFigure()
45 # self.drvObj.driver.openFigure()
46 # self.drvObj.driver.setTitleFig(title)
46 # self.drvObj.driver.setTitleFig(title)
47 # self.drvObj.driver.setSubPlots(nrows, ncolumns)
47 # self.drvObj.driver.setSubPlots(nrows, ncolumns)
48
48
49 def __initFigure(self):
49 def __initFigure(self):
50 nrows, ncolumns = self.getSubplots()
50 nrows, ncolumns = self.getSubplots()
51 self.drvObj.driver.openFigure()
51 self.drvObj.driver.openFigure()
52 self.drvObj.driver.setFigTitle(self.figtitle)
52 self.drvObj.driver.setFigTitle(self.figtitle)
53 self.drvObj.driver.setSubPlots(nrows, ncolumns)
53 self.drvObj.driver.setSubPlots(nrows, ncolumns)
54
54
55 def __isOutOfXRange(self,x):
55 def __isOutOfXRange(self,x):
56 return 1
56 return 1
57
57
58 def __refresh(self):
58 def __refresh(self):
59 self.drvObj.driver.refresh()
59 self.drvObj.driver.refresh()
60
60
61 def createFrames(self):
61 def createFrames(self):
62 raise ValueError, "No implemented"
62 raise ValueError, "No implemented"
63
63
64 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figtitle=None, save=False, gpath='./'):
64 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'):
65
65
66 nx, ny = data1D.shape
66 nx, ny = data1D.shape
67
67
68 if channelList == None:
68 if channelList == None:
69 channelList = range(nx)
69 channelList = range(nx)
70
70
71 if x == None:
71 if x == None:
72 x = numpy.arange(data1D.size)
72 x = numpy.arange(data1D.size)
73
73
74 if figtitle == None:
74 if figuretitle == None:
75 self.figtitle = ""
75 self.figuretitle = ""
76 else:
76 else:
77 self.figtitle = figtitle
77 self.figuretitle = figuretitle
78
78
79 if not(self.__isDriverOpen):
79 if not(self.__isDriverOpen):
80 self.__openDriver()
80 self.__openDriver()
81 self.__isDriverOpen = True
81 self.__isDriverOpen = True
82
82
83 if not(self.__isConfig):
83 if not(self.__isConfig):
84 self.xmin = xmin
84 self.xmin = xmin
85 self.xmax = xmax
85 self.xmax = xmax
86 self.minvalue = minvalue
86 self.minvalue = minvalue
87 self.maxvalue = maxvalue
87 self.maxvalue = maxvalue
88
88
89 if self.xmin == None: self.xmin = numpy.min(x)
89 if self.xmin == None: self.xmin = numpy.min(x)
90 if self.xmax == None: self.xmax = numpy.max(x)
90 if self.xmax == None: self.xmax = numpy.max(x)
91 if self.minvalue == None: self.minvalue = numpy.min(data1D)
91 if self.minvalue == None: self.minvalue = numpy.min(data1D)
92 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
92 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
93
93
94 self.createFrames()
94 self.createFrames()
95 self.__isConfig = True
95 self.__isConfig = True
96
96
97 if not(self.__isOutOfXRange(x)):
97 if not(self.__isOutOfXRange(x)):
98 self.__changeXRange(x)
98 self.__changeXRange(x)
99
99
100 if self.__isFigureOpen:
100 if self.__isFigureOpen:
101 self.driverObj.closePage()
101 self.driverObj.closePage()
102 self.__isFigureOpen = False
102 self.__isFigureOpen = False
103
103
104 self.__initFigure()
104 self.__initFigure()
105
105
106 for channel in channelList:
106 for channel in channelList:
107 # frametitle = self.plotTitleDict[channel]
108 frameObj = self.frameObjList[channel]
107 frameObj = self.frameObjList[channel]
109 frameObj.init(xmin=self.xmin,
108 frameObj.init(xmin=self.xmin,
110 xmax=self.xmax,
109 xmax=self.xmax,
111 ymin=self.minvalue,
110 ymin=self.minvalue,
112 ymax=self.maxvalue,
111 ymax=self.maxvalue,
113 minvalue=self.minvalue,
112 minvalue=self.minvalue,
114 maxvalue=self.maxvalue)
113 maxvalue=self.maxvalue)
115
114
116 for channel in channelList:
115 for channel in channelList:
117 dataCh = data1D[channel,:]
116 dataCh = data1D[channel,:]
118 frameObj = self.frameObjList[channel]
117 frameObj = self.frameObjList[channel]
119 # frameObj.clearData()
118 # frameObj.clearData()
120 frameObj.plot(x, dataCh)
119 frameObj.plot(x, dataCh)
121
120
122 # frameObj.refresh()
121 # frameObj.refresh()
123 self.__refresh()
122 self.__refresh()
124
123
125
124
126 #
125 #
127 # if save:
126 # if save:
128 # self.colorplotObj.setFigure(indexPlot)
127 # self.colorplotObj.setFigure(indexPlot)
129 # path = "/home/roj-idl71/tmp/"
128 # path = "/home/roj-idl71/tmp/"
130 # now = datetime.datetime.now().timetuple()
129 # now = datetime.datetime.now().timetuple()
131 # file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5])
130 # file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5])
132 # filename = os.path.join(path,file)
131 # filename = os.path.join(path,file)
133 # self.colorplotObj.savePlot(indexPlot, filename)
132 # self.colorplotObj.savePlot(indexPlot, filename)
134 #
133 #
135 # self.colorplotObj.closePage()
134 # self.colorplotObj.closePage()
135
136
137 def plotPcolor(self,data,
138 x=None,
139 y=None,
140 channelList=None,
141 xmin=None,
142 xmax=None,
143 ymin=None,
144 ymax=None,
145 minvalue=None,
146 maxvalue=None,
147 figuretitle=None,
148 deltax=None,
149 save=False,
150 gpath='./'):
151 # data,
152 # currenttime,
153 # range,
154 # starttime,
155 # endtime,
156 # minrange,
157 # maxrange,
158 # minvalue,
159 # maxvalue,
160 # figuretitle,
161 # interval,
162 # save,
163 # gpath):
164
165 if figuretitle == None:
166 self.figuretitle = ""
167 else:
168 self.figuretitle = figuretitle
169
170
171
172 if not(self.__isDriverOpen):
173 self.__openDriver()
174 self.__isDriverOpen = True
175
176 if not(self.__isConfig):
177
178 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,deltax)
179
180
181
182 # if self.xmin == None: self.xmin = numpy.min(x)
183 # if self.xmax == None: self.xmax = numpy.max(x)
184
185
186 self.createFrames()
187 self.__isConfig = True
188
189 if not(self.__isOutOfXRange(x)):
190 self.__changeXRange(x)
191
192 if self.__isFigureOpen:
193 self.driverObj.closePage()
194 self.__isFigureOpen = False
195
196 self.__initFigure()
197
136
198
137 class Frame:
199 class Frame:
138 nplots = None
200 nplots = None
139 plotObjList = []
201 plotObjList = []
140 title = ""
202 title = ""
141 def __init__(self,drvObj, idframe):
203 def __init__(self,drvObj, idframe):
142 self.drvObj = drvObj
204 self.drvObj = drvObj
143 self.idframe = idframe
205 self.idframe = idframe
144 self.createPlots()
206 self.createPlots()
145
207
146 def createPlots(self):
208 def createPlots(self):
147 raise ValueError, "No implemented"
209 raise ValueError, "No implemented"
148
210
149 def getScreenPosMainPlot(self):
211 def getScreenPosMainPlot(self):
150 raise ValueError, "No implemented"
212 raise ValueError, "No implemented"
151
213
152 def getScreenPos(self, nplot):
214 def getScreenPos(self, nplot):
153
215
154 if nplot == 0:
216 if nplot == 0:
155 xi, yi, xw, yw = self.getScreenPosMainPlot()
217 xi, yi, xw, yw = self.getScreenPosMainPlot()
156 return xi, yi, xw, yw
218 return xi, yi, xw, yw
157
219
158
220
159 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue):
221 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue):
160
222
161 for plotObj in self.plotObjList:
223 for plotObj in self.plotObjList:
162 plotObj.plotBox(xmin, xmax, ymin, ymax, minvalue, maxvalue)
224 plotObj.plotBox(xmin, xmax, ymin, ymax, minvalue, maxvalue)
163 # plotObj.setLabels() # ? evaluar si conviene colocarlo dentro del plotbox
225 # plotObj.setLabels() # ? evaluar si conviene colocarlo dentro del plotbox
164
226
165 def refresh(self):
227 def refresh(self):
166 for plotObj in self.plotObjList:
228 for plotObj in self.plotObjList:
167 plotObj.refresh()
229 plotObj.refresh()
168
230
169 class Plot:
231 class Plot:
170 title = ""
232 title = ""
171 xlabel = ""
233 xlabel = ""
172 ylabel = ""
234 ylabel = ""
173 xaxisastime = None
235 xaxisastime = None
174 timefmt = None
236 timefmt = None
175 xopt = ""
237 xopt = ""
176 yopt = ""
238 yopt = ""
177 xpos = None
239 xpos = None
178 ypos = None
240 ypos = None
179 szchar = None
241 szchar = None
180 idframe = None
242 idframe = None
181 idplot = None
243 idplot = None
182
244
183 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
245 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
184 self.drvObj = drvObj
246 self.drvObj = drvObj
185 self.idframe = idframe
247 self.idframe = idframe
186 self.idplot = idplot
248 self.idplot = idplot
187 self.xi = xi
249 self.xi = xi
188 self.yi = yi
250 self.yi = yi
189 self.xw = xw
251 self.xw = xw
190 self.yw = yw
252 self.yw = yw
191
253
192 # def setLabels(self):
254 # def setLabels(self):
193 # self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title)
255 # self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title)
194
256
195 def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue):
257 def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue):
196 self.xmin = xmin
258 self.xmin = xmin
197 self.xmax = xmax
259 self.xmax = xmax
198 self.ymin = ymin
260 self.ymin = ymin
199 self.ymax = ymax
261 self.ymax = ymax
200 self.minvalue = minvalue
262 self.minvalue = minvalue
201 self.maxvalue = maxvalue
263 self.maxvalue = maxvalue
202
264
203 self.drvObj.driver.plotBox(self.idframe,
265 self.drvObj.driver.plotBox(self.idframe,
204 self.xpos,
266 self.xpos,
205 self.ypos,
267 self.ypos,
206 self.xmin,
268 self.xmin,
207 self.xmax,
269 self.xmax,
208 self.ymin,
270 self.ymin,
209 self.ymax,
271 self.ymax,
210 self.minvalue,
272 self.minvalue,
211 self.maxvalue,
273 self.maxvalue,
212 self.xopt,
274 self.xopt,
213 self.yopt,
275 self.yopt,
214 self.szchar,
276 self.szchar,
215 self.xaxisastime,
277 self.xaxisastime,
216 self.timefmt)
278 self.timefmt)
217
279
218 self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title)
280 self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title)
219
281
220 def plotBasicLine(self,x, y, color):
282 def plotBasicLine(self,x, y, color):
221 """
283 """
222 Inputs:
284 Inputs:
223 x:
285 x:
224
286
225 y:
287 y:
226
288
227 color:
289 color:
228 """
290 """
229 self.drvObj.driver.basicLine(x, y, self.xmin, self.xmax, self.ymin, self.ymax, color, self.idframe, self.xpos, self.ypos)
291 self.drvObj.driver.basicLine(x, y, self.xmin, self.xmax, self.ymin, self.ymax, color, self.idframe, self.xpos, self.ypos)
230
292
231
293
232 No newline at end of file
294
@@ -1,153 +1,181
1 import plplot
1 import plplot
2 import numpy
2 import numpy
3 import sys
3 import sys
4 import plplot #condicional
4 import plplot #condicional
5
5
6 class Driver:
6 class Driver:
7 def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap):
7 def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
8 if driver == "plplot":
8 if driver == "plplot":
9 self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colorbar, colormap)
9 self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
10 elif driver == "mpl":
10 elif driver == "mpl":
11 self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap)
11 self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
12 else:
12 else:
13 raise ValueError, "The driver: %s is not defined"%driver
13 raise ValueError, "The driver: %s is not defined"%driver
14
14
15 class PlplotDriver:
15 class PlplotDriver:
16
16
17 __isDriverOpen = False
17 __isDriverOpen = False
18 pldriver = None
18 pldriver = None
19
19
20 def __init__(self, idfigure, xw, yw, wintitle, overplot, colorbar, colormap):
20 def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
21
21
22 if idfigure == None:
22 if idfigure == None:
23 raise ValueError, 'idfigure input must be defined'
23 raise ValueError, 'idfigure input must be defined'
24
24
25 self.idfigure = idfigure
25 self.idfigure = idfigure
26 self.xw = xw
26 self.xw = xw
27 self.yw = yw
27 self.yw = yw
28 self.wintitle = wintitle
28 self.wintitle = wintitle
29 self.overplot = overplot
29 self.overplot = overplot
30 self.colorbar = colorbar
31 self.colormap = colormap
30 self.colormap = colormap
32
31 self.colorbar = colorbar
33
34
32
35 def setFigure(self):
33 def setFigure(self):
36 """
34 """
37 previous configuration to open(init) the plplot driver
35 previous configuration to open(init) the plplot driver
38 """
36 """
39 plplot.plsstrm(self.idfigure)
37 plplot.plsstrm(self.idfigure)
40 plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL)
38 plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL)
41 plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw))
39 plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw))
42
40
43
41
44 def openDriver(self, pldriver=None):
42 def openDriver(self, pldriver=None):
45 if pldriver == None:
43 if pldriver == None:
46 if sys.platform == "linux":
44 if sys.platform == "linux":
47 pldriver = "xcairo"
45 pldriver = "xcairo"
48
46
49 if sys.platform == "linux2":
47 if sys.platform == "linux2":
50 pldriver = "xcairo"
48 pldriver = "xcairo"
51
49
52 elif sys.platform == "darwin":
50 elif sys.platform == "darwin":
53 pldriver = "xwin"
51 pldriver = "xwin"
54
52
55 else:
53 else:
56 pldriver = ""
54 pldriver = ""
57
55
58 plplot.plsdev("xwin") #para pruebas
56 plplot.plsdev("xwin") #para pruebas
59 plplot.plscolbg(255,255,255)
57 plplot.plscolbg(255,255,255)
60 plplot.plscol0(1,0,0,0)
58 plplot.plscol0(1,0,0,0)
61 plplot.plinit()
59 plplot.plinit()
62 plplot.plspause(False)
60 plplot.plspause(False)
63
61
64 self.pldriver = pldriver
62 self.pldriver = pldriver
65
63
66 def closeDriver(self):
64 def closeDriver(self):
67 pass
65 pass
68
66
69 def openPage(self):
67 def openPage(self):
70 plplot.plbop()
68 plplot.plbop()
71 plplot.pladv(0)
69 plplot.pladv(0)
72
70
73 def closePage(self):
71 def closePage(self):
74 plplot.pleop()
72 plplot.pleop()
75
73
76 def openFigure(self):
74 def openFigure(self):
77 plplot.plbop()
75 plplot.plbop()
78 plplot.pladv(0)
76 plplot.pladv(0)
79
77
80 def closeFigure(self):
78 def closeFigure(self):
81 plplot.pleop()
79 plplot.pleop()
82
80
83 def setSubPlots(self,nrows, ncolumns):
81 def setSubPlots(self,nrows, ncolumns):
84 plplot.plssub(ncolumns,nrows)
82 plplot.plssub(ncolumns,nrows)
85
83
86 def setPlotLabels(self, xlabel, ylabel, title):
84 def setPlotLabels(self, xlabel, ylabel, title):
87 plplot.pllab(xlabel, ylabel, title)
85 plplot.pllab(xlabel, ylabel, title)
88
86
89 def setFigTitle(self, title,color="black", szchar=0.55):
87 def setFigTitle(self, title,color="black", szchar=0.55):
90 self.setSubPlots(1, 0)
88 self.setSubPlots(1, 0)
91 plplot.pladv(0)
89 plplot.pladv(0)
92 plplot.plvpor(0., 1., 0., 1.)
90 plplot.plvpor(0., 1., 0., 1.)
93
91
94 if color == "black":
92 if color == "black":
95 plplot.plcol0(1)
93 plplot.plcol0(1)
96 if color == "white":
94 if color == "white":
97 plplot.plcol0(15)
95 plplot.plcol0(15)
98
96
99 plplot.plschr(0.0,szchar)
97 plplot.plschr(0.0,szchar)
100 plplot.plmtex("t",-1., 0.5, 0.5, title)
98 plplot.plmtex("t",-1., 0.5, 0.5, title)
101
99
100 def colorbar(self, minvalue, maxvalue, xpos, ypos):
101 # plplot.pladv(id)
102 # plplot.plschr(0.0,szchar-0.05)
103 xmin = 0; xmax = 1
104 ymin = minvalue; ymax = maxvalue
105 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
106 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
107 plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0)
108
109 data = numpy.arange(256)
110 data = numpy.reshape(data, (1,-1))
111
112 plplot.plimage(data,
113 float(xmin),
114 float(xmax),
115 float(ymin),
116 float(ymax),
117 0.,
118 255.,
119 float(xmin),
120 float(xmax),
121 float(ymin),
122 float(ymax))
123
124
102 def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"):
125 def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"):
103 """
126 """
104 xopt, yopt: entradas que no se aplican en MPL
127 xopt, yopt: entradas que no se aplican en MPL
105 """
128 """
106 plplot.pladv(id)
129 plplot.pladv(id)
107 plplot.plschr(0.0,szchar-0.05)
130 plplot.plschr(0.0,szchar-0.05)
108 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
131 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
109 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
132 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
110 if xaxisastime:
133 if xaxisastime:
111 plplot.pltimefmt(timefmt)
134 plplot.pltimefmt(timefmt)
112 timedelta = (xmax - xmin + 1)/8.
135 timedelta = (xmax - xmin + 1)/8.
113 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
136 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
114 else:
137 else:
115 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
138 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
116
139
117 def refresh(self):
140 def refresh(self):
118 plplot.plflush()
141 plplot.plflush()
119
142
120 def basicLine(self, x, y, xmin, xmax, ymin, ymax, color, id, xpos, ypos):
143 def basicLine(self, x, y, xmin, xmax, ymin, ymax, color, id, xpos, ypos):
121
144
122 """
145 """
123 Inputs:
146 Inputs:
124 x: datos en el eje x
147 x: datos en el eje x
125
148
126 y: datos en el eje y
149 y: datos en el eje y
127
150
128 xmin, xmax: intervalo de datos en el eje x
151 xmin, xmax: intervalo de datos en el eje x
129
152
130 ymin, ymax: intervalo de datos en el eje y
153 ymin, ymax: intervalo de datos en el eje y
131
154
132 color: color de la linea a dibujarse
155 color: color de la linea a dibujarse
133
156
134 id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada
157 id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada
135 plot esta definido por xpos, ypos.
158 plot esta definido por xpos, ypos.
136
159
137 xpos,ypos: coordenadas que indican la posicion del plot en el frame
160 xpos,ypos: coordenadas que indican la posicion del plot en el frame
138
161
139 """
162 """
140
163
141 plplot.pladv(id)
164 plplot.pladv(id)
142 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
165 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
143 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
166 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
144
167
145 if color == "blue":
168 if color == "blue":
146 colline = 9
169 colline = 9
147 if color == "green":
170 if color == "green":
148 colline = 3
171 colline = 3
149
172
150 plplot.plcol0(colline)
173 plplot.plcol0(colline)
151 plplot.plline(x, y)
174 plplot.plline(x, y)
152 plplot.plcol0(1)
175 plplot.plcol0(1)
153 plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0)
176 plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0)
177
178
179 class MplDriver:
180 def __init__(self):
181 pass No newline at end of file
@@ -1,106 +1,298
1 import numpy
1 import nump
2 import datetime
3 import time
2 from schainPlot import *
4 from schainPlot import *
3 #from schainPlotLib import Driver
5 #from schainPlotLib import Driver
4
6
7
8 class RTIFigure:
9 overplot = 1
10 xw = 700
11 yw = 650
12 showprofile = False
13 starttime = None
14 endtime = None
15 minrange = None
16 maxrange = None
17 minvalue = None
18 maxvalue = None
19
20
21 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
22 self.idfigure = idfigure
23 self.nframes = nframes
24 self.wintitle = wintitle
25 self.colormap = colormap
26 self.colorbar = colorbar
27 self.showprofile = showprofile
28 self.driver = driver
29 self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar)
30 self.drvObj.driver.setFigure()
31
32 def getSubplots(self):
33 nrows = self.nframes
34 ncolumns = 1
35 return nrows, ncolumns
36
37 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax):
38
39 if minvalue == None: minvalue = numpy.min(data)
40 if maxvalue == None: maxvalue = numpy.max(data)
41
42 utcdatetime = datetime.datetime.utcfromtimestamp(x)
43 startdatetime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin.hour,xmin.minute, xmin.second)
44 enddatetime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax.hour,xmax.minute, xmax.second)
45 deltatime = 0
46 if timezone == "lt": deltatime = time.timezone
47 startTimeInSecs = time.mktime(startdatetime.timetuple()) - deltatime
48 endTimeInSecs = time.mktime(enddatetime.timetuple()) - deltatime
49 self.starttime = xmin
50 self.endtime = xmax
51 self.xmin = startTimeInSecs
52 self.xmax = self.xmin + interval
53
54
55
56 if ymin == None: ymin = numpy.min(y)
57 if ymin == None: ymax = numpy.max(y)
58
59 starttime = None
60 endtime = None
61 minrange = None
62 maxrange = None
63 minvalue = None
64 maxvalue = None
65
66
67 self.xmin = s
68 self.xmax = self.starttime + timeinterval
69 self.ymin = minrange
70 self.ymax = maxrange
71 self.minvalue = minvalue
72 self.maxvalue = maxvalue
73
74
75 def createFrames(self):
76 for frame in range(self.nframes):
77 frameObj = ScopeFrame(self.drvObj,frame + 1)
78 self.frameObjList.append(frameObj)
79
80 class RTIFrame(Frame):
81 def __init__(self,drvObj,idframe,colorbar,showProfile):
82 self.drvObj = drvObj
83 self.idframe = idframe
84 self.nplots = 1
85
86 if showProfile:
87 self.nplots += 1
88
89 self.colorbar = colorbar
90 self.showprofile = showprofile
91 self.createPlots()
92
93 def createPlots(self):
94 plotObjList = []
95
96 idplot = 0
97 xi, yi, xw, yw = self.getScreenPos(idplot)
98 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw)
99 plotObjList.append(plotObj)
100
101 if self.showprofile:
102 idplot = 1
103 xi, yi, xw, yw = self.getScreenPos(idplot)
104 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw)
105 plotObjList.append(plotObj)
106
107 self.plotObjList = plotObjList
108
109 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
110 xi = 0.07
111
112 if self.showprofile:
113 xw = 0.65
114
115 else:
116 xw = 0.9
117
118 if self.colorbar:
119 xw = xw - 0.06
120
121 yi = 0.20; yw = 0.75
122
123 return xi, yi, xw, yw
124
125 def getScreenPosGraph1(self):
126 if self.colorbar:
127 xi = 0.65 + 0.05
128 else:
129 xi = 0.9 + 0.05
130
131 xw = xi + 0.2
132
133 yi = 0.2; yw = 0.75
134
135 return xi, yi, xw, yw
136
137
138 class RTIPlot:
139 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw):
140 self.drvObj = drvObj
141 self.idframe = idframe
142 self.idplot = idplot
143 self.xi = xi
144 self.yi = yi
145 self.xw = xw
146 self.yw = yw
147
148 if self.colorbar:
149 cbxi = xw + 0.03
150 cbxw = cbxi + 0.03
151 cbyi = yi
152 cbyw = yw
153 self.cbxpos = [cbxi,cbxw]
154 self.cbypos = [cbyi,cbyw]
155
156 self.xpos = [self.xi,self.xw]
157 self.ypos = [self.yi,self.yw]
158 self.xaxisastime = True
159 self.timefmt = "%H:%M"
160 self.xopt = "bcnstd"
161 self.yopt = "bcnstv"
162
163 self.szchar = 1.0
164 self.title = "Channel %d"%self.idframe
165 self.xlabel = "x-axis"
166 self.ylabel = "y-axis"
167
168 def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue):
169 self.xmin = xmin
170 self.xmax = xmax
171 self.ymin = ymin
172 self.ymax = ymax
173 self.minvalue = minvalue
174 self.maxvalue = maxvalue
175
176 self.drvObj.driver.plotBox(self.idframe,
177 self.xpos,
178 self.ypos,
179 self.xmin,
180 self.xmax,
181 self.ymin,
182 self.ymax,
183 self.minvalue,
184 self.maxvalue,
185 self.xopt,
186 self.yopt,
187 self.szchar,
188 self.xaxisastime,
189 self.timefmt)
190
191 self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title)
192
193 if self.colorbar:
194 self.drvObj.driver.colorbar(minvalue, maxvalue, self.cbxpos,self.cbypos)
195
196
197 def plot(self):
198 pass
199
200
201
202
203
5 class ScopeFigure(Figure):
204 class ScopeFigure(Figure):
6 overplot = 0
205 overplot = 0
7 xw = 700
206 xw = 700
8 yw = 650
207 yw = 650
9 colorbar = None
208 colorbar = None
10 # frameObjList = []
11
209
12 def __init__(self,idfigure,nframes,wintitle,driver):
210 def __init__(self,idfigure,nframes,wintitle,driver):
13 colormap = None
211 colormap = None
14 colorbar = False
212 colorbar = False
15 addGraph = 0
16 args=(addGraph, addGraph)
17
18
213
19 self.idfigure = idfigure
214 self.idfigure = idfigure
20 self.nframes = nframes
215 self.nframes = nframes
21 self.wintitle = wintitle
216 self.wintitle = wintitle
22 # self.xw =
217
23 # self.yw =
24 # self.overplot =
25 self.driver = driver
26 self.colorbar = colorbar
27 self.colormap = colormap
218 self.colormap = colormap
28
219 self.colorbar = colorbar
29 self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colorbar, self.colormap)
220 self.driver = driver
221 self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar)
30 self.drvObj.driver.setFigure()
222 self.drvObj.driver.setFigure()
31
223
32 # Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args)
224 # Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args)
33
225
34 def getSubplots(self):
226 def getSubplots(self):
35 nrows = self.nframes
227 nrows = self.nframes
36 ncolumns = 1
228 ncolumns = 1
37 return nrows, ncolumns
229 return nrows, ncolumns
38
230
39 def createFrames(self):
231 def createFrames(self):
40 for frame in range(self.nframes):
232 for frame in range(self.nframes):
41 frameObj = ScopeFrame(self.drvObj,frame + 1)
233 frameObj = ScopeFrame(self.drvObj,frame + 1)
42 self.frameObjList.append(frameObj)
234 self.frameObjList.append(frameObj)
43
235
44
236
45 class ScopeFrame(Frame):
237 class ScopeFrame(Frame):
46 # plotObjList = []
238 # plotObjList = []
47 xlabel = ""
239 xlabel = ""
48 ylabel = ""
240 ylabel = ""
49 title = ""
241 title = ""
50 def __init__(self,drvObj,idframe):
242 def __init__(self,drvObj,idframe):
51 self.drvObj = drvObj
243 self.drvObj = drvObj
52 self.idframe = idframe
244 self.idframe = idframe
53 self.nplots = 1 #nplots/frame
245 self.nplots = 1 #nplots/frame
54 self.createPlots()
246 self.createPlots()
55 # Frame.__init__(self, drvObj, idframe)
247 # Frame.__init__(self, drvObj, idframe)
56
248
57 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
249 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
58 xi = 0.07; xw = 0.9
250 xi = 0.07; xw = 0.9
59 yi = 0.20; yw = 0.75
251 yi = 0.20; yw = 0.75
60 return xi,yi,xw,yw
252 return xi,yi,xw,yw
61
253
62 def createPlots(self):
254 def createPlots(self):
63 plotObjList = []
255 plotObjList = []
64 for idplot in range(self.nplots):
256 for idplot in range(self.nplots):
65 xi, yi, xw, yw = self.getScreenPos(idplot)
257 xi, yi, xw, yw = self.getScreenPos(idplot)
66 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw)
258 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw)
67 plotObjList.append(plotObj)
259 plotObjList.append(plotObj)
68 self.plotObjList = plotObjList
260 self.plotObjList = plotObjList
69 # self.plotObjList.append(plotObj)
261 # self.plotObjList.append(plotObj)
70
262
71 def plot(self, x, y, z=None):
263 def plot(self, x, y, z=None):
72 for plotObj in self.plotObjList:
264 for plotObj in self.plotObjList:
73 plotObj.plot(x, y)
265 plotObj.plot(x, y)
74
266
75
267
76 class Plot1D(Plot):
268 class Plot1D(Plot):
77
269
78 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
270 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
79 self.drvObj = drvObj
271 self.drvObj = drvObj
80 self.idframe = idframe
272 self.idframe = idframe
81 self.idplot = idplot
273 self.idplot = idplot
82 self.xi = xi
274 self.xi = xi
83 self.yi = yi
275 self.yi = yi
84 self.xw = xw
276 self.xw = xw
85 self.yw = yw
277 self.yw = yw
86 self.xpos = [self.xi,self.xw]
278 self.xpos = [self.xi,self.xw]
87 self.ypos = [self.yi,self.yw]
279 self.ypos = [self.yi,self.yw]
88 self.xaxisastime = False
280 self.xaxisastime = False
89 self.timefmt = None
281 self.timefmt = None
90 self.xopt = "bcnst"
282 self.xopt = "bcnst"
91 self.yopt = "bcnstv"
283 self.yopt = "bcnstv"
92 self.szchar = 1.0
284 self.szchar = 1.0
93 self.title = "Channel %d"%self.idframe
285 self.title = "Channel %d"%self.idframe
94 self.xlabel = "x-axis"
286 self.xlabel = "x-axis"
95 self.ylabel = "y-axis"
287 self.ylabel = "y-axis"
96
288
97
289
98 def plot(self,x,y):
290 def plot(self,x,y):
99 if y.dtype == "complex128":
291 if y.dtype == "complex128":
100 color="blue"
292 color="blue"
101 self.plotBasicLine(x, y.real, color)
293 self.plotBasicLine(x, y.real, color)
102 color="red"
294 color="red"
103 self.plotBasicLine(x, y.imag, color)
295 self.plotBasicLine(x, y.imag, color)
104 else:
296 else:
105 color="blue"
297 color="blue"
106 self.plotBasicLine(x, y, color)
298 self.plotBasicLine(x, y, color)
General Comments 0
You need to be logged in to leave comments. Login now