@@ -1,863 +1,902 | |||||
1 | """ |
|
1 | """ | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @autor $Author$ |
|
4 | @autor $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 |
|
6 | |||
7 | """ |
|
7 | """ | |
8 |
|
8 | |||
9 | import numpy |
|
9 | import numpy | |
10 | import plplot |
|
10 | import plplot | |
11 |
|
11 | |||
12 | def cmap1_init(colormap="gray"): |
|
12 | def cmap1_init(colormap="gray"): | |
13 |
|
13 | |||
|
14 | if colormap == None: | |||
|
15 | return | |||
|
16 | ||||
14 | ncolor = None |
|
17 | ncolor = None | |
15 | rgb_lvl = None |
|
18 | rgb_lvl = None | |
16 |
|
19 | |||
17 | # Routine for defining a specific color map 1 in HLS space. |
|
20 | # Routine for defining a specific color map 1 in HLS space. | |
18 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
21 | # if gray is true, use basic grayscale variation from half-dark to light. | |
19 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
22 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |
20 |
|
23 | |||
21 | # Independent variable of control points. |
|
24 | # Independent variable of control points. | |
22 | i = numpy.array((0., 1.)) |
|
25 | i = numpy.array((0., 1.)) | |
23 | if colormap=="gray": |
|
26 | if colormap=="gray": | |
24 | ncolor = 256 |
|
27 | ncolor = 256 | |
25 | # Hue for control points. Doesn't matter since saturation is zero. |
|
28 | # Hue for control points. Doesn't matter since saturation is zero. | |
26 | h = numpy.array((0., 0.)) |
|
29 | h = numpy.array((0., 0.)) | |
27 | # Lightness ranging from half-dark (for interest) to light. |
|
30 | # Lightness ranging from half-dark (for interest) to light. | |
28 | l = numpy.array((0.5, 1.)) |
|
31 | l = numpy.array((0.5, 1.)) | |
29 | # Gray scale has zero saturation |
|
32 | # Gray scale has zero saturation | |
30 | s = numpy.array((0., 0.)) |
|
33 | s = numpy.array((0., 0.)) | |
31 |
|
34 | |||
32 | # number of cmap1 colours is 256 in this case. |
|
35 | # number of cmap1 colours is 256 in this case. | |
33 | plplot.plscmap1n(ncolor) |
|
36 | plplot.plscmap1n(ncolor) | |
34 | # Interpolate between control points to set up cmap1. |
|
37 | # Interpolate between control points to set up cmap1. | |
35 | plplot.plscmap1l(0, i, h, l, s) |
|
38 | plplot.plscmap1l(0, i, h, l, s) | |
36 |
|
39 | |||
37 | return None |
|
40 | return None | |
38 |
|
41 | |||
39 | if colormap=="br_green": |
|
42 | if colormap=="br_green": | |
40 | ncolor = 256 |
|
43 | ncolor = 256 | |
41 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
44 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
42 | h = numpy.array((240., 0.)) |
|
45 | h = numpy.array((240., 0.)) | |
43 | # Lightness and saturation are constant (values taken from C example). |
|
46 | # Lightness and saturation are constant (values taken from C example). | |
44 | l = numpy.array((0.6, 0.6)) |
|
47 | l = numpy.array((0.6, 0.6)) | |
45 | s = numpy.array((0.8, 0.8)) |
|
48 | s = numpy.array((0.8, 0.8)) | |
46 |
|
49 | |||
47 | # number of cmap1 colours is 256 in this case. |
|
50 | # number of cmap1 colours is 256 in this case. | |
48 | plplot.plscmap1n(ncolor) |
|
51 | plplot.plscmap1n(ncolor) | |
49 | # Interpolate between control points to set up cmap1. |
|
52 | # Interpolate between control points to set up cmap1. | |
50 | plplot.plscmap1l(0, i, h, l, s) |
|
53 | plplot.plscmap1l(0, i, h, l, s) | |
51 |
|
54 | |||
52 | return None |
|
55 | return None | |
53 |
|
56 | |||
54 | if colormap=="tricolor": |
|
57 | if colormap=="tricolor": | |
55 | ncolor = 3 |
|
58 | ncolor = 3 | |
56 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
59 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
57 | h = numpy.array((240., 0.)) |
|
60 | h = numpy.array((240., 0.)) | |
58 | # Lightness and saturation are constant (values taken from C example). |
|
61 | # Lightness and saturation are constant (values taken from C example). | |
59 | l = numpy.array((0.6, 0.6)) |
|
62 | l = numpy.array((0.6, 0.6)) | |
60 | s = numpy.array((0.8, 0.8)) |
|
63 | s = numpy.array((0.8, 0.8)) | |
61 |
|
64 | |||
62 | # number of cmap1 colours is 256 in this case. |
|
65 | # number of cmap1 colours is 256 in this case. | |
63 | plplot.plscmap1n(ncolor) |
|
66 | plplot.plscmap1n(ncolor) | |
64 | # Interpolate between control points to set up cmap1. |
|
67 | # Interpolate between control points to set up cmap1. | |
65 | plplot.plscmap1l(0, i, h, l, s) |
|
68 | plplot.plscmap1l(0, i, h, l, s) | |
66 |
|
69 | |||
67 | return None |
|
70 | return None | |
68 |
|
71 | |||
69 | if colormap == 'rgb' or colormap == 'rgb666': |
|
72 | if colormap == 'rgb' or colormap == 'rgb666': | |
70 |
|
73 | |||
71 | color_sz = 6 |
|
74 | color_sz = 6 | |
72 | ncolor = color_sz*color_sz*color_sz |
|
75 | ncolor = color_sz*color_sz*color_sz | |
73 | pos = numpy.zeros((ncolor)) |
|
76 | pos = numpy.zeros((ncolor)) | |
74 | r = numpy.zeros((ncolor)) |
|
77 | r = numpy.zeros((ncolor)) | |
75 | g = numpy.zeros((ncolor)) |
|
78 | g = numpy.zeros((ncolor)) | |
76 | b = numpy.zeros((ncolor)) |
|
79 | b = numpy.zeros((ncolor)) | |
77 | ind = 0 |
|
80 | ind = 0 | |
78 | for ri in range(color_sz): |
|
81 | for ri in range(color_sz): | |
79 | for gi in range(color_sz): |
|
82 | for gi in range(color_sz): | |
80 | for bi in range(color_sz): |
|
83 | for bi in range(color_sz): | |
81 | r[ind] = ri/(color_sz-1.0) |
|
84 | r[ind] = ri/(color_sz-1.0) | |
82 | g[ind] = gi/(color_sz-1.0) |
|
85 | g[ind] = gi/(color_sz-1.0) | |
83 | b[ind] = bi/(color_sz-1.0) |
|
86 | b[ind] = bi/(color_sz-1.0) | |
84 | pos[ind] = ind/(ncolor-1.0) |
|
87 | pos[ind] = ind/(ncolor-1.0) | |
85 | ind += 1 |
|
88 | ind += 1 | |
86 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
89 | rgb_lvl = [6,6,6] #Levels for RGB colors | |
87 |
|
90 | |||
88 | if colormap == 'rgb676': |
|
91 | if colormap == 'rgb676': | |
89 | ncolor = 6*7*6 |
|
92 | ncolor = 6*7*6 | |
90 | pos = numpy.zeros((ncolor)) |
|
93 | pos = numpy.zeros((ncolor)) | |
91 | r = numpy.zeros((ncolor)) |
|
94 | r = numpy.zeros((ncolor)) | |
92 | g = numpy.zeros((ncolor)) |
|
95 | g = numpy.zeros((ncolor)) | |
93 | b = numpy.zeros((ncolor)) |
|
96 | b = numpy.zeros((ncolor)) | |
94 | ind = 0 |
|
97 | ind = 0 | |
95 | for ri in range(8): |
|
98 | for ri in range(8): | |
96 | for gi in range(8): |
|
99 | for gi in range(8): | |
97 | for bi in range(4): |
|
100 | for bi in range(4): | |
98 | r[ind] = ri/(6-1.0) |
|
101 | r[ind] = ri/(6-1.0) | |
99 | g[ind] = gi/(7-1.0) |
|
102 | g[ind] = gi/(7-1.0) | |
100 | b[ind] = bi/(6-1.0) |
|
103 | b[ind] = bi/(6-1.0) | |
101 | pos[ind] = ind/(ncolor-1.0) |
|
104 | pos[ind] = ind/(ncolor-1.0) | |
102 | ind += 1 |
|
105 | ind += 1 | |
103 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
106 | rgb_lvl = [6,7,6] #Levels for RGB colors | |
104 |
|
107 | |||
105 | if colormap == 'rgb685': |
|
108 | if colormap == 'rgb685': | |
106 | ncolor = 6*8*5 |
|
109 | ncolor = 6*8*5 | |
107 | pos = numpy.zeros((ncolor)) |
|
110 | pos = numpy.zeros((ncolor)) | |
108 | r = numpy.zeros((ncolor)) |
|
111 | r = numpy.zeros((ncolor)) | |
109 | g = numpy.zeros((ncolor)) |
|
112 | g = numpy.zeros((ncolor)) | |
110 | b = numpy.zeros((ncolor)) |
|
113 | b = numpy.zeros((ncolor)) | |
111 | ind = 0 |
|
114 | ind = 0 | |
112 | for ri in range(8): |
|
115 | for ri in range(8): | |
113 | for gi in range(8): |
|
116 | for gi in range(8): | |
114 | for bi in range(4): |
|
117 | for bi in range(4): | |
115 | r[ind] = ri/(6-1.0) |
|
118 | r[ind] = ri/(6-1.0) | |
116 | g[ind] = gi/(8-1.0) |
|
119 | g[ind] = gi/(8-1.0) | |
117 | b[ind] = bi/(5-1.0) |
|
120 | b[ind] = bi/(5-1.0) | |
118 | pos[ind] = ind/(ncolor-1.0) |
|
121 | pos[ind] = ind/(ncolor-1.0) | |
119 | ind += 1 |
|
122 | ind += 1 | |
120 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
123 | rgb_lvl = [6,8,5] #Levels for RGB colors | |
121 |
|
124 | |||
122 | if colormap == 'rgb884': |
|
125 | if colormap == 'rgb884': | |
123 | ncolor = 8*8*4 |
|
126 | ncolor = 8*8*4 | |
124 | pos = numpy.zeros((ncolor)) |
|
127 | pos = numpy.zeros((ncolor)) | |
125 | r = numpy.zeros((ncolor)) |
|
128 | r = numpy.zeros((ncolor)) | |
126 | g = numpy.zeros((ncolor)) |
|
129 | g = numpy.zeros((ncolor)) | |
127 | b = numpy.zeros((ncolor)) |
|
130 | b = numpy.zeros((ncolor)) | |
128 | ind = 0 |
|
131 | ind = 0 | |
129 | for ri in range(8): |
|
132 | for ri in range(8): | |
130 | for gi in range(8): |
|
133 | for gi in range(8): | |
131 | for bi in range(4): |
|
134 | for bi in range(4): | |
132 | r[ind] = ri/(8-1.0) |
|
135 | r[ind] = ri/(8-1.0) | |
133 | g[ind] = gi/(8-1.0) |
|
136 | g[ind] = gi/(8-1.0) | |
134 | b[ind] = bi/(4-1.0) |
|
137 | b[ind] = bi/(4-1.0) | |
135 | pos[ind] = ind/(ncolor-1.0) |
|
138 | pos[ind] = ind/(ncolor-1.0) | |
136 | ind += 1 |
|
139 | ind += 1 | |
137 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
140 | rgb_lvl = [8,8,4] #Levels for RGB colors | |
138 |
|
141 | |||
139 | if ncolor == None: |
|
142 | if ncolor == None: | |
140 | raise ValueError, "The colormap selected is not valid" |
|
143 | raise ValueError, "The colormap selected is not valid" | |
141 |
|
144 | |||
142 | plplot.plscmap1n(ncolor) |
|
145 | plplot.plscmap1n(ncolor) | |
143 | plplot.plscmap1l(1, pos, r, g, b) |
|
146 | plplot.plscmap1l(1, pos, r, g, b) | |
144 |
|
147 | |||
145 | return rgb_lvl |
|
148 | return rgb_lvl | |
146 |
|
149 | |||
|
150 | def setColormap(colormap="br_green"): | |||
|
151 | cmap1_init(colormap) | |||
|
152 | ||||
147 | class BaseGraph: |
|
153 | class BaseGraph: | |
148 | """ |
|
154 | """ | |
149 |
|
155 | |||
150 | """ |
|
156 | """ | |
|
157 | hasNotRange = True | |||
|
158 | ||||
|
159 | xrange = None | |||
|
160 | yrange = None | |||
|
161 | zrange = None | |||
151 |
|
162 | |||
152 |
|
163 | xlabel = None | ||
|
164 | ylabel = None | |||
|
165 | title = None | |||
|
166 | ||||
|
167 | legends = None | |||
|
168 | ||||
|
169 | __name = None | |||
|
170 | ||||
|
171 | __colormap = None | |||
|
172 | __colbox = None | |||
|
173 | __colleg = None | |||
|
174 | ||||
|
175 | __xpos = None | |||
|
176 | __ypos = None | |||
|
177 | ||||
|
178 | __xopt = None #"bcnst" | |||
|
179 | __yopt = None #"bcnstv" | |||
|
180 | ||||
|
181 | __xlpos = None | |||
|
182 | __ylpos = None | |||
|
183 | ||||
|
184 | __xrangeIsTime = False | |||
|
185 | ||||
|
186 | #Advanced | |||
|
187 | __xg = None | |||
|
188 | __yg = None | |||
153 |
|
189 | |||
154 | def __init__(self): |
|
190 | def __init__(self): | |
155 | """ |
|
191 | """ | |
156 |
|
192 | |||
157 | """ |
|
193 | """ | |
158 | self.hasNotRange = True |
|
194 | self.hasNotRange = True | |
159 |
|
195 | |||
160 | self.xrange = None |
|
196 | self.xrange = None | |
161 | self.yrange = None |
|
197 | self.yrange = None | |
162 | self.zrange = None |
|
198 | self.zrange = None | |
163 |
|
199 | |||
164 | self.xlabel = None |
|
200 | self.xlabel = None | |
165 | self.ylabel = None |
|
201 | self.ylabel = None | |
166 | self.title = None |
|
202 | self.title = None | |
167 |
|
203 | |||
168 | self.legends = None |
|
204 | self.legends = None | |
169 |
|
205 | |||
170 | self.__name = None |
|
206 | self.__name = None | |
171 |
|
207 | |||
172 | self.__colormap = None |
|
208 | self.__colormap = None | |
173 | self.__colbox = None |
|
209 | self.__colbox = None | |
174 | self.__colleg = None |
|
210 | self.__colleg = None | |
175 |
|
211 | |||
176 | self.__xpos = None |
|
212 | self.__xpos = None | |
177 | self.__ypos = None |
|
213 | self.__ypos = None | |
178 |
|
214 | |||
179 | self.__xopt = None #"bcnst" |
|
215 | self.__xopt = None #"bcnst" | |
180 | self.__yopt = None #"bcnstv" |
|
216 | self.__yopt = None #"bcnstv" | |
181 |
|
217 | |||
182 | self.__xlpos = None |
|
218 | self.__xlpos = None | |
183 | self.__ylpos = None |
|
219 | self.__ylpos = None | |
184 |
|
220 | |||
185 | self.__xrangeIsTime = False |
|
221 | self.__xrangeIsTime = False | |
186 |
|
222 | |||
187 | #Advanced |
|
223 | #Advanced | |
188 | self.__xg = None |
|
224 | self.__xg = None | |
189 | self.__yg = None |
|
225 | self.__yg = None | |
190 |
|
226 | |||
191 | def setName(self, name): |
|
227 | def setName(self, name): | |
192 | self.__name = name |
|
228 | self.__name = name | |
193 |
|
229 | |||
194 | def setScreenPos(self, xpos, ypos): |
|
230 | def setScreenPos(self, xpos, ypos): | |
195 | self.__xpos = xpos |
|
231 | self.__xpos = xpos | |
196 | self.__ypos = ypos |
|
232 | self.__ypos = ypos | |
197 |
|
233 | |||
198 | def setOpt(self, xopt, yopt): |
|
234 | def setOpt(self, xopt, yopt): | |
199 | self.__xopt = xopt |
|
235 | self.__xopt = xopt | |
200 | self.__yopt = yopt |
|
236 | self.__yopt = yopt | |
201 |
|
237 | |||
202 | def setXAxisAsTime(self): |
|
238 | def setXAxisAsTime(self): | |
203 | self.__xrangeIsTime = True |
|
239 | self.__xrangeIsTime = True | |
204 |
|
240 | |||
205 |
|
241 | |||
206 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): |
|
242 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): | |
207 | """ |
|
243 | """ | |
208 | """ |
|
244 | """ | |
209 | self.title = title |
|
245 | self.title = title | |
210 | self.xlabel = xlabel |
|
246 | self.xlabel = xlabel | |
211 | self.ylabel = ylabel |
|
247 | self.ylabel = ylabel | |
212 | self.__colormap = colormap |
|
248 | self.__colormap = colormap | |
213 |
|
249 | |||
214 | def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False): |
|
250 | def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False): | |
215 | """ |
|
251 | """ | |
216 |
|
252 | |||
217 | """ |
|
253 | """ | |
218 | if self.__xrangeIsTime: |
|
254 | if self.__xrangeIsTime: | |
219 | plplot.pltimefmt("%H:%M") |
|
255 | plplot.pltimefmt("%H:%M") | |
220 |
|
256 | |||
221 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) |
|
257 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |
222 | plplot.plwind(float(xmin), |
|
258 | plplot.plwind(float(xmin), | |
223 | float(xmax), |
|
259 | float(xmax), | |
224 | float(ymin), |
|
260 | float(ymin), | |
225 | float(ymax) |
|
261 | float(ymax) | |
226 | ) |
|
262 | ) | |
227 |
|
263 | |||
228 | if xopt == None: xopt = self.__xopt |
|
264 | if xopt == None: xopt = self.__xopt | |
229 | if yopt == None: yopt = self.__yopt |
|
265 | if yopt == None: yopt = self.__yopt | |
230 |
|
266 | |||
231 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
267 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | |
232 |
|
268 | |||
233 | if not(nolabels): |
|
269 | if not(nolabels): | |
234 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
270 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |
235 |
|
271 | |||
236 |
|
272 | |||
237 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): |
|
273 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): | |
238 | data = numpy.arange(256) |
|
274 | data = numpy.arange(256) | |
239 | data = numpy.reshape(data, (1,-1)) |
|
275 | data = numpy.reshape(data, (1,-1)) | |
240 |
|
276 | |||
241 | plplot.plimage(data, |
|
277 | plplot.plimage(data, | |
242 | float(xmin), |
|
278 | float(xmin), | |
243 | float(xmax), |
|
279 | float(xmax), | |
244 | float(ymin), |
|
280 | float(ymin), | |
245 | float(ymax), |
|
281 | float(ymax), | |
246 | 0., |
|
282 | 0., | |
247 | 255., |
|
283 | 255., | |
248 | float(xmin), |
|
284 | float(xmin), | |
249 | float(xmax), |
|
285 | float(xmax), | |
250 | float(ymin), |
|
286 | float(ymin), | |
251 | float(ymax)) |
|
287 | float(ymax)) | |
252 |
|
288 | |||
253 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): |
|
289 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): | |
254 |
|
290 | |||
255 | if xmin == None: xmin = x[0] |
|
291 | if xmin == None: xmin = x[0] | |
256 | if xmax == None: xmax = x[-1] |
|
292 | if xmax == None: xmax = x[-1] | |
257 | if ymin == None: ymin = y[0] |
|
293 | if ymin == None: ymin = y[0] | |
258 | if ymax == None: ymax = y[-1] |
|
294 | if ymax == None: ymax = y[-1] | |
259 |
|
295 | |||
260 | plplot.plline(x, y) |
|
296 | plplot.plline(x, y) | |
261 |
|
297 | |||
262 | def basicXYwithErrorPlot(self): |
|
298 | def basicXYwithErrorPlot(self): | |
263 | pass |
|
299 | pass | |
264 |
|
300 | |||
265 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
301 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): | |
266 |
|
302 | |||
267 | if xmin == None: xmin = x[0] |
|
303 | if xmin == None: xmin = x[0] | |
268 | if xmax == None: xmax = x[-1] |
|
304 | if xmax == None: xmax = x[-1] | |
269 | if ymin == None: ymin = y[0] |
|
305 | if ymin == None: ymin = y[0] | |
270 | if ymax == None: ymax = y[-1] |
|
306 | if ymax == None: ymax = y[-1] | |
271 |
|
307 | |||
272 | plplot.plcol0(colline) |
|
308 | plplot.plcol0(colline) | |
273 | plplot.plline(x, y) |
|
309 | plplot.plline(x, y) | |
274 | plplot.plcol0(1) |
|
310 | plplot.plcol0(1) | |
275 |
|
311 | |||
276 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
312 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
277 | """ |
|
313 | """ | |
278 | """ |
|
314 | """ | |
279 | if xmin == None: xmin = x[0] |
|
315 | if xmin == None: xmin = x[0] | |
280 | if xmax == None: xmax = x[-1] |
|
316 | if xmax == None: xmax = x[-1] | |
281 | if ymin == None: ymin = y[0] |
|
317 | if ymin == None: ymin = y[0] | |
282 | if ymax == None: ymax = y[-1] |
|
318 | if ymax == None: ymax = y[-1] | |
283 | if zmin == None: zmin = numpy.nanmin(data) |
|
319 | if zmin == None: zmin = numpy.nanmin(data) | |
284 | if zmax == None: zmax = numpy.nanmax(data) |
|
320 | if zmax == None: zmax = numpy.nanmax(data) | |
285 |
|
321 | |||
286 | plplot.plimage(data, |
|
322 | plplot.plimage(data, | |
287 | float(x[0]), |
|
323 | float(x[0]), | |
288 | float(x[-1]), |
|
324 | float(x[-1]), | |
289 | float(y[0]), |
|
325 | float(y[0]), | |
290 | float(y[-1]), |
|
326 | float(y[-1]), | |
291 | float(zmin), |
|
327 | float(zmin), | |
292 | float(zmax), |
|
328 | float(zmax), | |
293 | float(xmin), |
|
329 | float(xmin), | |
294 | float(xmax), |
|
330 | float(xmax), | |
295 | float(ymin), |
|
331 | float(ymin), | |
296 | float(ymax) |
|
332 | float(ymax) | |
297 | ) |
|
333 | ) | |
298 |
|
334 | |||
299 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
335 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): | |
300 |
|
336 | |||
301 | if not(len(x)>1 and len(y)>1): |
|
337 | if not(len(x)>1 and len(y)>1): | |
302 | raise ValueError, "x axis and y axis are empty" |
|
338 | raise ValueError, "x axis and y axis are empty" | |
303 |
|
339 | |||
304 | if deltax == None: deltax = x[-1] - x[-2] |
|
340 | if deltax == None: deltax = x[-1] - x[-2] | |
305 | if deltay == None: deltay = y[-1] - y[-2] |
|
341 | if deltay == None: deltay = y[-1] - y[-2] | |
306 |
|
342 | |||
307 | x1 = numpy.append(x, x[-1] + deltax) |
|
343 | x1 = numpy.append(x, x[-1] + deltax) | |
308 | y1 = numpy.append(y, y[-1] + deltay) |
|
344 | y1 = numpy.append(y, y[-1] + deltay) | |
309 |
|
345 | |||
310 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
346 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |
311 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
347 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |
312 |
|
348 | |||
313 | self.__xg = xg |
|
349 | self.__xg = xg | |
314 | self.__yg = yg |
|
350 | self.__yg = yg | |
315 |
|
351 | |||
316 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): |
|
352 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): | |
317 | """ |
|
353 | """ | |
318 | """ |
|
354 | """ | |
319 |
|
355 | |||
320 | if self.__xg == None and self.__yg == None: |
|
356 | if self.__xg == None and self.__yg == None: | |
321 | self.__getBoxpltr(x, y) |
|
357 | self.__getBoxpltr(x, y) | |
322 |
|
358 | |||
323 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) |
|
359 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) | |
324 |
|
360 | |||
325 |
|
361 | |||
326 |
class LinearPlot |
|
362 | class LinearPlot: | |
|
363 | ||||
|
364 | linearGraphObj = BaseGraph() | |||
327 |
|
365 | |||
328 | __szchar = 1.0 |
|
366 | __szchar = 1.0 | |
|
367 | ||||
329 | __xrange = None |
|
368 | __xrange = None | |
|
369 | ||||
330 | __yrange = None |
|
370 | __yrange = None | |
331 |
|
371 | |||
332 | m_BaseGraph = None |
|
372 | __subpage = 0 | |
|
373 | m_BaseGraph= BaseGraph() | |||
|
374 | ||||
|
375 | ||||
333 |
|
376 | |||
334 | def __init__(self): |
|
377 | def __init__(self): | |
335 |
|
378 | |||
336 |
|
379 | |||
337 | key = "linearplot" |
|
380 | key = "linearplot" | |
338 |
self. |
|
381 | self.linearGraphObj = BaseGraph() | |
339 |
self. |
|
382 | self.linearGraphObj.setName(key) | |
340 |
|
383 | |||
341 | self.__subpage = 0 |
|
384 | self.__subpage = 0 | |
342 |
|
385 | |||
343 | def setColormap(self, colormap="br_green"): |
|
386 | def __iniSubpage(self): | |
344 |
|
||||
345 | if colormap == None: |
|
|||
346 | colormap = self.__colormap |
|
|||
347 |
|
||||
348 | cmap1_init(colormap) |
|
|||
349 |
|
||||
350 | def iniSubpage(self): |
|
|||
351 |
|
387 | |||
352 | if plplot.plgdev() == '': |
|
388 | if plplot.plgdev() == '': | |
353 | raise ValueError, "Plot device has not been initialize" |
|
389 | raise ValueError, "Plot device has not been initialize" | |
354 |
|
390 | |||
355 | plplot.pladv(self.__subpage) |
|
391 | plplot.pladv(self.__subpage) | |
356 | plplot.plschr(0.0, self.__szchar) |
|
392 | plplot.plschr(0.0, self.__szchar) | |
357 |
|
393 | |||
358 |
|
|
394 | setColormap() | |
359 |
|
395 | |||
360 | def setScreenPos(self, width='small'): |
|
396 | def setScreenPos(self, width='small'): | |
361 |
|
397 | |||
362 | if width == 'small': |
|
398 | if width == 'small': | |
363 | xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80 |
|
399 | xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80 | |
364 |
|
400 | |||
365 | if width == 'medium': |
|
401 | if width == 'medium': | |
366 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60 |
|
402 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60 | |
367 |
|
403 | |||
368 | xf = xi + xw |
|
404 | xf = xi + xw | |
369 | yf = yi + yw |
|
405 | yf = yi + yw | |
370 |
|
406 | |||
371 |
self. |
|
407 | self.linearGraphObj.setScreenPos([xi, xf], [yi, yf]) | |
372 |
|
408 | |||
373 | def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): |
|
409 | def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): | |
374 | """ |
|
410 | """ | |
375 | """ |
|
411 | """ | |
376 |
|
412 | |||
377 |
self. |
|
413 | self.linearGraphObj.setOpt("bcnts","bcntsv") | |
378 |
self. |
|
414 | self.linearGraphObj.setup(title, | |
379 | xlabel, |
|
415 | xlabel, | |
380 | ylabel |
|
416 | ylabel | |
381 | ) |
|
417 | ) | |
382 |
|
418 | |||
383 | self.setScreenPos(width='medium') |
|
419 | self.setScreenPos(width='medium') | |
384 |
|
420 | |||
385 | if XAxisAsTime: |
|
421 | if XAxisAsTime: | |
386 |
self. |
|
422 | self.linearGraphObj.setXAxisAsTime() | |
387 |
|
423 | |||
388 | self.__subpage = subpage |
|
424 | self.__subpage = subpage | |
389 | # def setRanges(self, xrange, yrange, zrange): |
|
425 | # def setRanges(self, xrange, yrange, zrange): | |
390 | # |
|
426 | # | |
391 |
# self. |
|
427 | # self.linearGraphObj.setRanges(xrange, yrange, zrange) | |
392 |
|
428 | |||
393 | def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
429 | def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): | |
394 | """ |
|
430 | """ | |
395 | Inputs: |
|
431 | Inputs: | |
396 |
|
432 | |||
397 | x : Numpy array of dimension 1 |
|
433 | x : Numpy array of dimension 1 | |
398 | y : Numpy array of dimension 1 |
|
434 | y : Numpy array of dimension 1 | |
399 |
|
435 | |||
400 | """ |
|
436 | """ | |
401 |
|
437 | |||
402 | try: |
|
438 | try: | |
403 | nX = numpy.shape(x) |
|
439 | nX = numpy.shape(x) | |
404 | except: |
|
440 | except: | |
405 | raise ValueError, "x is not a numpy array" |
|
441 | raise ValueError, "x is not a numpy array" | |
406 |
|
442 | |||
407 | if y == None: y = numpy.arange(nX) |
|
443 | if y == None: y = numpy.arange(nX) | |
408 |
|
444 | |||
409 | if xmin == None: xmin = x[0] |
|
445 | if xmin == None: xmin = x[0] | |
410 | if xmax == None: xmax = x[-1] |
|
446 | if xmax == None: xmax = x[-1] | |
411 | if ymin == None: ymin = y[0] |
|
447 | if ymin == None: ymin = y[0] | |
412 | if ymax == None: ymax = y[-1] |
|
448 | if ymax == None: ymax = y[-1] | |
413 |
|
449 | |||
414 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) |
|
450 | self.__iniSubpage() | |
415 |
self. |
|
451 | self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) | |
|
452 | self.linearGraphObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) | |||
416 |
|
453 | |||
417 | def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): |
|
454 | def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): | |
418 | """ |
|
455 | """ | |
419 | Inputs: |
|
456 | Inputs: | |
420 |
|
457 | |||
421 | x : Numpy array of dimension 1 |
|
458 | x : Numpy array of dimension 1 | |
422 | y : Complex numpy array of dimension 1 |
|
459 | y : Complex numpy array of dimension 1 | |
423 |
|
460 | |||
424 | """ |
|
461 | """ | |
425 |
|
462 | |||
426 | try: |
|
463 | try: | |
427 | nX = numpy.shape(x) |
|
464 | nX = numpy.shape(x) | |
428 | except: |
|
465 | except: | |
429 | raise ValueError, "x is not a numpy array" |
|
466 | raise ValueError, "x is not a numpy array" | |
430 |
|
467 | |||
431 | try: |
|
468 | try: | |
432 | nY = numpy.shape(y) |
|
469 | nY = numpy.shape(y) | |
433 | except: |
|
470 | except: | |
434 | raise ValueError, "y is not a numpy array" |
|
471 | raise ValueError, "y is not a numpy array" | |
435 |
|
472 | |||
436 | if xmin == None: xmin = x[0] |
|
473 | if xmin == None: xmin = x[0] | |
437 | if xmax == None: xmax = x[-1] |
|
474 | if xmax == None: xmax = x[-1] | |
438 | if ymin == None: ymin = y[0] |
|
475 | if ymin == None: ymin = y[0] | |
439 | if ymax == None: ymax = y[-1] |
|
476 | if ymax == None: ymax = y[-1] | |
440 |
|
477 | |||
441 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) |
|
478 | self.__iniSubpage() | |
|
479 | self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) | |||
442 |
|
480 | |||
443 | if type.lower() == 'power': |
|
481 | if type.lower() == 'power': | |
444 |
self. |
|
482 | self.linearGraphObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) | |
445 |
|
483 | |||
446 | if type.lower() == 'iq': |
|
484 | if type.lower() == 'iq': | |
447 |
|
485 | |||
448 |
self. |
|
486 | self.linearGraphObj.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) | |
449 |
self. |
|
487 | self.linearGraphObj.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) | |
450 |
|
488 | |||
451 |
class ColorPlot |
|
489 | class ColorPlot: | |
|
490 | ||||
|
491 | colorGraphObj = BaseGraph() | |||
|
492 | ||||
|
493 | graphObjDict = {} | |||
452 |
|
494 | |||
|
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 | ||||
453 | def __init__(self): |
|
512 | def __init__(self): | |
454 |
|
513 | |||
455 | self.graphObjDict = {} |
|
514 | self.graphObjDict = {} | |
456 |
|
515 | |||
457 | self.__subpage = 0 |
|
516 | self.__subpage = 0 | |
458 | self.__showColorbar = False |
|
517 | self.__showColorbar = False | |
459 | self.__showPowerProfile = True |
|
518 | self.__showPowerProfile = True | |
460 |
|
519 | |||
461 | self.__szchar = 0.65 |
|
520 | self.__szchar = 0.65 | |
462 | self.__xrange = None |
|
521 | self.__xrange = None | |
463 | self.__yrange = None |
|
522 | self.__yrange = None | |
464 | self.__zrange = None |
|
523 | self.__zrange = None | |
465 |
|
524 | |||
466 | key = "colorplot" |
|
525 | key = "colorplot" | |
467 |
self. |
|
526 | self.colorGraphObj = BaseGraph() | |
468 |
self. |
|
527 | self.colorGraphObj.setName(key) | |
469 |
|
528 | |||
470 |
def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap=" |
|
529 | def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | |
471 | """ |
|
530 | """ | |
472 | """ |
|
531 | """ | |
473 |
|
532 | |||
474 |
self. |
|
533 | self.colorGraphObj.setOpt("bcnts","bcntsv") | |
475 |
self. |
|
534 | self.colorGraphObj.setup(title, | |
476 | xlabel, |
|
535 | xlabel, | |
477 | ylabel |
|
536 | ylabel | |
478 | ) |
|
537 | ) | |
479 |
|
538 | |||
480 | self.__subpage = subpage |
|
539 | self.__subpage = subpage | |
481 | self.__colormap = colormap |
|
540 | self.__colormap = colormap | |
482 | self.__showColorbar = showColorbar |
|
541 | self.__showColorbar = showColorbar | |
483 | self.__showPowerProfile = showPowerProfile |
|
542 | self.__showPowerProfile = showPowerProfile | |
484 |
|
543 | |||
485 | if showColorbar: |
|
544 | if showColorbar: | |
486 | key = "colorbar" |
|
545 | key = "colorbar" | |
487 |
|
546 | |||
488 | cmapObj = BaseGraph() |
|
547 | cmapObj = BaseGraph() | |
489 | cmapObj.setName(key) |
|
548 | cmapObj.setName(key) | |
490 | cmapObj.setOpt("bc","bcmtv") |
|
549 | cmapObj.setOpt("bc","bcmtv") | |
491 | cmapObj.setup(title="dBs", |
|
550 | cmapObj.setup(title="dBs", | |
492 | xlabel="", |
|
551 | xlabel="", | |
493 | ylabel="", |
|
552 | ylabel="", | |
494 | colormap=colormap) |
|
553 | colormap=colormap) | |
495 |
|
554 | |||
496 | self.graphObjDict[key] = cmapObj |
|
555 | self.graphObjDict[key] = cmapObj | |
497 |
|
556 | |||
498 |
|
557 | |||
499 | if showPowerProfile: |
|
558 | if showPowerProfile: | |
500 | key = "powerprof" |
|
559 | key = "powerprof" | |
501 |
|
560 | |||
502 | powObj = BaseGraph() |
|
561 | powObj = BaseGraph() | |
503 | powObj.setName(key) |
|
562 | powObj.setName(key) | |
504 | powObj.setOpt("bcntg","bc") |
|
563 | powObj.setOpt("bcntg","bc") | |
505 | powObj.setup(title="Power Profile", |
|
564 | powObj.setup(title="Power Profile", | |
506 | xlabel="dB", |
|
565 | xlabel="dB", | |
507 | ylabel="") |
|
566 | ylabel="") | |
508 |
|
567 | |||
509 | self.graphObjDict[key] = powObj |
|
568 | self.graphObjDict[key] = powObj | |
510 |
|
569 | |||
511 | self.setScreenPos(width='small') |
|
570 | self.setScreenPos(width='small') | |
512 |
|
571 | |||
513 | if XAxisAsTime: |
|
572 | if XAxisAsTime: | |
514 |
self. |
|
573 | self.colorGraphObj.setXAxisAsTime() | |
515 |
|
574 | |||
516 |
|
575 | def __iniSubpage(self): | ||
517 |
|
||||
518 | def setColormap(self, colormap="br_green"): |
|
|||
519 |
|
||||
520 | if colormap == None: |
|
|||
521 | colormap = self.__colormap |
|
|||
522 |
|
||||
523 | cmap1_init(colormap) |
|
|||
524 |
|
||||
525 | def iniSubpage(self): |
|
|||
526 |
|
576 | |||
527 | if plplot.plgdev() == '': |
|
577 | if plplot.plgdev() == '': | |
528 | raise ValueError, "Plot device has not been initialize" |
|
578 | raise ValueError, "Plot device has not been initialize" | |
529 |
|
579 | |||
530 | plplot.pladv(self.__subpage) |
|
580 | plplot.pladv(self.__subpage) | |
531 | plplot.plschr(0.0, self.__szchar) |
|
581 | plplot.plschr(0.0, self.__szchar) | |
532 |
|
582 | |||
533 |
self. |
|
583 | setColormap(self.__colormap) | |
534 |
|
584 | |||
535 | def setScreenPos(self, width='small'): |
|
585 | def setScreenPos(self, width='small'): | |
536 |
|
586 | |||
537 | if width == 'small': |
|
587 | if width == 'small': | |
538 | xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.04; xpoww = 0.25; deltaxcmap = 0.02; deltaxpow = 0.06 |
|
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 | |
539 |
|
589 | |||
540 | if width == 'medium': |
|
590 | if width == 'medium': | |
541 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.04; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06 |
|
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 | |
542 |
|
592 | |||
543 | if self.__showColorbar: |
|
593 | if self.__showColorbar: | |
544 | xw -= xcmapw + deltaxcmap |
|
594 | xw -= xcmapw + deltaxcmap | |
545 |
|
595 | |||
546 | if self.__showPowerProfile: |
|
596 | if self.__showPowerProfile: | |
547 | xw -= xpoww + deltaxpow |
|
597 | xw -= xpoww + deltaxpow | |
548 |
|
598 | |||
549 | xf = xi + xw |
|
599 | xf = xi + xw | |
550 | yf = yi + yw |
|
600 | yf = yi + yw | |
551 | xcmapf = xf |
|
601 | xcmapf = xf | |
552 |
|
602 | |||
553 |
self. |
|
603 | self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) | |
554 |
|
604 | |||
555 | if self.__showColorbar: |
|
605 | if self.__showColorbar: | |
556 | xcmapi = xf + deltaxcmap |
|
606 | xcmapi = xf + deltaxcmap | |
557 | xcmapf = xcmapi + xcmapw |
|
607 | xcmapf = xcmapi + xcmapw | |
558 |
|
608 | |||
559 | key = "colorbar" |
|
609 | key = "colorbar" | |
560 | cmapObj = self.graphObjDict[key] |
|
610 | cmapObj = self.graphObjDict[key] | |
561 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) |
|
611 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |
562 |
|
612 | |||
563 | if self.__showPowerProfile: |
|
613 | if self.__showPowerProfile: | |
564 |
|
614 | |||
565 | xpowi = xcmapf + deltaxpow |
|
615 | xpowi = xcmapf + deltaxpow | |
566 | xpowf = xpowi + xpoww |
|
616 | xpowf = xpowi + xpoww | |
567 |
|
617 | |||
568 | key = "powerprof" |
|
618 | key = "powerprof" | |
569 | powObj = self.graphObjDict[key] |
|
619 | powObj = self.graphObjDict[key] | |
570 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) |
|
620 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |
571 |
|
621 | |||
572 |
|
622 | |||
573 |
|
623 | |||
574 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
624 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
575 | """ |
|
625 | """ | |
576 | Inputs: |
|
626 | Inputs: | |
577 |
|
627 | |||
578 | x : Numpy array of dimension 1 |
|
628 | x : Numpy array of dimension 1 | |
579 | y : Numpy array of dimension 1 |
|
629 | y : Numpy array of dimension 1 | |
580 |
|
630 | |||
581 | """ |
|
631 | """ | |
582 |
|
632 | |||
583 | try: |
|
633 | try: | |
584 | nX, nY = numpy.shape(data) |
|
634 | nX, nY = numpy.shape(data) | |
585 | except: |
|
635 | except: | |
586 | raise ValueError, "data is not a numpy array" |
|
636 | raise ValueError, "data is not a numpy array" | |
587 |
|
637 | |||
588 | if x == None: x = numpy.arange(nX) |
|
638 | if x == None: x = numpy.arange(nX) | |
589 | if y == None: y = numpy.arange(nY) |
|
639 | if y == None: y = numpy.arange(nY) | |
590 |
|
640 | |||
591 | if xmin == None: xmin = x[0] |
|
641 | if xmin == None: xmin = x[0] | |
592 | if xmax == None: xmax = x[-1] |
|
642 | if xmax == None: xmax = x[-1] | |
593 | if ymin == None: ymin = y[0] |
|
643 | if ymin == None: ymin = y[0] | |
594 | if ymax == None: ymax = y[-1] |
|
644 | if ymax == None: ymax = y[-1] | |
595 | if zmin == None: zmin = numpy.nanmin(data) |
|
645 | if zmin == None: zmin = numpy.nanmin(data) | |
596 | if zmax == None: zmax = numpy.nanmax(data) |
|
646 | if zmax == None: zmax = numpy.nanmax(data) | |
597 |
|
647 | |||
598 | plplot.plschr(0.0, self.__szchar) |
|
648 | plplot.plschr(0.0, self.__szchar) | |
599 |
|
649 | self.__iniSubpage() | ||
600 |
self. |
|
650 | self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax) | |
601 |
self. |
|
651 | self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) | |
602 |
|
652 | |||
603 | if self.__showColorbar: |
|
653 | if self.__showColorbar: | |
604 |
|
654 | |||
605 |
|
655 | |||
606 | key = "colorbar" |
|
656 | key = "colorbar" | |
607 | cmapObj = self.graphObjDict[key] |
|
657 | cmapObj = self.graphObjDict[key] | |
608 |
|
658 | |||
609 | plplot.plschr(0.0, self.__szchar-0.05) |
|
659 | plplot.plschr(0.0, self.__szchar-0.05) | |
610 | cmapObj.plotBox(0., 1., zmin, zmax) |
|
660 | cmapObj.plotBox(0., 1., zmin, zmax) | |
611 | cmapObj.colorbarPlot(0., 1., zmin, zmax) |
|
661 | cmapObj.colorbarPlot(0., 1., zmin, zmax) | |
612 |
|
662 | |||
613 | if self.__showPowerProfile: |
|
663 | if self.__showPowerProfile: | |
614 | power = numpy.max(data, axis=0) |
|
664 | power = numpy.max(data, axis=0) | |
615 |
|
665 | |||
616 | step = (ymax - ymin)/(nY-1) |
|
666 | step = (ymax - ymin)/(nY-1) | |
617 | heis = numpy.arange(ymin, ymax + step, step) |
|
667 | heis = numpy.arange(ymin, ymax + step, step) | |
618 |
|
668 | |||
619 | key = "powerprof" |
|
669 | key = "powerprof" | |
620 | powObj = self.graphObjDict[key] |
|
670 | powObj = self.graphObjDict[key] | |
621 |
|
671 | |||
622 | plplot.pllsty(2) |
|
672 | plplot.pllsty(2) | |
623 | plplot.plschr(0.0, self.__szchar-0.05) |
|
673 | plplot.plschr(0.0, self.__szchar-0.05) | |
624 | powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True) |
|
674 | powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True) | |
625 |
|
675 | |||
626 | plplot.pllsty(1) |
|
676 | plplot.pllsty(1) | |
627 | plplot.plschr(0.0, self.__szchar) |
|
677 | plplot.plschr(0.0, self.__szchar) | |
628 | powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc') |
|
678 | powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc') | |
629 |
|
679 | |||
630 | plplot.plcol0(9) |
|
680 | plplot.plcol0(9) | |
631 | powObj.basicXYPlot(power, heis) |
|
681 | powObj.basicXYPlot(power, heis) | |
632 | plplot.plcol0(1) |
|
682 | plplot.plcol0(1) | |
633 |
|
683 | |||
634 |
|
684 | |||
635 |
class ColorPlotX |
|
685 | class ColorPlotX: | |
636 |
|
686 | |||
637 |
|
687 | |||
638 | graphObjDict = {} |
|
688 | graphObjDict = {} | |
639 | showColorbar = False |
|
689 | showColorbar = False | |
640 | showPowerProfile = True |
|
690 | showPowerProfile = True | |
641 |
|
691 | |||
642 | __szchar = 0.7 |
|
692 | __szchar = 0.7 | |
643 | __xrange = None |
|
693 | __xrange = None | |
644 | __yrange = None |
|
694 | __yrange = None | |
645 | __zrange = None |
|
695 | __zrange = None | |
646 |
|
696 | |||
647 |
|
|
697 | colorGraphObj = BaseGraph() | |
648 |
|
698 | |||
649 | def __init__(self): |
|
699 | def __init__(self): | |
650 |
|
700 | |||
651 | key = "colorplot" |
|
701 | key = "colorplot" | |
652 |
self. |
|
702 | self.colorGraphObj.setName(key) | |
653 |
|
703 | |||
654 | self.__subpage = 0 |
|
704 | self.__subpage = 0 | |
655 |
|
705 | |||
656 |
self.graphObjDict[key] = self. |
|
706 | self.graphObjDict[key] = self.colorGraphObj | |
657 |
|
707 | |||
658 | def setColormap(self, colormap="br_green"): |
|
708 | def __iniSubpage(self): | |
659 |
|
||||
660 | if colormap == None: |
|
|||
661 | colormap = self.__colormap |
|
|||
662 |
|
||||
663 | cmap1_init(colormap) |
|
|||
664 |
|
||||
665 | def iniSubpage(self): |
|
|||
666 |
|
709 | |||
667 | if plplot.plgdev() == '': |
|
710 | if plplot.plgdev() == '': | |
668 | raise ValueError, "Plot device has not been initialize" |
|
711 | raise ValueError, "Plot device has not been initialize" | |
669 |
|
712 | |||
670 | plplot.pladv(self.__subpage) |
|
713 | plplot.pladv(self.__subpage) | |
671 | plplot.plschr(0.0, self.__szchar) |
|
714 | plplot.plschr(0.0, self.__szchar) | |
672 |
|
715 | |||
673 |
self. |
|
716 | setColormap(self.__colormap) | |
|
717 | ||||
|
718 | 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): | |||
|
719 | ||||
|
720 | if self.showColorbar: | |||
|
721 | xw -= xcmapw + deltaxcmap | |||
|
722 | ||||
|
723 | if self.showPowerProfile: | |||
|
724 | xw -= xpoww + deltaxpow | |||
674 |
|
725 | |||
|
726 | xf = xi + xw | |||
|
727 | yf = yi + yw | |||
|
728 | xcmapf = xf | |||
|
729 | ||||
|
730 | self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) | |||
|
731 | ||||
|
732 | if self.showColorbar: | |||
|
733 | xcmapi = xf + deltaxcmap | |||
|
734 | xcmapf = xcmapi + xcmapw | |||
|
735 | ||||
|
736 | key = "colorbar" | |||
|
737 | cmapObj = self.graphObjDict[key] | |||
|
738 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |||
|
739 | ||||
|
740 | if self.showPowerProfile: | |||
|
741 | ||||
|
742 | xpowi = xcmapf + deltaxpow | |||
|
743 | xpowf = xpowi + xpoww | |||
|
744 | ||||
|
745 | key = "powerprof" | |||
|
746 | powObj = self.graphObjDict[key] | |||
|
747 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |||
|
748 | ||||
|
749 | def setRanges(self, xrange, yrange, zrange): | |||
|
750 | ||||
|
751 | self.colorGraphObj.setRanges(xrange, yrange, zrange) | |||
|
752 | ||||
|
753 | keyList = self.graphObjDict.keys() | |||
|
754 | ||||
|
755 | key = "colorbar" | |||
|
756 | if key in keyList: | |||
|
757 | cmapObj = self.graphObjDict[key] | |||
|
758 | cmapObj.setRanges([0., 1.], zrange) | |||
|
759 | ||||
|
760 | key = "powerprof" | |||
|
761 | if key in keyList: | |||
|
762 | powObj = self.graphObjDict[key] | |||
|
763 | powObj.setRanges(zrange, yrange) | |||
|
764 | ||||
675 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): |
|
765 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | |
676 | """ |
|
766 | """ | |
677 | """ |
|
767 | """ | |
678 |
|
768 | |||
679 |
self. |
|
769 | self.colorGraphObj.setSubpage(subpage) | |
680 |
self. |
|
770 | self.colorGraphObj.setSzchar(self.__szchar) | |
681 |
self. |
|
771 | self.colorGraphObj.setOpt("bcnts","bcntsv") | |
682 |
self. |
|
772 | self.colorGraphObj.setup(title, | |
683 | xlabel, |
|
773 | xlabel, | |
684 | ylabel, |
|
774 | ylabel, | |
685 | colormap) |
|
775 | colormap) | |
686 |
|
776 | |||
687 | if showColorbar: |
|
777 | if showColorbar: | |
688 | key = "colorbar" |
|
778 | key = "colorbar" | |
689 |
|
779 | |||
690 | cmapObj = BaseGraph() |
|
780 | cmapObj = BaseGraph() | |
691 | cmapObj.setName(key) |
|
781 | cmapObj.setName(key) | |
692 | cmapObj.setSubpage(subpage) |
|
782 | cmapObj.setSubpage(subpage) | |
693 | cmapObj.setSzchar(self.__szchar) |
|
783 | cmapObj.setSzchar(self.__szchar) | |
694 | cmapObj.setOpt("bc","bcmt") |
|
784 | cmapObj.setOpt("bc","bcmt") | |
695 | cmapObj.setup(title="dBs", |
|
785 | cmapObj.setup(title="dBs", | |
696 | xlabel="", |
|
786 | xlabel="", | |
697 | ylabel="", |
|
787 | ylabel="", | |
698 | colormap=colormap) |
|
788 | colormap=colormap) | |
699 |
|
789 | |||
700 | self.graphObjDict[key] = cmapObj |
|
790 | self.graphObjDict[key] = cmapObj | |
701 |
|
791 | |||
702 |
|
792 | |||
703 | if showPowerProfile: |
|
793 | if showPowerProfile: | |
704 | key = "powerprof" |
|
794 | key = "powerprof" | |
705 |
|
795 | |||
706 | powObj = BaseGraph() |
|
796 | powObj = BaseGraph() | |
707 | powObj.setName(key) |
|
797 | powObj.setName(key) | |
708 | powObj.setSubpage(subpage) |
|
798 | powObj.setSubpage(subpage) | |
709 | powObj.setSzchar(self.__szchar) |
|
799 | powObj.setSzchar(self.__szchar) | |
710 | plplot.pllsty(2) |
|
800 | plplot.pllsty(2) | |
711 | powObj.setOpt("bcntg","bc") |
|
801 | powObj.setOpt("bcntg","bc") | |
712 | plplot.pllsty(1) |
|
802 | plplot.pllsty(1) | |
713 | powObj.setup(title="Power Profile", |
|
803 | powObj.setup(title="Power Profile", | |
714 | xlabel="dBs", |
|
804 | xlabel="dBs", | |
715 | ylabel="") |
|
805 | ylabel="") | |
716 |
|
806 | |||
717 | self.graphObjDict[key] = powObj |
|
807 | self.graphObjDict[key] = powObj | |
718 |
|
808 | |||
719 | self.showColorbar = showColorbar |
|
809 | self.showColorbar = showColorbar | |
720 | self.showPowerProfile = showPowerProfile |
|
810 | self.showPowerProfile = showPowerProfile | |
721 | self.setScreenPos() |
|
811 | self.setScreenPos() | |
722 |
|
812 | |||
723 | if XAxisAsTime: |
|
813 | if XAxisAsTime: | |
724 |
self. |
|
814 | self.colorGraphObj.setXAxisAsTime() | |
725 | #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) |
|
815 | #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) | |
726 |
|
816 | |||
727 |
|
||||
728 | 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): |
|
|||
729 |
|
||||
730 | if self.showColorbar: |
|
|||
731 | xw -= xcmapw + deltaxcmap |
|
|||
732 |
|
||||
733 | if self.showPowerProfile: |
|
|||
734 | xw -= xpoww + deltaxpow |
|
|||
735 |
|
||||
736 | xf = xi + xw |
|
|||
737 | yf = yi + yw |
|
|||
738 | xcmapf = xf |
|
|||
739 |
|
||||
740 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) |
|
|||
741 |
|
||||
742 | if self.showColorbar: |
|
|||
743 | xcmapi = xf + deltaxcmap |
|
|||
744 | xcmapf = xcmapi + xcmapw |
|
|||
745 |
|
||||
746 | key = "colorbar" |
|
|||
747 | cmapObj = self.graphObjDict[key] |
|
|||
748 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) |
|
|||
749 |
|
||||
750 | if self.showPowerProfile: |
|
|||
751 |
|
||||
752 | xpowi = xcmapf + deltaxpow |
|
|||
753 | xpowf = xpowi + xpoww |
|
|||
754 |
|
||||
755 | key = "powerprof" |
|
|||
756 | powObj = self.graphObjDict[key] |
|
|||
757 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) |
|
|||
758 |
|
||||
759 | def setRanges(self, xrange, yrange, zrange): |
|
|||
760 |
|
||||
761 | self.m_BaseGraph.setRanges(xrange, yrange, zrange) |
|
|||
762 |
|
817 | |||
763 | keyList = self.graphObjDict.keys() |
|
|||
764 |
|
||||
765 | key = "colorbar" |
|
|||
766 | if key in keyList: |
|
|||
767 | cmapObj = self.graphObjDict[key] |
|
|||
768 | cmapObj.setRanges([0., 1.], zrange) |
|
|||
769 |
|
||||
770 | key = "powerprof" |
|
|||
771 | if key in keyList: |
|
|||
772 | powObj = self.graphObjDict[key] |
|
|||
773 | powObj.setRanges(zrange, yrange) |
|
|||
774 |
|
||||
775 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
818 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
776 | """ |
|
819 | """ | |
777 | """ |
|
820 | """ | |
778 |
|
821 | |||
779 | try: |
|
822 | try: | |
780 | nX, nY = numpy.shape(data) |
|
823 | nX, nY = numpy.shape(data) | |
781 | except: |
|
824 | except: | |
782 | raise ValueError, "data is not a numpy array" |
|
825 | raise ValueError, "data is not a numpy array" | |
783 |
|
826 | |||
784 | if x == None: x = numpy.arange(nX) |
|
827 | if x == None: x = numpy.arange(nX) | |
785 | if y == None: y = numpy.arange(nY) |
|
828 | if y == None: y = numpy.arange(nY) | |
786 |
|
829 | |||
787 | if xmin == None: xmin = x[0] |
|
830 | if xmin == None: xmin = x[0] | |
788 | if xmax == None: xmax = x[-1] |
|
831 | if xmax == None: xmax = x[-1] | |
789 | if ymin == None: ymin = y[0] |
|
832 | if ymin == None: ymin = y[0] | |
790 | if ymax == None: ymax = y[-1] |
|
833 | if ymax == None: ymax = y[-1] | |
791 | if zmin == None: zmin = numpy.nanmin(data) |
|
834 | if zmin == None: zmin = numpy.nanmin(data) | |
792 | if zmax == None: zmax = numpy.nanmax(data) |
|
835 | if zmax == None: zmax = numpy.nanmax(data) | |
793 |
|
836 | |||
794 |
if self. |
|
837 | if self.colorGraphObj.hasNotRange: | |
795 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) |
|
838 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) | |
796 |
|
839 | |||
797 |
self. |
|
840 | self.colorGraphObj.initSubpage() | |
798 |
self. |
|
841 | self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.colorGraphObj.zrange[0], self.colorGraphObj.zrange[1]) | |
799 |
|
842 | |||
800 | if self.showColorbar: |
|
843 | if self.showColorbar: | |
801 | key = "colorbar" |
|
844 | key = "colorbar" | |
802 | cmapObj = self.graphObjDict[key] |
|
845 | cmapObj = self.graphObjDict[key] | |
803 | cmapObj.colorbarPlot() |
|
846 | cmapObj.colorbarPlot() | |
804 |
|
847 | |||
805 | if self.showPowerProfile: |
|
848 | if self.showPowerProfile: | |
806 | power = numpy.average(data, axis=1) |
|
849 | power = numpy.average(data, axis=1) | |
807 |
|
850 | |||
808 | step = (ymax - ymin)/(nY-1) |
|
851 | step = (ymax - ymin)/(nY-1) | |
809 | heis = numpy.arange(ymin, ymax + step, step) |
|
852 | heis = numpy.arange(ymin, ymax + step, step) | |
810 |
|
853 | |||
811 | key = "powerprof" |
|
854 | key = "powerprof" | |
812 | powObj = self.graphObjDict[key] |
|
855 | powObj = self.graphObjDict[key] | |
813 | powObj.basicXYPlot(power, heis) |
|
856 | powObj.basicXYPlot(power, heis) | |
814 |
|
857 | |||
815 | if __name__ == '__main__': |
|
858 | if __name__ == '__main__': | |
816 |
|
859 | |||
817 | import numpy |
|
860 | import numpy | |
818 | plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) |
|
861 | plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) | |
819 | plplot.plsdev("xwin") |
|
862 | plplot.plsdev("xwin") | |
820 | plplot.plscolbg(255,255,255) |
|
863 | plplot.plscolbg(255,255,255) | |
821 | plplot.plscol0(1,0,0,0) |
|
864 | plplot.plscol0(1,0,0,0) | |
822 | plplot.plspause(False) |
|
865 | plplot.plspause(False) | |
823 | plplot.plinit() |
|
866 | plplot.plinit() | |
824 | plplot.plssub(2, 2) |
|
867 | plplot.plssub(2, 2) | |
825 |
|
868 | |||
826 | nx = 64 |
|
869 | nx = 64 | |
827 | ny = 100 |
|
870 | ny = 100 | |
828 |
|
871 | |||
829 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
872 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
830 |
|
873 | |||
831 | baseObj = ColorPlot() |
|
874 | baseObj = ColorPlot() | |
832 | specObj = ColorPlot() |
|
875 | specObj = ColorPlot() | |
833 | baseObj1 = ColorPlot() |
|
876 | baseObj1 = ColorPlot() | |
834 | specObj1 = ColorPlot() |
|
877 | specObj1 = ColorPlot() | |
835 |
|
878 | |||
836 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True) |
|
879 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True) | |
837 | specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True) |
|
880 | specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True) | |
838 |
|
881 | |||
839 | baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True) |
|
882 | baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True) | |
840 | specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True) |
|
883 | specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True) | |
841 |
|
884 | |||
842 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
885 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
843 |
|
886 | |||
844 | plplot.plbop() |
|
887 | plplot.plbop() | |
845 | baseObj.iniSubpage() |
|
|||
846 | baseObj.plotData(data) |
|
888 | baseObj.plotData(data) | |
847 |
|
889 | |||
848 | specObj.iniSubpage() |
|
|||
849 | specObj.plotData(data) |
|
890 | specObj.plotData(data) | |
850 |
|
891 | |||
851 | baseObj1.iniSubpage() |
|
|||
852 | baseObj1.plotData(data) |
|
892 | baseObj1.plotData(data) | |
853 |
|
893 | |||
854 | specObj1.iniSubpage() |
|
|||
855 | specObj1.plotData(data) |
|
894 | specObj1.plotData(data) | |
856 |
|
895 | |||
857 | plplot.plflush() |
|
896 | plplot.plflush() | |
858 |
|
897 | |||
859 | plplot.plspause(1) |
|
898 | plplot.plspause(1) | |
860 | plplot.plend() |
|
899 | plplot.plend() | |
861 | exit(0) |
|
900 | exit(0) | |
862 |
|
901 | |||
863 |
|
902 |
@@ -1,178 +1,203 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | import os, sys |
|
8 | import os, sys | |
9 | import numpy |
|
9 | import numpy | |
10 | import datetime |
|
10 | import datetime | |
11 | import plplot |
|
11 | import plplot | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from Graphics.BaseGraph import * |
|
16 | from Graphics.BaseGraph import * | |
17 | from Model.Spectra import Spectra |
|
17 | from Model.Spectra import Spectra | |
18 |
|
18 | |||
19 |
class Spectrum |
|
19 | class Spectrum: | |
|
20 | ||||
|
21 | __isPlotConfig = False | |||
|
22 | ||||
|
23 | __isPlotIni = False | |||
|
24 | ||||
|
25 | __xrange = None | |||
|
26 | ||||
|
27 | __yrange = None | |||
20 |
|
28 | |||
|
29 | nGraphs = 0 | |||
|
30 | ||||
|
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 | ||||
21 | def __init__(self, Spectra, index=0): |
|
47 | def __init__(self, Spectra, index=0): | |
22 |
|
48 | |||
23 | """ |
|
49 | """ | |
24 |
|
50 | |||
25 | Inputs: |
|
51 | Inputs: | |
26 |
|
52 | |||
27 | type: "power" ->> Potencia |
|
53 | type: "power" ->> Potencia | |
28 | "iq" ->> Real + Imaginario |
|
54 | "iq" ->> Real + Imaginario | |
29 | """ |
|
55 | """ | |
30 |
|
56 | |||
31 | self.__isPlotConfig = False |
|
57 | self.__isPlotConfig = False | |
32 |
|
58 | |||
33 | self.__isPlotIni = False |
|
59 | self.__isPlotIni = False | |
34 |
|
60 | |||
35 | self.__xrange = None |
|
61 | self.__xrange = None | |
36 |
|
62 | |||
37 | self.__yrange = None |
|
63 | self.__yrange = None | |
38 |
|
64 | |||
39 | self.nGraphs = 0 |
|
65 | self.nGraphs = 0 | |
40 |
|
66 | |||
41 | self.indexPlot = index |
|
67 | self.indexPlot = index | |
42 |
|
68 | |||
43 | self.graphObjList = [] |
|
69 | self.graphObjList = [] | |
44 |
|
70 | |||
45 |
self. |
|
71 | self.spectraObj = Spectra | |
46 |
|
72 | |||
47 |
|
73 | |||
48 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): |
|
74 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |
49 |
|
75 | |||
50 | graphObj = ColorPlot() |
|
76 | graphObj = ColorPlot() | |
51 | graphObj.setup(subpage, |
|
77 | graphObj.setup(subpage, | |
52 | title, |
|
78 | title, | |
53 | xlabel, |
|
79 | xlabel, | |
54 | ylabel, |
|
80 | ylabel, | |
55 | showColorbar=showColorbar, |
|
81 | showColorbar=showColorbar, | |
56 | showPowerProfile=showPowerProfile, |
|
82 | showPowerProfile=showPowerProfile, | |
57 | XAxisAsTime=XAxisAsTime) |
|
83 | XAxisAsTime=XAxisAsTime) | |
58 |
|
84 | |||
59 | self.graphObjList.append(graphObj) |
|
85 | self.graphObjList.append(graphObj) | |
60 |
|
86 | |||
61 |
|
87 | |||
62 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): |
|
88 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |
63 |
|
89 | |||
64 |
nChan = int(self. |
|
90 | nChan = int(self.spectraObj.m_SystemHeader.numChannels) | |
65 | channels = range(nChan) |
|
91 | channels = range(nChan) | |
66 |
|
92 | |||
67 | myXlabel = "Radial Velocity (m/s)" |
|
93 | myXlabel = "Radial Velocity (m/s)" | |
68 | myYlabel = "Range (km)" |
|
94 | myYlabel = "Range (km)" | |
69 |
|
95 | |||
70 | for i in channels: |
|
96 | for i in channels: | |
71 | if titleList != None: |
|
97 | if titleList != None: | |
72 | myTitle = titleList[i] |
|
98 | myTitle = titleList[i] | |
73 | myXlabel = xlabelList[i] |
|
99 | myXlabel = xlabelList[i] | |
74 | myYlabel = ylabelList[i] |
|
100 | myYlabel = ylabelList[i] | |
75 |
|
101 | |||
76 |
# if self. |
|
102 | # if self.spectraObj.m_NoiseObj != None: | |
77 |
# noise = '%4.2fdB' %(self. |
|
103 | # noise = '%4.2fdB' %(self.spectraObj.m_NoiseObj[i]) | |
78 | # else: |
|
104 | # else: | |
79 | noise = '--' |
|
105 | noise = '--' | |
80 |
|
106 | |||
81 | myTitle = "Channel: %d - Noise: %s" %(i, noise) |
|
107 | myTitle = "Channel: %d - Noise: %s" %(i, noise) | |
82 |
|
108 | |||
83 | self.__addGraph(i+1, |
|
109 | self.__addGraph(i+1, | |
84 | title=myTitle, |
|
110 | title=myTitle, | |
85 | xlabel=myXlabel, |
|
111 | xlabel=myXlabel, | |
86 | ylabel=myYlabel, |
|
112 | ylabel=myYlabel, | |
87 | showColorbar=showColorbar, |
|
113 | showColorbar=showColorbar, | |
88 | showPowerProfile=showPowerProfile, |
|
114 | showPowerProfile=showPowerProfile, | |
89 | XAxisAsTime=XAxisAsTime) |
|
115 | XAxisAsTime=XAxisAsTime) | |
90 |
|
116 | |||
91 | self.nGraphs = nChan |
|
117 | self.nGraphs = nChan | |
92 | self.__isPlotConfig = True |
|
118 | self.__isPlotConfig = True | |
93 |
|
119 | |||
94 | def iniPlot(self, winTitle=""): |
|
120 | def iniPlot(self, winTitle=""): | |
95 |
|
121 | |||
96 | nx = int(numpy.sqrt(self.nGraphs)+1) |
|
122 | nx = int(numpy.sqrt(self.nGraphs)+1) | |
97 | #ny = int(self.nGraphs/nx) |
|
123 | #ny = int(self.nGraphs/nx) | |
98 |
|
124 | |||
99 | plplot.plsstrm(self.indexPlot) |
|
125 | plplot.plsstrm(self.indexPlot) | |
100 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) |
|
126 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) | |
101 | plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx)) |
|
127 | plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx)) | |
102 | plplot.plsdev("xwin") |
|
128 | plplot.plsdev("xwin") | |
103 | plplot.plscolbg(255,255,255) |
|
129 | plplot.plscolbg(255,255,255) | |
104 | plplot.plscol0(1,0,0,0) |
|
130 | plplot.plscol0(1,0,0,0) | |
105 | plplot.plinit() |
|
131 | plplot.plinit() | |
106 | plplot.plspause(False) |
|
132 | plplot.plspause(False) | |
107 | plplot.pladv(0) |
|
133 | plplot.pladv(0) | |
108 | plplot.plssub(nx, nx) |
|
134 | plplot.plssub(nx, nx) | |
109 |
|
135 | |||
110 | self.__nx = nx |
|
136 | self.__nx = nx | |
111 | self.__ny = nx |
|
137 | self.__ny = nx | |
112 | self.__isPlotIni = True |
|
138 | self.__isPlotIni = True | |
113 |
|
139 | |||
114 |
|
140 | |||
115 | 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"): |
|
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"): | |
116 |
|
142 | |||
117 | if not(self.__isPlotConfig): |
|
143 | if not(self.__isPlotConfig): | |
118 | self.setup(titleList, |
|
144 | self.setup(titleList, | |
119 | xlabelList, |
|
145 | xlabelList, | |
120 | ylabelList, |
|
146 | ylabelList, | |
121 | showColorbar, |
|
147 | showColorbar, | |
122 | showPowerProfile, |
|
148 | showPowerProfile, | |
123 | XAxisAsTime) |
|
149 | XAxisAsTime) | |
124 |
|
150 | |||
125 | if not(self.__isPlotIni): |
|
151 | if not(self.__isPlotIni): | |
126 | self.iniPlot(winTitle) |
|
152 | self.iniPlot(winTitle) | |
127 |
|
153 | |||
128 | plplot.plsstrm(self.indexPlot) |
|
154 | plplot.plsstrm(self.indexPlot) | |
129 |
|
155 | |||
130 |
data = 10.*numpy.log10(self. |
|
156 | data = 10.*numpy.log10(self.spectraObj.data_spc) | |
131 |
|
157 | |||
132 | #data.shape = Channels x Heights x Profiles |
|
158 | #data.shape = Channels x Heights x Profiles | |
133 | # data = numpy.transpose( data, (0,2,1) ) |
|
159 | # data = numpy.transpose( data, (0,2,1) ) | |
134 | #data.shape = Channels x Profiles x Heights |
|
160 | #data.shape = Channels x Profiles x Heights | |
135 |
|
161 | |||
136 | nChan, nX, nY = numpy.shape(data) |
|
162 | nChan, nX, nY = numpy.shape(data) | |
137 |
|
163 | |||
138 | x = numpy.arange(nX) |
|
164 | x = numpy.arange(nX) | |
139 |
y = self. |
|
165 | y = self.spectraObj.heightList | |
140 |
|
166 | |||
141 |
thisDatetime = datetime.datetime.fromtimestamp(self. |
|
167 | thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc) | |
142 | txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
168 | txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
143 |
|
169 | |||
144 | if xmin == None: xmin = x[0] |
|
170 | if xmin == None: xmin = x[0] | |
145 | if xmax == None: xmax = x[-1] |
|
171 | if xmax == None: xmax = x[-1] | |
146 | if ymin == None: ymin = y[0] |
|
172 | if ymin == None: ymin = y[0] | |
147 | if ymax == None: ymax = y[-1] |
|
173 | if ymax == None: ymax = y[-1] | |
148 | if zmin == None: zmin = numpy.nanmin(abs(data)) |
|
174 | if zmin == None: zmin = numpy.nanmin(abs(data)) | |
149 | if zmax == None: zmax = numpy.nanmax(abs(data)) |
|
175 | if zmax == None: zmax = numpy.nanmax(abs(data)) | |
150 |
|
176 | |||
151 | plplot.plbop() |
|
177 | plplot.plbop() | |
152 |
|
178 | |||
153 | plplot.plssub(self.__nx, self.__ny) |
|
179 | plplot.plssub(self.__nx, self.__ny) | |
154 | for i in range(self.nGraphs): |
|
180 | for i in range(self.nGraphs): | |
155 | self.graphObjList[i].iniSubpage() |
|
|||
156 | self.graphObjList[i].plotData(data[i,:,:], |
|
181 | self.graphObjList[i].plotData(data[i,:,:], | |
157 | x, |
|
182 | x, | |
158 | y, |
|
183 | y, | |
159 | xmin=xmin, |
|
184 | xmin=xmin, | |
160 | xmax=xmax, |
|
185 | xmax=xmax, | |
161 | ymin=ymin, |
|
186 | ymin=ymin, | |
162 | ymax=ymax, |
|
187 | ymax=ymax, | |
163 | zmin=zmin, |
|
188 | zmin=zmin, | |
164 | zmax=zmax) |
|
189 | zmax=zmax) | |
165 |
|
190 | |||
166 | plplot.plssub(1,0) |
|
191 | plplot.plssub(1,0) | |
167 | plplot.pladv(0) |
|
192 | plplot.pladv(0) | |
168 | plplot.plvpor(0., 1., 0., 1.) |
|
193 | plplot.plvpor(0., 1., 0., 1.) | |
169 | plplot.plmtex("t",-1., 0.5, 0.5, txtDate) |
|
194 | plplot.plmtex("t",-1., 0.5, 0.5, txtDate) | |
170 | plplot.plflush() |
|
195 | plplot.plflush() | |
171 | plplot.pleop() |
|
196 | plplot.pleop() | |
172 |
|
197 | |||
173 | def end(self): |
|
198 | def end(self): | |
174 | plplot.plend() |
|
199 | plplot.plend() | |
175 |
|
200 | |||
176 |
|
201 | |||
177 | if __name__ == '__main__': |
|
202 | if __name__ == '__main__': | |
178 | pass No newline at end of file |
|
203 | pass |
@@ -1,182 +1,207 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import plplot |
|
9 | import plplot | |
10 |
|
10 | |||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Graphics.BaseGraph import * |
|
14 | from Graphics.BaseGraph import * | |
15 | from Model.Voltage import Voltage |
|
15 | from Model.Voltage import Voltage | |
16 |
|
16 | |||
17 |
class Osciloscope |
|
17 | class Osciloscope: | |
18 |
|
18 | |||
19 | def __init__(self, Voltage, index=0): |
|
19 | voltageObj = Voltage() | |
20 |
|
|
20 | ||
21 | """ |
|
21 | linearGraphObj = LinearPlot() | |
22 |
|
|
22 | ||
23 | Inputs: |
|
23 | __isPlotConfig = False | |
24 |
|
|
24 | ||
25 | type: "power" ->> Potencia |
|
25 | __isPlotIni = False | |
26 | "iq" ->> Real + Imaginario |
|
26 | ||
27 | """ |
|
27 | __xrange = None | |
28 |
|
|
28 | ||
29 | self.__isPlotConfig = False |
|
29 | __yrange = None | |
30 |
|
|
30 | ||
31 | self.__isPlotIni = False |
|
31 | voltageObj = Voltage() | |
32 |
|
|
32 | ||
33 | self.__xrange = None |
|
33 | nGraphs = 0 | |
34 |
|
|
34 | ||
35 | self.__yrange = None |
|
35 | indexPlot = None | |
36 |
|
|
36 | ||
37 | self.m_Voltage = None |
|
37 | graphObjList = [] | |
38 |
|
38 | m_LinearPlot= LinearPlot() | ||
39 | self.nGraphs = 0 |
|
39 | ||
40 |
|
40 | |||
41 | self.indexPlot = index |
|
41 | m_Voltage= Voltage() | |
42 |
|
42 | |||
43 | self.graphObjList = [] |
|
43 | ||
44 |
|
44 | |||
45 | self.m_Voltage = Voltage |
|
45 | def __init__(self, Voltage, index=0): | |
46 |
|
|
46 | ||
47 |
|
47 | """ | ||
48 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): |
|
48 | ||
49 |
|
49 | Inputs: | ||
50 | graphObj = LinearPlot() |
|
50 | ||
51 | graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) |
|
51 | type: "power" ->> Potencia | |
52 | #graphObj.setScreenPos() |
|
52 | "iq" ->> Real + Imaginario | |
53 |
|
53 | """ | ||
54 | self.graphObjList.append(graphObj) |
|
54 | ||
55 |
|
55 | self.__isPlotConfig = False | ||
56 | del graphObj |
|
56 | ||
57 |
|
57 | self.__isPlotIni = False | ||
58 | # def setXRange(self, xmin, xmax): |
|
58 | ||
59 |
|
|
59 | self.__xrange = None | |
60 |
|
|
60 | ||
61 | # def setYRange(self, ymin, ymax): |
|
61 | self.__yrange = None | |
62 | # self.__yrange = (ymin, ymax) |
|
62 | ||
63 |
|
63 | self.voltageObj = None | ||
64 |
|
64 | |||
65 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): |
|
65 | self.nGraphs = 0 | |
66 |
|
66 | |||
67 | nChan = int(self.m_Voltage.m_SystemHeader.numChannels) |
|
67 | self.indexPlot = index | |
68 |
|
68 | |||
69 | myTitle = "" |
|
69 | self.graphObjList = [] | |
70 | myXlabel = "" |
|
70 | ||
71 | myYlabel = "" |
|
71 | self.voltageObj = Voltage | |
72 |
|
72 | |||
73 | for chan in range(nChan): |
|
73 | ||
74 | if titleList != None: |
|
74 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): | |
75 | myTitle = titleList[chan] |
|
75 | ||
76 | myXlabel = xlabelList[chan] |
|
76 | graphObj = LinearPlot() | |
77 | myYlabel = ylabelList[chan] |
|
77 | graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) | |
78 |
|
78 | #graphObj.setScreenPos() | ||
79 | self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) |
|
79 | ||
80 |
|
80 | self.graphObjList.append(graphObj) | ||
81 | self.nGraphs = nChan |
|
81 | ||
82 | self.__isPlotConfig = True |
|
82 | del graphObj | |
83 |
|
83 | |||
84 | def iniPlot(self, winTitle=""): |
|
84 | # def setXRange(self, xmin, xmax): | |
85 |
|
85 | # self.__xrange = (xmin, xmax) | ||
86 | plplot.plsstrm(self.indexPlot) |
|
86 | # | |
87 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) |
|
87 | # def setYRange(self, ymin, ymax): | |
88 | plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) |
|
88 | # self.__yrange = (ymin, ymax) | |
89 | plplot.plsdev("xwin") |
|
89 | ||
90 | plplot.plscolbg(255,255,255) |
|
90 | ||
91 | plplot.plscol0(1,0,0,0) |
|
91 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): | |
92 | plplot.plinit() |
|
92 | ||
93 | plplot.plspause(False) |
|
93 | nChan = int(self.voltageObj.m_SystemHeader.numChannels) | |
94 | plplot.plssub(1, self.nGraphs) |
|
94 | ||
95 |
|
95 | myTitle = "" | ||
96 | self.__isPlotIni = True |
|
96 | myXlabel = "" | |
97 |
|
97 | myYlabel = "" | ||
98 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): |
|
98 | ||
99 |
|
99 | for chan in range(nChan): | ||
100 | if idProfile != None and idProfile != self.m_Voltage.idProfile: |
|
100 | if titleList != None: | |
101 | return |
|
101 | myTitle = titleList[chan] | |
102 |
|
102 | myXlabel = xlabelList[chan] | ||
103 | if not(self.__isPlotConfig): |
|
103 | myYlabel = ylabelList[chan] | |
104 | self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) |
|
104 | ||
105 |
|
105 | self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) | ||
106 | if not(self.__isPlotIni): |
|
106 | ||
107 | self.iniPlot(winTitle) |
|
107 | self.nGraphs = nChan | |
108 |
|
108 | self.__isPlotConfig = True | ||
109 | plplot.plsstrm(self.indexPlot) |
|
109 | ||
110 |
|
110 | def iniPlot(self, winTitle=""): | ||
111 | data = self.m_Voltage.data |
|
111 | ||
112 |
|
112 | plplot.plsstrm(self.indexPlot) | ||
113 | x = self.m_Voltage.heights |
|
113 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) | |
114 |
|
114 | plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) | ||
115 | if xmin == None: xmin = x[0] |
|
115 | plplot.plsdev("xwin") | |
116 | if xmax == None: xmax = x[-1] |
|
116 | plplot.plscolbg(255,255,255) | |
117 | if ymin == None: ymin = numpy.nanmin(abs(data)) |
|
117 | plplot.plscol0(1,0,0,0) | |
118 | if ymax == None: ymax = numpy.nanmax(abs(data)) |
|
118 | plplot.plinit() | |
119 |
|
119 | plplot.plspause(False) | ||
120 |
plplot.plb |
|
120 | plplot.plssub(1, self.nGraphs) | |
121 | for chan in range(self.nGraphs): |
|
121 | ||
122 | y = data[chan,:] |
|
122 | self.__isPlotIni = True | |
123 |
|
123 | |||
124 | self.graphObjList[chan].iniSubpage() |
|
124 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): | |
125 | self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) |
|
125 | ||
126 |
|
126 | if idProfile != None and idProfile != self.voltageObj.idProfile: | ||
127 | plplot.plflush() |
|
127 | return | |
128 | plplot.pleop() |
|
128 | ||
129 |
|
129 | if not(self.__isPlotConfig): | ||
130 | def end(self): |
|
130 | self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) | |
131 | plplot.plend() |
|
131 | ||
132 |
|
132 | if not(self.__isPlotIni): | ||
133 | class VoltagePlot(object): |
|
133 | self.iniPlot(winTitle) | |
134 | ''' |
|
134 | ||
135 | classdocs |
|
135 | plplot.plsstrm(self.indexPlot) | |
136 | ''' |
|
136 | ||
137 |
|
137 | data = self.voltageObj.data | ||
138 | __m_Voltage = None |
|
138 | ||
139 |
|
139 | x = self.voltageObj.heights | ||
140 | def __init__(self, m_Voltage): |
|
140 | ||
141 | ''' |
|
141 | if xmin == None: xmin = x[0] | |
142 | Constructor |
|
142 | if xmax == None: xmax = x[-1] | |
143 | ''' |
|
143 | if ymin == None: ymin = numpy.nanmin(abs(data)) | |
144 | self.__m_Voltage = m_Voltage |
|
144 | if ymax == None: ymax = numpy.nanmax(abs(data)) | |
145 |
|
145 | |||
146 | def setup(self): |
|
146 | plplot.plbop() | |
147 | pass |
|
147 | for chan in range(self.nGraphs): | |
148 |
|
148 | y = data[chan,:] | ||
149 | def addGraph(self, type, xrange=None, yrange=None, zrange=None): |
|
149 | ||
150 | pass |
|
150 | self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) | |
151 |
|
151 | |||
152 | def plotData(self): |
|
152 | plplot.plflush() | |
153 | pass |
|
153 | plplot.pleop() | |
154 |
|
154 | |||
155 | if __name__ == '__main__': |
|
155 | def end(self): | |
156 |
|
156 | plplot.plend() | ||
157 | import numpy |
|
157 | ||
158 |
|
158 | class VoltagePlot(object): | ||
159 | plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) |
|
159 | ''' | |
160 | plplot.plsdev("xcairo") |
|
160 | classdocs | |
161 | plplot.plscolbg(255,255,255) |
|
161 | ''' | |
162 | plplot.plscol0(1,0,0,0) |
|
162 | ||
163 | plplot.plinit() |
|
163 | __m_Voltage = None | |
164 | plplot.plssub(1, 2) |
|
164 | ||
165 |
|
165 | def __init__(self, voltageObj): | ||
166 | nx = 64 |
|
166 | ''' | |
167 | ny = 100 |
|
167 | Constructor | |
168 |
|
168 | ''' | ||
169 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
169 | self.__m_Voltage = voltageObj | |
170 |
|
170 | |||
171 | baseObj = RTI() |
|
171 | def setup(self): | |
172 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) |
|
172 | pass | |
173 | baseObj.plotData(data) |
|
173 | ||
174 |
|
174 | def addGraph(self, type, xrange=None, yrange=None, zrange=None): | ||
175 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
175 | pass | |
176 |
|
176 | |||
177 | base2Obj = RTI() |
|
177 | def plotData(self): | |
178 | base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) |
|
178 | pass | |
179 | base2Obj.plotData(data) |
|
179 | ||
180 |
|
180 | if __name__ == '__main__': | ||
181 | plplot.plend() |
|
181 | ||
|
182 | import numpy | |||
|
183 | ||||
|
184 | plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) | |||
|
185 | plplot.plsdev("xcairo") | |||
|
186 | plplot.plscolbg(255,255,255) | |||
|
187 | plplot.plscol0(1,0,0,0) | |||
|
188 | plplot.plinit() | |||
|
189 | plplot.plssub(1, 2) | |||
|
190 | ||||
|
191 | nx = 64 | |||
|
192 | ny = 100 | |||
|
193 | ||||
|
194 | data = numpy.random.uniform(-50,50,(nx,ny)) | |||
|
195 | ||||
|
196 | baseObj = RTI() | |||
|
197 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) | |||
|
198 | baseObj.plotData(data) | |||
|
199 | ||||
|
200 | data = numpy.random.uniform(-50,50,(nx,ny)) | |||
|
201 | ||||
|
202 | base2Obj = RTI() | |||
|
203 | base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) | |||
|
204 | base2Obj.plotData(data) | |||
|
205 | ||||
|
206 | plplot.plend() | |||
182 | exit(0) No newline at end of file |
|
207 | exit(0) |
@@ -1,18 +1,22 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | class CorrelationProcessor: |
|
8 | class CorrelationProcessor: | |
9 | ''' |
|
9 | ''' | |
10 | classdocs |
|
10 | classdocs | |
11 | ''' |
|
11 | ''' | |
12 |
|
12 | |||
13 |
|
13 | |||
14 | def __init__(self): |
|
14 | def __init__(self): | |
15 | ''' |
|
15 | ''' | |
16 | Constructor |
|
16 | Constructor | |
17 | ''' |
|
17 | ''' | |
18 | pass No newline at end of file |
|
18 | pass | |
|
19 | m_Correlation= Correlation() | |||
|
20 | ||||
|
21 | m_Voltage= Voltage() | |||
|
22 |
@@ -1,112 +1,112 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | from Model.Spectra import Spectra |
|
2 | from Model.Spectra import Spectra | |
3 |
|
3 | |||
4 | def hildebrand_sekhon(Data, navg=1): |
|
4 | def hildebrand_sekhon(Data, navg=1): | |
5 | """ |
|
5 | """ | |
6 | This method is for the objective determination of de noise level in Doppler spectra. This |
|
6 | This method is for the objective determination of de noise level in Doppler spectra. This | |
7 | implementation technique is based on the fact that the standard deviation of the spectral |
|
7 | implementation technique is based on the fact that the standard deviation of the spectral | |
8 | densities is equal to the mean spectral density for white Gaussian noise |
|
8 | densities is equal to the mean spectral density for white Gaussian noise | |
9 |
|
9 | |||
10 | Inputs: |
|
10 | Inputs: | |
11 | Data : heights |
|
11 | Data : heights | |
12 | navg : numbers of averages |
|
12 | navg : numbers of averages | |
13 |
|
13 | |||
14 | Return: |
|
14 | Return: | |
15 | -1 : any error |
|
15 | -1 : any error | |
16 | anoise : noise's level |
|
16 | anoise : noise's level | |
17 | """ |
|
17 | """ | |
18 | divisor = 8 |
|
18 | divisor = 8 | |
19 | ratio = 7 / divisor |
|
19 | ratio = 7 / divisor | |
20 | data = Data.reshape(-1) |
|
20 | data = Data.reshape(-1) | |
21 | npts = data.size #numbers of points of the data |
|
21 | npts = data.size #numbers of points of the data | |
22 |
|
22 | |||
23 | if npts < 32: |
|
23 | if npts < 32: | |
24 | print "error in noise - requires at least 32 points" |
|
24 | print "error in noise - requires at least 32 points" | |
25 | return -1.0 |
|
25 | return -1.0 | |
26 |
|
26 | |||
27 | # data sorted in ascending order |
|
27 | # data sorted in ascending order | |
28 | nmin = int(npts/divisor + ratio); |
|
28 | nmin = int(npts/divisor + ratio); | |
29 | s = 0.0 |
|
29 | s = 0.0 | |
30 | s2 = 0.0 |
|
30 | s2 = 0.0 | |
31 | data2 = data[:npts] |
|
31 | data2 = data[:npts] | |
32 | data2.sort() |
|
32 | data2.sort() | |
33 |
|
33 | |||
34 | for i in range(nmin): |
|
34 | for i in range(nmin): | |
35 | s += data2[i] |
|
35 | s += data2[i] | |
36 | s2 += data2[i]**2; |
|
36 | s2 += data2[i]**2; | |
37 |
|
37 | |||
38 | icount = nmin |
|
38 | icount = nmin | |
39 | iflag = 0 |
|
39 | iflag = 0 | |
40 |
|
40 | |||
41 | for i in range(nmin, npts): |
|
41 | for i in range(nmin, npts): | |
42 | s += data2[i]; |
|
42 | s += data2[i]; | |
43 | s2 += data2[i]**2 |
|
43 | s2 += data2[i]**2 | |
44 | icount=icount+1; |
|
44 | icount=icount+1; | |
45 | p = s / float(icount); |
|
45 | p = s / float(icount); | |
46 | p2 = p**2; |
|
46 | p2 = p**2; | |
47 | q = s2 / float(icount) - p2; |
|
47 | q = s2 / float(icount) - p2; | |
48 | leftc = p2; |
|
48 | leftc = p2; | |
49 | rightc = q * float(navg); |
|
49 | rightc = q * float(navg); | |
50 |
|
50 | |||
51 | if leftc > rightc: |
|
51 | if leftc > rightc: | |
52 | iflag = 1; #No weather signal |
|
52 | iflag = 1; #No weather signal | |
53 | # Signal detect: R2 < 1 (R2 = leftc/rightc) |
|
53 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
54 | if(leftc < rightc): |
|
54 | if(leftc < rightc): | |
55 | if iflag: |
|
55 | if iflag: | |
56 | break |
|
56 | break | |
57 |
|
57 | |||
58 | anoise = 0.0; |
|
58 | anoise = 0.0; | |
59 | for j in range(i): |
|
59 | for j in range(i): | |
60 | anoise += data2[j]; |
|
60 | anoise += data2[j]; | |
61 |
|
61 | |||
62 | anoise = anoise / float(i); |
|
62 | anoise = anoise / float(i); | |
63 |
|
63 | |||
64 | return anoise; |
|
64 | return anoise; | |
65 |
|
65 | |||
66 |
|
66 | |||
67 |
class Noise |
|
67 | class Noise: | |
68 | """ |
|
68 | """ | |
69 | Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler |
|
69 | Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler | |
70 | """ |
|
70 | """ | |
71 | m_DataObj = None |
|
71 | m_DataObj = None | |
72 |
|
72 | |||
73 |
|
73 | |||
74 | def __init__(self, m_Spectra=None): |
|
74 | def __init__(self, m_Spectra=None): | |
75 | """ |
|
75 | """ | |
76 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. |
|
76 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. | |
77 |
|
77 | |||
78 | Affected: |
|
78 | Affected: | |
79 | self.m_DataObj |
|
79 | self.m_DataObj | |
80 |
|
80 | |||
81 | Return: |
|
81 | Return: | |
82 | None |
|
82 | None | |
83 | """ |
|
83 | """ | |
84 | if m_Spectra == None: |
|
84 | if m_Spectra == None: | |
85 | m_Spectra = Spectra() |
|
85 | m_Spectra = Spectra() | |
86 |
|
86 | |||
87 | if not(isinstance(m_Spectra, Spectra)): |
|
87 | if not(isinstance(m_Spectra, Spectra)): | |
88 | raise ValueError, "in Noise class, m_Spectra must be an Spectra class object" |
|
88 | raise ValueError, "in Noise class, m_Spectra must be an Spectra class object" | |
89 |
|
89 | |||
90 | self.m_DataObj = m_Spectra |
|
90 | self.m_DataObj = m_Spectra | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | def getNoiseLevelByHildebrandSekhon(self): |
|
93 | def getNoiseLevelByHildebrandSekhon(self): | |
94 | """ |
|
94 | """ | |
95 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
95 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
96 |
|
96 | |||
97 | Return: |
|
97 | Return: | |
98 | noise level |
|
98 | noise level | |
99 | """ |
|
99 | """ | |
100 | data = self.m_DataObj.data_spc |
|
100 | data = self.m_DataObj.data_spc | |
101 | daux = None |
|
101 | daux = None | |
102 |
|
102 | |||
103 | for channel in range(self.m_DataObj.nChannels): |
|
103 | for channel in range(self.m_DataObj.nChannels): | |
104 | daux = data[channel,:,:] |
|
104 | daux = data[channel,:,:] | |
105 | noiselevel = hildebrand_sekhon(daux) |
|
105 | noiselevel = hildebrand_sekhon(daux) | |
106 | print noiselevel |
|
106 | print noiselevel | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | for pair in range(self.m_DataObj.nPairs): |
|
109 | for pair in range(self.m_DataObj.nPairs): | |
110 | daux = data[pair,:,:] |
|
110 | daux = data[pair,:,:] | |
111 | noiselevel = hildebrand_sekhon(daux) |
|
111 | noiselevel = hildebrand_sekhon(daux) | |
112 | print noiselevel |
|
112 | print noiselevel |
@@ -1,511 +1,553 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 |
|
9 | |||
10 | path = os.path.split(os.getcwd())[0] |
|
10 | path = os.path.split(os.getcwd())[0] | |
11 | sys.path.append(path) |
|
11 | sys.path.append(path) | |
12 |
|
12 | |||
13 | from Model.Spectra import Spectra |
|
13 | from Model.Spectra import Spectra | |
14 | from IO.SpectraIO import SpectraWriter |
|
14 | from IO.SpectraIO import SpectraWriter | |
15 | from Graphics.SpectraPlot import Spectrum |
|
15 | from Graphics.SpectraPlot import Spectrum | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | class SpectraProcessor: |
|
18 | class SpectraProcessor: | |
19 | ''' |
|
19 | ''' | |
20 | classdocs |
|
20 | classdocs | |
21 | ''' |
|
21 | ''' | |
22 |
|
22 | |||
|
23 | dataInObj = None | |||
|
24 | ||||
|
25 | dataOutObj = None | |||
|
26 | ||||
|
27 | integratorObjIndex = None | |||
|
28 | ||||
|
29 | decoderObjIndex = None | |||
|
30 | ||||
|
31 | writerObjIndex = None | |||
|
32 | ||||
|
33 | plotterObjIndex = None | |||
|
34 | ||||
|
35 | integratorObjList = [] | |||
|
36 | ||||
|
37 | decoderObjList = [] | |||
|
38 | ||||
|
39 | writerObjList = [] | |||
|
40 | ||||
|
41 | plotterObjList = [] | |||
|
42 | ||||
|
43 | buffer = None | |||
|
44 | ||||
|
45 | ptsId = 0 | |||
|
46 | ||||
|
47 | nFFTPoints = None | |||
|
48 | ||||
|
49 | pairList = None | |||
|
50 | m_Spectra= Spectra() | |||
|
51 | ||||
|
52 | m_Voltage= Voltage() | |||
|
53 | ||||
|
54 | m_IncoherentIntegration= IncoherentIntegration() | |||
|
55 | ||||
|
56 | ||||
23 | def __init__(self, dataInObj, dataOutObj=None): |
|
57 | def __init__(self, dataInObj, dataOutObj=None): | |
24 | ''' |
|
58 | ''' | |
25 | Constructor |
|
59 | Constructor | |
26 | ''' |
|
60 | ''' | |
27 | self.dataInObj = dataInObj |
|
61 | self.dataInObj = dataInObj | |
28 |
|
62 | |||
29 | if dataOutObj == None: |
|
63 | if dataOutObj == None: | |
30 | self.dataOutObj = Spectra() |
|
64 | self.dataOutObj = Spectra() | |
31 | else: |
|
65 | else: | |
32 | self.dataOutObj = dataOutObj |
|
66 | self.dataOutObj = dataOutObj | |
33 |
|
67 | |||
34 | self.integratorIndex = None |
|
68 | self.integratorObjIndex = None | |
35 | self.decoderIndex = None |
|
69 | self.decoderObjIndex = None | |
36 | self.writerIndex = None |
|
70 | self.writerObjIndex = None | |
37 | self.plotterIndex = None |
|
71 | self.plotterObjIndex = None | |
38 |
|
72 | |||
39 | self.integratorList = [] |
|
73 | self.integratorObjList = [] | |
40 | self.decoderList = [] |
|
74 | self.decoderObjList = [] | |
41 | self.writerList = [] |
|
75 | self.writerObjList = [] | |
42 | self.plotterList = [] |
|
76 | self.plotterObjList = [] | |
43 |
|
77 | |||
44 | self.buffer = None |
|
78 | self.buffer = None | |
45 | self.ptsId = 0 |
|
79 | self.ptsId = 0 | |
46 |
|
80 | |||
47 | def init(self, nFFTPoints, pairList=None): |
|
81 | def init(self, nFFTPoints, pairList=None): | |
48 |
|
82 | |||
49 | self.integratorIndex = 0 |
|
83 | self.integratorObjIndex = 0 | |
50 | self.decoderIndex = 0 |
|
84 | self.decoderObjIndex = 0 | |
51 | self.writerIndex = 0 |
|
85 | self.writerObjIndex = 0 | |
52 | self.plotterIndex = 0 |
|
86 | self.plotterObjIndex = 0 | |
53 |
|
87 | |||
54 | if nFFTPoints == None: |
|
88 | if nFFTPoints == None: | |
55 | nFFTPoints = self.dataOutObj.nFFTPoints |
|
89 | nFFTPoints = self.dataOutObj.nFFTPoints | |
56 |
|
90 | |||
57 | self.nFFTPoints = nFFTPoints |
|
91 | self.nFFTPoints = nFFTPoints | |
58 | self.pairList = pairList |
|
92 | self.pairList = pairList | |
59 |
|
93 | |||
60 | if not( isinstance(self.dataInObj, Spectra) ): |
|
94 | if not( isinstance(self.dataInObj, Spectra) ): | |
61 | self.__getFft() |
|
95 | self.__getFft() | |
62 | else: |
|
96 | else: | |
63 | self.dataOutObj.copy(self.dataInObj) |
|
97 | self.dataOutObj.copy(self.dataInObj) | |
64 |
|
98 | |||
65 |
|
99 | |||
66 | def __getFft(self): |
|
100 | def __getFft(self): | |
67 | """ |
|
101 | """ | |
68 | Convierte valores de Voltaje a Spectra |
|
102 | Convierte valores de Voltaje a Spectra | |
69 |
|
103 | |||
70 | Affected: |
|
104 | Affected: | |
71 | self.dataOutObj.data_spc |
|
105 | self.dataOutObj.data_spc | |
72 | self.dataOutObj.data_cspc |
|
106 | self.dataOutObj.data_cspc | |
73 | self.dataOutObj.data_dc |
|
107 | self.dataOutObj.data_dc | |
74 | self.dataOutObj.heightList |
|
108 | self.dataOutObj.heightList | |
75 | self.dataOutObj.m_BasicHeader |
|
109 | self.dataOutObj.m_BasicHeader | |
76 | self.dataOutObj.m_ProcessingHeader |
|
110 | self.dataOutObj.m_ProcessingHeader | |
77 | self.dataOutObj.m_RadarControllerHeader |
|
111 | self.dataOutObj.m_RadarControllerHeader | |
78 | self.dataOutObj.m_SystemHeader |
|
112 | self.dataOutObj.m_SystemHeader | |
79 | self.ptsId |
|
113 | self.ptsId | |
80 | self.buffer |
|
114 | self.buffer | |
81 | self.dataOutObj.flagNoData |
|
115 | self.dataOutObj.flagNoData | |
82 | self.dataOutObj.dataType |
|
116 | self.dataOutObj.dataType | |
83 | self.dataOutObj.nPairs |
|
117 | self.dataOutObj.nPairs | |
84 | self.dataOutObj.nChannels |
|
118 | self.dataOutObj.nChannels | |
85 | self.dataOutObj.nProfiles |
|
119 | self.dataOutObj.nProfiles | |
86 | self.dataOutObj.m_SystemHeader.numChannels |
|
120 | self.dataOutObj.m_SystemHeader.numChannels | |
87 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
121 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
88 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
122 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
89 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
123 | self.dataOutObj.m_ProcessingHeader.numHeights | |
90 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
124 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
91 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
125 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
92 | """ |
|
126 | """ | |
93 | blocksize = 0 |
|
127 | blocksize = 0 | |
94 | nFFTPoints = self.nFFTPoints |
|
128 | nFFTPoints = self.nFFTPoints | |
95 | nChannels, nheis = self.dataInObj.data.shape |
|
129 | nChannels, nheis = self.dataInObj.data.shape | |
96 |
|
130 | |||
97 | if self.buffer == None: |
|
131 | if self.buffer == None: | |
98 | self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex') |
|
132 | self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex') | |
99 |
|
133 | |||
100 | self.buffer[:,self.ptsId,:] = self.dataInObj.data |
|
134 | self.buffer[:,self.ptsId,:] = self.dataInObj.data | |
101 | self.ptsId += 1 |
|
135 | self.ptsId += 1 | |
102 |
|
136 | |||
103 | if self.ptsId < self.dataOutObj.nFFTPoints: |
|
137 | if self.ptsId < self.dataOutObj.nFFTPoints: | |
104 | self.dataOutObj.flagNoData = True |
|
138 | self.dataOutObj.flagNoData = True | |
105 | return |
|
139 | return | |
106 |
|
140 | |||
107 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
141 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
108 | dc = fft_volt[:,0,:] |
|
142 | dc = fft_volt[:,0,:] | |
109 |
|
143 | |||
110 | #calculo de self-spectra |
|
144 | #calculo de self-spectra | |
111 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
145 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
112 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
146 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) | |
113 |
|
147 | |||
114 | blocksize += dc.size |
|
148 | blocksize += dc.size | |
115 | blocksize += spc.size |
|
149 | blocksize += spc.size | |
116 |
|
150 | |||
117 | cspc = None |
|
151 | cspc = None | |
118 | nPair = 0 |
|
152 | nPair = 0 | |
119 | if self.pairList != None: |
|
153 | if self.pairList != None: | |
120 | #calculo de cross-spectra |
|
154 | #calculo de cross-spectra | |
121 | nPairs = len(self.pairList) |
|
155 | nPairs = len(self.pairList) | |
122 | cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex') |
|
156 | cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex') | |
123 | for pair in self.pairList: |
|
157 | for pair in self.pairList: | |
124 | cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
158 | cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
125 | nPair += 1 |
|
159 | nPair += 1 | |
126 | blocksize += cspc.size |
|
160 | blocksize += cspc.size | |
127 |
|
161 | |||
128 | self.dataOutObj.data_spc = spc |
|
162 | self.dataOutObj.data_spc = spc | |
129 | self.dataOutObj.data_cspc = cspc |
|
163 | self.dataOutObj.data_cspc = cspc | |
130 | self.dataOutObj.data_dc = dc |
|
164 | self.dataOutObj.data_dc = dc | |
131 |
|
165 | |||
132 | self.ptsId = 0 |
|
166 | self.ptsId = 0 | |
133 | self.buffer = None |
|
167 | self.buffer = None | |
134 | self.dataOutObj.flagNoData = False |
|
168 | self.dataOutObj.flagNoData = False | |
135 |
|
169 | |||
136 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
170 | self.dataOutObj.heightList = self.dataInObj.heightList | |
137 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
171 | self.dataOutObj.channelList = self.dataInObj.channelList | |
138 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
172 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() | |
139 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
173 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() | |
140 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
174 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() | |
141 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
175 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() | |
142 |
|
176 | |||
143 | self.dataOutObj.dataType = self.dataInObj.dataType |
|
177 | self.dataOutObj.dataType = self.dataInObj.dataType | |
144 | self.dataOutObj.nPairs = nPair |
|
178 | self.dataOutObj.nPairs = nPair | |
145 | self.dataOutObj.nChannels = nChannels |
|
179 | self.dataOutObj.nChannels = nChannels | |
146 | self.dataOutObj.nProfiles = nFFTPoints |
|
180 | self.dataOutObj.nProfiles = nFFTPoints | |
147 | self.dataOutObj.nHeights = nheis |
|
181 | self.dataOutObj.nHeights = nheis | |
148 | self.dataOutObj.nFFTPoints = nFFTPoints |
|
182 | self.dataOutObj.nFFTPoints = nFFTPoints | |
149 | #self.dataOutObj.data = None |
|
183 | #self.dataOutObj.data = None | |
150 |
|
184 | |||
151 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
185 | self.dataOutObj.m_SystemHeader.numChannels = nChannels | |
152 | self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints |
|
186 | self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints | |
153 |
|
187 | |||
154 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
188 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
155 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair |
|
189 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair | |
156 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints |
|
190 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints | |
157 | self.dataOutObj.m_ProcessingHeader.numHeights = nheis |
|
191 | self.dataOutObj.m_ProcessingHeader.numHeights = nheis | |
158 | self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
192 | self.dataOutObj.m_ProcessingHeader.shif_fft = True | |
159 |
|
193 | |||
160 | spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1')) |
|
194 | spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1')) | |
161 | k = 0 |
|
195 | k = 0 | |
162 | for i in range( 0,nChannels*2,2 ): |
|
196 | for i in range( 0,nChannels*2,2 ): | |
163 | spectraComb[i] = k |
|
197 | spectraComb[i] = k | |
164 | spectraComb[i+1] = k |
|
198 | spectraComb[i+1] = k | |
165 | k += 1 |
|
199 | k += 1 | |
166 |
|
200 | |||
167 | k *= 2 |
|
201 | k *= 2 | |
168 |
|
202 | |||
169 | if self.pairList != None: |
|
203 | if self.pairList != None: | |
170 |
|
204 | |||
171 | for pair in self.pairList: |
|
205 | for pair in self.pairList: | |
172 | spectraComb[k] = pair[0] |
|
206 | spectraComb[k] = pair[0] | |
173 | spectraComb[k+1] = pair[1] |
|
207 | spectraComb[k+1] = pair[1] | |
174 | k += 2 |
|
208 | k += 2 | |
175 |
|
209 | |||
176 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
210 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb | |
177 |
|
211 | |||
178 |
|
212 | |||
179 | def addWriter(self,wrpath): |
|
213 | def addWriter(self,wrpath): | |
180 | objWriter = SpectraWriter(self.dataOutObj) |
|
214 | objWriter = SpectraWriter(self.dataOutObj) | |
181 | objWriter.setup(wrpath) |
|
215 | objWriter.setup(wrpath) | |
182 | self.writerList.append(objWriter) |
|
216 | self.writerObjList.append(objWriter) | |
183 |
|
217 | |||
184 |
|
218 | |||
185 | def addPlotter(self, index=None): |
|
219 | def addPlotter(self, index=None): | |
186 |
|
220 | |||
187 | if index==None: |
|
221 | if index==None: | |
188 | index = self.plotterIndex |
|
222 | index = self.plotterObjIndex | |
189 |
|
223 | |||
190 | plotObj = Spectrum(self.dataOutObj, index) |
|
224 | plotObj = Spectrum(self.dataOutObj, index) | |
191 | self.plotterList.append(plotObj) |
|
225 | self.plotterObjList.append(plotObj) | |
192 |
|
226 | |||
193 |
|
227 | |||
194 | def addIntegrator(self,N): |
|
228 | def addIntegrator(self,N): | |
195 |
|
229 | |||
196 | objIncohInt = IncoherentIntegration(N) |
|
230 | objIncohInt = IncoherentIntegration(N) | |
197 | self.integratorList.append(objIncohInt) |
|
231 | self.integratorObjList.append(objIncohInt) | |
198 |
|
232 | |||
199 |
|
233 | |||
200 | def writeData(self, wrpath): |
|
234 | def writeData(self, wrpath): | |
201 | if self.dataOutObj.flagNoData: |
|
235 | if self.dataOutObj.flagNoData: | |
202 | return 0 |
|
236 | return 0 | |
203 |
|
237 | |||
204 | if len(self.writerList) <= self.writerIndex: |
|
238 | if len(self.writerObjList) <= self.writerObjIndex: | |
205 | self.addWriter(wrpath) |
|
239 | self.addWriter(wrpath) | |
206 |
|
240 | |||
207 | self.writerList[self.writerIndex].putData() |
|
241 | self.writerObjList[self.writerObjIndex].putData() | |
208 |
|
242 | |||
209 | self.writerIndex += 1 |
|
243 | self.writerObjIndex += 1 | |
210 |
|
244 | |||
211 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): |
|
245 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): | |
212 | if self.dataOutObj.flagNoData: |
|
246 | if self.dataOutObj.flagNoData: | |
213 | return 0 |
|
247 | return 0 | |
214 |
|
248 | |||
215 | if len(self.plotterList) <= self.plotterIndex: |
|
249 | if len(self.plotterObjList) <= self.plotterObjIndex: | |
216 | self.addPlotter(index) |
|
250 | self.addPlotter(index) | |
217 |
|
251 | |||
218 | self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
252 | self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
219 |
|
253 | |||
220 | self.plotterIndex += 1 |
|
254 | self.plotterObjIndex += 1 | |
221 |
|
255 | |||
222 | def integrator(self, N): |
|
256 | def integrator(self, N): | |
223 | if self.dataOutObj.flagNoData: |
|
257 | if self.dataOutObj.flagNoData: | |
224 | return 0 |
|
258 | return 0 | |
225 |
|
259 | |||
226 | if len(self.integratorList) <= self.integratorIndex: |
|
260 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
227 | self.addIntegrator(N) |
|
261 | self.addIntegrator(N) | |
228 |
|
262 | |||
229 | myCohIntObj = self.integratorList[self.integratorIndex] |
|
263 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
230 | myCohIntObj.exe(self.dataOutObj.data_spc) |
|
264 | myCohIntObj.exe(self.dataOutObj.data_spc) | |
231 |
|
265 | |||
232 | if myCohIntObj.flag: |
|
266 | if myCohIntObj.flag: | |
233 | self.dataOutObj.data_spc = myCohIntObj.data |
|
267 | self.dataOutObj.data_spc = myCohIntObj.data | |
234 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= N |
|
268 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= N | |
235 | self.dataOutObj.flagNoData = False |
|
269 | self.dataOutObj.flagNoData = False | |
236 |
|
270 | |||
237 | else: |
|
271 | else: | |
238 | self.dataOutObj.flagNoData = True |
|
272 | self.dataOutObj.flagNoData = True | |
239 |
|
273 | |||
240 | self.integratorIndex += 1 |
|
274 | self.integratorObjIndex += 1 | |
241 |
|
275 | |||
242 | def removeDC(self, type): |
|
276 | def removeDC(self, type): | |
243 |
|
277 | |||
244 | if self.dataOutObj.flagNoData: |
|
278 | if self.dataOutObj.flagNoData: | |
245 | return 0 |
|
279 | return 0 | |
246 | pass |
|
280 | pass | |
247 |
|
281 | |||
248 | def removeInterference(self): |
|
282 | def removeInterference(self): | |
249 |
|
283 | |||
250 | if self.dataOutObj.flagNoData: |
|
284 | if self.dataOutObj.flagNoData: | |
251 | return 0 |
|
285 | return 0 | |
252 | pass |
|
286 | pass | |
253 |
|
287 | |||
254 | def removeSatellites(self): |
|
288 | def removeSatellites(self): | |
255 |
|
289 | |||
256 | if self.dataOutObj.flagNoData: |
|
290 | if self.dataOutObj.flagNoData: | |
257 | return 0 |
|
291 | return 0 | |
258 | pass |
|
292 | pass | |
259 |
|
293 | |||
260 | def selectChannels(self, channelList, pairList=None): |
|
294 | def selectChannels(self, channelList, pairList=None): | |
261 | """ |
|
295 | """ | |
262 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList |
|
296 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList | |
263 |
|
297 | |||
264 | Input: |
|
298 | Input: | |
265 | channelList : lista sencilla de canales a seleccionar por ej. (2,3,7) |
|
299 | channelList : lista sencilla de canales a seleccionar por ej. (2,3,7) | |
266 | pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) ) |
|
300 | pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) ) | |
267 |
|
301 | |||
268 | Affected: |
|
302 | Affected: | |
269 | self.dataOutObj.data_spc |
|
303 | self.dataOutObj.data_spc | |
270 | self.dataOutObj.data_cspc |
|
304 | self.dataOutObj.data_cspc | |
271 | self.dataOutObj.data_dc |
|
305 | self.dataOutObj.data_dc | |
272 | self.dataOutObj.nChannels |
|
306 | self.dataOutObj.nChannels | |
273 | self.dataOutObj.nPairs |
|
307 | self.dataOutObj.nPairs | |
274 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
308 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
275 | self.dataOutObj.m_SystemHeader.numChannels |
|
309 | self.dataOutObj.m_SystemHeader.numChannels | |
276 |
|
310 | |||
277 | Return: |
|
311 | Return: | |
278 | None |
|
312 | None | |
279 | """ |
|
313 | """ | |
280 |
|
314 | |||
281 | if self.dataOutObj.flagNoData: |
|
315 | if self.dataOutObj.flagNoData: | |
282 | return 0 |
|
316 | return 0 | |
283 |
|
317 | |||
284 | channelIndexList = [] |
|
318 | channelIndexList = [] | |
285 | for channel in channelList: |
|
319 | for channel in channelList: | |
286 | if channel in self.dataOutObj.channelList: |
|
320 | if channel in self.dataOutObj.channelList: | |
287 | index = self.dataOutObj.channelList.index(channel) |
|
321 | index = self.dataOutObj.channelList.index(channel) | |
288 | channelIndexList.append(index) |
|
322 | channelIndexList.append(index) | |
289 | continue |
|
323 | continue | |
290 |
|
324 | |||
291 | raise ValueError, "The value %d in channelList is not valid" %channel |
|
325 | raise ValueError, "The value %d in channelList is not valid" %channel | |
292 |
|
326 | |||
293 | nProfiles = self.dataOutObj.nProfiles |
|
327 | nProfiles = self.dataOutObj.nProfiles | |
294 | #dataType = self.dataOutObj.dataType |
|
328 | #dataType = self.dataOutObj.dataType | |
295 | nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights |
|
329 | nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights | |
296 | blocksize = 0 |
|
330 | blocksize = 0 | |
297 |
|
331 | |||
298 | #self spectra |
|
332 | #self spectra | |
299 | nChannels = len(channelIndexList) |
|
333 | nChannels = len(channelIndexList) | |
300 | spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] ) |
|
334 | spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] ) | |
301 |
|
335 | |||
302 | for index, channel in enumerate(channelIndexList): |
|
336 | for index, channel in enumerate(channelIndexList): | |
303 | spc[index,:,:] = self.dataOutObj.data_spc[index,:,:] |
|
337 | spc[index,:,:] = self.dataOutObj.data_spc[index,:,:] | |
304 |
|
338 | |||
305 | #DC channel |
|
339 | #DC channel | |
306 | dc = numpy.zeros( (nChannels,nHeights), dtype='complex' ) |
|
340 | dc = numpy.zeros( (nChannels,nHeights), dtype='complex' ) | |
307 | for index, channel in enumerate(channelIndexList): |
|
341 | for index, channel in enumerate(channelIndexList): | |
308 | dc[index,:] = self.dataOutObj.data_dc[channel,:] |
|
342 | dc[index,:] = self.dataOutObj.data_dc[channel,:] | |
309 |
|
343 | |||
310 | blocksize += dc.size |
|
344 | blocksize += dc.size | |
311 | blocksize += spc.size |
|
345 | blocksize += spc.size | |
312 |
|
346 | |||
313 | nPairs = 0 |
|
347 | nPairs = 0 | |
314 | cspc = None |
|
348 | cspc = None | |
315 |
|
349 | |||
316 | if pairList == None: |
|
350 | if pairList == None: | |
317 | pairList = self.pairList |
|
351 | pairList = self.pairList | |
318 |
|
352 | |||
319 | if (pairList != None) and (self.dataOutObj.data_cspc != None): |
|
353 | if (pairList != None) and (self.dataOutObj.data_cspc != None): | |
320 | #cross spectra |
|
354 | #cross spectra | |
321 | nPairs = len(pairList) |
|
355 | nPairs = len(pairList) | |
322 | cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' ) |
|
356 | cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' ) | |
323 |
|
357 | |||
324 | spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb |
|
358 | spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb | |
325 | totalSpectra = len(spectraComb) |
|
359 | totalSpectra = len(spectraComb) | |
326 | nchan = self.dataOutObj.nChannels |
|
360 | nchan = self.dataOutObj.nChannels | |
327 | pairIndexList = [] |
|
361 | pairIndexList = [] | |
328 |
|
362 | |||
329 | for pair in pairList: #busco el par en la lista de pares del Spectra Combinations |
|
363 | for pair in pairList: #busco el par en la lista de pares del Spectra Combinations | |
330 | for index in range(0,totalSpectra,2): |
|
364 | for index in range(0,totalSpectra,2): | |
331 | if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]: |
|
365 | if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]: | |
332 | pairIndexList.append( index/2 - nchan ) |
|
366 | pairIndexList.append( index/2 - nchan ) | |
333 |
|
367 | |||
334 | for index, pair in enumerate(pairIndexList): |
|
368 | for index, pair in enumerate(pairIndexList): | |
335 | cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:] |
|
369 | cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:] | |
336 | blocksize += cspc.size |
|
370 | blocksize += cspc.size | |
337 |
|
371 | |||
338 | else: |
|
372 | else: | |
339 | pairList = self.pairList |
|
373 | pairList = self.pairList | |
340 | cspc = self.dataOutObj.data_cspc |
|
374 | cspc = self.dataOutObj.data_cspc | |
341 | if cspc != None: |
|
375 | if cspc != None: | |
342 | blocksize += cspc.size |
|
376 | blocksize += cspc.size | |
343 |
|
377 | |||
344 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) |
|
378 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) | |
345 | i = 0 |
|
379 | i = 0 | |
346 | for val in channelList: |
|
380 | for val in channelList: | |
347 | spectraComb[i] = val |
|
381 | spectraComb[i] = val | |
348 | spectraComb[i+1] = val |
|
382 | spectraComb[i+1] = val | |
349 | i += 2 |
|
383 | i += 2 | |
350 |
|
384 | |||
351 | if pairList != None: |
|
385 | if pairList != None: | |
352 | for pair in pairList: |
|
386 | for pair in pairList: | |
353 | spectraComb[i] = pair[0] |
|
387 | spectraComb[i] = pair[0] | |
354 | spectraComb[i+1] = pair[1] |
|
388 | spectraComb[i+1] = pair[1] | |
355 | i += 2 |
|
389 | i += 2 | |
356 |
|
390 | |||
357 | self.dataOutObj.data_spc = spc |
|
391 | self.dataOutObj.data_spc = spc | |
358 | self.dataOutObj.data_cspc = cspc |
|
392 | self.dataOutObj.data_cspc = cspc | |
359 | self.dataOutObj.data_dc = dc |
|
393 | self.dataOutObj.data_dc = dc | |
360 | self.dataOutObj.nChannels = nChannels |
|
394 | self.dataOutObj.nChannels = nChannels | |
361 | self.dataOutObj.nPairs = nPairs |
|
395 | self.dataOutObj.nPairs = nPairs | |
362 |
|
396 | |||
363 | self.dataOutObj.channelList = channelList |
|
397 | self.dataOutObj.channelList = channelList | |
364 |
|
398 | |||
365 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
399 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb | |
366 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs |
|
400 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs | |
367 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
401 | self.dataOutObj.m_SystemHeader.numChannels = nChannels | |
368 | self.dataOutObj.nChannels = nChannels |
|
402 | self.dataOutObj.nChannels = nChannels | |
369 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
403 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
370 |
|
404 | |||
371 |
|
405 | |||
372 | def selectHeightsByValue(self, minHei, maxHei): |
|
406 | def selectHeightsByValue(self, minHei, maxHei): | |
373 | """ |
|
407 | """ | |
374 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
408 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
375 | minHei <= height <= maxHei |
|
409 | minHei <= height <= maxHei | |
376 |
|
410 | |||
377 | Input: |
|
411 | Input: | |
378 | minHei : valor minimo de altura a considerar |
|
412 | minHei : valor minimo de altura a considerar | |
379 | maxHei : valor maximo de altura a considerar |
|
413 | maxHei : valor maximo de altura a considerar | |
380 |
|
414 | |||
381 | Affected: |
|
415 | Affected: | |
382 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
416 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
383 |
|
417 | |||
384 | Return: |
|
418 | Return: | |
385 | None |
|
419 | None | |
386 | """ |
|
420 | """ | |
387 |
|
421 | |||
388 | if self.dataOutObj.flagNoData: |
|
422 | if self.dataOutObj.flagNoData: | |
389 | return 0 |
|
423 | return 0 | |
390 |
|
424 | |||
391 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): |
|
425 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): | |
392 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
426 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
393 |
|
427 | |||
394 | if (maxHei > self.dataOutObj.heightList[-1]): |
|
428 | if (maxHei > self.dataOutObj.heightList[-1]): | |
395 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
429 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
396 |
|
430 | |||
397 | minIndex = 0 |
|
431 | minIndex = 0 | |
398 | maxIndex = 0 |
|
432 | maxIndex = 0 | |
399 | data = self.dataOutObj.heightList |
|
433 | data = self.dataOutObj.heightList | |
400 |
|
434 | |||
401 | for i,val in enumerate(data): |
|
435 | for i,val in enumerate(data): | |
402 | if val < minHei: |
|
436 | if val < minHei: | |
403 | continue |
|
437 | continue | |
404 | else: |
|
438 | else: | |
405 | minIndex = i; |
|
439 | minIndex = i; | |
406 | break |
|
440 | break | |
407 |
|
441 | |||
408 | for i,val in enumerate(data): |
|
442 | for i,val in enumerate(data): | |
409 | if val <= maxHei: |
|
443 | if val <= maxHei: | |
410 | maxIndex = i; |
|
444 | maxIndex = i; | |
411 | else: |
|
445 | else: | |
412 | break |
|
446 | break | |
413 |
|
447 | |||
414 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
448 | self.selectHeightsByIndex(minIndex, maxIndex) | |
415 |
|
449 | |||
416 |
|
450 | |||
417 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
451 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
418 | """ |
|
452 | """ | |
419 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
453 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
420 | minIndex <= index <= maxIndex |
|
454 | minIndex <= index <= maxIndex | |
421 |
|
455 | |||
422 | Input: |
|
456 | Input: | |
423 | minIndex : valor minimo de altura a considerar |
|
457 | minIndex : valor minimo de altura a considerar | |
424 | maxIndex : valor maximo de altura a considerar |
|
458 | maxIndex : valor maximo de altura a considerar | |
425 |
|
459 | |||
426 | Affected: |
|
460 | Affected: | |
427 | self.dataOutObj.data_spc |
|
461 | self.dataOutObj.data_spc | |
428 | self.dataOutObj.data_cspc |
|
462 | self.dataOutObj.data_cspc | |
429 | self.dataOutObj.data_dc |
|
463 | self.dataOutObj.data_dc | |
430 | self.dataOutObj.heightList |
|
464 | self.dataOutObj.heightList | |
431 | self.dataOutObj.nHeights |
|
465 | self.dataOutObj.nHeights | |
432 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
466 | self.dataOutObj.m_ProcessingHeader.numHeights | |
433 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
467 | self.dataOutObj.m_ProcessingHeader.blockSize | |
434 | self.dataOutObj.m_ProcessingHeader.firstHeight |
|
468 | self.dataOutObj.m_ProcessingHeader.firstHeight | |
435 | self.dataOutObj.m_RadarControllerHeader.numHeights |
|
469 | self.dataOutObj.m_RadarControllerHeader.numHeights | |
436 |
|
470 | |||
437 | Return: |
|
471 | Return: | |
438 | None |
|
472 | None | |
439 | """ |
|
473 | """ | |
440 |
|
474 | |||
441 | if self.dataOutObj.flagNoData: |
|
475 | if self.dataOutObj.flagNoData: | |
442 | return 0 |
|
476 | return 0 | |
443 |
|
477 | |||
444 | if (minIndex < 0) or (minIndex > maxIndex): |
|
478 | if (minIndex < 0) or (minIndex > maxIndex): | |
445 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
479 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
446 |
|
480 | |||
447 | if (maxIndex >= self.dataOutObj.nHeights): |
|
481 | if (maxIndex >= self.dataOutObj.nHeights): | |
448 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
482 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
449 |
|
483 | |||
450 | nChannels = self.dataOutObj.nChannels |
|
484 | nChannels = self.dataOutObj.nChannels | |
451 | nPairs = self.dataOutObj.nPairs |
|
485 | nPairs = self.dataOutObj.nPairs | |
452 | nProfiles = self.dataOutObj.nProfiles |
|
486 | nProfiles = self.dataOutObj.nProfiles | |
453 | dataType = self.dataOutObj.dataType |
|
487 | dataType = self.dataOutObj.dataType | |
454 | nHeights = maxIndex - minIndex + 1 |
|
488 | nHeights = maxIndex - minIndex + 1 | |
455 | blockSize = 0 |
|
489 | blockSize = 0 | |
456 |
|
490 | |||
457 | #self spectra |
|
491 | #self spectra | |
458 | spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1] |
|
492 | spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1] | |
459 | blockSize += spc.size |
|
493 | blockSize += spc.size | |
460 |
|
494 | |||
461 | #cross spectra |
|
495 | #cross spectra | |
462 | cspc = None |
|
496 | cspc = None | |
463 | if self.dataOutObj.data_cspc != None: |
|
497 | if self.dataOutObj.data_cspc != None: | |
464 | cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1] |
|
498 | cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1] | |
465 | blockSize += cspc.size |
|
499 | blockSize += cspc.size | |
466 |
|
500 | |||
467 | #DC channel |
|
501 | #DC channel | |
468 | dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1] |
|
502 | dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1] | |
469 | blockSize += dc.size |
|
503 | blockSize += dc.size | |
470 |
|
504 | |||
471 | self.dataOutObj.data_spc = spc |
|
505 | self.dataOutObj.data_spc = spc | |
472 | if cspc != None: |
|
506 | if cspc != None: | |
473 | self.dataOutObj.data_cspc = cspc |
|
507 | self.dataOutObj.data_cspc = cspc | |
474 | self.dataOutObj.data_dc = dc |
|
508 | self.dataOutObj.data_dc = dc | |
475 |
|
509 | |||
476 | firstHeight = self.dataOutObj.heightList[minIndex] |
|
510 | firstHeight = self.dataOutObj.heightList[minIndex] | |
477 |
|
511 | |||
478 | self.dataOutObj.nHeights = nHeights |
|
512 | self.dataOutObj.nHeights = nHeights | |
479 | self.dataOutObj.m_ProcessingHeader.blockSize = blockSize |
|
513 | self.dataOutObj.m_ProcessingHeader.blockSize = blockSize | |
480 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights |
|
514 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights | |
481 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight |
|
515 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight | |
482 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights |
|
516 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights | |
483 |
|
517 | |||
484 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] |
|
518 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] | |
485 |
|
519 | |||
486 |
|
520 | |||
487 | class IncoherentIntegration: |
|
521 | class IncoherentIntegration: | |
|
522 | ||||
|
523 | profCounter = 1 | |||
|
524 | data = None | |||
|
525 | buffer = None | |||
|
526 | flag = False | |||
|
527 | nIncohInt = None | |||
|
528 | ||||
488 | def __init__(self, N): |
|
529 | def __init__(self, N): | |
|
530 | ||||
489 | self.profCounter = 1 |
|
531 | self.profCounter = 1 | |
490 | self.data = None |
|
532 | self.data = None | |
491 | self.buffer = None |
|
533 | self.buffer = None | |
492 | self.flag = False |
|
534 | self.flag = False | |
493 | self.nIncohInt = N |
|
535 | self.nIncohInt = N | |
494 |
|
536 | |||
495 | def exe(self,data): |
|
537 | def exe(self,data): | |
496 |
|
538 | |||
497 | if self.buffer == None: |
|
539 | if self.buffer == None: | |
498 | self.buffer = data |
|
540 | self.buffer = data | |
499 | else: |
|
541 | else: | |
500 | self.buffer = self.buffer + data |
|
542 | self.buffer = self.buffer + data | |
501 |
|
543 | |||
502 | if self.profCounter == self.nIncohInt: |
|
544 | if self.profCounter == self.nIncohInt: | |
503 | self.data = self.buffer |
|
545 | self.data = self.buffer | |
504 | self.buffer = None |
|
546 | self.buffer = None | |
505 | self.profCounter = 0 |
|
547 | self.profCounter = 0 | |
506 | self.flag = True |
|
548 | self.flag = True | |
507 | else: |
|
549 | else: | |
508 | self.flag = False |
|
550 | self.flag = False | |
509 |
|
551 | |||
510 | self.profCounter += 1 |
|
552 | self.profCounter += 1 | |
511 |
|
553 |
@@ -1,464 +1,503 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | import os, sys |
|
8 | import os, sys | |
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Model.Voltage import Voltage |
|
14 | from Model.Voltage import Voltage | |
15 | from IO.VoltageIO import VoltageWriter |
|
15 | from IO.VoltageIO import VoltageWriter | |
16 | from Graphics.VoltagePlot import Osciloscope |
|
16 | from Graphics.VoltagePlot import Osciloscope | |
17 |
|
17 | |||
18 | class VoltageProcessor: |
|
18 | class VoltageProcessor: | |
19 | ''' |
|
19 | ''' | |
20 | classdocs |
|
20 | classdocs | |
21 | ''' |
|
21 | ''' | |
|
22 | ||||
|
23 | dataInObj = None | |||
|
24 | dataOutObj = None | |||
|
25 | ||||
|
26 | integratorObjIndex = None | |||
|
27 | decoderObjIndex = None | |||
|
28 | profSelectorObjIndex = None | |||
|
29 | writerObjIndex = None | |||
|
30 | plotterObjIndex = None | |||
|
31 | ||||
|
32 | integratorObjList = [] | |||
|
33 | decoderObjList = [] | |||
|
34 | profileSelectorObjList = [] | |||
|
35 | writerObjList = [] | |||
|
36 | plotterObjList = [] | |||
|
37 | m_Voltage= Voltage() | |||
|
38 | ||||
|
39 | m_ProfileSelector= ProfileSelector() | |||
22 |
|
40 | |||
23 | def __init__(self, voltageInObj, voltageOutObj=None): |
|
41 | m_Decoder= Decoder() | |
|
42 | ||||
|
43 | m_CoherentIntegrator= CoherentIntegrator() | |||
|
44 | ||||
|
45 | ||||
|
46 | def __init__(self, dataInObj, dataOutObj=None): | |||
24 | ''' |
|
47 | ''' | |
25 | Constructor |
|
48 | Constructor | |
26 | ''' |
|
49 | ''' | |
27 |
|
50 | |||
28 |
self. |
|
51 | self.dataInObj = dataInObj | |
29 |
|
52 | |||
30 |
if |
|
53 | if dataOutObj == None: | |
31 |
self. |
|
54 | self.dataOutObj = Voltage() | |
32 | else: |
|
55 | else: | |
33 |
self. |
|
56 | self.dataOutObj = dataOutObj | |
34 |
|
57 | |||
35 | self.integratorIndex = None |
|
58 | self.integratorObjIndex = None | |
36 | self.decoderIndex = None |
|
59 | self.decoderObjIndex = None | |
37 | self.profSelectorIndex = None |
|
60 | self.profSelectorObjIndex = None | |
38 | self.writerIndex = None |
|
61 | self.writerObjIndex = None | |
39 | self.plotterIndex = None |
|
62 | self.plotterObjIndex = None | |
40 |
|
63 | |||
41 | self.integratorList = [] |
|
64 | self.integratorObjList = [] | |
42 | self.decoderList = [] |
|
65 | self.decoderObjList = [] | |
43 | self.profileSelectorList = [] |
|
66 | self.profileSelectorObjList = [] | |
44 | self.writerList = [] |
|
67 | self.writerObjList = [] | |
45 | self.plotterList = [] |
|
68 | self.plotterObjList = [] | |
46 |
|
69 | |||
47 | def init(self): |
|
70 | def init(self): | |
48 |
|
71 | |||
49 | self.integratorIndex = 0 |
|
72 | self.integratorObjIndex = 0 | |
50 | self.decoderIndex = 0 |
|
73 | self.decoderObjIndex = 0 | |
51 | self.profSelectorIndex = 0 |
|
74 | self.profSelectorObjIndex = 0 | |
52 | self.writerIndex = 0 |
|
75 | self.writerObjIndex = 0 | |
53 | self.plotterIndex = 0 |
|
76 | self.plotterObjIndex = 0 | |
54 |
self. |
|
77 | self.dataOutObj.copy(self.dataInObj) | |
55 |
|
78 | |||
56 | def addWriter(self, wrpath): |
|
79 | def addWriter(self, wrpath): | |
57 |
objWriter = VoltageWriter(self. |
|
80 | objWriter = VoltageWriter(self.dataOutObj) | |
58 | objWriter.setup(wrpath) |
|
81 | objWriter.setup(wrpath) | |
59 | self.writerList.append(objWriter) |
|
82 | self.writerObjList.append(objWriter) | |
60 |
|
83 | |||
61 | def addPlotter(self): |
|
84 | def addPlotter(self): | |
62 |
|
85 | |||
63 |
plotObj = Osciloscope(self. |
|
86 | plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex) | |
64 | self.plotterList.append(plotObj) |
|
87 | self.plotterObjList.append(plotObj) | |
65 |
|
88 | |||
66 | def addIntegrator(self, nCohInt): |
|
89 | def addIntegrator(self, nCohInt): | |
67 |
|
90 | |||
68 | objCohInt = CoherentIntegrator(nCohInt) |
|
91 | objCohInt = CoherentIntegrator(nCohInt) | |
69 | self.integratorList.append(objCohInt) |
|
92 | self.integratorObjList.append(objCohInt) | |
70 |
|
93 | |||
71 | def addDecoder(self, code, ncode, nbaud): |
|
94 | def addDecoder(self, code, ncode, nbaud): | |
72 |
|
95 | |||
73 | objDecoder = Decoder(code,ncode,nbaud) |
|
96 | objDecoder = Decoder(code,ncode,nbaud) | |
74 | self.decoderList.append(objDecoder) |
|
97 | self.decoderObjList.append(objDecoder) | |
75 |
|
98 | |||
76 | def addProfileSelector(self, nProfiles): |
|
99 | def addProfileSelector(self, nProfiles): | |
77 |
|
100 | |||
78 | objProfSelector = ProfileSelector(nProfiles) |
|
101 | objProfSelector = ProfileSelector(nProfiles) | |
79 | self.profileSelectorList.append(objProfSelector) |
|
102 | self.profileSelectorObjList.append(objProfSelector) | |
80 |
|
103 | |||
81 | def writeData(self,wrpath): |
|
104 | def writeData(self,wrpath): | |
82 |
|
105 | |||
83 |
if self. |
|
106 | if self.dataOutObj.flagNoData: | |
84 | return 0 |
|
107 | return 0 | |
85 |
|
108 | |||
86 | if len(self.writerList) <= self.writerIndex: |
|
109 | if len(self.writerObjList) <= self.writerObjIndex: | |
87 | self.addWriter(wrpath) |
|
110 | self.addWriter(wrpath) | |
88 |
|
111 | |||
89 | self.writerList[self.writerIndex].putData() |
|
112 | self.writerObjList[self.writerObjIndex].putData() | |
90 |
|
113 | |||
91 | # myWrObj = self.writerList[self.writerIndex] |
|
114 | # myWrObj = self.writerObjList[self.writerObjIndex] | |
92 | # myWrObj.putData() |
|
115 | # myWrObj.putData() | |
93 |
|
116 | |||
94 | self.writerIndex += 1 |
|
117 | self.writerObjIndex += 1 | |
95 |
|
118 | |||
96 | def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): |
|
119 | def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): | |
97 |
if self. |
|
120 | if self.dataOutObj.flagNoData: | |
98 | return 0 |
|
121 | return 0 | |
99 |
|
122 | |||
100 | if len(self.plotterList) <= self.plotterIndex: |
|
123 | if len(self.plotterObjList) <= self.plotterObjIndex: | |
101 | self.addPlotter() |
|
124 | self.addPlotter() | |
102 |
|
125 | |||
103 | self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
126 | self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
104 |
|
127 | |||
105 | self.plotterIndex += 1 |
|
128 | self.plotterObjIndex += 1 | |
106 |
|
129 | |||
107 | def integrator(self, N): |
|
130 | def integrator(self, N): | |
108 |
|
131 | |||
109 |
if self. |
|
132 | if self.dataOutObj.flagNoData: | |
110 | return 0 |
|
133 | return 0 | |
111 |
|
134 | |||
112 | if len(self.integratorList) <= self.integratorIndex: |
|
135 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
113 | self.addIntegrator(N) |
|
136 | self.addIntegrator(N) | |
114 |
|
137 | |||
115 | myCohIntObj = self.integratorList[self.integratorIndex] |
|
138 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
116 |
myCohIntObj.exe(self. |
|
139 | myCohIntObj.exe(self.dataOutObj.data) | |
117 |
|
140 | |||
118 | if myCohIntObj.flag: |
|
141 | if myCohIntObj.flag: | |
119 |
self. |
|
142 | self.dataOutObj.data = myCohIntObj.data | |
120 |
self. |
|
143 | self.dataOutObj.m_ProcessingHeader.coherentInt *= N | |
121 |
self. |
|
144 | self.dataOutObj.flagNoData = False | |
122 |
|
145 | |||
123 | else: |
|
146 | else: | |
124 |
self. |
|
147 | self.dataOutObj.flagNoData = True | |
125 |
|
148 | |||
126 | self.integratorIndex += 1 |
|
149 | self.integratorObjIndex += 1 | |
127 |
|
150 | |||
128 | def decoder(self,code=None,type = 0): |
|
151 | def decoder(self,code=None,type = 0): | |
129 |
|
152 | |||
130 |
if self. |
|
153 | if self.dataOutObj.flagNoData: | |
131 | return 0 |
|
154 | return 0 | |
132 |
|
155 | |||
133 | if code == None: |
|
156 | if code == None: | |
134 |
code = self. |
|
157 | code = self.dataOutObj.m_RadarControllerHeader.code | |
135 | ncode, nbaud = code.shape |
|
158 | ncode, nbaud = code.shape | |
136 |
|
159 | |||
137 | if len(self.decoderList) <= self.decoderIndex: |
|
160 | if len(self.decoderObjList) <= self.decoderObjIndex: | |
138 | self.addDecoder(code,ncode,nbaud) |
|
161 | self.addDecoder(code,ncode,nbaud) | |
139 |
|
162 | |||
140 | myDecodObj = self.decoderList[self.decoderIndex] |
|
163 | myDecodObj = self.decoderObjList[self.decoderObjIndex] | |
141 |
myDecodObj.exe(data=self. |
|
164 | myDecodObj.exe(data=self.dataOutObj.data,type=type) | |
142 |
|
165 | |||
143 | if myDecodObj.flag: |
|
166 | if myDecodObj.flag: | |
144 |
self. |
|
167 | self.dataOutObj.data = myDecodObj.data | |
145 |
self. |
|
168 | self.dataOutObj.flagNoData = False | |
146 | else: |
|
169 | else: | |
147 |
self. |
|
170 | self.dataOutObj.flagNoData = True | |
148 |
|
171 | |||
149 | self.decoderIndex += 1 |
|
172 | self.decoderObjIndex += 1 | |
150 |
|
173 | |||
151 |
|
174 | |||
152 | def filterByHei(self, window): |
|
175 | def filterByHei(self, window): | |
153 | pass |
|
176 | pass | |
154 |
|
177 | |||
155 |
|
178 | |||
156 | def selectChannels(self, channelList): |
|
179 | def selectChannels(self, channelList): | |
157 | """ |
|
180 | """ | |
158 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList |
|
181 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList | |
159 |
|
182 | |||
160 | Input: |
|
183 | Input: | |
161 | channelList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
184 | channelList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
162 |
|
185 | |||
163 | Affected: |
|
186 | Affected: | |
164 | self.dataOutObj.data |
|
187 | self.dataOutObj.data | |
165 |
self. |
|
188 | self.dataOutObj.channelList | |
166 | self.dataOutObj.nChannels |
|
189 | self.dataOutObj.nChannels | |
167 |
self. |
|
190 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
168 | self.dataOutObj.m_SystemHeader.numChannels |
|
191 | self.dataOutObj.m_SystemHeader.numChannels | |
169 |
self. |
|
192 | self.dataOutObj.m_ProcessingHeader.blockSize | |
170 |
|
193 | |||
171 | Return: |
|
194 | Return: | |
172 | None |
|
195 | None | |
173 | """ |
|
196 | """ | |
174 |
if self. |
|
197 | if self.dataOutObj.flagNoData: | |
175 | return 0 |
|
198 | return 0 | |
176 |
|
199 | |||
177 | for channel in channelList: |
|
200 | for channel in channelList: | |
178 |
if channel not in self. |
|
201 | if channel not in self.dataOutObj.channelList: | |
179 | raise ValueError, "The value %d in channelList is not valid" %channel |
|
202 | raise ValueError, "The value %d in channelList is not valid" %channel | |
180 |
|
203 | |||
181 | nchannels = len(channelList) |
|
204 | nchannels = len(channelList) | |
182 |
profiles = self. |
|
205 | profiles = self.dataOutObj.nProfiles | |
183 |
heights = self. |
|
206 | heights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights | |
184 |
|
207 | |||
185 | data = numpy.zeros( (nchannels,heights), dtype='complex' ) |
|
208 | data = numpy.zeros( (nchannels,heights), dtype='complex' ) | |
186 | for index,channel in enumerate(channelList): |
|
209 | for index,channel in enumerate(channelList): | |
187 |
data[index,:] = self. |
|
210 | data[index,:] = self.dataOutObj.data[channel,:] | |
188 |
|
211 | |||
189 |
self. |
|
212 | self.dataOutObj.data = data | |
190 |
self. |
|
213 | self.dataOutObj.channelList = channelList | |
191 |
self. |
|
214 | self.dataOutObj.nChannels = nchannels | |
192 |
self. |
|
215 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nchannels | |
193 |
self. |
|
216 | self.dataOutObj.m_SystemHeader.numChannels = nchannels | |
194 |
self. |
|
217 | self.dataOutObj.m_ProcessingHeader.blockSize = data.size | |
195 | return 1 |
|
218 | return 1 | |
196 |
|
219 | |||
197 |
|
220 | |||
198 | def selectHeightsByValue(self, minHei, maxHei): |
|
221 | def selectHeightsByValue(self, minHei, maxHei): | |
199 | """ |
|
222 | """ | |
200 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
223 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
201 | minHei <= height <= maxHei |
|
224 | minHei <= height <= maxHei | |
202 |
|
225 | |||
203 | Input: |
|
226 | Input: | |
204 | minHei : valor minimo de altura a considerar |
|
227 | minHei : valor minimo de altura a considerar | |
205 | maxHei : valor maximo de altura a considerar |
|
228 | maxHei : valor maximo de altura a considerar | |
206 |
|
229 | |||
207 | Affected: |
|
230 | Affected: | |
208 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
231 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
209 |
|
232 | |||
210 | Return: |
|
233 | Return: | |
211 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
234 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
212 | """ |
|
235 | """ | |
213 |
if self. |
|
236 | if self.dataOutObj.flagNoData: | |
214 | return 0 |
|
237 | return 0 | |
215 |
|
238 | |||
216 |
if (minHei < self. |
|
239 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): | |
217 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
240 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
218 |
|
241 | |||
219 |
if (maxHei > self. |
|
242 | if (maxHei > self.dataOutObj.heightList[-1]): | |
220 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
243 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
221 |
|
244 | |||
222 | minIndex = 0 |
|
245 | minIndex = 0 | |
223 | maxIndex = 0 |
|
246 | maxIndex = 0 | |
224 |
data = self. |
|
247 | data = self.dataOutObj.heightList | |
225 |
|
248 | |||
226 | for i,val in enumerate(data): |
|
249 | for i,val in enumerate(data): | |
227 | if val < minHei: |
|
250 | if val < minHei: | |
228 | continue |
|
251 | continue | |
229 | else: |
|
252 | else: | |
230 | minIndex = i; |
|
253 | minIndex = i; | |
231 | break |
|
254 | break | |
232 |
|
255 | |||
233 | for i,val in enumerate(data): |
|
256 | for i,val in enumerate(data): | |
234 | if val <= maxHei: |
|
257 | if val <= maxHei: | |
235 | maxIndex = i; |
|
258 | maxIndex = i; | |
236 | else: |
|
259 | else: | |
237 | break |
|
260 | break | |
238 |
|
261 | |||
239 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
262 | self.selectHeightsByIndex(minIndex, maxIndex) | |
240 | return 1 |
|
263 | return 1 | |
241 |
|
264 | |||
242 |
|
265 | |||
243 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
266 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
244 | """ |
|
267 | """ | |
245 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
268 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
246 | minIndex <= index <= maxIndex |
|
269 | minIndex <= index <= maxIndex | |
247 |
|
270 | |||
248 | Input: |
|
271 | Input: | |
249 | minIndex : valor de indice minimo de altura a considerar |
|
272 | minIndex : valor de indice minimo de altura a considerar | |
250 | maxIndex : valor de indice maximo de altura a considerar |
|
273 | maxIndex : valor de indice maximo de altura a considerar | |
251 |
|
274 | |||
252 | Affected: |
|
275 | Affected: | |
253 |
self. |
|
276 | self.dataOutObj.data | |
254 |
self. |
|
277 | self.dataOutObj.heightList | |
255 |
self. |
|
278 | self.dataOutObj.nHeights | |
256 |
self. |
|
279 | self.dataOutObj.m_ProcessingHeader.blockSize | |
257 |
self. |
|
280 | self.dataOutObj.m_ProcessingHeader.numHeights | |
258 |
self. |
|
281 | self.dataOutObj.m_ProcessingHeader.firstHeight | |
259 |
self. |
|
282 | self.dataOutObj.m_RadarControllerHeader | |
260 |
|
283 | |||
261 | Return: |
|
284 | Return: | |
262 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
285 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
263 | """ |
|
286 | """ | |
264 |
if self. |
|
287 | if self.dataOutObj.flagNoData: | |
265 | return 0 |
|
288 | return 0 | |
266 |
|
289 | |||
267 | if (minIndex < 0) or (minIndex > maxIndex): |
|
290 | if (minIndex < 0) or (minIndex > maxIndex): | |
268 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
291 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
269 |
|
292 | |||
270 |
if (maxIndex >= self. |
|
293 | if (maxIndex >= self.dataOutObj.nHeights): | |
271 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
294 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
272 |
|
295 | |||
273 | nHeights = maxIndex - minIndex + 1 |
|
296 | nHeights = maxIndex - minIndex + 1 | |
274 | firstHeight = 0 |
|
297 | firstHeight = 0 | |
275 |
|
298 | |||
276 | #voltage |
|
299 | #voltage | |
277 |
data = self. |
|
300 | data = self.dataOutObj.data[:,minIndex:maxIndex+1] | |
278 |
|
301 | |||
279 |
firstHeight = self. |
|
302 | firstHeight = self.dataOutObj.heightList[minIndex] | |
280 |
|
303 | |||
281 |
self. |
|
304 | self.dataOutObj.data = data | |
282 |
self. |
|
305 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] | |
283 |
self. |
|
306 | self.dataOutObj.nHeights = nHeights | |
284 |
self. |
|
307 | self.dataOutObj.m_ProcessingHeader.blockSize = data.size | |
285 |
self. |
|
308 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights | |
286 |
self. |
|
309 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight | |
287 |
self. |
|
310 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights | |
288 | return 1 |
|
311 | return 1 | |
289 |
|
312 | |||
290 |
|
313 | |||
291 | def selectProfiles(self, minIndex, maxIndex, nProfiles): |
|
314 | def selectProfiles(self, minIndex, maxIndex, nProfiles): | |
292 | """ |
|
315 | """ | |
293 | Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango |
|
316 | Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango | |
294 | minIndex <= index <= maxIndex |
|
317 | minIndex <= index <= maxIndex | |
295 |
|
318 | |||
296 | Input: |
|
319 | Input: | |
297 | minIndex : valor de indice minimo de perfil a considerar |
|
320 | minIndex : valor de indice minimo de perfil a considerar | |
298 | maxIndex : valor de indice maximo de perfil a considerar |
|
321 | maxIndex : valor de indice maximo de perfil a considerar | |
299 | nProfiles : numero de profiles |
|
322 | nProfiles : numero de profiles | |
300 |
|
323 | |||
301 | Affected: |
|
324 | Affected: | |
302 |
self. |
|
325 | self.dataOutObj.flagNoData | |
303 | self.profSelectorIndex |
|
326 | self.profSelectorObjIndex | |
304 |
|
327 | |||
305 | Return: |
|
328 | Return: | |
306 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
329 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
307 | """ |
|
330 | """ | |
308 |
|
331 | |||
309 |
if self. |
|
332 | if self.dataOutObj.flagNoData: | |
310 | return 0 |
|
333 | return 0 | |
311 |
|
334 | |||
312 | if self.profSelectorIndex >= len(self.profileSelectorList): |
|
335 | if self.profSelectorObjIndex >= len(self.profileSelectorObjList): | |
313 | self.addProfileSelector(nProfiles) |
|
336 | self.addProfileSelector(nProfiles) | |
314 |
|
337 | |||
315 | profileSelectorObj = self.profileSelectorList[self.profSelectorIndex] |
|
338 | profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex] | |
316 |
|
339 | |||
317 | if profileSelectorObj.isProfileInRange(minIndex, maxIndex): |
|
340 | if profileSelectorObj.isProfileInRange(minIndex, maxIndex): | |
318 |
self. |
|
341 | self.dataOutObj.flagNoData = False | |
319 | self.profSelectorIndex += 1 |
|
342 | self.profSelectorObjIndex += 1 | |
320 | return 1 |
|
343 | return 1 | |
321 |
|
344 | |||
322 |
self. |
|
345 | self.dataOutObj.flagNoData = True | |
323 | self.profSelectorIndex += 1 |
|
346 | self.profSelectorObjIndex += 1 | |
324 |
|
347 | |||
325 | return 0 |
|
348 | return 0 | |
326 |
|
349 | |||
327 | def selectNtxs(self, ntx): |
|
350 | def selectNtxs(self, ntx): | |
328 | pass |
|
351 | pass | |
329 |
|
352 | |||
330 |
|
353 | |||
331 | class Decoder: |
|
354 | class Decoder: | |
|
355 | ||||
|
356 | data = None | |||
|
357 | profCounter = 1 | |||
|
358 | nCode = ncode | |||
|
359 | nBaud = nbaud | |||
|
360 | codeIndex = 0 | |||
|
361 | code = code #this is a List | |||
|
362 | fft_code = None | |||
|
363 | flag = False | |||
|
364 | setCodeFft = False | |||
332 |
|
365 | |||
333 | def __init__(self,code, ncode, nbaud): |
|
366 | def __init__(self,code, ncode, nbaud): | |
334 |
|
367 | |||
335 |
self. |
|
368 | self.data = None | |
336 | self.profCounter = 1 |
|
369 | self.profCounter = 1 | |
337 | self.nCode = ncode |
|
370 | self.nCode = ncode | |
338 | self.nBaud = nbaud |
|
371 | self.nBaud = nbaud | |
339 | self.codeIndex = 0 |
|
372 | self.codeIndex = 0 | |
340 | self.code = code #this is a List |
|
373 | self.code = code #this is a List | |
341 | self.fft_code = None |
|
374 | self.fft_code = None | |
342 | self.flag = False |
|
375 | self.flag = False | |
343 | self.setCodeFft = False |
|
376 | self.setCodeFft = False | |
344 |
|
377 | |||
345 | def exe(self, data, ndata=None, type = 0): |
|
378 | def exe(self, data, ndata=None, type = 0): | |
346 |
|
379 | |||
347 | if ndata == None: ndata = data.shape[1] |
|
380 | if ndata == None: ndata = data.shape[1] | |
348 |
|
381 | |||
349 | if type == 0: |
|
382 | if type == 0: | |
350 | self.convolutionInFreq(data,ndata) |
|
383 | self.convolutionInFreq(data,ndata) | |
351 |
|
384 | |||
352 | if type == 1: |
|
385 | if type == 1: | |
353 | self.convolutionInTime(data, ndata) |
|
386 | self.convolutionInTime(data, ndata) | |
354 |
|
387 | |||
355 | def convolutionInFreq(self,data, ndata): |
|
388 | def convolutionInFreq(self,data, ndata): | |
356 |
|
389 | |||
357 | newcode = numpy.zeros(ndata) |
|
390 | newcode = numpy.zeros(ndata) | |
358 | newcode[0:self.nBaud] = self.code[self.codeIndex] |
|
391 | newcode[0:self.nBaud] = self.code[self.codeIndex] | |
359 |
|
392 | |||
360 | self.codeIndex += 1 |
|
393 | self.codeIndex += 1 | |
361 |
|
394 | |||
362 | fft_data = numpy.fft.fft(data, axis=1) |
|
395 | fft_data = numpy.fft.fft(data, axis=1) | |
363 | fft_code = numpy.conj(numpy.fft.fft(newcode)) |
|
396 | fft_code = numpy.conj(numpy.fft.fft(newcode)) | |
364 | fft_code = fft_code.reshape(1,len(fft_code)) |
|
397 | fft_code = fft_code.reshape(1,len(fft_code)) | |
365 |
|
398 | |||
366 | conv = fft_data.copy() |
|
399 | conv = fft_data.copy() | |
367 | conv.fill(0) |
|
400 | conv.fill(0) | |
368 |
|
401 | |||
369 | conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays |
|
402 | conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays | |
370 | # for i in range(ndata): |
|
403 | # for i in range(ndata): | |
371 | # conv[i,:] = fft_data[i,:]*fft_code[i] |
|
404 | # conv[i,:] = fft_data[i,:]*fft_code[i] | |
372 |
|
405 | |||
373 | self.data = numpy.fft.ifft(conv,axis=1) |
|
406 | self.data = numpy.fft.ifft(conv,axis=1) | |
374 | self.flag = True |
|
407 | self.flag = True | |
375 |
|
408 | |||
376 | if self.profCounter == self.nCode: |
|
409 | if self.profCounter == self.nCode: | |
377 | self.profCounter = 0 |
|
410 | self.profCounter = 0 | |
378 | self.codeIndex = 0 |
|
411 | self.codeIndex = 0 | |
379 |
|
412 | |||
380 | self.profCounter += 1 |
|
413 | self.profCounter += 1 | |
381 |
|
414 | |||
382 | def convolutionInTime(self, data, ndata): |
|
415 | def convolutionInTime(self, data, ndata): | |
383 |
|
416 | |||
384 | nchannel = data.shape[1] |
|
417 | nchannel = data.shape[1] | |
385 | newcode = self.code[self.codeIndex] |
|
418 | newcode = self.code[self.codeIndex] | |
386 | self.codeIndex += 1 |
|
419 | self.codeIndex += 1 | |
387 | conv = data.copy() |
|
420 | conv = data.copy() | |
388 | for i in range(nchannel): |
|
421 | for i in range(nchannel): | |
389 | conv[i,:] = numpy.correlate(data[i,:], newcode, 'same') |
|
422 | conv[i,:] = numpy.correlate(data[i,:], newcode, 'same') | |
390 |
|
423 | |||
391 | self.data = conv |
|
424 | self.data = conv | |
392 | self.flag = True |
|
425 | self.flag = True | |
393 |
|
426 | |||
394 | if self.profCounter == self.nCode: |
|
427 | if self.profCounter == self.nCode: | |
395 | self.profCounter = 0 |
|
428 | self.profCounter = 0 | |
396 | self.codeIndex = 0 |
|
429 | self.codeIndex = 0 | |
397 |
|
430 | |||
398 | self.profCounter += 1 |
|
431 | self.profCounter += 1 | |
399 |
|
432 | |||
400 |
|
433 | |||
401 | class CoherentIntegrator: |
|
434 | class CoherentIntegrator: | |
402 |
|
435 | |||
|
436 | profCounter = 1 | |||
|
437 | data = None | |||
|
438 | buffer = None | |||
|
439 | flag = False | |||
|
440 | nCohInt = N | |||
|
441 | ||||
403 | def __init__(self, N): |
|
442 | def __init__(self, N): | |
404 |
|
443 | |||
405 | self.profCounter = 1 |
|
444 | self.profCounter = 1 | |
406 | self.data = None |
|
445 | self.data = None | |
407 | self.buffer = None |
|
446 | self.buffer = None | |
408 | self.flag = False |
|
447 | self.flag = False | |
409 | self.nCohInt = N |
|
448 | self.nCohInt = N | |
410 |
|
449 | |||
411 | def exe(self, data): |
|
450 | def exe(self, data): | |
412 |
|
451 | |||
413 | if self.buffer == None: |
|
452 | if self.buffer == None: | |
414 | self.buffer = data |
|
453 | self.buffer = data | |
415 | else: |
|
454 | else: | |
416 | self.buffer = self.buffer + data |
|
455 | self.buffer = self.buffer + data | |
417 |
|
456 | |||
418 | if self.profCounter == self.nCohInt: |
|
457 | if self.profCounter == self.nCohInt: | |
419 | self.data = self.buffer |
|
458 | self.data = self.buffer | |
420 | self.buffer = None |
|
459 | self.buffer = None | |
421 | self.profCounter = 0 |
|
460 | self.profCounter = 0 | |
422 | self.flag = True |
|
461 | self.flag = True | |
423 | else: |
|
462 | else: | |
424 | self.flag = False |
|
463 | self.flag = False | |
425 |
|
464 | |||
426 | self.profCounter += 1 |
|
465 | self.profCounter += 1 | |
427 |
|
466 | |||
428 |
class ProfileSelector |
|
467 | class ProfileSelector: | |
429 |
|
468 | |||
430 | indexProfile = None |
|
469 | indexProfile = None | |
431 | # Tamanho total de los perfiles |
|
470 | # Tamanho total de los perfiles | |
432 | nProfiles = None |
|
471 | nProfiles = None | |
433 |
|
472 | |||
434 | def __init__(self, nProfiles): |
|
473 | def __init__(self, nProfiles): | |
435 |
|
474 | |||
436 | self.indexProfile = 0 |
|
475 | self.indexProfile = 0 | |
437 | self.nProfiles = nProfiles |
|
476 | self.nProfiles = nProfiles | |
438 |
|
477 | |||
439 | def isProfileInRange(self, minIndex, maxIndex): |
|
478 | def isProfileInRange(self, minIndex, maxIndex): | |
440 |
|
479 | |||
441 | if self.indexProfile < minIndex: |
|
480 | if self.indexProfile < minIndex: | |
442 | self.indexProfile += 1 |
|
481 | self.indexProfile += 1 | |
443 | return False |
|
482 | return False | |
444 |
|
483 | |||
445 | if self.indexProfile > maxIndex: |
|
484 | if self.indexProfile > maxIndex: | |
446 | self.indexProfile += 1 |
|
485 | self.indexProfile += 1 | |
447 | return False |
|
486 | return False | |
448 |
|
487 | |||
449 | self.indexProfile += 1 |
|
488 | self.indexProfile += 1 | |
450 |
|
489 | |||
451 | return True |
|
490 | return True | |
452 |
|
491 | |||
453 | def isProfileInList(self, profileList): |
|
492 | def isProfileInList(self, profileList): | |
454 |
|
493 | |||
455 | if self.indexProfile not in profileList: |
|
494 | if self.indexProfile not in profileList: | |
456 | self.indexProfile += 1 |
|
495 | self.indexProfile += 1 | |
457 | return False |
|
496 | return False | |
458 |
|
497 | |||
459 | self.indexProfile += 1 |
|
498 | self.indexProfile += 1 | |
460 |
|
499 | |||
461 | return True |
|
500 | return True | |
462 |
|
501 | |||
463 |
|
502 | |||
464 | No newline at end of file |
|
503 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now