@@ -1,4 +1,5 | |||||
1 | import numpy |
|
1 | import numpy | |
|
2 | import datetime | |||
2 | from schainPlotLib import Driver |
|
3 | from schainPlotLib import Driver | |
3 |
|
4 | |||
4 | class Figure: |
|
5 | class Figure: | |
@@ -14,10 +15,15 class Figure: | |||||
14 | overplot = None |
|
15 | overplot = None | |
15 | xmin = None |
|
16 | xmin = None | |
16 | xmax = None |
|
17 | xmax = None | |
|
18 | ymin = None | |||
|
19 | ymax = None | |||
17 | minvalue = None |
|
20 | minvalue = None | |
18 | maxvalue = None |
|
21 | maxvalue = None | |
|
22 | deltax = None | |||
|
23 | deltay = None | |||
19 | frameObjList = [] |
|
24 | frameObjList = [] | |
20 | figtitle = "" |
|
25 | figuretitle = "" | |
|
26 | xrangestep = None | |||
21 |
|
27 | |||
22 | def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colorbar= True, colormap=None, *args): |
|
28 | def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colorbar= True, colormap=None, *args): | |
23 | self.idfigure = idfigure |
|
29 | self.idfigure = idfigure | |
@@ -35,6 +41,7 class Figure: | |||||
35 | self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap) |
|
41 | self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap) | |
36 |
|
42 | |||
37 | self.drvObj.driver.setFigure() |
|
43 | self.drvObj.driver.setFigure() | |
|
44 | self.drvObj.driver.setColormap(colormap) | |||
38 |
|
45 | |||
39 |
|
46 | |||
40 | def __openDriver(self): |
|
47 | def __openDriver(self): | |
@@ -49,12 +56,20 class Figure: | |||||
49 | def __initFigure(self): |
|
56 | def __initFigure(self): | |
50 | nrows, ncolumns = self.getSubplots() |
|
57 | nrows, ncolumns = self.getSubplots() | |
51 | self.drvObj.driver.openFigure() |
|
58 | self.drvObj.driver.openFigure() | |
52 | self.drvObj.driver.setFigTitle(self.figtitle) |
|
59 | self.drvObj.driver.setFigTitle(self.figuretitle) | |
53 | self.drvObj.driver.setSubPlots(nrows, ncolumns) |
|
60 | self.drvObj.driver.setSubPlots(nrows, ncolumns) | |
54 |
|
61 | |||
55 | def __isOutOfXRange(self,x): |
|
62 | def __isOutOfXRange(self,x): | |
|
63 | ||||
|
64 | if ((x>=self.xmin) and (x<self.xmax)): | |||
|
65 | return 0 | |||
|
66 | ||||
56 | return 1 |
|
67 | return 1 | |
57 |
|
68 | |||
|
69 | def changeXRange(self,x): | |||
|
70 | ||||
|
71 | pass | |||
|
72 | ||||
58 | def __refresh(self): |
|
73 | def __refresh(self): | |
59 | self.drvObj.driver.refresh() |
|
74 | self.drvObj.driver.refresh() | |
60 |
|
75 | |||
@@ -101,6 +116,7 class Figure: | |||||
101 | self.driverObj.closePage() |
|
116 | self.driverObj.closePage() | |
102 | self.__isFigureOpen = False |
|
117 | self.__isFigureOpen = False | |
103 |
|
118 | |||
|
119 | ||||
104 | self.__initFigure() |
|
120 | self.__initFigure() | |
105 |
|
121 | |||
106 | for channel in channelList: |
|
122 | for channel in channelList: | |
@@ -135,32 +151,20 class Figure: | |||||
135 |
|
151 | |||
136 |
|
152 | |||
137 | def plotPcolor(self,data, |
|
153 | def plotPcolor(self,data, | |
138 |
|
|
154 | x=None, | |
139 |
|
|
155 | y=None, | |
140 |
|
|
156 | channelList=None, | |
141 |
|
|
157 | xmin=None, | |
142 |
|
|
158 | xmax=None, | |
143 |
|
|
159 | ymin=None, | |
144 |
|
|
160 | ymax=None, | |
145 |
|
|
161 | minvalue=None, | |
146 |
|
|
162 | maxvalue=None, | |
147 |
|
|
163 | figuretitle=None, | |
148 |
|
|
164 | xrangestep=None, | |
149 |
|
|
165 | save=False, | |
150 |
|
|
166 | gpath='./'): | |
151 | # data, |
|
167 | ||
152 | # currenttime, |
|
|||
153 | # range, |
|
|||
154 | # starttime, |
|
|||
155 | # endtime, |
|
|||
156 | # minrange, |
|
|||
157 | # maxrange, |
|
|||
158 | # minvalue, |
|
|||
159 | # maxvalue, |
|
|||
160 | # figuretitle, |
|
|||
161 | # interval, |
|
|||
162 | # save, |
|
|||
163 | # gpath): |
|
|||
164 |
|
168 | |||
165 | if figuretitle == None: |
|
169 | if figuretitle == None: | |
166 | self.figuretitle = "" |
|
170 | self.figuretitle = "" | |
@@ -175,31 +179,55 class Figure: | |||||
175 |
|
179 | |||
176 | if not(self.__isConfig): |
|
180 | if not(self.__isConfig): | |
177 |
|
181 | |||
178 |
self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue, |
|
182 | self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep) | |
179 |
|
||||
180 |
|
183 | |||
181 |
|
||||
182 | # if self.xmin == None: self.xmin = numpy.min(x) |
|
|||
183 | # if self.xmax == None: self.xmax = numpy.max(x) |
|
|||
184 |
|
||||
185 |
|
||||
186 | self.createFrames() |
|
184 | self.createFrames() | |
187 | self.__isConfig = True |
|
185 | self.__isConfig = True | |
188 |
|
186 | |||
189 |
if |
|
187 | if (self.__isOutOfXRange(x)): | |
190 | self.__changeXRange(x) |
|
|||
191 |
|
188 | |||
192 |
if self. |
|
189 | if not(self.changeXRange(x)): | |
193 | self.driverObj.closePage() |
|
190 | return 0 | |
194 | self.__isFigureOpen = False |
|
191 | ||
|
192 | self.__isFigureOpen = False | |||
|
193 | ||||
|
194 | # if self.__isFigureOpen: | |||
|
195 | # self.driverObj.closePage() | |||
|
196 | # self.__isFigureOpen = False | |||
195 |
|
197 | |||
|
198 | if not(self.__isFigureOpen): | |||
|
199 | ||||
|
200 | ||||
196 | self.__initFigure() |
|
201 | self.__initFigure() | |
|
202 | self.__isFigureOpen = True | |||
|
203 | ||||
|
204 | for channel in channelList: | |||
|
205 | frameObj = self.frameObjList[channel] | |||
|
206 | frameObj.init(xmin=self.xmin, | |||
|
207 | xmax=self.xmax, | |||
|
208 | ymin=self.ymin, | |||
|
209 | ymax=self.ymax, | |||
|
210 | minvalue=self.minvalue, | |||
|
211 | maxvalue=self.maxvalue, | |||
|
212 | deltax=self.deltax, | |||
|
213 | deltay=self.deltay) | |||
|
214 | ||||
|
215 | for channel in channelList: | |||
|
216 | dataCh = data[channel,:] | |||
|
217 | frameObj = self.frameObjList[channel] | |||
|
218 | # frameObj.clearData() | |||
|
219 | frameObj.plot(x, y, dataCh) | |||
|
220 | ||||
|
221 | # frameObj.refresh() | |||
|
222 | self.__refresh() | |||
|
223 | ||||
197 |
|
224 | |||
198 |
|
225 | |||
199 | class Frame: |
|
226 | class Frame: | |
200 | nplots = None |
|
227 | nplots = None | |
201 | plotObjList = [] |
|
228 | plotObjList = [] | |
202 | title = "" |
|
229 | title = "" | |
|
230 | ||||
203 | def __init__(self,drvObj, idframe): |
|
231 | def __init__(self,drvObj, idframe): | |
204 | self.drvObj = drvObj |
|
232 | self.drvObj = drvObj | |
205 | self.idframe = idframe |
|
233 | self.idframe = idframe | |
@@ -211,22 +239,25 class Frame: | |||||
211 | def getScreenPosMainPlot(self): |
|
239 | def getScreenPosMainPlot(self): | |
212 | raise ValueError, "No implemented" |
|
240 | raise ValueError, "No implemented" | |
213 |
|
241 | |||
|
242 | def getScreenPosGraph1(self): | |||
|
243 | raise ValueError, "No implemented" | |||
|
244 | ||||
214 | def getScreenPos(self, nplot): |
|
245 | def getScreenPos(self, nplot): | |
215 |
|
246 | |||
216 | if nplot == 0: |
|
247 | if nplot == 0: | |
217 | xi, yi, xw, yw = self.getScreenPosMainPlot() |
|
248 | xi, yi, xw, yw = self.getScreenPosMainPlot() | |
|
249 | ||||
|
250 | if nplot == 1: | |||
|
251 | xi, yi, xw, yw = self.getScreenPosGraph1() | |||
|
252 | ||||
218 | return xi, yi, xw, yw |
|
253 | return xi, yi, xw, yw | |
219 |
|
254 | |||
220 |
|
255 | |||
221 | def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue): |
|
256 | def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None): | |
222 |
|
257 | |||
223 | for plotObj in self.plotObjList: |
|
258 | for plotObj in self.plotObjList: | |
224 | plotObj.plotBox(xmin, xmax, ymin, ymax, minvalue, maxvalue) |
|
259 | plotObj.plotBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay) | |
225 | # plotObj.setLabels() # ? evaluar si conviene colocarlo dentro del plotbox |
|
260 | ||
226 |
|
||||
227 | def refresh(self): |
|
|||
228 | for plotObj in self.plotObjList: |
|
|||
229 | plotObj.refresh() |
|
|||
230 |
|
261 | |||
231 | class Plot: |
|
262 | class Plot: | |
232 | title = "" |
|
263 | title = "" | |
@@ -251,9 +282,6 class Plot: | |||||
251 | self.xw = xw |
|
282 | self.xw = xw | |
252 | self.yw = yw |
|
283 | self.yw = yw | |
253 |
|
284 | |||
254 | # def setLabels(self): |
|
|||
255 | # self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) |
|
|||
256 |
|
||||
257 | def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue): |
|
285 | def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue): | |
258 | self.xmin = xmin |
|
286 | self.xmin = xmin | |
259 | self.xmax = xmax |
|
287 | self.xmax = xmax | |
@@ -278,6 +306,26 class Plot: | |||||
278 | self.timefmt) |
|
306 | self.timefmt) | |
279 |
|
307 | |||
280 | self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) |
|
308 | self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) | |
|
309 | ||||
|
310 | def plotPcolor(self, x, y, z, deltax, deltay, getGrid): | |||
|
311 | ||||
|
312 | self.drvObj.driver.pcolor(self.idframe, | |||
|
313 | self.xpos, | |||
|
314 | self.ypos, | |||
|
315 | z, | |||
|
316 | x, | |||
|
317 | y, | |||
|
318 | self.xmin, | |||
|
319 | self.xmax, | |||
|
320 | self.ymin, | |||
|
321 | self.ymax, | |||
|
322 | self.minvalue, | |||
|
323 | self.maxvalue, | |||
|
324 | deltax, | |||
|
325 | deltay, | |||
|
326 | getGrid, | |||
|
327 | self.xaxisastime, | |||
|
328 | self.timefmt) | |||
281 |
|
329 | |||
282 | def plotBasicLine(self,x, y, color): |
|
330 | def plotBasicLine(self,x, y, color): | |
283 | """ |
|
331 | """ | |
@@ -288,7 +336,5 class Plot: | |||||
288 |
|
336 | |||
289 | color: |
|
337 | color: | |
290 | """ |
|
338 | """ | |
291 |
self.drvObj.driver.basicLine(x, y, self.xmin, self.xmax, self.ymin, self.ymax, color |
|
339 | self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color) | |
292 |
|
||||
293 |
|
||||
294 | No newline at end of file |
|
340 |
@@ -16,7 +16,8 class PlplotDriver: | |||||
16 |
|
16 | |||
17 | __isDriverOpen = False |
|
17 | __isDriverOpen = False | |
18 | pldriver = None |
|
18 | pldriver = None | |
19 |
|
19 | __xg = None | ||
|
20 | __yg = None | |||
20 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): |
|
21 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): | |
21 |
|
22 | |||
22 | if idfigure == None: |
|
23 | if idfigure == None: | |
@@ -97,7 +98,7 class PlplotDriver: | |||||
97 | plplot.plschr(0.0,szchar) |
|
98 | plplot.plschr(0.0,szchar) | |
98 | plplot.plmtex("t",-1., 0.5, 0.5, title) |
|
99 | plplot.plmtex("t",-1., 0.5, 0.5, title) | |
99 |
|
100 | |||
100 |
def |
|
101 | def plotColorbar(self, minvalue, maxvalue, xpos, ypos): | |
101 | # plplot.pladv(id) |
|
102 | # plplot.pladv(id) | |
102 | # plplot.plschr(0.0,szchar-0.05) |
|
103 | # plplot.plschr(0.0,szchar-0.05) | |
103 | xmin = 0; xmax = 1 |
|
104 | xmin = 0; xmax = 1 | |
@@ -120,7 +121,63 class PlplotDriver: | |||||
120 | float(xmax), |
|
121 | float(xmax), | |
121 | float(ymin), |
|
122 | float(ymin), | |
122 | float(ymax)) |
|
123 | float(ymax)) | |
|
124 | ||||
|
125 | ||||
|
126 | def __getGrid(self, x, y, deltax=None, deltay=None): | |||
|
127 | ||||
|
128 | if not(len(x)>0 and len(y)>0): | |||
|
129 | raise ValueError, "x axis and y axis are empty" | |||
|
130 | ||||
|
131 | if deltax == None: deltax = x[-1] - x[-2] | |||
|
132 | if deltay == None: deltay = y[-1] - y[-2] | |||
|
133 | ||||
|
134 | x1 = numpy.append(x, x[-1] + deltax) | |||
|
135 | y1 = numpy.append(y, y[-1] + deltay) | |||
|
136 | ||||
|
137 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |||
|
138 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |||
|
139 | ||||
|
140 | return xg, yg | |||
|
141 | ||||
|
142 | ||||
|
143 | def pcolor(self, id, xpos, ypos, data, x, y, xmin, xmax, ymin, ymax, zmin, zmax, deltax=None, deltay=None, getGrid=True, xaxisastime = False, timefmt="%H:%M"): | |||
|
144 | ||||
|
145 | plplot.pladv(id) | |||
|
146 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |||
|
147 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) | |||
123 |
|
148 | |||
|
149 | if xaxisastime: | |||
|
150 | timedelta = (xmax - xmin + 1)/8. | |||
|
151 | ||||
|
152 | if getGrid: | |||
|
153 | self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay) | |||
|
154 | ||||
|
155 | xmin = x[0] | |||
|
156 | xmax = xmin + deltax | |||
|
157 | ||||
|
158 | plplot.plimagefr(data, | |||
|
159 | float(xmin), | |||
|
160 | float(xmax), | |||
|
161 | float(ymin), | |||
|
162 | float(ymax), | |||
|
163 | 0., | |||
|
164 | 0., | |||
|
165 | float(zmin), | |||
|
166 | float(zmax), | |||
|
167 | plplot.pltr2, | |||
|
168 | self.__xg, | |||
|
169 | self.__yg) | |||
|
170 | ||||
|
171 | if xaxisastime: | |||
|
172 | plplot.pltimefmt(timefmt) | |||
|
173 | xopt = "bcstd" | |||
|
174 | yopt = "bcst" | |||
|
175 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) | |||
|
176 | else: | |||
|
177 | xopt = "bcst" | |||
|
178 | yopt = "bcst" | |||
|
179 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | |||
|
180 | ||||
124 |
|
181 | |||
125 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): |
|
182 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): | |
126 | """ |
|
183 | """ | |
@@ -140,7 +197,7 class PlplotDriver: | |||||
140 | def refresh(self): |
|
197 | def refresh(self): | |
141 | plplot.plflush() |
|
198 | plplot.plflush() | |
142 |
|
199 | |||
143 |
def basicLine(self, x, y, xmin, xmax, ymin, ymax, color |
|
200 | def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): | |
144 |
|
201 | |||
145 | """ |
|
202 | """ | |
146 | Inputs: |
|
203 | Inputs: | |
@@ -174,6 +231,180 class PlplotDriver: | |||||
174 | plplot.plline(x, y) |
|
231 | plplot.plline(x, y) | |
175 | plplot.plcol0(1) |
|
232 | plplot.plcol0(1) | |
176 | plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) |
|
233 | plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) | |
|
234 | ||||
|
235 | def setColormap(self, colormap="gray"): | |||
|
236 | ||||
|
237 | if colormap == None: | |||
|
238 | return | |||
|
239 | ||||
|
240 | ncolor = None | |||
|
241 | rgb_lvl = None | |||
|
242 | ||||
|
243 | # Routine for defining a specific color map 1 in HLS space. | |||
|
244 | # if gray is true, use basic grayscale variation from half-dark to light. | |||
|
245 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |||
|
246 | ||||
|
247 | # Independent variable of control points. | |||
|
248 | i = numpy.array((0., 1.)) | |||
|
249 | if colormap=="gray": | |||
|
250 | ncolor = 256 | |||
|
251 | # Hue for control points. Doesn't matter since saturation is zero. | |||
|
252 | h = numpy.array((0., 0.)) | |||
|
253 | # Lightness ranging from half-dark (for interest) to light. | |||
|
254 | l = numpy.array((0.5, 1.)) | |||
|
255 | # Gray scale has zero saturation | |||
|
256 | s = numpy.array((0., 0.)) | |||
|
257 | ||||
|
258 | # number of cmap1 colours is 256 in this case. | |||
|
259 | plplot.plscmap1n(ncolor) | |||
|
260 | # Interpolate between control points to set up cmap1. | |||
|
261 | plplot.plscmap1l(0, i, h, l, s) | |||
|
262 | ||||
|
263 | return None | |||
|
264 | ||||
|
265 | if colormap == 'jet': | |||
|
266 | ncolor = 256 | |||
|
267 | pos = numpy.zeros((ncolor)) | |||
|
268 | r = numpy.zeros((ncolor)) | |||
|
269 | g = numpy.zeros((ncolor)) | |||
|
270 | b = numpy.zeros((ncolor)) | |||
|
271 | ||||
|
272 | for i in range(ncolor): | |||
|
273 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 | |||
|
274 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 | |||
|
275 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 | |||
|
276 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 | |||
|
277 | ||||
|
278 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 | |||
|
279 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 | |||
|
280 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 | |||
|
281 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 | |||
|
282 | else: gf = 0.0 | |||
|
283 | ||||
|
284 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 | |||
|
285 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 | |||
|
286 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 | |||
|
287 | else: bf = 0 | |||
|
288 | ||||
|
289 | r[i] = rf | |||
|
290 | g[i] = gf | |||
|
291 | b[i] = bf | |||
|
292 | ||||
|
293 | pos[i] = float(i)/float(ncolor-1) | |||
|
294 | ||||
|
295 | ||||
|
296 | plplot.plscmap1n(ncolor) | |||
|
297 | plplot.plscmap1l(1, pos, r, g, b) | |||
|
298 | ||||
|
299 | ||||
|
300 | ||||
|
301 | if colormap=="br_green": | |||
|
302 | ncolor = 256 | |||
|
303 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
304 | h = numpy.array((240., 0.)) | |||
|
305 | # Lightness and saturation are constant (values taken from C example). | |||
|
306 | l = numpy.array((0.6, 0.6)) | |||
|
307 | s = numpy.array((0.8, 0.8)) | |||
|
308 | ||||
|
309 | # number of cmap1 colours is 256 in this case. | |||
|
310 | plplot.plscmap1n(ncolor) | |||
|
311 | # Interpolate between control points to set up cmap1. | |||
|
312 | plplot.plscmap1l(0, i, h, l, s) | |||
|
313 | ||||
|
314 | return None | |||
|
315 | ||||
|
316 | if colormap=="tricolor": | |||
|
317 | ncolor = 3 | |||
|
318 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
319 | h = numpy.array((240., 0.)) | |||
|
320 | # Lightness and saturation are constant (values taken from C example). | |||
|
321 | l = numpy.array((0.6, 0.6)) | |||
|
322 | s = numpy.array((0.8, 0.8)) | |||
|
323 | ||||
|
324 | # number of cmap1 colours is 256 in this case. | |||
|
325 | plplot.plscmap1n(ncolor) | |||
|
326 | # Interpolate between control points to set up cmap1. | |||
|
327 | plplot.plscmap1l(0, i, h, l, s) | |||
|
328 | ||||
|
329 | return None | |||
|
330 | ||||
|
331 | if colormap == 'rgb' or colormap == 'rgb666': | |||
|
332 | ||||
|
333 | color_sz = 6 | |||
|
334 | ncolor = color_sz*color_sz*color_sz | |||
|
335 | pos = numpy.zeros((ncolor)) | |||
|
336 | r = numpy.zeros((ncolor)) | |||
|
337 | g = numpy.zeros((ncolor)) | |||
|
338 | b = numpy.zeros((ncolor)) | |||
|
339 | ind = 0 | |||
|
340 | for ri in range(color_sz): | |||
|
341 | for gi in range(color_sz): | |||
|
342 | for bi in range(color_sz): | |||
|
343 | r[ind] = ri/(color_sz-1.0) | |||
|
344 | g[ind] = gi/(color_sz-1.0) | |||
|
345 | b[ind] = bi/(color_sz-1.0) | |||
|
346 | pos[ind] = ind/(ncolor-1.0) | |||
|
347 | ind += 1 | |||
|
348 | rgb_lvl = [6,6,6] #Levels for RGB colors | |||
|
349 | ||||
|
350 | if colormap == 'rgb676': | |||
|
351 | ncolor = 6*7*6 | |||
|
352 | pos = numpy.zeros((ncolor)) | |||
|
353 | r = numpy.zeros((ncolor)) | |||
|
354 | g = numpy.zeros((ncolor)) | |||
|
355 | b = numpy.zeros((ncolor)) | |||
|
356 | ind = 0 | |||
|
357 | for ri in range(8): | |||
|
358 | for gi in range(8): | |||
|
359 | for bi in range(4): | |||
|
360 | r[ind] = ri/(6-1.0) | |||
|
361 | g[ind] = gi/(7-1.0) | |||
|
362 | b[ind] = bi/(6-1.0) | |||
|
363 | pos[ind] = ind/(ncolor-1.0) | |||
|
364 | ind += 1 | |||
|
365 | rgb_lvl = [6,7,6] #Levels for RGB colors | |||
|
366 | ||||
|
367 | if colormap == 'rgb685': | |||
|
368 | ncolor = 6*8*5 | |||
|
369 | pos = numpy.zeros((ncolor)) | |||
|
370 | r = numpy.zeros((ncolor)) | |||
|
371 | g = numpy.zeros((ncolor)) | |||
|
372 | b = numpy.zeros((ncolor)) | |||
|
373 | ind = 0 | |||
|
374 | for ri in range(8): | |||
|
375 | for gi in range(8): | |||
|
376 | for bi in range(4): | |||
|
377 | r[ind] = ri/(6-1.0) | |||
|
378 | g[ind] = gi/(8-1.0) | |||
|
379 | b[ind] = bi/(5-1.0) | |||
|
380 | pos[ind] = ind/(ncolor-1.0) | |||
|
381 | ind += 1 | |||
|
382 | rgb_lvl = [6,8,5] #Levels for RGB colors | |||
|
383 | ||||
|
384 | if colormap == 'rgb884': | |||
|
385 | ncolor = 8*8*4 | |||
|
386 | pos = numpy.zeros((ncolor)) | |||
|
387 | r = numpy.zeros((ncolor)) | |||
|
388 | g = numpy.zeros((ncolor)) | |||
|
389 | b = numpy.zeros((ncolor)) | |||
|
390 | ind = 0 | |||
|
391 | for ri in range(8): | |||
|
392 | for gi in range(8): | |||
|
393 | for bi in range(4): | |||
|
394 | r[ind] = ri/(8-1.0) | |||
|
395 | g[ind] = gi/(8-1.0) | |||
|
396 | b[ind] = bi/(4-1.0) | |||
|
397 | pos[ind] = ind/(ncolor-1.0) | |||
|
398 | ind += 1 | |||
|
399 | rgb_lvl = [8,8,4] #Levels for RGB colors | |||
|
400 | ||||
|
401 | if ncolor == None: | |||
|
402 | raise ValueError, "The colormap selected is not valid" | |||
|
403 | ||||
|
404 | plplot.plscmap1n(ncolor) | |||
|
405 | plplot.plscmap1l(1, pos, r, g, b) | |||
|
406 | ||||
|
407 | return rgb_lvl | |||
177 |
|
408 | |||
178 |
|
409 | |||
179 | class MplDriver: |
|
410 | class MplDriver: |
@@ -1,11 +1,11 | |||||
1 | import nump |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import time |
|
3 | import time | |
4 | from schainPlot import * |
|
4 | from schainPlot import * | |
5 | #from schainPlotLib import Driver |
|
5 | #from schainPlotLib import Driver | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | class RTIFigure: |
|
8 | class RTIFigure(Figure): | |
9 | overplot = 1 |
|
9 | overplot = 1 | |
10 | xw = 700 |
|
10 | xw = 700 | |
11 | yw = 650 |
|
11 | yw = 650 | |
@@ -16,6 +16,7 class RTIFigure: | |||||
16 | maxrange = None |
|
16 | maxrange = None | |
17 | minvalue = None |
|
17 | minvalue = None | |
18 | maxvalue = None |
|
18 | maxvalue = None | |
|
19 | xrangestepinsecs = None | |||
19 |
|
20 | |||
20 |
|
21 | |||
21 | def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False): |
|
22 | def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False): | |
@@ -28,62 +29,102 class RTIFigure: | |||||
28 | self.driver = driver |
|
29 | self.driver = driver | |
29 | self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar) |
|
30 | self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar) | |
30 | self.drvObj.driver.setFigure() |
|
31 | self.drvObj.driver.setFigure() | |
|
32 | self.drvObj.driver.setColormap(colormap) | |||
31 |
|
33 | |||
32 | def getSubplots(self): |
|
34 | def getSubplots(self): | |
33 | nrows = self.nframes |
|
35 | nrows = self.nframes | |
34 | ncolumns = 1 |
|
36 | ncolumns = 1 | |
35 | return nrows, ncolumns |
|
37 | return nrows, ncolumns | |
36 |
|
38 | |||
37 |
def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, |
|
39 | def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep): | |
38 |
|
40 | |||
39 | if minvalue == None: minvalue = numpy.min(data) |
|
|||
40 | if maxvalue == None: maxvalue = numpy.max(data) |
|
|||
41 |
|
||||
42 | utcdatetime = datetime.datetime.utcfromtimestamp(x) |
|
|||
43 | startdatetime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin.hour,xmin.minute, xmin.second) |
|
|||
44 | enddatetime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax.hour,xmax.minute, xmax.second) |
|
|||
45 | deltatime = 0 |
|
|||
46 | if timezone == "lt": deltatime = time.timezone |
|
|||
47 | startTimeInSecs = time.mktime(startdatetime.timetuple()) - deltatime |
|
|||
48 | endTimeInSecs = time.mktime(enddatetime.timetuple()) - deltatime |
|
|||
49 | self.starttime = xmin |
|
41 | self.starttime = xmin | |
50 | self.endtime = xmax |
|
42 | self.endtime = xmax | |
51 | self.xmin = startTimeInSecs |
|
|||
52 | self.xmax = self.xmin + interval |
|
|||
53 |
|
||||
54 |
|
43 | |||
|
44 | cdatetime = datetime.datetime.utcfromtimestamp(x) #siempre en localtime | |||
|
45 | ||||
|
46 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second) | |||
|
47 | if ((xrangestep == 0) or (xrangestep == None)): | |||
|
48 | maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second) | |||
|
49 | self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple()) | |||
|
50 | npoints = 1000. | |||
|
51 | if xrangestep == 1: | |||
|
52 | maxdatetime = mindatetime + datetime.timedelta(hours=1) | |||
|
53 | self.xrangestepinsecs = 60*60. | |||
|
54 | npoints = 500. | |||
|
55 | if xrangestep == 2: | |||
|
56 | maxdatetime = mindatetime + datetime.timedelta(minutes=1) | |||
|
57 | self.xrangestepinsecs = 60. | |||
|
58 | npoints = 250. | |||
|
59 | if xrangestep == 3: | |||
|
60 | maxdatetime = mindatetime + datetime.timedelta(seconds=1) | |||
|
61 | self.xrangestepinsecs = 1. | |||
|
62 | npoints = 125. | |||
|
63 | ||||
|
64 | xmin = time.mktime(mindatetime.timetuple()) | |||
|
65 | xmax = time.mktime(maxdatetime.timetuple()) | |||
|
66 | ||||
|
67 | deltax = (xmax-xmin) / npoints | |||
55 |
|
68 | |||
56 | if ymin == None: ymin = numpy.min(y) |
|
|||
57 | if ymin == None: ymax = numpy.max(y) |
|
|||
58 |
|
69 | |||
59 | starttime = None |
|
70 | if ymin == None: ymin = numpy.min(y) | |
60 | endtime = None |
|
71 | if ymax == None: ymax = numpy.max(y) | |
61 | minrange = None |
|
|||
62 | maxrange = None |
|
|||
63 | minvalue = None |
|
|||
64 | maxvalue = None |
|
|||
65 |
|
72 | |||
|
73 | if minvalue == None: minvalue = 0. | |||
|
74 | if maxvalue == None: maxvalue = 50. | |||
66 |
|
75 | |||
67 |
self.xmin = |
|
76 | self.xmin = xmin | |
68 | self.xmax = self.starttime + timeinterval |
|
77 | self.xmax = xmax | |
69 |
self. |
|
78 | self.minrange = ymin | |
70 |
self. |
|
79 | self.maxrange = ymax | |
|
80 | self.ymin = ymin | |||
|
81 | self.ymax = ymax | |||
71 | self.minvalue = minvalue |
|
82 | self.minvalue = minvalue | |
72 | self.maxvalue = maxvalue |
|
83 | self.maxvalue = maxvalue | |
|
84 | self.xrangestep = xrangestep | |||
|
85 | self.deltax = deltax | |||
|
86 | ||||
|
87 | ||||
|
88 | def changeXRange(self,x): | |||
|
89 | ||||
|
90 | cdatetime = datetime.datetime.utcfromtimestamp(x) #siempre en localtime | |||
|
91 | ||||
|
92 | if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)): | |||
|
93 | if self.xrangestep == 1: | |||
|
94 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second) | |||
|
95 | ||||
|
96 | if self.xrangestep == 2: | |||
|
97 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second) | |||
|
98 | ||||
|
99 | if self.xrangestep == 3: | |||
|
100 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second) | |||
73 |
|
101 | |||
|
102 | # mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second) | |||
|
103 | self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone | |||
|
104 | self.xmax = self.xmin + self.xrangestepinsecs | |||
|
105 | ||||
|
106 | self.figuretitle = "%s: %s - %s"%(self.figuretitle, | |||
|
107 | datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"), | |||
|
108 | datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S")) | |||
|
109 | ||||
|
110 | ||||
|
111 | return 1 | |||
|
112 | ||||
|
113 | return 0 | |||
|
114 | ||||
74 |
|
115 | |||
75 | def createFrames(self): |
|
116 | def createFrames(self): | |
76 | for frame in range(self.nframes): |
|
117 | for frame in range(self.nframes): | |
77 |
frameObj = |
|
118 | frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile) | |
78 | self.frameObjList.append(frameObj) |
|
119 | self.frameObjList.append(frameObj) | |
79 |
|
120 | |||
80 | class RTIFrame(Frame): |
|
121 | class RTIFrame(Frame): | |
81 |
def __init__(self,drvObj,idframe,colorbar,show |
|
122 | def __init__(self,drvObj,idframe,colorbar,showprofile): | |
82 | self.drvObj = drvObj |
|
123 | self.drvObj = drvObj | |
83 | self.idframe = idframe |
|
124 | self.idframe = idframe | |
84 | self.nplots = 1 |
|
125 | self.nplots = 1 | |
85 |
|
126 | |||
86 |
if show |
|
127 | if showprofile: | |
87 | self.nplots += 1 |
|
128 | self.nplots += 1 | |
88 |
|
129 | |||
89 | self.colorbar = colorbar |
|
130 | self.colorbar = colorbar | |
@@ -95,7 +136,7 class RTIFrame(Frame): | |||||
95 |
|
136 | |||
96 | idplot = 0 |
|
137 | idplot = 0 | |
97 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
138 | xi, yi, xw, yw = self.getScreenPos(idplot) | |
98 | plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw) |
|
139 | plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar) | |
99 | plotObjList.append(plotObj) |
|
140 | plotObjList.append(plotObj) | |
100 |
|
141 | |||
101 | if self.showprofile: |
|
142 | if self.showprofile: | |
@@ -134,9 +175,28 class RTIFrame(Frame): | |||||
134 |
|
175 | |||
135 | return xi, yi, xw, yw |
|
176 | return xi, yi, xw, yw | |
136 |
|
177 | |||
|
178 | def plot(self, currenttime, range, data): | |||
|
179 | # for plotObj in self.plotObjList: | |||
|
180 | # plotObj.plot(currenttime, range, data) | |||
|
181 | ||||
|
182 | plotObj = self.plotObjList[0] | |||
|
183 | plotObj.plot(currenttime,range,data) | |||
|
184 | ||||
|
185 | if self.showprofile: | |||
|
186 | plotObj = self.plotObjList[1] | |||
|
187 | plotObj.plot(data,range) | |||
|
188 | ||||
137 |
|
189 | |||
138 | class RTIPlot: |
|
190 | class RTIPlot(Plot): | |
139 | def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw): |
|
191 | deltax = None | |
|
192 | deltay = None | |||
|
193 | xrange = [None,None] | |||
|
194 | xminpos = None | |||
|
195 | xmaxpos = None | |||
|
196 | xg = None | |||
|
197 | yg = None | |||
|
198 | ||||
|
199 | def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar): | |||
140 | self.drvObj = drvObj |
|
200 | self.drvObj = drvObj | |
141 | self.idframe = idframe |
|
201 | self.idframe = idframe | |
142 | self.idplot = idplot |
|
202 | self.idplot = idplot | |
@@ -144,6 +204,7 class RTIPlot: | |||||
144 | self.yi = yi |
|
204 | self.yi = yi | |
145 | self.xw = xw |
|
205 | self.xw = xw | |
146 | self.yw = yw |
|
206 | self.yw = yw | |
|
207 | self.colorbar = colorbar | |||
147 |
|
208 | |||
148 | if self.colorbar: |
|
209 | if self.colorbar: | |
149 | cbxi = xw + 0.03 |
|
210 | cbxi = xw + 0.03 | |
@@ -162,16 +223,19 class RTIPlot: | |||||
162 |
|
223 | |||
163 | self.szchar = 1.0 |
|
224 | self.szchar = 1.0 | |
164 | self.title = "Channel %d"%self.idframe |
|
225 | self.title = "Channel %d"%self.idframe | |
165 |
self.xlabel = " |
|
226 | self.xlabel = "Local Time" | |
166 |
self.ylabel = " |
|
227 | self.ylabel = "Range (Km)" | |
|
228 | ||||
167 |
|
229 | |||
168 | def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue): |
|
230 | def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None): | |
169 | self.xmin = xmin |
|
231 | self.xmin = xmin | |
170 | self.xmax = xmax |
|
232 | self.xmax = xmax | |
171 | self.ymin = ymin |
|
233 | self.ymin = ymin | |
172 | self.ymax = ymax |
|
234 | self.ymax = ymax | |
173 | self.minvalue = minvalue |
|
235 | self.minvalue = minvalue | |
174 | self.maxvalue = maxvalue |
|
236 | self.maxvalue = maxvalue | |
|
237 | self.deltax = deltax | |||
|
238 | self.deltay = deltay | |||
175 |
|
239 | |||
176 | self.drvObj.driver.plotBox(self.idframe, |
|
240 | self.drvObj.driver.plotBox(self.idframe, | |
177 | self.xpos, |
|
241 | self.xpos, | |
@@ -191,15 +255,26 class RTIPlot: | |||||
191 | self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) |
|
255 | self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title) | |
192 |
|
256 | |||
193 | if self.colorbar: |
|
257 | if self.colorbar: | |
194 |
self.drvObj.driver. |
|
258 | self.drvObj.driver.plotColorbar(minvalue, maxvalue, self.cbxpos,self.cbypos) | |
195 |
|
259 | |||
196 |
|
||||
197 | def plot(self): |
|
|||
198 | pass |
|
|||
199 |
|
||||
200 |
|
||||
201 |
|
||||
202 |
|
260 | |||
|
261 | ||||
|
262 | def plot(self, currenttime, range, data): | |||
|
263 | ||||
|
264 | if self.xmaxpos == None: | |||
|
265 | self.xmaxpos = currenttime | |||
|
266 | ||||
|
267 | if currenttime >= self.xmaxpos: | |||
|
268 | ||||
|
269 | self.xminpos = currenttime | |||
|
270 | self.xmaxpos = currenttime + self.deltax | |||
|
271 | x = [currenttime] | |||
|
272 | y = range | |||
|
273 | z = numpy.reshape(data, (1,-1)) | |||
|
274 | getGrid = True | |||
|
275 | ||||
|
276 | self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid) | |||
|
277 | ||||
203 |
|
278 | |||
204 | class ScopeFigure(Figure): |
|
279 | class ScopeFigure(Figure): | |
205 | overplot = 0 |
|
280 | overplot = 0 |
General Comments 0
You need to be logged in to leave comments.
Login now