##// END OF EJS Templates
Agrega la clase ProfileSelector y el metodo filterByHeights en jroprocessing.py...
Daniel Valdez -
r233:1c9beb790bbb
parent child
Show More
@@ -1,823 +1,967
1 import numpy
1 import numpy
2 import time, datetime
2 import time, datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class CrossSpectraPlot(Figure):
5 class CrossSpectraPlot(Figure):
6
6
7 __isConfig = None
7 __isConfig = None
8 __nsubplots = None
8 __nsubplots = None
9
9
10 WIDTHPROF = None
10 WIDTHPROF = None
11 HEIGHTPROF = None
11 HEIGHTPROF = None
12 PREFIX = 'cspc'
12 PREFIX = 'cspc'
13
13
14 def __init__(self):
14 def __init__(self):
15
15
16 self.__isConfig = False
16 self.__isConfig = False
17 self.__nsubplots = 4
17 self.__nsubplots = 4
18
18
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 400
20 self.HEIGHT = 400
21 self.WIDTHPROF = 0
21 self.WIDTHPROF = 0
22 self.HEIGHTPROF = 0
22 self.HEIGHTPROF = 0
23
23
24 def getSubplots(self):
24 def getSubplots(self):
25
25
26 ncol = 4
26 ncol = 4
27 nrow = self.nplots
27 nrow = self.nplots
28
28
29 return nrow, ncol
29 return nrow, ncol
30
30
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
32
32
33 self.__showprofile = showprofile
33 self.__showprofile = showprofile
34 self.nplots = nplots
34 self.nplots = nplots
35
35
36 ncolspan = 1
36 ncolspan = 1
37 colspan = 1
37 colspan = 1
38
38
39 self.createFigure(idfigure = idfigure,
39 self.createFigure(idfigure = idfigure,
40 wintitle = wintitle,
40 wintitle = wintitle,
41 widthplot = self.WIDTH + self.WIDTHPROF,
41 widthplot = self.WIDTH + self.WIDTHPROF,
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
43
43
44 nrow, ncol = self.getSubplots()
44 nrow, ncol = self.getSubplots()
45
45
46 counter = 0
46 counter = 0
47 for y in range(nrow):
47 for y in range(nrow):
48 for x in range(ncol):
48 for x in range(ncol):
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
50
50
51 counter += 1
51 counter += 1
52
52
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
55 save=False, figpath='./', figfile=None):
55 save=False, figpath='./', figfile=None):
56
56
57 """
57 """
58
58
59 Input:
59 Input:
60 dataOut :
60 dataOut :
61 idfigure :
61 idfigure :
62 wintitle :
62 wintitle :
63 channelList :
63 channelList :
64 showProfile :
64 showProfile :
65 xmin : None,
65 xmin : None,
66 xmax : None,
66 xmax : None,
67 ymin : None,
67 ymin : None,
68 ymax : None,
68 ymax : None,
69 zmin : None,
69 zmin : None,
70 zmax : None
70 zmax : None
71 """
71 """
72
72
73 if pairsList == None:
73 if pairsList == None:
74 pairsIndexList = dataOut.pairsIndexList
74 pairsIndexList = dataOut.pairsIndexList
75 else:
75 else:
76 pairsIndexList = []
76 pairsIndexList = []
77 for pair in pairsList:
77 for pair in pairsList:
78 if pair not in dataOut.pairsList:
78 if pair not in dataOut.pairsList:
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
80 pairsIndexList.append(dataOut.pairsList.index(pair))
80 pairsIndexList.append(dataOut.pairsList.index(pair))
81
81
82 if pairsIndexList == []:
82 if pairsIndexList == []:
83 return
83 return
84
84
85 if len(pairsIndexList) > 4:
85 if len(pairsIndexList) > 4:
86 pairsIndexList = pairsIndexList[0:4]
86 pairsIndexList = pairsIndexList[0:4]
87
87
88 x = dataOut.getFreqRange(1)
88 x = dataOut.getFreqRange(1)
89 y = dataOut.getHeiRange()
89 y = dataOut.getHeiRange()
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
91 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
91 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
92 avg = numpy.average(numpy.abs(z), axis=1)
92 avg = numpy.average(numpy.abs(z), axis=1)
93
93
94 noise = dataOut.getNoise()
94 noise = dataOut.getNoise()
95
95
96 if not self.__isConfig:
96 if not self.__isConfig:
97
97
98 nplots = len(pairsIndexList)
98 nplots = len(pairsIndexList)
99
99
100 self.setup(idfigure=idfigure,
100 self.setup(idfigure=idfigure,
101 nplots=nplots,
101 nplots=nplots,
102 wintitle=wintitle,
102 wintitle=wintitle,
103 showprofile=showprofile)
103 showprofile=showprofile)
104
104
105 if xmin == None: xmin = numpy.nanmin(x)
105 if xmin == None: xmin = numpy.nanmin(x)
106 if xmax == None: xmax = numpy.nanmax(x)
106 if xmax == None: xmax = numpy.nanmax(x)
107 if ymin == None: ymin = numpy.nanmin(y)
107 if ymin == None: ymin = numpy.nanmin(y)
108 if ymax == None: ymax = numpy.nanmax(y)
108 if ymax == None: ymax = numpy.nanmax(y)
109 if zmin == None: zmin = numpy.nanmin(avg)*0.9
109 if zmin == None: zmin = numpy.nanmin(avg)*0.9
110 if zmax == None: zmax = numpy.nanmax(avg)*0.9
110 if zmax == None: zmax = numpy.nanmax(avg)*0.9
111
111
112 self.__isConfig = True
112 self.__isConfig = True
113
113
114 thisDatetime = dataOut.datatime
114 thisDatetime = dataOut.datatime
115 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
115 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
116 xlabel = "Velocity (m/s)"
116 xlabel = "Velocity (m/s)"
117 ylabel = "Range (Km)"
117 ylabel = "Range (Km)"
118
118
119 self.setWinTitle(title)
119 self.setWinTitle(title)
120
120
121 for i in range(self.nplots):
121 for i in range(self.nplots):
122 pair = dataOut.pairsList[pairsIndexList[i]]
122 pair = dataOut.pairsList[pairsIndexList[i]]
123
123
124 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
124 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
125 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
125 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
126 axes0 = self.axesList[i*self.__nsubplots]
126 axes0 = self.axesList[i*self.__nsubplots]
127 axes0.pcolor(x, y, z,
127 axes0.pcolor(x, y, z,
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
129 xlabel=xlabel, ylabel=ylabel, title=title,
129 xlabel=xlabel, ylabel=ylabel, title=title,
130 ticksize=9, cblabel='')
130 ticksize=9, cblabel='')
131
131
132 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
132 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
133 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
133 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
134 axes0 = self.axesList[i*self.__nsubplots+1]
134 axes0 = self.axesList[i*self.__nsubplots+1]
135 axes0.pcolor(x, y, z,
135 axes0.pcolor(x, y, z,
136 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
136 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
137 xlabel=xlabel, ylabel=ylabel, title=title,
137 xlabel=xlabel, ylabel=ylabel, title=title,
138 ticksize=9, cblabel='')
138 ticksize=9, cblabel='')
139
139
140 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
140 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
141 coherence = numpy.abs(coherenceComplex)
141 coherence = numpy.abs(coherenceComplex)
142 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
142 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
143
143
144
144
145 title = "Coherence %d%d" %(pair[0], pair[1])
145 title = "Coherence %d%d" %(pair[0], pair[1])
146 axes0 = self.axesList[i*self.__nsubplots+2]
146 axes0 = self.axesList[i*self.__nsubplots+2]
147 axes0.pcolor(x, y, coherence,
147 axes0.pcolor(x, y, coherence,
148 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
148 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
149 xlabel=xlabel, ylabel=ylabel, title=title,
149 xlabel=xlabel, ylabel=ylabel, title=title,
150 ticksize=9, cblabel='')
150 ticksize=9, cblabel='')
151
151
152 title = "Phase %d%d" %(pair[0], pair[1])
152 title = "Phase %d%d" %(pair[0], pair[1])
153 axes0 = self.axesList[i*self.__nsubplots+3]
153 axes0 = self.axesList[i*self.__nsubplots+3]
154 axes0.pcolor(x, y, phase,
154 axes0.pcolor(x, y, phase,
155 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
155 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
156 xlabel=xlabel, ylabel=ylabel, title=title,
156 xlabel=xlabel, ylabel=ylabel, title=title,
157 ticksize=9, cblabel='', colormap='RdBu')
157 ticksize=9, cblabel='', colormap='RdBu')
158
158
159
159
160
160
161 self.draw()
161 self.draw()
162
162
163 if save:
163 if save:
164 date = thisDatetime.strftime("%Y%m%d")
164 date = thisDatetime.strftime("%Y%m%d")
165 if figfile == None:
165 if figfile == None:
166 figfile = self.getFilename(name = date)
166 figfile = self.getFilename(name = date)
167
167
168 self.saveFigure(figpath, figfile)
168 self.saveFigure(figpath, figfile)
169
169
170
170
171 class RTIPlot(Figure):
171 class RTIPlot(Figure):
172
172
173 __isConfig = None
173 __isConfig = None
174 __nsubplots = None
174 __nsubplots = None
175
175
176 WIDTHPROF = None
176 WIDTHPROF = None
177 HEIGHTPROF = None
177 HEIGHTPROF = None
178 PREFIX = 'rti'
178 PREFIX = 'rti'
179
179
180 def __init__(self):
180 def __init__(self):
181
181
182 self.timerange = 24*60*60
182 self.timerange = 24*60*60
183 self.__isConfig = False
183 self.__isConfig = False
184 self.__nsubplots = 1
184 self.__nsubplots = 1
185
185
186 self.WIDTH = 800
186 self.WIDTH = 800
187 self.HEIGHT = 200
187 self.HEIGHT = 200
188 self.WIDTHPROF = 120
188 self.WIDTHPROF = 120
189 self.HEIGHTPROF = 0
189 self.HEIGHTPROF = 0
190
190
191 def getSubplots(self):
191 def getSubplots(self):
192
192
193 ncol = 1
193 ncol = 1
194 nrow = self.nplots
194 nrow = self.nplots
195
195
196 return nrow, ncol
196 return nrow, ncol
197
197
198 def setup(self, idfigure, nplots, wintitle, showprofile=True):
198 def setup(self, idfigure, nplots, wintitle, showprofile=True):
199
199
200 self.__showprofile = showprofile
200 self.__showprofile = showprofile
201 self.nplots = nplots
201 self.nplots = nplots
202
202
203 ncolspan = 1
203 ncolspan = 1
204 colspan = 1
204 colspan = 1
205 if showprofile:
205 if showprofile:
206 ncolspan = 7
206 ncolspan = 7
207 colspan = 6
207 colspan = 6
208 self.__nsubplots = 2
208 self.__nsubplots = 2
209
209
210 self.createFigure(idfigure = idfigure,
210 self.createFigure(idfigure = idfigure,
211 wintitle = wintitle,
211 wintitle = wintitle,
212 widthplot = self.WIDTH + self.WIDTHPROF,
212 widthplot = self.WIDTH + self.WIDTHPROF,
213 heightplot = self.HEIGHT + self.HEIGHTPROF)
213 heightplot = self.HEIGHT + self.HEIGHTPROF)
214
214
215 nrow, ncol = self.getSubplots()
215 nrow, ncol = self.getSubplots()
216
216
217 counter = 0
217 counter = 0
218 for y in range(nrow):
218 for y in range(nrow):
219 for x in range(ncol):
219 for x in range(ncol):
220
220
221 if counter >= self.nplots:
221 if counter >= self.nplots:
222 break
222 break
223
223
224 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
224 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
225
225
226 if showprofile:
226 if showprofile:
227 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
227 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
228
228
229 counter += 1
229 counter += 1
230
230
231 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
231 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
232 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
232 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
233 timerange=None,
233 timerange=None,
234 save=False, figpath='./', figfile=None):
234 save=False, figpath='./', figfile=None):
235
235
236 """
236 """
237
237
238 Input:
238 Input:
239 dataOut :
239 dataOut :
240 idfigure :
240 idfigure :
241 wintitle :
241 wintitle :
242 channelList :
242 channelList :
243 showProfile :
243 showProfile :
244 xmin : None,
244 xmin : None,
245 xmax : None,
245 xmax : None,
246 ymin : None,
246 ymin : None,
247 ymax : None,
247 ymax : None,
248 zmin : None,
248 zmin : None,
249 zmax : None
249 zmax : None
250 """
250 """
251
251
252 if channelList == None:
252 if channelList == None:
253 channelIndexList = dataOut.channelIndexList
253 channelIndexList = dataOut.channelIndexList
254 else:
254 else:
255 channelIndexList = []
255 channelIndexList = []
256 for channel in channelList:
256 for channel in channelList:
257 if channel not in dataOut.channelList:
257 if channel not in dataOut.channelList:
258 raise ValueError, "Channel %d is not in dataOut.channelList"
258 raise ValueError, "Channel %d is not in dataOut.channelList"
259 channelIndexList.append(dataOut.channelList.index(channel))
259 channelIndexList.append(dataOut.channelList.index(channel))
260
260
261 if timerange != None:
261 if timerange != None:
262 self.timerange = timerange
262 self.timerange = timerange
263
263
264 tmin = None
264 tmin = None
265 tmax = None
265 tmax = None
266 x = dataOut.getTimeRange()
266 x = dataOut.getTimeRange()
267 y = dataOut.getHeiRange()
267 y = dataOut.getHeiRange()
268 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
268 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
269 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
269 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
270 avg = numpy.average(z, axis=1)
270 avg = numpy.average(z, axis=1)
271
271
272 noise = dataOut.getNoise()
272 noise = dataOut.getNoise()
273
273
274 if not self.__isConfig:
274 if not self.__isConfig:
275
275
276 nplots = len(channelIndexList)
276 nplots = len(channelIndexList)
277
277
278 self.setup(idfigure=idfigure,
278 self.setup(idfigure=idfigure,
279 nplots=nplots,
279 nplots=nplots,
280 wintitle=wintitle,
280 wintitle=wintitle,
281 showprofile=showprofile)
281 showprofile=showprofile)
282
282
283 tmin, tmax = self.getTimeLim(x, xmin, xmax)
283 tmin, tmax = self.getTimeLim(x, xmin, xmax)
284 if ymin == None: ymin = numpy.nanmin(y)
284 if ymin == None: ymin = numpy.nanmin(y)
285 if ymax == None: ymax = numpy.nanmax(y)
285 if ymax == None: ymax = numpy.nanmax(y)
286 if zmin == None: zmin = numpy.nanmin(avg)*0.9
286 if zmin == None: zmin = numpy.nanmin(avg)*0.9
287 if zmax == None: zmax = numpy.nanmax(avg)*0.9
287 if zmax == None: zmax = numpy.nanmax(avg)*0.9
288
288
289 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
289 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
290 self.__isConfig = True
290 self.__isConfig = True
291
291
292 thisDatetime = dataOut.datatime
292 thisDatetime = dataOut.datatime
293 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
293 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
294 xlabel = "Velocity (m/s)"
294 xlabel = "Velocity (m/s)"
295 ylabel = "Range (Km)"
295 ylabel = "Range (Km)"
296
296
297 self.setWinTitle(title)
297 self.setWinTitle(title)
298
298
299 for i in range(self.nplots):
299 for i in range(self.nplots):
300 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
300 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
301 axes = self.axesList[i*self.__nsubplots]
301 axes = self.axesList[i*self.__nsubplots]
302 z = avg[i].reshape((1,-1))
302 z = avg[i].reshape((1,-1))
303 axes.pcolor(x, y, z,
303 axes.pcolor(x, y, z,
304 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
304 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
305 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
305 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
306 ticksize=9, cblabel='', cbsize="1%")
306 ticksize=9, cblabel='', cbsize="1%")
307
307
308 if self.__showprofile:
308 if self.__showprofile:
309 axes = self.axesList[i*self.__nsubplots +1]
309 axes = self.axesList[i*self.__nsubplots +1]
310 axes.pline(avg[i], y,
310 axes.pline(avg[i], y,
311 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
311 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
312 xlabel='dB', ylabel='', title='',
312 xlabel='dB', ylabel='', title='',
313 ytick_visible=False,
313 ytick_visible=False,
314 grid='x')
314 grid='x')
315
315
316 self.draw()
316 self.draw()
317
317
318 if save:
318 if save:
319
319
320 if figfile == None:
320 if figfile == None:
321 figfile = self.getFilename(name = self.name)
321 figfile = self.getFilename(name = self.name)
322
322
323 self.saveFigure(figpath, figfile)
323 self.saveFigure(figpath, figfile)
324
324
325 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
325 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
326 self.__isConfig = False
326 self.__isConfig = False
327
327
328 class SpectraPlot(Figure):
328 class SpectraPlot(Figure):
329
329
330 __isConfig = None
330 __isConfig = None
331 __nsubplots = None
331 __nsubplots = None
332
332
333 WIDTHPROF = None
333 WIDTHPROF = None
334 HEIGHTPROF = None
334 HEIGHTPROF = None
335 PREFIX = 'spc'
335 PREFIX = 'spc'
336
336
337 def __init__(self):
337 def __init__(self):
338
338
339 self.__isConfig = False
339 self.__isConfig = False
340 self.__nsubplots = 1
340 self.__nsubplots = 1
341
341
342 self.WIDTH = 300
342 self.WIDTH = 300
343 self.HEIGHT = 400
343 self.HEIGHT = 400
344 self.WIDTHPROF = 120
344 self.WIDTHPROF = 120
345 self.HEIGHTPROF = 0
345 self.HEIGHTPROF = 0
346
346
347 def getSubplots(self):
347 def getSubplots(self):
348
348
349 ncol = int(numpy.sqrt(self.nplots)+0.9)
349 ncol = int(numpy.sqrt(self.nplots)+0.9)
350 nrow = int(self.nplots*1./ncol + 0.9)
350 nrow = int(self.nplots*1./ncol + 0.9)
351
351
352 return nrow, ncol
352 return nrow, ncol
353
353
354 def setup(self, idfigure, nplots, wintitle, showprofile=True):
354 def setup(self, idfigure, nplots, wintitle, showprofile=True):
355
355
356 self.__showprofile = showprofile
356 self.__showprofile = showprofile
357 self.nplots = nplots
357 self.nplots = nplots
358
358
359 ncolspan = 1
359 ncolspan = 1
360 colspan = 1
360 colspan = 1
361 if showprofile:
361 if showprofile:
362 ncolspan = 3
362 ncolspan = 3
363 colspan = 2
363 colspan = 2
364 self.__nsubplots = 2
364 self.__nsubplots = 2
365
365
366 self.createFigure(idfigure = idfigure,
366 self.createFigure(idfigure = idfigure,
367 wintitle = wintitle,
367 wintitle = wintitle,
368 widthplot = self.WIDTH + self.WIDTHPROF,
368 widthplot = self.WIDTH + self.WIDTHPROF,
369 heightplot = self.HEIGHT + self.HEIGHTPROF)
369 heightplot = self.HEIGHT + self.HEIGHTPROF)
370
370
371 nrow, ncol = self.getSubplots()
371 nrow, ncol = self.getSubplots()
372
372
373 counter = 0
373 counter = 0
374 for y in range(nrow):
374 for y in range(nrow):
375 for x in range(ncol):
375 for x in range(ncol):
376
376
377 if counter >= self.nplots:
377 if counter >= self.nplots:
378 break
378 break
379
379
380 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
380 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
381
381
382 if showprofile:
382 if showprofile:
383 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
383 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
384
384
385 counter += 1
385 counter += 1
386
386
387 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
387 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
388 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
388 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
389 save=False, figpath='./', figfile=None):
389 save=False, figpath='./', figfile=None):
390
390
391 """
391 """
392
392
393 Input:
393 Input:
394 dataOut :
394 dataOut :
395 idfigure :
395 idfigure :
396 wintitle :
396 wintitle :
397 channelList :
397 channelList :
398 showProfile :
398 showProfile :
399 xmin : None,
399 xmin : None,
400 xmax : None,
400 xmax : None,
401 ymin : None,
401 ymin : None,
402 ymax : None,
402 ymax : None,
403 zmin : None,
403 zmin : None,
404 zmax : None
404 zmax : None
405 """
405 """
406
406
407 if channelList == None:
407 if channelList == None:
408 channelIndexList = dataOut.channelIndexList
408 channelIndexList = dataOut.channelIndexList
409 else:
409 else:
410 channelIndexList = []
410 channelIndexList = []
411 for channel in channelList:
411 for channel in channelList:
412 if channel not in dataOut.channelList:
412 if channel not in dataOut.channelList:
413 raise ValueError, "Channel %d is not in dataOut.channelList"
413 raise ValueError, "Channel %d is not in dataOut.channelList"
414 channelIndexList.append(dataOut.channelList.index(channel))
414 channelIndexList.append(dataOut.channelList.index(channel))
415
415
416 x = dataOut.getVelRange(1)
416 x = dataOut.getVelRange(1)
417 y = dataOut.getHeiRange()
417 y = dataOut.getHeiRange()
418
418
419 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
419 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
420 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
420 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
421 avg = numpy.average(z, axis=1)
421 avg = numpy.average(z, axis=1)
422
422
423 noise = dataOut.getNoise()
423 noise = dataOut.getNoise()
424
424
425 if not self.__isConfig:
425 if not self.__isConfig:
426
426
427 nplots = len(channelIndexList)
427 nplots = len(channelIndexList)
428
428
429 self.setup(idfigure=idfigure,
429 self.setup(idfigure=idfigure,
430 nplots=nplots,
430 nplots=nplots,
431 wintitle=wintitle,
431 wintitle=wintitle,
432 showprofile=showprofile)
432 showprofile=showprofile)
433
433
434 if xmin == None: xmin = numpy.nanmin(x)
434 if xmin == None: xmin = numpy.nanmin(x)
435 if xmax == None: xmax = numpy.nanmax(x)
435 if xmax == None: xmax = numpy.nanmax(x)
436 if ymin == None: ymin = numpy.nanmin(y)
436 if ymin == None: ymin = numpy.nanmin(y)
437 if ymax == None: ymax = numpy.nanmax(y)
437 if ymax == None: ymax = numpy.nanmax(y)
438 if zmin == None: zmin = numpy.nanmin(avg)*0.9
438 if zmin == None: zmin = numpy.nanmin(avg)*0.9
439 if zmax == None: zmax = numpy.nanmax(avg)*0.9
439 if zmax == None: zmax = numpy.nanmax(avg)*0.9
440
440
441 self.__isConfig = True
441 self.__isConfig = True
442
442
443 thisDatetime = dataOut.datatime
443 thisDatetime = dataOut.datatime
444 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
444 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
445 xlabel = "Velocity (m/s)"
445 xlabel = "Velocity (m/s)"
446 ylabel = "Range (Km)"
446 ylabel = "Range (Km)"
447
447
448 self.setWinTitle(title)
448 self.setWinTitle(title)
449
449
450 for i in range(self.nplots):
450 for i in range(self.nplots):
451 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
451 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
452 axes = self.axesList[i*self.__nsubplots]
452 axes = self.axesList[i*self.__nsubplots]
453 axes.pcolor(x, y, z[i,:,:],
453 axes.pcolor(x, y, z[i,:,:],
454 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
454 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
455 xlabel=xlabel, ylabel=ylabel, title=title,
455 xlabel=xlabel, ylabel=ylabel, title=title,
456 ticksize=9, cblabel='')
456 ticksize=9, cblabel='')
457
457
458 if self.__showprofile:
458 if self.__showprofile:
459 axes = self.axesList[i*self.__nsubplots +1]
459 axes = self.axesList[i*self.__nsubplots +1]
460 axes.pline(avg[i], y,
460 axes.pline(avg[i], y,
461 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
461 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
462 xlabel='dB', ylabel='', title='',
462 xlabel='dB', ylabel='', title='',
463 ytick_visible=False,
463 ytick_visible=False,
464 grid='x')
464 grid='x')
465
465
466 self.draw()
466 self.draw()
467
467
468 if save:
468 if save:
469 date = thisDatetime.strftime("%Y%m%d")
469 date = thisDatetime.strftime("%Y%m%d")
470 if figfile == None:
470 if figfile == None:
471 figfile = self.getFilename(name = date)
471 figfile = self.getFilename(name = date)
472
472
473 self.saveFigure(figpath, figfile)
473 self.saveFigure(figpath, figfile)
474
474
475 class Scope(Figure):
475 class Scope(Figure):
476
476
477 __isConfig = None
477 __isConfig = None
478
478
479 def __init__(self):
479 def __init__(self):
480
480
481 self.__isConfig = False
481 self.__isConfig = False
482 self.WIDTH = 600
482 self.WIDTH = 600
483 self.HEIGHT = 200
483 self.HEIGHT = 200
484
484
485 def getSubplots(self):
485 def getSubplots(self):
486
486
487 nrow = self.nplots
487 nrow = self.nplots
488 ncol = 3
488 ncol = 3
489 return nrow, ncol
489 return nrow, ncol
490
490
491 def setup(self, idfigure, nplots, wintitle):
491 def setup(self, idfigure, nplots, wintitle):
492
492
493 self.nplots = nplots
493 self.nplots = nplots
494
494
495 self.createFigure(idfigure, wintitle)
495 self.createFigure(idfigure, wintitle)
496
496
497 nrow,ncol = self.getSubplots()
497 nrow,ncol = self.getSubplots()
498 colspan = 3
498 colspan = 3
499 rowspan = 1
499 rowspan = 1
500
500
501 for i in range(nplots):
501 for i in range(nplots):
502 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
502 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
503
503
504
504
505
505
506 def run(self, dataOut, idfigure, wintitle="", channelList=None,
506 def run(self, dataOut, idfigure, wintitle="", channelList=None,
507 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
507 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
508
508
509 """
509 """
510
510
511 Input:
511 Input:
512 dataOut :
512 dataOut :
513 idfigure :
513 idfigure :
514 wintitle :
514 wintitle :
515 channelList :
515 channelList :
516 xmin : None,
516 xmin : None,
517 xmax : None,
517 xmax : None,
518 ymin : None,
518 ymin : None,
519 ymax : None,
519 ymax : None,
520 """
520 """
521
521
522 if channelList == None:
522 if channelList == None:
523 channelIndexList = dataOut.channelIndexList
523 channelIndexList = dataOut.channelIndexList
524 else:
524 else:
525 channelIndexList = []
525 channelIndexList = []
526 for channel in channelList:
526 for channel in channelList:
527 if channel not in dataOut.channelList:
527 if channel not in dataOut.channelList:
528 raise ValueError, "Channel %d is not in dataOut.channelList"
528 raise ValueError, "Channel %d is not in dataOut.channelList"
529 channelIndexList.append(dataOut.channelList.index(channel))
529 channelIndexList.append(dataOut.channelList.index(channel))
530
530
531 x = dataOut.heightList
531 x = dataOut.heightList
532 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
532 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
533 y = y.real
533 y = y.real
534
534
535 if not self.__isConfig:
535 if not self.__isConfig:
536 nplots = len(channelIndexList)
536 nplots = len(channelIndexList)
537
537
538 self.setup(idfigure=idfigure,
538 self.setup(idfigure=idfigure,
539 nplots=nplots,
539 nplots=nplots,
540 wintitle=wintitle)
540 wintitle=wintitle)
541
541
542 if xmin == None: xmin = numpy.nanmin(x)
542 if xmin == None: xmin = numpy.nanmin(x)
543 if xmax == None: xmax = numpy.nanmax(x)
543 if xmax == None: xmax = numpy.nanmax(x)
544 if ymin == None: ymin = numpy.nanmin(y)
544 if ymin == None: ymin = numpy.nanmin(y)
545 if ymax == None: ymax = numpy.nanmax(y)
545 if ymax == None: ymax = numpy.nanmax(y)
546
546
547 self.__isConfig = True
547 self.__isConfig = True
548
548
549
549
550 thisDatetime = dataOut.datatime
550 thisDatetime = dataOut.datatime
551 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
551 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
552 xlabel = "Range (Km)"
552 xlabel = "Range (Km)"
553 ylabel = "Intensity"
553 ylabel = "Intensity"
554
554
555 self.setWinTitle(title)
555 self.setWinTitle(title)
556
556
557 for i in range(len(self.axesList)):
557 for i in range(len(self.axesList)):
558 title = "Channel %d" %(i)
558 title = "Channel %d" %(i)
559 axes = self.axesList[i]
559 axes = self.axesList[i]
560 ychannel = y[i,:]
560 ychannel = y[i,:]
561 axes.pline(x, ychannel,
561 axes.pline(x, ychannel,
562 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
562 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
563 xlabel=xlabel, ylabel=ylabel, title=title)
563 xlabel=xlabel, ylabel=ylabel, title=title)
564
564
565 self.draw()
565 self.draw()
566
566
567 if save:
567 if save:
568 self.saveFigure(filename)
568 self.saveFigure(filename)
569
569
570 class ProfilePlot(Figure):
570 class ProfilePlot(Figure):
571 __isConfig = None
571 __isConfig = None
572 __nsubplots = None
572 __nsubplots = None
573
573
574 WIDTHPROF = None
574 WIDTHPROF = None
575 HEIGHTPROF = None
575 HEIGHTPROF = None
576 PREFIX = 'spcprofile'
576 PREFIX = 'spcprofile'
577
577
578 def __init__(self):
578 def __init__(self):
579 self.__isConfig = False
579 self.__isConfig = False
580 self.__nsubplots = 1
580 self.__nsubplots = 1
581
581
582 self.WIDTH = 300
582 self.WIDTH = 300
583 self.HEIGHT = 500
583 self.HEIGHT = 500
584
584
585 def getSubplots(self):
585 def getSubplots(self):
586 ncol = 1
586 ncol = 1
587 nrow = 1
587 nrow = 1
588
588
589 return nrow, ncol
589 return nrow, ncol
590
590
591 def setup(self, idfigure, nplots, wintitle):
591 def setup(self, idfigure, nplots, wintitle):
592
592
593 self.nplots = nplots
593 self.nplots = nplots
594
594
595 ncolspan = 1
595 ncolspan = 1
596 colspan = 1
596 colspan = 1
597
597
598 self.createFigure(idfigure = idfigure,
598 self.createFigure(idfigure = idfigure,
599 wintitle = wintitle,
599 wintitle = wintitle,
600 widthplot = self.WIDTH,
600 widthplot = self.WIDTH,
601 heightplot = self.HEIGHT)
601 heightplot = self.HEIGHT)
602
602
603 nrow, ncol = self.getSubplots()
603 nrow, ncol = self.getSubplots()
604
604
605 counter = 0
605 counter = 0
606 for y in range(nrow):
606 for y in range(nrow):
607 for x in range(ncol):
607 for x in range(ncol):
608 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
608 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
609
609
610 def run(self, dataOut, idfigure, wintitle="", channelList=None,
610 def run(self, dataOut, idfigure, wintitle="", channelList=None,
611 xmin=None, xmax=None, ymin=None, ymax=None,
611 xmin=None, xmax=None, ymin=None, ymax=None,
612 save=False, figpath='./', figfile=None):
612 save=False, figpath='./', figfile=None):
613
613
614 if channelList == None:
614 if channelList == None:
615 channelIndexList = dataOut.channelIndexList
615 channelIndexList = dataOut.channelIndexList
616 channelList = dataOut.channelList
616 channelList = dataOut.channelList
617 else:
617 else:
618 channelIndexList = []
618 channelIndexList = []
619 for channel in channelList:
619 for channel in channelList:
620 if channel not in dataOut.channelList:
620 if channel not in dataOut.channelList:
621 raise ValueError, "Channel %d is not in dataOut.channelList"
621 raise ValueError, "Channel %d is not in dataOut.channelList"
622 channelIndexList.append(dataOut.channelList.index(channel))
622 channelIndexList.append(dataOut.channelList.index(channel))
623
623
624
624
625 y = dataOut.getHeiRange()
625 y = dataOut.getHeiRange()
626 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
626 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
627 avg = numpy.average(x, axis=1)
627 avg = numpy.average(x, axis=1)
628
628
629
629
630 if not self.__isConfig:
630 if not self.__isConfig:
631
631
632 nplots = 1
632 nplots = 1
633
633
634 self.setup(idfigure=idfigure,
634 self.setup(idfigure=idfigure,
635 nplots=nplots,
635 nplots=nplots,
636 wintitle=wintitle)
636 wintitle=wintitle)
637
637
638 if ymin == None: ymin = numpy.nanmin(y)
638 if ymin == None: ymin = numpy.nanmin(y)
639 if ymax == None: ymax = numpy.nanmax(y)
639 if ymax == None: ymax = numpy.nanmax(y)
640 if xmin == None: xmin = numpy.nanmin(avg)*0.9
640 if xmin == None: xmin = numpy.nanmin(avg)*0.9
641 if xmax == None: xmax = numpy.nanmax(avg)*0.9
641 if xmax == None: xmax = numpy.nanmax(avg)*0.9
642
642
643 self.__isConfig = True
643 self.__isConfig = True
644
644
645 thisDatetime = dataOut.datatime
645 thisDatetime = dataOut.datatime
646 title = "Power Profile"
646 title = "Power Profile"
647 xlabel = "dB"
647 xlabel = "dB"
648 ylabel = "Range (Km)"
648 ylabel = "Range (Km)"
649
649
650 self.setWinTitle(title)
650 self.setWinTitle(title)
651
651
652
652
653 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
653 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
654 axes = self.axesList[0]
654 axes = self.axesList[0]
655
655
656 legendlabels = ["channel %d"%x for x in channelList]
656 legendlabels = ["channel %d"%x for x in channelList]
657 axes.pmultiline(avg, y,
657 axes.pmultiline(avg, y,
658 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
658 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
659 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
659 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
660 ytick_visible=True, nxticks=5,
660 ytick_visible=True, nxticks=5,
661 grid='x')
661 grid='x')
662
662
663 self.draw()
663 self.draw()
664
664
665 if save:
665 if save:
666 date = thisDatetime.strftime("%Y%m%d")
666 date = thisDatetime.strftime("%Y%m%d")
667 if figfile == None:
667 if figfile == None:
668 figfile = self.getFilename(name = date)
668 figfile = self.getFilename(name = date)
669
669
670 self.saveFigure(figpath, figfile)
670 self.saveFigure(figpath, figfile)
671
671
672 class CoherencePlot(Figure):
672 class CoherencePlot(Figure):
673 __isConfig = None
673 __isConfig = None
674 __nsubplots = None
674 __nsubplots = None
675
675
676 WIDTHPROF = None
676 WIDTHPROF = None
677 HEIGHTPROF = None
677 HEIGHTPROF = None
678 PREFIX = 'coherencemap'
678 PREFIX = 'coherencemap'
679
679
680 def __init__(self):
680 def __init__(self):
681 self.timerange = 24*60*60
681 self.timerange = 24*60*60
682 self.__isConfig = False
682 self.__isConfig = False
683 self.__nsubplots = 1
683 self.__nsubplots = 1
684
684
685 self.WIDTH = 800
685 self.WIDTH = 800
686 self.HEIGHT = 200
686 self.HEIGHT = 200
687 self.WIDTHPROF = 120
687 self.WIDTHPROF = 120
688 self.HEIGHTPROF = 0
688 self.HEIGHTPROF = 0
689
689
690 def getSubplots(self):
690 def getSubplots(self):
691 ncol = 1
691 ncol = 1
692 nrow = self.nplots*2
692 nrow = self.nplots*2
693
693
694 return nrow, ncol
694 return nrow, ncol
695
695
696 def setup(self, idfigure, nplots, wintitle, showprofile=True):
696 def setup(self, idfigure, nplots, wintitle, showprofile=True):
697 self.__showprofile = showprofile
697 self.__showprofile = showprofile
698 self.nplots = nplots
698 self.nplots = nplots
699
699
700 ncolspan = 1
700 ncolspan = 1
701 colspan = 1
701 colspan = 1
702 if showprofile:
702 if showprofile:
703 ncolspan = 7
703 ncolspan = 7
704 colspan = 6
704 colspan = 6
705 self.__nsubplots = 2
705 self.__nsubplots = 2
706
706
707 self.createFigure(idfigure = idfigure,
707 self.createFigure(idfigure = idfigure,
708 wintitle = wintitle,
708 wintitle = wintitle,
709 widthplot = self.WIDTH + self.WIDTHPROF,
709 widthplot = self.WIDTH + self.WIDTHPROF,
710 heightplot = self.HEIGHT + self.HEIGHTPROF)
710 heightplot = self.HEIGHT + self.HEIGHTPROF)
711
711
712 nrow, ncol = self.getSubplots()
712 nrow, ncol = self.getSubplots()
713
713
714 for y in range(nrow):
714 for y in range(nrow):
715 for x in range(ncol):
715 for x in range(ncol):
716
716
717 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
717 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
718
718
719 if showprofile:
719 if showprofile:
720 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
720 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
721
721
722 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
722 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
723 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
723 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
724 timerange=None,
724 timerange=None,
725 save=False, figpath='./', figfile=None):
725 save=False, figpath='./', figfile=None):
726
726
727 if pairsList == None:
727 if pairsList == None:
728 pairsIndexList = dataOut.pairsIndexList
728 pairsIndexList = dataOut.pairsIndexList
729 else:
729 else:
730 pairsIndexList = []
730 pairsIndexList = []
731 for pair in pairsList:
731 for pair in pairsList:
732 if pair not in dataOut.pairsList:
732 if pair not in dataOut.pairsList:
733 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
733 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
734 pairsIndexList.append(dataOut.pairsList.index(pair))
734 pairsIndexList.append(dataOut.pairsList.index(pair))
735
735
736 if timerange != None:
736 if timerange != None:
737 self.timerange = timerange
737 self.timerange = timerange
738
738
739 tmin = None
739 tmin = None
740 tmax = None
740 tmax = None
741 x = dataOut.getTimeRange()
741 x = dataOut.getTimeRange()
742 y = dataOut.getHeiRange()
742 y = dataOut.getHeiRange()
743
743
744 if not self.__isConfig:
744 if not self.__isConfig:
745 nplots = len(pairsIndexList)
745 nplots = len(pairsIndexList)
746 self.setup(idfigure=idfigure,
746 self.setup(idfigure=idfigure,
747 nplots=nplots,
747 nplots=nplots,
748 wintitle=wintitle,
748 wintitle=wintitle,
749 showprofile=showprofile)
749 showprofile=showprofile)
750
750
751 tmin, tmax = self.getTimeLim(x, xmin, xmax)
751 tmin, tmax = self.getTimeLim(x, xmin, xmax)
752 if ymin == None: ymin = numpy.nanmin(y)
752 if ymin == None: ymin = numpy.nanmin(y)
753 if ymax == None: ymax = numpy.nanmax(y)
753 if ymax == None: ymax = numpy.nanmax(y)
754
754
755 self.__isConfig = True
755 self.__isConfig = True
756
756
757 thisDatetime = dataOut.datatime
757 thisDatetime = dataOut.datatime
758 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
758 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
759 xlabel = ""
759 xlabel = ""
760 ylabel = "Range (Km)"
760 ylabel = "Range (Km)"
761
761
762 self.setWinTitle(title)
762 self.setWinTitle(title)
763
763
764 for i in range(self.nplots):
764 for i in range(self.nplots):
765
765
766 pair = dataOut.pairsList[pairsIndexList[i]]
766 pair = dataOut.pairsList[pairsIndexList[i]]
767 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
767 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
768 coherence = numpy.abs(coherenceComplex)
768 coherence = numpy.abs(coherenceComplex)
769 avg = numpy.average(coherence, axis=0)
769 avg = numpy.average(coherence, axis=0)
770 z = avg.reshape((1,-1))
770 z = avg.reshape((1,-1))
771
771
772 counter = 0
772 counter = 0
773
773
774 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
774 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
775 axes = self.axesList[i*self.__nsubplots*2]
775 axes = self.axesList[i*self.__nsubplots*2]
776 axes.pcolor(x, y, z,
776 axes.pcolor(x, y, z,
777 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
777 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
778 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
778 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
779 ticksize=9, cblabel='', cbsize="1%")
779 ticksize=9, cblabel='', cbsize="1%")
780
780
781 if self.__showprofile:
781 if self.__showprofile:
782 counter += 1
782 counter += 1
783 axes = self.axesList[i*self.__nsubplots*2 + counter]
783 axes = self.axesList[i*self.__nsubplots*2 + counter]
784 axes.pline(avg, y,
784 axes.pline(avg, y,
785 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
785 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
786 xlabel='', ylabel='', title='', ticksize=7,
786 xlabel='', ylabel='', title='', ticksize=7,
787 ytick_visible=False, nxticks=5,
787 ytick_visible=False, nxticks=5,
788 grid='x')
788 grid='x')
789
789
790 counter += 1
790 counter += 1
791 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
791 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
792 avg = numpy.average(phase, axis=0)
792 avg = numpy.average(phase, axis=0)
793 z = avg.reshape((1,-1))
793 z = avg.reshape((1,-1))
794
794
795 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
795 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
796 axes = self.axesList[i*self.__nsubplots*2 + counter]
796 axes = self.axesList[i*self.__nsubplots*2 + counter]
797 axes.pcolor(x, y, z,
797 axes.pcolor(x, y, z,
798 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
798 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
799 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
799 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
800 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
800 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
801
801
802 if self.__showprofile:
802 if self.__showprofile:
803 counter += 1
803 counter += 1
804 axes = self.axesList[i*self.__nsubplots*2 + counter]
804 axes = self.axesList[i*self.__nsubplots*2 + counter]
805 axes.pline(avg, y,
805 axes.pline(avg, y,
806 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
806 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
807 xlabel='', ylabel='', title='', ticksize=7,
807 xlabel='', ylabel='', title='', ticksize=7,
808 ytick_visible=False, nxticks=4,
808 ytick_visible=False, nxticks=4,
809 grid='x')
809 grid='x')
810
810
811 self.draw()
811 self.draw()
812
812
813 if save:
813 if save:
814 date = thisDatetime.strftime("%Y%m%d")
814 date = thisDatetime.strftime("%Y%m%d")
815 if figfile == None:
815 if figfile == None:
816 figfile = self.getFilename(name = date)
816 figfile = self.getFilename(name = date)
817
817
818 self.saveFigure(figpath, figfile)
818 self.saveFigure(figpath, figfile)
819
819
820 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
820 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
821 self.__isConfig = False
821 self.__isConfig = False
822
822
823 No newline at end of file
823 class RTIfromNoise(Figure):
824
825 __isConfig = None
826 __nsubplots = None
827
828 WIDTHPROF = None
829 HEIGHTPROF = None
830 PREFIX = 'rti'
831
832 def __init__(self):
833
834 self.__timerange = 24*60*60
835 self.__isConfig = False
836 self.__nsubplots = 1
837
838 self.WIDTH = 800
839 self.HEIGHT = 200
840
841 def getSubplots(self):
842
843 ncol = 1
844 nrow = self.nplots
845
846 return nrow, ncol
847
848 def setup(self, idfigure, nplots, wintitle, showprofile=True):
849
850 self.__showprofile = showprofile
851 self.nplots = nplots
852
853 ncolspan = 1
854 colspan = 1
855
856 self.createFigure(idfigure = idfigure,
857 wintitle = wintitle,
858 widthplot = self.WIDTH + self.WIDTHPROF,
859 heightplot = self.HEIGHT + self.HEIGHTPROF)
860
861 nrow, ncol = self.getSubplots()
862
863 self.addAxes(nrow, ncol, 0, 0, 1, 1)
864
865
866
867 def __getTimeLim(self, x, xmin, xmax):
868
869 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
870 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
871
872 ####################################################
873 #If the x is out of xrange
874 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
875 xmin = None
876 xmax = None
877
878 if xmin == None:
879 td = thisdatetime - thisdate
880 xmin = td.seconds/(60*60.)
881
882 if xmax == None:
883 xmax = xmin + self.__timerange/(60*60.)
884
885 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
886 tmin = time.mktime(mindt.timetuple())
887
888 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
889 tmax = time.mktime(maxdt.timetuple())
890
891 self.__timerange = tmax - tmin
892
893 return tmin, tmax
894
895 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
896 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
897 timerange=None,
898 save=False, figpath='./', figfile=None):
899
900 if channelList == None:
901 channelIndexList = dataOut.channelIndexList
902 else:
903 channelIndexList = []
904 for channel in channelList:
905 if channel not in dataOut.channelList:
906 raise ValueError, "Channel %d is not in dataOut.channelList"
907 channelIndexList.append(dataOut.channelList.index(channel))
908
909 if timerange != None:
910 self.__timerange = timerange
911
912 tmin = None
913 tmax = None
914 x = dataOut.getTimeRange()
915 y = dataOut.getHeiRange()
916 x1 = dataOut.datatime
917 # z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
918 # avg = numpy.average(z, axis=1)
919
920 noise = dataOut.getNoise()
921
922 if not self.__isConfig:
923
924 nplots = len(channelIndexList)
925
926 self.setup(idfigure=idfigure,
927 nplots=nplots,
928 wintitle=wintitle,
929 showprofile=showprofile)
930
931 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
932 if ymin == None: ymin = numpy.nanmin(y)
933 if ymax == None: ymax = numpy.nanmax(y)
934 if zmin == None: zmin = numpy.nanmin(avg)*0.9
935 if zmax == None: zmax = numpy.nanmax(avg)*0.9
936
937 self.__isConfig = True
938
939 thisDatetime = dataOut.datatime
940 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
941 xlabel = "Velocity (m/s)"
942 ylabel = "Range (Km)"
943
944 self.setWinTitle(title)
945
946 for i in range(self.nplots):
947 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
948 axes = self.axesList[i*self.__nsubplots]
949 z = avg[i].reshape((1,-1))
950 axes.pcolor(x, y, z,
951 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
952 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
953 ticksize=9, cblabel='', cbsize="1%")
954
955
956 self.draw()
957
958 if save:
959 date = thisDatetime.strftime("%Y%m%d")
960 if figfile == None:
961 figfile = self.getFilename(name = date)
962
963 self.saveFigure(figpath, figfile)
964
965 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
966 self.__isConfig = False
967 No newline at end of file
@@ -1,1074 +1,1150
1 '''
1 '''
2
2
3 $Author: dsuarez $
3 $Author: dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 '''
5 '''
6 import os
6 import os
7 import numpy
7 import numpy
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 from jrodata import *
11 from jrodata import *
12 from jrodataIO import *
12 from jrodataIO import *
13 from jroplot import *
13 from jroplot import *
14
14
15 class ProcessingUnit:
15 class ProcessingUnit:
16
16
17 """
17 """
18 Esta es la clase base para el procesamiento de datos.
18 Esta es la clase base para el procesamiento de datos.
19
19
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
21 - Metodos internos (callMethod)
21 - Metodos internos (callMethod)
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
23 tienen que ser agreagados con el metodo "add".
23 tienen que ser agreagados con el metodo "add".
24
24
25 """
25 """
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
27 dataIn = None
27 dataIn = None
28
28
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
30 dataOut = None
30 dataOut = None
31
31
32
32
33 objectDict = None
33 objectDict = None
34
34
35 def __init__(self):
35 def __init__(self):
36
36
37 self.objectDict = {}
37 self.objectDict = {}
38
38
39 def init(self):
39 def init(self):
40
40
41 raise ValueError, "Not implemented"
41 raise ValueError, "Not implemented"
42
42
43 def addOperation(self, object, objId):
43 def addOperation(self, object, objId):
44
44
45 """
45 """
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
47 identificador asociado a este objeto.
47 identificador asociado a este objeto.
48
48
49 Input:
49 Input:
50
50
51 object : objeto de la clase "Operation"
51 object : objeto de la clase "Operation"
52
52
53 Return:
53 Return:
54
54
55 objId : identificador del objeto, necesario para ejecutar la operacion
55 objId : identificador del objeto, necesario para ejecutar la operacion
56 """
56 """
57
57
58 self.objectDict[objId] = object
58 self.objectDict[objId] = object
59
59
60 return objId
60 return objId
61
61
62 def operation(self, **kwargs):
62 def operation(self, **kwargs):
63
63
64 """
64 """
65 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
65 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
66 atributos del objeto dataOut
66 atributos del objeto dataOut
67
67
68 Input:
68 Input:
69
69
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
71 """
71 """
72
72
73 raise ValueError, "ImplementedError"
73 raise ValueError, "ImplementedError"
74
74
75 def callMethod(self, name, **kwargs):
75 def callMethod(self, name, **kwargs):
76
76
77 """
77 """
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
79
79
80 Input:
80 Input:
81 name : nombre del metodo a ejecutar
81 name : nombre del metodo a ejecutar
82
82
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
84
84
85 """
85 """
86 if name != 'run':
86 if name != 'run':
87
87
88 if name == 'init' and self.dataIn.isEmpty():
88 if name == 'init' and self.dataIn.isEmpty():
89 self.dataOut.flagNoData = True
89 self.dataOut.flagNoData = True
90 return False
90 return False
91
91
92 if name != 'init' and self.dataOut.isEmpty():
92 if name != 'init' and self.dataOut.isEmpty():
93 return False
93 return False
94
94
95 methodToCall = getattr(self, name)
95 methodToCall = getattr(self, name)
96
96
97 methodToCall(**kwargs)
97 methodToCall(**kwargs)
98
98
99 if name != 'run':
99 if name != 'run':
100 return True
100 return True
101
101
102 if self.dataOut.isEmpty():
102 if self.dataOut.isEmpty():
103 return False
103 return False
104
104
105 return True
105 return True
106
106
107 def callObject(self, objId, **kwargs):
107 def callObject(self, objId, **kwargs):
108
108
109 """
109 """
110 Ejecuta la operacion asociada al identificador del objeto "objId"
110 Ejecuta la operacion asociada al identificador del objeto "objId"
111
111
112 Input:
112 Input:
113
113
114 objId : identificador del objeto a ejecutar
114 objId : identificador del objeto a ejecutar
115
115
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
117
117
118 Return:
118 Return:
119
119
120 None
120 None
121 """
121 """
122
122
123 if self.dataOut.isEmpty():
123 if self.dataOut.isEmpty():
124 return False
124 return False
125
125
126 object = self.objectDict[objId]
126 object = self.objectDict[objId]
127
127
128 object.run(self.dataOut, **kwargs)
128 object.run(self.dataOut, **kwargs)
129
129
130 return True
130 return True
131
131
132 def call(self, operationConf, **kwargs):
132 def call(self, operationConf, **kwargs):
133
133
134 """
134 """
135 Return True si ejecuta la operacion "operationConf.name" con los
135 Return True si ejecuta la operacion "operationConf.name" con los
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
137 La operacion puede ser de dos tipos:
137 La operacion puede ser de dos tipos:
138
138
139 1. Un metodo propio de esta clase:
139 1. Un metodo propio de esta clase:
140
140
141 operation.type = "self"
141 operation.type = "self"
142
142
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
144 operation.type = "other".
144 operation.type = "other".
145
145
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
147 "addOperation" e identificado con el operation.id
147 "addOperation" e identificado con el operation.id
148
148
149
149
150 con el id de la operacion.
150 con el id de la operacion.
151
151
152 Input:
152 Input:
153
153
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
155
155
156 """
156 """
157
157
158 if operationConf.type == 'self':
158 if operationConf.type == 'self':
159 sts = self.callMethod(operationConf.name, **kwargs)
159 sts = self.callMethod(operationConf.name, **kwargs)
160
160
161 if operationConf.type == 'other':
161 if operationConf.type == 'other':
162 sts = self.callObject(operationConf.id, **kwargs)
162 sts = self.callObject(operationConf.id, **kwargs)
163
163
164 return sts
164 return sts
165
165
166 def setInput(self, dataIn):
166 def setInput(self, dataIn):
167
167
168 self.dataIn = dataIn
168 self.dataIn = dataIn
169
169
170 def getOutput(self):
170 def getOutput(self):
171
171
172 return self.dataOut
172 return self.dataOut
173
173
174 class Operation():
174 class Operation():
175
175
176 """
176 """
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
179 acumulacion dentro de esta clase
179 acumulacion dentro de esta clase
180
180
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
182
182
183 """
183 """
184
184
185 __buffer = None
185 __buffer = None
186 __isConfig = False
186 __isConfig = False
187
187
188 def __init__(self):
188 def __init__(self):
189
189
190 pass
190 pass
191
191
192 def run(self, dataIn, **kwargs):
192 def run(self, dataIn, **kwargs):
193
193
194 """
194 """
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
196
196
197 Input:
197 Input:
198
198
199 dataIn : objeto del tipo JROData
199 dataIn : objeto del tipo JROData
200
200
201 Return:
201 Return:
202
202
203 None
203 None
204
204
205 Affected:
205 Affected:
206 __buffer : buffer de recepcion de datos.
206 __buffer : buffer de recepcion de datos.
207
207
208 """
208 """
209
209
210 raise ValueError, "ImplementedError"
210 raise ValueError, "ImplementedError"
211
211
212 class VoltageProc(ProcessingUnit):
212 class VoltageProc(ProcessingUnit):
213
213
214
214
215 def __init__(self):
215 def __init__(self):
216
216
217 self.objectDict = {}
217 self.objectDict = {}
218 self.dataOut = Voltage()
218 self.dataOut = Voltage()
219
219
220 def init(self):
220 def init(self):
221
221
222 self.dataOut.copy(self.dataIn)
222 self.dataOut.copy(self.dataIn)
223 # No necesita copiar en cada init() los atributos de dataIn
223 # No necesita copiar en cada init() los atributos de dataIn
224 # la copia deberia hacerse por cada nuevo bloque de datos
224 # la copia deberia hacerse por cada nuevo bloque de datos
225
225
226 def selectChannels(self, channelList):
226 def selectChannels(self, channelList):
227
227
228 channelIndexList = []
228 channelIndexList = []
229
229
230 for channel in channelList:
230 for channel in channelList:
231 index = self.dataOut.channelList.index(channel)
231 index = self.dataOut.channelList.index(channel)
232 channelIndexList.append(index)
232 channelIndexList.append(index)
233
233
234 self.selectChannelsByIndex(channelIndexList)
234 self.selectChannelsByIndex(channelIndexList)
235
235
236 def selectChannelsByIndex(self, channelIndexList):
236 def selectChannelsByIndex(self, channelIndexList):
237 """
237 """
238 Selecciona un bloque de datos en base a canales segun el channelIndexList
238 Selecciona un bloque de datos en base a canales segun el channelIndexList
239
239
240 Input:
240 Input:
241 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
241 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
242
242
243 Affected:
243 Affected:
244 self.dataOut.data
244 self.dataOut.data
245 self.dataOut.channelIndexList
245 self.dataOut.channelIndexList
246 self.dataOut.nChannels
246 self.dataOut.nChannels
247 self.dataOut.m_ProcessingHeader.totalSpectra
247 self.dataOut.m_ProcessingHeader.totalSpectra
248 self.dataOut.systemHeaderObj.numChannels
248 self.dataOut.systemHeaderObj.numChannels
249 self.dataOut.m_ProcessingHeader.blockSize
249 self.dataOut.m_ProcessingHeader.blockSize
250
250
251 Return:
251 Return:
252 None
252 None
253 """
253 """
254
254
255 for channelIndex in channelIndexList:
255 for channelIndex in channelIndexList:
256 if channelIndex not in self.dataOut.channelIndexList:
256 if channelIndex not in self.dataOut.channelIndexList:
257 print channelIndexList
257 print channelIndexList
258 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
258 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
259
259
260 nChannels = len(channelIndexList)
260 nChannels = len(channelIndexList)
261
261
262 data = self.dataOut.data[channelIndexList,:]
262 data = self.dataOut.data[channelIndexList,:]
263
263
264 self.dataOut.data = data
264 self.dataOut.data = data
265 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
265 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
266 # self.dataOut.nChannels = nChannels
266 # self.dataOut.nChannels = nChannels
267
267
268 return 1
268 return 1
269
269
270 def selectHeights(self, minHei, maxHei):
270 def selectHeights(self, minHei, maxHei):
271 """
271 """
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
273 minHei <= height <= maxHei
273 minHei <= height <= maxHei
274
274
275 Input:
275 Input:
276 minHei : valor minimo de altura a considerar
276 minHei : valor minimo de altura a considerar
277 maxHei : valor maximo de altura a considerar
277 maxHei : valor maximo de altura a considerar
278
278
279 Affected:
279 Affected:
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
281
281
282 Return:
282 Return:
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
284 """
284 """
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
287
287
288 if (maxHei > self.dataOut.heightList[-1]):
288 if (maxHei > self.dataOut.heightList[-1]):
289 maxHei = self.dataOut.heightList[-1]
289 maxHei = self.dataOut.heightList[-1]
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
291
291
292 minIndex = 0
292 minIndex = 0
293 maxIndex = 0
293 maxIndex = 0
294 data = self.dataOut.heightList
294 data = self.dataOut.heightList
295
295
296 for i,val in enumerate(data):
296 for i,val in enumerate(data):
297 if val < minHei:
297 if val < minHei:
298 continue
298 continue
299 else:
299 else:
300 minIndex = i;
300 minIndex = i;
301 break
301 break
302
302
303 for i,val in enumerate(data):
303 for i,val in enumerate(data):
304 if val <= maxHei:
304 if val <= maxHei:
305 maxIndex = i;
305 maxIndex = i;
306 else:
306 else:
307 break
307 break
308
308
309 self.selectHeightsByIndex(minIndex, maxIndex)
309 self.selectHeightsByIndex(minIndex, maxIndex)
310
310
311 return 1
311 return 1
312
312
313
313
314 def selectHeightsByIndex(self, minIndex, maxIndex):
314 def selectHeightsByIndex(self, minIndex, maxIndex):
315 """
315 """
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
317 minIndex <= index <= maxIndex
317 minIndex <= index <= maxIndex
318
318
319 Input:
319 Input:
320 minIndex : valor de indice minimo de altura a considerar
320 minIndex : valor de indice minimo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
322
322
323 Affected:
323 Affected:
324 self.dataOut.data
324 self.dataOut.data
325 self.dataOut.heightList
325 self.dataOut.heightList
326
326
327 Return:
327 Return:
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
329 """
329 """
330
330
331 if (minIndex < 0) or (minIndex > maxIndex):
331 if (minIndex < 0) or (minIndex > maxIndex):
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
333
333
334 if (maxIndex >= self.dataOut.nHeights):
334 if (maxIndex >= self.dataOut.nHeights):
335 maxIndex = self.dataOut.nHeights-1
335 maxIndex = self.dataOut.nHeights-1
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
337
337
338 nHeights = maxIndex - minIndex + 1
338 nHeights = maxIndex - minIndex + 1
339
339
340 #voltage
340 #voltage
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
342
342
343 firstHeight = self.dataOut.heightList[minIndex]
343 firstHeight = self.dataOut.heightList[minIndex]
344
344
345 self.dataOut.data = data
345 self.dataOut.data = data
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
347
347
348 return 1
348 return 1
349
349
350
351 def filterByHeights(self, window):
352 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
353
354 if window == None:
355 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
356
357 newdelta = deltaHeight * window
358 r = self.dataOut.data.shape[1] % window
359 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
360 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
361 buffer = numpy.average(buffer,2)
362 self.dataOut.data = buffer
363 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta)
364
365
350
366
351 class CohInt(Operation):
367 class CohInt(Operation):
352
368
353 __isConfig = False
369 __isConfig = False
354
370
355 __profIndex = 0
371 __profIndex = 0
356 __withOverapping = False
372 __withOverapping = False
357
373
358 __byTime = False
374 __byTime = False
359 __initime = None
375 __initime = None
360 __lastdatatime = None
376 __lastdatatime = None
361 __integrationtime = None
377 __integrationtime = None
362
378
363 __buffer = None
379 __buffer = None
364
380
365 __dataReady = False
381 __dataReady = False
366
382
367 n = None
383 n = None
368
384
369
385
370 def __init__(self):
386 def __init__(self):
371
387
372 self.__isConfig = False
388 self.__isConfig = False
373
389
374 def setup(self, n=None, timeInterval=None, overlapping=False):
390 def setup(self, n=None, timeInterval=None, overlapping=False):
375 """
391 """
376 Set the parameters of the integration class.
392 Set the parameters of the integration class.
377
393
378 Inputs:
394 Inputs:
379
395
380 n : Number of coherent integrations
396 n : Number of coherent integrations
381 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
397 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
382 overlapping :
398 overlapping :
383
399
384 """
400 """
385
401
386 self.__initime = None
402 self.__initime = None
387 self.__lastdatatime = 0
403 self.__lastdatatime = 0
388 self.__buffer = None
404 self.__buffer = None
389 self.__dataReady = False
405 self.__dataReady = False
390
406
391
407
392 if n == None and timeInterval == None:
408 if n == None and timeInterval == None:
393 raise ValueError, "n or timeInterval should be specified ..."
409 raise ValueError, "n or timeInterval should be specified ..."
394
410
395 if n != None:
411 if n != None:
396 self.n = n
412 self.n = n
397 self.__byTime = False
413 self.__byTime = False
398 else:
414 else:
399 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
415 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
400 self.n = 9999
416 self.n = 9999
401 self.__byTime = True
417 self.__byTime = True
402
418
403 if overlapping:
419 if overlapping:
404 self.__withOverapping = True
420 self.__withOverapping = True
405 self.__buffer = None
421 self.__buffer = None
406 else:
422 else:
407 self.__withOverapping = False
423 self.__withOverapping = False
408 self.__buffer = 0
424 self.__buffer = 0
409
425
410 self.__profIndex = 0
426 self.__profIndex = 0
411
427
412 def putData(self, data):
428 def putData(self, data):
413
429
414 """
430 """
415 Add a profile to the __buffer and increase in one the __profileIndex
431 Add a profile to the __buffer and increase in one the __profileIndex
416
432
417 """
433 """
418
434
419 if not self.__withOverapping:
435 if not self.__withOverapping:
420 self.__buffer += data.copy()
436 self.__buffer += data.copy()
421 self.__profIndex += 1
437 self.__profIndex += 1
422 return
438 return
423
439
424 #Overlapping data
440 #Overlapping data
425 nChannels, nHeis = data.shape
441 nChannels, nHeis = data.shape
426 data = numpy.reshape(data, (1, nChannels, nHeis))
442 data = numpy.reshape(data, (1, nChannels, nHeis))
427
443
428 #If the buffer is empty then it takes the data value
444 #If the buffer is empty then it takes the data value
429 if self.__buffer == None:
445 if self.__buffer == None:
430 self.__buffer = data
446 self.__buffer = data
431 self.__profIndex += 1
447 self.__profIndex += 1
432 return
448 return
433
449
434 #If the buffer length is lower than n then stakcing the data value
450 #If the buffer length is lower than n then stakcing the data value
435 if self.__profIndex < self.n:
451 if self.__profIndex < self.n:
436 self.__buffer = numpy.vstack((self.__buffer, data))
452 self.__buffer = numpy.vstack((self.__buffer, data))
437 self.__profIndex += 1
453 self.__profIndex += 1
438 return
454 return
439
455
440 #If the buffer length is equal to n then replacing the last buffer value with the data value
456 #If the buffer length is equal to n then replacing the last buffer value with the data value
441 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
457 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
442 self.__buffer[self.n-1] = data
458 self.__buffer[self.n-1] = data
443 self.__profIndex = self.n
459 self.__profIndex = self.n
444 return
460 return
445
461
446
462
447 def pushData(self):
463 def pushData(self):
448 """
464 """
449 Return the sum of the last profiles and the profiles used in the sum.
465 Return the sum of the last profiles and the profiles used in the sum.
450
466
451 Affected:
467 Affected:
452
468
453 self.__profileIndex
469 self.__profileIndex
454
470
455 """
471 """
456
472
457 if not self.__withOverapping:
473 if not self.__withOverapping:
458 data = self.__buffer
474 data = self.__buffer
459 n = self.__profIndex
475 n = self.__profIndex
460
476
461 self.__buffer = 0
477 self.__buffer = 0
462 self.__profIndex = 0
478 self.__profIndex = 0
463
479
464 return data, n
480 return data, n
465
481
466 #Integration with Overlapping
482 #Integration with Overlapping
467 data = numpy.sum(self.__buffer, axis=0)
483 data = numpy.sum(self.__buffer, axis=0)
468 n = self.__profIndex
484 n = self.__profIndex
469
485
470 return data, n
486 return data, n
471
487
472 def byProfiles(self, data):
488 def byProfiles(self, data):
473
489
474 self.__dataReady = False
490 self.__dataReady = False
475 avgdata = None
491 avgdata = None
476 n = None
492 n = None
477
493
478 self.putData(data)
494 self.putData(data)
479
495
480 if self.__profIndex == self.n:
496 if self.__profIndex == self.n:
481
497
482 avgdata, n = self.pushData()
498 avgdata, n = self.pushData()
483 self.__dataReady = True
499 self.__dataReady = True
484
500
485 return avgdata
501 return avgdata
486
502
487 def byTime(self, data, datatime):
503 def byTime(self, data, datatime):
488
504
489 self.__dataReady = False
505 self.__dataReady = False
490 avgdata = None
506 avgdata = None
491 n = None
507 n = None
492
508
493 self.putData(data)
509 self.putData(data)
494
510
495 if (datatime - self.__initime) >= self.__integrationtime:
511 if (datatime - self.__initime) >= self.__integrationtime:
496 avgdata, n = self.pushData()
512 avgdata, n = self.pushData()
497 self.n = n
513 self.n = n
498 self.__dataReady = True
514 self.__dataReady = True
499
515
500 return avgdata
516 return avgdata
501
517
502 def integrate(self, data, datatime=None):
518 def integrate(self, data, datatime=None):
503
519
504 if self.__initime == None:
520 if self.__initime == None:
505 self.__initime = datatime
521 self.__initime = datatime
506
522
507 if self.__byTime:
523 if self.__byTime:
508 avgdata = self.byTime(data, datatime)
524 avgdata = self.byTime(data, datatime)
509 else:
525 else:
510 avgdata = self.byProfiles(data)
526 avgdata = self.byProfiles(data)
511
527
512
528
513 self.__lastdatatime = datatime
529 self.__lastdatatime = datatime
514
530
515 if avgdata == None:
531 if avgdata == None:
516 return None, None
532 return None, None
517
533
518 avgdatatime = self.__initime
534 avgdatatime = self.__initime
519
535
520 deltatime = datatime -self.__lastdatatime
536 deltatime = datatime -self.__lastdatatime
521
537
522 if not self.__withOverapping:
538 if not self.__withOverapping:
523 self.__initime = datatime
539 self.__initime = datatime
524 else:
540 else:
525 self.__initime += deltatime
541 self.__initime += deltatime
526
542
527 return avgdata, avgdatatime
543 return avgdata, avgdatatime
528
544
529 def run(self, dataOut, **kwargs):
545 def run(self, dataOut, **kwargs):
530
546
531 if not self.__isConfig:
547 if not self.__isConfig:
532 self.setup(**kwargs)
548 self.setup(**kwargs)
533 self.__isConfig = True
549 self.__isConfig = True
534
550
535 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
551 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
536
552
537 # dataOut.timeInterval *= n
553 # dataOut.timeInterval *= n
538 dataOut.flagNoData = True
554 dataOut.flagNoData = True
539
555
540 if self.__dataReady:
556 if self.__dataReady:
541 dataOut.data = avgdata
557 dataOut.data = avgdata
542 dataOut.nCohInt *= self.n
558 dataOut.nCohInt *= self.n
543 dataOut.utctime = avgdatatime
559 dataOut.utctime = avgdatatime
544 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
560 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
545 dataOut.flagNoData = False
561 dataOut.flagNoData = False
546
562
563
547 class Decoder(Operation):
564 class Decoder(Operation):
548
565
549 __isConfig = False
566 __isConfig = False
550 __profIndex = 0
567 __profIndex = 0
551
568
552 code = None
569 code = None
553
570
554 nCode = None
571 nCode = None
555 nBaud = None
572 nBaud = None
556
573
557 def __init__(self):
574 def __init__(self):
558
575
559 self.__isConfig = False
576 self.__isConfig = False
560
577
561 def setup(self, code):
578 def setup(self, code):
562
579
563 self.__profIndex = 0
580 self.__profIndex = 0
564
581
565 self.code = code
582 self.code = code
566
583
567 self.nCode = len(code)
584 self.nCode = len(code)
568 self.nBaud = len(code[0])
585 self.nBaud = len(code[0])
569
586
570 def convolutionInFreq(self, data):
587 def convolutionInFreq(self, data):
571
588
572 ndata = data.shape[1]
589 ndata = data.shape[1]
573 newcode = numpy.zeros(ndata)
590 newcode = numpy.zeros(ndata)
574 newcode[0:self.nBaud] = self.code[self.__profIndex]
591 newcode[0:self.nBaud] = self.code[self.__profIndex]
575
592
576 fft_data = numpy.fft.fft(data, axis=1)
593 fft_data = numpy.fft.fft(data, axis=1)
577 fft_code = numpy.conj(numpy.fft.fft(newcode))
594 fft_code = numpy.conj(numpy.fft.fft(newcode))
578 fft_code = fft_code.reshape(1,len(fft_code))
595 fft_code = fft_code.reshape(1,len(fft_code))
579
596
580 # conv = fft_data.copy()
597 # conv = fft_data.copy()
581 # conv.fill(0)
598 # conv.fill(0)
582
599
583 conv = fft_data*fft_code
600 conv = fft_data*fft_code
584
601
585 data = numpy.fft.ifft(conv,axis=1)
602 data = numpy.fft.ifft(conv,axis=1)
586
603
587 datadec = data[:,:-self.nBaud+1]
604 datadec = data[:,:-self.nBaud+1]
588 ndatadec = ndata - self.nBaud + 1
605 ndatadec = ndata - self.nBaud + 1
589
606
590 if self.__profIndex == self.nCode:
607 if self.__profIndex == self.nCode:
591 self.__profIndex = 0
608 self.__profIndex = 0
592
609
593 self.__profIndex += 1
610 self.__profIndex += 1
594
611
595 return ndatadec, datadec
612 return ndatadec, datadec
596
613
597
614
598 def convolutionInTime(self, data):
615 def convolutionInTime(self, data):
599
616
600 nchannel = data.shape[1]
617 nchannel = data.shape[1]
601 newcode = self.code[self.__profIndex]
618 newcode = self.code[self.__profIndex]
602
619
603 datadec = data.copy()
620 datadec = data.copy()
604
621
605 for i in range(nchannel):
622 for i in range(nchannel):
606 datadec[i,:] = numpy.correlate(data[i,:], newcode)
623 datadec[i,:] = numpy.correlate(data[i,:], newcode)
607
624
608 ndatadec = ndata - self.nBaud + 1
625 ndatadec = ndata - self.nBaud + 1
609
626
610 if self.__profIndex == self.nCode:
627 if self.__profIndex == self.nCode:
611 self.__profIndex = 0
628 self.__profIndex = 0
612
629
613 self.__profIndex += 1
630 self.__profIndex += 1
614
631
615 return ndatadec, datadec
632 return ndatadec, datadec
616
633
617 def run(self, dataOut, code=None, mode = 0):
634 def run(self, dataOut, code=None, mode = 0):
618
635
619 if not self.__isConfig:
636 if not self.__isConfig:
620
637
621 if code == None:
638 if code == None:
622 code = dataOut.code
639 code = dataOut.code
623
640
624 self.setup(code)
641 self.setup(code)
625 self.__isConfig = True
642 self.__isConfig = True
626
643
627 if mode == 0:
644 if mode == 0:
628 ndatadec, datadec = self.convolutionInFreq(data)
645 ndatadec, datadec = self.convolutionInFreq(data)
629
646
630 if mode == 1:
647 if mode == 1:
631 ndatadec, datadec = self.convolutionInTime(data)
648 ndatadec, datadec = self.convolutionInTime(data)
632
649
633 dataOut.data = datadec
650 dataOut.data = datadec
634
651
635 dataOut.heightList = dataOut.heightList[0:ndatadec+1]
652 dataOut.heightList = dataOut.heightList[0:ndatadec+1]
636
653
637 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
654 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
638
655
639 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
656 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
640
657
641
642
658
643 class SpectraProc(ProcessingUnit):
659 class SpectraProc(ProcessingUnit):
644
660
645 def __init__(self):
661 def __init__(self):
646
662
647 self.objectDict = {}
663 self.objectDict = {}
648 self.buffer = None
664 self.buffer = None
649 self.firstdatatime = None
665 self.firstdatatime = None
650 self.profIndex = 0
666 self.profIndex = 0
651 self.dataOut = Spectra()
667 self.dataOut = Spectra()
652
668
653 def __updateObjFromInput(self):
669 def __updateObjFromInput(self):
654
670
655 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
671 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
656 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
672 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
657 self.dataOut.channelList = self.dataIn.channelList
673 self.dataOut.channelList = self.dataIn.channelList
658 self.dataOut.heightList = self.dataIn.heightList
674 self.dataOut.heightList = self.dataIn.heightList
659 self.dataOut.dtype = self.dataIn.dtype
675 self.dataOut.dtype = self.dataIn.dtype
660 # self.dataOut.nHeights = self.dataIn.nHeights
676 # self.dataOut.nHeights = self.dataIn.nHeights
661 # self.dataOut.nChannels = self.dataIn.nChannels
677 # self.dataOut.nChannels = self.dataIn.nChannels
662 self.dataOut.nBaud = self.dataIn.nBaud
678 self.dataOut.nBaud = self.dataIn.nBaud
663 self.dataOut.nCode = self.dataIn.nCode
679 self.dataOut.nCode = self.dataIn.nCode
664 self.dataOut.code = self.dataIn.code
680 self.dataOut.code = self.dataIn.code
665 self.dataOut.nProfiles = self.dataOut.nFFTPoints
681 self.dataOut.nProfiles = self.dataOut.nFFTPoints
666 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
682 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
667 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
683 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
668 self.dataOut.utctime = self.firstdatatime
684 self.dataOut.utctime = self.firstdatatime
669 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
685 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
670 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
686 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
671 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
687 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
672 self.dataOut.nCohInt = self.dataIn.nCohInt
688 self.dataOut.nCohInt = self.dataIn.nCohInt
673 self.dataOut.nIncohInt = 1
689 self.dataOut.nIncohInt = 1
674 self.dataOut.ippSeconds = self.dataIn.ippSeconds
690 self.dataOut.ippSeconds = self.dataIn.ippSeconds
675
691
676 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
692 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
677
693
678 def __getFft(self):
694 def __getFft(self):
679 """
695 """
680 Convierte valores de Voltaje a Spectra
696 Convierte valores de Voltaje a Spectra
681
697
682 Affected:
698 Affected:
683 self.dataOut.data_spc
699 self.dataOut.data_spc
684 self.dataOut.data_cspc
700 self.dataOut.data_cspc
685 self.dataOut.data_dc
701 self.dataOut.data_dc
686 self.dataOut.heightList
702 self.dataOut.heightList
687 self.profIndex
703 self.profIndex
688 self.buffer
704 self.buffer
689 self.dataOut.flagNoData
705 self.dataOut.flagNoData
690 """
706 """
691 fft_volt = numpy.fft.fft(self.buffer,axis=1)
707 fft_volt = numpy.fft.fft(self.buffer,axis=1)
692 dc = fft_volt[:,0,:]
708 dc = fft_volt[:,0,:]
693
709
694 #calculo de self-spectra
710 #calculo de self-spectra
695 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
711 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
696 spc = fft_volt * numpy.conjugate(fft_volt)
712 spc = fft_volt * numpy.conjugate(fft_volt)
697 spc = spc.real
713 spc = spc.real
698
714
699 blocksize = 0
715 blocksize = 0
700 blocksize += dc.size
716 blocksize += dc.size
701 blocksize += spc.size
717 blocksize += spc.size
702
718
703 cspc = None
719 cspc = None
704 pairIndex = 0
720 pairIndex = 0
705 if self.dataOut.pairsList != None:
721 if self.dataOut.pairsList != None:
706 #calculo de cross-spectra
722 #calculo de cross-spectra
707 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
723 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
708 for pair in self.dataOut.pairsList:
724 for pair in self.dataOut.pairsList:
709 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
725 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
710 pairIndex += 1
726 pairIndex += 1
711 blocksize += cspc.size
727 blocksize += cspc.size
712
728
713 self.dataOut.data_spc = spc
729 self.dataOut.data_spc = spc
714 self.dataOut.data_cspc = cspc
730 self.dataOut.data_cspc = cspc
715 self.dataOut.data_dc = dc
731 self.dataOut.data_dc = dc
716 self.dataOut.blockSize = blocksize
732 self.dataOut.blockSize = blocksize
717
733
718 def init(self, nFFTPoints=None, pairsList=None):
734 def init(self, nFFTPoints=None, pairsList=None):
719
735
720 self.dataOut.flagNoData = True
736 self.dataOut.flagNoData = True
721
737
722 if self.dataIn.type == "Spectra":
738 if self.dataIn.type == "Spectra":
723 self.dataOut.copy(self.dataIn)
739 self.dataOut.copy(self.dataIn)
724 return
740 return
725
741
726 if self.dataIn.type == "Voltage":
742 if self.dataIn.type == "Voltage":
727
743
728 if nFFTPoints == None:
744 if nFFTPoints == None:
729 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
745 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
730
746
731 if pairsList == None:
747 if pairsList == None:
732 nPairs = 0
748 nPairs = 0
733 else:
749 else:
734 nPairs = len(pairsList)
750 nPairs = len(pairsList)
735
751
736 self.dataOut.nFFTPoints = nFFTPoints
752 self.dataOut.nFFTPoints = nFFTPoints
737 self.dataOut.pairsList = pairsList
753 self.dataOut.pairsList = pairsList
738 self.dataOut.nPairs = nPairs
754 self.dataOut.nPairs = nPairs
739
755
740 if self.buffer == None:
756 if self.buffer == None:
741 self.buffer = numpy.zeros((self.dataIn.nChannels,
757 self.buffer = numpy.zeros((self.dataIn.nChannels,
742 self.dataOut.nFFTPoints,
758 self.dataOut.nFFTPoints,
743 self.dataIn.nHeights),
759 self.dataIn.nHeights),
744 dtype='complex')
760 dtype='complex')
745
761
746
762
747 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
763 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
748 self.profIndex += 1
764 self.profIndex += 1
749
765
750 if self.firstdatatime == None:
766 if self.firstdatatime == None:
751 self.firstdatatime = self.dataIn.utctime
767 self.firstdatatime = self.dataIn.utctime
752
768
753 if self.profIndex == self.dataOut.nFFTPoints:
769 if self.profIndex == self.dataOut.nFFTPoints:
754 self.__updateObjFromInput()
770 self.__updateObjFromInput()
755 self.__getFft()
771 self.__getFft()
756
772
757 self.dataOut.flagNoData = False
773 self.dataOut.flagNoData = False
758
774
759 self.buffer = None
775 self.buffer = None
760 self.firstdatatime = None
776 self.firstdatatime = None
761 self.profIndex = 0
777 self.profIndex = 0
762
778
763 return
779 return
764
780
765 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
781 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
766
782
767 def selectChannels(self, channelList):
783 def selectChannels(self, channelList):
768
784
769 channelIndexList = []
785 channelIndexList = []
770
786
771 for channel in channelList:
787 for channel in channelList:
772 index = self.dataOut.channelList.index(channel)
788 index = self.dataOut.channelList.index(channel)
773 channelIndexList.append(index)
789 channelIndexList.append(index)
774
790
775 self.selectChannelsByIndex(channelIndexList)
791 self.selectChannelsByIndex(channelIndexList)
776
792
777 def selectChannelsByIndex(self, channelIndexList):
793 def selectChannelsByIndex(self, channelIndexList):
778 """
794 """
779 Selecciona un bloque de datos en base a canales segun el channelIndexList
795 Selecciona un bloque de datos en base a canales segun el channelIndexList
780
796
781 Input:
797 Input:
782 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
798 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
783
799
784 Affected:
800 Affected:
785 self.dataOut.data_spc
801 self.dataOut.data_spc
786 self.dataOut.channelIndexList
802 self.dataOut.channelIndexList
787 self.dataOut.nChannels
803 self.dataOut.nChannels
788
804
789 Return:
805 Return:
790 None
806 None
791 """
807 """
792
808
793 for channelIndex in channelIndexList:
809 for channelIndex in channelIndexList:
794 if channelIndex not in self.dataOut.channelIndexList:
810 if channelIndex not in self.dataOut.channelIndexList:
795 print channelIndexList
811 print channelIndexList
796 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
812 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
797
813
798 nChannels = len(channelIndexList)
814 nChannels = len(channelIndexList)
799
815
800 data_spc = self.dataOut.data_spc[channelIndexList,:]
816 data_spc = self.dataOut.data_spc[channelIndexList,:]
801
817
802 self.dataOut.data_spc = data_spc
818 self.dataOut.data_spc = data_spc
803 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
819 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
804 # self.dataOut.nChannels = nChannels
820 # self.dataOut.nChannels = nChannels
805
821
806 return 1
822 return 1
807
823
808
824
809 class IncohInt(Operation):
825 class IncohInt(Operation):
810
826
811
827
812 __profIndex = 0
828 __profIndex = 0
813 __withOverapping = False
829 __withOverapping = False
814
830
815 __byTime = False
831 __byTime = False
816 __initime = None
832 __initime = None
817 __lastdatatime = None
833 __lastdatatime = None
818 __integrationtime = None
834 __integrationtime = None
819
835
820 __buffer_spc = None
836 __buffer_spc = None
821 __buffer_cspc = None
837 __buffer_cspc = None
822 __buffer_dc = None
838 __buffer_dc = None
823
839
824 __dataReady = False
840 __dataReady = False
825
841
826 n = None
842 n = None
827
843
828
844
829 def __init__(self):
845 def __init__(self):
830
846
831 self.__isConfig = False
847 self.__isConfig = False
832
848
833 def setup(self, n=None, timeInterval=None, overlapping=False):
849 def setup(self, n=None, timeInterval=None, overlapping=False):
834 """
850 """
835 Set the parameters of the integration class.
851 Set the parameters of the integration class.
836
852
837 Inputs:
853 Inputs:
838
854
839 n : Number of coherent integrations
855 n : Number of coherent integrations
840 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
856 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
841 overlapping :
857 overlapping :
842
858
843 """
859 """
844
860
845 self.__initime = None
861 self.__initime = None
846 self.__lastdatatime = 0
862 self.__lastdatatime = 0
847 self.__buffer_spc = None
863 self.__buffer_spc = None
848 self.__buffer_cspc = None
864 self.__buffer_cspc = None
849 self.__buffer_dc = None
865 self.__buffer_dc = None
850 self.__dataReady = False
866 self.__dataReady = False
851
867
852
868
853 if n == None and timeInterval == None:
869 if n == None and timeInterval == None:
854 raise ValueError, "n or timeInterval should be specified ..."
870 raise ValueError, "n or timeInterval should be specified ..."
855
871
856 if n != None:
872 if n != None:
857 self.n = n
873 self.n = n
858 self.__byTime = False
874 self.__byTime = False
859 else:
875 else:
860 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
876 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
861 self.n = 9999
877 self.n = 9999
862 self.__byTime = True
878 self.__byTime = True
863
879
864 if overlapping:
880 if overlapping:
865 self.__withOverapping = True
881 self.__withOverapping = True
866 else:
882 else:
867 self.__withOverapping = False
883 self.__withOverapping = False
868 self.__buffer_spc = 0
884 self.__buffer_spc = 0
869 self.__buffer_cspc = 0
885 self.__buffer_cspc = 0
870 self.__buffer_dc = 0
886 self.__buffer_dc = 0
871
887
872 self.__profIndex = 0
888 self.__profIndex = 0
873
889
874 def putData(self, data_spc, data_cspc, data_dc):
890 def putData(self, data_spc, data_cspc, data_dc):
875
891
876 """
892 """
877 Add a profile to the __buffer_spc and increase in one the __profileIndex
893 Add a profile to the __buffer_spc and increase in one the __profileIndex
878
894
879 """
895 """
880
896
881 if not self.__withOverapping:
897 if not self.__withOverapping:
882 self.__buffer_spc += data_spc
898 self.__buffer_spc += data_spc
883
899
884 if data_cspc == None:
900 if data_cspc == None:
885 self.__buffer_cspc = None
901 self.__buffer_cspc = None
886 else:
902 else:
887 self.__buffer_cspc += data_cspc
903 self.__buffer_cspc += data_cspc
888
904
889 if data_dc == None:
905 if data_dc == None:
890 self.__buffer_dc = None
906 self.__buffer_dc = None
891 else:
907 else:
892 self.__buffer_dc += data_dc
908 self.__buffer_dc += data_dc
893
909
894 self.__profIndex += 1
910 self.__profIndex += 1
895 return
911 return
896
912
897 #Overlapping data
913 #Overlapping data
898 nChannels, nFFTPoints, nHeis = data_spc.shape
914 nChannels, nFFTPoints, nHeis = data_spc.shape
899 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
915 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
900 if data_cspc != None:
916 if data_cspc != None:
901 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
917 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
902 if data_dc != None:
918 if data_dc != None:
903 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
919 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
904
920
905 #If the buffer is empty then it takes the data value
921 #If the buffer is empty then it takes the data value
906 if self.__buffer_spc == None:
922 if self.__buffer_spc == None:
907 self.__buffer_spc = data_spc
923 self.__buffer_spc = data_spc
908
924
909 if data_cspc == None:
925 if data_cspc == None:
910 self.__buffer_cspc = None
926 self.__buffer_cspc = None
911 else:
927 else:
912 self.__buffer_cspc += data_cspc
928 self.__buffer_cspc += data_cspc
913
929
914 if data_dc == None:
930 if data_dc == None:
915 self.__buffer_dc = None
931 self.__buffer_dc = None
916 else:
932 else:
917 self.__buffer_dc += data_dc
933 self.__buffer_dc += data_dc
918
934
919 self.__profIndex += 1
935 self.__profIndex += 1
920 return
936 return
921
937
922 #If the buffer length is lower than n then stakcing the data value
938 #If the buffer length is lower than n then stakcing the data value
923 if self.__profIndex < self.n:
939 if self.__profIndex < self.n:
924 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
940 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
925
941
926 if data_cspc != None:
942 if data_cspc != None:
927 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
943 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
928
944
929 if data_dc != None:
945 if data_dc != None:
930 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
946 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
931
947
932 self.__profIndex += 1
948 self.__profIndex += 1
933 return
949 return
934
950
935 #If the buffer length is equal to n then replacing the last buffer value with the data value
951 #If the buffer length is equal to n then replacing the last buffer value with the data value
936 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
952 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
937 self.__buffer_spc[self.n-1] = data_spc
953 self.__buffer_spc[self.n-1] = data_spc
938
954
939 if data_cspc != None:
955 if data_cspc != None:
940 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
956 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
941 self.__buffer_cspc[self.n-1] = data_cspc
957 self.__buffer_cspc[self.n-1] = data_cspc
942
958
943 if data_dc != None:
959 if data_dc != None:
944 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
960 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
945 self.__buffer_dc[self.n-1] = data_dc
961 self.__buffer_dc[self.n-1] = data_dc
946
962
947 self.__profIndex = self.n
963 self.__profIndex = self.n
948 return
964 return
949
965
950
966
951 def pushData(self):
967 def pushData(self):
952 """
968 """
953 Return the sum of the last profiles and the profiles used in the sum.
969 Return the sum of the last profiles and the profiles used in the sum.
954
970
955 Affected:
971 Affected:
956
972
957 self.__profileIndex
973 self.__profileIndex
958
974
959 """
975 """
960 data_spc = None
976 data_spc = None
961 data_cspc = None
977 data_cspc = None
962 data_dc = None
978 data_dc = None
963
979
964 if not self.__withOverapping:
980 if not self.__withOverapping:
965 data_spc = self.__buffer_spc
981 data_spc = self.__buffer_spc
966 data_cspc = self.__buffer_cspc
982 data_cspc = self.__buffer_cspc
967 data_dc = self.__buffer_dc
983 data_dc = self.__buffer_dc
968
984
969 n = self.__profIndex
985 n = self.__profIndex
970
986
971 self.__buffer_spc = 0
987 self.__buffer_spc = 0
972 self.__buffer_cspc = 0
988 self.__buffer_cspc = 0
973 self.__buffer_dc = 0
989 self.__buffer_dc = 0
974 self.__profIndex = 0
990 self.__profIndex = 0
975
991
976 return data_spc, data_cspc, data_dc, n
992 return data_spc, data_cspc, data_dc, n
977
993
978 #Integration with Overlapping
994 #Integration with Overlapping
979 data_spc = numpy.sum(self.__buffer_spc, axis=0)
995 data_spc = numpy.sum(self.__buffer_spc, axis=0)
980
996
981 if self.__buffer_cspc != None:
997 if self.__buffer_cspc != None:
982 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
998 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
983
999
984 if self.__buffer_dc != None:
1000 if self.__buffer_dc != None:
985 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1001 data_dc = numpy.sum(self.__buffer_dc, axis=0)
986
1002
987 n = self.__profIndex
1003 n = self.__profIndex
988
1004
989 return data_spc, data_cspc, data_dc, n
1005 return data_spc, data_cspc, data_dc, n
990
1006
991 def byProfiles(self, *args):
1007 def byProfiles(self, *args):
992
1008
993 self.__dataReady = False
1009 self.__dataReady = False
994 avgdata_spc = None
1010 avgdata_spc = None
995 avgdata_cspc = None
1011 avgdata_cspc = None
996 avgdata_dc = None
1012 avgdata_dc = None
997 n = None
1013 n = None
998
1014
999 self.putData(*args)
1015 self.putData(*args)
1000
1016
1001 if self.__profIndex == self.n:
1017 if self.__profIndex == self.n:
1002
1018
1003 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1019 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1004 self.__dataReady = True
1020 self.__dataReady = True
1005
1021
1006 return avgdata_spc, avgdata_cspc, avgdata_dc
1022 return avgdata_spc, avgdata_cspc, avgdata_dc
1007
1023
1008 def byTime(self, datatime, *args):
1024 def byTime(self, datatime, *args):
1009
1025
1010 self.__dataReady = False
1026 self.__dataReady = False
1011 avgdata_spc = None
1027 avgdata_spc = None
1012 avgdata_cspc = None
1028 avgdata_cspc = None
1013 avgdata_dc = None
1029 avgdata_dc = None
1014 n = None
1030 n = None
1015
1031
1016 self.putData(*args)
1032 self.putData(*args)
1017
1033
1018 if (datatime - self.__initime) >= self.__integrationtime:
1034 if (datatime - self.__initime) >= self.__integrationtime:
1019 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1035 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1020 self.n = n
1036 self.n = n
1021 self.__dataReady = True
1037 self.__dataReady = True
1022
1038
1023 return avgdata_spc, avgdata_cspc, avgdata_dc
1039 return avgdata_spc, avgdata_cspc, avgdata_dc
1024
1040
1025 def integrate(self, datatime, *args):
1041 def integrate(self, datatime, *args):
1026
1042
1027 if self.__initime == None:
1043 if self.__initime == None:
1028 self.__initime = datatime
1044 self.__initime = datatime
1029
1045
1030 if self.__byTime:
1046 if self.__byTime:
1031 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1047 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1032 else:
1048 else:
1033 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1049 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1034
1050
1035 self.__lastdatatime = datatime
1051 self.__lastdatatime = datatime
1036
1052
1037 if avgdata_spc == None:
1053 if avgdata_spc == None:
1038 return None, None, None, None
1054 return None, None, None, None
1039
1055
1040 avgdatatime = self.__initime
1056 avgdatatime = self.__initime
1041
1057
1042 deltatime = datatime -self.__lastdatatime
1058 deltatime = datatime -self.__lastdatatime
1043
1059
1044 if not self.__withOverapping:
1060 if not self.__withOverapping:
1045 self.__initime = datatime
1061 self.__initime = datatime
1046 else:
1062 else:
1047 self.__initime += deltatime
1063 self.__initime += deltatime
1048
1064
1049 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1065 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1050
1066
1051 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1067 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1052
1068
1053 if not self.__isConfig:
1069 if not self.__isConfig:
1054 self.setup(n, timeInterval, overlapping)
1070 self.setup(n, timeInterval, overlapping)
1055 self.__isConfig = True
1071 self.__isConfig = True
1056
1072
1057 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1073 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1058 dataOut.data_spc,
1074 dataOut.data_spc,
1059 dataOut.data_cspc,
1075 dataOut.data_cspc,
1060 dataOut.data_dc)
1076 dataOut.data_dc)
1061
1077
1062 # dataOut.timeInterval *= n
1078 # dataOut.timeInterval *= n
1063 dataOut.flagNoData = True
1079 dataOut.flagNoData = True
1064
1080
1065 if self.__dataReady:
1081 if self.__dataReady:
1066 dataOut.data_spc = avgdata_spc
1082 dataOut.data_spc = avgdata_spc
1067 dataOut.data_cspc = avgdata_cspc
1083 dataOut.data_cspc = avgdata_cspc
1068 dataOut.data_dc = avgdata_dc
1084 dataOut.data_dc = avgdata_dc
1069
1085
1070 dataOut.nIncohInt *= self.n
1086 dataOut.nIncohInt *= self.n
1071 dataOut.utctime = avgdatatime
1087 dataOut.utctime = avgdatatime
1072 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1088 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1073 dataOut.flagNoData = False
1089 dataOut.flagNoData = False
1074 No newline at end of file
1090
1091 class ProfileSelector(Operation):
1092
1093 profileIndex = None
1094 # Tamanho total de los perfiles
1095 nProfiles = None
1096
1097 def __init__(self):
1098
1099 self.profileIndex = 0
1100
1101 def incIndex(self):
1102 self.profileIndex += 1
1103
1104 if self.profileIndex >= self.nProfiles:
1105 self.profileIndex = 0
1106
1107 def isProfileInRange(self, minIndex, maxIndex):
1108
1109 if self.profileIndex < minIndex:
1110 return False
1111
1112 if self.profileIndex > maxIndex:
1113 return False
1114
1115 return True
1116
1117 def isProfileInList(self, profileList):
1118
1119 if self.profileIndex not in profileList:
1120 return False
1121
1122 return True
1123
1124 def run(self, dataOut, profileList=None, profileRangeList=None):
1125
1126 self.nProfiles = dataOut.nProfiles
1127
1128 if profileList != None:
1129 if not(self.isProfileInList(profileList)):
1130 dataOut.flagNoData = True
1131 else:
1132 dataOut.flagNoData = False
1133 self.incIndex()
1134 return 1
1135
1136
1137 elif profileRangeList != None:
1138 minIndex = profileRangeList[0]
1139 maxIndex = profileRangeList[1]
1140 if not(self.isProfileInRange(minIndex, maxIndex)):
1141 dataOut.flagNoData = True
1142 else:
1143 dataOut.flagNoData = False
1144 self.incIndex()
1145 return 1
1146 else:
1147 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1148
1149 return 0
1150
General Comments 0
You need to be logged in to leave comments. Login now