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