##// END OF EJS Templates
update de operacion voltACFLags en jroproc_voltage.py y VoltACFPLot en jroplot_voltage.py
avaldez -
r1274:b6957aa66e1c
parent child
Show More
@@ -1,426 +1,400
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure
10 from figure import Figure
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13 class Scope(Figure):
13 class Scope(Figure):
14
14
15 isConfig = None
15 isConfig = None
16
16
17 def __init__(self, **kwargs):
17 def __init__(self, **kwargs):
18 Figure.__init__(self, **kwargs)
18 Figure.__init__(self, **kwargs)
19 self.isConfig = False
19 self.isConfig = False
20 self.WIDTH = 300
20 self.WIDTH = 300
21 self.HEIGHT = 200
21 self.HEIGHT = 200
22 self.counter_imagwr = 0
22 self.counter_imagwr = 0
23
23
24 def getSubplots(self):
24 def getSubplots(self):
25
25
26 nrow = self.nplots
26 nrow = self.nplots
27 ncol = 3
27 ncol = 3
28 return nrow, ncol
28 return nrow, ncol
29
29
30 def setup(self, id, nplots, wintitle, show):
30 def setup(self, id, nplots, wintitle, show):
31
31
32 self.nplots = nplots
32 self.nplots = nplots
33
33
34 self.createFigure(id=id,
34 self.createFigure(id=id,
35 wintitle=wintitle,
35 wintitle=wintitle,
36 show=show)
36 show=show)
37
37
38 nrow,ncol = self.getSubplots()
38 nrow,ncol = self.getSubplots()
39 colspan = 3
39 colspan = 3
40 rowspan = 1
40 rowspan = 1
41
41
42 for i in range(nplots):
42 for i in range(nplots):
43 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
43 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
44
44
45 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
45 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
46 yreal = y[channelIndexList,:].real
46 yreal = y[channelIndexList,:].real
47 yimag = y[channelIndexList,:].imag
47 yimag = y[channelIndexList,:].imag
48
48
49 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
49 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
50 xlabel = "Range (Km)"
50 xlabel = "Range (Km)"
51 ylabel = "Intensity - IQ"
51 ylabel = "Intensity - IQ"
52
52
53 if not self.isConfig:
53 if not self.isConfig:
54 nplots = len(channelIndexList)
54 nplots = len(channelIndexList)
55
55
56 self.setup(id=id,
56 self.setup(id=id,
57 nplots=nplots,
57 nplots=nplots,
58 wintitle='',
58 wintitle='',
59 show=show)
59 show=show)
60
60
61 if xmin == None: xmin = numpy.nanmin(x)
61 if xmin == None: xmin = numpy.nanmin(x)
62 if xmax == None: xmax = numpy.nanmax(x)
62 if xmax == None: xmax = numpy.nanmax(x)
63 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
63 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
64 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
64 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
65
65
66 self.isConfig = True
66 self.isConfig = True
67
67
68 self.setWinTitle(title)
68 self.setWinTitle(title)
69
69
70 for i in range(len(self.axesList)):
70 for i in range(len(self.axesList)):
71 title = "Channel %d" %(i)
71 title = "Channel %d" %(i)
72 axes = self.axesList[i]
72 axes = self.axesList[i]
73
73
74 axes.pline(x, yreal[i,:],
74 axes.pline(x, yreal[i,:],
75 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
75 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
76 xlabel=xlabel, ylabel=ylabel, title=title)
76 xlabel=xlabel, ylabel=ylabel, title=title)
77
77
78 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
78 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
79
79
80 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
80 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
81 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
81 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
82 yreal = y.real
82 yreal = y.real
83
83
84 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
84 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
85 xlabel = "Range (Km)"
85 xlabel = "Range (Km)"
86 ylabel = "Intensity"
86 ylabel = "Intensity"
87
87
88 if not self.isConfig:
88 if not self.isConfig:
89 nplots = len(channelIndexList)
89 nplots = len(channelIndexList)
90
90
91 self.setup(id=id,
91 self.setup(id=id,
92 nplots=nplots,
92 nplots=nplots,
93 wintitle='',
93 wintitle='',
94 show=show)
94 show=show)
95
95
96 if xmin == None: xmin = numpy.nanmin(x)
96 if xmin == None: xmin = numpy.nanmin(x)
97 if xmax == None: xmax = numpy.nanmax(x)
97 if xmax == None: xmax = numpy.nanmax(x)
98 if ymin == None: ymin = numpy.nanmin(yreal)
98 if ymin == None: ymin = numpy.nanmin(yreal)
99 if ymax == None: ymax = numpy.nanmax(yreal)
99 if ymax == None: ymax = numpy.nanmax(yreal)
100
100
101 self.isConfig = True
101 self.isConfig = True
102
102
103 self.setWinTitle(title)
103 self.setWinTitle(title)
104
104
105 for i in range(len(self.axesList)):
105 for i in range(len(self.axesList)):
106 title = "Channel %d" %(i)
106 title = "Channel %d" %(i)
107 axes = self.axesList[i]
107 axes = self.axesList[i]
108 ychannel = yreal[i,:]
108 ychannel = yreal[i,:]
109 axes.pline(x, ychannel,
109 axes.pline(x, ychannel,
110 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
110 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
111 xlabel=xlabel, ylabel=ylabel, title=title)
111 xlabel=xlabel, ylabel=ylabel, title=title)
112
112
113
113
114 def run(self, dataOut, id, wintitle="", channelList=None,
114 def run(self, dataOut, id, wintitle="", channelList=None,
115 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
115 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
116 figpath='./', figfile=None, show=True, wr_period=1,
116 figpath='./', figfile=None, show=True, wr_period=1,
117 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
117 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
118
118
119 """
119 """
120
120
121 Input:
121 Input:
122 dataOut :
122 dataOut :
123 id :
123 id :
124 wintitle :
124 wintitle :
125 channelList :
125 channelList :
126 xmin : None,
126 xmin : None,
127 xmax : None,
127 xmax : None,
128 ymin : None,
128 ymin : None,
129 ymax : None,
129 ymax : None,
130 """
130 """
131
131
132 if channelList == None:
132 if channelList == None:
133 channelIndexList = dataOut.channelIndexList
133 channelIndexList = dataOut.channelIndexList
134 else:
134 else:
135 channelIndexList = []
135 channelIndexList = []
136 for channel in channelList:
136 for channel in channelList:
137 if channel not in dataOut.channelList:
137 if channel not in dataOut.channelList:
138 raise ValueError, "Channel %d is not in dataOut.channelList"
138 raise ValueError, "Channel %d is not in dataOut.channelList"
139 channelIndexList.append(dataOut.channelList.index(channel))
139 channelIndexList.append(dataOut.channelList.index(channel))
140
140
141 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
141 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
142
142
143 if dataOut.flagDataAsBlock:
143 if dataOut.flagDataAsBlock:
144
144
145 for i in range(dataOut.nProfiles):
145 for i in range(dataOut.nProfiles):
146
146
147 wintitle1 = wintitle + " [Profile = %d] " %i
147 wintitle1 = wintitle + " [Profile = %d] " %i
148
148
149 if type == "power":
149 if type == "power":
150 self.plot_power(dataOut.heightList,
150 self.plot_power(dataOut.heightList,
151 dataOut.data[:,i,:],
151 dataOut.data[:,i,:],
152 id,
152 id,
153 channelIndexList,
153 channelIndexList,
154 thisDatetime,
154 thisDatetime,
155 wintitle1,
155 wintitle1,
156 show,
156 show,
157 xmin,
157 xmin,
158 xmax,
158 xmax,
159 ymin,
159 ymin,
160 ymax)
160 ymax)
161
161
162 if type == "iq":
162 if type == "iq":
163 self.plot_iq(dataOut.heightList,
163 self.plot_iq(dataOut.heightList,
164 dataOut.data[:,i,:],
164 dataOut.data[:,i,:],
165 id,
165 id,
166 channelIndexList,
166 channelIndexList,
167 thisDatetime,
167 thisDatetime,
168 wintitle1,
168 wintitle1,
169 show,
169 show,
170 xmin,
170 xmin,
171 xmax,
171 xmax,
172 ymin,
172 ymin,
173 ymax)
173 ymax)
174
174
175 self.draw()
175 self.draw()
176
176
177 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
177 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
178 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
178 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
179
179
180 self.save(figpath=figpath,
180 self.save(figpath=figpath,
181 figfile=figfile,
181 figfile=figfile,
182 save=save,
182 save=save,
183 ftp=ftp,
183 ftp=ftp,
184 wr_period=wr_period,
184 wr_period=wr_period,
185 thisDatetime=thisDatetime)
185 thisDatetime=thisDatetime)
186
186
187 else:
187 else:
188 wintitle += " [Profile = %d] " %dataOut.profileIndex
188 wintitle += " [Profile = %d] " %dataOut.profileIndex
189
189
190 if type == "power":
190 if type == "power":
191 self.plot_power(dataOut.heightList,
191 self.plot_power(dataOut.heightList,
192 dataOut.data,
192 dataOut.data,
193 id,
193 id,
194 channelIndexList,
194 channelIndexList,
195 thisDatetime,
195 thisDatetime,
196 wintitle,
196 wintitle,
197 show,
197 show,
198 xmin,
198 xmin,
199 xmax,
199 xmax,
200 ymin,
200 ymin,
201 ymax)
201 ymax)
202
202
203 if type == "iq":
203 if type == "iq":
204 self.plot_iq(dataOut.heightList,
204 self.plot_iq(dataOut.heightList,
205 dataOut.data,
205 dataOut.data,
206 id,
206 id,
207 channelIndexList,
207 channelIndexList,
208 thisDatetime,
208 thisDatetime,
209 wintitle,
209 wintitle,
210 show,
210 show,
211 xmin,
211 xmin,
212 xmax,
212 xmax,
213 ymin,
213 ymin,
214 ymax)
214 ymax)
215
215
216 self.draw()
216 self.draw()
217
217
218 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
218 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
219 figfile = self.getFilename(name = str_datetime)
219 figfile = self.getFilename(name = str_datetime)
220
220
221 self.save(figpath=figpath,
221 self.save(figpath=figpath,
222 figfile=figfile,
222 figfile=figfile,
223 save=save,
223 save=save,
224 ftp=ftp,
224 ftp=ftp,
225 wr_period=wr_period,
225 wr_period=wr_period,
226 thisDatetime=thisDatetime)
226 thisDatetime=thisDatetime)
227
227
228
228
229 class VoltACFPLot(Figure):
229 class VoltACFPLot(Figure):
230
230
231 isConfig = None
231 isConfig = None
232 __nsubplots = None
232 __nsubplots = None
233 PREFIX = 'voltacf'
233 PREFIX = 'voltacf'
234
234
235 def __init__(self, **kwargs):
235 def __init__(self, **kwargs):
236 Figure.__init__(self,**kwargs)
236 Figure.__init__(self,**kwargs)
237 self.isConfig = False
237 self.isConfig = False
238 self.__nsubplots = 1
238 self.__nsubplots = 1
239 self.PLOT_CODE = VOLT_ACF_CODE
239 self.PLOT_CODE = VOLT_ACF_CODE
240 self.WIDTH = 900
240 self.WIDTH = 900
241 self.HEIGHT = 700
241 self.HEIGHT = 700
242 self.counter_imagwr= 0
242 self.counter_imagwr= 0
243 self.FTP_WEI = None
243 self.FTP_WEI = None
244 self.EXP_CODE = None
244 self.EXP_CODE = None
245 self.SUB_EXP_CODE = None
245 self.SUB_EXP_CODE = None
246 self.PLOT_POS = None
246 self.PLOT_POS = None
247
247
248 def getSubplots(self) :
248 def getSubplots(self) :
249 ncol = 1
249 ncol = 1
250 nrow = 1
250 nrow = 1
251 return nrow, ncol
251 return nrow, ncol
252
252
253 def setup(self,id, nplots,wintitle,show):
253 def setup(self,id, nplots,wintitle,show):
254 self.nplots = nplots
254 self.nplots = nplots
255 ncolspan = 1
255 ncolspan = 1
256 colspan = 1
256 colspan = 1
257 self.createFigure(id=id,
257 self.createFigure(id=id,
258 wintitle = wintitle,
258 wintitle = wintitle,
259 widthplot = self.WIDTH,
259 widthplot = self.WIDTH,
260 heightplot = self.HEIGHT,
260 heightplot = self.HEIGHT,
261 show = show)
261 show = show)
262
262 nrow, ncol = self.getSubplots()
263 nrow, ncol = self.getSubplots()
263 counter = 0
264 counter = 0
265
264 for y in range(nrow):
266 for y in range(nrow):
265 for x in range(ncol):
267 for x in range(ncol):
266 self.addAxes(nrow, ncol*ncolspan,y, x*ncolspan, colspan, 1)
268 self.addAxes(nrow, ncol*ncolspan,y, x*ncolspan, colspan, 1)
267
269
268 def run(self,dataOut, id, wintitle="",channelList = None , channel =None, nSamples = None,
270 def run(self,dataOut, id, wintitle="",channelList = None , channel =None, nSamples = None,
269 nSampleList= None, resolutionFactor=None, xmin= None, xmax = None, ymin=None, ymax=None,
271 nSampleList= None, resolutionFactor=None, xmin= None, xmax = None, ymin=None, ymax=None,
270 save= False, figpath='./', figfile= None,show= True, ftp= False, wr_period=1, server= None,
272 save= False, figpath='./', figfile= None,show= True, ftp= False, wr_period=1, server= None,
271 folder= None, username =None, password= None, ftp_wei=0 , exp_code=0,sub_exp_code=0,plot_pos=0,
273 folder= None, username =None, password= None, ftp_wei=0 , exp_code=0,sub_exp_code=0,plot_pos=0,
272 xaxis="time"):
274 xaxis="time"):
273
275
274 channel0 = channel
276 channel0 = channel
275 nSamples = nSamples
277 nSamples = nSamples
276 resFactor = resolutionFactor
278 resFactor = resolutionFactor
277
279
278 if nSamples == None:
280 if nSamples == None:
279 nSamples = 20
281 nSamples = 20
280
282
281 if resFactor == None:
283 if resFactor == None:
282 resFactor = 5
284 resFactor = 5
283
285
284 if channel0 == None:
286 if channel0 == None:
285 channel0 = 0
287 channel0 = 0
286 else:
288 else:
287 if channel0 not in dataOut.channelList:
289 if channel0 not in dataOut.channelList:
288 raise ValueError, "Channel %d is not in %s dataOut.channelList"%(channel0, dataOut.channelList)
290 raise ValueError, "Channel %d is not in %s dataOut.channelList"%(channel0, dataOut.channelList)
289
291
290 if channelList == None:
292 if channelList == None:
291 channelIndexList = dataOut.channelIndexList
293 channelIndexList = dataOut.channelIndexList
292 channelList = dataOut.channelList
294 channelList = dataOut.channelList
293
295
294 else:
296 else:
295 channelIndexList = []
297 channelIndexList = []
296 for channel in channelList:
298 for channel in channelList:
297 if channel not in dataOut.channelList:
299 if channel not in dataOut.channelList:
298 raise ValueError, "Channel %d is not in dataOut.channelList"
300 raise ValueError, "Channel %d is not in dataOut.channelList"
299 channelIndexList.append(dataOut.channelList.index(channel))
301 channelIndexList.append(dataOut.channelList.index(channel))
300
302
301
302 #factor = dataOut.normFactor
303 #factor = dataOut.normFactor
303 y = dataOut.getHeiRange()
304 y = dataOut.getHeiRange()
304 #print y, dataOut.heightList[0]
305 #print y, dataOut.heightList[0]
305 #print "pause"
306 #print "pause"
306 #import time
307 #import time
307 #time.sleep(10)
308 #time.sleep(10)
308 deltaHeight = dataOut.heightList[1]-dataOut.heightList[0]
309 deltaHeight = dataOut.heightList[1]-dataOut.heightList[0]
309 z = dataOut.data
310 z = dataOut.data_acfLag
311
312 shape = dataOut.data_acfLag.shape
310
313
311 shape = dataOut.data.shape
312 hei_index = numpy.arange(shape[2])
314 hei_index = numpy.arange(shape[2])
313 hei_plot = numpy.arange(nSamples)*resFactor
315 hei_plot = numpy.arange(nSamples)*resFactor
314
316
315 if nSampleList is not None:
317 if nSampleList is not None:
316 for nsample in nSampleList:
318 for nsample in nSampleList:
317 if nsample not in dataOut.heightList/deltaHeight:
319 if nsample not in dataOut.heightList/deltaHeight:
318 print "Lista available : %s "%(dataOut.heightList/deltaHeight)
320 print "Lista available : %s "%(dataOut.heightList/deltaHeight)
319 raise ValueError, "nsample %d is not in %s dataOut.heightList"%(nsample,dataOut.heightList)
321 raise ValueError, "nsample %d is not in %s dataOut.heightList"%(nsample,dataOut.heightList)
320
322
321 if nSampleList is not None:
323 if nSampleList is not None:
322 hei_plot = numpy.array(nSampleList)*resFactor
324 hei_plot = numpy.array(nSampleList)*resFactor
323
325
324 if hei_plot[-1] >= hei_index[-1]:
326 if hei_plot[-1] >= hei_index[-1]:
325 print ("La cantidad de puntos en altura es %d y la resolucion es %f Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
327 print ("La cantidad de puntos en altura es %d y la resolucion es %f Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
326 raise ValueError, "resFactor %d multiplicado por el valor de %d nSamples es mayor a %d cantidad total de puntos"%(resFactor,nSamples,hei_index[-1])
328 raise ValueError, "resFactor %d multiplicado por el valor de %d nSamples es mayor a %d cantidad total de puntos"%(resFactor,nSamples,hei_index[-1])
327
329
328 #escalamiento -1 a 1 a resolucion (factor de resolucion en altura)* deltaHeight
330 #escalamiento -1 a 1 a resolucion (factor de resolucion en altura)* deltaHeight
329 #min = numpy.min(z[0,:,0])
331 #min = numpy.min(z[0,:,0])
330 #max =numpy.max(z[0,:,0])
332 #max =numpy.max(z[0,:,0])
333 #print shape[0]
331 for i in range(shape[0]):
334 for i in range(shape[0]):
335 #print "amigo i",i
332 for j in range(shape[2]):
336 for j in range(shape[2]):
333 min = numpy.min(z[i,:,j])
337 min = numpy.min(z[i,:,j])
334 max = numpy.max(z[i,:,j])
338 max = numpy.max(z[i,:,j])
335 z[i,:,j]= (((z[i,:,j]-min)/(max-min))*deltaHeight*resFactor + j*deltaHeight+dataOut.heightList[0])
339 z[i,:,j]= (((z[i,:,j]-min)/(max-min))*deltaHeight*resFactor + j*deltaHeight+dataOut.heightList[0])
336
340
337
338 if xaxis == "time":
341 if xaxis == "time":
339 x = dataOut.getAcfRange()*1000
342 x = dataOut.getAcfRange()*1000
340 zdB = z[channel0,:,hei_plot]
343 zdB = z[channel0,:,hei_plot]
341 xlabel = "Time (ms)"
344 xlabel = "Time (ms)"
342 ylabel = "VOLT_ACF"
345 ylabel = "VOLT_ACF"
343
344
345 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
346 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
346 title = wintitle + "VOLT ACF Plot Ch %s %s" %(channel0,thisDatetime.strftime("%d-%b-%Y"))
347 title = wintitle + "VOLT ACF Plot Ch %s %s" %(channel0,thisDatetime.strftime("%d-%b-%Y"))
347
348
348 if not self.isConfig:
349 if not self.isConfig:
349
350
350 nplots = 1
351 nplots = 1
351
352
352 self.setup(id=id,
353 self.setup(id=id,
353 nplots=nplots,
354 nplots=nplots,
354 wintitle=wintitle,
355 wintitle=wintitle,
355 show=show)
356 show=show)
356
357
357 if xmin == None: xmin = numpy.nanmin(x)#*0.9
358 if xmin == None: xmin = numpy.nanmin(x)#*0.9
358 if xmax == None: xmax = numpy.nanmax(x)#*1.1
359 if xmax == None: xmax = numpy.nanmax(x)#*1.1
359 if ymin == None: ymin = numpy.nanmin(zdB)
360 if ymin == None: ymin = numpy.nanmin(zdB)
360 if ymax == None: ymax = numpy.nanmax(zdB)
361 if ymax == None: ymax = numpy.nanmax(zdB)
361
362
362 print ("El parametro resFactor es %d y la resolucion en altura es %f"%(resFactor,deltaHeight ))
363 print ("El parametro resFactor es %d y la resolucion en altura es %f"%(resFactor,deltaHeight ))
363 print ("La cantidad de puntos en altura es %d y la nueva resolucion es %f Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
364 print ("La cantidad de puntos en altura es %d y la nueva resolucion es %f Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
364 print ("La altura maxima es %d Km"%(hei_plot[-1]*deltaHeight ))
365 print ("La altura maxima es %d Km"%(hei_plot[-1]*deltaHeight ))
365
366
366 self.FTP_WEI = ftp_wei
367 self.FTP_WEI = ftp_wei
367 self.EXP_CODE = exp_code
368 self.EXP_CODE = exp_code
368 self.SUB_EXP_CODE = sub_exp_code
369 self.SUB_EXP_CODE = sub_exp_code
369 self.PLOT_POS = plot_pos
370 self.PLOT_POS = plot_pos
370
371
371 self.isConfig = True
372 self.isConfig = True
372
373
373 self.setWinTitle(title)
374 self.setWinTitle(title)
374
375 title = "VOLT ACF Plot: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
375 title = "VOLT ACF Plot: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
376 axes = self.axesList[0]
376 axes = self.axesList[0]
377
377
378 legendlabels = ["Range = %dKm" %y[i] for i in hei_plot]
378 legendlabels = ["Range = %dKm" %y[i] for i in hei_plot]
379
379
380 axes.pmultilineyaxis( x, zdB,
380 axes.pmultilineyaxis( x, zdB,
381 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
381 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
382 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
382 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
383 ytick_visible=True, nxticks=5,
383 ytick_visible=True, nxticks=5,
384 grid='x')
384 grid='x')
385
385
386 self.draw()
386 self.draw()
387
387
388 if figfile == None:
388 if figfile == None:
389 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
389 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
390 name = str_datetime
390 name = str_datetime
391 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
391 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
392 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
392 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
393 figfile = self.getFilename(name)
393 figfile = self.getFilename(name)
394
394
395 self.save(figpath=figpath,
395 self.save(figpath=figpath,
396 figfile=figfile,
396 figfile=figfile,
397 save=save,
397 save=save,
398 ftp=ftp,
398 ftp=ftp,
399 wr_period=wr_period,
399 wr_period=wr_period,
400 thisDatetime=thisDatetime)
400 thisDatetime=thisDatetime)
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
@@ -1,1682 +1,1686
1 import sys
1 import sys
2 import numpy
2 import numpy
3 from scipy import interpolate
3 from scipy import interpolate
4 from schainpy import cSchain
4 from schainpy import cSchain
5 from jroproc_base import ProcessingUnit, Operation
5 from jroproc_base import ProcessingUnit, Operation
6 from schainpy.model.data.jrodata import Voltage
6 from schainpy.model.data.jrodata import Voltage
7 from time import time
7 from time import time
8
8
9 import math
9 import math
10
10
11 def rep_seq(x, rep=10):
11 def rep_seq(x, rep=10):
12 L = len(x) * rep
12 L = len(x) * rep
13 res = numpy.zeros(L, dtype=x.dtype)
13 res = numpy.zeros(L, dtype=x.dtype)
14 idx = numpy.arange(len(x)) * rep
14 idx = numpy.arange(len(x)) * rep
15 for i in numpy.arange(rep):
15 for i in numpy.arange(rep):
16 res[idx + i] = x
16 res[idx + i] = x
17 return(res)
17 return(res)
18
18
19
19
20 def create_pseudo_random_code(clen=10000, seed=0):
20 def create_pseudo_random_code(clen=10000, seed=0):
21 """
21 """
22 seed is a way of reproducing the random code without
22 seed is a way of reproducing the random code without
23 having to store all actual codes. the seed can then
23 having to store all actual codes. the seed can then
24 act as a sort of station_id.
24 act as a sort of station_id.
25
25
26 """
26 """
27 numpy.random.seed(seed)
27 numpy.random.seed(seed)
28 phases = numpy.array(
28 phases = numpy.array(
29 numpy.exp(1.0j * 2.0 * math.pi * numpy.random.random(clen)),
29 numpy.exp(1.0j * 2.0 * math.pi * numpy.random.random(clen)),
30 dtype=numpy.complex64,
30 dtype=numpy.complex64,
31 )
31 )
32 return(phases)
32 return(phases)
33
33
34
34
35 def periodic_convolution_matrix(envelope, rmin=0, rmax=100):
35 def periodic_convolution_matrix(envelope, rmin=0, rmax=100):
36 """
36 """
37 we imply that the number of measurements is equal to the number of elements
37 we imply that the number of measurements is equal to the number of elements
38 in code
38 in code
39
39
40 """
40 """
41 L = len(envelope)
41 L = len(envelope)
42 ridx = numpy.arange(rmin, rmax)
42 ridx = numpy.arange(rmin, rmax)
43 A = numpy.zeros([L, rmax-rmin], dtype=numpy.complex64)
43 A = numpy.zeros([L, rmax-rmin], dtype=numpy.complex64)
44 for i in numpy.arange(L):
44 for i in numpy.arange(L):
45 A[i, :] = envelope[(i-ridx) % L]
45 A[i, :] = envelope[(i-ridx) % L]
46 result = {}
46 result = {}
47 result['A'] = A
47 result['A'] = A
48 result['ridx'] = ridx
48 result['ridx'] = ridx
49 return(result)
49 return(result)
50
50
51
51
52 B_cache = 0
52 B_cache = 0
53 r_cache = 0
53 r_cache = 0
54 B_cached = False
54 B_cached = False
55 def create_estimation_matrix(code, rmin=0, rmax=1000, cache=True):
55 def create_estimation_matrix(code, rmin=0, rmax=1000, cache=True):
56 global B_cache
56 global B_cache
57 global r_cache
57 global r_cache
58 global B_cached
58 global B_cached
59
59
60 if not cache or not B_cached:
60 if not cache or not B_cached:
61 r_cache = periodic_convolution_matrix(
61 r_cache = periodic_convolution_matrix(
62 envelope=code, rmin=rmin, rmax=rmax,
62 envelope=code, rmin=rmin, rmax=rmax,
63 )
63 )
64 A = r_cache['A']
64 A = r_cache['A']
65 Ah = numpy.transpose(numpy.conjugate(A))
65 Ah = numpy.transpose(numpy.conjugate(A))
66 B_cache = numpy.dot(numpy.linalg.inv(numpy.dot(Ah, A)), Ah)
66 B_cache = numpy.dot(numpy.linalg.inv(numpy.dot(Ah, A)), Ah)
67 r_cache['B'] = B_cache
67 r_cache['B'] = B_cache
68 B_cached = True
68 B_cached = True
69 return(r_cache)
69 return(r_cache)
70 else:
70 else:
71 return(r_cache)
71 return(r_cache)
72
72
73 class VoltageProc(ProcessingUnit):
73 class VoltageProc(ProcessingUnit):
74
74
75
75
76 def __init__(self, **kwargs):
76 def __init__(self, **kwargs):
77
77
78 ProcessingUnit.__init__(self, **kwargs)
78 ProcessingUnit.__init__(self, **kwargs)
79
79
80 # self.objectDict = {}
80 # self.objectDict = {}
81 self.dataOut = Voltage()
81 self.dataOut = Voltage()
82 self.flip = 1
82 self.flip = 1
83
83
84 def run(self):
84 def run(self):
85 if self.dataIn.type == 'AMISR':
85 if self.dataIn.type == 'AMISR':
86 self.__updateObjFromAmisrInput()
86 self.__updateObjFromAmisrInput()
87
87
88 if self.dataIn.type == 'Voltage':
88 if self.dataIn.type == 'Voltage':
89 self.dataOut.copy(self.dataIn)
89 self.dataOut.copy(self.dataIn)
90
90
91 # self.dataOut.copy(self.dataIn)
91 # self.dataOut.copy(self.dataIn)
92
92
93 def __updateObjFromAmisrInput(self):
93 def __updateObjFromAmisrInput(self):
94
94
95 self.dataOut.timeZone = self.dataIn.timeZone
95 self.dataOut.timeZone = self.dataIn.timeZone
96 self.dataOut.dstFlag = self.dataIn.dstFlag
96 self.dataOut.dstFlag = self.dataIn.dstFlag
97 self.dataOut.errorCount = self.dataIn.errorCount
97 self.dataOut.errorCount = self.dataIn.errorCount
98 self.dataOut.useLocalTime = self.dataIn.useLocalTime
98 self.dataOut.useLocalTime = self.dataIn.useLocalTime
99
99
100 self.dataOut.flagNoData = self.dataIn.flagNoData
100 self.dataOut.flagNoData = self.dataIn.flagNoData
101 self.dataOut.data = self.dataIn.data
101 self.dataOut.data = self.dataIn.data
102 self.dataOut.utctime = self.dataIn.utctime
102 self.dataOut.utctime = self.dataIn.utctime
103 self.dataOut.channelList = self.dataIn.channelList
103 self.dataOut.channelList = self.dataIn.channelList
104 # self.dataOut.timeInterval = self.dataIn.timeInterval
104 # self.dataOut.timeInterval = self.dataIn.timeInterval
105 self.dataOut.heightList = self.dataIn.heightList
105 self.dataOut.heightList = self.dataIn.heightList
106 self.dataOut.nProfiles = self.dataIn.nProfiles
106 self.dataOut.nProfiles = self.dataIn.nProfiles
107
107
108 self.dataOut.nCohInt = self.dataIn.nCohInt
108 self.dataOut.nCohInt = self.dataIn.nCohInt
109 self.dataOut.ippSeconds = self.dataIn.ippSeconds
109 self.dataOut.ippSeconds = self.dataIn.ippSeconds
110 self.dataOut.frequency = self.dataIn.frequency
110 self.dataOut.frequency = self.dataIn.frequency
111
111
112 self.dataOut.azimuth = self.dataIn.azimuth
112 self.dataOut.azimuth = self.dataIn.azimuth
113 self.dataOut.zenith = self.dataIn.zenith
113 self.dataOut.zenith = self.dataIn.zenith
114
114
115 self.dataOut.beam.codeList = self.dataIn.beam.codeList
115 self.dataOut.beam.codeList = self.dataIn.beam.codeList
116 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
116 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
117 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
117 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
118 #
118 #
119 # pass#
119 # pass#
120 #
120 #
121 # def init(self):
121 # def init(self):
122 #
122 #
123 #
123 #
124 # if self.dataIn.type == 'AMISR':
124 # if self.dataIn.type == 'AMISR':
125 # self.__updateObjFromAmisrInput()
125 # self.__updateObjFromAmisrInput()
126 #
126 #
127 # if self.dataIn.type == 'Voltage':
127 # if self.dataIn.type == 'Voltage':
128 # self.dataOut.copy(self.dataIn)
128 # self.dataOut.copy(self.dataIn)
129 # # No necesita copiar en cada init() los atributos de dataIn
129 # # No necesita copiar en cada init() los atributos de dataIn
130 # # la copia deberia hacerse por cada nuevo bloque de datos
130 # # la copia deberia hacerse por cada nuevo bloque de datos
131
131
132 def selectChannels(self, channelList):
132 def selectChannels(self, channelList):
133
133
134 channelIndexList = []
134 channelIndexList = []
135
135
136 for channel in channelList:
136 for channel in channelList:
137 if channel not in self.dataOut.channelList:
137 if channel not in self.dataOut.channelList:
138 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
138 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
139
139
140 index = self.dataOut.channelList.index(channel)
140 index = self.dataOut.channelList.index(channel)
141 channelIndexList.append(index)
141 channelIndexList.append(index)
142
142
143 self.selectChannelsByIndex(channelIndexList)
143 self.selectChannelsByIndex(channelIndexList)
144
144
145 def selectChannelsByIndex(self, channelIndexList):
145 def selectChannelsByIndex(self, channelIndexList):
146 """
146 """
147 Selecciona un bloque de datos en base a canales segun el channelIndexList
147 Selecciona un bloque de datos en base a canales segun el channelIndexList
148
148
149 Input:
149 Input:
150 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
150 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
151
151
152 Affected:
152 Affected:
153 self.dataOut.data
153 self.dataOut.data
154 self.dataOut.channelIndexList
154 self.dataOut.channelIndexList
155 self.dataOut.nChannels
155 self.dataOut.nChannels
156 self.dataOut.m_ProcessingHeader.totalSpectra
156 self.dataOut.m_ProcessingHeader.totalSpectra
157 self.dataOut.systemHeaderObj.numChannels
157 self.dataOut.systemHeaderObj.numChannels
158 self.dataOut.m_ProcessingHeader.blockSize
158 self.dataOut.m_ProcessingHeader.blockSize
159
159
160 Return:
160 Return:
161 None
161 None
162 """
162 """
163
163
164 for channelIndex in channelIndexList:
164 for channelIndex in channelIndexList:
165 if channelIndex not in self.dataOut.channelIndexList:
165 if channelIndex not in self.dataOut.channelIndexList:
166 print channelIndexList
166 print channelIndexList
167 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
167 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
168
168
169 if self.dataOut.flagDataAsBlock:
169 if self.dataOut.flagDataAsBlock:
170 """
170 """
171 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
171 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
172 """
172 """
173 data = self.dataOut.data[channelIndexList,:,:]
173 data = self.dataOut.data[channelIndexList,:,:]
174 else:
174 else:
175 data = self.dataOut.data[channelIndexList,:]
175 data = self.dataOut.data[channelIndexList,:]
176
176
177 self.dataOut.data = data
177 self.dataOut.data = data
178 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
178 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
179 # self.dataOut.nChannels = nChannels
179 # self.dataOut.nChannels = nChannels
180
180
181 return 1
181 return 1
182
182
183 def selectHeights(self, minHei=None, maxHei=None):
183 def selectHeights(self, minHei=None, maxHei=None):
184 """
184 """
185 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
185 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
186 minHei <= height <= maxHei
186 minHei <= height <= maxHei
187
187
188 Input:
188 Input:
189 minHei : valor minimo de altura a considerar
189 minHei : valor minimo de altura a considerar
190 maxHei : valor maximo de altura a considerar
190 maxHei : valor maximo de altura a considerar
191
191
192 Affected:
192 Affected:
193 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
193 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
194
194
195 Return:
195 Return:
196 1 si el metodo se ejecuto con exito caso contrario devuelve 0
196 1 si el metodo se ejecuto con exito caso contrario devuelve 0
197 """
197 """
198
198
199 if minHei == None:
199 if minHei == None:
200 minHei = self.dataOut.heightList[0]
200 minHei = self.dataOut.heightList[0]
201
201
202 if maxHei == None:
202 if maxHei == None:
203 maxHei = self.dataOut.heightList[-1]
203 maxHei = self.dataOut.heightList[-1]
204
204
205 if (minHei < self.dataOut.heightList[0]):
205 if (minHei < self.dataOut.heightList[0]):
206 minHei = self.dataOut.heightList[0]
206 minHei = self.dataOut.heightList[0]
207
207
208 if (maxHei > self.dataOut.heightList[-1]):
208 if (maxHei > self.dataOut.heightList[-1]):
209 maxHei = self.dataOut.heightList[-1]
209 maxHei = self.dataOut.heightList[-1]
210
210
211 minIndex = 0
211 minIndex = 0
212 maxIndex = 0
212 maxIndex = 0
213 heights = self.dataOut.heightList
213 heights = self.dataOut.heightList
214
214
215 inda = numpy.where(heights >= minHei)
215 inda = numpy.where(heights >= minHei)
216 indb = numpy.where(heights <= maxHei)
216 indb = numpy.where(heights <= maxHei)
217
217
218 try:
218 try:
219 minIndex = inda[0][0]
219 minIndex = inda[0][0]
220 except:
220 except:
221 minIndex = 0
221 minIndex = 0
222
222
223 try:
223 try:
224 maxIndex = indb[0][-1]
224 maxIndex = indb[0][-1]
225 except:
225 except:
226 maxIndex = len(heights)
226 maxIndex = len(heights)
227
227
228 self.selectHeightsByIndex(minIndex, maxIndex)
228 self.selectHeightsByIndex(minIndex, maxIndex)
229
229
230 return 1
230 return 1
231
231
232
232
233 def selectHeightsByIndex(self, minIndex, maxIndex):
233 def selectHeightsByIndex(self, minIndex, maxIndex):
234 """
234 """
235 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
235 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
236 minIndex <= index <= maxIndex
236 minIndex <= index <= maxIndex
237
237
238 Input:
238 Input:
239 minIndex : valor de indice minimo de altura a considerar
239 minIndex : valor de indice minimo de altura a considerar
240 maxIndex : valor de indice maximo de altura a considerar
240 maxIndex : valor de indice maximo de altura a considerar
241
241
242 Affected:
242 Affected:
243 self.dataOut.data
243 self.dataOut.data
244 self.dataOut.heightList
244 self.dataOut.heightList
245
245
246 Return:
246 Return:
247 1 si el metodo se ejecuto con exito caso contrario devuelve 0
247 1 si el metodo se ejecuto con exito caso contrario devuelve 0
248 """
248 """
249
249
250 if (minIndex < 0) or (minIndex > maxIndex):
250 if (minIndex < 0) or (minIndex > maxIndex):
251 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
251 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
252
252
253 if (maxIndex >= self.dataOut.nHeights):
253 if (maxIndex >= self.dataOut.nHeights):
254 maxIndex = self.dataOut.nHeights
254 maxIndex = self.dataOut.nHeights
255
255
256 #voltage
256 #voltage
257 if self.dataOut.flagDataAsBlock:
257 if self.dataOut.flagDataAsBlock:
258 """
258 """
259 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
259 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
260 """
260 """
261 data = self.dataOut.data[:,:, minIndex:maxIndex]
261 data = self.dataOut.data[:,:, minIndex:maxIndex]
262 else:
262 else:
263 data = self.dataOut.data[:, minIndex:maxIndex]
263 data = self.dataOut.data[:, minIndex:maxIndex]
264
264
265 # firstHeight = self.dataOut.heightList[minIndex]
265 # firstHeight = self.dataOut.heightList[minIndex]
266
266
267 self.dataOut.data = data
267 self.dataOut.data = data
268 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
268 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
269
269
270 if self.dataOut.nHeights <= 1:
270 if self.dataOut.nHeights <= 1:
271 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
271 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
272
272
273 return 1
273 return 1
274
274
275
275
276 def filterByHeights(self, window):
276 def filterByHeights(self, window):
277
277
278 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
278 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
279
279
280 if window == None:
280 if window == None:
281 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
281 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
282
282
283 newdelta = deltaHeight * window
283 newdelta = deltaHeight * window
284 r = self.dataOut.nHeights % window
284 r = self.dataOut.nHeights % window
285 newheights = (self.dataOut.nHeights-r)/window
285 newheights = (self.dataOut.nHeights-r)/window
286
286
287 if newheights <= 1:
287 if newheights <= 1:
288 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
288 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
289
289
290 if self.dataOut.flagDataAsBlock:
290 if self.dataOut.flagDataAsBlock:
291 """
291 """
292 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
292 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
293 """
293 """
294 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
294 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
295 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
295 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
296 buffer = numpy.sum(buffer,3)
296 buffer = numpy.sum(buffer,3)
297
297
298 else:
298 else:
299 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
299 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
300 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
300 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
301 buffer = numpy.sum(buffer,2)
301 buffer = numpy.sum(buffer,2)
302
302
303 self.dataOut.data = buffer
303 self.dataOut.data = buffer
304 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
304 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
305 self.dataOut.windowOfFilter = window
305 self.dataOut.windowOfFilter = window
306
306
307 def setH0(self, h0, deltaHeight = None):
307 def setH0(self, h0, deltaHeight = None):
308
308
309 if not deltaHeight:
309 if not deltaHeight:
310 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
310 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
311
311
312 nHeights = self.dataOut.nHeights
312 nHeights = self.dataOut.nHeights
313
313
314 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
314 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
315
315
316 self.dataOut.heightList = newHeiRange
316 self.dataOut.heightList = newHeiRange
317
317
318 def deFlip(self, channelList = []):
318 def deFlip(self, channelList = []):
319
319
320 data = self.dataOut.data.copy()
320 data = self.dataOut.data.copy()
321
321
322 if self.dataOut.flagDataAsBlock:
322 if self.dataOut.flagDataAsBlock:
323 flip = self.flip
323 flip = self.flip
324 profileList = range(self.dataOut.nProfiles)
324 profileList = range(self.dataOut.nProfiles)
325
325
326 if not channelList:
326 if not channelList:
327 for thisProfile in profileList:
327 for thisProfile in profileList:
328 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
328 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
329 flip *= -1.0
329 flip *= -1.0
330 else:
330 else:
331 for thisChannel in channelList:
331 for thisChannel in channelList:
332 if thisChannel not in self.dataOut.channelList:
332 if thisChannel not in self.dataOut.channelList:
333 continue
333 continue
334
334
335 for thisProfile in profileList:
335 for thisProfile in profileList:
336 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
336 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
337 flip *= -1.0
337 flip *= -1.0
338
338
339 self.flip = flip
339 self.flip = flip
340
340
341 else:
341 else:
342 if not channelList:
342 if not channelList:
343 data[:,:] = data[:,:]*self.flip
343 data[:,:] = data[:,:]*self.flip
344 else:
344 else:
345 for thisChannel in channelList:
345 for thisChannel in channelList:
346 if thisChannel not in self.dataOut.channelList:
346 if thisChannel not in self.dataOut.channelList:
347 continue
347 continue
348
348
349 data[thisChannel,:] = data[thisChannel,:]*self.flip
349 data[thisChannel,:] = data[thisChannel,:]*self.flip
350
350
351 self.flip *= -1.
351 self.flip *= -1.
352
352
353 self.dataOut.data = data
353 self.dataOut.data = data
354
354
355 def setRadarFrequency(self, frequency=None):
355 def setRadarFrequency(self, frequency=None):
356
356
357 if frequency != None:
357 if frequency != None:
358 self.dataOut.frequency = frequency
358 self.dataOut.frequency = frequency
359
359
360 return 1
360 return 1
361
361
362 def interpolateHeights(self, topLim, botLim):
362 def interpolateHeights(self, topLim, botLim):
363 #69 al 72 para julia
363 #69 al 72 para julia
364 #82-84 para meteoros
364 #82-84 para meteoros
365 if len(numpy.shape(self.dataOut.data))==2:
365 if len(numpy.shape(self.dataOut.data))==2:
366 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
366 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
367 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
367 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
368 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
368 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
369 self.dataOut.data[:,botLim:topLim+1] = sampInterp
369 self.dataOut.data[:,botLim:topLim+1] = sampInterp
370 else:
370 else:
371 nHeights = self.dataOut.data.shape[2]
371 nHeights = self.dataOut.data.shape[2]
372 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
372 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
373 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
373 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
374 f = interpolate.interp1d(x, y, axis = 2)
374 f = interpolate.interp1d(x, y, axis = 2)
375 xnew = numpy.arange(botLim,topLim+1)
375 xnew = numpy.arange(botLim,topLim+1)
376 ynew = f(xnew)
376 ynew = f(xnew)
377
377
378 self.dataOut.data[:,:,botLim:topLim+1] = ynew
378 self.dataOut.data[:,:,botLim:topLim+1] = ynew
379
379
380 # import collections
380 # import collections
381
381
382 class CohInt(Operation):
382 class CohInt(Operation):
383
383
384 isConfig = False
384 isConfig = False
385 __profIndex = 0
385 __profIndex = 0
386 __byTime = False
386 __byTime = False
387 __initime = None
387 __initime = None
388 __lastdatatime = None
388 __lastdatatime = None
389 __integrationtime = None
389 __integrationtime = None
390 __buffer = None
390 __buffer = None
391 __bufferStride = []
391 __bufferStride = []
392 __dataReady = False
392 __dataReady = False
393 __profIndexStride = 0
393 __profIndexStride = 0
394 __dataToPutStride = False
394 __dataToPutStride = False
395 n = None
395 n = None
396
396
397 def __init__(self, **kwargs):
397 def __init__(self, **kwargs):
398
398
399 Operation.__init__(self, **kwargs)
399 Operation.__init__(self, **kwargs)
400
400
401 # self.isConfig = False
401 # self.isConfig = False
402
402
403 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
403 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
404 """
404 """
405 Set the parameters of the integration class.
405 Set the parameters of the integration class.
406
406
407 Inputs:
407 Inputs:
408
408
409 n : Number of coherent integrations
409 n : Number of coherent integrations
410 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
410 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
411 overlapping :
411 overlapping :
412 """
412 """
413
413
414 self.__initime = None
414 self.__initime = None
415 self.__lastdatatime = 0
415 self.__lastdatatime = 0
416 self.__buffer = None
416 self.__buffer = None
417 self.__dataReady = False
417 self.__dataReady = False
418 self.byblock = byblock
418 self.byblock = byblock
419 self.stride = stride
419 self.stride = stride
420
420
421 if n == None and timeInterval == None:
421 if n == None and timeInterval == None:
422 raise ValueError, "n or timeInterval should be specified ..."
422 raise ValueError, "n or timeInterval should be specified ..."
423
423
424 if n != None:
424 if n != None:
425 self.n = n
425 self.n = n
426 self.__byTime = False
426 self.__byTime = False
427 else:
427 else:
428 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
428 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
429 self.n = 9999
429 self.n = 9999
430 self.__byTime = True
430 self.__byTime = True
431
431
432 if overlapping:
432 if overlapping:
433 self.__withOverlapping = True
433 self.__withOverlapping = True
434 self.__buffer = None
434 self.__buffer = None
435 else:
435 else:
436 self.__withOverlapping = False
436 self.__withOverlapping = False
437 self.__buffer = 0
437 self.__buffer = 0
438
438
439 self.__profIndex = 0
439 self.__profIndex = 0
440
440
441 def putData(self, data):
441 def putData(self, data):
442
442
443 """
443 """
444 Add a profile to the __buffer and increase in one the __profileIndex
444 Add a profile to the __buffer and increase in one the __profileIndex
445
445
446 """
446 """
447
447
448 if not self.__withOverlapping:
448 if not self.__withOverlapping:
449 self.__buffer += data.copy()
449 self.__buffer += data.copy()
450 self.__profIndex += 1
450 self.__profIndex += 1
451 return
451 return
452
452
453 #Overlapping data
453 #Overlapping data
454 nChannels, nHeis = data.shape
454 nChannels, nHeis = data.shape
455 data = numpy.reshape(data, (1, nChannels, nHeis))
455 data = numpy.reshape(data, (1, nChannels, nHeis))
456
456
457 #If the buffer is empty then it takes the data value
457 #If the buffer is empty then it takes the data value
458 if self.__buffer is None:
458 if self.__buffer is None:
459 self.__buffer = data
459 self.__buffer = data
460 self.__profIndex += 1
460 self.__profIndex += 1
461 return
461 return
462
462
463 #If the buffer length is lower than n then stakcing the data value
463 #If the buffer length is lower than n then stakcing the data value
464 if self.__profIndex < self.n:
464 if self.__profIndex < self.n:
465 self.__buffer = numpy.vstack((self.__buffer, data))
465 self.__buffer = numpy.vstack((self.__buffer, data))
466 self.__profIndex += 1
466 self.__profIndex += 1
467 return
467 return
468
468
469 #If the buffer length is equal to n then replacing the last buffer value with the data value
469 #If the buffer length is equal to n then replacing the last buffer value with the data value
470 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
470 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
471 self.__buffer[self.n-1] = data
471 self.__buffer[self.n-1] = data
472 self.__profIndex = self.n
472 self.__profIndex = self.n
473 return
473 return
474
474
475
475
476 def pushData(self):
476 def pushData(self):
477 """
477 """
478 Return the sum of the last profiles and the profiles used in the sum.
478 Return the sum of the last profiles and the profiles used in the sum.
479
479
480 Affected:
480 Affected:
481
481
482 self.__profileIndex
482 self.__profileIndex
483
483
484 """
484 """
485
485
486 if not self.__withOverlapping:
486 if not self.__withOverlapping:
487 data = self.__buffer
487 data = self.__buffer
488 n = self.__profIndex
488 n = self.__profIndex
489
489
490 self.__buffer = 0
490 self.__buffer = 0
491 self.__profIndex = 0
491 self.__profIndex = 0
492
492
493 return data, n
493 return data, n
494
494
495 #Integration with Overlapping
495 #Integration with Overlapping
496 data = numpy.sum(self.__buffer, axis=0)
496 data = numpy.sum(self.__buffer, axis=0)
497 # print data
497 # print data
498 # raise
498 # raise
499 n = self.__profIndex
499 n = self.__profIndex
500
500
501 return data, n
501 return data, n
502
502
503 def byProfiles(self, data):
503 def byProfiles(self, data):
504
504
505 self.__dataReady = False
505 self.__dataReady = False
506 avgdata = None
506 avgdata = None
507 # n = None
507 # n = None
508 # print data
508 # print data
509 # raise
509 # raise
510 self.putData(data)
510 self.putData(data)
511
511
512 if self.__profIndex == self.n:
512 if self.__profIndex == self.n:
513 avgdata, n = self.pushData()
513 avgdata, n = self.pushData()
514 self.__dataReady = True
514 self.__dataReady = True
515
515
516 return avgdata
516 return avgdata
517
517
518 def byTime(self, data, datatime):
518 def byTime(self, data, datatime):
519
519
520 self.__dataReady = False
520 self.__dataReady = False
521 avgdata = None
521 avgdata = None
522 n = None
522 n = None
523
523
524 self.putData(data)
524 self.putData(data)
525
525
526 if (datatime - self.__initime) >= self.__integrationtime:
526 if (datatime - self.__initime) >= self.__integrationtime:
527 avgdata, n = self.pushData()
527 avgdata, n = self.pushData()
528 self.n = n
528 self.n = n
529 self.__dataReady = True
529 self.__dataReady = True
530
530
531 return avgdata
531 return avgdata
532
532
533 def integrateByStride(self, data, datatime):
533 def integrateByStride(self, data, datatime):
534 # print data
534 # print data
535 if self.__profIndex == 0:
535 if self.__profIndex == 0:
536 self.__buffer = [[data.copy(), datatime]]
536 self.__buffer = [[data.copy(), datatime]]
537 else:
537 else:
538 self.__buffer.append([data.copy(),datatime])
538 self.__buffer.append([data.copy(),datatime])
539 self.__profIndex += 1
539 self.__profIndex += 1
540 self.__dataReady = False
540 self.__dataReady = False
541
541
542 if self.__profIndex == self.n * self.stride :
542 if self.__profIndex == self.n * self.stride :
543 self.__dataToPutStride = True
543 self.__dataToPutStride = True
544 self.__profIndexStride = 0
544 self.__profIndexStride = 0
545 self.__profIndex = 0
545 self.__profIndex = 0
546 self.__bufferStride = []
546 self.__bufferStride = []
547 for i in range(self.stride):
547 for i in range(self.stride):
548 current = self.__buffer[i::self.stride]
548 current = self.__buffer[i::self.stride]
549 data = numpy.sum([t[0] for t in current], axis=0)
549 data = numpy.sum([t[0] for t in current], axis=0)
550 avgdatatime = numpy.average([t[1] for t in current])
550 avgdatatime = numpy.average([t[1] for t in current])
551 # print data
551 # print data
552 self.__bufferStride.append((data, avgdatatime))
552 self.__bufferStride.append((data, avgdatatime))
553
553
554 if self.__dataToPutStride:
554 if self.__dataToPutStride:
555 self.__dataReady = True
555 self.__dataReady = True
556 self.__profIndexStride += 1
556 self.__profIndexStride += 1
557 if self.__profIndexStride == self.stride:
557 if self.__profIndexStride == self.stride:
558 self.__dataToPutStride = False
558 self.__dataToPutStride = False
559 # print self.__bufferStride[self.__profIndexStride - 1]
559 # print self.__bufferStride[self.__profIndexStride - 1]
560 # raise
560 # raise
561 return self.__bufferStride[self.__profIndexStride - 1]
561 return self.__bufferStride[self.__profIndexStride - 1]
562
562
563
563
564 return None, None
564 return None, None
565
565
566 def integrate(self, data, datatime=None):
566 def integrate(self, data, datatime=None):
567
567
568 if self.__initime == None:
568 if self.__initime == None:
569 self.__initime = datatime
569 self.__initime = datatime
570
570
571 if self.__byTime:
571 if self.__byTime:
572 avgdata = self.byTime(data, datatime)
572 avgdata = self.byTime(data, datatime)
573 else:
573 else:
574 avgdata = self.byProfiles(data)
574 avgdata = self.byProfiles(data)
575
575
576
576
577 self.__lastdatatime = datatime
577 self.__lastdatatime = datatime
578
578
579 if avgdata is None:
579 if avgdata is None:
580 return None, None
580 return None, None
581
581
582 avgdatatime = self.__initime
582 avgdatatime = self.__initime
583
583
584 deltatime = datatime - self.__lastdatatime
584 deltatime = datatime - self.__lastdatatime
585
585
586 if not self.__withOverlapping:
586 if not self.__withOverlapping:
587 self.__initime = datatime
587 self.__initime = datatime
588 else:
588 else:
589 self.__initime += deltatime
589 self.__initime += deltatime
590
590
591 return avgdata, avgdatatime
591 return avgdata, avgdatatime
592
592
593 def integrateByBlock(self, dataOut):
593 def integrateByBlock(self, dataOut):
594
594
595 times = int(dataOut.data.shape[1]/self.n)
595 times = int(dataOut.data.shape[1]/self.n)
596 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
596 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
597
597
598 id_min = 0
598 id_min = 0
599 id_max = self.n
599 id_max = self.n
600
600
601 for i in range(times):
601 for i in range(times):
602 junk = dataOut.data[:,id_min:id_max,:]
602 junk = dataOut.data[:,id_min:id_max,:]
603 avgdata[:,i,:] = junk.sum(axis=1)
603 avgdata[:,i,:] = junk.sum(axis=1)
604 id_min += self.n
604 id_min += self.n
605 id_max += self.n
605 id_max += self.n
606
606
607 timeInterval = dataOut.ippSeconds*self.n
607 timeInterval = dataOut.ippSeconds*self.n
608 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
608 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
609 self.__dataReady = True
609 self.__dataReady = True
610 return avgdata, avgdatatime
610 return avgdata, avgdatatime
611
611
612 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
612 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
613 if not self.isConfig:
613 if not self.isConfig:
614 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
614 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
615 self.isConfig = True
615 self.isConfig = True
616
616
617 if dataOut.flagDataAsBlock:
617 if dataOut.flagDataAsBlock:
618 """
618 """
619 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
619 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
620 """
620 """
621 avgdata, avgdatatime = self.integrateByBlock(dataOut)
621 avgdata, avgdatatime = self.integrateByBlock(dataOut)
622 dataOut.nProfiles /= self.n
622 dataOut.nProfiles /= self.n
623 else:
623 else:
624 if stride is None:
624 if stride is None:
625 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
625 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
626 else:
626 else:
627 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
627 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
628
628
629
629
630 # dataOut.timeInterval *= n
630 # dataOut.timeInterval *= n
631 dataOut.flagNoData = True
631 dataOut.flagNoData = True
632
632
633 if self.__dataReady:
633 if self.__dataReady:
634 dataOut.data = avgdata
634 dataOut.data = avgdata
635 dataOut.nCohInt *= self.n
635 dataOut.nCohInt *= self.n
636 dataOut.utctime = avgdatatime
636 dataOut.utctime = avgdatatime
637 # print avgdata, avgdatatime
637 # print avgdata, avgdatatime
638 # raise
638 # raise
639 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
639 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
640 dataOut.flagNoData = False
640 dataOut.flagNoData = False
641
641
642 class Decoder(Operation):
642 class Decoder(Operation):
643
643
644 isConfig = False
644 isConfig = False
645 __profIndex = 0
645 __profIndex = 0
646
646
647 code = None
647 code = None
648
648
649 nCode = None
649 nCode = None
650 nBaud = None
650 nBaud = None
651
651
652 def __init__(self, **kwargs):
652 def __init__(self, **kwargs):
653
653
654 Operation.__init__(self, **kwargs)
654 Operation.__init__(self, **kwargs)
655
655
656 self.times = None
656 self.times = None
657 self.osamp = None
657 self.osamp = None
658 # self.__setValues = False
658 # self.__setValues = False
659 self.isConfig = False
659 self.isConfig = False
660
660
661 def setup(self, code, osamp, dataOut):
661 def setup(self, code, osamp, dataOut):
662
662
663 self.__profIndex = 0
663 self.__profIndex = 0
664
664
665 self.code = code
665 self.code = code
666
666
667 self.nCode = len(code)
667 self.nCode = len(code)
668 self.nBaud = len(code[0])
668 self.nBaud = len(code[0])
669
669
670 if (osamp != None) and (osamp >1):
670 if (osamp != None) and (osamp >1):
671 self.osamp = osamp
671 self.osamp = osamp
672 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
672 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
673 self.nBaud = self.nBaud*self.osamp
673 self.nBaud = self.nBaud*self.osamp
674
674
675 self.__nChannels = dataOut.nChannels
675 self.__nChannels = dataOut.nChannels
676 self.__nProfiles = dataOut.nProfiles
676 self.__nProfiles = dataOut.nProfiles
677 self.__nHeis = dataOut.nHeights
677 self.__nHeis = dataOut.nHeights
678
678
679 if self.__nHeis < self.nBaud:
679 if self.__nHeis < self.nBaud:
680 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
680 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
681
681
682 #Frequency
682 #Frequency
683 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
683 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
684
684
685 __codeBuffer[:,0:self.nBaud] = self.code
685 __codeBuffer[:,0:self.nBaud] = self.code
686
686
687 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
687 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
688
688
689 if dataOut.flagDataAsBlock:
689 if dataOut.flagDataAsBlock:
690
690
691 self.ndatadec = self.__nHeis #- self.nBaud + 1
691 self.ndatadec = self.__nHeis #- self.nBaud + 1
692
692
693 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
693 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
694
694
695 else:
695 else:
696
696
697 #Time
697 #Time
698 self.ndatadec = self.__nHeis #- self.nBaud + 1
698 self.ndatadec = self.__nHeis #- self.nBaud + 1
699
699
700 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
700 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
701
701
702 def __convolutionInFreq(self, data):
702 def __convolutionInFreq(self, data):
703
703
704 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
704 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
705
705
706 fft_data = numpy.fft.fft(data, axis=1)
706 fft_data = numpy.fft.fft(data, axis=1)
707
707
708 conv = fft_data*fft_code
708 conv = fft_data*fft_code
709
709
710 data = numpy.fft.ifft(conv,axis=1)
710 data = numpy.fft.ifft(conv,axis=1)
711
711
712 return data
712 return data
713
713
714 def __convolutionInFreqOpt(self, data):
714 def __convolutionInFreqOpt(self, data):
715
715
716 raise NotImplementedError
716 raise NotImplementedError
717
717
718 def __convolutionInTime(self, data):
718 def __convolutionInTime(self, data):
719
719
720 code = self.code[self.__profIndex]
720 code = self.code[self.__profIndex]
721 for i in range(self.__nChannels):
721 for i in range(self.__nChannels):
722 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
722 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
723
723
724 return self.datadecTime
724 return self.datadecTime
725
725
726 def __convolutionByBlockInTime(self, data):
726 def __convolutionByBlockInTime(self, data):
727
727
728 repetitions = self.__nProfiles / self.nCode
728 repetitions = self.__nProfiles / self.nCode
729
729
730 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
730 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
731 junk = junk.flatten()
731 junk = junk.flatten()
732 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
732 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
733 profilesList = xrange(self.__nProfiles)
733 profilesList = xrange(self.__nProfiles)
734
734
735 for i in range(self.__nChannels):
735 for i in range(self.__nChannels):
736 for j in profilesList:
736 for j in profilesList:
737 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
737 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
738 return self.datadecTime
738 return self.datadecTime
739
739
740 def __convolutionByBlockInFreq(self, data):
740 def __convolutionByBlockInFreq(self, data):
741
741
742 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
742 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
743
743
744
744
745 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
745 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
746
746
747 fft_data = numpy.fft.fft(data, axis=2)
747 fft_data = numpy.fft.fft(data, axis=2)
748
748
749 conv = fft_data*fft_code
749 conv = fft_data*fft_code
750
750
751 data = numpy.fft.ifft(conv,axis=2)
751 data = numpy.fft.ifft(conv,axis=2)
752
752
753 return data
753 return data
754
754
755
755
756 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
756 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
757
757
758 if dataOut.flagDecodeData:
758 if dataOut.flagDecodeData:
759 print "This data is already decoded, recoding again ..."
759 print "This data is already decoded, recoding again ..."
760
760
761 if not self.isConfig:
761 if not self.isConfig:
762
762
763 if code is None:
763 if code is None:
764 if dataOut.code is None:
764 if dataOut.code is None:
765 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
765 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
766
766
767 code = dataOut.code
767 code = dataOut.code
768 else:
768 else:
769 code = numpy.array(code).reshape(nCode,nBaud)
769 code = numpy.array(code).reshape(nCode,nBaud)
770 self.setup(code, osamp, dataOut)
770 self.setup(code, osamp, dataOut)
771
771
772 self.isConfig = True
772 self.isConfig = True
773
773
774 if mode == 3:
774 if mode == 3:
775 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
775 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
776
776
777 if times != None:
777 if times != None:
778 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
778 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
779
779
780 if self.code is None:
780 if self.code is None:
781 print "Fail decoding: Code is not defined."
781 print "Fail decoding: Code is not defined."
782 return
782 return
783
783
784 self.__nProfiles = dataOut.nProfiles
784 self.__nProfiles = dataOut.nProfiles
785 datadec = None
785 datadec = None
786
786
787 if mode == 3:
787 if mode == 3:
788 mode = 0
788 mode = 0
789
789
790 if dataOut.flagDataAsBlock:
790 if dataOut.flagDataAsBlock:
791 """
791 """
792 Decoding when data have been read as block,
792 Decoding when data have been read as block,
793 """
793 """
794
794
795 if mode == 0:
795 if mode == 0:
796 datadec = self.__convolutionByBlockInTime(dataOut.data)
796 datadec = self.__convolutionByBlockInTime(dataOut.data)
797 if mode == 1:
797 if mode == 1:
798 datadec = self.__convolutionByBlockInFreq(dataOut.data)
798 datadec = self.__convolutionByBlockInFreq(dataOut.data)
799 else:
799 else:
800 """
800 """
801 Decoding when data have been read profile by profile
801 Decoding when data have been read profile by profile
802 """
802 """
803 if mode == 0:
803 if mode == 0:
804 datadec = self.__convolutionInTime(dataOut.data)
804 datadec = self.__convolutionInTime(dataOut.data)
805
805
806 if mode == 1:
806 if mode == 1:
807 datadec = self.__convolutionInFreq(dataOut.data)
807 datadec = self.__convolutionInFreq(dataOut.data)
808
808
809 if mode == 2:
809 if mode == 2:
810 datadec = self.__convolutionInFreqOpt(dataOut.data)
810 datadec = self.__convolutionInFreqOpt(dataOut.data)
811
811
812 if datadec is None:
812 if datadec is None:
813 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
813 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
814
814
815 dataOut.code = self.code
815 dataOut.code = self.code
816 dataOut.nCode = self.nCode
816 dataOut.nCode = self.nCode
817 dataOut.nBaud = self.nBaud
817 dataOut.nBaud = self.nBaud
818
818
819 dataOut.data = datadec
819 dataOut.data = datadec
820
820
821 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
821 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
822
822
823 dataOut.flagDecodeData = True #asumo q la data esta decodificada
823 dataOut.flagDecodeData = True #asumo q la data esta decodificada
824
824
825 if self.__profIndex == self.nCode-1:
825 if self.__profIndex == self.nCode-1:
826 self.__profIndex = 0
826 self.__profIndex = 0
827 return 1
827 return 1
828
828
829 self.__profIndex += 1
829 self.__profIndex += 1
830
830
831 return 1
831 return 1
832 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
832 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
833
833
834
834
835 class ProfileConcat(Operation):
835 class ProfileConcat(Operation):
836
836
837 isConfig = False
837 isConfig = False
838 buffer = None
838 buffer = None
839 concat_m =None
839 concat_m =None
840
840
841 def __init__(self, **kwargs):
841 def __init__(self, **kwargs):
842
842
843 Operation.__init__(self, **kwargs)
843 Operation.__init__(self, **kwargs)
844 self.profileIndex = 0
844 self.profileIndex = 0
845
845
846 def reset(self):
846 def reset(self):
847 self.buffer = numpy.zeros_like(self.buffer)
847 self.buffer = numpy.zeros_like(self.buffer)
848 self.start_index = 0
848 self.start_index = 0
849 self.times = 1
849 self.times = 1
850
850
851 def setup(self, data, m, n=1):
851 def setup(self, data, m, n=1):
852 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
852 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
853 self.nHeights = data.shape[1]#.nHeights
853 self.nHeights = data.shape[1]#.nHeights
854 self.start_index = 0
854 self.start_index = 0
855 self.times = 1
855 self.times = 1
856
856
857 def concat(self, data):
857 def concat(self, data):
858
858
859 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
859 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
860 self.start_index = self.start_index + self.nHeights
860 self.start_index = self.start_index + self.nHeights
861
861
862 def run(self, dataOut, m):
862 def run(self, dataOut, m):
863
863
864 self.concat_m= m
864 self.concat_m= m
865 dataOut.flagNoData = True
865 dataOut.flagNoData = True
866
866
867 if not self.isConfig:
867 if not self.isConfig:
868 self.setup(dataOut.data, m, 1)
868 self.setup(dataOut.data, m, 1)
869 self.isConfig = True
869 self.isConfig = True
870
870
871 if dataOut.flagDataAsBlock:
871 if dataOut.flagDataAsBlock:
872 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
872 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
873
873
874 else:
874 else:
875 self.concat(dataOut.data)
875 self.concat(dataOut.data)
876 self.times += 1
876 self.times += 1
877 if self.times > m:
877 if self.times > m:
878 dataOut.data = self.buffer
878 dataOut.data = self.buffer
879 self.reset()
879 self.reset()
880 dataOut.flagNoData = False
880 dataOut.flagNoData = False
881 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
881 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
882 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
882 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
883 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
883 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
884 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
884 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
885 dataOut.ippSeconds *= m
885 dataOut.ippSeconds *= m
886 dataOut.concat_m = int(m)
886 dataOut.concat_m = int(m)
887
887
888 class ProfileSelector(Operation):
888 class ProfileSelector(Operation):
889
889
890 profileIndex = None
890 profileIndex = None
891 # Tamanho total de los perfiles
891 # Tamanho total de los perfiles
892 nProfiles = None
892 nProfiles = None
893
893
894 def __init__(self, **kwargs):
894 def __init__(self, **kwargs):
895
895
896 Operation.__init__(self, **kwargs)
896 Operation.__init__(self, **kwargs)
897 self.profileIndex = 0
897 self.profileIndex = 0
898
898
899 def incProfileIndex(self):
899 def incProfileIndex(self):
900
900
901 self.profileIndex += 1
901 self.profileIndex += 1
902
902
903 if self.profileIndex >= self.nProfiles:
903 if self.profileIndex >= self.nProfiles:
904 self.profileIndex = 0
904 self.profileIndex = 0
905
905
906 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
906 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
907
907
908 if profileIndex < minIndex:
908 if profileIndex < minIndex:
909 return False
909 return False
910
910
911 if profileIndex > maxIndex:
911 if profileIndex > maxIndex:
912 return False
912 return False
913
913
914 return True
914 return True
915
915
916 def isThisProfileInList(self, profileIndex, profileList):
916 def isThisProfileInList(self, profileIndex, profileList):
917
917
918 if profileIndex not in profileList:
918 if profileIndex not in profileList:
919 return False
919 return False
920
920
921 return True
921 return True
922
922
923 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
923 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
924
924
925 """
925 """
926 ProfileSelector:
926 ProfileSelector:
927
927
928 Inputs:
928 Inputs:
929 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
929 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
930
930
931 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
931 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
932
932
933 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
933 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
934
934
935 """
935 """
936 print "HOLA MUNDO CRUEL"
936 #print "HOLA MUNDO CRUEL"
937 if rangeList is not None:
937 if rangeList is not None:
938 if type(rangeList[0]) not in (tuple, list):
938 if type(rangeList[0]) not in (tuple, list):
939 rangeList = [rangeList]
939 rangeList = [rangeList]
940
940
941 dataOut.flagNoData = True
941 dataOut.flagNoData = True
942
942
943 if dataOut.flagDataAsBlock:
943 if dataOut.flagDataAsBlock:
944 """
944 """
945 data dimension = [nChannels, nProfiles, nHeis]
945 data dimension = [nChannels, nProfiles, nHeis]
946 """
946 """
947 if profileList != None:
947 if profileList != None:
948 dataOut.data = dataOut.data[:,profileList,:]
948 dataOut.data = dataOut.data[:,profileList,:]
949
949
950 if profileRangeList != None:
950 if profileRangeList != None:
951 minIndex = profileRangeList[0]
951 minIndex = profileRangeList[0]
952 maxIndex = profileRangeList[1]
952 maxIndex = profileRangeList[1]
953 profileList = range(minIndex, maxIndex+1)
953 profileList = range(minIndex, maxIndex+1)
954
954
955 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
955 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
956
956
957 if rangeList != None:
957 if rangeList != None:
958
958
959 profileList = []
959 profileList = []
960
960
961 for thisRange in rangeList:
961 for thisRange in rangeList:
962 minIndex = thisRange[0]
962 minIndex = thisRange[0]
963 maxIndex = thisRange[1]
963 maxIndex = thisRange[1]
964
964
965 profileList.extend(range(minIndex, maxIndex+1))
965 profileList.extend(range(minIndex, maxIndex+1))
966
966
967 dataOut.data = dataOut.data[:,profileList,:]
967 dataOut.data = dataOut.data[:,profileList,:]
968
968
969 dataOut.nProfiles = len(profileList)
969 dataOut.nProfiles = len(profileList)
970 dataOut.profileIndex = dataOut.nProfiles - 1
970 dataOut.profileIndex = dataOut.nProfiles - 1
971 dataOut.flagNoData = False
971 dataOut.flagNoData = False
972
972
973 return True
973 return True
974
974
975 """
975 """
976 data dimension = [nChannels, nHeis]
976 data dimension = [nChannels, nHeis]
977 """
977 """
978
978
979 if profileList != None:
979 if profileList != None:
980
980
981 if self.isThisProfileInList(dataOut.profileIndex, profileList):
981 if self.isThisProfileInList(dataOut.profileIndex, profileList):
982
982
983 self.nProfiles = len(profileList)
983 self.nProfiles = len(profileList)
984 dataOut.nProfiles = self.nProfiles
984 dataOut.nProfiles = self.nProfiles
985 dataOut.profileIndex = self.profileIndex
985 dataOut.profileIndex = self.profileIndex
986 dataOut.flagNoData = False
986 dataOut.flagNoData = False
987
987
988 self.incProfileIndex()
988 self.incProfileIndex()
989 return True
989 return True
990
990
991 if profileRangeList != None:
991 if profileRangeList != None:
992
992
993 minIndex = profileRangeList[0]
993 minIndex = profileRangeList[0]
994 maxIndex = profileRangeList[1]
994 maxIndex = profileRangeList[1]
995
995
996 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
996 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
997
997
998 self.nProfiles = maxIndex - minIndex + 1
998 self.nProfiles = maxIndex - minIndex + 1
999 dataOut.nProfiles = self.nProfiles
999 dataOut.nProfiles = self.nProfiles
1000 dataOut.profileIndex = self.profileIndex
1000 dataOut.profileIndex = self.profileIndex
1001 dataOut.flagNoData = False
1001 dataOut.flagNoData = False
1002
1002
1003 self.incProfileIndex()
1003 self.incProfileIndex()
1004 return True
1004 return True
1005
1005
1006 if rangeList != None:
1006 if rangeList != None:
1007
1007
1008 nProfiles = 0
1008 nProfiles = 0
1009
1009
1010 for thisRange in rangeList:
1010 for thisRange in rangeList:
1011 minIndex = thisRange[0]
1011 minIndex = thisRange[0]
1012 maxIndex = thisRange[1]
1012 maxIndex = thisRange[1]
1013
1013
1014 nProfiles += maxIndex - minIndex + 1
1014 nProfiles += maxIndex - minIndex + 1
1015
1015
1016 for thisRange in rangeList:
1016 for thisRange in rangeList:
1017
1017
1018 minIndex = thisRange[0]
1018 minIndex = thisRange[0]
1019 maxIndex = thisRange[1]
1019 maxIndex = thisRange[1]
1020
1020
1021 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1021 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1022
1022
1023 self.nProfiles = nProfiles
1023 self.nProfiles = nProfiles
1024 dataOut.nProfiles = self.nProfiles
1024 dataOut.nProfiles = self.nProfiles
1025 dataOut.profileIndex = self.profileIndex
1025 dataOut.profileIndex = self.profileIndex
1026 dataOut.flagNoData = False
1026 dataOut.flagNoData = False
1027
1027
1028 self.incProfileIndex()
1028 self.incProfileIndex()
1029
1029
1030 break
1030 break
1031
1031
1032 return True
1032 return True
1033
1033
1034
1034
1035 if beam != None: #beam is only for AMISR data
1035 if beam != None: #beam is only for AMISR data
1036 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1036 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1037 dataOut.flagNoData = False
1037 dataOut.flagNoData = False
1038 dataOut.profileIndex = self.profileIndex
1038 dataOut.profileIndex = self.profileIndex
1039
1039
1040 self.incProfileIndex()
1040 self.incProfileIndex()
1041
1041
1042 return True
1042 return True
1043
1043
1044 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
1044 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
1045
1045
1046 return False
1046 return False
1047
1047
1048 class Reshaper(Operation):
1048 class Reshaper(Operation):
1049
1049
1050 def __init__(self, **kwargs):
1050 def __init__(self, **kwargs):
1051
1051
1052 Operation.__init__(self, **kwargs)
1052 Operation.__init__(self, **kwargs)
1053
1053
1054 self.__buffer = None
1054 self.__buffer = None
1055 self.__nitems = 0
1055 self.__nitems = 0
1056
1056
1057 def __appendProfile(self, dataOut, nTxs):
1057 def __appendProfile(self, dataOut, nTxs):
1058
1058
1059 if self.__buffer is None:
1059 if self.__buffer is None:
1060 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1060 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1061 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1061 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1062
1062
1063 ini = dataOut.nHeights * self.__nitems
1063 ini = dataOut.nHeights * self.__nitems
1064 end = ini + dataOut.nHeights
1064 end = ini + dataOut.nHeights
1065
1065
1066 self.__buffer[:, ini:end] = dataOut.data
1066 self.__buffer[:, ini:end] = dataOut.data
1067
1067
1068 self.__nitems += 1
1068 self.__nitems += 1
1069
1069
1070 return int(self.__nitems*nTxs)
1070 return int(self.__nitems*nTxs)
1071
1071
1072 def __getBuffer(self):
1072 def __getBuffer(self):
1073
1073
1074 if self.__nitems == int(1./self.__nTxs):
1074 if self.__nitems == int(1./self.__nTxs):
1075
1075
1076 self.__nitems = 0
1076 self.__nitems = 0
1077
1077
1078 return self.__buffer.copy()
1078 return self.__buffer.copy()
1079
1079
1080 return None
1080 return None
1081
1081
1082 def __checkInputs(self, dataOut, shape, nTxs):
1082 def __checkInputs(self, dataOut, shape, nTxs):
1083
1083
1084 if shape is None and nTxs is None:
1084 if shape is None and nTxs is None:
1085 raise ValueError, "Reshaper: shape of factor should be defined"
1085 raise ValueError, "Reshaper: shape of factor should be defined"
1086
1086
1087 if nTxs:
1087 if nTxs:
1088 if nTxs < 0:
1088 if nTxs < 0:
1089 raise ValueError, "nTxs should be greater than 0"
1089 raise ValueError, "nTxs should be greater than 0"
1090
1090
1091 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1091 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1092 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1092 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1093
1093
1094 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1094 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1095
1095
1096 return shape, nTxs
1096 return shape, nTxs
1097
1097
1098 if len(shape) != 2 and len(shape) != 3:
1098 if len(shape) != 2 and len(shape) != 3:
1099 raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)
1099 raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)
1100
1100
1101 if len(shape) == 2:
1101 if len(shape) == 2:
1102 shape_tuple = [dataOut.nChannels]
1102 shape_tuple = [dataOut.nChannels]
1103 shape_tuple.extend(shape)
1103 shape_tuple.extend(shape)
1104 else:
1104 else:
1105 shape_tuple = list(shape)
1105 shape_tuple = list(shape)
1106
1106
1107 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1107 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1108
1108
1109 return shape_tuple, nTxs
1109 return shape_tuple, nTxs
1110
1110
1111 def run(self, dataOut, shape=None, nTxs=None):
1111 def run(self, dataOut, shape=None, nTxs=None):
1112
1112
1113 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1113 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1114
1114
1115 dataOut.flagNoData = True
1115 dataOut.flagNoData = True
1116 profileIndex = None
1116 profileIndex = None
1117
1117
1118 if dataOut.flagDataAsBlock:
1118 if dataOut.flagDataAsBlock:
1119
1119
1120 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1120 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1121 dataOut.flagNoData = False
1121 dataOut.flagNoData = False
1122
1122
1123 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1123 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1124
1124
1125 else:
1125 else:
1126
1126
1127 if self.__nTxs < 1:
1127 if self.__nTxs < 1:
1128
1128
1129 self.__appendProfile(dataOut, self.__nTxs)
1129 self.__appendProfile(dataOut, self.__nTxs)
1130 new_data = self.__getBuffer()
1130 new_data = self.__getBuffer()
1131
1131
1132 if new_data is not None:
1132 if new_data is not None:
1133 dataOut.data = new_data
1133 dataOut.data = new_data
1134 dataOut.flagNoData = False
1134 dataOut.flagNoData = False
1135
1135
1136 profileIndex = dataOut.profileIndex*nTxs
1136 profileIndex = dataOut.profileIndex*nTxs
1137
1137
1138 else:
1138 else:
1139 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1139 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1140
1140
1141 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1141 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1142
1142
1143 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1143 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1144
1144
1145 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1145 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1146
1146
1147 dataOut.profileIndex = profileIndex
1147 dataOut.profileIndex = profileIndex
1148
1148
1149 dataOut.ippSeconds /= self.__nTxs
1149 dataOut.ippSeconds /= self.__nTxs
1150
1150
1151 class SplitProfiles(Operation):
1151 class SplitProfiles(Operation):
1152
1152
1153 def __init__(self, **kwargs):
1153 def __init__(self, **kwargs):
1154
1154
1155 Operation.__init__(self, **kwargs)
1155 Operation.__init__(self, **kwargs)
1156
1156
1157 def run(self, dataOut, n):
1157 def run(self, dataOut, n):
1158
1158
1159 dataOut.flagNoData = True
1159 dataOut.flagNoData = True
1160 profileIndex = None
1160 profileIndex = None
1161
1161
1162 if dataOut.flagDataAsBlock:
1162 if dataOut.flagDataAsBlock:
1163
1163
1164 #nchannels, nprofiles, nsamples
1164 #nchannels, nprofiles, nsamples
1165 shape = dataOut.data.shape
1165 shape = dataOut.data.shape
1166
1166
1167 if shape[2] % n != 0:
1167 if shape[2] % n != 0:
1168 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1168 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1169
1169
1170 new_shape = shape[0], shape[1]*n, shape[2]/n
1170 new_shape = shape[0], shape[1]*n, shape[2]/n
1171
1171
1172 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1172 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1173 dataOut.flagNoData = False
1173 dataOut.flagNoData = False
1174
1174
1175 profileIndex = int(dataOut.nProfiles/n) - 1
1175 profileIndex = int(dataOut.nProfiles/n) - 1
1176
1176
1177 else:
1177 else:
1178
1178
1179 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1179 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1180
1180
1181 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1181 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1182
1182
1183 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1183 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1184
1184
1185 dataOut.nProfiles = int(dataOut.nProfiles*n)
1185 dataOut.nProfiles = int(dataOut.nProfiles*n)
1186
1186
1187 dataOut.profileIndex = profileIndex
1187 dataOut.profileIndex = profileIndex
1188
1188
1189 dataOut.ippSeconds /= n
1189 dataOut.ippSeconds /= n
1190
1190
1191 class CombineProfiles(Operation):
1191 class CombineProfiles(Operation):
1192
1192
1193 def __init__(self, **kwargs):
1193 def __init__(self, **kwargs):
1194
1194
1195 Operation.__init__(self, **kwargs)
1195 Operation.__init__(self, **kwargs)
1196
1196
1197 self.__remData = None
1197 self.__remData = None
1198 self.__profileIndex = 0
1198 self.__profileIndex = 0
1199
1199
1200 def run(self, dataOut, n):
1200 def run(self, dataOut, n):
1201
1201
1202 dataOut.flagNoData = True
1202 dataOut.flagNoData = True
1203 profileIndex = None
1203 profileIndex = None
1204
1204
1205 if dataOut.flagDataAsBlock:
1205 if dataOut.flagDataAsBlock:
1206
1206
1207 #nchannels, nprofiles, nsamples
1207 #nchannels, nprofiles, nsamples
1208 shape = dataOut.data.shape
1208 shape = dataOut.data.shape
1209 new_shape = shape[0], shape[1]/n, shape[2]*n
1209 new_shape = shape[0], shape[1]/n, shape[2]*n
1210
1210
1211 if shape[1] % n != 0:
1211 if shape[1] % n != 0:
1212 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1212 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1213
1213
1214 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1214 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1215 dataOut.flagNoData = False
1215 dataOut.flagNoData = False
1216
1216
1217 profileIndex = int(dataOut.nProfiles*n) - 1
1217 profileIndex = int(dataOut.nProfiles*n) - 1
1218
1218
1219 else:
1219 else:
1220
1220
1221 #nchannels, nsamples
1221 #nchannels, nsamples
1222 if self.__remData is None:
1222 if self.__remData is None:
1223 newData = dataOut.data
1223 newData = dataOut.data
1224 else:
1224 else:
1225 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1225 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1226
1226
1227 self.__profileIndex += 1
1227 self.__profileIndex += 1
1228
1228
1229 if self.__profileIndex < n:
1229 if self.__profileIndex < n:
1230 self.__remData = newData
1230 self.__remData = newData
1231 #continue
1231 #continue
1232 return
1232 return
1233
1233
1234 self.__profileIndex = 0
1234 self.__profileIndex = 0
1235 self.__remData = None
1235 self.__remData = None
1236
1236
1237 dataOut.data = newData
1237 dataOut.data = newData
1238 dataOut.flagNoData = False
1238 dataOut.flagNoData = False
1239
1239
1240 profileIndex = dataOut.profileIndex/n
1240 profileIndex = dataOut.profileIndex/n
1241
1241
1242
1242
1243 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1243 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1244
1244
1245 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1245 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1246
1246
1247 dataOut.nProfiles = int(dataOut.nProfiles/n)
1247 dataOut.nProfiles = int(dataOut.nProfiles/n)
1248
1248
1249 dataOut.profileIndex = profileIndex
1249 dataOut.profileIndex = profileIndex
1250
1250
1251 dataOut.ippSeconds *= n
1251 dataOut.ippSeconds *= n
1252
1252
1253
1253
1254 class SSheightProfiles(Operation):
1254 class SSheightProfiles(Operation):
1255
1255
1256 step = None
1256 step = None
1257 nsamples = None
1257 nsamples = None
1258 bufferShape = None
1258 bufferShape = None
1259 profileShape = None
1259 profileShape = None
1260 sshProfiles = None
1260 sshProfiles = None
1261 profileIndex = None
1261 profileIndex = None
1262
1262
1263 def __init__(self, **kwargs):
1263 def __init__(self, **kwargs):
1264
1264
1265 Operation.__init__(self, **kwargs)
1265 Operation.__init__(self, **kwargs)
1266 self.isConfig = False
1266 self.isConfig = False
1267
1267
1268 def setup(self,dataOut ,step = None , nsamples = None):
1268 def setup(self,dataOut ,step = None , nsamples = None):
1269
1269
1270 if step == None and nsamples == None:
1270 if step == None and nsamples == None:
1271 raise ValueError, "step or nheights should be specified ..."
1271 raise ValueError, "step or nheights should be specified ..."
1272
1272
1273 self.step = step
1273 self.step = step
1274 self.nsamples = nsamples
1274 self.nsamples = nsamples
1275 self.__nChannels = dataOut.nChannels
1275 self.__nChannels = dataOut.nChannels
1276 self.__nProfiles = dataOut.nProfiles
1276 self.__nProfiles = dataOut.nProfiles
1277 self.__nHeis = dataOut.nHeights
1277 self.__nHeis = dataOut.nHeights
1278 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
1278 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
1279 print "input nChannels",self.__nChannels
1279 print "input nChannels",self.__nChannels
1280 print "input nProfiles",self.__nProfiles
1280 print "input nProfiles",self.__nProfiles
1281 print "input nHeis",self.__nHeis
1281 print "input nHeis",self.__nHeis
1282 print "input Shape",shape
1282 print "input Shape",shape
1283
1283
1284
1284
1285
1285
1286 residue = (shape[1] - self.nsamples) % self.step
1286 residue = (shape[1] - self.nsamples) % self.step
1287 if residue != 0:
1287 if residue != 0:
1288 print "The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue)
1288 print "The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue)
1289
1289
1290 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1290 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1291 numberProfile = self.nsamples
1291 numberProfile = self.nsamples
1292 numberSamples = (shape[1] - self.nsamples)/self.step
1292 numberSamples = (shape[1] - self.nsamples)/self.step
1293
1293
1294 print "new numberProfile",numberProfile
1294 print "new numberProfile",numberProfile
1295 print "new numberSamples",numberSamples
1295 print "new numberSamples",numberSamples
1296
1296
1297 print "New number of profile: %d, number of height: %d, Resolution %f Km"%(numberProfile,numberSamples,deltaHeight*self.step)
1297 print "New number of profile: %d, number of height: %d, Resolution %f Km"%(numberProfile,numberSamples,deltaHeight*self.step)
1298
1298
1299 self.bufferShape = shape[0], numberSamples, numberProfile # nchannels, nsamples , nprofiles
1299 self.bufferShape = shape[0], numberSamples, numberProfile # nchannels, nsamples , nprofiles
1300 self.profileShape = shape[0], numberProfile, numberSamples # nchannels, nprofiles, nsamples
1300 self.profileShape = shape[0], numberProfile, numberSamples # nchannels, nprofiles, nsamples
1301
1301
1302 self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex)
1302 self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex)
1303 self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex)
1303 self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex)
1304
1304
1305 def run(self, dataOut, step, nsamples):
1305 def run(self, dataOut, step, nsamples):
1306
1306
1307 dataOut.flagNoData = True
1307 dataOut.flagNoData = True
1308 dataOut.flagDataAsBlock = False
1308 dataOut.flagDataAsBlock = False
1309 profileIndex = None
1309 profileIndex = None
1310
1310
1311
1311
1312 if not self.isConfig:
1312 if not self.isConfig:
1313 self.setup(dataOut, step=step , nsamples=nsamples)
1313 self.setup(dataOut, step=step , nsamples=nsamples)
1314 self.isConfig = True
1314 self.isConfig = True
1315
1315
1316 for i in range(self.buffer.shape[1]):
1316 for i in range(self.buffer.shape[1]):
1317 #self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples])
1317 #self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples])
1318 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]
1318 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]
1319 #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights])
1319 #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights])
1320
1320
1321 for j in range(self.buffer.shape[0]):
1321 for j in range(self.buffer.shape[0]):
1322 self.sshProfiles[j] = numpy.transpose(self.buffer[j])
1322 self.sshProfiles[j] = numpy.transpose(self.buffer[j])
1323
1323
1324 profileIndex = self.nsamples
1324 profileIndex = self.nsamples
1325 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1325 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1326 ippSeconds = (deltaHeight*1.0e-6)/(0.15)
1326 ippSeconds = (deltaHeight*1.0e-6)/(0.15)
1327 #print "ippSeconds",ippSeconds
1327 #print "ippSeconds",ippSeconds
1328 try:
1328 try:
1329 if dataOut.concat_m is not None:
1329 if dataOut.concat_m is not None:
1330 ippSeconds= ippSeconds/float(dataOut.concat_m)
1330 ippSeconds= ippSeconds/float(dataOut.concat_m)
1331 #print "Profile concat %d"%dataOut.concat_m
1331 #print "Profile concat %d"%dataOut.concat_m
1332 except:
1332 except:
1333 pass
1333 pass
1334
1334
1335 dataOut.data = self.sshProfiles
1335 dataOut.data = self.sshProfiles
1336 dataOut.flagNoData = False
1336 dataOut.flagNoData = False
1337 dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0]
1337 dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0]
1338 dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples)
1338 dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples)
1339 dataOut.profileIndex = profileIndex
1339 dataOut.profileIndex = profileIndex
1340 dataOut.flagDataAsBlock = True
1340 dataOut.flagDataAsBlock = True
1341 dataOut.ippSeconds = ippSeconds
1341 dataOut.ippSeconds = ippSeconds
1342 dataOut.step = self.step
1342 dataOut.step = self.step
1343
1343
1344 class voltACFLags(Operation):
1344 class voltACFLags(Operation):
1345
1345
1346 data_acf = None
1346 data_acf = None
1347 lags = None
1347 lags = None
1348 mode = None
1348 mode = None
1349 fullBuffer = None
1349 fullBuffer = None
1350 pairsList = None
1350 pairsList = None
1351 tmp = None
1351 tmp = None
1352
1352
1353 def __init__(self, **kwargs):
1353 def __init__(self, **kwargs):
1354 Operation.__init__(self, **kwargs)
1354 Operation.__init__(self, **kwargs)
1355 self.isConfig = False
1355 self.isConfig = False
1356 self.profIndex = 0
1356 self.profIndex = 0
1357 self.buffer = None
1357 self.buffer = None
1358 self.channelList = []
1358
1359
1359
1360
1360 def setup(self,dataOut ,lags = None,mode =None, fullBuffer= None ,pairsList = None,nAvg = 1):
1361 def setup(self,dataOut ,lags = None,mode =None, fullBuffer= None ,pairsList = None,nAvg = 1):
1361
1362
1362 self.lags = lags
1363 self.lags = lags
1363 print self.lags
1364 print self.lags
1364 self.mode = mode
1365 self.mode = mode
1365 self.fullBuffer= fullBuffer
1366 self.fullBuffer= fullBuffer
1366 self.nAvg = nAvg
1367 self.nAvg = nAvg
1367 self.pairsList = pairsList
1368 self.pairsList = [pairsList]
1368 nChannels = dataOut.nChannels
1369 nChannels = dataOut.nChannels
1369 nProfiles = dataOut.nProfiles
1370 nProfiles = dataOut.nProfiles
1370 nHeights = dataOut.nHeights
1371 nHeights = dataOut.nHeights
1371 self.__nProfiles = dataOut.nProfiles
1372 self.__nProfiles = dataOut.nProfiles
1372 self.__nHeis = dataOut.nHeights
1373 self.__nHeis = dataOut.nHeights
1373
1374
1374 if mode == 'time':
1375 if mode == 'time':
1375 print "Mode lags equal time for default."
1376 print "Mode lags equal time for default."
1376 else:
1377 else:
1377 print "Mode lags equal height."
1378 print "Mode lags equal height."
1378
1379
1379 if pairsList == None:
1380 if pairsList == None:
1380 print "Pairs list selected by default (1,0)"
1381 print "Pairs list selected by default (1,0)"
1381 pairsList = [(0,1)]
1382 pairsList = [(0,1)]
1382 self.pairsList= pairsList
1383 self.pairsList= pairsList
1383
1384
1384 self.selectChannels(self.pairsList)
1385
1386 for i in range(len(self.pairsList)):
1387 self.channelList.append(self.pairsList[i][0])
1388 self.channelList.append(self.pairsList[i][1])
1385
1389
1386 if lags == None:
1390 if lags == None:
1387 if mode=='time':
1391 if mode=='time':
1388 self.lags = numpy.arange(0,nProfiles)# -nProfiles+1, nProfiles
1392 self.lags = numpy.arange(0,nProfiles)# -nProfiles+1, nProfiles
1389 print "self.lags", len(self.lags)
1393 print "self.lags", len(self.lags)
1390 if mode=='height':
1394 if mode=='height':
1391 self.lags = numpy.arange(0,nHeights)# -nHeights+1, nHeights
1395 self.lags = numpy.arange(0,nHeights)# -nHeights+1, nHeights
1392
1396
1393 # buffer de canalaes, perfiles, alturas
1397 # buffer de canalaes, perfiles, alturas
1394 if self.buffer is None:
1398 if self.buffer is None:
1395 self.buffer = numpy.zeros((len(pairsList),nProfiles,nHeights),dtype='complex')
1399 self.buffer = numpy.zeros((nChannels,nProfiles,nHeights),dtype='complex')
1396
1400
1397 if fullBuffer:
1401 if fullBuffer:
1398 self.tmp = numpy.zeros((len(pairsList), len(self.lags), nProfiles, nHeights), dtype = 'complex')*numpy.nan
1402 self.tmp = numpy.zeros((len(self.pairsList), len(self.lags), nProfiles, nHeights), dtype = 'complex')*numpy.nan
1399 elif mode =='time':
1403 elif mode =='time':
1400 self.tmp = numpy.zeros((len(pairsList), len(self.lags), nHeights),dtype='complex')
1404 self.tmp = numpy.zeros((len(self.pairsList), len(self.lags), nHeights),dtype='complex')
1401 elif mode =='height':
1405 elif mode =='height':
1402 self.tmp = numpy.zeros(len(pairsList), (len(self.lags), nProfiles),dtype='complex')
1406 self.tmp = numpy.zeros((len(self.pairsList), len(self.lags), nProfiles),dtype='complex')
1403
1407
1404 print "lags", len(self.lags),self.lags
1408 print "lags", len(self.lags),self.lags
1405 print "mode",self.mode
1409 print "mode",self.mode
1406 print "nChannels", nChannels
1410 print "nChannels", nChannels
1407 print "nProfiles", nProfiles
1411 print "nProfiles", nProfiles
1408 print "nHeights" , nHeights
1412 print "nHeights" , nHeights
1413 print "acf_channels",len(self.pairsList)
1414 print "channelList",self.channelList
1409 print "pairsList", pairsList,len(self.pairsList)
1415 print "pairsList", pairsList,len(self.pairsList)
1410 print "fullBuffer", fullBuffer
1416 print "fullBuffer", fullBuffer
1411 #print "type(pairsList)",type(pairsList)
1417 #print "type(pairsList)",type(pairsList)
1412 print "tmp.shape",self.tmp.shape
1418 print "tmp.shape",self.tmp.shape
1413
1419
1414
1420
1415 def run(self, dataOut, lags =None,mode ='time',fullBuffer= False ,pairsList = None,nAvg = 1):
1421 def run(self, dataOut, lags =None,mode ='time',fullBuffer= False ,pairsList = None,nAvg = 1):
1416
1422
1417 dataOut.flagNoData = True
1423 dataOut.flagNoData = True
1418
1424
1419 if not self.isConfig:
1425 if not self.isConfig:
1420 self.setup(dataOut, lags = lags,mode = mode, fullBuffer= fullBuffer ,pairsList = pairsList,nAvg=nAvg)
1426 self.setup(dataOut, lags = lags,mode = mode, fullBuffer= fullBuffer ,pairsList = pairsList,nAvg=nAvg)
1421 self.isConfig = True
1427 self.isConfig = True
1422 print "pairsList Ale", self.pairsList
1428
1423 print dataOut.data[pairsList,:].shape
1424 if dataOut.type == "Voltage":
1429 if dataOut.type == "Voltage":
1425 if dataOut.flagDataAsBlock:
1430 if dataOut.flagDataAsBlock:
1426 print "Not implemented yet"
1431 print "Not implemented yet"
1427 return 0
1432 return 0
1428 else:
1433 else:
1429 print "shapebuffer",self.buffer[:,0,:].shape
1434 self.buffer[:, self.profIndex, :] = dataOut.data
1430 self.buffer[:, self.profIndex, :] = dataOut.data#error
1431 self.profIndex += 1
1435 self.profIndex += 1
1432
1436
1433 if self.profIndex == self.__nProfiles :
1437 if self.profIndex == self.__nProfiles :
1438
1434 data_pre = self.buffer #data
1439 data_pre = self.buffer #data
1435 print "size",data_pre.shape
1436 # Here is the loop :D
1437 for l in range(len(self.pairsList)):
1440 for l in range(len(self.pairsList)):
1438 ch0 = self.pairsList[l][0]
1441 ch0 = self.pairsList[l][0]
1439 ch1 = self.pairsList[l][1]
1442 ch1 = self.pairsList[l][1]
1440 for i in range(len(self.lags)):
1443 for i in range(len(self.lags)):
1441 idx = self.lags[i]
1444 idx = self.lags[i]
1442 if self.mode == 'time':
1445 if self.mode == 'time':
1443 acf0 = data_pre[ch0,:self.__nProfiles-idx,:]*numpy.conj(data_pre[ch1,idx:,:]) # pair,lag,height
1446 acf0 = data_pre[ch0,:self.__nProfiles-idx,:]*numpy.conj(data_pre[ch1,idx:,:]) # pair,lag,height
1444 else:
1447 else:
1445 acf0 = data_pre[ch0,:,:self.__nHeights-idx]*numpy.conj(data_pre[ch1,:,idx:]) # pair,lag,profile
1448 acf0 = data_pre[ch0,:,:self.__nHeights-idx]*numpy.conj(data_pre[ch1,:,idx:]) # pair,lag,profile
1446
1449
1447 if self.fullBuffer:
1450 if self.fullBuffer:
1448 self.tmp[l,i,:acf0.shape[0],:]= acf0
1451 self.tmp[l,i,:acf0.shape[0],:]= acf0
1449 else:
1452 else:
1450 self.tmp[l,i,:]= numpy.sum(acf0,axis=0)
1453 self.tmp[l,i,:]= numpy.sum(acf0,axis=0)
1451 if self.fullBuffer:
1454 if self.fullBuffer:
1452 self.tmp = numpy.sum(numpy.reshape(self.tmp,(self.tmp.shape[0],self.tmp.shape[1],self.tmp.shape[2]/self.nAvg,self.nAvg,self.tmp.shape[3])),axis=3)
1455 self.tmp = numpy.sum(numpy.reshape(self.tmp,(self.tmp.shape[0],self.tmp.shape[1],self.tmp.shape[2]/self.nAvg,self.nAvg,self.tmp.shape[3])),axis=3)
1453 dataOut.nAvg = self.nAvg
1456 dataOut.nAvg = self.nAvg
1454
1455 if self.mode == 'time':
1457 if self.mode == 'time':
1458 #print "entre"
1456 delta = dataOut.ippSeconds*dataOut.nCohInt
1459 delta = dataOut.ippSeconds*dataOut.nCohInt
1457 else:
1460 else:
1458 delta = dataOut.heightList[1] - dataOut.heightList[0]
1461 delta = dataOut.heightList[1] - dataOut.heightList[0]
1459
1462
1460 shape= self.tmp.shape # mode time
1463 shape= self.tmp.shape
1461 # Normalizando
1464 for i in range(len(self.pairsList)):
1462 for i in range(len(pairsList)):
1463 for j in range(shape[2]):
1465 for j in range(shape[2]):
1464 self.tmp[i,:,j]= self.tmp[i,:,j].real / numpy.max(numpy.abs(self.tmp[i,:,j]))
1466 self.tmp[i,:,j]= self.tmp[i,:,j].real/numpy.max(numpy.abs(self.tmp[i,:,j]))
1465
1467
1466 #import matplotlib.pyplot as plt
1468 #import matplotlib.pyplot as plt
1467 #print "test",self.tmp.shape
1469 #print "test",self.tmp.shape
1468 #print self.tmp[0,0,0]
1470 #print self.tmp[0,0,0]
1469 #print numpy.max(numpy.abs(self.tmp[0,:,0]))
1471 #print numpy.max(numpy.abs(self.tmp[0,:,0]))
1470 #acf_tmp=self.tmp[0,:,100].real/numpy.max(numpy.abs(self.tmp[0,:,100]))
1472 #acf_tmp=self.tmp[0,:,100].real/numpy.max(numpy.abs(self.tmp[0,:,100]))
1471 #print acf_tmp
1473 #print acf_tmp
1472 #plt.plot(acf_tmp)
1474 #plt.plot(acf_tmp)
1473 #plt.show()
1475 #plt.show()
1474 #import time
1476 #import time
1475 #time.sleep(20)
1477 #time.sleep(20)
1476 dataOut.data = self.tmp
1478 dataOut.data = self.buffer
1479 dataOut.data_acfLag = self.tmp
1477 dataOut.mode = self.mode
1480 dataOut.mode = self.mode
1478 dataOut.nLags = len(self.lags)
1481 dataOut.nLags = len(self.lags)
1479 dataOut.nProfiles = len(self.lags)
1482 dataOut.nProfiles = len(self.lags)
1480 dataOut.pairsList = pairsList
1483 dataOut.pairsList = pairsList
1481 dataOut.nPairs = len(pairsList)
1484 dataOut.nPairs = len(pairsList)
1482 dataOut.lagRange = numpy.array(self.lags)*delta
1485 dataOut.lagRange = numpy.array(self.lags)*delta
1483 dataOut.flagDataAsBlock = True
1486 dataOut.flagDataAsBlock = True
1484 dataOut.flagNoData = False
1487 dataOut.flagNoData = False
1488 self.profIndex = 0
1485
1489
1486
1490
1487 import time
1491 import time
1488 #################################################
1492 #################################################
1489
1493
1490 class decoPseudorandom(Operation):
1494 class decoPseudorandom(Operation):
1491
1495
1492 nProfiles= 0
1496 nProfiles= 0
1493 buffer= None
1497 buffer= None
1494 isConfig = False
1498 isConfig = False
1495
1499
1496 def setup(self, clen= 10000,seed= 0,Nranges= 1000,oversample=1):
1500 def setup(self, clen= 10000,seed= 0,Nranges= 1000,oversample=1):
1497 #code = create_pseudo_random_code(clen=clen, seed=seed)
1501 #code = create_pseudo_random_code(clen=clen, seed=seed)
1498 code= rep_seq(create_pseudo_random_code(clen=clen, seed=seed),rep=oversample)
1502 code= rep_seq(create_pseudo_random_code(clen=clen, seed=seed),rep=oversample)
1499 #print ("code_rx", code.shape)
1503 #print ("code_rx", code.shape)
1500 #N = int(an_len/clen) # 100
1504 #N = int(an_len/clen) # 100
1501 B_cache = 0
1505 B_cache = 0
1502 r_cache = 0
1506 r_cache = 0
1503 B_cached = False
1507 B_cached = False
1504 r = create_estimation_matrix(code=code, cache=True, rmax=Nranges)
1508 r = create_estimation_matrix(code=code, cache=True, rmax=Nranges)
1505 #print ("code shape", code.shape)
1509 #print ("code shape", code.shape)
1506 #print ("seed",seed)
1510 #print ("seed",seed)
1507 #print ("Code", code[0:10])
1511 #print ("Code", code[0:10])
1508 self.B = r['B']
1512 self.B = r['B']
1509
1513
1510
1514
1511 def run (self,dataOut,length_code= 10000,seed= 0,Nranges= 1000,oversample=1):
1515 def run (self,dataOut,length_code= 10000,seed= 0,Nranges= 1000,oversample=1):
1512 #print((dataOut.data.shape))
1516 #print((dataOut.data.shape))
1513 if not self.isConfig:
1517 if not self.isConfig:
1514 self.setup(clen= length_code,seed= seed,Nranges= Nranges,oversample=oversample)
1518 self.setup(clen= length_code,seed= seed,Nranges= Nranges,oversample=oversample)
1515 self.isConfig = True
1519 self.isConfig = True
1516
1520
1517 dataOut.flagNoData = True
1521 dataOut.flagNoData = True
1518 data =dataOut.data
1522 data =dataOut.data
1519 #print "length_CODE",length_code
1523 #print "length_CODE",length_code
1520 data_shape = (data.shape[1])
1524 data_shape = (data.shape[1])
1521 #print "data_shape",data_shape
1525 #print "data_shape",data_shape
1522 n = (length_code /data_shape)
1526 n = (length_code /data_shape)
1523 #print "we need this number of sample",n
1527 #print "we need this number of sample",n
1524
1528
1525 if n>0 and self.buffer is None:
1529 if n>0 and self.buffer is None:
1526 self.buffer = numpy.zeros([1, length_code], dtype=numpy.complex64)
1530 self.buffer = numpy.zeros([1, length_code], dtype=numpy.complex64)
1527 self.buffer[0][0:data_shape] = data[0]
1531 self.buffer[0][0:data_shape] = data[0]
1528 #print "FIRST CREATION",self.buffer.shape
1532 #print "FIRST CREATION",self.buffer.shape
1529
1533
1530 else:
1534 else:
1531 self.buffer[0][self.nProfiles*data_shape:(self.nProfiles+1)*data_shape]=data[0]
1535 self.buffer[0][self.nProfiles*data_shape:(self.nProfiles+1)*data_shape]=data[0]
1532
1536
1533 #print "buffer_shape",(self.buffer.shape)
1537 #print "buffer_shape",(self.buffer.shape)
1534 self.nProfiles += 1
1538 self.nProfiles += 1
1535 #print "count",self.nProfiles
1539 #print "count",self.nProfiles
1536
1540
1537 if self.nProfiles== n:
1541 if self.nProfiles== n:
1538 temporal = numpy.dot(self.B, numpy.transpose(self.buffer))
1542 temporal = numpy.dot(self.B, numpy.transpose(self.buffer))
1539 #print temporal.shape
1543 #print temporal.shape
1540 #import time
1544 #import time
1541 #time.sleep(40)
1545 #time.sleep(40)
1542 dataOut.data=numpy.transpose(temporal)
1546 dataOut.data=numpy.transpose(temporal)
1543
1547
1544 dataOut.flagNoData = False
1548 dataOut.flagNoData = False
1545 self.buffer= None
1549 self.buffer= None
1546 self.nProfiles = 0
1550 self.nProfiles = 0
1547
1551
1548 # import collections
1552 # import collections
1549 # from scipy.stats import mode
1553 # from scipy.stats import mode
1550 #
1554 #
1551 # class Synchronize(Operation):
1555 # class Synchronize(Operation):
1552 #
1556 #
1553 # isConfig = False
1557 # isConfig = False
1554 # __profIndex = 0
1558 # __profIndex = 0
1555 #
1559 #
1556 # def __init__(self, **kwargs):
1560 # def __init__(self, **kwargs):
1557 #
1561 #
1558 # Operation.__init__(self, **kwargs)
1562 # Operation.__init__(self, **kwargs)
1559 # # self.isConfig = False
1563 # # self.isConfig = False
1560 # self.__powBuffer = None
1564 # self.__powBuffer = None
1561 # self.__startIndex = 0
1565 # self.__startIndex = 0
1562 # self.__pulseFound = False
1566 # self.__pulseFound = False
1563 #
1567 #
1564 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1568 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1565 #
1569 #
1566 # #Read data
1570 # #Read data
1567 #
1571 #
1568 # powerdB = dataOut.getPower(channel = channel)
1572 # powerdB = dataOut.getPower(channel = channel)
1569 # noisedB = dataOut.getNoise(channel = channel)[0]
1573 # noisedB = dataOut.getNoise(channel = channel)[0]
1570 #
1574 #
1571 # self.__powBuffer.extend(powerdB.flatten())
1575 # self.__powBuffer.extend(powerdB.flatten())
1572 #
1576 #
1573 # dataArray = numpy.array(self.__powBuffer)
1577 # dataArray = numpy.array(self.__powBuffer)
1574 #
1578 #
1575 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1579 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1576 #
1580 #
1577 # maxValue = numpy.nanmax(filteredPower)
1581 # maxValue = numpy.nanmax(filteredPower)
1578 #
1582 #
1579 # if maxValue < noisedB + 10:
1583 # if maxValue < noisedB + 10:
1580 # #No se encuentra ningun pulso de transmision
1584 # #No se encuentra ningun pulso de transmision
1581 # return None
1585 # return None
1582 #
1586 #
1583 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1587 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1584 #
1588 #
1585 # if len(maxValuesIndex) < 2:
1589 # if len(maxValuesIndex) < 2:
1586 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1590 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1587 # return None
1591 # return None
1588 #
1592 #
1589 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1593 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1590 #
1594 #
1591 # #Seleccionar solo valores con un espaciamiento de nSamples
1595 # #Seleccionar solo valores con un espaciamiento de nSamples
1592 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1596 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1593 #
1597 #
1594 # if len(pulseIndex) < 2:
1598 # if len(pulseIndex) < 2:
1595 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1599 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1596 # return None
1600 # return None
1597 #
1601 #
1598 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1602 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1599 #
1603 #
1600 # #remover senales que se distancien menos de 10 unidades o muestras
1604 # #remover senales que se distancien menos de 10 unidades o muestras
1601 # #(No deberian existir IPP menor a 10 unidades)
1605 # #(No deberian existir IPP menor a 10 unidades)
1602 #
1606 #
1603 # realIndex = numpy.where(spacing > 10 )[0]
1607 # realIndex = numpy.where(spacing > 10 )[0]
1604 #
1608 #
1605 # if len(realIndex) < 2:
1609 # if len(realIndex) < 2:
1606 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1610 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1607 # return None
1611 # return None
1608 #
1612 #
1609 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1613 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1610 # realPulseIndex = pulseIndex[realIndex]
1614 # realPulseIndex = pulseIndex[realIndex]
1611 #
1615 #
1612 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1616 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1613 #
1617 #
1614 # print "IPP = %d samples" %period
1618 # print "IPP = %d samples" %period
1615 #
1619 #
1616 # self.__newNSamples = dataOut.nHeights #int(period)
1620 # self.__newNSamples = dataOut.nHeights #int(period)
1617 # self.__startIndex = int(realPulseIndex[0])
1621 # self.__startIndex = int(realPulseIndex[0])
1618 #
1622 #
1619 # return 1
1623 # return 1
1620 #
1624 #
1621 #
1625 #
1622 # def setup(self, nSamples, nChannels, buffer_size = 4):
1626 # def setup(self, nSamples, nChannels, buffer_size = 4):
1623 #
1627 #
1624 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1628 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1625 # maxlen = buffer_size*nSamples)
1629 # maxlen = buffer_size*nSamples)
1626 #
1630 #
1627 # bufferList = []
1631 # bufferList = []
1628 #
1632 #
1629 # for i in range(nChannels):
1633 # for i in range(nChannels):
1630 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1634 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1631 # maxlen = buffer_size*nSamples)
1635 # maxlen = buffer_size*nSamples)
1632 #
1636 #
1633 # bufferList.append(bufferByChannel)
1637 # bufferList.append(bufferByChannel)
1634 #
1638 #
1635 # self.__nSamples = nSamples
1639 # self.__nSamples = nSamples
1636 # self.__nChannels = nChannels
1640 # self.__nChannels = nChannels
1637 # self.__bufferList = bufferList
1641 # self.__bufferList = bufferList
1638 #
1642 #
1639 # def run(self, dataOut, channel = 0):
1643 # def run(self, dataOut, channel = 0):
1640 #
1644 #
1641 # if not self.isConfig:
1645 # if not self.isConfig:
1642 # nSamples = dataOut.nHeights
1646 # nSamples = dataOut.nHeights
1643 # nChannels = dataOut.nChannels
1647 # nChannels = dataOut.nChannels
1644 # self.setup(nSamples, nChannels)
1648 # self.setup(nSamples, nChannels)
1645 # self.isConfig = True
1649 # self.isConfig = True
1646 #
1650 #
1647 # #Append new data to internal buffer
1651 # #Append new data to internal buffer
1648 # for thisChannel in range(self.__nChannels):
1652 # for thisChannel in range(self.__nChannels):
1649 # bufferByChannel = self.__bufferList[thisChannel]
1653 # bufferByChannel = self.__bufferList[thisChannel]
1650 # bufferByChannel.extend(dataOut.data[thisChannel])
1654 # bufferByChannel.extend(dataOut.data[thisChannel])
1651 #
1655 #
1652 # if self.__pulseFound:
1656 # if self.__pulseFound:
1653 # self.__startIndex -= self.__nSamples
1657 # self.__startIndex -= self.__nSamples
1654 #
1658 #
1655 # #Finding Tx Pulse
1659 # #Finding Tx Pulse
1656 # if not self.__pulseFound:
1660 # if not self.__pulseFound:
1657 # indexFound = self.__findTxPulse(dataOut, channel)
1661 # indexFound = self.__findTxPulse(dataOut, channel)
1658 #
1662 #
1659 # if indexFound == None:
1663 # if indexFound == None:
1660 # dataOut.flagNoData = True
1664 # dataOut.flagNoData = True
1661 # return
1665 # return
1662 #
1666 #
1663 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1667 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1664 # self.__pulseFound = True
1668 # self.__pulseFound = True
1665 # self.__startIndex = indexFound
1669 # self.__startIndex = indexFound
1666 #
1670 #
1667 # #If pulse was found ...
1671 # #If pulse was found ...
1668 # for thisChannel in range(self.__nChannels):
1672 # for thisChannel in range(self.__nChannels):
1669 # bufferByChannel = self.__bufferList[thisChannel]
1673 # bufferByChannel = self.__bufferList[thisChannel]
1670 # #print self.__startIndex
1674 # #print self.__startIndex
1671 # x = numpy.array(bufferByChannel)
1675 # x = numpy.array(bufferByChannel)
1672 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1676 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1673 #
1677 #
1674 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1678 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1675 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1679 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1676 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1680 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1677 #
1681 #
1678 # dataOut.data = self.__arrayBuffer
1682 # dataOut.data = self.__arrayBuffer
1679 #
1683 #
1680 # self.__startIndex += self.__newNSamples
1684 # self.__startIndex += self.__newNSamples
1681 #
1685 #
1682 # return
1686 # return
General Comments 0
You need to be logged in to leave comments. Login now