@@ -1,965 +1,1010 | |||||
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 | import os |
|
8 | import os | |
9 | import numpy |
|
9 | import numpy | |
10 | import sys |
|
10 | import sys | |
11 | import time |
|
11 | import time | |
12 | import datetime |
|
12 | import datetime | |
13 | import time |
|
13 | import time | |
14 | import plplot |
|
14 | import plplot | |
15 |
|
15 | |||
16 |
|
16 | |||
17 | def cmap1_init(colormap="gray"): |
|
17 | def cmap1_init(colormap="gray"): | |
18 |
|
18 | |||
19 | if colormap == None: |
|
19 | if colormap == None: | |
20 | return |
|
20 | return | |
21 |
|
21 | |||
22 | ncolor = None |
|
22 | ncolor = None | |
23 | rgb_lvl = None |
|
23 | rgb_lvl = None | |
24 |
|
24 | |||
25 | # Routine for defining a specific color map 1 in HLS space. |
|
25 | # Routine for defining a specific color map 1 in HLS space. | |
26 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
26 | # if gray is true, use basic grayscale variation from half-dark to light. | |
27 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
27 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |
28 |
|
28 | |||
29 | # Independent variable of control points. |
|
29 | # Independent variable of control points. | |
30 | i = numpy.array((0., 1.)) |
|
30 | i = numpy.array((0., 1.)) | |
31 | if colormap=="gray": |
|
31 | if colormap=="gray": | |
32 | ncolor = 256 |
|
32 | ncolor = 256 | |
33 | # Hue for control points. Doesn't matter since saturation is zero. |
|
33 | # Hue for control points. Doesn't matter since saturation is zero. | |
34 | h = numpy.array((0., 0.)) |
|
34 | h = numpy.array((0., 0.)) | |
35 | # Lightness ranging from half-dark (for interest) to light. |
|
35 | # Lightness ranging from half-dark (for interest) to light. | |
36 | l = numpy.array((0.5, 1.)) |
|
36 | l = numpy.array((0.5, 1.)) | |
37 | # Gray scale has zero saturation |
|
37 | # Gray scale has zero saturation | |
38 | s = numpy.array((0., 0.)) |
|
38 | s = numpy.array((0., 0.)) | |
39 |
|
39 | |||
40 | # number of cmap1 colours is 256 in this case. |
|
40 | # number of cmap1 colours is 256 in this case. | |
41 | plplot.plscmap1n(ncolor) |
|
41 | plplot.plscmap1n(ncolor) | |
42 | # Interpolate between control points to set up cmap1. |
|
42 | # Interpolate between control points to set up cmap1. | |
43 | plplot.plscmap1l(0, i, h, l, s) |
|
43 | plplot.plscmap1l(0, i, h, l, s) | |
44 |
|
44 | |||
45 | return None |
|
45 | return None | |
46 |
|
46 | |||
47 | if colormap == 'jet': |
|
47 | if colormap == 'jet': | |
48 | ncolor = 256 |
|
48 | ncolor = 256 | |
49 | pos = numpy.zeros((ncolor)) |
|
49 | pos = numpy.zeros((ncolor)) | |
50 | r = numpy.zeros((ncolor)) |
|
50 | r = numpy.zeros((ncolor)) | |
51 | g = numpy.zeros((ncolor)) |
|
51 | g = numpy.zeros((ncolor)) | |
52 | b = numpy.zeros((ncolor)) |
|
52 | b = numpy.zeros((ncolor)) | |
53 |
|
53 | |||
54 | for i in range(ncolor): |
|
54 | for i in range(ncolor): | |
55 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 |
|
55 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 | |
56 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 |
|
56 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 | |
57 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 |
|
57 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 | |
58 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 |
|
58 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 | |
59 |
|
59 | |||
60 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 |
|
60 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 | |
61 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 |
|
61 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 | |
62 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 |
|
62 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 | |
63 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 |
|
63 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 | |
64 | else: gf = 0.0 |
|
64 | else: gf = 0.0 | |
65 |
|
65 | |||
66 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 |
|
66 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 | |
67 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 |
|
67 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 | |
68 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 |
|
68 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 | |
69 | else: bf = 0 |
|
69 | else: bf = 0 | |
70 |
|
70 | |||
71 | r[i] = rf |
|
71 | r[i] = rf | |
72 | g[i] = gf |
|
72 | g[i] = gf | |
73 | b[i] = bf |
|
73 | b[i] = bf | |
74 |
|
74 | |||
75 | pos[i] = float(i)/float(ncolor-1) |
|
75 | pos[i] = float(i)/float(ncolor-1) | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | plplot.plscmap1n(ncolor) |
|
78 | plplot.plscmap1n(ncolor) | |
79 | plplot.plscmap1l(1, pos, r, g, b) |
|
79 | plplot.plscmap1l(1, pos, r, g, b) | |
80 |
|
80 | |||
81 |
|
81 | |||
82 |
|
82 | |||
83 | if colormap=="br_green": |
|
83 | if colormap=="br_green": | |
84 | ncolor = 256 |
|
84 | ncolor = 256 | |
85 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
85 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
86 | h = numpy.array((240., 0.)) |
|
86 | h = numpy.array((240., 0.)) | |
87 | # Lightness and saturation are constant (values taken from C example). |
|
87 | # Lightness and saturation are constant (values taken from C example). | |
88 | l = numpy.array((0.6, 0.6)) |
|
88 | l = numpy.array((0.6, 0.6)) | |
89 | s = numpy.array((0.8, 0.8)) |
|
89 | s = numpy.array((0.8, 0.8)) | |
90 |
|
90 | |||
91 | # number of cmap1 colours is 256 in this case. |
|
91 | # number of cmap1 colours is 256 in this case. | |
92 | plplot.plscmap1n(ncolor) |
|
92 | plplot.plscmap1n(ncolor) | |
93 | # Interpolate between control points to set up cmap1. |
|
93 | # Interpolate between control points to set up cmap1. | |
94 | plplot.plscmap1l(0, i, h, l, s) |
|
94 | plplot.plscmap1l(0, i, h, l, s) | |
95 |
|
95 | |||
96 | return None |
|
96 | return None | |
97 |
|
97 | |||
98 | if colormap=="tricolor": |
|
98 | if colormap=="tricolor": | |
99 | ncolor = 3 |
|
99 | ncolor = 3 | |
100 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
100 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
101 | h = numpy.array((240., 0.)) |
|
101 | h = numpy.array((240., 0.)) | |
102 | # Lightness and saturation are constant (values taken from C example). |
|
102 | # Lightness and saturation are constant (values taken from C example). | |
103 | l = numpy.array((0.6, 0.6)) |
|
103 | l = numpy.array((0.6, 0.6)) | |
104 | s = numpy.array((0.8, 0.8)) |
|
104 | s = numpy.array((0.8, 0.8)) | |
105 |
|
105 | |||
106 | # number of cmap1 colours is 256 in this case. |
|
106 | # number of cmap1 colours is 256 in this case. | |
107 | plplot.plscmap1n(ncolor) |
|
107 | plplot.plscmap1n(ncolor) | |
108 | # Interpolate between control points to set up cmap1. |
|
108 | # Interpolate between control points to set up cmap1. | |
109 | plplot.plscmap1l(0, i, h, l, s) |
|
109 | plplot.plscmap1l(0, i, h, l, s) | |
110 |
|
110 | |||
111 | return None |
|
111 | return None | |
112 |
|
112 | |||
113 | if colormap == 'rgb' or colormap == 'rgb666': |
|
113 | if colormap == 'rgb' or colormap == 'rgb666': | |
114 |
|
114 | |||
115 | color_sz = 6 |
|
115 | color_sz = 6 | |
116 | ncolor = color_sz*color_sz*color_sz |
|
116 | ncolor = color_sz*color_sz*color_sz | |
117 | pos = numpy.zeros((ncolor)) |
|
117 | pos = numpy.zeros((ncolor)) | |
118 | r = numpy.zeros((ncolor)) |
|
118 | r = numpy.zeros((ncolor)) | |
119 | g = numpy.zeros((ncolor)) |
|
119 | g = numpy.zeros((ncolor)) | |
120 | b = numpy.zeros((ncolor)) |
|
120 | b = numpy.zeros((ncolor)) | |
121 | ind = 0 |
|
121 | ind = 0 | |
122 | for ri in range(color_sz): |
|
122 | for ri in range(color_sz): | |
123 | for gi in range(color_sz): |
|
123 | for gi in range(color_sz): | |
124 | for bi in range(color_sz): |
|
124 | for bi in range(color_sz): | |
125 | r[ind] = ri/(color_sz-1.0) |
|
125 | r[ind] = ri/(color_sz-1.0) | |
126 | g[ind] = gi/(color_sz-1.0) |
|
126 | g[ind] = gi/(color_sz-1.0) | |
127 | b[ind] = bi/(color_sz-1.0) |
|
127 | b[ind] = bi/(color_sz-1.0) | |
128 | pos[ind] = ind/(ncolor-1.0) |
|
128 | pos[ind] = ind/(ncolor-1.0) | |
129 | ind += 1 |
|
129 | ind += 1 | |
130 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
130 | rgb_lvl = [6,6,6] #Levels for RGB colors | |
131 |
|
131 | |||
132 | if colormap == 'rgb676': |
|
132 | if colormap == 'rgb676': | |
133 | ncolor = 6*7*6 |
|
133 | ncolor = 6*7*6 | |
134 | pos = numpy.zeros((ncolor)) |
|
134 | pos = numpy.zeros((ncolor)) | |
135 | r = numpy.zeros((ncolor)) |
|
135 | r = numpy.zeros((ncolor)) | |
136 | g = numpy.zeros((ncolor)) |
|
136 | g = numpy.zeros((ncolor)) | |
137 | b = numpy.zeros((ncolor)) |
|
137 | b = numpy.zeros((ncolor)) | |
138 | ind = 0 |
|
138 | ind = 0 | |
139 | for ri in range(8): |
|
139 | for ri in range(8): | |
140 | for gi in range(8): |
|
140 | for gi in range(8): | |
141 | for bi in range(4): |
|
141 | for bi in range(4): | |
142 | r[ind] = ri/(6-1.0) |
|
142 | r[ind] = ri/(6-1.0) | |
143 | g[ind] = gi/(7-1.0) |
|
143 | g[ind] = gi/(7-1.0) | |
144 | b[ind] = bi/(6-1.0) |
|
144 | b[ind] = bi/(6-1.0) | |
145 | pos[ind] = ind/(ncolor-1.0) |
|
145 | pos[ind] = ind/(ncolor-1.0) | |
146 | ind += 1 |
|
146 | ind += 1 | |
147 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
147 | rgb_lvl = [6,7,6] #Levels for RGB colors | |
148 |
|
148 | |||
149 | if colormap == 'rgb685': |
|
149 | if colormap == 'rgb685': | |
150 | ncolor = 6*8*5 |
|
150 | ncolor = 6*8*5 | |
151 | pos = numpy.zeros((ncolor)) |
|
151 | pos = numpy.zeros((ncolor)) | |
152 | r = numpy.zeros((ncolor)) |
|
152 | r = numpy.zeros((ncolor)) | |
153 | g = numpy.zeros((ncolor)) |
|
153 | g = numpy.zeros((ncolor)) | |
154 | b = numpy.zeros((ncolor)) |
|
154 | b = numpy.zeros((ncolor)) | |
155 | ind = 0 |
|
155 | ind = 0 | |
156 | for ri in range(8): |
|
156 | for ri in range(8): | |
157 | for gi in range(8): |
|
157 | for gi in range(8): | |
158 | for bi in range(4): |
|
158 | for bi in range(4): | |
159 | r[ind] = ri/(6-1.0) |
|
159 | r[ind] = ri/(6-1.0) | |
160 | g[ind] = gi/(8-1.0) |
|
160 | g[ind] = gi/(8-1.0) | |
161 | b[ind] = bi/(5-1.0) |
|
161 | b[ind] = bi/(5-1.0) | |
162 | pos[ind] = ind/(ncolor-1.0) |
|
162 | pos[ind] = ind/(ncolor-1.0) | |
163 | ind += 1 |
|
163 | ind += 1 | |
164 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
164 | rgb_lvl = [6,8,5] #Levels for RGB colors | |
165 |
|
165 | |||
166 | if colormap == 'rgb884': |
|
166 | if colormap == 'rgb884': | |
167 | ncolor = 8*8*4 |
|
167 | ncolor = 8*8*4 | |
168 | pos = numpy.zeros((ncolor)) |
|
168 | pos = numpy.zeros((ncolor)) | |
169 | r = numpy.zeros((ncolor)) |
|
169 | r = numpy.zeros((ncolor)) | |
170 | g = numpy.zeros((ncolor)) |
|
170 | g = numpy.zeros((ncolor)) | |
171 | b = numpy.zeros((ncolor)) |
|
171 | b = numpy.zeros((ncolor)) | |
172 | ind = 0 |
|
172 | ind = 0 | |
173 | for ri in range(8): |
|
173 | for ri in range(8): | |
174 | for gi in range(8): |
|
174 | for gi in range(8): | |
175 | for bi in range(4): |
|
175 | for bi in range(4): | |
176 | r[ind] = ri/(8-1.0) |
|
176 | r[ind] = ri/(8-1.0) | |
177 | g[ind] = gi/(8-1.0) |
|
177 | g[ind] = gi/(8-1.0) | |
178 | b[ind] = bi/(4-1.0) |
|
178 | b[ind] = bi/(4-1.0) | |
179 | pos[ind] = ind/(ncolor-1.0) |
|
179 | pos[ind] = ind/(ncolor-1.0) | |
180 | ind += 1 |
|
180 | ind += 1 | |
181 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
181 | rgb_lvl = [8,8,4] #Levels for RGB colors | |
182 |
|
182 | |||
183 | if ncolor == None: |
|
183 | if ncolor == None: | |
184 | raise ValueError, "The colormap selected is not valid" |
|
184 | raise ValueError, "The colormap selected is not valid" | |
185 |
|
185 | |||
186 | plplot.plscmap1n(ncolor) |
|
186 | plplot.plscmap1n(ncolor) | |
187 | plplot.plscmap1l(1, pos, r, g, b) |
|
187 | plplot.plscmap1l(1, pos, r, g, b) | |
188 |
|
188 | |||
189 | return rgb_lvl |
|
189 | return rgb_lvl | |
190 |
|
190 | |||
191 | def setColormap(colormap="jet"): |
|
191 | def setColormap(colormap="jet"): | |
192 | cmap1_init(colormap) |
|
192 | cmap1_init(colormap) | |
193 |
|
193 | |||
194 | def savePlplot(filename,width,height): |
|
194 | def savePlplot(filename,width,height): | |
195 | curr_strm = plplot.plgstrm() |
|
195 | curr_strm = plplot.plgstrm() | |
196 | save_strm = plplot.plmkstrm() |
|
196 | save_strm = plplot.plmkstrm() | |
197 | plplot.plsetopt("geometry", "%dx%d"%(width,height)) |
|
197 | plplot.plsetopt("geometry", "%dx%d"%(width,height)) | |
198 | plplot.plsdev("png") |
|
198 | plplot.plsdev("png") | |
199 | plplot.plsfnam(filename) |
|
199 | plplot.plsfnam(filename) | |
200 | plplot.plcpstrm(curr_strm,0) |
|
200 | plplot.plcpstrm(curr_strm,0) | |
201 | plplot.plreplot() |
|
201 | plplot.plreplot() | |
202 | plplot.plclear() |
|
|||
203 | plplot.plend1() |
|
202 | plplot.plend1() | |
204 | plplot.plsstrm(curr_strm) |
|
203 | plplot.plsstrm(curr_strm) | |
205 |
|
204 | |||
206 |
|
205 | |||
207 | def initPlplot(indexPlot,ncol,nrow,winTitle,width,height): |
|
206 | def initPlplot(indexPlot,ncol,nrow,winTitle,width,height): | |
208 | plplot.plsstrm(indexPlot) |
|
207 | plplot.plsstrm(indexPlot) | |
209 | plplot.plparseopts([winTitle],plplot.PL_PARSE_FULL) |
|
208 | plplot.plparseopts([winTitle],plplot.PL_PARSE_FULL) | |
210 | plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow)) |
|
209 | plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow)) | |
211 | plplot.plsdev("xwin") |
|
210 | plplot.plsdev("xwin") | |
212 | plplot.plscolbg(255,255,255) |
|
211 | plplot.plscolbg(255,255,255) | |
213 | plplot.plscol0(1,0,0,0) |
|
212 | plplot.plscol0(1,0,0,0) | |
214 | plplot.plinit() |
|
213 | plplot.plinit() | |
215 | plplot.plspause(False) |
|
214 | plplot.plspause(False) | |
216 | plplot.plssub(ncol,nrow) |
|
215 | plplot.plssub(ncol,nrow) | |
217 |
|
216 | |||
|
217 | def setNewPage(): | |||
|
218 | plplot.plbop() | |||
|
219 | plplot.pladv(0) | |||
|
220 | ||||
|
221 | def closePage(): | |||
|
222 | plplot.pleop() | |||
|
223 | ||||
218 | def clearData(objGraph): |
|
224 | def clearData(objGraph): | |
219 | objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc") |
|
225 | objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc") | |
220 |
|
226 | |||
221 | objGraph.setColor(15) #Setting Line Color to White |
|
227 | objGraph.setColor(15) #Setting Line Color to White | |
222 |
|
228 | |||
223 | if objGraph.datatype == "complex": |
|
229 | if objGraph.datatype == "complex": | |
224 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real) |
|
230 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real) | |
225 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag) |
|
231 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag) | |
226 |
|
232 | |||
227 | if objGraph.datatype == "real": |
|
233 | if objGraph.datatype == "real": | |
228 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata) |
|
234 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata) | |
229 |
|
235 | |||
230 | objGraph.setColor(1) #Setting Line Color to Black |
|
236 | objGraph.setColor(1) #Setting Line Color to Black | |
231 | # objGraph.setLineStyle(2) |
|
237 | # objGraph.setLineStyle(2) | |
232 | # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bcntg", "bc") |
|
238 | # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bcntg", "bc") | |
233 | # objGraph.setLineStyle(1) |
|
239 | # objGraph.setLineStyle(1) | |
234 |
|
240 | |||
235 | def setStrm(indexPlot): |
|
241 | def setStrm(indexPlot): | |
236 | plplot.plsstrm(indexPlot) |
|
242 | plplot.plsstrm(indexPlot) | |
237 |
|
243 | |||
238 | def plFlush(): |
|
244 | def plFlush(): | |
239 | plplot.plflush() |
|
245 | plplot.plflush() | |
240 |
|
246 | |||
241 | def setPlTitle(pltitle,color): |
|
247 | def setPlTitle(pltitle,color, szchar=0.7): | |
242 | setSubpages(1, 0) |
|
248 | setSubpages(1, 0) | |
243 | plplot.pladv(0) |
|
249 | plplot.pladv(0) | |
244 | plplot.plvpor(0., 1., 0., 1.) |
|
250 | plplot.plvpor(0., 1., 0., 1.) | |
245 |
|
251 | |||
246 | if color == "black": |
|
252 | if color == "black": | |
247 | plplot.plcol0(1) |
|
253 | plplot.plcol0(1) | |
248 | if color == "white": |
|
254 | if color == "white": | |
249 | plplot.plcol0(15) |
|
255 | plplot.plcol0(15) | |
250 |
|
256 | |||
|
257 | plplot.plschr(0.0,szchar) | |||
251 | plplot.plmtex("t",-1., 0.5, 0.5, pltitle) |
|
258 | plplot.plmtex("t",-1., 0.5, 0.5, pltitle) | |
252 |
|
259 | |||
253 | def setSubpages(ncol,nrow): |
|
260 | def setSubpages(ncol,nrow): | |
254 | plplot.plssub(ncol,nrow) |
|
261 | plplot.plssub(ncol,nrow) | |
255 |
|
262 | |||
256 | class BaseGraph: |
|
263 | class BaseGraph: | |
|
264 | ||||
257 | __name = None |
|
265 | __name = None | |
258 | __xpos = None |
|
266 | __xpos = None | |
259 | __ypos = None |
|
267 | __ypos = None | |
260 | __subplot = None |
|
268 | __subplot = None | |
261 | __xg = None |
|
269 | __xg = None | |
262 | __yg = None |
|
270 | __yg = None | |
263 | xdata = None |
|
271 | xdata = None | |
264 | ydata = None |
|
272 | ydata = None | |
265 | getGrid = True |
|
273 | getGrid = True | |
266 | xaxisIsTime = False |
|
274 | xaxisIsTime = False | |
267 | deltax = None |
|
275 | deltax = None | |
268 | xmin = None |
|
276 | xmin = None | |
269 | xmax = None |
|
277 | xmax = None | |
|
278 | ||||
270 | def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0): |
|
279 | def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0): | |
|
280 | ||||
271 | self.setName(name) |
|
281 | self.setName(name) | |
272 | self.setScreenPos(xpos, ypos) |
|
282 | self.setScreenPos(xpos, ypos) | |
273 | self.setLabels(xlabel,ylabel,title) |
|
283 | self.setLabels(xlabel,ylabel,title) | |
274 | self.setSubPlot(subplot) |
|
284 | self.setSubPlot(subplot) | |
275 | self.setSizeOfChar(szchar) |
|
285 | self.setSizeOfChar(szchar) | |
276 | self.setXYZrange(xrange,yrange,zrange) |
|
286 | self.setXYZrange(xrange,yrange,zrange) | |
277 | self.getGrid = True |
|
287 | self.getGrid = True | |
278 | self.xaxisIsTime = False |
|
288 | self.xaxisIsTime = False | |
279 | self.deltax = deltax |
|
289 | self.deltax = deltax | |
280 |
|
290 | |||
281 | def setXYZrange(self,xrange,yrange,zrange): |
|
291 | def setXYZrange(self,xrange,yrange,zrange): | |
282 | self.xrange = xrange |
|
292 | self.xrange = xrange | |
283 | self.yrange = yrange |
|
293 | self.yrange = yrange | |
284 | self.zrange = zrange |
|
294 | self.zrange = zrange | |
285 |
|
295 | |||
286 | def setName(self, name): |
|
296 | def setName(self, name): | |
287 | self.__name = name |
|
297 | self.__name = name | |
288 |
|
298 | |||
289 | def setScreenPos(self,xpos,ypos): |
|
299 | def setScreenPos(self,xpos,ypos): | |
290 | self.__xpos = xpos |
|
300 | self.__xpos = xpos | |
291 | self.__ypos = ypos |
|
301 | self.__ypos = ypos | |
292 |
|
302 | |||
293 | def setXYData(self,xdata=None,ydata=None,datatype="real"): |
|
303 | def setXYData(self,xdata=None,ydata=None,datatype="real"): | |
294 | if((xdata != None) and (ydata != None)): |
|
304 | if((xdata != None) and (ydata != None)): | |
295 | self.xdata = xdata |
|
305 | self.xdata = xdata | |
296 | self.ydata = ydata |
|
306 | self.ydata = ydata | |
297 | self.datatype = datatype |
|
307 | self.datatype = datatype | |
298 |
|
308 | |||
299 | if((self.xdata == None) and (self.ydata == None)): |
|
309 | if((self.xdata == None) and (self.ydata == None)): | |
300 | return None |
|
310 | return None | |
301 |
|
311 | |||
302 | return 1 |
|
312 | return 1 | |
303 |
|
313 | |||
304 |
|
314 | |||
305 | def setLabels(self,xlabel=None,ylabel=None,title=None): |
|
315 | def setLabels(self,xlabel=None,ylabel=None,title=None): | |
306 | if xlabel != None: self.xlabel = xlabel |
|
316 | if xlabel != None: self.xlabel = xlabel | |
307 | if ylabel != None: self.ylabel = ylabel |
|
317 | if ylabel != None: self.ylabel = ylabel | |
308 | if title != None: self.title = title |
|
318 | if title != None: self.title = title | |
309 |
|
319 | |||
310 | def setSubPlot(self,subplot): |
|
320 | def setSubPlot(self,subplot): | |
311 | self.__subplot = subplot |
|
321 | self.__subplot = subplot | |
312 |
|
322 | |||
313 | def setSizeOfChar(self,szchar): |
|
323 | def setSizeOfChar(self,szchar): | |
314 | self.__szchar = szchar |
|
324 | self.__szchar = szchar | |
315 |
|
325 | |||
316 | def setLineStyle(self,style): |
|
326 | def setLineStyle(self,style): | |
317 | plplot.pllsty(style) |
|
327 | plplot.pllsty(style) | |
318 |
|
328 | |||
319 | def setColor(self,color): |
|
329 | def setColor(self,color): | |
320 | plplot.plcol0(color) |
|
330 | plplot.plcol0(color) | |
321 |
|
331 | |||
322 | def setXAxisAsTime(self,value=False): |
|
332 | def setXAxisAsTime(self,value=False): | |
323 | self.xaxisIsTime = value |
|
333 | self.xaxisIsTime = value | |
324 |
|
334 | |||
325 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
335 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): | |
326 |
|
336 | |||
327 | if xmin == None: xmin = x[0] |
|
337 | if xmin == None: xmin = x[0] | |
328 | if xmax == None: xmax = x[-1] |
|
338 | if xmax == None: xmax = x[-1] | |
329 | if ymin == None: ymin = y[0] |
|
339 | if ymin == None: ymin = y[0] | |
330 | if ymax == None: ymax = y[-1] |
|
340 | if ymax == None: ymax = y[-1] | |
331 |
|
341 | |||
332 | plplot.plcol0(colline) |
|
342 | plplot.plcol0(colline) | |
333 | plplot.plline(x, y) |
|
343 | plplot.plline(x, y) | |
334 | plplot.plcol0(1) |
|
344 | plplot.plcol0(1) | |
335 |
|
345 | |||
336 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): |
|
346 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): | |
337 |
|
347 | |||
338 | if xmin == None: xmin = x[0] |
|
348 | if xmin == None: xmin = x[0] | |
339 | if xmax == None: xmax = x[-1] |
|
349 | if xmax == None: xmax = x[-1] | |
340 | if ymin == None: ymin = y[0] |
|
350 | if ymin == None: ymin = y[0] | |
341 | if ymax == None: ymax = y[-1] |
|
351 | if ymax == None: ymax = y[-1] | |
342 |
|
352 | |||
343 | plplot.plline(x, y) |
|
353 | plplot.plline(x, y) | |
344 |
|
354 | |||
345 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
355 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
346 | """ |
|
356 | """ | |
347 | """ |
|
357 | """ | |
348 | if xmin == None: xmin = x[0] |
|
358 | if xmin == None: xmin = x[0] | |
349 | if xmax == None: xmax = x[-1] |
|
359 | if xmax == None: xmax = x[-1] | |
350 | if ymin == None: ymin = y[0] |
|
360 | if ymin == None: ymin = y[0] | |
351 | if ymax == None: ymax = y[-1] |
|
361 | if ymax == None: ymax = y[-1] | |
352 | if zmin == None: zmin = numpy.nanmin(data) |
|
362 | if zmin == None: zmin = numpy.nanmin(data) | |
353 | if zmax == None: zmax = numpy.nanmax(data) |
|
363 | if zmax == None: zmax = numpy.nanmax(data) | |
354 |
|
364 | |||
355 | plplot.plimage(data, |
|
365 | plplot.plimage(data, | |
356 | float(x[0]), |
|
366 | float(x[0]), | |
357 | float(x[-1]), |
|
367 | float(x[-1]), | |
358 | float(y[0]), |
|
368 | float(y[0]), | |
359 | float(y[-1]), |
|
369 | float(y[-1]), | |
360 | float(zmin), |
|
370 | float(zmin), | |
361 | float(zmax), |
|
371 | float(zmax), | |
362 | float(xmin), |
|
372 | float(xmin), | |
363 | float(xmax), |
|
373 | float(xmax), | |
364 | float(ymin), |
|
374 | float(ymin), | |
365 | float(ymax) |
|
375 | float(ymax) | |
366 | ) |
|
376 | ) | |
367 |
|
377 | |||
368 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
378 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): | |
369 |
|
379 | |||
370 | if not(len(x)>0 and len(y)>0): |
|
380 | if not(len(x)>0 and len(y)>0): | |
371 | raise ValueError, "x axis and y axis are empty" |
|
381 | raise ValueError, "x axis and y axis are empty" | |
372 |
|
382 | |||
373 | if deltax == None: deltax = x[-1] - x[-2] |
|
383 | if deltax == None: deltax = x[-1] - x[-2] | |
374 | if deltay == None: deltay = y[-1] - y[-2] |
|
384 | if deltay == None: deltay = y[-1] - y[-2] | |
375 |
|
385 | |||
376 | x1 = numpy.append(x, x[-1] + deltax) |
|
386 | x1 = numpy.append(x, x[-1] + deltax) | |
377 | y1 = numpy.append(y, y[-1] + deltay) |
|
387 | y1 = numpy.append(y, y[-1] + deltay) | |
378 |
|
388 | |||
379 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
389 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |
380 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
390 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |
381 |
|
391 | |||
382 | self.__xg = xg |
|
392 | self.__xg = xg | |
383 | self.__yg = yg |
|
393 | self.__yg = yg | |
384 |
|
394 | |||
385 | return xg, yg |
|
395 | return xg, yg | |
386 |
|
396 | |||
387 |
|
397 | |||
388 | def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True): |
|
398 | def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True): | |
389 | if getGrid: |
|
399 | if getGrid: | |
390 | xg, yg = self.__getBoxpltr(x, y, deltax, deltay) |
|
400 | xg, yg = self.__getBoxpltr(x, y, deltax, deltay) | |
391 | else: |
|
401 | else: | |
392 | xg = self.__xg |
|
402 | xg = self.__xg | |
393 | yg = self.__yg |
|
403 | yg = self.__yg | |
394 |
|
404 | |||
395 | plplot.plimagefr(data, |
|
405 | plplot.plimagefr(data, | |
396 | float(xmin), |
|
406 | float(xmin), | |
397 | float(xmax), |
|
407 | float(xmax), | |
398 | float(ymin), |
|
408 | float(ymin), | |
399 | float(ymax), |
|
409 | float(ymax), | |
400 | 0., |
|
410 | 0., | |
401 | 0., |
|
411 | 0., | |
402 | float(zmin), |
|
412 | float(zmin), | |
403 | float(zmax), |
|
413 | float(zmax), | |
404 | plplot.pltr2, |
|
414 | plplot.pltr2, | |
405 | xg, |
|
415 | xg, | |
406 | yg) |
|
416 | yg) | |
407 |
|
417 | |||
408 |
|
418 | |||
409 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): |
|
419 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): | |
410 | data = numpy.arange(256) |
|
420 | data = numpy.arange(256) | |
411 | data = numpy.reshape(data, (1,-1)) |
|
421 | data = numpy.reshape(data, (1,-1)) | |
412 |
|
422 | |||
413 | plplot.plimage(data, |
|
423 | plplot.plimage(data, | |
414 | float(xmin), |
|
424 | float(xmin), | |
415 | float(xmax), |
|
425 | float(xmax), | |
416 | float(ymin), |
|
426 | float(ymin), | |
417 | float(ymax), |
|
427 | float(ymax), | |
418 | 0., |
|
428 | 0., | |
419 | 255., |
|
429 | 255., | |
420 | float(xmin), |
|
430 | float(xmin), | |
421 | float(xmax), |
|
431 | float(xmax), | |
422 | float(ymin), |
|
432 | float(ymin), | |
423 | float(ymax)) |
|
433 | float(ymax)) | |
424 |
|
434 | |||
425 | def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False): |
|
435 | def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False): | |
426 |
|
436 | |||
427 | plplot.plschr(0.0,self.__szchar-0.05) |
|
437 | plplot.plschr(0.0,self.__szchar-0.05) | |
428 | plplot.pladv(self.__subplot) |
|
438 | plplot.pladv(self.__subplot) | |
429 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) |
|
439 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |
430 | plplot.plwind(float(xmin), # self.xrange[0] |
|
440 | plplot.plwind(float(xmin), # self.xrange[0] | |
431 | float(xmax), # self.xrange[1] |
|
441 | float(xmax), # self.xrange[1] | |
432 | float(ymin), # self.yrange[0] |
|
442 | float(ymin), # self.yrange[0] | |
433 | float(ymax) # self.yrange[1] |
|
443 | float(ymax) # self.yrange[1] | |
434 | ) |
|
444 | ) | |
435 |
|
445 | |||
436 |
|
446 | |||
437 |
|
447 | |||
438 | if self.xaxisIsTime: |
|
448 | if self.xaxisIsTime: | |
439 | plplot.pltimefmt("%H:%M") |
|
449 | plplot.pltimefmt("%H:%M") | |
440 | timedelta = (xmax - xmin + 1)/8. |
|
450 | timedelta = (xmax - xmin + 1)/8. | |
441 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) |
|
451 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) | |
442 | else: |
|
452 | else: | |
443 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
453 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | |
444 |
|
454 | |||
445 |
|
455 | |||
446 | if not(nolabels): |
|
456 | if not(nolabels): | |
447 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
457 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |
448 |
|
458 | |||
449 |
|
459 | |||
450 | def delLabels(self): |
|
460 | def delLabels(self): | |
451 | self.setColor(15) #Setting Line Color to White |
|
461 | self.setColor(15) #Setting Line Color to White | |
452 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
462 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |
453 | self.setColor(1) #Setting Line Color to Black |
|
463 | self.setColor(1) #Setting Line Color to Black | |
454 |
|
464 | |||
455 |
|
465 | |||
456 |
|
466 | |||
457 | def plotImage(self,x,y,z,xrange,yrange,zrange): |
|
467 | def plotImage(self,x,y,z,xrange,yrange,zrange): | |
458 | xi = x[0] |
|
468 | xi = x[0] | |
459 | xf = x[-1] |
|
469 | xf = x[-1] | |
460 | yi = y[0] |
|
470 | yi = y[0] | |
461 | yf = y[-1] |
|
471 | yf = y[-1] | |
462 |
|
472 | |||
463 | plplot.plimage(z, |
|
473 | plplot.plimage(z, | |
464 | float(xi), |
|
474 | float(xi), | |
465 | float(xf), |
|
475 | float(xf), | |
466 | float(yi), |
|
476 | float(yi), | |
467 | float(yf), |
|
477 | float(yf), | |
468 | float(zrange[0]), |
|
478 | float(zrange[0]), | |
469 | float(zrange[1]), |
|
479 | float(zrange[1]), | |
470 | float(xi), |
|
480 | float(xi), | |
471 | float(xf), |
|
481 | float(xf), | |
472 | float(yrange[0]), |
|
482 | float(yrange[0]), | |
473 | yrange[1]) |
|
483 | yrange[1]) | |
474 |
|
484 | |||
475 | class LinearPlot: |
|
485 | class LinearPlot: | |
476 | linearObjDic = {} |
|
486 | linearObjDic = {} | |
477 | __xpos = None |
|
487 | __xpos = None | |
478 | __ypos = None |
|
488 | __ypos = None | |
479 | def __init__(self,indexPlot,nsubplot,winTitle): |
|
489 | def __init__(self,indexPlot,nsubplot,winTitle): | |
480 | self.width = 700 |
|
490 | self.width = 700 | |
481 | self.height = 150 |
|
491 | self.height = 150 | |
482 | ncol = 1 |
|
492 | ncol = 1 | |
483 | nrow = nsubplot |
|
493 | nrow = nsubplot | |
484 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) |
|
494 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) | |
485 |
|
495 | |||
486 |
|
496 | |||
487 | def setFigure(self,indexPlot): |
|
497 | def setFigure(self,indexPlot): | |
488 | setStrm(indexPlot) |
|
498 | setStrm(indexPlot) | |
489 |
|
499 | |||
490 | def setPosition(self): |
|
500 | def setPosition(self): | |
491 |
|
501 | |||
492 | xi = 0.07; xf = 0.9 #0.8,0.7,0.5 |
|
502 | xi = 0.07; xf = 0.9 #0.8,0.7,0.5 | |
493 | yi = 0.15; yf = 0.8 |
|
503 | yi = 0.15; yf = 0.8 | |
494 |
|
504 | |||
495 | xpos = [xi,xf] |
|
505 | xpos = [xi,xf] | |
496 | ypos = [yi,yf] |
|
506 | ypos = [yi,yf] | |
497 |
|
507 | |||
498 | self.__xpos = xpos |
|
508 | self.__xpos = xpos | |
499 | self.__ypos = ypos |
|
509 | self.__ypos = ypos | |
500 |
|
510 | |||
501 | return xpos,ypos |
|
511 | return xpos,ypos | |
502 |
|
512 | |||
503 | def refresh(self): |
|
513 | def refresh(self): | |
504 | plFlush() |
|
514 | plFlush() | |
505 |
|
515 | |||
506 | def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel): |
|
516 | def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel): | |
507 | szchar = 1.10 |
|
517 | szchar = 1.10 | |
508 | name = "linear" |
|
518 | name = "linear" | |
509 | key = name + "%d"%subplot |
|
519 | key = name + "%d"%subplot | |
510 | xrange = [xmin,xmax] |
|
520 | xrange = [xmin,xmax] | |
511 | yrange = [ymin,ymax] |
|
521 | yrange = [ymin,ymax] | |
512 |
|
522 | |||
513 | xpos,ypos = self.setPosition() |
|
523 | xpos,ypos = self.setPosition() | |
514 | linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange) |
|
524 | linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange) | |
515 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcnst", "bcnstv") |
|
525 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcnst", "bcnstv") | |
516 | self.linearObjDic[key] = linearObj |
|
526 | self.linearObjDic[key] = linearObj | |
517 |
|
527 | |||
518 | def plot(self,subplot,x,y,type="power"): |
|
528 | def plot(self,subplot,x,y,type="power"): | |
519 | name = "linear" |
|
529 | name = "linear" | |
520 | key = name + "%d"%subplot |
|
530 | key = name + "%d"%subplot | |
521 |
|
531 | |||
522 | linearObj = self.linearObjDic[key] |
|
532 | linearObj = self.linearObjDic[key] | |
523 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") |
|
533 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") | |
524 |
|
534 | |||
525 | if linearObj.setXYData() != None: |
|
535 | if linearObj.setXYData() != None: | |
526 | clearData(linearObj) |
|
536 | clearData(linearObj) | |
527 |
|
537 | |||
528 | else: |
|
538 | else: | |
529 | if type.lower() == 'power': |
|
539 | if type.lower() == 'power': | |
530 | linearObj.setXYData(x,abs(y),"real") |
|
540 | linearObj.setXYData(x,abs(y),"real") | |
531 | if type.lower() == 'iq': |
|
541 | if type.lower() == 'iq': | |
532 | linearObj.setXYData(x,y,"complex") |
|
542 | linearObj.setXYData(x,y,"complex") | |
533 |
|
543 | |||
534 | if type.lower() == 'power': |
|
544 | if type.lower() == 'power': | |
535 | colline = 9 |
|
545 | colline = 9 | |
536 | linearObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) |
|
546 | linearObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) | |
537 | linearObj.setXYData(x,abs(y),"real") |
|
547 | linearObj.setXYData(x,abs(y),"real") | |
538 |
|
548 | |||
539 | if type.lower() == 'iq': |
|
549 | if type.lower() == 'iq': | |
540 | colline = 9 |
|
550 | colline = 9 | |
541 | linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline) |
|
551 | linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline) | |
542 | colline = 13 |
|
552 | colline = 13 | |
543 | linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline) |
|
553 | linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline) | |
544 |
|
554 | |||
545 | linearObj.setXYData(x,y,"complex") |
|
555 | linearObj.setXYData(x,y,"complex") | |
546 |
|
556 | |||
547 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") |
|
557 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst") | |
548 |
|
558 | |||
549 |
|
559 | |||
550 | # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bc", "bc") |
|
560 | # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bc", "bc") | |
551 | # linearObj.basicXYPlot(data,y) |
|
561 | # linearObj.basicXYPlot(data,y) | |
552 | # linearObj.setXYData(data,y) |
|
562 | # linearObj.setXYData(data,y) | |
553 |
|
563 | |||
554 |
|
564 | |||
555 |
|
565 | |||
556 |
class |
|
566 | class PcolorPlot: | |
557 | pcolorObjDic = {} |
|
567 | pcolorObjDic = {} | |
558 | colorbarObjDic = {} |
|
568 | colorbarObjDic = {} | |
559 | pwprofileObjDic = {} |
|
569 | pwprofileObjDic = {} | |
560 | showColorbar = None |
|
570 | showColorbar = None | |
561 | showPowerProfile = None |
|
571 | showPowerProfile = None | |
562 | XAxisAsTime = None |
|
572 | XAxisAsTime = None | |
563 | width = None |
|
573 | width = None | |
564 | height = None |
|
574 | height = None | |
565 | __spcxpos = None |
|
575 | __spcxpos = None | |
566 | __spcypos = None |
|
576 | __spcypos = None | |
567 | __cmapxpos = None |
|
577 | __cmapxpos = None | |
568 | __cmapypos = None |
|
578 | __cmapypos = None | |
569 | __profxpos = None |
|
579 | __profxpos = None | |
570 | __profypos = None |
|
580 | __profypos = None | |
571 | __lastTitle = None |
|
581 | __lastTitle = None | |
572 |
|
582 | |||
573 | def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
583 | def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): | |
574 | self.width = 460 |
|
584 | self.width = 460 | |
575 | self.height = 300 |
|
585 | self.height = 300 | |
576 | self.showColorbar = showColorbar |
|
586 | self.showColorbar = showColorbar | |
577 | self.showPowerProfile = showPowerProfile |
|
587 | self.showPowerProfile = showPowerProfile | |
578 | self.XAxisAsTime = XAxisAsTime |
|
588 | self.XAxisAsTime = XAxisAsTime | |
579 |
|
589 | |||
580 |
|
|
590 | ||
581 | if (nsubplot%2)==0: |
|
591 | ncol = int(numpy.sqrt(nsubplot)+0.9) | |
582 |
|
|
592 | nrow = int(nsubplot*1./ncol + 0.9) | |
583 | else: |
|
|||
584 | ncol = int(nsubplot)/nrow + 1 |
|
|||
585 |
|
593 | |||
586 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) |
|
594 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) | |
587 | setColormap(colormap) |
|
595 | setColormap(colormap) | |
588 | self.ncol = ncol |
|
596 | self.ncol = ncol | |
589 | self.nrow = nrow |
|
597 | self.nrow = nrow | |
590 |
|
598 | |||
591 | def setFigure(self,indexPlot): |
|
599 | def setFigure(self,indexPlot): | |
592 | setStrm(indexPlot) |
|
600 | setStrm(indexPlot) | |
593 |
|
601 | |||
594 | def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile |
|
602 | def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile | |
595 | if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075 |
|
603 | if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075 | |
596 | else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5 |
|
604 | else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5 | |
597 | yi = 0.15; yf = 0.80 |
|
605 | yi = 0.15; yf = 0.80 | |
598 |
|
606 | |||
599 | xpos = [xi,xf] |
|
607 | xpos = [xi,xf] | |
600 | ypos = [yi,yf] |
|
608 | ypos = [yi,yf] | |
601 |
|
609 | |||
602 | self.__spcxpos = xpos |
|
610 | self.__spcxpos = xpos | |
603 | self.__spcypos = ypos |
|
611 | self.__spcypos = ypos | |
604 |
|
612 | |||
605 | return xpos,ypos |
|
613 | return xpos,ypos | |
606 |
|
614 | |||
607 | def setColorbarScreenPos(self): |
|
615 | def setColorbarScreenPos(self): | |
608 |
|
616 | |||
609 | xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03 |
|
617 | xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03 | |
610 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
618 | yi = self.__spcypos[0]; yf = self.__spcypos[1] | |
611 |
|
619 | |||
612 | xpos = [xi,xf] |
|
620 | xpos = [xi,xf] | |
613 | ypos = [yi,yf] |
|
621 | ypos = [yi,yf] | |
614 |
|
622 | |||
615 | self.__cmapxpos = xpos |
|
623 | self.__cmapxpos = xpos | |
616 | self.__cmapypos = ypos |
|
624 | self.__cmapypos = ypos | |
617 |
|
625 | |||
618 | return xpos,ypos |
|
626 | return xpos,ypos | |
619 |
|
627 | |||
620 | def setPowerprofileScreenPos(self): |
|
628 | def setPowerprofileScreenPos(self): | |
621 |
|
629 | |||
622 | xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25 |
|
630 | xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25 | |
623 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
631 | yi = self.__spcypos[0]; yf = self.__spcypos[1] | |
624 |
|
632 | |||
625 | xpos = [xi,xf] |
|
633 | xpos = [xi,xf] | |
626 | ypos = [yi,yf] |
|
634 | ypos = [yi,yf] | |
627 |
|
635 | |||
628 | self.__profxpos = [xi,xf] |
|
636 | self.__profxpos = [xi,xf] | |
629 | self.__profypos = [yi,yf] |
|
637 | self.__profypos = [yi,yf] | |
630 |
|
638 | |||
631 | return xpos,ypos |
|
639 | return xpos,ypos | |
632 |
|
640 | |||
633 |
def |
|
641 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel): | |
|
642 | """ | |||
|
643 | Crea los objetos necesarios para un subplot | |||
|
644 | """ | |||
|
645 | ||||
634 | # Config Spectra plot |
|
646 | # Config Spectra plot | |
|
647 | ||||
635 | szchar = 0.7 |
|
648 | szchar = 0.7 | |
636 | name = "spc" |
|
649 | name = "spc" | |
637 | key = name + "%d"%subplot |
|
650 | key = name + "%d"%subplot | |
638 | xrange = [xmin,xmax] |
|
651 | xrange = [xmin,xmax] | |
639 | yrange = [ymin,ymax] |
|
652 | yrange = [ymin,ymax] | |
640 | zrange = [zmin,zmax] |
|
653 | zrange = [zmin,zmax] | |
641 |
|
654 | |||
642 | xpos,ypos = self.setSpectraPos() |
|
655 | xpos,ypos = self.setSpectraPos() | |
643 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange) |
|
656 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange) | |
644 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv") |
|
|||
645 | self.pcolorObjDic[key] = pcolorObj |
|
657 | self.pcolorObjDic[key] = pcolorObj | |
646 |
|
658 | |||
647 | # Config Colorbar |
|
659 | # Config Colorbar | |
648 | if self.showColorbar: |
|
660 | if self.showColorbar: | |
649 | szchar = 0.65 |
|
661 | szchar = 0.65 | |
650 | name = "colorbar" |
|
662 | name = "colorbar" | |
651 | key = name + "%d"%subplot |
|
663 | key = name + "%d"%subplot | |
652 |
|
664 | |||
653 | xpos,ypos = self.setColorbarScreenPos() |
|
665 | xpos,ypos = self.setColorbarScreenPos() | |
654 | xrange = [0.,1.] |
|
666 | xrange = [0.,1.] | |
655 | yrange = [zmin,zmax] |
|
667 | yrange = [zmin,zmax] | |
656 | cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) |
|
668 | cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) | |
657 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm") |
|
|||
658 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
|||
659 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") |
|
|||
660 | self.colorbarObjDic[key] = cmapObj |
|
669 | self.colorbarObjDic[key] = cmapObj | |
661 |
|
670 | |||
662 | # Config Power profile |
|
671 | # Config Power profile | |
663 | if self.showPowerProfile: |
|
672 | if self.showPowerProfile: | |
664 | szchar = 0.55 |
|
673 | szchar = 0.55 | |
665 | name = "pwprofile" |
|
674 | name = "pwprofile" | |
666 | key = name + "%d"%subplot |
|
675 | key = name + "%d"%subplot | |
667 |
|
676 | |||
668 | xpos,ypos = self.setPowerprofileScreenPos() |
|
677 | xpos,ypos = self.setPowerprofileScreenPos() | |
669 | xrange = [zmin,zmax] |
|
678 | xrange = [zmin,zmax] | |
670 | yrange = [ymin,ymax] |
|
679 | yrange = [ymin,ymax] | |
671 | powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) |
|
680 | powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) | |
|
681 | self.pwprofileObjDic[key] = powObj | |||
|
682 | ||||
|
683 | def setNewPage(self, pltitle='No title'): | |||
|
684 | szchar = 0.7 | |||
|
685 | setNewPage() | |||
|
686 | setPlTitle(pltitle,"black", szchar=szchar) | |||
|
687 | setSubpages(self.ncol, self.nrow) | |||
|
688 | ||||
|
689 | def closePage(self): | |||
|
690 | closePage() | |||
|
691 | ||||
|
692 | def iniPlot(self,subplot): | |||
|
693 | """ | |||
|
694 | Inicializa los subplots con su frame, titulo, etc | |||
|
695 | """ | |||
|
696 | ||||
|
697 | # Config Spectra plot | |||
|
698 | name = "spc" | |||
|
699 | key = name + "%d"%subplot | |||
|
700 | ||||
|
701 | pcolorObj = self.pcolorObjDic[key] | |||
|
702 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv") | |||
|
703 | ||||
|
704 | # Config Colorbar | |||
|
705 | if self.showColorbar: | |||
|
706 | name = "colorbar" | |||
|
707 | key = name + "%d"%subplot | |||
|
708 | ||||
|
709 | cmapObj = self.colorbarObjDic[key] | |||
|
710 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") | |||
|
711 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) | |||
|
712 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") | |||
|
713 | ||||
|
714 | # Config Power profile | |||
|
715 | if self.showPowerProfile: | |||
|
716 | name = "pwprofile" | |||
|
717 | key = name + "%d"%subplot | |||
|
718 | ||||
|
719 | powObj = self.pwprofileObjDic[key] | |||
672 | powObj.setLineStyle(2) |
|
720 | powObj.setLineStyle(2) | |
673 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
721 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") | |
674 | powObj.setLineStyle(1) |
|
722 | powObj.setLineStyle(1) | |
675 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
723 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") | |
676 | self.pwprofileObjDic[key] = powObj |
|
|||
677 |
|
724 | |||
678 | def printTitle(self,pltitle): |
|
725 | def printTitle(self,pltitle): | |
679 | if self.__lastTitle != None: |
|
726 | # if self.__lastTitle != None: | |
680 | setPlTitle(self.__lastTitle,"white") |
|
727 | # setPlTitle(self.__lastTitle,"white") | |
681 |
|
728 | # | ||
682 | self.__lastTitle = pltitle |
|
729 | # self.__lastTitle = pltitle | |
683 |
|
730 | |||
684 | setPlTitle(pltitle,"black") |
|
731 | setPlTitle(pltitle,"black") | |
685 |
|
732 | |||
686 | setSubpages(self.ncol,self.nrow) |
|
733 | # setSubpages(self.ncol,self.nrow) | |
687 |
|
734 | |||
688 | def plot(self,subplot,x,y,z,subtitle): |
|
735 | def plot(self,subplot,x,y,z,subtitle): | |
689 | # Spectra plot |
|
736 | # Spectra plot | |
690 |
|
737 | |||
691 | name = "spc" |
|
738 | name = "spc" | |
692 | key = name + "%d"%subplot |
|
739 | key = name + "%d"%subplot | |
693 |
|
740 | |||
694 | # newx = [x[0],x[-1]] |
|
741 | # newx = [x[0],x[-1]] | |
695 | pcolorObj = self.pcolorObjDic[key] |
|
742 | pcolorObj = self.pcolorObjDic[key] | |
|
743 | ||||
696 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst") |
|
744 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst") | |
697 | pcolorObj.delLabels() |
|
745 | ||
|
746 | #pcolorObj.delLabels() | |||
698 | pcolorObj.setLabels(title=subtitle) |
|
747 | pcolorObj.setLabels(title=subtitle) | |
699 |
|
748 | |||
700 | deltax = None; deltay = None |
|
749 | deltax = None; deltay = None | |
701 |
|
750 | |||
702 | pcolorObj.advPcolorPlot(z, |
|
751 | pcolorObj.advPcolorPlot(z, | |
703 | x, |
|
752 | x, | |
704 | y, |
|
753 | y, | |
705 | xmin=pcolorObj.xrange[0], |
|
754 | xmin=pcolorObj.xrange[0], | |
706 | xmax=pcolorObj.xrange[1], |
|
755 | xmax=pcolorObj.xrange[1], | |
707 | ymin=pcolorObj.yrange[0], |
|
756 | ymin=pcolorObj.yrange[0], | |
708 | ymax=pcolorObj.yrange[1], |
|
757 | ymax=pcolorObj.yrange[1], | |
709 | zmin=pcolorObj.zrange[0], |
|
758 | zmin=pcolorObj.zrange[0], | |
710 | zmax=pcolorObj.zrange[1], |
|
759 | zmax=pcolorObj.zrange[1], | |
711 | deltax=deltax, |
|
760 | deltax=deltax, | |
712 | deltay=deltay, |
|
761 | deltay=deltay, | |
713 | getGrid=pcolorObj.getGrid) |
|
762 | getGrid=pcolorObj.getGrid) | |
714 |
|
763 | |||
|
764 | #Solo se calcula la primera vez que se ingresa a la funcion | |||
715 | pcolorObj.getGrid = False |
|
765 | pcolorObj.getGrid = False | |
716 |
|
766 | |||
717 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst") |
|
767 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst", nolabels=True) | |
718 |
|
768 | |||
719 | # Power Profile |
|
769 | # Power Profile | |
720 | if self.showPowerProfile: |
|
770 | if self.showPowerProfile: | |
721 | power = numpy.average(z, axis=0) |
|
771 | power = numpy.average(z, axis=0) | |
722 | name = "pwprofile" |
|
772 | name = "pwprofile" | |
723 | key = name + "%d"%subplot |
|
773 | key = name + "%d"%subplot | |
724 | powObj = self.pwprofileObjDic[key] |
|
774 | powObj = self.pwprofileObjDic[key] | |
725 |
|
775 | |||
726 | if powObj.setXYData() != None: |
|
776 | if powObj.setXYData() != None: | |
727 | clearData(powObj) |
|
777 | #clearData(powObj) | |
728 | powObj.setLineStyle(2) |
|
778 | powObj.setLineStyle(2) | |
729 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
779 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") | |
730 | powObj.setLineStyle(1) |
|
780 | powObj.setLineStyle(1) | |
731 | else: |
|
781 | else: | |
732 | powObj.setXYData(power,y) |
|
782 | powObj.setXYData(power,y) | |
733 |
|
783 | |||
734 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
784 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") | |
735 | powObj.basicXYPlot(power,y) |
|
785 | powObj.basicXYPlot(power,y) | |
736 | powObj.setXYData(power,y) |
|
786 | powObj.setXYData(power,y) | |
737 |
|
787 | |||
738 |
def savePlot(self,indexPlot, |
|
788 | def savePlot(self,indexPlot,filename): | |
739 |
|
789 | |||
740 | now = datetime.datetime.now().timetuple() |
|
|||
741 | file = "spc_img%02d_%03d_%02d%02d%02d"%(indexPlot,now[7],now[3],now[4],now[5]) |
|
|||
742 | filename = os.path.join(path,file+".png") |
|
|||
743 | width = self.width*self.ncol |
|
790 | width = self.width*self.ncol | |
744 | hei = self.height*self.nrow |
|
791 | hei = self.height*self.nrow | |
745 | savePlplot(filename,width,hei) |
|
792 | savePlplot(filename,width,hei) | |
746 |
|
||||
747 |
|
||||
748 |
|
793 | |||
749 | def refresh(self): |
|
794 | def refresh(self): | |
750 | plFlush() |
|
795 | plFlush() | |
751 |
|
796 | |||
752 | class RtiPlot: |
|
797 | class RtiPlot: | |
753 |
|
798 | |||
754 | pcolorObjDic = {} |
|
799 | pcolorObjDic = {} | |
755 | colorbarObjDic = {} |
|
800 | colorbarObjDic = {} | |
756 | pwprofileObjDic = {} |
|
801 | pwprofileObjDic = {} | |
757 | showColorbar = None |
|
802 | showColorbar = None | |
758 | showPowerProfile = None |
|
803 | showPowerProfile = None | |
759 | XAxisAsTime = None |
|
804 | XAxisAsTime = None | |
760 | widht = None |
|
805 | widht = None | |
761 | height = None |
|
806 | height = None | |
762 | __rtixpos = None |
|
807 | __rtixpos = None | |
763 | __rtiypos = None |
|
808 | __rtiypos = None | |
764 | __cmapxpos = None |
|
809 | __cmapxpos = None | |
765 | __cmapypos = None |
|
810 | __cmapypos = None | |
766 | __profxpos = None |
|
811 | __profxpos = None | |
767 | __profypos = None |
|
812 | __profypos = None | |
768 |
|
813 | |||
769 | def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
814 | def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): | |
770 | self.width = 700 |
|
815 | self.width = 700 | |
771 | self.height = 150 |
|
816 | self.height = 150 | |
772 | self.showColorbar = showColorbar |
|
817 | self.showColorbar = showColorbar | |
773 | self.showPowerProfile = showPowerProfile |
|
818 | self.showPowerProfile = showPowerProfile | |
774 | self.XAxisAsTime = XAxisAsTime |
|
819 | self.XAxisAsTime = XAxisAsTime | |
775 |
|
820 | |||
776 | ncol = 1 |
|
821 | ncol = 1 | |
777 | nrow = nsubplot |
|
822 | nrow = nsubplot | |
778 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) |
|
823 | initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height) | |
779 | setColormap(colormap) |
|
824 | setColormap(colormap) | |
780 |
|
825 | |||
781 | def setFigure(self,indexPlot): |
|
826 | def setFigure(self,indexPlot): | |
782 | setStrm(indexPlot) |
|
827 | setStrm(indexPlot) | |
783 |
|
828 | |||
784 | def setRtiScreenPos(self): |
|
829 | def setRtiScreenPos(self): | |
785 |
|
830 | |||
786 | if self.showPowerProfile: xi = 0.07; xf = 0.65 |
|
831 | if self.showPowerProfile: xi = 0.07; xf = 0.65 | |
787 | else: xi = 0.07; xf = 0.9 |
|
832 | else: xi = 0.07; xf = 0.9 | |
788 | yi = 0.15; yf = 0.80 |
|
833 | yi = 0.15; yf = 0.80 | |
789 |
|
834 | |||
790 | xpos = [xi,xf] |
|
835 | xpos = [xi,xf] | |
791 | ypos = [yi,yf] |
|
836 | ypos = [yi,yf] | |
792 |
|
837 | |||
793 | self.__rtixpos = xpos |
|
838 | self.__rtixpos = xpos | |
794 | self.__rtiypos = ypos |
|
839 | self.__rtiypos = ypos | |
795 |
|
840 | |||
796 | return xpos,ypos |
|
841 | return xpos,ypos | |
797 |
|
842 | |||
798 | def setColorbarScreenPos(self): |
|
843 | def setColorbarScreenPos(self): | |
799 |
|
844 | |||
800 | xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03 |
|
845 | xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03 | |
801 |
|
846 | |||
802 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
847 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] | |
803 |
|
848 | |||
804 | xpos = [xi,xf] |
|
849 | xpos = [xi,xf] | |
805 | ypos = [yi,yf] |
|
850 | ypos = [yi,yf] | |
806 |
|
851 | |||
807 | self.__cmapxpos = xpos |
|
852 | self.__cmapxpos = xpos | |
808 | self.__cmapypos = ypos |
|
853 | self.__cmapypos = ypos | |
809 |
|
854 | |||
810 | return xpos,ypos |
|
855 | return xpos,ypos | |
811 |
|
856 | |||
812 | def setPowerprofileScreenPos(self): |
|
857 | def setPowerprofileScreenPos(self): | |
813 |
|
858 | |||
814 | xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20 |
|
859 | xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20 | |
815 |
|
860 | |||
816 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
861 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] | |
817 |
|
862 | |||
818 | xpos = [xi,xf] |
|
863 | xpos = [xi,xf] | |
819 | ypos = [yi,yf] |
|
864 | ypos = [yi,yf] | |
820 |
|
865 | |||
821 | self.__profxpos = [xi,xf] |
|
866 | self.__profxpos = [xi,xf] | |
822 | self.__profypos = [yi,yf] |
|
867 | self.__profypos = [yi,yf] | |
823 |
|
868 | |||
824 | return xpos,ypos |
|
869 | return xpos,ypos | |
825 |
|
870 | |||
826 | def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone="lt",npoints=100): |
|
871 | def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone="lt",npoints=100): | |
827 | # Config Rti plot |
|
872 | # Config Rti plot | |
828 | szchar = 1.10 |
|
873 | szchar = 1.10 | |
829 | name = "rti" |
|
874 | name = "rti" | |
830 | key = name + "%d"%subplot |
|
875 | key = name + "%d"%subplot | |
831 |
|
876 | |||
832 | # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal] |
|
877 | # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal] | |
833 | thisDateTime = datetime.datetime.fromtimestamp(timedata) |
|
878 | thisDateTime = datetime.datetime.fromtimestamp(timedata) | |
834 | startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0) |
|
879 | startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0) | |
835 | endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59) |
|
880 | endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59) | |
836 | deltaTime = 0 |
|
881 | deltaTime = 0 | |
837 | if timezone == "lt": |
|
882 | if timezone == "lt": | |
838 | deltaTime = time.timezone |
|
883 | deltaTime = time.timezone | |
839 | startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime |
|
884 | startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime | |
840 | endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime |
|
885 | endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime | |
841 |
|
886 | |||
842 | xrange = [startTimeInSecs,endTimeInSecs] |
|
887 | xrange = [startTimeInSecs,endTimeInSecs] | |
843 | totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1. |
|
888 | totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1. | |
844 | deltax = totalTimeInXrange / npoints |
|
889 | deltax = totalTimeInXrange / npoints | |
845 |
|
890 | |||
846 | yrange = [ymin,ymax] |
|
891 | yrange = [ymin,ymax] | |
847 | zrange = [zmin,zmax] |
|
892 | zrange = [zmin,zmax] | |
848 |
|
893 | |||
849 | xpos,ypos = self.setRtiScreenPos() |
|
894 | xpos,ypos = self.setRtiScreenPos() | |
850 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax) |
|
895 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax) | |
851 | if self.XAxisAsTime: |
|
896 | if self.XAxisAsTime: | |
852 | pcolorObj.setXAxisAsTime(self.XAxisAsTime) |
|
897 | pcolorObj.setXAxisAsTime(self.XAxisAsTime) | |
853 | xopt = "bcnstd" |
|
898 | xopt = "bcnstd" | |
854 | yopt = "bcnstv" |
|
899 | yopt = "bcnstv" | |
855 | else: |
|
900 | else: | |
856 | xopt = "bcnst" |
|
901 | xopt = "bcnst" | |
857 | yopt = "bcnstv" |
|
902 | yopt = "bcnstv" | |
858 |
|
903 | |||
859 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
904 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) | |
860 | self.pcolorObjDic[key] = pcolorObj |
|
905 | self.pcolorObjDic[key] = pcolorObj | |
861 |
|
906 | |||
862 |
|
907 | |||
863 | # Config Colorbar |
|
908 | # Config Colorbar | |
864 | if self.showColorbar: |
|
909 | if self.showColorbar: | |
865 | szchar = 0.9 |
|
910 | szchar = 0.9 | |
866 | name = "colorbar" |
|
911 | name = "colorbar" | |
867 | key = name + "%d"%subplot |
|
912 | key = name + "%d"%subplot | |
868 |
|
913 | |||
869 | xpos,ypos = self.setColorbarScreenPos() |
|
914 | xpos,ypos = self.setColorbarScreenPos() | |
870 | xrange = [0.,1.] |
|
915 | xrange = [0.,1.] | |
871 | yrange = [zmin,zmax] |
|
916 | yrange = [zmin,zmax] | |
872 | cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) |
|
917 | cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange) | |
873 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm") |
|
918 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm") | |
874 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
919 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) | |
875 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") |
|
920 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv") | |
876 | self.colorbarObjDic[key] = cmapObj |
|
921 | self.colorbarObjDic[key] = cmapObj | |
877 |
|
922 | |||
878 |
|
923 | |||
879 | # Config Power profile |
|
924 | # Config Power profile | |
880 | if self.showPowerProfile: |
|
925 | if self.showPowerProfile: | |
881 | szchar = 0.8 |
|
926 | szchar = 0.8 | |
882 | name = "pwprofile" |
|
927 | name = "pwprofile" | |
883 | key = name + "%d"%subplot |
|
928 | key = name + "%d"%subplot | |
884 |
|
929 | |||
885 | xpos,ypos = self.setPowerprofileScreenPos() |
|
930 | xpos,ypos = self.setPowerprofileScreenPos() | |
886 | xrange = [zmin,zmax] |
|
931 | xrange = [zmin,zmax] | |
887 | yrange = [ymin,ymax] |
|
932 | yrange = [ymin,ymax] | |
888 | powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) |
|
933 | powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange) | |
889 | powObj.setLineStyle(2) |
|
934 | powObj.setLineStyle(2) | |
890 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
935 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") | |
891 | powObj.setLineStyle(1) |
|
936 | powObj.setLineStyle(1) | |
892 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
937 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") | |
893 | self.pwprofileObjDic[key] = powObj |
|
938 | self.pwprofileObjDic[key] = powObj | |
894 |
|
939 | |||
895 |
|
940 | |||
896 | def plot(self,subplot,x,y,z): |
|
941 | def plot(self,subplot,x,y,z): | |
897 | # RTI plot |
|
942 | # RTI plot | |
898 | name = "rti" |
|
943 | name = "rti" | |
899 | key = name + "%d"%subplot |
|
944 | key = name + "%d"%subplot | |
900 |
|
945 | |||
901 | data = numpy.reshape(z, (1,-1)) |
|
946 | data = numpy.reshape(z, (1,-1)) | |
902 | data = numpy.abs(data) |
|
947 | data = numpy.abs(data) | |
903 | data = 10*numpy.log10(data) |
|
948 | data = 10*numpy.log10(data) | |
904 | newx = [x,x+1] |
|
949 | newx = [x,x+1] | |
905 |
|
950 | |||
906 | pcolorObj = self.pcolorObjDic[key] |
|
951 | pcolorObj = self.pcolorObjDic[key] | |
907 |
|
952 | |||
908 | if pcolorObj.xaxisIsTime: |
|
953 | if pcolorObj.xaxisIsTime: | |
909 | xopt = "bcstd" |
|
954 | xopt = "bcstd" | |
910 | yopt = "bcst" |
|
955 | yopt = "bcst" | |
911 | else: |
|
956 | else: | |
912 | xopt = "bcst" |
|
957 | xopt = "bcst" | |
913 | yopt = "bcst" |
|
958 | yopt = "bcst" | |
914 |
|
959 | |||
915 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
960 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) | |
916 |
|
961 | |||
917 | deltax = pcolorObj.deltax |
|
962 | deltax = pcolorObj.deltax | |
918 | deltay = None |
|
963 | deltay = None | |
919 |
|
964 | |||
920 | if pcolorObj.xmin == None and pcolorObj.xmax == None: |
|
965 | if pcolorObj.xmin == None and pcolorObj.xmax == None: | |
921 | pcolorObj.xmin = x |
|
966 | pcolorObj.xmin = x | |
922 | pcolorObj.xmax = x |
|
967 | pcolorObj.xmax = x | |
923 |
|
968 | |||
924 | if x >= pcolorObj.xmax: |
|
969 | if x >= pcolorObj.xmax: | |
925 | xmin = x |
|
970 | xmin = x | |
926 | xmax = x + deltax |
|
971 | xmax = x + deltax | |
927 | x = [x] |
|
972 | x = [x] | |
928 | pcolorObj.advPcolorPlot(data, |
|
973 | pcolorObj.advPcolorPlot(data, | |
929 | x, |
|
974 | x, | |
930 | y, |
|
975 | y, | |
931 | xmin=xmin, |
|
976 | xmin=xmin, | |
932 | xmax=xmax, |
|
977 | xmax=xmax, | |
933 | ymin=pcolorObj.yrange[0], |
|
978 | ymin=pcolorObj.yrange[0], | |
934 | ymax=pcolorObj.yrange[1], |
|
979 | ymax=pcolorObj.yrange[1], | |
935 | zmin=pcolorObj.zrange[0], |
|
980 | zmin=pcolorObj.zrange[0], | |
936 | zmax=pcolorObj.zrange[1], |
|
981 | zmax=pcolorObj.zrange[1], | |
937 | deltax=deltax, |
|
982 | deltax=deltax, | |
938 | deltay=deltay, |
|
983 | deltay=deltay, | |
939 | getGrid=pcolorObj.getGrid) |
|
984 | getGrid=pcolorObj.getGrid) | |
940 |
|
985 | |||
941 | pcolorObj.xmin = xmin |
|
986 | pcolorObj.xmin = xmin | |
942 | pcolorObj.xmax = xmax |
|
987 | pcolorObj.xmax = xmax | |
943 |
|
988 | |||
944 |
|
989 | |||
945 | # Power Profile |
|
990 | # Power Profile | |
946 | if self.showPowerProfile: |
|
991 | if self.showPowerProfile: | |
947 | data = numpy.reshape(data,(numpy.size(data))) |
|
992 | data = numpy.reshape(data,(numpy.size(data))) | |
948 | name = "pwprofile" |
|
993 | name = "pwprofile" | |
949 | key = name + "%d"%subplot |
|
994 | key = name + "%d"%subplot | |
950 | powObj = self.pwprofileObjDic[key] |
|
995 | powObj = self.pwprofileObjDic[key] | |
951 |
|
996 | |||
952 | if powObj.setXYData() != None: |
|
997 | if powObj.setXYData() != None: | |
953 | clearData(powObj) |
|
998 | clearData(powObj) | |
954 | powObj.setLineStyle(2) |
|
999 | powObj.setLineStyle(2) | |
955 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") |
|
1000 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc") | |
956 | powObj.setLineStyle(1) |
|
1001 | powObj.setLineStyle(1) | |
957 | else: |
|
1002 | else: | |
958 | powObj.setXYData(data,y) |
|
1003 | powObj.setXYData(data,y) | |
959 |
|
1004 | |||
960 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") |
|
1005 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc") | |
961 | powObj.basicXYPlot(data,y) |
|
1006 | powObj.basicXYPlot(data,y) | |
962 | powObj.setXYData(data,y) |
|
1007 | powObj.setXYData(data,y) | |
963 |
|
1008 | |||
964 | def refresh(self): |
|
1009 | def refresh(self): | |
965 | plFlush() No newline at end of file |
|
1010 | plFlush() |
@@ -1,126 +1,170 | |||||
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 numpy |
|
8 | import numpy | |
9 | import os |
|
9 | import os | |
10 | import sys |
|
10 | import sys | |
11 | import plplot |
|
11 | import plplot | |
12 | import datetime |
|
12 | import datetime | |
13 |
|
13 | |||
14 | path = os.path.split(os.getcwd())[0] |
|
14 | path = os.path.split(os.getcwd())[0] | |
15 | sys.path.append(path) |
|
15 | sys.path.append(path) | |
16 |
|
16 | |||
17 | from Graphics.BaseGraph import * |
|
17 | from Graphics.BaseGraph import * | |
18 | from Model.Spectra import Spectra |
|
18 | from Model.Spectra import Spectra | |
19 |
|
19 | |||
20 | class Spectrum: |
|
20 | class Spectrum: | |
21 | colorplotObj = None |
|
21 | colorplotObj = None | |
22 |
|
22 | |||
23 | def __init__(self,Spectra, index): |
|
23 | def __init__(self,Spectra, index): | |
24 | self.__isPlotConfig = False |
|
24 | self.__isPlotConfig = False | |
25 | self.__isPlotIni = False |
|
25 | self.__isPlotIni = False | |
26 | self.__xrange = None |
|
26 | self.__xrange = None | |
27 | self.__yrange = None |
|
27 | self.__yrange = None | |
28 |
self.n |
|
28 | self.nsubplots = 0 | |
29 | self.indexPlot = index |
|
29 | self.indexPlot = index | |
30 | self.spectraObj = Spectra |
|
30 | self.spectraObj = Spectra | |
31 |
|
31 | |||
32 | def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False): |
|
32 | def setup(self,indexPlot, nsubplots, winTitle='', colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | |
33 | self.colorplotObj = SpectraPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) |
|
33 | """ | |
34 |
|
34 | Crea un objeto colorPlot con las opciones seleccinoadas | ||
35 | def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList): |
|
35 | """ | |
36 | nsubplot = self.spectraObj.nChannels |
|
36 | ||
|
37 | self.nsubplots = nsubplots | |||
|
38 | self.colorplotObj = PcolorPlot(indexPlot, | |||
|
39 | nsubplots, | |||
|
40 | winTitle, | |||
|
41 | colormap, | |||
|
42 | showColorbar, | |||
|
43 | showPowerProfile, | |||
|
44 | XAxisAsTime) | |||
|
45 | ||||
|
46 | def createObjects(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList): | |||
|
47 | """ | |||
|
48 | Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos | |||
|
49 | """ | |||
37 |
|
50 | |||
38 | for index in range(nsubplot): |
|
51 | for index in range(self.nsubplots): | |
39 | title = titleList[index] |
|
52 | title = titleList[index] | |
40 | xlabel = xlabelList[index] |
|
53 | xlabel = xlabelList[index] | |
41 | ylabel = ylabelList[index] |
|
54 | ylabel = ylabelList[index] | |
42 | subplot = index |
|
55 | subplot = index | |
43 |
self.colorplotObj. |
|
56 | self.colorplotObj.createObjects(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel) | |
|
57 | ||||
|
58 | def initPlot(self): | |||
|
59 | """ | |||
|
60 | Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos | |||
|
61 | """ | |||
|
62 | ||||
|
63 | ||||
|
64 | for index in range(self.nsubplots): | |||
|
65 | subplot = index | |||
|
66 | self.colorplotObj.iniPlot(subplot+1) | |||
44 |
|
67 | |||
45 |
|
68 | |||
46 | def plotData(self, |
|
69 | def plotData(self, | |
47 | xmin=None, |
|
70 | xmin=None, | |
48 | xmax=None, |
|
71 | xmax=None, | |
49 | ymin=None, |
|
72 | ymin=None, | |
50 | ymax=None, |
|
73 | ymax=None, | |
51 | zmin=None, |
|
74 | zmin=None, | |
52 | zmax=None, |
|
75 | zmax=None, | |
53 | titleList=None, |
|
76 | titleList=None, | |
54 | xlabelList=None, |
|
77 | xlabelList=None, | |
55 | ylabelList=None, |
|
78 | ylabelList=None, | |
56 | winTitle='', |
|
79 | winTitle='', | |
57 | colormap = "br_green", |
|
80 | colormap = "br_green", | |
58 | showColorbar = True, |
|
81 | showColorbar = True, | |
59 | showPowerProfile = True, |
|
82 | showPowerProfile = True, | |
60 | XAxisAsTime = False, |
|
83 | XAxisAsTime = False, | |
61 |
save = False |
|
84 | save = False, | |
|
85 | channelList=[]): | |||
|
86 | ||||
|
87 | if channelList == []: | |||
|
88 | channelList = numpy.arange(self.spectraObj.nChannels) | |||
|
89 | ||||
62 |
|
90 | |||
63 | databuffer = 10.*numpy.log10(self.spectraObj.data_spc) |
|
91 | nsubplots = len(channelList) | |
64 |
n |
|
92 | nX = self.spectraObj.nFFTPoints | |
|
93 | nY = self.spectraObj.nHeights | |||
65 |
|
94 | |||
66 |
|
|
95 | if self.spectraObj.noise == None: | |
67 | nsubplot, nX, nY = numpy.shape(databuffer) |
|
96 | noise = numpy.ones(nsubplots) | |
|
97 | else: | |||
|
98 | noise = 10.*numpy.log10(self.spectraObj.noise[channelList]) | |||
|
99 | ||||
|
100 | datadB = 10.*numpy.log10(self.spectraObj.data_spc[channelList,:,:]) | |||
|
101 | noisedB = 10.*numpy.log10(noise) | |||
68 |
|
102 | |||
69 | x = numpy.arange(nX) |
|
103 | x = numpy.arange(nX) | |
70 | y = self.spectraObj.heightList |
|
104 | y = self.spectraObj.heightList | |
71 |
|
105 | |||
72 | indexPlot = self.indexPlot |
|
106 | indexPlot = self.indexPlot | |
73 |
|
107 | |||
74 | if not(self.__isPlotConfig): |
|
108 | if not(self.__isPlotConfig): | |
75 | self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) |
|
109 | self.setup(indexPlot, | |
|
110 | nsubplots, | |||
|
111 | winTitle, | |||
|
112 | colormap, | |||
|
113 | showColorbar, | |||
|
114 | showPowerProfile, | |||
|
115 | XAxisAsTime) | |||
|
116 | ||||
|
117 | ||||
76 | self.__isPlotConfig = True |
|
118 | self.__isPlotConfig = True | |
77 |
|
119 | |||
78 | if not(self.__isPlotIni): |
|
120 | if not(self.__isPlotIni): | |
79 | if titleList == None: |
|
121 | if titleList == None: | |
80 | titleList = [] |
|
122 | titleList = [] | |
81 | for i in range(nsubplot): |
|
123 | for i in range(nsubplots): | |
82 | titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i])) |
|
124 | titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i])) | |
83 |
|
125 | |||
84 | if xlabelList == None: |
|
126 | if xlabelList == None: | |
85 | xlabelList = [] |
|
127 | xlabelList = [] | |
86 | for i in range(nsubplot): |
|
128 | for i in range(nsubplots): | |
87 | xlabelList.append("") |
|
129 | xlabelList.append("") | |
88 |
|
130 | |||
89 | if ylabelList == None: |
|
131 | if ylabelList == None: | |
90 | ylabelList = [] |
|
132 | ylabelList = [] | |
91 | for i in range(nsubplot): |
|
133 | for i in range(nsubplots): | |
92 | ylabelList.append("Range (Km)") |
|
134 | ylabelList.append("Range (Km)") | |
93 |
|
135 | |||
94 | if xmin == None: xmin = x[0] |
|
136 | if xmin == None: xmin = x[0] | |
95 | if xmax == None: xmax = x[-1] |
|
137 | if xmax == None: xmax = x[-1] | |
96 | if ymin == None: ymin = y[0] |
|
138 | if ymin == None: ymin = y[0] | |
97 | if ymax == None: ymax = y[-1] |
|
139 | if ymax == None: ymax = y[-1] | |
98 | if zmin == None: zmin = 0 |
|
140 | if zmin == None: zmin = 0 | |
99 | if zmax == None: zmax = 120 |
|
141 | if zmax == None: zmax = 120 | |
100 |
|
142 | |||
101 |
self. |
|
143 | self.createObjects(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList) | |
102 | self.__isPlotIni = True |
|
144 | self.__isPlotIni = True | |
103 |
|
145 | |||
104 | self.colorplotObj.setFigure(indexPlot) |
|
|||
105 |
|
||||
106 | thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc) |
|
146 | thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc) | |
107 | pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
147 | pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
108 |
|
148 | |||
109 | self.colorplotObj.printTitle(pltitle) #setPlTitle(pltitle) |
|
149 | self.colorplotObj.setFigure(indexPlot) | |
110 |
|
150 | self.colorplotObj.setNewPage(pltitle) | ||
111 | for index in range(nsubplot): |
|
151 | self.initPlot() | |
112 | data = databuffer[index,:,:] |
|
|||
113 | subtitle = "Channel: %d - Noise: %.2f" %(index, noise[index]) |
|
|||
114 | self.colorplotObj.plot(index+1,x,y,data,subtitle) |
|
|||
115 |
|
||||
116 |
|
152 | |||
|
153 | for channel in range(nsubplots): | |||
|
154 | data = datadB[channel,:,:] | |||
|
155 | subtitle = "Channel: %d - Noise: %.2f" %(channel, noise[channel]) | |||
|
156 | self.colorplotObj.plot(channel+1, x, y, data, subtitle) | |||
117 |
|
157 | |||
118 | self.colorplotObj.refresh() |
|
158 | self.colorplotObj.refresh() | |
119 |
|
159 | |||
120 | if save: |
|
160 | if save: | |
121 | self.colorplotObj.setFigure(indexPlot) |
|
161 | self.colorplotObj.setFigure(indexPlot) | |
122 |
path |
|
162 | path = "/home/roj-idl71/tmp/" | |
123 | self.colorplotObj.savePlot(indexPlot,path4plot) |
|
163 | now = datetime.datetime.now().timetuple() | |
124 |
|
164 | file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5]) | ||
|
165 | filename = os.path.join(path,file) | |||
|
166 | self.colorplotObj.savePlot(indexPlot, filename) | |||
|
167 | ||||
|
168 | self.colorplotObj.closePage() | |||
125 |
|
169 | |||
126 |
|
170 |
@@ -1,197 +1,190 | |||||
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 numpy |
|
7 | import numpy | |
8 | import os |
|
8 | import os | |
9 | import sys |
|
9 | import sys | |
10 |
|
10 | |||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Graphics.BaseGraph import * |
|
14 | from Graphics.BaseGraph import * | |
15 | from Model.Voltage import Voltage |
|
15 | from Model.Voltage import Voltage | |
16 |
|
16 | |||
17 | class Osciloscope: |
|
17 | class Osciloscope: | |
18 | linearplotObj = None |
|
18 | linearplotObj = None | |
19 |
|
19 | |||
20 | def __init__(self, Voltage, index): |
|
20 | def __init__(self, Voltage, index): | |
21 | self.__isPlotConfig = False |
|
21 | self.__isPlotConfig = False | |
22 | self.__isPlotIni = False |
|
22 | self.__isPlotIni = False | |
23 | self.__xrange = None |
|
23 | self.__xrange = None | |
24 | self.__yrange = None |
|
24 | self.__yrange = None | |
25 | self.indexPlot = index |
|
25 | self.indexPlot = index | |
26 | self.voltageObj = Voltage |
|
26 | self.voltageObj = Voltage | |
27 |
|
27 | |||
28 | def setup(self,indexPlot,nsubplot,winTitle=''): |
|
28 | def setup(self,indexPlot,nsubplot,winTitle=''): | |
29 | self.linearplotObj = LinearPlot(indexPlot,nsubplot,winTitle) |
|
29 | self.linearplotObj = LinearPlot(indexPlot,nsubplot,winTitle) | |
30 |
|
30 | |||
31 | def initPlot(self,xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList): |
|
31 | def initPlot(self,xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList): | |
32 | nsubplot = self.voltageObj.nChannels |
|
32 | nsubplot = self.voltageObj.nChannels | |
33 |
|
33 | |||
34 | for index in range(nsubplot): |
|
34 | for index in range(nsubplot): | |
35 | title = titleList[index] |
|
35 | title = titleList[index] | |
36 | xlabel = xlabelList[index] |
|
36 | xlabel = xlabelList[index] | |
37 | ylabel = ylabelList[index] |
|
37 | ylabel = ylabelList[index] | |
38 | subplot = index |
|
38 | subplot = index | |
39 | self.linearplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,title,xlabel,ylabel) |
|
39 | self.linearplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,title,xlabel,ylabel) | |
40 |
|
40 | |||
41 | def plotData(self, |
|
41 | def plotData(self, | |
42 | xmin=None, |
|
42 | xmin=None, | |
43 | xmax=None, |
|
43 | xmax=None, | |
44 | ymin=None, |
|
44 | ymin=None, | |
45 | ymax=None, |
|
45 | ymax=None, | |
46 | titleList=None, |
|
46 | titleList=None, | |
47 | xlabelList=None, |
|
47 | xlabelList=None, | |
48 | ylabelList=None, |
|
48 | ylabelList=None, | |
49 | winTitle='', |
|
49 | winTitle='', | |
50 | type="power"): |
|
50 | type="power"): | |
51 |
|
51 | |||
52 | databuffer = self.voltageObj.data |
|
52 | databuffer = self.voltageObj.data | |
53 |
|
53 | |||
54 | height = self.voltageObj.heightList |
|
54 | height = self.voltageObj.heightList | |
55 | nsubplot = self.voltageObj.nChannels |
|
55 | nsubplot = self.voltageObj.nChannels | |
56 | indexPlot = self.indexPlot |
|
56 | indexPlot = self.indexPlot | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | if not(self.__isPlotConfig): |
|
59 | if not(self.__isPlotConfig): | |
60 | self.setup(indexPlot,nsubplot,winTitle) |
|
60 | self.setup(indexPlot,nsubplot,winTitle) | |
61 | self.__isPlotConfig = True |
|
61 | self.__isPlotConfig = True | |
62 |
|
62 | |||
63 | if not(self.__isPlotIni): |
|
63 | if not(self.__isPlotIni): | |
64 | if titleList == None: |
|
64 | if titleList == None: | |
65 | titleList = [] |
|
65 | titleList = [] | |
66 | thisDatetime = datetime.datetime.fromtimestamp(self.voltageObj.m_BasicHeader.utc) |
|
66 | thisDatetime = datetime.datetime.fromtimestamp(self.voltageObj.m_BasicHeader.utc) | |
67 | txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
67 | txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
68 | for i in range(nsubplot): |
|
68 | for i in range(nsubplot): | |
69 | titleList.append("Channel: %d %s" %(i, txtdate)) |
|
69 | titleList.append("Channel: %d %s" %(i, txtdate)) | |
70 |
|
70 | |||
71 | if xlabelList == None: |
|
71 | if xlabelList == None: | |
72 | xlabelList = [] |
|
72 | xlabelList = [] | |
73 | for i in range(nsubplot): |
|
73 | for i in range(nsubplot): | |
74 | xlabelList.append("") |
|
74 | xlabelList.append("") | |
75 |
|
75 | |||
76 | if ylabelList == None: |
|
76 | if ylabelList == None: | |
77 | ylabelList = [] |
|
77 | ylabelList = [] | |
78 | for i in range(nsubplot): |
|
78 | for i in range(nsubplot): | |
79 | ylabelList.append("") |
|
79 | ylabelList.append("") | |
80 |
|
80 | |||
81 | if xmin == None: xmin = height[0] |
|
81 | if xmin == None: xmin = height[0] | |
82 | if xmax == None: xmax = height[-1] |
|
82 | if xmax == None: xmax = height[-1] | |
83 | if ymin == None: ymin = numpy.nanmin(abs(databuffer)) |
|
83 | if ymin == None: ymin = numpy.nanmin(abs(databuffer)) | |
84 | if ymax == None: ymax = numpy.nanmax(abs(databuffer)) |
|
84 | if ymax == None: ymax = numpy.nanmax(abs(databuffer)) | |
85 |
|
85 | |||
86 | self.initPlot(xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList) |
|
86 | self.initPlot(xmin,xmax,ymin,ymax,titleList,xlabelList,ylabelList) | |
87 | self.__isPlotIni = True |
|
87 | self.__isPlotIni = True | |
88 |
|
88 | |||
89 | self.linearplotObj.setFigure(indexPlot) |
|
89 | self.linearplotObj.setFigure(indexPlot) | |
90 |
|
90 | |||
91 | for index in range(nsubplot): |
|
91 | for index in range(nsubplot): | |
92 | data = databuffer[index,:] |
|
92 | data = databuffer[index,:] | |
93 | self.linearplotObj.plot(subplot=index+1,x=height,y=data,type=type) |
|
93 | self.linearplotObj.plot(subplot=index+1,x=height,y=data,type=type) | |
94 |
|
94 | |||
95 | self.linearplotObj.refresh() |
|
95 | self.linearplotObj.refresh() | |
96 |
|
96 | |||
97 |
|
||||
98 |
|
||||
99 |
|
||||
100 |
|
||||
101 |
|
||||
102 |
|
||||
103 |
|
||||
104 | class RTI: |
|
97 | class RTI: | |
105 | colorplotObj = None |
|
98 | colorplotObj = None | |
106 |
|
99 | |||
107 | def __init__(self, Voltage, index): |
|
100 | def __init__(self, Voltage, index): | |
108 | self.__isPlotConfig = False |
|
101 | self.__isPlotConfig = False | |
109 | self.__isPlotIni = False |
|
102 | self.__isPlotIni = False | |
110 | self.__xrange = None |
|
103 | self.__xrange = None | |
111 | self.__yrange = None |
|
104 | self.__yrange = None | |
112 | self.indexPlot = index |
|
105 | self.indexPlot = index | |
113 | self.voltageObj = Voltage |
|
106 | self.voltageObj = Voltage | |
114 |
|
107 | |||
115 | def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False): |
|
108 | def setup(self,indexPlot,nsubplot,winTitle='',colormap="br_green",showColorbar=False,showPowerProfile=False,XAxisAsTime=False): | |
116 | self.colorplotObj = RtiPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) |
|
109 | self.colorplotObj = RtiPlot(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) | |
117 |
|
110 | |||
118 | def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints): |
|
111 | def initPlot(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints): | |
119 |
|
112 | |||
120 | nsubplot = self.voltageObj.nChannels |
|
113 | nsubplot = self.voltageObj.nChannels | |
121 | timedata = self.voltageObj.m_BasicHeader.utc |
|
114 | timedata = self.voltageObj.m_BasicHeader.utc | |
122 |
|
115 | |||
123 | for index in range(nsubplot): |
|
116 | for index in range(nsubplot): | |
124 | title = titleList[index] |
|
117 | title = titleList[index] | |
125 | xlabel = xlabelList[index] |
|
118 | xlabel = xlabelList[index] | |
126 | ylabel = ylabelList[index] |
|
119 | ylabel = ylabelList[index] | |
127 | subplot = index |
|
120 | subplot = index | |
128 | self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone,npoints) |
|
121 | self.colorplotObj.setup(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone,npoints) | |
129 |
|
122 | |||
130 | def plotData(self, |
|
123 | def plotData(self, | |
131 | xmin=None, |
|
124 | xmin=None, | |
132 | xmax=None, |
|
125 | xmax=None, | |
133 | ymin=None, |
|
126 | ymin=None, | |
134 | ymax=None, |
|
127 | ymax=None, | |
135 | zmin=None, |
|
128 | zmin=None, | |
136 | zmax=None, |
|
129 | zmax=None, | |
137 | titleList=None, |
|
130 | titleList=None, | |
138 | xlabelList=None, |
|
131 | xlabelList=None, | |
139 | ylabelList=None, |
|
132 | ylabelList=None, | |
140 | winTitle='', |
|
133 | winTitle='', | |
141 | timezone='lt', |
|
134 | timezone='lt', | |
142 | npoints=1000.0, |
|
135 | npoints=1000.0, | |
143 | colormap="br_green", |
|
136 | colormap="br_green", | |
144 | showColorbar=True, |
|
137 | showColorbar=True, | |
145 | showPowerProfile=True, |
|
138 | showPowerProfile=True, | |
146 | XAxisAsTime=True): |
|
139 | XAxisAsTime=True): | |
147 |
|
140 | |||
148 | databuffer = self.voltageObj.data |
|
141 | databuffer = self.voltageObj.data | |
149 | timedata = self.voltageObj.m_BasicHeader.utc |
|
142 | timedata = self.voltageObj.m_BasicHeader.utc | |
150 | height = self.voltageObj.heightList |
|
143 | height = self.voltageObj.heightList | |
151 | nsubplot = self.voltageObj.nChannels |
|
144 | nsubplot = self.voltageObj.nChannels | |
152 | indexPlot = self.indexPlot |
|
145 | indexPlot = self.indexPlot | |
153 |
|
146 | |||
154 | if not(self.__isPlotConfig): |
|
147 | if not(self.__isPlotConfig): | |
155 | self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) |
|
148 | self.setup(indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime) | |
156 | self.__isPlotConfig = True |
|
149 | self.__isPlotConfig = True | |
157 |
|
150 | |||
158 | if not(self.__isPlotIni): |
|
151 | if not(self.__isPlotIni): | |
159 | if titleList == None: |
|
152 | if titleList == None: | |
160 | titleList = [] |
|
153 | titleList = [] | |
161 | thisDatetime = datetime.datetime.fromtimestamp(timedata) |
|
154 | thisDatetime = datetime.datetime.fromtimestamp(timedata) | |
162 | txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
155 | txtdate = "Date: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
163 | for i in range(nsubplot): |
|
156 | for i in range(nsubplot): | |
164 | titleList.append("Channel: %d %s" %(i, txtdate)) |
|
157 | titleList.append("Channel: %d %s" %(i, txtdate)) | |
165 |
|
158 | |||
166 | if xlabelList == None: |
|
159 | if xlabelList == None: | |
167 | xlabelList = [] |
|
160 | xlabelList = [] | |
168 | for i in range(nsubplot): |
|
161 | for i in range(nsubplot): | |
169 | xlabelList.append("") |
|
162 | xlabelList.append("") | |
170 |
|
163 | |||
171 | if ylabelList == None: |
|
164 | if ylabelList == None: | |
172 | ylabelList = [] |
|
165 | ylabelList = [] | |
173 | for i in range(nsubplot): |
|
166 | for i in range(nsubplot): | |
174 | ylabelList.append("") |
|
167 | ylabelList.append("") | |
175 |
|
168 | |||
176 | if xmin == None: xmin = 0 |
|
169 | if xmin == None: xmin = 0 | |
177 | if xmax == None: xmax = 23 |
|
170 | if xmax == None: xmax = 23 | |
178 | if ymin == None: ymin = min(self.voltageObj.heightList) |
|
171 | if ymin == None: ymin = min(self.voltageObj.heightList) | |
179 | if ymax == None: ymax = max(self.voltageObj.heightList) |
|
172 | if ymax == None: ymax = max(self.voltageObj.heightList) | |
180 | if zmin == None: zmin = 0 |
|
173 | if zmin == None: zmin = 0 | |
181 | if zmax == None: zmax = 50 |
|
174 | if zmax == None: zmax = 50 | |
182 |
|
175 | |||
183 |
|
176 | |||
184 | self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints) |
|
177 | self.initPlot(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList,timezone,npoints) | |
185 | self.__isPlotIni = True |
|
178 | self.__isPlotIni = True | |
186 |
|
179 | |||
187 |
|
180 | |||
188 | self.colorplotObj.setFigure(indexPlot) |
|
181 | self.colorplotObj.setFigure(indexPlot) | |
189 |
|
182 | |||
190 | if timezone == 'lt': |
|
183 | if timezone == 'lt': | |
191 | timedata = timedata - time.timezone |
|
184 | timedata = timedata - time.timezone | |
192 |
|
185 | |||
193 | for index in range(nsubplot): |
|
186 | for index in range(nsubplot): | |
194 | data = databuffer[index,:] |
|
187 | data = databuffer[index,:] | |
195 | self.colorplotObj.plot(subplot=index+1,x=timedata,y=height,z=data) |
|
188 | self.colorplotObj.plot(subplot=index+1,x=timedata,y=height,z=data) | |
196 |
|
189 | |||
197 | self.colorplotObj.refresh() |
|
190 | self.colorplotObj.refresh() |
@@ -1,213 +1,200 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | from Model.Spectra import Spectra |
|
|||
3 |
|
2 | |||
4 |
def hildebrand_sekhon( |
|
3 | def hildebrand_sekhon(data, navg): | |
5 | """ |
|
4 | """ | |
6 | This method is for the objective determination of de noise level in Doppler spectra. This |
|
5 | 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 |
|
6 | 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 |
|
7 | densities is equal to the mean spectral density for white Gaussian noise | |
9 |
|
8 | |||
10 | Inputs: |
|
9 | Inputs: | |
11 | Data : heights |
|
10 | Data : heights | |
12 | navg : numbers of averages |
|
11 | navg : numbers of averages | |
13 |
|
12 | |||
14 | Return: |
|
13 | Return: | |
15 | -1 : any error |
|
14 | -1 : any error | |
16 | anoise : noise's level |
|
15 | anoise : noise's level | |
17 | """ |
|
16 | """ | |
18 |
|
17 | |||
19 | divisor = 8 |
|
18 | dataflat = data.reshape(-1) | |
20 | ratio = 7 / divisor |
|
19 | dataflat.sort() | |
21 | data = Data.reshape(-1) |
|
20 | npts = dataflat.size #numbers of points of the data | |
22 | npts = data.size #numbers of points of the data |
|
|||
23 |
|
21 | |||
24 | if npts < 32: |
|
22 | if npts < 32: | |
25 | print "error in noise - requires at least 32 points" |
|
23 | print "error in noise - requires at least 32 points" | |
26 | return -1.0 |
|
24 | return -1.0 | |
27 |
|
25 | |||
|
26 | dataflat2 = numpy.power(dataflat,2) | |||
|
27 | ||||
|
28 | cs = numpy.cumsum(dataflat) | |||
|
29 | cs2 = numpy.cumsum(dataflat2) | |||
|
30 | ||||
28 | # data sorted in ascending order |
|
31 | # data sorted in ascending order | |
29 |
nmin = int(npts |
|
32 | nmin = int((npts + 7.)/8) | |
30 | s = 0.0 |
|
|||
31 | s2 = 0.0 |
|
|||
32 | data2 = data[:npts] |
|
|||
33 | data2.sort() |
|
|||
34 |
|
||||
35 | for i in range(nmin): |
|
|||
36 | s += data2[i] |
|
|||
37 | s2 += data2[i]**2; |
|
|||
38 |
|
||||
39 | icount = nmin |
|
|||
40 | iflag = 0 |
|
|||
41 |
|
33 | |||
42 | for i in range(nmin, npts): |
|
34 | for i in range(nmin, npts): | |
43 |
s |
|
35 | s = cs[i] | |
44 |
s2 |
|
36 | s2 = cs2[i] | |
45 | icount=icount+1; |
|
37 | p = s / float(i); | |
46 | p = s / float(icount); |
|
|||
47 | p2 = p**2; |
|
38 | p2 = p**2; | |
48 |
q = s2 / float(i |
|
39 | q = s2 / float(i) - p2; | |
49 | leftc = p2; |
|
40 | leftc = p2; | |
50 | rightc = q * float(navg); |
|
41 | rightc = q * float(navg); | |
51 |
|
42 | R2 = leftc/rightc | ||
52 | if leftc > rightc: |
|
43 | ||
53 | iflag = 1; #No weather signal |
|
|||
54 | # Signal detect: R2 < 1 (R2 = leftc/rightc) |
|
44 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
55 |
if |
|
45 | if R2 < 1: | |
56 |
|
|
46 | npts_noise = i | |
57 |
|
|
47 | break | |
58 |
|
48 | |||
59 | anoise = 0.0; |
|
49 | ||
60 | for j in range(i): |
|
50 | anoise = numpy.average(dataflat[0:npts_noise]) | |
61 | anoise += data2[j]; |
|
|||
62 |
|
||||
63 | anoise = anoise / float(i); |
|
|||
64 |
|
51 | |||
65 | return anoise; |
|
52 | return anoise; | |
66 |
|
53 | |||
67 | def sorting_bruce(Data, navg): |
|
54 | def sorting_bruce(Data, navg): | |
68 | sortdata = numpy.sort(Data) |
|
55 | sortdata = numpy.sort(Data) | |
69 | lenOfData = len(Data) |
|
56 | lenOfData = len(Data) | |
70 | nums_min = lenOfData/10 |
|
57 | nums_min = lenOfData/10 | |
71 |
|
58 | |||
72 | if (lenOfData/10) > 0: |
|
59 | if (lenOfData/10) > 0: | |
73 | nums_min = lenOfData/10 |
|
60 | nums_min = lenOfData/10 | |
74 | else: |
|
61 | else: | |
75 | nums_min = 0 |
|
62 | nums_min = 0 | |
76 |
|
63 | |||
77 | rtest = 1.0 + 1.0/navg |
|
64 | rtest = 1.0 + 1.0/navg | |
78 |
|
65 | |||
79 | sum = 0. |
|
66 | sum = 0. | |
80 |
|
67 | |||
81 | sumq = 0. |
|
68 | sumq = 0. | |
82 |
|
69 | |||
83 | j = 0 |
|
70 | j = 0 | |
84 |
|
71 | |||
85 | cont = 1 |
|
72 | cont = 1 | |
86 |
|
73 | |||
87 | while((cont==1)and(j<lenOfData)): |
|
74 | while((cont==1)and(j<lenOfData)): | |
88 |
|
75 | |||
89 | sum += sortdata[j] |
|
76 | sum += sortdata[j] | |
90 |
|
77 | |||
91 | sumq += sortdata[j]**2 |
|
78 | sumq += sortdata[j]**2 | |
92 |
|
79 | |||
93 | j += 1 |
|
80 | j += 1 | |
94 |
|
81 | |||
95 | if j > nums_min: |
|
82 | if j > nums_min: | |
96 | if ((sumq*j) <= (rtest*sum**2)): |
|
83 | if ((sumq*j) <= (rtest*sum**2)): | |
97 | lnoise = sum / j |
|
84 | lnoise = sum / j | |
98 | else: |
|
85 | else: | |
99 | j = j - 1 |
|
86 | j = j - 1 | |
100 | sum = sum - sordata[j] |
|
87 | sum = sum - sordata[j] | |
101 | sumq = sumq - sordata[j]**2 |
|
88 | sumq = sumq - sordata[j]**2 | |
102 | cont = 0 |
|
89 | cont = 0 | |
103 |
|
90 | |||
104 | if j == nums_min: |
|
91 | if j == nums_min: | |
105 | lnoise = sum /j |
|
92 | lnoise = sum /j | |
106 |
|
93 | |||
107 | return lnoise |
|
94 | return lnoise | |
108 |
|
95 | |||
109 | class Noise: |
|
96 | class Noise: | |
110 | """ |
|
97 | """ | |
111 | Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler |
|
98 | Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler | |
112 | """ |
|
99 | """ | |
113 | data = None |
|
100 | data = None | |
114 | noise = None |
|
101 | noise = None | |
115 | dim = None |
|
102 | dim = None | |
116 |
|
103 | |||
117 | def __init__(self, data=None): |
|
104 | def __init__(self, data=None): | |
118 | """ |
|
105 | """ | |
119 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. |
|
106 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. | |
120 |
|
107 | |||
121 | Inputs: |
|
108 | Inputs: | |
122 | data: Numpy array de la forma nChan x nHeis x nProfiles |
|
109 | data: Numpy array de la forma nChan x nHeis x nProfiles | |
123 |
|
110 | |||
124 | Affected: |
|
111 | Affected: | |
125 | self.noise |
|
112 | self.noise | |
126 |
|
113 | |||
127 | Return: |
|
114 | Return: | |
128 | None |
|
115 | None | |
129 | """ |
|
116 | """ | |
130 |
|
117 | |||
131 | self.data = data |
|
118 | self.data = data | |
132 | self.dim = None |
|
119 | self.dim = None | |
133 | self.nChannels = None |
|
120 | self.nChannels = None | |
134 | self.noise = None |
|
121 | self.noise = None | |
135 |
|
122 | |||
136 | def setNoise(self, data): |
|
123 | def setNoise(self, data): | |
137 | """ |
|
124 | """ | |
138 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. |
|
125 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. | |
139 |
|
126 | |||
140 | Inputs: |
|
127 | Inputs: | |
141 | data: Numpy array de la forma nChan x nHeis x nProfiles |
|
128 | data: Numpy array de la forma nChan x nHeis x nProfiles | |
142 |
|
129 | |||
143 | Affected: |
|
130 | Affected: | |
144 | self.noise |
|
131 | self.noise | |
145 |
|
132 | |||
146 | Return: |
|
133 | Return: | |
147 | None |
|
134 | None | |
148 | """ |
|
135 | """ | |
149 |
|
136 | |||
150 | if data == None: |
|
137 | if data == None: | |
151 | raise ValueError, "The data value is not defined" |
|
138 | raise ValueError, "The data value is not defined" | |
152 |
|
139 | |||
153 | shape = data.shape |
|
140 | shape = data.shape | |
154 | self.dim = len(shape) |
|
141 | self.dim = len(shape) | |
155 | if self.dim == 3: |
|
142 | if self.dim == 3: | |
156 | nChan, nProfiles, nHeis = shape |
|
143 | nChan, nProfiles, nHeis = shape | |
157 | elif self.dim == 2: |
|
144 | elif self.dim == 2: | |
158 | nChan, nHeis = shape |
|
145 | nChan, nHeis = shape | |
159 | else: |
|
146 | else: | |
160 | raise ValueError, "" |
|
147 | raise ValueError, "" | |
161 |
|
148 | |||
162 | self.nChannels = nChan |
|
149 | self.nChannels = nChan | |
163 | self.data = data.copy() |
|
150 | self.data = data.copy() | |
164 | self.noise = numpy.zeros(nChan) |
|
151 | self.noise = numpy.zeros(nChan) | |
165 |
|
152 | |||
166 | return 1 |
|
153 | return 1 | |
167 |
|
154 | |||
168 |
|
155 | |||
169 | def byHildebrand(self, navg=1): |
|
156 | def byHildebrand(self, navg=1): | |
170 | """ |
|
157 | """ | |
171 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
158 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
172 |
|
159 | |||
173 | Return: |
|
160 | Return: | |
174 | noiselevel |
|
161 | noiselevel | |
175 | """ |
|
162 | """ | |
176 |
|
163 | |||
177 | daux = None |
|
164 | daux = None | |
178 |
|
165 | |||
179 | for channel in range(self.nChannels): |
|
166 | for channel in range(self.nChannels): | |
180 | daux = self.data[channel,:,:] |
|
167 | daux = self.data[channel,:,:] | |
181 | self.noise[channel] = hildebrand_sekhon(daux, navg) |
|
168 | self.noise[channel] = hildebrand_sekhon(daux, navg) | |
182 | return self.noise |
|
169 | return self.noise | |
183 |
|
170 | |||
184 | def byWindow(self, heiIndexMin, heiIndexMax, freqIndexMin, freqIndexMax): |
|
171 | def byWindow(self, heiIndexMin, heiIndexMax, freqIndexMin, freqIndexMax): | |
185 | """ |
|
172 | """ | |
186 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: |
|
173 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: | |
187 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) |
|
174 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) | |
188 |
|
175 | |||
189 | Inputs: |
|
176 | Inputs: | |
190 | heiIndexMin: Limite inferior del eje de alturas |
|
177 | heiIndexMin: Limite inferior del eje de alturas | |
191 | heiIndexMax: Limite superior del eje de alturas |
|
178 | heiIndexMax: Limite superior del eje de alturas | |
192 | freqIndexMin: Limite inferior del eje de frecuencia |
|
179 | freqIndexMin: Limite inferior del eje de frecuencia | |
193 | freqIndexMax: Limite supoerior del eje de frecuencia |
|
180 | freqIndexMax: Limite supoerior del eje de frecuencia | |
194 | """ |
|
181 | """ | |
195 |
|
182 | |||
196 | data = self.data[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] |
|
183 | data = self.data[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] | |
197 |
|
184 | |||
198 | for channel in range(self.nChannels): |
|
185 | for channel in range(self.nChannels): | |
199 | daux = data[channel,:,:] |
|
186 | daux = data[channel,:,:] | |
200 | self.noise[channel] = numpy.average(daux) |
|
187 | self.noise[channel] = numpy.average(daux) | |
201 |
|
188 | |||
202 | return self.noise |
|
189 | return self.noise | |
203 |
|
190 | |||
204 | def bySort(self,navg = 1): |
|
191 | def bySort(self,navg = 1): | |
205 | daux = None |
|
192 | daux = None | |
206 |
|
193 | |||
207 | for channel in range(self.nChannels): |
|
194 | for channel in range(self.nChannels): | |
208 | daux = self.data[channel,:,:] |
|
195 | daux = self.data[channel,:,:] | |
209 | self.noise[channel] = sorting_bruce(daux, navg) |
|
196 | self.noise[channel] = sorting_bruce(daux, navg) | |
210 |
|
197 | |||
211 | return self.noise |
|
198 | return self.noise | |
212 |
|
199 | |||
213 | No newline at end of file |
|
200 |
@@ -1,693 +1,696 | |||||
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 time | |||
9 |
|
10 | |||
10 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
11 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
12 |
|
13 | |||
13 | from Model.Spectra import Spectra |
|
14 | from Model.Spectra import Spectra | |
14 | from IO.SpectraIO import SpectraWriter |
|
15 | from IO.SpectraIO import SpectraWriter | |
15 | from Graphics.SpectraPlot import Spectrum |
|
16 | from Graphics.SpectraPlot import Spectrum | |
16 | from JRONoise import Noise |
|
17 | from JRONoise import Noise | |
17 |
|
18 | |||
18 | class SpectraProcessor: |
|
19 | class SpectraProcessor: | |
19 | ''' |
|
20 | ''' | |
20 | classdocs |
|
21 | classdocs | |
21 | ''' |
|
22 | ''' | |
22 |
|
23 | |||
23 | dataInObj = None |
|
24 | dataInObj = None | |
24 |
|
25 | |||
25 | dataOutObj = None |
|
26 | dataOutObj = None | |
26 |
|
27 | |||
27 | noiseObj = None |
|
28 | noiseObj = None | |
28 |
|
29 | |||
29 | integratorObjList = [] |
|
30 | integratorObjList = [] | |
30 |
|
31 | |||
31 | decoderObjList = [] |
|
32 | decoderObjList = [] | |
32 |
|
33 | |||
33 | writerObjList = [] |
|
34 | writerObjList = [] | |
34 |
|
35 | |||
35 | plotterObjList = [] |
|
36 | plotterObjList = [] | |
36 |
|
37 | |||
37 | integratorObjIndex = None |
|
38 | integratorObjIndex = None | |
38 |
|
39 | |||
39 | decoderObjIndex = None |
|
40 | decoderObjIndex = None | |
40 |
|
41 | |||
41 | writerObjIndex = None |
|
42 | writerObjIndex = None | |
42 |
|
43 | |||
43 | plotterObjIndex = None |
|
44 | plotterObjIndex = None | |
44 |
|
45 | |||
45 | buffer = None |
|
46 | buffer = None | |
46 |
|
47 | |||
47 | profIndex = 0 |
|
48 | profIndex = 0 | |
48 |
|
49 | |||
49 | nFFTPoints = None |
|
50 | nFFTPoints = None | |
50 |
|
51 | |||
51 | nChannels = None |
|
52 | nChannels = None | |
52 |
|
53 | |||
53 | nHeights = None |
|
54 | nHeights = None | |
54 |
|
55 | |||
55 | nPairs = None |
|
56 | nPairs = None | |
56 |
|
57 | |||
57 | pairList = None |
|
58 | pairList = None | |
58 |
|
59 | |||
59 |
|
60 | |||
60 | def __init__(self): |
|
61 | def __init__(self): | |
61 | ''' |
|
62 | ''' | |
62 | Constructor |
|
63 | Constructor | |
63 | ''' |
|
64 | ''' | |
64 |
|
65 | |||
65 | self.integratorObjIndex = None |
|
66 | self.integratorObjIndex = None | |
66 | self.decoderObjIndex = None |
|
67 | self.decoderObjIndex = None | |
67 | self.writerObjIndex = None |
|
68 | self.writerObjIndex = None | |
68 | self.plotterObjIndex = None |
|
69 | self.plotterObjIndex = None | |
69 |
|
70 | |||
70 | self.integratorObjList = [] |
|
71 | self.integratorObjList = [] | |
71 | self.decoderObjList = [] |
|
72 | self.decoderObjList = [] | |
72 | self.writerObjList = [] |
|
73 | self.writerObjList = [] | |
73 | self.plotterObjList = [] |
|
74 | self.plotterObjList = [] | |
74 |
|
75 | |||
75 | self.noiseObj = Noise() |
|
76 | self.noiseObj = Noise() | |
76 | self.buffer = None |
|
77 | self.buffer = None | |
77 | self.profIndex = 0 |
|
78 | self.profIndex = 0 | |
78 |
|
79 | |||
79 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
80 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): | |
80 |
|
81 | |||
81 | if dataInObj == None: |
|
82 | if dataInObj == None: | |
82 | raise ValueError, "" |
|
83 | raise ValueError, "" | |
83 |
|
84 | |||
84 | if nFFTPoints == None: |
|
85 | if nFFTPoints == None: | |
85 | raise ValueError, "" |
|
86 | raise ValueError, "" | |
86 |
|
87 | |||
87 | self.dataInObj = dataInObj |
|
88 | self.dataInObj = dataInObj | |
88 |
|
89 | |||
89 | if dataOutObj == None: |
|
90 | if dataOutObj == None: | |
90 | dataOutObj = Spectra() |
|
91 | dataOutObj = Spectra() | |
91 |
|
92 | |||
92 | self.dataOutObj = dataOutObj |
|
93 | self.dataOutObj = dataOutObj | |
93 | self.noiseObj = Noise() |
|
94 | self.noiseObj = Noise() | |
94 |
|
95 | |||
95 | ########################################## |
|
96 | ########################################## | |
96 | self.nFFTPoints = nFFTPoints |
|
97 | self.nFFTPoints = nFFTPoints | |
97 | self.nChannels = self.dataInObj.nChannels |
|
98 | self.nChannels = self.dataInObj.nChannels | |
98 | self.nHeights = self.dataInObj.nHeights |
|
99 | self.nHeights = self.dataInObj.nHeights | |
99 | self.pairList = pairList |
|
100 | self.pairList = pairList | |
100 | if pairList != None: |
|
101 | if pairList != None: | |
101 | self.nPairs = len(pairList) |
|
102 | self.nPairs = len(pairList) | |
102 | else: |
|
103 | else: | |
103 | self.nPairs = 0 |
|
104 | self.nPairs = 0 | |
104 |
|
105 | |||
105 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
106 | self.dataOutObj.heightList = self.dataInObj.heightList | |
106 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
107 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |
107 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
108 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() | |
108 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
109 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() | |
109 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
110 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() | |
110 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
111 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() | |
111 |
|
112 | |||
112 | self.dataOutObj.dataType = self.dataInObj.dataType |
|
113 | self.dataOutObj.dataType = self.dataInObj.dataType | |
113 | self.dataOutObj.nPairs = self.nPairs |
|
114 | self.dataOutObj.nPairs = self.nPairs | |
114 | self.dataOutObj.nChannels = self.nChannels |
|
115 | self.dataOutObj.nChannels = self.nChannels | |
115 | self.dataOutObj.nProfiles = self.nFFTPoints |
|
116 | self.dataOutObj.nProfiles = self.nFFTPoints | |
116 | self.dataOutObj.nHeights = self.nHeights |
|
117 | self.dataOutObj.nHeights = self.nHeights | |
117 | self.dataOutObj.nFFTPoints = self.nFFTPoints |
|
118 | self.dataOutObj.nFFTPoints = self.nFFTPoints | |
118 | #self.dataOutObj.data = None |
|
119 | #self.dataOutObj.data = None | |
119 |
|
120 | |||
120 | self.dataOutObj.m_SystemHeader.numChannels = self.nChannels |
|
121 | self.dataOutObj.m_SystemHeader.numChannels = self.nChannels | |
121 | self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints |
|
122 | self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints | |
122 |
|
123 | |||
123 | self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs |
|
124 | self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs | |
124 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints |
|
125 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints | |
125 | self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights |
|
126 | self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights | |
126 | self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
127 | self.dataOutObj.m_ProcessingHeader.shif_fft = True | |
127 |
|
128 | |||
128 | spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) |
|
129 | spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) | |
129 | k = 0 |
|
130 | k = 0 | |
130 | for i in range( 0,self.nChannels*2,2 ): |
|
131 | for i in range( 0,self.nChannels*2,2 ): | |
131 | spectraComb[i] = k |
|
132 | spectraComb[i] = k | |
132 | spectraComb[i+1] = k |
|
133 | spectraComb[i+1] = k | |
133 | k += 1 |
|
134 | k += 1 | |
134 |
|
135 | |||
135 | k *= 2 |
|
136 | k *= 2 | |
136 |
|
137 | |||
137 | if self.pairList != None: |
|
138 | if self.pairList != None: | |
138 |
|
139 | |||
139 | for pair in self.pairList: |
|
140 | for pair in self.pairList: | |
140 | spectraComb[k] = pair[0] |
|
141 | spectraComb[k] = pair[0] | |
141 | spectraComb[k+1] = pair[1] |
|
142 | spectraComb[k+1] = pair[1] | |
142 | k += 2 |
|
143 | k += 2 | |
143 |
|
144 | |||
144 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
145 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb | |
145 |
|
146 | |||
146 | return self.dataOutObj |
|
147 | return self.dataOutObj | |
147 |
|
148 | |||
148 | def init(self): |
|
149 | def init(self): | |
149 |
|
150 | |||
150 | self.integratorObjIndex = 0 |
|
151 | self.integratorObjIndex = 0 | |
151 | self.decoderObjIndex = 0 |
|
152 | self.decoderObjIndex = 0 | |
152 | self.writerObjIndex = 0 |
|
153 | self.writerObjIndex = 0 | |
153 | self.plotterObjIndex = 0 |
|
154 | self.plotterObjIndex = 0 | |
154 |
|
155 | |||
155 | if self.dataInObj.type == "Voltage": |
|
156 | if self.dataInObj.type == "Voltage": | |
156 |
|
157 | |||
157 | if self.buffer == None: |
|
158 | if self.buffer == None: | |
158 | self.buffer = numpy.zeros((self.nChannels, |
|
159 | self.buffer = numpy.zeros((self.nChannels, | |
159 | self.nFFTPoints, |
|
160 | self.nFFTPoints, | |
160 | self.nHeights), |
|
161 | self.nHeights), | |
161 | dtype='complex') |
|
162 | dtype='complex') | |
162 |
|
163 | |||
163 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
164 | self.buffer[:,self.profIndex,:] = self.dataInObj.data | |
164 | self.profIndex += 1 |
|
165 | self.profIndex += 1 | |
165 |
|
166 | |||
166 |
if self.profIndex == self.nFFTPoints: |
|
167 | if self.profIndex == self.nFFTPoints: | |
167 | self.__getFft() |
|
168 | self.__getFft() | |
168 | self.dataOutObj.flagNoData = False |
|
169 | self.dataOutObj.flagNoData = False | |
169 |
|
170 | |||
170 | self.buffer = None |
|
171 | self.buffer = None | |
171 | self.profIndex = 0 |
|
172 | self.profIndex = 0 | |
172 | return |
|
173 | return | |
173 |
|
174 | |||
174 | self.dataOutObj.flagNoData = True |
|
175 | self.dataOutObj.flagNoData = True | |
175 |
|
176 | |||
176 | return |
|
177 | return | |
177 |
|
178 | |||
178 | #Other kind of data |
|
179 | #Other kind of data | |
179 | if self.dataInObj.type == "Spectra": |
|
180 | if self.dataInObj.type == "Spectra": | |
180 | self.dataOutObj.copy(self.dataInObj) |
|
181 | self.dataOutObj.copy(self.dataInObj) | |
181 | self.dataOutObj.flagNoData = False |
|
182 | self.dataOutObj.flagNoData = False | |
182 | return |
|
183 | return | |
183 |
|
184 | |||
184 | raise ValueError, "The datatype is not valid" |
|
185 | raise ValueError, "The datatype is not valid" | |
185 |
|
186 | |||
186 | def __getFft(self): |
|
187 | def __getFft(self): | |
187 | """ |
|
188 | """ | |
188 | Convierte valores de Voltaje a Spectra |
|
189 | Convierte valores de Voltaje a Spectra | |
189 |
|
190 | |||
190 | Affected: |
|
191 | Affected: | |
191 | self.dataOutObj.data_spc |
|
192 | self.dataOutObj.data_spc | |
192 | self.dataOutObj.data_cspc |
|
193 | self.dataOutObj.data_cspc | |
193 | self.dataOutObj.data_dc |
|
194 | self.dataOutObj.data_dc | |
194 | self.dataOutObj.heightList |
|
195 | self.dataOutObj.heightList | |
195 | self.dataOutObj.m_BasicHeader |
|
196 | self.dataOutObj.m_BasicHeader | |
196 | self.dataOutObj.m_ProcessingHeader |
|
197 | self.dataOutObj.m_ProcessingHeader | |
197 | self.dataOutObj.m_RadarControllerHeader |
|
198 | self.dataOutObj.m_RadarControllerHeader | |
198 | self.dataOutObj.m_SystemHeader |
|
199 | self.dataOutObj.m_SystemHeader | |
199 | self.profIndex |
|
200 | self.profIndex | |
200 | self.buffer |
|
201 | self.buffer | |
201 | self.dataOutObj.flagNoData |
|
202 | self.dataOutObj.flagNoData | |
202 | self.dataOutObj.dataType |
|
203 | self.dataOutObj.dataType | |
203 | self.dataOutObj.nPairs |
|
204 | self.dataOutObj.nPairs | |
204 | self.dataOutObj.nChannels |
|
205 | self.dataOutObj.nChannels | |
205 | self.dataOutObj.nProfiles |
|
206 | self.dataOutObj.nProfiles | |
206 | self.dataOutObj.m_SystemHeader.numChannels |
|
207 | self.dataOutObj.m_SystemHeader.numChannels | |
207 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
208 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
208 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
209 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
209 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
210 | self.dataOutObj.m_ProcessingHeader.numHeights | |
210 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
211 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
211 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
212 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
212 | """ |
|
213 | """ | |
|
214 | ||||
213 | if self.dataInObj.flagNoData: |
|
215 | if self.dataInObj.flagNoData: | |
214 | return 0 |
|
216 | return 0 | |
215 |
|
217 | |||
216 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
218 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
217 | dc = fft_volt[:,0,:] |
|
219 | dc = fft_volt[:,0,:] | |
218 |
|
220 | |||
219 | #calculo de self-spectra |
|
221 | #calculo de self-spectra | |
220 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
222 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
221 |
spc = |
|
223 | spc = fft_volt * numpy.conjugate(fft_volt) | |
|
224 | spc = spc.real | |||
222 |
|
225 | |||
223 | blocksize = 0 |
|
226 | blocksize = 0 | |
224 | blocksize += dc.size |
|
227 | blocksize += dc.size | |
225 | blocksize += spc.size |
|
228 | blocksize += spc.size | |
226 |
|
229 | |||
227 | cspc = None |
|
230 | cspc = None | |
228 | pairIndex = 0 |
|
231 | pairIndex = 0 | |
229 | if self.pairList != None: |
|
232 | if self.pairList != None: | |
230 | #calculo de cross-spectra |
|
233 | #calculo de cross-spectra | |
231 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') |
|
234 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') | |
232 | for pair in self.pairList: |
|
235 | for pair in self.pairList: | |
233 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
236 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
234 | pairIndex += 1 |
|
237 | pairIndex += 1 | |
235 | blocksize += cspc.size |
|
238 | blocksize += cspc.size | |
236 |
|
239 | |||
237 | self.dataOutObj.data_spc = spc |
|
240 | self.dataOutObj.data_spc = spc | |
238 | self.dataOutObj.data_cspc = cspc |
|
241 | self.dataOutObj.data_cspc = cspc | |
239 | self.dataOutObj.data_dc = dc |
|
242 | self.dataOutObj.data_dc = dc | |
240 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
243 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
241 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc |
|
244 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc | |
242 |
|
245 | |||
243 | self.getNoise() |
|
246 | # self.getNoise() | |
244 |
|
247 | |||
245 | def addWriter(self,wrpath): |
|
248 | def addWriter(self,wrpath): | |
246 | objWriter = SpectraWriter(self.dataOutObj) |
|
249 | objWriter = SpectraWriter(self.dataOutObj) | |
247 | objWriter.setup(wrpath) |
|
250 | objWriter.setup(wrpath) | |
248 | self.writerObjList.append(objWriter) |
|
251 | self.writerObjList.append(objWriter) | |
249 |
|
252 | |||
250 | def addPlotter(self,index=None): |
|
253 | def addPlotter(self,index=None): | |
251 | if index==None: |
|
254 | if index==None: | |
252 | index = self.plotterObjIndex |
|
255 | index = self.plotterObjIndex | |
253 |
|
256 | |||
254 | plotObj = Spectrum(self.dataOutObj, index) |
|
257 | plotObj = Spectrum(self.dataOutObj, index) | |
255 | self.plotterObjList.append(plotObj) |
|
258 | self.plotterObjList.append(plotObj) | |
256 |
|
259 | |||
257 | def addIntegrator(self,N,timeInterval): |
|
260 | def addIntegrator(self,N,timeInterval): | |
258 |
|
261 | |||
259 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
262 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
260 | self.integratorObjList.append(objIncohInt) |
|
263 | self.integratorObjList.append(objIncohInt) | |
261 |
|
264 | |||
262 | def writeData(self, wrpath): |
|
265 | def writeData(self, wrpath): | |
263 | if self.dataOutObj.flagNoData: |
|
266 | if self.dataOutObj.flagNoData: | |
264 | return 0 |
|
267 | return 0 | |
265 |
|
268 | |||
266 | if len(self.writerObjList) <= self.writerObjIndex: |
|
269 | if len(self.writerObjList) <= self.writerObjIndex: | |
267 | self.addWriter(wrpath) |
|
270 | self.addWriter(wrpath) | |
268 |
|
271 | |||
269 | self.writerObjList[self.writerObjIndex].putData() |
|
272 | self.writerObjList[self.writerObjIndex].putData() | |
270 |
|
273 | |||
271 | self.writerObjIndex += 1 |
|
274 | self.writerObjIndex += 1 | |
272 |
|
275 | |||
273 | def plotData(self, |
|
276 | def plotData(self, | |
274 | xmin=None, |
|
277 | xmin=None, | |
275 | xmax=None, |
|
278 | xmax=None, | |
276 | ymin=None, |
|
279 | ymin=None, | |
277 | ymax=None, |
|
280 | ymax=None, | |
278 | zmin=None, |
|
281 | zmin=None, | |
279 | zmax=None, |
|
282 | zmax=None, | |
280 | titleList=None, |
|
283 | titleList=None, | |
281 | xlabelList=None, |
|
284 | xlabelList=None, | |
282 | ylabelList=None, |
|
285 | ylabelList=None, | |
283 | winTitle='', |
|
286 | winTitle='', | |
284 | colormap="br_green", |
|
287 | colormap="br_green", | |
285 | showColorbar=False, |
|
288 | showColorbar=False, | |
286 | showPowerProfile=False, |
|
289 | showPowerProfile=False, | |
287 | XAxisAsTime=False, |
|
290 | XAxisAsTime=False, | |
288 | save=False, |
|
291 | save=False, | |
289 |
index=None |
|
292 | index=None, | |
|
293 | channelList=[]): | |||
290 |
|
294 | |||
291 | if self.dataOutObj.flagNoData: |
|
295 | if self.dataOutObj.flagNoData: | |
292 | return 0 |
|
296 | return 0 | |
293 |
|
297 | |||
294 | if len(self.plotterObjList) <= self.plotterObjIndex: |
|
298 | if len(self.plotterObjList) <= self.plotterObjIndex: | |
295 | self.addPlotter(index) |
|
299 | self.addPlotter(index) | |
296 |
|
300 | |||
297 | self.plotterObjList[self.plotterObjIndex].plotData(xmin, |
|
301 | self.plotterObjList[self.plotterObjIndex].plotData(xmin, | |
298 | xmax, |
|
302 | xmax, | |
299 | ymin, |
|
303 | ymin, | |
300 | ymax, |
|
304 | ymax, | |
301 | zmin, |
|
305 | zmin, | |
302 | zmax, |
|
306 | zmax, | |
303 | titleList, |
|
307 | titleList, | |
304 | xlabelList, |
|
308 | xlabelList, | |
305 | ylabelList, |
|
309 | ylabelList, | |
306 | winTitle, |
|
310 | winTitle, | |
307 | colormap, |
|
311 | colormap, | |
308 | showColorbar, |
|
312 | showColorbar, | |
309 | showPowerProfile, |
|
313 | showPowerProfile, | |
310 | XAxisAsTime, |
|
314 | XAxisAsTime, | |
311 |
save |
|
315 | save, | |
|
316 | channelList) | |||
312 |
|
317 | |||
313 | self.plotterObjIndex += 1 |
|
318 | self.plotterObjIndex += 1 | |
314 |
|
319 | |||
315 | def integrator(self, N=None, timeInterval=None): |
|
320 | def integrator(self, N=None, timeInterval=None): | |
316 |
|
321 | |||
317 | if self.dataOutObj.flagNoData: |
|
322 | if self.dataOutObj.flagNoData: | |
318 | return 0 |
|
323 | return 0 | |
319 |
|
324 | |||
320 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
325 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
321 | self.addIntegrator(N,timeInterval) |
|
326 | self.addIntegrator(N,timeInterval) | |
322 |
|
327 | |||
323 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
328 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
324 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
329 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) | |
325 |
|
330 | |||
326 | if myIncohIntObj.isReady: |
|
331 | if myIncohIntObj.isReady: | |
327 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
332 | self.dataOutObj.data_spc = myIncohIntObj.data | |
328 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
333 | self.dataOutObj.nAvg = myIncohIntObj.navg | |
329 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg |
|
334 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg | |
330 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg |
|
335 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg | |
331 | self.dataOutObj.flagNoData = False |
|
336 | self.dataOutObj.flagNoData = False | |
332 |
|
|
337 | ||
333 | self.getNoise(type="hildebrand") |
|
338 | """Calcular el ruido""" | |
334 |
|
|
339 | self.getNoise() | |
335 |
|
||||
336 | else: |
|
340 | else: | |
337 | self.dataOutObj.flagNoData = True |
|
341 | self.dataOutObj.flagNoData = True | |
338 |
|
342 | |||
339 | self.integratorObjIndex += 1 |
|
343 | self.integratorObjIndex += 1 | |
340 |
|
344 | |||
341 | """Calcular el ruido""" |
|
345 | ||
342 | # self.getNoise(type="hildebrand", parm=1) |
|
|||
343 |
|
346 | |||
344 | def removeDC(self, type): |
|
347 | def removeDC(self, type): | |
345 |
|
348 | |||
346 | if self.dataOutObj.flagNoData: |
|
349 | if self.dataOutObj.flagNoData: | |
347 | return 0 |
|
350 | return 0 | |
348 |
|
351 | |||
349 | def removeInterference(self): |
|
352 | def removeInterference(self): | |
350 |
|
353 | |||
351 | if self.dataOutObj.flagNoData: |
|
354 | if self.dataOutObj.flagNoData: | |
352 | return 0 |
|
355 | return 0 | |
353 |
|
356 | |||
354 | def removeSatellites(self): |
|
357 | def removeSatellites(self): | |
355 |
|
358 | |||
356 | if self.dataOutObj.flagNoData: |
|
359 | if self.dataOutObj.flagNoData: | |
357 | return 0 |
|
360 | return 0 | |
358 |
|
361 | |||
359 | def getNoise(self, type="hildebrand", parm=None): |
|
362 | def getNoise(self, type="hildebrand", parm=None): | |
360 |
|
363 | |||
361 | if parm == None: |
|
364 | if parm == None: | |
362 | parm =self.dataOutObj.m_ProcessingHeader.incoherentInt |
|
365 | parm =self.dataOutObj.m_ProcessingHeader.incoherentInt | |
363 |
|
366 | |||
364 | self.noiseObj.setNoise(self.dataOutObj.data_spc) |
|
367 | self.noiseObj.setNoise(self.dataOutObj.data_spc) | |
365 |
|
368 | |||
366 | if type == "hildebrand": |
|
369 | if type == "hildebrand": | |
367 | noise = self.noiseObj.byHildebrand(parm) |
|
370 | noise = self.noiseObj.byHildebrand(parm) | |
368 |
|
371 | |||
369 | if type == "window": |
|
372 | if type == "window": | |
370 | noise = self.noiseObj.byWindow(parm) |
|
373 | noise = self.noiseObj.byWindow(parm) | |
371 |
|
374 | |||
372 | if type == "sort": |
|
375 | if type == "sort": | |
373 | noise = self.noiseObj.bySort(parm) |
|
376 | noise = self.noiseObj.bySort(parm) | |
374 |
|
377 | |||
375 | self.dataOutObj.noise = noise |
|
378 | self.dataOutObj.noise = noise | |
376 | # print 10*numpy.log10(noise) |
|
379 | # print 10*numpy.log10(noise) | |
377 |
|
380 | |||
378 | def selectChannels(self, channelList, pairList=[]): |
|
381 | def selectChannels(self, channelList, pairList=[]): | |
379 |
|
382 | |||
380 | channelIndexList = [] |
|
383 | channelIndexList = [] | |
381 |
|
384 | |||
382 | for channel in channelList: |
|
385 | for channel in channelList: | |
383 | if channel in self.dataOutObj.channelList: |
|
386 | if channel in self.dataOutObj.channelList: | |
384 | index = self.dataOutObj.channelList.index(channel) |
|
387 | index = self.dataOutObj.channelList.index(channel) | |
385 | channelIndexList.append(index) |
|
388 | channelIndexList.append(index) | |
386 |
|
389 | |||
387 | pairIndexList = [] |
|
390 | pairIndexList = [] | |
388 |
|
391 | |||
389 | for pair in pairList: |
|
392 | for pair in pairList: | |
390 | if pair in self.dataOutObj.pairList: |
|
393 | if pair in self.dataOutObj.pairList: | |
391 | index = self.dataOutObj.pairList.index(pair) |
|
394 | index = self.dataOutObj.pairList.index(pair) | |
392 | pairIndexList.append(index) |
|
395 | pairIndexList.append(index) | |
393 |
|
396 | |||
394 | self.selectChannelsByIndex(channelIndexList, pairIndexList) |
|
397 | self.selectChannelsByIndex(channelIndexList, pairIndexList) | |
395 |
|
398 | |||
396 | def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]): |
|
399 | def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]): | |
397 | """ |
|
400 | """ | |
398 | Selecciona un bloque de datos en base a canales y pares segun el |
|
401 | Selecciona un bloque de datos en base a canales y pares segun el | |
399 | channelIndexList y el pairIndexList |
|
402 | channelIndexList y el pairIndexList | |
400 |
|
403 | |||
401 | Input: |
|
404 | Input: | |
402 | channelIndexList : lista de indices de los canales a seleccionar por ej. |
|
405 | channelIndexList : lista de indices de los canales a seleccionar por ej. | |
403 |
|
406 | |||
404 | Si tenemos los canales |
|
407 | Si tenemos los canales | |
405 |
|
408 | |||
406 | self.channelList = (2,3,5,7) |
|
409 | self.channelList = (2,3,5,7) | |
407 |
|
410 | |||
408 | y deseamos escoger los canales (3,7) |
|
411 | y deseamos escoger los canales (3,7) | |
409 | entonces colocaremos el parametro |
|
412 | entonces colocaremos el parametro | |
410 |
|
413 | |||
411 | channelndexList = (1,3) |
|
414 | channelndexList = (1,3) | |
412 |
|
415 | |||
413 | pairIndexList : tupla de indice depares que se desea selecionar por ej. |
|
416 | pairIndexList : tupla de indice depares que se desea selecionar por ej. | |
414 |
|
417 | |||
415 | Si tenemos los pares : |
|
418 | Si tenemos los pares : | |
416 |
|
419 | |||
417 | ( (0,1), (0,2), (1,3), (2,5) ) |
|
420 | ( (0,1), (0,2), (1,3), (2,5) ) | |
418 |
|
421 | |||
419 | y deseamos seleccionar los pares ((0,2), (2,5)) |
|
422 | y deseamos seleccionar los pares ((0,2), (2,5)) | |
420 | entonces colocaremos el parametro |
|
423 | entonces colocaremos el parametro | |
421 |
|
424 | |||
422 | pairIndexList = (1,3) |
|
425 | pairIndexList = (1,3) | |
423 |
|
426 | |||
424 | Affected: |
|
427 | Affected: | |
425 | self.dataOutObj.data_spc |
|
428 | self.dataOutObj.data_spc | |
426 | self.dataOutObj.data_cspc |
|
429 | self.dataOutObj.data_cspc | |
427 | self.dataOutObj.data_dc |
|
430 | self.dataOutObj.data_dc | |
428 | self.dataOutObj.nChannels |
|
431 | self.dataOutObj.nChannels | |
429 | self.dataOutObj.nPairs |
|
432 | self.dataOutObj.nPairs | |
430 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
433 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
431 | self.dataOutObj.m_SystemHeader.numChannels |
|
434 | self.dataOutObj.m_SystemHeader.numChannels | |
432 |
|
435 | |||
433 | self.dataOutObj.noise |
|
436 | self.dataOutObj.noise | |
434 | Return: |
|
437 | Return: | |
435 | None |
|
438 | None | |
436 | """ |
|
439 | """ | |
437 |
|
440 | |||
438 | if self.dataOutObj.flagNoData: |
|
441 | if self.dataOutObj.flagNoData: | |
439 | return 0 |
|
442 | return 0 | |
440 |
|
443 | |||
441 | if pairIndexList == []: |
|
444 | if pairIndexList == []: | |
442 | pairIndexList = numpy.arange(len(self.dataOutObj.pairList)) |
|
445 | pairIndexList = numpy.arange(len(self.dataOutObj.pairList)) | |
443 |
|
446 | |||
444 | nChannels = len(channelIndexList) |
|
447 | nChannels = len(channelIndexList) | |
445 | nPairs = len(pairIndexList) |
|
448 | nPairs = len(pairIndexList) | |
446 |
|
449 | |||
447 | blocksize = 0 |
|
450 | blocksize = 0 | |
448 | #self spectra |
|
451 | #self spectra | |
449 | spc = self.dataOutObj.data_spc[channelIndexList,:,:] |
|
452 | spc = self.dataOutObj.data_spc[channelIndexList,:,:] | |
450 | blocksize += spc.size |
|
453 | blocksize += spc.size | |
451 |
|
454 | |||
452 | cspc = None |
|
455 | cspc = None | |
453 | if pairIndexList != []: |
|
456 | if pairIndexList != []: | |
454 | cspc = self.dataOutObj.data_cspc[pairIndexList,:,:] |
|
457 | cspc = self.dataOutObj.data_cspc[pairIndexList,:,:] | |
455 | blocksize += cspc.size |
|
458 | blocksize += cspc.size | |
456 |
|
459 | |||
457 | #DC channel |
|
460 | #DC channel | |
458 | dc = None |
|
461 | dc = None | |
459 | if self.dataOutObj.m_ProcessingHeader.flag_dc: |
|
462 | if self.dataOutObj.m_ProcessingHeader.flag_dc: | |
460 | dc = self.dataOutObj.data_dc[channelIndexList,:] |
|
463 | dc = self.dataOutObj.data_dc[channelIndexList,:] | |
461 | blocksize += dc.size |
|
464 | blocksize += dc.size | |
462 |
|
465 | |||
463 | #Almacenar las combinaciones de canales y cros espectros |
|
466 | #Almacenar las combinaciones de canales y cros espectros | |
464 |
|
467 | |||
465 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) |
|
468 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) | |
466 | i = 0 |
|
469 | i = 0 | |
467 | for spcChannel in channelIndexList: |
|
470 | for spcChannel in channelIndexList: | |
468 | spectraComb[i] = spcChannel |
|
471 | spectraComb[i] = spcChannel | |
469 | spectraComb[i+1] = spcChannel |
|
472 | spectraComb[i+1] = spcChannel | |
470 | i += 2 |
|
473 | i += 2 | |
471 |
|
474 | |||
472 | if pairList != None: |
|
475 | if pairList != None: | |
473 | for pair in pairList: |
|
476 | for pair in pairList: | |
474 | spectraComb[i] = pair[0] |
|
477 | spectraComb[i] = pair[0] | |
475 | spectraComb[i+1] = pair[1] |
|
478 | spectraComb[i+1] = pair[1] | |
476 | i += 2 |
|
479 | i += 2 | |
477 |
|
480 | |||
478 | ####### |
|
481 | ####### | |
479 |
|
482 | |||
480 | self.dataOutObj.data_spc = spc |
|
483 | self.dataOutObj.data_spc = spc | |
481 | self.dataOutObj.data_cspc = cspc |
|
484 | self.dataOutObj.data_cspc = cspc | |
482 | self.dataOutObj.data_dc = dc |
|
485 | self.dataOutObj.data_dc = dc | |
483 | self.dataOutObj.nChannels = nChannels |
|
486 | self.dataOutObj.nChannels = nChannels | |
484 | self.dataOutObj.nPairs = nPairs |
|
487 | self.dataOutObj.nPairs = nPairs | |
485 |
|
488 | |||
486 | self.dataOutObj.channelIndexList = channelIndexList |
|
489 | self.dataOutObj.channelIndexList = channelIndexList | |
487 |
|
490 | |||
488 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
491 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb | |
489 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs |
|
492 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs | |
490 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
493 | self.dataOutObj.m_SystemHeader.numChannels = nChannels | |
491 | self.dataOutObj.nChannels = nChannels |
|
494 | self.dataOutObj.nChannels = nChannels | |
492 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
495 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
493 |
|
496 | |||
494 | if cspc == None: |
|
497 | if cspc == None: | |
495 | self.dataOutObj.m_ProcessingHeader.flag_dc = False |
|
498 | self.dataOutObj.m_ProcessingHeader.flag_dc = False | |
496 | if dc == None: |
|
499 | if dc == None: | |
497 | self.dataOutObj.m_ProcessingHeader.flag_cpsc = False |
|
500 | self.dataOutObj.m_ProcessingHeader.flag_cpsc = False | |
498 |
|
501 | |||
499 | def selectHeightsByValue(self, minHei, maxHei): |
|
502 | def selectHeightsByValue(self, minHei, maxHei): | |
500 | """ |
|
503 | """ | |
501 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
504 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
502 | minHei <= height <= maxHei |
|
505 | minHei <= height <= maxHei | |
503 |
|
506 | |||
504 | Input: |
|
507 | Input: | |
505 | minHei : valor minimo de altura a considerar |
|
508 | minHei : valor minimo de altura a considerar | |
506 | maxHei : valor maximo de altura a considerar |
|
509 | maxHei : valor maximo de altura a considerar | |
507 |
|
510 | |||
508 | Affected: |
|
511 | Affected: | |
509 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
512 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
510 |
|
513 | |||
511 | Return: |
|
514 | Return: | |
512 | None |
|
515 | None | |
513 | """ |
|
516 | """ | |
514 |
|
517 | |||
515 | if self.dataOutObj.flagNoData: |
|
518 | if self.dataOutObj.flagNoData: | |
516 | return 0 |
|
519 | return 0 | |
517 |
|
520 | |||
518 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): |
|
521 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): | |
519 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
522 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
520 |
|
523 | |||
521 | if (maxHei > self.dataOutObj.heightList[-1]): |
|
524 | if (maxHei > self.dataOutObj.heightList[-1]): | |
522 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
525 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
523 |
|
526 | |||
524 | minIndex = 0 |
|
527 | minIndex = 0 | |
525 | maxIndex = 0 |
|
528 | maxIndex = 0 | |
526 | data = self.dataOutObj.heightList |
|
529 | data = self.dataOutObj.heightList | |
527 |
|
530 | |||
528 | for i,val in enumerate(data): |
|
531 | for i,val in enumerate(data): | |
529 | if val < minHei: |
|
532 | if val < minHei: | |
530 | continue |
|
533 | continue | |
531 | else: |
|
534 | else: | |
532 | minIndex = i; |
|
535 | minIndex = i; | |
533 | break |
|
536 | break | |
534 |
|
537 | |||
535 | for i,val in enumerate(data): |
|
538 | for i,val in enumerate(data): | |
536 | if val <= maxHei: |
|
539 | if val <= maxHei: | |
537 | maxIndex = i; |
|
540 | maxIndex = i; | |
538 | else: |
|
541 | else: | |
539 | break |
|
542 | break | |
540 |
|
543 | |||
541 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
544 | self.selectHeightsByIndex(minIndex, maxIndex) | |
542 |
|
545 | |||
543 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
546 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
544 | """ |
|
547 | """ | |
545 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
548 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
546 | minIndex <= index <= maxIndex |
|
549 | minIndex <= index <= maxIndex | |
547 |
|
550 | |||
548 | Input: |
|
551 | Input: | |
549 | minIndex : valor minimo de altura a considerar |
|
552 | minIndex : valor minimo de altura a considerar | |
550 | maxIndex : valor maximo de altura a considerar |
|
553 | maxIndex : valor maximo de altura a considerar | |
551 |
|
554 | |||
552 | Affected: |
|
555 | Affected: | |
553 | self.dataOutObj.data_spc |
|
556 | self.dataOutObj.data_spc | |
554 | self.dataOutObj.data_cspc |
|
557 | self.dataOutObj.data_cspc | |
555 | self.dataOutObj.data_dc |
|
558 | self.dataOutObj.data_dc | |
556 | self.dataOutObj.heightList |
|
559 | self.dataOutObj.heightList | |
557 | self.dataOutObj.nHeights |
|
560 | self.dataOutObj.nHeights | |
558 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
561 | self.dataOutObj.m_ProcessingHeader.numHeights | |
559 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
562 | self.dataOutObj.m_ProcessingHeader.blockSize | |
560 | self.dataOutObj.m_ProcessingHeader.firstHeight |
|
563 | self.dataOutObj.m_ProcessingHeader.firstHeight | |
561 | self.dataOutObj.m_RadarControllerHeader.numHeights |
|
564 | self.dataOutObj.m_RadarControllerHeader.numHeights | |
562 |
|
565 | |||
563 | Return: |
|
566 | Return: | |
564 | None |
|
567 | None | |
565 | """ |
|
568 | """ | |
566 |
|
569 | |||
567 | if self.dataOutObj.flagNoData: |
|
570 | if self.dataOutObj.flagNoData: | |
568 | return 0 |
|
571 | return 0 | |
569 |
|
572 | |||
570 | if (minIndex < 0) or (minIndex > maxIndex): |
|
573 | if (minIndex < 0) or (minIndex > maxIndex): | |
571 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
574 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
572 |
|
575 | |||
573 | if (maxIndex >= self.dataOutObj.nHeights): |
|
576 | if (maxIndex >= self.dataOutObj.nHeights): | |
574 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
577 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
575 |
|
578 | |||
576 | nChannels = self.dataOutObj.nChannels |
|
579 | nChannels = self.dataOutObj.nChannels | |
577 | nPairs = self.dataOutObj.nPairs |
|
580 | nPairs = self.dataOutObj.nPairs | |
578 | nProfiles = self.dataOutObj.nProfiles |
|
581 | nProfiles = self.dataOutObj.nProfiles | |
579 | dataType = self.dataOutObj.dataType |
|
582 | dataType = self.dataOutObj.dataType | |
580 | nHeights = maxIndex - minIndex + 1 |
|
583 | nHeights = maxIndex - minIndex + 1 | |
581 | blockSize = 0 |
|
584 | blockSize = 0 | |
582 |
|
585 | |||
583 | #self spectra |
|
586 | #self spectra | |
584 | spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1] |
|
587 | spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1] | |
585 | blockSize += spc.size |
|
588 | blockSize += spc.size | |
586 |
|
589 | |||
587 | #cross spectra |
|
590 | #cross spectra | |
588 | cspc = None |
|
591 | cspc = None | |
589 | if self.dataOutObj.data_cspc != None: |
|
592 | if self.dataOutObj.data_cspc != None: | |
590 | cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1] |
|
593 | cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1] | |
591 | blockSize += cspc.size |
|
594 | blockSize += cspc.size | |
592 |
|
595 | |||
593 | #DC channel |
|
596 | #DC channel | |
594 | dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1] |
|
597 | dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1] | |
595 | blockSize += dc.size |
|
598 | blockSize += dc.size | |
596 |
|
599 | |||
597 | self.dataOutObj.data_spc = spc |
|
600 | self.dataOutObj.data_spc = spc | |
598 | if cspc != None: |
|
601 | if cspc != None: | |
599 | self.dataOutObj.data_cspc = cspc |
|
602 | self.dataOutObj.data_cspc = cspc | |
600 | self.dataOutObj.data_dc = dc |
|
603 | self.dataOutObj.data_dc = dc | |
601 |
|
604 | |||
602 | firstHeight = self.dataOutObj.heightList[minIndex] |
|
605 | firstHeight = self.dataOutObj.heightList[minIndex] | |
603 |
|
606 | |||
604 | self.dataOutObj.nHeights = nHeights |
|
607 | self.dataOutObj.nHeights = nHeights | |
605 | self.dataOutObj.m_ProcessingHeader.blockSize = blockSize |
|
608 | self.dataOutObj.m_ProcessingHeader.blockSize = blockSize | |
606 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights |
|
609 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights | |
607 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight |
|
610 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight | |
608 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights |
|
611 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights | |
609 |
|
612 | |||
610 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] |
|
613 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] | |
611 |
|
614 | |||
612 |
|
615 | |||
613 | class IncoherentIntegration: |
|
616 | class IncoherentIntegration: | |
614 |
|
617 | |||
615 | integ_counter = None |
|
618 | integ_counter = None | |
616 | data = None |
|
619 | data = None | |
617 | navg = None |
|
620 | navg = None | |
618 | buffer = None |
|
621 | buffer = None | |
619 | nIncohInt = None |
|
622 | nIncohInt = None | |
620 |
|
623 | |||
621 | def __init__(self, N = None, timeInterval = None): |
|
624 | def __init__(self, N = None, timeInterval = None): | |
622 | """ |
|
625 | """ | |
623 | N |
|
626 | N | |
624 | timeInterval - interval time [min], integer value |
|
627 | timeInterval - interval time [min], integer value | |
625 | """ |
|
628 | """ | |
626 |
|
629 | |||
627 | self.data = None |
|
630 | self.data = None | |
628 | self.navg = None |
|
631 | self.navg = None | |
629 | self.buffer = None |
|
632 | self.buffer = None | |
630 | self.timeOut = None |
|
633 | self.timeOut = None | |
631 | self.exitCondition = False |
|
634 | self.exitCondition = False | |
632 | self.isReady = False |
|
635 | self.isReady = False | |
633 | self.nIncohInt = N |
|
636 | self.nIncohInt = N | |
634 | self.integ_counter = 0 |
|
637 | self.integ_counter = 0 | |
635 | if timeInterval!=None: |
|
638 | if timeInterval!=None: | |
636 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
639 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
637 |
|
640 | |||
638 | if ((timeInterval==None) and (N==None)): |
|
641 | if ((timeInterval==None) and (N==None)): | |
639 | print 'N = None ; timeInterval = None' |
|
642 | print 'N = None ; timeInterval = None' | |
640 | sys.exit(0) |
|
643 | sys.exit(0) | |
641 | elif timeInterval == None: |
|
644 | elif timeInterval == None: | |
642 | self.timeFlag = False |
|
645 | self.timeFlag = False | |
643 | else: |
|
646 | else: | |
644 | self.timeFlag = True |
|
647 | self.timeFlag = True | |
645 |
|
648 | |||
646 |
|
649 | |||
647 | def exe(self,data,timeOfData): |
|
650 | def exe(self,data,timeOfData): | |
648 | """ |
|
651 | """ | |
649 | data |
|
652 | data | |
650 |
|
653 | |||
651 | timeOfData [seconds] |
|
654 | timeOfData [seconds] | |
652 | """ |
|
655 | """ | |
653 |
|
656 | |||
654 | if self.timeFlag: |
|
657 | if self.timeFlag: | |
655 | if self.timeOut == None: |
|
658 | if self.timeOut == None: | |
656 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
659 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
657 |
|
660 | |||
658 | if timeOfData < self.timeOut: |
|
661 | if timeOfData < self.timeOut: | |
659 | if self.buffer == None: |
|
662 | if self.buffer == None: | |
660 | self.buffer = data |
|
663 | self.buffer = data | |
661 | else: |
|
664 | else: | |
662 | self.buffer = self.buffer + data |
|
665 | self.buffer = self.buffer + data | |
663 | self.integ_counter += 1 |
|
666 | self.integ_counter += 1 | |
664 | else: |
|
667 | else: | |
665 | self.exitCondition = True |
|
668 | self.exitCondition = True | |
666 |
|
669 | |||
667 | else: |
|
670 | else: | |
668 | if self.integ_counter < self.nIncohInt: |
|
671 | if self.integ_counter < self.nIncohInt: | |
669 | if self.buffer == None: |
|
672 | if self.buffer == None: | |
670 | self.buffer = data |
|
673 | self.buffer = data | |
671 | else: |
|
674 | else: | |
672 | self.buffer = self.buffer + data |
|
675 | self.buffer = self.buffer + data | |
673 |
|
676 | |||
674 | self.integ_counter += 1 |
|
677 | self.integ_counter += 1 | |
675 |
|
678 | |||
676 | if self.integ_counter == self.nIncohInt: |
|
679 | if self.integ_counter == self.nIncohInt: | |
677 | self.exitCondition = True |
|
680 | self.exitCondition = True | |
678 |
|
681 | |||
679 | if self.exitCondition: |
|
682 | if self.exitCondition: | |
680 | self.data = self.buffer |
|
683 | self.data = self.buffer | |
681 | self.navg = self.integ_counter |
|
684 | self.navg = self.integ_counter | |
682 | self.isReady = True |
|
685 | self.isReady = True | |
683 | self.buffer = None |
|
686 | self.buffer = None | |
684 | self.timeOut = None |
|
687 | self.timeOut = None | |
685 | self.integ_counter = 0 |
|
688 | self.integ_counter = 0 | |
686 | self.exitCondition = False |
|
689 | self.exitCondition = False | |
687 |
|
690 | |||
688 | if self.timeFlag: |
|
691 | if self.timeFlag: | |
689 | self.buffer = data |
|
692 | self.buffer = data | |
690 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
693 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
691 | else: |
|
694 | else: | |
692 | self.isReady = False |
|
695 | self.isReady = False | |
693 | No newline at end of file |
|
696 |
General Comments 0
You need to be logged in to leave comments.
Login now