##// END OF EJS Templates
JRODATA: timeInterval is a property now
Miguel Valdez -
r528:de1409f843e0
parent child
Show More
@@ -1,339 +1,339
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from model.data.jrodata import SpectraHeis
4 from model.data.jrodata import SpectraHeis
5
5
6 class SpectraHeisProc(ProcessingUnit):
6 class SpectraHeisProc(ProcessingUnit):
7
7
8 def __init__(self):
8 def __init__(self):
9
9
10 ProcessingUnit.__init__(self)
10 ProcessingUnit.__init__(self)
11
11
12 # self.buffer = None
12 # self.buffer = None
13 # self.firstdatatime = None
13 # self.firstdatatime = None
14 # self.profIndex = 0
14 # self.profIndex = 0
15 self.dataOut = SpectraHeis()
15 self.dataOut = SpectraHeis()
16
16
17 def __updateObjFromInput(self):
17 def __updateObjFromInput(self):
18
18
19 self.dataOut.timeZone = self.dataIn.timeZone
19 self.dataOut.timeZone = self.dataIn.timeZone
20 self.dataOut.dstFlag = self.dataIn.dstFlag
20 self.dataOut.dstFlag = self.dataIn.dstFlag
21 self.dataOut.errorCount = self.dataIn.errorCount
21 self.dataOut.errorCount = self.dataIn.errorCount
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
23
23
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
26 self.dataOut.channelList = self.dataIn.channelList
26 self.dataOut.channelList = self.dataIn.channelList
27 self.dataOut.heightList = self.dataIn.heightList
27 self.dataOut.heightList = self.dataIn.heightList
28 # self.dataOut.dtype = self.dataIn.dtype
28 # self.dataOut.dtype = self.dataIn.dtype
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
30 # self.dataOut.nHeights = self.dataIn.nHeights
30 # self.dataOut.nHeights = self.dataIn.nHeights
31 # self.dataOut.nChannels = self.dataIn.nChannels
31 # self.dataOut.nChannels = self.dataIn.nChannels
32 self.dataOut.nBaud = self.dataIn.nBaud
32 self.dataOut.nBaud = self.dataIn.nBaud
33 self.dataOut.nCode = self.dataIn.nCode
33 self.dataOut.nCode = self.dataIn.nCode
34 self.dataOut.code = self.dataIn.code
34 self.dataOut.code = self.dataIn.code
35 # self.dataOut.nProfiles = 1
35 # self.dataOut.nProfiles = 1
36 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
36 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
37 self.dataOut.nFFTPoints = self.dataIn.nHeights
37 self.dataOut.nFFTPoints = self.dataIn.nHeights
38 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
38 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
39 # self.dataOut.flagNoData = self.dataIn.flagNoData
39 # self.dataOut.flagNoData = self.dataIn.flagNoData
40 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
40 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
41 self.dataOut.utctime = self.dataIn.utctime
41 self.dataOut.utctime = self.dataIn.utctime
42 # self.dataOut.utctime = self.firstdatatime
42 # self.dataOut.utctime = self.firstdatatime
43 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
43 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
44 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
44 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
45 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
45 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
46 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.nCohInt = self.dataIn.nCohInt
47 self.dataOut.nIncohInt = 1
47 self.dataOut.nIncohInt = 1
48 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
48 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
50
50
51 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
51 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
52 # self.dataOut.set=self.dataIn.set
52 # self.dataOut.set=self.dataIn.set
53 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
53 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
54
54
55
55
56 def __updateObjFromFits(self):
56 def __updateObjFromFits(self):
57 self.dataOut.utctime = self.dataIn.utctime
57 self.dataOut.utctime = self.dataIn.utctime
58 self.dataOut.channelIndexList = self.dataIn.channelIndexList
58 self.dataOut.channelIndexList = self.dataIn.channelIndexList
59
59
60 self.dataOut.channelList = self.dataIn.channelList
60 self.dataOut.channelList = self.dataIn.channelList
61 self.dataOut.heightList = self.dataIn.heightList
61 self.dataOut.heightList = self.dataIn.heightList
62 self.dataOut.data_spc = self.dataIn.data
62 self.dataOut.data_spc = self.dataIn.data
63 self.dataOut.timeInterval = self.dataIn.timeInterval
63 self.dataOut.timeInterval = self.dataIn.timeInterval
64 self.dataOut.timeZone = self.dataIn.timeZone
64 self.dataOut.timeZone = self.dataIn.timeZone
65 self.dataOut.useLocalTime = True
65 self.dataOut.useLocalTime = True
66 # self.dataOut.
66 # self.dataOut.
67 # self.dataOut.
67 # self.dataOut.
68
68
69 def __getFft(self):
69 def __getFft(self):
70
70
71 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
71 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
72 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
72 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
73 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
73 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
74 self.dataOut.data_spc = spc
74 self.dataOut.data_spc = spc
75
75
76 def run(self):
76 def run(self):
77
77
78 self.dataOut.flagNoData = True
78 self.dataOut.flagNoData = True
79
79
80 if self.dataIn.type == "Fits":
80 if self.dataIn.type == "Fits":
81 self.__updateObjFromFits()
81 self.__updateObjFromFits()
82 self.dataOut.flagNoData = False
82 self.dataOut.flagNoData = False
83 return
83 return
84
84
85 if self.dataIn.type == "SpectraHeis":
85 if self.dataIn.type == "SpectraHeis":
86 self.dataOut.copy(self.dataIn)
86 self.dataOut.copy(self.dataIn)
87 return
87 return
88
88
89 if self.dataIn.type == "Voltage":
89 if self.dataIn.type == "Voltage":
90 self.__updateObjFromInput()
90 self.__updateObjFromInput()
91 self.__getFft()
91 self.__getFft()
92 self.dataOut.flagNoData = False
92 self.dataOut.flagNoData = False
93
93
94 return
94 return
95
95
96 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
96 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
97
97
98
98
99 def selectChannels(self, channelList):
99 def selectChannels(self, channelList):
100
100
101 channelIndexList = []
101 channelIndexList = []
102
102
103 for channel in channelList:
103 for channel in channelList:
104 index = self.dataOut.channelList.index(channel)
104 index = self.dataOut.channelList.index(channel)
105 channelIndexList.append(index)
105 channelIndexList.append(index)
106
106
107 self.selectChannelsByIndex(channelIndexList)
107 self.selectChannelsByIndex(channelIndexList)
108
108
109 def selectChannelsByIndex(self, channelIndexList):
109 def selectChannelsByIndex(self, channelIndexList):
110 """
110 """
111 Selecciona un bloque de datos en base a canales segun el channelIndexList
111 Selecciona un bloque de datos en base a canales segun el channelIndexList
112
112
113 Input:
113 Input:
114 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
114 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
115
115
116 Affected:
116 Affected:
117 self.dataOut.data
117 self.dataOut.data
118 self.dataOut.channelIndexList
118 self.dataOut.channelIndexList
119 self.dataOut.nChannels
119 self.dataOut.nChannels
120 self.dataOut.m_ProcessingHeader.totalSpectra
120 self.dataOut.m_ProcessingHeader.totalSpectra
121 self.dataOut.systemHeaderObj.numChannels
121 self.dataOut.systemHeaderObj.numChannels
122 self.dataOut.m_ProcessingHeader.blockSize
122 self.dataOut.m_ProcessingHeader.blockSize
123
123
124 Return:
124 Return:
125 None
125 None
126 """
126 """
127
127
128 for channelIndex in channelIndexList:
128 for channelIndex in channelIndexList:
129 if channelIndex not in self.dataOut.channelIndexList:
129 if channelIndex not in self.dataOut.channelIndexList:
130 print channelIndexList
130 print channelIndexList
131 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
131 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
132
132
133 # nChannels = len(channelIndexList)
133 # nChannels = len(channelIndexList)
134
134
135 data_spc = self.dataOut.data_spc[channelIndexList,:]
135 data_spc = self.dataOut.data_spc[channelIndexList,:]
136
136
137 self.dataOut.data_spc = data_spc
137 self.dataOut.data_spc = data_spc
138 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
138 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
139
139
140 return 1
140 return 1
141
141
142 class IncohInt4SpectraHeis(Operation):
142 class IncohInt4SpectraHeis(Operation):
143
143
144 isConfig = False
144 isConfig = False
145
145
146 __profIndex = 0
146 __profIndex = 0
147 __withOverapping = False
147 __withOverapping = False
148
148
149 __byTime = False
149 __byTime = False
150 __initime = None
150 __initime = None
151 __lastdatatime = None
151 __lastdatatime = None
152 __integrationtime = None
152 __integrationtime = None
153
153
154 __buffer = None
154 __buffer = None
155
155
156 __dataReady = False
156 __dataReady = False
157
157
158 n = None
158 n = None
159
159
160
160
161 def __init__(self):
161 def __init__(self):
162
162
163 Operation.__init__(self)
163 Operation.__init__(self)
164 # self.isConfig = False
164 # self.isConfig = False
165
165
166 def setup(self, n=None, timeInterval=None, overlapping=False):
166 def setup(self, n=None, timeInterval=None, overlapping=False):
167 """
167 """
168 Set the parameters of the integration class.
168 Set the parameters of the integration class.
169
169
170 Inputs:
170 Inputs:
171
171
172 n : Number of coherent integrations
172 n : Number of coherent integrations
173 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
173 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
174 overlapping :
174 overlapping :
175
175
176 """
176 """
177
177
178 self.__initime = None
178 self.__initime = None
179 self.__lastdatatime = 0
179 self.__lastdatatime = 0
180 self.__buffer = None
180 self.__buffer = None
181 self.__dataReady = False
181 self.__dataReady = False
182
182
183
183
184 if n == None and timeInterval == None:
184 if n == None and timeInterval == None:
185 raise ValueError, "n or timeInterval should be specified ..."
185 raise ValueError, "n or timeInterval should be specified ..."
186
186
187 if n != None:
187 if n != None:
188 self.n = n
188 self.n = n
189 self.__byTime = False
189 self.__byTime = False
190 else:
190 else:
191 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
191 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
192 self.n = 9999
192 self.n = 9999
193 self.__byTime = True
193 self.__byTime = True
194
194
195 if overlapping:
195 if overlapping:
196 self.__withOverapping = True
196 self.__withOverapping = True
197 self.__buffer = None
197 self.__buffer = None
198 else:
198 else:
199 self.__withOverapping = False
199 self.__withOverapping = False
200 self.__buffer = 0
200 self.__buffer = 0
201
201
202 self.__profIndex = 0
202 self.__profIndex = 0
203
203
204 def putData(self, data):
204 def putData(self, data):
205
205
206 """
206 """
207 Add a profile to the __buffer and increase in one the __profileIndex
207 Add a profile to the __buffer and increase in one the __profileIndex
208
208
209 """
209 """
210
210
211 if not self.__withOverapping:
211 if not self.__withOverapping:
212 self.__buffer += data.copy()
212 self.__buffer += data.copy()
213 self.__profIndex += 1
213 self.__profIndex += 1
214 return
214 return
215
215
216 #Overlapping data
216 #Overlapping data
217 nChannels, nHeis = data.shape
217 nChannels, nHeis = data.shape
218 data = numpy.reshape(data, (1, nChannels, nHeis))
218 data = numpy.reshape(data, (1, nChannels, nHeis))
219
219
220 #If the buffer is empty then it takes the data value
220 #If the buffer is empty then it takes the data value
221 if self.__buffer == None:
221 if self.__buffer == None:
222 self.__buffer = data
222 self.__buffer = data
223 self.__profIndex += 1
223 self.__profIndex += 1
224 return
224 return
225
225
226 #If the buffer length is lower than n then stakcing the data value
226 #If the buffer length is lower than n then stakcing the data value
227 if self.__profIndex < self.n:
227 if self.__profIndex < self.n:
228 self.__buffer = numpy.vstack((self.__buffer, data))
228 self.__buffer = numpy.vstack((self.__buffer, data))
229 self.__profIndex += 1
229 self.__profIndex += 1
230 return
230 return
231
231
232 #If the buffer length is equal to n then replacing the last buffer value with the data value
232 #If the buffer length is equal to n then replacing the last buffer value with the data value
233 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
233 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
234 self.__buffer[self.n-1] = data
234 self.__buffer[self.n-1] = data
235 self.__profIndex = self.n
235 self.__profIndex = self.n
236 return
236 return
237
237
238
238
239 def pushData(self):
239 def pushData(self):
240 """
240 """
241 Return the sum of the last profiles and the profiles used in the sum.
241 Return the sum of the last profiles and the profiles used in the sum.
242
242
243 Affected:
243 Affected:
244
244
245 self.__profileIndex
245 self.__profileIndex
246
246
247 """
247 """
248
248
249 if not self.__withOverapping:
249 if not self.__withOverapping:
250 data = self.__buffer
250 data = self.__buffer
251 n = self.__profIndex
251 n = self.__profIndex
252
252
253 self.__buffer = 0
253 self.__buffer = 0
254 self.__profIndex = 0
254 self.__profIndex = 0
255
255
256 return data, n
256 return data, n
257
257
258 #Integration with Overlapping
258 #Integration with Overlapping
259 data = numpy.sum(self.__buffer, axis=0)
259 data = numpy.sum(self.__buffer, axis=0)
260 n = self.__profIndex
260 n = self.__profIndex
261
261
262 return data, n
262 return data, n
263
263
264 def byProfiles(self, data):
264 def byProfiles(self, data):
265
265
266 self.__dataReady = False
266 self.__dataReady = False
267 avgdata = None
267 avgdata = None
268 # n = None
268 # n = None
269
269
270 self.putData(data)
270 self.putData(data)
271
271
272 if self.__profIndex == self.n:
272 if self.__profIndex == self.n:
273
273
274 avgdata, n = self.pushData()
274 avgdata, n = self.pushData()
275 self.__dataReady = True
275 self.__dataReady = True
276
276
277 return avgdata
277 return avgdata
278
278
279 def byTime(self, data, datatime):
279 def byTime(self, data, datatime):
280
280
281 self.__dataReady = False
281 self.__dataReady = False
282 avgdata = None
282 avgdata = None
283 n = None
283 n = None
284
284
285 self.putData(data)
285 self.putData(data)
286
286
287 if (datatime - self.__initime) >= self.__integrationtime:
287 if (datatime - self.__initime) >= self.__integrationtime:
288 avgdata, n = self.pushData()
288 avgdata, n = self.pushData()
289 self.n = n
289 self.n = n
290 self.__dataReady = True
290 self.__dataReady = True
291
291
292 return avgdata
292 return avgdata
293
293
294 def integrate(self, data, datatime=None):
294 def integrate(self, data, datatime=None):
295
295
296 if self.__initime == None:
296 if self.__initime == None:
297 self.__initime = datatime
297 self.__initime = datatime
298
298
299 if self.__byTime:
299 if self.__byTime:
300 avgdata = self.byTime(data, datatime)
300 avgdata = self.byTime(data, datatime)
301 else:
301 else:
302 avgdata = self.byProfiles(data)
302 avgdata = self.byProfiles(data)
303
303
304
304
305 self.__lastdatatime = datatime
305 self.__lastdatatime = datatime
306
306
307 if avgdata == None:
307 if avgdata == None:
308 return None, None
308 return None, None
309
309
310 avgdatatime = self.__initime
310 avgdatatime = self.__initime
311
311
312 deltatime = datatime -self.__lastdatatime
312 deltatime = datatime -self.__lastdatatime
313
313
314 if not self.__withOverapping:
314 if not self.__withOverapping:
315 self.__initime = datatime
315 self.__initime = datatime
316 else:
316 else:
317 self.__initime += deltatime
317 self.__initime += deltatime
318
318
319 return avgdata, avgdatatime
319 return avgdata, avgdatatime
320
320
321 def run(self, dataOut, **kwargs):
321 def run(self, dataOut, **kwargs):
322
322
323 if not self.isConfig:
323 if not self.isConfig:
324 self.setup(**kwargs)
324 self.setup(**kwargs)
325 self.isConfig = True
325 self.isConfig = True
326
326
327 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
327 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
328
328
329 # dataOut.timeInterval *= n
329 # dataOut.timeInterval *= n
330 dataOut.flagNoData = True
330 dataOut.flagNoData = True
331
331
332 if self.__dataReady:
332 if self.__dataReady:
333 dataOut.data_spc = avgdata
333 dataOut.data_spc = avgdata
334 dataOut.nIncohInt *= self.n
334 dataOut.nIncohInt *= self.n
335 # dataOut.nCohInt *= self.n
335 # dataOut.nCohInt *= self.n
336 dataOut.utctime = avgdatatime
336 dataOut.utctime = avgdatatime
337 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
337 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
338 # dataOut.timeInterval = self.__timeInterval*self.n
338 # dataOut.timeInterval = self.__timeInterval*self.n
339 dataOut.flagNoData = False No newline at end of file
339 dataOut.flagNoData = False
@@ -1,935 +1,935
1 import numpy
1 import numpy
2 import math
2 import math
3
3
4 from jroproc_base import ProcessingUnit, Operation
4 from jroproc_base import ProcessingUnit, Operation
5 from model.data.jrodata import Spectra
5 from model.data.jrodata import Spectra
6 from model.data.jrodata import hildebrand_sekhon
6 from model.data.jrodata import hildebrand_sekhon
7
7
8 class SpectraProc(ProcessingUnit):
8 class SpectraProc(ProcessingUnit):
9
9
10 def __init__(self):
10 def __init__(self):
11
11
12 ProcessingUnit.__init__(self)
12 ProcessingUnit.__init__(self)
13
13
14 self.buffer = None
14 self.buffer = None
15 self.firstdatatime = None
15 self.firstdatatime = None
16 self.profIndex = 0
16 self.profIndex = 0
17 self.dataOut = Spectra()
17 self.dataOut = Spectra()
18 self.id_min = None
18 self.id_min = None
19 self.id_max = None
19 self.id_max = None
20
20
21 def __updateObjFromInput(self):
21 def __updateObjFromInput(self):
22
22
23 self.dataOut.timeZone = self.dataIn.timeZone
23 self.dataOut.timeZone = self.dataIn.timeZone
24 self.dataOut.dstFlag = self.dataIn.dstFlag
24 self.dataOut.dstFlag = self.dataIn.dstFlag
25 self.dataOut.errorCount = self.dataIn.errorCount
25 self.dataOut.errorCount = self.dataIn.errorCount
26 self.dataOut.useLocalTime = self.dataIn.useLocalTime
26 self.dataOut.useLocalTime = self.dataIn.useLocalTime
27
27
28 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
28 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
29 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
29 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
30 self.dataOut.channelList = self.dataIn.channelList
30 self.dataOut.channelList = self.dataIn.channelList
31 self.dataOut.heightList = self.dataIn.heightList
31 self.dataOut.heightList = self.dataIn.heightList
32 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
32 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
33 # self.dataOut.nHeights = self.dataIn.nHeights
33 # self.dataOut.nHeights = self.dataIn.nHeights
34 # self.dataOut.nChannels = self.dataIn.nChannels
34 # self.dataOut.nChannels = self.dataIn.nChannels
35 self.dataOut.nBaud = self.dataIn.nBaud
35 self.dataOut.nBaud = self.dataIn.nBaud
36 self.dataOut.nCode = self.dataIn.nCode
36 self.dataOut.nCode = self.dataIn.nCode
37 self.dataOut.code = self.dataIn.code
37 self.dataOut.code = self.dataIn.code
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
39 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
39 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
40 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
40 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
41 self.dataOut.utctime = self.firstdatatime
41 self.dataOut.utctime = self.firstdatatime
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
44 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
44 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
45 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.nIncohInt = 1
46 self.dataOut.nIncohInt = 1
47 # self.dataOut.ippSeconds = self.dataIn.ippSeconds
47 # self.dataOut.ippSeconds = self.dataIn.ippSeconds
48 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
48 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
49
49
50 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
50 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
51 self.dataOut.frequency = self.dataIn.frequency
51 self.dataOut.frequency = self.dataIn.frequency
52 self.dataOut.realtime = self.dataIn.realtime
52 self.dataOut.realtime = self.dataIn.realtime
53
53
54 self.dataOut.azimuth = self.dataIn.azimuth
54 self.dataOut.azimuth = self.dataIn.azimuth
55 self.dataOut.zenith = self.dataIn.zenith
55 self.dataOut.zenith = self.dataIn.zenith
56
56
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
60
60
61 def __getFft(self):
61 def __getFft(self):
62 """
62 """
63 Convierte valores de Voltaje a Spectra
63 Convierte valores de Voltaje a Spectra
64
64
65 Affected:
65 Affected:
66 self.dataOut.data_spc
66 self.dataOut.data_spc
67 self.dataOut.data_cspc
67 self.dataOut.data_cspc
68 self.dataOut.data_dc
68 self.dataOut.data_dc
69 self.dataOut.heightList
69 self.dataOut.heightList
70 self.profIndex
70 self.profIndex
71 self.buffer
71 self.buffer
72 self.dataOut.flagNoData
72 self.dataOut.flagNoData
73 """
73 """
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
75 fft_volt = fft_volt.astype(numpy.dtype('complex'))
75 fft_volt = fft_volt.astype(numpy.dtype('complex'))
76 dc = fft_volt[:,0,:]
76 dc = fft_volt[:,0,:]
77
77
78 #calculo de self-spectra
78 #calculo de self-spectra
79 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
79 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
80 spc = fft_volt * numpy.conjugate(fft_volt)
80 spc = fft_volt * numpy.conjugate(fft_volt)
81 spc = spc.real
81 spc = spc.real
82
82
83 blocksize = 0
83 blocksize = 0
84 blocksize += dc.size
84 blocksize += dc.size
85 blocksize += spc.size
85 blocksize += spc.size
86
86
87 cspc = None
87 cspc = None
88 pairIndex = 0
88 pairIndex = 0
89 if self.dataOut.pairsList != None:
89 if self.dataOut.pairsList != None:
90 #calculo de cross-spectra
90 #calculo de cross-spectra
91 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
91 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
92 for pair in self.dataOut.pairsList:
92 for pair in self.dataOut.pairsList:
93 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
93 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
94 pairIndex += 1
94 pairIndex += 1
95 blocksize += cspc.size
95 blocksize += cspc.size
96
96
97 self.dataOut.data_spc = spc
97 self.dataOut.data_spc = spc
98 self.dataOut.data_cspc = cspc
98 self.dataOut.data_cspc = cspc
99 self.dataOut.data_dc = dc
99 self.dataOut.data_dc = dc
100 self.dataOut.blockSize = blocksize
100 self.dataOut.blockSize = blocksize
101 self.dataOut.flagShiftFFT = False
101 self.dataOut.flagShiftFFT = False
102
102
103 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
103 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
104
104
105 self.dataOut.flagNoData = True
105 self.dataOut.flagNoData = True
106
106
107 if self.dataIn.type == "Spectra":
107 if self.dataIn.type == "Spectra":
108 self.dataOut.copy(self.dataIn)
108 self.dataOut.copy(self.dataIn)
109 return True
109 return True
110
110
111 if self.dataIn.type == "Voltage":
111 if self.dataIn.type == "Voltage":
112
112
113 if nFFTPoints == None:
113 if nFFTPoints == None:
114 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
114 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
115
115
116 if nProfiles == None:
116 if nProfiles == None:
117 raise ValueError, "This SpectraProc.run() need nProfiles input variable"
117 raise ValueError, "This SpectraProc.run() need nProfiles input variable"
118
118
119
119
120 if ippFactor == None:
120 if ippFactor == None:
121 ippFactor = 1
121 ippFactor = 1
122 self.dataOut.ippFactor = ippFactor
122 self.dataOut.ippFactor = ippFactor
123
123
124 self.dataOut.nFFTPoints = nFFTPoints
124 self.dataOut.nFFTPoints = nFFTPoints
125 self.dataOut.pairsList = pairsList
125 self.dataOut.pairsList = pairsList
126
126
127 if self.buffer == None:
127 if self.buffer == None:
128 self.buffer = numpy.zeros((self.dataIn.nChannels,
128 self.buffer = numpy.zeros((self.dataIn.nChannels,
129 nProfiles,
129 nProfiles,
130 self.dataIn.nHeights),
130 self.dataIn.nHeights),
131 dtype='complex')
131 dtype='complex')
132 self.id_min = 0
132 self.id_min = 0
133 self.id_max = self.dataIn.data.shape[1]
133 self.id_max = self.dataIn.data.shape[1]
134
134
135 if len(self.dataIn.data.shape) == 2:
135 if len(self.dataIn.data.shape) == 2:
136 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
136 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
137 self.profIndex += 1
137 self.profIndex += 1
138 else:
138 else:
139 if self.dataIn.data.shape[1] == nProfiles:
139 if self.dataIn.data.shape[1] == nProfiles:
140 self.buffer = self.dataIn.data.copy()
140 self.buffer = self.dataIn.data.copy()
141 self.profIndex = nProfiles
141 self.profIndex = nProfiles
142 elif self.dataIn.data.shape[1] < nProfiles:
142 elif self.dataIn.data.shape[1] < nProfiles:
143 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
143 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
144 self.profIndex += self.dataIn.data.shape[1]
144 self.profIndex += self.dataIn.data.shape[1]
145 self.id_min += self.dataIn.data.shape[1]
145 self.id_min += self.dataIn.data.shape[1]
146 self.id_max += self.dataIn.data.shape[1]
146 self.id_max += self.dataIn.data.shape[1]
147 else:
147 else:
148 raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
148 raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
149 self.dataOut.flagNoData = True
149 self.dataOut.flagNoData = True
150 return 0
150 return 0
151
151
152
152
153 if self.firstdatatime == None:
153 if self.firstdatatime == None:
154 self.firstdatatime = self.dataIn.utctime
154 self.firstdatatime = self.dataIn.utctime
155
155
156 if self.profIndex == nProfiles:
156 if self.profIndex == nProfiles:
157 self.__updateObjFromInput()
157 self.__updateObjFromInput()
158 self.__getFft()
158 self.__getFft()
159
159
160 self.dataOut.flagNoData = False
160 self.dataOut.flagNoData = False
161
161
162 self.buffer = None
162 self.buffer = None
163 self.firstdatatime = None
163 self.firstdatatime = None
164 self.profIndex = 0
164 self.profIndex = 0
165
165
166 return True
166 return True
167
167
168 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
168 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
169
169
170 def selectChannels(self, channelList):
170 def selectChannels(self, channelList):
171
171
172 channelIndexList = []
172 channelIndexList = []
173
173
174 for channel in channelList:
174 for channel in channelList:
175 index = self.dataOut.channelList.index(channel)
175 index = self.dataOut.channelList.index(channel)
176 channelIndexList.append(index)
176 channelIndexList.append(index)
177
177
178 self.selectChannelsByIndex(channelIndexList)
178 self.selectChannelsByIndex(channelIndexList)
179
179
180 def selectChannelsByIndex(self, channelIndexList):
180 def selectChannelsByIndex(self, channelIndexList):
181 """
181 """
182 Selecciona un bloque de datos en base a canales segun el channelIndexList
182 Selecciona un bloque de datos en base a canales segun el channelIndexList
183
183
184 Input:
184 Input:
185 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
185 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
186
186
187 Affected:
187 Affected:
188 self.dataOut.data_spc
188 self.dataOut.data_spc
189 self.dataOut.channelIndexList
189 self.dataOut.channelIndexList
190 self.dataOut.nChannels
190 self.dataOut.nChannels
191
191
192 Return:
192 Return:
193 None
193 None
194 """
194 """
195
195
196 for channelIndex in channelIndexList:
196 for channelIndex in channelIndexList:
197 if channelIndex not in self.dataOut.channelIndexList:
197 if channelIndex not in self.dataOut.channelIndexList:
198 print channelIndexList
198 print channelIndexList
199 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
199 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
200
200
201 # nChannels = len(channelIndexList)
201 # nChannels = len(channelIndexList)
202
202
203 data_spc = self.dataOut.data_spc[channelIndexList,:]
203 data_spc = self.dataOut.data_spc[channelIndexList,:]
204
204
205 self.dataOut.data_spc = data_spc
205 self.dataOut.data_spc = data_spc
206 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
206 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
207 # self.dataOut.nChannels = nChannels
207 # self.dataOut.nChannels = nChannels
208
208
209 return 1
209 return 1
210
210
211 def selectHeights(self, minHei, maxHei):
211 def selectHeights(self, minHei, maxHei):
212 """
212 """
213 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
213 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
214 minHei <= height <= maxHei
214 minHei <= height <= maxHei
215
215
216 Input:
216 Input:
217 minHei : valor minimo de altura a considerar
217 minHei : valor minimo de altura a considerar
218 maxHei : valor maximo de altura a considerar
218 maxHei : valor maximo de altura a considerar
219
219
220 Affected:
220 Affected:
221 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
221 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
222
222
223 Return:
223 Return:
224 1 si el metodo se ejecuto con exito caso contrario devuelve 0
224 1 si el metodo se ejecuto con exito caso contrario devuelve 0
225 """
225 """
226 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
226 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
227 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
227 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
228
228
229 if (maxHei > self.dataOut.heightList[-1]):
229 if (maxHei > self.dataOut.heightList[-1]):
230 maxHei = self.dataOut.heightList[-1]
230 maxHei = self.dataOut.heightList[-1]
231 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
231 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
232
232
233 minIndex = 0
233 minIndex = 0
234 maxIndex = 0
234 maxIndex = 0
235 heights = self.dataOut.heightList
235 heights = self.dataOut.heightList
236
236
237 inda = numpy.where(heights >= minHei)
237 inda = numpy.where(heights >= minHei)
238 indb = numpy.where(heights <= maxHei)
238 indb = numpy.where(heights <= maxHei)
239
239
240 try:
240 try:
241 minIndex = inda[0][0]
241 minIndex = inda[0][0]
242 except:
242 except:
243 minIndex = 0
243 minIndex = 0
244
244
245 try:
245 try:
246 maxIndex = indb[0][-1]
246 maxIndex = indb[0][-1]
247 except:
247 except:
248 maxIndex = len(heights)
248 maxIndex = len(heights)
249
249
250 self.selectHeightsByIndex(minIndex, maxIndex)
250 self.selectHeightsByIndex(minIndex, maxIndex)
251
251
252 return 1
252 return 1
253
253
254 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
254 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
255 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
255 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
256
256
257 if hei_ref != None:
257 if hei_ref != None:
258 newheis = numpy.where(self.dataOut.heightList>hei_ref)
258 newheis = numpy.where(self.dataOut.heightList>hei_ref)
259
259
260 minIndex = min(newheis[0])
260 minIndex = min(newheis[0])
261 maxIndex = max(newheis[0])
261 maxIndex = max(newheis[0])
262 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
262 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
263 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
263 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
264
264
265 # determina indices
265 # determina indices
266 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
266 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
267 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
267 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
268 beacon_dB = numpy.sort(avg_dB)[-nheis:]
268 beacon_dB = numpy.sort(avg_dB)[-nheis:]
269 beacon_heiIndexList = []
269 beacon_heiIndexList = []
270 for val in avg_dB.tolist():
270 for val in avg_dB.tolist():
271 if val >= beacon_dB[0]:
271 if val >= beacon_dB[0]:
272 beacon_heiIndexList.append(avg_dB.tolist().index(val))
272 beacon_heiIndexList.append(avg_dB.tolist().index(val))
273
273
274 #data_spc = data_spc[:,:,beacon_heiIndexList]
274 #data_spc = data_spc[:,:,beacon_heiIndexList]
275 data_cspc = None
275 data_cspc = None
276 if self.dataOut.data_cspc != None:
276 if self.dataOut.data_cspc != None:
277 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
277 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
278 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
278 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
279
279
280 data_dc = None
280 data_dc = None
281 if self.dataOut.data_dc != None:
281 if self.dataOut.data_dc != None:
282 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
282 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
283 #data_dc = data_dc[:,beacon_heiIndexList]
283 #data_dc = data_dc[:,beacon_heiIndexList]
284
284
285 self.dataOut.data_spc = data_spc
285 self.dataOut.data_spc = data_spc
286 self.dataOut.data_cspc = data_cspc
286 self.dataOut.data_cspc = data_cspc
287 self.dataOut.data_dc = data_dc
287 self.dataOut.data_dc = data_dc
288 self.dataOut.heightList = heightList
288 self.dataOut.heightList = heightList
289 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
289 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
290
290
291 return 1
291 return 1
292
292
293
293
294 def selectHeightsByIndex(self, minIndex, maxIndex):
294 def selectHeightsByIndex(self, minIndex, maxIndex):
295 """
295 """
296 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
296 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
297 minIndex <= index <= maxIndex
297 minIndex <= index <= maxIndex
298
298
299 Input:
299 Input:
300 minIndex : valor de indice minimo de altura a considerar
300 minIndex : valor de indice minimo de altura a considerar
301 maxIndex : valor de indice maximo de altura a considerar
301 maxIndex : valor de indice maximo de altura a considerar
302
302
303 Affected:
303 Affected:
304 self.dataOut.data_spc
304 self.dataOut.data_spc
305 self.dataOut.data_cspc
305 self.dataOut.data_cspc
306 self.dataOut.data_dc
306 self.dataOut.data_dc
307 self.dataOut.heightList
307 self.dataOut.heightList
308
308
309 Return:
309 Return:
310 1 si el metodo se ejecuto con exito caso contrario devuelve 0
310 1 si el metodo se ejecuto con exito caso contrario devuelve 0
311 """
311 """
312
312
313 if (minIndex < 0) or (minIndex > maxIndex):
313 if (minIndex < 0) or (minIndex > maxIndex):
314 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
314 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
315
315
316 if (maxIndex >= self.dataOut.nHeights):
316 if (maxIndex >= self.dataOut.nHeights):
317 maxIndex = self.dataOut.nHeights-1
317 maxIndex = self.dataOut.nHeights-1
318 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
318 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
319
319
320 # nHeights = maxIndex - minIndex + 1
320 # nHeights = maxIndex - minIndex + 1
321
321
322 #Spectra
322 #Spectra
323 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
323 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
324
324
325 data_cspc = None
325 data_cspc = None
326 if self.dataOut.data_cspc != None:
326 if self.dataOut.data_cspc != None:
327 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
327 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
328
328
329 data_dc = None
329 data_dc = None
330 if self.dataOut.data_dc != None:
330 if self.dataOut.data_dc != None:
331 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
331 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
332
332
333 self.dataOut.data_spc = data_spc
333 self.dataOut.data_spc = data_spc
334 self.dataOut.data_cspc = data_cspc
334 self.dataOut.data_cspc = data_cspc
335 self.dataOut.data_dc = data_dc
335 self.dataOut.data_dc = data_dc
336
336
337 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
337 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
338
338
339 return 1
339 return 1
340
340
341 def removeDC(self, mode = 2):
341 def removeDC(self, mode = 2):
342 jspectra = self.dataOut.data_spc
342 jspectra = self.dataOut.data_spc
343 jcspectra = self.dataOut.data_cspc
343 jcspectra = self.dataOut.data_cspc
344
344
345
345
346 num_chan = jspectra.shape[0]
346 num_chan = jspectra.shape[0]
347 num_hei = jspectra.shape[2]
347 num_hei = jspectra.shape[2]
348
348
349 if jcspectra != None:
349 if jcspectra != None:
350 jcspectraExist = True
350 jcspectraExist = True
351 num_pairs = jcspectra.shape[0]
351 num_pairs = jcspectra.shape[0]
352 else: jcspectraExist = False
352 else: jcspectraExist = False
353
353
354 freq_dc = jspectra.shape[1]/2
354 freq_dc = jspectra.shape[1]/2
355 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
355 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
356
356
357 if ind_vel[0]<0:
357 if ind_vel[0]<0:
358 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
358 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
359
359
360 if mode == 1:
360 if mode == 1:
361 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
361 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
362
362
363 if jcspectraExist:
363 if jcspectraExist:
364 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
364 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
365
365
366 if mode == 2:
366 if mode == 2:
367
367
368 vel = numpy.array([-2,-1,1,2])
368 vel = numpy.array([-2,-1,1,2])
369 xx = numpy.zeros([4,4])
369 xx = numpy.zeros([4,4])
370
370
371 for fil in range(4):
371 for fil in range(4):
372 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
372 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
373
373
374 xx_inv = numpy.linalg.inv(xx)
374 xx_inv = numpy.linalg.inv(xx)
375 xx_aux = xx_inv[0,:]
375 xx_aux = xx_inv[0,:]
376
376
377 for ich in range(num_chan):
377 for ich in range(num_chan):
378 yy = jspectra[ich,ind_vel,:]
378 yy = jspectra[ich,ind_vel,:]
379 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
379 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
380
380
381 junkid = jspectra[ich,freq_dc,:]<=0
381 junkid = jspectra[ich,freq_dc,:]<=0
382 cjunkid = sum(junkid)
382 cjunkid = sum(junkid)
383
383
384 if cjunkid.any():
384 if cjunkid.any():
385 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
385 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
386
386
387 if jcspectraExist:
387 if jcspectraExist:
388 for ip in range(num_pairs):
388 for ip in range(num_pairs):
389 yy = jcspectra[ip,ind_vel,:]
389 yy = jcspectra[ip,ind_vel,:]
390 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
390 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
391
391
392
392
393 self.dataOut.data_spc = jspectra
393 self.dataOut.data_spc = jspectra
394 self.dataOut.data_cspc = jcspectra
394 self.dataOut.data_cspc = jcspectra
395
395
396 return 1
396 return 1
397
397
398 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
398 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
399
399
400 jspectra = self.dataOut.data_spc
400 jspectra = self.dataOut.data_spc
401 jcspectra = self.dataOut.data_cspc
401 jcspectra = self.dataOut.data_cspc
402 jnoise = self.dataOut.getNoise()
402 jnoise = self.dataOut.getNoise()
403 num_incoh = self.dataOut.nIncohInt
403 num_incoh = self.dataOut.nIncohInt
404
404
405 num_channel = jspectra.shape[0]
405 num_channel = jspectra.shape[0]
406 num_prof = jspectra.shape[1]
406 num_prof = jspectra.shape[1]
407 num_hei = jspectra.shape[2]
407 num_hei = jspectra.shape[2]
408
408
409 #hei_interf
409 #hei_interf
410 if hei_interf == None:
410 if hei_interf == None:
411 count_hei = num_hei/2 #Como es entero no importa
411 count_hei = num_hei/2 #Como es entero no importa
412 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
412 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
413 hei_interf = numpy.asarray(hei_interf)[0]
413 hei_interf = numpy.asarray(hei_interf)[0]
414 #nhei_interf
414 #nhei_interf
415 if (nhei_interf == None):
415 if (nhei_interf == None):
416 nhei_interf = 5
416 nhei_interf = 5
417 if (nhei_interf < 1):
417 if (nhei_interf < 1):
418 nhei_interf = 1
418 nhei_interf = 1
419 if (nhei_interf > count_hei):
419 if (nhei_interf > count_hei):
420 nhei_interf = count_hei
420 nhei_interf = count_hei
421 if (offhei_interf == None):
421 if (offhei_interf == None):
422 offhei_interf = 0
422 offhei_interf = 0
423
423
424 ind_hei = range(num_hei)
424 ind_hei = range(num_hei)
425 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
425 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
426 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
426 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
427 mask_prof = numpy.asarray(range(num_prof))
427 mask_prof = numpy.asarray(range(num_prof))
428 num_mask_prof = mask_prof.size
428 num_mask_prof = mask_prof.size
429 comp_mask_prof = [0, num_prof/2]
429 comp_mask_prof = [0, num_prof/2]
430
430
431
431
432 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
432 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
433 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
433 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
434 jnoise = numpy.nan
434 jnoise = numpy.nan
435 noise_exist = jnoise[0] < numpy.Inf
435 noise_exist = jnoise[0] < numpy.Inf
436
436
437 #Subrutina de Remocion de la Interferencia
437 #Subrutina de Remocion de la Interferencia
438 for ich in range(num_channel):
438 for ich in range(num_channel):
439 #Se ordena los espectros segun su potencia (menor a mayor)
439 #Se ordena los espectros segun su potencia (menor a mayor)
440 power = jspectra[ich,mask_prof,:]
440 power = jspectra[ich,mask_prof,:]
441 power = power[:,hei_interf]
441 power = power[:,hei_interf]
442 power = power.sum(axis = 0)
442 power = power.sum(axis = 0)
443 psort = power.ravel().argsort()
443 psort = power.ravel().argsort()
444
444
445 #Se estima la interferencia promedio en los Espectros de Potencia empleando
445 #Se estima la interferencia promedio en los Espectros de Potencia empleando
446 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
446 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
447
447
448 if noise_exist:
448 if noise_exist:
449 # tmp_noise = jnoise[ich] / num_prof
449 # tmp_noise = jnoise[ich] / num_prof
450 tmp_noise = jnoise[ich]
450 tmp_noise = jnoise[ich]
451 junkspc_interf = junkspc_interf - tmp_noise
451 junkspc_interf = junkspc_interf - tmp_noise
452 #junkspc_interf[:,comp_mask_prof] = 0
452 #junkspc_interf[:,comp_mask_prof] = 0
453
453
454 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
454 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
455 jspc_interf = jspc_interf.transpose()
455 jspc_interf = jspc_interf.transpose()
456 #Calculando el espectro de interferencia promedio
456 #Calculando el espectro de interferencia promedio
457 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
457 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
458 noiseid = noiseid[0]
458 noiseid = noiseid[0]
459 cnoiseid = noiseid.size
459 cnoiseid = noiseid.size
460 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
460 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
461 interfid = interfid[0]
461 interfid = interfid[0]
462 cinterfid = interfid.size
462 cinterfid = interfid.size
463
463
464 if (cnoiseid > 0): jspc_interf[noiseid] = 0
464 if (cnoiseid > 0): jspc_interf[noiseid] = 0
465
465
466 #Expandiendo los perfiles a limpiar
466 #Expandiendo los perfiles a limpiar
467 if (cinterfid > 0):
467 if (cinterfid > 0):
468 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
468 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
469 new_interfid = numpy.asarray(new_interfid)
469 new_interfid = numpy.asarray(new_interfid)
470 new_interfid = {x for x in new_interfid}
470 new_interfid = {x for x in new_interfid}
471 new_interfid = numpy.array(list(new_interfid))
471 new_interfid = numpy.array(list(new_interfid))
472 new_cinterfid = new_interfid.size
472 new_cinterfid = new_interfid.size
473 else: new_cinterfid = 0
473 else: new_cinterfid = 0
474
474
475 for ip in range(new_cinterfid):
475 for ip in range(new_cinterfid):
476 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
476 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
477 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
477 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
478
478
479
479
480 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
480 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
481
481
482 #Removiendo la interferencia del punto de mayor interferencia
482 #Removiendo la interferencia del punto de mayor interferencia
483 ListAux = jspc_interf[mask_prof].tolist()
483 ListAux = jspc_interf[mask_prof].tolist()
484 maxid = ListAux.index(max(ListAux))
484 maxid = ListAux.index(max(ListAux))
485
485
486
486
487 if cinterfid > 0:
487 if cinterfid > 0:
488 for ip in range(cinterfid*(interf == 2) - 1):
488 for ip in range(cinterfid*(interf == 2) - 1):
489 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
489 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
490 cind = len(ind)
490 cind = len(ind)
491
491
492 if (cind > 0):
492 if (cind > 0):
493 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
493 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
494
494
495 ind = numpy.array([-2,-1,1,2])
495 ind = numpy.array([-2,-1,1,2])
496 xx = numpy.zeros([4,4])
496 xx = numpy.zeros([4,4])
497
497
498 for id1 in range(4):
498 for id1 in range(4):
499 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
499 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
500
500
501 xx_inv = numpy.linalg.inv(xx)
501 xx_inv = numpy.linalg.inv(xx)
502 xx = xx_inv[:,0]
502 xx = xx_inv[:,0]
503 ind = (ind + maxid + num_mask_prof)%num_mask_prof
503 ind = (ind + maxid + num_mask_prof)%num_mask_prof
504 yy = jspectra[ich,mask_prof[ind],:]
504 yy = jspectra[ich,mask_prof[ind],:]
505 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
505 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
506
506
507
507
508 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
508 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
509 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
509 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
510
510
511 #Remocion de Interferencia en el Cross Spectra
511 #Remocion de Interferencia en el Cross Spectra
512 if jcspectra == None: return jspectra, jcspectra
512 if jcspectra == None: return jspectra, jcspectra
513 num_pairs = jcspectra.size/(num_prof*num_hei)
513 num_pairs = jcspectra.size/(num_prof*num_hei)
514 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
514 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
515
515
516 for ip in range(num_pairs):
516 for ip in range(num_pairs):
517
517
518 #-------------------------------------------
518 #-------------------------------------------
519
519
520 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
520 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
521 cspower = cspower[:,hei_interf]
521 cspower = cspower[:,hei_interf]
522 cspower = cspower.sum(axis = 0)
522 cspower = cspower.sum(axis = 0)
523
523
524 cspsort = cspower.ravel().argsort()
524 cspsort = cspower.ravel().argsort()
525 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
525 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
526 junkcspc_interf = junkcspc_interf.transpose()
526 junkcspc_interf = junkcspc_interf.transpose()
527 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
527 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
528
528
529 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
529 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
530
530
531 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
531 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
532 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
532 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
533 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
533 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
534
534
535 for iprof in range(num_prof):
535 for iprof in range(num_prof):
536 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
536 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
537 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
537 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
538
538
539 #Removiendo la Interferencia
539 #Removiendo la Interferencia
540 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
540 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
541
541
542 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
542 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
543 maxid = ListAux.index(max(ListAux))
543 maxid = ListAux.index(max(ListAux))
544
544
545 ind = numpy.array([-2,-1,1,2])
545 ind = numpy.array([-2,-1,1,2])
546 xx = numpy.zeros([4,4])
546 xx = numpy.zeros([4,4])
547
547
548 for id1 in range(4):
548 for id1 in range(4):
549 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
549 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
550
550
551 xx_inv = numpy.linalg.inv(xx)
551 xx_inv = numpy.linalg.inv(xx)
552 xx = xx_inv[:,0]
552 xx = xx_inv[:,0]
553
553
554 ind = (ind + maxid + num_mask_prof)%num_mask_prof
554 ind = (ind + maxid + num_mask_prof)%num_mask_prof
555 yy = jcspectra[ip,mask_prof[ind],:]
555 yy = jcspectra[ip,mask_prof[ind],:]
556 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
556 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
557
557
558 #Guardar Resultados
558 #Guardar Resultados
559 self.dataOut.data_spc = jspectra
559 self.dataOut.data_spc = jspectra
560 self.dataOut.data_cspc = jcspectra
560 self.dataOut.data_cspc = jcspectra
561
561
562 return 1
562 return 1
563
563
564 def setRadarFrequency(self, frequency=None):
564 def setRadarFrequency(self, frequency=None):
565 if frequency != None:
565 if frequency != None:
566 self.dataOut.frequency = frequency
566 self.dataOut.frequency = frequency
567
567
568 return 1
568 return 1
569
569
570 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
570 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
571 #validacion de rango
571 #validacion de rango
572 if minHei == None:
572 if minHei == None:
573 minHei = self.dataOut.heightList[0]
573 minHei = self.dataOut.heightList[0]
574
574
575 if maxHei == None:
575 if maxHei == None:
576 maxHei = self.dataOut.heightList[-1]
576 maxHei = self.dataOut.heightList[-1]
577
577
578 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
578 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
579 print 'minHei: %.2f is out of the heights range'%(minHei)
579 print 'minHei: %.2f is out of the heights range'%(minHei)
580 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
580 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
581 minHei = self.dataOut.heightList[0]
581 minHei = self.dataOut.heightList[0]
582
582
583 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
583 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
584 print 'maxHei: %.2f is out of the heights range'%(maxHei)
584 print 'maxHei: %.2f is out of the heights range'%(maxHei)
585 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
585 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
586 maxHei = self.dataOut.heightList[-1]
586 maxHei = self.dataOut.heightList[-1]
587
587
588 # validacion de velocidades
588 # validacion de velocidades
589 velrange = self.dataOut.getVelRange(1)
589 velrange = self.dataOut.getVelRange(1)
590
590
591 if minVel == None:
591 if minVel == None:
592 minVel = velrange[0]
592 minVel = velrange[0]
593
593
594 if maxVel == None:
594 if maxVel == None:
595 maxVel = velrange[-1]
595 maxVel = velrange[-1]
596
596
597 if (minVel < velrange[0]) or (minVel > maxVel):
597 if (minVel < velrange[0]) or (minVel > maxVel):
598 print 'minVel: %.2f is out of the velocity range'%(minVel)
598 print 'minVel: %.2f is out of the velocity range'%(minVel)
599 print 'minVel is setting to %.2f'%(velrange[0])
599 print 'minVel is setting to %.2f'%(velrange[0])
600 minVel = velrange[0]
600 minVel = velrange[0]
601
601
602 if (maxVel > velrange[-1]) or (maxVel < minVel):
602 if (maxVel > velrange[-1]) or (maxVel < minVel):
603 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
603 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
604 print 'maxVel is setting to %.2f'%(velrange[-1])
604 print 'maxVel is setting to %.2f'%(velrange[-1])
605 maxVel = velrange[-1]
605 maxVel = velrange[-1]
606
606
607 # seleccion de indices para rango
607 # seleccion de indices para rango
608 minIndex = 0
608 minIndex = 0
609 maxIndex = 0
609 maxIndex = 0
610 heights = self.dataOut.heightList
610 heights = self.dataOut.heightList
611
611
612 inda = numpy.where(heights >= minHei)
612 inda = numpy.where(heights >= minHei)
613 indb = numpy.where(heights <= maxHei)
613 indb = numpy.where(heights <= maxHei)
614
614
615 try:
615 try:
616 minIndex = inda[0][0]
616 minIndex = inda[0][0]
617 except:
617 except:
618 minIndex = 0
618 minIndex = 0
619
619
620 try:
620 try:
621 maxIndex = indb[0][-1]
621 maxIndex = indb[0][-1]
622 except:
622 except:
623 maxIndex = len(heights)
623 maxIndex = len(heights)
624
624
625 if (minIndex < 0) or (minIndex > maxIndex):
625 if (minIndex < 0) or (minIndex > maxIndex):
626 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
626 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
627
627
628 if (maxIndex >= self.dataOut.nHeights):
628 if (maxIndex >= self.dataOut.nHeights):
629 maxIndex = self.dataOut.nHeights-1
629 maxIndex = self.dataOut.nHeights-1
630
630
631 # seleccion de indices para velocidades
631 # seleccion de indices para velocidades
632 indminvel = numpy.where(velrange >= minVel)
632 indminvel = numpy.where(velrange >= minVel)
633 indmaxvel = numpy.where(velrange <= maxVel)
633 indmaxvel = numpy.where(velrange <= maxVel)
634 try:
634 try:
635 minIndexVel = indminvel[0][0]
635 minIndexVel = indminvel[0][0]
636 except:
636 except:
637 minIndexVel = 0
637 minIndexVel = 0
638
638
639 try:
639 try:
640 maxIndexVel = indmaxvel[0][-1]
640 maxIndexVel = indmaxvel[0][-1]
641 except:
641 except:
642 maxIndexVel = len(velrange)
642 maxIndexVel = len(velrange)
643
643
644 #seleccion del espectro
644 #seleccion del espectro
645 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
645 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
646 #estimacion de ruido
646 #estimacion de ruido
647 noise = numpy.zeros(self.dataOut.nChannels)
647 noise = numpy.zeros(self.dataOut.nChannels)
648
648
649 for channel in range(self.dataOut.nChannels):
649 for channel in range(self.dataOut.nChannels):
650 daux = data_spc[channel,:,:]
650 daux = data_spc[channel,:,:]
651 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
651 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
652
652
653 self.dataOut.noise_estimation = noise.copy()
653 self.dataOut.noise_estimation = noise.copy()
654
654
655 return 1
655 return 1
656
656
657 class IncohInt(Operation):
657 class IncohInt(Operation):
658
658
659
659
660 __profIndex = 0
660 __profIndex = 0
661 __withOverapping = False
661 __withOverapping = False
662
662
663 __byTime = False
663 __byTime = False
664 __initime = None
664 __initime = None
665 __lastdatatime = None
665 __lastdatatime = None
666 __integrationtime = None
666 __integrationtime = None
667
667
668 __buffer_spc = None
668 __buffer_spc = None
669 __buffer_cspc = None
669 __buffer_cspc = None
670 __buffer_dc = None
670 __buffer_dc = None
671
671
672 __dataReady = False
672 __dataReady = False
673
673
674 __timeInterval = None
674 __timeInterval = None
675
675
676 n = None
676 n = None
677
677
678
678
679
679
680 def __init__(self):
680 def __init__(self):
681
681
682 Operation.__init__(self)
682 Operation.__init__(self)
683 # self.isConfig = False
683 # self.isConfig = False
684
684
685 def setup(self, n=None, timeInterval=None, overlapping=False):
685 def setup(self, n=None, timeInterval=None, overlapping=False):
686 """
686 """
687 Set the parameters of the integration class.
687 Set the parameters of the integration class.
688
688
689 Inputs:
689 Inputs:
690
690
691 n : Number of coherent integrations
691 n : Number of coherent integrations
692 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
692 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
693 overlapping :
693 overlapping :
694
694
695 """
695 """
696
696
697 self.__initime = None
697 self.__initime = None
698 self.__lastdatatime = 0
698 self.__lastdatatime = 0
699 self.__buffer_spc = None
699 self.__buffer_spc = None
700 self.__buffer_cspc = None
700 self.__buffer_cspc = None
701 self.__buffer_dc = None
701 self.__buffer_dc = None
702 self.__dataReady = False
702 self.__dataReady = False
703
703
704
704
705 if n == None and timeInterval == None:
705 if n == None and timeInterval == None:
706 raise ValueError, "n or timeInterval should be specified ..."
706 raise ValueError, "n or timeInterval should be specified ..."
707
707
708 if n != None:
708 if n != None:
709 self.n = n
709 self.n = n
710 self.__byTime = False
710 self.__byTime = False
711 else:
711 else:
712 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
712 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
713 self.n = 9999
713 self.n = 9999
714 self.__byTime = True
714 self.__byTime = True
715
715
716 if overlapping:
716 if overlapping:
717 self.__withOverapping = True
717 self.__withOverapping = True
718 else:
718 else:
719 self.__withOverapping = False
719 self.__withOverapping = False
720 self.__buffer_spc = 0
720 self.__buffer_spc = 0
721 self.__buffer_cspc = 0
721 self.__buffer_cspc = 0
722 self.__buffer_dc = 0
722 self.__buffer_dc = 0
723
723
724 self.__profIndex = 0
724 self.__profIndex = 0
725
725
726 def putData(self, data_spc, data_cspc, data_dc):
726 def putData(self, data_spc, data_cspc, data_dc):
727
727
728 """
728 """
729 Add a profile to the __buffer_spc and increase in one the __profileIndex
729 Add a profile to the __buffer_spc and increase in one the __profileIndex
730
730
731 """
731 """
732
732
733 if not self.__withOverapping:
733 if not self.__withOverapping:
734 self.__buffer_spc += data_spc
734 self.__buffer_spc += data_spc
735
735
736 if data_cspc == None:
736 if data_cspc == None:
737 self.__buffer_cspc = None
737 self.__buffer_cspc = None
738 else:
738 else:
739 self.__buffer_cspc += data_cspc
739 self.__buffer_cspc += data_cspc
740
740
741 if data_dc == None:
741 if data_dc == None:
742 self.__buffer_dc = None
742 self.__buffer_dc = None
743 else:
743 else:
744 self.__buffer_dc += data_dc
744 self.__buffer_dc += data_dc
745
745
746 self.__profIndex += 1
746 self.__profIndex += 1
747 return
747 return
748
748
749 #Overlapping data
749 #Overlapping data
750 nChannels, nFFTPoints, nHeis = data_spc.shape
750 nChannels, nFFTPoints, nHeis = data_spc.shape
751 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
751 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
752 if data_cspc != None:
752 if data_cspc != None:
753 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
753 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
754 if data_dc != None:
754 if data_dc != None:
755 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
755 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
756
756
757 #If the buffer is empty then it takes the data value
757 #If the buffer is empty then it takes the data value
758 if self.__buffer_spc == None:
758 if self.__buffer_spc == None:
759 self.__buffer_spc = data_spc
759 self.__buffer_spc = data_spc
760
760
761 if data_cspc == None:
761 if data_cspc == None:
762 self.__buffer_cspc = None
762 self.__buffer_cspc = None
763 else:
763 else:
764 self.__buffer_cspc += data_cspc
764 self.__buffer_cspc += data_cspc
765
765
766 if data_dc == None:
766 if data_dc == None:
767 self.__buffer_dc = None
767 self.__buffer_dc = None
768 else:
768 else:
769 self.__buffer_dc += data_dc
769 self.__buffer_dc += data_dc
770
770
771 self.__profIndex += 1
771 self.__profIndex += 1
772 return
772 return
773
773
774 #If the buffer length is lower than n then stakcing the data value
774 #If the buffer length is lower than n then stakcing the data value
775 if self.__profIndex < self.n:
775 if self.__profIndex < self.n:
776 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
776 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
777
777
778 if data_cspc != None:
778 if data_cspc != None:
779 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
779 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
780
780
781 if data_dc != None:
781 if data_dc != None:
782 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
782 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
783
783
784 self.__profIndex += 1
784 self.__profIndex += 1
785 return
785 return
786
786
787 #If the buffer length is equal to n then replacing the last buffer value with the data value
787 #If the buffer length is equal to n then replacing the last buffer value with the data value
788 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
788 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
789 self.__buffer_spc[self.n-1] = data_spc
789 self.__buffer_spc[self.n-1] = data_spc
790
790
791 if data_cspc != None:
791 if data_cspc != None:
792 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
792 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
793 self.__buffer_cspc[self.n-1] = data_cspc
793 self.__buffer_cspc[self.n-1] = data_cspc
794
794
795 if data_dc != None:
795 if data_dc != None:
796 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
796 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
797 self.__buffer_dc[self.n-1] = data_dc
797 self.__buffer_dc[self.n-1] = data_dc
798
798
799 self.__profIndex = self.n
799 self.__profIndex = self.n
800 return
800 return
801
801
802
802
803 def pushData(self):
803 def pushData(self):
804 """
804 """
805 Return the sum of the last profiles and the profiles used in the sum.
805 Return the sum of the last profiles and the profiles used in the sum.
806
806
807 Affected:
807 Affected:
808
808
809 self.__profileIndex
809 self.__profileIndex
810
810
811 """
811 """
812 data_spc = None
812 data_spc = None
813 data_cspc = None
813 data_cspc = None
814 data_dc = None
814 data_dc = None
815
815
816 if not self.__withOverapping:
816 if not self.__withOverapping:
817 data_spc = self.__buffer_spc
817 data_spc = self.__buffer_spc
818 data_cspc = self.__buffer_cspc
818 data_cspc = self.__buffer_cspc
819 data_dc = self.__buffer_dc
819 data_dc = self.__buffer_dc
820
820
821 n = self.__profIndex
821 n = self.__profIndex
822
822
823 self.__buffer_spc = 0
823 self.__buffer_spc = 0
824 self.__buffer_cspc = 0
824 self.__buffer_cspc = 0
825 self.__buffer_dc = 0
825 self.__buffer_dc = 0
826 self.__profIndex = 0
826 self.__profIndex = 0
827
827
828 return data_spc, data_cspc, data_dc, n
828 return data_spc, data_cspc, data_dc, n
829
829
830 #Integration with Overlapping
830 #Integration with Overlapping
831 data_spc = numpy.sum(self.__buffer_spc, axis=0)
831 data_spc = numpy.sum(self.__buffer_spc, axis=0)
832
832
833 if self.__buffer_cspc != None:
833 if self.__buffer_cspc != None:
834 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
834 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
835
835
836 if self.__buffer_dc != None:
836 if self.__buffer_dc != None:
837 data_dc = numpy.sum(self.__buffer_dc, axis=0)
837 data_dc = numpy.sum(self.__buffer_dc, axis=0)
838
838
839 n = self.__profIndex
839 n = self.__profIndex
840
840
841 return data_spc, data_cspc, data_dc, n
841 return data_spc, data_cspc, data_dc, n
842
842
843 def byProfiles(self, *args):
843 def byProfiles(self, *args):
844
844
845 self.__dataReady = False
845 self.__dataReady = False
846 avgdata_spc = None
846 avgdata_spc = None
847 avgdata_cspc = None
847 avgdata_cspc = None
848 avgdata_dc = None
848 avgdata_dc = None
849 # n = None
849 # n = None
850
850
851 self.putData(*args)
851 self.putData(*args)
852
852
853 if self.__profIndex == self.n:
853 if self.__profIndex == self.n:
854
854
855 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
855 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
856 self.__dataReady = True
856 self.__dataReady = True
857
857
858 return avgdata_spc, avgdata_cspc, avgdata_dc
858 return avgdata_spc, avgdata_cspc, avgdata_dc
859
859
860 def byTime(self, datatime, *args):
860 def byTime(self, datatime, *args):
861
861
862 self.__dataReady = False
862 self.__dataReady = False
863 avgdata_spc = None
863 avgdata_spc = None
864 avgdata_cspc = None
864 avgdata_cspc = None
865 avgdata_dc = None
865 avgdata_dc = None
866 n = None
866 n = None
867
867
868 self.putData(*args)
868 self.putData(*args)
869
869
870 if (datatime - self.__initime) >= self.__integrationtime:
870 if (datatime - self.__initime) >= self.__integrationtime:
871 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
871 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
872 self.n = n
872 self.n = n
873 self.__dataReady = True
873 self.__dataReady = True
874
874
875 return avgdata_spc, avgdata_cspc, avgdata_dc
875 return avgdata_spc, avgdata_cspc, avgdata_dc
876
876
877 def integrate(self, datatime, *args):
877 def integrate(self, datatime, *args):
878
878
879 if self.__initime == None:
879 if self.__initime == None:
880 self.__initime = datatime
880 self.__initime = datatime
881
881
882 if self.__byTime:
882 if self.__byTime:
883 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
883 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
884 else:
884 else:
885 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
885 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
886
886
887 self.__lastdatatime = datatime
887 self.__lastdatatime = datatime
888
888
889 if avgdata_spc == None:
889 if avgdata_spc == None:
890 return None, None, None, None
890 return None, None, None, None
891
891
892 avgdatatime = self.__initime
892 avgdatatime = self.__initime
893 try:
893 try:
894 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
894 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
895 except:
895 except:
896 self.__timeInterval = self.__lastdatatime - self.__initime
896 self.__timeInterval = self.__lastdatatime - self.__initime
897
897
898 deltatime = datatime -self.__lastdatatime
898 deltatime = datatime -self.__lastdatatime
899
899
900 if not self.__withOverapping:
900 if not self.__withOverapping:
901 self.__initime = datatime
901 self.__initime = datatime
902 else:
902 else:
903 self.__initime += deltatime
903 self.__initime += deltatime
904
904
905 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
905 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
906
906
907 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
907 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
908
908
909 if n==1:
909 if n==1:
910 dataOut.flagNoData = False
910 dataOut.flagNoData = False
911 return
911 return
912
912
913 if not self.isConfig:
913 if not self.isConfig:
914 self.setup(n, timeInterval, overlapping)
914 self.setup(n, timeInterval, overlapping)
915 self.isConfig = True
915 self.isConfig = True
916
916
917 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
917 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
918 dataOut.data_spc,
918 dataOut.data_spc,
919 dataOut.data_cspc,
919 dataOut.data_cspc,
920 dataOut.data_dc)
920 dataOut.data_dc)
921
921
922 # dataOut.timeInterval *= n
922 # dataOut.timeInterval *= n
923 dataOut.flagNoData = True
923 dataOut.flagNoData = True
924
924
925 if self.__dataReady:
925 if self.__dataReady:
926
926
927 dataOut.data_spc = avgdata_spc
927 dataOut.data_spc = avgdata_spc
928 dataOut.data_cspc = avgdata_cspc
928 dataOut.data_cspc = avgdata_cspc
929 dataOut.data_dc = avgdata_dc
929 dataOut.data_dc = avgdata_dc
930
930
931 dataOut.nIncohInt *= self.n
931 dataOut.nIncohInt *= self.n
932 dataOut.utctime = avgdatatime
932 dataOut.utctime = avgdatatime
933 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
933 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
934 dataOut.timeInterval = self.__timeInterval*self.n
934 # dataOut.timeInterval = self.__timeInterval*self.n
935 dataOut.flagNoData = False
935 dataOut.flagNoData = False
General Comments 0
You need to be logged in to leave comments. Login now