##// END OF EJS Templates
Nueva version para graficos Scope, RTI, Spectra. Se hicieron pruebas con los experimentos EwDRIFTS, MST, IMAGING
Daniel Valdez -
r141:1997872d9e6c
parent child
Show More
@@ -1,340 +1,344
1 1 import numpy
2 2 import datetime
3 3 from schainPlotLib import Driver
4 4
5 5 class Figure:
6 6 __isDriverOpen = False
7 7 __isFigureOpen = False
8 8 __isConfig = False
9 9 drvObj = None
10 10 idfigure = None
11 11 nframes = None
12 12 wintitle = None
13 13 colormap = None
14 14 driver = None
15 15 overplot = None
16 16 xmin = None
17 17 xmax = None
18 18 ymin = None
19 19 ymax = None
20 20 minvalue = None
21 21 maxvalue = None
22 22 deltax = None
23 23 deltay = None
24 24 frameObjList = []
25 25 figuretitle = ""
26 26 xrangestep = None
27 27
28 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', colormap=None, colorbar= True, *args):
29
30 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
31 self.driver = driver
29 32 self.idfigure = idfigure
30 self.nframes = nframes
31 self.wintitle = wintitle
32 33 self.xw = xw
33 34 self.yw = yw
35 self.nframes = nframes
36 self.wintitle = wintitle
37 self.colormap = colormap
34 38 self.overplot = overplot
35 39 self.colorbar = colorbar
36 self.colormap = colormap
37 #esta seccion deberia ser dinamica de acuerdo a len(args)
38 self.showGraph1 = args[0]
39 self.showGraph2 = args[1]
40
41 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap)
40 # self.showGraph1 = args[0]
41 # self.showGraph2 = args[1]
42 42
43 43 self.drvObj.driver.setFigure()
44 44 self.drvObj.driver.setColormap(colormap)
45 45
46
46 47
47 48 def __openDriver(self):
48 49 self.drvObj.driver.openDriver()
49
50 # def __openFigure(self):
51 # nrows, ncolumns = self.getSubplots()
52 # self.drvObj.driver.openFigure()
53 # self.drvObj.driver.setTitleFig(title)
54 # self.drvObj.driver.setSubPlots(nrows, ncolumns)
55 50
56 51 def __initFigure(self):
57 52 nrows, ncolumns = self.getSubplots()
58 53 self.drvObj.driver.openFigure()
59 54 self.drvObj.driver.setFigTitle(self.figuretitle)
60 55 self.drvObj.driver.setSubPlots(nrows, ncolumns)
61 56
62 57 def __isOutOfXRange(self,x):
63
64 if ((x>=self.xmin) and (x<self.xmax)):
58 try:
59 if ((x>=self.xmin) and (x<self.xmax)):
60 return 0
61 except:
65 62 return 0
66
63
67 64 return 1
68 65
69 66 def changeXRange(self,x):
70 67
71 68 pass
72 69
73 70 def __refresh(self):
74 71 self.drvObj.driver.refresh()
75 72
76 73 def createFrames(self):
77 74 raise ValueError, "No implemented"
78 75
79 76 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'):
80 77
81 78 nx, ny = data1D.shape
82 79
83 80 if channelList == None:
84 81 channelList = range(nx)
85 82
86 83 if x == None:
87 84 x = numpy.arange(data1D.size)
88 85
89 86 if figuretitle == None:
90 87 self.figuretitle = ""
91 88 else:
92 89 self.figuretitle = figuretitle
93 90
94 91 if not(self.__isDriverOpen):
95 92 self.__openDriver()
96 93 self.__isDriverOpen = True
97 94
98 95 if not(self.__isConfig):
99 96 self.xmin = xmin
100 97 self.xmax = xmax
101 98 self.minvalue = minvalue
102 99 self.maxvalue = maxvalue
103 100
104 101 if self.xmin == None: self.xmin = numpy.min(x)
105 102 if self.xmax == None: self.xmax = numpy.max(x)
106 103 if self.minvalue == None: self.minvalue = numpy.min(data1D)
107 104 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
108 105
109 106 self.createFrames()
110 107 self.__isConfig = True
111 108
112 109 if not(self.__isOutOfXRange(x)):
113 self.__changeXRange(x)
110 self.changeXRange(x)
114 111
115 112 if self.__isFigureOpen:
116 113 self.driverObj.closePage()
117 114 self.__isFigureOpen = False
118 115
119 116
120 117 self.__initFigure()
121 118
122 119 for channel in channelList:
123 120 frameObj = self.frameObjList[channel]
124 121 frameObj.init(xmin=self.xmin,
125 122 xmax=self.xmax,
126 123 ymin=self.minvalue,
127 124 ymax=self.maxvalue,
128 125 minvalue=self.minvalue,
129 126 maxvalue=self.maxvalue)
130 127
131 128 for channel in channelList:
132 129 dataCh = data1D[channel,:]
133 130 frameObj = self.frameObjList[channel]
134 131 # frameObj.clearData()
135 132 frameObj.plot(x, dataCh)
136 133
137 134 # frameObj.refresh()
138 135 self.__refresh()
139 136
140 137
141 138 #
142 139 # if save:
143 140 # self.colorplotObj.setFigure(indexPlot)
144 141 # path = "/home/roj-idl71/tmp/"
145 142 # now = datetime.datetime.now().timetuple()
146 143 # file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5])
147 144 # filename = os.path.join(path,file)
148 145 # self.colorplotObj.savePlot(indexPlot, filename)
149 146 #
150 147 # self.colorplotObj.closePage()
151 148
152 149
153 150 def plotPcolor(self,data,
154 151 x=None,
155 152 y=None,
156 153 channelList=None,
157 154 xmin=None,
158 155 xmax=None,
159 156 ymin=None,
160 157 ymax=None,
161 158 minvalue=None,
162 159 maxvalue=None,
163 160 figuretitle=None,
164 161 xrangestep=None,
165 162 save=False,
166 gpath='./'):
163 gpath='./',
164 clearData=False,
165 *args):
167 166
168 167
169 168 if figuretitle == None:
170 169 self.figuretitle = ""
171 170 else:
172 171 self.figuretitle = figuretitle
173 172
174 173
175 174
176 175 if not(self.__isDriverOpen):
177 176 self.__openDriver()
178 177 self.__isDriverOpen = True
179 178
180 179 if not(self.__isConfig):
181 180
182 181 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep)
183 182
184 183 self.createFrames()
185 184 self.__isConfig = True
186 185
187 186 if (self.__isOutOfXRange(x)):
188 187
189 188 if not(self.changeXRange(x)):
190 189 return 0
191 190
192 191 self.__isFigureOpen = False
193
194 # if self.__isFigureOpen:
195 # self.driverObj.closePage()
196 # self.__isFigureOpen = False
197 192
198 193 if not(self.__isFigureOpen):
199 194
200 195
201 196 self.__initFigure()
202 197 self.__isFigureOpen = True
203 198
204 199 for channel in channelList:
200 if len(args) != 0: value = args[0][channel]
201 else: value = args
202
205 203 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)
204 frameObj.init(self.xmin,
205 self.xmax,
206 self.ymin,
207 self.ymax,
208 self.minvalue,
209 self.maxvalue,
210 self.deltax,
211 self.deltay,
212 self.colorbar,
213 value)
214 214
215 215 for channel in channelList:
216 216 dataCh = data[channel,:]
217 217 frameObj = self.frameObjList[channel]
218 # frameObj.clearData()
219 218 frameObj.plot(x, y, dataCh)
220 219
221 # frameObj.refresh()
220
222 221 self.__refresh()
222 if clearData == True:
223 self.__isFigureOpen = False
223 224
224 225
225 226
226 227 class Frame:
227 228 nplots = None
228 229 plotObjList = []
229 230 title = ""
230 231
231 232 def __init__(self,drvObj, idframe):
232 233 self.drvObj = drvObj
233 234 self.idframe = idframe
234 235 self.createPlots()
235 236
236 237 def createPlots(self):
237 238 raise ValueError, "No implemented"
238 239
239 240 def getScreenPosMainPlot(self):
240 241 raise ValueError, "No implemented"
241 242
242 243 def getScreenPosGraph1(self):
243 244 raise ValueError, "No implemented"
244 245
245 246 def getScreenPos(self, nplot):
246 247
247 248 if nplot == 0:
248 249 xi, yi, xw, yw = self.getScreenPosMainPlot()
249 250
250 251 if nplot == 1:
251 252 xi, yi, xw, yw = self.getScreenPosGraph1()
252 253
253 254 return xi, yi, xw, yw
254 255
255 256
256 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None):
257 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
257 258
258 259 for plotObj in self.plotObjList:
259 plotObj.plotBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay)
260 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
261 plotObj.plotBox()
262
260 263
261 264
262 265 class Plot:
263 266 title = ""
264 267 xlabel = ""
265 268 ylabel = ""
266 269 xaxisastime = None
267 270 timefmt = None
268 271 xopt = ""
269 272 yopt = ""
270 273 xpos = None
271 274 ypos = None
272 275 szchar = None
273 276 idframe = None
274 277 idplot = None
278 colorbar = None
279 cbxpos = None
280 cbypos = None
275 281
276 282 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
277 283 self.drvObj = drvObj
278 284 self.idframe = idframe
279 285 self.idplot = idplot
280 286 self.xi = xi
281 287 self.yi = yi
282 288 self.xw = xw
283 289 self.yw = yw
284 290
285 def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue):
286 self.xmin = xmin
287 self.xmax = xmax
288 self.ymin = ymin
289 self.ymax = ymax
290 self.minvalue = minvalue
291 self.maxvalue = maxvalue
291
292 def plotBox(self):
292 293
293 294 self.drvObj.driver.plotBox(self.idframe,
294 295 self.xpos,
295 296 self.ypos,
296 297 self.xmin,
297 298 self.xmax,
298 299 self.ymin,
299 300 self.ymax,
300 301 self.minvalue,
301 302 self.maxvalue,
302 303 self.xopt,
303 304 self.yopt,
304 305 self.szchar,
305 306 self.xaxisastime,
306 307 self.timefmt)
307 308
308 309 self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title)
310
311 if self.colorbar:
312 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
309 313
310 314 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
311 315
312 316 self.drvObj.driver.pcolor(self.idframe,
313 317 self.xpos,
314 318 self.ypos,
315 319 z,
316 320 x,
317 321 y,
318 322 self.xmin,
319 323 self.xmax,
320 324 self.ymin,
321 325 self.ymax,
322 326 self.minvalue,
323 327 self.maxvalue,
324 328 deltax,
325 329 deltay,
326 330 getGrid,
327 331 self.xaxisastime,
328 332 self.timefmt)
329 333
330 334 def plotBasicLine(self,x, y, color):
331 335 """
332 336 Inputs:
333 337 x:
334 338
335 339 y:
336 340
337 341 color:
338 342 """
339 343 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
340 344 No newline at end of file
@@ -1,412 +1,415
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, colorbar):
8 8 if driver == "plplot":
9 9 self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
10 10 elif driver == "mpl":
11 11 self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
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 __xg = None
20 20 __yg = None
21 21 def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
22 22
23 23 if idfigure == None:
24 24 raise ValueError, 'idfigure input must be defined'
25 25
26 26 self.idfigure = idfigure
27 27 self.xw = xw
28 28 self.yw = yw
29 29 self.wintitle = wintitle
30 30 self.overplot = overplot
31 31 self.colormap = colormap
32 32 self.colorbar = colorbar
33 33
34 34 def setFigure(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 41
42 42
43 43 def openDriver(self, pldriver=None):
44 44 if pldriver == None:
45 45 if sys.platform == "linux":
46 46 pldriver = "xcairo"
47 47
48 48 if sys.platform == "linux2":
49 49 pldriver = "xcairo"
50 50
51 51 elif sys.platform == "darwin":
52 52 pldriver = "xwin"
53 53
54 54 else:
55 55 pldriver = ""
56 56
57 57 plplot.plsdev("xwin") #para pruebas
58 58 plplot.plscolbg(255,255,255)
59 59 plplot.plscol0(1,0,0,0)
60 60 plplot.plinit()
61 61 plplot.plspause(False)
62 62
63 63 self.pldriver = pldriver
64 64
65 65 def closeDriver(self):
66 66 pass
67 67
68 68 def openPage(self):
69 69 plplot.plbop()
70 70 plplot.pladv(0)
71 71
72 72 def closePage(self):
73 73 plplot.pleop()
74 74
75 75 def openFigure(self):
76 76 plplot.plbop()
77 77 plplot.pladv(0)
78 78
79 79 def closeFigure(self):
80 80 plplot.pleop()
81 81
82 82 def setSubPlots(self,nrows, ncolumns):
83 83 plplot.plssub(ncolumns,nrows)
84 84
85 85 def setPlotLabels(self, xlabel, ylabel, title):
86 86 plplot.pllab(xlabel, ylabel, title)
87 87
88 88 def setFigTitle(self, title,color="black", szchar=0.55):
89 89 self.setSubPlots(1, 0)
90 90 plplot.pladv(0)
91 91 plplot.plvpor(0., 1., 0., 1.)
92 92
93 93 if color == "black":
94 94 plplot.plcol0(1)
95 95 if color == "white":
96 96 plplot.plcol0(15)
97 97
98 98 plplot.plschr(0.0,szchar)
99 99 plplot.plmtex("t",-1., 0.5, 0.5, title)
100 100
101 101 def plotColorbar(self, minvalue, maxvalue, xpos, ypos):
102 102 # plplot.pladv(id)
103 103 # plplot.plschr(0.0,szchar-0.05)
104 104 xmin = 0; xmax = 1
105 105 ymin = minvalue; ymax = maxvalue
106 106 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
107 107 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
108 108 plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0)
109 109
110 110 data = numpy.arange(256)
111 111 data = numpy.reshape(data, (1,-1))
112 112
113 113 plplot.plimage(data,
114 114 float(xmin),
115 115 float(xmax),
116 116 float(ymin),
117 117 float(ymax),
118 118 0.,
119 119 255.,
120 120 float(xmin),
121 121 float(xmax),
122 122 float(ymin),
123 123 float(ymax))
124 124
125 125
126 126 def __getGrid(self, x, y, deltax=None, deltay=None):
127 127
128 128 if not(len(x)>0 and len(y)>0):
129 129 raise ValueError, "x axis and y axis are empty"
130 130
131 131 if deltax == None: deltax = x[-1] - x[-2]
132 132 if deltay == None: deltay = y[-1] - y[-2]
133 133
134 134 x1 = numpy.append(x, x[-1] + deltax)
135 135 y1 = numpy.append(y, y[-1] + deltay)
136 136
137 137 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
138 138 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
139 139
140 140 return xg, yg
141 141
142 142
143 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 144
145 145 plplot.pladv(id)
146 146 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
147 147 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
148 148
149 149 if xaxisastime:
150 150 timedelta = (xmax - xmin + 1)/8.
151 151
152 152 if getGrid:
153 153 self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay)
154 154
155 if deltax == None: deltax = x[-1] - x[0]
156 # if deltay == None: deltay = y[-1] - y[-2]
157
155 158 xmin = x[0]
156 159 xmax = xmin + deltax
157 160
158 161 plplot.plimagefr(data,
159 162 float(xmin),
160 163 float(xmax),
161 164 float(ymin),
162 165 float(ymax),
163 166 0.,
164 167 0.,
165 168 float(zmin),
166 169 float(zmax),
167 170 plplot.pltr2,
168 171 self.__xg,
169 172 self.__yg)
170 173
171 174 if xaxisastime:
172 175 plplot.pltimefmt(timefmt)
173 176 xopt = "bcstd"
174 177 yopt = "bcst"
175 178 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
176 179 else:
177 180 xopt = "bcst"
178 181 yopt = "bcst"
179 182 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
180 183
181 184
182 185 def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"):
183 186 """
184 187 xopt, yopt: entradas que no se aplican en MPL
185 188 """
186 189 plplot.pladv(id)
187 190 plplot.plschr(0.0,szchar-0.05)
188 191 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
189 192 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
190 193 if xaxisastime:
191 194 plplot.pltimefmt(timefmt)
192 195 timedelta = (xmax - xmin + 1)/8.
193 196 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
194 197 else:
195 198 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
196 199
197 200 def refresh(self):
198 201 plplot.plflush()
199 202
200 203 def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color):
201 204
202 205 """
203 206 Inputs:
204 207 x: datos en el eje x
205 208
206 209 y: datos en el eje y
207 210
208 211 xmin, xmax: intervalo de datos en el eje x
209 212
210 213 ymin, ymax: intervalo de datos en el eje y
211 214
212 215 color: color de la linea a dibujarse
213 216
214 217 id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada
215 218 plot esta definido por xpos, ypos.
216 219
217 220 xpos,ypos: coordenadas que indican la posicion del plot en el frame
218 221
219 222 """
220 223
221 224 plplot.pladv(id)
222 225 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
223 226 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
224 227
225 228 if color == "blue":
226 229 colline = 9
227 230 if color == "green":
228 231 colline = 3
229 232
230 233 plplot.plcol0(colline)
231 234 plplot.plline(x, y)
232 235 plplot.plcol0(1)
233 236 plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0)
234 237
235 238 def setColormap(self, colormap="gray"):
236 239
237 240 if colormap == None:
238 241 return
239 242
240 243 ncolor = None
241 244 rgb_lvl = None
242 245
243 246 # Routine for defining a specific color map 1 in HLS space.
244 247 # if gray is true, use basic grayscale variation from half-dark to light.
245 248 # otherwise use false color variation from blue (240 deg) to red (360 deg).
246 249
247 250 # Independent variable of control points.
248 251 i = numpy.array((0., 1.))
249 252 if colormap=="gray":
250 253 ncolor = 256
251 254 # Hue for control points. Doesn't matter since saturation is zero.
252 255 h = numpy.array((0., 0.))
253 256 # Lightness ranging from half-dark (for interest) to light.
254 257 l = numpy.array((0.5, 1.))
255 258 # Gray scale has zero saturation
256 259 s = numpy.array((0., 0.))
257 260
258 261 # number of cmap1 colours is 256 in this case.
259 262 plplot.plscmap1n(ncolor)
260 263 # Interpolate between control points to set up cmap1.
261 264 plplot.plscmap1l(0, i, h, l, s)
262 265
263 266 return None
264 267
265 268 if colormap == 'jet':
266 269 ncolor = 256
267 270 pos = numpy.zeros((ncolor))
268 271 r = numpy.zeros((ncolor))
269 272 g = numpy.zeros((ncolor))
270 273 b = numpy.zeros((ncolor))
271 274
272 275 for i in range(ncolor):
273 276 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
274 277 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
275 278 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
276 279 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
277 280
278 281 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
279 282 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
280 283 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
281 284 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
282 285 else: gf = 0.0
283 286
284 287 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
285 288 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
286 289 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
287 290 else: bf = 0
288 291
289 292 r[i] = rf
290 293 g[i] = gf
291 294 b[i] = bf
292 295
293 296 pos[i] = float(i)/float(ncolor-1)
294 297
295 298
296 299 plplot.plscmap1n(ncolor)
297 300 plplot.plscmap1l(1, pos, r, g, b)
298 301
299 302
300 303
301 304 if colormap=="br_green":
302 305 ncolor = 256
303 306 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
304 307 h = numpy.array((240., 0.))
305 308 # Lightness and saturation are constant (values taken from C example).
306 309 l = numpy.array((0.6, 0.6))
307 310 s = numpy.array((0.8, 0.8))
308 311
309 312 # number of cmap1 colours is 256 in this case.
310 313 plplot.plscmap1n(ncolor)
311 314 # Interpolate between control points to set up cmap1.
312 315 plplot.plscmap1l(0, i, h, l, s)
313 316
314 317 return None
315 318
316 319 if colormap=="tricolor":
317 320 ncolor = 3
318 321 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
319 322 h = numpy.array((240., 0.))
320 323 # Lightness and saturation are constant (values taken from C example).
321 324 l = numpy.array((0.6, 0.6))
322 325 s = numpy.array((0.8, 0.8))
323 326
324 327 # number of cmap1 colours is 256 in this case.
325 328 plplot.plscmap1n(ncolor)
326 329 # Interpolate between control points to set up cmap1.
327 330 plplot.plscmap1l(0, i, h, l, s)
328 331
329 332 return None
330 333
331 334 if colormap == 'rgb' or colormap == 'rgb666':
332 335
333 336 color_sz = 6
334 337 ncolor = color_sz*color_sz*color_sz
335 338 pos = numpy.zeros((ncolor))
336 339 r = numpy.zeros((ncolor))
337 340 g = numpy.zeros((ncolor))
338 341 b = numpy.zeros((ncolor))
339 342 ind = 0
340 343 for ri in range(color_sz):
341 344 for gi in range(color_sz):
342 345 for bi in range(color_sz):
343 346 r[ind] = ri/(color_sz-1.0)
344 347 g[ind] = gi/(color_sz-1.0)
345 348 b[ind] = bi/(color_sz-1.0)
346 349 pos[ind] = ind/(ncolor-1.0)
347 350 ind += 1
348 351 rgb_lvl = [6,6,6] #Levels for RGB colors
349 352
350 353 if colormap == 'rgb676':
351 354 ncolor = 6*7*6
352 355 pos = numpy.zeros((ncolor))
353 356 r = numpy.zeros((ncolor))
354 357 g = numpy.zeros((ncolor))
355 358 b = numpy.zeros((ncolor))
356 359 ind = 0
357 360 for ri in range(8):
358 361 for gi in range(8):
359 362 for bi in range(4):
360 363 r[ind] = ri/(6-1.0)
361 364 g[ind] = gi/(7-1.0)
362 365 b[ind] = bi/(6-1.0)
363 366 pos[ind] = ind/(ncolor-1.0)
364 367 ind += 1
365 368 rgb_lvl = [6,7,6] #Levels for RGB colors
366 369
367 370 if colormap == 'rgb685':
368 371 ncolor = 6*8*5
369 372 pos = numpy.zeros((ncolor))
370 373 r = numpy.zeros((ncolor))
371 374 g = numpy.zeros((ncolor))
372 375 b = numpy.zeros((ncolor))
373 376 ind = 0
374 377 for ri in range(8):
375 378 for gi in range(8):
376 379 for bi in range(4):
377 380 r[ind] = ri/(6-1.0)
378 381 g[ind] = gi/(8-1.0)
379 382 b[ind] = bi/(5-1.0)
380 383 pos[ind] = ind/(ncolor-1.0)
381 384 ind += 1
382 385 rgb_lvl = [6,8,5] #Levels for RGB colors
383 386
384 387 if colormap == 'rgb884':
385 388 ncolor = 8*8*4
386 389 pos = numpy.zeros((ncolor))
387 390 r = numpy.zeros((ncolor))
388 391 g = numpy.zeros((ncolor))
389 392 b = numpy.zeros((ncolor))
390 393 ind = 0
391 394 for ri in range(8):
392 395 for gi in range(8):
393 396 for bi in range(4):
394 397 r[ind] = ri/(8-1.0)
395 398 g[ind] = gi/(8-1.0)
396 399 b[ind] = bi/(4-1.0)
397 400 pos[ind] = ind/(ncolor-1.0)
398 401 ind += 1
399 402 rgb_lvl = [8,8,4] #Levels for RGB colors
400 403
401 404 if ncolor == None:
402 405 raise ValueError, "The colormap selected is not valid"
403 406
404 407 plplot.plscmap1n(ncolor)
405 408 plplot.plscmap1l(1, pos, r, g, b)
406 409
407 410 return rgb_lvl
408 411
409 412
410 413 class MplDriver:
411 414 def __init__(self):
412 415 pass No newline at end of file
@@ -1,373 +1,529
1 1 import numpy
2 2 import datetime
3 3 import time
4 4 from schainPlot import *
5 #from schainPlotLib import Driver
5
6 class SpcFigure(Figure):
7 overplot = 0
8 xw = 800
9 yw = 650
10 showprofile = False
11
12 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
13 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
14
15 self.showprofile = showprofile
16
17 def getSubplots(self):
18 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
19 nrows = int(self.nframes*1./ncolumns + 0.9)
20
21 return nrows, ncolumns
22
23 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
24
25 if xmin == None: xmin = numpy.min(x)
26 if xmax == None: xmax = numpy.max(x)
27 if ymin == None: ymin = numpy.min(y)
28 if ymax == None: ymax = numpy.max(y)
29 if minvalue == None: minvalue = 20.
30 if maxvalue == None: maxvalue = 90.
31
32 self.xmin = xmin
33 self.xmax = xmax
34 self.minrange = ymin
35 self.maxrange = ymax
36 self.ymin = ymin
37 self.ymax = ymax
38 self.minvalue = minvalue
39 self.maxvalue = maxvalue
40
41
42 def changeXRange(self, *args):
43 pass
44
45 def createFrames(self):
46 for frame in range(self.nframes):
47 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
48 self.frameObjList.append(frameObj)
49
50 class SpcFrame(Frame):
51 def __init__(self,drvObj,idframe,colorbar,showprofile):
52 self.drvObj = drvObj
53 self.idframe = idframe
54 self.nplots = 1
55
56 if showprofile:
57 self.nplots += 1
58
59 self.colorbar = colorbar
60 self.showprofile = showprofile
61 self.createPlots()
62
63 def createPlots(self):
64 plotObjList = []
65 idplot = 0
66 xi, yi, xw, yw = self.getScreenPos(idplot)
67 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
68 plotObjList.append(plotObj)
69
70 if self.showprofile:
71 idplot = 1
72 xi, yi, xw, yw = self.getScreenPos(idplot)
73 type = "pwbox"
74 title = ""
75 xlabel = "dB"
76 ylabel = ""
77 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
78 plotObjList.append(plotObj)
79
80 self.plotObjList = plotObjList
81
82 def getScreenPosMainPlot(self):
83 xi = 0.15
84
85 if self.showprofile:
86 xw = 0.65
87
88 else:
89 xw = 0.75
90
91 if self.colorbar:
92 xw = xw - 0.06
93
94 yi = 0.20; yw = 0.75
95
96 return xi, yi, xw, yw
97
98 def getScreenPosGraph1(self):
99 if self.colorbar:
100 xi = 0.65 + 0.08
101 else:
102 xi = 0.75 + 0.05
103
104 xw = xi + 0.2
105
106 yi = 0.2; yw = 0.75
107
108 return xi, yi, xw, yw
109
110 def plot(self,x, y, data):
111 plotObj = self.plotObjList[0]
112 plotObj.plot(x,y,data)
113
114 if self.showprofile:
115 plotObj = self.plotObjList[1]
116 plotObj.plot(data,y)
117
118 class SpcPlot(Plot):
119
120 getGrid = True
121
122 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
123 self.drvObj = drvObj
124 self.idframe = idframe
125 self.idplot = idplot
126 self.xi = xi
127 self.yi = yi
128 self.xw = xw
129 self.yw = yw
130 self.colorbar = colorbar
131
132 if self.colorbar:
133 cbxi = xw + 0.03
134 cbxw = cbxi + 0.03
135 cbyi = yi
136 cbyw = yw
137 self.cbxpos = [cbxi,cbxw]
138 self.cbypos = [cbyi,cbyw]
139
140 self.xpos = [self.xi,self.xw]
141 self.ypos = [self.yi,self.yw]
142 self.xaxisastime = False
143 self.timefmt = None
144 self.xopt = "bcnst"
145 self.yopt = "bcnstv"
146
147 self.szchar = 0.8
148 self.strforchannel = "Channel %d"%self.idframe
149 self.xlabel = "m/s"
150 self.ylabel = "Range (Km)"
151
152 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
153 self.xmin = xmin
154 self.xmax = xmax
155 self.ymin = ymin
156 self.ymax = ymax
157 self.minvalue = minvalue
158 self.maxvalue = maxvalue
159 self.colorbar = args[2]
160 self.title = "%s - %s"%(self.strforchannel,args[3])
161
162
163
164 def plot(self, x, y, data):
165 z = data
166 deltax = None
167 deltay = None
168 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
169 self.getGrid = False
6 170
7 171
8 172 class RTIFigure(Figure):
9 173 overplot = 1
10 174 xw = 700
11 175 yw = 650
12 176 showprofile = False
13 177 starttime = None
14 178 endtime = None
15 179 minrange = None
16 180 maxrange = None
17 181 minvalue = None
18 182 maxvalue = None
19 183 xrangestepinsecs = None
20 184
21 185
22 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
23 self.idfigure = idfigure
24 self.nframes = nframes
25 self.wintitle = wintitle
26 self.colormap = colormap
27 self.colorbar = colorbar
186 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
187 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
188
28 189 self.showprofile = showprofile
29 self.driver = driver
30 self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar)
31 self.drvObj.driver.setFigure()
32 self.drvObj.driver.setColormap(colormap)
33
190
34 191 def getSubplots(self):
35 192 nrows = self.nframes
36 193 ncolumns = 1
37 194 return nrows, ncolumns
38 195
39 196 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep):
40 197
41 198 self.starttime = xmin
42 199 self.endtime = xmax
43 200
44 cdatetime = datetime.datetime.utcfromtimestamp(x) #siempre en localtime
201 cdatetime = datetime.datetime.utcfromtimestamp(x)
45 202
46 203 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
47 204 if ((xrangestep == 0) or (xrangestep == None)):
48 205 maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second)
49 206 self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple())
50 207 npoints = 1000.
51 208 if xrangestep == 1:
52 209 maxdatetime = mindatetime + datetime.timedelta(hours=1)
53 210 self.xrangestepinsecs = 60*60.
54 211 npoints = 500.
55 212 if xrangestep == 2:
56 213 maxdatetime = mindatetime + datetime.timedelta(minutes=1)
57 214 self.xrangestepinsecs = 60.
58 215 npoints = 250.
59 216 if xrangestep == 3:
60 217 maxdatetime = mindatetime + datetime.timedelta(seconds=1)
61 218 self.xrangestepinsecs = 1.
62 219 npoints = 125.
63 220
64 221 xmin = time.mktime(mindatetime.timetuple())
65 222 xmax = time.mktime(maxdatetime.timetuple())
66 223
67 224 deltax = (xmax-xmin) / npoints
68 225
69 226
70 227 if ymin == None: ymin = numpy.min(y)
71 228 if ymax == None: ymax = numpy.max(y)
72 229
73 230 if minvalue == None: minvalue = 0.
74 231 if maxvalue == None: maxvalue = 50.
75 232
76 233 self.xmin = xmin
77 234 self.xmax = xmax
78 235 self.minrange = ymin
79 236 self.maxrange = ymax
80 237 self.ymin = ymin
81 238 self.ymax = ymax
82 239 self.minvalue = minvalue
83 240 self.maxvalue = maxvalue
84 241 self.xrangestep = xrangestep
85 242 self.deltax = deltax
86
87
243
88 244 def changeXRange(self,x):
89 245
90 cdatetime = datetime.datetime.utcfromtimestamp(x) #siempre en localtime
246 cdatetime = datetime.datetime.utcfromtimestamp(x)
91 247
92 248 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
93 249 if self.xrangestep == 1:
94 250 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second)
95 251
96 252 if self.xrangestep == 2:
97 253 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second)
98 254
99 255 if self.xrangestep == 3:
100 256 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
101 257
102 # mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
103 258 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
104 259 self.xmax = self.xmin + self.xrangestepinsecs
105 260
106 self.figuretitle = "%s: %s - %s"%(self.figuretitle,
261 self.figuretitle = "%s %s : %s"%(self.figuretitle,
107 262 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
108 263 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
109
110
111 264 return 1
112 265
113 266 return 0
114
115 267
116 268 def createFrames(self):
117 269 for frame in range(self.nframes):
118 270 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
119 271 self.frameObjList.append(frameObj)
120 272
121 273 class RTIFrame(Frame):
122 274 def __init__(self,drvObj,idframe,colorbar,showprofile):
123 275 self.drvObj = drvObj
124 276 self.idframe = idframe
125 277 self.nplots = 1
126 278
127 279 if showprofile:
128 280 self.nplots += 1
129 281
130 282 self.colorbar = colorbar
131 283 self.showprofile = showprofile
132 284 self.createPlots()
133 285
134 286 def createPlots(self):
135 287 plotObjList = []
136 288
137 289 idplot = 0
138 290 xi, yi, xw, yw = self.getScreenPos(idplot)
291
139 292 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
140 293 plotObjList.append(plotObj)
141 294
142 295 if self.showprofile:
143 296 idplot = 1
144 297 xi, yi, xw, yw = self.getScreenPos(idplot)
145 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw)
298 type = "pwbox"
299 title = ""
300 xlabel = "dB"
301 ylabel = ""
302 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
146 303 plotObjList.append(plotObj)
147 304
148 305 self.plotObjList = plotObjList
149 306
150 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
307 def getScreenPosMainPlot(self):
151 308 xi = 0.07
152
153 309 if self.showprofile:
154 310 xw = 0.65
155
156 311 else:
157 312 xw = 0.9
158 313
159 314 if self.colorbar:
160 315 xw = xw - 0.06
161 316
162 317 yi = 0.20; yw = 0.75
163 318
164 319 return xi, yi, xw, yw
165 320
166 321 def getScreenPosGraph1(self):
167 322 if self.colorbar:
168 xi = 0.65 + 0.05
323 xi = 0.65 + 0.08
169 324 else:
170 325 xi = 0.9 + 0.05
171 326
172 327 xw = xi + 0.2
173 328
174 329 yi = 0.2; yw = 0.75
175 330
176 331 return xi, yi, xw, yw
177 332
178 333 def plot(self, currenttime, range, data):
179 # for plotObj in self.plotObjList:
180 # plotObj.plot(currenttime, range, data)
181
182 334 plotObj = self.plotObjList[0]
183 335 plotObj.plot(currenttime,range,data)
184 336
185 337 if self.showprofile:
186 338 plotObj = self.plotObjList[1]
187 339 plotObj.plot(data,range)
188 340
189 341
190 342 class RTIPlot(Plot):
191 343 deltax = None
192 344 deltay = None
193 345 xrange = [None,None]
194 346 xminpos = None
195 347 xmaxpos = None
196 348 xg = None
197 349 yg = None
198 350
199 351 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
200 352 self.drvObj = drvObj
201 353 self.idframe = idframe
202 354 self.idplot = idplot
203 355 self.xi = xi
204 356 self.yi = yi
205 357 self.xw = xw
206 358 self.yw = yw
207 359 self.colorbar = colorbar
208 360
209 361 if self.colorbar:
210 362 cbxi = xw + 0.03
211 363 cbxw = cbxi + 0.03
212 364 cbyi = yi
213 365 cbyw = yw
214 366 self.cbxpos = [cbxi,cbxw]
215 367 self.cbypos = [cbyi,cbyw]
216 368
217 369 self.xpos = [self.xi,self.xw]
218 370 self.ypos = [self.yi,self.yw]
219 371 self.xaxisastime = True
220 372 self.timefmt = "%H:%M"
221 373 self.xopt = "bcnstd"
222 374 self.yopt = "bcnstv"
223 375
224 376 self.szchar = 1.0
225 377 self.title = "Channel %d"%self.idframe
226 378 self.xlabel = "Local Time"
227 379 self.ylabel = "Range (Km)"
228 380
229 381
230 def plotBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None):
382 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
231 383 self.xmin = xmin
232 384 self.xmax = xmax
233 385 self.ymin = ymin
234 386 self.ymax = ymax
235 387 self.minvalue = minvalue
236 388 self.maxvalue = maxvalue
237 389 self.deltax = deltax
238 390 self.deltay = deltay
239
240 self.drvObj.driver.plotBox(self.idframe,
241 self.xpos,
242 self.ypos,
243 self.xmin,
244 self.xmax,
245 self.ymin,
246 self.ymax,
247 self.minvalue,
248 self.maxvalue,
249 self.xopt,
250 self.yopt,
251 self.szchar,
252 self.xaxisastime,
253 self.timefmt)
254
255 self.drvObj.driver.setPlotLabels(self.xlabel, self.ylabel, self.title)
256
257 if self.colorbar:
258 self.drvObj.driver.plotColorbar(minvalue, maxvalue, self.cbxpos,self.cbypos)
259
260
391 self.colorbar = colorbar
261 392
262 393 def plot(self, currenttime, range, data):
263 394
264 395 if self.xmaxpos == None:
265 396 self.xmaxpos = currenttime
266 397
267 398 if currenttime >= self.xmaxpos:
268 399
269 400 self.xminpos = currenttime
270 401 self.xmaxpos = currenttime + self.deltax
271 402 x = [currenttime]
272 403 y = range
273 404 z = numpy.reshape(data, (1,-1))
274 405 getGrid = True
275 406
276 407 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
277 408
278 409
279 410 class ScopeFigure(Figure):
280 411 overplot = 0
281 412 xw = 700
282 413 yw = 650
283 414 colorbar = None
284 415
285 416 def __init__(self,idfigure,nframes,wintitle,driver):
286 417 colormap = None
287 418 colorbar = False
288 419
289 420 self.idfigure = idfigure
290 421 self.nframes = nframes
291 422 self.wintitle = wintitle
292 423
293 424 self.colormap = colormap
294 425 self.colorbar = colorbar
295 426 self.driver = driver
296 427 self.drvObj = Driver(self.driver, self.idfigure, self.xw, self.yw, self.wintitle, self.overplot, self.colormap, self.colorbar)
297 428 self.drvObj.driver.setFigure()
298 429
299 430 # Figure.__init__(self,idfigure,nframes,wintitle,self.xw,self.yw,self.overplot,driver,colorbar,colormap,*args)
300 431
301 432 def getSubplots(self):
302 433 nrows = self.nframes
303 434 ncolumns = 1
304 435 return nrows, ncolumns
305 436
306 437 def createFrames(self):
307 438 for frame in range(self.nframes):
308 439 frameObj = ScopeFrame(self.drvObj,frame + 1)
309 440 self.frameObjList.append(frameObj)
310 441
311 442
312 443 class ScopeFrame(Frame):
313 444 # plotObjList = []
314 445 xlabel = ""
315 446 ylabel = ""
316 447 title = ""
317 448 def __init__(self,drvObj,idframe):
318 449 self.drvObj = drvObj
319 450 self.idframe = idframe
320 451 self.nplots = 1 #nplots/frame
321 452 self.createPlots()
322 453 # Frame.__init__(self, drvObj, idframe)
323 454
324 455 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
325 456 xi = 0.07; xw = 0.9
326 457 yi = 0.20; yw = 0.75
327 458 return xi,yi,xw,yw
328 459
329 460 def createPlots(self):
330 461 plotObjList = []
331 462 for idplot in range(self.nplots):
332 463 xi, yi, xw, yw = self.getScreenPos(idplot)
333 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw)
464 type = "scopebox"
465 title = "Channel %d"%self.idframe
466 xlabel = "range (Km)"
467 ylabel = "intensity"
468 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
334 469 plotObjList.append(plotObj)
335 470 self.plotObjList = plotObjList
336 471 # self.plotObjList.append(plotObj)
337 472
338 473 def plot(self, x, y, z=None):
339 474 for plotObj in self.plotObjList:
340 475 plotObj.plot(x, y)
341 476
342 477
343 478 class Plot1D(Plot):
344
345 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
479 # type, title, xlabel, ylabel
480 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel):
346 481 self.drvObj = drvObj
347 482 self.idframe = idframe
348 483 self.idplot = idplot
349 484 self.xi = xi
350 485 self.yi = yi
351 486 self.xw = xw
352 487 self.yw = yw
353 488 self.xpos = [self.xi,self.xw]
354 489 self.ypos = [self.yi,self.yw]
355 490 self.xaxisastime = False
356 491 self.timefmt = None
357 492 self.xopt = "bcnst"
358 493 self.yopt = "bcnstv"
359 494 self.szchar = 1.0
360 self.title = "Channel %d"%self.idframe
361 self.xlabel = "x-axis"
362 self.ylabel = "y-axis"
495 self.type = type
496 self.title = title
497 self.xlabel = xlabel
498 self.ylabel = ylabel
499
363 500
501
502 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
503 if self.type == "pwbox":
504 self.xmin = minvalue
505 self.xmax = maxvalue
506 self.ymin = ymin
507 self.ymax = ymax
508 self.minvalue = minvalue
509 self.maxvalue = maxvalue
510
511 else:
512 self.xmin = xmin
513 self.xmax = xmax
514 self.ymin = ymin
515 self.ymax = ymax
516 self.minvalue = minvalue
517 self.maxvalue = maxvalue
518
519 self.colorbar = False
364 520
365 521 def plot(self,x,y):
366 522 if y.dtype == "complex128":
367 523 color="blue"
368 524 self.plotBasicLine(x, y.real, color)
369 525 color="red"
370 526 self.plotBasicLine(x, y.imag, color)
371 527 else:
372 528 color="blue"
373 529 self.plotBasicLine(x, y, color)
@@ -1,388 +1,371
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import numpy
9 9 import time
10
10 import datetime
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from Data.JROData import Spectra
15 15 from IO.SpectraIO import SpectraWriter
16 #from Graphics.SpectraPlot import Spectrum
16 from Graphics.schainPlotTypes import SpcFigure
17 17 #from JRONoise import Noise
18 18
19 19 class SpectraProcessor:
20 20 '''
21 21 classdocs
22 22 '''
23 23
24 24 dataInObj = None
25 25
26 26 dataOutObj = None
27 27
28 28 noiseObj = None
29 29
30 30 integratorObjList = []
31 31
32 32 writerObjList = []
33 33
34 34 integratorObjIndex = None
35 35
36 36 writerObjIndex = None
37 37
38 38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39
40 # integratorObjList = []
41 #
42 # decoderObjList = []
43 #
44 # writerObjList = []
45 #
46 # plotterObjList = []
47 #
48 # integratorObjIndex = None
49 #
50 # decoderObjIndex = None
51 #
52 # writerObjIndex = None
53 #
54 # plotterObjIndex = None
55 #
56 # buffer = None
57 #
58 # profIndex = 0
59 #
60 # nFFTPoints = None
61 #
62 # nChannels = None
63 #
64 # nHeights = None
65 #
66 # nPairs = None
67 #
68 # pairList = None
69 39
70 40
71 41 def __init__(self):
72 42 '''
73 43 Constructor
74 44 '''
75 45
76 46 self.integratorObjIndex = None
77 47 self.writerObjIndex = None
48 self.plotObjIndex = None
78 49 self.integratorObjList = []
79 50 self.writerObjList = []
51 self.plotObjList = []
80 52 self.noiseObj = None
81 53 self.buffer = None
82 54 self.profIndex = 0
83 55
84 56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
85 57
86 58 if dataInObj == None:
87 59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
88 60
89 61 if dataInObj.type == "Voltage":
90 62 if nFFTPoints == None:
91 63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
92 64 else:
93 65 nFFTPoints = dataInObj.nFFTPoints
94 66
95 67 self.dataInObj = dataInObj
96 68
97 69 if dataOutObj == None:
98 70 dataOutObj = Spectra()
99 71
100 72 self.dataOutObj = dataOutObj
101 73
102 # self.noiseObj = Noise() #aun no se incluye el objeto Noise()
103
104 ##########################################
105 # self.nFFTPoints = nFFTPoints
106 # self.nChannels = self.dataInObj.nChannels
107 # self.nHeights = self.dataInObj.nHeights
108 # self.pairList = pairList
109 # if pairList != None:
110 # self.nPairs = len(pairList)
111 # else:
112 # self.nPairs = 0
113 #
114 # self.dataOutObj.heightList = self.dataInObj.heightList
115 # self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
116 # self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
117 # self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
118 # self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
119 # self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
120 #
121 # self.dataOutObj.dataType = self.dataInObj.dataType
122 # self.dataOutObj.nPairs = self.nPairs
123 # self.dataOutObj.nChannels = self.nChannels
124 # self.dataOutObj.nProfiles = self.nFFTPoints
125 # self.dataOutObj.nHeights = self.nHeights
126 # self.dataOutObj.nFFTPoints = self.nFFTPoints
127 # #self.dataOutObj.data = None
128 #
129 # self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
130 # self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
131 #
132 # self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
133 # self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
134 # self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
135 # self.dataOutObj.m_ProcessingHeader.shif_fft = True
136 #
137 # spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
138 # k = 0
139 # for i in range( 0,self.nChannels*2,2 ):
140 # spectraComb[i] = k
141 # spectraComb[i+1] = k
142 # k += 1
143 #
144 # k *= 2
145 #
146 # if self.pairList != None:
147 #
148 # for pair in self.pairList:
149 # spectraComb[k] = pair[0]
150 # spectraComb[k+1] = pair[1]
151 # k += 2
152 #
153 # self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
154
155 74 return self.dataOutObj
156 75
157 76 def init(self):
158 #
159 # self.nHeights = self.dataInObj.nHeights
160 # self.dataOutObj.nHeights = self.nHeights
161 # self.dataOutObj.heightList = self.dataInObj.heightList
162 #
163 77
164 78 self.integratorObjIndex = 0
165 79 self.writerObjIndex = 0
166
80 self.plotObjIndex = 0
167 81 if self.dataInObj.type == "Voltage":
168 82
169 83 if self.buffer == None:
170 84 self.buffer = numpy.zeros((self.nChannels,
171 85 self.nFFTPoints,
172 86 self.dataInObj.nHeights),
173 87 dtype='complex')
174 88
175 89 self.buffer[:,self.profIndex,:] = self.dataInObj.data
176 90 self.profIndex += 1
177 91
178 92 if self.profIndex == self.nFFTPoints:
179 93 self.__getFft()
180 94 self.dataOutObj.flagNoData = False
181 95
182 96 self.buffer = None
183 97 self.profIndex = 0
184 98 return
185 99
186 100 self.dataOutObj.flagNoData = True
187 101
188 102 return
189 103
190 104 #Other kind of data
191 105 if self.dataInObj.type == "Spectra":
192 106 self.dataOutObj.copy(self.dataInObj)
193 107 self.dataOutObj.flagNoData = False
194 108 return
195 109
196 110 raise ValueError, "The datatype is not valid"
197 111
198 112 def __getFft(self):
199 113 """
200 114 Convierte valores de Voltaje a Spectra
201 115
202 116 Affected:
203 117 self.dataOutObj.data_spc
204 118 self.dataOutObj.data_cspc
205 119 self.dataOutObj.data_dc
206 120 self.dataOutObj.heightList
207 121 self.dataOutObj.m_BasicHeader
208 122 self.dataOutObj.m_ProcessingHeader
209 123 self.dataOutObj.m_RadarControllerHeader
210 124 self.dataOutObj.m_SystemHeader
211 125 self.profIndex
212 126 self.buffer
213 127 self.dataOutObj.flagNoData
214 128 self.dataOutObj.dataType
215 129 self.dataOutObj.nPairs
216 130 self.dataOutObj.nChannels
217 131 self.dataOutObj.nProfiles
218 132 self.dataOutObj.m_SystemHeader.numChannels
219 133 self.dataOutObj.m_ProcessingHeader.totalSpectra
220 134 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
221 135 self.dataOutObj.m_ProcessingHeader.numHeights
222 136 self.dataOutObj.m_ProcessingHeader.spectraComb
223 137 self.dataOutObj.m_ProcessingHeader.shif_fft
224 138 """
225 139
226 140 if self.dataInObj.flagNoData:
227 141 return 0
228 142
229 143 fft_volt = numpy.fft.fft(self.buffer,axis=1)
230 144 dc = fft_volt[:,0,:]
231 145
232 146 #calculo de self-spectra
233 147 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
234 148 spc = fft_volt * numpy.conjugate(fft_volt)
235 149 spc = spc.real
236 150
237 151 blocksize = 0
238 152 blocksize += dc.size
239 153 blocksize += spc.size
240 154
241 155 cspc = None
242 156 pairIndex = 0
243 157 if self.pairList != None:
244 158 #calculo de cross-spectra
245 159 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
246 160 for pair in self.pairList:
247 161 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
248 162 pairIndex += 1
249 163 blocksize += cspc.size
250 164
251 165 self.dataOutObj.data_spc = spc
252 166 self.dataOutObj.data_cspc = cspc
253 167 self.dataOutObj.data_dc = dc
254 168 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
255 169 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
256 170
257 171 # self.getNoise()
258 172
259 173 def addWriter(self, wrpath, blocksPerFile):
260 174 objWriter = SpectraWriter(self.dataOutObj)
261 175 objWriter.setup(wrpath, blocksPerFile)
262 176 self.writerObjList.append(objWriter)
263 177
264 178 def addIntegrator(self,N,timeInterval):
265 179
266 180 objIncohInt = IncoherentIntegration(N,timeInterval)
267 181 self.integratorObjList.append(objIncohInt)
268 182
183 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
184 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
185 self.plotObjList.append(spcObj)
186
187 def plotSpc(self, idfigure=None,
188 xmin=None,
189 xmax=None,
190 ymin=None,
191 ymax=None,
192 minvalue=None,
193 maxvalue=None,
194 wintitle='',
195 driver='plplot',
196 colormap='br_greeen',
197 colorbar=True,
198 showprofile=False,
199 save=False,
200 gpath=None):
201
202 if self.dataOutObj.flagNoData:
203 return 0
204
205 nframes = len(self.dataOutObj.channelList)
206
207 if len(self.plotObjList) <= self.plotObjIndex:
208 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
209
210 x = numpy.arange(self.dataOutObj.nFFTPoints)
211
212 y = self.dataOutObj.heightList
213
214 channelList = self.dataOutObj.channelList
215
216 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
217 # noisedB = 10.*numpy.log10(noise)
218 noisedB = numpy.arange(len(channelList)+1)
219 noisedB = noisedB *1.2
220 titleList = []
221 for i in range(len(noisedB)):
222 title = "%.2f"%noisedB[i]
223 titleList.append(title)
224
225 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
226 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
227 figuretitle = "Spc Radar Data: %s"%dateTime
228
229 cleardata = True
230
231 plotObj = self.plotObjList[self.plotObjIndex]
232
233 plotObj.plotPcolor(data,
234 x,
235 y,
236 channelList,
237 xmin,
238 xmax,
239 ymin,
240 ymax,
241 minvalue,
242 maxvalue,
243 figuretitle,
244 None,
245 save,
246 gpath,
247 cleardata,
248 titleList)
249
250 self.plotObjIndex += 1
251
252
269 253 def writeData(self, wrpath, blocksPerFile):
270 254 if self.dataOutObj.flagNoData:
271 255 return 0
272 256
273 257 if len(self.writerObjList) <= self.writerObjIndex:
274 258 self.addWriter(wrpath, blocksPerFile)
275 259
276 260 self.writerObjList[self.writerObjIndex].putData()
277 261
278 262 self.writerObjIndex += 1
279 263
280 264 def integrator(self, N=None, timeInterval=None):
281 265
282 266 if self.dataOutObj.flagNoData:
283 267 return 0
284 268
285 269 if len(self.integratorObjList) <= self.integratorObjIndex:
286 270 self.addIntegrator(N,timeInterval)
287 271
288 272 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
289 273 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
290 274
291 275 if myIncohIntObj.isReady:
292 276 self.dataOutObj.data_spc = myIncohIntObj.data
293 277 self.dataOutObj.nAvg = myIncohIntObj.navg
294 278 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
295 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
296 279 self.dataOutObj.flagNoData = False
297 280
298 281 """Calcular el ruido"""
299 282 self.getNoise()
300 283 else:
301 284 self.dataOutObj.flagNoData = True
302 285
303 286 self.integratorObjIndex += 1
304 287
305 288
306 289
307 290
308 291 class IncoherentIntegration:
309 292
310 293 integ_counter = None
311 294 data = None
312 295 navg = None
313 296 buffer = None
314 297 nIncohInt = None
315 298
316 299 def __init__(self, N = None, timeInterval = None):
317 300 """
318 301 N
319 302 timeInterval - interval time [min], integer value
320 303 """
321 304
322 305 self.data = None
323 306 self.navg = None
324 307 self.buffer = None
325 308 self.timeOut = None
326 309 self.exitCondition = False
327 310 self.isReady = False
328 311 self.nIncohInt = N
329 312 self.integ_counter = 0
330 313 if timeInterval!=None:
331 314 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
332 315
333 316 if ((timeInterval==None) and (N==None)):
334 317 print 'N = None ; timeInterval = None'
335 318 sys.exit(0)
336 319 elif timeInterval == None:
337 320 self.timeFlag = False
338 321 else:
339 322 self.timeFlag = True
340 323
341 324
342 325 def exe(self,data,timeOfData):
343 326 """
344 327 data
345 328
346 329 timeOfData [seconds]
347 330 """
348 331
349 332 if self.timeFlag:
350 333 if self.timeOut == None:
351 334 self.timeOut = timeOfData + self.timeIntervalInSeconds
352 335
353 336 if timeOfData < self.timeOut:
354 337 if self.buffer == None:
355 338 self.buffer = data
356 339 else:
357 340 self.buffer = self.buffer + data
358 341 self.integ_counter += 1
359 342 else:
360 343 self.exitCondition = True
361 344
362 345 else:
363 346 if self.integ_counter < self.nIncohInt:
364 347 if self.buffer == None:
365 348 self.buffer = data
366 349 else:
367 350 self.buffer = self.buffer + data
368 351
369 352 self.integ_counter += 1
370 353
371 354 if self.integ_counter == self.nIncohInt:
372 355 self.exitCondition = True
373 356
374 357 if self.exitCondition:
375 358 self.data = self.buffer
376 359 self.navg = self.integ_counter
377 360 self.isReady = True
378 361 self.buffer = None
379 362 self.timeOut = None
380 363 self.integ_counter = 0
381 364 self.exitCondition = False
382 365
383 366 if self.timeFlag:
384 367 self.buffer = data
385 368 self.timeOut = timeOfData + self.timeIntervalInSeconds
386 369 else:
387 370 self.isReady = False
388 371 No newline at end of file
@@ -1,287 +1,288
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 import datetime
11 11 import time
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from Data.JROData import Voltage
17 17 from IO.VoltageIO import VoltageWriter
18 18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
19 19
20 20 class VoltageProcessor:
21 21
22 22 dataInObj = None
23 23 dataOutObj = None
24 24 integratorObjIndex = None
25 25 writerObjIndex = None
26 26 integratorObjList = None
27 27 writerObjList = None
28 28
29 29 def __init__(self):
30 30 self.integratorObjIndex = None
31 31 self.writerObjIndex = None
32 32 self.plotObjIndex = None
33 33 self.integratorObjList = []
34 34 self.writerObjList = []
35 35 self.plotObjList = []
36 36
37 37 def setup(self,dataInObj=None,dataOutObj=None):
38 38 self.dataInObj = dataInObj
39 39
40 40 if self.dataOutObj == None:
41 41 dataOutObj = Voltage()
42 42
43 43 self.dataOutObj = dataOutObj
44 44
45 45 return self.dataOutObj
46 46
47 47 def init(self):
48 48 self.integratorObjIndex = 0
49 49 self.writerObjIndex = 0
50 50 self.plotObjIndex = 0
51 51
52 52 if not(self.dataInObj.flagNoData):
53 53 self.dataOutObj.copy(self.dataInObj)
54 54 # No necesita copiar en cada init() los atributos de dataInObj
55 55 # la copia deberia hacerse por cada nuevo bloque de datos
56 56
57 def addRti(self, idfigure, nframes, wintitle, driver, colorbar, colormap, showprofile):
58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colorbar, colormap, showprofile)
57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
59 59 self.plotObjList.append(rtiObj)
60 60
61 61 def plotRti(self, idfigure=None,
62 62 starttime=None,
63 63 endtime=None,
64 64 rangemin=None,
65 65 rangemax=None,
66 66 minvalue=None,
67 67 maxvalue=None,
68 68 wintitle='',
69 69 driver='plplot',
70 70 colormap='br_greeen',
71 71 colorbar=True,
72 72 showprofile=False,
73 73 xrangestep=None,
74 74 save=False,
75 75 gpath=None):
76 76
77 77 if self.dataOutObj.flagNoData:
78 78 return 0
79 79
80 80 nframes = len(self.dataOutObj.channelList)
81 81
82 82 if len(self.plotObjList) <= self.plotObjIndex:
83 83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
84 84
85 85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
86 86 data = 10*numpy.log10(data.real)
87 87
88 88 # currenttime = self.dataOutObj.dataUtcTime
89 89 # if timezone == "lt":
90 90 currenttime = self.dataOutObj.dataUtcTime - time.timezone
91 91
92
93
94 92 range = self.dataOutObj.heightList
95 93
96 94 channelList = self.dataOutObj.channelList
97 95
98 96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
99 97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
100 98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
101 99
102 100 figuretitle = "RTI Plot Radar Data" #+ date
103 101
104 102 plotObj = self.plotObjList[self.plotObjIndex]
105 103
104 cleardata = False
105
106 106 plotObj.plotPcolor(data,
107 107 currenttime,
108 108 range,
109 109 channelList,
110 110 starttime,
111 111 endtime,
112 112 rangemin,
113 113 rangemax,
114 114 minvalue,
115 115 maxvalue,
116 116 figuretitle,
117 117 xrangestep,
118 118 save,
119 gpath)
119 gpath,
120 cleardata)
120 121
121 122 self.plotObjIndex += 1
122 123
123 124 def addScope(self, idfigure, nframes, wintitle, driver):
124 125 if idfigure==None:
125 126 idfigure = self.plotObjIndex
126 127
127 128 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
128 129 self.plotObjList.append(scopeObj)
129 130
130 131 def plotScope(self,
131 132 idfigure=None,
132 133 minvalue=None,
133 134 maxvalue=None,
134 135 xmin=None,
135 136 xmax=None,
136 137 wintitle='',
137 138 driver='plplot',
138 139 save=False,
139 140 gpath=None,
140 141 titleList=None,
141 142 xlabelList=None,
142 143 ylabelList=None,
143 144 type="power"):
144 145
145 146 if self.dataOutObj.flagNoData:
146 147 return 0
147 148
148 149 nframes = len(self.dataOutObj.channelList)
149 150
150 151 if len(self.plotObjList) <= self.plotObjIndex:
151 152 self.addScope(idfigure, nframes, wintitle, driver)
152 153
153 154
154 155 if type=="power":
155 156 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
156 157 data1D = data1D.real
157 158
158 159 if type =="iq":
159 160 data1D = self.dataOutObj.data
160 161
161 162 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
162 163
163 164 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
164 165 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
165 166
166 167 figureTitle = "Scope Plot Radar Data: " + date
167 168
168 169 plotObj = self.plotObjList[self.plotObjIndex]
169 170
170 171 plotObj.plot1DArray(data1D,
171 172 self.dataOutObj.heightList,
172 173 self.dataOutObj.channelList,
173 174 xmin,
174 175 xmax,
175 176 minvalue,
176 177 maxvalue,
177 178 figureTitle,
178 179 save,
179 180 gpath)
180 181
181 182 self.plotObjIndex += 1
182 183
183 184
184 185 def addIntegrator(self,N,timeInterval):
185 186 objCohInt = CoherentIntegrator(N,timeInterval)
186 187 self.integratorObjList.append(objCohInt)
187 188
188 189 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
189 190 writerObj = VoltageWriter(self.dataOutObj)
190 191 writerObj.setup(wrpath,blocksPerFile,profilesPerBlock)
191 192 self.writerObjList.append(writerObj)
192 193
193 194 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
194 195
195 196 if self.dataOutObj.flagNoData:
196 197 return 0
197 198
198 199 if len(self.writerObjList) <= self.writerObjIndex:
199 200 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
200 201
201 202 self.writerObjList[self.writerObjIndex].putData()
202 203
203 204 self.writerObjIndex += 1
204 205
205 206 def integrator(self, N=None, timeInterval=None):
206 207 if self.dataOutObj.flagNoData:
207 208 return 0
208 209 if len(self.integratorObjList) <= self.integratorObjIndex:
209 210 self.addIntegrator(N,timeInterval)
210 211
211 212 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
212 213 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None)
213 214
214 215
215 216
216 217 class CoherentIntegrator:
217 218
218 219 integ_counter = None
219 220 data = None
220 221 navg = None
221 222 buffer = None
222 223 nCohInt = None
223 224
224 225 def __init__(self, N=None,timeInterval=None):
225 226
226 227 self.data = None
227 228 self.navg = None
228 229 self.buffer = None
229 230 self.timeOut = None
230 231 self.exitCondition = False
231 232 self.isReady = False
232 233 self.nCohInt = N
233 234 self.integ_counter = 0
234 235 if timeInterval!=None:
235 236 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
236 237
237 238 if ((timeInterval==None) and (N==None)):
238 239 raise ValueError, "N = None ; timeInterval = None"
239 240
240 241 if timeInterval == None:
241 242 self.timeFlag = False
242 243 else:
243 244 self.timeFlag = True
244 245
245 246 def exe(self, data, timeOfData):
246 247
247 248 if self.timeFlag:
248 249 if self.timeOut == None:
249 250 self.timeOut = timeOfData + self.timeIntervalInSeconds
250 251
251 252 if timeOfData < self.timeOut:
252 253 if self.buffer == None:
253 254 self.buffer = data
254 255 else:
255 256 self.buffer = self.buffer + data
256 257 self.integ_counter += 1
257 258 else:
258 259 self.exitCondition = True
259 260
260 261 else:
261 262 if self.integ_counter < self.nCohInt:
262 263 if self.buffer == None:
263 264 self.buffer = data
264 265 else:
265 266 self.buffer = self.buffer + data
266 267
267 268 self.integ_counter += 1
268 269
269 270 if self.integ_counter == self.nCohInt:
270 271 self.exitCondition = True
271 272
272 273 if self.exitCondition:
273 274 self.data = self.buffer
274 275 self.navg = self.integ_counter
275 276 self.isReady = True
276 277 self.buffer = None
277 278 self.timeOut = None
278 279 self.integ_counter = 0
279 280 self.exitCondition = False
280 281
281 282 if self.timeFlag:
282 283 self.buffer = data
283 284 self.timeOut = timeOfData + self.timeIntervalInSeconds
284 285 else:
285 286 self.isReady = False
286 287
287 288
General Comments 0
You need to be logged in to leave comments. Login now