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