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