##// END OF EJS Templates
fix typo :(
Juan C. Espinoza -
r1178:b6f37e899fd6
parent child
Show More
@@ -1,1330 +1,1330
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.model.proc.jroproc_base import ProcessingUnit,, Operation
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage
5 from schainpy.model.data.jrodata import Voltage
6 from schainpy.utils import log
6 from schainpy.utils import log
7 from time import time
7 from time import time
8
8
9
9
10 @MPDecorator
10 @MPDecorator
11 class VoltageProc(ProcessingUnit):
11 class VoltageProc(ProcessingUnit):
12
12
13 def __init__(self):
13 def __init__(self):
14
14
15 ProcessingUnit.__init__(self)
15 ProcessingUnit.__init__(self)
16
16
17 self.dataOut = Voltage()
17 self.dataOut = Voltage()
18 self.flip = 1
18 self.flip = 1
19 self.setupReq = False
19 self.setupReq = False
20
20
21 def run(self):
21 def run(self):
22
22
23 if self.dataIn.type == 'AMISR':
23 if self.dataIn.type == 'AMISR':
24 self.__updateObjFromAmisrInput()
24 self.__updateObjFromAmisrInput()
25
25
26 if self.dataIn.type == 'Voltage':
26 if self.dataIn.type == 'Voltage':
27 self.dataOut.copy(self.dataIn)
27 self.dataOut.copy(self.dataIn)
28
28
29 # self.dataOut.copy(self.dataIn)
29 # self.dataOut.copy(self.dataIn)
30
30
31 def __updateObjFromAmisrInput(self):
31 def __updateObjFromAmisrInput(self):
32
32
33 self.dataOut.timeZone = self.dataIn.timeZone
33 self.dataOut.timeZone = self.dataIn.timeZone
34 self.dataOut.dstFlag = self.dataIn.dstFlag
34 self.dataOut.dstFlag = self.dataIn.dstFlag
35 self.dataOut.errorCount = self.dataIn.errorCount
35 self.dataOut.errorCount = self.dataIn.errorCount
36 self.dataOut.useLocalTime = self.dataIn.useLocalTime
36 self.dataOut.useLocalTime = self.dataIn.useLocalTime
37
37
38 self.dataOut.flagNoData = self.dataIn.flagNoData
38 self.dataOut.flagNoData = self.dataIn.flagNoData
39 self.dataOut.data = self.dataIn.data
39 self.dataOut.data = self.dataIn.data
40 self.dataOut.utctime = self.dataIn.utctime
40 self.dataOut.utctime = self.dataIn.utctime
41 self.dataOut.channelList = self.dataIn.channelList
41 self.dataOut.channelList = self.dataIn.channelList
42 # self.dataOut.timeInterval = self.dataIn.timeInterval
42 # self.dataOut.timeInterval = self.dataIn.timeInterval
43 self.dataOut.heightList = self.dataIn.heightList
43 self.dataOut.heightList = self.dataIn.heightList
44 self.dataOut.nProfiles = self.dataIn.nProfiles
44 self.dataOut.nProfiles = self.dataIn.nProfiles
45
45
46 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.nCohInt = self.dataIn.nCohInt
47 self.dataOut.ippSeconds = self.dataIn.ippSeconds
47 self.dataOut.ippSeconds = self.dataIn.ippSeconds
48 self.dataOut.frequency = self.dataIn.frequency
48 self.dataOut.frequency = self.dataIn.frequency
49
49
50 self.dataOut.azimuth = self.dataIn.azimuth
50 self.dataOut.azimuth = self.dataIn.azimuth
51 self.dataOut.zenith = self.dataIn.zenith
51 self.dataOut.zenith = self.dataIn.zenith
52
52
53 self.dataOut.beam.codeList = self.dataIn.beam.codeList
53 self.dataOut.beam.codeList = self.dataIn.beam.codeList
54 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
54 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
55 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
55 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
56 #
56 #
57 # pass#
57 # pass#
58 #
58 #
59 # def init(self):
59 # def init(self):
60 #
60 #
61 #
61 #
62 # if self.dataIn.type == 'AMISR':
62 # if self.dataIn.type == 'AMISR':
63 # self.__updateObjFromAmisrInput()
63 # self.__updateObjFromAmisrInput()
64 #
64 #
65 # if self.dataIn.type == 'Voltage':
65 # if self.dataIn.type == 'Voltage':
66 # self.dataOut.copy(self.dataIn)
66 # self.dataOut.copy(self.dataIn)
67 # # No necesita copiar en cada init() los atributos de dataIn
67 # # No necesita copiar en cada init() los atributos de dataIn
68 # # la copia deberia hacerse por cada nuevo bloque de datos
68 # # la copia deberia hacerse por cada nuevo bloque de datos
69
69
70 def selectChannels(self, channelList):
70 def selectChannels(self, channelList):
71
71
72 channelIndexList = []
72 channelIndexList = []
73
73
74 for channel in channelList:
74 for channel in channelList:
75 if channel not in self.dataOut.channelList:
75 if channel not in self.dataOut.channelList:
76 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
76 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
77
77
78 index = self.dataOut.channelList.index(channel)
78 index = self.dataOut.channelList.index(channel)
79 channelIndexList.append(index)
79 channelIndexList.append(index)
80
80
81 self.selectChannelsByIndex(channelIndexList)
81 self.selectChannelsByIndex(channelIndexList)
82
82
83 def selectChannelsByIndex(self, channelIndexList):
83 def selectChannelsByIndex(self, channelIndexList):
84 """
84 """
85 Selecciona un bloque de datos en base a canales segun el channelIndexList
85 Selecciona un bloque de datos en base a canales segun el channelIndexList
86
86
87 Input:
87 Input:
88 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
88 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
89
89
90 Affected:
90 Affected:
91 self.dataOut.data
91 self.dataOut.data
92 self.dataOut.channelIndexList
92 self.dataOut.channelIndexList
93 self.dataOut.nChannels
93 self.dataOut.nChannels
94 self.dataOut.m_ProcessingHeader.totalSpectra
94 self.dataOut.m_ProcessingHeader.totalSpectra
95 self.dataOut.systemHeaderObj.numChannels
95 self.dataOut.systemHeaderObj.numChannels
96 self.dataOut.m_ProcessingHeader.blockSize
96 self.dataOut.m_ProcessingHeader.blockSize
97
97
98 Return:
98 Return:
99 None
99 None
100 """
100 """
101
101
102 for channelIndex in channelIndexList:
102 for channelIndex in channelIndexList:
103 if channelIndex not in self.dataOut.channelIndexList:
103 if channelIndex not in self.dataOut.channelIndexList:
104 print(channelIndexList)
104 print(channelIndexList)
105 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
105 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
106
106
107 if self.dataOut.flagDataAsBlock:
107 if self.dataOut.flagDataAsBlock:
108 """
108 """
109 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
109 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
110 """
110 """
111 data = self.dataOut.data[channelIndexList,:,:]
111 data = self.dataOut.data[channelIndexList,:,:]
112 else:
112 else:
113 data = self.dataOut.data[channelIndexList,:]
113 data = self.dataOut.data[channelIndexList,:]
114
114
115 self.dataOut.data = data
115 self.dataOut.data = data
116 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
116 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
117 # self.dataOut.nChannels = nChannels
117 # self.dataOut.nChannels = nChannels
118
118
119 return 1
119 return 1
120
120
121 def selectHeights(self, minHei=None, maxHei=None):
121 def selectHeights(self, minHei=None, maxHei=None):
122 """
122 """
123 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
123 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
124 minHei <= height <= maxHei
124 minHei <= height <= maxHei
125
125
126 Input:
126 Input:
127 minHei : valor minimo de altura a considerar
127 minHei : valor minimo de altura a considerar
128 maxHei : valor maximo de altura a considerar
128 maxHei : valor maximo de altura a considerar
129
129
130 Affected:
130 Affected:
131 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
131 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
132
132
133 Return:
133 Return:
134 1 si el metodo se ejecuto con exito caso contrario devuelve 0
134 1 si el metodo se ejecuto con exito caso contrario devuelve 0
135 """
135 """
136
136
137 if minHei == None:
137 if minHei == None:
138 minHei = self.dataOut.heightList[0]
138 minHei = self.dataOut.heightList[0]
139
139
140 if maxHei == None:
140 if maxHei == None:
141 maxHei = self.dataOut.heightList[-1]
141 maxHei = self.dataOut.heightList[-1]
142
142
143 if (minHei < self.dataOut.heightList[0]):
143 if (minHei < self.dataOut.heightList[0]):
144 minHei = self.dataOut.heightList[0]
144 minHei = self.dataOut.heightList[0]
145
145
146 if (maxHei > self.dataOut.heightList[-1]):
146 if (maxHei > self.dataOut.heightList[-1]):
147 maxHei = self.dataOut.heightList[-1]
147 maxHei = self.dataOut.heightList[-1]
148
148
149 minIndex = 0
149 minIndex = 0
150 maxIndex = 0
150 maxIndex = 0
151 heights = self.dataOut.heightList
151 heights = self.dataOut.heightList
152
152
153 inda = numpy.where(heights >= minHei)
153 inda = numpy.where(heights >= minHei)
154 indb = numpy.where(heights <= maxHei)
154 indb = numpy.where(heights <= maxHei)
155
155
156 try:
156 try:
157 minIndex = inda[0][0]
157 minIndex = inda[0][0]
158 except:
158 except:
159 minIndex = 0
159 minIndex = 0
160
160
161 try:
161 try:
162 maxIndex = indb[0][-1]
162 maxIndex = indb[0][-1]
163 except:
163 except:
164 maxIndex = len(heights)
164 maxIndex = len(heights)
165
165
166 self.selectHeightsByIndex(minIndex, maxIndex)
166 self.selectHeightsByIndex(minIndex, maxIndex)
167
167
168 return 1
168 return 1
169
169
170
170
171 def selectHeightsByIndex(self, minIndex, maxIndex):
171 def selectHeightsByIndex(self, minIndex, maxIndex):
172 """
172 """
173 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
173 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
174 minIndex <= index <= maxIndex
174 minIndex <= index <= maxIndex
175
175
176 Input:
176 Input:
177 minIndex : valor de indice minimo de altura a considerar
177 minIndex : valor de indice minimo de altura a considerar
178 maxIndex : valor de indice maximo de altura a considerar
178 maxIndex : valor de indice maximo de altura a considerar
179
179
180 Affected:
180 Affected:
181 self.dataOut.data
181 self.dataOut.data
182 self.dataOut.heightList
182 self.dataOut.heightList
183
183
184 Return:
184 Return:
185 1 si el metodo se ejecuto con exito caso contrario devuelve 0
185 1 si el metodo se ejecuto con exito caso contrario devuelve 0
186 """
186 """
187
187
188 if (minIndex < 0) or (minIndex > maxIndex):
188 if (minIndex < 0) or (minIndex > maxIndex):
189 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
189 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
190
190
191 if (maxIndex >= self.dataOut.nHeights):
191 if (maxIndex >= self.dataOut.nHeights):
192 maxIndex = self.dataOut.nHeights
192 maxIndex = self.dataOut.nHeights
193
193
194 #voltage
194 #voltage
195 if self.dataOut.flagDataAsBlock:
195 if self.dataOut.flagDataAsBlock:
196 """
196 """
197 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
197 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
198 """
198 """
199 data = self.dataOut.data[:,:, minIndex:maxIndex]
199 data = self.dataOut.data[:,:, minIndex:maxIndex]
200 else:
200 else:
201 data = self.dataOut.data[:, minIndex:maxIndex]
201 data = self.dataOut.data[:, minIndex:maxIndex]
202
202
203 # firstHeight = self.dataOut.heightList[minIndex]
203 # firstHeight = self.dataOut.heightList[minIndex]
204
204
205 self.dataOut.data = data
205 self.dataOut.data = data
206 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
206 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
207
207
208 if self.dataOut.nHeights <= 1:
208 if self.dataOut.nHeights <= 1:
209 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
209 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
210
210
211 return 1
211 return 1
212
212
213
213
214 def filterByHeights(self, window):
214 def filterByHeights(self, window):
215
215
216 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
216 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
217
217
218 if window == None:
218 if window == None:
219 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
219 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
220
220
221 newdelta = deltaHeight * window
221 newdelta = deltaHeight * window
222 r = self.dataOut.nHeights % window
222 r = self.dataOut.nHeights % window
223 newheights = (self.dataOut.nHeights-r)/window
223 newheights = (self.dataOut.nHeights-r)/window
224
224
225 if newheights <= 1:
225 if newheights <= 1:
226 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window))
226 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window))
227
227
228 if self.dataOut.flagDataAsBlock:
228 if self.dataOut.flagDataAsBlock:
229 """
229 """
230 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
230 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
231 """
231 """
232 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
232 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
233 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
233 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
234 buffer = numpy.sum(buffer,3)
234 buffer = numpy.sum(buffer,3)
235
235
236 else:
236 else:
237 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
237 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
238 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
238 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
239 buffer = numpy.sum(buffer,2)
239 buffer = numpy.sum(buffer,2)
240
240
241 self.dataOut.data = buffer
241 self.dataOut.data = buffer
242 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
242 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
243 self.dataOut.windowOfFilter = window
243 self.dataOut.windowOfFilter = window
244
244
245 def setH0(self, h0, deltaHeight = None):
245 def setH0(self, h0, deltaHeight = None):
246
246
247 if not deltaHeight:
247 if not deltaHeight:
248 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
248 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
249
249
250 nHeights = self.dataOut.nHeights
250 nHeights = self.dataOut.nHeights
251
251
252 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
252 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
253
253
254 self.dataOut.heightList = newHeiRange
254 self.dataOut.heightList = newHeiRange
255
255
256 def deFlip(self, channelList = []):
256 def deFlip(self, channelList = []):
257
257
258 data = self.dataOut.data.copy()
258 data = self.dataOut.data.copy()
259
259
260 if self.dataOut.flagDataAsBlock:
260 if self.dataOut.flagDataAsBlock:
261 flip = self.flip
261 flip = self.flip
262 profileList = list(range(self.dataOut.nProfiles))
262 profileList = list(range(self.dataOut.nProfiles))
263
263
264 if not channelList:
264 if not channelList:
265 for thisProfile in profileList:
265 for thisProfile in profileList:
266 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
266 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
267 flip *= -1.0
267 flip *= -1.0
268 else:
268 else:
269 for thisChannel in channelList:
269 for thisChannel in channelList:
270 if thisChannel not in self.dataOut.channelList:
270 if thisChannel not in self.dataOut.channelList:
271 continue
271 continue
272
272
273 for thisProfile in profileList:
273 for thisProfile in profileList:
274 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
274 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
275 flip *= -1.0
275 flip *= -1.0
276
276
277 self.flip = flip
277 self.flip = flip
278
278
279 else:
279 else:
280 if not channelList:
280 if not channelList:
281 data[:,:] = data[:,:]*self.flip
281 data[:,:] = data[:,:]*self.flip
282 else:
282 else:
283 for thisChannel in channelList:
283 for thisChannel in channelList:
284 if thisChannel not in self.dataOut.channelList:
284 if thisChannel not in self.dataOut.channelList:
285 continue
285 continue
286
286
287 data[thisChannel,:] = data[thisChannel,:]*self.flip
287 data[thisChannel,:] = data[thisChannel,:]*self.flip
288
288
289 self.flip *= -1.
289 self.flip *= -1.
290
290
291 self.dataOut.data = data
291 self.dataOut.data = data
292
292
293 def setRadarFrequency(self, frequency=None):
293 def setRadarFrequency(self, frequency=None):
294
294
295 if frequency != None:
295 if frequency != None:
296 self.dataOut.frequency = frequency
296 self.dataOut.frequency = frequency
297
297
298 return 1
298 return 1
299
299
300 def interpolateHeights(self, topLim, botLim):
300 def interpolateHeights(self, topLim, botLim):
301 #69 al 72 para julia
301 #69 al 72 para julia
302 #82-84 para meteoros
302 #82-84 para meteoros
303 if len(numpy.shape(self.dataOut.data))==2:
303 if len(numpy.shape(self.dataOut.data))==2:
304 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
304 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
305 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
305 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
306 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
306 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
307 self.dataOut.data[:,botLim:topLim+1] = sampInterp
307 self.dataOut.data[:,botLim:topLim+1] = sampInterp
308 else:
308 else:
309 nHeights = self.dataOut.data.shape[2]
309 nHeights = self.dataOut.data.shape[2]
310 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
310 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
311 y = self.dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
311 y = self.dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
312 f = interpolate.interp1d(x, y, axis = 2)
312 f = interpolate.interp1d(x, y, axis = 2)
313 xnew = numpy.arange(botLim,topLim+1)
313 xnew = numpy.arange(botLim,topLim+1)
314 ynew = f(xnew)
314 ynew = f(xnew)
315
315
316 self.dataOut.data[:,:,botLim:topLim+1] = ynew
316 self.dataOut.data[:,:,botLim:topLim+1] = ynew
317
317
318 # import collections
318 # import collections
319
319
320 class CohInt(Operation):
320 class CohInt(Operation):
321
321
322 isConfig = False
322 isConfig = False
323 __profIndex = 0
323 __profIndex = 0
324 __byTime = False
324 __byTime = False
325 __initime = None
325 __initime = None
326 __lastdatatime = None
326 __lastdatatime = None
327 __integrationtime = None
327 __integrationtime = None
328 __buffer = None
328 __buffer = None
329 __bufferStride = []
329 __bufferStride = []
330 __dataReady = False
330 __dataReady = False
331 __profIndexStride = 0
331 __profIndexStride = 0
332 __dataToPutStride = False
332 __dataToPutStride = False
333 n = None
333 n = None
334
334
335 def __init__(self):#, **kwargs):
335 def __init__(self):#, **kwargs):
336
336
337 Operation.__init__(self)#, **kwargs)
337 Operation.__init__(self)#, **kwargs)
338
338
339 # self.isConfig = False
339 # self.isConfig = False
340
340
341 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
341 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
342 """
342 """
343 Set the parameters of the integration class.
343 Set the parameters of the integration class.
344
344
345 Inputs:
345 Inputs:
346
346
347 n : Number of coherent integrations
347 n : Number of coherent integrations
348 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
348 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
349 overlapping :
349 overlapping :
350 """
350 """
351
351
352 self.__initime = None
352 self.__initime = None
353 self.__lastdatatime = 0
353 self.__lastdatatime = 0
354 self.__buffer = None
354 self.__buffer = None
355 self.__dataReady = False
355 self.__dataReady = False
356 self.byblock = byblock
356 self.byblock = byblock
357 self.stride = stride
357 self.stride = stride
358
358
359 if n == None and timeInterval == None:
359 if n == None and timeInterval == None:
360 raise ValueError("n or timeInterval should be specified ...")
360 raise ValueError("n or timeInterval should be specified ...")
361
361
362 if n != None:
362 if n != None:
363 self.n = n
363 self.n = n
364 self.__byTime = False
364 self.__byTime = False
365 else:
365 else:
366 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
366 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
367 self.n = 9999
367 self.n = 9999
368 self.__byTime = True
368 self.__byTime = True
369
369
370 if overlapping:
370 if overlapping:
371 self.__withOverlapping = True
371 self.__withOverlapping = True
372 self.__buffer = None
372 self.__buffer = None
373 else:
373 else:
374 self.__withOverlapping = False
374 self.__withOverlapping = False
375 self.__buffer = 0
375 self.__buffer = 0
376
376
377 self.__profIndex = 0
377 self.__profIndex = 0
378
378
379 def putData(self, data):
379 def putData(self, data):
380
380
381 """
381 """
382 Add a profile to the __buffer and increase in one the __profileIndex
382 Add a profile to the __buffer and increase in one the __profileIndex
383
383
384 """
384 """
385
385
386 if not self.__withOverlapping:
386 if not self.__withOverlapping:
387 self.__buffer += data.copy()
387 self.__buffer += data.copy()
388 self.__profIndex += 1
388 self.__profIndex += 1
389 return
389 return
390
390
391 #Overlapping data
391 #Overlapping data
392 nChannels, nHeis = data.shape
392 nChannels, nHeis = data.shape
393 data = numpy.reshape(data, (1, nChannels, nHeis))
393 data = numpy.reshape(data, (1, nChannels, nHeis))
394
394
395 #If the buffer is empty then it takes the data value
395 #If the buffer is empty then it takes the data value
396 if self.__buffer is None:
396 if self.__buffer is None:
397 self.__buffer = data
397 self.__buffer = data
398 self.__profIndex += 1
398 self.__profIndex += 1
399 return
399 return
400
400
401 #If the buffer length is lower than n then stakcing the data value
401 #If the buffer length is lower than n then stakcing the data value
402 if self.__profIndex < self.n:
402 if self.__profIndex < self.n:
403 self.__buffer = numpy.vstack((self.__buffer, data))
403 self.__buffer = numpy.vstack((self.__buffer, data))
404 self.__profIndex += 1
404 self.__profIndex += 1
405 return
405 return
406
406
407 #If the buffer length is equal to n then replacing the last buffer value with the data value
407 #If the buffer length is equal to n then replacing the last buffer value with the data value
408 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
408 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
409 self.__buffer[self.n-1] = data
409 self.__buffer[self.n-1] = data
410 self.__profIndex = self.n
410 self.__profIndex = self.n
411 return
411 return
412
412
413
413
414 def pushData(self):
414 def pushData(self):
415 """
415 """
416 Return the sum of the last profiles and the profiles used in the sum.
416 Return the sum of the last profiles and the profiles used in the sum.
417
417
418 Affected:
418 Affected:
419
419
420 self.__profileIndex
420 self.__profileIndex
421
421
422 """
422 """
423
423
424 if not self.__withOverlapping:
424 if not self.__withOverlapping:
425 data = self.__buffer
425 data = self.__buffer
426 n = self.__profIndex
426 n = self.__profIndex
427
427
428 self.__buffer = 0
428 self.__buffer = 0
429 self.__profIndex = 0
429 self.__profIndex = 0
430
430
431 return data, n
431 return data, n
432
432
433 #Integration with Overlapping
433 #Integration with Overlapping
434 data = numpy.sum(self.__buffer, axis=0)
434 data = numpy.sum(self.__buffer, axis=0)
435 # print data
435 # print data
436 # raise
436 # raise
437 n = self.__profIndex
437 n = self.__profIndex
438
438
439 return data, n
439 return data, n
440
440
441 def byProfiles(self, data):
441 def byProfiles(self, data):
442
442
443 self.__dataReady = False
443 self.__dataReady = False
444 avgdata = None
444 avgdata = None
445 # n = None
445 # n = None
446 # print data
446 # print data
447 # raise
447 # raise
448 self.putData(data)
448 self.putData(data)
449
449
450 if self.__profIndex == self.n:
450 if self.__profIndex == self.n:
451 avgdata, n = self.pushData()
451 avgdata, n = self.pushData()
452 self.__dataReady = True
452 self.__dataReady = True
453
453
454 return avgdata
454 return avgdata
455
455
456 def byTime(self, data, datatime):
456 def byTime(self, data, datatime):
457
457
458 self.__dataReady = False
458 self.__dataReady = False
459 avgdata = None
459 avgdata = None
460 n = None
460 n = None
461
461
462 self.putData(data)
462 self.putData(data)
463
463
464 if (datatime - self.__initime) >= self.__integrationtime:
464 if (datatime - self.__initime) >= self.__integrationtime:
465 avgdata, n = self.pushData()
465 avgdata, n = self.pushData()
466 self.n = n
466 self.n = n
467 self.__dataReady = True
467 self.__dataReady = True
468
468
469 return avgdata
469 return avgdata
470
470
471 def integrateByStride(self, data, datatime):
471 def integrateByStride(self, data, datatime):
472 # print data
472 # print data
473 if self.__profIndex == 0:
473 if self.__profIndex == 0:
474 self.__buffer = [[data.copy(), datatime]]
474 self.__buffer = [[data.copy(), datatime]]
475 else:
475 else:
476 self.__buffer.append([data.copy(),datatime])
476 self.__buffer.append([data.copy(),datatime])
477 self.__profIndex += 1
477 self.__profIndex += 1
478 self.__dataReady = False
478 self.__dataReady = False
479
479
480 if self.__profIndex == self.n * self.stride :
480 if self.__profIndex == self.n * self.stride :
481 self.__dataToPutStride = True
481 self.__dataToPutStride = True
482 self.__profIndexStride = 0
482 self.__profIndexStride = 0
483 self.__profIndex = 0
483 self.__profIndex = 0
484 self.__bufferStride = []
484 self.__bufferStride = []
485 for i in range(self.stride):
485 for i in range(self.stride):
486 current = self.__buffer[i::self.stride]
486 current = self.__buffer[i::self.stride]
487 data = numpy.sum([t[0] for t in current], axis=0)
487 data = numpy.sum([t[0] for t in current], axis=0)
488 avgdatatime = numpy.average([t[1] for t in current])
488 avgdatatime = numpy.average([t[1] for t in current])
489 # print data
489 # print data
490 self.__bufferStride.append((data, avgdatatime))
490 self.__bufferStride.append((data, avgdatatime))
491
491
492 if self.__dataToPutStride:
492 if self.__dataToPutStride:
493 self.__dataReady = True
493 self.__dataReady = True
494 self.__profIndexStride += 1
494 self.__profIndexStride += 1
495 if self.__profIndexStride == self.stride:
495 if self.__profIndexStride == self.stride:
496 self.__dataToPutStride = False
496 self.__dataToPutStride = False
497 # print self.__bufferStride[self.__profIndexStride - 1]
497 # print self.__bufferStride[self.__profIndexStride - 1]
498 # raise
498 # raise
499 return self.__bufferStride[self.__profIndexStride - 1]
499 return self.__bufferStride[self.__profIndexStride - 1]
500
500
501
501
502 return None, None
502 return None, None
503
503
504 def integrate(self, data, datatime=None):
504 def integrate(self, data, datatime=None):
505
505
506 if self.__initime == None:
506 if self.__initime == None:
507 self.__initime = datatime
507 self.__initime = datatime
508
508
509 if self.__byTime:
509 if self.__byTime:
510 avgdata = self.byTime(data, datatime)
510 avgdata = self.byTime(data, datatime)
511 else:
511 else:
512 avgdata = self.byProfiles(data)
512 avgdata = self.byProfiles(data)
513
513
514
514
515 self.__lastdatatime = datatime
515 self.__lastdatatime = datatime
516
516
517 if avgdata is None:
517 if avgdata is None:
518 return None, None
518 return None, None
519
519
520 avgdatatime = self.__initime
520 avgdatatime = self.__initime
521
521
522 deltatime = datatime - self.__lastdatatime
522 deltatime = datatime - self.__lastdatatime
523
523
524 if not self.__withOverlapping:
524 if not self.__withOverlapping:
525 self.__initime = datatime
525 self.__initime = datatime
526 else:
526 else:
527 self.__initime += deltatime
527 self.__initime += deltatime
528
528
529 return avgdata, avgdatatime
529 return avgdata, avgdatatime
530
530
531 def integrateByBlock(self, dataOut):
531 def integrateByBlock(self, dataOut):
532
532
533 times = int(dataOut.data.shape[1]/self.n)
533 times = int(dataOut.data.shape[1]/self.n)
534 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
534 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
535
535
536 id_min = 0
536 id_min = 0
537 id_max = self.n
537 id_max = self.n
538
538
539 for i in range(times):
539 for i in range(times):
540 junk = dataOut.data[:,id_min:id_max,:]
540 junk = dataOut.data[:,id_min:id_max,:]
541 avgdata[:,i,:] = junk.sum(axis=1)
541 avgdata[:,i,:] = junk.sum(axis=1)
542 id_min += self.n
542 id_min += self.n
543 id_max += self.n
543 id_max += self.n
544
544
545 timeInterval = dataOut.ippSeconds*self.n
545 timeInterval = dataOut.ippSeconds*self.n
546 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
546 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
547 self.__dataReady = True
547 self.__dataReady = True
548 return avgdata, avgdatatime
548 return avgdata, avgdatatime
549
549
550 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
550 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
551
551
552 if not self.isConfig:
552 if not self.isConfig:
553 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
553 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
554 self.isConfig = True
554 self.isConfig = True
555
555
556 if dataOut.flagDataAsBlock:
556 if dataOut.flagDataAsBlock:
557 """
557 """
558 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
558 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
559 """
559 """
560 avgdata, avgdatatime = self.integrateByBlock(dataOut)
560 avgdata, avgdatatime = self.integrateByBlock(dataOut)
561 dataOut.nProfiles /= self.n
561 dataOut.nProfiles /= self.n
562 else:
562 else:
563 if stride is None:
563 if stride is None:
564 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
564 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
565 else:
565 else:
566 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
566 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
567
567
568
568
569 # dataOut.timeInterval *= n
569 # dataOut.timeInterval *= n
570 dataOut.flagNoData = True
570 dataOut.flagNoData = True
571
571
572 if self.__dataReady:
572 if self.__dataReady:
573 dataOut.data = avgdata
573 dataOut.data = avgdata
574 dataOut.nCohInt *= self.n
574 dataOut.nCohInt *= self.n
575 dataOut.utctime = avgdatatime
575 dataOut.utctime = avgdatatime
576 # print avgdata, avgdatatime
576 # print avgdata, avgdatatime
577 # raise
577 # raise
578 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
578 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
579 dataOut.flagNoData = False
579 dataOut.flagNoData = False
580 return dataOut
580 return dataOut
581
581
582 class Decoder(Operation):
582 class Decoder(Operation):
583
583
584 isConfig = False
584 isConfig = False
585 __profIndex = 0
585 __profIndex = 0
586
586
587 code = None
587 code = None
588
588
589 nCode = None
589 nCode = None
590 nBaud = None
590 nBaud = None
591
591
592 def __init__(self):#, **kwargs):
592 def __init__(self):#, **kwargs):
593
593
594 Operation.__init__(self)#, **kwargs)
594 Operation.__init__(self)#, **kwargs)
595
595
596 self.times = None
596 self.times = None
597 self.osamp = None
597 self.osamp = None
598 # self.__setValues = False
598 # self.__setValues = False
599 # self.isConfig = False
599 # self.isConfig = False
600 self.setupReq = False
600 self.setupReq = False
601 def setup(self, code, osamp, dataOut):
601 def setup(self, code, osamp, dataOut):
602
602
603 self.__profIndex = 0
603 self.__profIndex = 0
604
604
605 self.code = code
605 self.code = code
606
606
607 self.nCode = len(code)
607 self.nCode = len(code)
608 self.nBaud = len(code[0])
608 self.nBaud = len(code[0])
609
609
610 if (osamp != None) and (osamp >1):
610 if (osamp != None) and (osamp >1):
611 self.osamp = osamp
611 self.osamp = osamp
612 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
612 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
613 self.nBaud = self.nBaud*self.osamp
613 self.nBaud = self.nBaud*self.osamp
614
614
615 self.__nChannels = dataOut.nChannels
615 self.__nChannels = dataOut.nChannels
616 self.__nProfiles = dataOut.nProfiles
616 self.__nProfiles = dataOut.nProfiles
617 self.__nHeis = dataOut.nHeights
617 self.__nHeis = dataOut.nHeights
618
618
619 if self.__nHeis < self.nBaud:
619 if self.__nHeis < self.nBaud:
620 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
620 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
621
621
622 #Frequency
622 #Frequency
623 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
623 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
624
624
625 __codeBuffer[:,0:self.nBaud] = self.code
625 __codeBuffer[:,0:self.nBaud] = self.code
626
626
627 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
627 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
628
628
629 if dataOut.flagDataAsBlock:
629 if dataOut.flagDataAsBlock:
630
630
631 self.ndatadec = self.__nHeis #- self.nBaud + 1
631 self.ndatadec = self.__nHeis #- self.nBaud + 1
632
632
633 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
633 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
634
634
635 else:
635 else:
636
636
637 #Time
637 #Time
638 self.ndatadec = self.__nHeis #- self.nBaud + 1
638 self.ndatadec = self.__nHeis #- self.nBaud + 1
639
639
640 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
640 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
641
641
642 def __convolutionInFreq(self, data):
642 def __convolutionInFreq(self, data):
643
643
644 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
644 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
645
645
646 fft_data = numpy.fft.fft(data, axis=1)
646 fft_data = numpy.fft.fft(data, axis=1)
647
647
648 conv = fft_data*fft_code
648 conv = fft_data*fft_code
649
649
650 data = numpy.fft.ifft(conv,axis=1)
650 data = numpy.fft.ifft(conv,axis=1)
651
651
652 return data
652 return data
653
653
654 def __convolutionInFreqOpt(self, data):
654 def __convolutionInFreqOpt(self, data):
655
655
656 raise NotImplementedError
656 raise NotImplementedError
657
657
658 def __convolutionInTime(self, data):
658 def __convolutionInTime(self, data):
659
659
660 code = self.code[self.__profIndex]
660 code = self.code[self.__profIndex]
661 for i in range(self.__nChannels):
661 for i in range(self.__nChannels):
662 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
662 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
663
663
664 return self.datadecTime
664 return self.datadecTime
665
665
666 def __convolutionByBlockInTime(self, data):
666 def __convolutionByBlockInTime(self, data):
667
667
668 repetitions = self.__nProfiles / self.nCode
668 repetitions = self.__nProfiles / self.nCode
669
669
670 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
670 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
671 junk = junk.flatten()
671 junk = junk.flatten()
672 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
672 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
673 profilesList = range(self.__nProfiles)
673 profilesList = range(self.__nProfiles)
674
674
675 for i in range(self.__nChannels):
675 for i in range(self.__nChannels):
676 for j in profilesList:
676 for j in profilesList:
677 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
677 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
678 return self.datadecTime
678 return self.datadecTime
679
679
680 def __convolutionByBlockInFreq(self, data):
680 def __convolutionByBlockInFreq(self, data):
681
681
682 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
682 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
683
683
684
684
685 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
685 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
686
686
687 fft_data = numpy.fft.fft(data, axis=2)
687 fft_data = numpy.fft.fft(data, axis=2)
688
688
689 conv = fft_data*fft_code
689 conv = fft_data*fft_code
690
690
691 data = numpy.fft.ifft(conv,axis=2)
691 data = numpy.fft.ifft(conv,axis=2)
692
692
693 return data
693 return data
694
694
695
695
696 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
696 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
697
697
698 if dataOut.flagDecodeData:
698 if dataOut.flagDecodeData:
699 print("This data is already decoded, recoding again ...")
699 print("This data is already decoded, recoding again ...")
700
700
701 if not self.isConfig:
701 if not self.isConfig:
702
702
703 if code is None:
703 if code is None:
704 if dataOut.code is None:
704 if dataOut.code is None:
705 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
705 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
706
706
707 code = dataOut.code
707 code = dataOut.code
708 else:
708 else:
709 code = numpy.array(code).reshape(nCode,nBaud)
709 code = numpy.array(code).reshape(nCode,nBaud)
710 self.setup(code, osamp, dataOut)
710 self.setup(code, osamp, dataOut)
711
711
712 self.isConfig = True
712 self.isConfig = True
713
713
714 if mode == 3:
714 if mode == 3:
715 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
715 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
716
716
717 if times != None:
717 if times != None:
718 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
718 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
719
719
720 if self.code is None:
720 if self.code is None:
721 print("Fail decoding: Code is not defined.")
721 print("Fail decoding: Code is not defined.")
722 return
722 return
723
723
724 self.__nProfiles = dataOut.nProfiles
724 self.__nProfiles = dataOut.nProfiles
725 datadec = None
725 datadec = None
726
726
727 if mode == 3:
727 if mode == 3:
728 mode = 0
728 mode = 0
729
729
730 if dataOut.flagDataAsBlock:
730 if dataOut.flagDataAsBlock:
731 """
731 """
732 Decoding when data have been read as block,
732 Decoding when data have been read as block,
733 """
733 """
734
734
735 if mode == 0:
735 if mode == 0:
736 datadec = self.__convolutionByBlockInTime(dataOut.data)
736 datadec = self.__convolutionByBlockInTime(dataOut.data)
737 if mode == 1:
737 if mode == 1:
738 datadec = self.__convolutionByBlockInFreq(dataOut.data)
738 datadec = self.__convolutionByBlockInFreq(dataOut.data)
739 else:
739 else:
740 """
740 """
741 Decoding when data have been read profile by profile
741 Decoding when data have been read profile by profile
742 """
742 """
743 if mode == 0:
743 if mode == 0:
744 datadec = self.__convolutionInTime(dataOut.data)
744 datadec = self.__convolutionInTime(dataOut.data)
745
745
746 if mode == 1:
746 if mode == 1:
747 datadec = self.__convolutionInFreq(dataOut.data)
747 datadec = self.__convolutionInFreq(dataOut.data)
748
748
749 if mode == 2:
749 if mode == 2:
750 datadec = self.__convolutionInFreqOpt(dataOut.data)
750 datadec = self.__convolutionInFreqOpt(dataOut.data)
751
751
752 if datadec is None:
752 if datadec is None:
753 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
753 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
754
754
755 dataOut.code = self.code
755 dataOut.code = self.code
756 dataOut.nCode = self.nCode
756 dataOut.nCode = self.nCode
757 dataOut.nBaud = self.nBaud
757 dataOut.nBaud = self.nBaud
758
758
759 dataOut.data = datadec
759 dataOut.data = datadec
760
760
761 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
761 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
762
762
763 dataOut.flagDecodeData = True #asumo q la data esta decodificada
763 dataOut.flagDecodeData = True #asumo q la data esta decodificada
764
764
765 if self.__profIndex == self.nCode-1:
765 if self.__profIndex == self.nCode-1:
766 self.__profIndex = 0
766 self.__profIndex = 0
767 return dataOut
767 return dataOut
768
768
769 self.__profIndex += 1
769 self.__profIndex += 1
770
770
771 return dataOut
771 return dataOut
772 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
772 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
773
773
774
774
775 class ProfileConcat(Operation):
775 class ProfileConcat(Operation):
776
776
777 isConfig = False
777 isConfig = False
778 buffer = None
778 buffer = None
779
779
780 def __init__(self):#, **kwargs):
780 def __init__(self):#, **kwargs):
781
781
782 Operation.__init__(self)#, **kwargs)
782 Operation.__init__(self)#, **kwargs)
783 self.profileIndex = 0
783 self.profileIndex = 0
784
784
785 def reset(self):
785 def reset(self):
786 self.buffer = numpy.zeros_like(self.buffer)
786 self.buffer = numpy.zeros_like(self.buffer)
787 self.start_index = 0
787 self.start_index = 0
788 self.times = 1
788 self.times = 1
789
789
790 def setup(self, data, m, n=1):
790 def setup(self, data, m, n=1):
791 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
791 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
792 self.nHeights = data.shape[1]#.nHeights
792 self.nHeights = data.shape[1]#.nHeights
793 self.start_index = 0
793 self.start_index = 0
794 self.times = 1
794 self.times = 1
795
795
796 def concat(self, data):
796 def concat(self, data):
797
797
798 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
798 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
799 self.start_index = self.start_index + self.nHeights
799 self.start_index = self.start_index + self.nHeights
800
800
801 def run(self, dataOut, m):
801 def run(self, dataOut, m):
802
802
803 dataOut.flagNoData = True
803 dataOut.flagNoData = True
804
804
805 if not self.isConfig:
805 if not self.isConfig:
806 self.setup(dataOut.data, m, 1)
806 self.setup(dataOut.data, m, 1)
807 self.isConfig = True
807 self.isConfig = True
808
808
809 if dataOut.flagDataAsBlock:
809 if dataOut.flagDataAsBlock:
810 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
810 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
811
811
812 else:
812 else:
813 self.concat(dataOut.data)
813 self.concat(dataOut.data)
814 self.times += 1
814 self.times += 1
815 if self.times > m:
815 if self.times > m:
816 dataOut.data = self.buffer
816 dataOut.data = self.buffer
817 self.reset()
817 self.reset()
818 dataOut.flagNoData = False
818 dataOut.flagNoData = False
819 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
819 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
820 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
820 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
821 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
821 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
822 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
822 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
823 dataOut.ippSeconds *= m
823 dataOut.ippSeconds *= m
824 return dataOut
824 return dataOut
825
825
826 class ProfileSelector(Operation):
826 class ProfileSelector(Operation):
827
827
828 profileIndex = None
828 profileIndex = None
829 # Tamanho total de los perfiles
829 # Tamanho total de los perfiles
830 nProfiles = None
830 nProfiles = None
831
831
832 def __init__(self):#, **kwargs):
832 def __init__(self):#, **kwargs):
833
833
834 Operation.__init__(self)#, **kwargs)
834 Operation.__init__(self)#, **kwargs)
835 self.profileIndex = 0
835 self.profileIndex = 0
836
836
837 def incProfileIndex(self):
837 def incProfileIndex(self):
838
838
839 self.profileIndex += 1
839 self.profileIndex += 1
840
840
841 if self.profileIndex >= self.nProfiles:
841 if self.profileIndex >= self.nProfiles:
842 self.profileIndex = 0
842 self.profileIndex = 0
843
843
844 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
844 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
845
845
846 if profileIndex < minIndex:
846 if profileIndex < minIndex:
847 return False
847 return False
848
848
849 if profileIndex > maxIndex:
849 if profileIndex > maxIndex:
850 return False
850 return False
851
851
852 return True
852 return True
853
853
854 def isThisProfileInList(self, profileIndex, profileList):
854 def isThisProfileInList(self, profileIndex, profileList):
855
855
856 if profileIndex not in profileList:
856 if profileIndex not in profileList:
857 return False
857 return False
858
858
859 return True
859 return True
860
860
861 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
861 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
862
862
863 """
863 """
864 ProfileSelector:
864 ProfileSelector:
865
865
866 Inputs:
866 Inputs:
867 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
867 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
868
868
869 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
869 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
870
870
871 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
871 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
872
872
873 """
873 """
874
874
875 if rangeList is not None:
875 if rangeList is not None:
876 if type(rangeList[0]) not in (tuple, list):
876 if type(rangeList[0]) not in (tuple, list):
877 rangeList = [rangeList]
877 rangeList = [rangeList]
878
878
879 dataOut.flagNoData = True
879 dataOut.flagNoData = True
880
880
881 if dataOut.flagDataAsBlock:
881 if dataOut.flagDataAsBlock:
882 """
882 """
883 data dimension = [nChannels, nProfiles, nHeis]
883 data dimension = [nChannels, nProfiles, nHeis]
884 """
884 """
885 if profileList != None:
885 if profileList != None:
886 dataOut.data = dataOut.data[:,profileList,:]
886 dataOut.data = dataOut.data[:,profileList,:]
887
887
888 if profileRangeList != None:
888 if profileRangeList != None:
889 minIndex = profileRangeList[0]
889 minIndex = profileRangeList[0]
890 maxIndex = profileRangeList[1]
890 maxIndex = profileRangeList[1]
891 profileList = list(range(minIndex, maxIndex+1))
891 profileList = list(range(minIndex, maxIndex+1))
892
892
893 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
893 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
894
894
895 if rangeList != None:
895 if rangeList != None:
896
896
897 profileList = []
897 profileList = []
898
898
899 for thisRange in rangeList:
899 for thisRange in rangeList:
900 minIndex = thisRange[0]
900 minIndex = thisRange[0]
901 maxIndex = thisRange[1]
901 maxIndex = thisRange[1]
902
902
903 profileList.extend(list(range(minIndex, maxIndex+1)))
903 profileList.extend(list(range(minIndex, maxIndex+1)))
904
904
905 dataOut.data = dataOut.data[:,profileList,:]
905 dataOut.data = dataOut.data[:,profileList,:]
906
906
907 dataOut.nProfiles = len(profileList)
907 dataOut.nProfiles = len(profileList)
908 dataOut.profileIndex = dataOut.nProfiles - 1
908 dataOut.profileIndex = dataOut.nProfiles - 1
909 dataOut.flagNoData = False
909 dataOut.flagNoData = False
910
910
911 return True
911 return True
912
912
913 """
913 """
914 data dimension = [nChannels, nHeis]
914 data dimension = [nChannels, nHeis]
915 """
915 """
916
916
917 if profileList != None:
917 if profileList != None:
918
918
919 if self.isThisProfileInList(dataOut.profileIndex, profileList):
919 if self.isThisProfileInList(dataOut.profileIndex, profileList):
920
920
921 self.nProfiles = len(profileList)
921 self.nProfiles = len(profileList)
922 dataOut.nProfiles = self.nProfiles
922 dataOut.nProfiles = self.nProfiles
923 dataOut.profileIndex = self.profileIndex
923 dataOut.profileIndex = self.profileIndex
924 dataOut.flagNoData = False
924 dataOut.flagNoData = False
925
925
926 self.incProfileIndex()
926 self.incProfileIndex()
927 return True
927 return True
928
928
929 if profileRangeList != None:
929 if profileRangeList != None:
930
930
931 minIndex = profileRangeList[0]
931 minIndex = profileRangeList[0]
932 maxIndex = profileRangeList[1]
932 maxIndex = profileRangeList[1]
933
933
934 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
934 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
935
935
936 self.nProfiles = maxIndex - minIndex + 1
936 self.nProfiles = maxIndex - minIndex + 1
937 dataOut.nProfiles = self.nProfiles
937 dataOut.nProfiles = self.nProfiles
938 dataOut.profileIndex = self.profileIndex
938 dataOut.profileIndex = self.profileIndex
939 dataOut.flagNoData = False
939 dataOut.flagNoData = False
940
940
941 self.incProfileIndex()
941 self.incProfileIndex()
942 return True
942 return True
943
943
944 if rangeList != None:
944 if rangeList != None:
945
945
946 nProfiles = 0
946 nProfiles = 0
947
947
948 for thisRange in rangeList:
948 for thisRange in rangeList:
949 minIndex = thisRange[0]
949 minIndex = thisRange[0]
950 maxIndex = thisRange[1]
950 maxIndex = thisRange[1]
951
951
952 nProfiles += maxIndex - minIndex + 1
952 nProfiles += maxIndex - minIndex + 1
953
953
954 for thisRange in rangeList:
954 for thisRange in rangeList:
955
955
956 minIndex = thisRange[0]
956 minIndex = thisRange[0]
957 maxIndex = thisRange[1]
957 maxIndex = thisRange[1]
958
958
959 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
959 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
960
960
961 self.nProfiles = nProfiles
961 self.nProfiles = nProfiles
962 dataOut.nProfiles = self.nProfiles
962 dataOut.nProfiles = self.nProfiles
963 dataOut.profileIndex = self.profileIndex
963 dataOut.profileIndex = self.profileIndex
964 dataOut.flagNoData = False
964 dataOut.flagNoData = False
965
965
966 self.incProfileIndex()
966 self.incProfileIndex()
967
967
968 break
968 break
969
969
970 return True
970 return True
971
971
972
972
973 if beam != None: #beam is only for AMISR data
973 if beam != None: #beam is only for AMISR data
974 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
974 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
975 dataOut.flagNoData = False
975 dataOut.flagNoData = False
976 dataOut.profileIndex = self.profileIndex
976 dataOut.profileIndex = self.profileIndex
977
977
978 self.incProfileIndex()
978 self.incProfileIndex()
979
979
980 return True
980 return True
981
981
982 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
982 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
983
983
984 #return False
984 #return False
985 return dataOut
985 return dataOut
986
986
987 class Reshaper(Operation):
987 class Reshaper(Operation):
988
988
989 def __init__(self):#, **kwargs):
989 def __init__(self):#, **kwargs):
990
990
991 Operation.__init__(self)#, **kwargs)
991 Operation.__init__(self)#, **kwargs)
992
992
993 self.__buffer = None
993 self.__buffer = None
994 self.__nitems = 0
994 self.__nitems = 0
995
995
996 def __appendProfile(self, dataOut, nTxs):
996 def __appendProfile(self, dataOut, nTxs):
997
997
998 if self.__buffer is None:
998 if self.__buffer is None:
999 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
999 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1000 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1000 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1001
1001
1002 ini = dataOut.nHeights * self.__nitems
1002 ini = dataOut.nHeights * self.__nitems
1003 end = ini + dataOut.nHeights
1003 end = ini + dataOut.nHeights
1004
1004
1005 self.__buffer[:, ini:end] = dataOut.data
1005 self.__buffer[:, ini:end] = dataOut.data
1006
1006
1007 self.__nitems += 1
1007 self.__nitems += 1
1008
1008
1009 return int(self.__nitems*nTxs)
1009 return int(self.__nitems*nTxs)
1010
1010
1011 def __getBuffer(self):
1011 def __getBuffer(self):
1012
1012
1013 if self.__nitems == int(1./self.__nTxs):
1013 if self.__nitems == int(1./self.__nTxs):
1014
1014
1015 self.__nitems = 0
1015 self.__nitems = 0
1016
1016
1017 return self.__buffer.copy()
1017 return self.__buffer.copy()
1018
1018
1019 return None
1019 return None
1020
1020
1021 def __checkInputs(self, dataOut, shape, nTxs):
1021 def __checkInputs(self, dataOut, shape, nTxs):
1022
1022
1023 if shape is None and nTxs is None:
1023 if shape is None and nTxs is None:
1024 raise ValueError("Reshaper: shape of factor should be defined")
1024 raise ValueError("Reshaper: shape of factor should be defined")
1025
1025
1026 if nTxs:
1026 if nTxs:
1027 if nTxs < 0:
1027 if nTxs < 0:
1028 raise ValueError("nTxs should be greater than 0")
1028 raise ValueError("nTxs should be greater than 0")
1029
1029
1030 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1030 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1031 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1031 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1032
1032
1033 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1033 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1034
1034
1035 return shape, nTxs
1035 return shape, nTxs
1036
1036
1037 if len(shape) != 2 and len(shape) != 3:
1037 if len(shape) != 2 and len(shape) != 3:
1038 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))
1038 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))
1039
1039
1040 if len(shape) == 2:
1040 if len(shape) == 2:
1041 shape_tuple = [dataOut.nChannels]
1041 shape_tuple = [dataOut.nChannels]
1042 shape_tuple.extend(shape)
1042 shape_tuple.extend(shape)
1043 else:
1043 else:
1044 shape_tuple = list(shape)
1044 shape_tuple = list(shape)
1045
1045
1046 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1046 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1047
1047
1048 return shape_tuple, nTxs
1048 return shape_tuple, nTxs
1049
1049
1050 def run(self, dataOut, shape=None, nTxs=None):
1050 def run(self, dataOut, shape=None, nTxs=None):
1051
1051
1052 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1052 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1053
1053
1054 dataOut.flagNoData = True
1054 dataOut.flagNoData = True
1055 profileIndex = None
1055 profileIndex = None
1056
1056
1057 if dataOut.flagDataAsBlock:
1057 if dataOut.flagDataAsBlock:
1058
1058
1059 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1059 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1060 dataOut.flagNoData = False
1060 dataOut.flagNoData = False
1061
1061
1062 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1062 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1063
1063
1064 else:
1064 else:
1065
1065
1066 if self.__nTxs < 1:
1066 if self.__nTxs < 1:
1067
1067
1068 self.__appendProfile(dataOut, self.__nTxs)
1068 self.__appendProfile(dataOut, self.__nTxs)
1069 new_data = self.__getBuffer()
1069 new_data = self.__getBuffer()
1070
1070
1071 if new_data is not None:
1071 if new_data is not None:
1072 dataOut.data = new_data
1072 dataOut.data = new_data
1073 dataOut.flagNoData = False
1073 dataOut.flagNoData = False
1074
1074
1075 profileIndex = dataOut.profileIndex*nTxs
1075 profileIndex = dataOut.profileIndex*nTxs
1076
1076
1077 else:
1077 else:
1078 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1078 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1079
1079
1080 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1080 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1081
1081
1082 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1082 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1083
1083
1084 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1084 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1085
1085
1086 dataOut.profileIndex = profileIndex
1086 dataOut.profileIndex = profileIndex
1087
1087
1088 dataOut.ippSeconds /= self.__nTxs
1088 dataOut.ippSeconds /= self.__nTxs
1089
1089
1090 return dataOut
1090 return dataOut
1091
1091
1092 class SplitProfiles(Operation):
1092 class SplitProfiles(Operation):
1093
1093
1094 def __init__(self):#, **kwargs):
1094 def __init__(self):#, **kwargs):
1095
1095
1096 Operation.__init__(self)#, **kwargs)
1096 Operation.__init__(self)#, **kwargs)
1097
1097
1098 def run(self, dataOut, n):
1098 def run(self, dataOut, n):
1099
1099
1100 dataOut.flagNoData = True
1100 dataOut.flagNoData = True
1101 profileIndex = None
1101 profileIndex = None
1102
1102
1103 if dataOut.flagDataAsBlock:
1103 if dataOut.flagDataAsBlock:
1104
1104
1105 #nchannels, nprofiles, nsamples
1105 #nchannels, nprofiles, nsamples
1106 shape = dataOut.data.shape
1106 shape = dataOut.data.shape
1107
1107
1108 if shape[2] % n != 0:
1108 if shape[2] % n != 0:
1109 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1109 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1110
1110
1111 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1111 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1112
1112
1113 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1113 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1114 dataOut.flagNoData = False
1114 dataOut.flagNoData = False
1115
1115
1116 profileIndex = int(dataOut.nProfiles/n) - 1
1116 profileIndex = int(dataOut.nProfiles/n) - 1
1117
1117
1118 else:
1118 else:
1119
1119
1120 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1120 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1121
1121
1122 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1122 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1123
1123
1124 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1124 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1125
1125
1126 dataOut.nProfiles = int(dataOut.nProfiles*n)
1126 dataOut.nProfiles = int(dataOut.nProfiles*n)
1127
1127
1128 dataOut.profileIndex = profileIndex
1128 dataOut.profileIndex = profileIndex
1129
1129
1130 dataOut.ippSeconds /= n
1130 dataOut.ippSeconds /= n
1131
1131
1132 return dataOut
1132 return dataOut
1133
1133
1134 class CombineProfiles(Operation):
1134 class CombineProfiles(Operation):
1135 def __init__(self):#, **kwargs):
1135 def __init__(self):#, **kwargs):
1136
1136
1137 Operation.__init__(self)#, **kwargs)
1137 Operation.__init__(self)#, **kwargs)
1138
1138
1139 self.__remData = None
1139 self.__remData = None
1140 self.__profileIndex = 0
1140 self.__profileIndex = 0
1141
1141
1142 def run(self, dataOut, n):
1142 def run(self, dataOut, n):
1143
1143
1144 dataOut.flagNoData = True
1144 dataOut.flagNoData = True
1145 profileIndex = None
1145 profileIndex = None
1146
1146
1147 if dataOut.flagDataAsBlock:
1147 if dataOut.flagDataAsBlock:
1148
1148
1149 #nchannels, nprofiles, nsamples
1149 #nchannels, nprofiles, nsamples
1150 shape = dataOut.data.shape
1150 shape = dataOut.data.shape
1151 new_shape = shape[0], shape[1]/n, shape[2]*n
1151 new_shape = shape[0], shape[1]/n, shape[2]*n
1152
1152
1153 if shape[1] % n != 0:
1153 if shape[1] % n != 0:
1154 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1154 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1155
1155
1156 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1156 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1157 dataOut.flagNoData = False
1157 dataOut.flagNoData = False
1158
1158
1159 profileIndex = int(dataOut.nProfiles*n) - 1
1159 profileIndex = int(dataOut.nProfiles*n) - 1
1160
1160
1161 else:
1161 else:
1162
1162
1163 #nchannels, nsamples
1163 #nchannels, nsamples
1164 if self.__remData is None:
1164 if self.__remData is None:
1165 newData = dataOut.data
1165 newData = dataOut.data
1166 else:
1166 else:
1167 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1167 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1168
1168
1169 self.__profileIndex += 1
1169 self.__profileIndex += 1
1170
1170
1171 if self.__profileIndex < n:
1171 if self.__profileIndex < n:
1172 self.__remData = newData
1172 self.__remData = newData
1173 #continue
1173 #continue
1174 return
1174 return
1175
1175
1176 self.__profileIndex = 0
1176 self.__profileIndex = 0
1177 self.__remData = None
1177 self.__remData = None
1178
1178
1179 dataOut.data = newData
1179 dataOut.data = newData
1180 dataOut.flagNoData = False
1180 dataOut.flagNoData = False
1181
1181
1182 profileIndex = dataOut.profileIndex/n
1182 profileIndex = dataOut.profileIndex/n
1183
1183
1184
1184
1185 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1185 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1186
1186
1187 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1187 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1188
1188
1189 dataOut.nProfiles = int(dataOut.nProfiles/n)
1189 dataOut.nProfiles = int(dataOut.nProfiles/n)
1190
1190
1191 dataOut.profileIndex = profileIndex
1191 dataOut.profileIndex = profileIndex
1192
1192
1193 dataOut.ippSeconds *= n
1193 dataOut.ippSeconds *= n
1194
1194
1195 return dataOut
1195 return dataOut
1196 # import collections
1196 # import collections
1197 # from scipy.stats import mode
1197 # from scipy.stats import mode
1198 #
1198 #
1199 # class Synchronize(Operation):
1199 # class Synchronize(Operation):
1200 #
1200 #
1201 # isConfig = False
1201 # isConfig = False
1202 # __profIndex = 0
1202 # __profIndex = 0
1203 #
1203 #
1204 # def __init__(self, **kwargs):
1204 # def __init__(self, **kwargs):
1205 #
1205 #
1206 # Operation.__init__(self, **kwargs)
1206 # Operation.__init__(self, **kwargs)
1207 # # self.isConfig = False
1207 # # self.isConfig = False
1208 # self.__powBuffer = None
1208 # self.__powBuffer = None
1209 # self.__startIndex = 0
1209 # self.__startIndex = 0
1210 # self.__pulseFound = False
1210 # self.__pulseFound = False
1211 #
1211 #
1212 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1212 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1213 #
1213 #
1214 # #Read data
1214 # #Read data
1215 #
1215 #
1216 # powerdB = dataOut.getPower(channel = channel)
1216 # powerdB = dataOut.getPower(channel = channel)
1217 # noisedB = dataOut.getNoise(channel = channel)[0]
1217 # noisedB = dataOut.getNoise(channel = channel)[0]
1218 #
1218 #
1219 # self.__powBuffer.extend(powerdB.flatten())
1219 # self.__powBuffer.extend(powerdB.flatten())
1220 #
1220 #
1221 # dataArray = numpy.array(self.__powBuffer)
1221 # dataArray = numpy.array(self.__powBuffer)
1222 #
1222 #
1223 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1223 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1224 #
1224 #
1225 # maxValue = numpy.nanmax(filteredPower)
1225 # maxValue = numpy.nanmax(filteredPower)
1226 #
1226 #
1227 # if maxValue < noisedB + 10:
1227 # if maxValue < noisedB + 10:
1228 # #No se encuentra ningun pulso de transmision
1228 # #No se encuentra ningun pulso de transmision
1229 # return None
1229 # return None
1230 #
1230 #
1231 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1231 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1232 #
1232 #
1233 # if len(maxValuesIndex) < 2:
1233 # if len(maxValuesIndex) < 2:
1234 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1234 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1235 # return None
1235 # return None
1236 #
1236 #
1237 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1237 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1238 #
1238 #
1239 # #Seleccionar solo valores con un espaciamiento de nSamples
1239 # #Seleccionar solo valores con un espaciamiento de nSamples
1240 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1240 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1241 #
1241 #
1242 # if len(pulseIndex) < 2:
1242 # if len(pulseIndex) < 2:
1243 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1243 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1244 # return None
1244 # return None
1245 #
1245 #
1246 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1246 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1247 #
1247 #
1248 # #remover senales que se distancien menos de 10 unidades o muestras
1248 # #remover senales que se distancien menos de 10 unidades o muestras
1249 # #(No deberian existir IPP menor a 10 unidades)
1249 # #(No deberian existir IPP menor a 10 unidades)
1250 #
1250 #
1251 # realIndex = numpy.where(spacing > 10 )[0]
1251 # realIndex = numpy.where(spacing > 10 )[0]
1252 #
1252 #
1253 # if len(realIndex) < 2:
1253 # if len(realIndex) < 2:
1254 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1254 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1255 # return None
1255 # return None
1256 #
1256 #
1257 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1257 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1258 # realPulseIndex = pulseIndex[realIndex]
1258 # realPulseIndex = pulseIndex[realIndex]
1259 #
1259 #
1260 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1260 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1261 #
1261 #
1262 # print "IPP = %d samples" %period
1262 # print "IPP = %d samples" %period
1263 #
1263 #
1264 # self.__newNSamples = dataOut.nHeights #int(period)
1264 # self.__newNSamples = dataOut.nHeights #int(period)
1265 # self.__startIndex = int(realPulseIndex[0])
1265 # self.__startIndex = int(realPulseIndex[0])
1266 #
1266 #
1267 # return 1
1267 # return 1
1268 #
1268 #
1269 #
1269 #
1270 # def setup(self, nSamples, nChannels, buffer_size = 4):
1270 # def setup(self, nSamples, nChannels, buffer_size = 4):
1271 #
1271 #
1272 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1272 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1273 # maxlen = buffer_size*nSamples)
1273 # maxlen = buffer_size*nSamples)
1274 #
1274 #
1275 # bufferList = []
1275 # bufferList = []
1276 #
1276 #
1277 # for i in range(nChannels):
1277 # for i in range(nChannels):
1278 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1278 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1279 # maxlen = buffer_size*nSamples)
1279 # maxlen = buffer_size*nSamples)
1280 #
1280 #
1281 # bufferList.append(bufferByChannel)
1281 # bufferList.append(bufferByChannel)
1282 #
1282 #
1283 # self.__nSamples = nSamples
1283 # self.__nSamples = nSamples
1284 # self.__nChannels = nChannels
1284 # self.__nChannels = nChannels
1285 # self.__bufferList = bufferList
1285 # self.__bufferList = bufferList
1286 #
1286 #
1287 # def run(self, dataOut, channel = 0):
1287 # def run(self, dataOut, channel = 0):
1288 #
1288 #
1289 # if not self.isConfig:
1289 # if not self.isConfig:
1290 # nSamples = dataOut.nHeights
1290 # nSamples = dataOut.nHeights
1291 # nChannels = dataOut.nChannels
1291 # nChannels = dataOut.nChannels
1292 # self.setup(nSamples, nChannels)
1292 # self.setup(nSamples, nChannels)
1293 # self.isConfig = True
1293 # self.isConfig = True
1294 #
1294 #
1295 # #Append new data to internal buffer
1295 # #Append new data to internal buffer
1296 # for thisChannel in range(self.__nChannels):
1296 # for thisChannel in range(self.__nChannels):
1297 # bufferByChannel = self.__bufferList[thisChannel]
1297 # bufferByChannel = self.__bufferList[thisChannel]
1298 # bufferByChannel.extend(dataOut.data[thisChannel])
1298 # bufferByChannel.extend(dataOut.data[thisChannel])
1299 #
1299 #
1300 # if self.__pulseFound:
1300 # if self.__pulseFound:
1301 # self.__startIndex -= self.__nSamples
1301 # self.__startIndex -= self.__nSamples
1302 #
1302 #
1303 # #Finding Tx Pulse
1303 # #Finding Tx Pulse
1304 # if not self.__pulseFound:
1304 # if not self.__pulseFound:
1305 # indexFound = self.__findTxPulse(dataOut, channel)
1305 # indexFound = self.__findTxPulse(dataOut, channel)
1306 #
1306 #
1307 # if indexFound == None:
1307 # if indexFound == None:
1308 # dataOut.flagNoData = True
1308 # dataOut.flagNoData = True
1309 # return
1309 # return
1310 #
1310 #
1311 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1311 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1312 # self.__pulseFound = True
1312 # self.__pulseFound = True
1313 # self.__startIndex = indexFound
1313 # self.__startIndex = indexFound
1314 #
1314 #
1315 # #If pulse was found ...
1315 # #If pulse was found ...
1316 # for thisChannel in range(self.__nChannels):
1316 # for thisChannel in range(self.__nChannels):
1317 # bufferByChannel = self.__bufferList[thisChannel]
1317 # bufferByChannel = self.__bufferList[thisChannel]
1318 # #print self.__startIndex
1318 # #print self.__startIndex
1319 # x = numpy.array(bufferByChannel)
1319 # x = numpy.array(bufferByChannel)
1320 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1320 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1321 #
1321 #
1322 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1322 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1323 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1323 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1324 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1324 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1325 #
1325 #
1326 # dataOut.data = self.__arrayBuffer
1326 # dataOut.data = self.__arrayBuffer
1327 #
1327 #
1328 # self.__startIndex += self.__newNSamples
1328 # self.__startIndex += self.__newNSamples
1329 #
1329 #
1330 # return
1330 # return
General Comments 0
You need to be logged in to leave comments. Login now