##// END OF EJS Templates
Adicion del factor de normalizacion en la clase Spectra....
Daniel Valdez -
r245:0a5b40329524
parent child
Show More
@@ -1,396 +1,401
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6
6
7 class Figure:
7 class Figure:
8
8
9 __driver = mpldriver
9 __driver = mpldriver
10 fig = None
10 fig = None
11
11
12 idfigure = None
12 idfigure = None
13 wintitle = None
13 wintitle = None
14 width = None
14 width = None
15 height = None
15 height = None
16 nplots = None
16 nplots = None
17 timerange = None
17 timerange = None
18
18
19 axesObjList = []
19 axesObjList = []
20
20
21 WIDTH = None
21 WIDTH = None
22 HEIGHT = None
22 HEIGHT = None
23 PREFIX = 'fig'
23 PREFIX = 'fig'
24
24
25 def __init__(self):
25 def __init__(self):
26
26
27 raise ValueError, "This method is not implemented"
27 raise ValueError, "This method is not implemented"
28
28
29 def __del__(self):
29 def __del__(self):
30
30
31 self.__driver.closeFigure()
31 self.__driver.closeFigure()
32
32
33 def getFilename(self, name, ext='.png'):
33 def getFilename(self, name, ext='.png'):
34
34
35 filename = '%s-%s_%s%s' %(self.wintitle[0:10], self.PREFIX, name, ext)
35 filename = '%s-%s_%s%s' %(self.wintitle[0:10], self.PREFIX, name, ext)
36
36
37 return filename
37 return filename
38
38
39 def getAxesObjList(self):
39 def getAxesObjList(self):
40
40
41 return self.axesObjList
41 return self.axesObjList
42
42
43 def getSubplots(self):
43 def getSubplots(self):
44
44
45 raise ValueError, "Abstract method: This method should be defined"
45 raise ValueError, "Abstract method: This method should be defined"
46
46
47 def getScreenDim(self, widthplot, heightplot):
47 def getScreenDim(self, widthplot, heightplot):
48
48
49 nrow, ncol = self.getSubplots()
49 nrow, ncol = self.getSubplots()
50
50
51 widthscreen = widthplot*ncol
51 widthscreen = widthplot*ncol
52 heightscreen = heightplot*nrow
52 heightscreen = heightplot*nrow
53
53
54 return widthscreen, heightscreen
54 return widthscreen, heightscreen
55
55
56 def getTimeLim(self, x, xmin, xmax):
56 def getTimeLim(self, x, xmin, xmax):
57
57
58 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
58 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
59 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
59 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
60
60
61 ####################################################
61 ####################################################
62 #If the x is out of xrange
62 #If the x is out of xrange
63 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
63 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
64 xmin = None
64 xmin = None
65 xmax = None
65 xmax = None
66
66
67 if xmin == None:
67 if xmin == None:
68 td = thisdatetime - thisdate
68 td = thisdatetime - thisdate
69 xmin = td.seconds/(60*60.)
69 xmin = td.seconds/(60*60.)
70
70
71 if xmax == None:
71 if xmax == None:
72 xmax = xmin + self.timerange/(60*60.)
72 xmax = xmin + self.timerange/(60*60.)
73
73
74 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
74 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
75 tmin = time.mktime(mindt.timetuple())
75 tmin = time.mktime(mindt.timetuple())
76
76
77 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
77 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
78 tmax = time.mktime(maxdt.timetuple())
78 tmax = time.mktime(maxdt.timetuple())
79
79
80 self.timerange = tmax - tmin
80 self.timerange = tmax - tmin
81
81
82 return tmin, tmax
82 return tmin, tmax
83
83
84 def init(self, idfigure, nplots, wintitle):
84 def init(self, idfigure, nplots, wintitle):
85
85
86 raise ValueError, "This method has been replaced with createFigure"
86 raise ValueError, "This method has been replaced with createFigure"
87
87
88 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
88 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
89
89
90 """
90 """
91 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
91 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
92 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
92 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
93 y self.HEIGHT y el numero de subplots (nrow, ncol)
93 y self.HEIGHT y el numero de subplots (nrow, ncol)
94
94
95 Input:
95 Input:
96 idfigure : Los parametros necesarios son
96 idfigure : Los parametros necesarios son
97 wintitle :
97 wintitle :
98
98
99 """
99 """
100
100
101 if widthplot == None:
101 if widthplot == None:
102 widthplot = self.WIDTH
102 widthplot = self.WIDTH
103
103
104 if heightplot == None:
104 if heightplot == None:
105 heightplot = self.HEIGHT
105 heightplot = self.HEIGHT
106
106
107 self.idfigure = idfigure
107 self.idfigure = idfigure
108
108
109 self.wintitle = wintitle
109 self.wintitle = wintitle
110
110
111 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
111 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
112
112
113 self.fig = self.__driver.createFigure(self.idfigure,
113 self.fig = self.__driver.createFigure(self.idfigure,
114 self.wintitle,
114 self.wintitle,
115 self.widthscreen,
115 self.widthscreen,
116 self.heightscreen)
116 self.heightscreen)
117
117
118 self.axesObjList = []
118 self.axesObjList = []
119
119
120 def setDriver(self, driver=mpldriver):
120 def setDriver(self, driver=mpldriver):
121
121
122 self.__driver = driver
122 self.__driver = driver
123
123
124 def setTitle(self, title):
124 def setTitle(self, title):
125
125
126 self.__driver.setTitle(self.fig, title)
126 self.__driver.setTitle(self.fig, title)
127
127
128 def setWinTitle(self, title):
128 def setWinTitle(self, title):
129
129
130 self.__driver.setWinTitle(self.fig, title=title)
130 self.__driver.setWinTitle(self.fig, title=title)
131
131
132 def setTextFromAxes(self, text):
132 def setTextFromAxes(self, text):
133
133
134 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
134 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
135
135
136 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
136 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
137
137
138 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
138 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
139
139
140 def addAxes(self, *args):
140 def addAxes(self, *args):
141 """
141 """
142
142
143 Input:
143 Input:
144 *args : Los parametros necesarios son
144 *args : Los parametros necesarios son
145 nrow, ncol, xpos, ypos, colspan, rowspan
145 nrow, ncol, xpos, ypos, colspan, rowspan
146 """
146 """
147
147
148 axesObj = Axes(self.fig, *args)
148 axesObj = Axes(self.fig, *args)
149 self.axesObjList.append(axesObj)
149 self.axesObjList.append(axesObj)
150
150
151 def saveFigure(self, figpath, figfile, *args):
151 def saveFigure(self, figpath, figfile, *args):
152
152
153 filename = os.path.join(figpath, figfile)
153 filename = os.path.join(figpath, figfile)
154 self.__driver.saveFigure(self.fig, filename, *args)
154 self.__driver.saveFigure(self.fig, filename, *args)
155
155
156 def draw(self):
156 def draw(self):
157
157
158 self.__driver.draw(self.fig)
158 self.__driver.draw(self.fig)
159
159
160 def run(self):
160 def run(self):
161
161
162 raise ValueError, "This method is not implemented"
162 raise ValueError, "This method is not implemented"
163
163
164 axesList = property(getAxesObjList)
164 axesList = property(getAxesObjList)
165
165
166
166
167 class Axes:
167 class Axes:
168
168
169 __driver = mpldriver
169 __driver = mpldriver
170 fig = None
170 fig = None
171 ax = None
171 ax = None
172 plot = None
172 plot = None
173
173
174 __firsttime = None
174 __firsttime = None
175
175
176 __showprofile = False
176 __showprofile = False
177
177
178 xmin = None
178 xmin = None
179 xmax = None
179 xmax = None
180 ymin = None
180 ymin = None
181 ymax = None
181 ymax = None
182 zmin = None
182 zmin = None
183 zmax = None
183 zmax = None
184
184
185 def __init__(self, *args):
185 def __init__(self, *args):
186
186
187 """
187 """
188
188
189 Input:
189 Input:
190 *args : Los parametros necesarios son
190 *args : Los parametros necesarios son
191 fig, nrow, ncol, xpos, ypos, colspan, rowspan
191 fig, nrow, ncol, xpos, ypos, colspan, rowspan
192 """
192 """
193
193
194 ax = self.__driver.createAxes(*args)
194 ax = self.__driver.createAxes(*args)
195 self.fig = args[0]
195 self.fig = args[0]
196 self.ax = ax
196 self.ax = ax
197 self.plot = None
197 self.plot = None
198
198
199 self.__firsttime = True
199 self.__firsttime = True
200 self.idlineList = []
200 self.idlineList = []
201
201
202 def setText(self, text):
202 def setText(self, text):
203
203
204 self.__driver.setAxesText(self.ax, text)
204 self.__driver.setAxesText(self.ax, text)
205
205
206 def setXAxisAsTime(self):
206 def setXAxisAsTime(self):
207 pass
207 pass
208
208
209 def pline(self, x, y,
209 def pline(self, x, y,
210 xmin=None, xmax=None,
210 xmin=None, xmax=None,
211 ymin=None, ymax=None,
211 ymin=None, ymax=None,
212 xlabel='', ylabel='',
212 xlabel='', ylabel='',
213 title='',
213 title='',
214 **kwargs):
214 **kwargs):
215
215
216 """
216 """
217
217
218 Input:
218 Input:
219 x :
219 x :
220 y :
220 y :
221 xmin :
221 xmin :
222 xmax :
222 xmax :
223 ymin :
223 ymin :
224 ymax :
224 ymax :
225 xlabel :
225 xlabel :
226 ylabel :
226 ylabel :
227 title :
227 title :
228 **kwargs : Los parametros aceptados son
228 **kwargs : Los parametros aceptados son
229
229
230 ticksize
230 ticksize
231 ytick_visible
231 ytick_visible
232 """
232 """
233
233
234 if self.__firsttime:
234 if self.__firsttime:
235
235
236 if xmin == None: xmin = numpy.nanmin(x)
236 if xmin == None: xmin = numpy.nanmin(x)
237 if xmax == None: xmax = numpy.nanmax(x)
237 if xmax == None: xmax = numpy.nanmax(x)
238 if ymin == None: ymin = numpy.nanmin(y)
238 if ymin == None: ymin = numpy.nanmin(y)
239 if ymax == None: ymax = numpy.nanmax(y)
239 if ymax == None: ymax = numpy.nanmax(y)
240
240
241 self.plot = self.__driver.createPline(self.ax, x, y,
241 self.plot = self.__driver.createPline(self.ax, x, y,
242 xmin, xmax,
242 xmin, xmax,
243 ymin, ymax,
243 ymin, ymax,
244 xlabel=xlabel,
244 xlabel=xlabel,
245 ylabel=ylabel,
245 ylabel=ylabel,
246 title=title,
246 title=title,
247 **kwargs)
247 **kwargs)
248
248
249 self.idlineList.append(0)
249 self.idlineList.append(0)
250 self.__firsttime = False
250 self.__firsttime = False
251 return
251 return
252
252
253 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
253 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
254 ylabel=ylabel,
254 ylabel=ylabel,
255 title=title)
255 title=title)
256
256
257 def addpline(self, x, y, idline, **kwargs):
257 def addpline(self, x, y, idline, **kwargs):
258 lines = self.ax.lines
258 lines = self.ax.lines
259
259
260 if idline in self.idlineList:
260 if idline in self.idlineList:
261 self.__driver.set_linedata(self.ax, x, y, idline)
261 self.__driver.set_linedata(self.ax, x, y, idline)
262
262
263 if idline not in(self.idlineList):
263 if idline not in(self.idlineList):
264 self.__driver.addpline(self.ax, x, y, **kwargs)
264 self.__driver.addpline(self.ax, x, y, **kwargs)
265 self.idlineList.append(idline)
265 self.idlineList.append(idline)
266
266
267 return
267 return
268
268
269 def pmultiline(self, x, y,
269 def pmultiline(self, x, y,
270 xmin=None, xmax=None,
270 xmin=None, xmax=None,
271 ymin=None, ymax=None,
271 ymin=None, ymax=None,
272 xlabel='', ylabel='',
272 xlabel='', ylabel='',
273 title='',
273 title='',
274 **kwargs):
274 **kwargs):
275
275
276 if self.__firsttime:
276 if self.__firsttime:
277
277
278 if xmin == None: xmin = numpy.nanmin(x)
278 if xmin == None: xmin = numpy.nanmin(x)
279 if xmax == None: xmax = numpy.nanmax(x)
279 if xmax == None: xmax = numpy.nanmax(x)
280 if ymin == None: ymin = numpy.nanmin(y)
280 if ymin == None: ymin = numpy.nanmin(y)
281 if ymax == None: ymax = numpy.nanmax(y)
281 if ymax == None: ymax = numpy.nanmax(y)
282
282
283 self.plot = self.__driver.createPmultiline(self.ax, x, y,
283 self.plot = self.__driver.createPmultiline(self.ax, x, y,
284 xmin, xmax,
284 xmin, xmax,
285 ymin, ymax,
285 ymin, ymax,
286 xlabel=xlabel,
286 xlabel=xlabel,
287 ylabel=ylabel,
287 ylabel=ylabel,
288 title=title,
288 title=title,
289 **kwargs)
289 **kwargs)
290 self.__firsttime = False
290 self.__firsttime = False
291 return
291 return
292
292
293 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
293 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
294 ylabel=ylabel,
294 ylabel=ylabel,
295 title=title)
295 title=title)
296
296
297 def pmultilineyaxis(self, x, y,
297 def pmultilineyaxis(self, x, y,
298 xmin=None, xmax=None,
298 xmin=None, xmax=None,
299 ymin=None, ymax=None,
299 ymin=None, ymax=None,
300 xlabel='', ylabel='',
300 xlabel='', ylabel='',
301 title='',
301 title='',
302 **kwargs):
302 **kwargs):
303
303
304 if self.__firsttime:
304 if self.__firsttime:
305
305
306 if xmin == None: xmin = numpy.nanmin(x)
306 if xmin == None: xmin = numpy.nanmin(x)
307 if xmax == None: xmax = numpy.nanmax(x)
307 if xmax == None: xmax = numpy.nanmax(x)
308 if ymin == None: ymin = numpy.nanmin(y)
308 if ymin == None: ymin = numpy.nanmin(y)
309 if ymax == None: ymax = numpy.nanmax(y)
309 if ymax == None: ymax = numpy.nanmax(y)
310
310
311 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
311 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
312 xmin, xmax,
312 xmin, xmax,
313 ymin, ymax,
313 ymin, ymax,
314 xlabel=xlabel,
314 xlabel=xlabel,
315 ylabel=ylabel,
315 ylabel=ylabel,
316 title=title,
316 title=title,
317 **kwargs)
317 **kwargs)
318 if self.xmin == None: self.xmin = xmin
319 if self.xmax == None: self.xmax = xmax
320 if self.ymin == None: self.ymin = ymin
321 if self.ymax == None: self.ymax = ymax
322
318 self.__firsttime = False
323 self.__firsttime = False
319 return
324 return
320
325
321 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
326 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
322 ylabel=ylabel,
327 ylabel=ylabel,
323 title=title)
328 title=title)
324
329
325 def pcolor(self, x, y, z,
330 def pcolor(self, x, y, z,
326 xmin=None, xmax=None,
331 xmin=None, xmax=None,
327 ymin=None, ymax=None,
332 ymin=None, ymax=None,
328 zmin=None, zmax=None,
333 zmin=None, zmax=None,
329 xlabel='', ylabel='',
334 xlabel='', ylabel='',
330 title='', rti = False, colormap='jet',
335 title='', rti = False, colormap='jet',
331 **kwargs):
336 **kwargs):
332
337
333 """
338 """
334 Input:
339 Input:
335 x :
340 x :
336 y :
341 y :
337 x :
342 x :
338 xmin :
343 xmin :
339 xmax :
344 xmax :
340 ymin :
345 ymin :
341 ymax :
346 ymax :
342 zmin :
347 zmin :
343 zmax :
348 zmax :
344 xlabel :
349 xlabel :
345 ylabel :
350 ylabel :
346 title :
351 title :
347 **kwargs : Los parametros aceptados son
352 **kwargs : Los parametros aceptados son
348 ticksize=9,
353 ticksize=9,
349 cblabel=''
354 cblabel=''
350 rti = True or False
355 rti = True or False
351 """
356 """
352
357
353 if self.__firsttime:
358 if self.__firsttime:
354
359
355 if xmin == None: xmin = numpy.nanmin(x)
360 if xmin == None: xmin = numpy.nanmin(x)
356 if xmax == None: xmax = numpy.nanmax(x)
361 if xmax == None: xmax = numpy.nanmax(x)
357 if ymin == None: ymin = numpy.nanmin(y)
362 if ymin == None: ymin = numpy.nanmin(y)
358 if ymax == None: ymax = numpy.nanmax(y)
363 if ymax == None: ymax = numpy.nanmax(y)
359 if zmin == None: zmin = numpy.nanmin(z)
364 if zmin == None: zmin = numpy.nanmin(z)
360 if zmax == None: zmax = numpy.nanmax(z)
365 if zmax == None: zmax = numpy.nanmax(z)
361
366
362
367
363 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
368 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
364 xmin, xmax,
369 xmin, xmax,
365 ymin, ymax,
370 ymin, ymax,
366 zmin, zmax,
371 zmin, zmax,
367 xlabel=xlabel,
372 xlabel=xlabel,
368 ylabel=ylabel,
373 ylabel=ylabel,
369 title=title,
374 title=title,
370 colormap=colormap,
375 colormap=colormap,
371 **kwargs)
376 **kwargs)
372
377
373 if self.xmin == None: self.xmin = xmin
378 if self.xmin == None: self.xmin = xmin
374 if self.xmax == None: self.xmax = xmax
379 if self.xmax == None: self.xmax = xmax
375 if self.ymin == None: self.ymin = ymin
380 if self.ymin == None: self.ymin = ymin
376 if self.ymax == None: self.ymax = ymax
381 if self.ymax == None: self.ymax = ymax
377 if self.zmin == None: self.zmin = zmin
382 if self.zmin == None: self.zmin = zmin
378 if self.zmax == None: self.zmax = zmax
383 if self.zmax == None: self.zmax = zmax
379
384
380 self.__firsttime = False
385 self.__firsttime = False
381 return
386 return
382
387
383 if rti:
388 if rti:
384 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
389 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
385 xlabel=xlabel,
390 xlabel=xlabel,
386 ylabel=ylabel,
391 ylabel=ylabel,
387 title=title,
392 title=title,
388 colormap=colormap)
393 colormap=colormap)
389 return
394 return
390
395
391 self.__driver.pcolor(self.plot, z,
396 self.__driver.pcolor(self.plot, z,
392 xlabel=xlabel,
397 xlabel=xlabel,
393 ylabel=ylabel,
398 ylabel=ylabel,
394 title=title)
399 title=title)
395
400
396 No newline at end of file
401
@@ -1,366 +1,370
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import sys
3 import matplotlib
4 import matplotlib
5 if sys.platform == 'linux':
4 matplotlib.use("GTKAgg")
6 matplotlib.use("GTKAgg")
7 if sys.platform == 'darwin':
8 matplotlib.use("TKAgg")
5 import matplotlib.pyplot
9 import matplotlib.pyplot
6 import matplotlib.dates
10 import matplotlib.dates
7 #import scitools.numpyutils
11 #import scitools.numpyutils
8 from mpl_toolkits.axes_grid1 import make_axes_locatable
12 from mpl_toolkits.axes_grid1 import make_axes_locatable
9
13
10 from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter
14 from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter
11 from matplotlib.ticker import FuncFormatter
15 from matplotlib.ticker import FuncFormatter
12 from matplotlib.ticker import *
16 from matplotlib.ticker import *
13
17
14 ###########################################
18 ###########################################
15 #Actualizacion de las funciones del driver
19 #Actualizacion de las funciones del driver
16 ###########################################
20 ###########################################
17
21
18 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
22 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
19
23
20 matplotlib.pyplot.ioff()
24 matplotlib.pyplot.ioff()
21 fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
25 fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
22 fig.canvas.manager.set_window_title(wintitle)
26 fig.canvas.manager.set_window_title(wintitle)
23 fig.canvas.manager.resize(width, height)
27 fig.canvas.manager.resize(width, height)
24 matplotlib.pyplot.ion()
28 matplotlib.pyplot.ion()
25 matplotlib.pyplot.show()
29 matplotlib.pyplot.show()
26
30
27 return fig
31 return fig
28
32
29 def closeFigure():
33 def closeFigure():
30
34
31 matplotlib.pyplot.ioff()
35 matplotlib.pyplot.ioff()
32 matplotlib.pyplot.show()
36 matplotlib.pyplot.show()
33
37
34 return
38 return
35
39
36 def saveFigure(fig, filename):
40 def saveFigure(fig, filename):
37
41
38 matplotlib.pyplot.ioff()
42 matplotlib.pyplot.ioff()
39 fig.savefig(filename)
43 fig.savefig(filename)
40 matplotlib.pyplot.ion()
44 matplotlib.pyplot.ion()
41
45
42 def setWinTitle(fig, title):
46 def setWinTitle(fig, title):
43
47
44 fig.canvas.manager.set_window_title(title)
48 fig.canvas.manager.set_window_title(title)
45
49
46 def setTitle(fig, title):
50 def setTitle(fig, title):
47
51
48 fig.suptitle(title)
52 fig.suptitle(title)
49
53
50 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
54 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
51
55
52 matplotlib.pyplot.ioff()
56 matplotlib.pyplot.ioff()
53 matplotlib.pyplot.figure(fig.number)
57 matplotlib.pyplot.figure(fig.number)
54 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
58 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
55 (xpos, ypos),
59 (xpos, ypos),
56 colspan=colspan,
60 colspan=colspan,
57 rowspan=rowspan)
61 rowspan=rowspan)
58
62
59 matplotlib.pyplot.ion()
63 matplotlib.pyplot.ion()
60 return axes
64 return axes
61
65
62 def setAxesText(ax, text):
66 def setAxesText(ax, text):
63
67
64 ax.annotate(text,
68 ax.annotate(text,
65 xy = (.1, .99),
69 xy = (.1, .99),
66 xycoords = 'figure fraction',
70 xycoords = 'figure fraction',
67 horizontalalignment = 'left',
71 horizontalalignment = 'left',
68 verticalalignment = 'top',
72 verticalalignment = 'top',
69 fontsize = 10)
73 fontsize = 10)
70
74
71 def printLabels(ax, xlabel, ylabel, title):
75 def printLabels(ax, xlabel, ylabel, title):
72
76
73 ax.set_xlabel(xlabel, size=11)
77 ax.set_xlabel(xlabel, size=11)
74 ax.set_ylabel(ylabel, size=11)
78 ax.set_ylabel(ylabel, size=11)
75 ax.set_title(title, size=12)
79 ax.set_title(title, size=12)
76
80
77 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
81 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
78 ticksize=9, xtick_visible=True, ytick_visible=True,
82 ticksize=9, xtick_visible=True, ytick_visible=True,
79 nxticks=4, nyticks=10,
83 nxticks=4, nyticks=10,
80 grid=None):
84 grid=None):
81
85
82 """
86 """
83
87
84 Input:
88 Input:
85 grid : None, 'both', 'x', 'y'
89 grid : None, 'both', 'x', 'y'
86 """
90 """
87
91
88 matplotlib.pyplot.ioff()
92 matplotlib.pyplot.ioff()
89
93
90 ax.set_xlim([xmin,xmax])
94 ax.set_xlim([xmin,xmax])
91 ax.set_ylim([ymin,ymax])
95 ax.set_ylim([ymin,ymax])
92
96
93 printLabels(ax, xlabel, ylabel, title)
97 printLabels(ax, xlabel, ylabel, title)
94
98
95 ######################################################
99 ######################################################
96 if (xmax-xmin)<=1:
100 if (xmax-xmin)<=1:
97 xtickspos = numpy.linspace(xmin,xmax,nxticks)
101 xtickspos = numpy.linspace(xmin,xmax,nxticks)
98 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
102 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
99 ax.set_xticks(xtickspos)
103 ax.set_xticks(xtickspos)
100 else:
104 else:
101 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
105 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
102 ax.set_xticks(xtickspos)
106 ax.set_xticks(xtickspos)
103
107
104 for tick in ax.get_xticklabels():
108 for tick in ax.get_xticklabels():
105 tick.set_visible(xtick_visible)
109 tick.set_visible(xtick_visible)
106
110
107 for tick in ax.xaxis.get_major_ticks():
111 for tick in ax.xaxis.get_major_ticks():
108 tick.label.set_fontsize(ticksize)
112 tick.label.set_fontsize(ticksize)
109
113
110 ######################################################
114 ######################################################
111 for tick in ax.get_yticklabels():
115 for tick in ax.get_yticklabels():
112 tick.set_visible(ytick_visible)
116 tick.set_visible(ytick_visible)
113
117
114 for tick in ax.yaxis.get_major_ticks():
118 for tick in ax.yaxis.get_major_ticks():
115 tick.label.set_fontsize(ticksize)
119 tick.label.set_fontsize(ticksize)
116
120
117 ax.plot(x, y)
121 ax.plot(x, y)
118 iplot = ax.lines[-1]
122 iplot = ax.lines[-1]
119
123
120 ######################################################
124 ######################################################
121 if '0.' in matplotlib.__version__[0:2]:
125 if '0.' in matplotlib.__version__[0:2]:
122 print "The matplotlib version has to be updated to 1.1 or newer"
126 print "The matplotlib version has to be updated to 1.1 or newer"
123 return iplot
127 return iplot
124
128
125 if '1.0.' in matplotlib.__version__[0:4]:
129 if '1.0.' in matplotlib.__version__[0:4]:
126 print "The matplotlib version has to be updated to 1.1 or newer"
130 print "The matplotlib version has to be updated to 1.1 or newer"
127 return iplot
131 return iplot
128
132
129 if grid != None:
133 if grid != None:
130 ax.grid(b=True, which='major', axis=grid)
134 ax.grid(b=True, which='major', axis=grid)
131
135
132 matplotlib.pyplot.tight_layout()
136 matplotlib.pyplot.tight_layout()
133
137
134 matplotlib.pyplot.ion()
138 matplotlib.pyplot.ion()
135
139
136 return iplot
140 return iplot
137
141
138 def set_linedata(ax, x, y, idline):
142 def set_linedata(ax, x, y, idline):
139
143
140 ax.lines[idline].set_data(x,y)
144 ax.lines[idline].set_data(x,y)
141
145
142 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
146 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
143
147
144 ax = iplot.get_axes()
148 ax = iplot.get_axes()
145
149
146 printLabels(ax, xlabel, ylabel, title)
150 printLabels(ax, xlabel, ylabel, title)
147
151
148 set_linedata(ax, x, y, idline=0)
152 set_linedata(ax, x, y, idline=0)
149
153
150 def addpline(ax, x, y, color, linestyle, lw):
154 def addpline(ax, x, y, color, linestyle, lw):
151
155
152 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
156 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
153
157
154
158
155 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
159 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
156 xlabel='', ylabel='', title='', ticksize = 9,
160 xlabel='', ylabel='', title='', ticksize = 9,
157 colormap='jet',cblabel='', cbsize="5%",
161 colormap='jet',cblabel='', cbsize="5%",
158 XAxisAsTime=False):
162 XAxisAsTime=False):
159
163
160 matplotlib.pyplot.ioff()
164 matplotlib.pyplot.ioff()
161
165
162 divider = make_axes_locatable(ax)
166 divider = make_axes_locatable(ax)
163 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
167 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
164 fig = ax.get_figure()
168 fig = ax.get_figure()
165 fig.add_axes(ax_cb)
169 fig.add_axes(ax_cb)
166
170
167 ax.set_xlim([xmin,xmax])
171 ax.set_xlim([xmin,xmax])
168 ax.set_ylim([ymin,ymax])
172 ax.set_ylim([ymin,ymax])
169
173
170 printLabels(ax, xlabel, ylabel, title)
174 printLabels(ax, xlabel, ylabel, title)
171
175
172 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
176 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
173 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
177 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
174 cb.set_label(cblabel)
178 cb.set_label(cblabel)
175
179
176 # for tl in ax_cb.get_yticklabels():
180 # for tl in ax_cb.get_yticklabels():
177 # tl.set_visible(True)
181 # tl.set_visible(True)
178
182
179 for tick in ax.yaxis.get_major_ticks():
183 for tick in ax.yaxis.get_major_ticks():
180 tick.label.set_fontsize(ticksize)
184 tick.label.set_fontsize(ticksize)
181
185
182 for tick in ax.xaxis.get_major_ticks():
186 for tick in ax.xaxis.get_major_ticks():
183 tick.label.set_fontsize(ticksize)
187 tick.label.set_fontsize(ticksize)
184
188
185 for tick in cb.ax.get_yticklabels():
189 for tick in cb.ax.get_yticklabels():
186 tick.set_fontsize(ticksize)
190 tick.set_fontsize(ticksize)
187
191
188 ax_cb.yaxis.tick_right()
192 ax_cb.yaxis.tick_right()
189
193
190 if '0.' in matplotlib.__version__[0:2]:
194 if '0.' in matplotlib.__version__[0:2]:
191 print "The matplotlib version has to be updated to 1.1 or newer"
195 print "The matplotlib version has to be updated to 1.1 or newer"
192 return imesh
196 return imesh
193
197
194 if '1.0.' in matplotlib.__version__[0:4]:
198 if '1.0.' in matplotlib.__version__[0:4]:
195 print "The matplotlib version has to be updated to 1.1 or newer"
199 print "The matplotlib version has to be updated to 1.1 or newer"
196 return imesh
200 return imesh
197
201
198 matplotlib.pyplot.tight_layout()
202 matplotlib.pyplot.tight_layout()
199
203
200 if XAxisAsTime:
204 if XAxisAsTime:
201
205
202 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
206 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
203 ax.xaxis.set_major_formatter(FuncFormatter(func))
207 ax.xaxis.set_major_formatter(FuncFormatter(func))
204 ax.xaxis.set_major_locator(LinearLocator(7))
208 ax.xaxis.set_major_locator(LinearLocator(7))
205
209
206 matplotlib.pyplot.ion()
210 matplotlib.pyplot.ion()
207 return imesh
211 return imesh
208
212
209 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
213 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
210
214
211 z = z.T
215 z = z.T
212
216
213 ax = imesh.get_axes()
217 ax = imesh.get_axes()
214
218
215 printLabels(ax, xlabel, ylabel, title)
219 printLabels(ax, xlabel, ylabel, title)
216
220
217 imesh.set_array(z.ravel())
221 imesh.set_array(z.ravel())
218
222
219 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
223 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
220
224
221 printLabels(ax, xlabel, ylabel, title)
225 printLabels(ax, xlabel, ylabel, title)
222
226
223 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
227 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
224
228
225 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
229 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
226 ticksize=9, xtick_visible=True, ytick_visible=True,
230 ticksize=9, xtick_visible=True, ytick_visible=True,
227 nxticks=4, nyticks=10,
231 nxticks=4, nyticks=10,
228 grid=None):
232 grid=None):
229
233
230 """
234 """
231
235
232 Input:
236 Input:
233 grid : None, 'both', 'x', 'y'
237 grid : None, 'both', 'x', 'y'
234 """
238 """
235
239
236 matplotlib.pyplot.ioff()
240 matplotlib.pyplot.ioff()
237
241
238 lines = ax.plot(x.T, y)
242 lines = ax.plot(x.T, y)
239 leg = ax.legend(lines, legendlabels, loc='upper right')
243 leg = ax.legend(lines, legendlabels, loc='upper right')
240 leg.get_frame().set_alpha(0.5)
244 leg.get_frame().set_alpha(0.5)
241 ax.set_xlim([xmin,xmax])
245 ax.set_xlim([xmin,xmax])
242 ax.set_ylim([ymin,ymax])
246 ax.set_ylim([ymin,ymax])
243 printLabels(ax, xlabel, ylabel, title)
247 printLabels(ax, xlabel, ylabel, title)
244
248
245 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
249 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
246 ax.set_xticks(xtickspos)
250 ax.set_xticks(xtickspos)
247
251
248 for tick in ax.get_xticklabels():
252 for tick in ax.get_xticklabels():
249 tick.set_visible(xtick_visible)
253 tick.set_visible(xtick_visible)
250
254
251 for tick in ax.xaxis.get_major_ticks():
255 for tick in ax.xaxis.get_major_ticks():
252 tick.label.set_fontsize(ticksize)
256 tick.label.set_fontsize(ticksize)
253
257
254 for tick in ax.get_yticklabels():
258 for tick in ax.get_yticklabels():
255 tick.set_visible(ytick_visible)
259 tick.set_visible(ytick_visible)
256
260
257 for tick in ax.yaxis.get_major_ticks():
261 for tick in ax.yaxis.get_major_ticks():
258 tick.label.set_fontsize(ticksize)
262 tick.label.set_fontsize(ticksize)
259
263
260 iplot = ax.lines[-1]
264 iplot = ax.lines[-1]
261
265
262 if '0.' in matplotlib.__version__[0:2]:
266 if '0.' in matplotlib.__version__[0:2]:
263 print "The matplotlib version has to be updated to 1.1 or newer"
267 print "The matplotlib version has to be updated to 1.1 or newer"
264 return iplot
268 return iplot
265
269
266 if '1.0.' in matplotlib.__version__[0:4]:
270 if '1.0.' in matplotlib.__version__[0:4]:
267 print "The matplotlib version has to be updated to 1.1 or newer"
271 print "The matplotlib version has to be updated to 1.1 or newer"
268 return iplot
272 return iplot
269
273
270 if grid != None:
274 if grid != None:
271 ax.grid(b=True, which='major', axis=grid)
275 ax.grid(b=True, which='major', axis=grid)
272
276
273 matplotlib.pyplot.tight_layout()
277 matplotlib.pyplot.tight_layout()
274
278
275 matplotlib.pyplot.ion()
279 matplotlib.pyplot.ion()
276
280
277 return iplot
281 return iplot
278
282
279
283
280 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
284 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
281
285
282 ax = iplot.get_axes()
286 ax = iplot.get_axes()
283
287
284 printLabels(ax, xlabel, ylabel, title)
288 printLabels(ax, xlabel, ylabel, title)
285
289
286 for i in range(len(ax.lines)):
290 for i in range(len(ax.lines)):
287 line = ax.lines[i]
291 line = ax.lines[i]
288 line.set_data(x[i,:],y)
292 line.set_data(x[i,:],y)
289
293
290 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
294 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
291 ticksize=9, xtick_visible=True, ytick_visible=True,
295 ticksize=9, xtick_visible=True, ytick_visible=True,
292 nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid",
296 nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid",
293 grid=None, XAxisAsTime=False):
297 grid=None, XAxisAsTime=False):
294
298
295 """
299 """
296
300
297 Input:
301 Input:
298 grid : None, 'both', 'x', 'y'
302 grid : None, 'both', 'x', 'y'
299 """
303 """
300
304
301 matplotlib.pyplot.ioff()
305 matplotlib.pyplot.ioff()
302
306
303 lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
307 lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
304 leg = ax.legend(lines, legendlabels, bbox_to_anchor=(1.05, 1), loc='upper right', numpoints=1, handlelength=1.5, \
308 leg = ax.legend(lines, legendlabels, bbox_to_anchor=(1.05, 1), loc='upper right', numpoints=1, handlelength=1.5, \
305 handletextpad=0.5, borderpad=0.2, labelspacing=0.2, borderaxespad=0.)
309 handletextpad=0.5, borderpad=0.2, labelspacing=0.2, borderaxespad=0.)
306
310
307 ax.set_xlim([xmin,xmax])
311 ax.set_xlim([xmin,xmax])
308 ax.set_ylim([ymin,ymax])
312 ax.set_ylim([ymin,ymax])
309 printLabels(ax, xlabel, ylabel, title)
313 printLabels(ax, xlabel, ylabel, title)
310
314
311 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
315 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
312 # ax.set_xticks(xtickspos)
316 # ax.set_xticks(xtickspos)
313
317
314 for tick in ax.get_xticklabels():
318 for tick in ax.get_xticklabels():
315 tick.set_visible(xtick_visible)
319 tick.set_visible(xtick_visible)
316
320
317 for tick in ax.xaxis.get_major_ticks():
321 for tick in ax.xaxis.get_major_ticks():
318 tick.label.set_fontsize(ticksize)
322 tick.label.set_fontsize(ticksize)
319
323
320 for tick in ax.get_yticklabels():
324 for tick in ax.get_yticklabels():
321 tick.set_visible(ytick_visible)
325 tick.set_visible(ytick_visible)
322
326
323 for tick in ax.yaxis.get_major_ticks():
327 for tick in ax.yaxis.get_major_ticks():
324 tick.label.set_fontsize(ticksize)
328 tick.label.set_fontsize(ticksize)
325
329
326 iplot = ax.lines[-1]
330 iplot = ax.lines[-1]
327
331
328 if '0.' in matplotlib.__version__[0:2]:
332 if '0.' in matplotlib.__version__[0:2]:
329 print "The matplotlib version has to be updated to 1.1 or newer"
333 print "The matplotlib version has to be updated to 1.1 or newer"
330 return iplot
334 return iplot
331
335
332 if '1.0.' in matplotlib.__version__[0:4]:
336 if '1.0.' in matplotlib.__version__[0:4]:
333 print "The matplotlib version has to be updated to 1.1 or newer"
337 print "The matplotlib version has to be updated to 1.1 or newer"
334 return iplot
338 return iplot
335
339
336 if grid != None:
340 if grid != None:
337 ax.grid(b=True, which='major', axis=grid)
341 ax.grid(b=True, which='major', axis=grid)
338
342
339 matplotlib.pyplot.tight_layout()
343 matplotlib.pyplot.tight_layout()
340
344
341 if XAxisAsTime:
345 if XAxisAsTime:
342
346
343 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
347 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
344 ax.xaxis.set_major_formatter(FuncFormatter(func))
348 ax.xaxis.set_major_formatter(FuncFormatter(func))
345 ax.xaxis.set_major_locator(LinearLocator(7))
349 ax.xaxis.set_major_locator(LinearLocator(7))
346
350
347 matplotlib.pyplot.ion()
351 matplotlib.pyplot.ion()
348
352
349 return iplot
353 return iplot
350
354
351 def pmultilineinyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
355 def pmultilineinyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
352
356
353 ax = iplot.get_axes()
357 ax = iplot.get_axes()
354
358
355 printLabels(ax, xlabel, ylabel, title)
359 printLabels(ax, xlabel, ylabel, title)
356
360
357 for i in range(len(ax.lines)):
361 for i in range(len(ax.lines)):
358 line = ax.lines[i]
362 line = ax.lines[i]
359 line.set_data(x,y[i,:])
363 line.set_data(x,y[i,:])
360
364
361 def draw(fig):
365 def draw(fig):
362
366
363 if type(fig) == 'int':
367 if type(fig) == 'int':
364 raise ValueError, "This parameter should be of tpye matplotlib figure"
368 raise ValueError, "This parameter should be of tpye matplotlib figure"
365
369
366 fig.canvas.draw() No newline at end of file
370 fig.canvas.draw()
@@ -1,525 +1,536
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import copy
8 import copy
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11
11
12 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from jroheaderIO import SystemHeader, RadarControllerHeader
13
13
14 def hildebrand_sekhon(data, navg):
14 def hildebrand_sekhon(data, navg):
15 """
15 """
16 This method is for the objective determination of de noise level in Doppler spectra. This
16 This method is for the objective determination of de noise level in Doppler spectra. This
17 implementation technique is based on the fact that the standard deviation of the spectral
17 implementation technique is based on the fact that the standard deviation of the spectral
18 densities is equal to the mean spectral density for white Gaussian noise
18 densities is equal to the mean spectral density for white Gaussian noise
19
19
20 Inputs:
20 Inputs:
21 Data : heights
21 Data : heights
22 navg : numbers of averages
22 navg : numbers of averages
23
23
24 Return:
24 Return:
25 -1 : any error
25 -1 : any error
26 anoise : noise's level
26 anoise : noise's level
27 """
27 """
28
28
29 dataflat = data.copy().reshape(-1)
29 dataflat = data.copy().reshape(-1)
30 dataflat.sort()
30 dataflat.sort()
31 npts = dataflat.size #numbers of points of the data
31 npts = dataflat.size #numbers of points of the data
32 npts_noise = 0.2*npts
32 npts_noise = 0.2*npts
33
33
34 if npts < 32:
34 if npts < 32:
35 print "error in noise - requires at least 32 points"
35 print "error in noise - requires at least 32 points"
36 return -1.0
36 return -1.0
37
37
38 dataflat2 = numpy.power(dataflat,2)
38 dataflat2 = numpy.power(dataflat,2)
39
39
40 cs = numpy.cumsum(dataflat)
40 cs = numpy.cumsum(dataflat)
41 cs2 = numpy.cumsum(dataflat2)
41 cs2 = numpy.cumsum(dataflat2)
42
42
43 # data sorted in ascending order
43 # data sorted in ascending order
44 nmin = int((npts + 7.)/8)
44 nmin = int((npts + 7.)/8)
45
45
46 for i in range(nmin, npts):
46 for i in range(nmin, npts):
47 s = cs[i]
47 s = cs[i]
48 s2 = cs2[i]
48 s2 = cs2[i]
49 p = s / float(i);
49 p = s / float(i);
50 p2 = p**2;
50 p2 = p**2;
51 q = s2 / float(i) - p2;
51 q = s2 / float(i) - p2;
52 leftc = p2;
52 leftc = p2;
53 rightc = q * float(navg);
53 rightc = q * float(navg);
54 R2 = leftc/rightc
54 R2 = leftc/rightc
55
55
56 # Signal detect: R2 < 1 (R2 = leftc/rightc)
56 # Signal detect: R2 < 1 (R2 = leftc/rightc)
57 if R2 < 1:
57 if R2 < 1:
58 npts_noise = i
58 npts_noise = i
59 break
59 break
60
60
61
61
62 anoise = numpy.average(dataflat[0:npts_noise])
62 anoise = numpy.average(dataflat[0:npts_noise])
63
63
64 return anoise;
64 return anoise;
65
65
66 def sorting_bruce(data, navg):
66 def sorting_bruce(data, navg):
67
67
68 data = data.copy()
68 data = data.copy()
69
69
70 sortdata = numpy.sort(data)
70 sortdata = numpy.sort(data)
71 lenOfData = len(data)
71 lenOfData = len(data)
72 nums_min = lenOfData/10
72 nums_min = lenOfData/10
73
73
74 if (lenOfData/10) > 0:
74 if (lenOfData/10) > 0:
75 nums_min = lenOfData/10
75 nums_min = lenOfData/10
76 else:
76 else:
77 nums_min = 0
77 nums_min = 0
78
78
79 rtest = 1.0 + 1.0/navg
79 rtest = 1.0 + 1.0/navg
80
80
81 sum = 0.
81 sum = 0.
82
82
83 sumq = 0.
83 sumq = 0.
84
84
85 j = 0
85 j = 0
86
86
87 cont = 1
87 cont = 1
88
88
89 while((cont==1)and(j<lenOfData)):
89 while((cont==1)and(j<lenOfData)):
90
90
91 sum += sortdata[j]
91 sum += sortdata[j]
92
92
93 sumq += sortdata[j]**2
93 sumq += sortdata[j]**2
94
94
95 j += 1
95 j += 1
96
96
97 if j > nums_min:
97 if j > nums_min:
98 if ((sumq*j) <= (rtest*sum**2)):
98 if ((sumq*j) <= (rtest*sum**2)):
99 lnoise = sum / j
99 lnoise = sum / j
100 else:
100 else:
101 j = j - 1
101 j = j - 1
102 sum = sum - sordata[j]
102 sum = sum - sordata[j]
103 sumq = sumq - sordata[j]**2
103 sumq = sumq - sordata[j]**2
104 cont = 0
104 cont = 0
105
105
106 if j == nums_min:
106 if j == nums_min:
107 lnoise = sum /j
107 lnoise = sum /j
108
108
109 return lnoise
109 return lnoise
110
110
111 class JROData:
111 class JROData:
112
112
113 # m_BasicHeader = BasicHeader()
113 # m_BasicHeader = BasicHeader()
114 # m_ProcessingHeader = ProcessingHeader()
114 # m_ProcessingHeader = ProcessingHeader()
115
115
116 systemHeaderObj = SystemHeader()
116 systemHeaderObj = SystemHeader()
117
117
118 radarControllerHeaderObj = RadarControllerHeader()
118 radarControllerHeaderObj = RadarControllerHeader()
119
119
120 # data = None
120 # data = None
121
121
122 type = None
122 type = None
123
123
124 dtype = None
124 dtype = None
125
125
126 # nChannels = None
126 # nChannels = None
127
127
128 # nHeights = None
128 # nHeights = None
129
129
130 nProfiles = None
130 nProfiles = None
131
131
132 heightList = None
132 heightList = None
133
133
134 channelList = None
134 channelList = None
135
135
136 flagNoData = True
136 flagNoData = True
137
137
138 flagTimeBlock = False
138 flagTimeBlock = False
139
139
140 utctime = None
140 utctime = None
141
141
142 blocksize = None
142 blocksize = None
143
143
144 nCode = None
144 nCode = None
145
145
146 nBaud = None
146 nBaud = None
147
147
148 code = None
148 code = None
149
149
150 flagDecodeData = False #asumo q la data no esta decodificada
150 flagDecodeData = False #asumo q la data no esta decodificada
151
151
152 flagDeflipData = False #asumo q la data no esta sin flip
152 flagDeflipData = False #asumo q la data no esta sin flip
153
153
154 flagShiftFFT = False
154 flagShiftFFT = False
155
155
156 ippSeconds = None
156 ippSeconds = None
157
157
158 timeInterval = None
158 timeInterval = None
159
159
160 nCohInt = None
160 nCohInt = None
161
161
162 noise = None
162 noise = None
163
163
164 windowOfFilter = 1
165
164 #Speed of ligth
166 #Speed of ligth
165 C = 3e8
167 C = 3e8
166
168
167 frequency = 49.92e6
169 frequency = 49.92e6
168
170
169 def __init__(self):
171 def __init__(self):
170
172
171 raise ValueError, "This class has not been implemented"
173 raise ValueError, "This class has not been implemented"
172
174
173 def copy(self, inputObj=None):
175 def copy(self, inputObj=None):
174
176
175 if inputObj == None:
177 if inputObj == None:
176 return copy.deepcopy(self)
178 return copy.deepcopy(self)
177
179
178 for key in inputObj.__dict__.keys():
180 for key in inputObj.__dict__.keys():
179 self.__dict__[key] = inputObj.__dict__[key]
181 self.__dict__[key] = inputObj.__dict__[key]
180
182
181 def deepcopy(self):
183 def deepcopy(self):
182
184
183 return copy.deepcopy(self)
185 return copy.deepcopy(self)
184
186
185 def isEmpty(self):
187 def isEmpty(self):
186
188
187 return self.flagNoData
189 return self.flagNoData
188
190
189 def getNoise(self):
191 def getNoise(self):
190
192
191 raise ValueError, "Not implemented"
193 raise ValueError, "Not implemented"
192
194
193 def getNChannels(self):
195 def getNChannels(self):
194
196
195 return len(self.channelList)
197 return len(self.channelList)
196
198
197 def getChannelIndexList(self):
199 def getChannelIndexList(self):
198
200
199 return range(self.nChannels)
201 return range(self.nChannels)
200
202
201 def getNHeights(self):
203 def getNHeights(self):
202
204
203 return len(self.heightList)
205 return len(self.heightList)
204
206
205 def getHeiRange(self, extrapoints=0):
207 def getHeiRange(self, extrapoints=0):
206
208
207 heis = self.heightList
209 heis = self.heightList
208 # deltah = self.heightList[1] - self.heightList[0]
210 # deltah = self.heightList[1] - self.heightList[0]
209 #
211 #
210 # heis.append(self.heightList[-1])
212 # heis.append(self.heightList[-1])
211
213
212 return heis
214 return heis
213
215
214 def getDatatime(self):
216 def getDatatime(self):
215
217
216 datatime = datetime.datetime.utcfromtimestamp(self.utctime)
218 datatime = datetime.datetime.utcfromtimestamp(self.utctime)
217 return datatime
219 return datatime
218
220
219 def getTimeRange(self):
221 def getTimeRange(self):
220
222
221 datatime = []
223 datatime = []
222
224
223 datatime.append(self.utctime)
225 datatime.append(self.utctime)
224 datatime.append(self.utctime + self.timeInterval)
226 datatime.append(self.utctime + self.timeInterval)
225
227
226 datatime = numpy.array(datatime)
228 datatime = numpy.array(datatime)
227
229
228 return datatime
230 return datatime
229
231
230 def getFmax(self):
232 def getFmax(self):
231
233
232 PRF = 1./(self.ippSeconds * self.nCohInt)
234 PRF = 1./(self.ippSeconds * self.nCohInt)
233
235
234 fmax = PRF/2.
236 fmax = PRF/2.
235
237
236 return fmax
238 return fmax
237
239
238 def getVmax(self):
240 def getVmax(self):
239
241
240 _lambda = self.C/self.frequency
242 _lambda = self.C/self.frequency
241
243
242 vmax = self.getFmax() * _lambda
244 vmax = self.getFmax() * _lambda
243
245
244 return vmax
246 return vmax
245
247
246 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
248 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
247 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
249 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
248 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
250 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
249 noise = property(getNoise, "I'm the 'nHeights' property.")
251 noise = property(getNoise, "I'm the 'nHeights' property.")
250 datatime = property(getDatatime, "I'm the 'datatime' property")
252 datatime = property(getDatatime, "I'm the 'datatime' property")
251
253
252 class Voltage(JROData):
254 class Voltage(JROData):
253
255
254 #data es un numpy array de 2 dmensiones (canales, alturas)
256 #data es un numpy array de 2 dmensiones (canales, alturas)
255 data = None
257 data = None
256
258
257 def __init__(self):
259 def __init__(self):
258 '''
260 '''
259 Constructor
261 Constructor
260 '''
262 '''
261
263
262 self.radarControllerHeaderObj = RadarControllerHeader()
264 self.radarControllerHeaderObj = RadarControllerHeader()
263
265
264 self.systemHeaderObj = SystemHeader()
266 self.systemHeaderObj = SystemHeader()
265
267
266 self.type = "Voltage"
268 self.type = "Voltage"
267
269
268 self.data = None
270 self.data = None
269
271
270 self.dtype = None
272 self.dtype = None
271
273
272 # self.nChannels = 0
274 # self.nChannels = 0
273
275
274 # self.nHeights = 0
276 # self.nHeights = 0
275
277
276 self.nProfiles = None
278 self.nProfiles = None
277
279
278 self.heightList = None
280 self.heightList = None
279
281
280 self.channelList = None
282 self.channelList = None
281
283
282 # self.channelIndexList = None
284 # self.channelIndexList = None
283
285
284 self.flagNoData = True
286 self.flagNoData = True
285
287
286 self.flagTimeBlock = False
288 self.flagTimeBlock = False
287
289
288 self.utctime = None
290 self.utctime = None
289
291
290 self.nCohInt = None
292 self.nCohInt = None
291
293
292 self.blocksize = None
294 self.blocksize = None
293
295
294 self.flagDecodeData = False #asumo q la data no esta decodificada
296 self.flagDecodeData = False #asumo q la data no esta decodificada
295
297
296 self.flagDeflipData = False #asumo q la data no esta sin flip
298 self.flagDeflipData = False #asumo q la data no esta sin flip
297
299
298 self.flagShiftFFT = False
300 self.flagShiftFFT = False
299
301
300
302
301 def getNoisebyHildebrand(self):
303 def getNoisebyHildebrand(self):
302 """
304 """
303 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
305 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
304
306
305 Return:
307 Return:
306 noiselevel
308 noiselevel
307 """
309 """
308
310
309 for channel in range(self.nChannels):
311 for channel in range(self.nChannels):
310 daux = self.data_spc[channel,:,:]
312 daux = self.data_spc[channel,:,:]
311 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
313 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
312
314
313 return self.noise
315 return self.noise
314
316
315 def getNoise(self, type = 1):
317 def getNoise(self, type = 1):
316
318
317 self.noise = numpy.zeros(self.nChannels)
319 self.noise = numpy.zeros(self.nChannels)
318
320
319 if type == 1:
321 if type == 1:
320 noise = self.getNoisebyHildebrand()
322 noise = self.getNoisebyHildebrand()
321
323
322 return 10*numpy.log10(noise)
324 return 10*numpy.log10(noise)
323
325
324 class Spectra(JROData):
326 class Spectra(JROData):
325
327
326 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
328 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
327 data_spc = None
329 data_spc = None
328
330
329 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
331 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
330 data_cspc = None
332 data_cspc = None
331
333
332 #data es un numpy array de 2 dmensiones (canales, alturas)
334 #data es un numpy array de 2 dmensiones (canales, alturas)
333 data_dc = None
335 data_dc = None
334
336
335 nFFTPoints = None
337 nFFTPoints = None
336
338
337 nPairs = None
339 nPairs = None
338
340
339 pairsList = None
341 pairsList = None
340
342
341 nIncohInt = None
343 nIncohInt = None
342
344
343 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
345 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
344
346
345 nCohInt = None #se requiere para determinar el valor de timeInterval
347 nCohInt = None #se requiere para determinar el valor de timeInterval
346
348
347 def __init__(self):
349 def __init__(self):
348 '''
350 '''
349 Constructor
351 Constructor
350 '''
352 '''
351
353
352 self.radarControllerHeaderObj = RadarControllerHeader()
354 self.radarControllerHeaderObj = RadarControllerHeader()
353
355
354 self.systemHeaderObj = SystemHeader()
356 self.systemHeaderObj = SystemHeader()
355
357
356 self.type = "Spectra"
358 self.type = "Spectra"
357
359
358 # self.data = None
360 # self.data = None
359
361
360 self.dtype = None
362 self.dtype = None
361
363
362 # self.nChannels = 0
364 # self.nChannels = 0
363
365
364 # self.nHeights = 0
366 # self.nHeights = 0
365
367
366 self.nProfiles = None
368 self.nProfiles = None
367
369
368 self.heightList = None
370 self.heightList = None
369
371
370 self.channelList = None
372 self.channelList = None
371
373
372 # self.channelIndexList = None
374 # self.channelIndexList = None
373
375
374 self.flagNoData = True
376 self.flagNoData = True
375
377
376 self.flagTimeBlock = False
378 self.flagTimeBlock = False
377
379
378 self.utctime = None
380 self.utctime = None
379
381
380 self.nCohInt = None
382 self.nCohInt = None
381
383
382 self.nIncohInt = None
384 self.nIncohInt = None
383
385
384 self.blocksize = None
386 self.blocksize = None
385
387
386 self.nFFTPoints = None
388 self.nFFTPoints = None
387
389
388 self.wavelength = None
390 self.wavelength = None
389
391
390 self.flagDecodeData = False #asumo q la data no esta decodificada
392 self.flagDecodeData = False #asumo q la data no esta decodificada
391
393
392 self.flagDeflipData = False #asumo q la data no esta sin flip
394 self.flagDeflipData = False #asumo q la data no esta sin flip
393
395
394 self.flagShiftFFT = False
396 self.flagShiftFFT = False
395
397
396 def getNoisebyHildebrand(self):
398 def getNoisebyHildebrand(self):
397 """
399 """
398 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
400 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
399
401
400 Return:
402 Return:
401 noiselevel
403 noiselevel
402 """
404 """
403
405
404 for channel in range(self.nChannels):
406 for channel in range(self.nChannels):
405 daux = self.data_spc[channel,:,:]
407 daux = self.data_spc[channel,:,:]
406 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
408 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
407
409
408 return self.noise
410 return self.noise
409
411
410 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
412 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
411 """
413 """
412 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
414 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
413 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
415 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
414
416
415 Inputs:
417 Inputs:
416 heiIndexMin: Limite inferior del eje de alturas
418 heiIndexMin: Limite inferior del eje de alturas
417 heiIndexMax: Limite superior del eje de alturas
419 heiIndexMax: Limite superior del eje de alturas
418 freqIndexMin: Limite inferior del eje de frecuencia
420 freqIndexMin: Limite inferior del eje de frecuencia
419 freqIndexMax: Limite supoerior del eje de frecuencia
421 freqIndexMax: Limite supoerior del eje de frecuencia
420 """
422 """
421
423
422 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
424 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
423
425
424 for channel in range(self.nChannels):
426 for channel in range(self.nChannels):
425 daux = data[channel,:,:]
427 daux = data[channel,:,:]
426 self.noise[channel] = numpy.average(daux)
428 self.noise[channel] = numpy.average(daux)
427
429
428 return self.noise
430 return self.noise
429
431
430 def getNoisebySort(self):
432 def getNoisebySort(self):
431
433
432 for channel in range(self.nChannels):
434 for channel in range(self.nChannels):
433 daux = self.data_spc[channel,:,:]
435 daux = self.data_spc[channel,:,:]
434 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
436 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
435
437
436 return self.noise
438 return self.noise
437
439
438 def getNoise(self, type = 1):
440 def getNoise(self, type = 1):
439
441
440 self.noise = numpy.zeros(self.nChannels)
442 self.noise = numpy.zeros(self.nChannels)
441
443
442 if type == 1:
444 if type == 1:
443 noise = self.getNoisebyHildebrand()
445 noise = self.getNoisebyHildebrand()
444
446
445 if type == 2:
447 if type == 2:
446 noise = self.getNoisebySort()
448 noise = self.getNoisebySort()
447
449
448 if type == 3:
450 if type == 3:
449 noise = self.getNoisebyWindow()
451 noise = self.getNoisebyWindow()
450
452
451 return 10*numpy.log10(noise)
453 return noise
452
454
453
455
454 def getFreqRange(self, extrapoints=0):
456 def getFreqRange(self, extrapoints=0):
455
457
456 deltafreq = self.getFmax() / self.nFFTPoints
458 deltafreq = self.getFmax() / self.nFFTPoints
457 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
459 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
458
460
459 return freqrange
461 return freqrange
460
462
461 def getVelRange(self, extrapoints=0):
463 def getVelRange(self, extrapoints=0):
462
464
463 deltav = self.getVmax() / self.nFFTPoints
465 deltav = self.getVmax() / self.nFFTPoints
464 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
466 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
465
467
466 return velrange
468 return velrange
467
469
468 def getNPairs(self):
470 def getNPairs(self):
469
471
470 return len(self.pairsList)
472 return len(self.pairsList)
471
473
472 def getPairsIndexList(self):
474 def getPairsIndexList(self):
473
475
474 return range(self.nPairs)
476 return range(self.nPairs)
475
477
478 def getNormFactor(self):
479 pwcode = 1
480 if self.flagDecodeData:
481 pwcode = numpy.sum(self.code[0]**2)
482 normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*self.windowOfFilter*pwcode
483
484 return normFactor
485
476 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
486 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
477 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
487 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
488 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
478
489
479 class SpectraHeis(JROData):
490 class SpectraHeis(JROData):
480
491
481 data_spc = None
492 data_spc = None
482
493
483 data_cspc = None
494 data_cspc = None
484
495
485 data_dc = None
496 data_dc = None
486
497
487 nFFTPoints = None
498 nFFTPoints = None
488
499
489 nPairs = None
500 nPairs = None
490
501
491 pairsList = None
502 pairsList = None
492
503
493 nIncohInt = None
504 nIncohInt = None
494
505
495 def __init__(self):
506 def __init__(self):
496
507
497 self.radarControllerHeaderObj = RadarControllerHeader()
508 self.radarControllerHeaderObj = RadarControllerHeader()
498
509
499 self.systemHeaderObj = SystemHeader()
510 self.systemHeaderObj = SystemHeader()
500
511
501 self.type = "SpectraHeis"
512 self.type = "SpectraHeis"
502
513
503 self.dtype = None
514 self.dtype = None
504
515
505 # self.nChannels = 0
516 # self.nChannels = 0
506
517
507 # self.nHeights = 0
518 # self.nHeights = 0
508
519
509 self.nProfiles = None
520 self.nProfiles = None
510
521
511 self.heightList = None
522 self.heightList = None
512
523
513 self.channelList = None
524 self.channelList = None
514
525
515 # self.channelIndexList = None
526 # self.channelIndexList = None
516
527
517 self.flagNoData = True
528 self.flagNoData = True
518
529
519 self.flagTimeBlock = False
530 self.flagTimeBlock = False
520
531
521 self.nPairs = 0
532 self.nPairs = 0
522
533
523 self.utctime = None
534 self.utctime = None
524
535
525 self.blocksize = None
536 self.blocksize = None
@@ -1,954 +1,986
1 import numpy
1 import numpy
2 import time, datetime
2 import time, datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class CrossSpectraPlot(Figure):
5 class CrossSpectraPlot(Figure):
6
6
7 __isConfig = None
7 __isConfig = None
8 __nsubplots = None
8 __nsubplots = None
9
9
10 WIDTH = None
10 WIDTH = None
11 HEIGHT = None
11 HEIGHT = None
12 WIDTHPROF = None
12 WIDTHPROF = None
13 HEIGHTPROF = None
13 HEIGHTPROF = None
14 PREFIX = 'cspc'
14 PREFIX = 'cspc'
15
15
16 def __init__(self):
16 def __init__(self):
17
17
18 self.__isConfig = False
18 self.__isConfig = False
19 self.__nsubplots = 4
19 self.__nsubplots = 4
20
20
21 self.WIDTH = 250
21 self.WIDTH = 250
22 self.HEIGHT = 250
22 self.HEIGHT = 250
23 self.WIDTHPROF = 0
23 self.WIDTHPROF = 0
24 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
25
25
26 def getSubplots(self):
26 def getSubplots(self):
27
27
28 ncol = 4
28 ncol = 4
29 nrow = self.nplots
29 nrow = self.nplots
30
30
31 return nrow, ncol
31 return nrow, ncol
32
32
33 def setup(self, idfigure, nplots, wintitle, showprofile=True):
33 def setup(self, idfigure, nplots, wintitle, showprofile=True):
34
34
35 self.__showprofile = showprofile
35 self.__showprofile = showprofile
36 self.nplots = nplots
36 self.nplots = nplots
37
37
38 ncolspan = 1
38 ncolspan = 1
39 colspan = 1
39 colspan = 1
40
40
41 self.createFigure(idfigure = idfigure,
41 self.createFigure(idfigure = idfigure,
42 wintitle = wintitle,
42 wintitle = wintitle,
43 widthplot = self.WIDTH + self.WIDTHPROF,
43 widthplot = self.WIDTH + self.WIDTHPROF,
44 heightplot = self.HEIGHT + self.HEIGHTPROF)
44 heightplot = self.HEIGHT + self.HEIGHTPROF)
45
45
46 nrow, ncol = self.getSubplots()
46 nrow, ncol = self.getSubplots()
47
47
48 counter = 0
48 counter = 0
49 for y in range(nrow):
49 for y in range(nrow):
50 for x in range(ncol):
50 for x in range(ncol):
51 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
51 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
52
52
53 counter += 1
53 counter += 1
54
54
55 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
55 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
56 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
56 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
57 save=False, figpath='./', figfile=None):
57 save=False, figpath='./', figfile=None):
58
58
59 """
59 """
60
60
61 Input:
61 Input:
62 dataOut :
62 dataOut :
63 idfigure :
63 idfigure :
64 wintitle :
64 wintitle :
65 channelList :
65 channelList :
66 showProfile :
66 showProfile :
67 xmin : None,
67 xmin : None,
68 xmax : None,
68 xmax : None,
69 ymin : None,
69 ymin : None,
70 ymax : None,
70 ymax : None,
71 zmin : None,
71 zmin : None,
72 zmax : None
72 zmax : None
73 """
73 """
74
74
75 if pairsList == None:
75 if pairsList == None:
76 pairsIndexList = dataOut.pairsIndexList
76 pairsIndexList = dataOut.pairsIndexList
77 else:
77 else:
78 pairsIndexList = []
78 pairsIndexList = []
79 for pair in pairsList:
79 for pair in pairsList:
80 if pair not in dataOut.pairsList:
80 if pair not in dataOut.pairsList:
81 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
81 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
82 pairsIndexList.append(dataOut.pairsList.index(pair))
82 pairsIndexList.append(dataOut.pairsList.index(pair))
83
83
84 if pairsIndexList == []:
84 if pairsIndexList == []:
85 return
85 return
86
86
87 if len(pairsIndexList) > 4:
87 if len(pairsIndexList) > 4:
88 pairsIndexList = pairsIndexList[0:4]
88 pairsIndexList = pairsIndexList[0:4]
89
89 factor = dataOut.normFactor
90 x = dataOut.getVelRange(1)
90 x = dataOut.getVelRange(1)
91 y = dataOut.getHeiRange()
91 y = dataOut.getHeiRange()
92 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
92 z = dataOut.data_spc[:,:,:]/factor
93 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
93 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
94 avg = numpy.average(numpy.abs(z), axis=1)
94 avg = numpy.average(numpy.abs(z), axis=1)
95 noise = dataOut.getNoise()/factor
96
97 zdB = 10*numpy.log10(z)
98 avgdB = 10*numpy.log10(avg)
99 noisedB = 10*numpy.log10(noise)
95
100
96 noise = dataOut.getNoise()
97
101
98 thisDatetime = dataOut.datatime
102 thisDatetime = dataOut.datatime
99 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
103 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
100 xlabel = "Velocity (m/s)"
104 xlabel = "Velocity (m/s)"
101 ylabel = "Range (Km)"
105 ylabel = "Range (Km)"
102
106
103 if not self.__isConfig:
107 if not self.__isConfig:
104
108
105 nplots = len(pairsIndexList)
109 nplots = len(pairsIndexList)
106
110
107 self.setup(idfigure=idfigure,
111 self.setup(idfigure=idfigure,
108 nplots=nplots,
112 nplots=nplots,
109 wintitle=wintitle,
113 wintitle=wintitle,
110 showprofile=showprofile)
114 showprofile=showprofile)
111
115
112 if xmin == None: xmin = numpy.nanmin(x)
116 if xmin == None: xmin = numpy.nanmin(x)
113 if xmax == None: xmax = numpy.nanmax(x)
117 if xmax == None: xmax = numpy.nanmax(x)
114 if ymin == None: ymin = numpy.nanmin(y)
118 if ymin == None: ymin = numpy.nanmin(y)
115 if ymax == None: ymax = numpy.nanmax(y)
119 if ymax == None: ymax = numpy.nanmax(y)
116 if zmin == None: zmin = numpy.nanmin(avg)*0.9
120 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
117 if zmax == None: zmax = numpy.nanmax(avg)*0.9
121 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
118
122
119 self.__isConfig = True
123 self.__isConfig = True
120
124
121 self.setWinTitle(title)
125 self.setWinTitle(title)
122
126
123 for i in range(self.nplots):
127 for i in range(self.nplots):
124 pair = dataOut.pairsList[pairsIndexList[i]]
128 pair = dataOut.pairsList[pairsIndexList[i]]
125
129
126 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
130 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
127 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
131 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
128 axes0 = self.axesList[i*self.__nsubplots]
132 axes0 = self.axesList[i*self.__nsubplots]
129 axes0.pcolor(x, y, z,
133 axes0.pcolor(x, y, zdB,
130 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
134 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
131 xlabel=xlabel, ylabel=ylabel, title=title,
135 xlabel=xlabel, ylabel=ylabel, title=title,
132 ticksize=9, cblabel='')
136 ticksize=9, cblabel='')
133
137
134 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
138 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
135 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
139 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
136 axes0 = self.axesList[i*self.__nsubplots+1]
140 axes0 = self.axesList[i*self.__nsubplots+1]
137 axes0.pcolor(x, y, z,
141 axes0.pcolor(x, y, zdB,
138 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
142 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
139 xlabel=xlabel, ylabel=ylabel, title=title,
143 xlabel=xlabel, ylabel=ylabel, title=title,
140 ticksize=9, cblabel='')
144 ticksize=9, cblabel='')
141
145
142 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
146 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
143 coherence = numpy.abs(coherenceComplex)
147 coherence = numpy.abs(coherenceComplex)
144 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
148 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
145
149
146
150
147 title = "Coherence %d%d" %(pair[0], pair[1])
151 title = "Coherence %d%d" %(pair[0], pair[1])
148 axes0 = self.axesList[i*self.__nsubplots+2]
152 axes0 = self.axesList[i*self.__nsubplots+2]
149 axes0.pcolor(x, y, coherence,
153 axes0.pcolor(x, y, coherence,
150 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
154 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
151 xlabel=xlabel, ylabel=ylabel, title=title,
155 xlabel=xlabel, ylabel=ylabel, title=title,
152 ticksize=9, cblabel='')
156 ticksize=9, cblabel='')
153
157
154 title = "Phase %d%d" %(pair[0], pair[1])
158 title = "Phase %d%d" %(pair[0], pair[1])
155 axes0 = self.axesList[i*self.__nsubplots+3]
159 axes0 = self.axesList[i*self.__nsubplots+3]
156 axes0.pcolor(x, y, phase,
160 axes0.pcolor(x, y, phase,
157 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
161 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
158 xlabel=xlabel, ylabel=ylabel, title=title,
162 xlabel=xlabel, ylabel=ylabel, title=title,
159 ticksize=9, cblabel='', colormap='RdBu_r')
163 ticksize=9, cblabel='', colormap='RdBu_r')
160
164
161
165
162
166
163 self.draw()
167 self.draw()
164
168
165 if save:
169 if save:
166 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
170 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
167 if figfile == None:
171 if figfile == None:
168 figfile = self.getFilename(name = date)
172 figfile = self.getFilename(name = date)
169
173
170 self.saveFigure(figpath, figfile)
174 self.saveFigure(figpath, figfile)
171
175
172
176
173 class RTIPlot(Figure):
177 class RTIPlot(Figure):
174
178
175 __isConfig = None
179 __isConfig = None
176 __nsubplots = None
180 __nsubplots = None
177
181
178 WIDTHPROF = None
182 WIDTHPROF = None
179 HEIGHTPROF = None
183 HEIGHTPROF = None
180 PREFIX = 'rti'
184 PREFIX = 'rti'
181
185
182 def __init__(self):
186 def __init__(self):
183
187
184 self.timerange = 2*60*60
188 self.timerange = 2*60*60
185 self.__isConfig = False
189 self.__isConfig = False
186 self.__nsubplots = 1
190 self.__nsubplots = 1
187
191
188 self.WIDTH = 800
192 self.WIDTH = 800
189 self.HEIGHT = 200
193 self.HEIGHT = 200
190 self.WIDTHPROF = 120
194 self.WIDTHPROF = 120
191 self.HEIGHTPROF = 0
195 self.HEIGHTPROF = 0
192
196
193 def getSubplots(self):
197 def getSubplots(self):
194
198
195 ncol = 1
199 ncol = 1
196 nrow = self.nplots
200 nrow = self.nplots
197
201
198 return nrow, ncol
202 return nrow, ncol
199
203
200 def setup(self, idfigure, nplots, wintitle, showprofile=True):
204 def setup(self, idfigure, nplots, wintitle, showprofile=True):
201
205
202 self.__showprofile = showprofile
206 self.__showprofile = showprofile
203 self.nplots = nplots
207 self.nplots = nplots
204
208
205 ncolspan = 1
209 ncolspan = 1
206 colspan = 1
210 colspan = 1
207 if showprofile:
211 if showprofile:
208 ncolspan = 7
212 ncolspan = 7
209 colspan = 6
213 colspan = 6
210 self.__nsubplots = 2
214 self.__nsubplots = 2
211
215
212 self.createFigure(idfigure = idfigure,
216 self.createFigure(idfigure = idfigure,
213 wintitle = wintitle,
217 wintitle = wintitle,
214 widthplot = self.WIDTH + self.WIDTHPROF,
218 widthplot = self.WIDTH + self.WIDTHPROF,
215 heightplot = self.HEIGHT + self.HEIGHTPROF)
219 heightplot = self.HEIGHT + self.HEIGHTPROF)
216
220
217 nrow, ncol = self.getSubplots()
221 nrow, ncol = self.getSubplots()
218
222
219 counter = 0
223 counter = 0
220 for y in range(nrow):
224 for y in range(nrow):
221 for x in range(ncol):
225 for x in range(ncol):
222
226
223 if counter >= self.nplots:
227 if counter >= self.nplots:
224 break
228 break
225
229
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
230 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
227
231
228 if showprofile:
232 if showprofile:
229 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
233 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
230
234
231 counter += 1
235 counter += 1
232
236
233 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
237 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
234 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
238 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
235 timerange=None,
239 timerange=None,
236 save=False, figpath='./', figfile=None):
240 save=False, figpath='./', figfile=None):
237
241
238 """
242 """
239
243
240 Input:
244 Input:
241 dataOut :
245 dataOut :
242 idfigure :
246 idfigure :
243 wintitle :
247 wintitle :
244 channelList :
248 channelList :
245 showProfile :
249 showProfile :
246 xmin : None,
250 xmin : None,
247 xmax : None,
251 xmax : None,
248 ymin : None,
252 ymin : None,
249 ymax : None,
253 ymax : None,
250 zmin : None,
254 zmin : None,
251 zmax : None
255 zmax : None
252 """
256 """
253
257
254 if channelList == None:
258 if channelList == None:
255 channelIndexList = dataOut.channelIndexList
259 channelIndexList = dataOut.channelIndexList
256 else:
260 else:
257 channelIndexList = []
261 channelIndexList = []
258 for channel in channelList:
262 for channel in channelList:
259 if channel not in dataOut.channelList:
263 if channel not in dataOut.channelList:
260 raise ValueError, "Channel %d is not in dataOut.channelList"
264 raise ValueError, "Channel %d is not in dataOut.channelList"
261 channelIndexList.append(dataOut.channelList.index(channel))
265 channelIndexList.append(dataOut.channelList.index(channel))
262
266
263 if timerange != None:
267 if timerange != None:
264 self.timerange = timerange
268 self.timerange = timerange
265
269
266 tmin = None
270 tmin = None
267 tmax = None
271 tmax = None
272 factor = dataOut.normFactor
268 x = dataOut.getTimeRange()
273 x = dataOut.getTimeRange()
269 y = dataOut.getHeiRange()
274 y = dataOut.getHeiRange()
270 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
275
276 z = dataOut.data_spc[channelIndexList,:,:]/factor
271 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
277 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
272 avg = numpy.average(z, axis=1)
278 avg = numpy.average(z, axis=1)
279 noise = dataOut.getNoise()/factor
273
280
274 noise = dataOut.getNoise()
281 # zdB = 10.*numpy.log10(z)
282 avgdB = 10.*numpy.log10(avg)
283 noisedB = 10.*numpy.log10(noise)
275
284
276 thisDatetime = dataOut.datatime
285 thisDatetime = dataOut.datatime
277 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
286 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
278 xlabel = "Velocity (m/s)"
287 xlabel = "Velocity (m/s)"
279 ylabel = "Range (Km)"
288 ylabel = "Range (Km)"
280
289
281 if not self.__isConfig:
290 if not self.__isConfig:
282
291
283 nplots = len(channelIndexList)
292 nplots = len(channelIndexList)
284
293
285 self.setup(idfigure=idfigure,
294 self.setup(idfigure=idfigure,
286 nplots=nplots,
295 nplots=nplots,
287 wintitle=wintitle,
296 wintitle=wintitle,
288 showprofile=showprofile)
297 showprofile=showprofile)
289
298
290 tmin, tmax = self.getTimeLim(x, xmin, xmax)
299 tmin, tmax = self.getTimeLim(x, xmin, xmax)
291 if ymin == None: ymin = numpy.nanmin(y)
300 if ymin == None: ymin = numpy.nanmin(y)
292 if ymax == None: ymax = numpy.nanmax(y)
301 if ymax == None: ymax = numpy.nanmax(y)
293 if zmin == None: zmin = numpy.nanmin(avg)*0.9
302 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
294 if zmax == None: zmax = numpy.nanmax(avg)*0.9
303 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
295
304
296 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
305 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
297 self.__isConfig = True
306 self.__isConfig = True
298
307
299
308
300 self.setWinTitle(title)
309 self.setWinTitle(title)
301
310
302 for i in range(self.nplots):
311 for i in range(self.nplots):
303 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
312 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
304 axes = self.axesList[i*self.__nsubplots]
313 axes = self.axesList[i*self.__nsubplots]
305 z = avg[i].reshape((1,-1))
314 zdB = avgdB[i].reshape((1,-1))
306 axes.pcolor(x, y, z,
315 axes.pcolor(x, y, zdB,
307 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
316 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
308 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
317 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
309 ticksize=9, cblabel='', cbsize="1%")
318 ticksize=9, cblabel='', cbsize="1%")
310
319
311 if self.__showprofile:
320 if self.__showprofile:
312 axes = self.axesList[i*self.__nsubplots +1]
321 axes = self.axesList[i*self.__nsubplots +1]
313 axes.pline(avg[i], y,
322 axes.pline(avgdB[i], y,
314 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
323 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
315 xlabel='dB', ylabel='', title='',
324 xlabel='dB', ylabel='', title='',
316 ytick_visible=False,
325 ytick_visible=False,
317 grid='x')
326 grid='x')
318
327
319 self.draw()
328 self.draw()
320
329
321 if save:
330 if save:
322
331
323 if figfile == None:
332 if figfile == None:
324 figfile = self.getFilename(name = self.name)
333 figfile = self.getFilename(name = self.name)
325
334
326 self.saveFigure(figpath, figfile)
335 self.saveFigure(figpath, figfile)
327
336
328 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
337 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
329 self.__isConfig = False
338 self.__isConfig = False
330
339
331 class SpectraPlot(Figure):
340 class SpectraPlot(Figure):
332
341
333 __isConfig = None
342 __isConfig = None
334 __nsubplots = None
343 __nsubplots = None
335
344
336 WIDTHPROF = None
345 WIDTHPROF = None
337 HEIGHTPROF = None
346 HEIGHTPROF = None
338 PREFIX = 'spc'
347 PREFIX = 'spc'
339
348
340 def __init__(self):
349 def __init__(self):
341
350
342 self.__isConfig = False
351 self.__isConfig = False
343 self.__nsubplots = 1
352 self.__nsubplots = 1
344
353
345 self.WIDTH = 230
354 self.WIDTH = 230
346 self.HEIGHT = 250
355 self.HEIGHT = 250
347 self.WIDTHPROF = 120
356 self.WIDTHPROF = 120
348 self.HEIGHTPROF = 0
357 self.HEIGHTPROF = 0
349
358
350 def getSubplots(self):
359 def getSubplots(self):
351
360
352 ncol = int(numpy.sqrt(self.nplots)+0.9)
361 ncol = int(numpy.sqrt(self.nplots)+0.9)
353 nrow = int(self.nplots*1./ncol + 0.9)
362 nrow = int(self.nplots*1./ncol + 0.9)
354
363
355 return nrow, ncol
364 return nrow, ncol
356
365
357 def setup(self, idfigure, nplots, wintitle, showprofile=True):
366 def setup(self, idfigure, nplots, wintitle, showprofile=True):
358
367
359 self.__showprofile = showprofile
368 self.__showprofile = showprofile
360 self.nplots = nplots
369 self.nplots = nplots
361
370
362 ncolspan = 1
371 ncolspan = 1
363 colspan = 1
372 colspan = 1
364 if showprofile:
373 if showprofile:
365 ncolspan = 3
374 ncolspan = 3
366 colspan = 2
375 colspan = 2
367 self.__nsubplots = 2
376 self.__nsubplots = 2
368
377
369 self.createFigure(idfigure = idfigure,
378 self.createFigure(idfigure = idfigure,
370 wintitle = wintitle,
379 wintitle = wintitle,
371 widthplot = self.WIDTH + self.WIDTHPROF,
380 widthplot = self.WIDTH + self.WIDTHPROF,
372 heightplot = self.HEIGHT + self.HEIGHTPROF)
381 heightplot = self.HEIGHT + self.HEIGHTPROF)
373
382
374 nrow, ncol = self.getSubplots()
383 nrow, ncol = self.getSubplots()
375
384
376 counter = 0
385 counter = 0
377 for y in range(nrow):
386 for y in range(nrow):
378 for x in range(ncol):
387 for x in range(ncol):
379
388
380 if counter >= self.nplots:
389 if counter >= self.nplots:
381 break
390 break
382
391
383 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
392 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
384
393
385 if showprofile:
394 if showprofile:
386 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
395 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
387
396
388 counter += 1
397 counter += 1
389
398
390 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
399 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
391 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
400 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
392 save=False, figpath='./', figfile=None):
401 save=False, figpath='./', figfile=None):
393
402
394 """
403 """
395
404
396 Input:
405 Input:
397 dataOut :
406 dataOut :
398 idfigure :
407 idfigure :
399 wintitle :
408 wintitle :
400 channelList :
409 channelList :
401 showProfile :
410 showProfile :
402 xmin : None,
411 xmin : None,
403 xmax : None,
412 xmax : None,
404 ymin : None,
413 ymin : None,
405 ymax : None,
414 ymax : None,
406 zmin : None,
415 zmin : None,
407 zmax : None
416 zmax : None
408 """
417 """
409
418
410 if channelList == None:
419 if channelList == None:
411 channelIndexList = dataOut.channelIndexList
420 channelIndexList = dataOut.channelIndexList
412 else:
421 else:
413 channelIndexList = []
422 channelIndexList = []
414 for channel in channelList:
423 for channel in channelList:
415 if channel not in dataOut.channelList:
424 if channel not in dataOut.channelList:
416 raise ValueError, "Channel %d is not in dataOut.channelList"
425 raise ValueError, "Channel %d is not in dataOut.channelList"
417 channelIndexList.append(dataOut.channelList.index(channel))
426 channelIndexList.append(dataOut.channelList.index(channel))
418
427 factor = dataOut.normFactor
419 x = dataOut.getVelRange(1)
428 x = dataOut.getVelRange(1)
420 y = dataOut.getHeiRange()
429 y = dataOut.getHeiRange()
421
430
422 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
431 z = dataOut.data_spc[channelIndexList,:,:]/factor
423 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
432 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
424 avg = numpy.average(z, axis=1)
433 avg = numpy.average(z, axis=1)
434 noise = dataOut.getNoise()/factor
425
435
426 noise = dataOut.getNoise()
436 zdB = 10*numpy.log10(z)
437 avgdB = 10*numpy.log10(avg)
438 noisedB = 10*numpy.log10(noise)
427
439
428 thisDatetime = dataOut.datatime
440 thisDatetime = dataOut.datatime
429 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
441 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
430 xlabel = "Velocity (m/s)"
442 xlabel = "Velocity (m/s)"
431 ylabel = "Range (Km)"
443 ylabel = "Range (Km)"
432
444
433 if not self.__isConfig:
445 if not self.__isConfig:
434
446
435 nplots = len(channelIndexList)
447 nplots = len(channelIndexList)
436
448
437 self.setup(idfigure=idfigure,
449 self.setup(idfigure=idfigure,
438 nplots=nplots,
450 nplots=nplots,
439 wintitle=wintitle,
451 wintitle=wintitle,
440 showprofile=showprofile)
452 showprofile=showprofile)
441
453
442 if xmin == None: xmin = numpy.nanmin(x)
454 if xmin == None: xmin = numpy.nanmin(x)
443 if xmax == None: xmax = numpy.nanmax(x)
455 if xmax == None: xmax = numpy.nanmax(x)
444 if ymin == None: ymin = numpy.nanmin(y)
456 if ymin == None: ymin = numpy.nanmin(y)
445 if ymax == None: ymax = numpy.nanmax(y)
457 if ymax == None: ymax = numpy.nanmax(y)
446 if zmin == None: zmin = numpy.nanmin(avg)*0.9
458 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
447 if zmax == None: zmax = numpy.nanmax(avg)*0.9
459 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
448
460
449 self.__isConfig = True
461 self.__isConfig = True
450
462
451 self.setWinTitle(title)
463 self.setWinTitle(title)
452
464
453 for i in range(self.nplots):
465 for i in range(self.nplots):
454 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
466 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
455 axes = self.axesList[i*self.__nsubplots]
467 axes = self.axesList[i*self.__nsubplots]
456 axes.pcolor(x, y, z[i,:,:],
468 axes.pcolor(x, y, zdB[i,:,:],
457 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
469 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
458 xlabel=xlabel, ylabel=ylabel, title=title,
470 xlabel=xlabel, ylabel=ylabel, title=title,
459 ticksize=9, cblabel='')
471 ticksize=9, cblabel='')
460
472
461 if self.__showprofile:
473 if self.__showprofile:
462 axes = self.axesList[i*self.__nsubplots +1]
474 axes = self.axesList[i*self.__nsubplots +1]
463 axes.pline(avg[i], y,
475 axes.pline(avgdB[i], y,
464 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
476 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
465 xlabel='dB', ylabel='', title='',
477 xlabel='dB', ylabel='', title='',
466 ytick_visible=False,
478 ytick_visible=False,
467 grid='x')
479 grid='x')
468
480
469 noiseline = numpy.repeat(noise[i], len(y))
481 noiseline = numpy.repeat(noisedB[i], len(y))
470 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
482 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
471
483
472 self.draw()
484 self.draw()
473
485
474 if save:
486 if save:
475 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
487 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
476 if figfile == None:
488 if figfile == None:
477 figfile = self.getFilename(name = date)
489 figfile = self.getFilename(name = date)
478
490
479 self.saveFigure(figpath, figfile)
491 self.saveFigure(figpath, figfile)
480
492
481 class Scope(Figure):
493 class Scope(Figure):
482
494
483 __isConfig = None
495 __isConfig = None
484
496
485 def __init__(self):
497 def __init__(self):
486
498
487 self.__isConfig = False
499 self.__isConfig = False
488 self.WIDTH = 600
500 self.WIDTH = 600
489 self.HEIGHT = 200
501 self.HEIGHT = 200
490
502
491 def getSubplots(self):
503 def getSubplots(self):
492
504
493 nrow = self.nplots
505 nrow = self.nplots
494 ncol = 3
506 ncol = 3
495 return nrow, ncol
507 return nrow, ncol
496
508
497 def setup(self, idfigure, nplots, wintitle):
509 def setup(self, idfigure, nplots, wintitle):
498
510
499 self.nplots = nplots
511 self.nplots = nplots
500
512
501 self.createFigure(idfigure, wintitle)
513 self.createFigure(idfigure, wintitle)
502
514
503 nrow,ncol = self.getSubplots()
515 nrow,ncol = self.getSubplots()
504 colspan = 3
516 colspan = 3
505 rowspan = 1
517 rowspan = 1
506
518
507 for i in range(nplots):
519 for i in range(nplots):
508 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
520 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
509
521
510
522
511
523
512 def run(self, dataOut, idfigure, wintitle="", channelList=None,
524 def run(self, dataOut, idfigure, wintitle="", channelList=None,
513 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
525 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
514 figpath='./', figfile=None):
526 figpath='./', figfile=None):
515
527
516 """
528 """
517
529
518 Input:
530 Input:
519 dataOut :
531 dataOut :
520 idfigure :
532 idfigure :
521 wintitle :
533 wintitle :
522 channelList :
534 channelList :
523 xmin : None,
535 xmin : None,
524 xmax : None,
536 xmax : None,
525 ymin : None,
537 ymin : None,
526 ymax : None,
538 ymax : None,
527 """
539 """
528
540
529 if channelList == None:
541 if channelList == None:
530 channelIndexList = dataOut.channelIndexList
542 channelIndexList = dataOut.channelIndexList
531 else:
543 else:
532 channelIndexList = []
544 channelIndexList = []
533 for channel in channelList:
545 for channel in channelList:
534 if channel not in dataOut.channelList:
546 if channel not in dataOut.channelList:
535 raise ValueError, "Channel %d is not in dataOut.channelList"
547 raise ValueError, "Channel %d is not in dataOut.channelList"
536 channelIndexList.append(dataOut.channelList.index(channel))
548 channelIndexList.append(dataOut.channelList.index(channel))
537
549
538 x = dataOut.heightList
550 x = dataOut.heightList
539 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
551 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
540 y = y.real
552 y = y.real
541
553
542 thisDatetime = dataOut.datatime
554 thisDatetime = dataOut.datatime
543 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
555 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
544 xlabel = "Range (Km)"
556 xlabel = "Range (Km)"
545 ylabel = "Intensity"
557 ylabel = "Intensity"
546
558
547 if not self.__isConfig:
559 if not self.__isConfig:
548 nplots = len(channelIndexList)
560 nplots = len(channelIndexList)
549
561
550 self.setup(idfigure=idfigure,
562 self.setup(idfigure=idfigure,
551 nplots=nplots,
563 nplots=nplots,
552 wintitle=wintitle)
564 wintitle=wintitle)
553
565
554 if xmin == None: xmin = numpy.nanmin(x)
566 if xmin == None: xmin = numpy.nanmin(x)
555 if xmax == None: xmax = numpy.nanmax(x)
567 if xmax == None: xmax = numpy.nanmax(x)
556 if ymin == None: ymin = numpy.nanmin(y)
568 if ymin == None: ymin = numpy.nanmin(y)
557 if ymax == None: ymax = numpy.nanmax(y)
569 if ymax == None: ymax = numpy.nanmax(y)
558
570
559 self.__isConfig = True
571 self.__isConfig = True
560
572
561 self.setWinTitle(title)
573 self.setWinTitle(title)
562
574
563 for i in range(len(self.axesList)):
575 for i in range(len(self.axesList)):
564 title = "Channel %d" %(i)
576 title = "Channel %d" %(i)
565 axes = self.axesList[i]
577 axes = self.axesList[i]
566 ychannel = y[i,:]
578 ychannel = y[i,:]
567 axes.pline(x, ychannel,
579 axes.pline(x, ychannel,
568 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
580 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
569 xlabel=xlabel, ylabel=ylabel, title=title)
581 xlabel=xlabel, ylabel=ylabel, title=title)
570
582
571 self.draw()
583 self.draw()
572
584
573 if save:
585 if save:
574 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
586 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
575 if figfile == None:
587 if figfile == None:
576 figfile = self.getFilename(name = date)
588 figfile = self.getFilename(name = date)
577
589
578 self.saveFigure(figpath, figfile)
590 self.saveFigure(figpath, figfile)
579
591
580 class ProfilePlot(Figure):
592 class ProfilePlot(Figure):
581 __isConfig = None
593 __isConfig = None
582 __nsubplots = None
594 __nsubplots = None
583
595
584 WIDTHPROF = None
596 WIDTHPROF = None
585 HEIGHTPROF = None
597 HEIGHTPROF = None
586 PREFIX = 'spcprofile'
598 PREFIX = 'spcprofile'
587
599
588 def __init__(self):
600 def __init__(self):
589 self.__isConfig = False
601 self.__isConfig = False
590 self.__nsubplots = 1
602 self.__nsubplots = 1
591
603
592 self.WIDTH = 300
604 self.WIDTH = 300
593 self.HEIGHT = 500
605 self.HEIGHT = 500
594
606
595 def getSubplots(self):
607 def getSubplots(self):
596 ncol = 1
608 ncol = 1
597 nrow = 1
609 nrow = 1
598
610
599 return nrow, ncol
611 return nrow, ncol
600
612
601 def setup(self, idfigure, nplots, wintitle):
613 def setup(self, idfigure, nplots, wintitle):
602
614
603 self.nplots = nplots
615 self.nplots = nplots
604
616
605 ncolspan = 1
617 ncolspan = 1
606 colspan = 1
618 colspan = 1
607
619
608 self.createFigure(idfigure = idfigure,
620 self.createFigure(idfigure = idfigure,
609 wintitle = wintitle,
621 wintitle = wintitle,
610 widthplot = self.WIDTH,
622 widthplot = self.WIDTH,
611 heightplot = self.HEIGHT)
623 heightplot = self.HEIGHT)
612
624
613 nrow, ncol = self.getSubplots()
625 nrow, ncol = self.getSubplots()
614
626
615 counter = 0
627 counter = 0
616 for y in range(nrow):
628 for y in range(nrow):
617 for x in range(ncol):
629 for x in range(ncol):
618 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
630 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
619
631
620 def run(self, dataOut, idfigure, wintitle="", channelList=None,
632 def run(self, dataOut, idfigure, wintitle="", channelList=None,
621 xmin=None, xmax=None, ymin=None, ymax=None,
633 xmin=None, xmax=None, ymin=None, ymax=None,
622 save=False, figpath='./', figfile=None):
634 save=False, figpath='./', figfile=None):
623
635
624 if channelList == None:
636 if channelList == None:
625 channelIndexList = dataOut.channelIndexList
637 channelIndexList = dataOut.channelIndexList
626 channelList = dataOut.channelList
638 channelList = dataOut.channelList
627 else:
639 else:
628 channelIndexList = []
640 channelIndexList = []
629 for channel in channelList:
641 for channel in channelList:
630 if channel not in dataOut.channelList:
642 if channel not in dataOut.channelList:
631 raise ValueError, "Channel %d is not in dataOut.channelList"
643 raise ValueError, "Channel %d is not in dataOut.channelList"
632 channelIndexList.append(dataOut.channelList.index(channel))
644 channelIndexList.append(dataOut.channelList.index(channel))
633
645
634
646 factor = dataOut.normFactor
635 y = dataOut.getHeiRange()
647 y = dataOut.getHeiRange()
636 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
648 x = dataOut.data_spc[channelIndexList,:,:]/factor
649 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
637 avg = numpy.average(x, axis=1)
650 avg = numpy.average(x, axis=1)
638
651
652 avgdB = 10*numpy.log10(avg)
653
639 thisDatetime = dataOut.datatime
654 thisDatetime = dataOut.datatime
640 title = "Power Profile"
655 title = "Power Profile"
641 xlabel = "dB"
656 xlabel = "dB"
642 ylabel = "Range (Km)"
657 ylabel = "Range (Km)"
643
658
644 if not self.__isConfig:
659 if not self.__isConfig:
645
660
646 nplots = 1
661 nplots = 1
647
662
648 self.setup(idfigure=idfigure,
663 self.setup(idfigure=idfigure,
649 nplots=nplots,
664 nplots=nplots,
650 wintitle=wintitle)
665 wintitle=wintitle)
651
666
652 if ymin == None: ymin = numpy.nanmin(y)
667 if ymin == None: ymin = numpy.nanmin(y)
653 if ymax == None: ymax = numpy.nanmax(y)
668 if ymax == None: ymax = numpy.nanmax(y)
654 if xmin == None: xmin = numpy.nanmin(avg)*0.9
669 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
655 if xmax == None: xmax = numpy.nanmax(avg)*0.9
670 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
656
671
657 self.__isConfig = True
672 self.__isConfig = True
658
673
659 self.setWinTitle(title)
674 self.setWinTitle(title)
660
675
661
676
662 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
677 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
663 axes = self.axesList[0]
678 axes = self.axesList[0]
664
679
665 legendlabels = ["channel %d"%x for x in channelList]
680 legendlabels = ["channel %d"%x for x in channelList]
666 axes.pmultiline(avg, y,
681 axes.pmultiline(avgdB, y,
667 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
682 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
668 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
683 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
669 ytick_visible=True, nxticks=5,
684 ytick_visible=True, nxticks=5,
670 grid='x')
685 grid='x')
671
686
672 self.draw()
687 self.draw()
673
688
674 if save:
689 if save:
675 date = thisDatetime.strftime("%Y%m%d")
690 date = thisDatetime.strftime("%Y%m%d")
676 if figfile == None:
691 if figfile == None:
677 figfile = self.getFilename(name = date)
692 figfile = self.getFilename(name = date)
678
693
679 self.saveFigure(figpath, figfile)
694 self.saveFigure(figpath, figfile)
680
695
681 class CoherenceMap(Figure):
696 class CoherenceMap(Figure):
682 __isConfig = None
697 __isConfig = None
683 __nsubplots = None
698 __nsubplots = None
684
699
685 WIDTHPROF = None
700 WIDTHPROF = None
686 HEIGHTPROF = None
701 HEIGHTPROF = None
687 PREFIX = 'coherencemap'
702 PREFIX = 'coherencemap'
688
703
689 def __init__(self):
704 def __init__(self):
690 self.timerange = 2*60*60
705 self.timerange = 2*60*60
691 self.__isConfig = False
706 self.__isConfig = False
692 self.__nsubplots = 1
707 self.__nsubplots = 1
693
708
694 self.WIDTH = 800
709 self.WIDTH = 800
695 self.HEIGHT = 200
710 self.HEIGHT = 200
696 self.WIDTHPROF = 120
711 self.WIDTHPROF = 120
697 self.HEIGHTPROF = 0
712 self.HEIGHTPROF = 0
698
713
699 def getSubplots(self):
714 def getSubplots(self):
700 ncol = 1
715 ncol = 1
701 nrow = self.nplots*2
716 nrow = self.nplots*2
702
717
703 return nrow, ncol
718 return nrow, ncol
704
719
705 def setup(self, idfigure, nplots, wintitle, showprofile=True):
720 def setup(self, idfigure, nplots, wintitle, showprofile=True):
706 self.__showprofile = showprofile
721 self.__showprofile = showprofile
707 self.nplots = nplots
722 self.nplots = nplots
708
723
709 ncolspan = 1
724 ncolspan = 1
710 colspan = 1
725 colspan = 1
711 if showprofile:
726 if showprofile:
712 ncolspan = 7
727 ncolspan = 7
713 colspan = 6
728 colspan = 6
714 self.__nsubplots = 2
729 self.__nsubplots = 2
715
730
716 self.createFigure(idfigure = idfigure,
731 self.createFigure(idfigure = idfigure,
717 wintitle = wintitle,
732 wintitle = wintitle,
718 widthplot = self.WIDTH + self.WIDTHPROF,
733 widthplot = self.WIDTH + self.WIDTHPROF,
719 heightplot = self.HEIGHT + self.HEIGHTPROF)
734 heightplot = self.HEIGHT + self.HEIGHTPROF)
720
735
721 nrow, ncol = self.getSubplots()
736 nrow, ncol = self.getSubplots()
722
737
723 for y in range(nrow):
738 for y in range(nrow):
724 for x in range(ncol):
739 for x in range(ncol):
725
740
726 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
741 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
727
742
728 if showprofile:
743 if showprofile:
729 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
744 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
730
745
731 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
746 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
732 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
747 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
733 timerange=None,
748 timerange=None,
734 save=False, figpath='./', figfile=None):
749 save=False, figpath='./', figfile=None):
735
750
736 if pairsList == None:
751 if pairsList == None:
737 pairsIndexList = dataOut.pairsIndexList
752 pairsIndexList = dataOut.pairsIndexList
738 else:
753 else:
739 pairsIndexList = []
754 pairsIndexList = []
740 for pair in pairsList:
755 for pair in pairsList:
741 if pair not in dataOut.pairsList:
756 if pair not in dataOut.pairsList:
742 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
757 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
743 pairsIndexList.append(dataOut.pairsList.index(pair))
758 pairsIndexList.append(dataOut.pairsList.index(pair))
744
759
745 if timerange != None:
760 if timerange != None:
746 self.timerange = timerange
761 self.timerange = timerange
747
762
748 if pairsIndexList == []:
763 if pairsIndexList == []:
749 return
764 return
750
765
751 if len(pairsIndexList) > 4:
766 if len(pairsIndexList) > 4:
752 pairsIndexList = pairsIndexList[0:4]
767 pairsIndexList = pairsIndexList[0:4]
753
768
754 tmin = None
769 tmin = None
755 tmax = None
770 tmax = None
756 x = dataOut.getTimeRange()
771 x = dataOut.getTimeRange()
757 y = dataOut.getHeiRange()
772 y = dataOut.getHeiRange()
758
773
759 thisDatetime = dataOut.datatime
774 thisDatetime = dataOut.datatime
760 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
775 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
761 xlabel = ""
776 xlabel = ""
762 ylabel = "Range (Km)"
777 ylabel = "Range (Km)"
763
778
764 if not self.__isConfig:
779 if not self.__isConfig:
765 nplots = len(pairsIndexList)
780 nplots = len(pairsIndexList)
766 self.setup(idfigure=idfigure,
781 self.setup(idfigure=idfigure,
767 nplots=nplots,
782 nplots=nplots,
768 wintitle=wintitle,
783 wintitle=wintitle,
769 showprofile=showprofile)
784 showprofile=showprofile)
770
785
771 tmin, tmax = self.getTimeLim(x, xmin, xmax)
786 tmin, tmax = self.getTimeLim(x, xmin, xmax)
772 if ymin == None: ymin = numpy.nanmin(y)
787 if ymin == None: ymin = numpy.nanmin(y)
773 if ymax == None: ymax = numpy.nanmax(y)
788 if ymax == None: ymax = numpy.nanmax(y)
774
789
775 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
790 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
776
791
777 self.__isConfig = True
792 self.__isConfig = True
778
793
779 self.setWinTitle(title)
794 self.setWinTitle(title)
780
795
781 for i in range(self.nplots):
796 for i in range(self.nplots):
782
797
783 pair = dataOut.pairsList[pairsIndexList[i]]
798 pair = dataOut.pairsList[pairsIndexList[i]]
784 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
799 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
785 coherence = numpy.abs(coherenceComplex)
800 coherence = numpy.abs(coherenceComplex)
786 avg = numpy.average(coherence, axis=0)
801 avg = numpy.average(coherence, axis=0)
787 z = avg.reshape((1,-1))
802 z = avg.reshape((1,-1))
788
803
789 counter = 0
804 counter = 0
790
805
791 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
806 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
792 axes = self.axesList[i*self.__nsubplots*2]
807 axes = self.axesList[i*self.__nsubplots*2]
793 axes.pcolor(x, y, z,
808 axes.pcolor(x, y, z,
794 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
809 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
795 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
810 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
796 ticksize=9, cblabel='', cbsize="1%")
811 ticksize=9, cblabel='', cbsize="1%")
797
812
798 if self.__showprofile:
813 if self.__showprofile:
799 counter += 1
814 counter += 1
800 axes = self.axesList[i*self.__nsubplots*2 + counter]
815 axes = self.axesList[i*self.__nsubplots*2 + counter]
801 axes.pline(avg, y,
816 axes.pline(avg, y,
802 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
817 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
803 xlabel='', ylabel='', title='', ticksize=7,
818 xlabel='', ylabel='', title='', ticksize=7,
804 ytick_visible=False, nxticks=5,
819 ytick_visible=False, nxticks=5,
805 grid='x')
820 grid='x')
806
821
807 counter += 1
822 counter += 1
808 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
823 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
809 avg = numpy.average(phase, axis=0)
824 avg = numpy.average(phase, axis=0)
810 z = avg.reshape((1,-1))
825 z = avg.reshape((1,-1))
811
826
812 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
827 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
813 axes = self.axesList[i*self.__nsubplots*2 + counter]
828 axes = self.axesList[i*self.__nsubplots*2 + counter]
814 axes.pcolor(x, y, z,
829 axes.pcolor(x, y, z,
815 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
830 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
816 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
831 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
817 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
832 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
818
833
819 if self.__showprofile:
834 if self.__showprofile:
820 counter += 1
835 counter += 1
821 axes = self.axesList[i*self.__nsubplots*2 + counter]
836 axes = self.axesList[i*self.__nsubplots*2 + counter]
822 axes.pline(avg, y,
837 axes.pline(avg, y,
823 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
838 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
824 xlabel='', ylabel='', title='', ticksize=7,
839 xlabel='', ylabel='', title='', ticksize=7,
825 ytick_visible=False, nxticks=4,
840 ytick_visible=False, nxticks=4,
826 grid='x')
841 grid='x')
827
842
828 self.draw()
843 self.draw()
829
844
830 if save:
845 if save:
831
846
832 if figfile == None:
847 if figfile == None:
833 figfile = self.getFilename(name = self.name)
848 figfile = self.getFilename(name = self.name)
834
849
835 self.saveFigure(figpath, figfile)
850 self.saveFigure(figpath, figfile)
836
851
837 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
852 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
838 self.__isConfig = False
853 self.__isConfig = False
839
854
840 class RTIfromNoise(Figure):
855 class RTIfromNoise(Figure):
841
856
842 __isConfig = None
857 __isConfig = None
843 __nsubplots = None
858 __nsubplots = None
844
859
845 PREFIX = 'rtinoise'
860 PREFIX = 'rtinoise'
846
861
847 def __init__(self):
862 def __init__(self):
848
863
849 self.timerange = 24*60*60
864 self.timerange = 24*60*60
850 self.__isConfig = False
865 self.__isConfig = False
851 self.__nsubplots = 1
866 self.__nsubplots = 1
852
867
853 self.WIDTH = 820
868 self.WIDTH = 820
854 self.HEIGHT = 200
869 self.HEIGHT = 200
870 self.WIDTHPROF = 120
871 self.HEIGHTPROF = 0
872 self.xdata = None
873 self.ydata = None
855
874
856 def getSubplots(self):
875 def getSubplots(self):
857
876
858 ncol = 1
877 ncol = 1
859 nrow = 1
878 nrow = 1
860
879
861 return nrow, ncol
880 return nrow, ncol
862
881
863 def setup(self, idfigure, nplots, wintitle, showprofile=True):
882 def setup(self, idfigure, nplots, wintitle, showprofile=True):
864
883
865 self.__showprofile = showprofile
884 self.__showprofile = showprofile
866 self.nplots = nplots
885 self.nplots = nplots
867
886
868 ncolspan = 1
887 ncolspan = 7
869 colspan = 1
888 colspan = 6
889 self.__nsubplots = 2
870
890
871 self.createFigure(idfigure = idfigure,
891 self.createFigure(idfigure = idfigure,
872 wintitle = wintitle,
892 wintitle = wintitle,
873 widthplot = self.WIDTH,
893 widthplot = self.WIDTH+self.WIDTHPROF,
874 heightplot = self.HEIGHT)
894 heightplot = self.HEIGHT+self.HEIGHTPROF)
875
895
876 nrow, ncol = self.getSubplots()
896 nrow, ncol = self.getSubplots()
877
897
878 self.addAxes(nrow, ncol, 0, 0, 1, 1)
898 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
899
879
900
880 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
901 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
881 xmin=None, xmax=None, ymin=None, ymax=None,
902 xmin=None, xmax=None, ymin=None, ymax=None,
882 timerange=None,
903 timerange=None,
883 save=False, figpath='./', figfile=None):
904 save=False, figpath='./', figfile=None):
884
905
885 if channelList == None:
906 if channelList == None:
886 channelIndexList = dataOut.channelIndexList
907 channelIndexList = dataOut.channelIndexList
887 channelList = dataOut.channelList
908 channelList = dataOut.channelList
888 else:
909 else:
889 channelIndexList = []
910 channelIndexList = []
890 for channel in channelList:
911 for channel in channelList:
891 if channel not in dataOut.channelList:
912 if channel not in dataOut.channelList:
892 raise ValueError, "Channel %d is not in dataOut.channelList"
913 raise ValueError, "Channel %d is not in dataOut.channelList"
893 channelIndexList.append(dataOut.channelList.index(channel))
914 channelIndexList.append(dataOut.channelList.index(channel))
894
915
895 if timerange != None:
916 if timerange != None:
896 self.timerange = timerange
917 self.timerange = timerange
897
918
898 tmin = None
919 tmin = None
899 tmax = None
920 tmax = None
900 x = dataOut.getTimeRange()
921 x = dataOut.getTimeRange()
901 y = dataOut.getHeiRange()
922 y = dataOut.getHeiRange()
902
923 factor = dataOut.normFactor
903 noise = dataOut.getNoise()
924 noise = dataOut.getNoise()/factor
925 noisedB = 10*numpy.log10(noise)
904
926
905 thisDatetime = dataOut.datatime
927 thisDatetime = dataOut.datatime
906 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
928 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
907 xlabel = "Velocity (m/s)"
929 xlabel = ""
908 ylabel = "Range (Km)"
930 ylabel = "Range (Km)"
909
931
910 if not self.__isConfig:
932 if not self.__isConfig:
911
933
912 nplots = 1
934 nplots = 1
913
935
914 self.setup(idfigure=idfigure,
936 self.setup(idfigure=idfigure,
915 nplots=nplots,
937 nplots=nplots,
916 wintitle=wintitle,
938 wintitle=wintitle,
917 showprofile=showprofile)
939 showprofile=showprofile)
918
940
919 tmin, tmax = self.getTimeLim(x, xmin, xmax)
941 tmin, tmax = self.getTimeLim(x, xmin, xmax)
920 if ymin == None: ymin = numpy.nanmin(noise)
942 if ymin == None: ymin = numpy.nanmin(noisedB)
921 if ymax == None: ymax = numpy.nanmax(noise)
943 if ymax == None: ymax = numpy.nanmax(noisedB)
922
944
923 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
945 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
924 self.__isConfig = True
946 self.__isConfig = True
925
947
948 self.xdata = numpy.array([])
949 self.ydata = numpy.array([])
926
950
927 self.setWinTitle(title)
951 self.setWinTitle(title)
928
952
929
953
930 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
954 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
931
955
932 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
956 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
933 axes = self.axesList[0]
957 axes = self.axesList[0]
934 xdata = x[0:1]
958
935 ydata = noise[channelIndexList].reshape(-1,1)
959 self.xdata = numpy.hstack((self.xdata, x[0:1]))
936 axes.pmultilineyaxis(x=xdata, y=ydata,
960
961 if len(self.ydata)==0:
962 self.ydata = noisedB[channelIndexList].reshape(-1,1)
963 else:
964 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
965
966
967 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
937 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
968 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
938 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
969 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
939 XAxisAsTime=True
970 XAxisAsTime=True
940 )
971 )
941
972
942
943 self.draw()
973 self.draw()
944
974
945 if save:
975 if save:
946
976
947 if figfile == None:
977 if figfile == None:
948 figfile = self.getFilename(name = self.name)
978 figfile = self.getFilename(name = self.name)
949
979
950 self.saveFigure(figpath, figfile)
980 self.saveFigure(figpath, figfile)
951
981
952 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
982 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
953 self.__isConfig = False
983 self.__isConfig = False
984 del self.xdata
985 del self.ydata
954 No newline at end of file
986
@@ -1,1157 +1,1159
1 '''
1 '''
2
2
3 $Author: dsuarez $
3 $Author: dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 '''
5 '''
6 import os
6 import os
7 import numpy
7 import numpy
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 from jrodata import *
11 from jrodata import *
12 from jrodataIO import *
12 from jrodataIO import *
13 from jroplot import *
13 from jroplot import *
14
14
15 class ProcessingUnit:
15 class ProcessingUnit:
16
16
17 """
17 """
18 Esta es la clase base para el procesamiento de datos.
18 Esta es la clase base para el procesamiento de datos.
19
19
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
21 - Metodos internos (callMethod)
21 - Metodos internos (callMethod)
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
23 tienen que ser agreagados con el metodo "add".
23 tienen que ser agreagados con el metodo "add".
24
24
25 """
25 """
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
27 dataIn = None
27 dataIn = None
28
28
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
30 dataOut = None
30 dataOut = None
31
31
32
32
33 objectDict = None
33 objectDict = None
34
34
35 def __init__(self):
35 def __init__(self):
36
36
37 self.objectDict = {}
37 self.objectDict = {}
38
38
39 def init(self):
39 def init(self):
40
40
41 raise ValueError, "Not implemented"
41 raise ValueError, "Not implemented"
42
42
43 def addOperation(self, object, objId):
43 def addOperation(self, object, objId):
44
44
45 """
45 """
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
47 identificador asociado a este objeto.
47 identificador asociado a este objeto.
48
48
49 Input:
49 Input:
50
50
51 object : objeto de la clase "Operation"
51 object : objeto de la clase "Operation"
52
52
53 Return:
53 Return:
54
54
55 objId : identificador del objeto, necesario para ejecutar la operacion
55 objId : identificador del objeto, necesario para ejecutar la operacion
56 """
56 """
57
57
58 self.objectDict[objId] = object
58 self.objectDict[objId] = object
59
59
60 return objId
60 return objId
61
61
62 def operation(self, **kwargs):
62 def operation(self, **kwargs):
63
63
64 """
64 """
65 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
65 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
66 atributos del objeto dataOut
66 atributos del objeto dataOut
67
67
68 Input:
68 Input:
69
69
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
71 """
71 """
72
72
73 raise ValueError, "ImplementedError"
73 raise ValueError, "ImplementedError"
74
74
75 def callMethod(self, name, **kwargs):
75 def callMethod(self, name, **kwargs):
76
76
77 """
77 """
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
79
79
80 Input:
80 Input:
81 name : nombre del metodo a ejecutar
81 name : nombre del metodo a ejecutar
82
82
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
84
84
85 """
85 """
86 if name != 'run':
86 if name != 'run':
87
87
88 if name == 'init' and self.dataIn.isEmpty():
88 if name == 'init' and self.dataIn.isEmpty():
89 self.dataOut.flagNoData = True
89 self.dataOut.flagNoData = True
90 return False
90 return False
91
91
92 if name != 'init' and self.dataOut.isEmpty():
92 if name != 'init' and self.dataOut.isEmpty():
93 return False
93 return False
94
94
95 methodToCall = getattr(self, name)
95 methodToCall = getattr(self, name)
96
96
97 methodToCall(**kwargs)
97 methodToCall(**kwargs)
98
98
99 if name != 'run':
99 if name != 'run':
100 return True
100 return True
101
101
102 if self.dataOut.isEmpty():
102 if self.dataOut.isEmpty():
103 return False
103 return False
104
104
105 return True
105 return True
106
106
107 def callObject(self, objId, **kwargs):
107 def callObject(self, objId, **kwargs):
108
108
109 """
109 """
110 Ejecuta la operacion asociada al identificador del objeto "objId"
110 Ejecuta la operacion asociada al identificador del objeto "objId"
111
111
112 Input:
112 Input:
113
113
114 objId : identificador del objeto a ejecutar
114 objId : identificador del objeto a ejecutar
115
115
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
117
117
118 Return:
118 Return:
119
119
120 None
120 None
121 """
121 """
122
122
123 if self.dataOut.isEmpty():
123 if self.dataOut.isEmpty():
124 return False
124 return False
125
125
126 object = self.objectDict[objId]
126 object = self.objectDict[objId]
127
127
128 object.run(self.dataOut, **kwargs)
128 object.run(self.dataOut, **kwargs)
129
129
130 return True
130 return True
131
131
132 def call(self, operationConf, **kwargs):
132 def call(self, operationConf, **kwargs):
133
133
134 """
134 """
135 Return True si ejecuta la operacion "operationConf.name" con los
135 Return True si ejecuta la operacion "operationConf.name" con los
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
137 La operacion puede ser de dos tipos:
137 La operacion puede ser de dos tipos:
138
138
139 1. Un metodo propio de esta clase:
139 1. Un metodo propio de esta clase:
140
140
141 operation.type = "self"
141 operation.type = "self"
142
142
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
144 operation.type = "other".
144 operation.type = "other".
145
145
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
147 "addOperation" e identificado con el operation.id
147 "addOperation" e identificado con el operation.id
148
148
149
149
150 con el id de la operacion.
150 con el id de la operacion.
151
151
152 Input:
152 Input:
153
153
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
155
155
156 """
156 """
157
157
158 if operationConf.type == 'self':
158 if operationConf.type == 'self':
159 sts = self.callMethod(operationConf.name, **kwargs)
159 sts = self.callMethod(operationConf.name, **kwargs)
160
160
161 if operationConf.type == 'other':
161 if operationConf.type == 'other':
162 sts = self.callObject(operationConf.id, **kwargs)
162 sts = self.callObject(operationConf.id, **kwargs)
163
163
164 return sts
164 return sts
165
165
166 def setInput(self, dataIn):
166 def setInput(self, dataIn):
167
167
168 self.dataIn = dataIn
168 self.dataIn = dataIn
169
169
170 def getOutput(self):
170 def getOutput(self):
171
171
172 return self.dataOut
172 return self.dataOut
173
173
174 class Operation():
174 class Operation():
175
175
176 """
176 """
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
179 acumulacion dentro de esta clase
179 acumulacion dentro de esta clase
180
180
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
182
182
183 """
183 """
184
184
185 __buffer = None
185 __buffer = None
186 __isConfig = False
186 __isConfig = False
187
187
188 def __init__(self):
188 def __init__(self):
189
189
190 pass
190 pass
191
191
192 def run(self, dataIn, **kwargs):
192 def run(self, dataIn, **kwargs):
193
193
194 """
194 """
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
196
196
197 Input:
197 Input:
198
198
199 dataIn : objeto del tipo JROData
199 dataIn : objeto del tipo JROData
200
200
201 Return:
201 Return:
202
202
203 None
203 None
204
204
205 Affected:
205 Affected:
206 __buffer : buffer de recepcion de datos.
206 __buffer : buffer de recepcion de datos.
207
207
208 """
208 """
209
209
210 raise ValueError, "ImplementedError"
210 raise ValueError, "ImplementedError"
211
211
212 class VoltageProc(ProcessingUnit):
212 class VoltageProc(ProcessingUnit):
213
213
214
214
215 def __init__(self):
215 def __init__(self):
216
216
217 self.objectDict = {}
217 self.objectDict = {}
218 self.dataOut = Voltage()
218 self.dataOut = Voltage()
219 self.flip = 1
219 self.flip = 1
220
220
221 def init(self):
221 def init(self):
222
222
223 self.dataOut.copy(self.dataIn)
223 self.dataOut.copy(self.dataIn)
224 # No necesita copiar en cada init() los atributos de dataIn
224 # No necesita copiar en cada init() los atributos de dataIn
225 # la copia deberia hacerse por cada nuevo bloque de datos
225 # la copia deberia hacerse por cada nuevo bloque de datos
226
226
227 def selectChannels(self, channelList):
227 def selectChannels(self, channelList):
228
228
229 channelIndexList = []
229 channelIndexList = []
230
230
231 for channel in channelList:
231 for channel in channelList:
232 index = self.dataOut.channelList.index(channel)
232 index = self.dataOut.channelList.index(channel)
233 channelIndexList.append(index)
233 channelIndexList.append(index)
234
234
235 self.selectChannelsByIndex(channelIndexList)
235 self.selectChannelsByIndex(channelIndexList)
236
236
237 def selectChannelsByIndex(self, channelIndexList):
237 def selectChannelsByIndex(self, channelIndexList):
238 """
238 """
239 Selecciona un bloque de datos en base a canales segun el channelIndexList
239 Selecciona un bloque de datos en base a canales segun el channelIndexList
240
240
241 Input:
241 Input:
242 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
242 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
243
243
244 Affected:
244 Affected:
245 self.dataOut.data
245 self.dataOut.data
246 self.dataOut.channelIndexList
246 self.dataOut.channelIndexList
247 self.dataOut.nChannels
247 self.dataOut.nChannels
248 self.dataOut.m_ProcessingHeader.totalSpectra
248 self.dataOut.m_ProcessingHeader.totalSpectra
249 self.dataOut.systemHeaderObj.numChannels
249 self.dataOut.systemHeaderObj.numChannels
250 self.dataOut.m_ProcessingHeader.blockSize
250 self.dataOut.m_ProcessingHeader.blockSize
251
251
252 Return:
252 Return:
253 None
253 None
254 """
254 """
255
255
256 for channelIndex in channelIndexList:
256 for channelIndex in channelIndexList:
257 if channelIndex not in self.dataOut.channelIndexList:
257 if channelIndex not in self.dataOut.channelIndexList:
258 print channelIndexList
258 print channelIndexList
259 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
259 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
260
260
261 nChannels = len(channelIndexList)
261 nChannels = len(channelIndexList)
262
262
263 data = self.dataOut.data[channelIndexList,:]
263 data = self.dataOut.data[channelIndexList,:]
264
264
265 self.dataOut.data = data
265 self.dataOut.data = data
266 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
266 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
267 # self.dataOut.nChannels = nChannels
267 # self.dataOut.nChannels = nChannels
268
268
269 return 1
269 return 1
270
270
271 def selectHeights(self, minHei, maxHei):
271 def selectHeights(self, minHei, maxHei):
272 """
272 """
273 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
273 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
274 minHei <= height <= maxHei
274 minHei <= height <= maxHei
275
275
276 Input:
276 Input:
277 minHei : valor minimo de altura a considerar
277 minHei : valor minimo de altura a considerar
278 maxHei : valor maximo de altura a considerar
278 maxHei : valor maximo de altura a considerar
279
279
280 Affected:
280 Affected:
281 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
281 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
282
282
283 Return:
283 Return:
284 1 si el metodo se ejecuto con exito caso contrario devuelve 0
284 1 si el metodo se ejecuto con exito caso contrario devuelve 0
285 """
285 """
286 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
286 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
287 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
287 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
288
288
289 if (maxHei > self.dataOut.heightList[-1]):
289 if (maxHei > self.dataOut.heightList[-1]):
290 maxHei = self.dataOut.heightList[-1]
290 maxHei = self.dataOut.heightList[-1]
291 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
291 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
292
292
293 minIndex = 0
293 minIndex = 0
294 maxIndex = 0
294 maxIndex = 0
295 heights = self.dataOut.heightList
295 heights = self.dataOut.heightList
296
296
297 inda = numpy.where(heights >= minHei)
297 inda = numpy.where(heights >= minHei)
298 indb = numpy.where(heights <= maxHei)
298 indb = numpy.where(heights <= maxHei)
299
299
300 try:
300 try:
301 minIndex = inda[0][0]
301 minIndex = inda[0][0]
302 except:
302 except:
303 minIndex = 0
303 minIndex = 0
304
304
305 try:
305 try:
306 maxIndex = indb[0][-1]
306 maxIndex = indb[0][-1]
307 except:
307 except:
308 maxIndex = len(heights)
308 maxIndex = len(heights)
309
309
310 self.selectHeightsByIndex(minIndex, maxIndex)
310 self.selectHeightsByIndex(minIndex, maxIndex)
311
311
312 return 1
312 return 1
313
313
314
314
315 def selectHeightsByIndex(self, minIndex, maxIndex):
315 def selectHeightsByIndex(self, minIndex, maxIndex):
316 """
316 """
317 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
317 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
318 minIndex <= index <= maxIndex
318 minIndex <= index <= maxIndex
319
319
320 Input:
320 Input:
321 minIndex : valor de indice minimo de altura a considerar
321 minIndex : valor de indice minimo de altura a considerar
322 maxIndex : valor de indice maximo de altura a considerar
322 maxIndex : valor de indice maximo de altura a considerar
323
323
324 Affected:
324 Affected:
325 self.dataOut.data
325 self.dataOut.data
326 self.dataOut.heightList
326 self.dataOut.heightList
327
327
328 Return:
328 Return:
329 1 si el metodo se ejecuto con exito caso contrario devuelve 0
329 1 si el metodo se ejecuto con exito caso contrario devuelve 0
330 """
330 """
331
331
332 if (minIndex < 0) or (minIndex > maxIndex):
332 if (minIndex < 0) or (minIndex > maxIndex):
333 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
333 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
334
334
335 if (maxIndex >= self.dataOut.nHeights):
335 if (maxIndex >= self.dataOut.nHeights):
336 maxIndex = self.dataOut.nHeights-1
336 maxIndex = self.dataOut.nHeights-1
337 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
337 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
338
338
339 nHeights = maxIndex - minIndex + 1
339 nHeights = maxIndex - minIndex + 1
340
340
341 #voltage
341 #voltage
342 data = self.dataOut.data[:,minIndex:maxIndex+1]
342 data = self.dataOut.data[:,minIndex:maxIndex+1]
343
343
344 firstHeight = self.dataOut.heightList[minIndex]
344 firstHeight = self.dataOut.heightList[minIndex]
345
345
346 self.dataOut.data = data
346 self.dataOut.data = data
347 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
347 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
348
348
349 return 1
349 return 1
350
350
351
351
352 def filterByHeights(self, window):
352 def filterByHeights(self, window):
353 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
353 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
354
354
355 if window == None:
355 if window == None:
356 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
356 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
357
357
358 newdelta = deltaHeight * window
358 newdelta = deltaHeight * window
359 r = self.dataOut.data.shape[1] % window
359 r = self.dataOut.data.shape[1] % window
360 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
360 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
361 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
361 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
362 buffer = numpy.average(buffer,2)
362 buffer = numpy.sum(buffer,2)
363 self.dataOut.data = buffer
363 self.dataOut.data = buffer
364 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta)
364 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta)
365 self.dataOut.windowOfFilter = window
365
366
366 def deFlip(self):
367 def deFlip(self):
367 self.dataOut.data *= self.flip
368 self.dataOut.data *= self.flip
368 self.flip *= -1.
369 self.flip *= -1.
369
370
370
371
371 class CohInt(Operation):
372 class CohInt(Operation):
372
373
373 __isConfig = False
374 __isConfig = False
374
375
375 __profIndex = 0
376 __profIndex = 0
376 __withOverapping = False
377 __withOverapping = False
377
378
378 __byTime = False
379 __byTime = False
379 __initime = None
380 __initime = None
380 __lastdatatime = None
381 __lastdatatime = None
381 __integrationtime = None
382 __integrationtime = None
382
383
383 __buffer = None
384 __buffer = None
384
385
385 __dataReady = False
386 __dataReady = False
386
387
387 n = None
388 n = None
388
389
389
390
390 def __init__(self):
391 def __init__(self):
391
392
392 self.__isConfig = False
393 self.__isConfig = False
393
394
394 def setup(self, n=None, timeInterval=None, overlapping=False):
395 def setup(self, n=None, timeInterval=None, overlapping=False):
395 """
396 """
396 Set the parameters of the integration class.
397 Set the parameters of the integration class.
397
398
398 Inputs:
399 Inputs:
399
400
400 n : Number of coherent integrations
401 n : Number of coherent integrations
401 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
402 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
402 overlapping :
403 overlapping :
403
404
404 """
405 """
405
406
406 self.__initime = None
407 self.__initime = None
407 self.__lastdatatime = 0
408 self.__lastdatatime = 0
408 self.__buffer = None
409 self.__buffer = None
409 self.__dataReady = False
410 self.__dataReady = False
410
411
411
412
412 if n == None and timeInterval == None:
413 if n == None and timeInterval == None:
413 raise ValueError, "n or timeInterval should be specified ..."
414 raise ValueError, "n or timeInterval should be specified ..."
414
415
415 if n != None:
416 if n != None:
416 self.n = n
417 self.n = n
417 self.__byTime = False
418 self.__byTime = False
418 else:
419 else:
419 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
420 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
420 self.n = 9999
421 self.n = 9999
421 self.__byTime = True
422 self.__byTime = True
422
423
423 if overlapping:
424 if overlapping:
424 self.__withOverapping = True
425 self.__withOverapping = True
425 self.__buffer = None
426 self.__buffer = None
426 else:
427 else:
427 self.__withOverapping = False
428 self.__withOverapping = False
428 self.__buffer = 0
429 self.__buffer = 0
429
430
430 self.__profIndex = 0
431 self.__profIndex = 0
431
432
432 def putData(self, data):
433 def putData(self, data):
433
434
434 """
435 """
435 Add a profile to the __buffer and increase in one the __profileIndex
436 Add a profile to the __buffer and increase in one the __profileIndex
436
437
437 """
438 """
438
439
439 if not self.__withOverapping:
440 if not self.__withOverapping:
440 self.__buffer += data.copy()
441 self.__buffer += data.copy()
441 self.__profIndex += 1
442 self.__profIndex += 1
442 return
443 return
443
444
444 #Overlapping data
445 #Overlapping data
445 nChannels, nHeis = data.shape
446 nChannels, nHeis = data.shape
446 data = numpy.reshape(data, (1, nChannels, nHeis))
447 data = numpy.reshape(data, (1, nChannels, nHeis))
447
448
448 #If the buffer is empty then it takes the data value
449 #If the buffer is empty then it takes the data value
449 if self.__buffer == None:
450 if self.__buffer == None:
450 self.__buffer = data
451 self.__buffer = data
451 self.__profIndex += 1
452 self.__profIndex += 1
452 return
453 return
453
454
454 #If the buffer length is lower than n then stakcing the data value
455 #If the buffer length is lower than n then stakcing the data value
455 if self.__profIndex < self.n:
456 if self.__profIndex < self.n:
456 self.__buffer = numpy.vstack((self.__buffer, data))
457 self.__buffer = numpy.vstack((self.__buffer, data))
457 self.__profIndex += 1
458 self.__profIndex += 1
458 return
459 return
459
460
460 #If the buffer length is equal to n then replacing the last buffer value with the data value
461 #If the buffer length is equal to n then replacing the last buffer value with the data value
461 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
462 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
462 self.__buffer[self.n-1] = data
463 self.__buffer[self.n-1] = data
463 self.__profIndex = self.n
464 self.__profIndex = self.n
464 return
465 return
465
466
466
467
467 def pushData(self):
468 def pushData(self):
468 """
469 """
469 Return the sum of the last profiles and the profiles used in the sum.
470 Return the sum of the last profiles and the profiles used in the sum.
470
471
471 Affected:
472 Affected:
472
473
473 self.__profileIndex
474 self.__profileIndex
474
475
475 """
476 """
476
477
477 if not self.__withOverapping:
478 if not self.__withOverapping:
478 data = self.__buffer
479 data = self.__buffer
479 n = self.__profIndex
480 n = self.__profIndex
480
481
481 self.__buffer = 0
482 self.__buffer = 0
482 self.__profIndex = 0
483 self.__profIndex = 0
483
484
484 return data, n
485 return data, n
485
486
486 #Integration with Overlapping
487 #Integration with Overlapping
487 data = numpy.sum(self.__buffer, axis=0)
488 data = numpy.sum(self.__buffer, axis=0)
488 n = self.__profIndex
489 n = self.__profIndex
489
490
490 return data, n
491 return data, n
491
492
492 def byProfiles(self, data):
493 def byProfiles(self, data):
493
494
494 self.__dataReady = False
495 self.__dataReady = False
495 avgdata = None
496 avgdata = None
496 n = None
497 n = None
497
498
498 self.putData(data)
499 self.putData(data)
499
500
500 if self.__profIndex == self.n:
501 if self.__profIndex == self.n:
501
502
502 avgdata, n = self.pushData()
503 avgdata, n = self.pushData()
503 self.__dataReady = True
504 self.__dataReady = True
504
505
505 return avgdata
506 return avgdata
506
507
507 def byTime(self, data, datatime):
508 def byTime(self, data, datatime):
508
509
509 self.__dataReady = False
510 self.__dataReady = False
510 avgdata = None
511 avgdata = None
511 n = None
512 n = None
512
513
513 self.putData(data)
514 self.putData(data)
514
515
515 if (datatime - self.__initime) >= self.__integrationtime:
516 if (datatime - self.__initime) >= self.__integrationtime:
516 avgdata, n = self.pushData()
517 avgdata, n = self.pushData()
517 self.n = n
518 self.n = n
518 self.__dataReady = True
519 self.__dataReady = True
519
520
520 return avgdata
521 return avgdata
521
522
522 def integrate(self, data, datatime=None):
523 def integrate(self, data, datatime=None):
523
524
524 if self.__initime == None:
525 if self.__initime == None:
525 self.__initime = datatime
526 self.__initime = datatime
526
527
527 if self.__byTime:
528 if self.__byTime:
528 avgdata = self.byTime(data, datatime)
529 avgdata = self.byTime(data, datatime)
529 else:
530 else:
530 avgdata = self.byProfiles(data)
531 avgdata = self.byProfiles(data)
531
532
532
533
533 self.__lastdatatime = datatime
534 self.__lastdatatime = datatime
534
535
535 if avgdata == None:
536 if avgdata == None:
536 return None, None
537 return None, None
537
538
538 avgdatatime = self.__initime
539 avgdatatime = self.__initime
539
540
540 deltatime = datatime -self.__lastdatatime
541 deltatime = datatime -self.__lastdatatime
541
542
542 if not self.__withOverapping:
543 if not self.__withOverapping:
543 self.__initime = datatime
544 self.__initime = datatime
544 else:
545 else:
545 self.__initime += deltatime
546 self.__initime += deltatime
546
547
547 return avgdata, avgdatatime
548 return avgdata, avgdatatime
548
549
549 def run(self, dataOut, **kwargs):
550 def run(self, dataOut, **kwargs):
550
551
551 if not self.__isConfig:
552 if not self.__isConfig:
552 self.setup(**kwargs)
553 self.setup(**kwargs)
553 self.__isConfig = True
554 self.__isConfig = True
554
555
555 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
556 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
556
557
557 # dataOut.timeInterval *= n
558 # dataOut.timeInterval *= n
558 dataOut.flagNoData = True
559 dataOut.flagNoData = True
559
560
560 if self.__dataReady:
561 if self.__dataReady:
561 dataOut.data = avgdata
562 dataOut.data = avgdata
562 dataOut.nCohInt *= self.n
563 dataOut.nCohInt *= self.n
563 dataOut.utctime = avgdatatime
564 dataOut.utctime = avgdatatime
564 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
565 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
565 dataOut.flagNoData = False
566 dataOut.flagNoData = False
566
567
567
568
568 class Decoder(Operation):
569 class Decoder(Operation):
569
570
570 __isConfig = False
571 __isConfig = False
571 __profIndex = 0
572 __profIndex = 0
572
573
573 code = None
574 code = None
574
575
575 nCode = None
576 nCode = None
576 nBaud = None
577 nBaud = None
577
578
578 def __init__(self):
579 def __init__(self):
579
580
580 self.__isConfig = False
581 self.__isConfig = False
581
582
582 def setup(self, code):
583 def setup(self, code):
583
584
584 self.__profIndex = 0
585 self.__profIndex = 0
585
586
586 self.code = code
587 self.code = code
587
588
588 self.nCode = len(code)
589 self.nCode = len(code)
589 self.nBaud = len(code[0])
590 self.nBaud = len(code[0])
590
591
591 def convolutionInFreq(self, data):
592 def convolutionInFreq(self, data):
592
593
593 nchannel, ndata = data.shape
594 nchannel, ndata = data.shape
594 newcode = numpy.zeros(ndata)
595 newcode = numpy.zeros(ndata)
595 newcode[0:self.nBaud] = self.code[self.__profIndex]
596 newcode[0:self.nBaud] = self.code[self.__profIndex]
596
597
597 fft_data = numpy.fft.fft(data, axis=1)
598 fft_data = numpy.fft.fft(data, axis=1)
598 fft_code = numpy.conj(numpy.fft.fft(newcode))
599 fft_code = numpy.conj(numpy.fft.fft(newcode))
599 fft_code = fft_code.reshape(1,len(fft_code))
600 fft_code = fft_code.reshape(1,len(fft_code))
600
601
601 # conv = fft_data.copy()
602 # conv = fft_data.copy()
602 # conv.fill(0)
603 # conv.fill(0)
603
604
604 conv = fft_data*fft_code
605 conv = fft_data*fft_code
605
606
606 data = numpy.fft.ifft(conv,axis=1)
607 data = numpy.fft.ifft(conv,axis=1)
607
608
608 datadec = data[:,:-self.nBaud+1]
609 datadec = data[:,:-self.nBaud+1]
609 ndatadec = ndata - self.nBaud + 1
610 ndatadec = ndata - self.nBaud + 1
610
611
611 if self.__profIndex == self.nCode-1:
612 if self.__profIndex == self.nCode-1:
612 self.__profIndex = 0
613 self.__profIndex = 0
613 return ndatadec, datadec
614 return ndatadec, datadec
614
615
615 self.__profIndex += 1
616 self.__profIndex += 1
616
617
617 return ndatadec, datadec
618 return ndatadec, datadec
618
619
619
620
620 def convolutionInTime(self, data):
621 def convolutionInTime(self, data):
621
622
622 nchannel, ndata = data.shape
623 nchannel, ndata = data.shape
623 newcode = self.code[self.__profIndex]
624 newcode = self.code[self.__profIndex]
624 ndatadec = ndata - self.nBaud + 1
625 ndatadec = ndata - self.nBaud + 1
625
626
626 datadec = numpy.zeros((nchannel, ndatadec))
627 datadec = numpy.zeros((nchannel, ndatadec))
627
628
628 for i in range(nchannel):
629 for i in range(nchannel):
629 datadec[i,:] = numpy.correlate(data[i,:], newcode)
630 datadec[i,:] = numpy.correlate(data[i,:], newcode)
630
631
631 if self.__profIndex == self.nCode-1:
632 if self.__profIndex == self.nCode-1:
632 self.__profIndex = 0
633 self.__profIndex = 0
633 return ndatadec, datadec
634 return ndatadec, datadec
634
635
635 self.__profIndex += 1
636 self.__profIndex += 1
636
637
637 return ndatadec, datadec
638 return ndatadec, datadec
638
639
639 def run(self, dataOut, code=None, mode = 0):
640 def run(self, dataOut, code=None, mode = 0):
640
641
641 if not self.__isConfig:
642 if not self.__isConfig:
642
643
643 if code == None:
644 if code == None:
644 code = dataOut.code
645 code = dataOut.code
645
646
646 self.setup(code)
647 self.setup(code)
647 self.__isConfig = True
648 self.__isConfig = True
648
649
649 if mode == 0:
650 if mode == 0:
650 ndatadec, datadec = self.convolutionInFreq(dataOut.data)
651 ndatadec, datadec = self.convolutionInFreq(dataOut.data)
651
652
652 if mode == 1:
653 if mode == 1:
653 print "This function is not implemented"
654 print "This function is not implemented"
654 # ndatadec, datadec = self.convolutionInTime(dataOut.data)
655 # ndatadec, datadec = self.convolutionInTime(dataOut.data)
655
656
656 dataOut.data = datadec
657 dataOut.data = datadec
657
658
658 dataOut.heightList = dataOut.heightList[0:ndatadec]
659 dataOut.heightList = dataOut.heightList[0:ndatadec]
659
660
660 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
661 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
661
662
662 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
663 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
663
664
664
665
665 class SpectraProc(ProcessingUnit):
666 class SpectraProc(ProcessingUnit):
666
667
667 def __init__(self):
668 def __init__(self):
668
669
669 self.objectDict = {}
670 self.objectDict = {}
670 self.buffer = None
671 self.buffer = None
671 self.firstdatatime = None
672 self.firstdatatime = None
672 self.profIndex = 0
673 self.profIndex = 0
673 self.dataOut = Spectra()
674 self.dataOut = Spectra()
674
675
675 def __updateObjFromInput(self):
676 def __updateObjFromInput(self):
676
677
677 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
678 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
678 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
679 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
679 self.dataOut.channelList = self.dataIn.channelList
680 self.dataOut.channelList = self.dataIn.channelList
680 self.dataOut.heightList = self.dataIn.heightList
681 self.dataOut.heightList = self.dataIn.heightList
681 self.dataOut.dtype = self.dataIn.dtype
682 self.dataOut.dtype = self.dataIn.dtype
682 # self.dataOut.nHeights = self.dataIn.nHeights
683 # self.dataOut.nHeights = self.dataIn.nHeights
683 # self.dataOut.nChannels = self.dataIn.nChannels
684 # self.dataOut.nChannels = self.dataIn.nChannels
684 self.dataOut.nBaud = self.dataIn.nBaud
685 self.dataOut.nBaud = self.dataIn.nBaud
685 self.dataOut.nCode = self.dataIn.nCode
686 self.dataOut.nCode = self.dataIn.nCode
686 self.dataOut.code = self.dataIn.code
687 self.dataOut.code = self.dataIn.code
687 self.dataOut.nProfiles = self.dataOut.nFFTPoints
688 self.dataOut.nProfiles = self.dataOut.nFFTPoints
688 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
689 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
689 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
690 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
690 self.dataOut.utctime = self.firstdatatime
691 self.dataOut.utctime = self.firstdatatime
691 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
692 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
692 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
693 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
693 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
694 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
694 self.dataOut.nCohInt = self.dataIn.nCohInt
695 self.dataOut.nCohInt = self.dataIn.nCohInt
695 self.dataOut.nIncohInt = 1
696 self.dataOut.nIncohInt = 1
696 self.dataOut.ippSeconds = self.dataIn.ippSeconds
697 self.dataOut.ippSeconds = self.dataIn.ippSeconds
698 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
697
699
698 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
700 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
699
701
700 def __getFft(self):
702 def __getFft(self):
701 """
703 """
702 Convierte valores de Voltaje a Spectra
704 Convierte valores de Voltaje a Spectra
703
705
704 Affected:
706 Affected:
705 self.dataOut.data_spc
707 self.dataOut.data_spc
706 self.dataOut.data_cspc
708 self.dataOut.data_cspc
707 self.dataOut.data_dc
709 self.dataOut.data_dc
708 self.dataOut.heightList
710 self.dataOut.heightList
709 self.profIndex
711 self.profIndex
710 self.buffer
712 self.buffer
711 self.dataOut.flagNoData
713 self.dataOut.flagNoData
712 """
714 """
713 fft_volt = numpy.fft.fft(self.buffer,axis=1)
715 fft_volt = numpy.fft.fft(self.buffer,axis=1)
714 dc = fft_volt[:,0,:]
716 dc = fft_volt[:,0,:]
715
717
716 #calculo de self-spectra
718 #calculo de self-spectra
717 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
719 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
718 spc = fft_volt * numpy.conjugate(fft_volt)
720 spc = fft_volt * numpy.conjugate(fft_volt)
719 spc = spc.real
721 spc = spc.real
720
722
721 blocksize = 0
723 blocksize = 0
722 blocksize += dc.size
724 blocksize += dc.size
723 blocksize += spc.size
725 blocksize += spc.size
724
726
725 cspc = None
727 cspc = None
726 pairIndex = 0
728 pairIndex = 0
727 if self.dataOut.pairsList != None:
729 if self.dataOut.pairsList != None:
728 #calculo de cross-spectra
730 #calculo de cross-spectra
729 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
731 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
730 for pair in self.dataOut.pairsList:
732 for pair in self.dataOut.pairsList:
731 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
733 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
732 pairIndex += 1
734 pairIndex += 1
733 blocksize += cspc.size
735 blocksize += cspc.size
734
736
735 self.dataOut.data_spc = spc
737 self.dataOut.data_spc = spc
736 self.dataOut.data_cspc = cspc
738 self.dataOut.data_cspc = cspc
737 self.dataOut.data_dc = dc
739 self.dataOut.data_dc = dc
738 self.dataOut.blockSize = blocksize
740 self.dataOut.blockSize = blocksize
739
741
740 def init(self, nFFTPoints=None, pairsList=None):
742 def init(self, nFFTPoints=None, pairsList=None):
741
743
742 self.dataOut.flagNoData = True
744 self.dataOut.flagNoData = True
743
745
744 if self.dataIn.type == "Spectra":
746 if self.dataIn.type == "Spectra":
745 self.dataOut.copy(self.dataIn)
747 self.dataOut.copy(self.dataIn)
746 return
748 return
747
749
748 if self.dataIn.type == "Voltage":
750 if self.dataIn.type == "Voltage":
749
751
750 if nFFTPoints == None:
752 if nFFTPoints == None:
751 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
753 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
752
754
753 if pairsList == None:
755 if pairsList == None:
754 nPairs = 0
756 nPairs = 0
755 else:
757 else:
756 nPairs = len(pairsList)
758 nPairs = len(pairsList)
757
759
758 self.dataOut.nFFTPoints = nFFTPoints
760 self.dataOut.nFFTPoints = nFFTPoints
759 self.dataOut.pairsList = pairsList
761 self.dataOut.pairsList = pairsList
760 self.dataOut.nPairs = nPairs
762 self.dataOut.nPairs = nPairs
761
763
762 if self.buffer == None:
764 if self.buffer == None:
763 self.buffer = numpy.zeros((self.dataIn.nChannels,
765 self.buffer = numpy.zeros((self.dataIn.nChannels,
764 self.dataOut.nFFTPoints,
766 self.dataOut.nFFTPoints,
765 self.dataIn.nHeights),
767 self.dataIn.nHeights),
766 dtype='complex')
768 dtype='complex')
767
769
768
770
769 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
771 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
770 self.profIndex += 1
772 self.profIndex += 1
771
773
772 if self.firstdatatime == None:
774 if self.firstdatatime == None:
773 self.firstdatatime = self.dataIn.utctime
775 self.firstdatatime = self.dataIn.utctime
774
776
775 if self.profIndex == self.dataOut.nFFTPoints:
777 if self.profIndex == self.dataOut.nFFTPoints:
776 self.__updateObjFromInput()
778 self.__updateObjFromInput()
777 self.__getFft()
779 self.__getFft()
778
780
779 self.dataOut.flagNoData = False
781 self.dataOut.flagNoData = False
780
782
781 self.buffer = None
783 self.buffer = None
782 self.firstdatatime = None
784 self.firstdatatime = None
783 self.profIndex = 0
785 self.profIndex = 0
784
786
785 return
787 return
786
788
787 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
789 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
788
790
789 def selectChannels(self, channelList):
791 def selectChannels(self, channelList):
790
792
791 channelIndexList = []
793 channelIndexList = []
792
794
793 for channel in channelList:
795 for channel in channelList:
794 index = self.dataOut.channelList.index(channel)
796 index = self.dataOut.channelList.index(channel)
795 channelIndexList.append(index)
797 channelIndexList.append(index)
796
798
797 self.selectChannelsByIndex(channelIndexList)
799 self.selectChannelsByIndex(channelIndexList)
798
800
799 def selectChannelsByIndex(self, channelIndexList):
801 def selectChannelsByIndex(self, channelIndexList):
800 """
802 """
801 Selecciona un bloque de datos en base a canales segun el channelIndexList
803 Selecciona un bloque de datos en base a canales segun el channelIndexList
802
804
803 Input:
805 Input:
804 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
806 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
805
807
806 Affected:
808 Affected:
807 self.dataOut.data_spc
809 self.dataOut.data_spc
808 self.dataOut.channelIndexList
810 self.dataOut.channelIndexList
809 self.dataOut.nChannels
811 self.dataOut.nChannels
810
812
811 Return:
813 Return:
812 None
814 None
813 """
815 """
814
816
815 for channelIndex in channelIndexList:
817 for channelIndex in channelIndexList:
816 if channelIndex not in self.dataOut.channelIndexList:
818 if channelIndex not in self.dataOut.channelIndexList:
817 print channelIndexList
819 print channelIndexList
818 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
820 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
819
821
820 nChannels = len(channelIndexList)
822 nChannels = len(channelIndexList)
821
823
822 data_spc = self.dataOut.data_spc[channelIndexList,:]
824 data_spc = self.dataOut.data_spc[channelIndexList,:]
823
825
824 self.dataOut.data_spc = data_spc
826 self.dataOut.data_spc = data_spc
825 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
827 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
826 # self.dataOut.nChannels = nChannels
828 # self.dataOut.nChannels = nChannels
827
829
828 return 1
830 return 1
829
831
830
832
831 class IncohInt(Operation):
833 class IncohInt(Operation):
832
834
833
835
834 __profIndex = 0
836 __profIndex = 0
835 __withOverapping = False
837 __withOverapping = False
836
838
837 __byTime = False
839 __byTime = False
838 __initime = None
840 __initime = None
839 __lastdatatime = None
841 __lastdatatime = None
840 __integrationtime = None
842 __integrationtime = None
841
843
842 __buffer_spc = None
844 __buffer_spc = None
843 __buffer_cspc = None
845 __buffer_cspc = None
844 __buffer_dc = None
846 __buffer_dc = None
845
847
846 __dataReady = False
848 __dataReady = False
847
849
848 n = None
850 n = None
849
851
850
852
851 def __init__(self):
853 def __init__(self):
852
854
853 self.__isConfig = False
855 self.__isConfig = False
854
856
855 def setup(self, n=None, timeInterval=None, overlapping=False):
857 def setup(self, n=None, timeInterval=None, overlapping=False):
856 """
858 """
857 Set the parameters of the integration class.
859 Set the parameters of the integration class.
858
860
859 Inputs:
861 Inputs:
860
862
861 n : Number of coherent integrations
863 n : Number of coherent integrations
862 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
864 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
863 overlapping :
865 overlapping :
864
866
865 """
867 """
866
868
867 self.__initime = None
869 self.__initime = None
868 self.__lastdatatime = 0
870 self.__lastdatatime = 0
869 self.__buffer_spc = None
871 self.__buffer_spc = None
870 self.__buffer_cspc = None
872 self.__buffer_cspc = None
871 self.__buffer_dc = None
873 self.__buffer_dc = None
872 self.__dataReady = False
874 self.__dataReady = False
873
875
874
876
875 if n == None and timeInterval == None:
877 if n == None and timeInterval == None:
876 raise ValueError, "n or timeInterval should be specified ..."
878 raise ValueError, "n or timeInterval should be specified ..."
877
879
878 if n != None:
880 if n != None:
879 self.n = n
881 self.n = n
880 self.__byTime = False
882 self.__byTime = False
881 else:
883 else:
882 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
884 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
883 self.n = 9999
885 self.n = 9999
884 self.__byTime = True
886 self.__byTime = True
885
887
886 if overlapping:
888 if overlapping:
887 self.__withOverapping = True
889 self.__withOverapping = True
888 else:
890 else:
889 self.__withOverapping = False
891 self.__withOverapping = False
890 self.__buffer_spc = 0
892 self.__buffer_spc = 0
891 self.__buffer_cspc = 0
893 self.__buffer_cspc = 0
892 self.__buffer_dc = 0
894 self.__buffer_dc = 0
893
895
894 self.__profIndex = 0
896 self.__profIndex = 0
895
897
896 def putData(self, data_spc, data_cspc, data_dc):
898 def putData(self, data_spc, data_cspc, data_dc):
897
899
898 """
900 """
899 Add a profile to the __buffer_spc and increase in one the __profileIndex
901 Add a profile to the __buffer_spc and increase in one the __profileIndex
900
902
901 """
903 """
902
904
903 if not self.__withOverapping:
905 if not self.__withOverapping:
904 self.__buffer_spc += data_spc
906 self.__buffer_spc += data_spc
905
907
906 if data_cspc == None:
908 if data_cspc == None:
907 self.__buffer_cspc = None
909 self.__buffer_cspc = None
908 else:
910 else:
909 self.__buffer_cspc += data_cspc
911 self.__buffer_cspc += data_cspc
910
912
911 if data_dc == None:
913 if data_dc == None:
912 self.__buffer_dc = None
914 self.__buffer_dc = None
913 else:
915 else:
914 self.__buffer_dc += data_dc
916 self.__buffer_dc += data_dc
915
917
916 self.__profIndex += 1
918 self.__profIndex += 1
917 return
919 return
918
920
919 #Overlapping data
921 #Overlapping data
920 nChannels, nFFTPoints, nHeis = data_spc.shape
922 nChannels, nFFTPoints, nHeis = data_spc.shape
921 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
923 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
922 if data_cspc != None:
924 if data_cspc != None:
923 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
925 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
924 if data_dc != None:
926 if data_dc != None:
925 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
927 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
926
928
927 #If the buffer is empty then it takes the data value
929 #If the buffer is empty then it takes the data value
928 if self.__buffer_spc == None:
930 if self.__buffer_spc == None:
929 self.__buffer_spc = data_spc
931 self.__buffer_spc = data_spc
930
932
931 if data_cspc == None:
933 if data_cspc == None:
932 self.__buffer_cspc = None
934 self.__buffer_cspc = None
933 else:
935 else:
934 self.__buffer_cspc += data_cspc
936 self.__buffer_cspc += data_cspc
935
937
936 if data_dc == None:
938 if data_dc == None:
937 self.__buffer_dc = None
939 self.__buffer_dc = None
938 else:
940 else:
939 self.__buffer_dc += data_dc
941 self.__buffer_dc += data_dc
940
942
941 self.__profIndex += 1
943 self.__profIndex += 1
942 return
944 return
943
945
944 #If the buffer length is lower than n then stakcing the data value
946 #If the buffer length is lower than n then stakcing the data value
945 if self.__profIndex < self.n:
947 if self.__profIndex < self.n:
946 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
948 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
947
949
948 if data_cspc != None:
950 if data_cspc != None:
949 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
951 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
950
952
951 if data_dc != None:
953 if data_dc != None:
952 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
954 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
953
955
954 self.__profIndex += 1
956 self.__profIndex += 1
955 return
957 return
956
958
957 #If the buffer length is equal to n then replacing the last buffer value with the data value
959 #If the buffer length is equal to n then replacing the last buffer value with the data value
958 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
960 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
959 self.__buffer_spc[self.n-1] = data_spc
961 self.__buffer_spc[self.n-1] = data_spc
960
962
961 if data_cspc != None:
963 if data_cspc != None:
962 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
964 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
963 self.__buffer_cspc[self.n-1] = data_cspc
965 self.__buffer_cspc[self.n-1] = data_cspc
964
966
965 if data_dc != None:
967 if data_dc != None:
966 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
968 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
967 self.__buffer_dc[self.n-1] = data_dc
969 self.__buffer_dc[self.n-1] = data_dc
968
970
969 self.__profIndex = self.n
971 self.__profIndex = self.n
970 return
972 return
971
973
972
974
973 def pushData(self):
975 def pushData(self):
974 """
976 """
975 Return the sum of the last profiles and the profiles used in the sum.
977 Return the sum of the last profiles and the profiles used in the sum.
976
978
977 Affected:
979 Affected:
978
980
979 self.__profileIndex
981 self.__profileIndex
980
982
981 """
983 """
982 data_spc = None
984 data_spc = None
983 data_cspc = None
985 data_cspc = None
984 data_dc = None
986 data_dc = None
985
987
986 if not self.__withOverapping:
988 if not self.__withOverapping:
987 data_spc = self.__buffer_spc
989 data_spc = self.__buffer_spc
988 data_cspc = self.__buffer_cspc
990 data_cspc = self.__buffer_cspc
989 data_dc = self.__buffer_dc
991 data_dc = self.__buffer_dc
990
992
991 n = self.__profIndex
993 n = self.__profIndex
992
994
993 self.__buffer_spc = 0
995 self.__buffer_spc = 0
994 self.__buffer_cspc = 0
996 self.__buffer_cspc = 0
995 self.__buffer_dc = 0
997 self.__buffer_dc = 0
996 self.__profIndex = 0
998 self.__profIndex = 0
997
999
998 return data_spc, data_cspc, data_dc, n
1000 return data_spc, data_cspc, data_dc, n
999
1001
1000 #Integration with Overlapping
1002 #Integration with Overlapping
1001 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1003 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1002
1004
1003 if self.__buffer_cspc != None:
1005 if self.__buffer_cspc != None:
1004 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1006 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1005
1007
1006 if self.__buffer_dc != None:
1008 if self.__buffer_dc != None:
1007 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1009 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1008
1010
1009 n = self.__profIndex
1011 n = self.__profIndex
1010
1012
1011 return data_spc, data_cspc, data_dc, n
1013 return data_spc, data_cspc, data_dc, n
1012
1014
1013 def byProfiles(self, *args):
1015 def byProfiles(self, *args):
1014
1016
1015 self.__dataReady = False
1017 self.__dataReady = False
1016 avgdata_spc = None
1018 avgdata_spc = None
1017 avgdata_cspc = None
1019 avgdata_cspc = None
1018 avgdata_dc = None
1020 avgdata_dc = None
1019 n = None
1021 n = None
1020
1022
1021 self.putData(*args)
1023 self.putData(*args)
1022
1024
1023 if self.__profIndex == self.n:
1025 if self.__profIndex == self.n:
1024
1026
1025 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1027 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1026 self.__dataReady = True
1028 self.__dataReady = True
1027
1029
1028 return avgdata_spc, avgdata_cspc, avgdata_dc
1030 return avgdata_spc, avgdata_cspc, avgdata_dc
1029
1031
1030 def byTime(self, datatime, *args):
1032 def byTime(self, datatime, *args):
1031
1033
1032 self.__dataReady = False
1034 self.__dataReady = False
1033 avgdata_spc = None
1035 avgdata_spc = None
1034 avgdata_cspc = None
1036 avgdata_cspc = None
1035 avgdata_dc = None
1037 avgdata_dc = None
1036 n = None
1038 n = None
1037
1039
1038 self.putData(*args)
1040 self.putData(*args)
1039
1041
1040 if (datatime - self.__initime) >= self.__integrationtime:
1042 if (datatime - self.__initime) >= self.__integrationtime:
1041 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1043 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1042 self.n = n
1044 self.n = n
1043 self.__dataReady = True
1045 self.__dataReady = True
1044
1046
1045 return avgdata_spc, avgdata_cspc, avgdata_dc
1047 return avgdata_spc, avgdata_cspc, avgdata_dc
1046
1048
1047 def integrate(self, datatime, *args):
1049 def integrate(self, datatime, *args):
1048
1050
1049 if self.__initime == None:
1051 if self.__initime == None:
1050 self.__initime = datatime
1052 self.__initime = datatime
1051
1053
1052 if self.__byTime:
1054 if self.__byTime:
1053 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1055 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1054 else:
1056 else:
1055 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1057 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1056
1058
1057 self.__lastdatatime = datatime
1059 self.__lastdatatime = datatime
1058
1060
1059 if avgdata_spc == None:
1061 if avgdata_spc == None:
1060 return None, None, None, None
1062 return None, None, None, None
1061
1063
1062 avgdatatime = self.__initime
1064 avgdatatime = self.__initime
1063
1065
1064 deltatime = datatime -self.__lastdatatime
1066 deltatime = datatime -self.__lastdatatime
1065
1067
1066 if not self.__withOverapping:
1068 if not self.__withOverapping:
1067 self.__initime = datatime
1069 self.__initime = datatime
1068 else:
1070 else:
1069 self.__initime += deltatime
1071 self.__initime += deltatime
1070
1072
1071 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1073 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1072
1074
1073 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1075 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1074
1076
1075 if not self.__isConfig:
1077 if not self.__isConfig:
1076 self.setup(n, timeInterval, overlapping)
1078 self.setup(n, timeInterval, overlapping)
1077 self.__isConfig = True
1079 self.__isConfig = True
1078
1080
1079 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1081 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1080 dataOut.data_spc,
1082 dataOut.data_spc,
1081 dataOut.data_cspc,
1083 dataOut.data_cspc,
1082 dataOut.data_dc)
1084 dataOut.data_dc)
1083
1085
1084 # dataOut.timeInterval *= n
1086 # dataOut.timeInterval *= n
1085 dataOut.flagNoData = True
1087 dataOut.flagNoData = True
1086
1088
1087 if self.__dataReady:
1089 if self.__dataReady:
1088
1090
1089 dataOut.data_spc = avgdata_spc / self.n
1091 dataOut.data_spc = avgdata_spc
1090 dataOut.data_cspc = avgdata_cspc / self.n
1092 dataOut.data_cspc = avgdata_cspc
1091 dataOut.data_dc = avgdata_dc / self.n
1093 dataOut.data_dc = avgdata_dc
1092
1094
1093 dataOut.nIncohInt *= self.n
1095 dataOut.nIncohInt *= self.n
1094 dataOut.utctime = avgdatatime
1096 dataOut.utctime = avgdatatime
1095 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1097 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1096 dataOut.flagNoData = False
1098 dataOut.flagNoData = False
1097
1099
1098 class ProfileSelector(Operation):
1100 class ProfileSelector(Operation):
1099
1101
1100 profileIndex = None
1102 profileIndex = None
1101 # Tamanho total de los perfiles
1103 # Tamanho total de los perfiles
1102 nProfiles = None
1104 nProfiles = None
1103
1105
1104 def __init__(self):
1106 def __init__(self):
1105
1107
1106 self.profileIndex = 0
1108 self.profileIndex = 0
1107
1109
1108 def incIndex(self):
1110 def incIndex(self):
1109 self.profileIndex += 1
1111 self.profileIndex += 1
1110
1112
1111 if self.profileIndex >= self.nProfiles:
1113 if self.profileIndex >= self.nProfiles:
1112 self.profileIndex = 0
1114 self.profileIndex = 0
1113
1115
1114 def isProfileInRange(self, minIndex, maxIndex):
1116 def isProfileInRange(self, minIndex, maxIndex):
1115
1117
1116 if self.profileIndex < minIndex:
1118 if self.profileIndex < minIndex:
1117 return False
1119 return False
1118
1120
1119 if self.profileIndex > maxIndex:
1121 if self.profileIndex > maxIndex:
1120 return False
1122 return False
1121
1123
1122 return True
1124 return True
1123
1125
1124 def isProfileInList(self, profileList):
1126 def isProfileInList(self, profileList):
1125
1127
1126 if self.profileIndex not in profileList:
1128 if self.profileIndex not in profileList:
1127 return False
1129 return False
1128
1130
1129 return True
1131 return True
1130
1132
1131 def run(self, dataOut, profileList=None, profileRangeList=None):
1133 def run(self, dataOut, profileList=None, profileRangeList=None):
1132
1134
1133 dataOut.flagNoData = True
1135 dataOut.flagNoData = True
1134 self.nProfiles = dataOut.nProfiles
1136 self.nProfiles = dataOut.nProfiles
1135
1137
1136 if profileList != None:
1138 if profileList != None:
1137 if self.isProfileInList(profileList):
1139 if self.isProfileInList(profileList):
1138 dataOut.flagNoData = False
1140 dataOut.flagNoData = False
1139
1141
1140 self.incIndex()
1142 self.incIndex()
1141 return 1
1143 return 1
1142
1144
1143
1145
1144 elif profileRangeList != None:
1146 elif profileRangeList != None:
1145 minIndex = profileRangeList[0]
1147 minIndex = profileRangeList[0]
1146 maxIndex = profileRangeList[1]
1148 maxIndex = profileRangeList[1]
1147 if self.isProfileInRange(minIndex, maxIndex):
1149 if self.isProfileInRange(minIndex, maxIndex):
1148 dataOut.flagNoData = False
1150 dataOut.flagNoData = False
1149
1151
1150 self.incIndex()
1152 self.incIndex()
1151 return 1
1153 return 1
1152
1154
1153 else:
1155 else:
1154 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1156 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1155
1157
1156 return 0
1158 return 0
1157
1159
General Comments 0
You need to be logged in to leave comments. Login now