@@ -1,391 +1,412 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import time |
|
4 | 4 | import os |
|
5 | 5 | from schainPlotLib import Driver |
|
6 | 6 | |
|
7 | 7 | class Figure: |
|
8 | 8 | |
|
9 | 9 | __isDriverOpen = False |
|
10 | 10 | __isFigureOpen = False |
|
11 | 11 | __isConfig = False |
|
12 | ||
|
12 | __counter = 0 | |
|
13 | 13 | drvObj = None |
|
14 | 14 | driver = None |
|
15 | 15 | idfigure = None |
|
16 | 16 | nframes = None |
|
17 | 17 | wintitle = None |
|
18 | 18 | colormap = None |
|
19 | 19 | overplot = None |
|
20 | 20 | colorbar = None |
|
21 | 21 | |
|
22 | 22 | frameObjList = [] |
|
23 | 23 | |
|
24 | 24 | xw = None |
|
25 | 25 | yw = None |
|
26 | 26 | |
|
27 | 27 | xmin = None |
|
28 | 28 | xmax = None |
|
29 | 29 | ymin = None |
|
30 | 30 | ymax = None |
|
31 | 31 | |
|
32 | 32 | minvalue = None |
|
33 | 33 | maxvalue = None |
|
34 | 34 | deltax = None |
|
35 | 35 | deltay = None |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | figuretitle = "" |
|
39 | 39 | xrangestep = None |
|
40 | 40 | |
|
41 | 41 | def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args): |
|
42 | 42 | |
|
43 | 43 | self.__isDriverOpen = False |
|
44 | 44 | self.__isFigureOpen = False |
|
45 | 45 | self.__isConfig = False |
|
46 | self.__counter = 0 | |
|
46 | 47 | |
|
47 | 48 | self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar) |
|
48 | 49 | self.driver = driver |
|
49 | 50 | self.idfigure = idfigure |
|
50 | 51 | self.nframes = nframes |
|
51 | 52 | self.wintitle = wintitle |
|
52 | 53 | self.colormap = colormap |
|
53 | 54 | self.overplot = overplot |
|
54 | 55 | self.colorbar = colorbar |
|
55 | 56 | |
|
56 | 57 | self.xw = xw |
|
57 | 58 | self.yw = yw |
|
58 | 59 | |
|
59 | 60 | self.frameObjList = [] |
|
60 | 61 | |
|
61 | 62 | self.drvObj.driver.setFigure() |
|
62 | 63 | self.drvObj.driver.setColormap(colormap) |
|
63 | 64 | |
|
64 | 65 | def __openDriver(self): |
|
65 | 66 | |
|
66 | 67 | self.drvObj.driver.openDriver() |
|
67 | 68 | |
|
68 | 69 | def __newPage(self): |
|
69 | 70 | |
|
70 | 71 | |
|
71 | 72 | self.drvObj.driver.openPage() |
|
72 | 73 | nrows, ncolumns = self.getSubplots() |
|
73 | 74 | self.drvObj.driver.setFigTitle(self.figuretitle) |
|
74 | 75 | self.drvObj.driver.setSubPlots(nrows, ncolumns) |
|
75 | 76 | |
|
76 | 77 | def __closePage(self): |
|
77 | 78 | |
|
78 | 79 | self.drvObj.driver.closeFigure() |
|
79 | 80 | |
|
80 | 81 | def selectFigure(self): |
|
81 | 82 | |
|
82 | 83 | self.drvObj.driver.selectFigure() |
|
83 | 84 | |
|
84 | 85 | def __isOutOfXRange(self,x): |
|
85 | 86 | try: |
|
86 | 87 | if ((x>=self.xmin) and (x<self.xmax)): |
|
87 | 88 | return 0 |
|
88 | 89 | except: |
|
89 | 90 | return 0 |
|
90 | 91 | |
|
91 | 92 | return 1 |
|
92 | 93 | |
|
93 | 94 | def changeXRange(self,x): |
|
94 | 95 | |
|
95 | 96 | pass |
|
96 | 97 | |
|
97 | 98 | def __refresh(self): |
|
98 | 99 | self.drvObj.driver.refresh() |
|
99 | 100 | |
|
100 | 101 | def createFrames(self): |
|
101 | 102 | |
|
102 | 103 | self.frameObjList = [] |
|
103 | 104 | |
|
104 | 105 | raise ValueError, "No implemented" |
|
105 | 106 | |
|
106 | 107 | def save(self,filename): |
|
107 | 108 | |
|
108 | 109 | self.drvObj.driver.save(filename) |
|
109 | 110 | |
|
110 | def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'): | |
|
111 | def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./', ratio=1): | |
|
111 | 112 | |
|
112 | 113 | nx, ny = data1D.shape |
|
113 | 114 | |
|
114 | 115 | if channelList == None: |
|
115 | 116 | channelList = range(nx) |
|
116 | 117 | |
|
117 | 118 | if x == None: |
|
118 | 119 | x = numpy.arange(data1D.size) |
|
119 | 120 | |
|
120 | 121 | if figuretitle == None: |
|
121 | 122 | self.figuretitle = "" |
|
122 | 123 | else: |
|
123 | 124 | self.figuretitle = figuretitle |
|
124 | 125 | |
|
125 | 126 | if not(self.__isDriverOpen): |
|
126 | 127 | self.__openDriver() |
|
127 | 128 | self.__isDriverOpen = True |
|
128 | 129 | |
|
129 | 130 | if not(self.__isConfig): |
|
130 | 131 | self.xmin = xmin |
|
131 | 132 | self.xmax = xmax |
|
132 | 133 | self.minvalue = minvalue |
|
133 | 134 | self.maxvalue = maxvalue |
|
134 | 135 | |
|
135 | 136 | if self.xmin == None: self.xmin = numpy.min(x) |
|
136 | 137 | if self.xmax == None: self.xmax = numpy.max(x) |
|
137 | 138 | if self.minvalue == None: self.minvalue = numpy.min(data1D) |
|
138 | 139 | if self.maxvalue == None: self.maxvalue = numpy.max(data1D) |
|
139 | 140 | |
|
140 | 141 | self.createFrames() |
|
141 | 142 | self.__isConfig = True |
|
142 | 143 | |
|
143 | 144 | |
|
144 | 145 | |
|
145 | 146 | self.selectFigure() |
|
146 | 147 | self.__newPage() |
|
147 | 148 | |
|
148 | 149 | |
|
149 | for channel in channelList: | |
|
150 | for channel in range(len(channelList)): | |
|
150 | 151 | frameObj = self.frameObjList[channel] |
|
151 | 152 | frameObj.init(xmin=self.xmin, |
|
152 | 153 | xmax=self.xmax, |
|
153 | 154 | ymin=self.minvalue, |
|
154 | 155 | ymax=self.maxvalue, |
|
155 | 156 | minvalue=self.minvalue, |
|
156 | 157 | maxvalue=self.maxvalue) |
|
157 | 158 | |
|
158 | for channel in channelList: | |
|
159 | for channel in range(len(channelList)): | |
|
159 | 160 | dataCh = data1D[channel,:] |
|
160 | 161 | frameObj = self.frameObjList[channel] |
|
161 | 162 | frameObj.plot(x, dataCh) |
|
162 | 163 | |
|
163 | 164 | self.__refresh() |
|
164 | 165 | |
|
165 | ||
|
166 | 166 | if save: |
|
167 | if self.__counter == 0: | |
|
167 | 168 | path = gpath |
|
168 | 169 | now = datetime.datetime.now() |
|
169 |
file = " |
|
|
170 | file = "plot_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond) | |
|
170 | 171 | filename = os.path.join(path,file) |
|
171 | 172 | self.save(filename) |
|
173 | self.__counter += 1 | |
|
174 | ||
|
175 | if self.__counter == ratio: | |
|
176 | self.__counter = 0 | |
|
177 | ||
|
172 | 178 | |
|
173 | 179 | self.__closePage() |
|
174 | 180 | |
|
175 | 181 | |
|
176 | 182 | def plotPcolor(self,data, |
|
177 | 183 | x=None, |
|
178 | 184 | y=None, |
|
179 | 185 | channelList=None, |
|
180 | 186 | xmin=None, |
|
181 | 187 | xmax=None, |
|
182 | 188 | ymin=None, |
|
183 | 189 | ymax=None, |
|
184 | 190 | minvalue=None, |
|
185 | 191 | maxvalue=None, |
|
186 | 192 | figuretitle=None, |
|
187 | 193 | xrangestep=None, |
|
188 | 194 | deltax=None, |
|
189 | 195 | save=False, |
|
190 | 196 | gpath='./', |
|
197 | ratio=1, | |
|
191 | 198 | cleardata=False, |
|
192 | 199 | *args): |
|
193 | 200 | |
|
194 | 201 | |
|
195 | 202 | if figuretitle == None: |
|
196 | 203 | self.figuretitle = "" |
|
197 | 204 | else: |
|
198 | 205 | self.figuretitle = figuretitle |
|
199 | 206 | |
|
200 | 207 | |
|
201 | 208 | if not(self.__isDriverOpen): |
|
202 | 209 | self.__openDriver() |
|
203 | 210 | self.__isDriverOpen = True |
|
204 | 211 | |
|
205 | 212 | if not(self.__isConfig): |
|
206 | 213 | |
|
207 | 214 | self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax) |
|
208 | 215 | |
|
209 | 216 | self.createFrames() |
|
210 | 217 | self.__isConfig = True |
|
211 | 218 | |
|
212 | 219 | if (self.__isOutOfXRange(x)): |
|
213 | 220 | |
|
214 | 221 | if not(self.changeXRange(x)): |
|
215 | 222 | return 0 |
|
216 | 223 | |
|
217 | 224 | self.__closePage() |
|
218 | 225 | self.__isFigureOpen = False |
|
219 | 226 | |
|
220 | 227 | self.selectFigure() |
|
221 | 228 | |
|
222 | 229 | if not(self.__isFigureOpen): |
|
223 | 230 | self.__newPage() |
|
224 | 231 | self.__isFigureOpen = True |
|
225 | 232 | |
|
226 | for channel in channelList: | |
|
233 | for channel in range(len(channelList)): | |
|
227 | 234 | if len(args) != 0: value = args[0][channel] |
|
228 | 235 | else: value = args |
|
229 | 236 | |
|
230 | 237 | frameObj = self.frameObjList[channel] |
|
231 | 238 | frameObj.init(self.xmin, |
|
232 | 239 | self.xmax, |
|
233 | 240 | self.ymin, |
|
234 | 241 | self.ymax, |
|
235 | 242 | self.minvalue, |
|
236 | 243 | self.maxvalue, |
|
237 | 244 | self.deltax, |
|
238 | 245 | self.deltay, |
|
239 | 246 | self.colorbar, |
|
240 | 247 | value) |
|
241 | 248 | |
|
242 | 249 | |
|
243 | for channel in channelList: | |
|
250 | for channel in range(len(channelList)): | |
|
244 | 251 | dataCh = data[channel,:] |
|
245 | 252 | frameObj = self.frameObjList[channel] |
|
246 | 253 | frameObj.plot(x, y, dataCh) |
|
247 | 254 | |
|
248 | 255 | |
|
249 | 256 | self.__refresh() |
|
257 | ||
|
258 | if save: | |
|
259 | if self.__counter == 0: | |
|
260 | path = gpath | |
|
261 | now = datetime.datetime.now() | |
|
262 | file = "pcolor_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond) | |
|
263 | filename = os.path.join(path,file) | |
|
264 | self.save(filename) | |
|
265 | self.__counter += 1 | |
|
266 | ||
|
267 | if self.__counter == ratio: | |
|
268 | self.__counter = 0 | |
|
269 | ||
|
270 | ||
|
250 | 271 | if cleardata == True: |
|
251 | 272 | self.__closePage() |
|
252 | 273 | self.__isFigureOpen = False |
|
253 | 274 | |
|
254 | 275 | |
|
255 | 276 | |
|
256 | 277 | |
|
257 | 278 | class Frame: |
|
258 | 279 | |
|
259 | 280 | drvObj = None |
|
260 | 281 | idFrame = None |
|
261 | 282 | nplots = None |
|
262 | 283 | plotObjList = [] |
|
263 | 284 | title = "" |
|
264 | 285 | |
|
265 | 286 | def __init__(self,drvObj, idframe): |
|
266 | 287 | |
|
267 | 288 | self.drvObj = drvObj |
|
268 | 289 | self.idframe = idframe |
|
269 | 290 | nplots = None |
|
270 | 291 | self.plotObjList = [] |
|
271 | 292 | |
|
272 | 293 | self.createPlots() |
|
273 | 294 | |
|
274 | 295 | def createPlots(self): |
|
275 | 296 | raise ValueError, "No implemented" |
|
276 | 297 | |
|
277 | 298 | def getScreenPosMainPlot(self): |
|
278 | 299 | raise ValueError, "No implemented" |
|
279 | 300 | |
|
280 | 301 | def getScreenPosGraph1(self): |
|
281 | 302 | raise ValueError, "No implemented" |
|
282 | 303 | |
|
283 | 304 | def getScreenPos(self, nplot): |
|
284 | 305 | |
|
285 | 306 | if nplot == 0: |
|
286 | 307 | xi, yi, xw, yw = self.getScreenPosMainPlot() |
|
287 | 308 | |
|
288 | 309 | if nplot == 1: |
|
289 | 310 | xi, yi, xw, yw = self.getScreenPosGraph1() |
|
290 | 311 | |
|
291 | 312 | return xi, yi, xw, yw |
|
292 | 313 | |
|
293 | 314 | |
|
294 | 315 | def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args): |
|
295 | 316 | |
|
296 | 317 | for plotObj in self.plotObjList: |
|
297 | 318 | plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args) |
|
298 | 319 | plotObj.plotBox() |
|
299 | 320 | |
|
300 | 321 | |
|
301 | 322 | |
|
302 | 323 | class Plot: |
|
303 | 324 | |
|
304 | 325 | drvObj = None |
|
305 | 326 | idframe = None |
|
306 | 327 | idplot = None |
|
307 | 328 | xi = None |
|
308 | 329 | yi = None |
|
309 | 330 | xw = None |
|
310 | 331 | yw = None |
|
311 | 332 | |
|
312 | 333 | title = "" |
|
313 | 334 | xlabel = "" |
|
314 | 335 | ylabel = "" |
|
315 | 336 | xaxisastime = None |
|
316 | 337 | timefmt = None |
|
317 | 338 | xopt = "" |
|
318 | 339 | yopt = "" |
|
319 | 340 | xpos = None |
|
320 | 341 | ypos = None |
|
321 | 342 | szchar = None |
|
322 | 343 | idframe = None |
|
323 | 344 | idplot = None |
|
324 | 345 | colorbar = None |
|
325 | 346 | cbxpos = None |
|
326 | 347 | cbypos = None |
|
327 | 348 | |
|
328 | 349 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): |
|
329 | 350 | |
|
330 | 351 | self.drvObj = drvObj |
|
331 | 352 | self.idframe = idframe |
|
332 | 353 | self.idplot = idplot |
|
333 | 354 | self.xi = xi |
|
334 | 355 | self.yi = yi |
|
335 | 356 | self.xw = xw |
|
336 | 357 | self.yw = yw |
|
337 | 358 | |
|
338 | 359 | |
|
339 | 360 | def plotBox(self): |
|
340 | 361 | |
|
341 | 362 | self.drvObj.driver.plotBox(self.idframe, |
|
342 | 363 | self.xpos, |
|
343 | 364 | self.ypos, |
|
344 | 365 | self.xmin, |
|
345 | 366 | self.xmax, |
|
346 | 367 | self.ymin, |
|
347 | 368 | self.ymax, |
|
348 | 369 | self.minvalue, |
|
349 | 370 | self.maxvalue, |
|
350 | 371 | self.xopt, |
|
351 | 372 | self.yopt, |
|
352 | 373 | self.szchar, |
|
353 | 374 | self.xaxisastime, |
|
354 | 375 | self.timefmt) |
|
355 | 376 | |
|
356 | 377 | self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title) |
|
357 | 378 | |
|
358 | 379 | if self.colorbar: |
|
359 | 380 | self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos) |
|
360 | 381 | |
|
361 | 382 | def plotPcolor(self, x, y, z, deltax, deltay, getGrid): |
|
362 | 383 | |
|
363 | 384 | self.drvObj.driver.pcolor(self.idframe, |
|
364 | 385 | self.xpos, |
|
365 | 386 | self.ypos, |
|
366 | 387 | z, |
|
367 | 388 | x, |
|
368 | 389 | y, |
|
369 | 390 | self.xmin, |
|
370 | 391 | self.xmax, |
|
371 | 392 | self.ymin, |
|
372 | 393 | self.ymax, |
|
373 | 394 | self.minvalue, |
|
374 | 395 | self.maxvalue, |
|
375 | 396 | deltax, |
|
376 | 397 | deltay, |
|
377 | 398 | getGrid, |
|
378 | 399 | self.xaxisastime, |
|
379 | 400 | self.timefmt) |
|
380 | 401 | |
|
381 | 402 | def plotBasicLine(self,x, y, color): |
|
382 | 403 | """ |
|
383 | 404 | Inputs: |
|
384 | 405 | x: |
|
385 | 406 | |
|
386 | 407 | y: |
|
387 | 408 | |
|
388 | 409 | color: |
|
389 | 410 | """ |
|
390 | 411 | self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color) |
|
391 | 412 | No newline at end of file |
@@ -1,665 +1,695 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import time |
|
4 | 4 | from schainPlot import * |
|
5 | 5 | |
|
6 | 6 | class CrossSpc(Figure): |
|
7 | 7 | overplot = 0 |
|
8 | 8 | xw = 900 |
|
9 | 9 | yw = 650 |
|
10 | 10 | showprofile = False |
|
11 | 11 | signalA = None |
|
12 | 12 | signalB = None |
|
13 | 13 | coherence = None |
|
14 | 14 | phase = None |
|
15 | 15 | |
|
16 | 16 | def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
17 | 17 | Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar) |
|
18 | 18 | |
|
19 | 19 | self.showprofile = showprofile |
|
20 | 20 | self.signalA = None |
|
21 | 21 | self.signalB = None |
|
22 | 22 | self.coherence = None |
|
23 | 23 | self.phase = None |
|
24 | 24 | |
|
25 | 25 | def getSubplots(self): |
|
26 | 26 | nrows = self.nframes |
|
27 | 27 | ncolumns = 1 |
|
28 | 28 | return nrows, ncolumns |
|
29 | 29 | |
|
30 | 30 | def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args): |
|
31 | 31 | |
|
32 | 32 | if xmin == None: xmin = numpy.min(x) |
|
33 | 33 | if xmax == None: xmax = numpy.max(x) |
|
34 | 34 | if ymin == None: ymin = numpy.min(y) |
|
35 | 35 | if ymax == None: ymax = numpy.max(y) |
|
36 | 36 | if minvalue == None: minvalue = 20. |
|
37 | 37 | if maxvalue == None: maxvalue = 90. |
|
38 | 38 | |
|
39 | 39 | self.signalA = self.data[0] |
|
40 | 40 | self.signalB = self.data[1] |
|
41 | 41 | self.coherence = self.data[2] |
|
42 | 42 | self.phase = self.data[3] |
|
43 | 43 | |
|
44 | 44 | self.xmin = xmin |
|
45 | 45 | self.xmax = xmax |
|
46 | 46 | self.minrange = ymin |
|
47 | 47 | self.maxrange = ymax |
|
48 | 48 | self.ymin = ymin |
|
49 | 49 | self.ymax = ymax |
|
50 | 50 | self.minvalue = minvalue |
|
51 | 51 | self.maxvalue = maxvalue |
|
52 | 52 | |
|
53 | 53 | def changeXRange(self, *args): |
|
54 | 54 | pass |
|
55 | 55 | |
|
56 | 56 | def createFrames(self): |
|
57 | 57 | self.frameObjList = [] |
|
58 | 58 | |
|
59 | 59 | for frame in range(self.nframes): |
|
60 | 60 | frameObj = CrossSpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile) |
|
61 | 61 | self.frameObjList.append(frameObj) |
|
62 | 62 | |
|
63 | 63 | |
|
64 | 64 | class CrossSpcFrame(Frame): |
|
65 | xi = None | |
|
66 | xw = None | |
|
67 | yi = None | |
|
68 | yw = None | |
|
69 | alpha = None | |
|
65 | 70 | def __init__(self): |
|
66 | 71 | self.drvObj = drvObj |
|
67 | 72 | self.idframe = idframe |
|
68 | 73 | self.nplots = 4 |
|
69 | 74 | |
|
70 | 75 | if showprofile: |
|
71 | 76 | self.nplots += 4 |
|
72 | 77 | |
|
73 | 78 | self.colorbar = colorbar |
|
74 | 79 | self.showprofile = showprofile |
|
80 | self.xi = 0. | |
|
81 | self.xw = 0. | |
|
82 | self.yi = 0. | |
|
83 | self.yw = 0. | |
|
84 | self.alpha = 1. | |
|
85 | ||
|
75 | 86 | self.createPlots() |
|
76 | 87 | |
|
77 | 88 | def createPlots(self): |
|
78 | 89 | plotObjList = [] |
|
79 | 90 | idplot = 0 |
|
80 | 91 | counter_plot = 0 |
|
81 | 92 | for i in range(self.nplots): |
|
82 | 93 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
83 | 94 | plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar) |
|
84 | 95 | plotObjList.append(plotObj) |
|
85 | 96 | |
|
86 | 97 | if self.showprofile: |
|
87 | xi, yi, xw, yw = self.getScreenPos(idplot) | |
|
98 | xi, yi, xw, yw = self.getScreenPosGraph1(idplot) | |
|
88 | 99 | type = "pwbox" |
|
89 | 100 | title = "" |
|
90 | 101 | xlabel = "dB" |
|
91 | 102 | ylabel = "" |
|
92 | 103 | idplot += 1 |
|
93 | 104 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel) |
|
94 | 105 | plotObjList.append(plotObj) |
|
95 | 106 | idplot += 1 |
|
96 | 107 | |
|
97 | 108 | self.plotObjList = plotObjList |
|
98 | 109 | |
|
99 | def getScreenPos(self,idplot): | |
|
100 | pass | |
|
110 | # def getScreenPos(self,idplot): | |
|
111 | # pass | |
|
101 | 112 | |
|
102 |
def getScreenPos |
|
|
103 |
|
|
|
113 | def getScreenPos(self, diplot): | |
|
114 | ||
|
115 | xi = self.xi | |
|
116 | xw = self.xw | |
|
104 | 117 | |
|
105 | 118 | if self.showprofile: |
|
106 |
|
|
|
119 | width = 0.55 | |
|
120 | xw += width | |
|
121 | ||
|
122 | ||
|
123 | ||
|
124 | ||
|
125 | self.xi = 0.15 + idplot*self.alpha | |
|
126 | ||
|
127 | if self.showprofile: | |
|
128 | width = 0.55 | |
|
129 | self.xw += width | |
|
107 | 130 | |
|
108 | 131 | else: |
|
109 |
|
|
|
132 | width = 0.65 | |
|
133 | self.xw += width | |
|
110 | 134 | |
|
111 | 135 | if self.colorbar: |
|
112 | xw = xw - 0.06 | |
|
136 | self.xw = self.xw - 0.06 | |
|
137 | ||
|
138 | ||
|
139 | self.alpha = self.xw | |
|
113 | 140 | |
|
114 | 141 | yi = 0.20; yw = 0.75 |
|
115 | 142 | |
|
116 | 143 | return xi, yi, xw, yw |
|
117 | 144 | |
|
118 | 145 | def getScreenPosGraph1(self): |
|
119 | 146 | if self.colorbar: |
|
120 |
xi = |
|
|
147 | xi = self.xw + 0.08 | |
|
121 | 148 | else: |
|
122 |
xi = |
|
|
149 | xi = self.xw + 0.05 | |
|
150 | ||
|
151 | xw = xi + 0.2 | |
|
152 | ||
|
153 | self.alpha = xw | |
|
154 | ||
|
155 | if self.colorbar: | |
|
156 | self.xi = 0.65 + 0.08 | |
|
157 | else: | |
|
158 | self.xi = 0.75 + 0.05 | |
|
123 | 159 | |
|
124 | 160 | xw = xi + 0.2 |
|
125 | 161 | |
|
126 | 162 | yi = 0.2; yw = 0.75 |
|
127 | 163 | |
|
128 | 164 | return xi, yi, xw, yw |
|
129 | 165 | |
|
130 | 166 | def plot(self,x, y, data): |
|
131 | 167 | plotObj = self.plotObjList[0] |
|
132 | 168 | plotObj.plot(x,y,data) |
|
133 | 169 | |
|
134 | 170 | if self.showprofile: |
|
135 | 171 | plotObj = self.plotObjList[1] |
|
136 | 172 | avg_data = numpy.average(data, axis=0) |
|
137 | 173 | plotObj.plot(avg_data,y) |
|
138 | 174 | |
|
139 | 175 | |
|
140 | 176 | class SpcFigure(Figure): |
|
141 | 177 | overplot = 0 |
|
142 | 178 | xw = 900 |
|
143 | 179 | yw = 650 |
|
144 | 180 | showprofile = False |
|
145 | 181 | |
|
146 | 182 | def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
147 | 183 | Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar) |
|
148 | 184 | |
|
149 | 185 | self.showprofile = showprofile |
|
150 | 186 | |
|
151 | 187 | def getSubplots(self): |
|
152 | 188 | ncolumns = int(numpy.sqrt(self.nframes)+0.9) |
|
153 | 189 | nrows = int(self.nframes*1./ncolumns + 0.9) |
|
154 | 190 | |
|
155 | 191 | return nrows, ncolumns |
|
156 | 192 | |
|
157 | 193 | def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args): |
|
158 | 194 | |
|
159 | 195 | if xmin == None: xmin = numpy.min(x) |
|
160 | 196 | if xmax == None: xmax = numpy.max(x) |
|
161 | 197 | if ymin == None: ymin = numpy.min(y) |
|
162 | 198 | if ymax == None: ymax = numpy.max(y) |
|
163 | 199 | if minvalue == None: minvalue = 20. |
|
164 | 200 | if maxvalue == None: maxvalue = 90. |
|
165 | 201 | |
|
166 | 202 | self.xmin = xmin |
|
167 | 203 | self.xmax = xmax |
|
168 | 204 | self.minrange = ymin |
|
169 | 205 | self.maxrange = ymax |
|
170 | 206 | self.ymin = ymin |
|
171 | 207 | self.ymax = ymax |
|
172 | 208 | self.minvalue = minvalue |
|
173 | 209 | self.maxvalue = maxvalue |
|
174 | 210 | |
|
175 | 211 | |
|
176 | 212 | def changeXRange(self, *args): |
|
177 | 213 | pass |
|
178 | 214 | |
|
179 | 215 | def createFrames(self): |
|
180 | 216 | |
|
181 | 217 | self.frameObjList = [] |
|
182 | 218 | |
|
183 | 219 | for frame in range(self.nframes): |
|
184 | 220 | frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile) |
|
185 | 221 | self.frameObjList.append(frameObj) |
|
186 | 222 | |
|
187 | 223 | class SpcFrame(Frame): |
|
188 | 224 | def __init__(self,drvObj,idframe,colorbar,showprofile): |
|
189 | 225 | self.drvObj = drvObj |
|
190 | 226 | self.idframe = idframe |
|
191 | 227 | self.nplots = 1 |
|
192 | 228 | |
|
193 | 229 | if showprofile: |
|
194 | 230 | self.nplots += 1 |
|
195 | 231 | |
|
196 | 232 | self.colorbar = colorbar |
|
197 | 233 | self.showprofile = showprofile |
|
198 | 234 | self.createPlots() |
|
199 | 235 | |
|
200 | 236 | def createPlots(self): |
|
201 | 237 | plotObjList = [] |
|
202 | 238 | idplot = 0 |
|
203 | 239 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
204 | 240 | plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar) |
|
205 | 241 | plotObjList.append(plotObj) |
|
206 | 242 | |
|
207 | 243 | if self.showprofile: |
|
208 | 244 | idplot = 1 |
|
209 | 245 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
210 | 246 | type = "pwbox" |
|
211 | 247 | title = "" |
|
212 | 248 | xlabel = "dB" |
|
213 | 249 | ylabel = "" |
|
214 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel) | |
|
250 | szchar = 0.70 | |
|
251 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar) | |
|
215 | 252 | plotObjList.append(plotObj) |
|
216 | 253 | |
|
217 | 254 | self.plotObjList = plotObjList |
|
218 | 255 | |
|
219 | 256 | def getScreenPosMainPlot(self): |
|
220 | 257 | xi = 0.15 |
|
221 | 258 | |
|
222 | 259 | if self.showprofile: |
|
223 | 260 | xw = 0.55 |
|
224 | 261 | |
|
225 | 262 | else: |
|
226 | 263 | xw = 0.65 |
|
227 | 264 | |
|
228 | 265 | if self.colorbar: |
|
229 | 266 | xw = xw - 0.06 |
|
230 | 267 | |
|
231 | 268 | yi = 0.20; yw = 0.75 |
|
232 | 269 | |
|
233 | 270 | return xi, yi, xw, yw |
|
234 | 271 | |
|
235 | 272 | def getScreenPosGraph1(self): |
|
236 | 273 | if self.colorbar: |
|
237 | 274 | xi = 0.65 + 0.08 |
|
238 | 275 | else: |
|
239 | 276 | xi = 0.75 + 0.05 |
|
240 | 277 | |
|
241 | 278 | xw = xi + 0.2 |
|
242 | 279 | |
|
243 | 280 | yi = 0.2; yw = 0.75 |
|
244 | 281 | |
|
245 | 282 | return xi, yi, xw, yw |
|
246 | 283 | |
|
247 | 284 | def plot(self,x, y, data): |
|
248 | 285 | plotObj = self.plotObjList[0] |
|
249 | 286 | plotObj.plot(x,y,data) |
|
250 | 287 | |
|
251 | 288 | if self.showprofile: |
|
252 | 289 | plotObj = self.plotObjList[1] |
|
253 | 290 | avg_data = numpy.average(data, axis=0) |
|
254 | 291 | plotObj.plot(avg_data,y) |
|
255 | 292 | |
|
256 | 293 | class SpcPlot(Plot): |
|
257 | 294 | |
|
258 | 295 | getGrid = True |
|
259 | 296 | |
|
260 | 297 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar): |
|
261 | 298 | self.drvObj = drvObj |
|
262 | 299 | self.idframe = idframe |
|
263 | 300 | self.idplot = idplot |
|
264 | 301 | self.xi = xi |
|
265 | 302 | self.yi = yi |
|
266 | 303 | self.xw = xw |
|
267 | 304 | self.yw = yw |
|
268 | 305 | self.colorbar = colorbar |
|
269 | 306 | |
|
270 | 307 | if self.colorbar: |
|
271 | 308 | cbxi = xw + 0.03 |
|
272 | 309 | cbxw = cbxi + 0.03 |
|
273 | 310 | cbyi = yi |
|
274 | 311 | cbyw = yw |
|
275 | 312 | self.cbxpos = [cbxi,cbxw] |
|
276 | 313 | self.cbypos = [cbyi,cbyw] |
|
277 | 314 | |
|
278 | 315 | self.xpos = [self.xi,self.xw] |
|
279 | 316 | self.ypos = [self.yi,self.yw] |
|
280 | 317 | self.xaxisastime = False |
|
281 | 318 | self.timefmt = None |
|
282 | 319 | self.xopt = "bcnst" |
|
283 | 320 | self.yopt = "bcnstv" |
|
284 | 321 | |
|
285 | 322 | self.szchar = 0.7 |
|
286 | 323 | self.strforchannel = "Channel %d"%self.idframe |
|
287 | 324 | self.xlabel = "m/s" |
|
288 | 325 | self.ylabel = "Range (Km)" |
|
289 | 326 | |
|
290 | 327 | def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args): |
|
291 | 328 | self.xmin = xmin |
|
292 | 329 | self.xmax = xmax |
|
293 | 330 | self.ymin = ymin |
|
294 | 331 | self.ymax = ymax |
|
295 | 332 | self.minvalue = minvalue |
|
296 | 333 | self.maxvalue = maxvalue |
|
297 | 334 | self.colorbar = args[2] |
|
298 | 335 | self.title = "%s - %s"%(self.strforchannel,args[3]) |
|
299 | 336 | |
|
300 | 337 | |
|
301 | 338 | |
|
302 | 339 | def plot(self, x, y, data): |
|
303 | 340 | z = data |
|
304 | 341 | deltax = None |
|
305 | 342 | deltay = None |
|
306 | 343 | self.plotPcolor(x, y, z, deltax, deltay, self.getGrid) |
|
307 | 344 | self.getGrid = False |
|
308 | 345 | |
|
309 | 346 | |
|
310 | 347 | class RTIFigure(Figure): |
|
311 | 348 | overplot = 1 |
|
312 | 349 | xw = 700 |
|
313 | 350 | yw = 650 |
|
314 | 351 | showprofile = False |
|
315 | 352 | starttime = None |
|
316 | 353 | endtime = None |
|
317 | 354 | minrange = None |
|
318 | 355 | maxrange = None |
|
319 | 356 | minvalue = None |
|
320 | 357 | maxvalue = None |
|
321 | 358 | xrangestepinsecs = None |
|
322 | ||
|
359 | timefmt=None | |
|
323 | 360 | |
|
324 | 361 | def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False): |
|
325 | 362 | Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar) |
|
326 | 363 | |
|
327 | 364 | self.showprofile = showprofile |
|
328 | 365 | |
|
329 | 366 | def getSubplots(self): |
|
330 | 367 | nrows = self.nframes |
|
331 | 368 | ncolumns = 1 |
|
332 | 369 | return nrows, ncolumns |
|
333 | 370 | |
|
334 | 371 | def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep, deltax): |
|
335 | 372 | |
|
336 | 373 | self.starttime = xmin |
|
337 | 374 | self.endtime = xmax |
|
338 | 375 | |
|
339 | 376 | cdatetime = datetime.datetime.utcfromtimestamp(x) |
|
340 | 377 | |
|
341 | 378 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second) |
|
342 | if ((xrangestep == 0) or (xrangestep == None)): | |
|
343 | maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second) | |
|
344 | self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple()) | |
|
345 | npoints = 1000. | |
|
346 | if xrangestep == 1: | |
|
347 | maxdatetime = mindatetime + datetime.timedelta(hours=1) | |
|
348 | self.xrangestepinsecs = 60*60. | |
|
349 | npoints = 500. | |
|
350 | if xrangestep == 2: | |
|
351 | maxdatetime = mindatetime + datetime.timedelta(minutes=1) | |
|
352 | self.xrangestepinsecs = 60. | |
|
353 | npoints = 250. | |
|
354 | if xrangestep == 3: | |
|
355 | maxdatetime = mindatetime + datetime.timedelta(seconds=1) | |
|
356 | self.xrangestepinsecs = 1. | |
|
357 | npoints = 125. | |
|
379 | ||
|
380 | maxdatetime = mindatetime + datetime.timedelta(seconds=xrangestep) | |
|
381 | self.xrangestepinsecs = xrangestep | |
|
358 | 382 | |
|
359 | 383 | xmin = time.mktime(mindatetime.timetuple()) |
|
360 | 384 | xmax = time.mktime(maxdatetime.timetuple()) |
|
361 | 385 | |
|
362 | deltax1 = (xmax-xmin) / npoints | |
|
363 | # deltax = timeInterval | |
|
386 | if self.xrangestepinsecs<=60.: | |
|
387 | self.timefmt="%H:%M:%S" | |
|
388 | ||
|
389 | if self.xrangestepinsecs>0. and self.xrangestepinsecs<=1200.: | |
|
390 | self.timefmt="%H:%M:%S" | |
|
364 | 391 | |
|
392 | if self.xrangestepinsecs>1200. and self.xrangestepinsecs<=86400.: | |
|
393 | self.timefmt="%H:%M" | |
|
394 | ||
|
395 | if self.xrangestepinsecs>86400.: | |
|
396 | self.timefmt="%y:%m:%d:%H" | |
|
365 | 397 | |
|
366 | 398 | if ymin == None: ymin = numpy.min(y) |
|
367 | 399 | if ymax == None: ymax = numpy.max(y) |
|
368 | 400 | |
|
369 | 401 | if minvalue == None: minvalue = 0. |
|
370 | 402 | if maxvalue == None: maxvalue = 50. |
|
371 | 403 | |
|
372 | 404 | self.xmin = xmin |
|
373 | 405 | self.xmax = xmax |
|
374 | 406 | self.minrange = ymin |
|
375 | 407 | self.maxrange = ymax |
|
376 | 408 | self.ymin = ymin |
|
377 | 409 | self.ymax = ymax |
|
378 | 410 | self.minvalue = minvalue |
|
379 | 411 | self.maxvalue = maxvalue |
|
380 | 412 | self.xrangestep = xrangestep |
|
381 | 413 | self.deltax = deltax |
|
382 | 414 | |
|
383 | 415 | def changeXRange(self,x): |
|
384 | 416 | |
|
385 | 417 | cdatetime = datetime.datetime.utcfromtimestamp(x) |
|
386 | 418 | |
|
387 | 419 | if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)): |
|
388 | if self.xrangestep == 1: | |
|
389 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second) | |
|
390 | ||
|
391 | if self.xrangestep == 2: | |
|
392 | mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second) | |
|
393 | 420 |
|
|
394 | if self.xrangestep == 3: | |
|
395 | 421 |
|
|
396 | 422 | |
|
397 | 423 | self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone |
|
398 | 424 | self.xmax = self.xmin + self.xrangestepinsecs |
|
399 | 425 | |
|
400 | 426 | self.figuretitle = "%s %s : %s"%(self.figuretitle, |
|
401 | 427 | datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"), |
|
402 | 428 | datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S")) |
|
403 | 429 | return 1 |
|
404 | 430 | |
|
405 | 431 | return 0 |
|
406 | 432 | |
|
407 | 433 | def createFrames(self): |
|
408 | 434 | |
|
409 | 435 | self.frameObjList = [] |
|
410 | 436 | |
|
411 | 437 | for frame in range(self.nframes): |
|
412 | frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile) | |
|
438 | frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile, self.timefmt) | |
|
413 | 439 | self.frameObjList.append(frameObj) |
|
414 | 440 | |
|
415 | 441 | class RTIFrame(Frame): |
|
416 | def __init__(self,drvObj,idframe,colorbar,showprofile): | |
|
442 | def __init__(self,drvObj,idframe,colorbar,showprofile, timefmt): | |
|
417 | 443 | self.drvObj = drvObj |
|
418 | 444 | self.idframe = idframe |
|
419 | 445 | self.nplots = 1 |
|
420 | 446 | |
|
421 | 447 | if showprofile: |
|
422 | 448 | self.nplots += 1 |
|
423 | 449 | |
|
424 | 450 | self.colorbar = colorbar |
|
425 | 451 | self.showprofile = showprofile |
|
452 | self.timefmt = timefmt | |
|
426 | 453 | self.createPlots() |
|
427 | 454 | |
|
428 | 455 | def createPlots(self): |
|
429 | 456 | plotObjList = [] |
|
430 | 457 | |
|
431 | 458 | idplot = 0 |
|
432 | 459 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
433 | 460 | |
|
434 | plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar) | |
|
461 | plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar, self.timefmt) | |
|
435 | 462 | plotObjList.append(plotObj) |
|
436 | 463 | |
|
437 | 464 | if self.showprofile: |
|
438 | 465 | idplot = 1 |
|
439 | 466 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
440 | 467 | type = "pwbox" |
|
441 | 468 | title = "" |
|
442 | 469 | xlabel = "dB" |
|
443 | 470 | ylabel = "" |
|
444 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel) | |
|
471 | szchar = 0.75 | |
|
472 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar) | |
|
445 | 473 | plotObjList.append(plotObj) |
|
446 | 474 | |
|
447 | 475 | self.plotObjList = plotObjList |
|
448 | 476 | |
|
449 | 477 | def getScreenPosMainPlot(self): |
|
450 | 478 | xi = 0.07 |
|
451 | 479 | if self.showprofile: |
|
452 | 480 | xw = 0.65 |
|
453 | 481 | else: |
|
454 | 482 | xw = 0.9 |
|
455 | 483 | |
|
456 | 484 | if self.colorbar: |
|
457 | 485 | xw = xw - 0.06 |
|
458 | 486 | |
|
459 | 487 | yi = 0.20; yw = 0.75 |
|
460 | 488 | |
|
461 | 489 | return xi, yi, xw, yw |
|
462 | 490 | |
|
463 | 491 | def getScreenPosGraph1(self): |
|
464 | 492 | if self.colorbar: |
|
465 | 493 | xi = 0.65 + 0.08 |
|
466 | 494 | else: |
|
467 | 495 | xi = 0.9 + 0.05 |
|
468 | 496 | |
|
469 | 497 | xw = xi + 0.2 |
|
470 | 498 | |
|
471 | 499 | yi = 0.2; yw = 0.75 |
|
472 | 500 | |
|
473 | 501 | return xi, yi, xw, yw |
|
474 | 502 | |
|
475 | 503 | def plot(self, currenttime, range, data): |
|
476 | 504 | plotObj = self.plotObjList[0] |
|
477 | 505 | plotObj.plot(currenttime,range,data) |
|
478 | 506 | |
|
479 | 507 | if self.showprofile: |
|
480 | 508 | plotObj = self.plotObjList[1] |
|
481 | 509 | plotObj.plot(data,range) |
|
482 | 510 | |
|
483 | 511 | |
|
484 | 512 | class RTIPlot(Plot): |
|
485 | 513 | deltax = None |
|
486 | 514 | deltay = None |
|
487 | 515 | xrange = [None,None] |
|
488 | 516 | xminpos = None |
|
489 | 517 | xmaxpos = None |
|
490 | 518 | xg = None |
|
491 | 519 | yg = None |
|
492 | 520 | |
|
493 | def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar): | |
|
521 | def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar, timefmt): | |
|
494 | 522 | self.drvObj = drvObj |
|
495 | 523 | self.idframe = idframe |
|
496 | 524 | self.idplot = idplot |
|
497 | 525 | self.xi = xi |
|
498 | 526 | self.yi = yi |
|
499 | 527 | self.xw = xw |
|
500 | 528 | self.yw = yw |
|
501 | 529 | self.colorbar = colorbar |
|
502 | 530 | |
|
503 | 531 | if self.colorbar: |
|
504 | 532 | cbxi = xw + 0.03 |
|
505 | 533 | cbxw = cbxi + 0.03 |
|
506 | 534 | cbyi = yi |
|
507 | 535 | cbyw = yw |
|
508 | 536 | self.cbxpos = [cbxi,cbxw] |
|
509 | 537 | self.cbypos = [cbyi,cbyw] |
|
510 | 538 | |
|
511 | 539 | self.xpos = [self.xi,self.xw] |
|
512 | 540 | self.ypos = [self.yi,self.yw] |
|
513 | 541 | self.xaxisastime = True |
|
514 |
self.timefmt = |
|
|
542 | self.timefmt = timefmt | |
|
515 | 543 | self.xopt = "bcnstd" |
|
516 | 544 | self.yopt = "bcnstv" |
|
517 | 545 | |
|
518 | 546 | self.szchar = 1.0 |
|
519 | 547 | self.title = "Channel %d"%self.idframe |
|
520 | 548 | self.xlabel = "Local Time" |
|
521 | 549 | self.ylabel = "Range (Km)" |
|
522 | 550 | |
|
523 | 551 | |
|
524 | 552 | def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args): |
|
525 | 553 | self.xmin = xmin |
|
526 | 554 | self.xmax = xmax |
|
527 | 555 | self.ymin = ymin |
|
528 | 556 | self.ymax = ymax |
|
529 | 557 | self.minvalue = minvalue |
|
530 | 558 | self.maxvalue = maxvalue |
|
531 | 559 | self.deltax = deltax |
|
532 | 560 | self.deltay = deltay |
|
533 | 561 | self.colorbar = colorbar |
|
534 | 562 | |
|
535 | 563 | def plot(self, currenttime, range, data): |
|
536 | 564 | |
|
537 | 565 | if self.xmaxpos == None: |
|
538 | 566 | self.xmaxpos = currenttime |
|
539 | 567 | |
|
540 | 568 | # if currenttime >= self.xmaxpos: |
|
541 | 569 | |
|
542 | 570 | self.xminpos = currenttime |
|
543 | 571 | self.xmaxpos = currenttime + self.deltax |
|
544 | 572 | x = [currenttime] |
|
545 | 573 | y = range |
|
546 | 574 | z = numpy.reshape(data, (1,-1)) |
|
547 | 575 | getGrid = True |
|
548 | 576 | |
|
549 | 577 | self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid) |
|
550 | 578 | |
|
551 | 579 | |
|
552 | 580 | class ScopeFigure(Figure): |
|
553 | 581 | overplot = 0 |
|
554 | 582 | xw = 700 |
|
555 | 583 | yw = 650 |
|
556 | 584 | colorbar = None |
|
557 | 585 | |
|
558 | 586 | def __init__(self,idfigure,nframes,wintitle,driver): |
|
559 | 587 | colormap = None |
|
560 | 588 | colorbar = False |
|
561 | 589 | |
|
562 | 590 | Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar) |
|
563 | 591 | |
|
564 | 592 | |
|
565 | 593 | def getSubplots(self): |
|
566 | 594 | nrows = self.nframes |
|
567 | 595 | ncolumns = 1 |
|
568 | 596 | return nrows, ncolumns |
|
569 | 597 | |
|
570 | 598 | def createFrames(self): |
|
571 | 599 | |
|
572 | 600 | self.frameObjList = [] |
|
573 | 601 | |
|
574 | 602 | for frame in range(self.nframes): |
|
575 | 603 | frameObj = ScopeFrame(self.drvObj,frame + 1) |
|
576 | 604 | self.frameObjList.append(frameObj) |
|
577 | 605 | |
|
578 | 606 | |
|
579 | 607 | class ScopeFrame(Frame): |
|
580 | # plotObjList = [] | |
|
581 | 608 | xlabel = "" |
|
582 | 609 | ylabel = "" |
|
583 | 610 | title = "" |
|
611 | szchar = 1.1 | |
|
612 | ||
|
584 | 613 | def __init__(self,drvObj,idframe): |
|
585 | 614 | self.drvObj = drvObj |
|
586 | 615 | self.idframe = idframe |
|
587 |
self.nplots = 1 |
|
|
616 | self.nplots = 1 | |
|
588 | 617 | self.createPlots() |
|
589 | 618 | # Frame.__init__(self, drvObj, idframe) |
|
590 | 619 | |
|
591 | 620 | def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots |
|
592 | 621 | xi = 0.08; xw = 0.9 |
|
593 | 622 | yi = 0.20; yw = 0.75 |
|
594 | 623 | return xi,yi,xw,yw |
|
595 | 624 | |
|
596 | 625 | def createPlots(self): |
|
597 | 626 | plotObjList = [] |
|
598 | 627 | for idplot in range(self.nplots): |
|
599 | 628 | xi, yi, xw, yw = self.getScreenPos(idplot) |
|
600 | 629 | type = "scopebox" |
|
601 | 630 | title = "Channel %d"%self.idframe |
|
602 | 631 | xlabel = "range (Km)" |
|
603 | 632 | ylabel = "intensity" |
|
604 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel) | |
|
633 | plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, self.szchar) | |
|
605 | 634 | plotObjList.append(plotObj) |
|
635 | ||
|
606 | 636 | self.plotObjList = plotObjList |
|
607 | # self.plotObjList.append(plotObj) | |
|
637 | ||
|
608 | 638 | |
|
609 | 639 | def plot(self, x, y, z=None): |
|
610 | 640 | for plotObj in self.plotObjList: |
|
611 | 641 | plotObj.plot(x, y) |
|
612 | 642 | |
|
613 | 643 | |
|
614 | 644 | class Plot1D(Plot): |
|
615 | 645 | # type, title, xlabel, ylabel |
|
616 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel): | |
|
646 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar): | |
|
617 | 647 | self.drvObj = drvObj |
|
618 | 648 | self.idframe = idframe |
|
619 | 649 | self.idplot = idplot |
|
620 | 650 | self.xi = xi |
|
621 | 651 | self.yi = yi |
|
622 | 652 | self.xw = xw |
|
623 | 653 | self.yw = yw |
|
624 | 654 | self.xpos = [self.xi,self.xw] |
|
625 | 655 | self.ypos = [self.yi,self.yw] |
|
626 | 656 | self.xaxisastime = False |
|
627 | 657 | self.timefmt = None |
|
628 | 658 | self.xopt = "bcnst" |
|
629 | 659 | self.yopt = "bcnstv" |
|
630 |
self.szchar = |
|
|
660 | self.szchar = szchar | |
|
631 | 661 | self.type = type |
|
632 | 662 | self.title = title |
|
633 | 663 | self.xlabel = xlabel |
|
634 | 664 | self.ylabel = ylabel |
|
635 | 665 | |
|
636 | 666 | |
|
637 | 667 | |
|
638 | 668 | def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args): |
|
639 | 669 | if self.type == "pwbox": |
|
640 | 670 | self.xmin = minvalue |
|
641 | 671 | self.xmax = maxvalue |
|
642 | 672 | self.ymin = ymin |
|
643 | 673 | self.ymax = ymax |
|
644 | 674 | self.minvalue = minvalue |
|
645 | 675 | self.maxvalue = maxvalue |
|
646 | 676 | |
|
647 | 677 | else: |
|
648 | 678 | self.xmin = xmin |
|
649 | 679 | self.xmax = xmax |
|
650 | 680 | self.ymin = ymin |
|
651 | 681 | self.ymax = ymax |
|
652 | 682 | self.minvalue = minvalue |
|
653 | 683 | self.maxvalue = maxvalue |
|
654 | 684 | |
|
655 | 685 | self.colorbar = False |
|
656 | 686 | |
|
657 | 687 | def plot(self,x,y): |
|
658 | 688 | if y.dtype == "complex128": |
|
659 | 689 | color="blue" |
|
660 | 690 | self.plotBasicLine(x, y.real, color) |
|
661 | 691 | color="red" |
|
662 | 692 | self.plotBasicLine(x, y.imag, color) |
|
663 | 693 | else: |
|
664 | 694 | color="blue" |
|
665 | 695 | self.plotBasicLine(x, y, color) |
@@ -1,638 +1,639 | |||
|
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, pairsList=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 pairsList == None: |
|
74 | 74 | pairsList = dataInObj.pairsList |
|
75 | 75 | |
|
76 | 76 | if pairsList == None: |
|
77 | 77 | nPairs = 0 |
|
78 | 78 | else: |
|
79 | 79 | nPairs = len(pairsList) |
|
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.pairsList = pairsList |
|
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.pairsList != 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.dataOutObj.pairsList: |
|
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 addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
227 | 227 | crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
228 | 228 | self.plotObjList.append(crossSpcObj) |
|
229 | 229 | |
|
230 | 230 | def plotCrossSpc(self, idfigure=None, |
|
231 | 231 | xmin=None, |
|
232 | 232 | xmax=None, |
|
233 | 233 | ymin=None, |
|
234 | 234 | ymax=None, |
|
235 | 235 | minvalue=None, |
|
236 | 236 | maxvalue=None, |
|
237 | 237 | wintitle='', |
|
238 | 238 | driver='plplot', |
|
239 | 239 | colormap='br_green', |
|
240 | 240 | colorbar=True, |
|
241 | 241 | showprofile=False, |
|
242 | 242 | save=False, |
|
243 | 243 | gpath=None, |
|
244 | 244 | pairsList = None): |
|
245 | 245 | |
|
246 | 246 | if self.dataOutObj.flagNoData: |
|
247 | 247 | return 0 |
|
248 | 248 | |
|
249 | 249 | if pairsList == None: |
|
250 | 250 | pairsList = self.dataOutObj.pairsList |
|
251 | 251 | |
|
252 | 252 | nframes = len(pairsList) |
|
253 | 253 | |
|
254 | 254 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
255 | 255 | |
|
256 | 256 | y = self.dataOutObj.heightList |
|
257 | 257 | |
|
258 | 258 | |
|
259 | 259 | |
|
260 | 260 | |
|
261 | 261 | if len(self.plotObjList) <= self.plotObjIndex: |
|
262 | 262 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
263 | 263 | |
|
264 | 264 | |
|
265 | 265 | |
|
266 | 266 | |
|
267 | 267 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
268 | 268 | |
|
269 | 269 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
270 | 270 | self.plotObjList.append(spcObj) |
|
271 | 271 | |
|
272 | 272 | def plotSpc(self, idfigure=None, |
|
273 | 273 | xmin=None, |
|
274 | 274 | xmax=None, |
|
275 | 275 | ymin=None, |
|
276 | 276 | ymax=None, |
|
277 | 277 | minvalue=None, |
|
278 | 278 | maxvalue=None, |
|
279 | 279 | wintitle='', |
|
280 | 280 | driver='plplot', |
|
281 | 281 | colormap='br_green', |
|
282 | 282 | colorbar=True, |
|
283 | 283 | showprofile=False, |
|
284 | 284 | save=False, |
|
285 | 285 | gpath=None, |
|
286 | ratio=1, | |
|
286 | 287 |
channelList |
|
287 | 288 | |
|
288 | 289 | if self.dataOutObj.flagNoData: |
|
289 | 290 | return 0 |
|
290 | 291 | |
|
291 | 292 | if channelList == None: |
|
292 | 293 | channelList = self.dataOutObj.channelList |
|
293 | 294 | |
|
294 | 295 | nframes = len(channelList) |
|
295 | 296 | |
|
296 | 297 | if len(self.plotObjList) <= self.plotObjIndex: |
|
297 | 298 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
298 | 299 | |
|
299 | 300 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
300 | 301 | |
|
301 | 302 | y = self.dataOutObj.heightList |
|
302 | 303 | |
|
303 | 304 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) |
|
304 | 305 | # noisedB = 10.*numpy.log10(noise) |
|
305 | 306 | noisedB = numpy.arange(len(channelList)+1) |
|
306 | 307 | noisedB = noisedB *1.2 |
|
307 | 308 | titleList = [] |
|
308 | 309 | for i in range(len(noisedB)): |
|
309 | 310 | title = "%.2f"%noisedB[i] |
|
310 | 311 | titleList.append(title) |
|
311 | 312 | |
|
312 | 313 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
313 | 314 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
314 | 315 | figuretitle = "Spc Radar Data: %s"%dateTime |
|
315 | 316 | |
|
316 | 317 | cleardata = True |
|
317 | 318 | |
|
318 | 319 | plotObj = self.plotObjList[self.plotObjIndex] |
|
319 | 320 | |
|
320 | 321 | plotObj.plotPcolor(data=data, |
|
321 | 322 | x=x, |
|
322 | 323 | y=y, |
|
323 | 324 | channelList=channelList, |
|
324 | 325 | xmin=xmin, |
|
325 | 326 | xmax=xmax, |
|
326 | 327 | ymin=ymin, |
|
327 | 328 | ymax=ymax, |
|
328 | 329 | minvalue=minvalue, |
|
329 | 330 | maxvalue=maxvalue, |
|
330 | 331 | figuretitle=figuretitle, |
|
331 | 332 | xrangestep=None, |
|
332 | 333 | deltax=None, |
|
333 | 334 | save=save, |
|
334 | 335 | gpath=gpath, |
|
335 | 336 | cleardata=cleardata |
|
336 | 337 | ) |
|
337 | 338 | |
|
338 | 339 | self.plotObjIndex += 1 |
|
339 | 340 | |
|
340 | 341 | |
|
341 | 342 | def writeData(self, wrpath, blocksPerFile): |
|
342 | 343 | |
|
343 | 344 | if self.dataOutObj.flagNoData: |
|
344 | 345 | return 0 |
|
345 | 346 | |
|
346 | 347 | if len(self.writerObjList) <= self.writerObjIndex: |
|
347 | 348 | self.addWriter(wrpath, blocksPerFile) |
|
348 | 349 | |
|
349 | 350 | self.writerObjList[self.writerObjIndex].putData() |
|
350 | 351 | |
|
351 | 352 | self.writerObjIndex += 1 |
|
352 | 353 | |
|
353 | 354 | def integrator(self, N=None, timeInterval=None): |
|
354 | 355 | |
|
355 | 356 | if self.dataOutObj.flagNoData: |
|
356 | 357 | return 0 |
|
357 | 358 | |
|
358 | 359 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
359 | 360 | self.addIntegrator(N,timeInterval) |
|
360 | 361 | |
|
361 | 362 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
362 | 363 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
363 | 364 | |
|
364 | 365 | if myIncohIntObj.isReady: |
|
365 | 366 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
366 | 367 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
367 | 368 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
368 | 369 | self.dataOutObj.flagNoData = False |
|
369 | 370 | |
|
370 | 371 | """Calcular el ruido""" |
|
371 | 372 | self.getNoise() |
|
372 | 373 | else: |
|
373 | 374 | self.dataOutObj.flagNoData = True |
|
374 | 375 | |
|
375 | 376 | self.integratorObjIndex += 1 |
|
376 | 377 | |
|
377 | 378 | |
|
378 | 379 | class SpectraHeisProcessor: |
|
379 | 380 | |
|
380 | 381 | def __init__(self): |
|
381 | 382 | |
|
382 | 383 | self.integratorObjIndex = None |
|
383 | 384 | self.writerObjIndex = None |
|
384 | 385 | self.plotObjIndex = None |
|
385 | 386 | self.integratorObjList = [] |
|
386 | 387 | self.writerObjList = [] |
|
387 | 388 | self.plotObjList = [] |
|
388 | 389 | #self.noiseObj = Noise() |
|
389 | 390 | |
|
390 | 391 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
391 | 392 | |
|
392 | 393 | if nFFTPoints == None: |
|
393 | 394 | nFFTPoints = self.dataInObj.nHeights |
|
394 | 395 | |
|
395 | 396 | self.dataInObj = dataInObj |
|
396 | 397 | |
|
397 | 398 | if dataOutObj == None: |
|
398 | 399 | dataOutObj = SpectraHeis() |
|
399 | 400 | |
|
400 | 401 | self.dataOutObj = dataOutObj |
|
401 | 402 | |
|
402 | 403 | return self.dataOutObj |
|
403 | 404 | |
|
404 | 405 | def init(self): |
|
405 | 406 | |
|
406 | 407 | self.dataOutObj.flagNoData = True |
|
407 | 408 | |
|
408 | 409 | if self.dataInObj.flagNoData: |
|
409 | 410 | return 0 |
|
410 | 411 | |
|
411 | 412 | self.integratorObjIndex = 0 |
|
412 | 413 | self.writerObjIndex = 0 |
|
413 | 414 | self.plotObjIndex = 0 |
|
414 | 415 | |
|
415 | 416 | if self.dataInObj.type == "Voltage": |
|
416 | 417 | self.__updateObjFromInput() |
|
417 | 418 | self.__getFft() |
|
418 | 419 | self.dataOutObj.flagNoData = False |
|
419 | 420 | return |
|
420 | 421 | |
|
421 | 422 | #Other kind of data |
|
422 | 423 | if self.dataInObj.type == "SpectraHeis": |
|
423 | 424 | self.dataOutObj.copy(self.dataInObj) |
|
424 | 425 | self.dataOutObj.flagNoData = False |
|
425 | 426 | return |
|
426 | 427 | |
|
427 | 428 | raise ValueError, "The type is not valid" |
|
428 | 429 | |
|
429 | 430 | def __updateObjFromInput(self): |
|
430 | 431 | |
|
431 | 432 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
432 | 433 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
433 | 434 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
434 | 435 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
435 | 436 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
436 | 437 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
437 | 438 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
438 | 439 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
439 | 440 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
440 | 441 | self.dataOutObj.code = self.dataInObj.code |
|
441 | 442 | self.dataOutObj.nProfiles = 1 |
|
442 | 443 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights |
|
443 | 444 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
444 | 445 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData |
|
445 | 446 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
446 | 447 | self.dataOutObj.utctime = self.dataInObj.utctime |
|
447 | 448 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
448 | 449 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
449 | 450 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
450 | 451 | self.dataOutObj.nIncohInt = 1 |
|
451 | 452 | |
|
452 | 453 | def __getFft(self): |
|
453 | 454 | |
|
454 | 455 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) |
|
455 | 456 | #print fft_volt |
|
456 | 457 | #calculo de self-spectra |
|
457 | 458 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
458 | 459 | |
|
459 | 460 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
460 | 461 | self.dataOutObj.data_spc = spc |
|
461 | 462 | |
|
462 | 463 | def getSpectra(self): |
|
463 | 464 | |
|
464 | 465 | return self.dataOutObj.data_spc |
|
465 | 466 | |
|
466 | 467 | def getFrecuencies(self): |
|
467 | 468 | |
|
468 | 469 | print self.nFFTPoints |
|
469 | 470 | return numpy.arange(int(self.nFFTPoints)) |
|
470 | 471 | |
|
471 | 472 | def addIntegrator(self,N,timeInterval): |
|
472 | 473 | |
|
473 | 474 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
474 | 475 | self.integratorObjList.append(objIncohInt) |
|
475 | 476 | |
|
476 | 477 | def integrator(self, N=None, timeInterval=None): |
|
477 | 478 | |
|
478 | 479 | if self.dataOutObj.flagNoData: |
|
479 | 480 | return 0 |
|
480 | 481 | |
|
481 | 482 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
482 | 483 | self.addIntegrator(N,timeInterval) |
|
483 | 484 | |
|
484 | 485 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
485 | 486 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime) |
|
486 | 487 | |
|
487 | 488 | if myIncohIntObj.isReady: |
|
488 | 489 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
489 | 490 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg |
|
490 | 491 | self.dataOutObj.flagNoData = False |
|
491 | 492 | |
|
492 | 493 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) |
|
493 | 494 | # self.getNoise(type="sort", parm=16) |
|
494 | 495 | |
|
495 | 496 | else: |
|
496 | 497 | self.dataOutObj.flagNoData = True |
|
497 | 498 | |
|
498 | 499 | self.integratorObjIndex += 1 |
|
499 | 500 | |
|
500 | 501 | |
|
501 | 502 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
502 | 503 | |
|
503 | 504 | if idfigure==None: |
|
504 | 505 | idfigure = self.plotObjIndex |
|
505 | 506 | |
|
506 | 507 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
507 | 508 | self.plotObjList.append(scopeObj) |
|
508 | 509 | |
|
509 | 510 | def plotScope(self, |
|
510 | 511 | idfigure=None, |
|
511 | 512 | minvalue=None, |
|
512 | 513 | maxvalue=None, |
|
513 | 514 | xmin=None, |
|
514 | 515 | xmax=None, |
|
515 | 516 | wintitle='', |
|
516 | 517 | driver='plplot', |
|
517 | 518 | save=False, |
|
518 | 519 | gpath=None, |
|
519 | 520 | titleList=None, |
|
520 | 521 | xlabelList=None, |
|
521 | 522 | ylabelList=None): |
|
522 | 523 | |
|
523 | 524 | if self.dataOutObj.flagNoData: |
|
524 | 525 | return 0 |
|
525 | 526 | |
|
526 | 527 | nframes = len(self.dataOutObj.channelList) |
|
527 | 528 | |
|
528 | 529 | if len(self.plotObjList) <= self.plotObjIndex: |
|
529 | 530 | self.addScope(idfigure, nframes, wintitle, driver) |
|
530 | 531 | |
|
531 | 532 | |
|
532 | 533 | data1D = self.dataOutObj.data_spc |
|
533 | 534 | |
|
534 | 535 | x = numpy.arange(self.dataOutObj.nHeights) |
|
535 | 536 | |
|
536 | 537 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
537 | 538 | |
|
538 | 539 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
539 | 540 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
540 | 541 | |
|
541 | 542 | figureTitle = "Scope Plot Radar Data: " + date |
|
542 | 543 | |
|
543 | 544 | plotObj = self.plotObjList[self.plotObjIndex] |
|
544 | 545 | |
|
545 | 546 | plotObj.plot1DArray(data1D, |
|
546 | 547 | x, |
|
547 | 548 | self.dataOutObj.channelList, |
|
548 | 549 | xmin, |
|
549 | 550 | xmax, |
|
550 | 551 | minvalue, |
|
551 | 552 | maxvalue, |
|
552 | 553 | figureTitle, |
|
553 | 554 | save, |
|
554 | 555 | gpath) |
|
555 | 556 | |
|
556 | 557 | self.plotObjIndex += 1 |
|
557 | 558 | |
|
558 | 559 | class IncoherentIntegration: |
|
559 | 560 | |
|
560 | 561 | integ_counter = None |
|
561 | 562 | data = None |
|
562 | 563 | navg = None |
|
563 | 564 | buffer = None |
|
564 | 565 | nIncohInt = None |
|
565 | 566 | |
|
566 | 567 | def __init__(self, N = None, timeInterval = None): |
|
567 | 568 | """ |
|
568 | 569 | N |
|
569 | 570 | timeInterval - interval time [min], integer value |
|
570 | 571 | """ |
|
571 | 572 | |
|
572 | 573 | self.data = None |
|
573 | 574 | self.navg = None |
|
574 | 575 | self.buffer = None |
|
575 | 576 | self.timeOut = None |
|
576 | 577 | self.exitCondition = False |
|
577 | 578 | self.isReady = False |
|
578 | 579 | self.nIncohInt = N |
|
579 | 580 | self.integ_counter = 0 |
|
580 | 581 | if timeInterval!=None: |
|
581 | 582 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
582 | 583 | |
|
583 | 584 | if ((timeInterval==None) and (N==None)): |
|
584 | 585 | print 'N = None ; timeInterval = None' |
|
585 | 586 | sys.exit(0) |
|
586 | 587 | elif timeInterval == None: |
|
587 | 588 | self.timeFlag = False |
|
588 | 589 | else: |
|
589 | 590 | self.timeFlag = True |
|
590 | 591 | |
|
591 | 592 | |
|
592 | 593 | def exe(self,data,timeOfData): |
|
593 | 594 | """ |
|
594 | 595 | data |
|
595 | 596 | |
|
596 | 597 | timeOfData [seconds] |
|
597 | 598 | """ |
|
598 | 599 | |
|
599 | 600 | if self.timeFlag: |
|
600 | 601 | if self.timeOut == None: |
|
601 | 602 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
602 | 603 | |
|
603 | 604 | if timeOfData < self.timeOut: |
|
604 | 605 | if self.buffer == None: |
|
605 | 606 | self.buffer = data |
|
606 | 607 | else: |
|
607 | 608 | self.buffer = self.buffer + data |
|
608 | 609 | self.integ_counter += 1 |
|
609 | 610 | else: |
|
610 | 611 | self.exitCondition = True |
|
611 | 612 | |
|
612 | 613 | else: |
|
613 | 614 | if self.integ_counter < self.nIncohInt: |
|
614 | 615 | if self.buffer == None: |
|
615 | 616 | self.buffer = data |
|
616 | 617 | else: |
|
617 | 618 | self.buffer = self.buffer + data |
|
618 | 619 | |
|
619 | 620 | self.integ_counter += 1 |
|
620 | 621 | |
|
621 | 622 | if self.integ_counter == self.nIncohInt: |
|
622 | 623 | self.exitCondition = True |
|
623 | 624 | |
|
624 | 625 | if self.exitCondition: |
|
625 | 626 | self.data = self.buffer |
|
626 | 627 | self.navg = self.integ_counter |
|
627 | 628 | self.isReady = True |
|
628 | 629 | self.buffer = None |
|
629 | 630 | self.timeOut = None |
|
630 | 631 | self.integ_counter = 0 |
|
631 | 632 | self.exitCondition = False |
|
632 | 633 | |
|
633 | 634 | if self.timeFlag: |
|
634 | 635 | self.buffer = data |
|
635 | 636 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
636 | 637 | else: |
|
637 | 638 | self.isReady = False |
|
638 | 639 | No newline at end of file |
@@ -1,416 +1,419 | |||
|
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 | 57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
58 | 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 |
gpath=None |
|
|
75 | gpath=None, | |
|
76 | ratio=1, | |
|
77 | channelList=None): | |
|
76 | 78 | |
|
77 | 79 | if self.dataOutObj.flagNoData: |
|
78 | 80 | return 0 |
|
79 | 81 | |
|
80 | nframes = len(self.dataOutObj.channelList) | |
|
82 | if channelList == None: | |
|
83 | channelList = self.dataOutObj.channelList | |
|
84 | ||
|
85 | nframes = len(channelList) | |
|
81 | 86 | |
|
82 | 87 | if len(self.plotObjList) <= self.plotObjIndex: |
|
83 | 88 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
84 | 89 | |
|
85 | data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) | |
|
90 | data = self.dataOutObj.data[channelList,:] * numpy.conjugate(self.dataOutObj.data[channelList,:]) | |
|
86 | 91 | data = 10*numpy.log10(data.real) |
|
87 | 92 | |
|
88 | # currenttime = self.dataOutObj.utctime | |
|
89 | # if timezone == "lt": | |
|
90 | 93 | currenttime = self.dataOutObj.utctime - time.timezone |
|
91 | 94 | |
|
92 | 95 | range = self.dataOutObj.heightList |
|
93 | 96 | |
|
94 | channelList = self.dataOutObj.channelList | |
|
95 | ||
|
96 | 97 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
97 | 98 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
98 | 99 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) |
|
99 | 100 | print thisdatetime |
|
100 | 101 | figuretitle = "RTI Plot Radar Data" #+ date |
|
101 | 102 | |
|
102 | 103 | plotObj = self.plotObjList[self.plotObjIndex] |
|
103 | 104 | |
|
104 | 105 | cleardata = False |
|
105 | 106 | |
|
106 | 107 | deltax = self.dataOutObj.timeInterval |
|
107 | 108 | |
|
108 | 109 | plotObj.plotPcolor(data=data, |
|
109 | 110 | x=currenttime, |
|
110 | 111 | y=range, |
|
111 | 112 | channelList=channelList, |
|
112 | 113 | xmin=starttime, |
|
113 | 114 | xmax=endtime, |
|
114 | 115 | ymin=rangemin, |
|
115 | 116 | ymax=rangemax, |
|
116 | 117 | minvalue=minvalue, |
|
117 | 118 | maxvalue=maxvalue, |
|
118 | 119 | figuretitle=figuretitle, |
|
119 | 120 | xrangestep=xrangestep, |
|
120 | 121 | deltax=deltax, |
|
121 | 122 | save=save, |
|
122 | 123 | gpath=gpath, |
|
123 |
|
|
|
124 | ratio=ratio, | |
|
125 | cleardata=cleardata | |
|
126 | ) | |
|
124 | 127 | |
|
125 | 128 | |
|
126 | 129 | self.plotObjIndex += 1 |
|
127 | 130 | |
|
128 | 131 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
129 | 132 | if idfigure==None: |
|
130 | 133 | idfigure = self.plotObjIndex |
|
131 | 134 | |
|
132 | 135 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
133 | 136 | self.plotObjList.append(scopeObj) |
|
134 | 137 | |
|
135 | 138 | def plotScope(self, |
|
136 | 139 | idfigure=None, |
|
137 | 140 | minvalue=None, |
|
138 | 141 | maxvalue=None, |
|
139 | 142 | xmin=None, |
|
140 | 143 | xmax=None, |
|
141 | 144 | wintitle='', |
|
142 | 145 | driver='plplot', |
|
143 | 146 | save=False, |
|
144 | 147 | gpath=None, |
|
145 |
|
|
|
146 | xlabelList=None, | |
|
147 | ylabelList=None, | |
|
148 | ratio=1, | |
|
148 | 149 | type="power"): |
|
149 | 150 | |
|
150 | 151 | if self.dataOutObj.flagNoData: |
|
151 | 152 | return 0 |
|
152 | 153 | |
|
153 | 154 | nframes = len(self.dataOutObj.channelList) |
|
154 | 155 | |
|
155 | 156 | if len(self.plotObjList) <= self.plotObjIndex: |
|
156 | 157 | self.addScope(idfigure, nframes, wintitle, driver) |
|
157 | 158 | |
|
158 | 159 | |
|
159 | 160 | if type=="power": |
|
160 | 161 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
161 | 162 | data1D = data1D.real |
|
162 | 163 | |
|
163 | 164 | if type =="iq": |
|
164 | 165 | data1D = self.dataOutObj.data |
|
165 | 166 | |
|
166 | 167 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
167 | 168 | |
|
168 | 169 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
169 | 170 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
170 | 171 | |
|
171 | 172 | figuretitle = "Scope Plot Radar Data: " + date |
|
172 | 173 | |
|
173 | 174 | plotObj = self.plotObjList[self.plotObjIndex] |
|
174 | 175 | |
|
175 | 176 | plotObj.plot1DArray(data1D=data1D, |
|
176 | 177 | x=self.dataOutObj.heightList, |
|
177 | 178 | channelList=self.dataOutObj.channelList, |
|
178 | 179 | xmin=xmin, |
|
179 | 180 | xmax=xmax, |
|
180 | 181 | minvalue=minvalue, |
|
181 | 182 | maxvalue=maxvalue, |
|
182 | 183 | figuretitle=figuretitle, |
|
183 | 184 | save=save, |
|
184 |
gpath=gpath |
|
|
185 | gpath=gpath, | |
|
186 | ratio=ratio) | |
|
185 | 187 | |
|
186 | 188 | |
|
187 | 189 | self.plotObjIndex += 1 |
|
188 | 190 | |
|
189 | 191 | |
|
190 | 192 | def addIntegrator(self, *args): |
|
191 | 193 | objCohInt = CoherentIntegrator(*args) |
|
192 | 194 | self.integratorObjList.append(objCohInt) |
|
193 | 195 | |
|
194 | 196 | def addWriter(self, *args): |
|
195 | 197 | writerObj = VoltageWriter(self.dataOutObj) |
|
196 | 198 | writerObj.setup(*args) |
|
197 | 199 | self.writerObjList.append(writerObj) |
|
198 | 200 | |
|
199 | 201 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): |
|
200 | 202 | |
|
201 | 203 | if self.dataOutObj.flagNoData: |
|
202 | 204 | return 0 |
|
203 | 205 | |
|
204 | 206 | if len(self.writerObjList) <= self.writerObjIndex: |
|
205 | 207 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) |
|
206 | 208 | |
|
207 | 209 | self.writerObjList[self.writerObjIndex].putData() |
|
208 | 210 | |
|
209 | 211 | self.writerObjIndex += 1 |
|
210 | 212 | |
|
211 | 213 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
212 | 214 | |
|
213 | 215 | if self.dataOutObj.flagNoData: |
|
214 | 216 | return 0 |
|
215 | 217 | |
|
216 | 218 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
217 | 219 | self.addIntegrator(nCohInt, timeInterval, overlapping) |
|
218 | 220 | |
|
219 | 221 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
220 | 222 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) |
|
221 | 223 | |
|
222 | 224 | self.dataOutObj.timeInterval *= nCohInt |
|
223 | 225 | self.dataOutObj.flagNoData = True |
|
224 | 226 | |
|
225 | 227 | if myCohIntObj.isReady: |
|
228 | self.dataOutObj.timeInterval = myCohIntObj.nCohInt * self.dataOutObj.timeInterval | |
|
226 | 229 | self.dataOutObj.flagNoData = False |
|
227 | 230 | |
|
228 | 231 | def selectChannels(self, channelList): |
|
229 | 232 | |
|
230 | 233 | self.selectChannelsByIndex(channelList) |
|
231 | 234 | |
|
232 | 235 | def selectChannelsByIndex(self, channelIndexList): |
|
233 | 236 | """ |
|
234 | 237 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
235 | 238 | |
|
236 | 239 | Input: |
|
237 | 240 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
238 | 241 | |
|
239 | 242 | Affected: |
|
240 | 243 | self.dataOutObj.data |
|
241 | 244 | self.dataOutObj.channelIndexList |
|
242 | 245 | self.dataOutObj.nChannels |
|
243 | 246 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
244 | 247 | self.dataOutObj.systemHeaderObj.numChannels |
|
245 | 248 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
246 | 249 | |
|
247 | 250 | Return: |
|
248 | 251 | None |
|
249 | 252 | """ |
|
250 | 253 | if self.dataOutObj.flagNoData: |
|
251 | 254 | return 0 |
|
252 | 255 | |
|
253 | 256 | for channel in channelIndexList: |
|
254 | 257 | if channel not in self.dataOutObj.channelIndexList: |
|
255 | 258 | raise ValueError, "The value %d in channelIndexList is not valid" %channel |
|
256 | 259 | |
|
257 | 260 | nChannels = len(channelIndexList) |
|
258 | 261 | |
|
259 | 262 | data = self.dataOutObj.data[channelIndexList,:] |
|
260 | 263 | |
|
261 | 264 | self.dataOutObj.data = data |
|
262 | 265 | self.dataOutObj.channelIndexList = channelIndexList |
|
263 | 266 | self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList] |
|
264 | 267 | self.dataOutObj.nChannels = nChannels |
|
265 | 268 | |
|
266 | 269 | return 1 |
|
267 | 270 | |
|
268 | 271 | class CoherentIntegrator: |
|
269 | 272 | |
|
270 | 273 | |
|
271 | 274 | __profIndex = 0 |
|
272 | 275 | __withOverapping = False |
|
273 | 276 | |
|
274 | 277 | __isByTime = False |
|
275 | 278 | __initime = None |
|
276 | 279 | __integrationtime = None |
|
277 | 280 | |
|
278 | 281 | __buffer = None |
|
279 | 282 | |
|
280 | 283 | isReady = False |
|
281 | 284 | nCohInt = None |
|
282 | 285 | |
|
283 | 286 | |
|
284 | 287 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
285 | 288 | |
|
286 | 289 | """ |
|
287 | 290 | Set the parameters of the integration class. |
|
288 | 291 | |
|
289 | 292 | Inputs: |
|
290 | 293 | |
|
291 | 294 | nCohInt : Number of coherent integrations |
|
292 | 295 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work |
|
293 | 296 | overlapping : |
|
294 | 297 | |
|
295 | 298 | """ |
|
296 | 299 | |
|
297 | 300 | self.__buffer = None |
|
298 | 301 | self.isReady = False |
|
299 | 302 | |
|
300 | 303 | if nCohInt == None and timeInterval == None: |
|
301 | 304 | raise ValueError, "nCohInt or timeInterval should be specified ..." |
|
302 | 305 | |
|
303 | 306 | if nCohInt != None: |
|
304 | 307 | self.nCohInt = nCohInt |
|
305 | 308 | self.__isByTime = False |
|
306 | 309 | else: |
|
307 | 310 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
308 | 311 | self.__isByTime = True |
|
309 | 312 | |
|
310 | 313 | if overlapping: |
|
311 | 314 | self.__withOverapping = True |
|
312 | 315 | self.__buffer = None |
|
313 | 316 | else: |
|
314 | 317 | self.__withOverapping = False |
|
315 | 318 | self.__buffer = 0 |
|
316 | 319 | |
|
317 | 320 | self.__profIndex = 0 |
|
318 | 321 | |
|
319 | 322 | def putData(self, data): |
|
320 | 323 | |
|
321 | 324 | """ |
|
322 | 325 | Add a profile to the __buffer and increase in one the __profileIndex |
|
323 | 326 | |
|
324 | 327 | """ |
|
325 | 328 | if not self.__withOverapping: |
|
326 | 329 | self.__buffer += data |
|
327 | 330 | self.__profIndex += 1 |
|
328 | 331 | return |
|
329 | 332 | |
|
330 | 333 | #Overlapping data |
|
331 | 334 | nChannels, nHeis = data.shape |
|
332 | 335 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
333 | 336 | |
|
334 | 337 | if self.__buffer == None: |
|
335 | 338 | self.__buffer = data |
|
336 | 339 | self.__profIndex += 1 |
|
337 | 340 | return |
|
338 | 341 | |
|
339 | 342 | if self.__profIndex < self.nCohInt: |
|
340 | 343 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
341 | 344 | self.__profIndex += 1 |
|
342 | 345 | return |
|
343 | 346 | |
|
344 | 347 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
345 | 348 | self.__buffer[self.nCohInt-1] = data |
|
346 | 349 | #self.__profIndex = self.nCohInt |
|
347 | 350 | return |
|
348 | 351 | |
|
349 | 352 | |
|
350 | 353 | def pushData(self): |
|
351 | 354 | """ |
|
352 | 355 | Return the sum of the last profiles and the profiles used in the sum. |
|
353 | 356 | |
|
354 | 357 | Affected: |
|
355 | 358 | |
|
356 | 359 | self.__profileIndex |
|
357 | 360 | |
|
358 | 361 | """ |
|
359 | 362 | |
|
360 | 363 | if not self.__withOverapping: |
|
361 | 364 | data = self.__buffer |
|
362 | 365 | nCohInt = self.__profIndex |
|
363 | 366 | |
|
364 | 367 | self.__buffer = 0 |
|
365 | 368 | self.__profIndex = 0 |
|
366 | 369 | |
|
367 | 370 | return data, nCohInt |
|
368 | 371 | |
|
369 | 372 | #Overlapping data |
|
370 | 373 | data = numpy.sum(self.__buffer, axis=0) |
|
371 | 374 | nCohInt = self.__profIndex |
|
372 | 375 | |
|
373 | 376 | return data, nCohInt |
|
374 | 377 | |
|
375 | 378 | def byProfiles(self, data): |
|
376 | 379 | |
|
377 | 380 | self.isReady = False |
|
378 | 381 | avg_data = None |
|
379 | 382 | |
|
380 | 383 | self.putData(data) |
|
381 | 384 | |
|
382 | 385 | if self.__profIndex == self.nCohInt: |
|
383 | 386 | avg_data, nCohInt = self.pushData() |
|
384 | 387 | self.isReady = True |
|
385 | 388 | |
|
386 | 389 | return avg_data |
|
387 | 390 | |
|
388 | 391 | def byTime(self, data, datatime): |
|
389 | 392 | |
|
390 | 393 | self.isReady = False |
|
391 | 394 | avg_data = None |
|
392 | 395 | |
|
393 | 396 | if self.__initime == None: |
|
394 | 397 | self.__initime = datatime |
|
395 | 398 | |
|
396 | 399 | self.putData(data) |
|
397 | 400 | |
|
398 | 401 | if (datatime - self.__initime) >= self.__integrationtime: |
|
399 | 402 | avg_data, nCohInt = self.pushData() |
|
400 | 403 | self.nCohInt = nCohInt |
|
401 | 404 | self.isReady = True |
|
402 | 405 | |
|
403 | 406 | return avg_data |
|
404 | 407 | |
|
405 | 408 | def exe(self, data, datatime=None): |
|
406 | 409 | |
|
407 | 410 | if not self.__isByTime: |
|
408 | 411 | avg_data = self.byProfiles(data) |
|
409 | 412 | else: |
|
410 | 413 | avg_data = self.byTime(data, datatime) |
|
411 | 414 | |
|
412 | 415 | self.data = avg_data |
|
413 | 416 | |
|
414 | 417 | return avg_data |
|
415 | 418 | |
|
416 | 419 |
General Comments 0
You need to be logged in to leave comments.
Login now