##// END OF EJS Templates
Esta version actualiza las librerias de ploteo para graficos RTI, Spectra y Scope, tambien se agregan metodos para procesamiento de Spectra y Voltage. En el caso de Voltage, en la Integracion Coherente se realiza indicando el tiempo de integracion en minutos.
Daniel Valdez -
r108:181a583e8f11
parent child
Show More
This diff has been collapsed as it changes many lines, (1259 lines changed) Show them Hide them
@@ -1,903 +1,938
1 """
1 """
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @autor $Author$
4 @autor $Author$
5 @version $Id$
5 @version $Id$
6
6
7 """
7 """
8
8
9 import numpy
9 import numpy
10 import sys
11 import time
12 import datetime
13 import time
10 import plplot
14 import plplot
11
15
16
12 def cmap1_init(colormap="gray"):
17 def cmap1_init(colormap="gray"):
13
18
14 if colormap == None:
19 if colormap == None:
15 return
20 return
16
21
17 ncolor = None
22 ncolor = None
18 rgb_lvl = None
23 rgb_lvl = None
19
24
20 # Routine for defining a specific color map 1 in HLS space.
25 # Routine for defining a specific color map 1 in HLS space.
21 # if gray is true, use basic grayscale variation from half-dark to light.
26 # if gray is true, use basic grayscale variation from half-dark to light.
22 # otherwise use false color variation from blue (240 deg) to red (360 deg).
27 # otherwise use false color variation from blue (240 deg) to red (360 deg).
23
28
24 # Independent variable of control points.
29 # Independent variable of control points.
25 i = numpy.array((0., 1.))
30 i = numpy.array((0., 1.))
26 if colormap=="gray":
31 if colormap=="gray":
27 ncolor = 256
32 ncolor = 256
28 # Hue for control points. Doesn't matter since saturation is zero.
33 # Hue for control points. Doesn't matter since saturation is zero.
29 h = numpy.array((0., 0.))
34 h = numpy.array((0., 0.))
30 # Lightness ranging from half-dark (for interest) to light.
35 # Lightness ranging from half-dark (for interest) to light.
31 l = numpy.array((0.5, 1.))
36 l = numpy.array((0.5, 1.))
32 # Gray scale has zero saturation
37 # Gray scale has zero saturation
33 s = numpy.array((0., 0.))
38 s = numpy.array((0., 0.))
34
39
35 # number of cmap1 colours is 256 in this case.
40 # number of cmap1 colours is 256 in this case.
36 plplot.plscmap1n(ncolor)
41 plplot.plscmap1n(ncolor)
37 # Interpolate between control points to set up cmap1.
42 # Interpolate between control points to set up cmap1.
38 plplot.plscmap1l(0, i, h, l, s)
43 plplot.plscmap1l(0, i, h, l, s)
39
44
40 return None
45 return None
46
47 if colormap == 'jet':
48 ncolor = 256
49 pos = numpy.zeros((ncolor))
50 r = numpy.zeros((ncolor))
51 g = numpy.zeros((ncolor))
52 b = numpy.zeros((ncolor))
53
54 for i in range(ncolor):
55 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
56 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
57 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
58 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
59
60 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
61 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
62 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
63 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
64 else: gf = 0.0
65
66 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
67 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
68 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
69 else: bf = 0
70
71 r[i] = rf
72 g[i] = gf
73 b[i] = bf
41
74
75 pos[i] = float(i)/float(ncolor-1)
76
77
78 plplot.plscmap1n(ncolor)
79 plplot.plscmap1l(1, pos, r, g, b)
80
81
82
42 if colormap=="br_green":
83 if colormap=="br_green":
43 ncolor = 256
84 ncolor = 256
44 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
85 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
45 h = numpy.array((240., 0.))
86 h = numpy.array((240., 0.))
46 # Lightness and saturation are constant (values taken from C example).
87 # Lightness and saturation are constant (values taken from C example).
47 l = numpy.array((0.6, 0.6))
88 l = numpy.array((0.6, 0.6))
48 s = numpy.array((0.8, 0.8))
89 s = numpy.array((0.8, 0.8))
49
90
50 # number of cmap1 colours is 256 in this case.
91 # number of cmap1 colours is 256 in this case.
51 plplot.plscmap1n(ncolor)
92 plplot.plscmap1n(ncolor)
52 # Interpolate between control points to set up cmap1.
93 # Interpolate between control points to set up cmap1.
53 plplot.plscmap1l(0, i, h, l, s)
94 plplot.plscmap1l(0, i, h, l, s)
54
95
55 return None
96 return None
56
97
57 if colormap=="tricolor":
98 if colormap=="tricolor":
58 ncolor = 3
99 ncolor = 3
59 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
100 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
60 h = numpy.array((240., 0.))
101 h = numpy.array((240., 0.))
61 # Lightness and saturation are constant (values taken from C example).
102 # Lightness and saturation are constant (values taken from C example).
62 l = numpy.array((0.6, 0.6))
103 l = numpy.array((0.6, 0.6))
63 s = numpy.array((0.8, 0.8))
104 s = numpy.array((0.8, 0.8))
64
105
65 # number of cmap1 colours is 256 in this case.
106 # number of cmap1 colours is 256 in this case.
66 plplot.plscmap1n(ncolor)
107 plplot.plscmap1n(ncolor)
67 # Interpolate between control points to set up cmap1.
108 # Interpolate between control points to set up cmap1.
68 plplot.plscmap1l(0, i, h, l, s)
109 plplot.plscmap1l(0, i, h, l, s)
69
110
70 return None
111 return None
71
112
72 if colormap == 'rgb' or colormap == 'rgb666':
113 if colormap == 'rgb' or colormap == 'rgb666':
73
114
74 color_sz = 6
115 color_sz = 6
75 ncolor = color_sz*color_sz*color_sz
116 ncolor = color_sz*color_sz*color_sz
76 pos = numpy.zeros((ncolor))
117 pos = numpy.zeros((ncolor))
77 r = numpy.zeros((ncolor))
118 r = numpy.zeros((ncolor))
78 g = numpy.zeros((ncolor))
119 g = numpy.zeros((ncolor))
79 b = numpy.zeros((ncolor))
120 b = numpy.zeros((ncolor))
80 ind = 0
121 ind = 0
81 for ri in range(color_sz):
122 for ri in range(color_sz):
82 for gi in range(color_sz):
123 for gi in range(color_sz):
83 for bi in range(color_sz):
124 for bi in range(color_sz):
84 r[ind] = ri/(color_sz-1.0)
125 r[ind] = ri/(color_sz-1.0)
85 g[ind] = gi/(color_sz-1.0)
126 g[ind] = gi/(color_sz-1.0)
86 b[ind] = bi/(color_sz-1.0)
127 b[ind] = bi/(color_sz-1.0)
87 pos[ind] = ind/(ncolor-1.0)
128 pos[ind] = ind/(ncolor-1.0)
88 ind += 1
129 ind += 1
89 rgb_lvl = [6,6,6] #Levels for RGB colors
130 rgb_lvl = [6,6,6] #Levels for RGB colors
90
131
91 if colormap == 'rgb676':
132 if colormap == 'rgb676':
92 ncolor = 6*7*6
133 ncolor = 6*7*6
93 pos = numpy.zeros((ncolor))
134 pos = numpy.zeros((ncolor))
94 r = numpy.zeros((ncolor))
135 r = numpy.zeros((ncolor))
95 g = numpy.zeros((ncolor))
136 g = numpy.zeros((ncolor))
96 b = numpy.zeros((ncolor))
137 b = numpy.zeros((ncolor))
97 ind = 0
138 ind = 0
98 for ri in range(8):
139 for ri in range(8):
99 for gi in range(8):
140 for gi in range(8):
100 for bi in range(4):
141 for bi in range(4):
101 r[ind] = ri/(6-1.0)
142 r[ind] = ri/(6-1.0)
102 g[ind] = gi/(7-1.0)
143 g[ind] = gi/(7-1.0)
103 b[ind] = bi/(6-1.0)
144 b[ind] = bi/(6-1.0)
104 pos[ind] = ind/(ncolor-1.0)
145 pos[ind] = ind/(ncolor-1.0)
105 ind += 1
146 ind += 1
106 rgb_lvl = [6,7,6] #Levels for RGB colors
147 rgb_lvl = [6,7,6] #Levels for RGB colors
107
148
108 if colormap == 'rgb685':
149 if colormap == 'rgb685':
109 ncolor = 6*8*5
150 ncolor = 6*8*5
110 pos = numpy.zeros((ncolor))
151 pos = numpy.zeros((ncolor))
111 r = numpy.zeros((ncolor))
152 r = numpy.zeros((ncolor))
112 g = numpy.zeros((ncolor))
153 g = numpy.zeros((ncolor))
113 b = numpy.zeros((ncolor))
154 b = numpy.zeros((ncolor))
114 ind = 0
155 ind = 0
115 for ri in range(8):
156 for ri in range(8):
116 for gi in range(8):
157 for gi in range(8):
117 for bi in range(4):
158 for bi in range(4):
118 r[ind] = ri/(6-1.0)
159 r[ind] = ri/(6-1.0)
119 g[ind] = gi/(8-1.0)
160 g[ind] = gi/(8-1.0)
120 b[ind] = bi/(5-1.0)
161 b[ind] = bi/(5-1.0)
121 pos[ind] = ind/(ncolor-1.0)
162 pos[ind] = ind/(ncolor-1.0)
122 ind += 1
163 ind += 1
123 rgb_lvl = [6,8,5] #Levels for RGB colors
164 rgb_lvl = [6,8,5] #Levels for RGB colors
124
165
125 if colormap == 'rgb884':
166 if colormap == 'rgb884':
126 ncolor = 8*8*4
167 ncolor = 8*8*4
127 pos = numpy.zeros((ncolor))
168 pos = numpy.zeros((ncolor))
128 r = numpy.zeros((ncolor))
169 r = numpy.zeros((ncolor))
129 g = numpy.zeros((ncolor))
170 g = numpy.zeros((ncolor))
130 b = numpy.zeros((ncolor))
171 b = numpy.zeros((ncolor))
131 ind = 0
172 ind = 0
132 for ri in range(8):
173 for ri in range(8):
133 for gi in range(8):
174 for gi in range(8):
134 for bi in range(4):
175 for bi in range(4):
135 r[ind] = ri/(8-1.0)
176 r[ind] = ri/(8-1.0)
136 g[ind] = gi/(8-1.0)
177 g[ind] = gi/(8-1.0)
137 b[ind] = bi/(4-1.0)
178 b[ind] = bi/(4-1.0)
138 pos[ind] = ind/(ncolor-1.0)
179 pos[ind] = ind/(ncolor-1.0)
139 ind += 1
180 ind += 1
140 rgb_lvl = [8,8,4] #Levels for RGB colors
181 rgb_lvl = [8,8,4] #Levels for RGB colors
141
182
142 if ncolor == None:
183 if ncolor == None:
143 raise ValueError, "The colormap selected is not valid"
184 raise ValueError, "The colormap selected is not valid"
144
185
145 plplot.plscmap1n(ncolor)
186 plplot.plscmap1n(ncolor)
146 plplot.plscmap1l(1, pos, r, g, b)
187 plplot.plscmap1l(1, pos, r, g, b)
147
188
148 return rgb_lvl
189 return rgb_lvl
149
190
150 def setColormap(colormap="br_green"):
191 def setColormap(colormap="jet"):
151 cmap1_init(colormap)
192 cmap1_init(colormap)
152
193
153 class BaseGraph:
194 def initPlplot(indexPlot,ncol,nrow,winTitle,width,height):
154 """
195 plplot.plsstrm(indexPlot)
155
196 plplot.plparseopts([winTitle],plplot.PL_PARSE_FULL)
156 """
197 plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow))
157 hasNotRange = True
198 plplot.plsdev("xwin")
158
199 plplot.plscolbg(255,255,255)
159 xrange = None
200 plplot.plscol0(1,0,0,0)
160 yrange = None
201 plplot.plinit()
161 zrange = None
202 plplot.plspause(False)
203 plplot.plssub(ncol,nrow)
204
205 def clearData(objGraph):
206 objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc")
162
207
163 xlabel = None
208 objGraph.setColor(15) #Setting Line Color to White
164 ylabel = None
165 title = None
166
209
167 legends = None
210 if objGraph.datatype == "complex":
211 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real)
212 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag)
213
214 if objGraph.datatype == "real":
215 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata)
168
216
169 __name = None
217 objGraph.setColor(1) #Setting Line Color to Black
218 # objGraph.setLineStyle(2)
219 # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bcntg", "bc")
220 # objGraph.setLineStyle(1)
221
222 def setStrm(indexPlot):
223 plplot.plsstrm(indexPlot)
224
225 def plFlush():
226 plplot.plflush()
170
227
171 __colormap = None
228 def setPlTitle(pltitle,color):
172 __colbox = None
229 setSubpages(1, 0)
173 __colleg = None
230 plplot.pladv(0)
174
231 plplot.plvpor(0., 1., 0., 1.)
175 __xpos = None
176 __ypos = None
177
232
178 __xopt = None #"bcnst"
233 if color == "black":
179 __yopt = None #"bcnstv"
234 plplot.plcol0(1)
180
235 if color == "white":
181 __xlpos = None
236 plplot.plcol0(15)
182 __ylpos = None
183
237
184 __xrangeIsTime = False
238 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
185
239
186 #Advanced
240 def setSubpages(ncol,nrow):
241 plplot.plssub(ncol,nrow)
242
243 class BaseGraph:
244 __name = None
245 __xpos = None
246 __ypos = None
247 __subplot = None
187 __xg = None
248 __xg = None
188 __yg = None
249 __yg = None
189
250 xdata = None
190 def __init__(self):
251 ydata = None
191 """
252 getGrid = True
192
253 xaxisIsTime = False
193 """
254 deltax = None
194 self.hasNotRange = True
255 xmin = None
195
256 xmax = None
196 self.xrange = None
257 def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0):
197 self.yrange = None
258 self.setName(name)
198 self.zrange = None
259 self.setScreenPos(xpos, ypos)
199
260 self.setLabels(xlabel,ylabel,title)
200 self.xlabel = None
261 self.setSubPlot(subplot)
201 self.ylabel = None
262 self.setSizeOfChar(szchar)
202 self.title = None
263 self.setXYZrange(xrange,yrange,zrange)
203
264 self.getGrid = True
204 self.legends = None
265 self.xaxisIsTime = False
205
266 self.deltax = deltax
206 self.__name = None
267
207
268 def setXYZrange(self,xrange,yrange,zrange):
208 self.__colormap = None
269 self.xrange = xrange
209 self.__colbox = None
270 self.yrange = yrange
210 self.__colleg = None
271 self.zrange = zrange
211
212 self.__xpos = None
213 self.__ypos = None
214
215 self.__xopt = None #"bcnst"
216 self.__yopt = None #"bcnstv"
217
218 self.__xlpos = None
219 self.__ylpos = None
220
221 self.__xrangeIsTime = False
222
223 #Advanced
224 self.__xg = None
225 self.__yg = None
226
272
227 def setName(self, name):
273 def setName(self, name):
228 self.__name = name
274 self.__name = name
229
275
230 def setScreenPos(self, xpos, ypos):
276 def setScreenPos(self,xpos,ypos):
231 self.__xpos = xpos
277 self.__xpos = xpos
232 self.__ypos = ypos
278 self.__ypos = ypos
233
279
234 def setOpt(self, xopt, yopt):
280 def setXYData(self,xdata=None,ydata=None,datatype="real"):
235 self.__xopt = xopt
281 if((xdata != None) and (ydata != None)):
236 self.__yopt = yopt
282 self.xdata = xdata
237
283 self.ydata = ydata
238 def setXAxisAsTime(self):
284 self.datatype = datatype
239 self.__xrangeIsTime = True
240
241
242 def setup(self, title=None, xlabel=None, ylabel=None, colormap=None):
243 """
244 """
245 self.title = title
246 self.xlabel = xlabel
247 self.ylabel = ylabel
248 self.__colormap = colormap
249
250 def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False):
251 """
252
253 """
254 if self.__xrangeIsTime:
255 plplot.pltimefmt("%H:%M")
256
285
257 plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
286 if((self.xdata == None) and (self.ydata == None)):
258 plplot.plwind(float(xmin),
287 return None
259 float(xmax),
260 float(ymin),
261 float(ymax)
262 )
263
264 if xopt == None: xopt = self.__xopt
265 if yopt == None: yopt = self.__yopt
266
267 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
268
288
269 if not(nolabels):
289 return 1
270 plplot.pllab(self.xlabel, self.ylabel, self.title)
271
272
290
273 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
291
274 data = numpy.arange(256)
292 def setLabels(self,xlabel=None,ylabel=None,title=None):
275 data = numpy.reshape(data, (1,-1))
293 if xlabel != None: self.xlabel = xlabel
276
294 if ylabel != None: self.ylabel = ylabel
277 plplot.plimage(data,
295 if title != None: self.title = title
278 float(xmin),
296
279 float(xmax),
297 def setSubPlot(self,subplot):
280 float(ymin),
298 self.__subplot = subplot
281 float(ymax),
299
282 0.,
300 def setSizeOfChar(self,szchar):
283 255.,
301 self.__szchar = szchar
284 float(xmin),
285 float(xmax),
286 float(ymin),
287 float(ymax))
288
302
289 def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None):
303 def setLineStyle(self,style):
304 plplot.pllsty(style)
305
306 def setColor(self,color):
307 plplot.plcol0(color)
308
309 def setXAxisAsTime(self,value=False):
310 self.xaxisIsTime = value
311
312 def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
290
313
291 if xmin == None: xmin = x[0]
314 if xmin == None: xmin = x[0]
292 if xmax == None: xmax = x[-1]
315 if xmax == None: xmax = x[-1]
293 if ymin == None: ymin = y[0]
316 if ymin == None: ymin = y[0]
294 if ymax == None: ymax = y[-1]
317 if ymax == None: ymax = y[-1]
295
318
319 plplot.plcol0(colline)
296 plplot.plline(x, y)
320 plplot.plline(x, y)
321 plplot.plcol0(1)
297
322
298 def basicXYwithErrorPlot(self):
323 def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None):
299 pass
300
301 def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
302
324
303 if xmin == None: xmin = x[0]
325 if xmin == None: xmin = x[0]
304 if xmax == None: xmax = x[-1]
326 if xmax == None: xmax = x[-1]
305 if ymin == None: ymin = y[0]
327 if ymin == None: ymin = y[0]
306 if ymax == None: ymax = y[-1]
328 if ymax == None: ymax = y[-1]
307
329
308 plplot.plcol0(colline)
309 plplot.plline(x, y)
330 plplot.plline(x, y)
310 plplot.plcol0(1)
311
331
312 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
332 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
313 """
333 """
314 """
334 """
315 if xmin == None: xmin = x[0]
335 if xmin == None: xmin = x[0]
316 if xmax == None: xmax = x[-1]
336 if xmax == None: xmax = x[-1]
317 if ymin == None: ymin = y[0]
337 if ymin == None: ymin = y[0]
318 if ymax == None: ymax = y[-1]
338 if ymax == None: ymax = y[-1]
319 if zmin == None: zmin = numpy.nanmin(data)
339 if zmin == None: zmin = numpy.nanmin(data)
320 if zmax == None: zmax = numpy.nanmax(data)
340 if zmax == None: zmax = numpy.nanmax(data)
321
341
322 plplot.plimage(data,
342 plplot.plimage(data,
323 float(x[0]),
343 float(x[0]),
324 float(x[-1]),
344 float(x[-1]),
325 float(y[0]),
345 float(y[0]),
326 float(y[-1]),
346 float(y[-1]),
327 float(zmin),
347 float(zmin),
328 float(zmax),
348 float(zmax),
329 float(xmin),
349 float(xmin),
330 float(xmax),
350 float(xmax),
331 float(ymin),
351 float(ymin),
332 float(ymax)
352 float(ymax)
333 )
353 )
334
354
335 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
355 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
336
356
337 if not(len(x)>1 and len(y)>1):
357 if not(len(x)>0 and len(y)>0):
338 raise ValueError, "x axis and y axis are empty"
358 raise ValueError, "x axis and y axis are empty"
339
359
340 if deltax == None: deltax = x[-1] - x[-2]
360 if deltax == None: deltax = x[-1] - x[-2]
341 if deltay == None: deltay = y[-1] - y[-2]
361 if deltay == None: deltay = y[-1] - y[-2]
342
362
343 x1 = numpy.append(x, x[-1] + deltax)
363 x1 = numpy.append(x, x[-1] + deltax)
344 y1 = numpy.append(y, y[-1] + deltay)
364 y1 = numpy.append(y, y[-1] + deltay)
345
365
346 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
366 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
347 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
367 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
348
368
349 self.__xg = xg
369 self.__xg = xg
350 self.__yg = yg
370 self.__yg = yg
351
371
352 def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.):
372 return xg, yg
353 """
373
354 """
374
355
375 def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
356 if self.__xg == None and self.__yg == None:
376 if getGrid:
357 self.__getBoxpltr(x, y)
377 xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
358
378 else:
359 plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg)
379 xg = self.__xg
380 yg = self.__yg
381
382 plplot.plimagefr(data,
383 float(xmin),
384 float(xmax),
385 float(ymin),
386 float(ymax),
387 0.,
388 0.,
389 float(zmin),
390 float(zmax),
391 plplot.pltr2,
392 xg,
393 yg)
360
394
361
395
362 class LinearPlot:
396 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
363
397 data = numpy.arange(256)
364 linearGraphObj = BaseGraph()
398 data = numpy.reshape(data, (1,-1))
365
366 __szchar = 1.0
367
368 __xrange = None
369
370 __yrange = None
371
372 __subpage = 0
373 m_BaseGraph= BaseGraph()
374
375
376
377 def __init__(self):
378
379
380 key = "linearplot"
381 self.linearGraphObj = BaseGraph()
382 self.linearGraphObj.setName(key)
383
384 self.__subpage = 0
385
386 def __iniSubpage(self):
387
399
388 if plplot.plgdev() == '':
400 plplot.plimage(data,
389 raise ValueError, "Plot device has not been initialize"
401 float(xmin),
402 float(xmax),
403 float(ymin),
404 float(ymax),
405 0.,
406 255.,
407 float(xmin),
408 float(xmax),
409 float(ymin),
410 float(ymax))
411
412 def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False):
390
413
391 plplot.pladv(self.__subpage)
414 plplot.plschr(0.0,self.__szchar-0.05)
392 plplot.plschr(0.0, self.__szchar)
415 plplot.pladv(self.__subplot)
416 plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
417 plplot.plwind(float(xmin), # self.xrange[0]
418 float(xmax), # self.xrange[1]
419 float(ymin), # self.yrange[0]
420 float(ymax) # self.yrange[1]
421 )
393
422
394 setColormap()
395
423
396 def setScreenPos(self, width='small'):
397
424
398 if width == 'small':
425 if self.xaxisIsTime:
399 xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80
426 plplot.pltimefmt("%H:%M")
427 timedelta = (xmax - xmin + 1)/8.
428 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
429 else:
430 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
400
431
401 if width == 'medium':
402 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60
403
404 xf = xi + xw
405 yf = yi + yw
406
432
407 self.linearGraphObj.setScreenPos([xi, xf], [yi, yf])
433 if not(nolabels):
434 plplot.pllab(self.xlabel, self.ylabel, self.title)
408
435
409 def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False):
436
410 """
437 def delLabels(self):
411 """
438 self.setColor(15) #Setting Line Color to White
412
439 plplot.pllab(self.xlabel, self.ylabel, self.title)
413 self.linearGraphObj.setOpt("bcnts","bcntsv")
440 self.setColor(1) #Setting Line Color to Black
414 self.linearGraphObj.setup(title,
441
415 xlabel,
442
416 ylabel
443
417 )
444 def plotImage(self,x,y,z,xrange,yrange,zrange):
418
445 xi = x[0]
419 self.setScreenPos(width='medium')
446 xf = x[-1]
420
447 yi = y[0]
421 if XAxisAsTime:
448 yf = y[-1]
422 self.linearGraphObj.setXAxisAsTime()
449
423
450 plplot.plimage(z,
424 self.__subpage = subpage
451 float(xi),
425 # def setRanges(self, xrange, yrange, zrange):
452 float(xf),
426 #
453 float(yi),
427 # self.linearGraphObj.setRanges(xrange, yrange, zrange)
454 float(yf),
455 float(zrange[0]),
456 float(zrange[1]),
457 float(xi),
458 float(xf),
459 float(yrange[0]),
460 yrange[1])
461
462 class LinearPlot:
463 linearObjDic = {}
464 __xpos = None
465 __ypos = None
466 def __init__(self,indexPlot,nsubplot,winTitle):
467 self.width = 700
468 self.height = 150
469 ncol = 1
470 nrow = nsubplot
471 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
428
472
429 def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
473
430 """
474 def setFigure(self,indexPlot):
431 Inputs:
475 setStrm(indexPlot)
432
433 x : Numpy array of dimension 1
434 y : Numpy array of dimension 1
435
436 """
437
476
438 try:
477 def setPosition(self):
439 nX = numpy.shape(x)
440 except:
441 raise ValueError, "x is not a numpy array"
442
478
443 if y == None: y = numpy.arange(nX)
479 xi = 0.07; xf = 0.9 #0.8,0.7,0.5
480 yi = 0.15; yf = 0.8
444
481
445 if xmin == None: xmin = x[0]
482 xpos = [xi,xf]
446 if xmax == None: xmax = x[-1]
483 ypos = [yi,yf]
447 if ymin == None: ymin = y[0]
448 if ymax == None: ymax = y[-1]
449
484
450 self.__iniSubpage()
485 self.__xpos = xpos
451 self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax)
486 self.__ypos = ypos
452 self.linearGraphObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline)
453
454 def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'):
455 """
456 Inputs:
457
458 x : Numpy array of dimension 1
459 y : Complex numpy array of dimension 1
460
487
461 """
488 return xpos,ypos
489
490 def refresh(self):
491 plFlush()
462
492
463 try:
493 def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel):
464 nX = numpy.shape(x)
494 szchar = 1.10
465 except:
495 name = "linear"
466 raise ValueError, "x is not a numpy array"
496 key = name + "%d"%subplot
497 xrange = [xmin,xmax]
498 yrange = [ymin,ymax]
467
499
468 try:
500 xpos,ypos = self.setPosition()
469 nY = numpy.shape(y)
501 linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange)
470 except:
502 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcnst", "bcnstv")
471 raise ValueError, "y is not a numpy array"
503 self.linearObjDic[key] = linearObj
504
505 def plot(self,subplot,x,y,type="power"):
506 name = "linear"
507 key = name + "%d"%subplot
472
508
473 if xmin == None: xmin = x[0]
509 linearObj = self.linearObjDic[key]
474 if xmax == None: xmax = x[-1]
510 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst")
475 if ymin == None: ymin = y[0]
476 if ymax == None: ymax = y[-1]
477
511
478 self.__iniSubpage()
512 if linearObj.setXYData() != None:
479 self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax)
513 clearData(linearObj)
514
515 else:
516 if type.lower() == 'power':
517 linearObj.setXYData(x,abs(y),"real")
518 if type.lower() == 'iq':
519 linearObj.setXYData(x,y,"complex")
480
520
481 if type.lower() == 'power':
521 if type.lower() == 'power':
482 self.linearGraphObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline)
522 colline = 9
523 linearObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline)
524 linearObj.setXYData(x,abs(y),"real")
483
525
484 if type.lower() == 'iq':
526 if type.lower() == 'iq':
527 colline = 9
528 linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline)
529 colline = 13
530 linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline)
485
531
486 self.linearGraphObj.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline)
532 linearObj.setXYData(x,y,"complex")
487 self.linearGraphObj.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1)
488
489 class ColorPlot:
490
491 colorGraphObj = BaseGraph()
492
493 graphObjDict = {}
494
533
495 __subpage = 0
534 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst")
496
497 __showColorbar = False
498
499 __showPowerProfile = True
500
501 __szchar = 0.65
502
503 __xrange = None
504
505 __yrange = None
506
507 __zrange = None
508 m_BaseGraph= BaseGraph()
509
510
511
512 def __init__(self):
513
514 self.graphObjDict = {}
515
535
516 self.__subpage = 0
517 self.__showColorbar = False
518 self.__showPowerProfile = True
519
536
520 self.__szchar = 0.65
537 # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bc", "bc")
521 self.__xrange = None
538 # linearObj.basicXYPlot(data,y)
522 self.__yrange = None
539 # linearObj.setXYData(data,y)
523 self.__zrange = None
524
540
525 key = "colorplot"
541
526 self.colorGraphObj = BaseGraph()
527 self.colorGraphObj.setName(key)
528
542
529 def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
543 class SpectraPlot:
530 """
544 pcolorObjDic = {}
531 """
545 colorbarObjDic = {}
532
546 pwprofileObjDic = {}
533 self.colorGraphObj.setOpt("bcnts","bcntsv")
547 showColorbar = None
534 self.colorGraphObj.setup(title,
548 showPowerProfile = None
535 xlabel,
549 XAxisAsTime = None
536 ylabel
550 widht = None
537 )
551 height = None
538
552 __spcxpos = None
539 self.__subpage = subpage
553 __spcypos = None
540 self.__colormap = colormap
554 __cmapxpos = None
541 self.__showColorbar = showColorbar
555 __cmapypos = None
542 self.__showPowerProfile = showPowerProfile
556 __profxpos = None
543
557 __profypos = None
544 if showColorbar:
558 __lastTitle = None
545 key = "colorbar"
559
546
560 def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
547 cmapObj = BaseGraph()
561 self.width = 460
548 cmapObj.setName(key)
562 self.height = 300
549 cmapObj.setOpt("bc","bcmtv")
563 self.showColorbar = showColorbar
550 cmapObj.setup(title="dBs",
564 self.showPowerProfile = showPowerProfile
551 xlabel="",
565 self.XAxisAsTime = XAxisAsTime
552 ylabel="",
566
553 colormap=colormap)
567 nrow = 2
554
568 if (nsubplot%2)==0:
555 self.graphObjDict[key] = cmapObj
569 ncol = nsubplot/nrow
556
570 else:
557
571 ncol = int(nsubplot)/nrow + 1
558 if showPowerProfile:
572
559 key = "powerprof"
573 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
560
574 setColormap(colormap)
561 powObj = BaseGraph()
575 self.ncol = ncol
562 powObj.setName(key)
576 self.nrow = nrow
563 powObj.setOpt("bcntg","bc")
577
564 powObj.setup(title="Power Profile",
578 def setFigure(self,indexPlot):
565 xlabel="dB",
579 setStrm(indexPlot)
566 ylabel="")
580
567
581 def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile
568 self.graphObjDict[key] = powObj
582 if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075
569
583 else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5
570 self.setScreenPos(width='small')
584 yi = 0.15; yf = 0.80
571
572 if XAxisAsTime:
573 self.colorGraphObj.setXAxisAsTime()
574
575 def __iniSubpage(self):
576
585
577 if plplot.plgdev() == '':
586 xpos = [xi,xf]
578 raise ValueError, "Plot device has not been initialize"
587 ypos = [yi,yf]
579
588
580 plplot.pladv(self.__subpage)
589 self.__spcxpos = xpos
581 plplot.plschr(0.0, self.__szchar)
590 self.__spcypos = ypos
582
591
583 setColormap(self.__colormap)
592 return xpos,ypos
584
593
585 def setScreenPos(self, width='small'):
594 def setColorbarScreenPos(self):
595
596 xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03
597 yi = self.__spcypos[0]; yf = self.__spcypos[1]
586
598
587 if width == 'small':
599 xpos = [xi,xf]
588 xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.04; xpoww = 0.25; deltaxcmap = 0.02; deltaxpow = 0.06
600 ypos = [yi,yf]
589
601
590 if width == 'medium':
602 self.__cmapxpos = xpos
591 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.04; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06
603 self.__cmapypos = ypos
604
605 return xpos,ypos
606
607 def setPowerprofileScreenPos(self):
592
608
593 if self.__showColorbar:
609 xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25
594 xw -= xcmapw + deltaxcmap
610 yi = self.__spcypos[0]; yf = self.__spcypos[1]
595
611
596 if self.__showPowerProfile:
612 xpos = [xi,xf]
597 xw -= xpoww + deltaxpow
613 ypos = [yi,yf]
598
599 xf = xi + xw
600 yf = yi + yw
601 xcmapf = xf
602
614
603 self.colorGraphObj.setScreenPos([xi, xf], [yi, yf])
615 self.__profxpos = [xi,xf]
616 self.__profypos = [yi,yf]
604
617
605 if self.__showColorbar:
618 return xpos,ypos
606 xcmapi = xf + deltaxcmap
619
607 xcmapf = xcmapi + xcmapw
620 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
608
621 # Config Spectra plot
609 key = "colorbar"
622 szchar = 0.7
610 cmapObj = self.graphObjDict[key]
623 name = "spc"
611 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
624 key = name + "%d"%subplot
612
625 xrange = [xmin,xmax]
613 if self.__showPowerProfile:
626 yrange = [ymin,ymax]
614
627 zrange = [zmin,zmax]
615 xpowi = xcmapf + deltaxpow
628
616 xpowf = xpowi + xpoww
629 xpos,ypos = self.setSpectraPos()
630 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange)
631 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv")
632 self.pcolorObjDic[key] = pcolorObj
633
634 # Config Colorbar
635 if self.showColorbar:
636 szchar = 0.65
637 name = "colorbar"
638 key = name + "%d"%subplot
639
640 xpos,ypos = self.setColorbarScreenPos()
641 xrange = [0.,1.]
642 yrange = [zmin,zmax]
643 cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange)
644 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm")
645 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
646 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
647 self.colorbarObjDic[key] = cmapObj
648
649 # Config Power profile
650 if self.showPowerProfile:
651 szchar = 0.55
652 name = "pwprofile"
653 key = name + "%d"%subplot
617
654
618 key = "powerprof"
655 xpos,ypos = self.setPowerprofileScreenPos()
619 powObj = self.graphObjDict[key]
656 xrange = [zmin,zmax]
620 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
657 yrange = [ymin,ymax]
621
658 powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange)
622
659 powObj.setLineStyle(2)
660 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
661 powObj.setLineStyle(1)
662 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
663 self.pwprofileObjDic[key] = powObj
623
664
624 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, title = ''):
665 def printTitle(self,pltitle):
625 """
666 if self.__lastTitle != None:
626 Inputs:
667 setPlTitle(self.__lastTitle,"white")
627
668
628 x : Numpy array of dimension 1
669 self.__lastTitle = pltitle
629 y : Numpy array of dimension 1
630
670
631 """
671 setPlTitle(pltitle,"black")
632
672
633 try:
673 setSubpages(self.ncol,self.nrow)
634 nX, nY = numpy.shape(data)
635 except:
636 raise ValueError, "data is not a numpy array"
637
674
638 if x == None: x = numpy.arange(nX)
675 def plot(self,subplot,x,y,z,subtitle):
639 if y == None: y = numpy.arange(nY)
676 # Spectra plot
640
641 if xmin == None: xmin = x[0]
642 if xmax == None: xmax = x[-1]
643 if ymin == None: ymin = y[0]
644 if ymax == None: ymax = y[-1]
645 if zmin == None: zmin = numpy.nanmin(data)
646 if zmax == None: zmax = numpy.nanmax(data)
647
677
648 plplot.plschr(0.0, self.__szchar)
678 name = "spc"
649 self.__iniSubpage()
679 key = name + "%d"%subplot
650 self.colorGraphObj.title = title
651 self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax)
652 self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax)
653
680
654 if self.__showColorbar:
681 # newx = [x[0],x[-1]]
655
682 pcolorObj = self.pcolorObjDic[key]
656
683 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
657 key = "colorbar"
684 pcolorObj.delLabels()
658 cmapObj = self.graphObjDict[key]
685 pcolorObj.setLabels(title=subtitle)
659
660 plplot.plschr(0.0, self.__szchar-0.05)
661 cmapObj.plotBox(0., 1., zmin, zmax)
662 cmapObj.colorbarPlot(0., 1., zmin, zmax)
663
664 if self.__showPowerProfile:
665 power = numpy.average(data, axis=0)
666
667 step = (ymax - ymin)/(nY-1)
668 heis = numpy.arange(ymin, ymax + step, step)
669
670 key = "powerprof"
671 powObj = self.graphObjDict[key]
672
673 plplot.pllsty(2)
674 plplot.plschr(0.0, self.__szchar-0.05)
675 powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True)
676
677 plplot.pllsty(1)
678 plplot.plschr(0.0, self.__szchar)
679 powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc')
680
681 plplot.plcol0(9)
682 powObj.basicXYPlot(power, heis)
683 plplot.plcol0(1)
684
685
686
686 class ColorPlotX:
687 deltax = None; deltay = None
688
689 pcolorObj.advPcolorPlot(z,
690 x,
691 y,
692 xmin=pcolorObj.xrange[0],
693 xmax=pcolorObj.xrange[1],
694 ymin=pcolorObj.yrange[0],
695 ymax=pcolorObj.yrange[1],
696 zmin=pcolorObj.zrange[0],
697 zmax=pcolorObj.zrange[1],
698 deltax=deltax,
699 deltay=deltay,
700 getGrid=pcolorObj.getGrid)
701
702 pcolorObj.getGrid = False
703
704 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
705
706 # Power Profile
707 if self.showPowerProfile:
708 power = numpy.average(z, axis=0)
709 name = "pwprofile"
710 key = name + "%d"%subplot
711 powObj = self.pwprofileObjDic[key]
712
713 if powObj.setXYData() != None:
714 clearData(powObj)
715 else:
716 powObj.setXYData(power,y)
717
718 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
719 powObj.basicXYPlot(power,y)
720 powObj.setXYData(power,y)
721
722 def refresh(self):
723 plFlush()
687
724
725 class RtiPlot:
726
727 pcolorObjDic = {}
728 colorbarObjDic = {}
729 pwprofileObjDic = {}
730 showColorbar = None
731 showPowerProfile = None
732 XAxisAsTime = None
733 widht = None
734 height = None
735 __rtixpos = None
736 __rtiypos = None
737 __cmapxpos = None
738 __cmapypos = None
739 __profxpos = None
740 __profypos = None
741
742 def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
743 self.width = 700
744 self.height = 150
745 self.showColorbar = showColorbar
746 self.showPowerProfile = showPowerProfile
747 self.XAxisAsTime = XAxisAsTime
748
749 ncol = 1
750 nrow = nsubplot
751 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
752 setColormap(colormap)
688
753
689 graphObjDict = {}
754 def setFigure(self,indexPlot):
690 showColorbar = False
755 setStrm(indexPlot)
691 showPowerProfile = True
692
693 __szchar = 0.7
694 __xrange = None
695 __yrange = None
696 __zrange = None
697
698 colorGraphObj = BaseGraph()
699
756
700 def __init__(self):
757 def setRtiScreenPos(self):
701
758
702 key = "colorplot"
759 if self.showPowerProfile: xi = 0.07; xf = 0.65
703 self.colorGraphObj.setName(key)
760 else: xi = 0.07; xf = 0.9
704
761 yi = 0.15; yf = 0.80
705 self.__subpage = 0
706
707 self.graphObjDict[key] = self.colorGraphObj
708
709 def __iniSubpage(self):
710
762
711 if plplot.plgdev() == '':
763 xpos = [xi,xf]
712 raise ValueError, "Plot device has not been initialize"
764 ypos = [yi,yf]
713
765
714 plplot.pladv(self.__subpage)
766 self.__rtixpos = xpos
715 plplot.plschr(0.0, self.__szchar)
767 self.__rtiypos = ypos
716
768
717 setColormap(self.__colormap)
769 return xpos,ypos
718
770
719 def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06):
771 def setColorbarScreenPos(self):
720
772
721 if self.showColorbar:
773 xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03
722 xw -= xcmapw + deltaxcmap
723
724 if self.showPowerProfile:
725 xw -= xpoww + deltaxpow
726
774
727 xf = xi + xw
775 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
728 yf = yi + yw
729 xcmapf = xf
730
776
731 self.colorGraphObj.setScreenPos([xi, xf], [yi, yf])
777 xpos = [xi,xf]
778 ypos = [yi,yf]
732
779
733 if self.showColorbar:
780 self.__cmapxpos = xpos
734 xcmapi = xf + deltaxcmap
781 self.__cmapypos = ypos
735 xcmapf = xcmapi + xcmapw
782
736
783 return xpos,ypos
737 key = "colorbar"
738 cmapObj = self.graphObjDict[key]
739 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
740
741 if self.showPowerProfile:
742
743 xpowi = xcmapf + deltaxpow
744 xpowf = xpowi + xpoww
745
746 key = "powerprof"
747 powObj = self.graphObjDict[key]
748 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
749
784
750 def setRanges(self, xrange, yrange, zrange):
785 def setPowerprofileScreenPos(self):
751
752 self.colorGraphObj.setRanges(xrange, yrange, zrange)
753
754 keyList = self.graphObjDict.keys()
755
786
756 key = "colorbar"
787 xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20
757 if key in keyList:
758 cmapObj = self.graphObjDict[key]
759 cmapObj.setRanges([0., 1.], zrange)
760
761 key = "powerprof"
762 if key in keyList:
763 powObj = self.graphObjDict[key]
764 powObj.setRanges(zrange, yrange)
765
788
766 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
789 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
767 """
768 """
769
790
770 self.colorGraphObj.setSubpage(subpage)
791 xpos = [xi,xf]
771 self.colorGraphObj.setSzchar(self.__szchar)
792 ypos = [yi,yf]
772 self.colorGraphObj.setOpt("bcnts","bcntsv")
773 self.colorGraphObj.setup(title,
774 xlabel,
775 ylabel,
776 colormap)
777
793
778 if showColorbar:
794 self.__profxpos = [xi,xf]
779 key = "colorbar"
795 self.__profypos = [yi,yf]
780
796
781 cmapObj = BaseGraph()
797 return xpos,ypos
782 cmapObj.setName(key)
798
783 cmapObj.setSubpage(subpage)
799 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone="lt",npoints=100):
784 cmapObj.setSzchar(self.__szchar)
800 # Config Rti plot
785 cmapObj.setOpt("bc","bcmt")
801 szchar = 1.10
786 cmapObj.setup(title="dBs",
802 name = "rti"
787 xlabel="",
803 key = name + "%d"%subplot
788 ylabel="",
804
789 colormap=colormap)
805 # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal]
790
806 thisDateTime = datetime.datetime.fromtimestamp(timedata)
791 self.graphObjDict[key] = cmapObj
807 startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0)
792
808 endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59)
809 deltaTime = 0
810 if timezone == "lt":
811 deltaTime = time.timezone
812 startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime
813 endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime
814
815 xrange = [startTimeInSecs,endTimeInSecs]
816 totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1.
817 deltax = totalTimeInXrange / npoints
818
819 yrange = [ymin,ymax]
820 zrange = [zmin,zmax]
821
822 xpos,ypos = self.setRtiScreenPos()
823 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax)
824 if self.XAxisAsTime:
825 pcolorObj.setXAxisAsTime(self.XAxisAsTime)
826 xopt = "bcnstd"
827 yopt = "bcnstv"
828 else:
829 xopt = "bcnst"
830 yopt = "bcnstv"
831
832 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
833 self.pcolorObjDic[key] = pcolorObj
793
834
794 if showPowerProfile:
835
795 key = "powerprof"
836 # Config Colorbar
796
837 if self.showColorbar:
797 powObj = BaseGraph()
838 szchar = 0.9
798 powObj.setName(key)
839 name = "colorbar"
799 powObj.setSubpage(subpage)
840 key = name + "%d"%subplot
800 powObj.setSzchar(self.__szchar)
801 plplot.pllsty(2)
802 powObj.setOpt("bcntg","bc")
803 plplot.pllsty(1)
804 powObj.setup(title="Power Profile",
805 xlabel="dBs",
806 ylabel="")
807
808 self.graphObjDict[key] = powObj
809
841
810 self.showColorbar = showColorbar
842 xpos,ypos = self.setColorbarScreenPos()
811 self.showPowerProfile = showPowerProfile
843 xrange = [0.,1.]
812 self.setScreenPos()
844 yrange = [zmin,zmax]
845 cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange)
846 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm")
847 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
848 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
849 self.colorbarObjDic[key] = cmapObj
813
850
814 if XAxisAsTime:
815 self.colorGraphObj.setXAxisAsTime()
816 #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02)
817
818
819 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
820 """
821 """
822
823 try:
824 nX, nY = numpy.shape(data)
825 except:
826 raise ValueError, "data is not a numpy array"
827
828 if x == None: x = numpy.arange(nX)
829 if y == None: y = numpy.arange(nY)
830
831 if xmin == None: xmin = x[0]
832 if xmax == None: xmax = x[-1]
833 if ymin == None: ymin = y[0]
834 if ymax == None: ymax = y[-1]
835 if zmin == None: zmin = numpy.nanmin(data)
836 if zmax == None: zmax = numpy.nanmax(data)
837
838 if self.colorGraphObj.hasNotRange:
839 self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax])
840
841 self.colorGraphObj.initSubpage()
842 self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.colorGraphObj.zrange[0], self.colorGraphObj.zrange[1])
843
844 if self.showColorbar:
845 key = "colorbar"
846 cmapObj = self.graphObjDict[key]
847 cmapObj.colorbarPlot()
848
851
852 # Config Power profile
849 if self.showPowerProfile:
853 if self.showPowerProfile:
850 power = numpy.average(data, axis=1)
854 szchar = 0.8
851
855 name = "pwprofile"
852 step = (ymax - ymin)/(nY-1)
856 key = name + "%d"%subplot
853 heis = numpy.arange(ymin, ymax + step, step)
857
854
858 xpos,ypos = self.setPowerprofileScreenPos()
855 key = "powerprof"
859 xrange = [zmin,zmax]
856 powObj = self.graphObjDict[key]
860 yrange = [ymin,ymax]
857 powObj.basicXYPlot(power, heis)
861 powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange)
858
862 powObj.setLineStyle(2)
859 if __name__ == '__main__':
863 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
860
864 powObj.setLineStyle(1)
861 import numpy
865 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
862 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
866 self.pwprofileObjDic[key] = powObj
863 plplot.plsdev("xwin")
864 plplot.plscolbg(255,255,255)
865 plplot.plscol0(1,0,0,0)
866 plplot.plspause(False)
867 plplot.plinit()
868 plplot.plssub(2, 2)
869
870 nx = 64
871 ny = 100
872
873 data = numpy.random.uniform(-50,50,(nx,ny))
874
875 baseObj = ColorPlot()
876 specObj = ColorPlot()
877 baseObj1 = ColorPlot()
878 specObj1 = ColorPlot()
879
880 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True)
881 specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True)
882
867
883 baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True)
884 specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True)
885
886 data = numpy.random.uniform(-50,50,(nx,ny))
887
888 plplot.plbop()
889 baseObj.plotData(data)
890
891 specObj.plotData(data)
892
893 baseObj1.plotData(data)
894
895 specObj1.plotData(data)
896
868
897 plplot.plflush()
869 def plot(self,subplot,x,y,z):
898
870 # RTI plot
899 plplot.plspause(1)
871 name = "rti"
900 plplot.plend()
872 key = name + "%d"%subplot
901 exit(0)
873
902
874 data = numpy.reshape(z, (1,-1))
903
875 data = numpy.abs(data)
876 data = 10*numpy.log10(data)
877 newx = [x,x+1]
878
879 pcolorObj = self.pcolorObjDic[key]
880
881 if pcolorObj.xaxisIsTime:
882 xopt = "bcstd"
883 yopt = "bcst"
884 else:
885 xopt = "bcst"
886 yopt = "bcst"
887
888 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
889
890 deltax = pcolorObj.deltax
891 deltay = None
892
893 if pcolorObj.xmin == None and pcolorObj.xmax == None:
894 pcolorObj.xmin = x
895 pcolorObj.xmax = x
896
897 if x >= pcolorObj.xmax:
898 xmin = x
899 xmax = x + deltax
900 x = [x]
901 pcolorObj.advPcolorPlot(data,
902 x,
903 y,
904 xmin=xmin,
905 xmax=xmax,
906 ymin=pcolorObj.yrange[0],
907 ymax=pcolorObj.yrange[1],
908 zmin=pcolorObj.zrange[0],
909 zmax=pcolorObj.zrange[1],
910 deltax=deltax,
911 deltay=deltay,
912 getGrid=pcolorObj.getGrid)
913
914 pcolorObj.xmin = xmin
915 pcolorObj.xmax = xmax
916
917
918 # Power Profile
919 if self.showPowerProfile:
920 data = numpy.reshape(data,(numpy.size(data)))
921 name = "pwprofile"
922 key = name + "%d"%subplot
923 powObj = self.pwprofileObjDic[key]
924
925 if powObj.setXYData() != None:
926 clearData(powObj)
927 powObj.setLineStyle(2)
928 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
929 powObj.setLineStyle(1)
930 else:
931 powObj.setXYData(data,y)
932
933 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
934 powObj.basicXYPlot(data,y)
935 powObj.setXYData(data,y)
936
937 def refresh(self):
938 plFlush() No newline at end of file
@@ -1,204 +1,119
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
9 import numpy
8 import numpy
10 import datetime
9 import os
10 import sys
11 import plplot
11 import plplot
12 import datetime
12
13
13 path = os.path.split(os.getcwd())[0]
14 path = os.path.split(os.getcwd())[0]
14 sys.path.append(path)
15 sys.path.append(path)
15
16
16 from Graphics.BaseGraph import *
17 from Graphics.BaseGraph import *
17 from Model.Spectra import Spectra
18 from Model.Spectra import Spectra
18
19
19 class Spectrum:
20 class Spectrum:
20
21 colorplotObj = None
21 __isPlotConfig = False
22
23 __isPlotIni = False
24
25 __xrange = None
26
27 __yrange = None
28
29 nGraphs = 0
30
22
31 indexPlot = None
23 def __init__(self,Spectra, index):
32
33 graphObjList = []
34
35 spectraObj = Spectra
36
37 colorGraphObj = ColorPlot()
38 m_Spectra= Spectra()
39
40
41 m_ColorPlot= ColorPlot()
42
43
44
45
46
47 def __init__(self, Spectra, index=0):
48
49 """
50
51 Inputs:
52
53 type: "power" ->> Potencia
54 "iq" ->> Real + Imaginario
55 """
56
57 self.__isPlotConfig = False
24 self.__isPlotConfig = False
58
59 self.__isPlotIni = False
25 self.__isPlotIni = False
60
61 self.__xrange = None
26 self.__xrange = None
62
63 self.__yrange = None
27 self.__yrange = None
64
65 self.nGraphs = 0
28 self.nGraphs = 0
66
67 self.indexPlot = index
29 self.indexPlot = index
68
69 self.graphObjList = []
70
71 self.spectraObj = Spectra
30 self.spectraObj = Spectra
72
73
31
74 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
32 def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False):
75
33 self.colorplotObj = SpectraPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime)
76 graphObj = ColorPlot()
77 graphObj.setup(subpage,
78 title,
79 xlabel,
80 ylabel,
81 showColorbar=showColorbar,
82 showPowerProfile=showPowerProfile,
83 XAxisAsTime=XAxisAsTime)
84
85 self.graphObjList.append(graphObj)
86
87
34
88 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
35 def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList):
89
36 nsubplot = self.spectraObj.nChannels
90 nChan = int(self.spectraObj.m_SystemHeader.numChannels)
91 channels = range(nChan)
92
93 myXlabel = "Radial Velocity (m/s)"
94 myYlabel = "Range (km)"
95
96 for i in channels:
97 if titleList != None:
98 myTitle = titleList[i]
99 myXlabel = xlabelList[i]
100 myYlabel = ylabelList[i]
101
102 # if self.spectraObj.m_NoiseObj != None:
103 # noise = '%4.2fdB' %(self.spectraObj.m_NoiseObj[i])
104 # else:
105 noise = '--'
106
107 myTitle = "Channel: %d - Noise: %s" %(i, noise)
108
109 self.__addGraph(i+1,
110 title=myTitle,
111 xlabel=myXlabel,
112 ylabel=myYlabel,
113 showColorbar=showColorbar,
114 showPowerProfile=showPowerProfile,
115 XAxisAsTime=XAxisAsTime)
116
37
117 self.nGraphs = nChan
38 for index in range(nsubplot):
118 self.__isPlotConfig = True
39 title = titleList[index]
40 xlabel = xlabelList[index]
41 ylabel = ylabelList[index]
42 subplot = index
43 self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
119
44
120 def iniPlot(self, winTitle=""):
45
46 def plotData(self,
47 xmin=None,
48 xmax=None,
49 ymin=None,
50 ymax=None,
51 zmin=None,
52 zmax=None,
53 titleList=None,
54 xlabelList=None,
55 ylabelList=None,
56 winTitle='',
57 colormap = "br_green",
58 showColorbar = True,
59 showPowerProfile = True,
60 XAxisAsTime = False):
61
62 databuffer = 10.*numpy.log10(self.spectraObj.data_spc)
63 noise = 10.*numpy.log10(self.spectraObj.noise)
121
64
122 nx = int(numpy.sqrt(self.nGraphs)+1)
65 nsubplot = self.spectraObj.nChannels
123 #ny = int(self.nGraphs/nx)
66 nsubplot, nX, nY = numpy.shape(databuffer)
124
67
125 plplot.plsstrm(self.indexPlot)
68 x = numpy.arange(nX)
126 plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL)
69 y = self.spectraObj.heightList
127 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
128 plplot.plsdev("xwin")
129 plplot.plscolbg(255,255,255)
130 plplot.plscol0(1,0,0,0)
131 plplot.plinit()
132 plplot.plspause(False)
133 plplot.pladv(0)
134 plplot.plssub(nx, nx)
135
70
136 self.__nx = nx
71 indexPlot = self.indexPlot
137 self.__ny = nx
138 self.__isPlotIni = True
139
140
141 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False, winTitle="Spectra"):
142
72
143 if not(self.__isPlotConfig):
73 if not(self.__isPlotConfig):
144 self.setup(titleList,
74 self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime)
145 xlabelList,
75 self.__isPlotConfig = True
146 ylabelList,
147 showColorbar,
148 showPowerProfile,
149 XAxisAsTime)
150
76
151 if not(self.__isPlotIni):
77 if not(self.__isPlotIni):
152 self.iniPlot(winTitle)
78 if titleList == None:
153
79 titleList = []
154 plplot.plsstrm(self.indexPlot)
80 for i in range(nsubplot):
155
81 titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i]))
156 data = 10.*numpy.log10(self.spectraObj.data_spc)
82
157 noise = 10.*numpy.log10(self.spectraObj.noise)
83 if xlabelList == None:
158 #data.shape = Channels x Heights x Profiles
84 xlabelList = []
159 # data = numpy.transpose( data, (0,2,1) )
85 for i in range(nsubplot):
160 #data.shape = Channels x Profiles x Heights
86 xlabelList.append("")
161
87
162 nChan, nX, nY = numpy.shape(data)
88 if ylabelList == None:
89 ylabelList = []
90 for i in range(nsubplot):
91 ylabelList.append("Range (Km)")
92
93 if xmin == None: xmin = x[0]
94 if xmax == None: xmax = x[-1]
95 if ymin == None: ymin = y[0]
96 if ymax == None: ymax = y[-1]
97 if zmin == None: zmin = 0
98 if zmax == None: zmax = 120
99
100 self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList)
101 self.__isPlotIni = True
163
102
164 x = numpy.arange(nX)
103 self.colorplotObj.setFigure(indexPlot)
165 y = self.spectraObj.heightList
166
104
167 thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc)
105 thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc)
168 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
106 pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
169
107
170 if xmin == None: xmin = x[0]
108 self.colorplotObj.printTitle(pltitle) #setPlTitle(pltitle)
171 if xmax == None: xmax = x[-1]
172 if ymin == None: ymin = y[0]
173 if ymax == None: ymax = y[-1]
174 if zmin == None: zmin = numpy.nanmin(abs(data))
175 if zmax == None: zmax = numpy.nanmax(abs(data))
176
109
177 plplot.plbop()
110 for index in range(nsubplot):
111 data = databuffer[index,:,:]
112 subtitle = "Channel: %d - Noise: %.2f" %(index, noise[index])
113 self.colorplotObj.plot(index+1,x,y,data,subtitle)
178
114
179 plplot.plssub(self.__nx, self.__ny)
180 for i in range(self.nGraphs):
181 self.graphObjList[i].plotData(data[i,:,:],
182 x,
183 y,
184 xmin=xmin,
185 xmax=xmax,
186 ymin=ymin,
187 ymax=ymax,
188 zmin=zmin,
189 zmax=zmax,
190 title = "Channel: %d - Noise: %.2f" %(i, noise[i]))
191
115
192 plplot.plssub(1,0)
116
193 plplot.pladv(0)
117 self.colorplotObj.refresh()
194 plplot.plvpor(0., 1., 0., 1.)
118
195 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
196 plplot.plflush()
197 plplot.pleop()
198
199 def end(self):
200 plplot.plend()
201
202
119
203 if __name__ == '__main__':
204 pass No newline at end of file
@@ -1,204 +1,197
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import os, sys
8 import numpy
7 import numpy
9 import plplot
8 import os
9 import sys
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Graphics.BaseGraph import *
14 from Graphics.BaseGraph import *
15 from Model.Voltage import Voltage
15 from Model.Voltage import Voltage
16
16
17 class Osciloscope:
17 class Osciloscope:
18 linearplotObj = None
18
19
19 voltageObj = Voltage()
20 def __init__(self, Voltage, index):
21 self.__isPlotConfig = False
22 self.__isPlotIni = False
23 self.__xrange = None
24 self.__yrange = None
25 self.indexPlot = index
26 self.voltageObj = Voltage
20
27
21 linearGraphObj = LinearPlot()
28 def setup(self,indexPlot,nsubplot,winTitle=''):
29 self.linearplotObj = LinearPlot(indexPlot,nsubplot,winTitle)
22
30
23 __isPlotConfig = False
31 def initPlot(self,xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList):
32 nsubplot = self.voltageObj.nChannels
24
33
25 __isPlotIni = False
34 for index in range(nsubplot):
26
35 title = titleList[index]
27 __xrange = None
36 xlabel = xlabelList[index]
28
37 ylabel = ylabelList[index]
29 __yrange = None
38 subplot = index
30
39 self.linearplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,title,xlabel,ylabel)
31 voltageObj = Voltage()
32
33 nGraphs = 0
34
40
35 indexPlot = None
41 def plotData(self,
36
42 xmin=None,
37 graphObjList = []
43 xmax=None,
38 m_LinearPlot= LinearPlot()
44 ymin=None,
39
45 ymax=None,
40
46 titleList=None,
41 m_Voltage= Voltage()
47 xlabelList=None,
42
48 ylabelList=None,
43
49 winTitle='',
50 type="power"):
44
51
45 def __init__(self, Voltage, index=0):
52 databuffer = self.voltageObj.data
46
53
47 """
54 height = self.voltageObj.heightList
55 nsubplot = self.voltageObj.nChannels
56 indexPlot = self.indexPlot
48
57
49 Inputs:
50
51 type: "power" ->> Potencia
52 "iq" ->> Real + Imaginario
53 """
54
55 self.__isPlotConfig = False
56
58
57 self.__isPlotIni = False
59 if not(self.__isPlotConfig):
58
60 self.setup(indexPlot,nsubplot,winTitle)
59 self.__xrange = None
61 self.__isPlotConfig = True
60
62
61 self.__yrange = None
63 if not(self.__isPlotIni):
64 if titleList == None:
65 titleList = []
66 thisDatetime = datetime.datetime.fromtimestamp(self.voltageObj.m_BasicHeader.utc)
67 txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y"))
68 for i in range(nsubplot):
69 titleList.append("Channel: %d %s" %(i, txtdate))
70
71 if xlabelList == None:
72 xlabelList = []
73 for i in range(nsubplot):
74 xlabelList.append("")
75
76 if ylabelList == None:
77 ylabelList = []
78 for i in range(nsubplot):
79 ylabelList.append("")
80
81 if xmin == None: xmin = height[0]
82 if xmax == None: xmax = height[-1]
83 if ymin == None: ymin = numpy.nanmin(abs(databuffer))
84 if ymax == None: ymax = numpy.nanmax(abs(databuffer))
85
86 self.initPlot(xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList)
87 self.__isPlotIni = True
62
88
63 self.voltageObj = None
89 self.linearplotObj.setFigure(indexPlot)
64
90
65 self.nGraphs = 0
91 for index in range(nsubplot):
92 data = databuffer[index,:]
93 self.linearplotObj.plot(subplot=index+1,x=height,y=data,type=type)
66
94
67 self.indexPlot = index
95 self.linearplotObj.refresh()
68
96
69 self.graphObjList = []
70
97
71 self.voltageObj = Voltage
72
98
73
99
74 def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False):
75
100
76 graphObj = LinearPlot()
101
77 graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False)
78 #graphObj.setScreenPos()
79
80 self.graphObjList.append(graphObj)
81
102
82 del graphObj
83
84 # def setXRange(self, xmin, xmax):
85 # self.__xrange = (xmin, xmax)
86 #
87 # def setYRange(self, ymin, ymax):
88 # self.__yrange = (ymin, ymax)
89
103
104 class RTI:
105 colorplotObj = None
90
106
91 def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False):
107 def __init__(self, Voltage, index):
92
108 self.__isPlotConfig = False
93 nChan = int(self.voltageObj.m_SystemHeader.numChannels)
109 self.__isPlotIni = False
94
110 self.__xrange = None
95 myTitle = ""
111 self.__yrange = None
96 myXlabel = ""
112 self.indexPlot = index
97 myYlabel = ""
113 self.voltageObj = Voltage
98
114
99 for chan in range(nChan):
115 def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False):
100 if titleList != None:
116 self.colorplotObj = RtiPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime)
101 myTitle = titleList[chan]
117
102 myXlabel = xlabelList[chan]
118 def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints):
103 myYlabel = ylabelList[chan]
119
104
120 nsubplot = self.voltageObj.nChannels
105 self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime)
121 timedata = self.voltageObj.m_BasicHeader.utc
106
122
107 self.nGraphs = nChan
123 for index in range(nsubplot):
108 self.__isPlotConfig = True
124 title = titleList[index]
109
125 xlabel = xlabelList[index]
110 def iniPlot(self, winTitle=""):
126 ylabel = ylabelList[index]
111
127 subplot = index
112 plplot.plsstrm(self.indexPlot)
128 self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone,npoints)
113 plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL)
129
114 plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs))
130 def plotData(self,
115 plplot.plsdev("xwin")
131 xmin=None,
116 plplot.plscolbg(255,255,255)
132 xmax=None,
117 plplot.plscol0(1,0,0,0)
133 ymin=None,
118 plplot.plinit()
134 ymax=None,
119 plplot.plspause(False)
135 zmin=None,
120 plplot.plssub(1, self.nGraphs)
136 zmax=None,
121
137 titleList=None,
122 self.__isPlotIni = True
138 xlabelList=None,
123
139 ylabelList=None,
124 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"):
140 winTitle='',
125
141 timezone='lt',
142 npoints=1000.0,
143 colormap="br_green",
144 showColorbar=True,
145 showPowerProfile=True,
146 XAxisAsTime=True):
147
148 databuffer = self.voltageObj.data
149 timedata = self.voltageObj.m_BasicHeader.utc
150 height = self.voltageObj.heightList
151 nsubplot = self.voltageObj.nChannels
152 indexPlot = self.indexPlot
153
126 if not(self.__isPlotConfig):
154 if not(self.__isPlotConfig):
127 self.setup(titleList, xlabelList, ylabelList, XAxisAsTime)
155 self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime)
128
156 self.__isPlotConfig = True
157
129 if not(self.__isPlotIni):
158 if not(self.__isPlotIni):
130 self.iniPlot(winTitle)
159 if titleList == None:
131
160 titleList = []
132 plplot.plsstrm(self.indexPlot)
161 thisDatetime = datetime.datetime.fromtimestamp(timedata)
133
162 txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y"))
134 data = self.voltageObj.data
163 for i in range(nsubplot):
135
164 titleList.append("Channel: %d %s" %(i, txtdate))
136 x = self.voltageObj.heightList
165
166 if xlabelList == None:
167 xlabelList = []
168 for i in range(nsubplot):
169 xlabelList.append("")
170
171 if ylabelList == None:
172 ylabelList = []
173 for i in range(nsubplot):
174 ylabelList.append("")
175
176 if xmin == None: xmin = 0
177 if xmax == None: xmax = 23
178 if ymin == None: ymin = min(self.voltageObj.heightList)
179 if ymax == None: ymax = max(self.voltageObj.heightList)
180 if zmin == None: zmin = 0
181 if zmax == None: zmax = 50
182
183
184 self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints)
185 self.__isPlotIni = True
137
186
138 if xmin == None: xmin = x[0]
187
139 if xmax == None: xmax = x[-1]
188 self.colorplotObj.setFigure(indexPlot)
140 if ymin == None: ymin = numpy.nanmin(abs(data))
141 if ymax == None: ymax = numpy.nanmax(abs(data))
142
189
143 plplot.plbop()
190 if timezone == 'lt':
144 for chan in range(self.nGraphs):
191 timedata = timedata - time.timezone
145 y = data[chan,:]
146
147 self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type)
148
192
149 plplot.plflush()
193 for index in range(nsubplot):
150 plplot.pleop()
194 data = databuffer[index,:]
151
195 self.colorplotObj.plot(subplot=index+1,x=timedata,y=height,z=data)
152 def end(self):
153 plplot.plend()
154
196
155 class VoltagePlot(object):
197 self.colorplotObj.refresh()
156 '''
157 classdocs
158 '''
159
160 __m_Voltage = None
161
162 def __init__(self, voltageObj):
163 '''
164 Constructor
165 '''
166 self.__m_Voltage = voltageObj
167
168 def setup(self):
169 pass
170
171 def addGraph(self, type, xrange=None, yrange=None, zrange=None):
172 pass
173
174 def plotData(self):
175 pass
176
177 if __name__ == '__main__':
178
179 import numpy
180
181 plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2))
182 plplot.plsdev("xcairo")
183 plplot.plscolbg(255,255,255)
184 plplot.plscol0(1,0,0,0)
185 plplot.plinit()
186 plplot.plssub(1, 2)
187
188 nx = 64
189 ny = 100
190
191 data = numpy.random.uniform(-50,50,(nx,ny))
192
193 baseObj = RTI()
194 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False)
195 baseObj.plotData(data)
196
197 data = numpy.random.uniform(-50,50,(nx,ny))
198
199 base2Obj = RTI()
200 base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True)
201 base2Obj.plotData(data)
202
203 plplot.plend()
204 exit(0) No newline at end of file
@@ -1,660 +1,687
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9
9
10 path = os.path.split(os.getcwd())[0]
10 path = os.path.split(os.getcwd())[0]
11 sys.path.append(path)
11 sys.path.append(path)
12
12
13 from Model.Spectra import Spectra
13 from Model.Spectra import Spectra
14 from IO.SpectraIO import SpectraWriter
14 from IO.SpectraIO import SpectraWriter
15 from Graphics.SpectraPlot import Spectrum
15 from Graphics.SpectraPlot import Spectrum
16 from JRONoise import Noise
16 from JRONoise import Noise
17
17
18 class SpectraProcessor:
18 class SpectraProcessor:
19 '''
19 '''
20 classdocs
20 classdocs
21 '''
21 '''
22
22
23 dataInObj = None
23 dataInObj = None
24
24
25 dataOutObj = None
25 dataOutObj = None
26
26
27 noiseObj = None
27 noiseObj = None
28
28
29 integratorObjList = []
29 integratorObjList = []
30
30
31 decoderObjList = []
31 decoderObjList = []
32
32
33 writerObjList = []
33 writerObjList = []
34
34
35 plotterObjList = []
35 plotterObjList = []
36
36
37 integratorObjIndex = None
37 integratorObjIndex = None
38
38
39 decoderObjIndex = None
39 decoderObjIndex = None
40
40
41 writerObjIndex = None
41 writerObjIndex = None
42
42
43 plotterObjIndex = None
43 plotterObjIndex = None
44
44
45 buffer = None
45 buffer = None
46
46
47 profIndex = 0
47 profIndex = 0
48
48
49 nFFTPoints = None
49 nFFTPoints = None
50
50
51 nChannels = None
51 nChannels = None
52
52
53 nHeights = None
53 nHeights = None
54
54
55 nPairs = None
55 nPairs = None
56
56
57 pairList = None
57 pairList = None
58
58
59
59
60 def __init__(self):
60 def __init__(self):
61 '''
61 '''
62 Constructor
62 Constructor
63 '''
63 '''
64
64
65 self.integratorObjIndex = None
65 self.integratorObjIndex = None
66 self.decoderObjIndex = None
66 self.decoderObjIndex = None
67 self.writerObjIndex = None
67 self.writerObjIndex = None
68 self.plotterObjIndex = None
68 self.plotterObjIndex = None
69
69
70 self.integratorObjList = []
70 self.integratorObjList = []
71 self.decoderObjList = []
71 self.decoderObjList = []
72 self.writerObjList = []
72 self.writerObjList = []
73 self.plotterObjList = []
73 self.plotterObjList = []
74
74
75 self.noiseObj = Noise()
75 self.noiseObj = Noise()
76 self.buffer = None
76 self.buffer = None
77 self.profIndex = 0
77 self.profIndex = 0
78
78
79 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
79 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
80
80
81 if dataInObj == None:
81 if dataInObj == None:
82 raise ValueError, ""
82 raise ValueError, ""
83
83
84 if nFFTPoints == None:
84 if nFFTPoints == None:
85 raise ValueError, ""
85 raise ValueError, ""
86
86
87 self.dataInObj = dataInObj
87 self.dataInObj = dataInObj
88
88
89 if dataOutObj == None:
89 if dataOutObj == None:
90 dataOutObj = Spectra()
90 dataOutObj = Spectra()
91
91
92 self.dataOutObj = dataOutObj
92 self.dataOutObj = dataOutObj
93 self.noiseObj = Noise()
93 self.noiseObj = Noise()
94
94
95 ##########################################
95 ##########################################
96 self.nFFTPoints = nFFTPoints
96 self.nFFTPoints = nFFTPoints
97 self.nChannels = self.dataInObj.nChannels
97 self.nChannels = self.dataInObj.nChannels
98 self.nHeights = self.dataInObj.nHeights
98 self.nHeights = self.dataInObj.nHeights
99 self.pairList = pairList
99 self.pairList = pairList
100 if pairList != None:
100 if pairList != None:
101 self.nPairs = len(pairList)
101 self.nPairs = len(pairList)
102 else:
102 else:
103 self.nPairs = 0
103 self.nPairs = 0
104
104
105 self.dataOutObj.heightList = self.dataInObj.heightList
105 self.dataOutObj.heightList = self.dataInObj.heightList
106 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
106 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
107 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
107 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
108 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
108 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
109 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
109 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
110 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
110 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
111
111
112 self.dataOutObj.dataType = self.dataInObj.dataType
112 self.dataOutObj.dataType = self.dataInObj.dataType
113 self.dataOutObj.nPairs = self.nPairs
113 self.dataOutObj.nPairs = self.nPairs
114 self.dataOutObj.nChannels = self.nChannels
114 self.dataOutObj.nChannels = self.nChannels
115 self.dataOutObj.nProfiles = self.nFFTPoints
115 self.dataOutObj.nProfiles = self.nFFTPoints
116 self.dataOutObj.nHeights = self.nHeights
116 self.dataOutObj.nHeights = self.nHeights
117 self.dataOutObj.nFFTPoints = self.nFFTPoints
117 self.dataOutObj.nFFTPoints = self.nFFTPoints
118 #self.dataOutObj.data = None
118 #self.dataOutObj.data = None
119
119
120 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
120 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
121 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
121 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
122
122
123 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
123 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
124 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
124 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
125 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
125 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
126 self.dataOutObj.m_ProcessingHeader.shif_fft = True
126 self.dataOutObj.m_ProcessingHeader.shif_fft = True
127
127
128 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
128 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
129 k = 0
129 k = 0
130 for i in range( 0,self.nChannels*2,2 ):
130 for i in range( 0,self.nChannels*2,2 ):
131 spectraComb[i] = k
131 spectraComb[i] = k
132 spectraComb[i+1] = k
132 spectraComb[i+1] = k
133 k += 1
133 k += 1
134
134
135 k *= 2
135 k *= 2
136
136
137 if self.pairList != None:
137 if self.pairList != None:
138
138
139 for pair in self.pairList:
139 for pair in self.pairList:
140 spectraComb[k] = pair[0]
140 spectraComb[k] = pair[0]
141 spectraComb[k+1] = pair[1]
141 spectraComb[k+1] = pair[1]
142 k += 2
142 k += 2
143
143
144 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
144 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
145
145
146 return self.dataOutObj
146 return self.dataOutObj
147
147
148 def init(self):
148 def init(self):
149
149
150 self.integratorObjIndex = 0
150 self.integratorObjIndex = 0
151 self.decoderObjIndex = 0
151 self.decoderObjIndex = 0
152 self.writerObjIndex = 0
152 self.writerObjIndex = 0
153 self.plotterObjIndex = 0
153 self.plotterObjIndex = 0
154
154
155 if self.dataInObj.type == "Voltage":
155 if self.dataInObj.type == "Voltage":
156
156
157 if self.buffer == None:
157 if self.buffer == None:
158 self.buffer = numpy.zeros((self.nChannels,
158 self.buffer = numpy.zeros((self.nChannels,
159 self.nFFTPoints,
159 self.nFFTPoints,
160 self.nHeights),
160 self.nHeights),
161 dtype='complex')
161 dtype='complex')
162
162
163 self.buffer[:,self.profIndex,:] = self.dataInObj.data
163 self.buffer[:,self.profIndex,:] = self.dataInObj.data
164 self.profIndex += 1
164 self.profIndex += 1
165
165
166 if self.profIndex == self.nFFTPoints:
166 if self.profIndex == self.nFFTPoints:
167 self.__getFft()
167 self.__getFft()
168 self.dataOutObj.flagNoData = False
168 self.dataOutObj.flagNoData = False
169
169
170 self.buffer = None
170 self.buffer = None
171 self.profIndex = 0
171 self.profIndex = 0
172 return
172 return
173
173
174 self.dataOutObj.flagNoData = True
174 self.dataOutObj.flagNoData = True
175
175
176 return
176 return
177
177
178 #Other kind of data
178 #Other kind of data
179 if self.dataInObj.type == "Spectra":
179 if self.dataInObj.type == "Spectra":
180 self.dataOutObj.copy(self.dataInObj)
180 self.dataOutObj.copy(self.dataInObj)
181 self.dataOutObj.flagNoData = False
181 self.dataOutObj.flagNoData = False
182 return
182 return
183
183
184 raise ValueError, "The datatype is not valid"
184 raise ValueError, "The datatype is not valid"
185
185
186 def __getFft(self):
186 def __getFft(self):
187 """
187 """
188 Convierte valores de Voltaje a Spectra
188 Convierte valores de Voltaje a Spectra
189
189
190 Affected:
190 Affected:
191 self.dataOutObj.data_spc
191 self.dataOutObj.data_spc
192 self.dataOutObj.data_cspc
192 self.dataOutObj.data_cspc
193 self.dataOutObj.data_dc
193 self.dataOutObj.data_dc
194 self.dataOutObj.heightList
194 self.dataOutObj.heightList
195 self.dataOutObj.m_BasicHeader
195 self.dataOutObj.m_BasicHeader
196 self.dataOutObj.m_ProcessingHeader
196 self.dataOutObj.m_ProcessingHeader
197 self.dataOutObj.m_RadarControllerHeader
197 self.dataOutObj.m_RadarControllerHeader
198 self.dataOutObj.m_SystemHeader
198 self.dataOutObj.m_SystemHeader
199 self.profIndex
199 self.profIndex
200 self.buffer
200 self.buffer
201 self.dataOutObj.flagNoData
201 self.dataOutObj.flagNoData
202 self.dataOutObj.dataType
202 self.dataOutObj.dataType
203 self.dataOutObj.nPairs
203 self.dataOutObj.nPairs
204 self.dataOutObj.nChannels
204 self.dataOutObj.nChannels
205 self.dataOutObj.nProfiles
205 self.dataOutObj.nProfiles
206 self.dataOutObj.m_SystemHeader.numChannels
206 self.dataOutObj.m_SystemHeader.numChannels
207 self.dataOutObj.m_ProcessingHeader.totalSpectra
207 self.dataOutObj.m_ProcessingHeader.totalSpectra
208 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
208 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
209 self.dataOutObj.m_ProcessingHeader.numHeights
209 self.dataOutObj.m_ProcessingHeader.numHeights
210 self.dataOutObj.m_ProcessingHeader.spectraComb
210 self.dataOutObj.m_ProcessingHeader.spectraComb
211 self.dataOutObj.m_ProcessingHeader.shif_fft
211 self.dataOutObj.m_ProcessingHeader.shif_fft
212 """
212 """
213 if self.dataInObj.flagNoData:
213 if self.dataInObj.flagNoData:
214 return 0
214 return 0
215
215
216 fft_volt = numpy.fft.fft(self.buffer,axis=1)
216 fft_volt = numpy.fft.fft(self.buffer,axis=1)
217 dc = fft_volt[:,0,:]
217 dc = fft_volt[:,0,:]
218
218
219 #calculo de self-spectra
219 #calculo de self-spectra
220 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
220 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
221 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
221 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
222
222
223 blocksize = 0
223 blocksize = 0
224 blocksize += dc.size
224 blocksize += dc.size
225 blocksize += spc.size
225 blocksize += spc.size
226
226
227 cspc = None
227 cspc = None
228 pairIndex = 0
228 pairIndex = 0
229 if self.pairList != None:
229 if self.pairList != None:
230 #calculo de cross-spectra
230 #calculo de cross-spectra
231 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
231 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
232 for pair in self.pairList:
232 for pair in self.pairList:
233 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
233 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
234 pairIndex += 1
234 pairIndex += 1
235 blocksize += cspc.size
235 blocksize += cspc.size
236
236
237 self.dataOutObj.data_spc = spc
237 self.dataOutObj.data_spc = spc
238 self.dataOutObj.data_cspc = cspc
238 self.dataOutObj.data_cspc = cspc
239 self.dataOutObj.data_dc = dc
239 self.dataOutObj.data_dc = dc
240 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
240 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
241 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
241
242
242
243
243 def addWriter(self,wrpath):
244 def addWriter(self,wrpath):
244 objWriter = SpectraWriter(self.dataOutObj)
245 objWriter = SpectraWriter(self.dataOutObj)
245 objWriter.setup(wrpath)
246 objWriter.setup(wrpath)
246 self.writerObjList.append(objWriter)
247 self.writerObjList.append(objWriter)
247
248
248
249 def addPlotter(self,index=None):
249 def addPlotter(self, index=None):
250
251 if index==None:
250 if index==None:
252 index = self.plotterObjIndex
251 index = self.plotterObjIndex
253
252
254 plotObj = Spectrum(self.dataOutObj, index)
253 plotObj = Spectrum(self.dataOutObj, index)
255 self.plotterObjList.append(plotObj)
254 self.plotterObjList.append(plotObj)
256
257
255
258 def addIntegrator(self,N,timeInterval):
256 def addIntegrator(self,N,timeInterval):
259
257
260 objIncohInt = IncoherentIntegration(N,timeInterval)
258 objIncohInt = IncoherentIntegration(N,timeInterval)
261 self.integratorObjList.append(objIncohInt)
259 self.integratorObjList.append(objIncohInt)
262
260
263 def writeData(self, wrpath):
261 def writeData(self, wrpath):
264 if self.dataOutObj.flagNoData:
262 if self.dataOutObj.flagNoData:
265 return 0
263 return 0
266
264
267 if len(self.writerObjList) <= self.writerObjIndex:
265 if len(self.writerObjList) <= self.writerObjIndex:
268 self.addWriter(wrpath)
266 self.addWriter(wrpath)
269
267
270 self.writerObjList[self.writerObjIndex].putData()
268 self.writerObjList[self.writerObjIndex].putData()
271
269
272 self.writerObjIndex += 1
270 self.writerObjIndex += 1
273
271
274 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
272 def plotData(self,
273 xmin=None,
274 xmax=None,
275 ymin=None,
276 ymax=None,
277 zmin=None,
278 zmax=None,
279 titleList=None,
280 xlabelList=None,
281 ylabelList=None,
282 winTitle='',
283 colormap="br_green",
284 showColorbar=False,
285 showPowerProfile=False,
286 XAxisAsTime=False,
287 index=None):
288
275 if self.dataOutObj.flagNoData:
289 if self.dataOutObj.flagNoData:
276 return 0
290 return 0
277
291
278 if len(self.plotterObjList) <= self.plotterObjIndex:
292 if len(self.plotterObjList) <= self.plotterObjIndex:
279 self.addPlotter(index)
293 self.addPlotter(index)
280
294
281 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
295 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
296 xmax,
297 ymin,
298 ymax,
299 zmin,
300 zmax,
301 titleList,
302 xlabelList,
303 ylabelList,
304 winTitle,
305 colormap,
306 showColorbar,
307 showPowerProfile,
308 XAxisAsTime)
282
309
283 self.plotterObjIndex += 1
310 self.plotterObjIndex += 1
284
311
285 def integrator(self, N=None, timeInterval=None):
312 def integrator(self, N=None, timeInterval=None):
286
313
287 if self.dataOutObj.flagNoData:
314 if self.dataOutObj.flagNoData:
288 return 0
315 return 0
289
316
290 if len(self.integratorObjList) <= self.integratorObjIndex:
317 if len(self.integratorObjList) <= self.integratorObjIndex:
291 self.addIntegrator(N,timeInterval)
318 self.addIntegrator(N,timeInterval)
292
319
293 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
320 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
294 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
321 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
295
322
296 if myIncohIntObj.isReady:
323 if myIncohIntObj.isReady:
297 self.dataOutObj.data_spc = myIncohIntObj.data
324 self.dataOutObj.data_spc = myIncohIntObj.data
298 self.dataOutObj.nAvg = myIncohIntObj.navg
325 self.dataOutObj.nAvg = myIncohIntObj.navg
299 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
326 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
300 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
327 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
301 self.dataOutObj.flagNoData = False
328 self.dataOutObj.flagNoData = False
302
329
303 self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
330 self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
304 # self.getNoise(type="sort", parm=16)
331 # self.getNoise(type="sort", parm=16)
305
332
306 else:
333 else:
307 self.dataOutObj.flagNoData = True
334 self.dataOutObj.flagNoData = True
308
335
309 self.integratorObjIndex += 1
336 self.integratorObjIndex += 1
310
337
311 """Calcular el ruido"""
338 """Calcular el ruido"""
312 # self.getNoise(type="hildebrand", parm=1)
339 # self.getNoise(type="hildebrand", parm=1)
313
340
314 def removeDC(self, type):
341 def removeDC(self, type):
315
342
316 if self.dataOutObj.flagNoData:
343 if self.dataOutObj.flagNoData:
317 return 0
344 return 0
318
345
319 def removeInterference(self):
346 def removeInterference(self):
320
347
321 if self.dataOutObj.flagNoData:
348 if self.dataOutObj.flagNoData:
322 return 0
349 return 0
323
350
324 def removeSatellites(self):
351 def removeSatellites(self):
325
352
326 if self.dataOutObj.flagNoData:
353 if self.dataOutObj.flagNoData:
327 return 0
354 return 0
328
355
329 def getNoise(self, type="hildebrand", parm=None):
356 def getNoise(self, type="hildebrand", parm=None):
330
357
331 self.noiseObj.setNoise(self.dataOutObj.data_spc)
358 self.noiseObj.setNoise(self.dataOutObj.data_spc)
332
359
333 if type == "hildebrand":
360 if type == "hildebrand":
334 noise = self.noiseObj.byHildebrand(parm)
361 noise = self.noiseObj.byHildebrand(parm)
335
362
336 if type == "window":
363 if type == "window":
337 noise = self.noiseObj.byWindow(parm)
364 noise = self.noiseObj.byWindow(parm)
338
365
339 if type == "sort":
366 if type == "sort":
340 noise = self.noiseObj.bySort(parm)
367 noise = self.noiseObj.bySort(parm)
341
368
342 self.dataOutObj.noise = noise
369 self.dataOutObj.noise = noise
343 print 10*numpy.log10(noise)
370 # print 10*numpy.log10(noise)
344
371
345 def selectChannels(self, channelList, pairList=[]):
372 def selectChannels(self, channelList, pairList=[]):
346
373
347 channelIndexList = []
374 channelIndexList = []
348
375
349 for channel in channelList:
376 for channel in channelList:
350 if channel in self.dataOutObj.channelList:
377 if channel in self.dataOutObj.channelList:
351 index = self.dataOutObj.channelList.index(channel)
378 index = self.dataOutObj.channelList.index(channel)
352 channelIndexList.append(index)
379 channelIndexList.append(index)
353
380
354 pairIndexList = []
381 pairIndexList = []
355
382
356 for pair in pairList:
383 for pair in pairList:
357 if pair in self.dataOutObj.pairList:
384 if pair in self.dataOutObj.pairList:
358 index = self.dataOutObj.pairList.index(pair)
385 index = self.dataOutObj.pairList.index(pair)
359 pairIndexList.append(index)
386 pairIndexList.append(index)
360
387
361 self.selectChannelsByIndex(channelIndexList, pairIndexList)
388 self.selectChannelsByIndex(channelIndexList, pairIndexList)
362
389
363 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
390 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
364 """
391 """
365 Selecciona un bloque de datos en base a canales y pares segun el
392 Selecciona un bloque de datos en base a canales y pares segun el
366 channelIndexList y el pairIndexList
393 channelIndexList y el pairIndexList
367
394
368 Input:
395 Input:
369 channelIndexList : lista de indices de los canales a seleccionar por ej.
396 channelIndexList : lista de indices de los canales a seleccionar por ej.
370
397
371 Si tenemos los canales
398 Si tenemos los canales
372
399
373 self.channelList = (2,3,5,7)
400 self.channelList = (2,3,5,7)
374
401
375 y deseamos escoger los canales (3,7)
402 y deseamos escoger los canales (3,7)
376 entonces colocaremos el parametro
403 entonces colocaremos el parametro
377
404
378 channelndexList = (1,3)
405 channelndexList = (1,3)
379
406
380 pairIndexList : tupla de indice depares que se desea selecionar por ej.
407 pairIndexList : tupla de indice depares que se desea selecionar por ej.
381
408
382 Si tenemos los pares :
409 Si tenemos los pares :
383
410
384 ( (0,1), (0,2), (1,3), (2,5) )
411 ( (0,1), (0,2), (1,3), (2,5) )
385
412
386 y deseamos seleccionar los pares ((0,2), (2,5))
413 y deseamos seleccionar los pares ((0,2), (2,5))
387 entonces colocaremos el parametro
414 entonces colocaremos el parametro
388
415
389 pairIndexList = (1,3)
416 pairIndexList = (1,3)
390
417
391 Affected:
418 Affected:
392 self.dataOutObj.data_spc
419 self.dataOutObj.data_spc
393 self.dataOutObj.data_cspc
420 self.dataOutObj.data_cspc
394 self.dataOutObj.data_dc
421 self.dataOutObj.data_dc
395 self.dataOutObj.nChannels
422 self.dataOutObj.nChannels
396 self.dataOutObj.nPairs
423 self.dataOutObj.nPairs
397 self.dataOutObj.m_ProcessingHeader.spectraComb
424 self.dataOutObj.m_ProcessingHeader.spectraComb
398 self.dataOutObj.m_SystemHeader.numChannels
425 self.dataOutObj.m_SystemHeader.numChannels
399
426
400 self.dataOutObj.noise
427 self.dataOutObj.noise
401 Return:
428 Return:
402 None
429 None
403 """
430 """
404
431
405 if self.dataOutObj.flagNoData:
432 if self.dataOutObj.flagNoData:
406 return 0
433 return 0
407
434
408 if pairIndexList == []:
435 if pairIndexList == []:
409 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
436 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
410
437
411 nChannels = len(channelIndexList)
438 nChannels = len(channelIndexList)
412 nPairs = len(pairIndexList)
439 nPairs = len(pairIndexList)
413
440
414 blocksize = 0
441 blocksize = 0
415 #self spectra
442 #self spectra
416 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
443 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
417 blocksize += spc.size
444 blocksize += spc.size
418
445
419 cspc = None
446 cspc = None
420 if pairIndexList != []:
447 if pairIndexList != []:
421 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
448 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
422 blocksize += cspc.size
449 blocksize += cspc.size
423
450
424 #DC channel
451 #DC channel
425 dc = None
452 dc = None
426 if self.dataOutObj.m_ProcessingHeader.flag_dc:
453 if self.dataOutObj.m_ProcessingHeader.flag_dc:
427 dc = self.dataOutObj.data_dc[channelIndexList,:]
454 dc = self.dataOutObj.data_dc[channelIndexList,:]
428 blocksize += dc.size
455 blocksize += dc.size
429
456
430 #Almacenar las combinaciones de canales y cros espectros
457 #Almacenar las combinaciones de canales y cros espectros
431
458
432 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
459 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
433 i = 0
460 i = 0
434 for spcChannel in channelIndexList:
461 for spcChannel in channelIndexList:
435 spectraComb[i] = spcChannel
462 spectraComb[i] = spcChannel
436 spectraComb[i+1] = spcChannel
463 spectraComb[i+1] = spcChannel
437 i += 2
464 i += 2
438
465
439 if pairList != None:
466 if pairList != None:
440 for pair in pairList:
467 for pair in pairList:
441 spectraComb[i] = pair[0]
468 spectraComb[i] = pair[0]
442 spectraComb[i+1] = pair[1]
469 spectraComb[i+1] = pair[1]
443 i += 2
470 i += 2
444
471
445 #######
472 #######
446
473
447 self.dataOutObj.data_spc = spc
474 self.dataOutObj.data_spc = spc
448 self.dataOutObj.data_cspc = cspc
475 self.dataOutObj.data_cspc = cspc
449 self.dataOutObj.data_dc = dc
476 self.dataOutObj.data_dc = dc
450 self.dataOutObj.nChannels = nChannels
477 self.dataOutObj.nChannels = nChannels
451 self.dataOutObj.nPairs = nPairs
478 self.dataOutObj.nPairs = nPairs
452
479
453 self.dataOutObj.channelIndexList = channelIndexList
480 self.dataOutObj.channelIndexList = channelIndexList
454
481
455 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
482 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
456 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
483 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
457 self.dataOutObj.m_SystemHeader.numChannels = nChannels
484 self.dataOutObj.m_SystemHeader.numChannels = nChannels
458 self.dataOutObj.nChannels = nChannels
485 self.dataOutObj.nChannels = nChannels
459 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
486 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
460
487
461 if cspc == None:
488 if cspc == None:
462 self.dataOutObj.m_ProcessingHeader.flag_dc = False
489 self.dataOutObj.m_ProcessingHeader.flag_dc = False
463 if dc == None:
490 if dc == None:
464 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
491 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
465
492
466 def selectHeightsByValue(self, minHei, maxHei):
493 def selectHeightsByValue(self, minHei, maxHei):
467 """
494 """
468 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
495 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
469 minHei <= height <= maxHei
496 minHei <= height <= maxHei
470
497
471 Input:
498 Input:
472 minHei : valor minimo de altura a considerar
499 minHei : valor minimo de altura a considerar
473 maxHei : valor maximo de altura a considerar
500 maxHei : valor maximo de altura a considerar
474
501
475 Affected:
502 Affected:
476 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
503 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
477
504
478 Return:
505 Return:
479 None
506 None
480 """
507 """
481
508
482 if self.dataOutObj.flagNoData:
509 if self.dataOutObj.flagNoData:
483 return 0
510 return 0
484
511
485 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
512 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
486 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
513 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
487
514
488 if (maxHei > self.dataOutObj.heightList[-1]):
515 if (maxHei > self.dataOutObj.heightList[-1]):
489 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
516 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
490
517
491 minIndex = 0
518 minIndex = 0
492 maxIndex = 0
519 maxIndex = 0
493 data = self.dataOutObj.heightList
520 data = self.dataOutObj.heightList
494
521
495 for i,val in enumerate(data):
522 for i,val in enumerate(data):
496 if val < minHei:
523 if val < minHei:
497 continue
524 continue
498 else:
525 else:
499 minIndex = i;
526 minIndex = i;
500 break
527 break
501
528
502 for i,val in enumerate(data):
529 for i,val in enumerate(data):
503 if val <= maxHei:
530 if val <= maxHei:
504 maxIndex = i;
531 maxIndex = i;
505 else:
532 else:
506 break
533 break
507
534
508 self.selectHeightsByIndex(minIndex, maxIndex)
535 self.selectHeightsByIndex(minIndex, maxIndex)
509
536
510 def selectHeightsByIndex(self, minIndex, maxIndex):
537 def selectHeightsByIndex(self, minIndex, maxIndex):
511 """
538 """
512 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
539 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
513 minIndex <= index <= maxIndex
540 minIndex <= index <= maxIndex
514
541
515 Input:
542 Input:
516 minIndex : valor minimo de altura a considerar
543 minIndex : valor minimo de altura a considerar
517 maxIndex : valor maximo de altura a considerar
544 maxIndex : valor maximo de altura a considerar
518
545
519 Affected:
546 Affected:
520 self.dataOutObj.data_spc
547 self.dataOutObj.data_spc
521 self.dataOutObj.data_cspc
548 self.dataOutObj.data_cspc
522 self.dataOutObj.data_dc
549 self.dataOutObj.data_dc
523 self.dataOutObj.heightList
550 self.dataOutObj.heightList
524 self.dataOutObj.nHeights
551 self.dataOutObj.nHeights
525 self.dataOutObj.m_ProcessingHeader.numHeights
552 self.dataOutObj.m_ProcessingHeader.numHeights
526 self.dataOutObj.m_ProcessingHeader.blockSize
553 self.dataOutObj.m_ProcessingHeader.blockSize
527 self.dataOutObj.m_ProcessingHeader.firstHeight
554 self.dataOutObj.m_ProcessingHeader.firstHeight
528 self.dataOutObj.m_RadarControllerHeader.numHeights
555 self.dataOutObj.m_RadarControllerHeader.numHeights
529
556
530 Return:
557 Return:
531 None
558 None
532 """
559 """
533
560
534 if self.dataOutObj.flagNoData:
561 if self.dataOutObj.flagNoData:
535 return 0
562 return 0
536
563
537 if (minIndex < 0) or (minIndex > maxIndex):
564 if (minIndex < 0) or (minIndex > maxIndex):
538 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
565 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
539
566
540 if (maxIndex >= self.dataOutObj.nHeights):
567 if (maxIndex >= self.dataOutObj.nHeights):
541 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
568 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
542
569
543 nChannels = self.dataOutObj.nChannels
570 nChannels = self.dataOutObj.nChannels
544 nPairs = self.dataOutObj.nPairs
571 nPairs = self.dataOutObj.nPairs
545 nProfiles = self.dataOutObj.nProfiles
572 nProfiles = self.dataOutObj.nProfiles
546 dataType = self.dataOutObj.dataType
573 dataType = self.dataOutObj.dataType
547 nHeights = maxIndex - minIndex + 1
574 nHeights = maxIndex - minIndex + 1
548 blockSize = 0
575 blockSize = 0
549
576
550 #self spectra
577 #self spectra
551 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
578 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
552 blockSize += spc.size
579 blockSize += spc.size
553
580
554 #cross spectra
581 #cross spectra
555 cspc = None
582 cspc = None
556 if self.dataOutObj.data_cspc != None:
583 if self.dataOutObj.data_cspc != None:
557 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
584 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
558 blockSize += cspc.size
585 blockSize += cspc.size
559
586
560 #DC channel
587 #DC channel
561 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
588 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
562 blockSize += dc.size
589 blockSize += dc.size
563
590
564 self.dataOutObj.data_spc = spc
591 self.dataOutObj.data_spc = spc
565 if cspc != None:
592 if cspc != None:
566 self.dataOutObj.data_cspc = cspc
593 self.dataOutObj.data_cspc = cspc
567 self.dataOutObj.data_dc = dc
594 self.dataOutObj.data_dc = dc
568
595
569 firstHeight = self.dataOutObj.heightList[minIndex]
596 firstHeight = self.dataOutObj.heightList[minIndex]
570
597
571 self.dataOutObj.nHeights = nHeights
598 self.dataOutObj.nHeights = nHeights
572 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
599 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
573 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
600 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
574 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
601 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
575 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
602 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
576
603
577 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
604 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
578
605
579
606
580 class IncoherentIntegration:
607 class IncoherentIntegration:
581
608
582 integ_counter = None
609 integ_counter = None
583 data = None
610 data = None
584 navg = None
611 navg = None
585 buffer = None
612 buffer = None
586 nIncohInt = None
613 nIncohInt = None
587
614
588 def __init__(self, N = None, timeInterval = None):
615 def __init__(self, N = None, timeInterval = None):
589 """
616 """
590 N
617 N
591 timeInterval - interval time [min], integer value
618 timeInterval - interval time [min], integer value
592 """
619 """
593
620
594 self.data = None
621 self.data = None
595 self.navg = None
622 self.navg = None
596 self.buffer = None
623 self.buffer = None
597 self.timeOut = None
624 self.timeOut = None
598 self.exitCondition = False
625 self.exitCondition = False
599 self.isReady = False
626 self.isReady = False
600 self.nIncohInt = N
627 self.nIncohInt = N
601 self.integ_counter = 0
628 self.integ_counter = 0
602 if timeInterval!=None:
629 if timeInterval!=None:
603 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
630 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
604
631
605 if ((timeInterval==None) and (N==None)):
632 if ((timeInterval==None) and (N==None)):
606 print 'N = None ; timeInterval = None'
633 print 'N = None ; timeInterval = None'
607 sys.exit(0)
634 sys.exit(0)
608 elif timeInterval == None:
635 elif timeInterval == None:
609 self.timeFlag = False
636 self.timeFlag = False
610 else:
637 else:
611 self.timeFlag = True
638 self.timeFlag = True
612
639
613
640
614 def exe(self,data,timeOfData):
641 def exe(self,data,timeOfData):
615 """
642 """
616 data
643 data
617
644
618 timeOfData [seconds]
645 timeOfData [seconds]
619 """
646 """
620
647
621 if self.timeFlag:
648 if self.timeFlag:
622 if self.timeOut == None:
649 if self.timeOut == None:
623 self.timeOut = timeOfData + self.timeIntervalInSeconds
650 self.timeOut = timeOfData + self.timeIntervalInSeconds
624
651
625 if timeOfData < self.timeOut:
652 if timeOfData < self.timeOut:
626 if self.buffer == None:
653 if self.buffer == None:
627 self.buffer = data
654 self.buffer = data
628 else:
655 else:
629 self.buffer = self.buffer + data
656 self.buffer = self.buffer + data
630 self.integ_counter += 1
657 self.integ_counter += 1
631 else:
658 else:
632 self.exitCondition = True
659 self.exitCondition = True
633
660
634 else:
661 else:
635 if self.integ_counter < self.nIncohInt:
662 if self.integ_counter < self.nIncohInt:
636 if self.buffer == None:
663 if self.buffer == None:
637 self.buffer = data
664 self.buffer = data
638 else:
665 else:
639 self.buffer = self.buffer + data
666 self.buffer = self.buffer + data
640
667
641 self.integ_counter += 1
668 self.integ_counter += 1
642
669
643 if self.integ_counter == self.nIncohInt:
670 if self.integ_counter == self.nIncohInt:
644 self.exitCondition = True
671 self.exitCondition = True
645
672
646 if self.exitCondition:
673 if self.exitCondition:
647 self.data = self.buffer
674 self.data = self.buffer
648 self.navg = self.integ_counter
675 self.navg = self.integ_counter
649 self.isReady = True
676 self.isReady = True
650 self.buffer = None
677 self.buffer = None
651 self.timeOut = None
678 self.timeOut = None
652 self.integ_counter = 0
679 self.integ_counter = 0
653 self.exitCondition = False
680 self.exitCondition = False
654
681
655 if self.timeFlag:
682 if self.timeFlag:
656 self.buffer = data
683 self.buffer = data
657 self.timeOut = timeOfData + self.timeIntervalInSeconds
684 self.timeOut = timeOfData + self.timeIntervalInSeconds
658 else:
685 else:
659 self.isReady = False
686 self.isReady = False
660 No newline at end of file
687
@@ -1,585 +1,672
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
8 import os, sys
9 import numpy
9 import numpy
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Model.Voltage import Voltage
14 from Model.Voltage import Voltage
15 from IO.VoltageIO import VoltageWriter
15 from IO.VoltageIO import VoltageWriter
16 from Graphics.VoltagePlot import Osciloscope
16 from Graphics.VoltagePlot import Osciloscope
17 from Graphics.VoltagePlot import RTI
17
18
18 class VoltageProcessor:
19 class VoltageProcessor:
19 '''
20 '''
20 classdocs
21 classdocs
21 '''
22 '''
22
23
23 dataInObj = None
24 dataInObj = None
24 dataOutObj = None
25 dataOutObj = None
25
26
26 integratorObjIndex = None
27 integratorObjIndex = None
27 decoderObjIndex = None
28 decoderObjIndex = None
28 profSelectorObjIndex = None
29 profSelectorObjIndex = None
29 writerObjIndex = None
30 writerObjIndex = None
30 plotterObjIndex = None
31 plotterObjIndex = None
31 flipIndex = None
32 flipIndex = None
32
33
33 integratorObjList = []
34 integratorObjList = []
34 decoderObjList = []
35 decoderObjList = []
35 profileSelectorObjList = []
36 profileSelectorObjList = []
36 writerObjList = []
37 writerObjList = []
37 plotterObjList = []
38 plotterObjList = []
38 m_Voltage= Voltage()
39 m_Voltage= Voltage()
39
40
40 def __init__(self):
41 def __init__(self):
41 '''
42 '''
42 Constructor
43 Constructor
43 '''
44 '''
44
45
45 self.integratorObjIndex = None
46 self.integratorObjIndex = None
46 self.decoderObjIndex = None
47 self.decoderObjIndex = None
47 self.profSelectorObjIndex = None
48 self.profSelectorObjIndex = None
48 self.writerObjIndex = None
49 self.writerObjIndex = None
49 self.plotterObjIndex = None
50 self.plotterObjIndex = None
50 self.flipIndex = 1
51 self.flipIndex = 1
51 self.integratorObjList = []
52 self.integratorObjList = []
52 self.decoderObjList = []
53 self.decoderObjList = []
53 self.profileSelectorObjList = []
54 self.profileSelectorObjList = []
54 self.writerObjList = []
55 self.writerObjList = []
55 self.plotterObjList = []
56 self.plotterObjList = []
56
57
57 def setup(self, dataInObj=None, dataOutObj=None):
58 def setup(self, dataInObj=None, dataOutObj=None):
58
59
59 self.dataInObj = dataInObj
60 self.dataInObj = dataInObj
60
61
61 if dataOutObj == None:
62 if dataOutObj == None:
62 dataOutObj = Voltage()
63 dataOutObj = Voltage()
63
64
64 dataOutObj.copy(dataInObj)
65 dataOutObj.copy(dataInObj)
65
66
66 self.dataOutObj = dataOutObj
67 self.dataOutObj = dataOutObj
67
68
68 return self.dataOutObj
69 return self.dataOutObj
69
70
70
71
71 def init(self):
72 def init(self):
72
73
73 self.integratorObjIndex = 0
74 self.integratorObjIndex = 0
74 self.decoderObjIndex = 0
75 self.decoderObjIndex = 0
75 self.profSelectorObjIndex = 0
76 self.profSelectorObjIndex = 0
76 self.writerObjIndex = 0
77 self.writerObjIndex = 0
77 self.plotterObjIndex = 0
78 self.plotterObjIndex = 0
78 self.dataOutObj.copy(self.dataInObj)
79 self.dataOutObj.copy(self.dataInObj)
79
80
80 if self.profSelectorObjIndex != None:
81 if self.profSelectorObjIndex != None:
81 for profSelObj in self.profileSelectorObjList:
82 for profSelObj in self.profileSelectorObjList:
82 profSelObj.incIndex()
83 profSelObj.incIndex()
83
84
84 def addWriter(self, wrpath):
85 def addWriter(self, wrpath):
85 objWriter = VoltageWriter(self.dataOutObj)
86 objWriter = VoltageWriter(self.dataOutObj)
86 objWriter.setup(wrpath)
87 objWriter.setup(wrpath)
87 self.writerObjList.append(objWriter)
88 self.writerObjList.append(objWriter)
88
89
90 def addRti(self,index=None):
91 if index==None:
92 index = self.plotterObjIndex
93
94 plotObj = RTI(self.dataOutObj, index)
95 self.plotterObjList.append(plotObj)
96
89 def addPlotter(self, index=None):
97 def addPlotter(self, index=None):
90 if index==None:
98 if index==None:
91 index = self.plotterObjIndex
99 index = self.plotterObjIndex
92
100
93 plotObj = Osciloscope(self.dataOutObj, index)
101 plotObj = Osciloscope(self.dataOutObj, index)
94 self.plotterObjList.append(plotObj)
102 self.plotterObjList.append(plotObj)
95
103
96 def addIntegrator(self, N,timeInterval):
104 def addIntegrator(self, N,timeInterval):
97
105
98 objCohInt = CoherentIntegrator(N,timeInterval)
106 objCohInt = CoherentIntegrator(N,timeInterval)
99 self.integratorObjList.append(objCohInt)
107 self.integratorObjList.append(objCohInt)
100
108
101 def addDecoder(self, code, ncode, nbaud):
109 def addDecoder(self, code, ncode, nbaud):
102
110
103 objDecoder = Decoder(code,ncode,nbaud)
111 objDecoder = Decoder(code,ncode,nbaud)
104 self.decoderObjList.append(objDecoder)
112 self.decoderObjList.append(objDecoder)
105
113
106 def addProfileSelector(self, nProfiles):
114 def addProfileSelector(self, nProfiles):
107
115
108 objProfSelector = ProfileSelector(nProfiles)
116 objProfSelector = ProfileSelector(nProfiles)
109 self.profileSelectorObjList.append(objProfSelector)
117 self.profileSelectorObjList.append(objProfSelector)
110
118
111 def writeData(self,wrpath):
119 def writeData(self,wrpath):
112
120
113 if self.dataOutObj.flagNoData:
121 if self.dataOutObj.flagNoData:
114 return 0
122 return 0
115
123
116 if len(self.writerObjList) <= self.writerObjIndex:
124 if len(self.writerObjList) <= self.writerObjIndex:
117 self.addWriter(wrpath)
125 self.addWriter(wrpath)
118
126
119 self.writerObjList[self.writerObjIndex].putData()
127 self.writerObjList[self.writerObjIndex].putData()
120
128
121 # myWrObj = self.writerObjList[self.writerObjIndex]
122 # myWrObj.putData()
123
124 self.writerObjIndex += 1
129 self.writerObjIndex += 1
130
131 def addScope(self,index=None):
132 if index==None:
133 index = self.plotterObjIndex
134
135 plotObj = Osciloscope(self.dataOutObj, index)
136 self.plotterObjList.append(plotObj)
137
138 def plotScope(self,
139 xmin=None,
140 xmax=None,
141 ymin=None,
142 ymax=None,
143 titleList=None,
144 xlabelList=None,
145 ylabelList=None,
146 winTitle='',
147 type="power",
148 index=None):
149
150 if self.dataOutObj.flagNoData:
151 return 0
152
153 if len(self.plotterObjList) <= self.plotterObjIndex:
154 self.addScope(index)
155
156 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
157 xmax,
158 ymin,
159 ymax,
160 titleList,
161 xlabelList,
162 ylabelList,
163 winTitle,
164 type)
165
166 self.plotterObjIndex += 1
167
168 def plotRti(self,
169 xmin=None,
170 xmax=None,
171 ymin=None,
172 ymax=None,
173 zmin=None,
174 zmax=None,
175 titleList=None,
176 xlabelList=None,
177 ylabelList=None,
178 winTitle='',
179 timezone='lt',
180 npoints=1000.0,
181 colormap="br_green",
182 showColorbar=True,
183 showPowerProfile=False,
184 XAxisAsTime=True,
185 index=None):
186
187 if self.dataOutObj.flagNoData:
188 return 0
189
190 if len(self.plotterObjList) <= self.plotterObjIndex:
191 self.addRti(index)
192
193 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
194 xmax,
195 ymin,
196 ymax,
197 zmin,
198 zmax,
199 titleList,
200 xlabelList,
201 ylabelList,
202 winTitle,
203 timezone,
204 npoints,
205 colormap,
206 showColorbar,
207 showPowerProfile,
208 XAxisAsTime)
209
210 self.plotterObjIndex += 1
211
125
212
126 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None):
213 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None):
127 if self.dataOutObj.flagNoData:
214 if self.dataOutObj.flagNoData:
128 return 0
215 return 0
129
216
130 if len(self.plotterObjList) <= self.plotterObjIndex:
217 if len(self.plotterObjList) <= self.plotterObjIndex:
131 self.addPlotter(index)
218 self.addPlotter(index)
132
219
133 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle)
220 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle)
134
221
135 self.plotterObjIndex += 1
222 self.plotterObjIndex += 1
136
223
137 def integrator(self, N=None, timeInterval=None):
224 def integrator(self, N=None, timeInterval=None):
138
225
139 if self.dataOutObj.flagNoData:
226 if self.dataOutObj.flagNoData:
140 return 0
227 return 0
141
228
142 if len(self.integratorObjList) <= self.integratorObjIndex:
229 if len(self.integratorObjList) <= self.integratorObjIndex:
143 self.addIntegrator(N,timeInterval)
230 self.addIntegrator(N,timeInterval)
144
231
145 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
232 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
146 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=self.dataOutObj.m_BasicHeader.utc)
233 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=self.dataOutObj.m_BasicHeader.utc)
147
234
148 if myCohIntObj.isReady:
235 if myCohIntObj.isReady:
149 self.dataOutObj.data = myCohIntObj.data
236 self.dataOutObj.data = myCohIntObj.data
150 self.dataOutObj.nAvg = myCohIntObj.navg
237 self.dataOutObj.nAvg = myCohIntObj.navg
151 self.dataOutObj.m_ProcessingHeader.coherentInt *= myCohIntObj.navg
238 self.dataOutObj.m_ProcessingHeader.coherentInt *= myCohIntObj.navg
152 #print "myCohIntObj.navg: ",myCohIntObj.navg
239 #print "myCohIntObj.navg: ",myCohIntObj.navg
153 self.dataOutObj.flagNoData = False
240 self.dataOutObj.flagNoData = False
154
241
155 else:
242 else:
156 self.dataOutObj.flagNoData = True
243 self.dataOutObj.flagNoData = True
157
244
158 self.integratorObjIndex += 1
245 self.integratorObjIndex += 1
159
246
160 def decoder(self,code=None,type = 0):
247 def decoder(self,code=None,type = 0):
161
248
162 if self.dataOutObj.flagNoData:
249 if self.dataOutObj.flagNoData:
163 return 0
250 return 0
164
251
165 if code == None:
252 if code == None:
166 code = self.dataOutObj.m_RadarControllerHeader.code
253 code = self.dataOutObj.m_RadarControllerHeader.code
167 ncode, nbaud = code.shape
254 ncode, nbaud = code.shape
168
255
169 if len(self.decoderObjList) <= self.decoderObjIndex:
256 if len(self.decoderObjList) <= self.decoderObjIndex:
170 self.addDecoder(code,ncode,nbaud)
257 self.addDecoder(code,ncode,nbaud)
171
258
172 myDecodObj = self.decoderObjList[self.decoderObjIndex]
259 myDecodObj = self.decoderObjList[self.decoderObjIndex]
173 myDecodObj.exe(data=self.dataOutObj.data,type=type)
260 myDecodObj.exe(data=self.dataOutObj.data,type=type)
174
261
175 if myDecodObj.flag:
262 if myDecodObj.flag:
176 self.dataOutObj.data = myDecodObj.data
263 self.dataOutObj.data = myDecodObj.data
177 self.dataOutObj.flagNoData = False
264 self.dataOutObj.flagNoData = False
178 else:
265 else:
179 self.dataOutObj.flagNoData = True
266 self.dataOutObj.flagNoData = True
180
267
181 self.decoderObjIndex += 1
268 self.decoderObjIndex += 1
182
269
183
270
184 def filterByHei(self, window):
271 def filterByHei(self, window):
185 if window == None:
272 if window == None:
186 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
273 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
187
274
188 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
275 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
189 dim1 = self.dataOutObj.data.shape[0]
276 dim1 = self.dataOutObj.data.shape[0]
190 dim2 = self.dataOutObj.data.shape[1]
277 dim2 = self.dataOutObj.data.shape[1]
191 r = dim2 % window
278 r = dim2 % window
192
279
193 buffer = self.dataOutObj.data[:,0:dim2-r]
280 buffer = self.dataOutObj.data[:,0:dim2-r]
194 buffer = buffer.reshape(dim1,dim2/window,window)
281 buffer = buffer.reshape(dim1,dim2/window,window)
195 buffer = numpy.sum(buffer,2)
282 buffer = numpy.sum(buffer,2)
196 self.dataOutObj.data = buffer
283 self.dataOutObj.data = buffer
197
284
198 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
285 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
199 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
286 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
200
287
201 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
288 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
202
289
203 #self.dataOutObj.heightList es un numpy.array
290 #self.dataOutObj.heightList es un numpy.array
204 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
291 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
205
292
206 def deFlip(self):
293 def deFlip(self):
207 self.dataOutObj.data *= self.flipIndex
294 self.dataOutObj.data *= self.flipIndex
208 self.flipIndex *= -1.
295 self.flipIndex *= -1.
209
296
210 def selectChannels(self, channelList):
297 def selectChannels(self, channelList):
211 pass
298 pass
212
299
213 def selectChannelsByIndex(self, channelIndexList):
300 def selectChannelsByIndex(self, channelIndexList):
214 """
301 """
215 Selecciona un bloque de datos en base a canales segun el channelIndexList
302 Selecciona un bloque de datos en base a canales segun el channelIndexList
216
303
217 Input:
304 Input:
218 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
305 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
219
306
220 Affected:
307 Affected:
221 self.dataOutObj.data
308 self.dataOutObj.data
222 self.dataOutObj.channelIndexList
309 self.dataOutObj.channelIndexList
223 self.dataOutObj.nChannels
310 self.dataOutObj.nChannels
224 self.dataOutObj.m_ProcessingHeader.totalSpectra
311 self.dataOutObj.m_ProcessingHeader.totalSpectra
225 self.dataOutObj.m_SystemHeader.numChannels
312 self.dataOutObj.m_SystemHeader.numChannels
226 self.dataOutObj.m_ProcessingHeader.blockSize
313 self.dataOutObj.m_ProcessingHeader.blockSize
227
314
228 Return:
315 Return:
229 None
316 None
230 """
317 """
231 if self.dataOutObj.flagNoData:
318 if self.dataOutObj.flagNoData:
232 return 0
319 return 0
233
320
234 for channel in channelIndexList:
321 for channel in channelIndexList:
235 if channel not in self.dataOutObj.channelIndexList:
322 if channel not in self.dataOutObj.channelIndexList:
236 raise ValueError, "The value %d in channelIndexList is not valid" %channel
323 raise ValueError, "The value %d in channelIndexList is not valid" %channel
237
324
238 nChannels = len(channelIndexList)
325 nChannels = len(channelIndexList)
239
326
240 data = self.dataOutObj.data[channelIndexList,:]
327 data = self.dataOutObj.data[channelIndexList,:]
241
328
242 self.dataOutObj.data = data
329 self.dataOutObj.data = data
243 self.dataOutObj.channelIndexList = channelIndexList
330 self.dataOutObj.channelIndexList = channelIndexList
244 self.dataOutObj.nChannels = nChannels
331 self.dataOutObj.nChannels = nChannels
245
332
246 self.dataOutObj.m_ProcessingHeader.totalSpectra = 0
333 self.dataOutObj.m_ProcessingHeader.totalSpectra = 0
247 self.dataOutObj.m_SystemHeader.numChannels = nChannels
334 self.dataOutObj.m_SystemHeader.numChannels = nChannels
248 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
335 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
249 return 1
336 return 1
250
337
251
338
252 def selectHeightsByValue(self, minHei, maxHei):
339 def selectHeightsByValue(self, minHei, maxHei):
253 """
340 """
254 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
341 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
255 minHei <= height <= maxHei
342 minHei <= height <= maxHei
256
343
257 Input:
344 Input:
258 minHei : valor minimo de altura a considerar
345 minHei : valor minimo de altura a considerar
259 maxHei : valor maximo de altura a considerar
346 maxHei : valor maximo de altura a considerar
260
347
261 Affected:
348 Affected:
262 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
349 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
263
350
264 Return:
351 Return:
265 1 si el metodo se ejecuto con exito caso contrario devuelve 0
352 1 si el metodo se ejecuto con exito caso contrario devuelve 0
266 """
353 """
267 if self.dataOutObj.flagNoData:
354 if self.dataOutObj.flagNoData:
268 return 0
355 return 0
269
356
270 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
357 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
271 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
358 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
272
359
273 if (maxHei > self.dataOutObj.heightList[-1]):
360 if (maxHei > self.dataOutObj.heightList[-1]):
274 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
361 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
275
362
276 minIndex = 0
363 minIndex = 0
277 maxIndex = 0
364 maxIndex = 0
278 data = self.dataOutObj.heightList
365 data = self.dataOutObj.heightList
279
366
280 for i,val in enumerate(data):
367 for i,val in enumerate(data):
281 if val < minHei:
368 if val < minHei:
282 continue
369 continue
283 else:
370 else:
284 minIndex = i;
371 minIndex = i;
285 break
372 break
286
373
287 for i,val in enumerate(data):
374 for i,val in enumerate(data):
288 if val <= maxHei:
375 if val <= maxHei:
289 maxIndex = i;
376 maxIndex = i;
290 else:
377 else:
291 break
378 break
292
379
293 self.selectHeightsByIndex(minIndex, maxIndex)
380 self.selectHeightsByIndex(minIndex, maxIndex)
294 return 1
381 return 1
295
382
296
383
297 def selectHeightsByIndex(self, minIndex, maxIndex):
384 def selectHeightsByIndex(self, minIndex, maxIndex):
298 """
385 """
299 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
386 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
300 minIndex <= index <= maxIndex
387 minIndex <= index <= maxIndex
301
388
302 Input:
389 Input:
303 minIndex : valor de indice minimo de altura a considerar
390 minIndex : valor de indice minimo de altura a considerar
304 maxIndex : valor de indice maximo de altura a considerar
391 maxIndex : valor de indice maximo de altura a considerar
305
392
306 Affected:
393 Affected:
307 self.dataOutObj.data
394 self.dataOutObj.data
308 self.dataOutObj.heightList
395 self.dataOutObj.heightList
309 self.dataOutObj.nHeights
396 self.dataOutObj.nHeights
310 self.dataOutObj.m_ProcessingHeader.blockSize
397 self.dataOutObj.m_ProcessingHeader.blockSize
311 self.dataOutObj.m_ProcessingHeader.numHeights
398 self.dataOutObj.m_ProcessingHeader.numHeights
312 self.dataOutObj.m_ProcessingHeader.firstHeight
399 self.dataOutObj.m_ProcessingHeader.firstHeight
313 self.dataOutObj.m_RadarControllerHeader
400 self.dataOutObj.m_RadarControllerHeader
314
401
315 Return:
402 Return:
316 1 si el metodo se ejecuto con exito caso contrario devuelve 0
403 1 si el metodo se ejecuto con exito caso contrario devuelve 0
317 """
404 """
318 if self.dataOutObj.flagNoData:
405 if self.dataOutObj.flagNoData:
319 return 0
406 return 0
320
407
321 if (minIndex < 0) or (minIndex > maxIndex):
408 if (minIndex < 0) or (minIndex > maxIndex):
322 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
409 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
323
410
324 if (maxIndex >= self.dataOutObj.nHeights):
411 if (maxIndex >= self.dataOutObj.nHeights):
325 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
412 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
326
413
327 nHeights = maxIndex - minIndex + 1
414 nHeights = maxIndex - minIndex + 1
328
415
329 #voltage
416 #voltage
330 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
417 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
331
418
332 firstHeight = self.dataOutObj.heightList[minIndex]
419 firstHeight = self.dataOutObj.heightList[minIndex]
333
420
334 self.dataOutObj.data = data
421 self.dataOutObj.data = data
335 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
422 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
336 self.dataOutObj.nHeights = nHeights
423 self.dataOutObj.nHeights = nHeights
337 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
424 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
338 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
425 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
339 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
426 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
340 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
427 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
341 return 1
428 return 1
342
429
343 def selectProfilesByValue(self,indexList, nProfiles):
430 def selectProfilesByValue(self,indexList, nProfiles):
344 if self.dataOutObj.flagNoData:
431 if self.dataOutObj.flagNoData:
345 return 0
432 return 0
346
433
347 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
434 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
348 self.addProfileSelector(nProfiles)
435 self.addProfileSelector(nProfiles)
349
436
350 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
437 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
351
438
352 if not(profileSelectorObj.isProfileInList(indexList)):
439 if not(profileSelectorObj.isProfileInList(indexList)):
353 self.dataOutObj.flagNoData = True
440 self.dataOutObj.flagNoData = True
354 self.profSelectorObjIndex += 1
441 self.profSelectorObjIndex += 1
355 return 0
442 return 0
356
443
357 self.dataOutObj.flagNoData = False
444 self.dataOutObj.flagNoData = False
358 self.profSelectorObjIndex += 1
445 self.profSelectorObjIndex += 1
359
446
360 return 1
447 return 1
361
448
362
449
363 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
450 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
364 """
451 """
365 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
452 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
366 minIndex <= index <= maxIndex
453 minIndex <= index <= maxIndex
367
454
368 Input:
455 Input:
369 minIndex : valor de indice minimo de perfil a considerar
456 minIndex : valor de indice minimo de perfil a considerar
370 maxIndex : valor de indice maximo de perfil a considerar
457 maxIndex : valor de indice maximo de perfil a considerar
371 nProfiles : numero de profiles
458 nProfiles : numero de profiles
372
459
373 Affected:
460 Affected:
374 self.dataOutObj.flagNoData
461 self.dataOutObj.flagNoData
375 self.profSelectorObjIndex
462 self.profSelectorObjIndex
376
463
377 Return:
464 Return:
378 1 si el metodo se ejecuto con exito caso contrario devuelve 0
465 1 si el metodo se ejecuto con exito caso contrario devuelve 0
379 """
466 """
380
467
381 if self.dataOutObj.flagNoData:
468 if self.dataOutObj.flagNoData:
382 return 0
469 return 0
383
470
384 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
471 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
385 self.addProfileSelector(nProfiles)
472 self.addProfileSelector(nProfiles)
386
473
387 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
474 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
388
475
389 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
476 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
390 self.dataOutObj.flagNoData = True
477 self.dataOutObj.flagNoData = True
391 self.profSelectorObjIndex += 1
478 self.profSelectorObjIndex += 1
392 return 0
479 return 0
393
480
394 self.dataOutObj.flagNoData = False
481 self.dataOutObj.flagNoData = False
395 self.profSelectorObjIndex += 1
482 self.profSelectorObjIndex += 1
396
483
397 return 1
484 return 1
398
485
399 def selectNtxs(self, ntx):
486 def selectNtxs(self, ntx):
400 pass
487 pass
401
488
402
489
403 class Decoder:
490 class Decoder:
404
491
405 data = None
492 data = None
406 profCounter = 1
493 profCounter = 1
407 nCode = None
494 nCode = None
408 nBaud = None
495 nBaud = None
409 codeIndex = 0
496 codeIndex = 0
410 code = None
497 code = None
411 flag = False
498 flag = False
412
499
413 def __init__(self,code, ncode, nbaud):
500 def __init__(self,code, ncode, nbaud):
414
501
415 self.data = None
502 self.data = None
416 self.profCounter = 1
503 self.profCounter = 1
417 self.nCode = ncode
504 self.nCode = ncode
418 self.nBaud = nbaud
505 self.nBaud = nbaud
419 self.codeIndex = 0
506 self.codeIndex = 0
420 self.code = code #this is a List
507 self.code = code #this is a List
421 self.flag = False
508 self.flag = False
422
509
423 def exe(self, data, ndata=None, type = 0):
510 def exe(self, data, ndata=None, type = 0):
424
511
425 if ndata == None: ndata = data.shape[1]
512 if ndata == None: ndata = data.shape[1]
426
513
427 if type == 0:
514 if type == 0:
428 self.convolutionInFreq(data,ndata)
515 self.convolutionInFreq(data,ndata)
429
516
430 if type == 1:
517 if type == 1:
431 self.convolutionInTime(data, ndata)
518 self.convolutionInTime(data, ndata)
432
519
433 def convolutionInFreq(self,data, ndata):
520 def convolutionInFreq(self,data, ndata):
434
521
435 newcode = numpy.zeros(ndata)
522 newcode = numpy.zeros(ndata)
436 newcode[0:self.nBaud] = self.code[self.codeIndex]
523 newcode[0:self.nBaud] = self.code[self.codeIndex]
437
524
438 self.codeIndex += 1
525 self.codeIndex += 1
439
526
440 fft_data = numpy.fft.fft(data, axis=1)
527 fft_data = numpy.fft.fft(data, axis=1)
441 fft_code = numpy.conj(numpy.fft.fft(newcode))
528 fft_code = numpy.conj(numpy.fft.fft(newcode))
442 fft_code = fft_code.reshape(1,len(fft_code))
529 fft_code = fft_code.reshape(1,len(fft_code))
443
530
444 conv = fft_data.copy()
531 conv = fft_data.copy()
445 conv.fill(0)
532 conv.fill(0)
446
533
447 conv = fft_data*fft_code
534 conv = fft_data*fft_code
448
535
449 self.data = numpy.fft.ifft(conv,axis=1)
536 self.data = numpy.fft.ifft(conv,axis=1)
450 self.flag = True
537 self.flag = True
451
538
452 if self.profCounter == self.nCode:
539 if self.profCounter == self.nCode:
453 self.profCounter = 0
540 self.profCounter = 0
454 self.codeIndex = 0
541 self.codeIndex = 0
455
542
456 self.profCounter += 1
543 self.profCounter += 1
457
544
458 def convolutionInTime(self, data, ndata):
545 def convolutionInTime(self, data, ndata):
459
546
460 nchannel = data.shape[1]
547 nchannel = data.shape[1]
461 newcode = self.code[self.codeIndex]
548 newcode = self.code[self.codeIndex]
462 self.codeIndex += 1
549 self.codeIndex += 1
463 conv = data.copy()
550 conv = data.copy()
464 for i in range(nchannel):
551 for i in range(nchannel):
465 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
552 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
466
553
467 self.data = conv
554 self.data = conv
468 self.flag = True
555 self.flag = True
469
556
470 if self.profCounter == self.nCode:
557 if self.profCounter == self.nCode:
471 self.profCounter = 0
558 self.profCounter = 0
472 self.codeIndex = 0
559 self.codeIndex = 0
473
560
474 self.profCounter += 1
561 self.profCounter += 1
475
562
476
563
477 class CoherentIntegrator:
564 class CoherentIntegrator:
478
565
479 integ_counter = None
566 integ_counter = None
480 data = None
567 data = None
481 navg = None
568 navg = None
482 buffer = None
569 buffer = None
483 nCohInt = None
570 nCohInt = None
484
571
485 def __init__(self, N=None,timeInterval=None):
572 def __init__(self, N=None,timeInterval=None):
486
573
487 self.data = None
574 self.data = None
488 self.navg = None
575 self.navg = None
489 self.buffer = None
576 self.buffer = None
490 self.timeOut = None
577 self.timeOut = None
491 self.exitCondition = False
578 self.exitCondition = False
492 self.isReady = False
579 self.isReady = False
493 self.nCohInt = N
580 self.nCohInt = N
494 self.integ_counter = 0
581 self.integ_counter = 0
495 if timeInterval!=None:
582 if timeInterval!=None:
496 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
583 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
497
584
498 if ((timeInterval==None) and (N==None)):
585 if ((timeInterval==None) and (N==None)):
499 print 'N = None ; timeInterval = None'
586 print 'N = None ; timeInterval = None'
500 sys.exit(0)
587 sys.exit(0)
501 elif timeInterval == None:
588 elif timeInterval == None:
502 self.timeFlag = False
589 self.timeFlag = False
503 else:
590 else:
504 self.timeFlag = True
591 self.timeFlag = True
505
592
506 def exe(self, data, timeOfData):
593 def exe(self, data, timeOfData):
507
594
508 if self.timeFlag:
595 if self.timeFlag:
509 if self.timeOut == None:
596 if self.timeOut == None:
510 self.timeOut = timeOfData + self.timeIntervalInSeconds
597 self.timeOut = timeOfData + self.timeIntervalInSeconds
511
598
512 if timeOfData < self.timeOut:
599 if timeOfData < self.timeOut:
513 if self.buffer == None:
600 if self.buffer == None:
514 self.buffer = data
601 self.buffer = data
515 else:
602 else:
516 self.buffer = self.buffer + data
603 self.buffer = self.buffer + data
517 self.integ_counter += 1
604 self.integ_counter += 1
518 else:
605 else:
519 self.exitCondition = True
606 self.exitCondition = True
520
607
521 else:
608 else:
522 if self.integ_counter < self.nCohInt:
609 if self.integ_counter < self.nCohInt:
523 if self.buffer == None:
610 if self.buffer == None:
524 self.buffer = data
611 self.buffer = data
525 else:
612 else:
526 self.buffer = self.buffer + data
613 self.buffer = self.buffer + data
527
614
528 self.integ_counter += 1
615 self.integ_counter += 1
529
616
530 if self.integ_counter == self.nCohInt:
617 if self.integ_counter == self.nCohInt:
531 self.exitCondition = True
618 self.exitCondition = True
532
619
533 if self.exitCondition:
620 if self.exitCondition:
534 self.data = self.buffer
621 self.data = self.buffer
535 self.navg = self.integ_counter
622 self.navg = self.integ_counter
536 self.isReady = True
623 self.isReady = True
537 self.buffer = None
624 self.buffer = None
538 self.timeOut = None
625 self.timeOut = None
539 self.integ_counter = 0
626 self.integ_counter = 0
540 self.exitCondition = False
627 self.exitCondition = False
541
628
542 if self.timeFlag:
629 if self.timeFlag:
543 self.buffer = data
630 self.buffer = data
544 self.timeOut = timeOfData + self.timeIntervalInSeconds
631 self.timeOut = timeOfData + self.timeIntervalInSeconds
545 else:
632 else:
546 self.isReady = False
633 self.isReady = False
547
634
548
635
549
636
550 class ProfileSelector:
637 class ProfileSelector:
551
638
552 profileIndex = None
639 profileIndex = None
553 # Tamanho total de los perfiles
640 # Tamanho total de los perfiles
554 nProfiles = None
641 nProfiles = None
555
642
556 def __init__(self, nProfiles):
643 def __init__(self, nProfiles):
557
644
558 self.profileIndex = 0
645 self.profileIndex = 0
559 self.nProfiles = nProfiles
646 self.nProfiles = nProfiles
560
647
561 def incIndex(self):
648 def incIndex(self):
562 self.profileIndex += 1
649 self.profileIndex += 1
563
650
564 if self.profileIndex >= self.nProfiles:
651 if self.profileIndex >= self.nProfiles:
565 self.profileIndex = 0
652 self.profileIndex = 0
566
653
567 def isProfileInRange(self, minIndex, maxIndex):
654 def isProfileInRange(self, minIndex, maxIndex):
568
655
569 if self.profileIndex < minIndex:
656 if self.profileIndex < minIndex:
570 return False
657 return False
571
658
572 if self.profileIndex > maxIndex:
659 if self.profileIndex > maxIndex:
573 return False
660 return False
574
661
575 return True
662 return True
576
663
577 def isProfileInList(self, profileList):
664 def isProfileInList(self, profileList):
578
665
579 if self.profileIndex not in profileList:
666 if self.profileIndex not in profileList:
580 return False
667 return False
581
668
582 return True
669 return True
583
670
584
671
585 No newline at end of file
672
@@ -1,109 +1,93
1 '''
1 '''
2 Created on 27/03/2012
2 Created on Jul 31, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7 import os, sys
8 import os, sys
8 import time, datetime
9 import time, datetime
9
10
10 from Model.Voltage import Voltage
11 from Model.Voltage import Voltage
11 from IO.VoltageIO import *
12 from IO.VoltageIO import *
12 #from Graphics.VoltagePlot import Osciloscope
13
13
14 from Model.Spectra import Spectra
14 from Model.Spectra import Spectra
15 from IO.SpectraIO import *
15 from IO.SpectraIO import *
16
16
17 from Processing.VoltageProcessor import *
17 from Processing.VoltageProcessor import *
18 from Processing.SpectraProcessor import *
18 from Processing.SpectraProcessor import *
19
19
20
20
21 class TestSChain():
21 class TestSChain():
22
22
23 def __init__(self):
23 def __init__(self):
24 self.setValues()
24 self.setValues()
25 self.createObjects()
25 self.createObjects()
26 self.testSChain()
26 self.testSChain()
27
27
28
29 def setValues( self ):
28 def setValues( self ):
30
29
31 self.path = "/home/dsuarez/Projects" #1
30 self.path = "/home/dsuarez/Projects"
32 self.path = "/Users/jro/Documents/RadarData/EW_Drifts"
31 self.path = "/Users/jro/Documents/RadarData/EW_Drifts"
33 self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST"
32 self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST"
34 # self.startDateTime = datetime.datetime(2007,5,1,15,49,0)
35 # self.endDateTime = datetime.datetime(2007,5,1,23,0,0)
36
33
37 self.startDateTime = datetime.datetime(2009,01,1,0,0,0)
34 self.startDateTime = datetime.datetime(2009,01,1,0,0,0)
38 self.endDateTime = datetime.datetime(2009,01,31,0,20,0)
35 self.endDateTime = datetime.datetime(2009,01,31,0,20,0)
39
36
40 # self.startDateTime = datetime.datetime(2011,11,1,0,0,0)
41 # self.endDateTime = datetime.datetime(2011,12,31,0,20,0)
42
43
44 self.N = 4
37 self.N = 4
45 self.npts = 8
38 self.npts = 8
46
39
47 def createObjects( self ):
40 def createObjects( self ):
48
41
49 self.readerObj = VoltageReader()
42 self.readerObj = VoltageReader()
50 self.voltProcObj = VoltageProcessor()
43 self.voltProcObj = VoltageProcessor()
51 self.specProcObj = SpectraProcessor()
44 self.specProcObj = SpectraProcessor()
52
45
53 voltObj1 = self.readerObj.setup(
46 self.voltObj1 = self.readerObj.setup(
54 path = self.path,
47 path = self.path,
55 startDateTime = self.startDateTime,
48 startDateTime = self.startDateTime,
56 endDateTime = self.endDateTime,
49 endDateTime = self.endDateTime,
57 expLabel = '',
50 expLabel = '',
58 online = 0)
51 online = 0)
59
52
60 if not(voltObj1):
53 if not(self.voltObj1):
61 sys.exit(0)
54 sys.exit(0)
62
55
63 voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1)
56 self.voltObj2 = self.voltProcObj.setup(dataInObj = self.voltObj1)
64
57
65 specObj1 = self.specProcObj.setup(dataInObj = voltObj2,
58 self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj2,
66 nFFTPoints = 16)
59 nFFTPoints = 16)
67
60
68 # voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1,
69 # dataOutObj = voltObj2)
70 #
71 # specObj1 = self.specProcObj.setup(dataInObj = voltObj2,
72 # dataOutObj =specObj1,
73 # nFFTPoints=16)
74
75
61
76 def testSChain( self ):
62 def testSChain( self ):
77
63
78 ini = time.time()
64 ini = time.time()
65
79 while(True):
66 while(True):
80 self.readerObj.getData()
67 self.readerObj.getData()
81
68
82 self.voltProcObj.init()
69 self.voltProcObj.init()
83
70
84 # self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1)
71 self.voltProcObj.plotScope(winTitle="Scope 1",type="iq", index=1)
85 #
86 # self.voltProcObj.integrator(4)
87 #
88 # self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2)
89 #
90
72
73 self.voltProcObj.plotRti(winTitle='VOLTAGE INPUT', showPowerProfile=True, index=2)
74
75 self.voltProcObj.integrator(4)
76
91 self.specProcObj.init()
77 self.specProcObj.init()
92
78
93 self.specProcObj.integrator(N=1)
79 self.specProcObj.integrator(N=4)
94
80
95 self.specProcObj.plotData(winTitle='Spectra 1', index=1)
81 # self.specProcObj.plotSpec(winTitle='Spectra Test', showColorbar=True,showPowerProfile=True,index=3)
96
82 self.specProcObj.plotData(winTitle='Spectra Test', showColorbar=True,showPowerProfile=True,index=3)
97
83
98 if self.readerObj.flagNoMoreFiles:
84 if self.readerObj.flagNoMoreFiles:
99 break
85 break
100
86
101 if self.readerObj.flagIsNewBlock:
87 if self.readerObj.flagIsNewBlock:
102 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
88 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
103 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
89 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
104
90
105
106 # self.plotObj.end()
107
91
108 if __name__ == '__main__':
92 if __name__ == '__main__':
109 TestSChain() No newline at end of file
93 TestSChain()
General Comments 0
You need to be logged in to leave comments. Login now