##// END OF EJS Templates
Correccion en el ploteo de Graficos para efeciencia en consumo de memoria
Miguel Valdez -
r154:fd9b77bd6c94
parent child
Show More
@@ -1,393 +1,402
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
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
47 47 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
48 48 self.driver = driver
49 49 self.idfigure = idfigure
50 50 self.nframes = nframes
51 51 self.wintitle = wintitle
52 52 self.colormap = colormap
53 53 self.overplot = overplot
54 54 self.colorbar = colorbar
55 55
56 56 self.xw = xw
57 57 self.yw = yw
58 58
59 59 self.frameObjList = []
60 60
61 61 # self.showGraph1 = args[0]
62 62 # self.showGraph2 = args[1]
63 63
64 64 self.drvObj.driver.setFigure()
65 65 self.drvObj.driver.setColormap(colormap)
66 66
67 67 def __openDriver(self):
68 68
69 69 self.drvObj.driver.openDriver()
70 70
71 def __initFigure(self):
71 def __newPage(self):
72 72
73
74 self.drvObj.driver.openPage()
73 75 nrows, ncolumns = self.getSubplots()
74 self.drvObj.driver.openFigure()
75 76 self.drvObj.driver.setFigTitle(self.figuretitle)
76 77 self.drvObj.driver.setSubPlots(nrows, ncolumns)
77 78
79 def __closePage(self):
80
81 self.drvObj.driver.closeFigure()
82
78 83 def selectFigure(self):
79 84
80 85 self.drvObj.driver.selectFigure()
81 86
82 87 def __isOutOfXRange(self,x):
83 88 try:
84 89 if ((x>=self.xmin) and (x<self.xmax)):
85 90 return 0
86 91 except:
87 92 return 0
88 93
89 94 return 1
90 95
91 96 def changeXRange(self,x):
92 97
93 98 pass
94 99
95 100 def __refresh(self):
96 101 self.drvObj.driver.refresh()
97 102
98 103 def createFrames(self):
104
105 self.frameObjList = []
106
99 107 raise ValueError, "No implemented"
100 108
101 109 def save(self,filename):
102 110
103 111 self.drvObj.driver.save(filename)
104 112
105 113 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'):
106 114
107 115 nx, ny = data1D.shape
108 116
109 117 if channelList == None:
110 118 channelList = range(nx)
111 119
112 120 if x == None:
113 121 x = numpy.arange(data1D.size)
114 122
115 123 if figuretitle == None:
116 124 self.figuretitle = ""
117 125 else:
118 126 self.figuretitle = figuretitle
119 127
120 128 if not(self.__isDriverOpen):
121 129 self.__openDriver()
122 130 self.__isDriverOpen = True
123 131
124 132 if not(self.__isConfig):
125 133 self.xmin = xmin
126 134 self.xmax = xmax
127 135 self.minvalue = minvalue
128 136 self.maxvalue = maxvalue
129 137
130 138 if self.xmin == None: self.xmin = numpy.min(x)
131 139 if self.xmax == None: self.xmax = numpy.max(x)
132 140 if self.minvalue == None: self.minvalue = numpy.min(data1D)
133 141 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
134 142
135 143 self.createFrames()
136 144 self.__isConfig = True
137 145
138 146 if not(self.__isOutOfXRange(x)):
139 147 self.changeXRange(x)
140 148
141 149 if self.__isFigureOpen:
142 150 self.drvObj.driver.closePage()
143 151 self.__isFigureOpen = False
144 152
145 153 self.selectFigure()
146 154 self.__initFigure()
147 155
148 156 for channel in channelList:
149 157 frameObj = self.frameObjList[channel]
150 158 frameObj.init(xmin=self.xmin,
151 159 xmax=self.xmax,
152 160 ymin=self.minvalue,
153 161 ymax=self.maxvalue,
154 162 minvalue=self.minvalue,
155 163 maxvalue=self.maxvalue)
156 164
157 165 for channel in channelList:
158 166 dataCh = data1D[channel,:]
159 167 frameObj = self.frameObjList[channel]
160 168 # frameObj.clearData()
161 169 frameObj.plot(x, dataCh)
162 170
163 171 # frameObj.refresh()
164 172 self.__refresh()
165 173
166 174
167 175
168 176 if save:
169 177 # self.colorplotObj.setFigure(indexPlot)
170 178
171 179 path = gpath
172 180 now = datetime.datetime.now()
173 181 file = "scope_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
174 182 filename = os.path.join(path,file)
175 183 self.save(filename)
176 184
177
185 self.__closeFigure()
178 186
179 187
180 188 def plotPcolor(self,data,
181 189 x=None,
182 190 y=None,
183 191 channelList=None,
184 192 xmin=None,
185 193 xmax=None,
186 194 ymin=None,
187 195 ymax=None,
188 196 minvalue=None,
189 197 maxvalue=None,
190 198 figuretitle=None,
191 199 xrangestep=None,
192 200 deltax=None,
193 201 save=False,
194 202 gpath='./',
195 203 clearData=False,
196 204 *args):
197 205
198 206
199 207 if figuretitle == None:
200 208 self.figuretitle = ""
201 209 else:
202 210 self.figuretitle = figuretitle
203 211
204 212
205
206 213 if not(self.__isDriverOpen):
207 214 self.__openDriver()
208 215 self.__isDriverOpen = True
209 216
210 217 if not(self.__isConfig):
211 218
212 219 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax)
213 220
214 221 self.createFrames()
215 222 self.__isConfig = True
216 223
217 224 if (self.__isOutOfXRange(x)):
218 225
219 226 if not(self.changeXRange(x)):
220 227 return 0
221 228
222 self.__isFigureOpen = False
223
224 if not(self.__isFigureOpen):
229 self.__closeFigure()
225 230
231 self.selectFigure()
226 232
227 self.__initFigure()
233 if not(self.__isFigureOpen):
234 self.__newPage()
228 235 self.__isFigureOpen = True
229 236
230 237 for channel in channelList:
231 238 if len(args) != 0: value = args[0][channel]
232 239 else: value = args
233 240
234 241 frameObj = self.frameObjList[channel]
235 242 frameObj.init(self.xmin,
236 243 self.xmax,
237 244 self.ymin,
238 245 self.ymax,
239 246 self.minvalue,
240 247 self.maxvalue,
241 248 self.deltax,
242 249 self.deltay,
243 250 self.colorbar,
244 251 value)
245 self.selectFigure()
252
246 253
247 254 for channel in channelList:
248 255 dataCh = data[channel,:]
249 256 frameObj = self.frameObjList[channel]
250 257 frameObj.plot(x, y, dataCh)
251 258
252 259
253 260 self.__refresh()
254 261 if clearData == True:
262 self.__closePage()
255 263 self.__isFigureOpen = False
256 264
257 265
258 266
267
259 268 class Frame:
260 269
261 270 drvObj = None
262 271 idFrame = None
263 272 nplots = None
264 273 plotObjList = []
265 274 title = ""
266 275
267 276 def __init__(self,drvObj, idframe):
268 277
269 278 self.drvObj = drvObj
270 279 self.idframe = idframe
271 280 nplots = None
272 281 self.plotObjList = []
273 282
274 283 self.createPlots()
275 284
276 285 def createPlots(self):
277 286 raise ValueError, "No implemented"
278 287
279 288 def getScreenPosMainPlot(self):
280 289 raise ValueError, "No implemented"
281 290
282 291 def getScreenPosGraph1(self):
283 292 raise ValueError, "No implemented"
284 293
285 294 def getScreenPos(self, nplot):
286 295
287 296 if nplot == 0:
288 297 xi, yi, xw, yw = self.getScreenPosMainPlot()
289 298
290 299 if nplot == 1:
291 300 xi, yi, xw, yw = self.getScreenPosGraph1()
292 301
293 302 return xi, yi, xw, yw
294 303
295 304
296 305 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
297 306
298 307 for plotObj in self.plotObjList:
299 308 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
300 309 plotObj.plotBox()
301 310
302 311
303 312
304 313 class Plot:
305 314
306 315 drvObj = None
307 316 idframe = None
308 317 idplot = None
309 318 xi = None
310 319 yi = None
311 320 xw = None
312 321 yw = None
313 322
314 323 title = ""
315 324 xlabel = ""
316 325 ylabel = ""
317 326 xaxisastime = None
318 327 timefmt = None
319 328 xopt = ""
320 329 yopt = ""
321 330 xpos = None
322 331 ypos = None
323 332 szchar = None
324 333 idframe = None
325 334 idplot = None
326 335 colorbar = None
327 336 cbxpos = None
328 337 cbypos = None
329 338
330 339 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
331 340
332 341 self.drvObj = drvObj
333 342 self.idframe = idframe
334 343 self.idplot = idplot
335 344 self.xi = xi
336 345 self.yi = yi
337 346 self.xw = xw
338 347 self.yw = yw
339 348
340 349
341 350 def plotBox(self):
342 351
343 352 self.drvObj.driver.plotBox(self.idframe,
344 353 self.xpos,
345 354 self.ypos,
346 355 self.xmin,
347 356 self.xmax,
348 357 self.ymin,
349 358 self.ymax,
350 359 self.minvalue,
351 360 self.maxvalue,
352 361 self.xopt,
353 362 self.yopt,
354 363 self.szchar,
355 364 self.xaxisastime,
356 365 self.timefmt)
357 366
358 367 self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title)
359 368
360 369 if self.colorbar:
361 370 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
362 371
363 372 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
364 373
365 374 self.drvObj.driver.pcolor(self.idframe,
366 375 self.xpos,
367 376 self.ypos,
368 377 z,
369 378 x,
370 379 y,
371 380 self.xmin,
372 381 self.xmax,
373 382 self.ymin,
374 383 self.ymax,
375 384 self.minvalue,
376 385 self.maxvalue,
377 386 deltax,
378 387 deltay,
379 388 getGrid,
380 389 self.xaxisastime,
381 390 self.timefmt)
382 391
383 392 def plotBasicLine(self,x, y, color):
384 393 """
385 394 Inputs:
386 395 x:
387 396
388 397 y:
389 398
390 399 color:
391 400 """
392 401 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
393 402 No newline at end of file
@@ -1,521 +1,530
1 1 import numpy
2 2 import datetime
3 3 import time
4 4 from schainPlot import *
5 5
6 6 class SpcFigure(Figure):
7 7 overplot = 0
8 8 xw = 800
9 9 yw = 650
10 10 showprofile = False
11 11
12 12 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
13 13 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
14 14
15 15 self.showprofile = showprofile
16 16
17 17 def getSubplots(self):
18 18 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
19 19 nrows = int(self.nframes*1./ncolumns + 0.9)
20 20
21 21 return nrows, ncolumns
22 22
23 23 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
24 24
25 25 if xmin == None: xmin = numpy.min(x)
26 26 if xmax == None: xmax = numpy.max(x)
27 27 if ymin == None: ymin = numpy.min(y)
28 28 if ymax == None: ymax = numpy.max(y)
29 29 if minvalue == None: minvalue = 20.
30 30 if maxvalue == None: maxvalue = 90.
31 31
32 32 self.xmin = xmin
33 33 self.xmax = xmax
34 34 self.minrange = ymin
35 35 self.maxrange = ymax
36 36 self.ymin = ymin
37 37 self.ymax = ymax
38 38 self.minvalue = minvalue
39 39 self.maxvalue = maxvalue
40 40
41 41
42 42 def changeXRange(self, *args):
43 43 pass
44 44
45 45 def createFrames(self):
46
47 self.frameObjList = []
48
46 49 for frame in range(self.nframes):
47 50 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
48 51 self.frameObjList.append(frameObj)
49 52
50 53 class SpcFrame(Frame):
51 54 def __init__(self,drvObj,idframe,colorbar,showprofile):
52 55 self.drvObj = drvObj
53 56 self.idframe = idframe
54 57 self.nplots = 1
55 58
56 59 if showprofile:
57 60 self.nplots += 1
58 61
59 62 self.colorbar = colorbar
60 63 self.showprofile = showprofile
61 64 self.createPlots()
62 65
63 66 def createPlots(self):
64 67 plotObjList = []
65 68 idplot = 0
66 69 xi, yi, xw, yw = self.getScreenPos(idplot)
67 70 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
68 71 plotObjList.append(plotObj)
69 72
70 73 if self.showprofile:
71 74 idplot = 1
72 75 xi, yi, xw, yw = self.getScreenPos(idplot)
73 76 type = "pwbox"
74 77 title = ""
75 78 xlabel = "dB"
76 79 ylabel = ""
77 80 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
78 81 plotObjList.append(plotObj)
79 82
80 83 self.plotObjList = plotObjList
81 84
82 85 def getScreenPosMainPlot(self):
83 86 xi = 0.15
84 87
85 88 if self.showprofile:
86 89 xw = 0.65
87 90
88 91 else:
89 92 xw = 0.75
90 93
91 94 if self.colorbar:
92 95 xw = xw - 0.06
93 96
94 97 yi = 0.20; yw = 0.75
95 98
96 99 return xi, yi, xw, yw
97 100
98 101 def getScreenPosGraph1(self):
99 102 if self.colorbar:
100 103 xi = 0.65 + 0.08
101 104 else:
102 105 xi = 0.75 + 0.05
103 106
104 107 xw = xi + 0.2
105 108
106 109 yi = 0.2; yw = 0.75
107 110
108 111 return xi, yi, xw, yw
109 112
110 113 def plot(self,x, y, data):
111 114 plotObj = self.plotObjList[0]
112 115 plotObj.plot(x,y,data)
113 116
114 117 if self.showprofile:
115 118 plotObj = self.plotObjList[1]
116 119 plotObj.plot(data,y)
117 120
118 121 class SpcPlot(Plot):
119 122
120 123 getGrid = True
121 124
122 125 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
123 126 self.drvObj = drvObj
124 127 self.idframe = idframe
125 128 self.idplot = idplot
126 129 self.xi = xi
127 130 self.yi = yi
128 131 self.xw = xw
129 132 self.yw = yw
130 133 self.colorbar = colorbar
131 134
132 135 if self.colorbar:
133 136 cbxi = xw + 0.03
134 137 cbxw = cbxi + 0.03
135 138 cbyi = yi
136 139 cbyw = yw
137 140 self.cbxpos = [cbxi,cbxw]
138 141 self.cbypos = [cbyi,cbyw]
139 142
140 143 self.xpos = [self.xi,self.xw]
141 144 self.ypos = [self.yi,self.yw]
142 145 self.xaxisastime = False
143 146 self.timefmt = None
144 147 self.xopt = "bcnst"
145 148 self.yopt = "bcnstv"
146 149
147 150 self.szchar = 0.8
148 151 self.strforchannel = "Channel %d"%self.idframe
149 152 self.xlabel = "m/s"
150 153 self.ylabel = "Range (Km)"
151 154
152 155 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
153 156 self.xmin = xmin
154 157 self.xmax = xmax
155 158 self.ymin = ymin
156 159 self.ymax = ymax
157 160 self.minvalue = minvalue
158 161 self.maxvalue = maxvalue
159 162 self.colorbar = args[2]
160 163 self.title = "%s - %s"%(self.strforchannel,args[3])
161 164
162 165
163 166
164 167 def plot(self, x, y, data):
165 168 z = data
166 169 deltax = None
167 170 deltay = None
168 171 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
169 172 self.getGrid = False
170 173
171 174
172 175 class RTIFigure(Figure):
173 176 overplot = 1
174 177 xw = 700
175 178 yw = 650
176 179 showprofile = False
177 180 starttime = None
178 181 endtime = None
179 182 minrange = None
180 183 maxrange = None
181 184 minvalue = None
182 185 maxvalue = None
183 186 xrangestepinsecs = None
184 187
185 188
186 189 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
187 190 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
188 191
189 192 self.showprofile = showprofile
190 193
191 194 def getSubplots(self):
192 195 nrows = self.nframes
193 196 ncolumns = 1
194 197 return nrows, ncolumns
195 198
196 199 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep, deltax):
197 200
198 201 self.starttime = xmin
199 202 self.endtime = xmax
200 203
201 204 cdatetime = datetime.datetime.utcfromtimestamp(x)
202 205
203 206 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
204 207 if ((xrangestep == 0) or (xrangestep == None)):
205 208 maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second)
206 209 self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple())
207 210 npoints = 1000.
208 211 if xrangestep == 1:
209 212 maxdatetime = mindatetime + datetime.timedelta(hours=1)
210 213 self.xrangestepinsecs = 60*60.
211 214 npoints = 500.
212 215 if xrangestep == 2:
213 216 maxdatetime = mindatetime + datetime.timedelta(minutes=1)
214 217 self.xrangestepinsecs = 60.
215 218 npoints = 250.
216 219 if xrangestep == 3:
217 220 maxdatetime = mindatetime + datetime.timedelta(seconds=1)
218 221 self.xrangestepinsecs = 1.
219 222 npoints = 125.
220 223
221 224 xmin = time.mktime(mindatetime.timetuple())
222 225 xmax = time.mktime(maxdatetime.timetuple())
223 226
224 227 deltax1 = (xmax-xmin) / npoints
225 228 # deltax = timeInterval
226 229
227 230
228 231 if ymin == None: ymin = numpy.min(y)
229 232 if ymax == None: ymax = numpy.max(y)
230 233
231 234 if minvalue == None: minvalue = 0.
232 235 if maxvalue == None: maxvalue = 50.
233 236
234 237 self.xmin = xmin
235 238 self.xmax = xmax
236 239 self.minrange = ymin
237 240 self.maxrange = ymax
238 241 self.ymin = ymin
239 242 self.ymax = ymax
240 243 self.minvalue = minvalue
241 244 self.maxvalue = maxvalue
242 245 self.xrangestep = xrangestep
243 246 self.deltax = deltax
244 247
245 248 def changeXRange(self,x):
246 249
247 250 cdatetime = datetime.datetime.utcfromtimestamp(x)
248 251
249 252 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
250 253 if self.xrangestep == 1:
251 254 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second)
252 255
253 256 if self.xrangestep == 2:
254 257 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second)
255 258
256 259 if self.xrangestep == 3:
257 260 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
258 261
259 262 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
260 263 self.xmax = self.xmin + self.xrangestepinsecs
261 264
262 265 self.figuretitle = "%s %s : %s"%(self.figuretitle,
263 266 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
264 267 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
265 268 return 1
266 269
267 270 return 0
268 271
269 272 def createFrames(self):
273
274 self.frameObjList = []
275
270 276 for frame in range(self.nframes):
271 277 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
272 278 self.frameObjList.append(frameObj)
273 279
274 280 class RTIFrame(Frame):
275 281 def __init__(self,drvObj,idframe,colorbar,showprofile):
276 282 self.drvObj = drvObj
277 283 self.idframe = idframe
278 284 self.nplots = 1
279 285
280 286 if showprofile:
281 287 self.nplots += 1
282 288
283 289 self.colorbar = colorbar
284 290 self.showprofile = showprofile
285 291 self.createPlots()
286 292
287 293 def createPlots(self):
288 294 plotObjList = []
289 295
290 296 idplot = 0
291 297 xi, yi, xw, yw = self.getScreenPos(idplot)
292 298
293 299 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
294 300 plotObjList.append(plotObj)
295 301
296 302 if self.showprofile:
297 303 idplot = 1
298 304 xi, yi, xw, yw = self.getScreenPos(idplot)
299 305 type = "pwbox"
300 306 title = ""
301 307 xlabel = "dB"
302 308 ylabel = ""
303 309 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
304 310 plotObjList.append(plotObj)
305 311
306 312 self.plotObjList = plotObjList
307 313
308 314 def getScreenPosMainPlot(self):
309 315 xi = 0.07
310 316 if self.showprofile:
311 317 xw = 0.65
312 318 else:
313 319 xw = 0.9
314 320
315 321 if self.colorbar:
316 322 xw = xw - 0.06
317 323
318 324 yi = 0.20; yw = 0.75
319 325
320 326 return xi, yi, xw, yw
321 327
322 328 def getScreenPosGraph1(self):
323 329 if self.colorbar:
324 330 xi = 0.65 + 0.08
325 331 else:
326 332 xi = 0.9 + 0.05
327 333
328 334 xw = xi + 0.2
329 335
330 336 yi = 0.2; yw = 0.75
331 337
332 338 return xi, yi, xw, yw
333 339
334 340 def plot(self, currenttime, range, data):
335 341 plotObj = self.plotObjList[0]
336 342 plotObj.plot(currenttime,range,data)
337 343
338 344 if self.showprofile:
339 345 plotObj = self.plotObjList[1]
340 346 plotObj.plot(data,range)
341 347
342 348
343 349 class RTIPlot(Plot):
344 350 deltax = None
345 351 deltay = None
346 352 xrange = [None,None]
347 353 xminpos = None
348 354 xmaxpos = None
349 355 xg = None
350 356 yg = None
351 357
352 358 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
353 359 self.drvObj = drvObj
354 360 self.idframe = idframe
355 361 self.idplot = idplot
356 362 self.xi = xi
357 363 self.yi = yi
358 364 self.xw = xw
359 365 self.yw = yw
360 366 self.colorbar = colorbar
361 367
362 368 if self.colorbar:
363 369 cbxi = xw + 0.03
364 370 cbxw = cbxi + 0.03
365 371 cbyi = yi
366 372 cbyw = yw
367 373 self.cbxpos = [cbxi,cbxw]
368 374 self.cbypos = [cbyi,cbyw]
369 375
370 376 self.xpos = [self.xi,self.xw]
371 377 self.ypos = [self.yi,self.yw]
372 378 self.xaxisastime = True
373 379 self.timefmt = "%H:%M"
374 380 self.xopt = "bcnstd"
375 381 self.yopt = "bcnstv"
376 382
377 383 self.szchar = 1.0
378 384 self.title = "Channel %d"%self.idframe
379 385 self.xlabel = "Local Time"
380 386 self.ylabel = "Range (Km)"
381 387
382 388
383 389 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
384 390 self.xmin = xmin
385 391 self.xmax = xmax
386 392 self.ymin = ymin
387 393 self.ymax = ymax
388 394 self.minvalue = minvalue
389 395 self.maxvalue = maxvalue
390 396 self.deltax = deltax
391 397 self.deltay = deltay
392 398 self.colorbar = colorbar
393 399
394 400 def plot(self, currenttime, range, data):
395 401
396 402 if self.xmaxpos == None:
397 403 self.xmaxpos = currenttime
398 404
399 405 # if currenttime >= self.xmaxpos:
400 406
401 407 self.xminpos = currenttime
402 408 self.xmaxpos = currenttime + self.deltax
403 409 x = [currenttime]
404 410 y = range
405 411 z = numpy.reshape(data, (1,-1))
406 412 getGrid = True
407 413
408 414 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
409 415
410 416
411 417 class ScopeFigure(Figure):
412 418 overplot = 0
413 419 xw = 700
414 420 yw = 650
415 421 colorbar = None
416 422
417 423 def __init__(self,idfigure,nframes,wintitle,driver):
418 424 colormap = None
419 425 colorbar = False
420 426
421 427 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
422 428
423 429
424 430 def getSubplots(self):
425 431 nrows = self.nframes
426 432 ncolumns = 1
427 433 return nrows, ncolumns
428 434
429 435 def createFrames(self):
436
437 self.frameObjList = []
438
430 439 for frame in range(self.nframes):
431 440 frameObj = ScopeFrame(self.drvObj,frame + 1)
432 441 self.frameObjList.append(frameObj)
433 442
434 443
435 444 class ScopeFrame(Frame):
436 445 # plotObjList = []
437 446 xlabel = ""
438 447 ylabel = ""
439 448 title = ""
440 449 def __init__(self,drvObj,idframe):
441 450 self.drvObj = drvObj
442 451 self.idframe = idframe
443 452 self.nplots = 1 #nplots/frame
444 453 self.createPlots()
445 454 # Frame.__init__(self, drvObj, idframe)
446 455
447 456 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
448 457 xi = 0.08; xw = 0.9
449 458 yi = 0.20; yw = 0.75
450 459 return xi,yi,xw,yw
451 460
452 461 def createPlots(self):
453 462 plotObjList = []
454 463 for idplot in range(self.nplots):
455 464 xi, yi, xw, yw = self.getScreenPos(idplot)
456 465 type = "scopebox"
457 466 title = "Channel %d"%self.idframe
458 467 xlabel = "range (Km)"
459 468 ylabel = "intensity"
460 469 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
461 470 plotObjList.append(plotObj)
462 471 self.plotObjList = plotObjList
463 472 # self.plotObjList.append(plotObj)
464 473
465 474 def plot(self, x, y, z=None):
466 475 for plotObj in self.plotObjList:
467 476 plotObj.plot(x, y)
468 477
469 478
470 479 class Plot1D(Plot):
471 480 # type, title, xlabel, ylabel
472 481 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel):
473 482 self.drvObj = drvObj
474 483 self.idframe = idframe
475 484 self.idplot = idplot
476 485 self.xi = xi
477 486 self.yi = yi
478 487 self.xw = xw
479 488 self.yw = yw
480 489 self.xpos = [self.xi,self.xw]
481 490 self.ypos = [self.yi,self.yw]
482 491 self.xaxisastime = False
483 492 self.timefmt = None
484 493 self.xopt = "bcnst"
485 494 self.yopt = "bcnstv"
486 495 self.szchar = 1.0
487 496 self.type = type
488 497 self.title = title
489 498 self.xlabel = xlabel
490 499 self.ylabel = ylabel
491 500
492 501
493 502
494 503 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
495 504 if self.type == "pwbox":
496 505 self.xmin = minvalue
497 506 self.xmax = maxvalue
498 507 self.ymin = ymin
499 508 self.ymax = ymax
500 509 self.minvalue = minvalue
501 510 self.maxvalue = maxvalue
502 511
503 512 else:
504 513 self.xmin = xmin
505 514 self.xmax = xmax
506 515 self.ymin = ymin
507 516 self.ymax = ymax
508 517 self.minvalue = minvalue
509 518 self.maxvalue = maxvalue
510 519
511 520 self.colorbar = False
512 521
513 522 def plot(self,x,y):
514 523 if y.dtype == "complex128":
515 524 color="blue"
516 525 self.plotBasicLine(x, y.real, color)
517 526 color="red"
518 527 self.plotBasicLine(x, y.imag, color)
519 528 else:
520 529 color="blue"
521 530 self.plotBasicLine(x, y, color)
@@ -1,596 +1,597
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, SpectraHeis
15 15 from IO.SpectraIO import SpectraWriter
16 16 from Graphics.schainPlotTypes import ScopeFigure, 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 39
40 40
41 41 def __init__(self):
42 42 '''
43 43 Constructor
44 44 '''
45 45
46 46 self.integratorObjIndex = None
47 47 self.writerObjIndex = None
48 48 self.plotObjIndex = None
49 49 self.integratorOst = []
50 50 self.plotObjList = []
51 51 self.noiseObj = []
52 52 self.writerObjList = []
53 53 self.buffer = None
54 54 self.profIndex = 0
55 55
56 56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
57 57
58 58 if dataInObj == None:
59 59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
60 60
61 61 if dataInObj.type == "Voltage":
62 62 if nFFTPoints == None:
63 63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
64 64
65 65
66 66
67 67 if dataInObj.type == "Spectra":
68 68 if nFFTPoints != None:
69 69 raise ValueError, "The nFFTPoints cannot be selected to this object type"
70 70
71 71 nFFTPoints = dataInObj.nFFTPoints
72 72
73 73 if pairList == None:
74 74 pairList = self.dataInObj.pairList
75 75
76 76 if pairList == None:
77 77 nPairs = 0
78 78 else:
79 79 nPairs = len(pairList)
80 80
81 81 self.dataInObj = dataInObj
82 82
83 83 if dataOutObj == None:
84 84 dataOutObj = Spectra()
85 85
86 86 self.dataOutObj = dataOutObj
87 87 self.dataOutObj.nFFTPoints = nFFTPoints
88 88 self.dataOutObj.pairList = pairList
89 89 self.dataOutObj.nPairs = nPairs
90 90
91 91 return self.dataOutObj
92 92
93 93 def init(self):
94 94
95 95 self.dataOutObj.flagNoData = True
96 96
97 97 if self.dataInObj.flagNoData:
98 98 return 0
99 99
100 100 self.integratorObjIndex = 0
101 101 self.writerObjIndex = 0
102 102 self.plotObjIndex = 0
103 103
104 104
105 105 if self.dataInObj.type == "Spectra":
106 106
107 107 self.dataOutObj.copy(self.dataInObj)
108 108 self.dataOutObj.flagNoData = False
109 109 return
110 110
111 111 if self.dataInObj.type == "Voltage":
112 112
113 113 if self.buffer == None:
114 114 self.buffer = numpy.zeros((self.dataInObj.nChannels,
115 115 self.dataOutObj.nFFTPoints,
116 116 self.dataInObj.nHeights),
117 117 dtype='complex')
118 118
119 119 self.buffer[:,self.profIndex,:] = self.dataInObj.data
120 120 self.profIndex += 1
121 121
122 122 if self.profIndex == self.dataOutObj.nFFTPoints:
123 123
124 124 self.__updateObjFromInput()
125 125 self.__getFft()
126 126
127 127 self.dataOutObj.flagNoData = False
128 128
129 129 self.buffer = None
130 130 self.profIndex = 0
131 131
132 132 return
133 133
134 134 #Other kind of data
135 135 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
136 136
137 137 def __getFft(self):
138 138 """
139 139 Convierte valores de Voltaje a Spectra
140 140
141 141 Affected:
142 142 self.dataOutObj.data_spc
143 143 self.dataOutObj.data_cspc
144 144 self.dataOutObj.data_dc
145 145 self.dataOutObj.heightList
146 146 self.dataOutObj.m_BasicHeader
147 147 self.dataOutObj.m_ProcessingHeader
148 148 self.dataOutObj.radarControllerHeaderObj
149 149 self.dataOutObj.systemHeaderObj
150 150 self.profIndex
151 151 self.buffer
152 152 self.dataOutObj.flagNoData
153 153 self.dataOutObj.dtype
154 154 self.dataOutObj.nPairs
155 155 self.dataOutObj.nChannels
156 156 self.dataOutObj.nProfiles
157 157 self.dataOutObj.systemHeaderObj.numChannels
158 158 self.dataOutObj.m_ProcessingHeader.totalSpectra
159 159 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
160 160 self.dataOutObj.m_ProcessingHeader.numHeights
161 161 self.dataOutObj.m_ProcessingHeader.spectraComb
162 162 self.dataOutObj.m_ProcessingHeader.shif_fft
163 163 """
164 164
165 165 fft_volt = numpy.fft.fft(self.buffer,axis=1)
166 166 dc = fft_volt[:,0,:]
167 167
168 168 #calculo de self-spectra
169 169 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
170 170 spc = fft_volt * numpy.conjugate(fft_volt)
171 171 spc = spc.real
172 172
173 173 blocksize = 0
174 174 blocksize += dc.size
175 175 blocksize += spc.size
176 176
177 177 cspc = None
178 178 pairIndex = 0
179 179 if self.dataOutObj.pairList != None:
180 180 #calculo de cross-spectra
181 181 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
182 182 for pair in self.pairList:
183 183 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
184 184 pairIndex += 1
185 185 blocksize += cspc.size
186 186
187 187 self.dataOutObj.data_spc = spc
188 188 self.dataOutObj.data_cspc = cspc
189 189 self.dataOutObj.data_dc = dc
190 190 self.dataOutObj.blockSize = blocksize
191 191
192 192 # self.getNoise()
193 193
194 194 def __updateObjFromInput(self):
195 195
196 196 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
197 197 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
198 198 self.dataOutObj.channelList = self.dataInObj.channelList
199 199 self.dataOutObj.heightList = self.dataInObj.heightList
200 200 self.dataOutObj.dtype = self.dataInObj.dtype
201 201 self.dataOutObj.nHeights = self.dataInObj.nHeights
202 202 self.dataOutObj.nChannels = self.dataInObj.nChannels
203 203 self.dataOutObj.nBaud = self.dataInObj.nBaud
204 204 self.dataOutObj.nCode = self.dataInObj.nCode
205 205 self.dataOutObj.code = self.dataInObj.code
206 206 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
207 207 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
208 208 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
209 209 self.dataOutObj.utctime = self.dataInObj.utctime
210 210 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
211 211 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
212 212 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
213 213 self.dataOutObj.nIncohInt = 1
214 214
215 215 def addWriter(self, wrpath, blocksPerFile):
216 216
217 217 objWriter = SpectraWriter(self.dataOutObj)
218 218 objWriter.setup(wrpath, blocksPerFile)
219 219 self.writerObjList.append(objWriter)
220 220
221 221 def addIntegrator(self,N,timeInterval):
222 222
223 223 objIncohInt = IncoherentIntegration(N,timeInterval)
224 224 self.integratorObjList.append(objIncohInt)
225 225
226 226 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
227 227
228 228 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
229 229 self.plotObjList.append(spcObj)
230 230
231 231 def plotSpc(self, idfigure=None,
232 232 xmin=None,
233 233 xmax=None,
234 234 ymin=None,
235 235 ymax=None,
236 236 minvalue=None,
237 237 maxvalue=None,
238 238 wintitle='',
239 239 driver='plplot',
240 240 colormap='br_green',
241 241 colorbar=True,
242 242 showprofile=False,
243 243 save=False,
244 244 gpath=None,
245 245 channelList = None):
246 246
247 247 if self.dataOutObj.flagNoData:
248 248 return 0
249 249
250 250 if channelList == None:
251 251 channelList = self.dataOutObj.channelList
252 252
253 253 nframes = len(channelList)
254 254
255 255 if len(self.plotObjList) <= self.plotObjIndex:
256 256 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
257 257
258 258 x = numpy.arange(self.dataOutObj.nFFTPoints)
259 259
260 260 y = self.dataOutObj.heightList
261 261
262 262 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
263 263 # noisedB = 10.*numpy.log10(noise)
264 264 noisedB = numpy.arange(len(channelList)+1)
265 265 noisedB = noisedB *1.2
266 266 titleList = []
267 267 for i in range(len(noisedB)):
268 268 title = "%.2f"%noisedB[i]
269 269 titleList.append(title)
270 270
271 271 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
272 272 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
273 273 figuretitle = "Spc Radar Data: %s"%dateTime
274 274
275 275 cleardata = True
276 276
277 277 plotObj = self.plotObjList[self.plotObjIndex]
278 278
279 279 plotObj.plotPcolor(data,
280 x,
281 y,
282 channelList,
283 xmin,
284 xmax,
285 ymin,
286 ymax,
287 minvalue,
288 maxvalue,
289 figuretitle,
290 None,
291 save,
292 gpath,
293 cleardata,
294 titleList)
280 x=x,
281 y=y,
282 channelList=channelList,
283 xmin=xmin,
284 xmax=xmax,
285 ymin=ymin,
286 ymax=ymax,
287 minvalue=minvalue,
288 maxvalue=maxvalue,
289 figuretitle=figuretitle,
290 xrangestep=None,
291 deltax=None,
292 save=False,
293 gpath='./',
294 clearData=True
295 )
295 296
296 297 self.plotObjIndex += 1
297 298
298 299
299 300 def writeData(self, wrpath, blocksPerFile):
300 301
301 302 if self.dataOutObj.flagNoData:
302 303 return 0
303 304
304 305 if len(self.writerObjList) <= self.writerObjIndex:
305 306 self.addWriter(wrpath, blocksPerFile)
306 307
307 308 self.writerObjList[self.writerObjIndex].putData()
308 309
309 310 self.writerObjIndex += 1
310 311
311 312 def integrator(self, N=None, timeInterval=None):
312 313
313 314 if self.dataOutObj.flagNoData:
314 315 return 0
315 316
316 317 if len(self.integratorObjList) <= self.integratorObjIndex:
317 318 self.addIntegrator(N,timeInterval)
318 319
319 320 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
320 321 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
321 322
322 323 if myIncohIntObj.isReady:
323 324 self.dataOutObj.data_spc = myIncohIntObj.data
324 325 self.dataOutObj.nAvg = myIncohIntObj.navg
325 326 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
326 327 self.dataOutObj.flagNoData = False
327 328
328 329 """Calcular el ruido"""
329 330 self.getNoise()
330 331 else:
331 332 self.dataOutObj.flagNoData = True
332 333
333 334 self.integratorObjIndex += 1
334 335
335 336
336 337 class SpectraHeisProcessor:
337 338
338 339 def __init__(self):
339 340
340 341 self.integratorObjIndex = None
341 342 self.writerObjIndex = None
342 343 self.plotObjIndex = None
343 344 self.integratorObjList = []
344 345 self.writerObjList = []
345 346 self.plotObjList = []
346 347 #self.noiseObj = Noise()
347 348
348 349 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
349 350
350 351 if nFFTPoints == None:
351 352 nFFTPoints = self.dataInObj.nHeights
352 353
353 354 self.dataInObj = dataInObj
354 355
355 356 if dataOutObj == None:
356 357 dataOutObj = SpectraHeis()
357 358
358 359 self.dataOutObj = dataOutObj
359 360
360 361 return self.dataOutObj
361 362
362 363 def init(self):
363 364
364 365 self.dataOutObj.flagNoData = True
365 366
366 367 if self.dataInObj.flagNoData:
367 368 return 0
368 369
369 370 self.integratorObjIndex = 0
370 371 self.writerObjIndex = 0
371 372 self.plotObjIndex = 0
372 373
373 374 if self.dataInObj.type == "Voltage":
374 375 self.__updateObjFromInput()
375 376 self.__getFft()
376 377 self.dataOutObj.flagNoData = False
377 378 return
378 379
379 380 #Other kind of data
380 381 if self.dataInObj.type == "SpectraHeis":
381 382 self.dataOutObj.copy(self.dataInObj)
382 383 self.dataOutObj.flagNoData = False
383 384 return
384 385
385 386 raise ValueError, "The type is not valid"
386 387
387 388 def __updateObjFromInput(self):
388 389
389 390 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
390 391 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
391 392 self.dataOutObj.channelList = self.dataInObj.channelList
392 393 self.dataOutObj.heightList = self.dataInObj.heightList
393 394 self.dataOutObj.dtype = self.dataInObj.dtype
394 395 self.dataOutObj.nHeights = self.dataInObj.nHeights
395 396 self.dataOutObj.nChannels = self.dataInObj.nChannels
396 397 self.dataOutObj.nBaud = self.dataInObj.nBaud
397 398 self.dataOutObj.nCode = self.dataInObj.nCode
398 399 self.dataOutObj.code = self.dataInObj.code
399 400 self.dataOutObj.nProfiles = 1
400 401 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
401 402 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
402 403 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
403 404 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
404 405 self.dataOutObj.utctime = self.dataInObj.utctime
405 406 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
406 407 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
407 408 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
408 409 self.dataOutObj.nIncohInt = 1
409 410
410 411 def __getFft(self):
411 412
412 413 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
413 414 #print fft_volt
414 415 #calculo de self-spectra
415 416 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
416 417
417 418 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
418 419 self.dataOutObj.data_spc = spc
419 420
420 421 def getSpectra(self):
421 422
422 423 return self.dataOutObj.data_spc
423 424
424 425 def getFrecuencies(self):
425 426
426 427 print self.nFFTPoints
427 428 return numpy.arange(int(self.nFFTPoints))
428 429
429 430 def addIntegrator(self,N,timeInterval):
430 431
431 432 objIncohInt = IncoherentIntegration(N,timeInterval)
432 433 self.integratorObjList.append(objIncohInt)
433 434
434 435 def integrator(self, N=None, timeInterval=None):
435 436
436 437 if self.dataOutObj.flagNoData:
437 438 return 0
438 439
439 440 if len(self.integratorObjList) <= self.integratorObjIndex:
440 441 self.addIntegrator(N,timeInterval)
441 442
442 443 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
443 444 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
444 445
445 446 if myIncohIntObj.isReady:
446 447 self.dataOutObj.data_spc = myIncohIntObj.data
447 448 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
448 449 self.dataOutObj.flagNoData = False
449 450
450 451 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
451 452 # self.getNoise(type="sort", parm=16)
452 453
453 454 else:
454 455 self.dataOutObj.flagNoData = True
455 456
456 457 self.integratorObjIndex += 1
457 458
458 459
459 460 def addScope(self, idfigure, nframes, wintitle, driver):
460 461
461 462 if idfigure==None:
462 463 idfigure = self.plotObjIndex
463 464
464 465 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
465 466 self.plotObjList.append(scopeObj)
466 467
467 468 def plotScope(self,
468 469 idfigure=None,
469 470 minvalue=None,
470 471 maxvalue=None,
471 472 xmin=None,
472 473 xmax=None,
473 474 wintitle='',
474 475 driver='plplot',
475 476 save=False,
476 477 gpath=None,
477 478 titleList=None,
478 479 xlabelList=None,
479 480 ylabelList=None):
480 481
481 482 if self.dataOutObj.flagNoData:
482 483 return 0
483 484
484 485 nframes = len(self.dataOutObj.channelList)
485 486
486 487 if len(self.plotObjList) <= self.plotObjIndex:
487 488 self.addScope(idfigure, nframes, wintitle, driver)
488 489
489 490
490 491 data1D = self.dataOutObj.data_spc
491 492
492 493 x = numpy.arange(self.dataOutObj.nHeights)
493 494
494 495 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
495 496
496 497 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
497 498 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
498 499
499 500 figureTitle = "Scope Plot Radar Data: " + date
500 501
501 502 plotObj = self.plotObjList[self.plotObjIndex]
502 503
503 504 plotObj.plot1DArray(data1D,
504 505 x,
505 506 self.dataOutObj.channelList,
506 507 xmin,
507 508 xmax,
508 509 minvalue,
509 510 maxvalue,
510 511 figureTitle,
511 512 save,
512 513 gpath)
513 514
514 515 self.plotObjIndex += 1
515 516
516 517 class IncoherentIntegration:
517 518
518 519 integ_counter = None
519 520 data = None
520 521 navg = None
521 522 buffer = None
522 523 nIncohInt = None
523 524
524 525 def __init__(self, N = None, timeInterval = None):
525 526 """
526 527 N
527 528 timeInterval - interval time [min], integer value
528 529 """
529 530
530 531 self.data = None
531 532 self.navg = None
532 533 self.buffer = None
533 534 self.timeOut = None
534 535 self.exitCondition = False
535 536 self.isReady = False
536 537 self.nIncohInt = N
537 538 self.integ_counter = 0
538 539 if timeInterval!=None:
539 540 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
540 541
541 542 if ((timeInterval==None) and (N==None)):
542 543 print 'N = None ; timeInterval = None'
543 544 sys.exit(0)
544 545 elif timeInterval == None:
545 546 self.timeFlag = False
546 547 else:
547 548 self.timeFlag = True
548 549
549 550
550 551 def exe(self,data,timeOfData):
551 552 """
552 553 data
553 554
554 555 timeOfData [seconds]
555 556 """
556 557
557 558 if self.timeFlag:
558 559 if self.timeOut == None:
559 560 self.timeOut = timeOfData + self.timeIntervalInSeconds
560 561
561 562 if timeOfData < self.timeOut:
562 563 if self.buffer == None:
563 564 self.buffer = data
564 565 else:
565 566 self.buffer = self.buffer + data
566 567 self.integ_counter += 1
567 568 else:
568 569 self.exitCondition = True
569 570
570 571 else:
571 572 if self.integ_counter < self.nIncohInt:
572 573 if self.buffer == None:
573 574 self.buffer = data
574 575 else:
575 576 self.buffer = self.buffer + data
576 577
577 578 self.integ_counter += 1
578 579
579 580 if self.integ_counter == self.nIncohInt:
580 581 self.exitCondition = True
581 582
582 583 if self.exitCondition:
583 584 self.data = self.buffer
584 585 self.navg = self.integ_counter
585 586 self.isReady = True
586 587 self.buffer = None
587 588 self.timeOut = None
588 589 self.integ_counter = 0
589 590 self.exitCondition = False
590 591
591 592 if self.timeFlag:
592 593 self.buffer = data
593 594 self.timeOut = timeOfData + self.timeIntervalInSeconds
594 595 else:
595 596 self.isReady = False
596 597 No newline at end of file
@@ -1,86 +1,101
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6 import os, sys
7 7 import time, datetime
8 8
9 9 path = os.path.split(os.getcwd())[0]
10 10 sys.path.append(path)
11 11
12 12 from Data.JROData import Voltage
13 13 from IO.VoltageIO import *
14 14
15 15 from Processing.VoltageProcessor import *
16
16 from Processing.SpectraProcessor import *
17 17
18 18 class TestSChain():
19 19
20 20 def __init__(self):
21 21 self.setValues()
22 22 self.createObjects()
23 23 self.testSChain()
24 24
25 25 def setValues(self):
26 26 self.path = "/home/roj-idl71/Data/RAWDATA/Meteors"
27 self.path = "/remote/puma/2012_06/Meteors"
27 28
28 self.startDate = datetime.date(2005,1,1)
29 self.endDate = datetime.date(2012,7,30)
29 self.startDate = datetime.date(2012,1,1)
30 self.endDate = datetime.date(2012,12,30)
30 31
31 32 self.startTime = datetime.time(0,0,0)
32 33 self.endTime = datetime.time(23,59,59)
33 34
35 self.nFFTPoints = 64
36
34 37 self.wrpath = "/home/roj-idl71/tmp/results"
35 38 self.profilesPerBlock = 40
36 39 self.blocksPerFile = 50
37 40
38 41 def createObjects(self):
39 42
40 43 self.readerObj = VoltageReader()
41 44 self.voltProcObj = VoltageProcessor()
42 45 self.specProcObj = SpectraProcessor()
43 46
44 47 self.voltObj1 = self.readerObj.setup(
45 48 path = self.path,
46 49 startDate = self.startDate,
47 50 endDate = self.endDate,
48 51 startTime = self.startTime,
49 52 endTime = self.endTime,
50 53 expLabel = '',
51 54 online = 0)
52 55
53 56 self.voltObj2 = self.voltProcObj.setup(dataInObj = self.voltObj1)
57 self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj2, nFFTPoints = self.nFFTPoints)
54 58
55 59 def testSChain(self):
56 60
57 61 ini = time.time()
58 62
59 63 while(True):
60 64 self.readerObj.getData()
61 65
62 66 self.voltProcObj.init()
63 67
64 self.voltProcObj.integrator(1000, overlapping=True)
68 self.voltProcObj.integrator(10, overlapping=False)
65 69 #
66 70 # self.voltProcObj.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile)
67 71
68 72
69 self.voltProcObj.plotScope(idfigure=1,
70 wintitle='test plot library',
73 # self.voltProcObj.plotScope(idfigure=0,
74 # wintitle='test plot library',
75 # driver='plplot',
76 # save=False,
77 # gpath=None,
78 # type="power")
79
80 self.specProcObj.init()
81
82 self.specProcObj.plotSpc(idfigure=1,
83 wintitle='Spectra',
71 84 driver='plplot',
85 colormap='br_green',
86 colorbar=True,
87 showprofile=False,
72 88 save=False,
73 gpath=None,
74 type="power")
89 gpath=None)
75 90
76 91 if self.readerObj.flagNoMoreFiles:
77 92 break
78 93
79 94 if self.readerObj.flagIsNewBlock:
80 95 # print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),)
81 96 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
82 datetime.datetime.utcfromtimestamp(self.readerObj.basicHeaderObj.utc + self.readerObj.basicHeaderObj.miliSecond/1000.0),)
97 datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc + self.readerObj.basicHeaderObj.miliSecond/1000.0),)
83 98
84 99
85 100 if __name__ == '__main__':
86 101 TestSChain() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now