##// END OF EJS Templates
Miguel Valdez -
r102:0886b164077e
parent child
Show More
@@ -1,553 +1,548
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9
9
10 path = os.path.split(os.getcwd())[0]
10 path = os.path.split(os.getcwd())[0]
11 sys.path.append(path)
11 sys.path.append(path)
12
12
13 from Model.Spectra import Spectra
13 from Model.Spectra import Spectra
14 from IO.SpectraIO import SpectraWriter
14 from IO.SpectraIO import SpectraWriter
15 from Graphics.SpectraPlot import Spectrum
15 from Graphics.SpectraPlot import Spectrum
16
16
17
17
18 class SpectraProcessor:
18 class SpectraProcessor:
19 '''
19 '''
20 classdocs
20 classdocs
21 '''
21 '''
22
22
23 dataInObj = None
23 dataInObj = None
24
24
25 dataOutObj = None
25 dataOutObj = None
26
26
27 integratorObjIndex = None
27 integratorObjIndex = None
28
28
29 decoderObjIndex = None
29 decoderObjIndex = None
30
30
31 writerObjIndex = None
31 writerObjIndex = None
32
32
33 plotterObjIndex = None
33 plotterObjIndex = None
34
34
35 integratorObjList = []
35 integratorObjList = []
36
36
37 decoderObjList = []
37 decoderObjList = []
38
38
39 writerObjList = []
39 writerObjList = []
40
40
41 plotterObjList = []
41 plotterObjList = []
42
42
43 buffer = None
43 buffer = None
44
44
45 ptsId = 0
45 ptsId = 0
46
46
47 nFFTPoints = None
47 nFFTPoints = None
48
48
49 pairList = None
49 pairList = None
50 m_Spectra= Spectra()
51
52 m_Voltage= Voltage()
53
54 m_IncoherentIntegration= IncoherentIntegration()
55
50
56
51
57 def __init__(self, dataInObj, dataOutObj=None):
52 def __init__(self, dataInObj, dataOutObj=None):
58 '''
53 '''
59 Constructor
54 Constructor
60 '''
55 '''
61 self.dataInObj = dataInObj
56 self.dataInObj = dataInObj
62
57
63 if dataOutObj == None:
58 if dataOutObj == None:
64 self.dataOutObj = Spectra()
59 self.dataOutObj = Spectra()
65 else:
60 else:
66 self.dataOutObj = dataOutObj
61 self.dataOutObj = dataOutObj
67
62
68 self.integratorObjIndex = None
63 self.integratorObjIndex = None
69 self.decoderObjIndex = None
64 self.decoderObjIndex = None
70 self.writerObjIndex = None
65 self.writerObjIndex = None
71 self.plotterObjIndex = None
66 self.plotterObjIndex = None
72
67
73 self.integratorObjList = []
68 self.integratorObjList = []
74 self.decoderObjList = []
69 self.decoderObjList = []
75 self.writerObjList = []
70 self.writerObjList = []
76 self.plotterObjList = []
71 self.plotterObjList = []
77
72
78 self.buffer = None
73 self.buffer = None
79 self.ptsId = 0
74 self.ptsId = 0
80
75
81 def init(self, nFFTPoints, pairList=None):
76 def init(self, nFFTPoints, pairList=None):
82
77
83 self.integratorObjIndex = 0
78 self.integratorObjIndex = 0
84 self.decoderObjIndex = 0
79 self.decoderObjIndex = 0
85 self.writerObjIndex = 0
80 self.writerObjIndex = 0
86 self.plotterObjIndex = 0
81 self.plotterObjIndex = 0
87
82
88 if nFFTPoints == None:
83 if nFFTPoints == None:
89 nFFTPoints = self.dataOutObj.nFFTPoints
84 nFFTPoints = self.dataOutObj.nFFTPoints
90
85
91 self.nFFTPoints = nFFTPoints
86 self.nFFTPoints = nFFTPoints
92 self.pairList = pairList
87 self.pairList = pairList
93
88
94 if not( isinstance(self.dataInObj, Spectra) ):
89 if not( isinstance(self.dataInObj, Spectra) ):
95 self.__getFft()
90 self.__getFft()
96 else:
91 else:
97 self.dataOutObj.copy(self.dataInObj)
92 self.dataOutObj.copy(self.dataInObj)
98
93
99
94
100 def __getFft(self):
95 def __getFft(self):
101 """
96 """
102 Convierte valores de Voltaje a Spectra
97 Convierte valores de Voltaje a Spectra
103
98
104 Affected:
99 Affected:
105 self.dataOutObj.data_spc
100 self.dataOutObj.data_spc
106 self.dataOutObj.data_cspc
101 self.dataOutObj.data_cspc
107 self.dataOutObj.data_dc
102 self.dataOutObj.data_dc
108 self.dataOutObj.heightList
103 self.dataOutObj.heightList
109 self.dataOutObj.m_BasicHeader
104 self.dataOutObj.m_BasicHeader
110 self.dataOutObj.m_ProcessingHeader
105 self.dataOutObj.m_ProcessingHeader
111 self.dataOutObj.m_RadarControllerHeader
106 self.dataOutObj.m_RadarControllerHeader
112 self.dataOutObj.m_SystemHeader
107 self.dataOutObj.m_SystemHeader
113 self.ptsId
108 self.ptsId
114 self.buffer
109 self.buffer
115 self.dataOutObj.flagNoData
110 self.dataOutObj.flagNoData
116 self.dataOutObj.dataType
111 self.dataOutObj.dataType
117 self.dataOutObj.nPairs
112 self.dataOutObj.nPairs
118 self.dataOutObj.nChannels
113 self.dataOutObj.nChannels
119 self.dataOutObj.nProfiles
114 self.dataOutObj.nProfiles
120 self.dataOutObj.m_SystemHeader.numChannels
115 self.dataOutObj.m_SystemHeader.numChannels
121 self.dataOutObj.m_ProcessingHeader.totalSpectra
116 self.dataOutObj.m_ProcessingHeader.totalSpectra
122 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
117 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
123 self.dataOutObj.m_ProcessingHeader.numHeights
118 self.dataOutObj.m_ProcessingHeader.numHeights
124 self.dataOutObj.m_ProcessingHeader.spectraComb
119 self.dataOutObj.m_ProcessingHeader.spectraComb
125 self.dataOutObj.m_ProcessingHeader.shif_fft
120 self.dataOutObj.m_ProcessingHeader.shif_fft
126 """
121 """
127 blocksize = 0
122 blocksize = 0
128 nFFTPoints = self.nFFTPoints
123 nFFTPoints = self.nFFTPoints
129 nChannels, nheis = self.dataInObj.data.shape
124 nChannels, nheis = self.dataInObj.data.shape
130
125
131 if self.buffer == None:
126 if self.buffer == None:
132 self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex')
127 self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex')
133
128
134 self.buffer[:,self.ptsId,:] = self.dataInObj.data
129 self.buffer[:,self.ptsId,:] = self.dataInObj.data
135 self.ptsId += 1
130 self.ptsId += 1
136
131
137 if self.ptsId < self.dataOutObj.nFFTPoints:
132 if self.ptsId < self.dataOutObj.nFFTPoints:
138 self.dataOutObj.flagNoData = True
133 self.dataOutObj.flagNoData = True
139 return
134 return
140
135
141 fft_volt = numpy.fft.fft(self.buffer,axis=1)
136 fft_volt = numpy.fft.fft(self.buffer,axis=1)
142 dc = fft_volt[:,0,:]
137 dc = fft_volt[:,0,:]
143
138
144 #calculo de self-spectra
139 #calculo de self-spectra
145 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
140 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
146 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
141 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
147
142
148 blocksize += dc.size
143 blocksize += dc.size
149 blocksize += spc.size
144 blocksize += spc.size
150
145
151 cspc = None
146 cspc = None
152 nPair = 0
147 nPair = 0
153 if self.pairList != None:
148 if self.pairList != None:
154 #calculo de cross-spectra
149 #calculo de cross-spectra
155 nPairs = len(self.pairList)
150 nPairs = len(self.pairList)
156 cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex')
151 cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex')
157 for pair in self.pairList:
152 for pair in self.pairList:
158 cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
153 cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
159 nPair += 1
154 nPair += 1
160 blocksize += cspc.size
155 blocksize += cspc.size
161
156
162 self.dataOutObj.data_spc = spc
157 self.dataOutObj.data_spc = spc
163 self.dataOutObj.data_cspc = cspc
158 self.dataOutObj.data_cspc = cspc
164 self.dataOutObj.data_dc = dc
159 self.dataOutObj.data_dc = dc
165
160
166 self.ptsId = 0
161 self.ptsId = 0
167 self.buffer = None
162 self.buffer = None
168 self.dataOutObj.flagNoData = False
163 self.dataOutObj.flagNoData = False
169
164
170 self.dataOutObj.heightList = self.dataInObj.heightList
165 self.dataOutObj.heightList = self.dataInObj.heightList
171 self.dataOutObj.channelList = self.dataInObj.channelList
166 self.dataOutObj.channelList = self.dataInObj.channelList
172 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
167 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
173 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
168 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
174 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
169 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
175 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
170 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
176
171
177 self.dataOutObj.dataType = self.dataInObj.dataType
172 self.dataOutObj.dataType = self.dataInObj.dataType
178 self.dataOutObj.nPairs = nPair
173 self.dataOutObj.nPairs = nPair
179 self.dataOutObj.nChannels = nChannels
174 self.dataOutObj.nChannels = nChannels
180 self.dataOutObj.nProfiles = nFFTPoints
175 self.dataOutObj.nProfiles = nFFTPoints
181 self.dataOutObj.nHeights = nheis
176 self.dataOutObj.nHeights = nheis
182 self.dataOutObj.nFFTPoints = nFFTPoints
177 self.dataOutObj.nFFTPoints = nFFTPoints
183 #self.dataOutObj.data = None
178 #self.dataOutObj.data = None
184
179
185 self.dataOutObj.m_SystemHeader.numChannels = nChannels
180 self.dataOutObj.m_SystemHeader.numChannels = nChannels
186 self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints
181 self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints
187
182
188 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
183 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
189 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair
184 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair
190 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints
185 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints
191 self.dataOutObj.m_ProcessingHeader.numHeights = nheis
186 self.dataOutObj.m_ProcessingHeader.numHeights = nheis
192 self.dataOutObj.m_ProcessingHeader.shif_fft = True
187 self.dataOutObj.m_ProcessingHeader.shif_fft = True
193
188
194 spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1'))
189 spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1'))
195 k = 0
190 k = 0
196 for i in range( 0,nChannels*2,2 ):
191 for i in range( 0,nChannels*2,2 ):
197 spectraComb[i] = k
192 spectraComb[i] = k
198 spectraComb[i+1] = k
193 spectraComb[i+1] = k
199 k += 1
194 k += 1
200
195
201 k *= 2
196 k *= 2
202
197
203 if self.pairList != None:
198 if self.pairList != None:
204
199
205 for pair in self.pairList:
200 for pair in self.pairList:
206 spectraComb[k] = pair[0]
201 spectraComb[k] = pair[0]
207 spectraComb[k+1] = pair[1]
202 spectraComb[k+1] = pair[1]
208 k += 2
203 k += 2
209
204
210 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
205 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
211
206
212
207
213 def addWriter(self,wrpath):
208 def addWriter(self,wrpath):
214 objWriter = SpectraWriter(self.dataOutObj)
209 objWriter = SpectraWriter(self.dataOutObj)
215 objWriter.setup(wrpath)
210 objWriter.setup(wrpath)
216 self.writerObjList.append(objWriter)
211 self.writerObjList.append(objWriter)
217
212
218
213
219 def addPlotter(self, index=None):
214 def addPlotter(self, index=None):
220
215
221 if index==None:
216 if index==None:
222 index = self.plotterObjIndex
217 index = self.plotterObjIndex
223
218
224 plotObj = Spectrum(self.dataOutObj, index)
219 plotObj = Spectrum(self.dataOutObj, index)
225 self.plotterObjList.append(plotObj)
220 self.plotterObjList.append(plotObj)
226
221
227
222
228 def addIntegrator(self,N):
223 def addIntegrator(self,N):
229
224
230 objIncohInt = IncoherentIntegration(N)
225 objIncohInt = IncoherentIntegration(N)
231 self.integratorObjList.append(objIncohInt)
226 self.integratorObjList.append(objIncohInt)
232
227
233
228
234 def writeData(self, wrpath):
229 def writeData(self, wrpath):
235 if self.dataOutObj.flagNoData:
230 if self.dataOutObj.flagNoData:
236 return 0
231 return 0
237
232
238 if len(self.writerObjList) <= self.writerObjIndex:
233 if len(self.writerObjList) <= self.writerObjIndex:
239 self.addWriter(wrpath)
234 self.addWriter(wrpath)
240
235
241 self.writerObjList[self.writerObjIndex].putData()
236 self.writerObjList[self.writerObjIndex].putData()
242
237
243 self.writerObjIndex += 1
238 self.writerObjIndex += 1
244
239
245 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
240 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
246 if self.dataOutObj.flagNoData:
241 if self.dataOutObj.flagNoData:
247 return 0
242 return 0
248
243
249 if len(self.plotterObjList) <= self.plotterObjIndex:
244 if len(self.plotterObjList) <= self.plotterObjIndex:
250 self.addPlotter(index)
245 self.addPlotter(index)
251
246
252 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
247 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
253
248
254 self.plotterObjIndex += 1
249 self.plotterObjIndex += 1
255
250
256 def integrator(self, N):
251 def integrator(self, N):
257 if self.dataOutObj.flagNoData:
252 if self.dataOutObj.flagNoData:
258 return 0
253 return 0
259
254
260 if len(self.integratorObjList) <= self.integratorObjIndex:
255 if len(self.integratorObjList) <= self.integratorObjIndex:
261 self.addIntegrator(N)
256 self.addIntegrator(N)
262
257
263 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
258 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
264 myCohIntObj.exe(self.dataOutObj.data_spc)
259 myCohIntObj.exe(self.dataOutObj.data_spc)
265
260
266 if myCohIntObj.flag:
261 if myCohIntObj.flag:
267 self.dataOutObj.data_spc = myCohIntObj.data
262 self.dataOutObj.data_spc = myCohIntObj.data
268 self.dataOutObj.m_ProcessingHeader.incoherentInt *= N
263 self.dataOutObj.m_ProcessingHeader.incoherentInt *= N
269 self.dataOutObj.flagNoData = False
264 self.dataOutObj.flagNoData = False
270
265
271 else:
266 else:
272 self.dataOutObj.flagNoData = True
267 self.dataOutObj.flagNoData = True
273
268
274 self.integratorObjIndex += 1
269 self.integratorObjIndex += 1
275
270
276 def removeDC(self, type):
271 def removeDC(self, type):
277
272
278 if self.dataOutObj.flagNoData:
273 if self.dataOutObj.flagNoData:
279 return 0
274 return 0
280 pass
275 pass
281
276
282 def removeInterference(self):
277 def removeInterference(self):
283
278
284 if self.dataOutObj.flagNoData:
279 if self.dataOutObj.flagNoData:
285 return 0
280 return 0
286 pass
281 pass
287
282
288 def removeSatellites(self):
283 def removeSatellites(self):
289
284
290 if self.dataOutObj.flagNoData:
285 if self.dataOutObj.flagNoData:
291 return 0
286 return 0
292 pass
287 pass
293
288
294 def selectChannels(self, channelList, pairList=None):
289 def selectChannels(self, channelList, pairList=None):
295 """
290 """
296 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
291 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
297
292
298 Input:
293 Input:
299 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
294 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
300 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
295 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
301
296
302 Affected:
297 Affected:
303 self.dataOutObj.data_spc
298 self.dataOutObj.data_spc
304 self.dataOutObj.data_cspc
299 self.dataOutObj.data_cspc
305 self.dataOutObj.data_dc
300 self.dataOutObj.data_dc
306 self.dataOutObj.nChannels
301 self.dataOutObj.nChannels
307 self.dataOutObj.nPairs
302 self.dataOutObj.nPairs
308 self.dataOutObj.m_ProcessingHeader.spectraComb
303 self.dataOutObj.m_ProcessingHeader.spectraComb
309 self.dataOutObj.m_SystemHeader.numChannels
304 self.dataOutObj.m_SystemHeader.numChannels
310
305
311 Return:
306 Return:
312 None
307 None
313 """
308 """
314
309
315 if self.dataOutObj.flagNoData:
310 if self.dataOutObj.flagNoData:
316 return 0
311 return 0
317
312
318 channelIndexList = []
313 channelIndexList = []
319 for channel in channelList:
314 for channel in channelList:
320 if channel in self.dataOutObj.channelList:
315 if channel in self.dataOutObj.channelList:
321 index = self.dataOutObj.channelList.index(channel)
316 index = self.dataOutObj.channelList.index(channel)
322 channelIndexList.append(index)
317 channelIndexList.append(index)
323 continue
318 continue
324
319
325 raise ValueError, "The value %d in channelList is not valid" %channel
320 raise ValueError, "The value %d in channelList is not valid" %channel
326
321
327 nProfiles = self.dataOutObj.nProfiles
322 nProfiles = self.dataOutObj.nProfiles
328 #dataType = self.dataOutObj.dataType
323 #dataType = self.dataOutObj.dataType
329 nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights
324 nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights
330 blocksize = 0
325 blocksize = 0
331
326
332 #self spectra
327 #self spectra
333 nChannels = len(channelIndexList)
328 nChannels = len(channelIndexList)
334 spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] )
329 spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] )
335
330
336 for index, channel in enumerate(channelIndexList):
331 for index, channel in enumerate(channelIndexList):
337 spc[index,:,:] = self.dataOutObj.data_spc[index,:,:]
332 spc[index,:,:] = self.dataOutObj.data_spc[index,:,:]
338
333
339 #DC channel
334 #DC channel
340 dc = numpy.zeros( (nChannels,nHeights), dtype='complex' )
335 dc = numpy.zeros( (nChannels,nHeights), dtype='complex' )
341 for index, channel in enumerate(channelIndexList):
336 for index, channel in enumerate(channelIndexList):
342 dc[index,:] = self.dataOutObj.data_dc[channel,:]
337 dc[index,:] = self.dataOutObj.data_dc[channel,:]
343
338
344 blocksize += dc.size
339 blocksize += dc.size
345 blocksize += spc.size
340 blocksize += spc.size
346
341
347 nPairs = 0
342 nPairs = 0
348 cspc = None
343 cspc = None
349
344
350 if pairList == None:
345 if pairList == None:
351 pairList = self.pairList
346 pairList = self.pairList
352
347
353 if (pairList != None) and (self.dataOutObj.data_cspc != None):
348 if (pairList != None) and (self.dataOutObj.data_cspc != None):
354 #cross spectra
349 #cross spectra
355 nPairs = len(pairList)
350 nPairs = len(pairList)
356 cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' )
351 cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' )
357
352
358 spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb
353 spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb
359 totalSpectra = len(spectraComb)
354 totalSpectra = len(spectraComb)
360 nchan = self.dataOutObj.nChannels
355 nchan = self.dataOutObj.nChannels
361 pairIndexList = []
356 pairIndexList = []
362
357
363 for pair in pairList: #busco el par en la lista de pares del Spectra Combinations
358 for pair in pairList: #busco el par en la lista de pares del Spectra Combinations
364 for index in range(0,totalSpectra,2):
359 for index in range(0,totalSpectra,2):
365 if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]:
360 if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]:
366 pairIndexList.append( index/2 - nchan )
361 pairIndexList.append( index/2 - nchan )
367
362
368 for index, pair in enumerate(pairIndexList):
363 for index, pair in enumerate(pairIndexList):
369 cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:]
364 cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:]
370 blocksize += cspc.size
365 blocksize += cspc.size
371
366
372 else:
367 else:
373 pairList = self.pairList
368 pairList = self.pairList
374 cspc = self.dataOutObj.data_cspc
369 cspc = self.dataOutObj.data_cspc
375 if cspc != None:
370 if cspc != None:
376 blocksize += cspc.size
371 blocksize += cspc.size
377
372
378 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
373 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
379 i = 0
374 i = 0
380 for val in channelList:
375 for val in channelList:
381 spectraComb[i] = val
376 spectraComb[i] = val
382 spectraComb[i+1] = val
377 spectraComb[i+1] = val
383 i += 2
378 i += 2
384
379
385 if pairList != None:
380 if pairList != None:
386 for pair in pairList:
381 for pair in pairList:
387 spectraComb[i] = pair[0]
382 spectraComb[i] = pair[0]
388 spectraComb[i+1] = pair[1]
383 spectraComb[i+1] = pair[1]
389 i += 2
384 i += 2
390
385
391 self.dataOutObj.data_spc = spc
386 self.dataOutObj.data_spc = spc
392 self.dataOutObj.data_cspc = cspc
387 self.dataOutObj.data_cspc = cspc
393 self.dataOutObj.data_dc = dc
388 self.dataOutObj.data_dc = dc
394 self.dataOutObj.nChannels = nChannels
389 self.dataOutObj.nChannels = nChannels
395 self.dataOutObj.nPairs = nPairs
390 self.dataOutObj.nPairs = nPairs
396
391
397 self.dataOutObj.channelList = channelList
392 self.dataOutObj.channelList = channelList
398
393
399 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
394 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
400 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
395 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
401 self.dataOutObj.m_SystemHeader.numChannels = nChannels
396 self.dataOutObj.m_SystemHeader.numChannels = nChannels
402 self.dataOutObj.nChannels = nChannels
397 self.dataOutObj.nChannels = nChannels
403 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
398 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
404
399
405
400
406 def selectHeightsByValue(self, minHei, maxHei):
401 def selectHeightsByValue(self, minHei, maxHei):
407 """
402 """
408 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
403 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
409 minHei <= height <= maxHei
404 minHei <= height <= maxHei
410
405
411 Input:
406 Input:
412 minHei : valor minimo de altura a considerar
407 minHei : valor minimo de altura a considerar
413 maxHei : valor maximo de altura a considerar
408 maxHei : valor maximo de altura a considerar
414
409
415 Affected:
410 Affected:
416 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
411 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
417
412
418 Return:
413 Return:
419 None
414 None
420 """
415 """
421
416
422 if self.dataOutObj.flagNoData:
417 if self.dataOutObj.flagNoData:
423 return 0
418 return 0
424
419
425 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
420 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
426 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
421 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
427
422
428 if (maxHei > self.dataOutObj.heightList[-1]):
423 if (maxHei > self.dataOutObj.heightList[-1]):
429 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
424 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
430
425
431 minIndex = 0
426 minIndex = 0
432 maxIndex = 0
427 maxIndex = 0
433 data = self.dataOutObj.heightList
428 data = self.dataOutObj.heightList
434
429
435 for i,val in enumerate(data):
430 for i,val in enumerate(data):
436 if val < minHei:
431 if val < minHei:
437 continue
432 continue
438 else:
433 else:
439 minIndex = i;
434 minIndex = i;
440 break
435 break
441
436
442 for i,val in enumerate(data):
437 for i,val in enumerate(data):
443 if val <= maxHei:
438 if val <= maxHei:
444 maxIndex = i;
439 maxIndex = i;
445 else:
440 else:
446 break
441 break
447
442
448 self.selectHeightsByIndex(minIndex, maxIndex)
443 self.selectHeightsByIndex(minIndex, maxIndex)
449
444
450
445
451 def selectHeightsByIndex(self, minIndex, maxIndex):
446 def selectHeightsByIndex(self, minIndex, maxIndex):
452 """
447 """
453 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
448 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
454 minIndex <= index <= maxIndex
449 minIndex <= index <= maxIndex
455
450
456 Input:
451 Input:
457 minIndex : valor minimo de altura a considerar
452 minIndex : valor minimo de altura a considerar
458 maxIndex : valor maximo de altura a considerar
453 maxIndex : valor maximo de altura a considerar
459
454
460 Affected:
455 Affected:
461 self.dataOutObj.data_spc
456 self.dataOutObj.data_spc
462 self.dataOutObj.data_cspc
457 self.dataOutObj.data_cspc
463 self.dataOutObj.data_dc
458 self.dataOutObj.data_dc
464 self.dataOutObj.heightList
459 self.dataOutObj.heightList
465 self.dataOutObj.nHeights
460 self.dataOutObj.nHeights
466 self.dataOutObj.m_ProcessingHeader.numHeights
461 self.dataOutObj.m_ProcessingHeader.numHeights
467 self.dataOutObj.m_ProcessingHeader.blockSize
462 self.dataOutObj.m_ProcessingHeader.blockSize
468 self.dataOutObj.m_ProcessingHeader.firstHeight
463 self.dataOutObj.m_ProcessingHeader.firstHeight
469 self.dataOutObj.m_RadarControllerHeader.numHeights
464 self.dataOutObj.m_RadarControllerHeader.numHeights
470
465
471 Return:
466 Return:
472 None
467 None
473 """
468 """
474
469
475 if self.dataOutObj.flagNoData:
470 if self.dataOutObj.flagNoData:
476 return 0
471 return 0
477
472
478 if (minIndex < 0) or (minIndex > maxIndex):
473 if (minIndex < 0) or (minIndex > maxIndex):
479 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
474 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
480
475
481 if (maxIndex >= self.dataOutObj.nHeights):
476 if (maxIndex >= self.dataOutObj.nHeights):
482 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
477 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
483
478
484 nChannels = self.dataOutObj.nChannels
479 nChannels = self.dataOutObj.nChannels
485 nPairs = self.dataOutObj.nPairs
480 nPairs = self.dataOutObj.nPairs
486 nProfiles = self.dataOutObj.nProfiles
481 nProfiles = self.dataOutObj.nProfiles
487 dataType = self.dataOutObj.dataType
482 dataType = self.dataOutObj.dataType
488 nHeights = maxIndex - minIndex + 1
483 nHeights = maxIndex - minIndex + 1
489 blockSize = 0
484 blockSize = 0
490
485
491 #self spectra
486 #self spectra
492 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
487 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
493 blockSize += spc.size
488 blockSize += spc.size
494
489
495 #cross spectra
490 #cross spectra
496 cspc = None
491 cspc = None
497 if self.dataOutObj.data_cspc != None:
492 if self.dataOutObj.data_cspc != None:
498 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
493 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
499 blockSize += cspc.size
494 blockSize += cspc.size
500
495
501 #DC channel
496 #DC channel
502 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
497 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
503 blockSize += dc.size
498 blockSize += dc.size
504
499
505 self.dataOutObj.data_spc = spc
500 self.dataOutObj.data_spc = spc
506 if cspc != None:
501 if cspc != None:
507 self.dataOutObj.data_cspc = cspc
502 self.dataOutObj.data_cspc = cspc
508 self.dataOutObj.data_dc = dc
503 self.dataOutObj.data_dc = dc
509
504
510 firstHeight = self.dataOutObj.heightList[minIndex]
505 firstHeight = self.dataOutObj.heightList[minIndex]
511
506
512 self.dataOutObj.nHeights = nHeights
507 self.dataOutObj.nHeights = nHeights
513 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
508 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
514 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
509 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
515 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
510 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
516 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
511 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
517
512
518 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
513 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
519
514
520
515
521 class IncoherentIntegration:
516 class IncoherentIntegration:
522
517
523 profCounter = 1
518 profCounter = 1
524 data = None
519 data = None
525 buffer = None
520 buffer = None
526 flag = False
521 flag = False
527 nIncohInt = None
522 nIncohInt = None
528
523
529 def __init__(self, N):
524 def __init__(self, N):
530
525
531 self.profCounter = 1
526 self.profCounter = 1
532 self.data = None
527 self.data = None
533 self.buffer = None
528 self.buffer = None
534 self.flag = False
529 self.flag = False
535 self.nIncohInt = N
530 self.nIncohInt = N
536
531
537 def exe(self,data):
532 def exe(self,data):
538
533
539 if self.buffer == None:
534 if self.buffer == None:
540 self.buffer = data
535 self.buffer = data
541 else:
536 else:
542 self.buffer = self.buffer + data
537 self.buffer = self.buffer + data
543
538
544 if self.profCounter == self.nIncohInt:
539 if self.profCounter == self.nIncohInt:
545 self.data = self.buffer
540 self.data = self.buffer
546 self.buffer = None
541 self.buffer = None
547 self.profCounter = 0
542 self.profCounter = 0
548 self.flag = True
543 self.flag = True
549 else:
544 else:
550 self.flag = False
545 self.flag = False
551
546
552 self.profCounter += 1
547 self.profCounter += 1
553
548
@@ -1,537 +1,531
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
8 import os, sys
9 import numpy
9 import numpy
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Model.Voltage import Voltage
14 from Model.Voltage import Voltage
15 from IO.VoltageIO import VoltageWriter
15 from IO.VoltageIO import VoltageWriter
16 from Graphics.VoltagePlot import Osciloscope
16 from Graphics.VoltagePlot import Osciloscope
17
17
18 class VoltageProcessor:
18 class VoltageProcessor:
19 '''
19 '''
20 classdocs
20 classdocs
21 '''
21 '''
22
22
23 dataInObj = None
23 dataInObj = None
24 dataOutObj = None
24 dataOutObj = None
25
25
26 integratorObjIndex = None
26 integratorObjIndex = None
27 decoderObjIndex = None
27 decoderObjIndex = None
28 profSelectorObjIndex = None
28 profSelectorObjIndex = None
29 writerObjIndex = None
29 writerObjIndex = None
30 plotterObjIndex = None
30 plotterObjIndex = None
31 flipIndex = None
31 flipIndex = None
32
32
33 integratorObjList = []
33 integratorObjList = []
34 decoderObjList = []
34 decoderObjList = []
35 profileSelectorObjList = []
35 profileSelectorObjList = []
36 writerObjList = []
36 writerObjList = []
37 plotterObjList = []
37 plotterObjList = []
38 m_Voltage= Voltage()
38 m_Voltage= Voltage()
39
39
40 m_ProfileSelector = ProfileSelector()
41
42 m_Decoder = Decoder()
43
44 m_CoherentIntegrator = CoherentIntegrator()
45
46 def __init__(self, dataInObj, dataOutObj=None):
40 def __init__(self, dataInObj, dataOutObj=None):
47 '''
41 '''
48 Constructor
42 Constructor
49 '''
43 '''
50
44
51 self.dataInObj = dataInObj
45 self.dataInObj = dataInObj
52
46
53 if dataOutObj == None:
47 if dataOutObj == None:
54 self.dataOutObj = Voltage()
48 self.dataOutObj = Voltage()
55 else:
49 else:
56 self.dataOutObj = dataOutObj
50 self.dataOutObj = dataOutObj
57
51
58 self.integratorObjIndex = None
52 self.integratorObjIndex = None
59 self.decoderObjIndex = None
53 self.decoderObjIndex = None
60 self.profSelectorObjIndex = None
54 self.profSelectorObjIndex = None
61 self.writerObjIndex = None
55 self.writerObjIndex = None
62 self.plotterObjIndex = None
56 self.plotterObjIndex = None
63 self.flipIndex = 1
57 self.flipIndex = 1
64 self.integratorObjList = []
58 self.integratorObjList = []
65 self.decoderObjList = []
59 self.decoderObjList = []
66 self.profileSelectorObjList = []
60 self.profileSelectorObjList = []
67 self.writerObjList = []
61 self.writerObjList = []
68 self.plotterObjList = []
62 self.plotterObjList = []
69
63
70 def init(self):
64 def init(self):
71
65
72 self.integratorObjIndex = 0
66 self.integratorObjIndex = 0
73 self.decoderObjIndex = 0
67 self.decoderObjIndex = 0
74 self.profSelectorObjIndex = 0
68 self.profSelectorObjIndex = 0
75 self.writerObjIndex = 0
69 self.writerObjIndex = 0
76 self.plotterObjIndex = 0
70 self.plotterObjIndex = 0
77 self.dataOutObj.copy(self.dataInObj)
71 self.dataOutObj.copy(self.dataInObj)
78
72
79 if self.profSelectorObjIndex != None:
73 if self.profSelectorObjIndex != None:
80 for profSelObj in self.profileSelectorObjList:
74 for profSelObj in self.profileSelectorObjList:
81 profSelObj.incIndex()
75 profSelObj.incIndex()
82
76
83 def addWriter(self, wrpath):
77 def addWriter(self, wrpath):
84 objWriter = VoltageWriter(self.dataOutObj)
78 objWriter = VoltageWriter(self.dataOutObj)
85 objWriter.setup(wrpath)
79 objWriter.setup(wrpath)
86 self.writerObjList.append(objWriter)
80 self.writerObjList.append(objWriter)
87
81
88 def addPlotter(self):
82 def addPlotter(self):
89
83
90 plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex)
84 plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex)
91 self.plotterObjList.append(plotObj)
85 self.plotterObjList.append(plotObj)
92
86
93 def addIntegrator(self, nCohInt):
87 def addIntegrator(self, nCohInt):
94
88
95 objCohInt = CoherentIntegrator(nCohInt)
89 objCohInt = CoherentIntegrator(nCohInt)
96 self.integratorObjList.append(objCohInt)
90 self.integratorObjList.append(objCohInt)
97
91
98 def addDecoder(self, code, ncode, nbaud):
92 def addDecoder(self, code, ncode, nbaud):
99
93
100 objDecoder = Decoder(code,ncode,nbaud)
94 objDecoder = Decoder(code,ncode,nbaud)
101 self.decoderObjList.append(objDecoder)
95 self.decoderObjList.append(objDecoder)
102
96
103 def addProfileSelector(self, nProfiles):
97 def addProfileSelector(self, nProfiles):
104
98
105 objProfSelector = ProfileSelector(nProfiles)
99 objProfSelector = ProfileSelector(nProfiles)
106 self.profileSelectorObjList.append(objProfSelector)
100 self.profileSelectorObjList.append(objProfSelector)
107
101
108 def writeData(self,wrpath):
102 def writeData(self,wrpath):
109
103
110 if self.dataOutObj.flagNoData:
104 if self.dataOutObj.flagNoData:
111 return 0
105 return 0
112
106
113 if len(self.writerObjList) <= self.writerObjIndex:
107 if len(self.writerObjList) <= self.writerObjIndex:
114 self.addWriter(wrpath)
108 self.addWriter(wrpath)
115
109
116 self.writerObjList[self.writerObjIndex].putData()
110 self.writerObjList[self.writerObjIndex].putData()
117
111
118 # myWrObj = self.writerObjList[self.writerObjIndex]
112 # myWrObj = self.writerObjList[self.writerObjIndex]
119 # myWrObj.putData()
113 # myWrObj.putData()
120
114
121 self.writerObjIndex += 1
115 self.writerObjIndex += 1
122
116
123 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
117 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
124 if self.dataOutObj.flagNoData:
118 if self.dataOutObj.flagNoData:
125 return 0
119 return 0
126
120
127 if len(self.plotterObjList) <= self.plotterObjIndex:
121 if len(self.plotterObjList) <= self.plotterObjIndex:
128 self.addPlotter()
122 self.addPlotter()
129
123
130 self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
124 self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
131
125
132 self.plotterObjIndex += 1
126 self.plotterObjIndex += 1
133
127
134 def integrator(self, N):
128 def integrator(self, N):
135
129
136 if self.dataOutObj.flagNoData:
130 if self.dataOutObj.flagNoData:
137 return 0
131 return 0
138
132
139 if len(self.integratorObjList) <= self.integratorObjIndex:
133 if len(self.integratorObjList) <= self.integratorObjIndex:
140 self.addIntegrator(N)
134 self.addIntegrator(N)
141
135
142 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
136 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
143 myCohIntObj.exe(self.dataOutObj.data)
137 myCohIntObj.exe(self.dataOutObj.data)
144
138
145 if myCohIntObj.flag:
139 if myCohIntObj.flag:
146 self.dataOutObj.data = myCohIntObj.data
140 self.dataOutObj.data = myCohIntObj.data
147 self.dataOutObj.m_ProcessingHeader.coherentInt *= N
141 self.dataOutObj.m_ProcessingHeader.coherentInt *= N
148 self.dataOutObj.flagNoData = False
142 self.dataOutObj.flagNoData = False
149
143
150 else:
144 else:
151 self.dataOutObj.flagNoData = True
145 self.dataOutObj.flagNoData = True
152
146
153 self.integratorObjIndex += 1
147 self.integratorObjIndex += 1
154
148
155 def decoder(self,code=None,type = 0):
149 def decoder(self,code=None,type = 0):
156
150
157 if self.dataOutObj.flagNoData:
151 if self.dataOutObj.flagNoData:
158 return 0
152 return 0
159
153
160 if code == None:
154 if code == None:
161 code = self.dataOutObj.m_RadarControllerHeader.code
155 code = self.dataOutObj.m_RadarControllerHeader.code
162 ncode, nbaud = code.shape
156 ncode, nbaud = code.shape
163
157
164 if len(self.decoderObjList) <= self.decoderObjIndex:
158 if len(self.decoderObjList) <= self.decoderObjIndex:
165 self.addDecoder(code,ncode,nbaud)
159 self.addDecoder(code,ncode,nbaud)
166
160
167 myDecodObj = self.decoderObjList[self.decoderObjIndex]
161 myDecodObj = self.decoderObjList[self.decoderObjIndex]
168 myDecodObj.exe(data=self.dataOutObj.data,type=type)
162 myDecodObj.exe(data=self.dataOutObj.data,type=type)
169
163
170 if myDecodObj.flag:
164 if myDecodObj.flag:
171 self.dataOutObj.data = myDecodObj.data
165 self.dataOutObj.data = myDecodObj.data
172 self.dataOutObj.flagNoData = False
166 self.dataOutObj.flagNoData = False
173 else:
167 else:
174 self.dataOutObj.flagNoData = True
168 self.dataOutObj.flagNoData = True
175
169
176 self.decoderObjIndex += 1
170 self.decoderObjIndex += 1
177
171
178
172
179 def filterByHei(self, window):
173 def filterByHei(self, window):
180 if window == None:
174 if window == None:
181 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
175 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
182
176
183 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
177 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
184 dim1 = self.dataOutObj.data.shape[0]
178 dim1 = self.dataOutObj.data.shape[0]
185 dim2 = self.dataOutObj.data.shape[1]
179 dim2 = self.dataOutObj.data.shape[1]
186 r = dim2 % window
180 r = dim2 % window
187
181
188 buffer = self.dataOutObj.data[:,0:dim2-r]
182 buffer = self.dataOutObj.data[:,0:dim2-r]
189 buffer = buffer.reshape(dim1,dim2/window,window)
183 buffer = buffer.reshape(dim1,dim2/window,window)
190 buffer = numpy.sum(buffer,2)
184 buffer = numpy.sum(buffer,2)
191 self.dataOutObj.data = buffer
185 self.dataOutObj.data = buffer
192
186
193 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
187 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
194 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
188 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
195
189
196 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
190 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
197
191
198 #self.dataOutObj.heightList es un numpy.array
192 #self.dataOutObj.heightList es un numpy.array
199 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
193 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
200
194
201 def deFlip(self):
195 def deFlip(self):
202 self.dataOutObj.data *= self.flipIndex
196 self.dataOutObj.data *= self.flipIndex
203 self.flipIndex *= -1.
197 self.flipIndex *= -1.
204
198
205 def selectChannels(self, channelList):
199 def selectChannels(self, channelList):
206 """
200 """
207 Selecciona un bloque de datos en base a canales segun el channelList
201 Selecciona un bloque de datos en base a canales segun el channelList
208
202
209 Input:
203 Input:
210 channelList : lista sencilla de canales a seleccionar por ej. [2,3,7]
204 channelList : lista sencilla de canales a seleccionar por ej. [2,3,7]
211
205
212 Affected:
206 Affected:
213 self.dataOutObj.data
207 self.dataOutObj.data
214 self.dataOutObj.channelList
208 self.dataOutObj.channelList
215 self.dataOutObj.nChannels
209 self.dataOutObj.nChannels
216 self.dataOutObj.m_ProcessingHeader.totalSpectra
210 self.dataOutObj.m_ProcessingHeader.totalSpectra
217 self.dataOutObj.m_SystemHeader.numChannels
211 self.dataOutObj.m_SystemHeader.numChannels
218 self.dataOutObj.m_ProcessingHeader.blockSize
212 self.dataOutObj.m_ProcessingHeader.blockSize
219
213
220 Return:
214 Return:
221 None
215 None
222 """
216 """
223 if self.dataOutObj.flagNoData:
217 if self.dataOutObj.flagNoData:
224 return 0
218 return 0
225
219
226 for channel in channelList:
220 for channel in channelList:
227 if channel not in self.dataOutObj.channelList:
221 if channel not in self.dataOutObj.channelList:
228 raise ValueError, "The value %d in channelList is not valid" %channel
222 raise ValueError, "The value %d in channelList is not valid" %channel
229
223
230 nChannels = len(channelList)
224 nChannels = len(channelList)
231
225
232 data = self.dataOutObj.data[channelList,:]
226 data = self.dataOutObj.data[channelList,:]
233
227
234 self.dataOutObj.data = data
228 self.dataOutObj.data = data
235 self.dataOutObj.channelList = channelList
229 self.dataOutObj.channelList = channelList
236 self.dataOutObj.nChannels = nChannels
230 self.dataOutObj.nChannels = nChannels
237
231
238 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels
232 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels
239 self.dataOutObj.m_SystemHeader.numChannels = nChannels
233 self.dataOutObj.m_SystemHeader.numChannels = nChannels
240 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
234 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
241 return 1
235 return 1
242
236
243
237
244 def selectHeightsByValue(self, minHei, maxHei):
238 def selectHeightsByValue(self, minHei, maxHei):
245 """
239 """
246 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
240 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
247 minHei <= height <= maxHei
241 minHei <= height <= maxHei
248
242
249 Input:
243 Input:
250 minHei : valor minimo de altura a considerar
244 minHei : valor minimo de altura a considerar
251 maxHei : valor maximo de altura a considerar
245 maxHei : valor maximo de altura a considerar
252
246
253 Affected:
247 Affected:
254 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
248 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
255
249
256 Return:
250 Return:
257 1 si el metodo se ejecuto con exito caso contrario devuelve 0
251 1 si el metodo se ejecuto con exito caso contrario devuelve 0
258 """
252 """
259 if self.dataOutObj.flagNoData:
253 if self.dataOutObj.flagNoData:
260 return 0
254 return 0
261
255
262 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
256 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
263 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
257 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
264
258
265 if (maxHei > self.dataOutObj.heightList[-1]):
259 if (maxHei > self.dataOutObj.heightList[-1]):
266 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
260 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
267
261
268 minIndex = 0
262 minIndex = 0
269 maxIndex = 0
263 maxIndex = 0
270 data = self.dataOutObj.heightList
264 data = self.dataOutObj.heightList
271
265
272 for i,val in enumerate(data):
266 for i,val in enumerate(data):
273 if val < minHei:
267 if val < minHei:
274 continue
268 continue
275 else:
269 else:
276 minIndex = i;
270 minIndex = i;
277 break
271 break
278
272
279 for i,val in enumerate(data):
273 for i,val in enumerate(data):
280 if val <= maxHei:
274 if val <= maxHei:
281 maxIndex = i;
275 maxIndex = i;
282 else:
276 else:
283 break
277 break
284
278
285 self.selectHeightsByIndex(minIndex, maxIndex)
279 self.selectHeightsByIndex(minIndex, maxIndex)
286 return 1
280 return 1
287
281
288
282
289 def selectHeightsByIndex(self, minIndex, maxIndex):
283 def selectHeightsByIndex(self, minIndex, maxIndex):
290 """
284 """
291 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
285 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
292 minIndex <= index <= maxIndex
286 minIndex <= index <= maxIndex
293
287
294 Input:
288 Input:
295 minIndex : valor de indice minimo de altura a considerar
289 minIndex : valor de indice minimo de altura a considerar
296 maxIndex : valor de indice maximo de altura a considerar
290 maxIndex : valor de indice maximo de altura a considerar
297
291
298 Affected:
292 Affected:
299 self.dataOutObj.data
293 self.dataOutObj.data
300 self.dataOutObj.heightList
294 self.dataOutObj.heightList
301 self.dataOutObj.nHeights
295 self.dataOutObj.nHeights
302 self.dataOutObj.m_ProcessingHeader.blockSize
296 self.dataOutObj.m_ProcessingHeader.blockSize
303 self.dataOutObj.m_ProcessingHeader.numHeights
297 self.dataOutObj.m_ProcessingHeader.numHeights
304 self.dataOutObj.m_ProcessingHeader.firstHeight
298 self.dataOutObj.m_ProcessingHeader.firstHeight
305 self.dataOutObj.m_RadarControllerHeader
299 self.dataOutObj.m_RadarControllerHeader
306
300
307 Return:
301 Return:
308 1 si el metodo se ejecuto con exito caso contrario devuelve 0
302 1 si el metodo se ejecuto con exito caso contrario devuelve 0
309 """
303 """
310 if self.dataOutObj.flagNoData:
304 if self.dataOutObj.flagNoData:
311 return 0
305 return 0
312
306
313 if (minIndex < 0) or (minIndex > maxIndex):
307 if (minIndex < 0) or (minIndex > maxIndex):
314 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
308 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
315
309
316 if (maxIndex >= self.dataOutObj.nHeights):
310 if (maxIndex >= self.dataOutObj.nHeights):
317 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
311 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
318
312
319 nHeights = maxIndex - minIndex + 1
313 nHeights = maxIndex - minIndex + 1
320
314
321 #voltage
315 #voltage
322 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
316 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
323
317
324 firstHeight = self.dataOutObj.heightList[minIndex]
318 firstHeight = self.dataOutObj.heightList[minIndex]
325
319
326 self.dataOutObj.data = data
320 self.dataOutObj.data = data
327 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
321 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
328 self.dataOutObj.nHeights = nHeights
322 self.dataOutObj.nHeights = nHeights
329 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
323 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
330 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
324 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
331 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
325 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
332 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
326 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
333 return 1
327 return 1
334
328
335 def selectProfilesByValue(self,indexList, nProfiles):
329 def selectProfilesByValue(self,indexList, nProfiles):
336 if self.dataOutObj.flagNoData:
330 if self.dataOutObj.flagNoData:
337 return 0
331 return 0
338
332
339 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
333 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
340 self.addProfileSelector(nProfiles)
334 self.addProfileSelector(nProfiles)
341
335
342 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
336 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
343
337
344 if not(profileSelectorObj.isProfileInList(indexList)):
338 if not(profileSelectorObj.isProfileInList(indexList)):
345 self.dataOutObj.flagNoData = True
339 self.dataOutObj.flagNoData = True
346 self.profSelectorObjIndex += 1
340 self.profSelectorObjIndex += 1
347 return 0
341 return 0
348
342
349 self.dataOutObj.flagNoData = False
343 self.dataOutObj.flagNoData = False
350 self.profSelectorObjIndex += 1
344 self.profSelectorObjIndex += 1
351
345
352 return 1
346 return 1
353
347
354
348
355 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
349 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
356 """
350 """
357 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
351 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
358 minIndex <= index <= maxIndex
352 minIndex <= index <= maxIndex
359
353
360 Input:
354 Input:
361 minIndex : valor de indice minimo de perfil a considerar
355 minIndex : valor de indice minimo de perfil a considerar
362 maxIndex : valor de indice maximo de perfil a considerar
356 maxIndex : valor de indice maximo de perfil a considerar
363 nProfiles : numero de profiles
357 nProfiles : numero de profiles
364
358
365 Affected:
359 Affected:
366 self.dataOutObj.flagNoData
360 self.dataOutObj.flagNoData
367 self.profSelectorObjIndex
361 self.profSelectorObjIndex
368
362
369 Return:
363 Return:
370 1 si el metodo se ejecuto con exito caso contrario devuelve 0
364 1 si el metodo se ejecuto con exito caso contrario devuelve 0
371 """
365 """
372
366
373 if self.dataOutObj.flagNoData:
367 if self.dataOutObj.flagNoData:
374 return 0
368 return 0
375
369
376 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
370 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
377 self.addProfileSelector(nProfiles)
371 self.addProfileSelector(nProfiles)
378
372
379 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
373 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
380
374
381 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
375 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
382 self.dataOutObj.flagNoData = True
376 self.dataOutObj.flagNoData = True
383 self.profSelectorObjIndex += 1
377 self.profSelectorObjIndex += 1
384 return 0
378 return 0
385
379
386 self.dataOutObj.flagNoData = False
380 self.dataOutObj.flagNoData = False
387 self.profSelectorObjIndex += 1
381 self.profSelectorObjIndex += 1
388
382
389 return 1
383 return 1
390
384
391 def selectNtxs(self, ntx):
385 def selectNtxs(self, ntx):
392 pass
386 pass
393
387
394
388
395 class Decoder:
389 class Decoder:
396
390
397 data = None
391 data = None
398 profCounter = 1
392 profCounter = 1
399 nCode = None
393 nCode = None
400 nBaud = None
394 nBaud = None
401 codeIndex = 0
395 codeIndex = 0
402 code = None
396 code = None
403 flag = False
397 flag = False
404
398
405 def __init__(self,code, ncode, nbaud):
399 def __init__(self,code, ncode, nbaud):
406
400
407 self.data = None
401 self.data = None
408 self.profCounter = 1
402 self.profCounter = 1
409 self.nCode = ncode
403 self.nCode = ncode
410 self.nBaud = nbaud
404 self.nBaud = nbaud
411 self.codeIndex = 0
405 self.codeIndex = 0
412 self.code = code #this is a List
406 self.code = code #this is a List
413 self.flag = False
407 self.flag = False
414
408
415 def exe(self, data, ndata=None, type = 0):
409 def exe(self, data, ndata=None, type = 0):
416
410
417 if ndata == None: ndata = data.shape[1]
411 if ndata == None: ndata = data.shape[1]
418
412
419 if type == 0:
413 if type == 0:
420 self.convolutionInFreq(data,ndata)
414 self.convolutionInFreq(data,ndata)
421
415
422 if type == 1:
416 if type == 1:
423 self.convolutionInTime(data, ndata)
417 self.convolutionInTime(data, ndata)
424
418
425 def convolutionInFreq(self,data, ndata):
419 def convolutionInFreq(self,data, ndata):
426
420
427 newcode = numpy.zeros(ndata)
421 newcode = numpy.zeros(ndata)
428 newcode[0:self.nBaud] = self.code[self.codeIndex]
422 newcode[0:self.nBaud] = self.code[self.codeIndex]
429
423
430 self.codeIndex += 1
424 self.codeIndex += 1
431
425
432 fft_data = numpy.fft.fft(data, axis=1)
426 fft_data = numpy.fft.fft(data, axis=1)
433 fft_code = numpy.conj(numpy.fft.fft(newcode))
427 fft_code = numpy.conj(numpy.fft.fft(newcode))
434 fft_code = fft_code.reshape(1,len(fft_code))
428 fft_code = fft_code.reshape(1,len(fft_code))
435
429
436 conv = fft_data.copy()
430 conv = fft_data.copy()
437 conv.fill(0)
431 conv.fill(0)
438
432
439 conv = fft_data*fft_code
433 conv = fft_data*fft_code
440
434
441 self.data = numpy.fft.ifft(conv,axis=1)
435 self.data = numpy.fft.ifft(conv,axis=1)
442 self.flag = True
436 self.flag = True
443
437
444 if self.profCounter == self.nCode:
438 if self.profCounter == self.nCode:
445 self.profCounter = 0
439 self.profCounter = 0
446 self.codeIndex = 0
440 self.codeIndex = 0
447
441
448 self.profCounter += 1
442 self.profCounter += 1
449
443
450 def convolutionInTime(self, data, ndata):
444 def convolutionInTime(self, data, ndata):
451
445
452 nchannel = data.shape[1]
446 nchannel = data.shape[1]
453 newcode = self.code[self.codeIndex]
447 newcode = self.code[self.codeIndex]
454 self.codeIndex += 1
448 self.codeIndex += 1
455 conv = data.copy()
449 conv = data.copy()
456 for i in range(nchannel):
450 for i in range(nchannel):
457 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
451 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
458
452
459 self.data = conv
453 self.data = conv
460 self.flag = True
454 self.flag = True
461
455
462 if self.profCounter == self.nCode:
456 if self.profCounter == self.nCode:
463 self.profCounter = 0
457 self.profCounter = 0
464 self.codeIndex = 0
458 self.codeIndex = 0
465
459
466 self.profCounter += 1
460 self.profCounter += 1
467
461
468
462
469 class CoherentIntegrator:
463 class CoherentIntegrator:
470
464
471 profCounter = 1
465 profCounter = 1
472 data = None
466 data = None
473 buffer = None
467 buffer = None
474 flag = False
468 flag = False
475 nCohInt = None
469 nCohInt = None
476
470
477 def __init__(self, N):
471 def __init__(self, N):
478
472
479 self.profCounter = 1
473 self.profCounter = 1
480 self.data = None
474 self.data = None
481 self.buffer = None
475 self.buffer = None
482 self.flag = False
476 self.flag = False
483 self.nCohInt = N
477 self.nCohInt = N
484
478
485 def exe(self, data):
479 def exe(self, data):
486
480
487 if self.buffer == None:
481 if self.buffer == None:
488 self.buffer = data
482 self.buffer = data
489 else:
483 else:
490 self.buffer = self.buffer + data
484 self.buffer = self.buffer + data
491
485
492 if self.profCounter == self.nCohInt:
486 if self.profCounter == self.nCohInt:
493 self.data = self.buffer
487 self.data = self.buffer
494 self.buffer = None
488 self.buffer = None
495 self.profCounter = 0
489 self.profCounter = 0
496 self.flag = True
490 self.flag = True
497 else:
491 else:
498 self.flag = False
492 self.flag = False
499
493
500 self.profCounter += 1
494 self.profCounter += 1
501
495
502 class ProfileSelector:
496 class ProfileSelector:
503
497
504 profileIndex = None
498 profileIndex = None
505 # Tamanho total de los perfiles
499 # Tamanho total de los perfiles
506 nProfiles = None
500 nProfiles = None
507
501
508 def __init__(self, nProfiles):
502 def __init__(self, nProfiles):
509
503
510 self.profileIndex = 0
504 self.profileIndex = 0
511 self.nProfiles = nProfiles
505 self.nProfiles = nProfiles
512
506
513 def incIndex(self):
507 def incIndex(self):
514 self.profileIndex += 1
508 self.profileIndex += 1
515
509
516 if self.profileIndex >= self.nProfiles:
510 if self.profileIndex >= self.nProfiles:
517 self.profileIndex = 0
511 self.profileIndex = 0
518
512
519 def isProfileInRange(self, minIndex, maxIndex):
513 def isProfileInRange(self, minIndex, maxIndex):
520
514
521 if self.profileIndex < minIndex:
515 if self.profileIndex < minIndex:
522 return False
516 return False
523
517
524 if self.profileIndex > maxIndex:
518 if self.profileIndex > maxIndex:
525 return False
519 return False
526
520
527 return True
521 return True
528
522
529 def isProfileInList(self, profileList):
523 def isProfileInList(self, profileList):
530
524
531 if self.profileIndex not in profileList:
525 if self.profileIndex not in profileList:
532 return False
526 return False
533
527
534 return True
528 return True
535
529
536
530
537 No newline at end of file
531
General Comments 0
You need to be logged in to leave comments. Login now