##// END OF EJS Templates
-Los graficos de Spectra fueron agrandados...
Miguel Valdez -
r161:4c3983336b46
parent child
Show More
@@ -1,412 +1,412
1 1 import numpy
2 2 import datetime
3 3 import time
4 4 import os
5 5 from schainPlotLib import Driver
6 6
7 7 class Figure:
8 8
9 9 __isDriverOpen = False
10 10 __isFigureOpen = False
11 11 __isConfig = False
12 12 __counter = 0
13 13 drvObj = None
14 14 driver = None
15 15 idfigure = None
16 16 nframes = None
17 17 wintitle = None
18 18 colormap = None
19 19 overplot = None
20 20 colorbar = None
21 21
22 22 frameObjList = []
23 23
24 24 xw = None
25 25 yw = None
26 26
27 27 xmin = None
28 28 xmax = None
29 29 ymin = None
30 30 ymax = None
31 31
32 32 minvalue = None
33 33 maxvalue = None
34 34 deltax = None
35 35 deltay = None
36 36
37 37
38 38 figuretitle = ""
39 39 xrangestep = None
40 40
41 41 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args):
42 42
43 43 self.__isDriverOpen = False
44 44 self.__isFigureOpen = False
45 45 self.__isConfig = False
46 46 self.__counter = 0
47 47
48 48 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
49 49 self.driver = driver
50 50 self.idfigure = idfigure
51 51 self.nframes = nframes
52 52 self.wintitle = wintitle
53 53 self.colormap = colormap
54 54 self.overplot = overplot
55 55 self.colorbar = colorbar
56 56
57 57 self.xw = xw
58 58 self.yw = yw
59 59
60 60 self.frameObjList = []
61 61
62 62 self.drvObj.driver.setFigure()
63 63 self.drvObj.driver.setColormap(colormap)
64 64
65 65 def __openDriver(self):
66 66
67 67 self.drvObj.driver.openDriver()
68 68
69 69 def __newPage(self):
70 70
71 71
72 72 self.drvObj.driver.openPage()
73 73 nrows, ncolumns = self.getSubplots()
74 74 self.drvObj.driver.setFigTitle(self.figuretitle)
75 75 self.drvObj.driver.setSubPlots(nrows, ncolumns)
76 76
77 77 def __closePage(self):
78 78
79 79 self.drvObj.driver.closeFigure()
80 80
81 81 def selectFigure(self):
82 82
83 83 self.drvObj.driver.selectFigure()
84 84
85 85 def __isOutOfXRange(self,x):
86 86 try:
87 87 if ((x>=self.xmin) and (x<self.xmax)):
88 88 return 0
89 89 except:
90 90 return 0
91 91
92 92 return 1
93 93
94 94 def changeXRange(self,x):
95 95
96 96 pass
97 97
98 98 def __refresh(self):
99 99 self.drvObj.driver.refresh()
100 100
101 101 def createFrames(self):
102 102
103 103 self.frameObjList = []
104 104
105 105 raise ValueError, "No implemented"
106 106
107 107 def save(self,filename):
108 108
109 109 self.drvObj.driver.save(filename)
110 110
111 111 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./', ratio=1):
112 112
113 113 nx, ny = data1D.shape
114 114
115 115 if channelList == None:
116 116 channelList = range(nx)
117 117
118 118 if x == None:
119 119 x = numpy.arange(data1D.size)
120 120
121 121 if figuretitle == None:
122 122 self.figuretitle = ""
123 123 else:
124 124 self.figuretitle = figuretitle
125 125
126 126 if not(self.__isDriverOpen):
127 127 self.__openDriver()
128 128 self.__isDriverOpen = True
129 129
130 130 if not(self.__isConfig):
131 131 self.xmin = xmin
132 132 self.xmax = xmax
133 133 self.minvalue = minvalue
134 134 self.maxvalue = maxvalue
135 135
136 136 if self.xmin == None: self.xmin = numpy.min(x)
137 137 if self.xmax == None: self.xmax = numpy.max(x)
138 138 if self.minvalue == None: self.minvalue = numpy.min(data1D)
139 139 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
140 140
141 141 self.createFrames()
142 142 self.__isConfig = True
143 143
144 144
145 145
146 146 self.selectFigure()
147 147 self.__newPage()
148 148
149 149
150 150 for channel in range(len(channelList)):
151 151 frameObj = self.frameObjList[channel]
152 152 frameObj.init(xmin=self.xmin,
153 153 xmax=self.xmax,
154 154 ymin=self.minvalue,
155 155 ymax=self.maxvalue,
156 156 minvalue=self.minvalue,
157 157 maxvalue=self.maxvalue)
158 158
159 159 for channel in range(len(channelList)):
160 160 dataCh = data1D[channel,:]
161 161 frameObj = self.frameObjList[channel]
162 162 frameObj.plot(x, dataCh)
163 163
164 164 self.__refresh()
165 165
166 166 if save:
167 167 if self.__counter == 0:
168 168 path = gpath
169 169 now = datetime.datetime.now()
170 170 file = "plot_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
171 171 filename = os.path.join(path,file)
172 172 self.save(filename)
173 173 self.__counter += 1
174 174
175 175 if self.__counter == ratio:
176 176 self.__counter = 0
177 177
178 178
179 179 self.__closePage()
180 180
181 181
182 182 def plotPcolor(self,data,
183 183 x=None,
184 184 y=None,
185 185 channelList=None,
186 186 xmin=None,
187 187 xmax=None,
188 188 ymin=None,
189 189 ymax=None,
190 190 minvalue=None,
191 191 maxvalue=None,
192 192 figuretitle=None,
193 193 xrangestep=None,
194 194 deltax=None,
195 195 save=False,
196 196 gpath='./',
197 197 ratio=1,
198 198 cleardata=False,
199 199 *args):
200 200
201 201
202 202 if figuretitle == None:
203 203 self.figuretitle = ""
204 204 else:
205 205 self.figuretitle = figuretitle
206 206
207 207
208 208 if not(self.__isDriverOpen):
209 209 self.__openDriver()
210 210 self.__isDriverOpen = True
211 211
212 212 if not(self.__isConfig):
213 213
214 214 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax)
215 215
216 216 self.createFrames()
217 217 self.__isConfig = True
218 218
219 219 if (self.__isOutOfXRange(x)):
220 220
221 221 if not(self.changeXRange(x)):
222 222 return 0
223 223
224 224 self.__closePage()
225 225 self.__isFigureOpen = False
226 226
227 227 self.selectFigure()
228 228
229 229 if not(self.__isFigureOpen):
230 230 self.__newPage()
231 231 self.__isFigureOpen = True
232 232
233 233 for channel in range(len(channelList)):
234 234 if len(args) != 0: value = args[0][channel]
235 235 else: value = args
236 236
237 237 frameObj = self.frameObjList[channel]
238 238 frameObj.init(self.xmin,
239 239 self.xmax,
240 240 self.ymin,
241 241 self.ymax,
242 242 self.minvalue,
243 243 self.maxvalue,
244 244 self.deltax,
245 245 self.deltay,
246 246 self.colorbar,
247 247 value)
248 248
249 249
250 250 for channel in range(len(channelList)):
251 251 dataCh = data[channel,:]
252 252 frameObj = self.frameObjList[channel]
253 253 frameObj.plot(x, y, dataCh)
254 254
255 255
256 256 self.__refresh()
257 257
258 258 if save:
259 259 if self.__counter == 0:
260 260 path = gpath
261 261 now = datetime.datetime.now()
262 262 file = "pcolor_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
263 263 filename = os.path.join(path,file)
264 264 self.save(filename)
265 265 self.__counter += 1
266 266
267 267 if self.__counter == ratio:
268 268 self.__counter = 0
269 269
270 270
271 271 if cleardata == True:
272 272 self.__closePage()
273 273 self.__isFigureOpen = False
274 274
275 275
276 276
277 277
278 278 class Frame:
279 279
280 280 drvObj = None
281 281 idFrame = None
282 282 nplots = None
283 283 plotObjList = []
284 284 title = ""
285 285
286 286 def __init__(self,drvObj, idframe):
287 287
288 288 self.drvObj = drvObj
289 289 self.idframe = idframe
290 290 nplots = None
291 291 self.plotObjList = []
292 292
293 293 self.createPlots()
294 294
295 295 def createPlots(self):
296 296 raise ValueError, "No implemented"
297 297
298 298 def getScreenPosMainPlot(self):
299 299 raise ValueError, "No implemented"
300 300
301 301 def getScreenPosGraph1(self):
302 302 raise ValueError, "No implemented"
303 303
304 304 def getScreenPos(self, nplot):
305 305
306 306 if nplot == 0:
307 307 xi, yi, xw, yw = self.getScreenPosMainPlot()
308 308
309 309 if nplot == 1:
310 310 xi, yi, xw, yw = self.getScreenPosGraph1()
311 311
312 312 return xi, yi, xw, yw
313 313
314 314
315 315 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
316 316
317 317 for plotObj in self.plotObjList:
318 318 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
319 319 plotObj.plotBox()
320 320
321 321
322 322
323 323 class Plot:
324 324
325 325 drvObj = None
326 326 idframe = None
327 327 idplot = None
328 328 xi = None
329 329 yi = None
330 330 xw = None
331 331 yw = None
332 332
333 333 title = ""
334 334 xlabel = ""
335 335 ylabel = ""
336 336 xaxisastime = None
337 337 timefmt = None
338 338 xopt = ""
339 339 yopt = ""
340 340 xpos = None
341 341 ypos = None
342 342 szchar = None
343 343 idframe = None
344 344 idplot = None
345 345 colorbar = None
346 346 cbxpos = None
347 347 cbypos = None
348 348
349 349 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
350 350
351 351 self.drvObj = drvObj
352 352 self.idframe = idframe
353 353 self.idplot = idplot
354 354 self.xi = xi
355 355 self.yi = yi
356 356 self.xw = xw
357 357 self.yw = yw
358 358
359 359
360 360 def plotBox(self):
361 361
362 362 self.drvObj.driver.plotBox(self.idframe,
363 363 self.xpos,
364 364 self.ypos,
365 365 self.xmin,
366 366 self.xmax,
367 367 self.ymin,
368 368 self.ymax,
369 369 self.minvalue,
370 370 self.maxvalue,
371 371 self.xopt,
372 372 self.yopt,
373 373 self.szchar,
374 374 self.xaxisastime,
375 375 self.timefmt)
376 376
377 377 self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title)
378 378
379 379 if self.colorbar:
380 380 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
381 381
382 382 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
383 383
384 384 self.drvObj.driver.pcolor(self.idframe,
385 385 self.xpos,
386 386 self.ypos,
387 387 z,
388 388 x,
389 389 y,
390 390 self.xmin,
391 391 self.xmax,
392 392 self.ymin,
393 393 self.ymax,
394 394 self.minvalue,
395 395 self.maxvalue,
396 396 deltax,
397 397 deltay,
398 398 getGrid,
399 399 self.xaxisastime,
400 400 self.timefmt)
401 401
402 def plotBasicLine(self,x, y, color):
402 def plotBasicLine(self,x, y, color, xopt='bcst', yopt='bcst'):
403 403 """
404 404 Inputs:
405 405 x:
406 406
407 407 y:
408 408
409 409 color:
410 410 """
411 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
411 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color, xopt=xopt, yopt=yopt)
412 412 No newline at end of file
@@ -1,515 +1,516
1 1 import plplot
2 2 import numpy
3 3 import sys
4 4 import plplot #condicional
5 5
6 6 import matplotlib as mpl
7 7 #mpl.use('TKAgg')
8 8 import matplotlib.pyplot as plt
9 9
10 10 class Driver:
11 11 def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
12 12 if driver == "plplot":
13 13 self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
14 14 elif driver == "mpl":
15 15 self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
16 16 else:
17 17 raise ValueError, "The driver: %s is not defined"%driver
18 18
19 19 class PlplotDriver:
20 20
21 21 __isDriverOpen = False
22 22 pldriver = None
23 23 __xg = None
24 24 __yg = None
25 25 def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
26 26
27 27 if idfigure == None:
28 28 raise ValueError, 'idfigure input must be defined'
29 29
30 30 self.idfigure = idfigure
31 31 self.xw = xw
32 32 self.yw = yw
33 33 self.wintitle = wintitle
34 34 self.overplot = overplot
35 35 self.colormap = colormap
36 36 self.colorbar = colorbar
37 37
38 38 def setFigure(self):
39 39 """
40 40 previous configuration to open(init) the plplot driver
41 41 """
42 42 plplot.plsstrm(self.idfigure)
43 43 plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL)
44 44 plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw))
45 45
46 46 def selectFigure(self):
47 47
48 48 plplot.plsstrm(self.idfigure)
49 49
50
50 51 def openDriver(self, pldriver=None):
51 52 if pldriver == None:
52 53 if sys.platform == "linux":
53 54 pldriver = "xcairo"
54 55
55 56 if sys.platform == "linux2":
56 57 pldriver = "xcairo"
57 58
58 59 elif sys.platform == "darwin":
59 60 pldriver = "xwin"
60 61
61 62 else:
62 63 pldriver = ""
63 64
64 65 plplot.plsdev("xwin") #para pruebas
65 66 plplot.plscolbg(255,255,255)
66 67 plplot.plscol0(1,0,0,0)
67 68 plplot.plinit()
68 69 plplot.plspause(False)
69 70
70 71 self.pldriver = pldriver
71 72
72 73 def closeDriver(self):
73 74 pass
74 75
75 76 def openPage(self):
76 77 plplot.plbop()
77 plplot.pladv(0)
78 #plplot.pladv(0)
78 79
79 80 def closePage(self):
80 81 plplot.pleop()
81 82
82 83 def openFigure(self):
83 84 plplot.plbop()
84 85 plplot.pladv(0)
85 86
86 87 def closeFigure(self):
87 88 plplot.pleop()
88 89
89 90 def setSubPlots(self,nrows, ncolumns):
90 plplot.plssub(ncolumns,nrows)
91 plplot.plssub(ncolumns, nrows)
91 92
92 93 def setPlotLabels(self, id, xlabel, ylabel, title):
93 94 plplot.pllab(xlabel, ylabel, title)
94 95
95 96 def setFigTitle(self, title,color="black", szchar=0.55):
96 self.setSubPlots(1, 0)
97 self.setSubPlots(1, 1)
97 98 plplot.pladv(0)
98 99 plplot.plvpor(0., 1., 0., 1.)
99 100
100 101 if color == "black":
101 102 plplot.plcol0(1)
102 103 if color == "white":
103 104 plplot.plcol0(15)
104 105
105 106 plplot.plschr(0.0,szchar)
106 107 plplot.plmtex("t",-1., 0.5, 0.5, title)
107 108
108 109 def plotColorbar(self, minvalue, maxvalue, xpos, ypos):
109 110 # plplot.pladv(id)
110 111 # plplot.plschr(0.0,szchar-0.05)
111 112 xmin = 0; xmax = 1
112 113 ymin = minvalue; ymax = maxvalue
113 114 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
114 115 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
115 116 plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0)
116 117
117 118 data = numpy.arange(256)
118 119 data = numpy.reshape(data, (1,-1))
119 120
120 121 plplot.plimage(data,
121 122 float(xmin),
122 123 float(xmax),
123 124 float(ymin),
124 125 float(ymax),
125 126 0.,
126 127 255.,
127 128 float(xmin),
128 129 float(xmax),
129 130 float(ymin),
130 131 float(ymax))
131 132
132 133
133 134 def __getGrid(self, x, y, deltax=None, deltay=None):
134 135
135 136 if not(len(x)>0 and len(y)>0):
136 137 raise ValueError, "x axis and y axis are empty"
137 138
138 139 if deltax == None: deltax = x[-1] - x[-2]
139 140 if deltay == None: deltay = y[-1] - y[-2]
140 141
141 142 x1 = numpy.append(x, x[-1] + deltax)
142 143 y1 = numpy.append(y, y[-1] + deltay)
143 144
144 145 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
145 146 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
146 147
147 148 return xg, yg
148 149
149 150
150 151 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"):
151 152
152 153 plplot.pladv(id)
153 154 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
154 155 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
155 156
156 157 if xaxisastime:
157 158 timedelta = (xmax - xmin + 1)/8.
158 159
159 160 if getGrid:
160 161 self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay)
161 162
162 163 if deltax == None: deltax = x[-1] - x[0]
163 164 # if deltay == None: deltay = y[-1] - y[-2]
164 165
165 166 xmin = x[0]
166 167 xmax = xmin + deltax
167 168
168 169 plplot.plimagefr(data,
169 170 float(xmin),
170 171 float(xmax),
171 172 float(ymin),
172 173 float(ymax),
173 174 0.,
174 175 0.,
175 176 float(zmin),
176 177 float(zmax),
177 178 plplot.pltr2,
178 179 self.__xg,
179 180 self.__yg)
180 181
181 182 if xaxisastime:
182 183 plplot.pltimefmt(timefmt)
183 184 xopt = "bcstd"
184 185 yopt = "bcst"
185 186 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
186 187 else:
187 188 xopt = "bcst"
188 189 yopt = "bcst"
189 190 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
190 191
191 192
192 193 def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"):
193 194 """
194 195 xopt, yopt: entradas que no se aplican en MPL
195 196 """
196 197 plplot.pladv(id)
197 198 plplot.plschr(0.0,szchar-0.05)
198 199 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
199 200 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
200 201 if xaxisastime:
201 202 plplot.pltimefmt(timefmt)
202 203 timedelta = (xmax - xmin + 1)/8.
203 204 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
204 205 else:
205 206 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
206 207
207 208 def refresh(self):
208 209 plplot.plflush()
209 210
210 211 def show(self):
211 212 plplot.plspause(True)
212 213 plplot.plend()
213 214
214 def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color):
215 def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color, xopt="bcst", yopt="bcst"):
215 216
216 217 """
217 218 Inputs:
218 219 x: datos en el eje x
219 220
220 221 y: datos en el eje y
221 222
222 223 xmin, xmax: intervalo de datos en el eje x
223 224
224 225 ymin, ymax: intervalo de datos en el eje y
225 226
226 227 color: color de la linea a dibujarse
227 228
228 229 id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada
229 230 plot esta definido por xpos, ypos.
230 231
231 232 xpos,ypos: coordenadas que indican la posicion del plot en el frame
232 233
233 234 """
234 235
235 236 plplot.pladv(id)
236 237 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
237 238 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
238 239
239 240 if color == "blue":
240 241 colline = 9
241 242 if color == "green":
242 243 colline = 3
243 244
244 245 plplot.plcol0(colline)
245 246 plplot.plline(x, y)
246 247 plplot.plcol0(1)
247 plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0)
248 # plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
248 249
249 250 def save(self, filename):
250 251 curr_strm = plplot.plgstrm()
251 252 save_strm = plplot.plmkstrm()
252 253 plplot.plsetopt("geometry", "%dx%d"%(self.xw,self.yw))
253 254 plplot.plsdev("png")
254 255 plplot.plsfnam(filename)
255 256 plplot.plcpstrm(curr_strm,0)
256 257 plplot.plreplot()
257 258 plplot.plend1()
258 259 plplot.plsstrm(curr_strm)
259 260
260 261 def setColormap(self, colormap="gray"):
261 262
262 263 if colormap == None:
263 264 return
264 265
265 266 ncolor = None
266 267 rgb_lvl = None
267 268
268 269 # Routine for defining a specific color map 1 in HLS space.
269 270 # if gray is true, use basic grayscale variation from half-dark to light.
270 271 # otherwise use false color variation from blue (240 deg) to red (360 deg).
271 272
272 273 # Independent variable of control points.
273 274 i = numpy.array((0., 1.))
274 275 if colormap=="gray":
275 276 ncolor = 256
276 277 # Hue for control points. Doesn't matter since saturation is zero.
277 278 h = numpy.array((0., 0.))
278 279 # Lightness ranging from half-dark (for interest) to light.
279 280 l = numpy.array((0.5, 1.))
280 281 # Gray scale has zero saturation
281 282 s = numpy.array((0., 0.))
282 283
283 284 # number of cmap1 colours is 256 in this case.
284 285 plplot.plscmap1n(ncolor)
285 286 # Interpolate between control points to set up cmap1.
286 287 plplot.plscmap1l(0, i, h, l, s)
287 288
288 289 return None
289 290
290 291 if colormap == 'jet':
291 292 ncolor = 256
292 293 pos = numpy.zeros((ncolor))
293 294 r = numpy.zeros((ncolor))
294 295 g = numpy.zeros((ncolor))
295 296 b = numpy.zeros((ncolor))
296 297
297 298 for i in range(ncolor):
298 299 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
299 300 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
300 301 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
301 302 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
302 303
303 304 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
304 305 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
305 306 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
306 307 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
307 308 else: gf = 0.0
308 309
309 310 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
310 311 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
311 312 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
312 313 else: bf = 0
313 314
314 315 r[i] = rf
315 316 g[i] = gf
316 317 b[i] = bf
317 318
318 319 pos[i] = float(i)/float(ncolor-1)
319 320
320 321
321 322 plplot.plscmap1n(ncolor)
322 323 plplot.plscmap1l(1, pos, r, g, b)
323 324
324 325
325 326
326 327 if colormap=="br_green":
327 328 ncolor = 256
328 329 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
329 330 h = numpy.array((240., 0.))
330 331 # Lightness and saturation are constant (values taken from C example).
331 332 l = numpy.array((0.6, 0.6))
332 333 s = numpy.array((0.8, 0.8))
333 334
334 335 # number of cmap1 colours is 256 in this case.
335 336 plplot.plscmap1n(ncolor)
336 337 # Interpolate between control points to set up cmap1.
337 338 plplot.plscmap1l(0, i, h, l, s)
338 339
339 340 return None
340 341
341 342 if colormap=="tricolor":
342 343 ncolor = 3
343 344 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
344 345 h = numpy.array((240., 0.))
345 346 # Lightness and saturation are constant (values taken from C example).
346 347 l = numpy.array((0.6, 0.6))
347 348 s = numpy.array((0.8, 0.8))
348 349
349 350 # number of cmap1 colours is 256 in this case.
350 351 plplot.plscmap1n(ncolor)
351 352 # Interpolate between control points to set up cmap1.
352 353 plplot.plscmap1l(0, i, h, l, s)
353 354
354 355 return None
355 356
356 357 if colormap == 'rgb' or colormap == 'rgb666':
357 358
358 359 color_sz = 6
359 360 ncolor = color_sz*color_sz*color_sz
360 361 pos = numpy.zeros((ncolor))
361 362 r = numpy.zeros((ncolor))
362 363 g = numpy.zeros((ncolor))
363 364 b = numpy.zeros((ncolor))
364 365 ind = 0
365 366 for ri in range(color_sz):
366 367 for gi in range(color_sz):
367 368 for bi in range(color_sz):
368 369 r[ind] = ri/(color_sz-1.0)
369 370 g[ind] = gi/(color_sz-1.0)
370 371 b[ind] = bi/(color_sz-1.0)
371 372 pos[ind] = ind/(ncolor-1.0)
372 373 ind += 1
373 374 rgb_lvl = [6,6,6] #Levels for RGB colors
374 375
375 376 if colormap == 'rgb676':
376 377 ncolor = 6*7*6
377 378 pos = numpy.zeros((ncolor))
378 379 r = numpy.zeros((ncolor))
379 380 g = numpy.zeros((ncolor))
380 381 b = numpy.zeros((ncolor))
381 382 ind = 0
382 383 for ri in range(8):
383 384 for gi in range(8):
384 385 for bi in range(4):
385 386 r[ind] = ri/(6-1.0)
386 387 g[ind] = gi/(7-1.0)
387 388 b[ind] = bi/(6-1.0)
388 389 pos[ind] = ind/(ncolor-1.0)
389 390 ind += 1
390 391 rgb_lvl = [6,7,6] #Levels for RGB colors
391 392
392 393 if colormap == 'rgb685':
393 394 ncolor = 6*8*5
394 395 pos = numpy.zeros((ncolor))
395 396 r = numpy.zeros((ncolor))
396 397 g = numpy.zeros((ncolor))
397 398 b = numpy.zeros((ncolor))
398 399 ind = 0
399 400 for ri in range(8):
400 401 for gi in range(8):
401 402 for bi in range(4):
402 403 r[ind] = ri/(6-1.0)
403 404 g[ind] = gi/(8-1.0)
404 405 b[ind] = bi/(5-1.0)
405 406 pos[ind] = ind/(ncolor-1.0)
406 407 ind += 1
407 408 rgb_lvl = [6,8,5] #Levels for RGB colors
408 409
409 410 if colormap == 'rgb884':
410 411 ncolor = 8*8*4
411 412 pos = numpy.zeros((ncolor))
412 413 r = numpy.zeros((ncolor))
413 414 g = numpy.zeros((ncolor))
414 415 b = numpy.zeros((ncolor))
415 416 ind = 0
416 417 for ri in range(8):
417 418 for gi in range(8):
418 419 for bi in range(4):
419 420 r[ind] = ri/(8-1.0)
420 421 g[ind] = gi/(8-1.0)
421 422 b[ind] = bi/(4-1.0)
422 423 pos[ind] = ind/(ncolor-1.0)
423 424 ind += 1
424 425 rgb_lvl = [8,8,4] #Levels for RGB colors
425 426
426 427 if ncolor == None:
427 428 raise ValueError, "The colormap selected (%s) is not valid" %(colormap)
428 429
429 430 plplot.plscmap1n(ncolor)
430 431 plplot.plscmap1l(1, pos, r, g, b)
431 432
432 433 return rgb_lvl
433 434
434 435
435 436 class MplDriver:
436 437 # fig = None
437 438 nrows = None
438 439 ncolumns = None
439 440 __axesId = None
440 441 __setData = None
441 442
442 443 def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
443 444
444 445 if idfigure == None:
445 446 raise ValueError, 'idfigure input must be defined'
446 447 self.idfigure = idfigure
447 448 self.xw = xw
448 449 self.yw = yw
449 450 self.wintitle = wintitle
450 451 self.overplot = overplot
451 452 self.colormap = colormap
452 453 self.colorbar = colorbar
453 454 self.__axesId = {}
454 455
455 456 def setFigure(self):
456 457 plt.ioff()
457 458 fig = plt.figure(self.idfigure)
458 459 fig.canvas.manager.set_window_title(self.wintitle)
459 460 fig.canvas.resize(self.xw,self.yw)
460 461 plt.ion()
461 462
462 463
463 464 def setColormap(self, colormap):
464 465 pass
465 466
466 467 def openDriver(self):
467 468 pass
468 469
469 470 def openFigure(self):
470 471 pass
471 472
472 473 def setFigTitle(self,title):
473 474 fig = plt.figure(self.idfigure)
474 475 fig.suptitle(title,fontsize=11, fontweight='bold')
475 476
476 477 def setSubPlots(self,nrows,ncolumns):
477 478 fig = plt.figure(self.idfigure)
478 479 self.nrows = nrows
479 480 self.ncolumns = ncolumns
480 481 #self.__axesId = fig.add_subplot(nrows,ncolumns)
481 482
482 483 def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar, xaxisastime, timefmt):
483 484 fig = plt.figure(self.idfigure)
484 485 ax = fig.add_subplot(self.nrows,self.ncolumns,id)
485 486 ax.set_xlim([xmin,xmax])
486 487 ax.set_ylim([ymin,ymax])
487 488 self.__axesId.setdefault(id)
488 489 self.__axesId[id] = ax
489 490
490 491
491 492 def setPlotLabels(self, id, xlabel, ylabel, title):
492 493 ax = self.__axesId[id]
493 494 ax.set_xlabel(xlabel)
494 495 ax.set_ylabel(ylabel)
495 496 ax.set_title(title)
496 497
497 498 def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color):
498 499 ax = self.__axesId[id]
499 500
500 501 if self.__setData == None:
501 502 ax.plot(x,y,color)
502 503 self.__setData = True
503 504 else:
504 505 ax.lines[0].set_data(x,y)
505 506
506 507 def refresh(self):
507 508 plt.draw()
508 509
509 510
510 511 def plotColorbar(self):
511 512 pass
512 513
513 514
514 515 def closePage(self):
515 516 pass No newline at end of file
@@ -1,695 +1,699
1 1 import numpy
2 2 import datetime
3 3 import time
4 4 from schainPlot import *
5 5
6 6 class CrossSpc(Figure):
7 7 overplot = 0
8 8 xw = 900
9 9 yw = 650
10 10 showprofile = False
11 11 signalA = None
12 12 signalB = None
13 13 coherence = None
14 14 phase = None
15 15
16 16 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
17 17 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
18 18
19 19 self.showprofile = showprofile
20 20 self.signalA = None
21 21 self.signalB = None
22 22 self.coherence = None
23 23 self.phase = None
24 24
25 25 def getSubplots(self):
26 26 nrows = self.nframes
27 27 ncolumns = 1
28 28 return nrows, ncolumns
29 29
30 30 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
31 31
32 32 if xmin == None: xmin = numpy.min(x)
33 33 if xmax == None: xmax = numpy.max(x)
34 34 if ymin == None: ymin = numpy.min(y)
35 35 if ymax == None: ymax = numpy.max(y)
36 36 if minvalue == None: minvalue = 20.
37 37 if maxvalue == None: maxvalue = 90.
38 38
39 39 self.signalA = self.data[0]
40 40 self.signalB = self.data[1]
41 41 self.coherence = self.data[2]
42 42 self.phase = self.data[3]
43 43
44 44 self.xmin = xmin
45 45 self.xmax = xmax
46 46 self.minrange = ymin
47 47 self.maxrange = ymax
48 48 self.ymin = ymin
49 49 self.ymax = ymax
50 50 self.minvalue = minvalue
51 51 self.maxvalue = maxvalue
52 52
53 53 def changeXRange(self, *args):
54 54 pass
55 55
56 56 def createFrames(self):
57 57 self.frameObjList = []
58 58
59 59 for frame in range(self.nframes):
60 60 frameObj = CrossSpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
61 61 self.frameObjList.append(frameObj)
62 62
63 63
64 64 class CrossSpcFrame(Frame):
65 65 xi = None
66 66 xw = None
67 67 yi = None
68 68 yw = None
69 69 alpha = None
70 70 def __init__(self):
71 71 self.drvObj = drvObj
72 72 self.idframe = idframe
73 73 self.nplots = 4
74 74
75 75 if showprofile:
76 76 self.nplots += 4
77 77
78 78 self.colorbar = colorbar
79 79 self.showprofile = showprofile
80 80 self.xi = 0.
81 81 self.xw = 0.
82 82 self.yi = 0.
83 83 self.yw = 0.
84 84 self.alpha = 1.
85 85
86 86 self.createPlots()
87 87
88 88 def createPlots(self):
89 89 plotObjList = []
90 90 idplot = 0
91 91 counter_plot = 0
92 92 for i in range(self.nplots):
93 93 xi, yi, xw, yw = self.getScreenPos(idplot)
94 94 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
95 95 plotObjList.append(plotObj)
96 96
97 97 if self.showprofile:
98 98 xi, yi, xw, yw = self.getScreenPosGraph1(idplot)
99 99 type = "pwbox"
100 100 title = ""
101 101 xlabel = "dB"
102 102 ylabel = ""
103 103 idplot += 1
104 104 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
105 105 plotObjList.append(plotObj)
106 106 idplot += 1
107 107
108 108 self.plotObjList = plotObjList
109 109
110 110 # def getScreenPos(self,idplot):
111 111 # pass
112 112
113 113 def getScreenPos(self, diplot):
114 114
115 115 xi = self.xi
116 116 xw = self.xw
117 117
118 118 if self.showprofile:
119 119 width = 0.55
120 120 xw += width
121 121
122 122
123 123
124 124
125 125 self.xi = 0.15 + idplot*self.alpha
126 126
127 127 if self.showprofile:
128 128 width = 0.55
129 129 self.xw += width
130 130
131 131 else:
132 132 width = 0.65
133 133 self.xw += width
134 134
135 135 if self.colorbar:
136 136 self.xw = self.xw - 0.06
137 137
138 138
139 139 self.alpha = self.xw
140 140
141 141 yi = 0.20; yw = 0.75
142 142
143 143 return xi, yi, xw, yw
144 144
145 145 def getScreenPosGraph1(self):
146 146 if self.colorbar:
147 147 xi = self.xw + 0.08
148 148 else:
149 149 xi = self.xw + 0.05
150 150
151 151 xw = xi + 0.2
152 152
153 153 self.alpha = xw
154 154
155 155 if self.colorbar:
156 156 self.xi = 0.65 + 0.08
157 157 else:
158 158 self.xi = 0.75 + 0.05
159 159
160 160 xw = xi + 0.2
161 161
162 162 yi = 0.2; yw = 0.75
163 163
164 164 return xi, yi, xw, yw
165 165
166 166 def plot(self,x, y, data):
167 167 plotObj = self.plotObjList[0]
168 168 plotObj.plot(x,y,data)
169 169
170 170 if self.showprofile:
171 171 plotObj = self.plotObjList[1]
172 172 avg_data = numpy.average(data, axis=0)
173 173 plotObj.plot(avg_data,y)
174 174
175 175
176 176 class SpcFigure(Figure):
177 177 overplot = 0
178 178 xw = 900
179 179 yw = 650
180 180 showprofile = False
181 181
182 182 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
183 183 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
184 184
185 185 self.showprofile = showprofile
186 186
187 187 def getSubplots(self):
188 188 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
189 189 nrows = int(self.nframes*1./ncolumns + 0.9)
190 190
191 191 return nrows, ncolumns
192 192
193 193 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
194 194
195 195 if xmin == None: xmin = numpy.min(x)
196 196 if xmax == None: xmax = numpy.max(x)
197 197 if ymin == None: ymin = numpy.min(y)
198 198 if ymax == None: ymax = numpy.max(y)
199 199 if minvalue == None: minvalue = 20.
200 200 if maxvalue == None: maxvalue = 90.
201 201
202 202 self.xmin = xmin
203 203 self.xmax = xmax
204 204 self.minrange = ymin
205 205 self.maxrange = ymax
206 206 self.ymin = ymin
207 207 self.ymax = ymax
208 208 self.minvalue = minvalue
209 209 self.maxvalue = maxvalue
210 210
211 211
212 212 def changeXRange(self, *args):
213 213 pass
214 214
215 215 def createFrames(self):
216 216
217 217 self.frameObjList = []
218 218
219 219 for frame in range(self.nframes):
220 220 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
221 221 self.frameObjList.append(frameObj)
222 222
223 223 class SpcFrame(Frame):
224 224 def __init__(self,drvObj,idframe,colorbar,showprofile):
225 225 self.drvObj = drvObj
226 226 self.idframe = idframe
227 227 self.nplots = 1
228 228
229 229 if showprofile:
230 230 self.nplots += 1
231 231
232 232 self.colorbar = colorbar
233 233 self.showprofile = showprofile
234 234 self.createPlots()
235 235
236 236 def createPlots(self):
237 237 plotObjList = []
238 238 idplot = 0
239 239 xi, yi, xw, yw = self.getScreenPos(idplot)
240 240 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
241 241 plotObjList.append(plotObj)
242 242
243 243 if self.showprofile:
244 244 idplot = 1
245 245 xi, yi, xw, yw = self.getScreenPos(idplot)
246 246 type = "pwbox"
247 247 title = ""
248 248 xlabel = "dB"
249 249 ylabel = ""
250 250 szchar = 0.70
251 251 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar)
252 252 plotObjList.append(plotObj)
253 253
254 254 self.plotObjList = plotObjList
255 255
256 256 def getScreenPosMainPlot(self):
257 xi = 0.15
257
258 xi = 0.10
258 259
259 260 if self.showprofile:
260 xw = 0.55
261 xw = 0.62
261 262
262 263 else:
263 xw = 0.65
264 xw = 0.9
264 265
265 266 if self.colorbar:
266 267 xw = xw - 0.06
267 268
268 yi = 0.20; yw = 0.75
269 yi = 0.1; yw = 0.87
269 270
270 271 return xi, yi, xw, yw
271 272
272 273 def getScreenPosGraph1(self):
274
273 275 if self.colorbar:
274 276 xi = 0.65 + 0.08
275 277 else:
276 278 xi = 0.75 + 0.05
277 279
278 280 xw = xi + 0.2
279 281
280 yi = 0.2; yw = 0.75
282 yi = 0.1; yw = 0.87
281 283
282 284 return xi, yi, xw, yw
283 285
284 286 def plot(self,x, y, data):
285 287 plotObj = self.plotObjList[0]
286 288 plotObj.plot(x,y,data)
287 289
288 290 if self.showprofile:
289 291 plotObj = self.plotObjList[1]
290 292 avg_data = numpy.average(data, axis=0)
291 293 plotObj.plot(avg_data,y)
292 294
293 295 class SpcPlot(Plot):
294 296
295 297 getGrid = True
296 298
297 299 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
298 300 self.drvObj = drvObj
299 301 self.idframe = idframe
300 302 self.idplot = idplot
301 303 self.xi = xi
302 304 self.yi = yi
303 305 self.xw = xw
304 306 self.yw = yw
305 307 self.colorbar = colorbar
306 308
307 309 if self.colorbar:
308 310 cbxi = xw + 0.03
309 311 cbxw = cbxi + 0.03
310 312 cbyi = yi
311 313 cbyw = yw
312 314 self.cbxpos = [cbxi,cbxw]
313 315 self.cbypos = [cbyi,cbyw]
314 316
315 317 self.xpos = [self.xi,self.xw]
316 318 self.ypos = [self.yi,self.yw]
317 319 self.xaxisastime = False
318 320 self.timefmt = None
319 321 self.xopt = "bcnst"
320 322 self.yopt = "bcnstv"
321 323
322 324 self.szchar = 0.7
323 325 self.strforchannel = "Channel %d"%self.idframe
324 326 self.xlabel = "m/s"
325 327 self.ylabel = "Range (Km)"
326 328
327 329 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
328 330 self.xmin = xmin
329 331 self.xmax = xmax
330 332 self.ymin = ymin
331 333 self.ymax = ymax
332 334 self.minvalue = minvalue
333 335 self.maxvalue = maxvalue
334 336 self.colorbar = args[2]
335 337 self.title = "%s - %s"%(self.strforchannel,args[3])
336 338
337 339
338 340
339 341 def plot(self, x, y, data):
340 342 z = data
341 343 deltax = None
342 344 deltay = None
343 345 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
344 346 self.getGrid = False
345 347
346 348
347 349 class RTIFigure(Figure):
348 350 overplot = 1
349 351 xw = 700
350 352 yw = 650
351 353 showprofile = False
352 354 starttime = None
353 355 endtime = None
354 356 minrange = None
355 357 maxrange = None
356 358 minvalue = None
357 359 maxvalue = None
358 360 xrangestepinsecs = None
359 361 timefmt=None
360 362
361 363 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
362 364 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
363 365
364 366 self.showprofile = showprofile
365 367
366 368 def getSubplots(self):
367 369 nrows = self.nframes
368 370 ncolumns = 1
369 371 return nrows, ncolumns
370 372
371 373 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep, deltax):
372 374
373 375 self.starttime = xmin
374 376 self.endtime = xmax
375 377
376 378 cdatetime = datetime.datetime.utcfromtimestamp(x)
377 379
378 380 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
379 381
380 382 maxdatetime = mindatetime + datetime.timedelta(seconds=xrangestep)
381 383 self.xrangestepinsecs = xrangestep
382 384
383 385 xmin = time.mktime(mindatetime.timetuple())
384 386 xmax = time.mktime(maxdatetime.timetuple())
385 387
386 388 if self.xrangestepinsecs<=60.:
387 389 self.timefmt="%H:%M:%S"
388 390
389 391 if self.xrangestepinsecs>0. and self.xrangestepinsecs<=1200.:
390 392 self.timefmt="%H:%M:%S"
391 393
392 394 if self.xrangestepinsecs>1200. and self.xrangestepinsecs<=86400.:
393 395 self.timefmt="%H:%M"
394 396
395 397 if self.xrangestepinsecs>86400.:
396 398 self.timefmt="%y:%m:%d:%H"
397 399
398 400 if ymin == None: ymin = numpy.min(y)
399 401 if ymax == None: ymax = numpy.max(y)
400 402
401 403 if minvalue == None: minvalue = 0.
402 404 if maxvalue == None: maxvalue = 50.
403 405
404 406 self.xmin = xmin
405 407 self.xmax = xmax
406 408 self.minrange = ymin
407 409 self.maxrange = ymax
408 410 self.ymin = ymin
409 411 self.ymax = ymax
410 412 self.minvalue = minvalue
411 413 self.maxvalue = maxvalue
412 414 self.xrangestep = xrangestep
413 415 self.deltax = deltax
414 416
415 417 def changeXRange(self,x):
416 418
417 419 cdatetime = datetime.datetime.utcfromtimestamp(x)
418 420
419 421 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
420 422
421 423 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
422 424
423 425 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
424 426 self.xmax = self.xmin + self.xrangestepinsecs
425 427
426 428 self.figuretitle = "%s %s : %s"%(self.figuretitle,
427 429 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
428 430 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
429 431 return 1
430 432
431 433 return 0
432 434
433 435 def createFrames(self):
434 436
435 437 self.frameObjList = []
436 438
437 439 for frame in range(self.nframes):
438 440 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile, self.timefmt)
439 441 self.frameObjList.append(frameObj)
440 442
441 443 class RTIFrame(Frame):
442 444 def __init__(self,drvObj,idframe,colorbar,showprofile, timefmt):
443 445 self.drvObj = drvObj
444 446 self.idframe = idframe
445 447 self.nplots = 1
446 448
447 449 if showprofile:
448 450 self.nplots += 1
449 451
450 452 self.colorbar = colorbar
451 453 self.showprofile = showprofile
452 454 self.timefmt = timefmt
453 455 self.createPlots()
454 456
455 457 def createPlots(self):
456 458 plotObjList = []
457 459
458 460 idplot = 0
459 461 xi, yi, xw, yw = self.getScreenPos(idplot)
460 462
461 463 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar, self.timefmt)
462 464 plotObjList.append(plotObj)
463 465
464 466 if self.showprofile:
465 467 idplot = 1
466 468 xi, yi, xw, yw = self.getScreenPos(idplot)
467 469 type = "pwbox"
468 470 title = ""
469 471 xlabel = "dB"
470 472 ylabel = ""
471 473 szchar = 0.75
472 474 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar)
473 475 plotObjList.append(plotObj)
474 476
475 477 self.plotObjList = plotObjList
476 478
477 479 def getScreenPosMainPlot(self):
478 480 xi = 0.07
479 481 if self.showprofile:
480 482 xw = 0.65
481 483 else:
482 484 xw = 0.9
483 485
484 486 if self.colorbar:
485 487 xw = xw - 0.06
486 488
487 489 yi = 0.20; yw = 0.75
488 490
489 491 return xi, yi, xw, yw
490 492
491 493 def getScreenPosGraph1(self):
492 494 if self.colorbar:
493 495 xi = 0.65 + 0.08
494 496 else:
495 497 xi = 0.9 + 0.05
496 498
497 499 xw = xi + 0.2
498 500
499 501 yi = 0.2; yw = 0.75
500 502
501 503 return xi, yi, xw, yw
502 504
503 505 def plot(self, currenttime, range, data):
504 506 plotObj = self.plotObjList[0]
505 507 plotObj.plot(currenttime,range,data)
506 508
507 509 if self.showprofile:
508 510 plotObj = self.plotObjList[1]
509 511 plotObj.plot(data,range)
510 512
511 513
512 514 class RTIPlot(Plot):
513 515 deltax = None
514 516 deltay = None
515 517 xrange = [None,None]
516 518 xminpos = None
517 519 xmaxpos = None
518 520 xg = None
519 521 yg = None
520 522
521 523 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar, timefmt):
522 524 self.drvObj = drvObj
523 525 self.idframe = idframe
524 526 self.idplot = idplot
525 527 self.xi = xi
526 528 self.yi = yi
527 529 self.xw = xw
528 530 self.yw = yw
529 531 self.colorbar = colorbar
530 532
531 533 if self.colorbar:
532 534 cbxi = xw + 0.03
533 535 cbxw = cbxi + 0.03
534 536 cbyi = yi
535 537 cbyw = yw
536 538 self.cbxpos = [cbxi,cbxw]
537 539 self.cbypos = [cbyi,cbyw]
538 540
539 541 self.xpos = [self.xi,self.xw]
540 542 self.ypos = [self.yi,self.yw]
541 543 self.xaxisastime = True
542 544 self.timefmt = timefmt
543 545 self.xopt = "bcnstd"
544 546 self.yopt = "bcnstv"
545 547
546 548 self.szchar = 1.0
547 549 self.title = "Channel %d"%self.idframe
548 550 self.xlabel = "Local Time"
549 551 self.ylabel = "Range (Km)"
550 552
551 553
552 554 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
553 555 self.xmin = xmin
554 556 self.xmax = xmax
555 557 self.ymin = ymin
556 558 self.ymax = ymax
557 559 self.minvalue = minvalue
558 560 self.maxvalue = maxvalue
559 561 self.deltax = deltax
560 562 self.deltay = deltay
561 563 self.colorbar = colorbar
562 564
563 565 def plot(self, currenttime, range, data):
564 566
565 567 if self.xmaxpos == None:
566 568 self.xmaxpos = currenttime
567 569
568 570 # if currenttime >= self.xmaxpos:
569 571
570 572 self.xminpos = currenttime
571 573 self.xmaxpos = currenttime + self.deltax
572 574 x = [currenttime]
573 575 y = range
574 576 z = numpy.reshape(data, (1,-1))
575 577 getGrid = True
576 578
577 579 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
578 580
579 581
580 582 class ScopeFigure(Figure):
581 583 overplot = 0
582 584 xw = 700
583 585 yw = 650
584 586 colorbar = None
585 587
586 588 def __init__(self,idfigure,nframes,wintitle,driver):
587 589 colormap = None
588 590 colorbar = False
589 591
590 592 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
591 593
592 594
593 595 def getSubplots(self):
594 596 nrows = self.nframes
595 597 ncolumns = 1
596 598 return nrows, ncolumns
597 599
598 600 def createFrames(self):
599 601
600 602 self.frameObjList = []
601 603
602 604 for frame in range(self.nframes):
603 605 frameObj = ScopeFrame(self.drvObj,frame + 1)
604 606 self.frameObjList.append(frameObj)
605 607
606 608
607 609 class ScopeFrame(Frame):
608 610 xlabel = ""
609 611 ylabel = ""
610 612 title = ""
611 613 szchar = 1.1
612 614
613 615 def __init__(self,drvObj,idframe):
614 616 self.drvObj = drvObj
615 617 self.idframe = idframe
616 618 self.nplots = 1
617 619 self.createPlots()
618 620 # Frame.__init__(self, drvObj, idframe)
619 621
620 622 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
621 623 xi = 0.08; xw = 0.9
622 624 yi = 0.20; yw = 0.75
623 625 return xi,yi,xw,yw
624 626
625 627 def createPlots(self):
626 628 plotObjList = []
627 629 for idplot in range(self.nplots):
628 630 xi, yi, xw, yw = self.getScreenPos(idplot)
629 631 type = "scopebox"
630 632 title = "Channel %d"%self.idframe
631 633 xlabel = "range (Km)"
632 634 ylabel = "intensity"
633 635 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, self.szchar)
634 636 plotObjList.append(plotObj)
635 637
636 638 self.plotObjList = plotObjList
637 639
638 640
639 641 def plot(self, x, y, z=None):
640 642 for plotObj in self.plotObjList:
641 643 plotObj.plot(x, y)
642 644
643 645
644 646 class Plot1D(Plot):
645 647 # type, title, xlabel, ylabel
646 648 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar):
647 649 self.drvObj = drvObj
648 650 self.idframe = idframe
649 651 self.idplot = idplot
650 652 self.xi = xi
651 653 self.yi = yi
652 654 self.xw = xw
653 655 self.yw = yw
654 656 self.xpos = [self.xi,self.xw]
655 657 self.ypos = [self.yi,self.yw]
656 658 self.xaxisastime = False
657 659 self.timefmt = None
658 660 self.xopt = "bcnst"
659 661 self.yopt = "bcnstv"
660 662 self.szchar = szchar
661 663 self.type = type
662 664 self.title = title
663 665 self.xlabel = xlabel
664 666 self.ylabel = ylabel
665 667
666 668
667 669
668 670 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
669 671 if self.type == "pwbox":
670 672 self.xmin = minvalue
671 673 self.xmax = maxvalue
672 674 self.ymin = ymin
673 675 self.ymax = ymax
674 676 self.minvalue = minvalue
675 677 self.maxvalue = maxvalue
678 self.xopt = "bcnstg"
679 self.yopt = "bcmstv"
676 680
677 681 else:
678 682 self.xmin = xmin
679 683 self.xmax = xmax
680 684 self.ymin = ymin
681 685 self.ymax = ymax
682 686 self.minvalue = minvalue
683 687 self.maxvalue = maxvalue
684 688
685 689 self.colorbar = False
686 690
687 691 def plot(self,x,y):
688 692 if y.dtype == "complex128":
689 693 color="blue"
690 694 self.plotBasicLine(x, y.real, color)
691 695 color="red"
692 696 self.plotBasicLine(x, y.imag, color)
693 697 else:
694 698 color="blue"
695 699 self.plotBasicLine(x, y, color)
General Comments 0
You need to be logged in to leave comments. Login now