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