##// END OF EJS Templates
Changing the Model for the input Objects in Processing package...
Daniel Valdez -
r107:33fbc5472d1b
parent child
Show More
@@ -1,23 +1,13
1 [Read0]
1 [Read0]
2 id = 0
2 id = 0
3 type = VoltageReader
3 type = VoltageReader
4 setup = str,/Users/jro/Documents/RadarData/EW_Drifts,datetime,2011-11-20-0-0-1,datetime,2011-12-31-0-0-1,int,0,str,,str,None,int,0
4 setup = str,/Users/jro/Documents/RadarData/MST_ISR/MST,datetime,2009-01-01-0-0-1,datetime,2009-12-31-0-0-1,int,0,str,,str,None,int,0
5 getData = None,None
5 getData = None,None
6
6
7 [Processing0]
7 [Processing0]
8 id = 1
8 id = 1
9 type = Voltage
10 input = 0
11 setup = None,None
12 init = None,None
13 integrator = int,4,None,None
14 plotData = float,None,float,None,float,None,float,None,str,iq,str,Test Data Voltage 2,int,1
15
16 [Processing1]
17 id = 2
18 type = Spectra
9 type = Spectra
19 input = 1
10 input = 0
20 setup = int,8,None,None
11 setup = int,16,None,None
21 init = None,None
12 init = None,None
22 integrator = int,4,int,3
13 plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,1
23 plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,2
@@ -1,902 +1,903
1 """
1 """
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @autor $Author$
4 @autor $Author$
5 @version $Id$
5 @version $Id$
6
6
7 """
7 """
8
8
9 import numpy
9 import numpy
10 import plplot
10 import plplot
11
11
12 def cmap1_init(colormap="gray"):
12 def cmap1_init(colormap="gray"):
13
13
14 if colormap == None:
14 if colormap == None:
15 return
15 return
16
16
17 ncolor = None
17 ncolor = None
18 rgb_lvl = None
18 rgb_lvl = None
19
19
20 # Routine for defining a specific color map 1 in HLS space.
20 # Routine for defining a specific color map 1 in HLS space.
21 # if gray is true, use basic grayscale variation from half-dark to light.
21 # if gray is true, use basic grayscale variation from half-dark to light.
22 # otherwise use false color variation from blue (240 deg) to red (360 deg).
22 # otherwise use false color variation from blue (240 deg) to red (360 deg).
23
23
24 # Independent variable of control points.
24 # Independent variable of control points.
25 i = numpy.array((0., 1.))
25 i = numpy.array((0., 1.))
26 if colormap=="gray":
26 if colormap=="gray":
27 ncolor = 256
27 ncolor = 256
28 # Hue for control points. Doesn't matter since saturation is zero.
28 # Hue for control points. Doesn't matter since saturation is zero.
29 h = numpy.array((0., 0.))
29 h = numpy.array((0., 0.))
30 # Lightness ranging from half-dark (for interest) to light.
30 # Lightness ranging from half-dark (for interest) to light.
31 l = numpy.array((0.5, 1.))
31 l = numpy.array((0.5, 1.))
32 # Gray scale has zero saturation
32 # Gray scale has zero saturation
33 s = numpy.array((0., 0.))
33 s = numpy.array((0., 0.))
34
34
35 # number of cmap1 colours is 256 in this case.
35 # number of cmap1 colours is 256 in this case.
36 plplot.plscmap1n(ncolor)
36 plplot.plscmap1n(ncolor)
37 # Interpolate between control points to set up cmap1.
37 # Interpolate between control points to set up cmap1.
38 plplot.plscmap1l(0, i, h, l, s)
38 plplot.plscmap1l(0, i, h, l, s)
39
39
40 return None
40 return None
41
41
42 if colormap=="br_green":
42 if colormap=="br_green":
43 ncolor = 256
43 ncolor = 256
44 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
44 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
45 h = numpy.array((240., 0.))
45 h = numpy.array((240., 0.))
46 # Lightness and saturation are constant (values taken from C example).
46 # Lightness and saturation are constant (values taken from C example).
47 l = numpy.array((0.6, 0.6))
47 l = numpy.array((0.6, 0.6))
48 s = numpy.array((0.8, 0.8))
48 s = numpy.array((0.8, 0.8))
49
49
50 # number of cmap1 colours is 256 in this case.
50 # number of cmap1 colours is 256 in this case.
51 plplot.plscmap1n(ncolor)
51 plplot.plscmap1n(ncolor)
52 # Interpolate between control points to set up cmap1.
52 # Interpolate between control points to set up cmap1.
53 plplot.plscmap1l(0, i, h, l, s)
53 plplot.plscmap1l(0, i, h, l, s)
54
54
55 return None
55 return None
56
56
57 if colormap=="tricolor":
57 if colormap=="tricolor":
58 ncolor = 3
58 ncolor = 3
59 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
59 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
60 h = numpy.array((240., 0.))
60 h = numpy.array((240., 0.))
61 # Lightness and saturation are constant (values taken from C example).
61 # Lightness and saturation are constant (values taken from C example).
62 l = numpy.array((0.6, 0.6))
62 l = numpy.array((0.6, 0.6))
63 s = numpy.array((0.8, 0.8))
63 s = numpy.array((0.8, 0.8))
64
64
65 # number of cmap1 colours is 256 in this case.
65 # number of cmap1 colours is 256 in this case.
66 plplot.plscmap1n(ncolor)
66 plplot.plscmap1n(ncolor)
67 # Interpolate between control points to set up cmap1.
67 # Interpolate between control points to set up cmap1.
68 plplot.plscmap1l(0, i, h, l, s)
68 plplot.plscmap1l(0, i, h, l, s)
69
69
70 return None
70 return None
71
71
72 if colormap == 'rgb' or colormap == 'rgb666':
72 if colormap == 'rgb' or colormap == 'rgb666':
73
73
74 color_sz = 6
74 color_sz = 6
75 ncolor = color_sz*color_sz*color_sz
75 ncolor = color_sz*color_sz*color_sz
76 pos = numpy.zeros((ncolor))
76 pos = numpy.zeros((ncolor))
77 r = numpy.zeros((ncolor))
77 r = numpy.zeros((ncolor))
78 g = numpy.zeros((ncolor))
78 g = numpy.zeros((ncolor))
79 b = numpy.zeros((ncolor))
79 b = numpy.zeros((ncolor))
80 ind = 0
80 ind = 0
81 for ri in range(color_sz):
81 for ri in range(color_sz):
82 for gi in range(color_sz):
82 for gi in range(color_sz):
83 for bi in range(color_sz):
83 for bi in range(color_sz):
84 r[ind] = ri/(color_sz-1.0)
84 r[ind] = ri/(color_sz-1.0)
85 g[ind] = gi/(color_sz-1.0)
85 g[ind] = gi/(color_sz-1.0)
86 b[ind] = bi/(color_sz-1.0)
86 b[ind] = bi/(color_sz-1.0)
87 pos[ind] = ind/(ncolor-1.0)
87 pos[ind] = ind/(ncolor-1.0)
88 ind += 1
88 ind += 1
89 rgb_lvl = [6,6,6] #Levels for RGB colors
89 rgb_lvl = [6,6,6] #Levels for RGB colors
90
90
91 if colormap == 'rgb676':
91 if colormap == 'rgb676':
92 ncolor = 6*7*6
92 ncolor = 6*7*6
93 pos = numpy.zeros((ncolor))
93 pos = numpy.zeros((ncolor))
94 r = numpy.zeros((ncolor))
94 r = numpy.zeros((ncolor))
95 g = numpy.zeros((ncolor))
95 g = numpy.zeros((ncolor))
96 b = numpy.zeros((ncolor))
96 b = numpy.zeros((ncolor))
97 ind = 0
97 ind = 0
98 for ri in range(8):
98 for ri in range(8):
99 for gi in range(8):
99 for gi in range(8):
100 for bi in range(4):
100 for bi in range(4):
101 r[ind] = ri/(6-1.0)
101 r[ind] = ri/(6-1.0)
102 g[ind] = gi/(7-1.0)
102 g[ind] = gi/(7-1.0)
103 b[ind] = bi/(6-1.0)
103 b[ind] = bi/(6-1.0)
104 pos[ind] = ind/(ncolor-1.0)
104 pos[ind] = ind/(ncolor-1.0)
105 ind += 1
105 ind += 1
106 rgb_lvl = [6,7,6] #Levels for RGB colors
106 rgb_lvl = [6,7,6] #Levels for RGB colors
107
107
108 if colormap == 'rgb685':
108 if colormap == 'rgb685':
109 ncolor = 6*8*5
109 ncolor = 6*8*5
110 pos = numpy.zeros((ncolor))
110 pos = numpy.zeros((ncolor))
111 r = numpy.zeros((ncolor))
111 r = numpy.zeros((ncolor))
112 g = numpy.zeros((ncolor))
112 g = numpy.zeros((ncolor))
113 b = numpy.zeros((ncolor))
113 b = numpy.zeros((ncolor))
114 ind = 0
114 ind = 0
115 for ri in range(8):
115 for ri in range(8):
116 for gi in range(8):
116 for gi in range(8):
117 for bi in range(4):
117 for bi in range(4):
118 r[ind] = ri/(6-1.0)
118 r[ind] = ri/(6-1.0)
119 g[ind] = gi/(8-1.0)
119 g[ind] = gi/(8-1.0)
120 b[ind] = bi/(5-1.0)
120 b[ind] = bi/(5-1.0)
121 pos[ind] = ind/(ncolor-1.0)
121 pos[ind] = ind/(ncolor-1.0)
122 ind += 1
122 ind += 1
123 rgb_lvl = [6,8,5] #Levels for RGB colors
123 rgb_lvl = [6,8,5] #Levels for RGB colors
124
124
125 if colormap == 'rgb884':
125 if colormap == 'rgb884':
126 ncolor = 8*8*4
126 ncolor = 8*8*4
127 pos = numpy.zeros((ncolor))
127 pos = numpy.zeros((ncolor))
128 r = numpy.zeros((ncolor))
128 r = numpy.zeros((ncolor))
129 g = numpy.zeros((ncolor))
129 g = numpy.zeros((ncolor))
130 b = numpy.zeros((ncolor))
130 b = numpy.zeros((ncolor))
131 ind = 0
131 ind = 0
132 for ri in range(8):
132 for ri in range(8):
133 for gi in range(8):
133 for gi in range(8):
134 for bi in range(4):
134 for bi in range(4):
135 r[ind] = ri/(8-1.0)
135 r[ind] = ri/(8-1.0)
136 g[ind] = gi/(8-1.0)
136 g[ind] = gi/(8-1.0)
137 b[ind] = bi/(4-1.0)
137 b[ind] = bi/(4-1.0)
138 pos[ind] = ind/(ncolor-1.0)
138 pos[ind] = ind/(ncolor-1.0)
139 ind += 1
139 ind += 1
140 rgb_lvl = [8,8,4] #Levels for RGB colors
140 rgb_lvl = [8,8,4] #Levels for RGB colors
141
141
142 if ncolor == None:
142 if ncolor == None:
143 raise ValueError, "The colormap selected is not valid"
143 raise ValueError, "The colormap selected is not valid"
144
144
145 plplot.plscmap1n(ncolor)
145 plplot.plscmap1n(ncolor)
146 plplot.plscmap1l(1, pos, r, g, b)
146 plplot.plscmap1l(1, pos, r, g, b)
147
147
148 return rgb_lvl
148 return rgb_lvl
149
149
150 def setColormap(colormap="br_green"):
150 def setColormap(colormap="br_green"):
151 cmap1_init(colormap)
151 cmap1_init(colormap)
152
152
153 class BaseGraph:
153 class BaseGraph:
154 """
154 """
155
155
156 """
156 """
157 hasNotRange = True
157 hasNotRange = True
158
158
159 xrange = None
159 xrange = None
160 yrange = None
160 yrange = None
161 zrange = None
161 zrange = None
162
162
163 xlabel = None
163 xlabel = None
164 ylabel = None
164 ylabel = None
165 title = None
165 title = None
166
166
167 legends = None
167 legends = None
168
168
169 __name = None
169 __name = None
170
170
171 __colormap = None
171 __colormap = None
172 __colbox = None
172 __colbox = None
173 __colleg = None
173 __colleg = None
174
174
175 __xpos = None
175 __xpos = None
176 __ypos = None
176 __ypos = None
177
177
178 __xopt = None #"bcnst"
178 __xopt = None #"bcnst"
179 __yopt = None #"bcnstv"
179 __yopt = None #"bcnstv"
180
180
181 __xlpos = None
181 __xlpos = None
182 __ylpos = None
182 __ylpos = None
183
183
184 __xrangeIsTime = False
184 __xrangeIsTime = False
185
185
186 #Advanced
186 #Advanced
187 __xg = None
187 __xg = None
188 __yg = None
188 __yg = None
189
189
190 def __init__(self):
190 def __init__(self):
191 """
191 """
192
192
193 """
193 """
194 self.hasNotRange = True
194 self.hasNotRange = True
195
195
196 self.xrange = None
196 self.xrange = None
197 self.yrange = None
197 self.yrange = None
198 self.zrange = None
198 self.zrange = None
199
199
200 self.xlabel = None
200 self.xlabel = None
201 self.ylabel = None
201 self.ylabel = None
202 self.title = None
202 self.title = None
203
203
204 self.legends = None
204 self.legends = None
205
205
206 self.__name = None
206 self.__name = None
207
207
208 self.__colormap = None
208 self.__colormap = None
209 self.__colbox = None
209 self.__colbox = None
210 self.__colleg = None
210 self.__colleg = None
211
211
212 self.__xpos = None
212 self.__xpos = None
213 self.__ypos = None
213 self.__ypos = None
214
214
215 self.__xopt = None #"bcnst"
215 self.__xopt = None #"bcnst"
216 self.__yopt = None #"bcnstv"
216 self.__yopt = None #"bcnstv"
217
217
218 self.__xlpos = None
218 self.__xlpos = None
219 self.__ylpos = None
219 self.__ylpos = None
220
220
221 self.__xrangeIsTime = False
221 self.__xrangeIsTime = False
222
222
223 #Advanced
223 #Advanced
224 self.__xg = None
224 self.__xg = None
225 self.__yg = None
225 self.__yg = None
226
226
227 def setName(self, name):
227 def setName(self, name):
228 self.__name = name
228 self.__name = name
229
229
230 def setScreenPos(self, xpos, ypos):
230 def setScreenPos(self, xpos, ypos):
231 self.__xpos = xpos
231 self.__xpos = xpos
232 self.__ypos = ypos
232 self.__ypos = ypos
233
233
234 def setOpt(self, xopt, yopt):
234 def setOpt(self, xopt, yopt):
235 self.__xopt = xopt
235 self.__xopt = xopt
236 self.__yopt = yopt
236 self.__yopt = yopt
237
237
238 def setXAxisAsTime(self):
238 def setXAxisAsTime(self):
239 self.__xrangeIsTime = True
239 self.__xrangeIsTime = True
240
240
241
241
242 def setup(self, title=None, xlabel=None, ylabel=None, colormap=None):
242 def setup(self, title=None, xlabel=None, ylabel=None, colormap=None):
243 """
243 """
244 """
244 """
245 self.title = title
245 self.title = title
246 self.xlabel = xlabel
246 self.xlabel = xlabel
247 self.ylabel = ylabel
247 self.ylabel = ylabel
248 self.__colormap = colormap
248 self.__colormap = colormap
249
249
250 def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False):
250 def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False):
251 """
251 """
252
252
253 """
253 """
254 if self.__xrangeIsTime:
254 if self.__xrangeIsTime:
255 plplot.pltimefmt("%H:%M")
255 plplot.pltimefmt("%H:%M")
256
256
257 plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
257 plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
258 plplot.plwind(float(xmin),
258 plplot.plwind(float(xmin),
259 float(xmax),
259 float(xmax),
260 float(ymin),
260 float(ymin),
261 float(ymax)
261 float(ymax)
262 )
262 )
263
263
264 if xopt == None: xopt = self.__xopt
264 if xopt == None: xopt = self.__xopt
265 if yopt == None: yopt = self.__yopt
265 if yopt == None: yopt = self.__yopt
266
266
267 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
267 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
268
268
269 if not(nolabels):
269 if not(nolabels):
270 plplot.pllab(self.xlabel, self.ylabel, self.title)
270 plplot.pllab(self.xlabel, self.ylabel, self.title)
271
271
272
272
273 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
273 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
274 data = numpy.arange(256)
274 data = numpy.arange(256)
275 data = numpy.reshape(data, (1,-1))
275 data = numpy.reshape(data, (1,-1))
276
276
277 plplot.plimage(data,
277 plplot.plimage(data,
278 float(xmin),
278 float(xmin),
279 float(xmax),
279 float(xmax),
280 float(ymin),
280 float(ymin),
281 float(ymax),
281 float(ymax),
282 0.,
282 0.,
283 255.,
283 255.,
284 float(xmin),
284 float(xmin),
285 float(xmax),
285 float(xmax),
286 float(ymin),
286 float(ymin),
287 float(ymax))
287 float(ymax))
288
288
289 def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None):
289 def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None):
290
290
291 if xmin == None: xmin = x[0]
291 if xmin == None: xmin = x[0]
292 if xmax == None: xmax = x[-1]
292 if xmax == None: xmax = x[-1]
293 if ymin == None: ymin = y[0]
293 if ymin == None: ymin = y[0]
294 if ymax == None: ymax = y[-1]
294 if ymax == None: ymax = y[-1]
295
295
296 plplot.plline(x, y)
296 plplot.plline(x, y)
297
297
298 def basicXYwithErrorPlot(self):
298 def basicXYwithErrorPlot(self):
299 pass
299 pass
300
300
301 def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
301 def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
302
302
303 if xmin == None: xmin = x[0]
303 if xmin == None: xmin = x[0]
304 if xmax == None: xmax = x[-1]
304 if xmax == None: xmax = x[-1]
305 if ymin == None: ymin = y[0]
305 if ymin == None: ymin = y[0]
306 if ymax == None: ymax = y[-1]
306 if ymax == None: ymax = y[-1]
307
307
308 plplot.plcol0(colline)
308 plplot.plcol0(colline)
309 plplot.plline(x, y)
309 plplot.plline(x, y)
310 plplot.plcol0(1)
310 plplot.plcol0(1)
311
311
312 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
312 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
313 """
313 """
314 """
314 """
315 if xmin == None: xmin = x[0]
315 if xmin == None: xmin = x[0]
316 if xmax == None: xmax = x[-1]
316 if xmax == None: xmax = x[-1]
317 if ymin == None: ymin = y[0]
317 if ymin == None: ymin = y[0]
318 if ymax == None: ymax = y[-1]
318 if ymax == None: ymax = y[-1]
319 if zmin == None: zmin = numpy.nanmin(data)
319 if zmin == None: zmin = numpy.nanmin(data)
320 if zmax == None: zmax = numpy.nanmax(data)
320 if zmax == None: zmax = numpy.nanmax(data)
321
321
322 plplot.plimage(data,
322 plplot.plimage(data,
323 float(x[0]),
323 float(x[0]),
324 float(x[-1]),
324 float(x[-1]),
325 float(y[0]),
325 float(y[0]),
326 float(y[-1]),
326 float(y[-1]),
327 float(zmin),
327 float(zmin),
328 float(zmax),
328 float(zmax),
329 float(xmin),
329 float(xmin),
330 float(xmax),
330 float(xmax),
331 float(ymin),
331 float(ymin),
332 float(ymax)
332 float(ymax)
333 )
333 )
334
334
335 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
335 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
336
336
337 if not(len(x)>1 and len(y)>1):
337 if not(len(x)>1 and len(y)>1):
338 raise ValueError, "x axis and y axis are empty"
338 raise ValueError, "x axis and y axis are empty"
339
339
340 if deltax == None: deltax = x[-1] - x[-2]
340 if deltax == None: deltax = x[-1] - x[-2]
341 if deltay == None: deltay = y[-1] - y[-2]
341 if deltay == None: deltay = y[-1] - y[-2]
342
342
343 x1 = numpy.append(x, x[-1] + deltax)
343 x1 = numpy.append(x, x[-1] + deltax)
344 y1 = numpy.append(y, y[-1] + deltay)
344 y1 = numpy.append(y, y[-1] + deltay)
345
345
346 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
346 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
347 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
347 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
348
348
349 self.__xg = xg
349 self.__xg = xg
350 self.__yg = yg
350 self.__yg = yg
351
351
352 def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.):
352 def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.):
353 """
353 """
354 """
354 """
355
355
356 if self.__xg == None and self.__yg == None:
356 if self.__xg == None and self.__yg == None:
357 self.__getBoxpltr(x, y)
357 self.__getBoxpltr(x, y)
358
358
359 plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg)
359 plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg)
360
360
361
361
362 class LinearPlot:
362 class LinearPlot:
363
363
364 linearGraphObj = BaseGraph()
364 linearGraphObj = BaseGraph()
365
365
366 __szchar = 1.0
366 __szchar = 1.0
367
367
368 __xrange = None
368 __xrange = None
369
369
370 __yrange = None
370 __yrange = None
371
371
372 __subpage = 0
372 __subpage = 0
373 m_BaseGraph= BaseGraph()
373 m_BaseGraph= BaseGraph()
374
374
375
375
376
376
377 def __init__(self):
377 def __init__(self):
378
378
379
379
380 key = "linearplot"
380 key = "linearplot"
381 self.linearGraphObj = BaseGraph()
381 self.linearGraphObj = BaseGraph()
382 self.linearGraphObj.setName(key)
382 self.linearGraphObj.setName(key)
383
383
384 self.__subpage = 0
384 self.__subpage = 0
385
385
386 def __iniSubpage(self):
386 def __iniSubpage(self):
387
387
388 if plplot.plgdev() == '':
388 if plplot.plgdev() == '':
389 raise ValueError, "Plot device has not been initialize"
389 raise ValueError, "Plot device has not been initialize"
390
390
391 plplot.pladv(self.__subpage)
391 plplot.pladv(self.__subpage)
392 plplot.plschr(0.0, self.__szchar)
392 plplot.plschr(0.0, self.__szchar)
393
393
394 setColormap()
394 setColormap()
395
395
396 def setScreenPos(self, width='small'):
396 def setScreenPos(self, width='small'):
397
397
398 if width == 'small':
398 if width == 'small':
399 xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80
399 xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80
400
400
401 if width == 'medium':
401 if width == 'medium':
402 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60
402 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60
403
403
404 xf = xi + xw
404 xf = xi + xw
405 yf = yi + yw
405 yf = yi + yw
406
406
407 self.linearGraphObj.setScreenPos([xi, xf], [yi, yf])
407 self.linearGraphObj.setScreenPos([xi, xf], [yi, yf])
408
408
409 def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False):
409 def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False):
410 """
410 """
411 """
411 """
412
412
413 self.linearGraphObj.setOpt("bcnts","bcntsv")
413 self.linearGraphObj.setOpt("bcnts","bcntsv")
414 self.linearGraphObj.setup(title,
414 self.linearGraphObj.setup(title,
415 xlabel,
415 xlabel,
416 ylabel
416 ylabel
417 )
417 )
418
418
419 self.setScreenPos(width='medium')
419 self.setScreenPos(width='medium')
420
420
421 if XAxisAsTime:
421 if XAxisAsTime:
422 self.linearGraphObj.setXAxisAsTime()
422 self.linearGraphObj.setXAxisAsTime()
423
423
424 self.__subpage = subpage
424 self.__subpage = subpage
425 # def setRanges(self, xrange, yrange, zrange):
425 # def setRanges(self, xrange, yrange, zrange):
426 #
426 #
427 # self.linearGraphObj.setRanges(xrange, yrange, zrange)
427 # self.linearGraphObj.setRanges(xrange, yrange, zrange)
428
428
429 def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
429 def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
430 """
430 """
431 Inputs:
431 Inputs:
432
432
433 x : Numpy array of dimension 1
433 x : Numpy array of dimension 1
434 y : Numpy array of dimension 1
434 y : Numpy array of dimension 1
435
435
436 """
436 """
437
437
438 try:
438 try:
439 nX = numpy.shape(x)
439 nX = numpy.shape(x)
440 except:
440 except:
441 raise ValueError, "x is not a numpy array"
441 raise ValueError, "x is not a numpy array"
442
442
443 if y == None: y = numpy.arange(nX)
443 if y == None: y = numpy.arange(nX)
444
444
445 if xmin == None: xmin = x[0]
445 if xmin == None: xmin = x[0]
446 if xmax == None: xmax = x[-1]
446 if xmax == None: xmax = x[-1]
447 if ymin == None: ymin = y[0]
447 if ymin == None: ymin = y[0]
448 if ymax == None: ymax = y[-1]
448 if ymax == None: ymax = y[-1]
449
449
450 self.__iniSubpage()
450 self.__iniSubpage()
451 self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax)
451 self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax)
452 self.linearGraphObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline)
452 self.linearGraphObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline)
453
453
454 def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'):
454 def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'):
455 """
455 """
456 Inputs:
456 Inputs:
457
457
458 x : Numpy array of dimension 1
458 x : Numpy array of dimension 1
459 y : Complex numpy array of dimension 1
459 y : Complex numpy array of dimension 1
460
460
461 """
461 """
462
462
463 try:
463 try:
464 nX = numpy.shape(x)
464 nX = numpy.shape(x)
465 except:
465 except:
466 raise ValueError, "x is not a numpy array"
466 raise ValueError, "x is not a numpy array"
467
467
468 try:
468 try:
469 nY = numpy.shape(y)
469 nY = numpy.shape(y)
470 except:
470 except:
471 raise ValueError, "y is not a numpy array"
471 raise ValueError, "y is not a numpy array"
472
472
473 if xmin == None: xmin = x[0]
473 if xmin == None: xmin = x[0]
474 if xmax == None: xmax = x[-1]
474 if xmax == None: xmax = x[-1]
475 if ymin == None: ymin = y[0]
475 if ymin == None: ymin = y[0]
476 if ymax == None: ymax = y[-1]
476 if ymax == None: ymax = y[-1]
477
477
478 self.__iniSubpage()
478 self.__iniSubpage()
479 self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax)
479 self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax)
480
480
481 if type.lower() == 'power':
481 if type.lower() == 'power':
482 self.linearGraphObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline)
482 self.linearGraphObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline)
483
483
484 if type.lower() == 'iq':
484 if type.lower() == 'iq':
485
485
486 self.linearGraphObj.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline)
486 self.linearGraphObj.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline)
487 self.linearGraphObj.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1)
487 self.linearGraphObj.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1)
488
488
489 class ColorPlot:
489 class ColorPlot:
490
490
491 colorGraphObj = BaseGraph()
491 colorGraphObj = BaseGraph()
492
492
493 graphObjDict = {}
493 graphObjDict = {}
494
494
495 __subpage = 0
495 __subpage = 0
496
496
497 __showColorbar = False
497 __showColorbar = False
498
498
499 __showPowerProfile = True
499 __showPowerProfile = True
500
500
501 __szchar = 0.65
501 __szchar = 0.65
502
502
503 __xrange = None
503 __xrange = None
504
504
505 __yrange = None
505 __yrange = None
506
506
507 __zrange = None
507 __zrange = None
508 m_BaseGraph= BaseGraph()
508 m_BaseGraph= BaseGraph()
509
509
510
510
511
511
512 def __init__(self):
512 def __init__(self):
513
513
514 self.graphObjDict = {}
514 self.graphObjDict = {}
515
515
516 self.__subpage = 0
516 self.__subpage = 0
517 self.__showColorbar = False
517 self.__showColorbar = False
518 self.__showPowerProfile = True
518 self.__showPowerProfile = True
519
519
520 self.__szchar = 0.65
520 self.__szchar = 0.65
521 self.__xrange = None
521 self.__xrange = None
522 self.__yrange = None
522 self.__yrange = None
523 self.__zrange = None
523 self.__zrange = None
524
524
525 key = "colorplot"
525 key = "colorplot"
526 self.colorGraphObj = BaseGraph()
526 self.colorGraphObj = BaseGraph()
527 self.colorGraphObj.setName(key)
527 self.colorGraphObj.setName(key)
528
528
529 def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
529 def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
530 """
530 """
531 """
531 """
532
532
533 self.colorGraphObj.setOpt("bcnts","bcntsv")
533 self.colorGraphObj.setOpt("bcnts","bcntsv")
534 self.colorGraphObj.setup(title,
534 self.colorGraphObj.setup(title,
535 xlabel,
535 xlabel,
536 ylabel
536 ylabel
537 )
537 )
538
538
539 self.__subpage = subpage
539 self.__subpage = subpage
540 self.__colormap = colormap
540 self.__colormap = colormap
541 self.__showColorbar = showColorbar
541 self.__showColorbar = showColorbar
542 self.__showPowerProfile = showPowerProfile
542 self.__showPowerProfile = showPowerProfile
543
543
544 if showColorbar:
544 if showColorbar:
545 key = "colorbar"
545 key = "colorbar"
546
546
547 cmapObj = BaseGraph()
547 cmapObj = BaseGraph()
548 cmapObj.setName(key)
548 cmapObj.setName(key)
549 cmapObj.setOpt("bc","bcmtv")
549 cmapObj.setOpt("bc","bcmtv")
550 cmapObj.setup(title="dBs",
550 cmapObj.setup(title="dBs",
551 xlabel="",
551 xlabel="",
552 ylabel="",
552 ylabel="",
553 colormap=colormap)
553 colormap=colormap)
554
554
555 self.graphObjDict[key] = cmapObj
555 self.graphObjDict[key] = cmapObj
556
556
557
557
558 if showPowerProfile:
558 if showPowerProfile:
559 key = "powerprof"
559 key = "powerprof"
560
560
561 powObj = BaseGraph()
561 powObj = BaseGraph()
562 powObj.setName(key)
562 powObj.setName(key)
563 powObj.setOpt("bcntg","bc")
563 powObj.setOpt("bcntg","bc")
564 powObj.setup(title="Power Profile",
564 powObj.setup(title="Power Profile",
565 xlabel="dB",
565 xlabel="dB",
566 ylabel="")
566 ylabel="")
567
567
568 self.graphObjDict[key] = powObj
568 self.graphObjDict[key] = powObj
569
569
570 self.setScreenPos(width='small')
570 self.setScreenPos(width='small')
571
571
572 if XAxisAsTime:
572 if XAxisAsTime:
573 self.colorGraphObj.setXAxisAsTime()
573 self.colorGraphObj.setXAxisAsTime()
574
574
575 def __iniSubpage(self):
575 def __iniSubpage(self):
576
576
577 if plplot.plgdev() == '':
577 if plplot.plgdev() == '':
578 raise ValueError, "Plot device has not been initialize"
578 raise ValueError, "Plot device has not been initialize"
579
579
580 plplot.pladv(self.__subpage)
580 plplot.pladv(self.__subpage)
581 plplot.plschr(0.0, self.__szchar)
581 plplot.plschr(0.0, self.__szchar)
582
582
583 setColormap(self.__colormap)
583 setColormap(self.__colormap)
584
584
585 def setScreenPos(self, width='small'):
585 def setScreenPos(self, width='small'):
586
586
587 if width == 'small':
587 if width == 'small':
588 xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.04; xpoww = 0.25; deltaxcmap = 0.02; deltaxpow = 0.06
588 xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.04; xpoww = 0.25; deltaxcmap = 0.02; deltaxpow = 0.06
589
589
590 if width == 'medium':
590 if width == 'medium':
591 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.04; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06
591 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.04; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06
592
592
593 if self.__showColorbar:
593 if self.__showColorbar:
594 xw -= xcmapw + deltaxcmap
594 xw -= xcmapw + deltaxcmap
595
595
596 if self.__showPowerProfile:
596 if self.__showPowerProfile:
597 xw -= xpoww + deltaxpow
597 xw -= xpoww + deltaxpow
598
598
599 xf = xi + xw
599 xf = xi + xw
600 yf = yi + yw
600 yf = yi + yw
601 xcmapf = xf
601 xcmapf = xf
602
602
603 self.colorGraphObj.setScreenPos([xi, xf], [yi, yf])
603 self.colorGraphObj.setScreenPos([xi, xf], [yi, yf])
604
604
605 if self.__showColorbar:
605 if self.__showColorbar:
606 xcmapi = xf + deltaxcmap
606 xcmapi = xf + deltaxcmap
607 xcmapf = xcmapi + xcmapw
607 xcmapf = xcmapi + xcmapw
608
608
609 key = "colorbar"
609 key = "colorbar"
610 cmapObj = self.graphObjDict[key]
610 cmapObj = self.graphObjDict[key]
611 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
611 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
612
612
613 if self.__showPowerProfile:
613 if self.__showPowerProfile:
614
614
615 xpowi = xcmapf + deltaxpow
615 xpowi = xcmapf + deltaxpow
616 xpowf = xpowi + xpoww
616 xpowf = xpowi + xpoww
617
617
618 key = "powerprof"
618 key = "powerprof"
619 powObj = self.graphObjDict[key]
619 powObj = self.graphObjDict[key]
620 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
620 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
621
621
622
622
623
623
624 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
624 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, title = ''):
625 """
625 """
626 Inputs:
626 Inputs:
627
627
628 x : Numpy array of dimension 1
628 x : Numpy array of dimension 1
629 y : Numpy array of dimension 1
629 y : Numpy array of dimension 1
630
630
631 """
631 """
632
632
633 try:
633 try:
634 nX, nY = numpy.shape(data)
634 nX, nY = numpy.shape(data)
635 except:
635 except:
636 raise ValueError, "data is not a numpy array"
636 raise ValueError, "data is not a numpy array"
637
637
638 if x == None: x = numpy.arange(nX)
638 if x == None: x = numpy.arange(nX)
639 if y == None: y = numpy.arange(nY)
639 if y == None: y = numpy.arange(nY)
640
640
641 if xmin == None: xmin = x[0]
641 if xmin == None: xmin = x[0]
642 if xmax == None: xmax = x[-1]
642 if xmax == None: xmax = x[-1]
643 if ymin == None: ymin = y[0]
643 if ymin == None: ymin = y[0]
644 if ymax == None: ymax = y[-1]
644 if ymax == None: ymax = y[-1]
645 if zmin == None: zmin = numpy.nanmin(data)
645 if zmin == None: zmin = numpy.nanmin(data)
646 if zmax == None: zmax = numpy.nanmax(data)
646 if zmax == None: zmax = numpy.nanmax(data)
647
647
648 plplot.plschr(0.0, self.__szchar)
648 plplot.plschr(0.0, self.__szchar)
649 self.__iniSubpage()
649 self.__iniSubpage()
650 self.colorGraphObj.title = title
650 self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax)
651 self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax)
651 self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax)
652 self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax)
652
653
653 if self.__showColorbar:
654 if self.__showColorbar:
654
655
655
656
656 key = "colorbar"
657 key = "colorbar"
657 cmapObj = self.graphObjDict[key]
658 cmapObj = self.graphObjDict[key]
658
659
659 plplot.plschr(0.0, self.__szchar-0.05)
660 plplot.plschr(0.0, self.__szchar-0.05)
660 cmapObj.plotBox(0., 1., zmin, zmax)
661 cmapObj.plotBox(0., 1., zmin, zmax)
661 cmapObj.colorbarPlot(0., 1., zmin, zmax)
662 cmapObj.colorbarPlot(0., 1., zmin, zmax)
662
663
663 if self.__showPowerProfile:
664 if self.__showPowerProfile:
664 power = numpy.max(data, axis=0)
665 power = numpy.average(data, axis=0)
665
666
666 step = (ymax - ymin)/(nY-1)
667 step = (ymax - ymin)/(nY-1)
667 heis = numpy.arange(ymin, ymax + step, step)
668 heis = numpy.arange(ymin, ymax + step, step)
668
669
669 key = "powerprof"
670 key = "powerprof"
670 powObj = self.graphObjDict[key]
671 powObj = self.graphObjDict[key]
671
672
672 plplot.pllsty(2)
673 plplot.pllsty(2)
673 plplot.plschr(0.0, self.__szchar-0.05)
674 plplot.plschr(0.0, self.__szchar-0.05)
674 powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True)
675 powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True)
675
676
676 plplot.pllsty(1)
677 plplot.pllsty(1)
677 plplot.plschr(0.0, self.__szchar)
678 plplot.plschr(0.0, self.__szchar)
678 powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc')
679 powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc')
679
680
680 plplot.plcol0(9)
681 plplot.plcol0(9)
681 powObj.basicXYPlot(power, heis)
682 powObj.basicXYPlot(power, heis)
682 plplot.plcol0(1)
683 plplot.plcol0(1)
683
684
684
685
685 class ColorPlotX:
686 class ColorPlotX:
686
687
687
688
688 graphObjDict = {}
689 graphObjDict = {}
689 showColorbar = False
690 showColorbar = False
690 showPowerProfile = True
691 showPowerProfile = True
691
692
692 __szchar = 0.7
693 __szchar = 0.7
693 __xrange = None
694 __xrange = None
694 __yrange = None
695 __yrange = None
695 __zrange = None
696 __zrange = None
696
697
697 colorGraphObj = BaseGraph()
698 colorGraphObj = BaseGraph()
698
699
699 def __init__(self):
700 def __init__(self):
700
701
701 key = "colorplot"
702 key = "colorplot"
702 self.colorGraphObj.setName(key)
703 self.colorGraphObj.setName(key)
703
704
704 self.__subpage = 0
705 self.__subpage = 0
705
706
706 self.graphObjDict[key] = self.colorGraphObj
707 self.graphObjDict[key] = self.colorGraphObj
707
708
708 def __iniSubpage(self):
709 def __iniSubpage(self):
709
710
710 if plplot.plgdev() == '':
711 if plplot.plgdev() == '':
711 raise ValueError, "Plot device has not been initialize"
712 raise ValueError, "Plot device has not been initialize"
712
713
713 plplot.pladv(self.__subpage)
714 plplot.pladv(self.__subpage)
714 plplot.plschr(0.0, self.__szchar)
715 plplot.plschr(0.0, self.__szchar)
715
716
716 setColormap(self.__colormap)
717 setColormap(self.__colormap)
717
718
718 def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06):
719 def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06):
719
720
720 if self.showColorbar:
721 if self.showColorbar:
721 xw -= xcmapw + deltaxcmap
722 xw -= xcmapw + deltaxcmap
722
723
723 if self.showPowerProfile:
724 if self.showPowerProfile:
724 xw -= xpoww + deltaxpow
725 xw -= xpoww + deltaxpow
725
726
726 xf = xi + xw
727 xf = xi + xw
727 yf = yi + yw
728 yf = yi + yw
728 xcmapf = xf
729 xcmapf = xf
729
730
730 self.colorGraphObj.setScreenPos([xi, xf], [yi, yf])
731 self.colorGraphObj.setScreenPos([xi, xf], [yi, yf])
731
732
732 if self.showColorbar:
733 if self.showColorbar:
733 xcmapi = xf + deltaxcmap
734 xcmapi = xf + deltaxcmap
734 xcmapf = xcmapi + xcmapw
735 xcmapf = xcmapi + xcmapw
735
736
736 key = "colorbar"
737 key = "colorbar"
737 cmapObj = self.graphObjDict[key]
738 cmapObj = self.graphObjDict[key]
738 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
739 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
739
740
740 if self.showPowerProfile:
741 if self.showPowerProfile:
741
742
742 xpowi = xcmapf + deltaxpow
743 xpowi = xcmapf + deltaxpow
743 xpowf = xpowi + xpoww
744 xpowf = xpowi + xpoww
744
745
745 key = "powerprof"
746 key = "powerprof"
746 powObj = self.graphObjDict[key]
747 powObj = self.graphObjDict[key]
747 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
748 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
748
749
749 def setRanges(self, xrange, yrange, zrange):
750 def setRanges(self, xrange, yrange, zrange):
750
751
751 self.colorGraphObj.setRanges(xrange, yrange, zrange)
752 self.colorGraphObj.setRanges(xrange, yrange, zrange)
752
753
753 keyList = self.graphObjDict.keys()
754 keyList = self.graphObjDict.keys()
754
755
755 key = "colorbar"
756 key = "colorbar"
756 if key in keyList:
757 if key in keyList:
757 cmapObj = self.graphObjDict[key]
758 cmapObj = self.graphObjDict[key]
758 cmapObj.setRanges([0., 1.], zrange)
759 cmapObj.setRanges([0., 1.], zrange)
759
760
760 key = "powerprof"
761 key = "powerprof"
761 if key in keyList:
762 if key in keyList:
762 powObj = self.graphObjDict[key]
763 powObj = self.graphObjDict[key]
763 powObj.setRanges(zrange, yrange)
764 powObj.setRanges(zrange, yrange)
764
765
765 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
766 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
766 """
767 """
767 """
768 """
768
769
769 self.colorGraphObj.setSubpage(subpage)
770 self.colorGraphObj.setSubpage(subpage)
770 self.colorGraphObj.setSzchar(self.__szchar)
771 self.colorGraphObj.setSzchar(self.__szchar)
771 self.colorGraphObj.setOpt("bcnts","bcntsv")
772 self.colorGraphObj.setOpt("bcnts","bcntsv")
772 self.colorGraphObj.setup(title,
773 self.colorGraphObj.setup(title,
773 xlabel,
774 xlabel,
774 ylabel,
775 ylabel,
775 colormap)
776 colormap)
776
777
777 if showColorbar:
778 if showColorbar:
778 key = "colorbar"
779 key = "colorbar"
779
780
780 cmapObj = BaseGraph()
781 cmapObj = BaseGraph()
781 cmapObj.setName(key)
782 cmapObj.setName(key)
782 cmapObj.setSubpage(subpage)
783 cmapObj.setSubpage(subpage)
783 cmapObj.setSzchar(self.__szchar)
784 cmapObj.setSzchar(self.__szchar)
784 cmapObj.setOpt("bc","bcmt")
785 cmapObj.setOpt("bc","bcmt")
785 cmapObj.setup(title="dBs",
786 cmapObj.setup(title="dBs",
786 xlabel="",
787 xlabel="",
787 ylabel="",
788 ylabel="",
788 colormap=colormap)
789 colormap=colormap)
789
790
790 self.graphObjDict[key] = cmapObj
791 self.graphObjDict[key] = cmapObj
791
792
792
793
793 if showPowerProfile:
794 if showPowerProfile:
794 key = "powerprof"
795 key = "powerprof"
795
796
796 powObj = BaseGraph()
797 powObj = BaseGraph()
797 powObj.setName(key)
798 powObj.setName(key)
798 powObj.setSubpage(subpage)
799 powObj.setSubpage(subpage)
799 powObj.setSzchar(self.__szchar)
800 powObj.setSzchar(self.__szchar)
800 plplot.pllsty(2)
801 plplot.pllsty(2)
801 powObj.setOpt("bcntg","bc")
802 powObj.setOpt("bcntg","bc")
802 plplot.pllsty(1)
803 plplot.pllsty(1)
803 powObj.setup(title="Power Profile",
804 powObj.setup(title="Power Profile",
804 xlabel="dBs",
805 xlabel="dBs",
805 ylabel="")
806 ylabel="")
806
807
807 self.graphObjDict[key] = powObj
808 self.graphObjDict[key] = powObj
808
809
809 self.showColorbar = showColorbar
810 self.showColorbar = showColorbar
810 self.showPowerProfile = showPowerProfile
811 self.showPowerProfile = showPowerProfile
811 self.setScreenPos()
812 self.setScreenPos()
812
813
813 if XAxisAsTime:
814 if XAxisAsTime:
814 self.colorGraphObj.setXAxisAsTime()
815 self.colorGraphObj.setXAxisAsTime()
815 #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02)
816 #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02)
816
817
817
818
818 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
819 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
819 """
820 """
820 """
821 """
821
822
822 try:
823 try:
823 nX, nY = numpy.shape(data)
824 nX, nY = numpy.shape(data)
824 except:
825 except:
825 raise ValueError, "data is not a numpy array"
826 raise ValueError, "data is not a numpy array"
826
827
827 if x == None: x = numpy.arange(nX)
828 if x == None: x = numpy.arange(nX)
828 if y == None: y = numpy.arange(nY)
829 if y == None: y = numpy.arange(nY)
829
830
830 if xmin == None: xmin = x[0]
831 if xmin == None: xmin = x[0]
831 if xmax == None: xmax = x[-1]
832 if xmax == None: xmax = x[-1]
832 if ymin == None: ymin = y[0]
833 if ymin == None: ymin = y[0]
833 if ymax == None: ymax = y[-1]
834 if ymax == None: ymax = y[-1]
834 if zmin == None: zmin = numpy.nanmin(data)
835 if zmin == None: zmin = numpy.nanmin(data)
835 if zmax == None: zmax = numpy.nanmax(data)
836 if zmax == None: zmax = numpy.nanmax(data)
836
837
837 if self.colorGraphObj.hasNotRange:
838 if self.colorGraphObj.hasNotRange:
838 self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax])
839 self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax])
839
840
840 self.colorGraphObj.initSubpage()
841 self.colorGraphObj.initSubpage()
841 self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.colorGraphObj.zrange[0], self.colorGraphObj.zrange[1])
842 self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.colorGraphObj.zrange[0], self.colorGraphObj.zrange[1])
842
843
843 if self.showColorbar:
844 if self.showColorbar:
844 key = "colorbar"
845 key = "colorbar"
845 cmapObj = self.graphObjDict[key]
846 cmapObj = self.graphObjDict[key]
846 cmapObj.colorbarPlot()
847 cmapObj.colorbarPlot()
847
848
848 if self.showPowerProfile:
849 if self.showPowerProfile:
849 power = numpy.average(data, axis=1)
850 power = numpy.average(data, axis=1)
850
851
851 step = (ymax - ymin)/(nY-1)
852 step = (ymax - ymin)/(nY-1)
852 heis = numpy.arange(ymin, ymax + step, step)
853 heis = numpy.arange(ymin, ymax + step, step)
853
854
854 key = "powerprof"
855 key = "powerprof"
855 powObj = self.graphObjDict[key]
856 powObj = self.graphObjDict[key]
856 powObj.basicXYPlot(power, heis)
857 powObj.basicXYPlot(power, heis)
857
858
858 if __name__ == '__main__':
859 if __name__ == '__main__':
859
860
860 import numpy
861 import numpy
861 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
862 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
862 plplot.plsdev("xwin")
863 plplot.plsdev("xwin")
863 plplot.plscolbg(255,255,255)
864 plplot.plscolbg(255,255,255)
864 plplot.plscol0(1,0,0,0)
865 plplot.plscol0(1,0,0,0)
865 plplot.plspause(False)
866 plplot.plspause(False)
866 plplot.plinit()
867 plplot.plinit()
867 plplot.plssub(2, 2)
868 plplot.plssub(2, 2)
868
869
869 nx = 64
870 nx = 64
870 ny = 100
871 ny = 100
871
872
872 data = numpy.random.uniform(-50,50,(nx,ny))
873 data = numpy.random.uniform(-50,50,(nx,ny))
873
874
874 baseObj = ColorPlot()
875 baseObj = ColorPlot()
875 specObj = ColorPlot()
876 specObj = ColorPlot()
876 baseObj1 = ColorPlot()
877 baseObj1 = ColorPlot()
877 specObj1 = ColorPlot()
878 specObj1 = ColorPlot()
878
879
879 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True)
880 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True)
880 specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True)
881 specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True)
881
882
882 baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True)
883 baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True)
883 specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True)
884 specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True)
884
885
885 data = numpy.random.uniform(-50,50,(nx,ny))
886 data = numpy.random.uniform(-50,50,(nx,ny))
886
887
887 plplot.plbop()
888 plplot.plbop()
888 baseObj.plotData(data)
889 baseObj.plotData(data)
889
890
890 specObj.plotData(data)
891 specObj.plotData(data)
891
892
892 baseObj1.plotData(data)
893 baseObj1.plotData(data)
893
894
894 specObj1.plotData(data)
895 specObj1.plotData(data)
895
896
896 plplot.plflush()
897 plplot.plflush()
897
898
898 plplot.plspause(1)
899 plplot.plspause(1)
899 plplot.plend()
900 plplot.plend()
900 exit(0)
901 exit(0)
901
902
902
903
@@ -1,203 +1,204
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
8 import os, sys
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11 import plplot
11 import plplot
12
12
13 path = os.path.split(os.getcwd())[0]
13 path = os.path.split(os.getcwd())[0]
14 sys.path.append(path)
14 sys.path.append(path)
15
15
16 from Graphics.BaseGraph import *
16 from Graphics.BaseGraph import *
17 from Model.Spectra import Spectra
17 from Model.Spectra import Spectra
18
18
19 class Spectrum:
19 class Spectrum:
20
20
21 __isPlotConfig = False
21 __isPlotConfig = False
22
22
23 __isPlotIni = False
23 __isPlotIni = False
24
24
25 __xrange = None
25 __xrange = None
26
26
27 __yrange = None
27 __yrange = None
28
28
29 nGraphs = 0
29 nGraphs = 0
30
30
31 indexPlot = None
31 indexPlot = None
32
32
33 graphObjList = []
33 graphObjList = []
34
34
35 spectraObj = Spectra
35 spectraObj = Spectra
36
36
37 colorGraphObj = ColorPlot()
37 colorGraphObj = ColorPlot()
38 m_Spectra= Spectra()
38 m_Spectra= Spectra()
39
39
40
40
41 m_ColorPlot= ColorPlot()
41 m_ColorPlot= ColorPlot()
42
42
43
43
44
44
45
45
46
46
47 def __init__(self, Spectra, index=0):
47 def __init__(self, Spectra, index=0):
48
48
49 """
49 """
50
50
51 Inputs:
51 Inputs:
52
52
53 type: "power" ->> Potencia
53 type: "power" ->> Potencia
54 "iq" ->> Real + Imaginario
54 "iq" ->> Real + Imaginario
55 """
55 """
56
56
57 self.__isPlotConfig = False
57 self.__isPlotConfig = False
58
58
59 self.__isPlotIni = False
59 self.__isPlotIni = False
60
60
61 self.__xrange = None
61 self.__xrange = None
62
62
63 self.__yrange = None
63 self.__yrange = None
64
64
65 self.nGraphs = 0
65 self.nGraphs = 0
66
66
67 self.indexPlot = index
67 self.indexPlot = index
68
68
69 self.graphObjList = []
69 self.graphObjList = []
70
70
71 self.spectraObj = Spectra
71 self.spectraObj = Spectra
72
72
73
73
74 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
74 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
75
75
76 graphObj = ColorPlot()
76 graphObj = ColorPlot()
77 graphObj.setup(subpage,
77 graphObj.setup(subpage,
78 title,
78 title,
79 xlabel,
79 xlabel,
80 ylabel,
80 ylabel,
81 showColorbar=showColorbar,
81 showColorbar=showColorbar,
82 showPowerProfile=showPowerProfile,
82 showPowerProfile=showPowerProfile,
83 XAxisAsTime=XAxisAsTime)
83 XAxisAsTime=XAxisAsTime)
84
84
85 self.graphObjList.append(graphObj)
85 self.graphObjList.append(graphObj)
86
86
87
87
88 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
88 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
89
89
90 nChan = int(self.spectraObj.m_SystemHeader.numChannels)
90 nChan = int(self.spectraObj.m_SystemHeader.numChannels)
91 channels = range(nChan)
91 channels = range(nChan)
92
92
93 myXlabel = "Radial Velocity (m/s)"
93 myXlabel = "Radial Velocity (m/s)"
94 myYlabel = "Range (km)"
94 myYlabel = "Range (km)"
95
95
96 for i in channels:
96 for i in channels:
97 if titleList != None:
97 if titleList != None:
98 myTitle = titleList[i]
98 myTitle = titleList[i]
99 myXlabel = xlabelList[i]
99 myXlabel = xlabelList[i]
100 myYlabel = ylabelList[i]
100 myYlabel = ylabelList[i]
101
101
102 # if self.spectraObj.m_NoiseObj != None:
102 # if self.spectraObj.m_NoiseObj != None:
103 # noise = '%4.2fdB' %(self.spectraObj.m_NoiseObj[i])
103 # noise = '%4.2fdB' %(self.spectraObj.m_NoiseObj[i])
104 # else:
104 # else:
105 noise = '--'
105 noise = '--'
106
106
107 myTitle = "Channel: %d - Noise: %s" %(i, noise)
107 myTitle = "Channel: %d - Noise: %s" %(i, noise)
108
108
109 self.__addGraph(i+1,
109 self.__addGraph(i+1,
110 title=myTitle,
110 title=myTitle,
111 xlabel=myXlabel,
111 xlabel=myXlabel,
112 ylabel=myYlabel,
112 ylabel=myYlabel,
113 showColorbar=showColorbar,
113 showColorbar=showColorbar,
114 showPowerProfile=showPowerProfile,
114 showPowerProfile=showPowerProfile,
115 XAxisAsTime=XAxisAsTime)
115 XAxisAsTime=XAxisAsTime)
116
116
117 self.nGraphs = nChan
117 self.nGraphs = nChan
118 self.__isPlotConfig = True
118 self.__isPlotConfig = True
119
119
120 def iniPlot(self, winTitle=""):
120 def iniPlot(self, winTitle=""):
121
121
122 nx = int(numpy.sqrt(self.nGraphs)+1)
122 nx = int(numpy.sqrt(self.nGraphs)+1)
123 #ny = int(self.nGraphs/nx)
123 #ny = int(self.nGraphs/nx)
124
124
125 plplot.plsstrm(self.indexPlot)
125 plplot.plsstrm(self.indexPlot)
126 plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL)
126 plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL)
127 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
127 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
128 plplot.plsdev("xwin")
128 plplot.plsdev("xwin")
129 plplot.plscolbg(255,255,255)
129 plplot.plscolbg(255,255,255)
130 plplot.plscol0(1,0,0,0)
130 plplot.plscol0(1,0,0,0)
131 plplot.plinit()
131 plplot.plinit()
132 plplot.plspause(False)
132 plplot.plspause(False)
133 plplot.pladv(0)
133 plplot.pladv(0)
134 plplot.plssub(nx, nx)
134 plplot.plssub(nx, nx)
135
135
136 self.__nx = nx
136 self.__nx = nx
137 self.__ny = nx
137 self.__ny = nx
138 self.__isPlotIni = True
138 self.__isPlotIni = True
139
139
140
140
141 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False, winTitle="Spectra"):
141 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False, winTitle="Spectra"):
142
142
143 if not(self.__isPlotConfig):
143 if not(self.__isPlotConfig):
144 self.setup(titleList,
144 self.setup(titleList,
145 xlabelList,
145 xlabelList,
146 ylabelList,
146 ylabelList,
147 showColorbar,
147 showColorbar,
148 showPowerProfile,
148 showPowerProfile,
149 XAxisAsTime)
149 XAxisAsTime)
150
150
151 if not(self.__isPlotIni):
151 if not(self.__isPlotIni):
152 self.iniPlot(winTitle)
152 self.iniPlot(winTitle)
153
153
154 plplot.plsstrm(self.indexPlot)
154 plplot.plsstrm(self.indexPlot)
155
155
156 data = 10.*numpy.log10(self.spectraObj.data_spc)
156 data = 10.*numpy.log10(self.spectraObj.data_spc)
157
157 noise = 10.*numpy.log10(self.spectraObj.noise)
158 #data.shape = Channels x Heights x Profiles
158 #data.shape = Channels x Heights x Profiles
159 # data = numpy.transpose( data, (0,2,1) )
159 # data = numpy.transpose( data, (0,2,1) )
160 #data.shape = Channels x Profiles x Heights
160 #data.shape = Channels x Profiles x Heights
161
161
162 nChan, nX, nY = numpy.shape(data)
162 nChan, nX, nY = numpy.shape(data)
163
163
164 x = numpy.arange(nX)
164 x = numpy.arange(nX)
165 y = self.spectraObj.heightList
165 y = self.spectraObj.heightList
166
166
167 thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc)
167 thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc)
168 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
168 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
169
169
170 if xmin == None: xmin = x[0]
170 if xmin == None: xmin = x[0]
171 if xmax == None: xmax = x[-1]
171 if xmax == None: xmax = x[-1]
172 if ymin == None: ymin = y[0]
172 if ymin == None: ymin = y[0]
173 if ymax == None: ymax = y[-1]
173 if ymax == None: ymax = y[-1]
174 if zmin == None: zmin = numpy.nanmin(abs(data))
174 if zmin == None: zmin = numpy.nanmin(abs(data))
175 if zmax == None: zmax = numpy.nanmax(abs(data))
175 if zmax == None: zmax = numpy.nanmax(abs(data))
176
176
177 plplot.plbop()
177 plplot.plbop()
178
178
179 plplot.plssub(self.__nx, self.__ny)
179 plplot.plssub(self.__nx, self.__ny)
180 for i in range(self.nGraphs):
180 for i in range(self.nGraphs):
181 self.graphObjList[i].plotData(data[i,:,:],
181 self.graphObjList[i].plotData(data[i,:,:],
182 x,
182 x,
183 y,
183 y,
184 xmin=xmin,
184 xmin=xmin,
185 xmax=xmax,
185 xmax=xmax,
186 ymin=ymin,
186 ymin=ymin,
187 ymax=ymax,
187 ymax=ymax,
188 zmin=zmin,
188 zmin=zmin,
189 zmax=zmax)
189 zmax=zmax,
190 title = "Channel: %d - Noise: %.2f" %(i, noise[i]))
190
191
191 plplot.plssub(1,0)
192 plplot.plssub(1,0)
192 plplot.pladv(0)
193 plplot.pladv(0)
193 plplot.plvpor(0., 1., 0., 1.)
194 plplot.plvpor(0., 1., 0., 1.)
194 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
195 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
195 plplot.plflush()
196 plplot.plflush()
196 plplot.pleop()
197 plplot.pleop()
197
198
198 def end(self):
199 def end(self):
199 plplot.plend()
200 plplot.plend()
200
201
201
202
202 if __name__ == '__main__':
203 if __name__ == '__main__':
203 pass No newline at end of file
204 pass
@@ -1,1219 +1,1235
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 @version $Id$
6 @version $Id$
7 '''
7 '''
8
8
9 import os, sys
9 import os, sys
10 import glob
10 import glob
11 import time
11 import time
12 import numpy
12 import numpy
13 import fnmatch
13 import fnmatch
14 import time, datetime
14 import time, datetime
15
15
16 path = os.path.split(os.getcwd())[0]
16 path = os.path.split(os.getcwd())[0]
17 sys.path.append(path)
17 sys.path.append(path)
18
18
19 from Model.JROHeader import *
19 from Model.JROHeader import *
20 from Model.JROData import JROData
20 from Model.JROData import JROData
21
21
22 def checkForRealPath(path, year, doy, set, ext):
22 def checkForRealPath(path, year, doy, set, ext):
23 """
23 """
24 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
24 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
25 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
25 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
26 el path exacto de un determinado file.
26 el path exacto de un determinado file.
27
27
28 Example :
28 Example :
29 nombre correcto del file es .../.../D2009307/P2009307367.ext
29 nombre correcto del file es .../.../D2009307/P2009307367.ext
30
30
31 Entonces la funcion prueba con las siguientes combinaciones
31 Entonces la funcion prueba con las siguientes combinaciones
32 .../.../x2009307/y2009307367.ext
32 .../.../x2009307/y2009307367.ext
33 .../.../x2009307/Y2009307367.ext
33 .../.../x2009307/Y2009307367.ext
34 .../.../X2009307/y2009307367.ext
34 .../.../X2009307/y2009307367.ext
35 .../.../X2009307/Y2009307367.ext
35 .../.../X2009307/Y2009307367.ext
36 siendo para este caso, la ultima combinacion de letras, identica al file buscado
36 siendo para este caso, la ultima combinacion de letras, identica al file buscado
37
37
38 Return:
38 Return:
39 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
39 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
40 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
40 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
41 para el filename
41 para el filename
42 """
42 """
43 filepath = None
43 filepath = None
44 find_flag = False
44 find_flag = False
45 filename = None
45 filename = None
46
46
47 if ext.lower() == ".r": #voltage
47 if ext.lower() == ".r": #voltage
48 header1 = "dD"
48 header1 = "dD"
49 header2 = "dD"
49 header2 = "dD"
50 elif ext.lower() == ".pdata": #spectra
50 elif ext.lower() == ".pdata": #spectra
51 header1 = "dD"
51 header1 = "dD"
52 header2 = "pP"
52 header2 = "pP"
53 else:
53 else:
54 return None, filename
54 return None, filename
55
55
56 for dir in header1: #barrido por las dos combinaciones posibles de "D"
56 for dir in header1: #barrido por las dos combinaciones posibles de "D"
57 for fil in header2: #barrido por las dos combinaciones posibles de "D"
57 for fil in header2: #barrido por las dos combinaciones posibles de "D"
58 doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D)
58 doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D)
59 filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
59 filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
60 filepath = os.path.join( path, doypath, filename ) #formo el path completo
60 filepath = os.path.join( path, doypath, filename ) #formo el path completo
61 if os.path.exists( filepath ): #verifico que exista
61 if os.path.exists( filepath ): #verifico que exista
62 find_flag = True
62 find_flag = True
63 break
63 break
64 if find_flag:
64 if find_flag:
65 break
65 break
66
66
67 if not(find_flag):
67 if not(find_flag):
68 return None, filename
68 return None, filename
69
69
70 return filepath, filename
70 return filepath, filename
71
71
72
72
73 def isNumber(str):
73 def isNumber(str):
74 """
74 """
75 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
75 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
76
76
77 Excepciones:
77 Excepciones:
78 Si un determinado string no puede ser convertido a numero
78 Si un determinado string no puede ser convertido a numero
79 Input:
79 Input:
80 str, string al cual se le analiza para determinar si convertible a un numero o no
80 str, string al cual se le analiza para determinar si convertible a un numero o no
81
81
82 Return:
82 Return:
83 True : si el string es uno numerico
83 True : si el string es uno numerico
84 False : no es un string numerico
84 False : no es un string numerico
85 """
85 """
86 try:
86 try:
87 float( str )
87 float( str )
88 return True
88 return True
89 except:
89 except:
90 return False
90 return False
91
91
92
92
93 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
93 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
94 """
94 """
95 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
95 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
96
96
97 Inputs:
97 Inputs:
98 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
98 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
99
99
100 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
100 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
101 segundos contados desde 01/01/1970.
101 segundos contados desde 01/01/1970.
102 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
102 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
103 segundos contados desde 01/01/1970.
103 segundos contados desde 01/01/1970.
104
104
105 Return:
105 Return:
106 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
106 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
107 fecha especificado, de lo contrario retorna False.
107 fecha especificado, de lo contrario retorna False.
108
108
109 Excepciones:
109 Excepciones:
110 Si el archivo no existe o no puede ser abierto
110 Si el archivo no existe o no puede ser abierto
111 Si la cabecera no puede ser leida.
111 Si la cabecera no puede ser leida.
112
112
113 """
113 """
114 m_BasicHeader = BasicHeader()
114 m_BasicHeader = BasicHeader()
115
115
116 try:
116 try:
117 fp = open(filename,'rb')
117 fp = open(filename,'rb')
118 except:
118 except:
119 raise IOError, "The file %s can't be opened" %(filename)
119 raise IOError, "The file %s can't be opened" %(filename)
120
120
121 sts = m_BasicHeader.read(fp)
121 sts = m_BasicHeader.read(fp)
122 fp.close()
122 fp.close()
123
123
124 if not(sts):
124 if not(sts):
125 print "Skipping the file %s because it has not a valid header" %(filename)
125 print "Skipping the file %s because it has not a valid header" %(filename)
126 return 0
126 return 0
127
127
128 if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds > m_BasicHeader.utc)):
128 if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds > m_BasicHeader.utc)):
129 return 0
129 return 0
130
130
131 return 1
131 return 1
132
132
133
133
134 def getlastFileFromPath(path, ext):
134 def getlastFileFromPath(path, ext):
135 """
135 """
136 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
136 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
137 al final de la depuracion devuelve el ultimo file de la lista que quedo.
137 al final de la depuracion devuelve el ultimo file de la lista que quedo.
138
138
139 Input:
139 Input:
140 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
140 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
141 ext : extension de los files contenidos en una carpeta
141 ext : extension de los files contenidos en una carpeta
142
142
143 Return:
143 Return:
144 El ultimo file de una determinada carpeta, no se considera el path.
144 El ultimo file de una determinada carpeta, no se considera el path.
145 """
145 """
146 validFilelist = []
146 validFilelist = []
147 fileList = os.listdir(path)
147 fileList = os.listdir(path)
148
148
149 # 0 1234 567 89A BCDE
149 # 0 1234 567 89A BCDE
150 # H YYYY DDD SSS .ext
150 # H YYYY DDD SSS .ext
151
151
152 for file in fileList:
152 for file in fileList:
153 try:
153 try:
154 year = int(file[1:5])
154 year = int(file[1:5])
155 doy = int(file[5:8])
155 doy = int(file[5:8])
156
156
157 if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue
157 if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue
158 except:
158 except:
159 continue
159 continue
160
160
161 validFilelist.append(file)
161 validFilelist.append(file)
162
162
163 if validFilelist:
163 if validFilelist:
164 validFilelist = sorted( validFilelist, key=str.lower )
164 validFilelist = sorted( validFilelist, key=str.lower )
165 return validFilelist[-1]
165 return validFilelist[-1]
166
166
167 return None
167 return None
168
168
169 class JRODataIO:
169 class JRODataIO:
170
170
171 #speed of light
171 #speed of light
172 c = 3E8
172 c = 3E8
173
173
174 m_BasicHeader = BasicHeader()
174 m_BasicHeader = BasicHeader()
175
175
176 m_SystemHeader = SystemHeader()
176 m_SystemHeader = SystemHeader()
177
177
178 m_RadarControllerHeader = RadarControllerHeader()
178 m_RadarControllerHeader = RadarControllerHeader()
179
179
180 m_ProcessingHeader = ProcessingHeader()
180 m_ProcessingHeader = ProcessingHeader()
181
181
182 m_DataObj = None
182 dataOutObj = None
183
183
184 online = 0
184 online = 0
185
185
186 fp = None
186 fp = None
187
187
188 dataType = None
188 dataType = None
189
189
190 fileSizeByHeader = None
190 fileSizeByHeader = None
191
191
192 filenameList = []
192 filenameList = []
193
193
194 filename = None
194 filename = None
195
195
196 fileSize = None
196 fileSize = None
197
197
198 firstHeaderSize = 0
198 firstHeaderSize = 0
199
199
200 basicHeaderSize = 24
200 basicHeaderSize = 24
201
201
202 nTotalBlocks = 0
202 nTotalBlocks = 0
203
203
204 ippSeconds = 0
204 ippSeconds = 0
205
205
206 blocksize = 0
206 blocksize = 0
207
207
208 set = 0
208 set = 0
209
209
210 ext = None
210 ext = None
211
211
212 path = None
212 path = None
213
213
214 maxTimeStep = 30
214 maxTimeStep = 30
215
215
216
216
217 delay = 3 #seconds
217 delay = 3 #seconds
218
218
219 nTries = 3 #quantity tries
219 nTries = 3 #quantity tries
220
220
221 nFiles = 3 #number of files for searching
221 nFiles = 3 #number of files for searching
222
222
223
223
224 flagNoMoreFiles = 0
224 flagNoMoreFiles = 0
225
225
226 flagIsNewFile = 1
226 flagIsNewFile = 1
227
227
228 flagResetProcessing = 0
228 flagResetProcessing = 0
229
229
230 flagIsNewBlock = 0
230 flagIsNewBlock = 0
231
231
232 def __init__(self):
232 def __init__(self):
233 pass
233 pass
234
234
235 class JRODataReader(JRODataIO):
235 class JRODataReader(JRODataIO):
236
236
237 """
237 """
238 Esta clase es usada como la clase padre de las clases VoltageReader y SpectraReader.
238 Esta clase es usada como la clase padre de las clases VoltageReader y SpectraReader.
239 Contiene todos lo metodos necesarios para leer datos desde archivos en formato
239 Contiene todos lo metodos necesarios para leer datos desde archivos en formato
240 jicamarca o pdata (.r o .pdata). La lectura de los datos siempre se realiza por bloques. Los datos
240 jicamarca o pdata (.r o .pdata). La lectura de los datos siempre se realiza por bloques. Los datos
241 leidos son array de 3 dimensiones:
241 leidos son array de 3 dimensiones:
242
242
243 Para Voltajes - perfiles * alturas * canales
243 Para Voltajes - perfiles * alturas * canales
244
244
245 Para Spectra - paresCanalesIguales * alturas * perfiles (Self Spectra)
245 Para Spectra - paresCanalesIguales * alturas * perfiles (Self Spectra)
246 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
246 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
247 canales * alturas (DC Channels)
247 canales * alturas (DC Channels)
248
248
249 y son almacenados en su buffer respectivo.
249 y son almacenados en su buffer respectivo.
250
250
251 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
251 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
252 RadarControllerHeader y DataObj. Los tres primeros se usan para almacenar informacion de la
252 RadarControllerHeader y DataObj. Los tres primeros se usan para almacenar informacion de la
253 cabecera de datos (metadata), y el cuarto (DataObj) para obtener y almacenar los datos desde
253 cabecera de datos (metadata), y el cuarto (DataObj) para obtener y almacenar los datos desde
254 el buffer de datos cada vez que se ejecute el metodo "getData".
254 el buffer de datos cada vez que se ejecute el metodo "getData".
255 """
255 """
256
256
257 nReadBlocks = 0
257 nReadBlocks = 0
258
258
259 def __init__(self, m_DataObj=None):
259 def __init__(self, dataOutObj=None):
260
260
261 raise ValueError, "This class can't be instanced"
261 raise ValueError, "This class can't be instanced"
262
262
263
263
264 def hasNotDataInBuffer(self):
264 def hasNotDataInBuffer(self):
265
265
266 raise ValueError, "Not implemented"
266 raise ValueError, "Not implemented"
267
267
268 def getBlockDimension(self):
268 def getBlockDimension(self):
269
269
270 raise ValueError, "No implemented"
270 raise ValueError, "No implemented"
271
271
272 def readBlock(self):
272 def readBlock(self):
273
273
274 self.nTotalBlocks += 1
274 self.nTotalBlocks += 1
275 self.nReadBlocks += 1
275 self.nReadBlocks += 1
276
276
277 raise ValueError, "This method has not been implemented"
277 raise ValueError, "This method has not been implemented"
278
278
279 def getData( self ):
279 def getData( self ):
280
280
281 raise ValueError, "This method has not been implemented"
281 raise ValueError, "This method has not been implemented"
282
282
283 def createObjByDefault(self):
284 """
285 Los objetos creados por defecto por cada clase (Voltaje o Espectro) difieren en el tipo
286 raise ValueError, "This method has not been implemented
287 """
288 raise ValueError, "This method has not been implemented"
289
290 def setup(self, dataOutObj=None, path=None, startDateTime=None, endDateTime=None, set=0, expLabel = "", ext = None, online = 0):
291 """
292 setup configura los parametros de lectura de la clase DataReader.
293
294 Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos
295 que coincidan con los parametros especificados; esta lista de archivos son almacenados en
296 self.filenameList.
297
298 Input:
299 path : Directorios donde se ubican los datos a leer. Dentro de este
300 directorio deberia de estar subdirectorios de la forma:
301
302 path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext]
303
304 startDateTime : Fecha inicial. Rechaza todos los archivos donde
305 file end time < startDatetime (obejto datetime.datetime)
306
307 endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde
308 file end time < startDatetime (obejto datetime.datetime)
309
310 set : Set del primer archivo a leer. Por defecto None
311
312 expLabel : Nombre del subdirectorio de datos. Por defecto ""
313
314 ext : Extension de los archivos a leer. Por defecto .r
315
316 online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas
317
318 Return:
319 0 : Si no encuentra files que cumplan con las condiciones dadas
320 1 : Si encuentra files que cumplan con las condiciones dadas
321
322 Affected:
323 self.startUTCSeconds
324 self.endUTCSeconds
325 self.startYear
326 self.endYear
327 self.startDoy
328 self.endDoy
329 self.pathList
330 self.filenameList
331 self.online
332 """
333 if path == None:
334 raise ValueError, "The path is not valid"
335
336 if ext == None:
337 ext = self.ext
338
339 if dataOutObj == None:
340 dataOutObj = self.createObjByDefault()
341
342 self.dataOutObj = dataOutObj
343
344 if online:
345 print "Searching files ..."
346 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
347
348 if not(doypath):
349 for nTries in range( self.nTries ):
350 print '\tWaiting %0.2f sec for valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
351 time.sleep( self.delay )
352 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
353 if doypath:
354 break
355
356 if not(doypath):
357 print "There 'isn't valied files in %s" % path
358 return None
359
360 self.year = year
361 self.doy = doy
362 self.set = set - 1
363 self.path = path
364
365 else: # offline
366 pathList, filenameList = self.__searchFilesOffLine(path, startDateTime, endDateTime, set, expLabel, ext)
367 if not(pathList):
368 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
369 return None
370
371 self.fileIndex = -1
372 self.pathList = pathList
373 self.filenameList = filenameList
374
375 self.online = online
376 self.ext = ext
377
378 ext = ext.lower()
379
380 if not( self.setNextFile() ):
381 if (startDateTime != None) and (endDateTime != None):
382 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
383 elif startDateTime != None:
384 print "No files in : %s" % startDateTime.ctime()
385 else:
386 print "No files"
387 return None
388
389 if startDateTime != None:
390 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
391 self.startYear = startDateTime.timetuple().tm_year
392 self.startDoy = startDateTime.timetuple().tm_yday
393
394 if endDateTime != None:
395 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
396 self.endYear = endDateTime.timetuple().tm_year
397 self.endDoy = endDateTime.timetuple().tm_yday
398 #call fillHeaderValues() - to Data Object
399
400 self.updateDataHeader()
401
402 return self.dataOutObj
283
403
284 def __rdSystemHeader(self, fp=None):
404 def __rdSystemHeader(self, fp=None):
285
405
286 if fp == None:
406 if fp == None:
287 fp = self.fp
407 fp = self.fp
288
408
289 self.m_SystemHeader.read(fp)
409 self.m_SystemHeader.read(fp)
290
410
291
411
292 def __rdRadarControllerHeader(self, fp=None):
412 def __rdRadarControllerHeader(self, fp=None):
293 if fp == None:
413 if fp == None:
294 fp = self.fp
414 fp = self.fp
295
415
296 self.m_RadarControllerHeader.read(fp)
416 self.m_RadarControllerHeader.read(fp)
297
417
298
418
299 def __rdProcessingHeader(self, fp=None):
419 def __rdProcessingHeader(self, fp=None):
300 if fp == None:
420 if fp == None:
301 fp = self.fp
421 fp = self.fp
302
422
303 self.m_ProcessingHeader.read(fp)
423 self.m_ProcessingHeader.read(fp)
304
424
305
425
306 def __rdBasicHeader(self, fp=None):
426 def __rdBasicHeader(self, fp=None):
307
427
308 if fp == None:
428 if fp == None:
309 fp = self.fp
429 fp = self.fp
310
430
311 self.m_BasicHeader.read(fp)
431 self.m_BasicHeader.read(fp)
312
432
313 def __readFirstHeader(self):
433 def __readFirstHeader(self):
314 """
434 """
315 Lectura del First Header, es decir el Basic Header y el Long Header
435 Lectura del First Header, es decir el Basic Header y el Long Header
316
436
317 Affected:
437 Affected:
318 self.m_BasicHeader
438 self.m_BasicHeader
319 self.m_SystemHeader
439 self.m_SystemHeader
320 self.m_RadarControllerHeader
440 self.m_RadarControllerHeader
321 self.m_ProcessingHeader
441 self.m_ProcessingHeader
322 self.firstHeaderSize
442 self.firstHeaderSize
323 self.dataType
443 self.dataType
324 self.fileSizeByHeader
444 self.fileSizeByHeader
325 self.ippSeconds
445 self.ippSeconds
326
446
327 Return:
447 Return:
328 None
448 None
329 """
449 """
330 self.__rdBasicHeader()
450 self.__rdBasicHeader()
331 self.__rdSystemHeader()
451 self.__rdSystemHeader()
332 self.__rdRadarControllerHeader()
452 self.__rdRadarControllerHeader()
333 self.__rdProcessingHeader()
453 self.__rdProcessingHeader()
334 self.firstHeaderSize = self.m_BasicHeader.size
454 self.firstHeaderSize = self.m_BasicHeader.size
335
455
336 datatype = int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
456 datatype = int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
337 if datatype == 0:
457 if datatype == 0:
338 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
458 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
339
459
340 elif datatype == 1:
460 elif datatype == 1:
341 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
461 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
342
462
343 elif datatype == 2:
463 elif datatype == 2:
344 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
464 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
345
465
346 elif datatype == 3:
466 elif datatype == 3:
347 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
467 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
348
468
349 elif datatype == 4:
469 elif datatype == 4:
350 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
470 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
351
471
352 elif datatype == 5:
472 elif datatype == 5:
353 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
473 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
354
474
355 else:
475 else:
356 raise ValueError, 'Data type was not defined'
476 raise ValueError, 'Data type was not defined'
357
477
358 self.dataType = datatype_str
478 self.dataType = datatype_str
359 self.ippSeconds = 2 * 1000 * self.m_RadarControllerHeader.ipp / self.c
479 self.ippSeconds = 2 * 1000 * self.m_RadarControllerHeader.ipp / self.c
360
480
361 self.fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1)
481 self.fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1)
362
482 self.dataOutObj.channelList = numpy.arange(self.m_SystemHeader.numChannels)
483 self.dataOutObj.channelIndexList = numpy.arange(self.m_SystemHeader.numChannels)
484
363 self.getBlockDimension()
485 self.getBlockDimension()
364
486
365
487
366 def __setNewBlock(self):
488 def __setNewBlock(self):
367 """
489 """
368 Lee el Basic Header y posiciona le file pointer en la posicion inicial del bloque a leer
490 Lee el Basic Header y posiciona le file pointer en la posicion inicial del bloque a leer
369
491
370 Affected:
492 Affected:
371 self.m_BasicHeader
493 self.m_BasicHeader
372 self.flagNoContinuousBlock
494 self.flagNoContinuousBlock
373 self.ns
495 self.ns
374
496
375 Return:
497 Return:
376 0 : Si el file no tiene un Basic Header que pueda ser leido
498 0 : Si el file no tiene un Basic Header que pueda ser leido
377 1 : Si se pudo leer el Basic Header
499 1 : Si se pudo leer el Basic Header
378 """
500 """
379 if self.fp == None:
501 if self.fp == None:
380 return 0
502 return 0
381
503
382 if self.flagIsNewFile:
504 if self.flagIsNewFile:
383 return 1
505 return 1
384
506
385 self.lastUTTime = self.m_BasicHeader.utc
507 self.lastUTTime = self.m_BasicHeader.utc
386
508
387 currentSize = self.fileSize - self.fp.tell()
509 currentSize = self.fileSize - self.fp.tell()
388 neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize
510 neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize
389
511
390 #If there is enough data setting new data block
512 #If there is enough data setting new data block
391 if ( currentSize >= neededSize ):
513 if ( currentSize >= neededSize ):
392 self.__rdBasicHeader()
514 self.__rdBasicHeader()
393 return 1
515 return 1
394
516
395 #si es OnLine y ademas aun no se han leido un bloque completo entonces se espera por uno valido
517 #si es OnLine y ademas aun no se han leido un bloque completo entonces se espera por uno valido
396 if self.online and (self.nReadBlocks < self.m_ProcessingHeader.dataBlocksPerFile):
518 if self.online and (self.nReadBlocks < self.m_ProcessingHeader.dataBlocksPerFile):
397
519
398 fpointer = self.fp.tell()
520 fpointer = self.fp.tell()
399
521
400 for nTries in range( self.nTries ):
522 for nTries in range( self.nTries ):
401 #self.fp.close()
523 #self.fp.close()
402
524
403 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
525 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
404 time.sleep( self.delay )
526 time.sleep( self.delay )
405
527
406 #self.fp = open( self.filename, 'rb' )
528 #self.fp = open( self.filename, 'rb' )
407 #self.fp.seek( fpointer )
529 #self.fp.seek( fpointer )
408
530
409 self.fileSize = os.path.getsize( self.filename )
531 self.fileSize = os.path.getsize( self.filename )
410 currentSize = self.fileSize - fpointer
532 currentSize = self.fileSize - fpointer
411
533
412 if ( currentSize >= neededSize ):
534 if ( currentSize >= neededSize ):
413 self.__rdBasicHeader()
535 self.__rdBasicHeader()
414 return 1
536 return 1
415
537
416 #Setting new file
538 #Setting new file
417 if not( self.setNextFile() ):
539 if not( self.setNextFile() ):
418 return 0
540 return 0
419
541
420 deltaTime = self.m_BasicHeader.utc - self.lastUTTime # check this
542 deltaTime = self.m_BasicHeader.utc - self.lastUTTime # check this
421
543
422 self.flagResetProcessing = 0
544 self.flagResetProcessing = 0
423
545
424 if deltaTime > self.maxTimeStep:
546 if deltaTime > self.maxTimeStep:
425 self.flagResetProcessing = 1
547 self.flagResetProcessing = 1
426
548
427 return 1
549 return 1
428
550
429 def readNextBlock(self):
551 def readNextBlock(self):
430 """
552 """
431 Establece un nuevo bloque de datos a leer y los lee, si es que no existiese
553 Establece un nuevo bloque de datos a leer y los lee, si es que no existiese
432 mas bloques disponibles en el archivo actual salta al siguiente.
554 mas bloques disponibles en el archivo actual salta al siguiente.
433
555
434 Affected:
556 Affected:
435 self.lastUTTime
557 self.lastUTTime
436
558
437 Return: None
559 Return: None
438 """
560 """
439
561
440 if not(self.__setNewBlock()):
562 if not(self.__setNewBlock()):
441 return 0
563 return 0
442
564
443 if not(self.readBlock()):
565 if not(self.readBlock()):
444 return 0
566 return 0
445
567
446 return 1
568 return 1
447
569
448 def __setNextFileOnline(self):
570 def __setNextFileOnline(self):
449 """
571 """
450 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
572 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
451 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
573 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
452 siguientes.
574 siguientes.
453
575
454 Affected:
576 Affected:
455 self.flagIsNewFile
577 self.flagIsNewFile
456 self.filename
578 self.filename
457 self.fileSize
579 self.fileSize
458 self.fp
580 self.fp
459 self.set
581 self.set
460 self.flagNoMoreFiles
582 self.flagNoMoreFiles
461
583
462 Return:
584 Return:
463 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
585 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
464 1 : si el file fue abierto con exito y esta listo a ser leido
586 1 : si el file fue abierto con exito y esta listo a ser leido
465
587
466 Excepciones:
588 Excepciones:
467 Si un determinado file no puede ser abierto
589 Si un determinado file no puede ser abierto
468 """
590 """
469 nFiles = 0
591 nFiles = 0
470 fileOk_flag = False
592 fileOk_flag = False
471 firstTime_flag = True
593 firstTime_flag = True
472
594
473 self.set += 1
595 self.set += 1
474
596
475 #busca el 1er file disponible
597 #busca el 1er file disponible
476 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
598 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
477 if file:
599 if file:
478 if self.__verifyFile(file, False):
600 if self.__verifyFile(file, False):
479 fileOk_flag = True
601 fileOk_flag = True
480
602
481 #si no encuentra un file entonces espera y vuelve a buscar
603 #si no encuentra un file entonces espera y vuelve a buscar
482 if not(fileOk_flag):
604 if not(fileOk_flag):
483 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
605 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
484
606
485 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
607 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
486 tries = self.nTries
608 tries = self.nTries
487 else:
609 else:
488 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
610 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
489
611
490 for nTries in range( tries ):
612 for nTries in range( tries ):
491 if firstTime_flag:
613 if firstTime_flag:
492 print "\tWaiting %0.2f sec for new \"%s\" file, try %03d ..." % ( self.delay, filename, nTries+1 )
614 print "\tWaiting %0.2f sec for new \"%s\" file, try %03d ..." % ( self.delay, filename, nTries+1 )
493 time.sleep( self.delay )
615 time.sleep( self.delay )
494 else:
616 else:
495 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
617 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
496
618
497 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
619 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
498 if file:
620 if file:
499 if self.__verifyFile(file):
621 if self.__verifyFile(file):
500 fileOk_flag = True
622 fileOk_flag = True
501 break
623 break
502
624
503 if fileOk_flag:
625 if fileOk_flag:
504 break
626 break
505
627
506 firstTime_flag = False
628 firstTime_flag = False
507
629
508 print "\tSkipping the file \"%s\" due to this file doesn't exist yet" % filename
630 print "\tSkipping the file \"%s\" due to this file doesn't exist yet" % filename
509 self.set += 1
631 self.set += 1
510
632
511 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
633 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
512 self.set = 0
634 self.set = 0
513 self.doy += 1
635 self.doy += 1
514
636
515 if fileOk_flag:
637 if fileOk_flag:
516 self.fileSize = os.path.getsize( file )
638 self.fileSize = os.path.getsize( file )
517 self.filename = file
639 self.filename = file
518 self.flagIsNewFile = 1
640 self.flagIsNewFile = 1
519 if self.fp != None: self.fp.close()
641 if self.fp != None: self.fp.close()
520 self.fp = open(file)
642 self.fp = open(file)
521 self.flagNoMoreFiles = 0
643 self.flagNoMoreFiles = 0
522 print 'Setting the file: %s' % file
644 print 'Setting the file: %s' % file
523 else:
645 else:
524 self.fileSize = 0
646 self.fileSize = 0
525 self.filename = None
647 self.filename = None
526 self.flagIsNewFile = 0
648 self.flagIsNewFile = 0
527 self.fp = None
649 self.fp = None
528 self.flagNoMoreFiles = 1
650 self.flagNoMoreFiles = 1
529 print 'No more Files'
651 print 'No more Files'
530
652
531 return fileOk_flag
653 return fileOk_flag
532
654
533
655
534 def __setNextFileOffline(self):
656 def __setNextFileOffline(self):
535 """
657 """
536 Busca el siguiente file dentro de un folder que tenga suficiente data para ser leida
658 Busca el siguiente file dentro de un folder que tenga suficiente data para ser leida
537
659
538 Affected:
660 Affected:
539 self.flagIsNewFile
661 self.flagIsNewFile
540 self.fileIndex
662 self.fileIndex
541 self.filename
663 self.filename
542 self.fileSize
664 self.fileSize
543 self.fp
665 self.fp
544
666
545 Return:
667 Return:
546 0 : si un determinado file no puede ser abierto
668 0 : si un determinado file no puede ser abierto
547 1 : si el file fue abierto con exito
669 1 : si el file fue abierto con exito
548
670
549 Excepciones:
671 Excepciones:
550 Si un determinado file no puede ser abierto
672 Si un determinado file no puede ser abierto
551 """
673 """
552 idFile = self.fileIndex
674 idFile = self.fileIndex
553
675
554 while(True):
676 while(True):
555
677
556 idFile += 1
678 idFile += 1
557
679
558 if not(idFile < len(self.filenameList)):
680 if not(idFile < len(self.filenameList)):
559 self.flagNoMoreFiles = 1
681 self.flagNoMoreFiles = 1
560 print 'No more Files'
682 print 'No more Files'
561 return 0
683 return 0
562
684
563 filename = self.filenameList[idFile]
685 filename = self.filenameList[idFile]
564
686
565 if not(self.__verifyFile(filename)):
687 if not(self.__verifyFile(filename)):
566 continue
688 continue
567
689
568 fileSize = os.path.getsize(filename)
690 fileSize = os.path.getsize(filename)
569 fp = open(filename,'rb')
691 fp = open(filename,'rb')
570 break
692 break
571
693
572 self.flagIsNewFile = 1
694 self.flagIsNewFile = 1
573 self.fileIndex = idFile
695 self.fileIndex = idFile
574 self.filename = filename
696 self.filename = filename
575 self.fileSize = fileSize
697 self.fileSize = fileSize
576 self.fp = fp
698 self.fp = fp
577
699
578 print 'Setting the file: %s'%self.filename
700 print 'Setting the file: %s'%self.filename
579
701
580 return 1
702 return 1
581
703
582
704
583 def setNextFile(self):
705 def setNextFile(self):
584 """
706 """
585 Determina el siguiente file a leer y si hay uno disponible lee el First Header
707 Determina el siguiente file a leer y si hay uno disponible lee el First Header
586
708
587 Affected:
709 Affected:
588 self.m_BasicHeader
710 self.m_BasicHeader
589 self.m_SystemHeader
711 self.m_SystemHeader
590 self.m_RadarControllerHeader
712 self.m_RadarControllerHeader
591 self.m_ProcessingHeader
713 self.m_ProcessingHeader
592 self.firstHeaderSize
714 self.firstHeaderSize
593
715
594 Return:
716 Return:
595 0 : Si no hay files disponibles
717 0 : Si no hay files disponibles
596 1 : Si hay mas files disponibles
718 1 : Si hay mas files disponibles
597 """
719 """
598 if self.fp != None:
720 if self.fp != None:
599 self.fp.close()
721 self.fp.close()
600
722
601 if self.online:
723 if self.online:
602 newFile = self.__setNextFileOnline()
724 newFile = self.__setNextFileOnline()
603 else:
725 else:
604 newFile = self.__setNextFileOffline()
726 newFile = self.__setNextFileOffline()
605
727
606 if not(newFile):
728 if not(newFile):
607 return 0
729 return 0
608
730
609 self.__readFirstHeader()
731 self.__readFirstHeader()
610 self.nReadBlocks = 0
732 self.nReadBlocks = 0
611 return 1
733 return 1
612
734
613 def __searchFilesOnLine(self, path, startDateTime=None, endDateTime=None, expLabel = "", ext = None):
735 def __searchFilesOnLine(self, path, startDateTime=None, endDateTime=None, expLabel = "", ext = None):
614 """
736 """
615 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
737 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
616 devuelve el archivo encontrado ademas de otros datos.
738 devuelve el archivo encontrado ademas de otros datos.
617
739
618 Input:
740 Input:
619 path : carpeta donde estan contenidos los files que contiene data
741 path : carpeta donde estan contenidos los files que contiene data
620 startDateTime : punto especifico en el tiempo del cual se requiere la data
742 startDateTime : punto especifico en el tiempo del cual se requiere la data
621 ext : extension de los files
743 ext : extension de los files
622
744
623 Return:
745 Return:
624 year : el anho
746 year : el anho
625 doy : el numero de dia del anho
747 doy : el numero de dia del anho
626 set : el set del archivo
748 set : el set del archivo
627 filename : el ultimo file de una determinada carpeta
749 filename : el ultimo file de una determinada carpeta
628 directory : eL directorio donde esta el file encontrado
750 directory : eL directorio donde esta el file encontrado
629 """
751 """
630 dirList = []
752 dirList = []
631 pathList = []
753 pathList = []
632 directory = None
754 directory = None
633
755
634 for thisPath in os.listdir(path):
756 for thisPath in os.listdir(path):
635 if os.path.isdir(os.path.join(path,thisPath)):
757 if os.path.isdir(os.path.join(path,thisPath)):
636 dirList.append(thisPath)
758 dirList.append(thisPath)
637
759
638 if not(dirList):
760 if not(dirList):
639 return None, None, None, None, None
761 return None, None, None, None, None
640
762
641 dirList = sorted( dirList, key=str.lower )
763 dirList = sorted( dirList, key=str.lower )
642
764
643 if startDateTime:
765 if startDateTime:
644 thisDateTime = startDateTime
766 thisDateTime = startDateTime
645 if endDateTime == None: endDateTime = startDateTime
767 if endDateTime == None: endDateTime = startDateTime
646
768
647 while(thisDateTime <= endDateTime):
769 while(thisDateTime <= endDateTime):
648 year = thisDateTime.timetuple().tm_year
770 year = thisDateTime.timetuple().tm_year
649 doy = thisDateTime.timetuple().tm_yday
771 doy = thisDateTime.timetuple().tm_yday
650
772
651 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
773 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
652 if len(match) == 0:
774 if len(match) == 0:
653 thisDateTime += datetime.timedelta(1)
775 thisDateTime += datetime.timedelta(1)
654 continue
776 continue
655
777
656 pathList.append(os.path.join(path,match[0], expLabel))
778 pathList.append(os.path.join(path,match[0], expLabel))
657 thisDateTime += datetime.timedelta(1)
779 thisDateTime += datetime.timedelta(1)
658
780
659 if not(pathList):
781 if not(pathList):
660 print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
782 print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
661 return None, None, None, None, None
783 return None, None, None, None, None
662
784
663 directory = pathList[0]
785 directory = pathList[0]
664
786
665 else:
787 else:
666 directory = dirList[-1]
788 directory = dirList[-1]
667 directory = os.path.join(path,directory)
789 directory = os.path.join(path,directory)
668
790
669 filename = getlastFileFromPath(directory, ext)
791 filename = getlastFileFromPath(directory, ext)
670
792
671 if not(filename):
793 if not(filename):
672 return None, None, None, None, None
794 return None, None, None, None, None
673
795
674 if not(self.__verifyFile(os.path.join(directory, filename))):
796 if not(self.__verifyFile(os.path.join(directory, filename))):
675 return None, None, None, None, None
797 return None, None, None, None, None
676
798
677 year = int( filename[1:5] )
799 year = int( filename[1:5] )
678 doy = int( filename[5:8] )
800 doy = int( filename[5:8] )
679 set = int( filename[8:11] )
801 set = int( filename[8:11] )
680
802
681 return directory, filename, year, doy, set
803 return directory, filename, year, doy, set
682
804
683
805
684 def __searchFilesOffLine(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"):
806 def __searchFilesOffLine(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"):
685 """
807 """
686 Realiza una busqueda de los archivos que coincidan con los parametros
808 Realiza una busqueda de los archivos que coincidan con los parametros
687 especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda
809 especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda
688 correcta la estructura de directorios debe ser la siguiente:
810 correcta la estructura de directorios debe ser la siguiente:
689
811
690 ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext
812 ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext
691
813
692 [yyyy]: anio
814 [yyyy]: anio
693 [ddd] : dia del anio
815 [ddd] : dia del anio
694 [sss] : set del archivo
816 [sss] : set del archivo
695
817
696 Inputs:
818 Inputs:
697 path : Directorio de datos donde se realizara la busqueda. Todos los
819 path : Directorio de datos donde se realizara la busqueda. Todos los
698 ficheros que concidan con el criterio de busqueda seran
820 ficheros que concidan con el criterio de busqueda seran
699 almacenados en una lista y luego retornados.
821 almacenados en una lista y luego retornados.
700 startDateTime : Fecha inicial. Rechaza todos los archivos donde
822 startDateTime : Fecha inicial. Rechaza todos los archivos donde
701 file end time < startDateTime (obejto datetime.datetime)
823 file end time < startDateTime (obejto datetime.datetime)
702
824
703 endDateTime : Fecha final. Rechaza todos los archivos donde
825 endDateTime : Fecha final. Rechaza todos los archivos donde
704 file start time > endDateTime (obejto datetime.datetime)
826 file start time > endDateTime (obejto datetime.datetime)
705
827
706 set : Set del primer archivo a leer. Por defecto None
828 set : Set del primer archivo a leer. Por defecto None
707
829
708 expLabel : Nombre del subdirectorio de datos. Por defecto ""
830 expLabel : Nombre del subdirectorio de datos. Por defecto ""
709
831
710 ext : Extension de los archivos a leer. Por defecto .r
832 ext : Extension de los archivos a leer. Por defecto .r
711
833
712 Return:
834 Return:
713
835
714 (pathList, filenameList)
836 (pathList, filenameList)
715
837
716 pathList : Lista de directorios donde se encontraron archivos dentro
838 pathList : Lista de directorios donde se encontraron archivos dentro
717 de los parametros especificados
839 de los parametros especificados
718 filenameList : Lista de archivos (ruta completa) que coincidieron con los
840 filenameList : Lista de archivos (ruta completa) que coincidieron con los
719 parametros especificados.
841 parametros especificados.
720
842
721 Variables afectadas:
843 Variables afectadas:
722
844
723 self.filenameList: Lista de archivos (ruta completa) que la clase utiliza
845 self.filenameList: Lista de archivos (ruta completa) que la clase utiliza
724 como fuente para leer los bloque de datos, si se termina
846 como fuente para leer los bloque de datos, si se termina
725 de leer todos los bloques de datos de un determinado
847 de leer todos los bloques de datos de un determinado
726 archivo se pasa al siguiente archivo de la lista.
848 archivo se pasa al siguiente archivo de la lista.
727
849
728 Excepciones:
850 Excepciones:
729
851
730 """
852 """
731
853
732 print "Searching files ..."
854 print "Searching files ..."
733
855
734 dirList = []
856 dirList = []
735 for thisPath in os.listdir(path):
857 for thisPath in os.listdir(path):
736 if os.path.isdir(os.path.join(path,thisPath)):
858 if os.path.isdir(os.path.join(path,thisPath)):
737 dirList.append(thisPath)
859 dirList.append(thisPath)
738
860
739 if not(dirList):
861 if not(dirList):
740 return None, None
862 return None, None
741
863
742 pathList = []
864 pathList = []
743
865
744 thisDateTime = startDateTime
866 thisDateTime = startDateTime
745
867
746 while(thisDateTime <= endDateTime):
868 while(thisDateTime <= endDateTime):
747 year = thisDateTime.timetuple().tm_year
869 year = thisDateTime.timetuple().tm_year
748 doy = thisDateTime.timetuple().tm_yday
870 doy = thisDateTime.timetuple().tm_yday
749
871
750 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
872 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
751 if len(match) == 0:
873 if len(match) == 0:
752 thisDateTime += datetime.timedelta(1)
874 thisDateTime += datetime.timedelta(1)
753 continue
875 continue
754
876
755 pathList.append(os.path.join(path,match[0],expLabel))
877 pathList.append(os.path.join(path,match[0],expLabel))
756 thisDateTime += datetime.timedelta(1)
878 thisDateTime += datetime.timedelta(1)
757
879
758 startUtSeconds = time.mktime(startDateTime.timetuple())
880 startUtSeconds = time.mktime(startDateTime.timetuple())
759 endUtSeconds = time.mktime(endDateTime.timetuple())
881 endUtSeconds = time.mktime(endDateTime.timetuple())
760
882
761 filenameList = []
883 filenameList = []
762 for thisPath in pathList:
884 for thisPath in pathList:
763 fileList = glob.glob1(thisPath, "*%s" %ext)
885 fileList = glob.glob1(thisPath, "*%s" %ext)
764 fileList.sort()
886 fileList.sort()
765 for file in fileList:
887 for file in fileList:
766 filename = os.path.join(thisPath,file)
888 filename = os.path.join(thisPath,file)
767 if isThisFileinRange(filename, startUtSeconds, endUtSeconds):
889 if isThisFileinRange(filename, startUtSeconds, endUtSeconds):
768 filenameList.append(filename)
890 filenameList.append(filename)
769
891
770 if not(filenameList):
892 if not(filenameList):
771 return None, None
893 return None, None
772
894
773 self.filenameList = filenameList
895 self.filenameList = filenameList
774
896
775 return pathList, filenameList
897 return pathList, filenameList
776
898
777 def __verifyFile(self, filename, msgFlag=True):
899 def __verifyFile(self, filename, msgFlag=True):
778 """
900 """
779 Verifica que el filename tenga data valida, para ello leo el FirstHeader del file
901 Verifica que el filename tenga data valida, para ello leo el FirstHeader del file
780
902
781 Return:
903 Return:
782 0 : file no valido para ser leido
904 0 : file no valido para ser leido
783 1 : file valido para ser leido
905 1 : file valido para ser leido
784 """
906 """
785 msg = None
907 msg = None
786
908
787 try:
909 try:
788 fp = open( filename,'rb' ) #lectura binaria
910 fp = open( filename,'rb' ) #lectura binaria
789 currentPosition = fp.tell()
911 currentPosition = fp.tell()
790 except:
912 except:
791 if msgFlag:
913 if msgFlag:
792 print "The file %s can't be opened" % (filename)
914 print "The file %s can't be opened" % (filename)
793 return False
915 return False
794
916
795 neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize
917 neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize
796
918
797 if neededSize == 0:
919 if neededSize == 0:
798
920
799 m_BasicHeader = BasicHeader()
921 m_BasicHeader = BasicHeader()
800 m_SystemHeader = SystemHeader()
922 m_SystemHeader = SystemHeader()
801 m_RadarControllerHeader = RadarControllerHeader()
923 m_RadarControllerHeader = RadarControllerHeader()
802 m_ProcessingHeader = ProcessingHeader()
924 m_ProcessingHeader = ProcessingHeader()
803
925
804 try:
926 try:
805 if not( m_BasicHeader.read(fp) ): raise ValueError
927 if not( m_BasicHeader.read(fp) ): raise ValueError
806 if not( m_SystemHeader.read(fp) ): raise ValueError
928 if not( m_SystemHeader.read(fp) ): raise ValueError
807 if not( m_RadarControllerHeader.read(fp) ): raise ValueError
929 if not( m_RadarControllerHeader.read(fp) ): raise ValueError
808 if not( m_ProcessingHeader.read(fp) ): raise ValueError
930 if not( m_ProcessingHeader.read(fp) ): raise ValueError
809 data_type = int(numpy.log2((m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
931 data_type = int(numpy.log2((m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
810
932
811 neededSize = m_ProcessingHeader.blockSize + m_BasicHeader.size
933 neededSize = m_ProcessingHeader.blockSize + m_BasicHeader.size
812
934
813 except:
935 except:
814 if msgFlag:
936 if msgFlag:
815 print "\tThe file %s is empty or it hasn't enough data" % filename
937 print "\tThe file %s is empty or it hasn't enough data" % filename
816
938
817 fp.close()
939 fp.close()
818 return False
940 return False
819
941
820 else:
942 else:
821 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
943 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
822
944
823 fp.close()
945 fp.close()
824 fileSize = os.path.getsize(filename)
946 fileSize = os.path.getsize(filename)
825 currentSize = fileSize - currentPosition
947 currentSize = fileSize - currentPosition
826
948
827 if currentSize < neededSize:
949 if currentSize < neededSize:
828 if msgFlag and (msg != None):
950 if msgFlag and (msg != None):
829 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
951 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
830 return False
952 return False
831
953
832 return True
954 return True
833
955
834 def updateDataHeader(self):
956 def updateDataHeader(self):
835
957
836 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
958 self.dataOutObj.m_BasicHeader = self.m_BasicHeader.copy()
837 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
959 self.dataOutObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
838 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
960 self.dataOutObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
839 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
961 self.dataOutObj.m_SystemHeader = self.m_SystemHeader.copy()
840
841 self.m_DataObj.dataType = self.dataType
842 self.m_DataObj.updateObjFromHeader()
843
844 def setup(self, path, startDateTime=None, endDateTime=None, set=0, expLabel = "", ext = None, online = 0):
845 """
846 setup configura los parametros de lectura de la clase DataReader.
847
848 Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos
849 que coincidan con los parametros especificados; esta lista de archivos son almacenados en
850 self.filenameList.
851
852 Input:
853 path : Directorios donde se ubican los datos a leer. Dentro de este
854 directorio deberia de estar subdirectorios de la forma:
855
856 path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext]
857
858 startDateTime : Fecha inicial. Rechaza todos los archivos donde
859 file end time < startDatetime (obejto datetime.datetime)
860
861 endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde
862 file end time < startDatetime (obejto datetime.datetime)
863
864 set : Set del primer archivo a leer. Por defecto None
865
866 expLabel : Nombre del subdirectorio de datos. Por defecto ""
867
868 ext : Extension de los archivos a leer. Por defecto .r
869
870 online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas
871
872 Return:
873 0 : Si no encuentra files que cumplan con las condiciones dadas
874 1 : Si encuentra files que cumplan con las condiciones dadas
875
876 Affected:
877 self.startUTCSeconds
878 self.endUTCSeconds
879 self.startYear
880 self.endYear
881 self.startDoy
882 self.endDoy
883 self.pathList
884 self.filenameList
885 self.online
886 """
887
962
888 if ext == None:
963 self.dataOutObj.dataType = self.dataType
889 ext = self.ext
964 self.dataOutObj.updateObjFromHeader()
890
891 if online:
892 print "Searching files ..."
893 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
894
965
895 if not(doypath):
896 for nTries in range( self.nTries ):
897 print '\tWaiting %0.2f sec for valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
898 time.sleep( self.delay )
899 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
900 if doypath:
901 break
902
903 if not(doypath):
904 print "There 'isn't valied files in %s" % path
905 return 0
906
907 self.year = year
908 self.doy = doy
909 self.set = set - 1
910 self.path = path
911
912 else: # offline
913 pathList, filenameList = self.__searchFilesOffLine(path, startDateTime, endDateTime, set, expLabel, ext)
914 if not(pathList):
915 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
916 return 0
917
918 self.fileIndex = -1
919 self.pathList = pathList
920 self.filenameList = filenameList
921
922 self.online = online
923 self.ext = ext
924
925 ext = ext.lower()
926
927 if not( self.setNextFile() ):
928 if (startDateTime != None) and (endDateTime != None):
929 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
930 elif startDateTime != None:
931 print "No files in : %s" % startDateTime.ctime()
932 else:
933 print "No files"
934 return 0
935
936 if startDateTime != None:
937 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
938 self.startYear = startDateTime.timetuple().tm_year
939 self.startDoy = startDateTime.timetuple().tm_yday
940
941 if endDateTime != None:
942 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
943 self.endYear = endDateTime.timetuple().tm_year
944 self.endDoy = endDateTime.timetuple().tm_yday
945 #call fillHeaderValues() - to Data Object
946
947 self.updateDataHeader()
948
949 return 1
950
966
951 class JRODataWriter(JRODataIO):
967 class JRODataWriter(JRODataIO):
952
968
953 """
969 """
954 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
970 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
955 de los datos siempre se realiza por bloques.
971 de los datos siempre se realiza por bloques.
956 """
972 """
957
973
958 nWriteBlocks = 0
974 nWriteBlocks = 0
959
975
960 setFile = None
976 setFile = None
961
977
962
978
963 def __init__(self, m_DataObj=None):
979 def __init__(self, dataOutObj=None):
964 raise ValueError, "Not implemented"
980 raise ValueError, "Not implemented"
965
981
966
982
967 def hasAllDataInBuffer(self):
983 def hasAllDataInBuffer(self):
968 raise ValueError, "Not implemented"
984 raise ValueError, "Not implemented"
969
985
970
986
971 def setBlockDimension(self):
987 def setBlockDimension(self):
972 raise ValueError, "Not implemented"
988 raise ValueError, "Not implemented"
973
989
974
990
975 def writeBlock(self):
991 def writeBlock(self):
976 raise ValueError, "No implemented"
992 raise ValueError, "No implemented"
977
993
978
994
979 def putData(self):
995 def putData(self):
980 raise ValueError, "No implemented"
996 raise ValueError, "No implemented"
981
997
982
998
983 def __writeFirstHeader(self):
999 def __writeFirstHeader(self):
984 """
1000 """
985 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1001 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
986
1002
987 Affected:
1003 Affected:
988 __dataType
1004 __dataType
989
1005
990 Return:
1006 Return:
991 None
1007 None
992 """
1008 """
993 self.__writeBasicHeader()
1009 self.__writeBasicHeader()
994 self.__wrSystemHeader()
1010 self.__wrSystemHeader()
995 self.__wrRadarControllerHeader()
1011 self.__wrRadarControllerHeader()
996 self.__wrProcessingHeader()
1012 self.__wrProcessingHeader()
997 self.dataType = self.m_DataObj.dataType
1013 self.dataType = self.dataOutObj.dataType
998
1014
999
1015
1000 def __writeBasicHeader(self, fp=None):
1016 def __writeBasicHeader(self, fp=None):
1001 """
1017 """
1002 Escribe solo el Basic header en el file creado
1018 Escribe solo el Basic header en el file creado
1003
1019
1004 Return:
1020 Return:
1005 None
1021 None
1006 """
1022 """
1007 if fp == None:
1023 if fp == None:
1008 fp = self.fp
1024 fp = self.fp
1009
1025
1010 self.m_DataObj.m_BasicHeader.write(fp)
1026 self.dataOutObj.m_BasicHeader.write(fp)
1011
1027
1012
1028
1013 def __wrSystemHeader(self, fp=None):
1029 def __wrSystemHeader(self, fp=None):
1014 """
1030 """
1015 Escribe solo el System header en el file creado
1031 Escribe solo el System header en el file creado
1016
1032
1017 Return:
1033 Return:
1018 None
1034 None
1019 """
1035 """
1020 if fp == None:
1036 if fp == None:
1021 fp = self.fp
1037 fp = self.fp
1022
1038
1023 self.m_DataObj.m_SystemHeader.write(fp)
1039 self.dataOutObj.m_SystemHeader.write(fp)
1024
1040
1025
1041
1026 def __wrRadarControllerHeader(self, fp=None):
1042 def __wrRadarControllerHeader(self, fp=None):
1027 """
1043 """
1028 Escribe solo el RadarController header en el file creado
1044 Escribe solo el RadarController header en el file creado
1029
1045
1030 Return:
1046 Return:
1031 None
1047 None
1032 """
1048 """
1033 if fp == None:
1049 if fp == None:
1034 fp = self.fp
1050 fp = self.fp
1035
1051
1036 self.m_DataObj.m_RadarControllerHeader.write(fp)
1052 self.dataOutObj.m_RadarControllerHeader.write(fp)
1037
1053
1038
1054
1039 def __wrProcessingHeader(self, fp=None):
1055 def __wrProcessingHeader(self, fp=None):
1040 """
1056 """
1041 Escribe solo el Processing header en el file creado
1057 Escribe solo el Processing header en el file creado
1042
1058
1043 Return:
1059 Return:
1044 None
1060 None
1045 """
1061 """
1046 if fp == None:
1062 if fp == None:
1047 fp = self.fp
1063 fp = self.fp
1048
1064
1049 self.m_DataObj.m_ProcessingHeader.write(fp)
1065 self.dataOutObj.m_ProcessingHeader.write(fp)
1050
1066
1051
1067
1052 def setNextFile(self):
1068 def setNextFile(self):
1053 """
1069 """
1054 Determina el siguiente file que sera escrito
1070 Determina el siguiente file que sera escrito
1055
1071
1056 Affected:
1072 Affected:
1057 self.filename
1073 self.filename
1058 self.subfolder
1074 self.subfolder
1059 self.fp
1075 self.fp
1060 self.setFile
1076 self.setFile
1061 self.flagIsNewFile
1077 self.flagIsNewFile
1062
1078
1063 Return:
1079 Return:
1064 0 : Si el archivo no puede ser escrito
1080 0 : Si el archivo no puede ser escrito
1065 1 : Si el archivo esta listo para ser escrito
1081 1 : Si el archivo esta listo para ser escrito
1066 """
1082 """
1067 ext = self.ext
1083 ext = self.ext
1068 path = self.path
1084 path = self.path
1069
1085
1070 if self.fp != None:
1086 if self.fp != None:
1071 self.fp.close()
1087 self.fp.close()
1072
1088
1073 timeTuple = time.localtime( self.m_DataObj.m_BasicHeader.utc )
1089 timeTuple = time.localtime( self.dataOutObj.m_BasicHeader.utc )
1074 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1090 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1075
1091
1076 doypath = os.path.join( path, subfolder )
1092 doypath = os.path.join( path, subfolder )
1077 if not( os.path.exists(doypath) ):
1093 if not( os.path.exists(doypath) ):
1078 os.mkdir(doypath)
1094 os.mkdir(doypath)
1079 self.setFile = -1 #inicializo mi contador de seteo
1095 self.setFile = -1 #inicializo mi contador de seteo
1080 else:
1096 else:
1081 filesList = os.listdir( doypath )
1097 filesList = os.listdir( doypath )
1082 if len( filesList ) > 0:
1098 if len( filesList ) > 0:
1083 filesList = sorted( filesList, key=str.lower )
1099 filesList = sorted( filesList, key=str.lower )
1084 filen = filesList[-1]
1100 filen = filesList[-1]
1085 # el filename debera tener el siguiente formato
1101 # el filename debera tener el siguiente formato
1086 # 0 1234 567 89A BCDE (hex)
1102 # 0 1234 567 89A BCDE (hex)
1087 # x YYYY DDD SSS .ext
1103 # x YYYY DDD SSS .ext
1088 if isNumber( filen[8:11] ):
1104 if isNumber( filen[8:11] ):
1089 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1105 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1090 else:
1106 else:
1091 self.setFile = -1
1107 self.setFile = -1
1092 else:
1108 else:
1093 self.setFile = -1 #inicializo mi contador de seteo
1109 self.setFile = -1 #inicializo mi contador de seteo
1094
1110
1095 setFile = self.setFile
1111 setFile = self.setFile
1096 setFile += 1
1112 setFile += 1
1097
1113
1098 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1114 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1099 timeTuple.tm_year,
1115 timeTuple.tm_year,
1100 timeTuple.tm_yday,
1116 timeTuple.tm_yday,
1101 setFile,
1117 setFile,
1102 ext )
1118 ext )
1103
1119
1104 filename = os.path.join( path, subfolder, file )
1120 filename = os.path.join( path, subfolder, file )
1105
1121
1106 fp = open( filename,'wb' )
1122 fp = open( filename,'wb' )
1107
1123
1108 self.nWriteBlocks = 0
1124 self.nWriteBlocks = 0
1109
1125
1110 #guardando atributos
1126 #guardando atributos
1111 self.filename = filename
1127 self.filename = filename
1112 self.subfolder = subfolder
1128 self.subfolder = subfolder
1113 self.fp = fp
1129 self.fp = fp
1114 self.setFile = setFile
1130 self.setFile = setFile
1115 self.flagIsNewFile = 1
1131 self.flagIsNewFile = 1
1116
1132
1117 print 'Writing the file: %s'%self.filename
1133 print 'Writing the file: %s'%self.filename
1118
1134
1119 self.__writeFirstHeader()
1135 self.__writeFirstHeader()
1120
1136
1121 return 1
1137 return 1
1122
1138
1123
1139
1124 def __setNewBlock(self):
1140 def __setNewBlock(self):
1125 """
1141 """
1126 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1142 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1127
1143
1128 Return:
1144 Return:
1129 0 : si no pudo escribir nada
1145 0 : si no pudo escribir nada
1130 1 : Si escribio el Basic el First Header
1146 1 : Si escribio el Basic el First Header
1131 """
1147 """
1132 if self.fp == None:
1148 if self.fp == None:
1133 self.setNextFile()
1149 self.setNextFile()
1134
1150
1135 if self.flagIsNewFile:
1151 if self.flagIsNewFile:
1136 return 1
1152 return 1
1137
1153
1138 if self.nWriteBlocks < self.m_ProcessingHeader.dataBlocksPerFile:
1154 if self.nWriteBlocks < self.m_ProcessingHeader.dataBlocksPerFile:
1139 self.__writeBasicHeader()
1155 self.__writeBasicHeader()
1140 return 1
1156 return 1
1141
1157
1142 if not( self.setNextFile() ):
1158 if not( self.setNextFile() ):
1143 return 0
1159 return 0
1144
1160
1145 return 1
1161 return 1
1146
1162
1147
1163
1148 def writeNextBlock(self):
1164 def writeNextBlock(self):
1149 """
1165 """
1150 Selecciona el bloque siguiente de datos y los escribe en un file
1166 Selecciona el bloque siguiente de datos y los escribe en un file
1151
1167
1152 Return:
1168 Return:
1153 0 : Si no hizo pudo escribir el bloque de datos
1169 0 : Si no hizo pudo escribir el bloque de datos
1154 1 : Si no pudo escribir el bloque de datos
1170 1 : Si no pudo escribir el bloque de datos
1155 """
1171 """
1156 if not( self.__setNewBlock() ):
1172 if not( self.__setNewBlock() ):
1157 return 0
1173 return 0
1158
1174
1159 self.writeBlock()
1175 self.writeBlock()
1160
1176
1161 return 1
1177 return 1
1162
1178
1163
1179
1164 def getDataHeader(self):
1180 def getDataHeader(self):
1165 """
1181 """
1166 Obtiene una copia del First Header
1182 Obtiene una copia del First Header
1167
1183
1168 Affected:
1184 Affected:
1169 self.m_BasicHeader
1185 self.m_BasicHeader
1170 self.m_SystemHeader
1186 self.m_SystemHeader
1171 self.m_RadarControllerHeader
1187 self.m_RadarControllerHeader
1172 self.m_ProcessingHeader
1188 self.m_ProcessingHeader
1173 self.dataType
1189 self.dataType
1174
1190
1175 Return:
1191 Return:
1176 None
1192 None
1177 """
1193 """
1178 self.m_DataObj.updateHeaderFromObj()
1194 self.dataOutObj.updateHeaderFromObj()
1179
1195
1180 self.m_BasicHeader = self.m_DataObj.m_BasicHeader.copy()
1196 self.m_BasicHeader = self.dataOutObj.m_BasicHeader.copy()
1181 self.m_SystemHeader = self.m_DataObj.m_SystemHeader.copy()
1197 self.m_SystemHeader = self.dataOutObj.m_SystemHeader.copy()
1182 self.m_RadarControllerHeader = self.m_DataObj.m_RadarControllerHeader.copy()
1198 self.m_RadarControllerHeader = self.dataOutObj.m_RadarControllerHeader.copy()
1183 self.m_ProcessingHeader = self.m_DataObj.m_ProcessingHeader.copy()
1199 self.m_ProcessingHeader = self.dataOutObj.m_ProcessingHeader.copy()
1184
1200
1185 self.dataType = self.m_DataObj.dataType
1201 self.dataType = self.dataOutObj.dataType
1186
1202
1187
1203
1188 def setup(self, path, set=0, ext=None):
1204 def setup(self, path, set=0, ext=None):
1189 """
1205 """
1190 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1206 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1191
1207
1192 Inputs:
1208 Inputs:
1193 path : el path destino en el cual se escribiran los files a crear
1209 path : el path destino en el cual se escribiran los files a crear
1194 format : formato en el cual sera salvado un file
1210 format : formato en el cual sera salvado un file
1195 set : el setebo del file
1211 set : el setebo del file
1196
1212
1197 Return:
1213 Return:
1198 0 : Si no realizo un buen seteo
1214 0 : Si no realizo un buen seteo
1199 1 : Si realizo un buen seteo
1215 1 : Si realizo un buen seteo
1200 """
1216 """
1201
1217
1202 if ext == None:
1218 if ext == None:
1203 ext = self.ext
1219 ext = self.ext
1204
1220
1205 ext = ext.lower()
1221 ext = ext.lower()
1206
1222
1207 self.path = path
1223 self.path = path
1208 self.setFile = set - 1
1224 self.setFile = set - 1
1209 self.ext = ext
1225 self.ext = ext
1210 #self.format = format
1226 #self.format = format
1211 self.getDataHeader()
1227 self.getDataHeader()
1212
1228
1213 self.setBlockDimension()
1229 self.setBlockDimension()
1214
1230
1215 if not( self.setNextFile() ):
1231 if not( self.setNextFile() ):
1216 print "There isn't a next file"
1232 print "There isn't a next file"
1217 return 0
1233 return 0
1218
1234
1219 return 1
1235 return 1
@@ -1,551 +1,535
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 Model.JROHeader import *
18 from Model.JROHeader import *
19 from Model.Spectra import Spectra
19 from Model.Spectra import Spectra
20
20
21 from JRODataIO import JRODataReader
21 from JRODataIO import JRODataReader
22 from JRODataIO import JRODataWriter
22 from JRODataIO import JRODataWriter
23 from JRODataIO import isNumber
23 from JRODataIO import isNumber
24
24
25
25
26 class SpectraReader(JRODataReader):
26 class SpectraReader(JRODataReader):
27 """
27 """
28 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
28 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
29 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
29 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
30 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
30 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
31
31
32 paresCanalesIguales * alturas * perfiles (Self Spectra)
32 paresCanalesIguales * alturas * perfiles (Self Spectra)
33 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
33 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
34 canales * alturas (DC Channels)
34 canales * alturas (DC Channels)
35
35
36 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
36 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
37 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
37 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
38 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
38 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
39 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
39 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
40
40
41 Example:
41 Example:
42 dpath = "/home/myuser/data"
42 dpath = "/home/myuser/data"
43
43
44 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
44 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
45
45
46 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
46 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
47
47
48 readerObj = SpectraReader()
48 readerObj = SpectraReader()
49
49
50 readerObj.setup(dpath, startTime, endTime)
50 readerObj.setup(dpath, startTime, endTime)
51
51
52 while(True):
52 while(True):
53
53
54 readerObj.getData()
54 readerObj.getData()
55
55
56 print readerObj.m_Spectra.data
56 print readerObj.dataOutObj.data
57
57
58 if readerObj.flagNoMoreFiles:
58 if readerObj.flagNoMoreFiles:
59 break
59 break
60
60
61 """
61 """
62 m_DataObj = None
62 dataOutObj = None
63
63
64 data_spc = None
64 data_spc = None
65 data_cspc = None
65 data_cspc = None
66 data_dc = None
66 data_dc = None
67
67
68 pts2read_SelfSpectra = 0
68 pts2read_SelfSpectra = 0
69 pts2read_CrossSpectra = 0
69 pts2read_CrossSpectra = 0
70 pts2read_DCchannels = 0
70 pts2read_DCchannels = 0
71
71
72 nChannels = 0
72 nChannels = 0
73
74 nPairs = 0
73 nPairs = 0
75
74
76 #pairList = None
75 flag_cspc = False
77
78 channelList = None
79
76
80 def __init__(self, m_Spectra=None):
77 def __init__(self, dataOutObj=None):
81 """
78 """
82 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
79 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
83
80
84 Inputs:
81 Inputs:
85 m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para
82 dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para
86 almacenar un perfil de datos cada vez que se haga un requerimiento
83 almacenar un perfil de datos cada vez que se haga un requerimiento
87 (getData). El perfil sera obtenido a partir del buffer de datos,
84 (getData). El perfil sera obtenido a partir del buffer de datos,
88 si el buffer esta vacio se hara un nuevo proceso de lectura de un
85 si el buffer esta vacio se hara un nuevo proceso de lectura de un
89 bloque de datos.
86 bloque de datos.
90 Si este parametro no es pasado se creara uno internamente.
87 Si este parametro no es pasado se creara uno internamente.
91
88
92 Affected:
89 Affected:
93 self.m_DataObj
90 self.dataOutObj
94
91
95 Return : None
92 Return : None
96 """
93 """
97 if m_Spectra == None:
98 m_Spectra = Spectra()
99
100 if not( isinstance(m_Spectra, Spectra) ):
101 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
102
103 self.m_DataObj = m_Spectra
104
94
105 self.data_spc = None
95 self.data_spc = None
106 self.data_cspc = None
96 self.data_cspc = None
107 self.data_dc = None
97 self.data_dc = None
108
98
109 self.pts2read_SelfSpectra = 0
99 self.pts2read_SelfSpectra = 0
110 self.pts2read_CrossSpectra = 0
100 self.pts2read_CrossSpectra = 0
111 self.pts2read_DCs = 0
101 self.pts2read_DCs = 0
112
102
113 self.nChannels = 0
103 self.nChannels = 0
114
104
115 self.nPairs = 0
105 self.nPairs = 0
116
106
117 self.ext = ".pdata"
107 self.ext = ".pdata"
118
108
119 self.optchar = "P"
109 self.optchar = "P"
120
110
121 ######################
111 ######################
122
112
123 self.m_BasicHeader = BasicHeader()
113 self.m_BasicHeader = BasicHeader()
124
114
125 self.m_SystemHeader = SystemHeader()
115 self.m_SystemHeader = SystemHeader()
126
116
127 self.m_RadarControllerHeader = RadarControllerHeader()
117 self.m_RadarControllerHeader = RadarControllerHeader()
128
118
129 self.m_ProcessingHeader = ProcessingHeader()
119 self.m_ProcessingHeader = ProcessingHeader()
130
120
131 self.online = 0
121 self.online = 0
132
122
133 self.fp = None
123 self.fp = None
134
124
135 self.fileSizeByHeader = None
125 self.fileSizeByHeader = None
136
126
137 self.filenameList = []
127 self.filenameList = []
138
128
139 self.filename = None
129 self.filename = None
140
130
141 self.fileSize = None
131 self.fileSize = None
142
132
143 self.firstHeaderSize = 0
133 self.firstHeaderSize = 0
144
134
145 self.basicHeaderSize = 24
135 self.basicHeaderSize = 24
146
136
147 self.dataType = None
137 self.dataType = None
148
138
149 self.maxTimeStep = 30
139 self.maxTimeStep = 30
150
140
151 self.flagNoMoreFiles = 0
141 self.flagNoMoreFiles = 0
152
142
153 self.set = 0
143 self.set = 0
154
144
155 self.path = None
145 self.path = None
156
146
157 self.delay = 3 #seconds
147 self.delay = 3 #seconds
158
148
159 self.nTries = 3 #quantity tries
149 self.nTries = 3 #quantity tries
160
150
161 self.nFiles = 3 #number of files for searching
151 self.nFiles = 3 #number of files for searching
162
152
163 self.nReadBlocks = 0
153 self.nReadBlocks = 0
164
154
165 self.flagIsNewFile = 1
155 self.flagIsNewFile = 1
166
156
167 self.ippSeconds = 0
157 self.ippSeconds = 0
168
158
169 self.flagResetProcessing = 0
159 self.flagResetProcessing = 0
170
160
171 self.flagIsNewBlock = 0
161 self.flagIsNewBlock = 0
172
162
173 self.nTotalBlocks = 0
163 self.nTotalBlocks = 0
174
164
175 self.blocksize = 0
165 self.blocksize = 0
176
166
177 #pairList = None
167 def createObjByDefault(self):
178
179 channelList = None
180
168
181 self.flag_cspc = False
169 dataObj = Spectra()
182
170
183
171 return dataObj
172
184 def __hasNotDataInBuffer(self):
173 def __hasNotDataInBuffer(self):
185 return 1
174 return 1
186
175
187
176
188 def getBlockDimension(self):
177 def getBlockDimension(self):
189 """
178 """
190 Obtiene la cantidad de puntos a leer por cada bloque de datos
179 Obtiene la cantidad de puntos a leer por cada bloque de datos
191
180
192 Affected:
181 Affected:
193 self.nChannels
182 self.nChannels
194 self.nPairs
183 self.nPairs
195 self.pts2read_SelfSpectra
184 self.pts2read_SelfSpectra
196 self.pts2read_CrossSpectra
185 self.pts2read_CrossSpectra
197 self.pts2read_DCchannels
186 self.pts2read_DCchannels
198 self.blocksize
187 self.blocksize
199 self.m_DataObj.nChannels
188 self.dataOutObj.nChannels
200 self.m_DataObj.nPairs
189 self.dataOutObj.nPairs
201
190
202 Return:
191 Return:
203 None
192 None
204 """
193 """
205 self.nChannels = 0
194 self.nChannels = 0
206 self.nPairs = 0
195 self.nPairs = 0
207 self.pairList = []
196 self.pairList = []
208
197
209 for i in range( 0, self.m_ProcessingHeader.totalSpectra*2, 2 ):
198 for i in range( 0, self.m_ProcessingHeader.totalSpectra*2, 2 ):
210 if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]:
199 if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]:
211 self.nChannels = self.nChannels + 1 #par de canales iguales
200 self.nChannels = self.nChannels + 1 #par de canales iguales
212 else:
201 else:
213 self.nPairs = self.nPairs + 1 #par de canales diferentes
202 self.nPairs = self.nPairs + 1 #par de canales diferentes
214 self.pairList.append( (self.m_ProcessingHeader.spectraComb[i], self.m_ProcessingHeader.spectraComb[i+1]) )
203 self.pairList.append( (self.m_ProcessingHeader.spectraComb[i], self.m_ProcessingHeader.spectraComb[i+1]) )
215
216 if self.nPairs > 0:
217 self.flag_cspc = True
218
204
219 pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock
205 pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock
220
206
221 self.pts2read_SelfSpectra = int(self.nChannels * pts2read)
207 self.pts2read_SelfSpectra = int(self.nChannels * pts2read)
222 self.blocksize = self.pts2read_SelfSpectra
208 self.blocksize = self.pts2read_SelfSpectra
223
209
224 if self.flag_cspc:
210 if self.m_ProcessingHeader.flag_cspc:
225 self.pts2read_CrossSpectra = int(self.nPairs * pts2read)
211 self.pts2read_CrossSpectra = int(self.nPairs * pts2read)
226 self.blocksize += self.pts2read_CrossSpectra
212 self.blocksize += self.pts2read_CrossSpectra
227
213
228 if self.m_ProcessingHeader.flag_dc:
214 if self.m_ProcessingHeader.flag_dc:
229 self.pts2read_DCchannels = int(self.m_SystemHeader.numChannels * self.m_ProcessingHeader.numHeights)
215 self.pts2read_DCchannels = int(self.m_SystemHeader.numChannels * self.m_ProcessingHeader.numHeights)
230 self.blocksize += self.pts2read_DCchannels
216 self.blocksize += self.pts2read_DCchannels
231
217
232 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
218 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
233
234 self.channelList = numpy.arange(self.nChannels)
235
219
236
220
237 def readBlock(self):
221 def readBlock(self):
238 """
222 """
239 Lee el bloque de datos desde la posicion actual del puntero del archivo
223 Lee el bloque de datos desde la posicion actual del puntero del archivo
240 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
224 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
241 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
225 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
242 es seteado a 0
226 es seteado a 0
243
227
244 Return: None
228 Return: None
245
229
246 Variables afectadas:
230 Variables afectadas:
247 self.datablockIndex
231 self.datablockIndex
248 self.flagIsNewFile
232 self.flagIsNewFile
249 self.flagIsNewBlock
233 self.flagIsNewBlock
250 self.nTotalBlocks
234 self.nTotalBlocks
251 self.data_spc
235 self.data_spc
252 self.data_cspc
236 self.data_cspc
253 self.data_dc
237 self.data_dc
254
238
255 Exceptions:
239 Exceptions:
256 Si un bloque leido no es un bloque valido
240 Si un bloque leido no es un bloque valido
257 """
241 """
258 blockOk_flag = False
242 blockOk_flag = False
259 fpointer = self.fp.tell()
243 fpointer = self.fp.tell()
260
244
261 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
245 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
262 spc = spc.reshape( (self.nChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
246 spc = spc.reshape( (self.nChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
263
247
264 if self.flag_cspc:
248 if self.flag_cspc:
265 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
249 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
266 cspc = cspc.reshape( (self.nPairs, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
250 cspc = cspc.reshape( (self.nPairs, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
267
251
268 if self.m_ProcessingHeader.flag_dc:
252 if self.m_ProcessingHeader.flag_dc:
269 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
253 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
270 dc = dc.reshape( (self.m_SystemHeader.numChannels, self.m_ProcessingHeader.numHeights) ) #transforma a un arreglo 2D
254 dc = dc.reshape( (self.m_SystemHeader.numChannels, self.m_ProcessingHeader.numHeights) ) #transforma a un arreglo 2D
271
255
272
256
273 if not(self.m_ProcessingHeader.shif_fft):
257 if not(self.m_ProcessingHeader.shif_fft):
274 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
258 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
275
259
276 if self.flag_cspc:
260 if self.flag_cspc:
277 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
261 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
278
262
279
263
280 spc = numpy.transpose( spc, (0,2,1) )
264 spc = numpy.transpose( spc, (0,2,1) )
281 self.data_spc = spc
265 self.data_spc = spc
282
266
283 if self.flag_cspc:
267 if self.flag_cspc:
284 cspc = numpy.transpose( cspc, (0,2,1) )
268 cspc = numpy.transpose( cspc, (0,2,1) )
285 self.data_cspc = cspc['real'] + cspc['imag']*1j
269 self.data_cspc = cspc['real'] + cspc['imag']*1j
286 else:
270 else:
287 self.data_cspc = None
271 self.data_cspc = None
288
272
289 if self.m_ProcessingHeader.flag_dc:
273 if self.m_ProcessingHeader.flag_dc:
290 self.data_dc = dc['real'] + dc['imag']*1j
274 self.data_dc = dc['real'] + dc['imag']*1j
291 else:
275 else:
292 self.data_dc = None
276 self.data_dc = None
293
277
294 self.datablockIndex = 0
278 self.datablockIndex = 0
295 self.flagIsNewFile = 0
279 self.flagIsNewFile = 0
296 self.flagIsNewBlock = 1
280 self.flagIsNewBlock = 1
297
281
298 self.nTotalBlocks += 1
282 self.nTotalBlocks += 1
299 self.nReadBlocks += 1
283 self.nReadBlocks += 1
300
284
301 return 1
285 return 1
302
286
303
287
304 def getData(self):
288 def getData(self):
305 """
289 """
306 Copia el buffer de lectura a la clase "Spectra",
290 Copia el buffer de lectura a la clase "Spectra",
307 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
291 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
308 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
292 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
309
293
310 Return:
294 Return:
311 0 : Si no hay mas archivos disponibles
295 0 : Si no hay mas archivos disponibles
312 1 : Si hizo una buena copia del buffer
296 1 : Si hizo una buena copia del buffer
313
297
314 Affected:
298 Affected:
315 self.m_DataObj
299 self.dataOutObj
316 self.datablockIndex
300 self.datablockIndex
317 self.flagResetProcessing
301 self.flagResetProcessing
318 self.flagIsNewBlock
302 self.flagIsNewBlock
319 """
303 """
320
304
321 if self.flagNoMoreFiles: return 0
305 if self.flagNoMoreFiles: return 0
322
306
323 self.flagResetProcessing = 0
307 self.flagResetProcessing = 0
324 self.flagIsNewBlock = 0
308 self.flagIsNewBlock = 0
325
309
326 if self.__hasNotDataInBuffer():
310 if self.__hasNotDataInBuffer():
327
311
328 if not( self.readNextBlock() ):
312 if not( self.readNextBlock() ):
329 return 0
313 return 0
330
314
331 self.updateDataHeader()
315 self.updateDataHeader()
332
316
333 if self.flagNoMoreFiles == 1:
317 if self.flagNoMoreFiles == 1:
334 print 'Process finished'
318 print 'Process finished'
335 return 0
319 return 0
336
320
337 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
321 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
338
322
339 if self.data_dc == None:
323 if self.data_dc == None:
340 self.m_DataObj.flagNoData = True
324 self.dataOutObj.flagNoData = True
341 return 0
325 return 0
342
326
343 self.m_DataObj.flagNoData = False
327 self.dataOutObj.flagNoData = False
344 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
328 self.dataOutObj.flagResetProcessing = self.flagResetProcessing
345
329
346 self.m_DataObj.data_spc = self.data_spc
330 self.dataOutObj.data_spc = self.data_spc
347 self.m_DataObj.data_cspc = self.data_cspc
331 self.dataOutObj.data_cspc = self.data_cspc
348 self.m_DataObj.data_dc = self.data_dc
332 self.dataOutObj.data_dc = self.data_dc
349
333
350 return 1
334 return 1
351
335
352
336
353 class SpectraWriter(JRODataWriter):
337 class SpectraWriter(JRODataWriter):
354
338
355 """
339 """
356 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
340 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
357 de los datos siempre se realiza por bloques.
341 de los datos siempre se realiza por bloques.
358 """
342 """
359
343
360 m_DataObj = None
344 dataOutObj = None
361
345
362 shape_spc_Buffer = None
346 shape_spc_Buffer = None
363 shape_cspc_Buffer = None
347 shape_cspc_Buffer = None
364 shape_dc_Buffer = None
348 shape_dc_Buffer = None
365
349
366 data_spc = None
350 data_spc = None
367 data_cspc = None
351 data_cspc = None
368 data_dc = None
352 data_dc = None
369
353
370
354
371 def __init__(self, m_Spectra=None):
355 def __init__(self, dataOutObj=None):
372 """
356 """
373 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
357 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
374
358
375 Affected:
359 Affected:
376 self.m_DataObj
360 self.dataOutObj
377 self.m_BasicHeader
361 self.m_BasicHeader
378 self.m_SystemHeader
362 self.m_SystemHeader
379 self.m_RadarControllerHeader
363 self.m_RadarControllerHeader
380 self.m_ProcessingHeader
364 self.m_ProcessingHeader
381
365
382 Return: None
366 Return: None
383 """
367 """
384 if m_Spectra == None:
368 if dataOutObj == None:
385 m_Spectra = Spectra()
369 dataOutObj = Spectra()
386
370
387 if not( isinstance(m_Spectra, Spectra) ):
371 if not( isinstance(dataOutObj, Spectra) ):
388 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
372 raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object"
389
373
390 self.m_DataObj = m_Spectra
374 self.dataOutObj = dataOutObj
391
375
392 self.ext = ".pdata"
376 self.ext = ".pdata"
393
377
394 self.optchar = "P"
378 self.optchar = "P"
395
379
396 self.shape_spc_Buffer = None
380 self.shape_spc_Buffer = None
397 self.shape_cspc_Buffer = None
381 self.shape_cspc_Buffer = None
398 self.shape_dc_Buffer = None
382 self.shape_dc_Buffer = None
399
383
400 self.data_spc = None
384 self.data_spc = None
401 self.data_cspc = None
385 self.data_cspc = None
402 self.data_dc = None
386 self.data_dc = None
403
387
404 ####################################
388 ####################################
405
389
406 self.fp = None
390 self.fp = None
407
391
408 self.nWriteBlocks = 0
392 self.nWriteBlocks = 0
409
393
410 self.flagIsNewFile = 1
394 self.flagIsNewFile = 1
411
395
412 self.nTotalBlocks = 0
396 self.nTotalBlocks = 0
413
397
414 self.flagIsNewBlock = 0
398 self.flagIsNewBlock = 0
415
399
416 self.flagNoMoreFiles = 0
400 self.flagNoMoreFiles = 0
417
401
418 self.setFile = None
402 self.setFile = None
419
403
420 self.dataType = None
404 self.dataType = None
421
405
422 self.path = None
406 self.path = None
423
407
424 self.noMoreFiles = 0
408 self.noMoreFiles = 0
425
409
426 self.filename = None
410 self.filename = None
427
411
428 self.m_BasicHeader= BasicHeader()
412 self.m_BasicHeader= BasicHeader()
429
413
430 self.m_SystemHeader = SystemHeader()
414 self.m_SystemHeader = SystemHeader()
431
415
432 self.m_RadarControllerHeader = RadarControllerHeader()
416 self.m_RadarControllerHeader = RadarControllerHeader()
433
417
434 self.m_ProcessingHeader = ProcessingHeader()
418 self.m_ProcessingHeader = ProcessingHeader()
435
419
436
420
437 def hasAllDataInBuffer(self):
421 def hasAllDataInBuffer(self):
438 return 1
422 return 1
439
423
440
424
441 def setBlockDimension(self):
425 def setBlockDimension(self):
442 """
426 """
443 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
427 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
444
428
445 Affected:
429 Affected:
446 self.shape_spc_Buffer
430 self.shape_spc_Buffer
447 self.shape_cspc_Buffer
431 self.shape_cspc_Buffer
448 self.shape_dc_Buffer
432 self.shape_dc_Buffer
449
433
450 Return: None
434 Return: None
451 """
435 """
452 self.shape_spc_Buffer = (self.m_DataObj.nChannels,
436 self.shape_spc_Buffer = (self.dataOutObj.nChannels,
453 self.m_ProcessingHeader.numHeights,
437 self.m_ProcessingHeader.numHeights,
454 self.m_ProcessingHeader.profilesPerBlock)
438 self.m_ProcessingHeader.profilesPerBlock)
455
439
456 self.shape_cspc_Buffer = (self.m_DataObj.nPairs,
440 self.shape_cspc_Buffer = (self.dataOutObj.nPairs,
457 self.m_ProcessingHeader.numHeights,
441 self.m_ProcessingHeader.numHeights,
458 self.m_ProcessingHeader.profilesPerBlock)
442 self.m_ProcessingHeader.profilesPerBlock)
459
443
460 self.shape_dc_Buffer = (self.m_SystemHeader.numChannels,
444 self.shape_dc_Buffer = (self.m_SystemHeader.numChannels,
461 self.m_ProcessingHeader.numHeights)
445 self.m_ProcessingHeader.numHeights)
462
446
463
447
464 def writeBlock(self):
448 def writeBlock(self):
465 """
449 """
466 Escribe el buffer en el file designado
450 Escribe el buffer en el file designado
467
451
468 Affected:
452 Affected:
469 self.data_spc
453 self.data_spc
470 self.data_cspc
454 self.data_cspc
471 self.data_dc
455 self.data_dc
472 self.flagIsNewFile
456 self.flagIsNewFile
473 self.flagIsNewBlock
457 self.flagIsNewBlock
474 self.nTotalBlocks
458 self.nTotalBlocks
475 self.nWriteBlocks
459 self.nWriteBlocks
476
460
477 Return: None
461 Return: None
478 """
462 """
479
463
480 spc = numpy.transpose( self.data_spc, (0,2,1) )
464 spc = numpy.transpose( self.data_spc, (0,2,1) )
481 if not( self.m_ProcessingHeader.shif_fft ):
465 if not( self.m_ProcessingHeader.shif_fft ):
482 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
466 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
483 data = spc.reshape((-1))
467 data = spc.reshape((-1))
484 data.tofile(self.fp)
468 data.tofile(self.fp)
485
469
486 if self.data_cspc != None:
470 if self.data_cspc != None:
487 data = numpy.zeros( self.shape_cspc_Buffer, self.dataType )
471 data = numpy.zeros( self.shape_cspc_Buffer, self.dataType )
488 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
472 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
489 if not( self.m_ProcessingHeader.shif_fft ):
473 if not( self.m_ProcessingHeader.shif_fft ):
490 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
474 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
491 data['real'] = cspc.real
475 data['real'] = cspc.real
492 data['imag'] = cspc.imag
476 data['imag'] = cspc.imag
493 data = data.reshape((-1))
477 data = data.reshape((-1))
494 data.tofile(self.fp)
478 data.tofile(self.fp)
495
479
496 data = numpy.zeros( self.shape_dc_Buffer, self.dataType )
480 data = numpy.zeros( self.shape_dc_Buffer, self.dataType )
497 dc = self.data_dc
481 dc = self.data_dc
498 data['real'] = dc.real
482 data['real'] = dc.real
499 data['imag'] = dc.imag
483 data['imag'] = dc.imag
500 data = data.reshape((-1))
484 data = data.reshape((-1))
501 data.tofile(self.fp)
485 data.tofile(self.fp)
502
486
503 self.data_spc.fill(0)
487 self.data_spc.fill(0)
504 self.data_dc.fill(0)
488 self.data_dc.fill(0)
505 if self.data_cspc != None:
489 if self.data_cspc != None:
506 self.data_cspc.fill(0)
490 self.data_cspc.fill(0)
507
491
508 self.flagIsNewFile = 0
492 self.flagIsNewFile = 0
509 self.flagIsNewBlock = 1
493 self.flagIsNewBlock = 1
510 self.nTotalBlocks += 1
494 self.nTotalBlocks += 1
511 self.nWriteBlocks += 1
495 self.nWriteBlocks += 1
512
496
513
497
514 def putData(self):
498 def putData(self):
515 """
499 """
516 Setea un bloque de datos y luego los escribe en un file
500 Setea un bloque de datos y luego los escribe en un file
517
501
518 Affected:
502 Affected:
519 self.data_spc
503 self.data_spc
520 self.data_cspc
504 self.data_cspc
521 self.data_dc
505 self.data_dc
522
506
523 Return:
507 Return:
524 0 : Si no hay data o no hay mas files que puedan escribirse
508 0 : Si no hay data o no hay mas files que puedan escribirse
525 1 : Si se escribio la data de un bloque en un file
509 1 : Si se escribio la data de un bloque en un file
526 """
510 """
527 self.flagIsNewBlock = 0
511 self.flagIsNewBlock = 0
528
512
529 if self.m_DataObj.flagNoData:
513 if self.dataOutObj.flagNoData:
530 return 0
514 return 0
531
515
532 if self.m_DataObj.flagResetProcessing:
516 if self.dataOutObj.flagResetProcessing:
533 self.data_spc.fill(0)
517 self.data_spc.fill(0)
534 self.data_cspc.fill(0)
518 self.data_cspc.fill(0)
535 self.data_dc.fill(0)
519 self.data_dc.fill(0)
536 self.setNextFile()
520 self.setNextFile()
537
521
538 self.data_spc = self.m_DataObj.data_spc
522 self.data_spc = self.dataOutObj.data_spc
539 self.data_cspc = self.m_DataObj.data_cspc
523 self.data_cspc = self.dataOutObj.data_cspc
540 self.data_dc = self.m_DataObj.data_dc
524 self.data_dc = self.dataOutObj.data_dc
541
525
542 # #self.m_ProcessingHeader.dataBlocksPerFile)
526 # #self.m_ProcessingHeader.dataBlocksPerFile)
543 if self.hasAllDataInBuffer():
527 if self.hasAllDataInBuffer():
544 self.getDataHeader()
528 self.getDataHeader()
545 self.writeNextBlock()
529 self.writeNextBlock()
546
530
547 if self.flagNoMoreFiles:
531 if self.flagNoMoreFiles:
548 #print 'Process finished'
532 #print 'Process finished'
549 return 0
533 return 0
550
534
551 return 1 No newline at end of file
535 return 1
@@ -1,434 +1,433
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 Model.JROHeader import *
17 from Model.JROHeader import *
18 from Model.Voltage import Voltage
18 from Model.Voltage import Voltage
19
19
20 from IO.JRODataIO import JRODataReader
20 from IO.JRODataIO import JRODataReader
21 from IO.JRODataIO import JRODataWriter
21 from IO.JRODataIO import JRODataWriter
22
22
23
23
24 class VoltageReader(JRODataReader):
24 class VoltageReader(JRODataReader):
25 """
25 """
26 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
26 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
27 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
27 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
28 perfiles*alturas*canales) son almacenados en la variable "buffer".
28 perfiles*alturas*canales) son almacenados en la variable "buffer".
29
29
30 perfiles * alturas * canales
30 perfiles * alturas * canales
31
31
32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
33 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
33 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
34 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
34 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
36
36
37 Example:
37 Example:
38
38
39 dpath = "/home/myuser/data"
39 dpath = "/home/myuser/data"
40
40
41 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
41 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
42
42
43 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
43 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
44
44
45 readerObj = VoltageReader()
45 readerObj = VoltageReader()
46
46
47 readerObj.setup(dpath, startTime, endTime)
47 readerObj.setup(dpath, startTime, endTime)
48
48
49 while(True):
49 while(True):
50
50
51 #to get one profile
51 #to get one profile
52 profile = readerObj.getData()
52 profile = readerObj.getData()
53
53
54 #print the profile
54 #print the profile
55 print profile
55 print profile
56
56
57 #If you want to see all datablock
57 #If you want to see all datablock
58 print readerObj.datablock
58 print readerObj.datablock
59
59
60 if readerObj.flagNoMoreFiles:
60 if readerObj.flagNoMoreFiles:
61 break
61 break
62
62
63 """
63 """
64 m_DataObj = None
64 dataOutObj = None
65
65
66 datablock = None
66 datablock = None
67
67
68 ext = ".r"
68 ext = ".r"
69
69
70 optchar = "D"
70 optchar = "D"
71
71
72
72
73 def __init__(self, m_Voltage=None):
73 def __init__(self, dataOutObj=None):
74 """
74 """
75 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
75 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
76
76
77 Input:
77 Input:
78 m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para
78 dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para
79 almacenar un perfil de datos cada vez que se haga un requerimiento
79 almacenar un perfil de datos cada vez que se haga un requerimiento
80 (getData). El perfil sera obtenido a partir del buffer de datos,
80 (getData). El perfil sera obtenido a partir del buffer de datos,
81 si el buffer esta vacio se hara un nuevo proceso de lectura de un
81 si el buffer esta vacio se hara un nuevo proceso de lectura de un
82 bloque de datos.
82 bloque de datos.
83 Si este parametro no es pasado se creara uno internamente.
83 Si este parametro no es pasado se creara uno internamente.
84
84
85 Variables afectadas:
85 Variables afectadas:
86 self.m_DataObj
86 self.dataOutObj
87
87
88 Return:
88 Return:
89 None
89 None
90 """
90 """
91 if m_Voltage == None:
92 m_Voltage = Voltage()
93
94 if not(isinstance(m_Voltage, Voltage)):
95 raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object"
96
97 self.m_DataObj = m_Voltage
98
91
99 self.datablock = None
92 self.datablock = None
100
93
101 self.utc = 0
94 self.utc = 0
102
95
103 self.ext = ".r"
96 self.ext = ".r"
104
97
105 self.optchar = "D"
98 self.optchar = "D"
106
99
107 self.m_BasicHeader = BasicHeader()
100 self.m_BasicHeader = BasicHeader()
108
101
109 self.m_SystemHeader = SystemHeader()
102 self.m_SystemHeader = SystemHeader()
110
103
111 self.m_RadarControllerHeader = RadarControllerHeader()
104 self.m_RadarControllerHeader = RadarControllerHeader()
112
105
113 self.m_ProcessingHeader = ProcessingHeader()
106 self.m_ProcessingHeader = ProcessingHeader()
114
107
115 self.online = 0
108 self.online = 0
116
109
117 self.fp = None
110 self.fp = None
118
111
119 self.idFile = None
112 self.idFile = None
120
113
121 self.startDateTime = None
114 self.startDateTime = None
122
115
123 self.endDateTime = None
116 self.endDateTime = None
124
117
125 self.dataType = None
118 self.dataType = None
126
119
127 self.fileSizeByHeader = None
120 self.fileSizeByHeader = None
128
121
129 self.filenameList = []
122 self.filenameList = []
130
123
131 self.filename = None
124 self.filename = None
132
125
133 self.fileSize = None
126 self.fileSize = None
134
127
135 self.firstHeaderSize = 0
128 self.firstHeaderSize = 0
136
129
137 self.basicHeaderSize = 24
130 self.basicHeaderSize = 24
138
131
139 self.pathList = []
132 self.pathList = []
140
133
141 self.filenameList = []
134 self.filenameList = []
142
135
143 self.lastUTTime = 0
136 self.lastUTTime = 0
144
137
145 self.maxTimeStep = 30
138 self.maxTimeStep = 30
146
139
147 self.flagNoMoreFiles = 0
140 self.flagNoMoreFiles = 0
148
141
149 self.set = 0
142 self.set = 0
150
143
151 self.path = None
144 self.path = None
152
145
153 self.profileIndex = 9999
146 self.profileIndex = 9999
154
147
155 self.delay = 3 #seconds
148 self.delay = 3 #seconds
156
149
157 self.nTries = 3 #quantity tries
150 self.nTries = 3 #quantity tries
158
151
159 self.nFiles = 3 #number of files for searching
152 self.nFiles = 3 #number of files for searching
160
153
161 self.nReadBlocks = 0
154 self.nReadBlocks = 0
162
155
163 self.flagIsNewFile = 1
156 self.flagIsNewFile = 1
164
157
165 self.ippSeconds = 0
158 self.ippSeconds = 0
166
159
167 self.flagResetProcessing = 0
160 self.flagResetProcessing = 0
168
161
169 self.flagIsNewBlock = 0
162 self.flagIsNewBlock = 0
170
163
171 self.nTotalBlocks = 0
164 self.nTotalBlocks = 0
172
165
173 self.blocksize = 0
166 self.blocksize = 0
174
167
168 def createObjByDefault(self):
169
170 dataObj = Voltage()
171
172 return dataObj
173
175 def __hasNotDataInBuffer(self):
174 def __hasNotDataInBuffer(self):
176 if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock:
175 if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock:
177 return 1
176 return 1
178 return 0
177 return 0
179
178
180
179
181 def getBlockDimension(self):
180 def getBlockDimension(self):
182 """
181 """
183 Obtiene la cantidad de puntos a leer por cada bloque de datos
182 Obtiene la cantidad de puntos a leer por cada bloque de datos
184
183
185 Affected:
184 Affected:
186 self.blocksize
185 self.blocksize
187
186
188 Return:
187 Return:
189 None
188 None
190 """
189 """
191 pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels
190 pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels
192 self.blocksize = pts2read
191 self.blocksize = pts2read
193
192
194
193
195 def readBlock(self):
194 def readBlock(self):
196 """
195 """
197 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
196 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
198 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
197 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
199 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
198 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
200 es seteado a 0
199 es seteado a 0
201
200
202 Inputs:
201 Inputs:
203 None
202 None
204
203
205 Return:
204 Return:
206 None
205 None
207
206
208 Affected:
207 Affected:
209 self.profileIndex
208 self.profileIndex
210 self.datablock
209 self.datablock
211 self.flagIsNewFile
210 self.flagIsNewFile
212 self.flagIsNewBlock
211 self.flagIsNewBlock
213 self.nTotalBlocks
212 self.nTotalBlocks
214
213
215 Exceptions:
214 Exceptions:
216 Si un bloque leido no es un bloque valido
215 Si un bloque leido no es un bloque valido
217 """
216 """
218
217
219 junk = numpy.fromfile( self.fp, self.dataType, self.blocksize )
218 junk = numpy.fromfile( self.fp, self.dataType, self.blocksize )
220
219
221 try:
220 try:
222 junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) )
221 junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) )
223 except:
222 except:
224 print "The read block (%3d) has not enough data" %self.nReadBlocks
223 print "The read block (%3d) has not enough data" %self.nReadBlocks
225 return 0
224 return 0
226
225
227 junk = numpy.transpose(junk, (2,0,1))
226 junk = numpy.transpose(junk, (2,0,1))
228 self.datablock = junk['real'] + junk['imag']*1j
227 self.datablock = junk['real'] + junk['imag']*1j
229
228
230 self.profileIndex = 0
229 self.profileIndex = 0
231
230
232 self.flagIsNewFile = 0
231 self.flagIsNewFile = 0
233 self.flagIsNewBlock = 1
232 self.flagIsNewBlock = 1
234
233
235 self.nTotalBlocks += 1
234 self.nTotalBlocks += 1
236 self.nReadBlocks += 1
235 self.nReadBlocks += 1
237
236
238 return 1
237 return 1
239
238
240
239
241 def getData(self):
240 def getData(self):
242 """
241 """
243 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
242 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
244 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
243 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
245 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
244 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
246
245
247 Ademas incrementa el contador del buffer en 1.
246 Ademas incrementa el contador del buffer en 1.
248
247
249 Return:
248 Return:
250 data : retorna un perfil de voltages (alturas * canales) copiados desde el
249 data : retorna un perfil de voltages (alturas * canales) copiados desde el
251 buffer. Si no hay mas archivos a leer retorna None.
250 buffer. Si no hay mas archivos a leer retorna None.
252
251
253 Variables afectadas:
252 Variables afectadas:
254 self.m_DataObj
253 self.dataOutObj
255 self.profileIndex
254 self.profileIndex
256
255
257 Affected:
256 Affected:
258 self.m_DataObj
257 self.dataOutObj
259 self.profileIndex
258 self.profileIndex
260 self.flagResetProcessing
259 self.flagResetProcessing
261 self.flagIsNewBlock
260 self.flagIsNewBlock
262 """
261 """
263 if self.flagNoMoreFiles: return 0
262 if self.flagNoMoreFiles: return 0
264
263
265 self.flagResetProcessing = 0
264 self.flagResetProcessing = 0
266 self.flagIsNewBlock = 0
265 self.flagIsNewBlock = 0
267
266
268 if self.__hasNotDataInBuffer():
267 if self.__hasNotDataInBuffer():
269
268
270 if not( self.readNextBlock() ):
269 if not( self.readNextBlock() ):
271 return 0
270 return 0
272
271
273 self.updateDataHeader()
272 self.updateDataHeader()
274
273
275 if self.flagNoMoreFiles == 1:
274 if self.flagNoMoreFiles == 1:
276 print 'Process finished'
275 print 'Process finished'
277 return 0
276 return 0
278
277
279 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
278 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
280
279
281 if self.datablock == None:
280 if self.datablock == None:
282 self.m_DataObj.flagNoData = True
281 self.dataOutObj.flagNoData = True
283 return 0
282 return 0
284
283
285 time = self.m_BasicHeader.utc + self.profileIndex * self.ippSeconds
284 time = self.m_BasicHeader.utc + self.profileIndex * self.ippSeconds
286 self.m_DataObj.m_BasicHeader.utc = time
285 self.dataOutObj.m_BasicHeader.utc = time
287
286
288 self.m_DataObj.flagNoData = False
287 self.dataOutObj.flagNoData = False
289 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
288 self.dataOutObj.flagResetProcessing = self.flagResetProcessing
290
289
291 self.m_DataObj.data = self.datablock[:,self.profileIndex,:]
290 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
292
291
293 self.profileIndex += 1
292 self.profileIndex += 1
294
293
295 #call setData - to Data Object
294 #call setData - to Data Object
296
295
297 return 1 #self.m_DataObj.data
296 return 1 #self.dataOutObj.data
298
297
299
298
300 class VoltageWriter(JRODataWriter):
299 class VoltageWriter(JRODataWriter):
301 """
300 """
302 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
301 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
303 de los datos siempre se realiza por bloques.
302 de los datos siempre se realiza por bloques.
304 """
303 """
305 __configHeaderFile = 'wrSetHeadet.txt'
304 __configHeaderFile = 'wrSetHeadet.txt'
306
305
307 m_DataObj = None
306 dataOutObj = None
308
307
309 ext = ".r"
308 ext = ".r"
310
309
311 optchar = "D"
310 optchar = "D"
312
311
313 datablock = None
312 datablock = None
314
313
315 profileIndex = 0
314 profileIndex = 0
316
315
317 shapeBuffer = None
316 shapeBuffer = None
318
317
319
318
320 def __init__(self, m_Voltage=None):
319 def __init__(self, dataOutObj=None):
321 """
320 """
322 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
321 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
323
322
324 Affected:
323 Affected:
325 self.m_DataObj
324 self.dataOutObj
326
325
327 Return: None
326 Return: None
328 """
327 """
329 if m_Voltage == None:
328 if dataOutObj == None:
330 m_Voltage = Voltage()
329 dataOutObj = Voltage()
331
330
332 if not( isinstance(m_Voltage, Voltage) ):
331 if not( isinstance(dataOutObj, Voltage) ):
333 raise ValueError, "in VoltageReader, m_Voltage must be an Spectra class object"
332 raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object"
334
333
335 self.m_DataObj = m_Voltage
334 self.dataOutObj = dataOutObj
336
335
337
336
338 def hasAllDataInBuffer(self):
337 def hasAllDataInBuffer(self):
339 if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock:
338 if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock:
340 return 1
339 return 1
341 return 0
340 return 0
342
341
343
342
344 def setBlockDimension(self):
343 def setBlockDimension(self):
345 """
344 """
346 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
345 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
347
346
348 Affected:
347 Affected:
349 self.shape_spc_Buffer
348 self.shape_spc_Buffer
350 self.shape_cspc_Buffer
349 self.shape_cspc_Buffer
351 self.shape_dc_Buffer
350 self.shape_dc_Buffer
352
351
353 Return: None
352 Return: None
354 """
353 """
355 self.shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock,
354 self.shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock,
356 self.m_ProcessingHeader.numHeights,
355 self.m_ProcessingHeader.numHeights,
357 self.m_SystemHeader.numChannels )
356 self.m_SystemHeader.numChannels )
358
357
359 self.datablock = numpy.zeros((self.m_SystemHeader.numChannels,
358 self.datablock = numpy.zeros((self.m_SystemHeader.numChannels,
360 self.m_ProcessingHeader.profilesPerBlock,
359 self.m_ProcessingHeader.profilesPerBlock,
361 self.m_ProcessingHeader.numHeights),
360 self.m_ProcessingHeader.numHeights),
362 dtype=numpy.dtype('complex'))
361 dtype=numpy.dtype('complex'))
363
362
364
363
365 def writeBlock(self):
364 def writeBlock(self):
366 """
365 """
367 Escribe el buffer en el file designado
366 Escribe el buffer en el file designado
368
367
369 Affected:
368 Affected:
370 self.profileIndex
369 self.profileIndex
371 self.flagIsNewFile
370 self.flagIsNewFile
372 self.flagIsNewBlock
371 self.flagIsNewBlock
373 self.nTotalBlocks
372 self.nTotalBlocks
374 self.nWriteBlocks
373 self.nWriteBlocks
375
374
376 Return: None
375 Return: None
377 """
376 """
378 data = numpy.zeros( self.shapeBuffer, self.dataType )
377 data = numpy.zeros( self.shapeBuffer, self.dataType )
379
378
380 junk = numpy.transpose(self.datablock, (1,2,0))
379 junk = numpy.transpose(self.datablock, (1,2,0))
381
380
382 data['real'] = junk.real
381 data['real'] = junk.real
383 data['imag'] = junk.imag
382 data['imag'] = junk.imag
384
383
385 data = data.reshape( (-1) )
384 data = data.reshape( (-1) )
386
385
387 data.tofile( self.fp )
386 data.tofile( self.fp )
388
387
389 self.datablock.fill(0)
388 self.datablock.fill(0)
390 self.profileIndex = 0
389 self.profileIndex = 0
391 self.flagIsNewFile = 0
390 self.flagIsNewFile = 0
392 self.flagIsNewBlock = 1
391 self.flagIsNewBlock = 1
393 self.nTotalBlocks += 1
392 self.nTotalBlocks += 1
394 self.nWriteBlocks += 1
393 self.nWriteBlocks += 1
395
394
396
395
397 def putData(self):
396 def putData(self):
398 """
397 """
399 Setea un bloque de datos y luego los escribe en un file
398 Setea un bloque de datos y luego los escribe en un file
400
399
401 Affected:
400 Affected:
402 self.flagIsNewBlock
401 self.flagIsNewBlock
403 self.profileIndex
402 self.profileIndex
404
403
405 Return:
404 Return:
406 0 : Si no hay data o no hay mas files que puedan escribirse
405 0 : Si no hay data o no hay mas files que puedan escribirse
407 1 : Si se escribio la data de un bloque en un file
406 1 : Si se escribio la data de un bloque en un file
408 """
407 """
409 self.flagIsNewBlock = 0
408 self.flagIsNewBlock = 0
410
409
411 if self.m_DataObj.flagNoData:
410 if self.dataOutObj.flagNoData:
412 return 0
411 return 0
413
412
414 if self.m_DataObj.flagResetProcessing:
413 if self.dataOutObj.flagResetProcessing:
415
414
416 self.datablock.fill(0)
415 self.datablock.fill(0)
417 self.profileIndex = 0
416 self.profileIndex = 0
418 self.setNextFile()
417 self.setNextFile()
419
418
420 self.datablock[:,self.profileIndex,:] = self.m_DataObj.data
419 self.datablock[:,self.profileIndex,:] = self.dataOutObj.data
421
420
422 self.profileIndex += 1
421 self.profileIndex += 1
423
422
424 if self.hasAllDataInBuffer():
423 if self.hasAllDataInBuffer():
425 #if self.flagIsNewFile:
424 #if self.flagIsNewFile:
426 self.getDataHeader()
425 self.getDataHeader()
427 self.writeNextBlock()
426 self.writeNextBlock()
428
427
429 if self.flagNoMoreFiles:
428 if self.flagNoMoreFiles:
430 #print 'Process finished'
429 #print 'Process finished'
431 return 0
430 return 0
432
431
433 return 1
432 return 1
434 No newline at end of file
433
@@ -1,109 +1,105
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import copy
7 import copy
8 import numpy
8 import numpy
9
9
10 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
11
11
12 class Data:
12 class Data:
13 '''
13 '''
14 classdocs
14 classdocs
15 '''
15 '''
16
16
17 def __init__(self):
17 def __init__(self):
18 '''
18 '''
19 Constructor
19 Constructor
20 '''
20 '''
21 raise ValueError, "This class has not been implemented"
21 raise ValueError, "This class has not been implemented"
22
22
23 def copy(self, objIn=None):
23 def copy(self, objIn=None):
24
24
25 if objIn == None:
25 if objIn == None:
26 return copy.deepcopy(self)
26 return copy.deepcopy(self)
27
27
28 for key in objIn.__dict__.keys():
28 for key in objIn.__dict__.keys():
29 self.__dict__[key] = objIn.__dict__[key]
29 self.__dict__[key] = objIn.__dict__[key]
30
30
31 def deepcopy(self):
31 def deepcopy(self):
32
32
33 return copy.deepcopy(self)
33 return copy.deepcopy(self)
34
34
35 class Noise(Data):
36 '''
37 classdocs
38 '''
39
35
40 def __init__(self):
41 '''
42 Constructor
43 '''
44 pass
45
36
46 class JROData(Data):
37 class JROData(Data):
47 '''
38 '''
48 classdocs
39 classdocs
49 '''
40 '''
50
41
51 m_RadarControllerHeader = RadarControllerHeader()
42 m_RadarControllerHeader = RadarControllerHeader()
52
43
53 m_ProcessingHeader = ProcessingHeader()
44 m_ProcessingHeader = ProcessingHeader()
54
45
55 m_SystemHeader = SystemHeader()
46 m_SystemHeader = SystemHeader()
56
47
57 m_BasicHeader = BasicHeader()
48 m_BasicHeader = BasicHeader()
58
49
59 m_NoiseObj = Noise()
50 noise = None
60
51
61 type = None
52 type = None
62
53
63 dataType = None
54 dataType = None
64
55
65 nHeights = None
56 nHeights = None
66
57
67 nProfiles = None
58 nProfiles = None
68
59
69 nChannels = None
60 nChannels = None
70
61
71 heightList = None
62 heightList = None
72
63
73 channelList = None
64 channelList = None
74
65
66 channelIndexList = None
67
68 pairList = None
69
75 flagNoData = False
70 flagNoData = False
76
71
77 flagResetProcessing = False
72 flagResetProcessing = False
78
73
79 def __init__(self):
74 def __init__(self):
80 '''
75 '''
81 Constructor
76 Constructor
82 '''
77 '''
83 raise ValueError, "This class has not been implemented"
78 raise ValueError, "This class has not been implemented"
84
79
85 def updateHeaderFromObj(self):
80 def updateHeaderFromObj(self):
86
81
87 xi = self.heightList[0]
82 xi = self.heightList[0]
88 step = self.heightList[1] - self.heightList[0]
83 step = self.heightList[1] - self.heightList[0]
89
84
90 self.m_ProcessingHeader.firstHeight = xi
85 self.m_ProcessingHeader.firstHeight = xi
91 self.m_ProcessingHeader.deltaHeight = step
86 self.m_ProcessingHeader.deltaHeight = step
92
87
93 self.m_ProcessingHeader.numHeights = self.nHeights
88 self.m_ProcessingHeader.numHeights = self.nHeights
94 self.m_SystemHeader.numChannels = self.nChannels
89 self.m_SystemHeader.numChannels = self.nChannels
95 self.m_SystemHeader.numProfiles = self.nProfiles
90 self.m_SystemHeader.numProfiles = self.nProfiles
96
91
97 def updateObjFromHeader(self):
92 def updateObjFromHeader(self):
98
93
99 xi = self.m_ProcessingHeader.firstHeight
94 xi = self.m_ProcessingHeader.firstHeight
100 step = self.m_ProcessingHeader.deltaHeight
95 step = self.m_ProcessingHeader.deltaHeight
101 xf = xi + self.m_ProcessingHeader.numHeights*step
96 xf = xi + self.m_ProcessingHeader.numHeights*step
102
97
103 self.heightList = numpy.arange(xi, xf, step)
98 self.heightList = numpy.arange(xi, xf, step)
99 self.channelIndexList = numpy.arange(self.m_SystemHeader.numChannels)
104 self.channelList = numpy.arange(self.m_SystemHeader.numChannels)
100 self.channelList = numpy.arange(self.m_SystemHeader.numChannels)
105
101
106 self.nHeights = len(self.heightList)
102 self.nHeights = len(self.heightList)
107 self.nProfiles = self.m_SystemHeader.numProfiles
103 self.nProfiles = self.m_SystemHeader.numProfiles
108 self.nChannels = len(self.channelList)
104 self.nChannels = len(self.channelList)
109 No newline at end of file
105
@@ -1,486 +1,505
1 '''
1 '''
2 Created on 23/01/2012
2 Created on 23/01/2012
3
3
4 @author $Author: vsarmiento $
4 @author $Author: vsarmiento $
5 @version $Id: HeaderIO.py 37 2012-03-26 22:55:13Z vsarmiento $
5 @version $Id: HeaderIO.py 37 2012-03-26 22:55:13Z vsarmiento $
6 '''
6 '''
7
7
8 import numpy
8 import numpy
9 import copy
9 import copy
10
10
11 class Header:
11 class Header:
12
12
13 def __init__(self):
13 def __init__(self):
14 raise
14 raise
15
15
16 def copy(self):
16 def copy(self):
17 return copy.deepcopy(self)
17 return copy.deepcopy(self)
18
18
19 def read():
19 def read():
20 pass
20 pass
21
21
22 def write():
22 def write():
23 pass
23 pass
24
24
25 class BasicHeader(Header):
25 class BasicHeader(Header):
26
26
27 size = None
27 size = None
28 version = None
28 version = None
29 dataBlock = None
29 dataBlock = None
30 utc = None
30 utc = None
31 miliSecond = None
31 miliSecond = None
32 timeZone = None
32 timeZone = None
33 dstFlag = None
33 dstFlag = None
34 errorCount = None
34 errorCount = None
35 struct = None
35 struct = None
36
36
37 def __init__(self):
37 def __init__(self):
38 self.size = 0
38 self.size = 0
39 self.version = 0
39 self.version = 0
40 self.dataBlock = 0
40 self.dataBlock = 0
41 self.utc = 0
41 self.utc = 0
42 self.miliSecond = 0
42 self.miliSecond = 0
43 self.timeZone = 0
43 self.timeZone = 0
44 self.dstFlag = 0
44 self.dstFlag = 0
45 self.errorCount = 0
45 self.errorCount = 0
46 self.struct = numpy.dtype([
46 self.struct = numpy.dtype([
47 ('nSize','<u4'),
47 ('nSize','<u4'),
48 ('nVersion','<u2'),
48 ('nVersion','<u2'),
49 ('nDataBlockId','<u4'),
49 ('nDataBlockId','<u4'),
50 ('nUtime','<u4'),
50 ('nUtime','<u4'),
51 ('nMilsec','<u2'),
51 ('nMilsec','<u2'),
52 ('nTimezone','<i2'),
52 ('nTimezone','<i2'),
53 ('nDstflag','<i2'),
53 ('nDstflag','<i2'),
54 ('nErrorCount','<u4')
54 ('nErrorCount','<u4')
55 ])
55 ])
56
56
57
57
58 def read(self, fp):
58 def read(self, fp):
59 try:
59 try:
60 header = numpy.fromfile(fp, self.struct,1)
60 header = numpy.fromfile(fp, self.struct,1)
61 self.size = header['nSize'][0]
61 self.size = header['nSize'][0]
62 self.version = header['nVersion'][0]
62 self.version = header['nVersion'][0]
63 self.dataBlock = header['nDataBlockId'][0]
63 self.dataBlock = header['nDataBlockId'][0]
64 self.utc = header['nUtime'][0]
64 self.utc = header['nUtime'][0]
65 self.miliSecond = header['nMilsec'][0]
65 self.miliSecond = header['nMilsec'][0]
66 self.timeZone = header['nTimezone'][0]
66 self.timeZone = header['nTimezone'][0]
67 self.dstFlag = header['nDstflag'][0]
67 self.dstFlag = header['nDstflag'][0]
68 self.errorCount = header['nErrorCount'][0]
68 self.errorCount = header['nErrorCount'][0]
69 except:
69 except:
70 return 0
70 return 0
71
71
72 return 1
72 return 1
73
73
74 def write(self, fp):
74 def write(self, fp):
75 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
75 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
76 header = numpy.array(headerTuple,self.struct)
76 header = numpy.array(headerTuple,self.struct)
77 header.tofile(fp)
77 header.tofile(fp)
78
78
79 return 1
79 return 1
80
80
81 class SystemHeader(Header):
81 class SystemHeader(Header):
82
82
83 size = None
83 size = None
84 numSamples = None
84 numSamples = None
85 numProfiles = None
85 numProfiles = None
86 numChannels = None
86 numChannels = None
87 adcResolution = None
87 adcResolution = None
88 pciDioBusWidth = None
88 pciDioBusWidth = None
89 struct = None
89 struct = None
90
90
91 def __init__(self):
91 def __init__(self):
92 self.size = 0
92 self.size = 0
93 self.numSamples = 0
93 self.numSamples = 0
94 self.numProfiles = 0
94 self.numProfiles = 0
95 self.numChannels = 0
95 self.numChannels = 0
96 self.adcResolution = 0
96 self.adcResolution = 0
97 self.pciDioBusWidth = 0
97 self.pciDioBusWidth = 0
98 self.struct = numpy.dtype([
98 self.struct = numpy.dtype([
99 ('nSize','<u4'),
99 ('nSize','<u4'),
100 ('nNumSamples','<u4'),
100 ('nNumSamples','<u4'),
101 ('nNumProfiles','<u4'),
101 ('nNumProfiles','<u4'),
102 ('nNumChannels','<u4'),
102 ('nNumChannels','<u4'),
103 ('nADCResolution','<u4'),
103 ('nADCResolution','<u4'),
104 ('nPCDIOBusWidth','<u4'),
104 ('nPCDIOBusWidth','<u4'),
105 ])
105 ])
106
106
107
107
108 def read(self, fp):
108 def read(self, fp):
109 try:
109 try:
110 header = numpy.fromfile(fp,self.struct,1)
110 header = numpy.fromfile(fp,self.struct,1)
111 self.size = header['nSize'][0]
111 self.size = header['nSize'][0]
112 self.numSamples = header['nNumSamples'][0]
112 self.numSamples = header['nNumSamples'][0]
113 self.numProfiles = header['nNumProfiles'][0]
113 self.numProfiles = header['nNumProfiles'][0]
114 self.numChannels = header['nNumChannels'][0]
114 self.numChannels = header['nNumChannels'][0]
115 self.adcResolution = header['nADCResolution'][0]
115 self.adcResolution = header['nADCResolution'][0]
116 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
116 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
117 except:
117 except:
118 return 0
118 return 0
119
119
120 return 1
120 return 1
121
121
122 def write(self, fp):
122 def write(self, fp):
123 headerTuple = (self.size,self.numSamples,self.numProfiles,self.numChannels,self.adcResolution,self.pciDioBusWidth)
123 headerTuple = (self.size,self.numSamples,self.numProfiles,self.numChannels,self.adcResolution,self.pciDioBusWidth)
124 header = numpy.array(headerTuple,self.struct)
124 header = numpy.array(headerTuple,self.struct)
125 header.tofile(fp)
125 header.tofile(fp)
126
126
127 return 1
127 return 1
128
128
129 class RadarControllerHeader(Header):
129 class RadarControllerHeader(Header):
130
130
131 size = None
131 size = None
132 expType = None
132 expType = None
133 nTx = None
133 nTx = None
134 ipp = None
134 ipp = None
135 txA = None
135 txA = None
136 txB = None
136 txB = None
137 numWindows = None
137 numWindows = None
138 numTaus = None
138 numTaus = None
139 codeType = None
139 codeType = None
140 line6Function = None
140 line6Function = None
141 line5Function = None
141 line5Function = None
142 fClock = None
142 fClock = None
143 prePulseBefore = None
143 prePulseBefore = None
144 prePulserAfter = None
144 prePulserAfter = None
145 rangeIpp = None
145 rangeIpp = None
146 rangeTxA = None
146 rangeTxA = None
147 rangeTxB = None
147 rangeTxB = None
148 struct = None
148 struct = None
149
149
150 def __init__(self):
150 def __init__(self):
151 self.size = 0
151 self.size = 0
152 self.expType = 0
152 self.expType = 0
153 self.nTx = 0
153 self.nTx = 0
154 self.ipp = 0
154 self.ipp = 0
155 self.txA = 0
155 self.txA = 0
156 self.txB = 0
156 self.txB = 0
157 self.numWindows = 0
157 self.numWindows = 0
158 self.numTaus = 0
158 self.numTaus = 0
159 self.codeType = 0
159 self.codeType = 0
160 self.line6Function = 0
160 self.line6Function = 0
161 self.line5Function = 0
161 self.line5Function = 0
162 self.fClock = 0
162 self.fClock = 0
163 self.prePulseBefore = 0
163 self.prePulseBefore = 0
164 self.prePulserAfter = 0
164 self.prePulserAfter = 0
165 self.rangeIpp = 0
165 self.rangeIpp = 0
166 self.rangeTxA = 0
166 self.rangeTxA = 0
167 self.rangeTxB = 0
167 self.rangeTxB = 0
168 self.struct = numpy.dtype([
168 self.struct = numpy.dtype([
169 ('nSize','<u4'),
169 ('nSize','<u4'),
170 ('nExpType','<u4'),
170 ('nExpType','<u4'),
171 ('nNTx','<u4'),
171 ('nNTx','<u4'),
172 ('fIpp','<f4'),
172 ('fIpp','<f4'),
173 ('fTxA','<f4'),
173 ('fTxA','<f4'),
174 ('fTxB','<f4'),
174 ('fTxB','<f4'),
175 ('nNumWindows','<u4'),
175 ('nNumWindows','<u4'),
176 ('nNumTaus','<u4'),
176 ('nNumTaus','<u4'),
177 ('nCodeType','<u4'),
177 ('nCodeType','<u4'),
178 ('nLine6Function','<u4'),
178 ('nLine6Function','<u4'),
179 ('nLine5Function','<u4'),
179 ('nLine5Function','<u4'),
180 ('fClock','<f4'),
180 ('fClock','<f4'),
181 ('nPrePulseBefore','<u4'),
181 ('nPrePulseBefore','<u4'),
182 ('nPrePulseAfter','<u4'),
182 ('nPrePulseAfter','<u4'),
183 ('sRangeIPP','<a20'),
183 ('sRangeIPP','<a20'),
184 ('sRangeTxA','<a20'),
184 ('sRangeTxA','<a20'),
185 ('sRangeTxB','<a20'),
185 ('sRangeTxB','<a20'),
186 ])
186 ])
187
187
188 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
188 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
189
189
190 self.samplingWindow = None
190 self.samplingWindow = None
191 self.numHeights = None
191 self.numHeights = None
192 self.firstHeight = None
192 self.firstHeight = None
193 self.deltaHeight = None
193 self.deltaHeight = None
194 self.samplesWin = None
194 self.samplesWin = None
195
195
196 self.numCode = None
196 self.numCode = None
197 self.numBaud = None
197 self.numBaud = None
198 self.code = None
198 self.code = None
199 self.flip1 = None
199 self.flip1 = None
200 self.flip2 = None
200 self.flip2 = None
201
201
202 self.dynamic = numpy.array([],numpy.dtype('byte'))
202 self.dynamic = numpy.array([],numpy.dtype('byte'))
203
203
204
204
205 def read(self, fp):
205 def read(self, fp):
206 try:
206 try:
207 startFp = fp.tell()
207 startFp = fp.tell()
208 header = numpy.fromfile(fp,self.struct,1)
208 header = numpy.fromfile(fp,self.struct,1)
209 self.size = header['nSize'][0]
209 self.size = header['nSize'][0]
210 self.expType = header['nExpType'][0]
210 self.expType = header['nExpType'][0]
211 self.nTx = header['nNTx'][0]
211 self.nTx = header['nNTx'][0]
212 self.ipp = header['fIpp'][0]
212 self.ipp = header['fIpp'][0]
213 self.txA = header['fTxA'][0]
213 self.txA = header['fTxA'][0]
214 self.txB = header['fTxB'][0]
214 self.txB = header['fTxB'][0]
215 self.numWindows = header['nNumWindows'][0]
215 self.numWindows = header['nNumWindows'][0]
216 self.numTaus = header['nNumTaus'][0]
216 self.numTaus = header['nNumTaus'][0]
217 self.codeType = header['nCodeType'][0]
217 self.codeType = header['nCodeType'][0]
218 self.line6Function = header['nLine6Function'][0]
218 self.line6Function = header['nLine6Function'][0]
219 self.line5Function = header['nLine5Function'][0]
219 self.line5Function = header['nLine5Function'][0]
220 self.fClock = header['fClock'][0]
220 self.fClock = header['fClock'][0]
221 self.prePulseBefore = header['nPrePulseBefore'][0]
221 self.prePulseBefore = header['nPrePulseBefore'][0]
222 self.prePulserAfter = header['nPrePulseAfter'][0]
222 self.prePulserAfter = header['nPrePulseAfter'][0]
223 self.rangeIpp = header['sRangeIPP'][0]
223 self.rangeIpp = header['sRangeIPP'][0]
224 self.rangeTxA = header['sRangeTxA'][0]
224 self.rangeTxA = header['sRangeTxA'][0]
225 self.rangeTxB = header['sRangeTxB'][0]
225 self.rangeTxB = header['sRangeTxB'][0]
226 # jump Dynamic Radar Controller Header
226 # jump Dynamic Radar Controller Header
227 jumpFp = self.size - 116
227 jumpFp = self.size - 116
228 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
228 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
229 #pointer backward to dynamic header and read
229 #pointer backward to dynamic header and read
230 backFp = fp.tell() - jumpFp
230 backFp = fp.tell() - jumpFp
231 fp.seek(backFp)
231 fp.seek(backFp)
232
232
233 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.numWindows)
233 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.numWindows)
234 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
234 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
235 self.firstHeight = self.samplingWindow['h0']
235 self.firstHeight = self.samplingWindow['h0']
236 self.deltaHeight = self.samplingWindow['dh']
236 self.deltaHeight = self.samplingWindow['dh']
237 self.samplesWin = self.samplingWindow['nsa']
237 self.samplesWin = self.samplingWindow['nsa']
238
238
239 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
239 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
240
240
241 if self.codeType != 0:
241 if self.codeType != 0:
242 self.numCode = numpy.fromfile(fp,'<u4',1)
242 self.numCode = numpy.fromfile(fp,'<u4',1)
243 self.numBaud = numpy.fromfile(fp,'<u4',1)
243 self.numBaud = numpy.fromfile(fp,'<u4',1)
244 self.code = numpy.empty([self.numCode,self.numBaud],dtype='u1')
244 self.code = numpy.empty([self.numCode,self.numBaud],dtype='u1')
245 tempList = []
245 tempList = []
246 for ic in range(self.numCode):
246 for ic in range(self.numCode):
247 temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.numBaud/32.))
247 temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.numBaud/32.))
248 tempList.append(temp)
248 tempList.append(temp)
249 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.numBaud:]
249 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.numBaud:]
250 self.code = 2.0*self.code - 1.0
250 self.code = 2.0*self.code - 1.0
251
251
252 if self.line5Function == RCfunction.FLIP:
252 if self.line5Function == RCfunction.FLIP:
253 self.flip1 = numpy.fromfile(fp,'<u4',1)
253 self.flip1 = numpy.fromfile(fp,'<u4',1)
254
254
255 if self.line6Function == RCfunction.FLIP:
255 if self.line6Function == RCfunction.FLIP:
256 self.flip2 = numpy.fromfile(fp,'<u4',1)
256 self.flip2 = numpy.fromfile(fp,'<u4',1)
257
257
258 endFp = self.size + startFp
258 endFp = self.size + startFp
259 jumpFp = endFp - fp.tell()
259 jumpFp = endFp - fp.tell()
260 if jumpFp > 0:
260 if jumpFp > 0:
261 fp.seek(jumpFp)
261 fp.seek(jumpFp)
262
262
263 except:
263 except:
264 return 0
264 return 0
265
265
266 return 1
266 return 1
267
267
268 def write(self, fp):
268 def write(self, fp):
269 headerTuple = (self.size,
269 headerTuple = (self.size,
270 self.expType,
270 self.expType,
271 self.nTx,
271 self.nTx,
272 self.ipp,
272 self.ipp,
273 self.txA,
273 self.txA,
274 self.txB,
274 self.txB,
275 self.numWindows,
275 self.numWindows,
276 self.numTaus,
276 self.numTaus,
277 self.codeType,
277 self.codeType,
278 self.line6Function,
278 self.line6Function,
279 self.line5Function,
279 self.line5Function,
280 self.fClock,
280 self.fClock,
281 self.prePulseBefore,
281 self.prePulseBefore,
282 self.prePulserAfter,
282 self.prePulserAfter,
283 self.rangeIpp,
283 self.rangeIpp,
284 self.rangeTxA,
284 self.rangeTxA,
285 self.rangeTxB)
285 self.rangeTxB)
286
286
287 header = numpy.array(headerTuple,self.struct)
287 header = numpy.array(headerTuple,self.struct)
288 header.tofile(fp)
288 header.tofile(fp)
289
289
290 dynamic = self.dynamic
290 dynamic = self.dynamic
291 dynamic.tofile(fp)
291 dynamic.tofile(fp)
292
292
293 return 1
293 return 1
294
294
295
295
296
296
297 class ProcessingHeader(Header):
297 class ProcessingHeader(Header):
298
298
299 size = None
299 size = None
300 dataType = None
300 dataType = None
301 blockSize = None
301 blockSize = None
302 profilesPerBlock = None
302 profilesPerBlock = None
303 dataBlocksPerFile = None
303 dataBlocksPerFile = None
304 numWindows = None
304 numWindows = None
305 processFlags = None
305 processFlags = None
306 coherentInt = None
306 coherentInt = None
307 incoherentInt = None
307 incoherentInt = None
308 totalSpectra = None
308 totalSpectra = None
309 struct = None
309 struct = None
310 flag_dc = None
311 flag_cspc = None
310
312
311 def __init__(self):
313 def __init__(self):
312 self.size = 0
314 self.size = 0
313 self.dataType = 0
315 self.dataType = 0
314 self.blockSize = 0
316 self.blockSize = 0
315 self.profilesPerBlock = 0
317 self.profilesPerBlock = 0
316 self.dataBlocksPerFile = 0
318 self.dataBlocksPerFile = 0
317 self.numWindows = 0
319 self.numWindows = 0
318 self.processFlags = 0
320 self.processFlags = 0
319 self.coherentInt = 0
321 self.coherentInt = 0
320 self.incoherentInt = 0
322 self.incoherentInt = 0
321 self.totalSpectra = 0
323 self.totalSpectra = 0
322 self.struct = numpy.dtype([
324 self.struct = numpy.dtype([
323 ('nSize','<u4'),
325 ('nSize','<u4'),
324 ('nDataType','<u4'),
326 ('nDataType','<u4'),
325 ('nSizeOfDataBlock','<u4'),
327 ('nSizeOfDataBlock','<u4'),
326 ('nProfilesperBlock','<u4'),
328 ('nProfilesperBlock','<u4'),
327 ('nDataBlocksperFile','<u4'),
329 ('nDataBlocksperFile','<u4'),
328 ('nNumWindows','<u4'),
330 ('nNumWindows','<u4'),
329 ('nProcessFlags','<u4'),
331 ('nProcessFlags','<u4'),
330 ('nCoherentIntegrations','<u4'),
332 ('nCoherentIntegrations','<u4'),
331 ('nIncoherentIntegrations','<u4'),
333 ('nIncoherentIntegrations','<u4'),
332 ('nTotalSpectra','<u4')
334 ('nTotalSpectra','<u4')
333 ])
335 ])
334 self.samplingWindow = 0
336 self.samplingWindow = 0
335 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
337 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
336 self.numHeights = 0
338 self.numHeights = 0
337 self.firstHeight = 0
339 self.firstHeight = 0
338 self.deltaHeight = 0
340 self.deltaHeight = 0
339 self.samplesWin = 0
341 self.samplesWin = 0
340 self.spectraComb = 0
342 self.spectraComb = 0
341 self.numCode = 0
343 self.numCode = 0
342 self.code = 0
344 self.code = 0
343 self.numBaud = 0
345 self.numBaud = 0
344 self.shif_fft = False
346 self.shif_fft = False
345 self.flag_dc = False
347 self.flag_dc = False
348 self.flag_cspc = False
346
349
347 def read(self, fp):
350 def read(self, fp):
348 try:
351 try:
349 header = numpy.fromfile(fp,self.struct,1)
352 header = numpy.fromfile(fp,self.struct,1)
350 self.size = header['nSize'][0]
353 self.size = header['nSize'][0]
351 self.dataType = header['nDataType'][0]
354 self.dataType = header['nDataType'][0]
352 self.blockSize = header['nSizeOfDataBlock'][0]
355 self.blockSize = header['nSizeOfDataBlock'][0]
353 self.profilesPerBlock = header['nProfilesperBlock'][0]
356 self.profilesPerBlock = header['nProfilesperBlock'][0]
354 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
357 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
355 self.numWindows = header['nNumWindows'][0]
358 self.numWindows = header['nNumWindows'][0]
356 self.processFlags = header['nProcessFlags']
359 self.processFlags = header['nProcessFlags']
357 self.coherentInt = header['nCoherentIntegrations'][0]
360 self.coherentInt = header['nCoherentIntegrations'][0]
358 self.incoherentInt = header['nIncoherentIntegrations'][0]
361 self.incoherentInt = header['nIncoherentIntegrations'][0]
359 self.totalSpectra = header['nTotalSpectra'][0]
362 self.totalSpectra = header['nTotalSpectra'][0]
360 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows)
363 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows)
361 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
364 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
362 self.firstHeight = self.samplingWindow['h0']
365 self.firstHeight = self.samplingWindow['h0']
363 self.deltaHeight = self.samplingWindow['dh']
366 self.deltaHeight = self.samplingWindow['dh']
364 self.samplesWin = self.samplingWindow['nsa']
367 self.samplesWin = self.samplingWindow['nsa']
365 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
368 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
366
369
367 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
370 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
368 self.numCode = numpy.fromfile(fp,'<u4',1)
371 self.numCode = numpy.fromfile(fp,'<u4',1)
369 self.numBaud = numpy.fromfile(fp,'<u4',1)
372 self.numBaud = numpy.fromfile(fp,'<u4',1)
370 self.code = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode)
373 self.code = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode)
371
374
372 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
375 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
373 self.shif_fft = True
376 self.shif_fft = True
374 else:
377 else:
375 self.shif_fft = False
378 self.shif_fft = False
376
379
377 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
380 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
378 self.flag_dc = True
381 self.flag_dc = True
382
383 nChannels = 0
384 nPairs = 0
385 pairList = []
386
387 for i in range( 0, self.totalSpectra*2, 2 ):
388 if self.spectraComb[i] == self.spectraComb[i+1]:
389 nChannels = nChannels + 1 #par de canales iguales
390 else:
391 nPairs = nPairs + 1 #par de canales diferentes
392 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
393
394 self.flag_cspc = False
395 if nPairs > 0:
396 self.flag_cspc = True
397
379 except:
398 except:
380 return 0
399 return 0
381
400
382 return 1
401 return 1
383
402
384 def write(self, fp):
403 def write(self, fp):
385 headerTuple = (self.size,
404 headerTuple = (self.size,
386 self.dataType,
405 self.dataType,
387 self.blockSize,
406 self.blockSize,
388 self.profilesPerBlock,
407 self.profilesPerBlock,
389 self.dataBlocksPerFile,
408 self.dataBlocksPerFile,
390 self.numWindows,
409 self.numWindows,
391 self.processFlags,
410 self.processFlags,
392 self.coherentInt,
411 self.coherentInt,
393 self.incoherentInt,
412 self.incoherentInt,
394 self.totalSpectra)
413 self.totalSpectra)
395
414
396 header = numpy.array(headerTuple,self.struct)
415 header = numpy.array(headerTuple,self.struct)
397 header.tofile(fp)
416 header.tofile(fp)
398
417
399 if self.numWindows != 0:
418 if self.numWindows != 0:
400 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
419 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
401 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
420 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
402 samplingWindow.tofile(fp)
421 samplingWindow.tofile(fp)
403
422
404
423
405 if self.totalSpectra != 0:
424 if self.totalSpectra != 0:
406 spectraComb = numpy.array([],numpy.dtype('u1'))
425 spectraComb = numpy.array([],numpy.dtype('u1'))
407 spectraComb = self.spectraComb
426 spectraComb = self.spectraComb
408 spectraComb.tofile(fp)
427 spectraComb.tofile(fp)
409
428
410
429
411 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
430 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
412 numCode = self.numCode
431 numCode = self.numCode
413 numCode.tofile(fp)
432 numCode.tofile(fp)
414
433
415 numBaud = self.numBaud
434 numBaud = self.numBaud
416 numBaud.tofile(fp)
435 numBaud.tofile(fp)
417
436
418 code = self.code.reshape(numCode*numBaud)
437 code = self.code.reshape(numCode*numBaud)
419 code.tofile(fp)
438 code.tofile(fp)
420
439
421 return 1
440 return 1
422
441
423 class RCfunction:
442 class RCfunction:
424 NONE=0
443 NONE=0
425 FLIP=1
444 FLIP=1
426 CODE=2
445 CODE=2
427 SAMPLING=3
446 SAMPLING=3
428 LIN6DIV256=4
447 LIN6DIV256=4
429 SYNCHRO=5
448 SYNCHRO=5
430
449
431 class nCodeType:
450 class nCodeType:
432 NONE=0
451 NONE=0
433 USERDEFINE=1
452 USERDEFINE=1
434 BARKER2=2
453 BARKER2=2
435 BARKER3=3
454 BARKER3=3
436 BARKER4=4
455 BARKER4=4
437 BARKER5=5
456 BARKER5=5
438 BARKER7=6
457 BARKER7=6
439 BARKER11=7
458 BARKER11=7
440 BARKER13=8
459 BARKER13=8
441 AC128=9
460 AC128=9
442 COMPLEMENTARYCODE2=10
461 COMPLEMENTARYCODE2=10
443 COMPLEMENTARYCODE4=11
462 COMPLEMENTARYCODE4=11
444 COMPLEMENTARYCODE8=12
463 COMPLEMENTARYCODE8=12
445 COMPLEMENTARYCODE16=13
464 COMPLEMENTARYCODE16=13
446 COMPLEMENTARYCODE32=14
465 COMPLEMENTARYCODE32=14
447 COMPLEMENTARYCODE64=15
466 COMPLEMENTARYCODE64=15
448 COMPLEMENTARYCODE128=16
467 COMPLEMENTARYCODE128=16
449 CODE_BINARY28=17
468 CODE_BINARY28=17
450
469
451 class PROCFLAG:
470 class PROCFLAG:
452 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
471 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
453 DECODE_DATA = numpy.uint32(0x00000002)
472 DECODE_DATA = numpy.uint32(0x00000002)
454 SPECTRA_CALC = numpy.uint32(0x00000004)
473 SPECTRA_CALC = numpy.uint32(0x00000004)
455 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
474 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
456 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
475 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
457 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
476 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
458
477
459 DATATYPE_CHAR = numpy.uint32(0x00000040)
478 DATATYPE_CHAR = numpy.uint32(0x00000040)
460 DATATYPE_SHORT = numpy.uint32(0x00000080)
479 DATATYPE_SHORT = numpy.uint32(0x00000080)
461 DATATYPE_LONG = numpy.uint32(0x00000100)
480 DATATYPE_LONG = numpy.uint32(0x00000100)
462 DATATYPE_INT64 = numpy.uint32(0x00000200)
481 DATATYPE_INT64 = numpy.uint32(0x00000200)
463 DATATYPE_FLOAT = numpy.uint32(0x00000400)
482 DATATYPE_FLOAT = numpy.uint32(0x00000400)
464 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
483 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
465
484
466 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
485 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
467 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
486 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
468 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
487 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
469
488
470 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
489 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
471 DEFLIP_DATA = numpy.uint32(0x00010000)
490 DEFLIP_DATA = numpy.uint32(0x00010000)
472 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
491 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
473
492
474 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
493 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
475 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
494 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
476 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
495 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
477 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
496 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
478 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
497 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
479
498
480 EXP_NAME_ESP = numpy.uint32(0x00200000)
499 EXP_NAME_ESP = numpy.uint32(0x00200000)
481 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
500 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
482
501
483 OPERATION_MASK = numpy.uint32(0x0000003F)
502 OPERATION_MASK = numpy.uint32(0x0000003F)
484 DATATYPE_MASK = numpy.uint32(0x00000FC0)
503 DATATYPE_MASK = numpy.uint32(0x00000FC0)
485 DATAARRANGE_MASK = numpy.uint32(0x00007000)
504 DATAARRANGE_MASK = numpy.uint32(0x00007000)
486 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
505 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
@@ -1,78 +1,76
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 from JROData import JROData, Noise
8 from JROData import JROData
9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10
10
11 class Spectra(JROData):
11 class Spectra(JROData):
12 '''
12 '''
13 classdocs
13 classdocs
14 '''
14 '''
15
15
16 data_spc = None
16 data_spc = None
17
17
18 data_cspc = None
18 data_cspc = None
19
19
20 data_dc = None
20 data_dc = None
21
21
22 nFFTPoints = None
22 nFFTPoints = None
23
23
24 nPairs = None
24 nPairs = None
25
25
26 pairsList = None
26 pairsList = None
27
27
28
28
29 def __init__(self):
29 def __init__(self):
30 '''
30 '''
31 Constructor
31 Constructor
32 '''
32 '''
33
33
34 self.m_RadarControllerHeader = RadarControllerHeader()
34 self.m_RadarControllerHeader = RadarControllerHeader()
35
35
36 self.m_ProcessingHeader = ProcessingHeader()
36 self.m_ProcessingHeader = ProcessingHeader()
37
37
38 self.m_SystemHeader = SystemHeader()
38 self.m_SystemHeader = SystemHeader()
39
39
40 self.m_BasicHeader = BasicHeader()
40 self.m_BasicHeader = BasicHeader()
41
41
42 self.m_NoiseObj = Noise()
43
44 self.type = "Spectra"
42 self.type = "Spectra"
45
43
46 self.dataType = None
44 self.dataType = None
47
45
48 self.nHeights = 0
46 self.nHeights = 0
49
47
50 self.nChannels = 0
48 self.nChannels = 0
51
49
52 self.channelList = None
50 self.channelList = None
53
51
54 self.heightList = None
52 self.heightList = None
55
53
56 self.flagNoData = True
54 self.flagNoData = True
57
55
58 self.flagResetProcessing = False
56 self.flagResetProcessing = False
59
57
60
58
61 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
59 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
62 self.data_spc = None
60 self.data_spc = None
63
61
64 self.data_cspc = None
62 self.data_cspc = None
65
63
66 self.data_dc = None
64 self.data_dc = None
67
65
68 self.nFFTPoints = None
66 self.nFFTPoints = None
69
67
70 self.nAvg = None
68 self.nAvg = None
71
69
72 self.nPairs = 0
70 self.nPairs = 0
73
71
74 self.pairsList = None
72 self.pairsList = None
75
73
76
74
77
75
78 No newline at end of file
76
@@ -1,63 +1,61
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 from JROData import JROData, Noise
8 from JROData import JROData
9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10
10
11 class Voltage(JROData):
11 class Voltage(JROData):
12 '''
12 '''
13 classdocs
13 classdocs
14 '''
14 '''
15
15
16 data = None
16 data = None
17
17
18 nProfiles = None
18 nProfiles = None
19
19
20 profileIndex = None
20 profileIndex = None
21
21
22 def __init__(self):
22 def __init__(self):
23 '''
23 '''
24 Constructor
24 Constructor
25 '''
25 '''
26
26
27 self.m_RadarControllerHeader = RadarControllerHeader()
27 self.m_RadarControllerHeader = RadarControllerHeader()
28
28
29 self.m_ProcessingHeader = ProcessingHeader()
29 self.m_ProcessingHeader = ProcessingHeader()
30
30
31 self.m_SystemHeader = SystemHeader()
31 self.m_SystemHeader = SystemHeader()
32
32
33 self.m_BasicHeader = BasicHeader()
33 self.m_BasicHeader = BasicHeader()
34
34
35 self.m_NoiseObj = Noise()
36
37 self.type = "Voltage"
35 self.type = "Voltage"
38
36
39 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
37 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
40 self.data = None
38 self.data = None
41
39
42 self.dataType = None
40 self.dataType = None
43
41
44 self.nHeights = 0
42 self.nHeights = 0
45
43
46 self.nChannels = 0
44 self.nChannels = 0
47
45
48 self.channelList = None
46 self.channelList = None
49
47
50 self.heightList = None
48 self.heightList = None
51
49
52 self.flagNoData = True
50 self.flagNoData = True
53
51
54 self.flagResetProcessing = False
52 self.flagResetProcessing = False
55
53
56 self.nAvg = None
54 self.nAvg = None
57
55
58 self.profileIndex = None
56 self.profileIndex = None
59
57
60 self.nProfiles = None
58 self.nProfiles = None
61
59
62
60
63 No newline at end of file
61
@@ -1,112 +1,213
1 import numpy
1 import numpy
2 from Model.Spectra import Spectra
2 from Model.Spectra import Spectra
3
3
4 def hildebrand_sekhon(Data, navg=1):
4 def hildebrand_sekhon(Data, navg):
5 """
5 """
6 This method is for the objective determination of de noise level in Doppler spectra. This
6 This method is for the objective determination of de noise level in Doppler spectra. This
7 implementation technique is based on the fact that the standard deviation of the spectral
7 implementation technique is based on the fact that the standard deviation of the spectral
8 densities is equal to the mean spectral density for white Gaussian noise
8 densities is equal to the mean spectral density for white Gaussian noise
9
9
10 Inputs:
10 Inputs:
11 Data : heights
11 Data : heights
12 navg : numbers of averages
12 navg : numbers of averages
13
13
14 Return:
14 Return:
15 -1 : any error
15 -1 : any error
16 anoise : noise's level
16 anoise : noise's level
17 """
17 """
18
18 divisor = 8
19 divisor = 8
19 ratio = 7 / divisor
20 ratio = 7 / divisor
20 data = Data.reshape(-1)
21 data = Data.reshape(-1)
21 npts = data.size #numbers of points of the data
22 npts = data.size #numbers of points of the data
22
23
23 if npts < 32:
24 if npts < 32:
24 print "error in noise - requires at least 32 points"
25 print "error in noise - requires at least 32 points"
25 return -1.0
26 return -1.0
26
27
27 # data sorted in ascending order
28 # data sorted in ascending order
28 nmin = int(npts/divisor + ratio);
29 nmin = int(npts/divisor + ratio);
29 s = 0.0
30 s = 0.0
30 s2 = 0.0
31 s2 = 0.0
31 data2 = data[:npts]
32 data2 = data[:npts]
32 data2.sort()
33 data2.sort()
33
34
34 for i in range(nmin):
35 for i in range(nmin):
35 s += data2[i]
36 s += data2[i]
36 s2 += data2[i]**2;
37 s2 += data2[i]**2;
37
38
38 icount = nmin
39 icount = nmin
39 iflag = 0
40 iflag = 0
40
41
41 for i in range(nmin, npts):
42 for i in range(nmin, npts):
42 s += data2[i];
43 s += data2[i];
43 s2 += data2[i]**2
44 s2 += data2[i]**2
44 icount=icount+1;
45 icount=icount+1;
45 p = s / float(icount);
46 p = s / float(icount);
46 p2 = p**2;
47 p2 = p**2;
47 q = s2 / float(icount) - p2;
48 q = s2 / float(icount) - p2;
48 leftc = p2;
49 leftc = p2;
49 rightc = q * float(navg);
50 rightc = q * float(navg);
50
51
51 if leftc > rightc:
52 if leftc > rightc:
52 iflag = 1; #No weather signal
53 iflag = 1; #No weather signal
53 # Signal detect: R2 < 1 (R2 = leftc/rightc)
54 # Signal detect: R2 < 1 (R2 = leftc/rightc)
54 if(leftc < rightc):
55 if(leftc < rightc):
55 if iflag:
56 if iflag:
56 break
57 break
57
58
58 anoise = 0.0;
59 anoise = 0.0;
59 for j in range(i):
60 for j in range(i):
60 anoise += data2[j];
61 anoise += data2[j];
61
62
62 anoise = anoise / float(i);
63 anoise = anoise / float(i);
63
64
64 return anoise;
65 return anoise;
65
66
67 def sorting_bruce(Data, navg):
68 sortdata = numpy.sort(Data)
69 lenOfData = len(Data)
70 nums_min = lenOfData/10
71
72 if (lenOfData/10) > 0:
73 nums_min = lenOfData/10
74 else:
75 nums_min = 0
76
77 rtest = 1.0 + 1.0/navg
78
79 sum = 0.
80
81 sumq = 0.
82
83 j = 0
84
85 cont = 1
86
87 while((cont==1)and(j<lenOfData)):
88
89 sum += sortdata[j]
90
91 sumq += sortdata[j]**2
92
93 j += 1
94
95 if j > nums_min:
96 if ((sumq*j) <= (rtest*sum**2)):
97 lnoise = sum / j
98 else:
99 j = j - 1
100 sum = sum - sordata[j]
101 sumq = sumq - sordata[j]**2
102 cont = 0
103
104 if j == nums_min:
105 lnoise = sum /j
106
107 return lnoise
66
108
67 class Noise:
109 class Noise:
68 """
110 """
69 Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler
111 Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler
70 """
112 """
71 m_DataObj = None
113 data = None
114 noise = None
115 dim = None
72
116
117 def __init__(self, data=None):
118 """
119 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
73
120
74 def __init__(self, m_Spectra=None):
121 Inputs:
122 data: Numpy array de la forma nChan x nHeis x nProfiles
123
124 Affected:
125 self.noise
126
127 Return:
128 None
129 """
130
131 self.data = data
132 self.dim = None
133 self.nChannels = None
134 self.noise = None
135
136 def setNoise(self, data):
75 """
137 """
76 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
138 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
77
139
140 Inputs:
141 data: Numpy array de la forma nChan x nHeis x nProfiles
142
78 Affected:
143 Affected:
79 self.m_DataObj
144 self.noise
80
145
81 Return:
146 Return:
82 None
147 None
83 """
148 """
84 if m_Spectra == None:
85 m_Spectra = Spectra()
86
149
87 if not(isinstance(m_Spectra, Spectra)):
150 if data == None:
88 raise ValueError, "in Noise class, m_Spectra must be an Spectra class object"
151 return 0
152
153 shape = data.shape
154 self.dim = len(shape)
155 if self.dim == 3:
156 nChan, nProfiles, nHeis = shape
157 elif self.dim == 2:
158 nChan, nHeis = shape
159 else:
160 raise ValueError, ""
89
161
90 self.m_DataObj = m_Spectra
162 self.nChannels = nChan
163 self.data = data.copy()
164 self.noise = numpy.zeros(nChan)
91
165
166 return 1
167
92
168
93 def getNoiseLevelByHildebrandSekhon(self):
169 def byHildebrand(self, navg=1):
94 """
170 """
95 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
171 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
96
172
97 Return:
173 Return:
98 noise level
174 noiselevel
99 """
175 """
100 data = self.m_DataObj.data_spc
176
101 daux = None
177 daux = None
102
178
103 for channel in range(self.m_DataObj.nChannels):
179 for channel in range(self.nChannels):
180 daux = self.data[channel,:,:]
181 self.noise[channel] = hildebrand_sekhon(daux, navg)
182 return self.noise
183
184 def byWindow(self, heiIndexMin, heiIndexMax, freqIndexMin, freqIndexMax):
185 """
186 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
187 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
188
189 Inputs:
190 heiIndexMin: Limite inferior del eje de alturas
191 heiIndexMax: Limite superior del eje de alturas
192 freqIndexMin: Limite inferior del eje de frecuencia
193 freqIndexMax: Limite supoerior del eje de frecuencia
194 """
195
196 data = self.data[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
197
198 for channel in range(self.nChannels):
104 daux = data[channel,:,:]
199 daux = data[channel,:,:]
105 noiselevel = hildebrand_sekhon(daux)
200 self.noise[channel] = numpy.average(daux)
106 print noiselevel
107
201
202 return self.noise
203
204 def bySort(self,navg = 1):
205 daux = None
206
207 for channel in range(self.nChannels):
208 daux = self.data[channel,:,:]
209 self.noise[channel] = sorting_bruce(daux, navg)
210
211 return self.noise
108
212
109 for pair in range(self.m_DataObj.nPairs):
213 No newline at end of file
110 daux = data[pair,:,:]
111 noiselevel = hildebrand_sekhon(daux)
112 print noiselevel
@@ -1,620 +1,660
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9
9
10 path = os.path.split(os.getcwd())[0]
10 path = os.path.split(os.getcwd())[0]
11 sys.path.append(path)
11 sys.path.append(path)
12
12
13 from Model.Spectra import Spectra
13 from Model.Spectra import Spectra
14 from IO.SpectraIO import SpectraWriter
14 from IO.SpectraIO import SpectraWriter
15 from Graphics.SpectraPlot import Spectrum
15 from Graphics.SpectraPlot import Spectrum
16
16 from JRONoise import Noise
17
17
18 class SpectraProcessor:
18 class SpectraProcessor:
19 '''
19 '''
20 classdocs
20 classdocs
21 '''
21 '''
22
22
23 dataInObj = None
23 dataInObj = None
24
24
25 dataOutObj = None
25 dataOutObj = None
26
26
27 integratorObjIndex = None
27 noiseObj = None
28
29 decoderObjIndex = None
30
31 writerObjIndex = None
32
33 plotterObjIndex = None
34
28
35 integratorObjList = []
29 integratorObjList = []
36
30
37 decoderObjList = []
31 decoderObjList = []
38
32
39 writerObjList = []
33 writerObjList = []
40
34
41 plotterObjList = []
35 plotterObjList = []
42
36
37 integratorObjIndex = None
38
39 decoderObjIndex = None
40
41 writerObjIndex = None
42
43 plotterObjIndex = None
44
43 buffer = None
45 buffer = None
44
46
45 ptsId = 0
47 profIndex = 0
46
48
47 nFFTPoints = None
49 nFFTPoints = None
48
50
51 nChannels = None
52
53 nHeights = None
54
55 nPairs = None
56
49 pairList = None
57 pairList = None
50
58
51
59
52 def __init__(self, dataInObj=None, dataOutObj=None):
60 def __init__(self):
53 '''
61 '''
54 Constructor
62 Constructor
55 '''
63 '''
56 self.dataInObj = dataInObj
57
64
58 if dataOutObj == None:
59 self.dataOutObj = Spectra()
60 else:
61 self.dataOutObj = dataOutObj
62
63 self.integratorObjIndex = None
65 self.integratorObjIndex = None
64 self.decoderObjIndex = None
66 self.decoderObjIndex = None
65 self.writerObjIndex = None
67 self.writerObjIndex = None
66 self.plotterObjIndex = None
68 self.plotterObjIndex = None
67
69
68 self.integratorObjList = []
70 self.integratorObjList = []
69 self.decoderObjList = []
71 self.decoderObjList = []
70 self.writerObjList = []
72 self.writerObjList = []
71 self.plotterObjList = []
73 self.plotterObjList = []
72
74
75 self.noiseObj = Noise()
73 self.buffer = None
76 self.buffer = None
74 self.ptsId = 0
77 self.profIndex = 0
75
76 def setIO(self,inputObject, outputObject):
77
78 # if not( isinstance(inputObject, Voltage) ):
79 # print 'InputObject must be an instance from Voltage()'
80 # sys.exit(0)
81
78
82 if not( isinstance(outputObject, Spectra) ):
79 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
83 print 'OutputObject must be an instance from Spectra()'
84 sys.exit(0)
85
80
86 self.dataInObj = inputObject
81 if dataInObj == None:
87 self.dataOutObj = outputObject
82 raise ValueError, ""
88
83
89 def setup(self,nFFTPoints=None, pairList=None):
90 if nFFTPoints == None:
84 if nFFTPoints == None:
91 nFFTPoints = self.dataOutObj.nFFTPoints
85 raise ValueError, ""
86
87 self.dataInObj = dataInObj
92
88
89 if dataOutObj == None:
90 dataOutObj = Spectra()
91
92 self.dataOutObj = dataOutObj
93 self.noiseObj = Noise()
94
95 ##########################################
93 self.nFFTPoints = nFFTPoints
96 self.nFFTPoints = nFFTPoints
97 self.nChannels = self.dataInObj.nChannels
98 self.nHeights = self.dataInObj.nHeights
94 self.pairList = pairList
99 self.pairList = pairList
100 if pairList != None:
101 self.nPairs = len(pairList)
102 else:
103 self.nPairs = 0
104
105 self.dataOutObj.heightList = self.dataInObj.heightList
106 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
107 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
108 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
109 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
110 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
111
112 self.dataOutObj.dataType = self.dataInObj.dataType
113 self.dataOutObj.nPairs = self.nPairs
114 self.dataOutObj.nChannels = self.nChannels
115 self.dataOutObj.nProfiles = self.nFFTPoints
116 self.dataOutObj.nHeights = self.nHeights
117 self.dataOutObj.nFFTPoints = self.nFFTPoints
118 #self.dataOutObj.data = None
119
120 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
121 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
122
123 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
124 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
125 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
126 self.dataOutObj.m_ProcessingHeader.shif_fft = True
127
128 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
129 k = 0
130 for i in range( 0,self.nChannels*2,2 ):
131 spectraComb[i] = k
132 spectraComb[i+1] = k
133 k += 1
134
135 k *= 2
136
137 if self.pairList != None:
138
139 for pair in self.pairList:
140 spectraComb[k] = pair[0]
141 spectraComb[k+1] = pair[1]
142 k += 2
143
144 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
145
146 return self.dataOutObj
95
147
96 # def init(self, nFFTPoints, pairList=None):
97 def init(self):
148 def init(self):
98
149
99 self.integratorObjIndex = 0
150 self.integratorObjIndex = 0
100 self.decoderObjIndex = 0
151 self.decoderObjIndex = 0
101 self.writerObjIndex = 0
152 self.writerObjIndex = 0
102 self.plotterObjIndex = 0
153 self.plotterObjIndex = 0
103
154
104 # if nFFTPoints == None:
155 if self.dataInObj.type == "Voltage":
105 # nFFTPoints = self.dataOutObj.nFFTPoints
156
106 #
157 if self.buffer == None:
107 # self.nFFTPoints = nFFTPoints
158 self.buffer = numpy.zeros((self.nChannels,
108 # self.pairList = pairList
159 self.nFFTPoints,
109 #
160 self.nHeights),
110 if not( isinstance(self.dataInObj, Spectra) ):
161 dtype='complex')
111 self.__getFft()
162
112 else:
163 self.buffer[:,self.profIndex,:] = self.dataInObj.data
164 self.profIndex += 1
165
166 if self.profIndex == self.nFFTPoints:
167 self.__getFft()
168 self.dataOutObj.flagNoData = False
169
170 self.buffer = None
171 self.profIndex = 0
172 return
173
174 self.dataOutObj.flagNoData = True
175
176 return
177
178 #Other kind of data
179 if self.dataInObj.type == "Spectra":
113 self.dataOutObj.copy(self.dataInObj)
180 self.dataOutObj.copy(self.dataInObj)
114
181 self.dataOutObj.flagNoData = False
115
182 return
183
184 raise ValueError, "The datatype is not valid"
185
116 def __getFft(self):
186 def __getFft(self):
117 """
187 """
118 Convierte valores de Voltaje a Spectra
188 Convierte valores de Voltaje a Spectra
119
189
120 Affected:
190 Affected:
121 self.dataOutObj.data_spc
191 self.dataOutObj.data_spc
122 self.dataOutObj.data_cspc
192 self.dataOutObj.data_cspc
123 self.dataOutObj.data_dc
193 self.dataOutObj.data_dc
124 self.dataOutObj.heightList
194 self.dataOutObj.heightList
125 self.dataOutObj.m_BasicHeader
195 self.dataOutObj.m_BasicHeader
126 self.dataOutObj.m_ProcessingHeader
196 self.dataOutObj.m_ProcessingHeader
127 self.dataOutObj.m_RadarControllerHeader
197 self.dataOutObj.m_RadarControllerHeader
128 self.dataOutObj.m_SystemHeader
198 self.dataOutObj.m_SystemHeader
129 self.ptsId
199 self.profIndex
130 self.buffer
200 self.buffer
131 self.dataOutObj.flagNoData
201 self.dataOutObj.flagNoData
132 self.dataOutObj.dataType
202 self.dataOutObj.dataType
133 self.dataOutObj.nPairs
203 self.dataOutObj.nPairs
134 self.dataOutObj.nChannels
204 self.dataOutObj.nChannels
135 self.dataOutObj.nProfiles
205 self.dataOutObj.nProfiles
136 self.dataOutObj.m_SystemHeader.numChannels
206 self.dataOutObj.m_SystemHeader.numChannels
137 self.dataOutObj.m_ProcessingHeader.totalSpectra
207 self.dataOutObj.m_ProcessingHeader.totalSpectra
138 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
208 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
139 self.dataOutObj.m_ProcessingHeader.numHeights
209 self.dataOutObj.m_ProcessingHeader.numHeights
140 self.dataOutObj.m_ProcessingHeader.spectraComb
210 self.dataOutObj.m_ProcessingHeader.spectraComb
141 self.dataOutObj.m_ProcessingHeader.shif_fft
211 self.dataOutObj.m_ProcessingHeader.shif_fft
142 """
212 """
143 if self.dataInObj.flagNoData:
213 if self.dataInObj.flagNoData:
144 return 0
214 return 0
145
146 blocksize = 0
147 nFFTPoints = self.nFFTPoints
148 nChannels, nheis = self.dataInObj.data.shape
149
150 if self.buffer == None:
151 self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex')
152
153 self.buffer[:,self.ptsId,:] = self.dataInObj.data
154 self.ptsId += 1
155
156 if self.ptsId < self.nFFTPoints:
157 self.dataOutObj.flagNoData = True
158 return
159
215
160 fft_volt = numpy.fft.fft(self.buffer,axis=1)
216 fft_volt = numpy.fft.fft(self.buffer,axis=1)
161 dc = fft_volt[:,0,:]
217 dc = fft_volt[:,0,:]
162
218
163 #calculo de self-spectra
219 #calculo de self-spectra
164 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
220 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
165 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
221 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
166
222
223 blocksize = 0
167 blocksize += dc.size
224 blocksize += dc.size
168 blocksize += spc.size
225 blocksize += spc.size
169
226
170 cspc = None
227 cspc = None
171 nPair = 0
228 pairIndex = 0
172 if self.pairList != None:
229 if self.pairList != None:
173 #calculo de cross-spectra
230 #calculo de cross-spectra
174 nPairs = len(self.pairList)
231 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
175 cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex')
176 for pair in self.pairList:
232 for pair in self.pairList:
177 cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
233 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
178 nPair += 1
234 pairIndex += 1
179 blocksize += cspc.size
235 blocksize += cspc.size
180
236
181 self.dataOutObj.data_spc = spc
237 self.dataOutObj.data_spc = spc
182 self.dataOutObj.data_cspc = cspc
238 self.dataOutObj.data_cspc = cspc
183 self.dataOutObj.data_dc = dc
239 self.dataOutObj.data_dc = dc
184
185 self.ptsId = 0
186 self.buffer = None
187 self.dataOutObj.flagNoData = False
188
189 self.dataOutObj.heightList = self.dataInObj.heightList
190 self.dataOutObj.channelList = self.dataInObj.channelList
191 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
192 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
193 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
194 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
195
196 self.dataOutObj.dataType = self.dataInObj.dataType
197 self.dataOutObj.nPairs = nPair
198 self.dataOutObj.nChannels = nChannels
199 self.dataOutObj.nProfiles = nFFTPoints
200 self.dataOutObj.nHeights = nheis
201 self.dataOutObj.nFFTPoints = nFFTPoints
202 #self.dataOutObj.data = None
203
204 self.dataOutObj.m_SystemHeader.numChannels = nChannels
205 self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints
206
207 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
240 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
208 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair
209 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints
210 self.dataOutObj.m_ProcessingHeader.numHeights = nheis
211 self.dataOutObj.m_ProcessingHeader.shif_fft = True
212
213 spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1'))
214 k = 0
215 for i in range( 0,nChannels*2,2 ):
216 spectraComb[i] = k
217 spectraComb[i+1] = k
218 k += 1
219
220 k *= 2
221
222 if self.pairList != None:
223
224 for pair in self.pairList:
225 spectraComb[k] = pair[0]
226 spectraComb[k+1] = pair[1]
227 k += 2
228
229 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
230
241
231
242
232 def addWriter(self,wrpath):
243 def addWriter(self,wrpath):
233 objWriter = SpectraWriter(self.dataOutObj)
244 objWriter = SpectraWriter(self.dataOutObj)
234 objWriter.setup(wrpath)
245 objWriter.setup(wrpath)
235 self.writerObjList.append(objWriter)
246 self.writerObjList.append(objWriter)
236
247
237
248
238 def addPlotter(self, index=None):
249 def addPlotter(self, index=None):
239
250
240 if index==None:
251 if index==None:
241 index = self.plotterObjIndex
252 index = self.plotterObjIndex
242
253
243 plotObj = Spectrum(self.dataOutObj, index)
254 plotObj = Spectrum(self.dataOutObj, index)
244 self.plotterObjList.append(plotObj)
255 self.plotterObjList.append(plotObj)
245
256
246
257
247 def addIntegrator(self,N,timeInterval):
258 def addIntegrator(self,N,timeInterval):
248
259
249 objIncohInt = IncoherentIntegration(N,timeInterval)
260 objIncohInt = IncoherentIntegration(N,timeInterval)
250 self.integratorObjList.append(objIncohInt)
261 self.integratorObjList.append(objIncohInt)
251
262
252 def writeData(self, wrpath):
263 def writeData(self, wrpath):
253 if self.dataOutObj.flagNoData:
264 if self.dataOutObj.flagNoData:
254 return 0
265 return 0
255
266
256 if len(self.writerObjList) <= self.writerObjIndex:
267 if len(self.writerObjList) <= self.writerObjIndex:
257 self.addWriter(wrpath)
268 self.addWriter(wrpath)
258
269
259 self.writerObjList[self.writerObjIndex].putData()
270 self.writerObjList[self.writerObjIndex].putData()
260
271
261 self.writerObjIndex += 1
272 self.writerObjIndex += 1
262
273
263 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
274 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
264 if self.dataOutObj.flagNoData:
275 if self.dataOutObj.flagNoData:
265 return 0
276 return 0
266
277
267 if len(self.plotterObjList) <= self.plotterObjIndex:
278 if len(self.plotterObjList) <= self.plotterObjIndex:
268 self.addPlotter(index)
279 self.addPlotter(index)
269
280
270 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
281 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
271
282
272 self.plotterObjIndex += 1
283 self.plotterObjIndex += 1
273
284
274 def integrator(self, N=None, timeInterval=None):
285 def integrator(self, N=None, timeInterval=None):
275
286
276 if self.dataOutObj.flagNoData:
287 if self.dataOutObj.flagNoData:
277 return 0
288 return 0
278
289
279 if len(self.integratorObjList) <= self.integratorObjIndex:
290 if len(self.integratorObjList) <= self.integratorObjIndex:
280 self.addIntegrator(N,timeInterval)
291 self.addIntegrator(N,timeInterval)
281
292
282 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
293 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
283 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
294 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
284
295
285 if myIncohIntObj.isReady:
296 if myIncohIntObj.isReady:
286 self.dataOutObj.data_spc = myIncohIntObj.data
297 self.dataOutObj.data_spc = myIncohIntObj.data
287 self.dataOutObj.nAvg = myIncohIntObj.navg
298 self.dataOutObj.nAvg = myIncohIntObj.navg
288 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
299 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
289 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
300 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
290 self.dataOutObj.flagNoData = False
301 self.dataOutObj.flagNoData = False
291
302
303 self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
304 # self.getNoise(type="sort", parm=16)
305
292 else:
306 else:
293 self.dataOutObj.flagNoData = True
307 self.dataOutObj.flagNoData = True
294
308
295 self.integratorObjIndex += 1
309 self.integratorObjIndex += 1
296
310
311 """Calcular el ruido"""
312 # self.getNoise(type="hildebrand", parm=1)
313
297 def removeDC(self, type):
314 def removeDC(self, type):
298
315
299 if self.dataOutObj.flagNoData:
316 if self.dataOutObj.flagNoData:
300 return 0
317 return 0
301 pass
302
318
303 def removeInterference(self):
319 def removeInterference(self):
304
320
305 if self.dataOutObj.flagNoData:
321 if self.dataOutObj.flagNoData:
306 return 0
322 return 0
307 pass
308
323
309 def removeSatellites(self):
324 def removeSatellites(self):
310
325
311 if self.dataOutObj.flagNoData:
326 if self.dataOutObj.flagNoData:
312 return 0
327 return 0
313 pass
314
328
315 def selectChannels(self, channelList, pairList=None):
329 def getNoise(self, type="hildebrand", parm=None):
330
331 self.noiseObj.setNoise(self.dataOutObj.data_spc)
332
333 if type == "hildebrand":
334 noise = self.noiseObj.byHildebrand(parm)
335
336 if type == "window":
337 noise = self.noiseObj.byWindow(parm)
338
339 if type == "sort":
340 noise = self.noiseObj.bySort(parm)
341
342 self.dataOutObj.noise = noise
343 print 10*numpy.log10(noise)
344
345 def selectChannels(self, channelList, pairList=[]):
346
347 channelIndexList = []
348
349 for channel in channelList:
350 if channel in self.dataOutObj.channelList:
351 index = self.dataOutObj.channelList.index(channel)
352 channelIndexList.append(index)
353
354 pairIndexList = []
355
356 for pair in pairList:
357 if pair in self.dataOutObj.pairList:
358 index = self.dataOutObj.pairList.index(pair)
359 pairIndexList.append(index)
360
361 self.selectChannelsByIndex(channelIndexList, pairIndexList)
362
363 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
316 """
364 """
317 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
365 Selecciona un bloque de datos en base a canales y pares segun el
366 channelIndexList y el pairIndexList
318
367
319 Input:
368 Input:
320 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
369 channelIndexList : lista de indices de los canales a seleccionar por ej.
321 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
370
371 Si tenemos los canales
372
373 self.channelList = (2,3,5,7)
374
375 y deseamos escoger los canales (3,7)
376 entonces colocaremos el parametro
377
378 channelndexList = (1,3)
379
380 pairIndexList : tupla de indice depares que se desea selecionar por ej.
381
382 Si tenemos los pares :
383
384 ( (0,1), (0,2), (1,3), (2,5) )
385
386 y deseamos seleccionar los pares ((0,2), (2,5))
387 entonces colocaremos el parametro
388
389 pairIndexList = (1,3)
322
390
323 Affected:
391 Affected:
324 self.dataOutObj.data_spc
392 self.dataOutObj.data_spc
325 self.dataOutObj.data_cspc
393 self.dataOutObj.data_cspc
326 self.dataOutObj.data_dc
394 self.dataOutObj.data_dc
327 self.dataOutObj.nChannels
395 self.dataOutObj.nChannels
328 self.dataOutObj.nPairs
396 self.dataOutObj.nPairs
329 self.dataOutObj.m_ProcessingHeader.spectraComb
397 self.dataOutObj.m_ProcessingHeader.spectraComb
330 self.dataOutObj.m_SystemHeader.numChannels
398 self.dataOutObj.m_SystemHeader.numChannels
331
399
400 self.dataOutObj.noise
332 Return:
401 Return:
333 None
402 None
334 """
403 """
335
404
336 if self.dataOutObj.flagNoData:
405 if self.dataOutObj.flagNoData:
337 return 0
406 return 0
338
407
339 channelIndexList = []
408 if pairIndexList == []:
340 for channel in channelList:
409 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
341 if channel in self.dataOutObj.channelList:
410
342 index = self.dataOutObj.channelList.index(channel)
343 channelIndexList.append(index)
344 continue
345
346 raise ValueError, "The value %d in channelList is not valid" %channel
347
348 nProfiles = self.dataOutObj.nProfiles
349 #dataType = self.dataOutObj.dataType
350 nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights
351 blocksize = 0
352
353 #self spectra
354 nChannels = len(channelIndexList)
411 nChannels = len(channelIndexList)
355 spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] )
412 nPairs = len(pairIndexList)
356
357 for index, channel in enumerate(channelIndexList):
358 spc[index,:,:] = self.dataOutObj.data_spc[index,:,:]
359
413
360 #DC channel
414 blocksize = 0
361 dc = numpy.zeros( (nChannels,nHeights), dtype='complex' )
415 #self spectra
362 for index, channel in enumerate(channelIndexList):
416 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
363 dc[index,:] = self.dataOutObj.data_dc[channel,:]
364
365 blocksize += dc.size
366 blocksize += spc.size
417 blocksize += spc.size
367
368 nPairs = 0
369 cspc = None
370
418
371 if pairList == None:
419 cspc = None
372 pairList = self.pairList
420 if pairIndexList != []:
373
421 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
374 if (pairList != None) and (self.dataOutObj.data_cspc != None):
375 #cross spectra
376 nPairs = len(pairList)
377 cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' )
378
379 spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb
380 totalSpectra = len(spectraComb)
381 nchan = self.dataOutObj.nChannels
382 pairIndexList = []
383
384 for pair in pairList: #busco el par en la lista de pares del Spectra Combinations
385 for index in range(0,totalSpectra,2):
386 if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]:
387 pairIndexList.append( index/2 - nchan )
388
389 for index, pair in enumerate(pairIndexList):
390 cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:]
391 blocksize += cspc.size
422 blocksize += cspc.size
392
393 else:
394 pairList = self.pairList
395 cspc = self.dataOutObj.data_cspc
396 if cspc != None:
397 blocksize += cspc.size
398
423
424 #DC channel
425 dc = None
426 if self.dataOutObj.m_ProcessingHeader.flag_dc:
427 dc = self.dataOutObj.data_dc[channelIndexList,:]
428 blocksize += dc.size
429
430 #Almacenar las combinaciones de canales y cros espectros
431
399 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
432 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
400 i = 0
433 i = 0
401 for val in channelList:
434 for spcChannel in channelIndexList:
402 spectraComb[i] = val
435 spectraComb[i] = spcChannel
403 spectraComb[i+1] = val
436 spectraComb[i+1] = spcChannel
404 i += 2
437 i += 2
405
438
406 if pairList != None:
439 if pairList != None:
407 for pair in pairList:
440 for pair in pairList:
408 spectraComb[i] = pair[0]
441 spectraComb[i] = pair[0]
409 spectraComb[i+1] = pair[1]
442 spectraComb[i+1] = pair[1]
410 i += 2
443 i += 2
411
444
445 #######
446
412 self.dataOutObj.data_spc = spc
447 self.dataOutObj.data_spc = spc
413 self.dataOutObj.data_cspc = cspc
448 self.dataOutObj.data_cspc = cspc
414 self.dataOutObj.data_dc = dc
449 self.dataOutObj.data_dc = dc
415 self.dataOutObj.nChannels = nChannels
450 self.dataOutObj.nChannels = nChannels
416 self.dataOutObj.nPairs = nPairs
451 self.dataOutObj.nPairs = nPairs
417
452
418 self.dataOutObj.channelList = channelList
453 self.dataOutObj.channelIndexList = channelIndexList
419
454
420 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
455 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
421 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
456 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
422 self.dataOutObj.m_SystemHeader.numChannels = nChannels
457 self.dataOutObj.m_SystemHeader.numChannels = nChannels
423 self.dataOutObj.nChannels = nChannels
458 self.dataOutObj.nChannels = nChannels
424 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
459 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
425
460
461 if cspc == None:
462 self.dataOutObj.m_ProcessingHeader.flag_dc = False
463 if dc == None:
464 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
465
426 def selectHeightsByValue(self, minHei, maxHei):
466 def selectHeightsByValue(self, minHei, maxHei):
427 """
467 """
428 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
468 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
429 minHei <= height <= maxHei
469 minHei <= height <= maxHei
430
470
431 Input:
471 Input:
432 minHei : valor minimo de altura a considerar
472 minHei : valor minimo de altura a considerar
433 maxHei : valor maximo de altura a considerar
473 maxHei : valor maximo de altura a considerar
434
474
435 Affected:
475 Affected:
436 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
476 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
437
477
438 Return:
478 Return:
439 None
479 None
440 """
480 """
441
481
442 if self.dataOutObj.flagNoData:
482 if self.dataOutObj.flagNoData:
443 return 0
483 return 0
444
484
445 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
485 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
446 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
486 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
447
487
448 if (maxHei > self.dataOutObj.heightList[-1]):
488 if (maxHei > self.dataOutObj.heightList[-1]):
449 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
489 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
450
490
451 minIndex = 0
491 minIndex = 0
452 maxIndex = 0
492 maxIndex = 0
453 data = self.dataOutObj.heightList
493 data = self.dataOutObj.heightList
454
494
455 for i,val in enumerate(data):
495 for i,val in enumerate(data):
456 if val < minHei:
496 if val < minHei:
457 continue
497 continue
458 else:
498 else:
459 minIndex = i;
499 minIndex = i;
460 break
500 break
461
501
462 for i,val in enumerate(data):
502 for i,val in enumerate(data):
463 if val <= maxHei:
503 if val <= maxHei:
464 maxIndex = i;
504 maxIndex = i;
465 else:
505 else:
466 break
506 break
467
507
468 self.selectHeightsByIndex(minIndex, maxIndex)
508 self.selectHeightsByIndex(minIndex, maxIndex)
469
509
470 def selectHeightsByIndex(self, minIndex, maxIndex):
510 def selectHeightsByIndex(self, minIndex, maxIndex):
471 """
511 """
472 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
512 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
473 minIndex <= index <= maxIndex
513 minIndex <= index <= maxIndex
474
514
475 Input:
515 Input:
476 minIndex : valor minimo de altura a considerar
516 minIndex : valor minimo de altura a considerar
477 maxIndex : valor maximo de altura a considerar
517 maxIndex : valor maximo de altura a considerar
478
518
479 Affected:
519 Affected:
480 self.dataOutObj.data_spc
520 self.dataOutObj.data_spc
481 self.dataOutObj.data_cspc
521 self.dataOutObj.data_cspc
482 self.dataOutObj.data_dc
522 self.dataOutObj.data_dc
483 self.dataOutObj.heightList
523 self.dataOutObj.heightList
484 self.dataOutObj.nHeights
524 self.dataOutObj.nHeights
485 self.dataOutObj.m_ProcessingHeader.numHeights
525 self.dataOutObj.m_ProcessingHeader.numHeights
486 self.dataOutObj.m_ProcessingHeader.blockSize
526 self.dataOutObj.m_ProcessingHeader.blockSize
487 self.dataOutObj.m_ProcessingHeader.firstHeight
527 self.dataOutObj.m_ProcessingHeader.firstHeight
488 self.dataOutObj.m_RadarControllerHeader.numHeights
528 self.dataOutObj.m_RadarControllerHeader.numHeights
489
529
490 Return:
530 Return:
491 None
531 None
492 """
532 """
493
533
494 if self.dataOutObj.flagNoData:
534 if self.dataOutObj.flagNoData:
495 return 0
535 return 0
496
536
497 if (minIndex < 0) or (minIndex > maxIndex):
537 if (minIndex < 0) or (minIndex > maxIndex):
498 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
538 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
499
539
500 if (maxIndex >= self.dataOutObj.nHeights):
540 if (maxIndex >= self.dataOutObj.nHeights):
501 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
541 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
502
542
503 nChannels = self.dataOutObj.nChannels
543 nChannels = self.dataOutObj.nChannels
504 nPairs = self.dataOutObj.nPairs
544 nPairs = self.dataOutObj.nPairs
505 nProfiles = self.dataOutObj.nProfiles
545 nProfiles = self.dataOutObj.nProfiles
506 dataType = self.dataOutObj.dataType
546 dataType = self.dataOutObj.dataType
507 nHeights = maxIndex - minIndex + 1
547 nHeights = maxIndex - minIndex + 1
508 blockSize = 0
548 blockSize = 0
509
549
510 #self spectra
550 #self spectra
511 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
551 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
512 blockSize += spc.size
552 blockSize += spc.size
513
553
514 #cross spectra
554 #cross spectra
515 cspc = None
555 cspc = None
516 if self.dataOutObj.data_cspc != None:
556 if self.dataOutObj.data_cspc != None:
517 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
557 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
518 blockSize += cspc.size
558 blockSize += cspc.size
519
559
520 #DC channel
560 #DC channel
521 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
561 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
522 blockSize += dc.size
562 blockSize += dc.size
523
563
524 self.dataOutObj.data_spc = spc
564 self.dataOutObj.data_spc = spc
525 if cspc != None:
565 if cspc != None:
526 self.dataOutObj.data_cspc = cspc
566 self.dataOutObj.data_cspc = cspc
527 self.dataOutObj.data_dc = dc
567 self.dataOutObj.data_dc = dc
528
568
529 firstHeight = self.dataOutObj.heightList[minIndex]
569 firstHeight = self.dataOutObj.heightList[minIndex]
530
570
531 self.dataOutObj.nHeights = nHeights
571 self.dataOutObj.nHeights = nHeights
532 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
572 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
533 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
573 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
534 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
574 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
535 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
575 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
536
576
537 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
577 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
538
578
539
579
540 class IncoherentIntegration:
580 class IncoherentIntegration:
541
581
542 integ_counter = None
582 integ_counter = None
543 data = None
583 data = None
544 navg = None
584 navg = None
545 buffer = None
585 buffer = None
546 nIncohInt = None
586 nIncohInt = None
547
587
548 def __init__(self, N = None, timeInterval = None):
588 def __init__(self, N = None, timeInterval = None):
549 """
589 """
550 N
590 N
551 timeInterval - interval time [min], integer value
591 timeInterval - interval time [min], integer value
552 """
592 """
553
593
554 self.data = None
594 self.data = None
555 self.navg = None
595 self.navg = None
556 self.buffer = None
596 self.buffer = None
557 self.timeOut = None
597 self.timeOut = None
558 self.exitCondition = False
598 self.exitCondition = False
559 self.isReady = False
599 self.isReady = False
560 self.nIncohInt = N
600 self.nIncohInt = N
561 self.integ_counter = 0
601 self.integ_counter = 0
562 if timeInterval!=None:
602 if timeInterval!=None:
563 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
603 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
564
604
565 if ((timeInterval==None) and (N==None)):
605 if ((timeInterval==None) and (N==None)):
566 print 'N = None ; timeInterval = None'
606 print 'N = None ; timeInterval = None'
567 sys.exit(0)
607 sys.exit(0)
568 elif timeInterval == None:
608 elif timeInterval == None:
569 self.timeFlag = False
609 self.timeFlag = False
570 else:
610 else:
571 self.timeFlag = True
611 self.timeFlag = True
572
612
573
613
574 def exe(self,data,timeOfData):
614 def exe(self,data,timeOfData):
575 """
615 """
576 data
616 data
577
617
578 timeOfData [seconds]
618 timeOfData [seconds]
579 """
619 """
580
620
581 if self.timeFlag:
621 if self.timeFlag:
582 if self.timeOut == None:
622 if self.timeOut == None:
583 self.timeOut = timeOfData + self.timeIntervalInSeconds
623 self.timeOut = timeOfData + self.timeIntervalInSeconds
584
624
585 if timeOfData < self.timeOut:
625 if timeOfData < self.timeOut:
586 if self.buffer == None:
626 if self.buffer == None:
587 self.buffer = data
627 self.buffer = data
588 else:
628 else:
589 self.buffer = self.buffer + data
629 self.buffer = self.buffer + data
590 self.integ_counter += 1
630 self.integ_counter += 1
591 else:
631 else:
592 self.exitCondition = True
632 self.exitCondition = True
593
633
594 else:
634 else:
595 if self.integ_counter < self.nIncohInt:
635 if self.integ_counter < self.nIncohInt:
596 if self.buffer == None:
636 if self.buffer == None:
597 self.buffer = data
637 self.buffer = data
598 else:
638 else:
599 self.buffer = self.buffer + data
639 self.buffer = self.buffer + data
600
640
601 self.integ_counter += 1
641 self.integ_counter += 1
602
642
603 if self.integ_counter == self.nIncohInt:
643 if self.integ_counter == self.nIncohInt:
604 self.exitCondition = True
644 self.exitCondition = True
605
645
606 if self.exitCondition:
646 if self.exitCondition:
607 self.data = self.buffer
647 self.data = self.buffer
608 self.navg = self.integ_counter
648 self.navg = self.integ_counter
609 self.isReady = True
649 self.isReady = True
610 self.buffer = None
650 self.buffer = None
611 self.timeOut = None
651 self.timeOut = None
612 self.integ_counter = 0
652 self.integ_counter = 0
613 self.exitCondition = False
653 self.exitCondition = False
614
654
615 if self.timeFlag:
655 if self.timeFlag:
616 self.buffer = data
656 self.buffer = data
617 self.timeOut = timeOfData + self.timeIntervalInSeconds
657 self.timeOut = timeOfData + self.timeIntervalInSeconds
618 else:
658 else:
619 self.isReady = False
659 self.isReady = False
620 No newline at end of file
660
@@ -1,591 +1,585
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
8 import os, sys
9 import numpy
9 import numpy
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Model.Voltage import Voltage
14 from Model.Voltage import Voltage
15 from IO.VoltageIO import VoltageWriter
15 from IO.VoltageIO import VoltageWriter
16 from Graphics.VoltagePlot import Osciloscope
16 from Graphics.VoltagePlot import Osciloscope
17
17
18 class VoltageProcessor:
18 class VoltageProcessor:
19 '''
19 '''
20 classdocs
20 classdocs
21 '''
21 '''
22
22
23 dataInObj = None
23 dataInObj = None
24 dataOutObj = None
24 dataOutObj = None
25
25
26 integratorObjIndex = None
26 integratorObjIndex = None
27 decoderObjIndex = None
27 decoderObjIndex = None
28 profSelectorObjIndex = None
28 profSelectorObjIndex = None
29 writerObjIndex = None
29 writerObjIndex = None
30 plotterObjIndex = None
30 plotterObjIndex = None
31 flipIndex = None
31 flipIndex = None
32
32
33 integratorObjList = []
33 integratorObjList = []
34 decoderObjList = []
34 decoderObjList = []
35 profileSelectorObjList = []
35 profileSelectorObjList = []
36 writerObjList = []
36 writerObjList = []
37 plotterObjList = []
37 plotterObjList = []
38 m_Voltage= Voltage()
38 m_Voltage= Voltage()
39
39
40 def __init__(self, dataInObj=None, dataOutObj=None):
40 def __init__(self):
41 '''
41 '''
42 Constructor
42 Constructor
43 '''
43 '''
44
45 self.dataInObj = dataInObj
46
47 if dataOutObj == None:
48 self.dataOutObj = Voltage()
49 else:
50 self.dataOutObj = dataOutObj
51
44
52 self.integratorObjIndex = None
45 self.integratorObjIndex = None
53 self.decoderObjIndex = None
46 self.decoderObjIndex = None
54 self.profSelectorObjIndex = None
47 self.profSelectorObjIndex = None
55 self.writerObjIndex = None
48 self.writerObjIndex = None
56 self.plotterObjIndex = None
49 self.plotterObjIndex = None
57 self.flipIndex = 1
50 self.flipIndex = 1
58 self.integratorObjList = []
51 self.integratorObjList = []
59 self.decoderObjList = []
52 self.decoderObjList = []
60 self.profileSelectorObjList = []
53 self.profileSelectorObjList = []
61 self.writerObjList = []
54 self.writerObjList = []
62 self.plotterObjList = []
55 self.plotterObjList = []
63
64 def setIO(self,inputObject, outputObject):
65
56
66 if not( isinstance(inputObject, Voltage) ):
57 def setup(self, dataInObj=None, dataOutObj=None):
67 print 'InputObject must be an instance from Voltage()'
68 sys.exit(0)
69
58
70 if not( isinstance(outputObject, Voltage) ):
59 self.dataInObj = dataInObj
71 print 'OutputObject must be an instance from Voltage()'
60
72 sys.exit(0)
61 if dataOutObj == None:
62 dataOutObj = Voltage()
73
63
74 self.dataInObj = inputObject
64 dataOutObj.copy(dataInObj)
75 self.dataOutObj = outputObject
65
66 self.dataOutObj = dataOutObj
67
68 return self.dataOutObj
76
69
77 def setup(self):
78 pass
79
70
80 def init(self):
71 def init(self):
81
72
82 self.integratorObjIndex = 0
73 self.integratorObjIndex = 0
83 self.decoderObjIndex = 0
74 self.decoderObjIndex = 0
84 self.profSelectorObjIndex = 0
75 self.profSelectorObjIndex = 0
85 self.writerObjIndex = 0
76 self.writerObjIndex = 0
86 self.plotterObjIndex = 0
77 self.plotterObjIndex = 0
87 self.dataOutObj.copy(self.dataInObj)
78 self.dataOutObj.copy(self.dataInObj)
88
79
89 if self.profSelectorObjIndex != None:
80 if self.profSelectorObjIndex != None:
90 for profSelObj in self.profileSelectorObjList:
81 for profSelObj in self.profileSelectorObjList:
91 profSelObj.incIndex()
82 profSelObj.incIndex()
92
83
93 def addWriter(self, wrpath):
84 def addWriter(self, wrpath):
94 objWriter = VoltageWriter(self.dataOutObj)
85 objWriter = VoltageWriter(self.dataOutObj)
95 objWriter.setup(wrpath)
86 objWriter.setup(wrpath)
96 self.writerObjList.append(objWriter)
87 self.writerObjList.append(objWriter)
97
88
98 def addPlotter(self, index=None):
89 def addPlotter(self, index=None):
99 if index==None:
90 if index==None:
100 index = self.plotterObjIndex
91 index = self.plotterObjIndex
101
92
102 plotObj = Osciloscope(self.dataOutObj, index)
93 plotObj = Osciloscope(self.dataOutObj, index)
103 self.plotterObjList.append(plotObj)
94 self.plotterObjList.append(plotObj)
104
95
105 def addIntegrator(self, N,timeInterval):
96 def addIntegrator(self, N,timeInterval):
106
97
107 objCohInt = CoherentIntegrator(N,timeInterval)
98 objCohInt = CoherentIntegrator(N,timeInterval)
108 self.integratorObjList.append(objCohInt)
99 self.integratorObjList.append(objCohInt)
109
100
110 def addDecoder(self, code, ncode, nbaud):
101 def addDecoder(self, code, ncode, nbaud):
111
102
112 objDecoder = Decoder(code,ncode,nbaud)
103 objDecoder = Decoder(code,ncode,nbaud)
113 self.decoderObjList.append(objDecoder)
104 self.decoderObjList.append(objDecoder)
114
105
115 def addProfileSelector(self, nProfiles):
106 def addProfileSelector(self, nProfiles):
116
107
117 objProfSelector = ProfileSelector(nProfiles)
108 objProfSelector = ProfileSelector(nProfiles)
118 self.profileSelectorObjList.append(objProfSelector)
109 self.profileSelectorObjList.append(objProfSelector)
119
110
120 def writeData(self,wrpath):
111 def writeData(self,wrpath):
121
112
122 if self.dataOutObj.flagNoData:
113 if self.dataOutObj.flagNoData:
123 return 0
114 return 0
124
115
125 if len(self.writerObjList) <= self.writerObjIndex:
116 if len(self.writerObjList) <= self.writerObjIndex:
126 self.addWriter(wrpath)
117 self.addWriter(wrpath)
127
118
128 self.writerObjList[self.writerObjIndex].putData()
119 self.writerObjList[self.writerObjIndex].putData()
129
120
130 # myWrObj = self.writerObjList[self.writerObjIndex]
121 # myWrObj = self.writerObjList[self.writerObjIndex]
131 # myWrObj.putData()
122 # myWrObj.putData()
132
123
133 self.writerObjIndex += 1
124 self.writerObjIndex += 1
134
125
135 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None):
126 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None):
136 if self.dataOutObj.flagNoData:
127 if self.dataOutObj.flagNoData:
137 return 0
128 return 0
138
129
139 if len(self.plotterObjList) <= self.plotterObjIndex:
130 if len(self.plotterObjList) <= self.plotterObjIndex:
140 self.addPlotter(index)
131 self.addPlotter(index)
141
132
142 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle)
133 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle)
143
134
144 self.plotterObjIndex += 1
135 self.plotterObjIndex += 1
145
136
146 def integrator(self, N=None, timeInterval=None):
137 def integrator(self, N=None, timeInterval=None):
147
138
148 if self.dataOutObj.flagNoData:
139 if self.dataOutObj.flagNoData:
149 return 0
140 return 0
150
141
151 if len(self.integratorObjList) <= self.integratorObjIndex:
142 if len(self.integratorObjList) <= self.integratorObjIndex:
152 self.addIntegrator(N,timeInterval)
143 self.addIntegrator(N,timeInterval)
153
144
154 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
145 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
155 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=self.dataOutObj.m_BasicHeader.utc)
146 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=self.dataOutObj.m_BasicHeader.utc)
156
147
157 if myCohIntObj.isReady:
148 if myCohIntObj.isReady:
158 self.dataOutObj.data = myCohIntObj.data
149 self.dataOutObj.data = myCohIntObj.data
159 self.dataOutObj.nAvg = myCohIntObj.navg
150 self.dataOutObj.nAvg = myCohIntObj.navg
160 self.dataOutObj.m_ProcessingHeader.coherentInt *= myCohIntObj.navg
151 self.dataOutObj.m_ProcessingHeader.coherentInt *= myCohIntObj.navg
161 #print "myCohIntObj.navg: ",myCohIntObj.navg
152 #print "myCohIntObj.navg: ",myCohIntObj.navg
162 self.dataOutObj.flagNoData = False
153 self.dataOutObj.flagNoData = False
163
154
164 else:
155 else:
165 self.dataOutObj.flagNoData = True
156 self.dataOutObj.flagNoData = True
166
157
167 self.integratorObjIndex += 1
158 self.integratorObjIndex += 1
168
159
169 def decoder(self,code=None,type = 0):
160 def decoder(self,code=None,type = 0):
170
161
171 if self.dataOutObj.flagNoData:
162 if self.dataOutObj.flagNoData:
172 return 0
163 return 0
173
164
174 if code == None:
165 if code == None:
175 code = self.dataOutObj.m_RadarControllerHeader.code
166 code = self.dataOutObj.m_RadarControllerHeader.code
176 ncode, nbaud = code.shape
167 ncode, nbaud = code.shape
177
168
178 if len(self.decoderObjList) <= self.decoderObjIndex:
169 if len(self.decoderObjList) <= self.decoderObjIndex:
179 self.addDecoder(code,ncode,nbaud)
170 self.addDecoder(code,ncode,nbaud)
180
171
181 myDecodObj = self.decoderObjList[self.decoderObjIndex]
172 myDecodObj = self.decoderObjList[self.decoderObjIndex]
182 myDecodObj.exe(data=self.dataOutObj.data,type=type)
173 myDecodObj.exe(data=self.dataOutObj.data,type=type)
183
174
184 if myDecodObj.flag:
175 if myDecodObj.flag:
185 self.dataOutObj.data = myDecodObj.data
176 self.dataOutObj.data = myDecodObj.data
186 self.dataOutObj.flagNoData = False
177 self.dataOutObj.flagNoData = False
187 else:
178 else:
188 self.dataOutObj.flagNoData = True
179 self.dataOutObj.flagNoData = True
189
180
190 self.decoderObjIndex += 1
181 self.decoderObjIndex += 1
191
182
192
183
193 def filterByHei(self, window):
184 def filterByHei(self, window):
194 if window == None:
185 if window == None:
195 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
186 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
196
187
197 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
188 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
198 dim1 = self.dataOutObj.data.shape[0]
189 dim1 = self.dataOutObj.data.shape[0]
199 dim2 = self.dataOutObj.data.shape[1]
190 dim2 = self.dataOutObj.data.shape[1]
200 r = dim2 % window
191 r = dim2 % window
201
192
202 buffer = self.dataOutObj.data[:,0:dim2-r]
193 buffer = self.dataOutObj.data[:,0:dim2-r]
203 buffer = buffer.reshape(dim1,dim2/window,window)
194 buffer = buffer.reshape(dim1,dim2/window,window)
204 buffer = numpy.sum(buffer,2)
195 buffer = numpy.sum(buffer,2)
205 self.dataOutObj.data = buffer
196 self.dataOutObj.data = buffer
206
197
207 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
198 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
208 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
199 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
209
200
210 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
201 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
211
202
212 #self.dataOutObj.heightList es un numpy.array
203 #self.dataOutObj.heightList es un numpy.array
213 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
204 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
214
205
215 def deFlip(self):
206 def deFlip(self):
216 self.dataOutObj.data *= self.flipIndex
207 self.dataOutObj.data *= self.flipIndex
217 self.flipIndex *= -1.
208 self.flipIndex *= -1.
218
209
219 def selectChannels(self, channelList):
210 def selectChannels(self, channelList):
211 pass
212
213 def selectChannelsByIndex(self, channelIndexList):
220 """
214 """
221 Selecciona un bloque de datos en base a canales segun el channelList
215 Selecciona un bloque de datos en base a canales segun el channelIndexList
222
216
223 Input:
217 Input:
224 channelList : lista sencilla de canales a seleccionar por ej. [2,3,7]
218 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
225
219
226 Affected:
220 Affected:
227 self.dataOutObj.data
221 self.dataOutObj.data
228 self.dataOutObj.channelList
222 self.dataOutObj.channelIndexList
229 self.dataOutObj.nChannels
223 self.dataOutObj.nChannels
230 self.dataOutObj.m_ProcessingHeader.totalSpectra
224 self.dataOutObj.m_ProcessingHeader.totalSpectra
231 self.dataOutObj.m_SystemHeader.numChannels
225 self.dataOutObj.m_SystemHeader.numChannels
232 self.dataOutObj.m_ProcessingHeader.blockSize
226 self.dataOutObj.m_ProcessingHeader.blockSize
233
227
234 Return:
228 Return:
235 None
229 None
236 """
230 """
237 if self.dataOutObj.flagNoData:
231 if self.dataOutObj.flagNoData:
238 return 0
232 return 0
239
233
240 for channel in channelList:
234 for channel in channelIndexList:
241 if channel not in self.dataOutObj.channelList:
235 if channel not in self.dataOutObj.channelIndexList:
242 raise ValueError, "The value %d in channelList is not valid" %channel
236 raise ValueError, "The value %d in channelIndexList is not valid" %channel
243
237
244 nChannels = len(channelList)
238 nChannels = len(channelIndexList)
245
239
246 data = self.dataOutObj.data[channelList,:]
240 data = self.dataOutObj.data[channelIndexList,:]
247
241
248 self.dataOutObj.data = data
242 self.dataOutObj.data = data
249 self.dataOutObj.channelList = channelList
243 self.dataOutObj.channelIndexList = channelIndexList
250 self.dataOutObj.nChannels = nChannels
244 self.dataOutObj.nChannels = nChannels
251
245
252 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels
246 self.dataOutObj.m_ProcessingHeader.totalSpectra = 0
253 self.dataOutObj.m_SystemHeader.numChannels = nChannels
247 self.dataOutObj.m_SystemHeader.numChannels = nChannels
254 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
248 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
255 return 1
249 return 1
256
250
257
251
258 def selectHeightsByValue(self, minHei, maxHei):
252 def selectHeightsByValue(self, minHei, maxHei):
259 """
253 """
260 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
254 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
261 minHei <= height <= maxHei
255 minHei <= height <= maxHei
262
256
263 Input:
257 Input:
264 minHei : valor minimo de altura a considerar
258 minHei : valor minimo de altura a considerar
265 maxHei : valor maximo de altura a considerar
259 maxHei : valor maximo de altura a considerar
266
260
267 Affected:
261 Affected:
268 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
262 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
269
263
270 Return:
264 Return:
271 1 si el metodo se ejecuto con exito caso contrario devuelve 0
265 1 si el metodo se ejecuto con exito caso contrario devuelve 0
272 """
266 """
273 if self.dataOutObj.flagNoData:
267 if self.dataOutObj.flagNoData:
274 return 0
268 return 0
275
269
276 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
270 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
277 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
271 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
278
272
279 if (maxHei > self.dataOutObj.heightList[-1]):
273 if (maxHei > self.dataOutObj.heightList[-1]):
280 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
274 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
281
275
282 minIndex = 0
276 minIndex = 0
283 maxIndex = 0
277 maxIndex = 0
284 data = self.dataOutObj.heightList
278 data = self.dataOutObj.heightList
285
279
286 for i,val in enumerate(data):
280 for i,val in enumerate(data):
287 if val < minHei:
281 if val < minHei:
288 continue
282 continue
289 else:
283 else:
290 minIndex = i;
284 minIndex = i;
291 break
285 break
292
286
293 for i,val in enumerate(data):
287 for i,val in enumerate(data):
294 if val <= maxHei:
288 if val <= maxHei:
295 maxIndex = i;
289 maxIndex = i;
296 else:
290 else:
297 break
291 break
298
292
299 self.selectHeightsByIndex(minIndex, maxIndex)
293 self.selectHeightsByIndex(minIndex, maxIndex)
300 return 1
294 return 1
301
295
302
296
303 def selectHeightsByIndex(self, minIndex, maxIndex):
297 def selectHeightsByIndex(self, minIndex, maxIndex):
304 """
298 """
305 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
299 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
306 minIndex <= index <= maxIndex
300 minIndex <= index <= maxIndex
307
301
308 Input:
302 Input:
309 minIndex : valor de indice minimo de altura a considerar
303 minIndex : valor de indice minimo de altura a considerar
310 maxIndex : valor de indice maximo de altura a considerar
304 maxIndex : valor de indice maximo de altura a considerar
311
305
312 Affected:
306 Affected:
313 self.dataOutObj.data
307 self.dataOutObj.data
314 self.dataOutObj.heightList
308 self.dataOutObj.heightList
315 self.dataOutObj.nHeights
309 self.dataOutObj.nHeights
316 self.dataOutObj.m_ProcessingHeader.blockSize
310 self.dataOutObj.m_ProcessingHeader.blockSize
317 self.dataOutObj.m_ProcessingHeader.numHeights
311 self.dataOutObj.m_ProcessingHeader.numHeights
318 self.dataOutObj.m_ProcessingHeader.firstHeight
312 self.dataOutObj.m_ProcessingHeader.firstHeight
319 self.dataOutObj.m_RadarControllerHeader
313 self.dataOutObj.m_RadarControllerHeader
320
314
321 Return:
315 Return:
322 1 si el metodo se ejecuto con exito caso contrario devuelve 0
316 1 si el metodo se ejecuto con exito caso contrario devuelve 0
323 """
317 """
324 if self.dataOutObj.flagNoData:
318 if self.dataOutObj.flagNoData:
325 return 0
319 return 0
326
320
327 if (minIndex < 0) or (minIndex > maxIndex):
321 if (minIndex < 0) or (minIndex > maxIndex):
328 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
322 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
329
323
330 if (maxIndex >= self.dataOutObj.nHeights):
324 if (maxIndex >= self.dataOutObj.nHeights):
331 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
325 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
332
326
333 nHeights = maxIndex - minIndex + 1
327 nHeights = maxIndex - minIndex + 1
334
328
335 #voltage
329 #voltage
336 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
330 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
337
331
338 firstHeight = self.dataOutObj.heightList[minIndex]
332 firstHeight = self.dataOutObj.heightList[minIndex]
339
333
340 self.dataOutObj.data = data
334 self.dataOutObj.data = data
341 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
335 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
342 self.dataOutObj.nHeights = nHeights
336 self.dataOutObj.nHeights = nHeights
343 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
337 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
344 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
338 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
345 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
339 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
346 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
340 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
347 return 1
341 return 1
348
342
349 def selectProfilesByValue(self,indexList, nProfiles):
343 def selectProfilesByValue(self,indexList, nProfiles):
350 if self.dataOutObj.flagNoData:
344 if self.dataOutObj.flagNoData:
351 return 0
345 return 0
352
346
353 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
347 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
354 self.addProfileSelector(nProfiles)
348 self.addProfileSelector(nProfiles)
355
349
356 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
350 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
357
351
358 if not(profileSelectorObj.isProfileInList(indexList)):
352 if not(profileSelectorObj.isProfileInList(indexList)):
359 self.dataOutObj.flagNoData = True
353 self.dataOutObj.flagNoData = True
360 self.profSelectorObjIndex += 1
354 self.profSelectorObjIndex += 1
361 return 0
355 return 0
362
356
363 self.dataOutObj.flagNoData = False
357 self.dataOutObj.flagNoData = False
364 self.profSelectorObjIndex += 1
358 self.profSelectorObjIndex += 1
365
359
366 return 1
360 return 1
367
361
368
362
369 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
363 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
370 """
364 """
371 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
365 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
372 minIndex <= index <= maxIndex
366 minIndex <= index <= maxIndex
373
367
374 Input:
368 Input:
375 minIndex : valor de indice minimo de perfil a considerar
369 minIndex : valor de indice minimo de perfil a considerar
376 maxIndex : valor de indice maximo de perfil a considerar
370 maxIndex : valor de indice maximo de perfil a considerar
377 nProfiles : numero de profiles
371 nProfiles : numero de profiles
378
372
379 Affected:
373 Affected:
380 self.dataOutObj.flagNoData
374 self.dataOutObj.flagNoData
381 self.profSelectorObjIndex
375 self.profSelectorObjIndex
382
376
383 Return:
377 Return:
384 1 si el metodo se ejecuto con exito caso contrario devuelve 0
378 1 si el metodo se ejecuto con exito caso contrario devuelve 0
385 """
379 """
386
380
387 if self.dataOutObj.flagNoData:
381 if self.dataOutObj.flagNoData:
388 return 0
382 return 0
389
383
390 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
384 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
391 self.addProfileSelector(nProfiles)
385 self.addProfileSelector(nProfiles)
392
386
393 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
387 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
394
388
395 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
389 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
396 self.dataOutObj.flagNoData = True
390 self.dataOutObj.flagNoData = True
397 self.profSelectorObjIndex += 1
391 self.profSelectorObjIndex += 1
398 return 0
392 return 0
399
393
400 self.dataOutObj.flagNoData = False
394 self.dataOutObj.flagNoData = False
401 self.profSelectorObjIndex += 1
395 self.profSelectorObjIndex += 1
402
396
403 return 1
397 return 1
404
398
405 def selectNtxs(self, ntx):
399 def selectNtxs(self, ntx):
406 pass
400 pass
407
401
408
402
409 class Decoder:
403 class Decoder:
410
404
411 data = None
405 data = None
412 profCounter = 1
406 profCounter = 1
413 nCode = None
407 nCode = None
414 nBaud = None
408 nBaud = None
415 codeIndex = 0
409 codeIndex = 0
416 code = None
410 code = None
417 flag = False
411 flag = False
418
412
419 def __init__(self,code, ncode, nbaud):
413 def __init__(self,code, ncode, nbaud):
420
414
421 self.data = None
415 self.data = None
422 self.profCounter = 1
416 self.profCounter = 1
423 self.nCode = ncode
417 self.nCode = ncode
424 self.nBaud = nbaud
418 self.nBaud = nbaud
425 self.codeIndex = 0
419 self.codeIndex = 0
426 self.code = code #this is a List
420 self.code = code #this is a List
427 self.flag = False
421 self.flag = False
428
422
429 def exe(self, data, ndata=None, type = 0):
423 def exe(self, data, ndata=None, type = 0):
430
424
431 if ndata == None: ndata = data.shape[1]
425 if ndata == None: ndata = data.shape[1]
432
426
433 if type == 0:
427 if type == 0:
434 self.convolutionInFreq(data,ndata)
428 self.convolutionInFreq(data,ndata)
435
429
436 if type == 1:
430 if type == 1:
437 self.convolutionInTime(data, ndata)
431 self.convolutionInTime(data, ndata)
438
432
439 def convolutionInFreq(self,data, ndata):
433 def convolutionInFreq(self,data, ndata):
440
434
441 newcode = numpy.zeros(ndata)
435 newcode = numpy.zeros(ndata)
442 newcode[0:self.nBaud] = self.code[self.codeIndex]
436 newcode[0:self.nBaud] = self.code[self.codeIndex]
443
437
444 self.codeIndex += 1
438 self.codeIndex += 1
445
439
446 fft_data = numpy.fft.fft(data, axis=1)
440 fft_data = numpy.fft.fft(data, axis=1)
447 fft_code = numpy.conj(numpy.fft.fft(newcode))
441 fft_code = numpy.conj(numpy.fft.fft(newcode))
448 fft_code = fft_code.reshape(1,len(fft_code))
442 fft_code = fft_code.reshape(1,len(fft_code))
449
443
450 conv = fft_data.copy()
444 conv = fft_data.copy()
451 conv.fill(0)
445 conv.fill(0)
452
446
453 conv = fft_data*fft_code
447 conv = fft_data*fft_code
454
448
455 self.data = numpy.fft.ifft(conv,axis=1)
449 self.data = numpy.fft.ifft(conv,axis=1)
456 self.flag = True
450 self.flag = True
457
451
458 if self.profCounter == self.nCode:
452 if self.profCounter == self.nCode:
459 self.profCounter = 0
453 self.profCounter = 0
460 self.codeIndex = 0
454 self.codeIndex = 0
461
455
462 self.profCounter += 1
456 self.profCounter += 1
463
457
464 def convolutionInTime(self, data, ndata):
458 def convolutionInTime(self, data, ndata):
465
459
466 nchannel = data.shape[1]
460 nchannel = data.shape[1]
467 newcode = self.code[self.codeIndex]
461 newcode = self.code[self.codeIndex]
468 self.codeIndex += 1
462 self.codeIndex += 1
469 conv = data.copy()
463 conv = data.copy()
470 for i in range(nchannel):
464 for i in range(nchannel):
471 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
465 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
472
466
473 self.data = conv
467 self.data = conv
474 self.flag = True
468 self.flag = True
475
469
476 if self.profCounter == self.nCode:
470 if self.profCounter == self.nCode:
477 self.profCounter = 0
471 self.profCounter = 0
478 self.codeIndex = 0
472 self.codeIndex = 0
479
473
480 self.profCounter += 1
474 self.profCounter += 1
481
475
482
476
483 class CoherentIntegrator:
477 class CoherentIntegrator:
484
478
485 integ_counter = None
479 integ_counter = None
486 data = None
480 data = None
487 navg = None
481 navg = None
488 buffer = None
482 buffer = None
489 nCohInt = None
483 nCohInt = None
490
484
491 def __init__(self, N=None,timeInterval=None):
485 def __init__(self, N=None,timeInterval=None):
492
486
493 self.data = None
487 self.data = None
494 self.navg = None
488 self.navg = None
495 self.buffer = None
489 self.buffer = None
496 self.timeOut = None
490 self.timeOut = None
497 self.exitCondition = False
491 self.exitCondition = False
498 self.isReady = False
492 self.isReady = False
499 self.nCohInt = N
493 self.nCohInt = N
500 self.integ_counter = 0
494 self.integ_counter = 0
501 if timeInterval!=None:
495 if timeInterval!=None:
502 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
496 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
503
497
504 if ((timeInterval==None) and (N==None)):
498 if ((timeInterval==None) and (N==None)):
505 print 'N = None ; timeInterval = None'
499 print 'N = None ; timeInterval = None'
506 sys.exit(0)
500 sys.exit(0)
507 elif timeInterval == None:
501 elif timeInterval == None:
508 self.timeFlag = False
502 self.timeFlag = False
509 else:
503 else:
510 self.timeFlag = True
504 self.timeFlag = True
511
505
512 def exe(self, data, timeOfData):
506 def exe(self, data, timeOfData):
513
507
514 if self.timeFlag:
508 if self.timeFlag:
515 if self.timeOut == None:
509 if self.timeOut == None:
516 self.timeOut = timeOfData + self.timeIntervalInSeconds
510 self.timeOut = timeOfData + self.timeIntervalInSeconds
517
511
518 if timeOfData < self.timeOut:
512 if timeOfData < self.timeOut:
519 if self.buffer == None:
513 if self.buffer == None:
520 self.buffer = data
514 self.buffer = data
521 else:
515 else:
522 self.buffer = self.buffer + data
516 self.buffer = self.buffer + data
523 self.integ_counter += 1
517 self.integ_counter += 1
524 else:
518 else:
525 self.exitCondition = True
519 self.exitCondition = True
526
520
527 else:
521 else:
528 if self.integ_counter < self.nCohInt:
522 if self.integ_counter < self.nCohInt:
529 if self.buffer == None:
523 if self.buffer == None:
530 self.buffer = data
524 self.buffer = data
531 else:
525 else:
532 self.buffer = self.buffer + data
526 self.buffer = self.buffer + data
533
527
534 self.integ_counter += 1
528 self.integ_counter += 1
535
529
536 if self.integ_counter == self.nCohInt:
530 if self.integ_counter == self.nCohInt:
537 self.exitCondition = True
531 self.exitCondition = True
538
532
539 if self.exitCondition:
533 if self.exitCondition:
540 self.data = self.buffer
534 self.data = self.buffer
541 self.navg = self.integ_counter
535 self.navg = self.integ_counter
542 self.isReady = True
536 self.isReady = True
543 self.buffer = None
537 self.buffer = None
544 self.timeOut = None
538 self.timeOut = None
545 self.integ_counter = 0
539 self.integ_counter = 0
546 self.exitCondition = False
540 self.exitCondition = False
547
541
548 if self.timeFlag:
542 if self.timeFlag:
549 self.buffer = data
543 self.buffer = data
550 self.timeOut = timeOfData + self.timeIntervalInSeconds
544 self.timeOut = timeOfData + self.timeIntervalInSeconds
551 else:
545 else:
552 self.isReady = False
546 self.isReady = False
553
547
554
548
555
549
556 class ProfileSelector:
550 class ProfileSelector:
557
551
558 profileIndex = None
552 profileIndex = None
559 # Tamanho total de los perfiles
553 # Tamanho total de los perfiles
560 nProfiles = None
554 nProfiles = None
561
555
562 def __init__(self, nProfiles):
556 def __init__(self, nProfiles):
563
557
564 self.profileIndex = 0
558 self.profileIndex = 0
565 self.nProfiles = nProfiles
559 self.nProfiles = nProfiles
566
560
567 def incIndex(self):
561 def incIndex(self):
568 self.profileIndex += 1
562 self.profileIndex += 1
569
563
570 if self.profileIndex >= self.nProfiles:
564 if self.profileIndex >= self.nProfiles:
571 self.profileIndex = 0
565 self.profileIndex = 0
572
566
573 def isProfileInRange(self, minIndex, maxIndex):
567 def isProfileInRange(self, minIndex, maxIndex):
574
568
575 if self.profileIndex < minIndex:
569 if self.profileIndex < minIndex:
576 return False
570 return False
577
571
578 if self.profileIndex > maxIndex:
572 if self.profileIndex > maxIndex:
579 return False
573 return False
580
574
581 return True
575 return True
582
576
583 def isProfileInList(self, profileList):
577 def isProfileInList(self, profileList):
584
578
585 if self.profileIndex not in profileList:
579 if self.profileIndex not in profileList:
586 return False
580 return False
587
581
588 return True
582 return True
589
583
590
584
591 No newline at end of file
585
@@ -1,91 +1,109
1 '''
1 '''
2 Created on 27/03/2012
2 Created on 27/03/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
14 from Model.Spectra import Spectra
15 from IO.SpectraIO import *
15 from IO.SpectraIO import *
16
16
17 from Processing.VoltageProcessor import *
17 from Processing.VoltageProcessor import *
18 from Processing.SpectraProcessor import *
18 from Processing.SpectraProcessor import *
19
19
20
20
21 class TestSChain():
21 class TestSChain():
22
22
23 def __init__(self):
23 def __init__(self):
24 self.setValues()
24 self.setValues()
25 self.createObjects()
25 self.createObjects()
26 self.testSChain()
26 self.testSChain()
27
27
28
28
29 def setValues( self ):
29 def setValues( self ):
30
30
31 self.path = "/home/dsuarez/Projects" #1
31 self.path = "/home/dsuarez/Projects" #1
32 self.path = "/Users/jro/Documents/RadarData/EW_Drifts"
32 self.path = "/Users/jro/Documents/RadarData/EW_Drifts"
33 # self.path = "/Users/jro/Documents/RadarData/JULIA"
33 self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST"
34 # self.startDateTime = datetime.datetime(2007,5,1,15,49,0)
34 # self.startDateTime = datetime.datetime(2007,5,1,15,49,0)
35 # self.endDateTime = datetime.datetime(2007,5,1,23,0,0)
35 # self.endDateTime = datetime.datetime(2007,5,1,23,0,0)
36
36
37 self.startDateTime = datetime.datetime(2011,10,1,0,0,0)
37 self.startDateTime = datetime.datetime(2009,01,1,0,0,0)
38 self.endDateTime = datetime.datetime(2011,12,31,0,20,0)
38 self.endDateTime = datetime.datetime(2009,01,31,0,20,0)
39
40 # self.startDateTime = datetime.datetime(2011,11,1,0,0,0)
41 # self.endDateTime = datetime.datetime(2011,12,31,0,20,0)
42
43
39 self.N = 4
44 self.N = 4
40 self.npts = 8
45 self.npts = 8
41
46
42 def createObjects( self ):
47 def createObjects( self ):
43
48
44 self.voltObj1 = Voltage()
49 self.readerObj = VoltageReader()
45 self.voltObj2 = Voltage()
50 self.voltProcObj = VoltageProcessor()
46 self.specObj1 = Spectra()
51 self.specProcObj = SpectraProcessor()
47
48 self.readerObj = VoltageReader(self.voltObj1)
49 self.voltProcObj = VoltageProcessor(self.voltObj1, self.voltObj2)
50 self.specProcObj = SpectraProcessor(self.voltObj2, self.specObj1)
51
52
52 if not(self.readerObj.setup( self.path, self.startDateTime, self.endDateTime, expLabel='', online =0) ):
53 voltObj1 = self.readerObj.setup(
54 path = self.path,
55 startDateTime = self.startDateTime,
56 endDateTime = self.endDateTime,
57 expLabel = '',
58 online = 0)
59
60 if not(voltObj1):
53 sys.exit(0)
61 sys.exit(0)
54
62
55 self.specProcObj.setup(nFFTPoints=8)
63 voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1)
64
65 specObj1 = self.specProcObj.setup(dataInObj = voltObj2,
66 nFFTPoints = 16)
67
68 # voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1,
69 # dataOutObj = voltObj2)
70 #
71 # specObj1 = self.specProcObj.setup(dataInObj = voltObj2,
72 # dataOutObj =specObj1,
73 # nFFTPoints=16)
56
74
57
75
58 def testSChain( self ):
76 def testSChain( self ):
59
77
60 ini = time.time()
78 ini = time.time()
61 while(True):
79 while(True):
62 self.readerObj.getData()
80 self.readerObj.getData()
63
81
64 self.voltProcObj.init()
82 self.voltProcObj.init()
65
83
66 self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1)
84 # self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1)
67
85 #
68 self.voltProcObj.integrator(4)
86 # self.voltProcObj.integrator(4)
69
87 #
70 self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2)
88 # self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2)
89 #
71
90
72
73 self.specProcObj.init()
91 self.specProcObj.init()
74
92
75 self.specProcObj.integrator(N=2)
93 self.specProcObj.integrator(N=1)
76
94
77 self.specProcObj.plotData(winTitle='Spectra 1', index=3)
95 self.specProcObj.plotData(winTitle='Spectra 1', index=1)
78
96
79
97
80 if self.readerObj.flagNoMoreFiles:
98 if self.readerObj.flagNoMoreFiles:
81 break
99 break
82
100
83 if self.readerObj.flagIsNewBlock:
101 if self.readerObj.flagIsNewBlock:
84 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
102 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
85 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
103 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
86
104
87
105
88 # self.plotObj.end()
106 # self.plotObj.end()
89
107
90 if __name__ == '__main__':
108 if __name__ == '__main__':
91 TestSChain() No newline at end of file
109 TestSChain()
General Comments 0
You need to be logged in to leave comments. Login now