@@ -1,603 +1,844 | |||||
1 | """ |
|
1 | """ | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @autor $Author$ |
|
4 | @autor $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 |
|
6 | |||
7 | """ |
|
7 | """ | |
8 |
|
8 | |||
9 | import numpy |
|
9 | import numpy | |
10 | import plplot |
|
10 | import plplot | |
11 |
|
11 | |||
|
12 | def cmap1_init(colormap="gray"): | |||
|
13 | ||||
|
14 | ncolor = None | |||
|
15 | rgb_lvl = None | |||
|
16 | ||||
|
17 | # Routine for defining a specific color map 1 in HLS space. | |||
|
18 | # if gray is true, use basic grayscale variation from half-dark to light. | |||
|
19 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |||
|
20 | ||||
|
21 | # Independent variable of control points. | |||
|
22 | i = numpy.array((0., 1.)) | |||
|
23 | if colormap=="gray": | |||
|
24 | ncolor = 256 | |||
|
25 | # Hue for control points. Doesn't matter since saturation is zero. | |||
|
26 | h = numpy.array((0., 0.)) | |||
|
27 | # Lightness ranging from half-dark (for interest) to light. | |||
|
28 | l = numpy.array((0.5, 1.)) | |||
|
29 | # Gray scale has zero saturation | |||
|
30 | s = numpy.array((0., 0.)) | |||
|
31 | ||||
|
32 | # number of cmap1 colours is 256 in this case. | |||
|
33 | plplot.plscmap1n(ncolor) | |||
|
34 | # Interpolate between control points to set up cmap1. | |||
|
35 | plplot.plscmap1l(0, i, h, l, s) | |||
|
36 | ||||
|
37 | return None | |||
|
38 | ||||
|
39 | if colormap=="br_green": | |||
|
40 | ncolor = 256 | |||
|
41 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
42 | h = numpy.array((240., 0.)) | |||
|
43 | # Lightness and saturation are constant (values taken from C example). | |||
|
44 | l = numpy.array((0.6, 0.6)) | |||
|
45 | s = numpy.array((0.8, 0.8)) | |||
|
46 | ||||
|
47 | # number of cmap1 colours is 256 in this case. | |||
|
48 | plplot.plscmap1n(ncolor) | |||
|
49 | # Interpolate between control points to set up cmap1. | |||
|
50 | plplot.plscmap1l(0, i, h, l, s) | |||
|
51 | ||||
|
52 | return None | |||
|
53 | ||||
|
54 | if colormap=="tricolor": | |||
|
55 | ncolor = 3 | |||
|
56 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |||
|
57 | h = numpy.array((240., 0.)) | |||
|
58 | # Lightness and saturation are constant (values taken from C example). | |||
|
59 | l = numpy.array((0.6, 0.6)) | |||
|
60 | s = numpy.array((0.8, 0.8)) | |||
|
61 | ||||
|
62 | # number of cmap1 colours is 256 in this case. | |||
|
63 | plplot.plscmap1n(ncolor) | |||
|
64 | # Interpolate between control points to set up cmap1. | |||
|
65 | plplot.plscmap1l(0, i, h, l, s) | |||
|
66 | ||||
|
67 | return None | |||
|
68 | ||||
|
69 | if colormap == 'rgb' or colormap == 'rgb666': | |||
|
70 | ||||
|
71 | color_sz = 6 | |||
|
72 | ncolor = color_sz*color_sz*color_sz | |||
|
73 | pos = numpy.zeros((ncolor)) | |||
|
74 | r = numpy.zeros((ncolor)) | |||
|
75 | g = numpy.zeros((ncolor)) | |||
|
76 | b = numpy.zeros((ncolor)) | |||
|
77 | ind = 0 | |||
|
78 | for ri in range(color_sz): | |||
|
79 | for gi in range(color_sz): | |||
|
80 | for bi in range(color_sz): | |||
|
81 | r[ind] = ri/(color_sz-1.0) | |||
|
82 | g[ind] = gi/(color_sz-1.0) | |||
|
83 | b[ind] = bi/(color_sz-1.0) | |||
|
84 | pos[ind] = ind/(ncolor-1.0) | |||
|
85 | ind += 1 | |||
|
86 | rgb_lvl = [6,6,6] #Levels for RGB colors | |||
|
87 | ||||
|
88 | if colormap == 'rgb676': | |||
|
89 | ncolor = 6*7*6 | |||
|
90 | pos = numpy.zeros((ncolor)) | |||
|
91 | r = numpy.zeros((ncolor)) | |||
|
92 | g = numpy.zeros((ncolor)) | |||
|
93 | b = numpy.zeros((ncolor)) | |||
|
94 | ind = 0 | |||
|
95 | for ri in range(8): | |||
|
96 | for gi in range(8): | |||
|
97 | for bi in range(4): | |||
|
98 | r[ind] = ri/(6-1.0) | |||
|
99 | g[ind] = gi/(7-1.0) | |||
|
100 | b[ind] = bi/(6-1.0) | |||
|
101 | pos[ind] = ind/(ncolor-1.0) | |||
|
102 | ind += 1 | |||
|
103 | rgb_lvl = [6,7,6] #Levels for RGB colors | |||
|
104 | ||||
|
105 | if colormap == 'rgb685': | |||
|
106 | ncolor = 6*8*5 | |||
|
107 | pos = numpy.zeros((ncolor)) | |||
|
108 | r = numpy.zeros((ncolor)) | |||
|
109 | g = numpy.zeros((ncolor)) | |||
|
110 | b = numpy.zeros((ncolor)) | |||
|
111 | ind = 0 | |||
|
112 | for ri in range(8): | |||
|
113 | for gi in range(8): | |||
|
114 | for bi in range(4): | |||
|
115 | r[ind] = ri/(6-1.0) | |||
|
116 | g[ind] = gi/(8-1.0) | |||
|
117 | b[ind] = bi/(5-1.0) | |||
|
118 | pos[ind] = ind/(ncolor-1.0) | |||
|
119 | ind += 1 | |||
|
120 | rgb_lvl = [6,8,5] #Levels for RGB colors | |||
|
121 | ||||
|
122 | if colormap == 'rgb884': | |||
|
123 | ncolor = 8*8*4 | |||
|
124 | pos = numpy.zeros((ncolor)) | |||
|
125 | r = numpy.zeros((ncolor)) | |||
|
126 | g = numpy.zeros((ncolor)) | |||
|
127 | b = numpy.zeros((ncolor)) | |||
|
128 | ind = 0 | |||
|
129 | for ri in range(8): | |||
|
130 | for gi in range(8): | |||
|
131 | for bi in range(4): | |||
|
132 | r[ind] = ri/(8-1.0) | |||
|
133 | g[ind] = gi/(8-1.0) | |||
|
134 | b[ind] = bi/(4-1.0) | |||
|
135 | pos[ind] = ind/(ncolor-1.0) | |||
|
136 | ind += 1 | |||
|
137 | rgb_lvl = [8,8,4] #Levels for RGB colors | |||
|
138 | ||||
|
139 | if ncolor == None: | |||
|
140 | raise ValueError, "The colormap selected is not valid" | |||
|
141 | ||||
|
142 | plplot.plscmap1n(ncolor) | |||
|
143 | plplot.plscmap1l(1, pos, r, g, b) | |||
|
144 | ||||
|
145 | return rgb_lvl | |||
|
146 | ||||
12 | class BaseGraph: |
|
147 | class BaseGraph: | |
13 | """ |
|
148 | """ | |
14 |
|
149 | |||
15 | """ |
|
150 | """ | |
16 |
|
151 | |||
17 |
|
152 | |||
18 |
|
153 | |||
19 | def __init__(self): |
|
154 | def __init__(self): | |
20 | """ |
|
155 | """ | |
21 |
|
156 | |||
22 | """ |
|
157 | """ | |
23 | self.hasNotRange = True |
|
158 | self.hasNotRange = True | |
24 |
|
159 | |||
25 | self.xrange = None |
|
160 | self.xrange = None | |
26 | self.yrange = None |
|
161 | self.yrange = None | |
27 | self.zrange = None |
|
162 | self.zrange = None | |
28 |
|
163 | |||
29 | self.xlabel = None |
|
164 | self.xlabel = None | |
30 | self.ylabel = None |
|
165 | self.ylabel = None | |
31 | self.title = None |
|
166 | self.title = None | |
32 |
|
167 | |||
33 | self.legends = None |
|
168 | self.legends = None | |
34 |
|
169 | |||
35 | self.__name = None |
|
170 | self.__name = None | |
36 |
|
171 | |||
37 | self.__colormap = None |
|
172 | self.__colormap = None | |
38 | self.__colbox = None |
|
173 | self.__colbox = None | |
39 | self.__colleg = None |
|
174 | self.__colleg = None | |
40 |
|
175 | |||
41 | self.__xpos = None |
|
176 | self.__xpos = None | |
42 | self.__ypos = None |
|
177 | self.__ypos = None | |
43 |
|
178 | |||
44 | self.__xopt = None #"bcnst" |
|
179 | self.__xopt = None #"bcnst" | |
45 | self.__yopt = None #"bcnstv" |
|
180 | self.__yopt = None #"bcnstv" | |
46 |
|
181 | |||
47 | self.__xlpos = None |
|
182 | self.__xlpos = None | |
48 | self.__ylpos = None |
|
183 | self.__ylpos = None | |
49 |
|
184 | |||
50 | self.__xrangeIsTime = False |
|
185 | self.__xrangeIsTime = False | |
51 |
|
186 | |||
52 | #Advanced |
|
187 | #Advanced | |
53 | self.__xg = None |
|
188 | self.__xg = None | |
54 | self.__yg = None |
|
189 | self.__yg = None | |
55 |
|
190 | |||
56 | def setName(self, name): |
|
191 | def setName(self, name): | |
57 | self.__name = name |
|
192 | self.__name = name | |
58 |
|
193 | |||
59 | def setScreenPos(self, xpos, ypos): |
|
194 | def setScreenPos(self, xpos, ypos): | |
60 | self.__xpos = xpos |
|
195 | self.__xpos = xpos | |
61 | self.__ypos = ypos |
|
196 | self.__ypos = ypos | |
62 |
|
197 | |||
63 | def setOpt(self, xopt, yopt): |
|
198 | def setOpt(self, xopt, yopt): | |
64 | self.__xopt = xopt |
|
199 | self.__xopt = xopt | |
65 | self.__yopt = yopt |
|
200 | self.__yopt = yopt | |
66 |
|
201 | |||
67 | def setXAxisAsTime(self): |
|
202 | def setXAxisAsTime(self): | |
68 | self.__xrangeIsTime = True |
|
203 | self.__xrangeIsTime = True | |
69 |
|
204 | |||
70 |
|
205 | |||
71 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): |
|
206 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): | |
72 | """ |
|
207 | """ | |
73 | """ |
|
208 | """ | |
74 | self.title = title |
|
209 | self.title = title | |
75 | self.xlabel = xlabel |
|
210 | self.xlabel = xlabel | |
76 | self.ylabel = ylabel |
|
211 | self.ylabel = ylabel | |
77 | self.__colormap = colormap |
|
212 | self.__colormap = colormap | |
78 |
|
213 | |||
79 | def plotBox(self, xmin, xmax, ymin, ymax): |
|
214 | def plotBox(self, xmin, xmax, ymin, ymax): | |
80 | """ |
|
215 | """ | |
81 |
|
216 | |||
82 | """ |
|
217 | """ | |
83 | if self.__xrangeIsTime: |
|
218 | if self.__xrangeIsTime: | |
84 | plplot.pltimefmt("%H:%M") |
|
219 | plplot.pltimefmt("%H:%M") | |
85 |
|
220 | |||
86 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) |
|
221 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |
87 | plplot.plwind(float(xmin), |
|
222 | plplot.plwind(float(xmin), | |
88 | float(xmax), |
|
223 | float(xmax), | |
89 | float(ymin), |
|
224 | float(ymin), | |
90 | float(ymax) |
|
225 | float(ymax) | |
91 | ) |
|
226 | ) | |
92 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) |
|
227 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) | |
93 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
228 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |
94 |
|
229 | |||
95 |
|
230 | |||
96 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): |
|
231 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): | |
97 | data = numpy.arange(256) |
|
232 | data = numpy.arange(256) | |
98 | data = numpy.reshape(data, (1,-1)) |
|
233 | data = numpy.reshape(data, (1,-1)) | |
99 |
|
234 | |||
100 | self.plotBox(xmin, xmax, ymin, ymax) |
|
|||
101 | plplot.plimage(data, |
|
235 | plplot.plimage(data, | |
102 | float(xmin), |
|
236 | float(xmin), | |
103 | float(xmax), |
|
237 | float(xmax), | |
104 | float(ymin), |
|
238 | float(ymin), | |
105 | float(ymax), |
|
239 | float(ymax), | |
106 | 0., |
|
240 | 0., | |
107 | 255., |
|
241 | 255., | |
108 | float(xmin), |
|
242 | float(xmin), | |
109 | float(xmax), |
|
243 | float(xmax), | |
110 | float(ymin), |
|
244 | float(ymin), | |
111 | float(ymax)) |
|
245 | float(ymax)) | |
112 |
|
246 | |||
113 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): |
|
247 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): | |
114 |
|
248 | |||
115 | if xmin == None: xmin = x[0] |
|
249 | if xmin == None: xmin = x[0] | |
116 | if xmax == None: xmax = x[-1] |
|
250 | if xmax == None: xmax = x[-1] | |
117 | if ymin == None: ymin = y[0] |
|
251 | if ymin == None: ymin = y[0] | |
118 | if ymax == None: ymax = y[-1] |
|
252 | if ymax == None: ymax = y[-1] | |
119 |
|
253 | |||
120 | plplot.plline(x, y) |
|
254 | plplot.plline(x, y) | |
121 |
|
255 | |||
122 | def basicXYwithErrorPlot(self): |
|
256 | def basicXYwithErrorPlot(self): | |
123 | pass |
|
257 | pass | |
124 |
|
258 | |||
125 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
259 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): | |
126 |
|
260 | |||
127 | if xmin == None: xmin = x[0] |
|
261 | if xmin == None: xmin = x[0] | |
128 | if xmax == None: xmax = x[-1] |
|
262 | if xmax == None: xmax = x[-1] | |
129 | if ymin == None: ymin = y[0] |
|
263 | if ymin == None: ymin = y[0] | |
130 | if ymax == None: ymax = y[-1] |
|
264 | if ymax == None: ymax = y[-1] | |
131 |
|
265 | |||
132 | plplot.plcol0(colline) |
|
266 | plplot.plcol0(colline) | |
133 | plplot.plline(x, y) |
|
267 | plplot.plline(x, y) | |
134 | plplot.plcol0(1) |
|
268 | plplot.plcol0(1) | |
135 |
|
269 | |||
136 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
270 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
137 | """ |
|
271 | """ | |
138 | """ |
|
272 | """ | |
139 | if xmin == None: xmin = x[0] |
|
273 | if xmin == None: xmin = x[0] | |
140 | if xmax == None: xmax = x[-1] |
|
274 | if xmax == None: xmax = x[-1] | |
141 | if ymin == None: ymin = y[0] |
|
275 | if ymin == None: ymin = y[0] | |
142 | if ymax == None: ymax = y[-1] |
|
276 | if ymax == None: ymax = y[-1] | |
143 | if zmin == None: zmin = numpy.nanmin(data) |
|
277 | if zmin == None: zmin = numpy.nanmin(data) | |
144 | if zmax == None: zmax = numpy.nanmax(data) |
|
278 | if zmax == None: zmax = numpy.nanmax(data) | |
145 |
|
279 | |||
146 | plplot.plimage(data, |
|
280 | plplot.plimage(data, | |
147 | float(x[0]), |
|
281 | float(x[0]), | |
148 | float(x[-1]), |
|
282 | float(x[-1]), | |
149 | float(y[0]), |
|
283 | float(y[0]), | |
150 | float(y[-1]), |
|
284 | float(y[-1]), | |
151 | float(zmin), |
|
285 | float(zmin), | |
152 | float(zmax), |
|
286 | float(zmax), | |
153 | float(xmin), |
|
287 | float(xmin), | |
154 | float(xmax), |
|
288 | float(xmax), | |
155 | float(ymin), |
|
289 | float(ymin), | |
156 | float(ymax) |
|
290 | float(ymax) | |
157 | ) |
|
291 | ) | |
158 |
|
292 | |||
159 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
293 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): | |
160 |
|
294 | |||
161 | if not(len(x)>1 and len(y)>1): |
|
295 | if not(len(x)>1 and len(y)>1): | |
162 | raise ValueError, "x axis and y axis are empty" |
|
296 | raise ValueError, "x axis and y axis are empty" | |
163 |
|
297 | |||
164 | if deltax == None: deltax = x[-1] - x[-2] |
|
298 | if deltax == None: deltax = x[-1] - x[-2] | |
165 | if deltay == None: deltay = y[-1] - y[-2] |
|
299 | if deltay == None: deltay = y[-1] - y[-2] | |
166 |
|
300 | |||
167 | x1 = numpy.append(x, x[-1] + deltax) |
|
301 | x1 = numpy.append(x, x[-1] + deltax) | |
168 | y1 = numpy.append(y, y[-1] + deltay) |
|
302 | y1 = numpy.append(y, y[-1] + deltay) | |
169 |
|
303 | |||
170 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
304 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |
171 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
305 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |
172 |
|
306 | |||
173 | self.__xg = xg |
|
307 | self.__xg = xg | |
174 | self.__yg = yg |
|
308 | self.__yg = yg | |
175 |
|
309 | |||
176 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): |
|
310 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): | |
177 | """ |
|
311 | """ | |
178 | """ |
|
312 | """ | |
179 |
|
313 | |||
180 | if self.__xg == None and self.__yg == None: |
|
314 | if self.__xg == None and self.__yg == None: | |
181 | self.__getBoxpltr(x, y) |
|
315 | self.__getBoxpltr(x, y) | |
182 |
|
316 | |||
183 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) |
|
317 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) | |
184 |
|
318 | |||
185 |
|
319 | |||
186 | class LinearPlot(): |
|
320 | class LinearPlot(): | |
187 |
|
321 | |||
188 | __szchar = 1.0 |
|
322 | __szchar = 1.0 | |
189 | __xrange = None |
|
323 | __xrange = None | |
190 | __yrange = None |
|
324 | __yrange = None | |
191 |
|
325 | |||
192 | m_BaseGraph = None |
|
326 | m_BaseGraph = None | |
193 |
|
327 | |||
194 | def __init__(self): |
|
328 | def __init__(self): | |
195 |
|
329 | |||
196 |
|
330 | |||
197 | key = "linearplot" |
|
331 | key = "linearplot" | |
198 | self.m_BaseGraph = BaseGraph() |
|
332 | self.m_BaseGraph = BaseGraph() | |
199 | self.m_BaseGraph.setName(key) |
|
333 | self.m_BaseGraph.setName(key) | |
200 |
|
334 | |||
|
335 | self.__subpage = 0 | |||
|
336 | ||||
201 | def setColormap(self, colormap="br_green"): |
|
337 | def setColormap(self, colormap="br_green"): | |
202 |
|
338 | |||
203 | if colormap == None: |
|
339 | if colormap == None: | |
204 | colormap = self.__colormap |
|
340 | colormap = self.__colormap | |
205 |
|
341 | |||
206 | cmap1_init(colormap) |
|
342 | cmap1_init(colormap) | |
207 |
|
343 | |||
208 | def iniSubpage(self): |
|
344 | def iniSubpage(self): | |
209 |
|
345 | |||
210 | if plplot.plgdev() == '': |
|
346 | if plplot.plgdev() == '': | |
211 | raise ValueError, "Plot device has not been initialize" |
|
347 | raise ValueError, "Plot device has not been initialize" | |
212 |
|
348 | |||
213 | plplot.pladv(self.__subpage) |
|
349 | plplot.pladv(self.__subpage) | |
214 | plplot.plschr(0.0, self.__szchar) |
|
350 | plplot.plschr(0.0, self.__szchar) | |
215 |
|
351 | |||
216 | self.setColormap() |
|
352 | self.setColormap() | |
217 |
|
353 | |||
218 | def setScreenPos(self, width='small'): |
|
354 | def setScreenPos(self, width='small'): | |
219 |
|
355 | |||
220 | if width == 'small': |
|
356 | if width == 'small': | |
221 | xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80 |
|
357 | xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80 | |
222 |
|
358 | |||
223 | if width == 'medium': |
|
359 | if width == 'medium': | |
224 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60 |
|
360 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60 | |
225 |
|
361 | |||
226 | xf = xi + xw |
|
362 | xf = xi + xw | |
227 | yf = yi + yw |
|
363 | yf = yi + yw | |
228 |
|
364 | |||
229 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) |
|
365 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) | |
230 |
|
366 | |||
231 | def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): |
|
367 | def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): | |
232 | """ |
|
368 | """ | |
233 | """ |
|
369 | """ | |
234 |
|
370 | |||
235 | self.m_BaseGraph.setOpt("bcnts","bcntsv") |
|
371 | self.m_BaseGraph.setOpt("bcnts","bcntsv") | |
236 | self.m_BaseGraph.setup(title, |
|
372 | self.m_BaseGraph.setup(title, | |
237 | xlabel, |
|
373 | xlabel, | |
238 | ylabel |
|
374 | ylabel | |
239 | ) |
|
375 | ) | |
240 |
|
376 | |||
241 | self.setScreenPos(width='medium') |
|
377 | self.setScreenPos(width='medium') | |
242 |
|
378 | |||
243 | if XAxisAsTime: |
|
379 | if XAxisAsTime: | |
244 | self.m_BaseGraph.setXAxisAsTime() |
|
380 | self.m_BaseGraph.setXAxisAsTime() | |
245 |
|
381 | |||
246 | self.__subpage = subpage |
|
382 | self.__subpage = subpage | |
247 | # def setRanges(self, xrange, yrange, zrange): |
|
383 | # def setRanges(self, xrange, yrange, zrange): | |
248 | # |
|
384 | # | |
249 | # self.m_BaseGraph.setRanges(xrange, yrange, zrange) |
|
385 | # self.m_BaseGraph.setRanges(xrange, yrange, zrange) | |
250 |
|
386 | |||
251 | def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
387 | def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): | |
252 | """ |
|
388 | """ | |
253 | Inputs: |
|
389 | Inputs: | |
254 |
|
390 | |||
255 | x : Numpy array of dimension 1 |
|
391 | x : Numpy array of dimension 1 | |
256 | y : Numpy array of dimension 1 |
|
392 | y : Numpy array of dimension 1 | |
257 |
|
393 | |||
258 | """ |
|
394 | """ | |
259 |
|
395 | |||
260 | try: |
|
396 | try: | |
261 | nX = numpy.shape(x) |
|
397 | nX = numpy.shape(x) | |
262 | except: |
|
398 | except: | |
263 | raise ValueError, "x is not a numpy array" |
|
399 | raise ValueError, "x is not a numpy array" | |
264 |
|
400 | |||
265 | if y == None: y = numpy.arange(nX) |
|
401 | if y == None: y = numpy.arange(nX) | |
266 |
|
402 | |||
267 | if xmin == None: xmin = x[0] |
|
403 | if xmin == None: xmin = x[0] | |
268 | if xmax == None: xmax = x[-1] |
|
404 | if xmax == None: xmax = x[-1] | |
269 | if ymin == None: ymin = y[0] |
|
405 | if ymin == None: ymin = y[0] | |
270 | if ymax == None: ymax = y[-1] |
|
406 | if ymax == None: ymax = y[-1] | |
271 |
|
407 | |||
272 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) |
|
408 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) | |
273 | self.m_BaseGraph.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) |
|
409 | self.m_BaseGraph.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) | |
274 |
|
410 | |||
275 | def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): |
|
411 | def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): | |
276 | """ |
|
412 | """ | |
277 | Inputs: |
|
413 | Inputs: | |
278 |
|
414 | |||
279 | x : Numpy array of dimension 1 |
|
415 | x : Numpy array of dimension 1 | |
280 | y : Complex numpy array of dimension 1 |
|
416 | y : Complex numpy array of dimension 1 | |
281 |
|
417 | |||
282 | """ |
|
418 | """ | |
283 |
|
419 | |||
284 | try: |
|
420 | try: | |
285 | nX = numpy.shape(x) |
|
421 | nX = numpy.shape(x) | |
286 | except: |
|
422 | except: | |
287 | raise ValueError, "x is not a numpy array" |
|
423 | raise ValueError, "x is not a numpy array" | |
288 |
|
424 | |||
289 | try: |
|
425 | try: | |
290 | nY = numpy.shape(y) |
|
426 | nY = numpy.shape(y) | |
291 | except: |
|
427 | except: | |
292 | raise ValueError, "y is not a numpy array" |
|
428 | raise ValueError, "y is not a numpy array" | |
293 |
|
429 | |||
294 | if xmin == None: xmin = x[0] |
|
430 | if xmin == None: xmin = x[0] | |
295 | if xmax == None: xmax = x[-1] |
|
431 | if xmax == None: xmax = x[-1] | |
296 | if ymin == None: ymin = y[0] |
|
432 | if ymin == None: ymin = y[0] | |
297 | if ymax == None: ymax = y[-1] |
|
433 | if ymax == None: ymax = y[-1] | |
298 |
|
434 | |||
299 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) |
|
435 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) | |
300 |
|
436 | |||
301 | if type.lower() == 'power': |
|
437 | if type.lower() == 'power': | |
302 | self.m_BaseGraph.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) |
|
438 | self.m_BaseGraph.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) | |
303 |
|
439 | |||
304 | if type.lower() == 'iq': |
|
440 | if type.lower() == 'iq': | |
305 |
|
441 | |||
306 | self.m_BaseGraph.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) |
|
442 | self.m_BaseGraph.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) | |
307 | self.m_BaseGraph.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) |
|
443 | self.m_BaseGraph.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) | |
308 |
|
444 | |||
309 | class ColorPlot(): |
|
445 | class ColorPlot(): | |
|
446 | ||||
|
447 | def __init__(self): | |||
|
448 | ||||
|
449 | self.graphObjDict = {} | |||
|
450 | ||||
|
451 | self.__subpage = 0 | |||
|
452 | self.__showColorbar = False | |||
|
453 | self.__showPowerProfile = True | |||
|
454 | ||||
|
455 | self.__szchar = 0.7 | |||
|
456 | self.__xrange = None | |||
|
457 | self.__yrange = None | |||
|
458 | self.__zrange = None | |||
|
459 | ||||
|
460 | key = "colorplot" | |||
|
461 | self.m_BaseGraph = BaseGraph() | |||
|
462 | self.m_BaseGraph.setName(key) | |||
|
463 | ||||
|
464 | def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | |||
|
465 | """ | |||
|
466 | """ | |||
|
467 | ||||
|
468 | self.m_BaseGraph.setOpt("bcnts","bcntsv") | |||
|
469 | self.m_BaseGraph.setup(title, | |||
|
470 | xlabel, | |||
|
471 | ylabel | |||
|
472 | ) | |||
|
473 | ||||
|
474 | self.__subpage = subpage | |||
|
475 | self.__colormap = colormap | |||
|
476 | self.__showColorbar = showColorbar | |||
|
477 | self.__showPowerProfile = showPowerProfile | |||
|
478 | ||||
|
479 | if showColorbar: | |||
|
480 | key = "colorbar" | |||
|
481 | ||||
|
482 | cmapObj = BaseGraph() | |||
|
483 | cmapObj.setName(key) | |||
|
484 | cmapObj.setOpt("bc","bcmt") | |||
|
485 | cmapObj.setup(title="dBs", | |||
|
486 | xlabel="", | |||
|
487 | ylabel="", | |||
|
488 | colormap=colormap) | |||
|
489 | ||||
|
490 | self.graphObjDict[key] = cmapObj | |||
|
491 | ||||
|
492 | ||||
|
493 | if showPowerProfile: | |||
|
494 | key = "powerprof" | |||
|
495 | ||||
|
496 | powObj = BaseGraph() | |||
|
497 | powObj.setName(key) | |||
|
498 | powObj.setOpt("bcntg","bc") | |||
|
499 | powObj.setup(title="Power Profile", | |||
|
500 | xlabel="dBs", | |||
|
501 | ylabel="") | |||
|
502 | ||||
|
503 | self.graphObjDict[key] = powObj | |||
|
504 | ||||
|
505 | self.setScreenPos(width='small') | |||
|
506 | ||||
|
507 | if XAxisAsTime: | |||
|
508 | self.m_BaseGraph.setXAxisAsTime() | |||
|
509 | ||||
|
510 | ||||
|
511 | ||||
|
512 | def setColormap(self, colormap="br_green"): | |||
|
513 | ||||
|
514 | if colormap == None: | |||
|
515 | colormap = self.__colormap | |||
|
516 | ||||
|
517 | cmap1_init(colormap) | |||
|
518 | ||||
|
519 | def iniSubpage(self): | |||
|
520 | ||||
|
521 | if plplot.plgdev() == '': | |||
|
522 | raise ValueError, "Plot device has not been initialize" | |||
|
523 | ||||
|
524 | plplot.pladv(self.__subpage) | |||
|
525 | plplot.plschr(0.0, self.__szchar) | |||
|
526 | ||||
|
527 | self.setColormap() | |||
|
528 | ||||
|
529 | def setScreenPos(self, width='small'): | |||
|
530 | ||||
|
531 | if width == 'small': | |||
|
532 | xi = 0.12; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.05; xpoww = 0.26; deltaxcmap = 0.02; deltaxpow = 0.06 | |||
|
533 | ||||
|
534 | if width == 'medium': | |||
|
535 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.05; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06 | |||
|
536 | ||||
|
537 | if self.__showColorbar: | |||
|
538 | xw -= xcmapw + deltaxcmap | |||
|
539 | ||||
|
540 | if self.__showPowerProfile: | |||
|
541 | xw -= xpoww + deltaxpow | |||
|
542 | ||||
|
543 | xf = xi + xw | |||
|
544 | yf = yi + yw | |||
|
545 | xcmapf = xf | |||
|
546 | ||||
|
547 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) | |||
|
548 | ||||
|
549 | if self.__showColorbar: | |||
|
550 | xcmapi = xf + deltaxcmap | |||
|
551 | xcmapf = xcmapi + xcmapw | |||
|
552 | ||||
|
553 | key = "colorbar" | |||
|
554 | cmapObj = self.graphObjDict[key] | |||
|
555 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |||
|
556 | ||||
|
557 | if self.__showPowerProfile: | |||
|
558 | ||||
|
559 | xpowi = xcmapf + deltaxpow | |||
|
560 | xpowf = xpowi + xpoww | |||
|
561 | ||||
|
562 | key = "powerprof" | |||
|
563 | powObj = self.graphObjDict[key] | |||
|
564 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |||
|
565 | ||||
|
566 | ||||
|
567 | ||||
|
568 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |||
|
569 | """ | |||
|
570 | Inputs: | |||
|
571 | ||||
|
572 | x : Numpy array of dimension 1 | |||
|
573 | y : Numpy array of dimension 1 | |||
|
574 | ||||
|
575 | """ | |||
|
576 | ||||
|
577 | try: | |||
|
578 | nX, nY = numpy.shape(data) | |||
|
579 | except: | |||
|
580 | raise ValueError, "data is not a numpy array" | |||
|
581 | ||||
|
582 | if x == None: x = numpy.arange(nX) | |||
|
583 | if y == None: y = numpy.arange(nY) | |||
|
584 | ||||
|
585 | if xmin == None: xmin = x[0] | |||
|
586 | if xmax == None: xmax = x[-1] | |||
|
587 | if ymin == None: ymin = y[0] | |||
|
588 | if ymax == None: ymax = y[-1] | |||
|
589 | if zmin == None: zmin = numpy.nanmin(data) | |||
|
590 | if zmax == None: zmax = numpy.nanmax(data) | |||
|
591 | ||||
|
592 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) | |||
|
593 | self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) | |||
|
594 | ||||
|
595 | if self.__showColorbar: | |||
|
596 | key = "colorbar" | |||
|
597 | cmapObj = self.graphObjDict[key] | |||
|
598 | cmapObj.plotBox(0., 1., zmin, zmax) | |||
|
599 | cmapObj.colorbarPlot(0., 1., zmin, zmax) | |||
|
600 | ||||
|
601 | if self.__showPowerProfile: | |||
|
602 | power = numpy.average(data, axis=0) | |||
|
603 | ||||
|
604 | step = (ymax - ymin)/(nY-1) | |||
|
605 | heis = numpy.arange(ymin, ymax + step, step) | |||
|
606 | ||||
|
607 | key = "powerprof" | |||
|
608 | powObj = self.graphObjDict[key] | |||
|
609 | ||||
|
610 | plplot.pllsty(2) | |||
|
611 | powObj.plotBox(zmin, zmax, ymin, ymax) | |||
|
612 | plplot.pllsty(1) | |||
|
613 | powObj.basicXYPlot(power, heis) | |||
|
614 | ||||
|
615 | ||||
|
616 | class ColorPlotX(): | |||
310 |
|
617 | |||
311 |
|
618 | |||
312 | graphObjDict = {} |
|
619 | graphObjDict = {} | |
313 | showColorbar = False |
|
620 | showColorbar = False | |
314 | showPowerProfile = True |
|
621 | showPowerProfile = True | |
315 |
|
622 | |||
316 | __szchar = 0.7 |
|
623 | __szchar = 0.7 | |
317 | __xrange = None |
|
624 | __xrange = None | |
318 | __yrange = None |
|
625 | __yrange = None | |
319 | __zrange = None |
|
626 | __zrange = None | |
320 |
|
627 | |||
321 | m_BaseGraph = BaseGraph() |
|
628 | m_BaseGraph = BaseGraph() | |
322 |
|
629 | |||
323 | def __init__(self): |
|
630 | def __init__(self): | |
324 |
|
631 | |||
325 | key = "colorplot" |
|
632 | key = "colorplot" | |
326 | self.m_BaseGraph.setName(key) |
|
633 | self.m_BaseGraph.setName(key) | |
327 |
|
634 | |||
|
635 | self.__subpage = 0 | |||
|
636 | ||||
328 | self.graphObjDict[key] = self.m_BaseGraph |
|
637 | self.graphObjDict[key] = self.m_BaseGraph | |
329 |
|
638 | |||
|
639 | def setColormap(self, colormap="br_green"): | |||
|
640 | ||||
|
641 | if colormap == None: | |||
|
642 | colormap = self.__colormap | |||
|
643 | ||||
|
644 | cmap1_init(colormap) | |||
|
645 | ||||
|
646 | def iniSubpage(self): | |||
|
647 | ||||
|
648 | if plplot.plgdev() == '': | |||
|
649 | raise ValueError, "Plot device has not been initialize" | |||
|
650 | ||||
|
651 | plplot.pladv(self.__subpage) | |||
|
652 | plplot.plschr(0.0, self.__szchar) | |||
|
653 | ||||
|
654 | self.setColormap() | |||
|
655 | ||||
330 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): |
|
656 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | |
331 | """ |
|
657 | """ | |
332 | """ |
|
658 | """ | |
333 |
|
659 | |||
334 | self.m_BaseGraph.setSubpage(subpage) |
|
660 | self.m_BaseGraph.setSubpage(subpage) | |
335 | self.m_BaseGraph.setSzchar(self.__szchar) |
|
661 | self.m_BaseGraph.setSzchar(self.__szchar) | |
336 | self.m_BaseGraph.setOpt("bcnts","bcntsv") |
|
662 | self.m_BaseGraph.setOpt("bcnts","bcntsv") | |
337 | self.m_BaseGraph.setup(title, |
|
663 | self.m_BaseGraph.setup(title, | |
338 | xlabel, |
|
664 | xlabel, | |
339 | ylabel, |
|
665 | ylabel, | |
340 | colormap) |
|
666 | colormap) | |
341 |
|
667 | |||
342 | if showColorbar: |
|
668 | if showColorbar: | |
343 | key = "colorbar" |
|
669 | key = "colorbar" | |
344 |
|
670 | |||
345 | cmapObj = BaseGraph() |
|
671 | cmapObj = BaseGraph() | |
346 | cmapObj.setName(key) |
|
672 | cmapObj.setName(key) | |
347 | cmapObj.setSubpage(subpage) |
|
673 | cmapObj.setSubpage(subpage) | |
348 | cmapObj.setSzchar(self.__szchar) |
|
674 | cmapObj.setSzchar(self.__szchar) | |
349 | cmapObj.setOpt("bc","bcmt") |
|
675 | cmapObj.setOpt("bc","bcmt") | |
350 | cmapObj.setup(title="dBs", |
|
676 | cmapObj.setup(title="dBs", | |
351 | xlabel="", |
|
677 | xlabel="", | |
352 | ylabel="", |
|
678 | ylabel="", | |
353 | colormap=colormap) |
|
679 | colormap=colormap) | |
354 |
|
680 | |||
355 | self.graphObjDict[key] = cmapObj |
|
681 | self.graphObjDict[key] = cmapObj | |
356 |
|
682 | |||
357 |
|
683 | |||
358 | if showPowerProfile: |
|
684 | if showPowerProfile: | |
359 | key = "powerprof" |
|
685 | key = "powerprof" | |
360 |
|
686 | |||
361 | powObj = BaseGraph() |
|
687 | powObj = BaseGraph() | |
362 | powObj.setName(key) |
|
688 | powObj.setName(key) | |
363 | powObj.setSubpage(subpage) |
|
689 | powObj.setSubpage(subpage) | |
364 | powObj.setSzchar(self.__szchar) |
|
690 | powObj.setSzchar(self.__szchar) | |
365 | plplot.pllsty(2) |
|
691 | plplot.pllsty(2) | |
366 | powObj.setOpt("bcntg","bc") |
|
692 | powObj.setOpt("bcntg","bc") | |
367 | plplot.pllsty(1) |
|
693 | plplot.pllsty(1) | |
368 | powObj.setup(title="Power Profile", |
|
694 | powObj.setup(title="Power Profile", | |
369 | xlabel="dBs", |
|
695 | xlabel="dBs", | |
370 | ylabel="") |
|
696 | ylabel="") | |
371 |
|
697 | |||
372 | self.graphObjDict[key] = powObj |
|
698 | self.graphObjDict[key] = powObj | |
373 |
|
699 | |||
374 | self.showColorbar = showColorbar |
|
700 | self.showColorbar = showColorbar | |
375 | self.showPowerProfile = showPowerProfile |
|
701 | self.showPowerProfile = showPowerProfile | |
376 | self.setScreenPos() |
|
702 | self.setScreenPos() | |
377 |
|
703 | |||
378 | if XAxisAsTime: |
|
704 | if XAxisAsTime: | |
379 | self.m_BaseGraph.setXAxisAsTime() |
|
705 | self.m_BaseGraph.setXAxisAsTime() | |
380 | #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) |
|
706 | #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) | |
381 |
|
707 | |||
382 |
|
708 | |||
383 | def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): |
|
709 | def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): | |
384 |
|
710 | |||
385 | if self.showColorbar: |
|
711 | if self.showColorbar: | |
386 | xw -= xcmapw + deltaxcmap |
|
712 | xw -= xcmapw + deltaxcmap | |
387 |
|
713 | |||
388 | if self.showPowerProfile: |
|
714 | if self.showPowerProfile: | |
389 | xw -= xpoww + deltaxpow |
|
715 | xw -= xpoww + deltaxpow | |
390 |
|
716 | |||
391 | xf = xi + xw |
|
717 | xf = xi + xw | |
392 | yf = yi + yw |
|
718 | yf = yi + yw | |
393 | xcmapf = xf |
|
719 | xcmapf = xf | |
394 |
|
720 | |||
395 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) |
|
721 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) | |
396 |
|
722 | |||
397 | if self.showColorbar: |
|
723 | if self.showColorbar: | |
398 | xcmapi = xf + deltaxcmap |
|
724 | xcmapi = xf + deltaxcmap | |
399 | xcmapf = xcmapi + xcmapw |
|
725 | xcmapf = xcmapi + xcmapw | |
400 |
|
726 | |||
401 | key = "colorbar" |
|
727 | key = "colorbar" | |
402 | cmapObj = self.graphObjDict[key] |
|
728 | cmapObj = self.graphObjDict[key] | |
403 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) |
|
729 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |
404 |
|
730 | |||
405 | if self.showPowerProfile: |
|
731 | if self.showPowerProfile: | |
406 |
|
732 | |||
407 | xpowi = xcmapf + deltaxpow |
|
733 | xpowi = xcmapf + deltaxpow | |
408 | xpowf = xpowi + xpoww |
|
734 | xpowf = xpowi + xpoww | |
409 |
|
735 | |||
410 | key = "powerprof" |
|
736 | key = "powerprof" | |
411 | powObj = self.graphObjDict[key] |
|
737 | powObj = self.graphObjDict[key] | |
412 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) |
|
738 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |
413 |
|
739 | |||
414 | def setRanges(self, xrange, yrange, zrange): |
|
740 | def setRanges(self, xrange, yrange, zrange): | |
415 |
|
741 | |||
416 | self.m_BaseGraph.setRanges(xrange, yrange, zrange) |
|
742 | self.m_BaseGraph.setRanges(xrange, yrange, zrange) | |
417 |
|
743 | |||
418 | keyList = self.graphObjDict.keys() |
|
744 | keyList = self.graphObjDict.keys() | |
419 |
|
745 | |||
420 | key = "colorbar" |
|
746 | key = "colorbar" | |
421 | if key in keyList: |
|
747 | if key in keyList: | |
422 | cmapObj = self.graphObjDict[key] |
|
748 | cmapObj = self.graphObjDict[key] | |
423 | cmapObj.setRanges([0., 1.], zrange) |
|
749 | cmapObj.setRanges([0., 1.], zrange) | |
424 |
|
750 | |||
425 | key = "powerprof" |
|
751 | key = "powerprof" | |
426 | if key in keyList: |
|
752 | if key in keyList: | |
427 | powObj = self.graphObjDict[key] |
|
753 | powObj = self.graphObjDict[key] | |
428 | powObj.setRanges(zrange, yrange) |
|
754 | powObj.setRanges(zrange, yrange) | |
429 |
|
755 | |||
430 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
756 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
431 | """ |
|
757 | """ | |
432 | """ |
|
758 | """ | |
433 |
|
759 | |||
434 | try: |
|
760 | try: | |
435 | nX, nY = numpy.shape(data) |
|
761 | nX, nY = numpy.shape(data) | |
436 | except: |
|
762 | except: | |
437 | raise ValueError, "data is not a numpy array" |
|
763 | raise ValueError, "data is not a numpy array" | |
438 |
|
764 | |||
439 | if x == None: x = numpy.arange(nX) |
|
765 | if x == None: x = numpy.arange(nX) | |
440 | if y == None: y = numpy.arange(nY) |
|
766 | if y == None: y = numpy.arange(nY) | |
441 |
|
767 | |||
442 | if xmin == None: xmin = x[0] |
|
768 | if xmin == None: xmin = x[0] | |
443 | if xmax == None: xmax = x[-1] |
|
769 | if xmax == None: xmax = x[-1] | |
444 | if ymin == None: ymin = y[0] |
|
770 | if ymin == None: ymin = y[0] | |
445 | if ymax == None: ymax = y[-1] |
|
771 | if ymax == None: ymax = y[-1] | |
446 | if zmin == None: zmin = numpy.nanmin(data) |
|
772 | if zmin == None: zmin = numpy.nanmin(data) | |
447 | if zmax == None: zmax = numpy.nanmax(data) |
|
773 | if zmax == None: zmax = numpy.nanmax(data) | |
448 |
|
774 | |||
449 | if self.m_BaseGraph.hasNotRange: |
|
775 | if self.m_BaseGraph.hasNotRange: | |
450 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) |
|
776 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) | |
451 |
|
777 | |||
452 | self.m_BaseGraph.initSubpage() |
|
778 | self.m_BaseGraph.initSubpage() | |
453 | self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.m_BaseGraph.zrange[0], self.m_BaseGraph.zrange[1]) |
|
779 | self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.m_BaseGraph.zrange[0], self.m_BaseGraph.zrange[1]) | |
454 |
|
780 | |||
455 | if self.showColorbar: |
|
781 | if self.showColorbar: | |
456 | key = "colorbar" |
|
782 | key = "colorbar" | |
457 | cmapObj = self.graphObjDict[key] |
|
783 | cmapObj = self.graphObjDict[key] | |
458 | cmapObj.colorbarPlot() |
|
784 | cmapObj.colorbarPlot() | |
459 |
|
785 | |||
460 | if self.showPowerProfile: |
|
786 | if self.showPowerProfile: | |
461 | power = numpy.average(data, axis=1) |
|
787 | power = numpy.average(data, axis=1) | |
462 |
|
788 | |||
463 | step = (ymax - ymin)/(nY-1) |
|
789 | step = (ymax - ymin)/(nY-1) | |
464 | heis = numpy.arange(ymin, ymax + step, step) |
|
790 | heis = numpy.arange(ymin, ymax + step, step) | |
465 |
|
791 | |||
466 | key = "powerprof" |
|
792 | key = "powerprof" | |
467 | powObj = self.graphObjDict[key] |
|
793 | powObj = self.graphObjDict[key] | |
468 | powObj.basicXYPlot(power, heis) |
|
794 | powObj.basicXYPlot(power, heis) | |
469 |
|
795 | |||
470 | def cmap1_init(colormap="gray"): |
|
796 | if __name__ == '__main__': | |
471 |
|
797 | |||
472 | ncolor = None |
|
798 | import numpy | |
473 | rgb_lvl = None |
|
799 | plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) | |
|
800 | plplot.plsdev("xwin") | |||
|
801 | plplot.plscolbg(255,255,255) | |||
|
802 | plplot.plscol0(1,0,0,0) | |||
|
803 | plplot.plspause(False) | |||
|
804 | plplot.plinit() | |||
|
805 | plplot.plssub(2, 2) | |||
474 |
|
806 | |||
475 | # Routine for defining a specific color map 1 in HLS space. |
|
807 | nx = 64 | |
476 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
808 | ny = 100 | |
477 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
|||
478 |
|
||||
479 | # Independent variable of control points. |
|
|||
480 | i = numpy.array((0., 1.)) |
|
|||
481 | if colormap=="gray": |
|
|||
482 | ncolor = 256 |
|
|||
483 | # Hue for control points. Doesn't matter since saturation is zero. |
|
|||
484 | h = numpy.array((0., 0.)) |
|
|||
485 | # Lightness ranging from half-dark (for interest) to light. |
|
|||
486 | l = numpy.array((0.5, 1.)) |
|
|||
487 | # Gray scale has zero saturation |
|
|||
488 | s = numpy.array((0., 0.)) |
|
|||
489 |
|
||||
490 | # number of cmap1 colours is 256 in this case. |
|
|||
491 | plplot.plscmap1n(ncolor) |
|
|||
492 | # Interpolate between control points to set up cmap1. |
|
|||
493 | plplot.plscmap1l(0, i, h, l, s) |
|
|||
494 |
|
||||
495 | return None |
|
|||
496 |
|
||||
497 | if colormap=="br_green": |
|
|||
498 | ncolor = 256 |
|
|||
499 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
|||
500 | h = numpy.array((240., 0.)) |
|
|||
501 | # Lightness and saturation are constant (values taken from C example). |
|
|||
502 | l = numpy.array((0.6, 0.6)) |
|
|||
503 | s = numpy.array((0.8, 0.8)) |
|
|||
504 |
|
||||
505 | # number of cmap1 colours is 256 in this case. |
|
|||
506 | plplot.plscmap1n(ncolor) |
|
|||
507 | # Interpolate between control points to set up cmap1. |
|
|||
508 | plplot.plscmap1l(0, i, h, l, s) |
|
|||
509 |
|
||||
510 | return None |
|
|||
511 |
|
809 | |||
512 | if colormap=="tricolor": |
|
810 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
513 | ncolor = 3 |
|
811 | ||
514 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
812 | baseObj = ColorPlot() | |
515 | h = numpy.array((240., 0.)) |
|
813 | specObj = ColorPlot() | |
516 | # Lightness and saturation are constant (values taken from C example). |
|
814 | baseObj1 = ColorPlot() | |
517 | l = numpy.array((0.6, 0.6)) |
|
815 | specObj1 = ColorPlot() | |
518 | s = numpy.array((0.8, 0.8)) |
|
816 | ||
|
817 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True) | |||
|
818 | specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True) | |||
519 |
|
819 | |||
520 | # number of cmap1 colours is 256 in this case. |
|
820 | baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True) | |
521 | plplot.plscmap1n(ncolor) |
|
821 | specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True) | |
522 | # Interpolate between control points to set up cmap1. |
|
|||
523 | plplot.plscmap1l(0, i, h, l, s) |
|
|||
524 |
|
822 | |||
525 | return None |
|
823 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
526 |
|
824 | |||
527 | if colormap == 'rgb' or colormap == 'rgb666': |
|
825 | plplot.plbop() | |
528 |
|
826 | baseObj.iniSubpage() | ||
529 | color_sz = 6 |
|
827 | baseObj.plotData(data) | |
530 | ncolor = color_sz*color_sz*color_sz |
|
|||
531 | pos = numpy.zeros((ncolor)) |
|
|||
532 | r = numpy.zeros((ncolor)) |
|
|||
533 | g = numpy.zeros((ncolor)) |
|
|||
534 | b = numpy.zeros((ncolor)) |
|
|||
535 | ind = 0 |
|
|||
536 | for ri in range(color_sz): |
|
|||
537 | for gi in range(color_sz): |
|
|||
538 | for bi in range(color_sz): |
|
|||
539 | r[ind] = ri/(color_sz-1.0) |
|
|||
540 | g[ind] = gi/(color_sz-1.0) |
|
|||
541 | b[ind] = bi/(color_sz-1.0) |
|
|||
542 | pos[ind] = ind/(ncolor-1.0) |
|
|||
543 | ind += 1 |
|
|||
544 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
|||
545 |
|
||||
546 | if colormap == 'rgb676': |
|
|||
547 | ncolor = 6*7*6 |
|
|||
548 | pos = numpy.zeros((ncolor)) |
|
|||
549 | r = numpy.zeros((ncolor)) |
|
|||
550 | g = numpy.zeros((ncolor)) |
|
|||
551 | b = numpy.zeros((ncolor)) |
|
|||
552 | ind = 0 |
|
|||
553 | for ri in range(8): |
|
|||
554 | for gi in range(8): |
|
|||
555 | for bi in range(4): |
|
|||
556 | r[ind] = ri/(6-1.0) |
|
|||
557 | g[ind] = gi/(7-1.0) |
|
|||
558 | b[ind] = bi/(6-1.0) |
|
|||
559 | pos[ind] = ind/(ncolor-1.0) |
|
|||
560 | ind += 1 |
|
|||
561 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
|||
562 |
|
828 | |||
563 | if colormap == 'rgb685': |
|
829 | specObj.iniSubpage() | |
564 | ncolor = 6*8*5 |
|
830 | specObj.plotData(data) | |
565 | pos = numpy.zeros((ncolor)) |
|
|||
566 | r = numpy.zeros((ncolor)) |
|
|||
567 | g = numpy.zeros((ncolor)) |
|
|||
568 | b = numpy.zeros((ncolor)) |
|
|||
569 | ind = 0 |
|
|||
570 | for ri in range(8): |
|
|||
571 | for gi in range(8): |
|
|||
572 | for bi in range(4): |
|
|||
573 | r[ind] = ri/(6-1.0) |
|
|||
574 | g[ind] = gi/(8-1.0) |
|
|||
575 | b[ind] = bi/(5-1.0) |
|
|||
576 | pos[ind] = ind/(ncolor-1.0) |
|
|||
577 | ind += 1 |
|
|||
578 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
|||
579 |
|
||||
580 | if colormap == 'rgb884': |
|
|||
581 | ncolor = 8*8*4 |
|
|||
582 | pos = numpy.zeros((ncolor)) |
|
|||
583 | r = numpy.zeros((ncolor)) |
|
|||
584 | g = numpy.zeros((ncolor)) |
|
|||
585 | b = numpy.zeros((ncolor)) |
|
|||
586 | ind = 0 |
|
|||
587 | for ri in range(8): |
|
|||
588 | for gi in range(8): |
|
|||
589 | for bi in range(4): |
|
|||
590 | r[ind] = ri/(8-1.0) |
|
|||
591 | g[ind] = gi/(8-1.0) |
|
|||
592 | b[ind] = bi/(4-1.0) |
|
|||
593 | pos[ind] = ind/(ncolor-1.0) |
|
|||
594 | ind += 1 |
|
|||
595 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
|||
596 |
|
831 | |||
597 | if ncolor == None: |
|
832 | baseObj1.iniSubpage() | |
598 | raise ValueError, "The colormap selected is not valid" |
|
833 | baseObj1.plotData(data) | |
599 |
|
834 | |||
600 | plplot.plscmap1n(ncolor) |
|
835 | specObj1.iniSubpage() | |
601 | plplot.plscmap1l(1, pos, r, g, b) |
|
836 | specObj1.plotData(data) | |
602 |
|
837 | |||
603 | return rgb_lvl No newline at end of file |
|
838 | plplot.plflush() | |
|
839 | ||||
|
840 | plplot.plspause(1) | |||
|
841 | plplot.plend() | |||
|
842 | exit(0) | |||
|
843 | ||||
|
844 |
@@ -1,234 +1,149 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
|
8 | import os, sys | |||
8 | import numpy |
|
9 | import numpy | |
9 | import plplot |
|
10 | import plplot | |
10 |
|
11 | |||
11 | from BaseGraph import * |
|
12 | path = os.path.split(os.getcwd())[0] | |
|
13 | sys.path.append(path) | |||
12 |
|
14 | |||
13 | class Spectrum: |
|
15 | from Graphics.BaseGraph import * | |
14 |
|
16 | from Model.Spectra import Spectra | ||
15 | graphObjDict = {} |
|
|||
16 | showColorbar = False |
|
|||
17 | showPowerProfile = True |
|
|||
18 |
|
||||
19 | __szchar = 0.7 |
|
|||
20 | __xrange = None |
|
|||
21 | __yrange = None |
|
|||
22 | __zrange = None |
|
|||
23 | baseObj = BaseGraph() |
|
|||
24 |
|
17 | |||
|
18 | class Spectrum(): | |||
25 |
|
19 | |||
26 | def __init__(self): |
|
20 | def __init__(self, Spectra): | |
27 |
|
||||
28 | key = "spec" |
|
|||
29 |
|
|
21 | ||
30 | baseObj = BaseGraph() |
|
|||
31 | baseObj.setName(key) |
|
|||
32 |
|
||||
33 | self.graphObjDict[key] = baseObj |
|
|||
34 |
|
||||
35 |
|
||||
36 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False): |
|
|||
37 |
|
|
22 | """ | |
38 | """ |
|
|||
39 |
|
||||
40 | xi = 0.12; xw = 0.78; xf = xi + xw |
|
|||
41 | yi = 0.14; yw = 0.80; yf = yi + yw |
|
|||
42 |
|
||||
43 | xcmapi = xcmapf = 0.; xpowi = xpowf = 0. |
|
|||
44 |
|
||||
45 | key = "spec" |
|
|||
46 | baseObj = self.graphObjDict[key] |
|
|||
47 | baseObj.setSubpage(subpage) |
|
|||
48 | baseObj.setSzchar(self.__szchar) |
|
|||
49 | baseObj.setOpt("bcnts","bcnts") |
|
|||
50 | baseObj.setup(title, |
|
|||
51 | xlabel, |
|
|||
52 | ylabel, |
|
|||
53 | colormap) |
|
|||
54 |
|
||||
55 | if showColorbar: |
|
|||
56 | key = "colorbar" |
|
|||
57 |
|
||||
58 | cmapObj = BaseGraph() |
|
|||
59 | cmapObj.setName(key) |
|
|||
60 | cmapObj.setSubpage(subpage) |
|
|||
61 | cmapObj.setSzchar(self.__szchar) |
|
|||
62 | cmapObj.setOpt("bc","bcmt") |
|
|||
63 | cmapObj.setup(title="dBs", |
|
|||
64 | xlabel="", |
|
|||
65 | ylabel="", |
|
|||
66 | colormap=colormap) |
|
|||
67 |
|
||||
68 | self.graphObjDict[key] = cmapObj |
|
|||
69 |
|
||||
70 | xcmapi = 0. |
|
|||
71 | xcmapw = 0.05 |
|
|||
72 | xw -= xcmapw |
|
|||
73 |
|
|
23 | ||
74 | if showPowerProfile: |
|
24 | Inputs: | |
75 | key = "powerprof" |
|
|||
76 |
|
|
25 | ||
77 | powObj = BaseGraph() |
|
26 | type: "power" ->> Potencia | |
78 | powObj.setName(key) |
|
27 | "iq" ->> Real + Imaginario | |
79 | powObj.setSubpage(subpage) |
|
28 | """ | |
80 | powObj.setSzchar(self.__szchar) |
|
|||
81 | plplot.pllsty(2) |
|
|||
82 | powObj.setOpt("bcntg","bc") |
|
|||
83 | plplot.pllsty(1) |
|
|||
84 | powObj.setup(title="Power Profile", |
|
|||
85 | xlabel="dBs", |
|
|||
86 | ylabel="") |
|
|||
87 |
|
||||
88 | self.graphObjDict[key] = powObj |
|
|||
89 |
|
||||
90 | xpowi = 0. |
|
|||
91 | xpoww = 0.24 |
|
|||
92 | xw -= xpoww |
|
|||
93 |
|
||||
94 | xf = xi + xw |
|
|||
95 | yf = yi + yw |
|
|||
96 | xcmapf = xf |
|
|||
97 |
|
29 | |||
98 | baseObj.setScreenPos([xi, xf], [yi, yf]) |
|
30 | self.__isPlotConfig = False | |
99 |
|
31 | |||
100 | if showColorbar: |
|
32 | self.__isPlotIni = False | |
101 | xcmapi = xf + 0.02 |
|
|||
102 | xcmapf = xcmapi + xcmapw |
|
|||
103 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) |
|
|||
104 |
|
||||
105 | if showPowerProfile: |
|
|||
106 | xpowi = xcmapf + 0.06 |
|
|||
107 | xpowf = xpowi + xpoww |
|
|||
108 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) |
|
|||
109 |
|
||||
110 |
|
33 | |||
111 | # baseObj.initSubpage() |
|
34 | self.__xrange = None | |
112 | # |
|
|||
113 | # if showColorbar: |
|
|||
114 | # cmapObj.initPlot() |
|
|||
115 | # |
|
|||
116 | # if showPowerProfile: |
|
|||
117 | # powObj.initPlot() |
|
|||
118 |
|
||||
119 | self.showColorbar = showColorbar |
|
|||
120 | self.showPowerProfile = showPowerProfile |
|
|||
121 |
|
||||
122 | def setRanges(self, xrange, yrange, zrange): |
|
|||
123 |
|
35 | |||
124 | key = "spec" |
|
36 | self.__yrange = None | |
125 | baseObj = self.graphObjDict[key] |
|
|||
126 | baseObj.setRanges(xrange, yrange, zrange) |
|
|||
127 |
|
37 | |||
128 | keyList = self.graphObjDict.keys() |
|
38 | self.nGraphs = 0 | |
129 |
|
39 | |||
130 | key = "colorbar" |
|
40 | self.graphObjList = [] | |
131 | if key in keyList: |
|
41 | ||
132 | cmapObj = self.graphObjDict[key] |
|
42 | self.m_Spectra = Spectra | |
133 | cmapObj.setRanges([0., 1.], zrange) |
|
|||
134 |
|
43 | |||
135 | key = "powerprof" |
|
|||
136 | if key in keyList: |
|
|||
137 | powObj = self.graphObjDict[key] |
|
|||
138 | powObj.setRanges(zrange, yrange) |
|
|||
139 |
|
44 | |||
140 | def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
45 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |
|
46 | ||||
|
47 | graphObj = ColorPlot() | |||
|
48 | graphObj.setup(subpage, | |||
|
49 | title, | |||
|
50 | xlabel, | |||
|
51 | ylabel, | |||
|
52 | showColorbar=showColorbar, | |||
|
53 | showPowerProfile=showPowerProfile, | |||
|
54 | XAxisAsTime=XAxisAsTime) | |||
|
55 | ||||
|
56 | self.graphObjList.append(graphObj) | |||
|
57 | ||||
|
58 | ||||
|
59 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |||
141 |
|
60 | |||
142 | key = "spec" |
|
61 | nChan = int(self.m_Spectra.m_SystemHeader.numChannels) | |
143 | baseObj = self.graphObjDict[key] |
|
|||
144 | baseObj.initSubpage() |
|
|||
145 |
|
62 | |||
146 | if xmin == None: |
|
63 | myTitle = "" | |
147 | xmin = 0. |
|
64 | myXlabel = "" | |
|
65 | myYlabel = "" | |||
148 |
|
66 | |||
149 | if xmax == None: |
|
67 | for i in range(nChan): | |
150 | xmax = 1. |
|
68 | if titleList != None: | |
|
69 | myTitle = titleList[i] | |||
|
70 | myXlabel = xlabelList[i] | |||
|
71 | myYlabel = ylabelList[i] | |||
|
72 | ||||
|
73 | self.__addGraph(i+1, | |||
|
74 | title=myTitle, | |||
|
75 | xlabel=myXlabel, | |||
|
76 | ylabel=myYlabel, | |||
|
77 | showColorbar=showColorbar, | |||
|
78 | showPowerProfile=showPowerProfile, | |||
|
79 | XAxisAsTime=XAxisAsTime) | |||
|
80 | ||||
|
81 | self.nGraphs = nChan | |||
|
82 | self.__isPlotConfig = True | |||
151 |
|
83 | |||
152 | if ymin == None: |
|
84 | def iniPlot(self): | |
153 | ymin = 0. |
|
|||
154 |
|
85 | |||
155 | if ymax == None: |
|
86 | nx = int(numpy.sqrt(self.nGraphs)+1) | |
156 | ymax = 1. |
|
87 | #ny = int(self.nGraphs/nx) | |
157 |
|
88 | |||
158 | if zmin == None: |
|
89 | plplot.plsetopt("geometry", "%dx%d" %(400*nx, 300*nx)) | |
159 | zmin = numpy.nanmin(data) |
|
90 | plplot.plsdev("xcairo") | |
|
91 | plplot.plscolbg(255,255,255) | |||
|
92 | plplot.plscol0(1,0,0,0) | |||
|
93 | plplot.plinit() | |||
|
94 | plplot.plspause(False) | |||
|
95 | plplot.pladv(0) | |||
|
96 | plplot.plssub(nx, nx) | |||
160 |
|
97 | |||
161 | if zmax == None: |
|
98 | self.__isPlotIni = True | |
162 | zmax = numpy.nanmax(data) |
|
|||
163 |
|
99 | |||
164 | if not(baseObj.hasRange): |
|
100 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): | |
165 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) |
|
101 | ||
166 |
|
102 | if not(self.__isPlotConfig): | ||
167 | baseObj.basicPcolorPlot(data, xmin, xmax, ymin, ymax, baseObj.zrange[0], baseObj.zrange[1]) |
|
103 | self.setup(titleList, | |
168 |
|
104 | xlabelList, | ||
169 | if self.showColorbar: |
|
105 | ylabelList, | |
170 |
|
|
106 | showColorbar, | |
171 | cmapObj = self.graphObjDict[key] |
|
107 | showPowerProfile, | |
172 | cmapObj.colorbarPlot() |
|
108 | XAxisAsTime) | |
173 |
|
109 | |||
174 |
if self. |
|
110 | if not(self.__isPlotIni): | |
175 | power = numpy.average(data, axis=1) |
|
111 | self.iniPlot() | |
176 |
|
|
112 | ||
177 | step = (ymax - ymin)/(power.shape[0]-1) |
|
113 | data = numpy.log10(self.m_Spectra.data_spc) | |
178 | heis = numpy.arange(ymin, ymax + step, step) |
|
114 | ||
|
115 | nX, nY, nChan = numpy.shape(data) | |||
|
116 | ||||
|
117 | x = numpy.arange(nX) | |||
|
118 | y = self.m_Spectra.heights | |||
|
119 | ||||
|
120 | if xmin == None: xmin = x[0] | |||
|
121 | if xmax == None: xmax = x[-1] | |||
|
122 | if ymin == None: ymin = y[0] | |||
|
123 | if ymax == None: ymax = y[-1] | |||
|
124 | if zmin == None: zmin = numpy.nanmin(abs(data)) | |||
|
125 | if zmax == None: zmax = numpy.nanmax(abs(data)) | |||
|
126 | ||||
|
127 | plplot.plbop() | |||
|
128 | for i in range(self.nGraphs): | |||
|
129 | self.graphObjList[i].iniSubpage() | |||
|
130 | self.graphObjList[i].plotData(data[:,:,i], | |||
|
131 | x, | |||
|
132 | y, | |||
|
133 | xmin=xmin, | |||
|
134 | xmax=xmax, | |||
|
135 | ymin=ymin, | |||
|
136 | ymax=ymax, | |||
|
137 | zmin=zmin, | |||
|
138 | zmax=zmax) | |||
179 |
|
139 | |||
180 | key = "powerprof" |
|
140 | ||
181 | powObj = self.graphObjDict[key] |
|
141 | plplot.plflush() | |
182 | powObj.basicXYPlot(power, heis) |
|
142 | plplot.pleop() | |
183 |
|
||||
184 | class CrossSpectrum: |
|
|||
185 | graphObjDict = {} |
|
|||
186 | showColorbar = False |
|
|||
187 | showPowerProfile = True |
|
|||
188 |
|
143 | |||
189 | __szchar = 0.7 |
|
144 | def end(self): | |
190 | __showPhase = False |
|
145 | plplot.plend() | |
191 | __xrange = None |
|
146 | ||
192 | __yrange = None |
|
|||
193 | __zrange = None |
|
|||
194 | m_BaseGraph= BaseGraph() |
|
|||
195 |
|
||||
196 | def __init__(self): |
|
|||
197 | pass |
|
|||
198 |
|
||||
199 | def setup(self, subpage, title, xlabel, ylabel, colormap, showColorbar, showPowerProfile): |
|
|||
200 | pass |
|
|||
201 |
|
||||
202 | def setRanges(self, xrange, yrange, zrange): |
|
|||
203 | pass |
|
|||
204 |
|
||||
205 | def plotData(self, data, xmin, xmax, ymin, ymax, zmin, zmax): |
|
|||
206 | pass |
|
|||
207 |
|
147 | |||
208 | if __name__ == '__main__': |
|
148 | if __name__ == '__main__': | |
209 |
|
149 | pass No newline at end of file | ||
210 | import numpy |
|
|||
211 | plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) |
|
|||
212 | plplot.plsdev("xcairo") |
|
|||
213 | plplot.plscolbg(255,255,255) |
|
|||
214 | plplot.plscol0(1,0,0,0) |
|
|||
215 | plplot.plinit() |
|
|||
216 | plplot.plssub(2, 2) |
|
|||
217 |
|
||||
218 | nx = 64 |
|
|||
219 | ny = 100 |
|
|||
220 |
|
||||
221 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
|||
222 |
|
||||
223 | baseObj = ColorPlot() |
|
|||
224 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) |
|
|||
225 | baseObj.plotData(data) |
|
|||
226 |
|
||||
227 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
|||
228 |
|
||||
229 | spec2Obj = ColorPlot() |
|
|||
230 | spec2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) |
|
|||
231 | spec2Obj.plotData(data) |
|
|||
232 |
|
||||
233 | plplot.plend() |
|
|||
234 | exit(0) No newline at end of file |
|
@@ -1,813 +1,813 | |||||
1 | ''' |
|
1 | ''' | |
2 | File: SpectraIO.py |
|
2 | File: SpectraIO.py | |
3 | Created on 20/02/2012 |
|
3 | Created on 20/02/2012 | |
4 |
|
4 | |||
5 | @author $Author$ |
|
5 | @author $Author$ | |
6 | @version $Id$ |
|
6 | @version $Id$ | |
7 | ''' |
|
7 | ''' | |
8 |
|
8 | |||
9 | import os, sys |
|
9 | import os, sys | |
10 | import numpy |
|
10 | import numpy | |
11 | import glob |
|
11 | import glob | |
12 | import fnmatch |
|
12 | import fnmatch | |
13 | import time, datetime |
|
13 | import time, datetime | |
14 |
|
14 | |||
15 | path = os.path.split(os.getcwd())[0] |
|
15 | path = os.path.split(os.getcwd())[0] | |
16 | sys.path.append(path) |
|
16 | sys.path.append(path) | |
17 |
|
17 | |||
18 | from HeaderIO import * |
|
18 | from HeaderIO import * | |
19 | from DataIO import DataReader |
|
19 | from DataIO import DataReader | |
20 | from DataIO import DataWriter |
|
20 | from DataIO import DataWriter | |
21 |
|
21 | |||
22 | from Model.Spectra import Spectra |
|
22 | from Model.Spectra import Spectra | |
23 |
|
23 | |||
24 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
24 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
25 | """ |
|
25 | """ | |
26 | Esta funcion determina si un archivo de datos en formato Jicamarca(.r) se encuentra |
|
26 | Esta funcion determina si un archivo de datos en formato Jicamarca(.r) se encuentra | |
27 | o no dentro del rango de fecha especificado. |
|
27 | o no dentro del rango de fecha especificado. | |
28 |
|
28 | |||
29 | Inputs: |
|
29 | Inputs: | |
30 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
30 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
31 |
|
31 | |||
32 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
32 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
33 | segundos contados desde 01/01/1970. |
|
33 | segundos contados desde 01/01/1970. | |
34 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
34 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
35 | segundos contados desde 01/01/1970. |
|
35 | segundos contados desde 01/01/1970. | |
36 |
|
36 | |||
37 | Return: |
|
37 | Return: | |
38 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
38 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
39 | fecha especificado, de lo contrario retorna False. |
|
39 | fecha especificado, de lo contrario retorna False. | |
40 |
|
40 | |||
41 | Excepciones: |
|
41 | Excepciones: | |
42 | Si el archivo no existe o no puede ser abierto |
|
42 | Si el archivo no existe o no puede ser abierto | |
43 | Si la cabecera no puede ser leida. |
|
43 | Si la cabecera no puede ser leida. | |
44 |
|
44 | |||
45 | """ |
|
45 | """ | |
46 | m_BasicHeader = BasicHeader() |
|
46 | m_BasicHeader = BasicHeader() | |
47 |
|
47 | |||
48 | try: |
|
48 | try: | |
49 | fp = open(filename,'rb') |
|
49 | fp = open(filename,'rb') | |
50 | except: |
|
50 | except: | |
51 | raise IOError, "The file %s can't be opened" %(filename) |
|
51 | raise IOError, "The file %s can't be opened" %(filename) | |
52 |
|
52 | |||
53 | if not(m_BasicHeader.read(fp)): |
|
53 | if not(m_BasicHeader.read(fp)): | |
54 | raise IOError, "The file %s has not a valid header" %(filename) |
|
54 | raise IOError, "The file %s has not a valid header" %(filename) | |
55 |
|
55 | |||
56 | fp.close() |
|
56 | fp.close() | |
57 |
|
57 | |||
58 | if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): |
|
58 | if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): | |
59 | return 0 |
|
59 | return 0 | |
60 |
|
60 | |||
61 | return 1 |
|
61 | return 1 | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | class SpectraReader(DataReader): |
|
64 | class SpectraReader(DataReader): | |
65 | """ |
|
65 | """ | |
66 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
66 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
67 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
67 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
68 | perfiless*alturas*canales) son almacenados en la variable "buffer". |
|
68 | perfiless*alturas*canales) son almacenados en la variable "buffer". | |
69 |
|
69 | |||
70 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
70 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
71 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
71 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
72 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
72 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
73 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
73 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
74 |
|
74 | |||
75 | Example: |
|
75 | Example: | |
76 |
|
76 | |||
77 | dpath = "/home/myuser/data" |
|
77 | dpath = "/home/myuser/data" | |
78 |
|
78 | |||
79 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
79 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
80 |
|
80 | |||
81 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
81 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
82 |
|
82 | |||
83 | readerObj = SpectraReader() |
|
83 | readerObj = SpectraReader() | |
84 |
|
84 | |||
85 | readerObj.setup(dpath, startTime, endTime) |
|
85 | readerObj.setup(dpath, startTime, endTime) | |
86 |
|
86 | |||
87 | while(True): |
|
87 | while(True): | |
88 |
|
88 | |||
89 | readerObj.getData() |
|
89 | readerObj.getData() | |
90 |
|
90 | |||
91 | print readerObj.m_Spectra.data |
|
91 | print readerObj.m_Spectra.data | |
92 |
|
92 | |||
93 | if readerObj.noMoreFiles: |
|
93 | if readerObj.noMoreFiles: | |
94 | break |
|
94 | break | |
95 |
|
95 | |||
96 | """ |
|
96 | """ | |
97 |
|
97 | |||
98 | #speed of light |
|
98 | #speed of light | |
99 | __c = 3E8 |
|
99 | __c = 3E8 | |
100 |
|
100 | |||
101 | def __init__( self, m_Spectra = None ): |
|
101 | def __init__( self, m_Spectra = None ): | |
102 | """ |
|
102 | """ | |
103 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
103 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
104 |
|
104 | |||
105 | Input: |
|
105 | Input: | |
106 | m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
106 | m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para | |
107 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
107 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
108 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
108 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
109 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
109 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
110 | bloque de datos. |
|
110 | bloque de datos. | |
111 | Si este parametro no es pasado se creara uno internamente. |
|
111 | Si este parametro no es pasado se creara uno internamente. | |
112 |
|
112 | |||
113 | Variables afectadas: |
|
113 | Variables afectadas: | |
114 | self.m_Spectra |
|
114 | self.m_Spectra | |
115 | self.m_BasicHeader |
|
115 | self.m_BasicHeader | |
116 | self.m_SystemHeader |
|
116 | self.m_SystemHeader | |
117 | self.m_RadarControllerHeader |
|
117 | self.m_RadarControllerHeader | |
118 | self.m_ProcessingHeader |
|
118 | self.m_ProcessingHeader | |
119 |
|
119 | |||
120 |
|
120 | |||
121 | Return: |
|
121 | Return: | |
122 | Void |
|
122 | Void | |
123 |
|
123 | |||
124 | """ |
|
124 | """ | |
125 | if m_Spectra == None: |
|
125 | if m_Spectra == None: | |
126 | m_Spectra = Spectra() |
|
126 | m_Spectra = Spectra() | |
127 |
|
127 | |||
128 | if not( isinstance(m_Spectra, Spectra) ): |
|
128 | if not( isinstance(m_Spectra, Spectra) ): | |
129 | raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object" |
|
129 | raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object" | |
130 |
|
130 | |||
131 | self.m_Spectra = m_Spectra |
|
131 | self.m_Spectra = m_Spectra | |
132 |
|
132 | |||
133 | self.m_BasicHeader = BasicHeader() |
|
133 | self.m_BasicHeader = BasicHeader() | |
134 |
|
134 | |||
135 | self.m_SystemHeader = SystemHeader() |
|
135 | self.m_SystemHeader = SystemHeader() | |
136 |
|
136 | |||
137 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
137 | self.m_RadarControllerHeader = RadarControllerHeader() | |
138 |
|
138 | |||
139 | self.m_ProcessingHeader = ProcessingHeader() |
|
139 | self.m_ProcessingHeader = ProcessingHeader() | |
140 |
|
140 | |||
141 | self.__fp = None |
|
141 | self.__fp = None | |
142 |
|
142 | |||
143 | self.__idFile = None |
|
143 | self.__idFile = None | |
144 |
|
144 | |||
145 | self.__startDateTime = None |
|
145 | self.__startDateTime = None | |
146 |
|
146 | |||
147 | self.__endDateTime = None |
|
147 | self.__endDateTime = None | |
148 |
|
148 | |||
149 | self.__dataType = None |
|
149 | self.__dataType = None | |
150 |
|
150 | |||
151 | self.__fileSizeByHeader = 0 |
|
151 | self.__fileSizeByHeader = 0 | |
152 |
|
152 | |||
153 | self.__pathList = [] |
|
153 | self.__pathList = [] | |
154 |
|
154 | |||
155 | self.filenameList = [] |
|
155 | self.filenameList = [] | |
156 |
|
156 | |||
157 | self.__lastUTTime = 0 |
|
157 | self.__lastUTTime = 0 | |
158 |
|
158 | |||
159 | self.__maxTimeStep = 30 |
|
159 | self.__maxTimeStep = 30 | |
160 |
|
160 | |||
161 | self.__flagIsNewFile = 0 |
|
161 | self.__flagIsNewFile = 0 | |
162 |
|
162 | |||
163 | self.flagResetProcessing = 0 |
|
163 | self.flagResetProcessing = 0 | |
164 |
|
164 | |||
165 | self.flagIsNewBlock = 0 |
|
165 | self.flagIsNewBlock = 0 | |
166 |
|
166 | |||
167 | self.noMoreFiles = 0 |
|
167 | self.noMoreFiles = 0 | |
168 |
|
168 | |||
169 | self.nReadBlocks = 0 |
|
169 | self.nReadBlocks = 0 | |
170 |
|
170 | |||
171 | self.online = 0 |
|
171 | self.online = 0 | |
172 |
|
172 | |||
173 | self.firstHeaderSize = 0 |
|
173 | self.firstHeaderSize = 0 | |
174 |
|
174 | |||
175 | self.basicHeaderSize = 24 |
|
175 | self.basicHeaderSize = 24 | |
176 |
|
176 | |||
177 | self.filename = None |
|
177 | self.filename = None | |
178 |
|
178 | |||
179 | self.fileSize = None |
|
179 | self.fileSize = None | |
180 |
|
180 | |||
181 | self.__buffer_spc = None |
|
181 | self.__buffer_spc = None | |
182 | self.__buffer_cspc = None |
|
182 | self.__buffer_cspc = None | |
183 | self.__buffer_dc = None |
|
183 | self.__buffer_dc = None | |
184 |
|
184 | |||
185 | self.__buffer_id = 0 |
|
185 | self.__buffer_id = 0 | |
186 |
|
186 | |||
187 | self.__ippSeconds = 0 |
|
187 | self.__ippSeconds = 0 | |
188 |
|
188 | |||
189 | self.nSelfChannels = 0 |
|
189 | self.nSelfChannels = 0 | |
190 |
|
190 | |||
191 | self.nCrossPairs = 0 |
|
191 | self.nCrossPairs = 0 | |
192 |
|
192 | |||
193 | self.nChannels = 0 |
|
193 | self.nChannels = 0 | |
194 |
|
194 | |||
195 | def __rdSystemHeader( self, fp=None ): |
|
195 | def __rdSystemHeader( self, fp=None ): | |
196 | if fp == None: |
|
196 | if fp == None: | |
197 | fp = self.__fp |
|
197 | fp = self.__fp | |
198 |
|
198 | |||
199 | self.m_SystemHeader.read( fp ) |
|
199 | self.m_SystemHeader.read( fp ) | |
200 |
|
200 | |||
201 | def __rdRadarControllerHeader( self, fp=None ): |
|
201 | def __rdRadarControllerHeader( self, fp=None ): | |
202 | if fp == None: |
|
202 | if fp == None: | |
203 | fp = self.__fp |
|
203 | fp = self.__fp | |
204 |
|
204 | |||
205 | self.m_RadarControllerHeader.read(fp) |
|
205 | self.m_RadarControllerHeader.read(fp) | |
206 |
|
206 | |||
207 | def __rdProcessingHeader( self,fp=None ): |
|
207 | def __rdProcessingHeader( self,fp=None ): | |
208 | if fp == None: |
|
208 | if fp == None: | |
209 | fp = self.__fp |
|
209 | fp = self.__fp | |
210 |
|
210 | |||
211 | self.m_ProcessingHeader.read(fp) |
|
211 | self.m_ProcessingHeader.read(fp) | |
212 |
|
212 | |||
213 | def __rdBasicHeader( self, fp=None ): |
|
213 | def __rdBasicHeader( self, fp=None ): | |
214 | if fp == None: |
|
214 | if fp == None: | |
215 | fp = self.__fp |
|
215 | fp = self.__fp | |
216 |
|
216 | |||
217 | self.m_BasicHeader.read(fp) |
|
217 | self.m_BasicHeader.read(fp) | |
218 |
|
218 | |||
219 | def __readFirstHeader( self ): |
|
219 | def __readFirstHeader( self ): | |
220 | self.__rdBasicHeader() |
|
220 | self.__rdBasicHeader() | |
221 | self.__rdSystemHeader() |
|
221 | self.__rdSystemHeader() | |
222 | self.__rdRadarControllerHeader() |
|
222 | self.__rdRadarControllerHeader() | |
223 | self.__rdProcessingHeader() |
|
223 | self.__rdProcessingHeader() | |
224 | self.firstHeaderSize = self.m_BasicHeader.size |
|
224 | self.firstHeaderSize = self.m_BasicHeader.size | |
225 |
|
225 | |||
226 | data_type = int( numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR) ) |
|
226 | data_type = int( numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR) ) | |
227 | if data_type == 0: |
|
227 | if data_type == 0: | |
228 | tmp = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
228 | tmp = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
229 |
|
229 | |||
230 | elif data_type == 1: |
|
230 | elif data_type == 1: | |
231 | tmp = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
231 | tmp = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
232 |
|
232 | |||
233 | elif data_type == 2: |
|
233 | elif data_type == 2: | |
234 | tmp = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
234 | tmp = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
235 |
|
235 | |||
236 | elif data_type == 3: |
|
236 | elif data_type == 3: | |
237 | tmp = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
237 | tmp = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
238 |
|
238 | |||
239 | elif data_type == 4: |
|
239 | elif data_type == 4: | |
240 | tmp = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
240 | tmp = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
241 |
|
241 | |||
242 | elif data_type == 5: |
|
242 | elif data_type == 5: | |
243 | tmp = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
243 | tmp = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
244 |
|
244 | |||
245 | else: |
|
245 | else: | |
246 | raise ValueError, 'Data type was not defined' |
|
246 | raise ValueError, 'Data type was not defined' | |
247 |
|
247 | |||
248 | xi = self.m_ProcessingHeader.firstHeight |
|
248 | xi = self.m_ProcessingHeader.firstHeight | |
249 | step = self.m_ProcessingHeader.deltaHeight |
|
249 | step = self.m_ProcessingHeader.deltaHeight | |
250 | xf = xi + self.m_ProcessingHeader.numHeights*step |
|
250 | xf = xi + self.m_ProcessingHeader.numHeights*step | |
251 |
|
251 | |||
252 | self.__heights = numpy.arange(xi, xf, step) |
|
252 | self.__heights = numpy.arange(xi, xf, step) | |
253 | self.__dataType = tmp |
|
253 | self.__dataType = tmp | |
254 | self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) |
|
254 | self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) | |
255 | self.__ippSeconds = 2 * 1000 * self.m_RadarControllerHeader.ipp/self.__c |
|
255 | self.__ippSeconds = 2 * 1000 * self.m_RadarControllerHeader.ipp/self.__c | |
256 |
|
256 | |||
257 | def __setNextFileOnline( self ): |
|
257 | def __setNextFileOnline( self ): | |
258 | return 1 |
|
258 | return 1 | |
259 |
|
259 | |||
260 | def __setNextFileOffline( self ): |
|
260 | def __setNextFileOffline( self ): | |
261 | idFile = self.__idFile |
|
261 | idFile = self.__idFile | |
262 |
|
262 | |||
263 | while(True): |
|
263 | while(True): | |
264 | idFile += 1 |
|
264 | idFile += 1 | |
265 |
|
265 | |||
266 | if not( idFile < len(self.filenameList) ): |
|
266 | if not( idFile < len(self.filenameList) ): | |
267 | self.noMoreFiles = 1 |
|
267 | self.noMoreFiles = 1 | |
268 | return 0 |
|
268 | return 0 | |
269 |
|
269 | |||
270 | filename = self.filenameList[idFile] |
|
270 | filename = self.filenameList[idFile] | |
271 | fileSize = os.path.getsize(filename) |
|
271 | fileSize = os.path.getsize(filename) | |
272 |
|
272 | |||
273 | try: |
|
273 | try: | |
274 | fp = open( filename, 'rb' ) |
|
274 | fp = open( filename, 'rb' ) | |
275 | except: |
|
275 | except: | |
276 | raise IOError, "The file %s can't be opened" %filename |
|
276 | raise IOError, "The file %s can't be opened" %filename | |
277 |
|
277 | |||
278 | currentSize = fileSize - fp.tell() |
|
278 | currentSize = fileSize - fp.tell() | |
279 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize |
|
279 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize | |
280 |
|
280 | |||
281 | if (currentSize < neededSize): |
|
281 | if (currentSize < neededSize): | |
282 | print "Skipping the file %s due to it hasn't enough data" %filename |
|
282 | print "Skipping the file %s due to it hasn't enough data" %filename | |
283 | continue |
|
283 | continue | |
284 |
|
284 | |||
285 | break |
|
285 | break | |
286 |
|
286 | |||
287 | self.__flagIsNewFile = 1 |
|
287 | self.__flagIsNewFile = 1 | |
288 | self.__idFile = idFile |
|
288 | self.__idFile = idFile | |
289 | self.filename = filename |
|
289 | self.filename = filename | |
290 | self.fileSize = fileSize |
|
290 | self.fileSize = fileSize | |
291 | self.__fp = fp |
|
291 | self.__fp = fp | |
292 |
|
292 | |||
293 | print 'Setting the file: %s'%self.filename |
|
293 | print 'Setting the file: %s'%self.filename | |
294 |
|
294 | |||
295 | return 1 |
|
295 | return 1 | |
296 |
|
296 | |||
297 | def __setNextFile(self): |
|
297 | def __setNextFile(self): | |
298 | if self.online: |
|
298 | if self.online: | |
299 | newFile = self.__setNextFileOnline() |
|
299 | newFile = self.__setNextFileOnline() | |
300 | else: |
|
300 | else: | |
301 | newFile = self.__setNextFileOffline() |
|
301 | newFile = self.__setNextFileOffline() | |
302 |
|
302 | |||
303 | if not(newFile): |
|
303 | if not(newFile): | |
304 | return 0 |
|
304 | return 0 | |
305 |
|
305 | |||
306 | self.__readFirstHeader() |
|
306 | self.__readFirstHeader() | |
307 |
|
307 | |||
308 | return 1 |
|
308 | return 1 | |
309 |
|
309 | |||
310 | def __setNewBlock( self ): |
|
310 | def __setNewBlock( self ): | |
311 | if self.__fp == None: |
|
311 | if self.__fp == None: | |
312 | return 0 |
|
312 | return 0 | |
313 |
|
313 | |||
314 | if self.__flagIsNewFile: |
|
314 | if self.__flagIsNewFile: | |
315 | return 1 |
|
315 | return 1 | |
316 |
|
316 | |||
317 | currentSize = self.fileSize - self.__fp.tell() |
|
317 | currentSize = self.fileSize - self.__fp.tell() | |
318 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize |
|
318 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize | |
319 |
|
319 | |||
320 | #If there is enough data setting new data block |
|
320 | #If there is enough data setting new data block | |
321 | if ( currentSize >= neededSize ): |
|
321 | if ( currentSize >= neededSize ): | |
322 | self.__rdBasicHeader() |
|
322 | self.__rdBasicHeader() | |
323 | return 1 |
|
323 | return 1 | |
324 |
|
324 | |||
325 | #Setting new file |
|
325 | #Setting new file | |
326 | if not( self.__setNextFile() ): |
|
326 | if not( self.__setNextFile() ): | |
327 | return 0 |
|
327 | return 0 | |
328 |
|
328 | |||
329 | deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this |
|
329 | deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this | |
330 |
|
330 | |||
331 | self.flagResetProcessing = 0 |
|
331 | self.flagResetProcessing = 0 | |
332 |
|
332 | |||
333 | if deltaTime > self.__maxTimeStep: |
|
333 | if deltaTime > self.__maxTimeStep: | |
334 | self.flagResetProcessing = 1 |
|
334 | self.flagResetProcessing = 1 | |
335 | self.ns = 0 |
|
335 | self.ns = 0 | |
336 |
|
336 | |||
337 | return 1 |
|
337 | return 1 | |
338 |
|
338 | |||
339 |
|
339 | |||
340 |
|
340 | |||
341 | def __readBlock(self): |
|
341 | def __readBlock(self): | |
342 | """ |
|
342 | """ | |
343 | __readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
343 | __readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
344 | (self.__fp) y actualiza todos los parametros relacionados al bloque de datos |
|
344 | (self.__fp) y actualiza todos los parametros relacionados al bloque de datos | |
345 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
345 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
346 | es seteado a 0 |
|
346 | es seteado a 0 | |
347 |
|
347 | |||
348 | Inputs: |
|
348 | Inputs: | |
349 | None |
|
349 | None | |
350 |
|
350 | |||
351 | Return: |
|
351 | Return: | |
352 | None |
|
352 | None | |
353 |
|
353 | |||
354 | Variables afectadas: |
|
354 | Variables afectadas: | |
355 |
|
355 | |||
356 | self.__buffer_id |
|
356 | self.__buffer_id | |
357 |
|
357 | |||
358 | self.__buffer_sspc |
|
358 | self.__buffer_sspc | |
359 |
|
359 | |||
360 | self.__flagIsNewFile |
|
360 | self.__flagIsNewFile | |
361 |
|
361 | |||
362 | self.flagIsNewBlock |
|
362 | self.flagIsNewBlock | |
363 |
|
363 | |||
364 | self.nReadBlocks |
|
364 | self.nReadBlocks | |
365 |
|
365 | |||
366 | """ |
|
366 | """ | |
367 | Npair_SelfSpectra = 0 |
|
367 | Npair_SelfSpectra = 0 | |
368 | Npair_CrossSpectra = 0 |
|
368 | Npair_CrossSpectra = 0 | |
369 |
|
369 | |||
370 | for i in range( 0,self.m_ProcessingHeader.totalSpectra*2,2 ): |
|
370 | for i in range( 0,self.m_ProcessingHeader.totalSpectra*2,2 ): | |
371 | if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]: |
|
371 | if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]: | |
372 | Npair_SelfSpectra = Npair_SelfSpectra + 1 |
|
372 | Npair_SelfSpectra = Npair_SelfSpectra + 1 | |
373 | else: |
|
373 | else: | |
374 | Npair_CrossSpectra = Npair_CrossSpectra + 1 |
|
374 | Npair_CrossSpectra = Npair_CrossSpectra + 1 | |
375 |
|
375 | |||
376 | # self.__buffer_sspc = numpy.concatenate( (data_sspc,data_cspc,data_dcc), axis=0 ) |
|
376 | # self.__buffer_sspc = numpy.concatenate( (data_sspc,data_cspc,data_dcc), axis=0 ) | |
377 |
|
377 | |||
378 | self.__buffer_id = 0 |
|
378 | self.__buffer_id = 0 | |
379 | self.__flagIsNewFile = 0 |
|
379 | self.__flagIsNewFile = 0 | |
380 | self.flagIsNewBlock = 1 |
|
380 | self.flagIsNewBlock = 1 | |
381 |
|
381 | |||
382 | pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights |
|
382 | pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights | |
383 |
|
383 | |||
384 | spc = numpy.fromfile(self.__fp, self.__dataType[0], int(pts2read*Npair_SelfSpectra)) |
|
384 | spc = numpy.fromfile(self.__fp, self.__dataType[0], int(pts2read*Npair_SelfSpectra)) | |
385 | cspc = numpy.fromfile(self.__fp, self.__dataType, int(pts2read*Npair_CrossSpectra)) |
|
385 | cspc = numpy.fromfile(self.__fp, self.__dataType, int(pts2read*Npair_CrossSpectra)) | |
386 |
dc = numpy.fromfile(self.__fp, self.__dataType, int( |
|
386 | dc = numpy.fromfile(self.__fp, self.__dataType, int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) ) | |
387 |
|
387 | |||
388 | spc = spc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_SelfSpectra)) |
|
388 | spc = spc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_SelfSpectra)) | |
389 | cspc = cspc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_CrossSpectra)) |
|
389 | cspc = cspc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_CrossSpectra)) | |
390 |
dc = dc.reshape((self.m_ProcessingHeader. |
|
390 | dc = dc.reshape((self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) | |
391 |
|
391 | |||
392 | data_spc = spc |
|
392 | data_spc = spc | |
393 | data_cspc = cspc['real'] + cspc['imag']*1j |
|
393 | data_cspc = cspc['real'] + cspc['imag']*1j | |
394 | data_dc = dc['real'] + dc['imag']*1j |
|
394 | data_dc = dc['real'] + dc['imag']*1j | |
395 |
|
395 | |||
396 | self.__buffer_spc = data_spc |
|
396 | self.__buffer_spc = data_spc | |
397 | self.__buffer_cspc = data_cspc |
|
397 | self.__buffer_cspc = data_cspc | |
398 | self.__buffer_dc = data_dc |
|
398 | self.__buffer_dc = data_dc | |
399 |
|
399 | |||
400 | self.__flagIsNewFile = 0 |
|
400 | self.__flagIsNewFile = 0 | |
401 |
|
401 | |||
402 | self.flagIsNewBlock = 1 |
|
402 | self.flagIsNewBlock = 1 | |
403 |
|
403 | |||
404 | self.nReadBlocks += 1 |
|
404 | self.nReadBlocks += 1 | |
405 |
|
405 | |||
406 |
|
406 | |||
407 | def __hasNotDataInBuffer(self): |
|
407 | def __hasNotDataInBuffer(self): | |
408 | return 1 |
|
408 | return 1 | |
409 |
|
409 | |||
410 | def __searchFiles(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".pdata"): |
|
410 | def __searchFiles(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".pdata"): | |
411 | """ |
|
411 | """ | |
412 | __searchFiles realiza una busqueda de los archivos que coincidan con los parametros |
|
412 | __searchFiles realiza una busqueda de los archivos que coincidan con los parametros | |
413 | especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda |
|
413 | especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda | |
414 | correcta la estructura de directorios debe ser la siguiente: |
|
414 | correcta la estructura de directorios debe ser la siguiente: | |
415 |
|
415 | |||
416 | ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext |
|
416 | ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext | |
417 |
|
417 | |||
418 | [yyyy]: anio |
|
418 | [yyyy]: anio | |
419 | [ddd] : dia del anio |
|
419 | [ddd] : dia del anio | |
420 | [sss] : set del archivo |
|
420 | [sss] : set del archivo | |
421 |
|
421 | |||
422 | Inputs: |
|
422 | Inputs: | |
423 | path : Directorio de datos donde se realizara la busqueda. Todos los |
|
423 | path : Directorio de datos donde se realizara la busqueda. Todos los | |
424 | ficheros que concidan con el criterio de busqueda seran |
|
424 | ficheros que concidan con el criterio de busqueda seran | |
425 | almacenados en una lista y luego retornados. |
|
425 | almacenados en una lista y luego retornados. | |
426 | startDateTime : Fecha inicial. Rechaza todos los archivos donde |
|
426 | startDateTime : Fecha inicial. Rechaza todos los archivos donde | |
427 | file end time < startDateTime (objeto datetime.datetime) |
|
427 | file end time < startDateTime (objeto datetime.datetime) | |
428 |
|
428 | |||
429 | endDateTime : Fecha final. Rechaza todos los archivos donde |
|
429 | endDateTime : Fecha final. Rechaza todos los archivos donde | |
430 | file start time > endDateTime (obejto datetime.datetime) |
|
430 | file start time > endDateTime (obejto datetime.datetime) | |
431 |
|
431 | |||
432 | set : Set del primer archivo a leer. Por defecto None |
|
432 | set : Set del primer archivo a leer. Por defecto None | |
433 |
|
433 | |||
434 | expLabel : Nombre del subdirectorio de datos. Por defecto "" |
|
434 | expLabel : Nombre del subdirectorio de datos. Por defecto "" | |
435 |
|
435 | |||
436 | ext : Extension de los archivos a leer. Por defecto .r |
|
436 | ext : Extension de los archivos a leer. Por defecto .r | |
437 |
|
437 | |||
438 | Return: |
|
438 | Return: | |
439 |
|
439 | |||
440 | (pathList, filenameList) |
|
440 | (pathList, filenameList) | |
441 |
|
441 | |||
442 | pathList : Lista de directorios donde se encontraron archivos dentro |
|
442 | pathList : Lista de directorios donde se encontraron archivos dentro | |
443 | de los parametros especificados |
|
443 | de los parametros especificados | |
444 | filenameList : Lista de archivos (ruta completa) que coincidieron con los |
|
444 | filenameList : Lista de archivos (ruta completa) que coincidieron con los | |
445 | parametros especificados. |
|
445 | parametros especificados. | |
446 |
|
446 | |||
447 | Variables afectadas: |
|
447 | Variables afectadas: | |
448 |
|
448 | |||
449 | self.filenameList: Lista de archivos (ruta completa) que la clase utiliza |
|
449 | self.filenameList: Lista de archivos (ruta completa) que la clase utiliza | |
450 | como fuente para leer los bloque de datos, si se termina |
|
450 | como fuente para leer los bloque de datos, si se termina | |
451 | de leer todos los bloques de datos de un determinado |
|
451 | de leer todos los bloques de datos de un determinado | |
452 | archivo se pasa al siguiente archivo de la lista. |
|
452 | archivo se pasa al siguiente archivo de la lista. | |
453 |
|
453 | |||
454 | Excepciones: |
|
454 | Excepciones: | |
455 |
|
455 | |||
456 | """ |
|
456 | """ | |
457 |
|
457 | |||
458 | print "Searching files ..." |
|
458 | print "Searching files ..." | |
459 |
|
459 | |||
460 | dirList = [] |
|
460 | dirList = [] | |
461 | for thisPath in os.listdir(path): |
|
461 | for thisPath in os.listdir(path): | |
462 | if os.path.isdir(os.path.join(path,thisPath)): |
|
462 | if os.path.isdir(os.path.join(path,thisPath)): | |
463 | dirList.append(thisPath) |
|
463 | dirList.append(thisPath) | |
464 |
|
464 | |||
465 | pathList = [] |
|
465 | pathList = [] | |
466 |
|
466 | |||
467 | thisDateTime = startDateTime |
|
467 | thisDateTime = startDateTime | |
468 |
|
468 | |||
469 | while(thisDateTime <= endDateTime): |
|
469 | while(thisDateTime <= endDateTime): | |
470 | year = thisDateTime.timetuple().tm_year |
|
470 | year = thisDateTime.timetuple().tm_year | |
471 | doy = thisDateTime.timetuple().tm_yday |
|
471 | doy = thisDateTime.timetuple().tm_yday | |
472 |
|
472 | |||
473 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
473 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
474 | if len(match) == 0: |
|
474 | if len(match) == 0: | |
475 | thisDateTime += datetime.timedelta(1) |
|
475 | thisDateTime += datetime.timedelta(1) | |
476 | continue |
|
476 | continue | |
477 |
|
477 | |||
478 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
478 | pathList.append(os.path.join(path,match[0],expLabel)) | |
479 | thisDateTime += datetime.timedelta(1) |
|
479 | thisDateTime += datetime.timedelta(1) | |
480 |
|
480 | |||
481 | startUtSeconds = time.mktime(startDateTime.timetuple()) |
|
481 | startUtSeconds = time.mktime(startDateTime.timetuple()) | |
482 | endUtSeconds = time.mktime(endDateTime.timetuple()) |
|
482 | endUtSeconds = time.mktime(endDateTime.timetuple()) | |
483 |
|
483 | |||
484 | filenameList = [] |
|
484 | filenameList = [] | |
485 | for thisPath in pathList: |
|
485 | for thisPath in pathList: | |
486 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
486 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
487 | fileList.sort() |
|
487 | fileList.sort() | |
488 | for file in fileList: |
|
488 | for file in fileList: | |
489 | filename = os.path.join(thisPath,file) |
|
489 | filename = os.path.join(thisPath,file) | |
490 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
490 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
491 | filenameList.append(filename) |
|
491 | filenameList.append(filename) | |
492 |
|
492 | |||
493 | self.filenameList = filenameList |
|
493 | self.filenameList = filenameList | |
494 |
|
494 | |||
495 | return pathList, filenameList |
|
495 | return pathList, filenameList | |
496 |
|
496 | |||
497 |
|
497 | |||
498 | def setup( self, path, startDateTime, endDateTime=None, set=None, expLabel = "", ext = ".pdata", online = 0 ): |
|
498 | def setup( self, path, startDateTime, endDateTime=None, set=None, expLabel = "", ext = ".pdata", online = 0 ): | |
499 | """ |
|
499 | """ | |
500 | setup configura los parametros de lectura de la clase SpectraReader. |
|
500 | setup configura los parametros de lectura de la clase SpectraReader. | |
501 |
|
501 | |||
502 | Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos |
|
502 | Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos | |
503 | que coincidan con los parametros especificados; esta lista de archivos son almacenados en |
|
503 | que coincidan con los parametros especificados; esta lista de archivos son almacenados en | |
504 | self.filenameList. |
|
504 | self.filenameList. | |
505 |
|
505 | |||
506 | Input: |
|
506 | Input: | |
507 | path : Directorios donde se ubican los datos a leer. Dentro de este |
|
507 | path : Directorios donde se ubican los datos a leer. Dentro de este | |
508 | directorio deberia de estar subdirectorios de la forma: |
|
508 | directorio deberia de estar subdirectorios de la forma: | |
509 |
|
509 | |||
510 | path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] |
|
510 | path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] | |
511 |
|
511 | |||
512 | startDateTime : Fecha inicial. Rechaza todos los archivos donde |
|
512 | startDateTime : Fecha inicial. Rechaza todos los archivos donde | |
513 | file end time < startDatetime (objeto datetime.datetime) |
|
513 | file end time < startDatetime (objeto datetime.datetime) | |
514 |
|
514 | |||
515 | endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde |
|
515 | endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde | |
516 | file end time < startDatetime (objeto datetime.datetime) |
|
516 | file end time < startDatetime (objeto datetime.datetime) | |
517 |
|
517 | |||
518 | set : Set del primer archivo a leer. Por defecto None |
|
518 | set : Set del primer archivo a leer. Por defecto None | |
519 |
|
519 | |||
520 | expLabel : Nombre del subdirectorio de datos. Por defecto "" |
|
520 | expLabel : Nombre del subdirectorio de datos. Por defecto "" | |
521 |
|
521 | |||
522 | ext : Extension de los archivos a leer. Por defecto .r |
|
522 | ext : Extension de los archivos a leer. Por defecto .r | |
523 |
|
523 | |||
524 | online : |
|
524 | online : | |
525 |
|
525 | |||
526 | Return: |
|
526 | Return: | |
527 |
|
527 | |||
528 | Affected: |
|
528 | Affected: | |
529 |
|
529 | |||
530 | Excepciones: |
|
530 | Excepciones: | |
531 |
|
531 | |||
532 | Example: |
|
532 | Example: | |
533 |
|
533 | |||
534 | """ |
|
534 | """ | |
535 | if online == 0: |
|
535 | if online == 0: | |
536 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) |
|
536 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) | |
537 |
|
537 | |||
538 | self.__idFile = -1 |
|
538 | self.__idFile = -1 | |
539 |
|
539 | |||
540 | if not(self.__setNextFile()): |
|
540 | if not(self.__setNextFile()): | |
541 | print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) |
|
541 | print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |
542 | return 0 |
|
542 | return 0 | |
543 |
|
543 | |||
544 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) |
|
544 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) | |
545 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) |
|
545 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) | |
546 |
|
546 | |||
547 | self.startYear = startDateTime.timetuple().tm_year |
|
547 | self.startYear = startDateTime.timetuple().tm_year | |
548 | self.endYear = endDateTime.timetuple().tm_year |
|
548 | self.endYear = endDateTime.timetuple().tm_year | |
549 |
|
549 | |||
550 | self.startDoy = startDateTime.timetuple().tm_yday |
|
550 | self.startDoy = startDateTime.timetuple().tm_yday | |
551 | self.endDoy = endDateTime.timetuple().tm_yday |
|
551 | self.endDoy = endDateTime.timetuple().tm_yday | |
552 | #call fillHeaderValues() - to Data Object |
|
552 | #call fillHeaderValues() - to Data Object | |
553 |
|
553 | |||
554 | self.__pathList = pathList |
|
554 | self.__pathList = pathList | |
555 | self.filenameList = filenameList |
|
555 | self.filenameList = filenameList | |
556 | self.online = online |
|
556 | self.online = online | |
557 |
|
557 | |||
558 | return 1 |
|
558 | return 1 | |
559 |
|
559 | |||
560 | def readNextBlock(self): |
|
560 | def readNextBlock(self): | |
561 | """ |
|
561 | """ | |
562 | readNextBlock establece un nuevo bloque de datos a leer y los lee, si es que no existiese |
|
562 | readNextBlock establece un nuevo bloque de datos a leer y los lee, si es que no existiese | |
563 | mas bloques disponibles en el archivo actual salta al siguiente. |
|
563 | mas bloques disponibles en el archivo actual salta al siguiente. | |
564 |
|
564 | |||
565 | """ |
|
565 | """ | |
566 |
|
566 | |||
567 | if not( self.__setNewBlock() ): |
|
567 | if not( self.__setNewBlock() ): | |
568 | return 0 |
|
568 | return 0 | |
569 |
|
569 | |||
570 | self.__readBlock() |
|
570 | self.__readBlock() | |
571 |
|
571 | |||
572 | self.__lastUTTime = self.m_BasicHeader.utc |
|
572 | self.__lastUTTime = self.m_BasicHeader.utc | |
573 |
|
573 | |||
574 | return 1 |
|
574 | return 1 | |
575 |
|
575 | |||
576 |
|
576 | |||
577 | def getData(self): |
|
577 | def getData(self): | |
578 | """ |
|
578 | """ | |
579 | getData copia el buffer de lectura a la clase "Spectra", |
|
579 | getData copia el buffer de lectura a la clase "Spectra", | |
580 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
580 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
581 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
581 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
582 |
|
582 | |||
583 | Inputs: |
|
583 | Inputs: | |
584 | None |
|
584 | None | |
585 |
|
585 | |||
586 | Return: |
|
586 | Return: | |
587 | data : retorna un bloque de datos (nFFTs * alturas * canales) copiados desde el |
|
587 | data : retorna un bloque de datos (nFFTs * alturas * canales) copiados desde el | |
588 | buffer. Si no hay mas archivos a leer retorna None. |
|
588 | buffer. Si no hay mas archivos a leer retorna None. | |
589 |
|
589 | |||
590 | Variables afectadas: |
|
590 | Variables afectadas: | |
591 | self.m_Spectra |
|
591 | self.m_Spectra | |
592 | self.__buffer_id |
|
592 | self.__buffer_id | |
593 |
|
593 | |||
594 | Excepciones: |
|
594 | Excepciones: | |
595 |
|
595 | |||
596 | """ |
|
596 | """ | |
597 |
|
597 | |||
598 | self.flagResetProcessing = 0 |
|
598 | self.flagResetProcessing = 0 | |
599 | self.flagIsNewBlock = 0 |
|
599 | self.flagIsNewBlock = 0 | |
600 |
|
600 | |||
601 | if self.__hasNotDataInBuffer(): |
|
601 | if self.__hasNotDataInBuffer(): | |
602 | self.readNextBlock() |
|
602 | self.readNextBlock() | |
603 |
|
603 | |||
604 | self.m_Spectra.m_BasicHeader = self.m_BasicHeader.copy() |
|
604 | self.m_Spectra.m_BasicHeader = self.m_BasicHeader.copy() | |
605 | self.m_Spectra.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
|
605 | self.m_Spectra.m_ProcessingHeader = self.m_ProcessingHeader.copy() | |
606 | self.m_Spectra.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() |
|
606 | self.m_Spectra.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() | |
607 | self.m_Spectra.m_SystemHeader = self.m_SystemHeader.copy() |
|
607 | self.m_Spectra.m_SystemHeader = self.m_SystemHeader.copy() | |
608 | self.m_Spectra.heights = self.__heights |
|
608 | self.m_Spectra.heights = self.__heights | |
609 | self.m_Spectra.dataType = self.__dataType |
|
609 | self.m_Spectra.dataType = self.__dataType | |
610 |
|
610 | |||
611 | if self.noMoreFiles == 1: |
|
611 | if self.noMoreFiles == 1: | |
612 | print 'Process finished' |
|
612 | print 'Process finished' | |
613 | return 0 |
|
613 | return 0 | |
614 |
|
614 | |||
615 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
615 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
616 | #print type(self.__buffer_sspc) |
|
616 | #print type(self.__buffer_sspc) | |
617 |
|
617 | |||
618 | time = self.m_BasicHeader.utc + self.__buffer_id*self.__ippSeconds |
|
618 | time = self.m_BasicHeader.utc + self.__buffer_id*self.__ippSeconds | |
619 |
|
619 | |||
620 | self.m_Spectra.m_BasicHeader.utc = time |
|
620 | self.m_Spectra.m_BasicHeader.utc = time | |
621 | self.m_Spectra.data_spc = self.__buffer_spc |
|
621 | self.m_Spectra.data_spc = self.__buffer_spc | |
622 | self.m_Spectra.data_cspc = self.__buffer_cspc |
|
622 | self.m_Spectra.data_cspc = self.__buffer_cspc | |
623 | self.m_Spectra.data_dc = self.__buffer_dc |
|
623 | self.m_Spectra.data_dc = self.__buffer_dc | |
624 |
|
624 | |||
625 | #call setData - to Data Object |
|
625 | #call setData - to Data Object | |
626 |
|
626 | |||
627 | return 1 |
|
627 | return 1 | |
628 |
|
628 | |||
629 |
|
629 | |||
630 | class SpectraWriter(DataWriter): |
|
630 | class SpectraWriter(DataWriter): | |
631 |
|
631 | |||
632 | def __init__(self): |
|
632 | def __init__(self): | |
633 | if m_Spectra == None: |
|
633 | if m_Spectra == None: | |
634 | m_Spectra = Spectra() |
|
634 | m_Spectra = Spectra() | |
635 |
|
635 | |||
636 | self.m_Spectra = m_Spectra |
|
636 | self.m_Spectra = m_Spectra | |
637 |
|
637 | |||
638 | self.__fp = None |
|
638 | self.__fp = None | |
639 |
|
639 | |||
640 | self.__blocksCounter = 0 |
|
640 | self.__blocksCounter = 0 | |
641 |
|
641 | |||
642 | self.__setFile = None |
|
642 | self.__setFile = None | |
643 |
|
643 | |||
644 | self.__flagIsNewFile = 0 |
|
644 | self.__flagIsNewFile = 0 | |
645 |
|
645 | |||
646 | self.__buffer_sspc = 0 |
|
646 | self.__buffer_sspc = 0 | |
647 |
|
647 | |||
648 | self.__buffer_id = 0 |
|
648 | self.__buffer_id = 0 | |
649 |
|
649 | |||
650 | self.__dataType = None |
|
650 | self.__dataType = None | |
651 |
|
651 | |||
652 | self.__ext = None |
|
652 | self.__ext = None | |
653 |
|
653 | |||
654 | self.nWriteBlocks = 0 |
|
654 | self.nWriteBlocks = 0 | |
655 |
|
655 | |||
656 | self.flagIsNewBlock = 0 |
|
656 | self.flagIsNewBlock = 0 | |
657 |
|
657 | |||
658 | self.noMoreFiles = 0 |
|
658 | self.noMoreFiles = 0 | |
659 |
|
659 | |||
660 | self.filename = None |
|
660 | self.filename = None | |
661 |
|
661 | |||
662 | self.m_BasicHeader= BasicHeader() |
|
662 | self.m_BasicHeader= BasicHeader() | |
663 |
|
663 | |||
664 | self.m_SystemHeader = SystemHeader() |
|
664 | self.m_SystemHeader = SystemHeader() | |
665 |
|
665 | |||
666 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
666 | self.m_RadarControllerHeader = RadarControllerHeader() | |
667 |
|
667 | |||
668 | self.m_ProcessingHeader = ProcessingHeader() |
|
668 | self.m_ProcessingHeader = ProcessingHeader() | |
669 |
|
669 | |||
670 | def __setNextFile(self): |
|
670 | def __setNextFile(self): | |
671 | setFile = self.__setFile |
|
671 | setFile = self.__setFile | |
672 | ext = self.__ext |
|
672 | ext = self.__ext | |
673 | path = self.__path |
|
673 | path = self.__path | |
674 |
|
674 | |||
675 | setFile += 1 |
|
675 | setFile += 1 | |
676 |
|
676 | |||
677 | if not(self.__blocksCounter >= self.m_ProcessingHeader.dataBlocksPerFile): |
|
677 | if not(self.__blocksCounter >= self.m_ProcessingHeader.dataBlocksPerFile): | |
678 | self.__fp.close() |
|
678 | self.__fp.close() | |
679 | return 0 |
|
679 | return 0 | |
680 |
|
680 | |||
681 | timeTuple = time.localtime(self.m_Spectra.m_BasicHeader.utc) # utc from m_Spectra |
|
681 | timeTuple = time.localtime(self.m_Spectra.m_BasicHeader.utc) # utc from m_Spectra | |
682 | file = 'D%4.4d%3.3d%3.3d%s' % (timeTuple.tm_year,timeTuple.tm_doy,setFile,ext) |
|
682 | file = 'D%4.4d%3.3d%3.3d%s' % (timeTuple.tm_year,timeTuple.tm_doy,setFile,ext) | |
683 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_doy) |
|
683 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_doy) | |
684 | tmp = os.path.join(path,subfolder) |
|
684 | tmp = os.path.join(path,subfolder) | |
685 | if not(os.path.exists(tmp)): |
|
685 | if not(os.path.exists(tmp)): | |
686 | os.mkdir(tmp) |
|
686 | os.mkdir(tmp) | |
687 |
|
687 | |||
688 | filename = os.path.join(path,subfolder,file) |
|
688 | filename = os.path.join(path,subfolder,file) | |
689 | fp = open(filename,'wb') |
|
689 | fp = open(filename,'wb') | |
690 |
|
690 | |||
691 | #guardando atributos |
|
691 | #guardando atributos | |
692 | self.filename = filename |
|
692 | self.filename = filename | |
693 | self.__subfolder = subfolder |
|
693 | self.__subfolder = subfolder | |
694 | self.__fp = fp |
|
694 | self.__fp = fp | |
695 | self.__setFile = setFile |
|
695 | self.__setFile = setFile | |
696 | self.__flagIsNewFile = 1 |
|
696 | self.__flagIsNewFile = 1 | |
697 |
|
697 | |||
698 | print 'Writing the file: %s'%self.filename |
|
698 | print 'Writing the file: %s'%self.filename | |
699 |
|
699 | |||
700 | return 1 |
|
700 | return 1 | |
701 |
|
701 | |||
702 |
|
702 | |||
703 |
|
703 | |||
704 | def __setNewBlock(self): |
|
704 | def __setNewBlock(self): | |
705 | if self.__fp == None: |
|
705 | if self.__fp == None: | |
706 | return 0 |
|
706 | return 0 | |
707 |
|
707 | |||
708 | if self.__flagIsNewFile: |
|
708 | if self.__flagIsNewFile: | |
709 | return 1 |
|
709 | return 1 | |
710 |
|
710 | |||
711 | #Bloques completados? |
|
711 | #Bloques completados? | |
712 | if self.__blocksCounter < self.m_ProcessingHeader.profilesPerBlock: |
|
712 | if self.__blocksCounter < self.m_ProcessingHeader.profilesPerBlock: | |
713 | self.__writeBasicHeader() |
|
713 | self.__writeBasicHeader() | |
714 | return 1 |
|
714 | return 1 | |
715 |
|
715 | |||
716 | if not(self.__setNextFile()): |
|
716 | if not(self.__setNextFile()): | |
717 | return 0 |
|
717 | return 0 | |
718 |
|
718 | |||
719 | self.__writeFirstHeader() |
|
719 | self.__writeFirstHeader() | |
720 |
|
720 | |||
721 | return 1 |
|
721 | return 1 | |
722 |
|
722 | |||
723 | def __writeBlock(self): |
|
723 | def __writeBlock(self): | |
724 |
|
724 | |||
725 | numpy.save(self.__fp,self.__buffer_sspc) |
|
725 | numpy.save(self.__fp,self.__buffer_sspc) | |
726 |
|
726 | |||
727 | self.__buffer_sspc = numpy.array([],self.__dataType) |
|
727 | self.__buffer_sspc = numpy.array([],self.__dataType) | |
728 |
|
728 | |||
729 | self.__buffer_id = 0 |
|
729 | self.__buffer_id = 0 | |
730 |
|
730 | |||
731 | self.__flagIsNewFile = 0 |
|
731 | self.__flagIsNewFile = 0 | |
732 |
|
732 | |||
733 | self.flagIsNewBlock = 1 |
|
733 | self.flagIsNewBlock = 1 | |
734 |
|
734 | |||
735 | self.nWriteBlocks += 1 |
|
735 | self.nWriteBlocks += 1 | |
736 |
|
736 | |||
737 | self.__blocksCounter += 1 |
|
737 | self.__blocksCounter += 1 | |
738 |
|
738 | |||
739 | def writeNextBlock(self): |
|
739 | def writeNextBlock(self): | |
740 | if not(self.__setNewBlock()): |
|
740 | if not(self.__setNewBlock()): | |
741 | return 0 |
|
741 | return 0 | |
742 |
|
742 | |||
743 | self.__writeBlock() |
|
743 | self.__writeBlock() | |
744 |
|
744 | |||
745 | return 1 |
|
745 | return 1 | |
746 |
|
746 | |||
747 | def __hasAllDataInBuffer(self): |
|
747 | def __hasAllDataInBuffer(self): | |
748 | if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock: |
|
748 | if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock: | |
749 | return 1 |
|
749 | return 1 | |
750 |
|
750 | |||
751 | return 0 |
|
751 | return 0 | |
752 |
|
752 | |||
753 | def putData(self): |
|
753 | def putData(self): | |
754 | self.flagIsNewBlock = 0 |
|
754 | self.flagIsNewBlock = 0 | |
755 |
|
755 | |||
756 | if self.m_Spectra.noData: |
|
756 | if self.m_Spectra.noData: | |
757 | return None |
|
757 | return None | |
758 |
|
758 | |||
759 | shape = self.m_Spectra.data.shape |
|
759 | shape = self.m_Spectra.data.shape | |
760 | data = numpy.zeros(shape,self.__dataType) |
|
760 | data = numpy.zeros(shape,self.__dataType) | |
761 | data['real'] = self.m_Spectra.data.real |
|
761 | data['real'] = self.m_Spectra.data.real | |
762 | data['imag'] = self.m_Spectra.data.imag |
|
762 | data['imag'] = self.m_Spectra.data.imag | |
763 | data = data.reshape((-1)) |
|
763 | data = data.reshape((-1)) | |
764 |
|
764 | |||
765 | self.__buffer_sspc = numpy.hstack((self.__buffer_sspc,data)) |
|
765 | self.__buffer_sspc = numpy.hstack((self.__buffer_sspc,data)) | |
766 |
|
766 | |||
767 | self.__buffer_id += 1 |
|
767 | self.__buffer_id += 1 | |
768 |
|
768 | |||
769 | if __hasAllDataInBuffer(): |
|
769 | if __hasAllDataInBuffer(): | |
770 | self.writeNextBlock() |
|
770 | self.writeNextBlock() | |
771 |
|
771 | |||
772 |
|
772 | |||
773 | if self.noMoreFiles: |
|
773 | if self.noMoreFiles: | |
774 | print 'Process finished' |
|
774 | print 'Process finished' | |
775 | return None |
|
775 | return None | |
776 |
|
776 | |||
777 | return 1 |
|
777 | return 1 | |
778 |
|
778 | |||
779 |
|
779 | |||
780 | def setup(self,path,set=None,format=None): |
|
780 | def setup(self,path,set=None,format=None): | |
781 |
|
781 | |||
782 | if set == None: |
|
782 | if set == None: | |
783 | set = -1 |
|
783 | set = -1 | |
784 | else: |
|
784 | else: | |
785 | set -= 1 |
|
785 | set -= 1 | |
786 |
|
786 | |||
787 | if format == 'hdf5': |
|
787 | if format == 'hdf5': | |
788 | ext = '.hdf5' |
|
788 | ext = '.hdf5' | |
789 | print 'call hdf5 library' |
|
789 | print 'call hdf5 library' | |
790 | return 0 |
|
790 | return 0 | |
791 |
|
791 | |||
792 | if format == 'rawdata': |
|
792 | if format == 'rawdata': | |
793 | ext = '.r' |
|
793 | ext = '.r' | |
794 |
|
794 | |||
795 | #call to config_headers |
|
795 | #call to config_headers | |
796 |
|
796 | |||
797 | self.__setFile = set |
|
797 | self.__setFile = set | |
798 |
|
798 | |||
799 | if not(self.__setNextFile()): |
|
799 | if not(self.__setNextFile()): | |
800 | print "zzzzzzzzzzzz" |
|
800 | print "zzzzzzzzzzzz" | |
801 | return 0 |
|
801 | return 0 | |
802 |
|
802 | |||
803 | self.__writeFirstHeader() # dentro de esta funcion se debe setear e __dataType |
|
803 | self.__writeFirstHeader() # dentro de esta funcion se debe setear e __dataType | |
804 |
|
804 | |||
805 | self.__buffer_sspc = numpy.array([],self.__dataType) |
|
805 | self.__buffer_sspc = numpy.array([],self.__dataType) | |
806 |
|
806 | |||
807 |
|
807 | |||
808 |
|
808 | |||
809 | def __writeBasicHeader(self): |
|
809 | def __writeBasicHeader(self): | |
810 | pass |
|
810 | pass | |
811 |
|
811 | |||
812 | def __writeFirstHeader(self): |
|
812 | def __writeFirstHeader(self): | |
813 | pass |
|
813 | pass |
@@ -1,945 +1,950 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on 23/01/2012 |
|
2 | Created on 23/01/2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | import os, sys |
|
8 | import os, sys | |
9 | import numpy |
|
9 | import numpy | |
10 | import glob |
|
10 | import glob | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import time, datetime |
|
12 | import time, 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 IO.HeaderIO import * |
|
17 | from IO.HeaderIO import * | |
18 | from IO.DataIO import DataReader |
|
18 | from IO.DataIO import DataReader | |
19 | from IO.DataIO import DataWriter |
|
19 | from IO.DataIO import DataWriter | |
20 |
|
20 | |||
21 | from Model.Voltage import Voltage |
|
21 | from Model.Voltage import Voltage | |
22 |
|
22 | |||
23 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
23 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
24 | """ |
|
24 | """ | |
25 | Esta funcion determina si un archivo de datos en formato Jicamarca(.r) se encuentra |
|
25 | Esta funcion determina si un archivo de datos en formato Jicamarca(.r) se encuentra | |
26 | o no dentro del rango de fecha especificado. |
|
26 | o no dentro del rango de fecha especificado. | |
27 |
|
27 | |||
28 | Inputs: |
|
28 | Inputs: | |
29 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
29 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
30 |
|
30 | |||
31 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
31 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
32 | segundos contados desde 01/01/1970. |
|
32 | segundos contados desde 01/01/1970. | |
33 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
33 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
34 | segundos contados desde 01/01/1970. |
|
34 | segundos contados desde 01/01/1970. | |
35 |
|
35 | |||
36 | Return: |
|
36 | Return: | |
37 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
37 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
38 | fecha especificado, de lo contrario retorna False. |
|
38 | fecha especificado, de lo contrario retorna False. | |
39 |
|
39 | |||
40 | Excepciones: |
|
40 | Excepciones: | |
41 | Si el archivo no existe o no puede ser abierto |
|
41 | Si el archivo no existe o no puede ser abierto | |
42 | Si la cabecera no puede ser leida. |
|
42 | Si la cabecera no puede ser leida. | |
43 |
|
43 | |||
44 | """ |
|
44 | """ | |
45 | m_BasicHeader = BasicHeader() |
|
45 | m_BasicHeader = BasicHeader() | |
46 |
|
46 | |||
47 | try: |
|
47 | try: | |
48 | fp = open(filename,'rb') |
|
48 | fp = open(filename,'rb') | |
49 | except: |
|
49 | except: | |
50 | raise IOError, "The file %s can't be opened" %(filename) |
|
50 | raise IOError, "The file %s can't be opened" %(filename) | |
51 |
|
51 | |||
52 | if not(m_BasicHeader.read(fp)): |
|
52 | if not(m_BasicHeader.read(fp)): | |
53 | raise IOError, "The file %s has not a valid header" %(filename) |
|
53 | raise IOError, "The file %s has not a valid header" %(filename) | |
54 |
|
54 | |||
55 | fp.close() |
|
55 | fp.close() | |
56 |
|
56 | |||
57 | if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): |
|
57 | if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): | |
58 | return 0 |
|
58 | return 0 | |
59 |
|
59 | |||
60 | return 1 |
|
60 | return 1 | |
61 |
|
61 | |||
62 | class VoltageReader(DataReader): |
|
62 | class VoltageReader(DataReader): | |
63 | """ |
|
63 | """ | |
64 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
64 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
65 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
65 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
66 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
66 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
67 |
|
67 | |||
68 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
68 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
69 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
69 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
70 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
70 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
71 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
71 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
72 |
|
72 | |||
73 | Example: |
|
73 | Example: | |
74 |
|
74 | |||
75 | dpath = "/home/myuser/data" |
|
75 | dpath = "/home/myuser/data" | |
76 |
|
76 | |||
77 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
77 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
78 |
|
78 | |||
79 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
79 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
80 |
|
80 | |||
81 | readerObj = VoltageReader() |
|
81 | readerObj = VoltageReader() | |
82 |
|
82 | |||
83 | readerObj.setup(dpath, startTime, endTime) |
|
83 | readerObj.setup(dpath, startTime, endTime) | |
84 |
|
84 | |||
85 | while(True): |
|
85 | while(True): | |
86 |
|
86 | |||
87 | readerObj.getData() |
|
87 | #to get one profile | |
|
88 | profile = readerObj.getData() | |||
88 |
|
89 | |||
89 | print readerObj.m_Voltage.data |
|
90 | #print the profile | |
|
91 | print profile | |||
|
92 | ||||
|
93 | #If you want to see all datablock | |||
|
94 | print readerObj.datablock | |||
90 |
|
95 | |||
91 | if readerObj.noMoreFiles: |
|
96 | if readerObj.noMoreFiles: | |
92 | break |
|
97 | break | |
93 |
|
98 | |||
94 | """ |
|
99 | """ | |
95 |
|
100 | |||
96 | #speed of light |
|
101 | #speed of light | |
97 | __c = 3E8 |
|
102 | __c = 3E8 | |
98 |
|
103 | |||
99 | def __init__(self, m_Voltage = None): |
|
104 | def __init__(self, m_Voltage = None): | |
100 | """ |
|
105 | """ | |
101 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
106 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
102 |
|
107 | |||
103 | Input: |
|
108 | Input: | |
104 | m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
109 | m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para | |
105 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
110 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
106 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
111 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
107 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
112 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
108 | bloque de datos. |
|
113 | bloque de datos. | |
109 | Si este parametro no es pasado se creara uno internamente. |
|
114 | Si este parametro no es pasado se creara uno internamente. | |
110 |
|
115 | |||
111 | Variables afectadas: |
|
116 | Variables afectadas: | |
112 | self.m_Voltage |
|
117 | self.m_Voltage | |
113 | self.m_BasicHeader |
|
118 | self.m_BasicHeader | |
114 | self.m_SystemHeader |
|
119 | self.m_SystemHeader | |
115 | self.m_RadarControllerHeader |
|
120 | self.m_RadarControllerHeader | |
116 | self.m_ProcessingHeader |
|
121 | self.m_ProcessingHeader | |
117 |
|
122 | |||
118 |
|
123 | |||
119 | Return: |
|
124 | Return: | |
120 | Void |
|
125 | Void | |
121 |
|
126 | |||
122 | """ |
|
127 | """ | |
123 | if m_Voltage == None: |
|
128 | if m_Voltage == None: | |
124 | m_Voltage = Voltage() |
|
129 | m_Voltage = Voltage() | |
125 |
|
130 | |||
126 | if not(isinstance(m_Voltage, Voltage)): |
|
131 | if not(isinstance(m_Voltage, Voltage)): | |
127 | raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object" |
|
132 | raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object" | |
128 |
|
133 | |||
129 | self.m_Voltage = m_Voltage |
|
134 | self.m_Voltage = m_Voltage | |
130 |
|
135 | |||
131 | self.m_BasicHeader = BasicHeader() |
|
136 | self.m_BasicHeader = BasicHeader() | |
132 |
|
137 | |||
133 | self.m_SystemHeader = SystemHeader() |
|
138 | self.m_SystemHeader = SystemHeader() | |
134 |
|
139 | |||
135 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
140 | self.m_RadarControllerHeader = RadarControllerHeader() | |
136 |
|
141 | |||
137 | self.m_ProcessingHeader = ProcessingHeader() |
|
142 | self.m_ProcessingHeader = ProcessingHeader() | |
138 |
|
143 | |||
139 | self.__fp = None |
|
144 | self.__fp = None | |
140 |
|
145 | |||
141 | self.__idFile = None |
|
146 | self.__idFile = None | |
142 |
|
147 | |||
143 | self.__startDateTime = None |
|
148 | self.__startDateTime = None | |
144 |
|
149 | |||
145 | self.__endDateTime = None |
|
150 | self.__endDateTime = None | |
146 |
|
151 | |||
147 | self.__dataType = None |
|
152 | self.__dataType = None | |
148 |
|
153 | |||
149 | self.__fileSizeByHeader = 0 |
|
154 | self.__fileSizeByHeader = 0 | |
150 |
|
155 | |||
151 | self.__pathList = [] |
|
156 | self.__pathList = [] | |
152 |
|
157 | |||
153 | self.filenameList = [] |
|
158 | self.filenameList = [] | |
154 |
|
159 | |||
155 | self.__lastUTTime = 0 |
|
160 | self.__lastUTTime = 0 | |
156 |
|
161 | |||
157 | self.__maxTimeStep = 30 |
|
162 | self.__maxTimeStep = 30 | |
158 |
|
163 | |||
159 | self.__flagIsNewFile = 0 |
|
164 | self.__flagIsNewFile = 0 | |
160 |
|
165 | |||
161 | self.__ippSeconds = 0 |
|
166 | self.__ippSeconds = 0 | |
162 |
|
167 | |||
163 | self.flagResetProcessing = 0 |
|
168 | self.flagResetProcessing = 0 | |
164 |
|
169 | |||
165 | self.flagIsNewBlock = 0 |
|
170 | self.flagIsNewBlock = 0 | |
166 |
|
171 | |||
167 | self.noMoreFiles = 0 |
|
172 | self.noMoreFiles = 0 | |
168 |
|
173 | |||
169 | self.nReadBlocks = 0 |
|
174 | self.nReadBlocks = 0 | |
170 |
|
175 | |||
171 | self.online = 0 |
|
176 | self.online = 0 | |
172 |
|
177 | |||
173 | self.filename = None |
|
178 | self.filename = None | |
174 |
|
179 | |||
175 | self.fileSize = None |
|
180 | self.fileSize = None | |
176 |
|
181 | |||
177 | self.firstHeaderSize = 0 |
|
182 | self.firstHeaderSize = 0 | |
178 |
|
183 | |||
179 | self.basicHeaderSize = 24 |
|
184 | self.basicHeaderSize = 24 | |
180 |
|
185 | |||
181 | self.idProfile = 0 |
|
186 | self.idProfile = 0 | |
182 |
|
187 | |||
183 |
self. |
|
188 | self.datablock = None | |
184 |
|
189 | |||
185 |
self. |
|
190 | self.datablock_id = 9999 | |
186 |
|
191 | |||
187 | def __rdSystemHeader(self,fp=None): |
|
192 | def __rdSystemHeader(self,fp=None): | |
188 | if fp == None: |
|
193 | if fp == None: | |
189 | fp = self.__fp |
|
194 | fp = self.__fp | |
190 |
|
195 | |||
191 | self.m_SystemHeader.read(fp) |
|
196 | self.m_SystemHeader.read(fp) | |
192 |
|
197 | |||
193 | def __rdRadarControllerHeader(self,fp=None): |
|
198 | def __rdRadarControllerHeader(self,fp=None): | |
194 | if fp == None: |
|
199 | if fp == None: | |
195 | fp = self.__fp |
|
200 | fp = self.__fp | |
196 |
|
201 | |||
197 | self.m_RadarControllerHeader.read(fp) |
|
202 | self.m_RadarControllerHeader.read(fp) | |
198 |
|
203 | |||
199 | def __rdProcessingHeader(self,fp=None): |
|
204 | def __rdProcessingHeader(self,fp=None): | |
200 | if fp == None: |
|
205 | if fp == None: | |
201 | fp = self.__fp |
|
206 | fp = self.__fp | |
202 |
|
207 | |||
203 | self.m_ProcessingHeader.read(fp) |
|
208 | self.m_ProcessingHeader.read(fp) | |
204 |
|
209 | |||
205 | def __rdBasicHeader(self, fp=None): |
|
210 | def __rdBasicHeader(self, fp=None): | |
206 |
|
211 | |||
207 | if fp == None: |
|
212 | if fp == None: | |
208 | fp = self.__fp |
|
213 | fp = self.__fp | |
209 |
|
214 | |||
210 | self.m_BasicHeader.read(fp) |
|
215 | self.m_BasicHeader.read(fp) | |
211 |
|
216 | |||
212 | def __readFirstHeader(self): |
|
217 | def __readFirstHeader(self): | |
213 |
|
218 | |||
214 | self.__rdBasicHeader() |
|
219 | self.__rdBasicHeader() | |
215 | self.__rdSystemHeader() |
|
220 | self.__rdSystemHeader() | |
216 | self.__rdRadarControllerHeader() |
|
221 | self.__rdRadarControllerHeader() | |
217 | self.__rdProcessingHeader() |
|
222 | self.__rdProcessingHeader() | |
218 | self.firstHeaderSize = self.m_BasicHeader.size |
|
223 | self.firstHeaderSize = self.m_BasicHeader.size | |
219 |
|
224 | |||
220 | data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
225 | data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
221 | if data_type == 0: |
|
226 | if data_type == 0: | |
222 | tmp = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
227 | tmp = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
223 |
|
228 | |||
224 | elif data_type == 1: |
|
229 | elif data_type == 1: | |
225 | tmp = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
230 | tmp = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
226 |
|
231 | |||
227 | elif data_type == 2: |
|
232 | elif data_type == 2: | |
228 | tmp = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
233 | tmp = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
229 |
|
234 | |||
230 | elif data_type == 3: |
|
235 | elif data_type == 3: | |
231 | tmp = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
236 | tmp = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
232 |
|
237 | |||
233 | elif data_type == 4: |
|
238 | elif data_type == 4: | |
234 | tmp = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
239 | tmp = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
235 |
|
240 | |||
236 | elif data_type == 5: |
|
241 | elif data_type == 5: | |
237 | tmp = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
242 | tmp = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
238 |
|
243 | |||
239 | else: |
|
244 | else: | |
240 | raise ValueError, 'Data type was not defined' |
|
245 | raise ValueError, 'Data type was not defined' | |
241 |
|
246 | |||
242 | xi = self.m_ProcessingHeader.firstHeight |
|
247 | xi = self.m_ProcessingHeader.firstHeight | |
243 | step = self.m_ProcessingHeader.deltaHeight |
|
248 | step = self.m_ProcessingHeader.deltaHeight | |
244 | xf = xi + self.m_ProcessingHeader.numHeights*step |
|
249 | xf = xi + self.m_ProcessingHeader.numHeights*step | |
245 |
|
250 | |||
246 | self.__heights = numpy.arange(xi, xf, step) |
|
251 | self.__heights = numpy.arange(xi, xf, step) | |
247 | self.__dataType = tmp |
|
252 | self.__dataType = tmp | |
248 | self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) |
|
253 | self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) | |
249 | self.__ippSeconds = 2*1000*self.m_RadarControllerHeader.ipp/self.__c |
|
254 | self.__ippSeconds = 2*1000*self.m_RadarControllerHeader.ipp/self.__c | |
250 |
|
255 | |||
251 | def __setNextFileOnline(self): |
|
256 | def __setNextFileOnline(self): | |
252 | return 0 |
|
257 | return 0 | |
253 |
|
258 | |||
254 | def __setNextFileOffline(self): |
|
259 | def __setNextFileOffline(self): | |
255 |
|
260 | |||
256 | idFile = self.__idFile |
|
261 | idFile = self.__idFile | |
257 | while(True): |
|
262 | while(True): | |
258 |
|
263 | |||
259 | idFile += 1 |
|
264 | idFile += 1 | |
260 |
|
265 | |||
261 | if not(idFile < len(self.filenameList)): |
|
266 | if not(idFile < len(self.filenameList)): | |
262 | self.noMoreFiles = 1 |
|
267 | self.noMoreFiles = 1 | |
263 | return 0 |
|
268 | return 0 | |
264 |
|
269 | |||
265 | filename = self.filenameList[idFile] |
|
270 | filename = self.filenameList[idFile] | |
266 | fileSize = os.path.getsize(filename) |
|
271 | fileSize = os.path.getsize(filename) | |
267 |
|
272 | |||
268 | try: |
|
273 | try: | |
269 | fp = open(filename,'rb') |
|
274 | fp = open(filename,'rb') | |
270 | except: |
|
275 | except: | |
271 | raise IOError, "The file %s can't be opened" %filename |
|
276 | raise IOError, "The file %s can't be opened" %filename | |
272 |
|
277 | |||
273 | currentSize = fileSize - fp.tell() |
|
278 | currentSize = fileSize - fp.tell() | |
274 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize |
|
279 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize | |
275 |
|
280 | |||
276 | if (currentSize < neededSize): |
|
281 | if (currentSize < neededSize): | |
277 | print "Skipping the file %s due to it hasn't enough data" %filename |
|
282 | print "Skipping the file %s due to it hasn't enough data" %filename | |
278 | continue |
|
283 | continue | |
279 |
|
284 | |||
280 | break |
|
285 | break | |
281 |
|
286 | |||
282 | self.__flagIsNewFile = 1 |
|
287 | self.__flagIsNewFile = 1 | |
283 | self.__idFile = idFile |
|
288 | self.__idFile = idFile | |
284 | self.filename = filename |
|
289 | self.filename = filename | |
285 | self.fileSize = fileSize |
|
290 | self.fileSize = fileSize | |
286 | self.__fp = fp |
|
291 | self.__fp = fp | |
287 |
|
292 | |||
288 | print 'Setting the file: %s'%self.filename |
|
293 | print 'Setting the file: %s'%self.filename | |
289 |
|
294 | |||
290 | return 1 |
|
295 | return 1 | |
291 |
|
296 | |||
292 | def __setNextFile(self): |
|
297 | def __setNextFile(self): | |
293 |
|
298 | |||
294 | if self.online: |
|
299 | if self.online: | |
295 | newFile = self.__setNextFileOnline() |
|
300 | newFile = self.__setNextFileOnline() | |
296 | else: |
|
301 | else: | |
297 | newFile = self.__setNextFileOffline() |
|
302 | newFile = self.__setNextFileOffline() | |
298 |
|
303 | |||
299 | if not(newFile): |
|
304 | if not(newFile): | |
300 | return 0 |
|
305 | return 0 | |
301 |
|
306 | |||
302 | self.__readFirstHeader() |
|
307 | self.__readFirstHeader() | |
303 |
|
308 | |||
304 | return 1 |
|
309 | return 1 | |
305 |
|
310 | |||
306 | def __setNewBlock(self): |
|
311 | def __setNewBlock(self): | |
307 |
|
312 | |||
308 | if self.__fp == None: |
|
313 | if self.__fp == None: | |
309 | return 0 |
|
314 | return 0 | |
310 |
|
315 | |||
311 | if self.__flagIsNewFile: |
|
316 | if self.__flagIsNewFile: | |
312 | return 1 |
|
317 | return 1 | |
313 |
|
318 | |||
314 | currentSize = self.fileSize - self.__fp.tell() |
|
319 | currentSize = self.fileSize - self.__fp.tell() | |
315 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize |
|
320 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize | |
316 |
|
321 | |||
317 | #If there is enough data setting new data block |
|
322 | #If there is enough data setting new data block | |
318 | if (currentSize >= neededSize): |
|
323 | if (currentSize >= neededSize): | |
319 | self.__rdBasicHeader() |
|
324 | self.__rdBasicHeader() | |
320 | return 1 |
|
325 | return 1 | |
321 |
|
326 | |||
322 | #Setting new file |
|
327 | #Setting new file | |
323 | if not(self.__setNextFile()): |
|
328 | if not(self.__setNextFile()): | |
324 | return 0 |
|
329 | return 0 | |
325 |
|
330 | |||
326 | deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this |
|
331 | deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this | |
327 |
|
332 | |||
328 | self.flagResetProcessing = 0 |
|
333 | self.flagResetProcessing = 0 | |
329 |
|
334 | |||
330 | if deltaTime > self.__maxTimeStep: |
|
335 | if deltaTime > self.__maxTimeStep: | |
331 | self.flagResetProcessing = 1 |
|
336 | self.flagResetProcessing = 1 | |
332 | self.nReadBlocks = 0 |
|
337 | self.nReadBlocks = 0 | |
333 |
|
338 | |||
334 | return 1 |
|
339 | return 1 | |
335 |
|
340 | |||
336 | def __readBlock(self): |
|
341 | def __readBlock(self): | |
337 | """ |
|
342 | """ | |
338 | __readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
343 | __readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
339 | (self.__fp) y actualiza todos los parametros relacionados al bloque de datos |
|
344 | (self.__fp) y actualiza todos los parametros relacionados al bloque de datos | |
340 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
345 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
341 | es seteado a 0 |
|
346 | es seteado a 0 | |
342 |
|
347 | |||
343 |
|
348 | |||
344 | Inputs: |
|
349 | Inputs: | |
345 | None |
|
350 | None | |
346 |
|
351 | |||
347 | Return: |
|
352 | Return: | |
348 | None |
|
353 | None | |
349 |
|
354 | |||
350 | Variables afectadas: |
|
355 | Variables afectadas: | |
351 |
|
356 | |||
352 |
self. |
|
357 | self.datablock_id | |
353 |
|
358 | |||
354 |
self. |
|
359 | self.datablock | |
355 |
|
360 | |||
356 | self.__flagIsNewFile |
|
361 | self.__flagIsNewFile | |
357 |
|
362 | |||
358 | self.idProfile |
|
363 | self.idProfile | |
359 |
|
364 | |||
360 | self.flagIsNewBlock |
|
365 | self.flagIsNewBlock | |
361 |
|
366 | |||
362 | self.nReadBlocks |
|
367 | self.nReadBlocks | |
363 |
|
368 | |||
364 | """ |
|
369 | """ | |
365 |
|
370 | |||
366 | pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels |
|
371 | pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels | |
367 |
|
372 | |||
368 | junk = numpy.fromfile(self.__fp, self.__dataType, pts2read) |
|
373 | junk = numpy.fromfile(self.__fp, self.__dataType, pts2read) | |
369 |
|
374 | |||
370 | junk = junk.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) |
|
375 | junk = junk.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) | |
371 |
|
376 | |||
372 | data = junk['real'] + junk['imag']*1j |
|
377 | data = junk['real'] + junk['imag']*1j | |
373 |
|
378 | |||
374 |
self. |
|
379 | self.datablock_id = 0 | |
375 |
|
380 | |||
376 |
self. |
|
381 | self.datablock = data | |
377 |
|
382 | |||
378 | self.__flagIsNewFile = 0 |
|
383 | self.__flagIsNewFile = 0 | |
379 |
|
384 | |||
380 | self.idProfile = 0 |
|
385 | self.idProfile = 0 | |
381 |
|
386 | |||
382 | self.flagIsNewBlock = 1 |
|
387 | self.flagIsNewBlock = 1 | |
383 |
|
388 | |||
384 | self.nReadBlocks += 1 |
|
389 | self.nReadBlocks += 1 | |
385 |
|
390 | |||
386 | def __hasNotDataInBuffer(self): |
|
391 | def __hasNotDataInBuffer(self): | |
387 |
if self. |
|
392 | if self.datablock_id >= self.m_ProcessingHeader.profilesPerBlock: | |
388 | return 1 |
|
393 | return 1 | |
389 |
|
394 | |||
390 | return 0 |
|
395 | return 0 | |
391 |
|
396 | |||
392 | def __searchFiles(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"): |
|
397 | def __searchFiles(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"): | |
393 | """ |
|
398 | """ | |
394 | __searchFiles realiza una busqueda de los archivos que coincidan con los parametros |
|
399 | __searchFiles realiza una busqueda de los archivos que coincidan con los parametros | |
395 | especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda |
|
400 | especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda | |
396 | correcta la estructura de directorios debe ser la siguiente: |
|
401 | correcta la estructura de directorios debe ser la siguiente: | |
397 |
|
402 | |||
398 | ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext |
|
403 | ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext | |
399 |
|
404 | |||
400 | [yyyy]: anio |
|
405 | [yyyy]: anio | |
401 | [ddd] : dia del anio |
|
406 | [ddd] : dia del anio | |
402 | [sss] : set del archivo |
|
407 | [sss] : set del archivo | |
403 |
|
408 | |||
404 | Inputs: |
|
409 | Inputs: | |
405 | path : Directorio de datos donde se realizara la busqueda. Todos los |
|
410 | path : Directorio de datos donde se realizara la busqueda. Todos los | |
406 | ficheros que concidan con el criterio de busqueda seran |
|
411 | ficheros que concidan con el criterio de busqueda seran | |
407 | almacenados en una lista y luego retornados. |
|
412 | almacenados en una lista y luego retornados. | |
408 | startDateTime : Fecha inicial. Rechaza todos los archivos donde |
|
413 | startDateTime : Fecha inicial. Rechaza todos los archivos donde | |
409 | file end time < startDateTime (obejto datetime.datetime) |
|
414 | file end time < startDateTime (obejto datetime.datetime) | |
410 |
|
415 | |||
411 | endDateTime : Fecha final. Rechaza todos los archivos donde |
|
416 | endDateTime : Fecha final. Rechaza todos los archivos donde | |
412 | file start time > endDateTime (obejto datetime.datetime) |
|
417 | file start time > endDateTime (obejto datetime.datetime) | |
413 |
|
418 | |||
414 | set : Set del primer archivo a leer. Por defecto None |
|
419 | set : Set del primer archivo a leer. Por defecto None | |
415 |
|
420 | |||
416 | expLabel : Nombre del subdirectorio de datos. Por defecto "" |
|
421 | expLabel : Nombre del subdirectorio de datos. Por defecto "" | |
417 |
|
422 | |||
418 | ext : Extension de los archivos a leer. Por defecto .r |
|
423 | ext : Extension de los archivos a leer. Por defecto .r | |
419 |
|
424 | |||
420 | Return: |
|
425 | Return: | |
421 |
|
426 | |||
422 | (pathList, filenameList) |
|
427 | (pathList, filenameList) | |
423 |
|
428 | |||
424 | pathList : Lista de directorios donde se encontraron archivos dentro |
|
429 | pathList : Lista de directorios donde se encontraron archivos dentro | |
425 | de los parametros especificados |
|
430 | de los parametros especificados | |
426 | filenameList : Lista de archivos (ruta completa) que coincidieron con los |
|
431 | filenameList : Lista de archivos (ruta completa) que coincidieron con los | |
427 | parametros especificados. |
|
432 | parametros especificados. | |
428 |
|
433 | |||
429 | Variables afectadas: |
|
434 | Variables afectadas: | |
430 |
|
435 | |||
431 | self.filenameList: Lista de archivos (ruta completa) que la clase utiliza |
|
436 | self.filenameList: Lista de archivos (ruta completa) que la clase utiliza | |
432 | como fuente para leer los bloque de datos, si se termina |
|
437 | como fuente para leer los bloque de datos, si se termina | |
433 | de leer todos los bloques de datos de un determinado |
|
438 | de leer todos los bloques de datos de un determinado | |
434 | archivo se pasa al siguiente archivo de la lista. |
|
439 | archivo se pasa al siguiente archivo de la lista. | |
435 |
|
440 | |||
436 | Excepciones: |
|
441 | Excepciones: | |
437 |
|
442 | |||
438 | """ |
|
443 | """ | |
439 |
|
444 | |||
440 | print "Searching files ..." |
|
445 | print "Searching files ..." | |
441 |
|
446 | |||
442 | dirList = [] |
|
447 | dirList = [] | |
443 | for thisPath in os.listdir(path): |
|
448 | for thisPath in os.listdir(path): | |
444 | if os.path.isdir(os.path.join(path,thisPath)): |
|
449 | if os.path.isdir(os.path.join(path,thisPath)): | |
445 | dirList.append(thisPath) |
|
450 | dirList.append(thisPath) | |
446 |
|
451 | |||
447 | pathList = [] |
|
452 | pathList = [] | |
448 |
|
453 | |||
449 | thisDateTime = startDateTime |
|
454 | thisDateTime = startDateTime | |
450 |
|
455 | |||
451 | while(thisDateTime <= endDateTime): |
|
456 | while(thisDateTime <= endDateTime): | |
452 | year = thisDateTime.timetuple().tm_year |
|
457 | year = thisDateTime.timetuple().tm_year | |
453 | doy = thisDateTime.timetuple().tm_yday |
|
458 | doy = thisDateTime.timetuple().tm_yday | |
454 |
|
459 | |||
455 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
460 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
456 | if len(match) == 0: |
|
461 | if len(match) == 0: | |
457 | thisDateTime += datetime.timedelta(1) |
|
462 | thisDateTime += datetime.timedelta(1) | |
458 | continue |
|
463 | continue | |
459 |
|
464 | |||
460 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
465 | pathList.append(os.path.join(path,match[0],expLabel)) | |
461 | thisDateTime += datetime.timedelta(1) |
|
466 | thisDateTime += datetime.timedelta(1) | |
462 |
|
467 | |||
463 | startUtSeconds = time.mktime(startDateTime.timetuple()) |
|
468 | startUtSeconds = time.mktime(startDateTime.timetuple()) | |
464 | endUtSeconds = time.mktime(endDateTime.timetuple()) |
|
469 | endUtSeconds = time.mktime(endDateTime.timetuple()) | |
465 |
|
470 | |||
466 | filenameList = [] |
|
471 | filenameList = [] | |
467 | for thisPath in pathList: |
|
472 | for thisPath in pathList: | |
468 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
473 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
469 | fileList.sort() |
|
474 | fileList.sort() | |
470 | for file in fileList: |
|
475 | for file in fileList: | |
471 | filename = os.path.join(thisPath,file) |
|
476 | filename = os.path.join(thisPath,file) | |
472 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
477 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
473 | filenameList.append(filename) |
|
478 | filenameList.append(filename) | |
474 |
|
479 | |||
475 | self.filenameList = filenameList |
|
480 | self.filenameList = filenameList | |
476 |
|
481 | |||
477 | return pathList, filenameList |
|
482 | return pathList, filenameList | |
478 |
|
483 | |||
479 | def setup(self, path, startDateTime, endDateTime=None, set=None, expLabel = "", ext = ".r", online = 0): |
|
484 | def setup(self, path, startDateTime, endDateTime=None, set=None, expLabel = "", ext = ".r", online = 0): | |
480 | """ |
|
485 | """ | |
481 | setup configura los parametros de lectura de la clase VoltageReader. |
|
486 | setup configura los parametros de lectura de la clase VoltageReader. | |
482 |
|
487 | |||
483 | Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos |
|
488 | Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos | |
484 | que coincidan con los parametros especificados; esta lista de archivos son almacenados en |
|
489 | que coincidan con los parametros especificados; esta lista de archivos son almacenados en | |
485 | self.filenameList. |
|
490 | self.filenameList. | |
486 |
|
491 | |||
487 | Input: |
|
492 | Input: | |
488 | path : Directorios donde se ubican los datos a leer. Dentro de este |
|
493 | path : Directorios donde se ubican los datos a leer. Dentro de este | |
489 | directorio deberia de estar subdirectorios de la forma: |
|
494 | directorio deberia de estar subdirectorios de la forma: | |
490 |
|
495 | |||
491 | path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] |
|
496 | path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] | |
492 |
|
497 | |||
493 | startDateTime : Fecha inicial. Rechaza todos los archivos donde |
|
498 | startDateTime : Fecha inicial. Rechaza todos los archivos donde | |
494 | file end time < startDatetime (obejto datetime.datetime) |
|
499 | file end time < startDatetime (obejto datetime.datetime) | |
495 |
|
500 | |||
496 | endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde |
|
501 | endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde | |
497 | file end time < startDatetime (obejto datetime.datetime) |
|
502 | file end time < startDatetime (obejto datetime.datetime) | |
498 |
|
503 | |||
499 | set : Set del primer archivo a leer. Por defecto None |
|
504 | set : Set del primer archivo a leer. Por defecto None | |
500 |
|
505 | |||
501 | expLabel : Nombre del subdirectorio de datos. Por defecto "" |
|
506 | expLabel : Nombre del subdirectorio de datos. Por defecto "" | |
502 |
|
507 | |||
503 | ext : Extension de los archivos a leer. Por defecto .r |
|
508 | ext : Extension de los archivos a leer. Por defecto .r | |
504 |
|
509 | |||
505 | online : |
|
510 | online : | |
506 |
|
511 | |||
507 | Return: |
|
512 | Return: | |
508 |
|
513 | |||
509 | Affected: |
|
514 | Affected: | |
510 |
|
515 | |||
511 | Excepciones: |
|
516 | Excepciones: | |
512 |
|
517 | |||
513 | Example: |
|
518 | Example: | |
514 |
|
519 | |||
515 | """ |
|
520 | """ | |
516 |
|
521 | |||
517 | if online == 0: |
|
522 | if online == 0: | |
518 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) |
|
523 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) | |
519 |
|
524 | |||
520 | self.__idFile = -1 |
|
525 | self.__idFile = -1 | |
521 |
|
526 | |||
522 | if not(self.__setNextFile()): |
|
527 | if not(self.__setNextFile()): | |
523 | print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) |
|
528 | print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |
524 | return 0 |
|
529 | return 0 | |
525 |
|
530 | |||
526 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) |
|
531 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) | |
527 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) |
|
532 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) | |
528 |
|
533 | |||
529 | self.startYear = startDateTime.timetuple().tm_year |
|
534 | self.startYear = startDateTime.timetuple().tm_year | |
530 | self.endYear = endDateTime.timetuple().tm_year |
|
535 | self.endYear = endDateTime.timetuple().tm_year | |
531 |
|
536 | |||
532 | self.startDoy = startDateTime.timetuple().tm_yday |
|
537 | self.startDoy = startDateTime.timetuple().tm_yday | |
533 | self.endDoy = endDateTime.timetuple().tm_yday |
|
538 | self.endDoy = endDateTime.timetuple().tm_yday | |
534 |
|
539 | |||
535 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() |
|
540 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() | |
536 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
|
541 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() | |
537 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() |
|
542 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() | |
538 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() |
|
543 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() | |
539 | self.m_Voltage.dataType = self.__dataType |
|
544 | self.m_Voltage.dataType = self.__dataType | |
540 |
|
545 | |||
541 | self.__pathList = pathList |
|
546 | self.__pathList = pathList | |
542 | self.filenameList = filenameList |
|
547 | self.filenameList = filenameList | |
543 | self.online = online |
|
548 | self.online = online | |
544 |
|
549 | |||
545 | return 1 |
|
550 | return 1 | |
546 |
|
551 | |||
547 | def readNextBlock(self): |
|
552 | def readNextBlock(self): | |
548 | """ |
|
553 | """ | |
549 | readNextBlock establece un nuevo bloque de datos a leer y los lee, si es que no existiese |
|
554 | readNextBlock establece un nuevo bloque de datos a leer y los lee, si es que no existiese | |
550 | mas bloques disponibles en el archivo actual salta al siguiente. |
|
555 | mas bloques disponibles en el archivo actual salta al siguiente. | |
551 |
|
556 | |||
552 | """ |
|
557 | """ | |
553 |
|
558 | |||
554 | if not(self.__setNewBlock()): |
|
559 | if not(self.__setNewBlock()): | |
555 | return 0 |
|
560 | return 0 | |
556 |
|
561 | |||
557 | self.__readBlock() |
|
562 | self.__readBlock() | |
558 |
|
563 | |||
559 | self.__lastUTTime = self.m_BasicHeader.utc |
|
564 | self.__lastUTTime = self.m_BasicHeader.utc | |
560 |
|
565 | |||
561 | return 1 |
|
566 | return 1 | |
562 |
|
567 | |||
563 | def getData(self): |
|
568 | def getData(self): | |
564 | """ |
|
569 | """ | |
565 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
570 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
566 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
571 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
567 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
572 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
568 |
|
573 | |||
569 | Ademas incrementa el contador del buffer en 1. |
|
574 | Ademas incrementa el contador del buffer en 1. | |
570 |
|
575 | |||
571 | Inputs: |
|
576 | Inputs: | |
572 | None |
|
577 | None | |
573 |
|
578 | |||
574 | Return: |
|
579 | Return: | |
575 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
580 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
576 | buffer. Si no hay mas archivos a leer retorna None. |
|
581 | buffer. Si no hay mas archivos a leer retorna None. | |
577 |
|
582 | |||
578 | Variables afectadas: |
|
583 | Variables afectadas: | |
579 | self.m_Voltage |
|
584 | self.m_Voltage | |
580 |
self. |
|
585 | self.datablock_id | |
581 | self.idProfile |
|
586 | self.idProfile | |
582 |
|
587 | |||
583 | Excepciones: |
|
588 | Excepciones: | |
584 |
|
589 | |||
585 | """ |
|
590 | """ | |
586 | self.flagResetProcessing = 0 |
|
591 | self.flagResetProcessing = 0 | |
587 | self.flagIsNewBlock = 0 |
|
592 | self.flagIsNewBlock = 0 | |
588 |
|
593 | |||
589 | if self.__hasNotDataInBuffer(): |
|
594 | if self.__hasNotDataInBuffer(): | |
590 | self.readNextBlock() |
|
595 | self.readNextBlock() | |
591 |
|
596 | |||
592 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() |
|
597 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() | |
593 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
|
598 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() | |
594 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() |
|
599 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() | |
595 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() |
|
600 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() | |
596 |
|
601 | |||
597 | self.m_Voltage.heights = self.__heights |
|
602 | self.m_Voltage.heights = self.__heights | |
598 | self.m_Voltage.dataType = self.__dataType |
|
603 | self.m_Voltage.dataType = self.__dataType | |
599 |
|
604 | |||
600 | if self.noMoreFiles == 1: |
|
605 | if self.noMoreFiles == 1: | |
601 | print 'Process finished' |
|
606 | print 'Process finished' | |
602 | return None |
|
607 | return None | |
603 |
|
608 | |||
604 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
609 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
605 |
|
610 | |||
606 |
time = self.m_BasicHeader.utc + self. |
|
611 | time = self.m_BasicHeader.utc + self.datablock_id*self.__ippSeconds | |
607 | self.m_Voltage.m_BasicHeader.utc = time |
|
612 | self.m_Voltage.m_BasicHeader.utc = time | |
608 |
self.m_Voltage.data = self. |
|
613 | self.m_Voltage.data = self.datablock[self.datablock_id,:,:] | |
609 | self.m_Voltage.flagNoData = False |
|
614 | self.m_Voltage.flagNoData = False | |
610 | self.m_Voltage.flagResetProcessing = self.flagResetProcessing |
|
615 | self.m_Voltage.flagResetProcessing = self.flagResetProcessing | |
611 |
|
616 | |||
612 | self.m_Voltage.idProfile = self.idProfile |
|
617 | self.m_Voltage.idProfile = self.idProfile | |
613 |
|
618 | |||
614 |
|
619 | |||
615 |
self. |
|
620 | self.datablock_id += 1 | |
616 | self.idProfile += 1 |
|
621 | self.idProfile += 1 | |
617 |
|
622 | |||
618 | #call setData - to Data Object |
|
623 | #call setData - to Data Object | |
619 |
|
624 | |||
620 |
return |
|
625 | return self.m_Voltage.data | |
621 |
|
626 | |||
622 | class VoltageWriter(DataWriter): |
|
627 | class VoltageWriter(DataWriter): | |
623 | __configHeaderFile = 'wrSetHeadet.txt' |
|
628 | __configHeaderFile = 'wrSetHeadet.txt' | |
624 |
|
629 | |||
625 | def __init__(self, m_Voltage = None): |
|
630 | def __init__(self, m_Voltage = None): | |
626 |
|
631 | |||
627 | if m_Voltage == None: |
|
632 | if m_Voltage == None: | |
628 | m_Voltage = Voltage() |
|
633 | m_Voltage = Voltage() | |
629 |
|
634 | |||
630 | self.m_Voltage = m_Voltage |
|
635 | self.m_Voltage = m_Voltage | |
631 |
|
636 | |||
632 | self.__path = None |
|
637 | self.__path = None | |
633 |
|
638 | |||
634 | self.__fp = None |
|
639 | self.__fp = None | |
635 |
|
640 | |||
636 | self.__format = None |
|
641 | self.__format = None | |
637 |
|
642 | |||
638 | self.__blocksCounter = 0 |
|
643 | self.__blocksCounter = 0 | |
639 |
|
644 | |||
640 | self.__setFile = None |
|
645 | self.__setFile = None | |
641 |
|
646 | |||
642 | self.__flagIsNewFile = 1 |
|
647 | self.__flagIsNewFile = 1 | |
643 |
|
648 | |||
644 |
self. |
|
649 | self.datablock = None | |
645 |
|
650 | |||
646 |
self. |
|
651 | self.datablock_id = 0 | |
647 |
|
652 | |||
648 | self.__dataType = None |
|
653 | self.__dataType = None | |
649 |
|
654 | |||
650 | self.__ext = None |
|
655 | self.__ext = None | |
651 |
|
656 | |||
652 | self.__shapeBuffer = None |
|
657 | self.__shapeBuffer = None | |
653 |
|
658 | |||
654 | self.nWriteBlocks = 0 |
|
659 | self.nWriteBlocks = 0 | |
655 |
|
660 | |||
656 | self.flagIsNewBlock = 0 |
|
661 | self.flagIsNewBlock = 0 | |
657 |
|
662 | |||
658 | self.noMoreFiles = 0 |
|
663 | self.noMoreFiles = 0 | |
659 |
|
664 | |||
660 | self.filename = None |
|
665 | self.filename = None | |
661 |
|
666 | |||
662 | self.m_BasicHeader= BasicHeader() |
|
667 | self.m_BasicHeader= BasicHeader() | |
663 |
|
668 | |||
664 | self.m_SystemHeader = SystemHeader() |
|
669 | self.m_SystemHeader = SystemHeader() | |
665 |
|
670 | |||
666 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
671 | self.m_RadarControllerHeader = RadarControllerHeader() | |
667 |
|
672 | |||
668 | self.m_ProcessingHeader = ProcessingHeader() |
|
673 | self.m_ProcessingHeader = ProcessingHeader() | |
669 |
|
674 | |||
670 |
|
675 | |||
671 | def __writeBasicHeader(self, fp=None): |
|
676 | def __writeBasicHeader(self, fp=None): | |
672 | if fp == None: |
|
677 | if fp == None: | |
673 | fp = self.__fp |
|
678 | fp = self.__fp | |
674 |
|
679 | |||
675 | self.m_BasicHeader.write(fp) |
|
680 | self.m_BasicHeader.write(fp) | |
676 |
|
681 | |||
677 | def __wrSystemHeader(self,fp=None): |
|
682 | def __wrSystemHeader(self,fp=None): | |
678 | if fp == None: |
|
683 | if fp == None: | |
679 | fp = self.__fp |
|
684 | fp = self.__fp | |
680 |
|
685 | |||
681 | self.m_SystemHeader.write(fp) |
|
686 | self.m_SystemHeader.write(fp) | |
682 |
|
687 | |||
683 | def __wrRadarControllerHeader(self,fp=None): |
|
688 | def __wrRadarControllerHeader(self,fp=None): | |
684 | if fp == None: |
|
689 | if fp == None: | |
685 | fp = self.__fp |
|
690 | fp = self.__fp | |
686 |
|
691 | |||
687 | self.m_RadarControllerHeader.write(fp) |
|
692 | self.m_RadarControllerHeader.write(fp) | |
688 |
|
693 | |||
689 | def __wrProcessingHeader(self,fp=None): |
|
694 | def __wrProcessingHeader(self,fp=None): | |
690 | if fp == None: |
|
695 | if fp == None: | |
691 | fp = self.__fp |
|
696 | fp = self.__fp | |
692 |
|
697 | |||
693 | self.m_ProcessingHeader.write(fp) |
|
698 | self.m_ProcessingHeader.write(fp) | |
694 |
|
699 | |||
695 | def __writeFirstHeader(self): |
|
700 | def __writeFirstHeader(self): | |
696 | self.__writeBasicHeader() |
|
701 | self.__writeBasicHeader() | |
697 | self.__wrSystemHeader() |
|
702 | self.__wrSystemHeader() | |
698 | self.__wrRadarControllerHeader() |
|
703 | self.__wrRadarControllerHeader() | |
699 | self.__wrProcessingHeader() |
|
704 | self.__wrProcessingHeader() | |
700 | self.__dataType = self.m_Voltage.dataType |
|
705 | self.__dataType = self.m_Voltage.dataType | |
701 |
|
706 | |||
702 |
|
707 | |||
703 | def __setNextFile(self): |
|
708 | def __setNextFile(self): | |
704 |
|
709 | |||
705 | setFile = self.__setFile |
|
710 | setFile = self.__setFile | |
706 | ext = self.__ext |
|
711 | ext = self.__ext | |
707 | path = self.__path |
|
712 | path = self.__path | |
708 |
|
713 | |||
709 | setFile += 1 |
|
714 | setFile += 1 | |
710 |
|
715 | |||
711 | if self.__fp != None: |
|
716 | if self.__fp != None: | |
712 | self.__fp.close() |
|
717 | self.__fp.close() | |
713 |
|
718 | |||
714 | timeTuple = time.localtime(self.m_Voltage.m_BasicHeader.utc) # utc from m_Voltage |
|
719 | timeTuple = time.localtime(self.m_Voltage.m_BasicHeader.utc) # utc from m_Voltage | |
715 | file = 'D%4.4d%3.3d%3.3d%s' % (timeTuple.tm_year,timeTuple.tm_yday,setFile,ext) |
|
720 | file = 'D%4.4d%3.3d%3.3d%s' % (timeTuple.tm_year,timeTuple.tm_yday,setFile,ext) | |
716 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
721 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
717 | tmp = os.path.join(path,subfolder) |
|
722 | tmp = os.path.join(path,subfolder) | |
718 | if not(os.path.exists(tmp)): |
|
723 | if not(os.path.exists(tmp)): | |
719 | os.mkdir(tmp) |
|
724 | os.mkdir(tmp) | |
720 |
|
725 | |||
721 | filename = os.path.join(path,subfolder,file) |
|
726 | filename = os.path.join(path,subfolder,file) | |
722 | fp = open(filename,'wb') |
|
727 | fp = open(filename,'wb') | |
723 |
|
728 | |||
724 | self.__blocksCounter = 0 |
|
729 | self.__blocksCounter = 0 | |
725 |
|
730 | |||
726 | #guardando atributos |
|
731 | #guardando atributos | |
727 | self.filename = filename |
|
732 | self.filename = filename | |
728 | self.__subfolder = subfolder |
|
733 | self.__subfolder = subfolder | |
729 | self.__fp = fp |
|
734 | self.__fp = fp | |
730 | self.__setFile = setFile |
|
735 | self.__setFile = setFile | |
731 | self.__flagIsNewFile = 1 |
|
736 | self.__flagIsNewFile = 1 | |
732 |
|
737 | |||
733 | print 'Writing the file: %s'%self.filename |
|
738 | print 'Writing the file: %s'%self.filename | |
734 |
|
739 | |||
735 | self.__writeFirstHeader() |
|
740 | self.__writeFirstHeader() | |
736 |
|
741 | |||
737 | return 1 |
|
742 | return 1 | |
738 |
|
743 | |||
739 | def __setNewBlock(self): |
|
744 | def __setNewBlock(self): | |
740 |
|
745 | |||
741 | if self.__fp == None: |
|
746 | if self.__fp == None: | |
742 | self.__setNextFile() |
|
747 | self.__setNextFile() | |
743 |
|
748 | |||
744 | if self.__flagIsNewFile: |
|
749 | if self.__flagIsNewFile: | |
745 | return 1 |
|
750 | return 1 | |
746 |
|
751 | |||
747 | if self.__blocksCounter < self.m_ProcessingHeader.dataBlocksPerFile: |
|
752 | if self.__blocksCounter < self.m_ProcessingHeader.dataBlocksPerFile: | |
748 | self.__writeBasicHeader() |
|
753 | self.__writeBasicHeader() | |
749 | return 1 |
|
754 | return 1 | |
750 |
|
755 | |||
751 | if not(self.__setNextFile()): |
|
756 | if not(self.__setNextFile()): | |
752 | return 0 |
|
757 | return 0 | |
753 |
|
758 | |||
754 | return 1 |
|
759 | return 1 | |
755 |
|
760 | |||
756 | def __writeBlock(self): |
|
761 | def __writeBlock(self): | |
757 |
|
762 | |||
758 | data = numpy.zeros(self.__shapeBuffer, self.__dataType) |
|
763 | data = numpy.zeros(self.__shapeBuffer, self.__dataType) | |
759 |
|
764 | |||
760 |
data['real'] = self. |
|
765 | data['real'] = self.datablock.real | |
761 |
data['imag'] = self. |
|
766 | data['imag'] = self.datablock.imag | |
762 |
|
767 | |||
763 | data = data.reshape((-1)) |
|
768 | data = data.reshape((-1)) | |
764 |
|
769 | |||
765 | data.tofile(self.__fp) |
|
770 | data.tofile(self.__fp) | |
766 |
|
771 | |||
767 |
self. |
|
772 | self.datablock.fill(0) | |
768 |
|
773 | |||
769 |
self. |
|
774 | self.datablock_id = 0 | |
770 |
|
775 | |||
771 | self.__flagIsNewFile = 0 |
|
776 | self.__flagIsNewFile = 0 | |
772 |
|
777 | |||
773 | self.flagIsNewBlock = 1 |
|
778 | self.flagIsNewBlock = 1 | |
774 |
|
779 | |||
775 | self.nWriteBlocks += 1 |
|
780 | self.nWriteBlocks += 1 | |
776 |
|
781 | |||
777 | self.__blocksCounter += 1 |
|
782 | self.__blocksCounter += 1 | |
778 |
|
783 | |||
779 |
|
784 | |||
780 | def writeNextBlock(self): |
|
785 | def writeNextBlock(self): | |
781 |
|
786 | |||
782 | if not(self.__setNewBlock()): |
|
787 | if not(self.__setNewBlock()): | |
783 | return 0 |
|
788 | return 0 | |
784 |
|
789 | |||
785 | self.__writeBlock() |
|
790 | self.__writeBlock() | |
786 |
|
791 | |||
787 | return 1 |
|
792 | return 1 | |
788 |
|
793 | |||
789 | def __hasAllDataInBuffer(self): |
|
794 | def __hasAllDataInBuffer(self): | |
790 |
if self. |
|
795 | if self.datablock_id >= self.m_ProcessingHeader.profilesPerBlock: | |
791 | return 1 |
|
796 | return 1 | |
792 |
|
797 | |||
793 | return 0 |
|
798 | return 0 | |
794 |
|
799 | |||
795 | def putData(self): |
|
800 | def putData(self): | |
796 |
|
801 | |||
797 | self.flagIsNewBlock = 0 |
|
802 | self.flagIsNewBlock = 0 | |
798 |
|
803 | |||
799 | if self.m_Voltage.flagNoData: |
|
804 | if self.m_Voltage.flagNoData: | |
800 | return 0 |
|
805 | return 0 | |
801 |
|
806 | |||
802 | if self.m_Voltage.flagResetProcessing: |
|
807 | if self.m_Voltage.flagResetProcessing: | |
803 |
|
808 | |||
804 |
self. |
|
809 | self.datablock.fill(0) | |
805 |
|
810 | |||
806 |
self. |
|
811 | self.datablock_id = 0 | |
807 | self.__setNextFile() |
|
812 | self.__setNextFile() | |
808 |
|
813 | |||
809 |
self. |
|
814 | self.datablock[self.datablock_id,:,:] = self.m_Voltage.data | |
810 |
|
815 | |||
811 |
self. |
|
816 | self.datablock_id += 1 | |
812 |
|
817 | |||
813 | if self.__hasAllDataInBuffer(): |
|
818 | if self.__hasAllDataInBuffer(): | |
814 |
|
819 | |||
815 | self.__getHeader() |
|
820 | self.__getHeader() | |
816 | self.writeNextBlock() |
|
821 | self.writeNextBlock() | |
817 |
|
822 | |||
818 | if self.noMoreFiles: |
|
823 | if self.noMoreFiles: | |
819 | #print 'Process finished' |
|
824 | #print 'Process finished' | |
820 | return 0 |
|
825 | return 0 | |
821 |
|
826 | |||
822 | return 1 |
|
827 | return 1 | |
823 |
|
828 | |||
824 | def __getHeader(self): |
|
829 | def __getHeader(self): | |
825 | self.m_BasicHeader = self.m_Voltage.m_BasicHeader.copy() |
|
830 | self.m_BasicHeader = self.m_Voltage.m_BasicHeader.copy() | |
826 | self.m_SystemHeader = self.m_Voltage.m_SystemHeader.copy() |
|
831 | self.m_SystemHeader = self.m_Voltage.m_SystemHeader.copy() | |
827 | self.m_RadarControllerHeader = self.m_Voltage.m_RadarControllerHeader.copy() |
|
832 | self.m_RadarControllerHeader = self.m_Voltage.m_RadarControllerHeader.copy() | |
828 | self.m_ProcessingHeader = self.m_Voltage.m_ProcessingHeader.copy() |
|
833 | self.m_ProcessingHeader = self.m_Voltage.m_ProcessingHeader.copy() | |
829 | self.__dataType = self.m_Voltage.dataType |
|
834 | self.__dataType = self.m_Voltage.dataType | |
830 |
|
835 | |||
831 | def __setHeaderByFile(self): |
|
836 | def __setHeaderByFile(self): | |
832 |
|
837 | |||
833 | format = self.__format |
|
838 | format = self.__format | |
834 | header = ['Basic','System','RadarController','Processing'] |
|
839 | header = ['Basic','System','RadarController','Processing'] | |
835 |
|
840 | |||
836 | fmtFromFile = None |
|
841 | fmtFromFile = None | |
837 | headerFromFile = None |
|
842 | headerFromFile = None | |
838 |
|
843 | |||
839 |
|
844 | |||
840 | fileTable = self.__configHeaderFile |
|
845 | fileTable = self.__configHeaderFile | |
841 |
|
846 | |||
842 | if os.access(fileTable, os.R_OK): |
|
847 | if os.access(fileTable, os.R_OK): | |
843 | import re, string |
|
848 | import re, string | |
844 |
|
849 | |||
845 | f = open(fileTable,'r') |
|
850 | f = open(fileTable,'r') | |
846 | lines = f.read() |
|
851 | lines = f.read() | |
847 | f.close() |
|
852 | f.close() | |
848 |
|
853 | |||
849 | #Delete comments into expConfig |
|
854 | #Delete comments into expConfig | |
850 | while 1: |
|
855 | while 1: | |
851 |
|
856 | |||
852 | startComment = string.find(lines.lower(),'#') |
|
857 | startComment = string.find(lines.lower(),'#') | |
853 | if startComment == -1: |
|
858 | if startComment == -1: | |
854 | break |
|
859 | break | |
855 | endComment = string.find(lines.lower(),'\n',startComment) |
|
860 | endComment = string.find(lines.lower(),'\n',startComment) | |
856 | lines = string.replace(lines,lines[startComment:endComment+1],'', 1) |
|
861 | lines = string.replace(lines,lines[startComment:endComment+1],'', 1) | |
857 |
|
862 | |||
858 | while expFromFile == None: |
|
863 | while expFromFile == None: | |
859 |
|
864 | |||
860 | currFmt = string.find(lines.lower(),'format="%s"' %(expName)) |
|
865 | currFmt = string.find(lines.lower(),'format="%s"' %(expName)) | |
861 | nextFmt = string.find(lines.lower(),'format',currFmt+10) |
|
866 | nextFmt = string.find(lines.lower(),'format',currFmt+10) | |
862 |
|
867 | |||
863 | if currFmt == -1: |
|
868 | if currFmt == -1: | |
864 | break |
|
869 | break | |
865 | if nextFmt == -1: |
|
870 | if nextFmt == -1: | |
866 | nextFmt = len(lines)-1 |
|
871 | nextFmt = len(lines)-1 | |
867 |
|
872 | |||
868 | fmtTable = lines[currFmt:nextFmt] |
|
873 | fmtTable = lines[currFmt:nextFmt] | |
869 | lines = lines[nextFmt:] |
|
874 | lines = lines[nextFmt:] | |
870 |
|
875 | |||
871 | fmtRead = self.__getValueFromArg(fmtTable,'format') |
|
876 | fmtRead = self.__getValueFromArg(fmtTable,'format') | |
872 | if fmtRead != format: |
|
877 | if fmtRead != format: | |
873 | continue |
|
878 | continue | |
874 | fmtFromFile = fmtRead |
|
879 | fmtFromFile = fmtRead | |
875 |
|
880 | |||
876 | lines2 = fmtTable |
|
881 | lines2 = fmtTable | |
877 |
|
882 | |||
878 | while headerFromFile == None: |
|
883 | while headerFromFile == None: | |
879 |
|
884 | |||
880 | currHeader = string.find(lines2.lower(),'header="%s"' %(header)) |
|
885 | currHeader = string.find(lines2.lower(),'header="%s"' %(header)) | |
881 | nextHeader = string.find(lines2.lower(),'header',currHeader+10) |
|
886 | nextHeader = string.find(lines2.lower(),'header',currHeader+10) | |
882 |
|
887 | |||
883 | if currHeader == -1: |
|
888 | if currHeader == -1: | |
884 | break |
|
889 | break | |
885 | if nextHeader == -1: |
|
890 | if nextHeader == -1: | |
886 | nextHeader = len(lines2)-1 |
|
891 | nextHeader = len(lines2)-1 | |
887 |
|
892 | |||
888 | headerTable = lines2[currHeader:nextHeader] |
|
893 | headerTable = lines2[currHeader:nextHeader] | |
889 | lines2 = lines2[nextHeader:] |
|
894 | lines2 = lines2[nextHeader:] | |
890 |
|
895 | |||
891 | headerRead = self.__getValueFromArg(headerTable,'site') |
|
896 | headerRead = self.__getValueFromArg(headerTable,'site') | |
892 | if not(headerRead in header): |
|
897 | if not(headerRead in header): | |
893 | continue |
|
898 | continue | |
894 | headerFromFile = headerRead |
|
899 | headerFromFile = headerRead | |
895 |
|
900 | |||
896 | if headerRead == 'Basic': |
|
901 | if headerRead == 'Basic': | |
897 | self.m_BasicHeader.size = self.__getValueFromArg(headerTable,'size',lower=False) |
|
902 | self.m_BasicHeader.size = self.__getValueFromArg(headerTable,'size',lower=False) | |
898 | self.m_BasicHeader.version = self.__getValueFromArg(headerTable,'version',lower=False) |
|
903 | self.m_BasicHeader.version = self.__getValueFromArg(headerTable,'version',lower=False) | |
899 | self.m_BasicHeader.dataBlock = self.__getValueFromArg(headerTable,'dataBlock',lower=False) |
|
904 | self.m_BasicHeader.dataBlock = self.__getValueFromArg(headerTable,'dataBlock',lower=False) | |
900 | self.m_BasicHeader.utc = self.__getValueFromArg(headerTable,'utc',lower=False) |
|
905 | self.m_BasicHeader.utc = self.__getValueFromArg(headerTable,'utc',lower=False) | |
901 | self.m_BasicHeader.miliSecond = self.__getValueFromArg(headerTable,'miliSecond',lower=False) |
|
906 | self.m_BasicHeader.miliSecond = self.__getValueFromArg(headerTable,'miliSecond',lower=False) | |
902 | self.m_BasicHeader.timeZone = self.__getValueFromArg(headerTable,'timeZone',lower=False) |
|
907 | self.m_BasicHeader.timeZone = self.__getValueFromArg(headerTable,'timeZone',lower=False) | |
903 | self.m_BasicHeader.dstFlag = self.__getValueFromArg(headerTable,'dstFlag',lower=False) |
|
908 | self.m_BasicHeader.dstFlag = self.__getValueFromArg(headerTable,'dstFlag',lower=False) | |
904 | self.m_BasicHeader.errorCount = self.__getValueFromArg(headerTable,'errorCount',lower=False) |
|
909 | self.m_BasicHeader.errorCount = self.__getValueFromArg(headerTable,'errorCount',lower=False) | |
905 |
|
910 | |||
906 | else: |
|
911 | else: | |
907 | print "file access denied:%s"%fileTable |
|
912 | print "file access denied:%s"%fileTable | |
908 | sys.exit(0) |
|
913 | sys.exit(0) | |
909 |
|
914 | |||
910 | def setup(self, path, set=0, format='rawdata'): |
|
915 | def setup(self, path, set=0, format='rawdata'): | |
911 |
|
916 | |||
912 |
|
917 | |||
913 | if format == 'hdf5': |
|
918 | if format == 'hdf5': | |
914 | ext = '.hdf5' |
|
919 | ext = '.hdf5' | |
915 | format = 'hdf5' |
|
920 | format = 'hdf5' | |
916 | print 'call hdf5 library' |
|
921 | print 'call hdf5 library' | |
917 | return 0 |
|
922 | return 0 | |
918 |
|
923 | |||
919 | if format == 'rawdata': |
|
924 | if format == 'rawdata': | |
920 | ext = '.r' |
|
925 | ext = '.r' | |
921 | format = 'Jicamarca' |
|
926 | format = 'Jicamarca' | |
922 |
|
927 | |||
923 | #call to config_headers |
|
928 | #call to config_headers | |
924 | #self.__setHeaderByFile() |
|
929 | #self.__setHeaderByFile() | |
925 |
|
930 | |||
926 | self.__path = path |
|
931 | self.__path = path | |
927 | self.__setFile = set - 1 |
|
932 | self.__setFile = set - 1 | |
928 | self.__ext = ext |
|
933 | self.__ext = ext | |
929 | self.__format = format |
|
934 | self.__format = format | |
930 |
|
935 | |||
931 | self.__getHeader() |
|
936 | self.__getHeader() | |
932 | self.__shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock, |
|
937 | self.__shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock, | |
933 | self.m_ProcessingHeader.numHeights, |
|
938 | self.m_ProcessingHeader.numHeights, | |
934 | self.m_SystemHeader.numChannels ) |
|
939 | self.m_SystemHeader.numChannels ) | |
935 |
|
940 | |||
936 |
self. |
|
941 | self.datablock = numpy.zeros(self.__shapeBuffer, numpy.dtype('complex')) | |
937 |
|
942 | |||
938 | # if not(self.__setNextFile()): |
|
943 | # if not(self.__setNextFile()): | |
939 | # return 0 |
|
944 | # return 0 | |
940 | return 1 |
|
945 | return 1 | |
941 |
|
946 | |||
942 |
|
947 | |||
943 |
|
948 | |||
944 |
|
949 | |||
945 | No newline at end of file |
|
950 |
@@ -1,74 +1,75 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on 23/01/2012 |
|
2 | Created on 23/01/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 time, datetime |
|
8 | import time, datetime | |
9 |
|
9 | |||
10 | from Model.Voltage import Voltage |
|
10 | from Model.Voltage import Voltage | |
11 | from IO.VoltageIO import * |
|
11 | from IO.VoltageIO import * | |
12 | from Graphics.VoltagePlot import Osciloscope |
|
12 | from Graphics.VoltagePlot import Osciloscope | |
13 |
|
13 | |||
|
14 | from Model.Spectra import Spectra | |||
|
15 | from IO.SpectraIO import * | |||
|
16 | from Graphics.SpectraPlot import Spectrum | |||
|
17 | ||||
14 | class TestSChain(): |
|
18 | class TestSChain(): | |
15 |
|
19 | |||
16 |
|
20 | |||
17 | def __init__(self): |
|
21 | def __init__(self): | |
18 | self.setValues() |
|
22 | self.setValues() | |
19 | self.createObjects() |
|
23 | self.createObjects() | |
20 | self.testSChain() |
|
24 | self.testSChain() | |
21 | pass |
|
25 | pass | |
22 |
|
26 | |||
23 | def setValues(self): |
|
27 | def setValues(self): | |
24 |
|
28 | |||
25 | self.path = '/home/roj-idl71/Data/RAWDATA/DP_Faraday/' |
|
29 | self.path = '/home/roj-idl71/Data/RAWDATA/DP_Faraday/' | |
26 | self.path = '/Users/danielangelsuarezmunoz/Documents/Projects/testWR' |
|
30 | self.path = '/Users/danielangelsuarezmunoz/Documents/Projects/testWR' | |
27 | self.path = '/home/roj-idl71/Data/RAWDATA/IMAGING' |
|
31 | self.path = '/home/roj-idl71/Data/RAWDATA/IMAGING' | |
28 | self.path = '/home/roj-idl71/tmp/data' |
|
32 | # self.path = '/home/roj-idl71/tmp/data' | |
29 | #self.path = '/remote/puma/2004_11/DVD/' |
|
33 | #self.path = '/remote/puma/2004_11/DVD/' | |
30 |
|
34 | |||
31 | self.ppath = "/home/roj-idl71/tmp/data" |
|
35 | self.ppath = "/home/roj-idl71/tmp/data" | |
32 |
self.startDateTime = datetime.datetime(20 |
|
36 | self.startDateTime = datetime.datetime(2011,1,1,17,49,0) | |
33 |
self.endDateTime = datetime.datetime(201 |
|
37 | self.endDateTime = datetime.datetime(2011,1,30,18,10,0) | |
34 |
|
38 | |||
35 | def createObjects(self): |
|
39 | def createObjects(self): | |
36 |
|
40 | |||
37 |
self. |
|
41 | self.Obj = Spectra() | |
38 |
self.readerObj = |
|
42 | self.readerObj = SpectraReader(self.Obj) | |
39 |
self.plotObj = |
|
43 | self.plotObj = Spectrum(self.Obj) | |
40 |
self.writerObj = |
|
44 | # self.writerObj = SpectraWriter(self.Obj) | |
41 |
|
45 | |||
42 | if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime)): |
|
46 | if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, expLabel='')): | |
43 | sys.exit(0) |
|
47 | sys.exit(0) | |
44 |
|
48 | |||
45 | if not(self.writerObj.setup(self.ppath)): |
|
49 | # if not(self.writerObj.setup(self.ppath)): | |
46 | sys.exit(0) |
|
50 | # sys.exit(0) | |
47 |
|
51 | |||
48 | def testSChain(self): |
|
52 | def testSChain(self): | |
49 |
|
53 | |||
50 | ini = time.time() |
|
54 | ini = time.time() | |
51 | while(True): |
|
55 | while(True): | |
52 | self.readerObj.getData() |
|
56 | self.readerObj.getData() | |
53 | self.plotObj.plotData(idProfile = 1, type='iq', ymin = -100, ymax = 100) |
|
57 | self.plotObj.plotData(showColorbar=False, showPowerProfile=True) | |
54 |
|
58 | |||
55 | # self.writerObj.putData() |
|
59 | # self.writerObj.putData() | |
56 |
|
60 | |||
57 | if self.readerObj.noMoreFiles: |
|
61 | if self.readerObj.noMoreFiles: | |
58 | break |
|
62 | break | |
59 |
|
63 | |||
60 | if self.readerObj.flagIsNewBlock: |
|
64 | if self.readerObj.flagIsNewBlock: | |
61 | print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks, |
|
65 | print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks, | |
62 | datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) |
|
66 | datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) | |
63 | fin = time.time() |
|
67 | fin = time.time() | |
64 | print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) |
|
68 | print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) | |
65 |
ini = time.time() |
|
69 | ini = time.time() | |
66 |
|
||||
67 |
|
||||
68 |
|
||||
69 |
|
||||
70 |
|
70 | |||
|
71 | #time.sleep(0.5) | |||
71 | self.plotObj.end() |
|
72 | self.plotObj.end() | |
72 |
|
73 | |||
73 | if __name__ == '__main__': |
|
74 | if __name__ == '__main__': | |
74 | TestSChain() No newline at end of file |
|
75 | TestSChain() |
General Comments 0
You need to be logged in to leave comments.
Login now