@@ -1,247 +1,396 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Model.Voltage import Voltage |
|
15 | 15 | from IO.VoltageIO import VoltageWriter |
|
16 | 16 | from Graphics.VoltagePlot import Osciloscope |
|
17 | 17 | |
|
18 | 18 | class VoltageProcessor: |
|
19 | 19 | ''' |
|
20 | 20 | classdocs |
|
21 | 21 | ''' |
|
22 | 22 | |
|
23 | 23 | def __init__(self, voltageInObj, voltageOutObj=None): |
|
24 | 24 | ''' |
|
25 | 25 | Constructor |
|
26 | 26 | ''' |
|
27 | 27 | |
|
28 | 28 | self.voltageInObj = voltageInObj |
|
29 | 29 | |
|
30 | 30 | if voltageOutObj == None: |
|
31 | 31 | self.voltageOutObj = Voltage() |
|
32 | 32 | else: |
|
33 | 33 | self.voltageOutObj = voltageOutObj |
|
34 | 34 | |
|
35 | 35 | self.integratorIndex = None |
|
36 | 36 | self.decoderIndex = None |
|
37 | 37 | self.writerIndex = None |
|
38 | 38 | self.plotterIndex = None |
|
39 | 39 | |
|
40 | 40 | self.integratorList = [] |
|
41 | 41 | self.decoderList = [] |
|
42 | 42 | self.writerList = [] |
|
43 | 43 | self.plotterList = [] |
|
44 | 44 | |
|
45 | 45 | def init(self): |
|
46 | 46 | self.integratorIndex = 0 |
|
47 | 47 | self.decoderIndex = 0 |
|
48 | 48 | self.writerIndex = 0 |
|
49 | 49 | self.plotterIndex = 0 |
|
50 | 50 | self.voltageOutObj.copy(self.voltageInObj) |
|
51 | 51 | |
|
52 | 52 | def addWriter(self,wrpath): |
|
53 | 53 | objWriter = VoltageWriter(self.voltageOutObj) |
|
54 | 54 | objWriter.setup(wrpath) |
|
55 | 55 | self.writerList.append(objWriter) |
|
56 | 56 | |
|
57 | 57 | def addPlotter(self): |
|
58 | 58 | |
|
59 | 59 | plotObj = Osciloscope(self.voltageOutObj,self.plotterIndex) |
|
60 | 60 | self.plotterList.append(plotObj) |
|
61 | 61 | |
|
62 | 62 | def addIntegrator(self,N): |
|
63 | 63 | |
|
64 | 64 | objCohInt = CoherentIntegrator(N) |
|
65 | 65 | self.integratorList.append(objCohInt) |
|
66 | 66 | |
|
67 | 67 | def addDecoder(self,code,ncode,nbaud): |
|
68 | 68 | |
|
69 | 69 | objDecoder = Decoder(code,ncode,nbaud) |
|
70 | 70 | self.decoderList.append(objDecoder) |
|
71 | 71 | |
|
72 | 72 | def writeData(self,wrpath): |
|
73 | 73 | if self.voltageOutObj.flagNoData: |
|
74 | 74 | return 0 |
|
75 | 75 | |
|
76 | 76 | if len(self.writerList) <= self.writerIndex: |
|
77 | 77 | self.addWriter(wrpath) |
|
78 | 78 | |
|
79 | 79 | self.writerList[self.writerIndex].putData() |
|
80 | 80 | |
|
81 | 81 | # myWrObj = self.writerList[self.writerIndex] |
|
82 | 82 | # myWrObj.putData() |
|
83 | 83 | |
|
84 | 84 | self.writerIndex += 1 |
|
85 | 85 | |
|
86 | 86 | def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): |
|
87 | 87 | if self.voltageOutObj.flagNoData: |
|
88 | 88 | return 0 |
|
89 | 89 | |
|
90 | 90 | if len(self.plotterList) <= self.plotterIndex: |
|
91 | 91 | self.addPlotter() |
|
92 | 92 | |
|
93 | 93 | self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
94 | 94 | |
|
95 | 95 | self.plotterIndex += 1 |
|
96 | 96 | |
|
97 | 97 | def integrator(self, N): |
|
98 | 98 | if self.voltageOutObj.flagNoData: |
|
99 | 99 | return 0 |
|
100 | 100 | |
|
101 | 101 | if len(self.integratorList) <= self.integratorIndex: |
|
102 | 102 | self.addIntegrator(N) |
|
103 | 103 | |
|
104 | 104 | myCohIntObj = self.integratorList[self.integratorIndex] |
|
105 | 105 | myCohIntObj.exe(self.voltageOutObj.data) |
|
106 | 106 | |
|
107 | 107 | if myCohIntObj.flag: |
|
108 | 108 | self.voltageOutObj.data = myCohIntObj.data |
|
109 | 109 | self.voltageOutObj.m_ProcessingHeader.coherentInt *= N |
|
110 | 110 | self.voltageOutObj.flagNoData = False |
|
111 | 111 | |
|
112 | 112 | else: |
|
113 | 113 | self.voltageOutObj.flagNoData = True |
|
114 | 114 | |
|
115 | 115 | self.integratorIndex += 1 |
|
116 | 116 | |
|
117 | 117 | def decoder(self,code=None,type = 0): |
|
118 | 118 | if self.voltageOutObj.flagNoData: |
|
119 | 119 | return 0 |
|
120 | 120 | if code == None: |
|
121 | 121 | code = self.voltageOutObj.m_RadarControllerHeader.code |
|
122 | 122 | ncode, nbaud = code.shape |
|
123 | 123 | |
|
124 | 124 | if len(self.decoderList) <= self.decoderIndex: |
|
125 | 125 | self.addDecoder(code,ncode,nbaud) |
|
126 | 126 | |
|
127 | 127 | myDecodObj = self.decoderList[self.decoderIndex] |
|
128 | 128 | myDecodObj.exe(data=self.voltageOutObj.data,type=type) |
|
129 | 129 | |
|
130 | 130 | if myDecodObj.flag: |
|
131 | 131 | self.voltageOutObj.data = myDecodObj.data |
|
132 | 132 | self.voltageOutObj.flagNoData = False |
|
133 | 133 | else: |
|
134 | 134 | self.voltageOutObj.flagNoData = True |
|
135 | 135 | |
|
136 | 136 | self.decoderIndex += 1 |
|
137 | 137 | |
|
138 | def removeDC(self): | |
|
139 | pass | |
|
140 | 138 | |
|
141 | def removeSignalInt(self): | |
|
139 | def filterByHei(self, window): | |
|
142 | 140 | pass |
|
143 | 141 | |
|
144 | def selChannel(self): | |
|
145 | pass | |
|
146 | 142 | |
|
147 |
def sel |
|
|
148 |
|
|
|
143 | def selectChannels(self, channelList): | |
|
144 | """ | |
|
145 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList | |
|
146 | ||
|
147 | Input: | |
|
148 | channelList : lista sencilla de canales a seleccionar por ej. (2,3,7) | |
|
149 | pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) ) | |
|
150 | ||
|
151 | Affected: | |
|
152 | self.dataOutObj.datablock | |
|
153 | self.dataOutObj.nChannels | |
|
154 | self.dataOutObj.m_SystemHeader.numChannels | |
|
155 | self.voltageOutObj.m_ProcessingHeader.blockSize | |
|
156 | ||
|
157 | Return: | |
|
158 | None | |
|
159 | """ | |
|
160 | if not(channelList): | |
|
161 | return | |
|
162 | ||
|
163 | channels = 0 | |
|
164 | profiles = self.voltageOutObj.nProfiles | |
|
165 | heights = self.voltageOutObj.m_ProcessingHeader.numHeights | |
|
166 | ||
|
167 | #self spectra | |
|
168 | channels = len(channelList) | |
|
169 | data = numpy.zeros( (channels,profiles,heights), dtype='complex' ) | |
|
170 | for index,channel in enumerate(channelList): | |
|
171 | data[index,:,:] = self.voltageOutObj.data_spc[channel,:,:] | |
|
172 | ||
|
173 | self.voltageOutObj.datablock = data | |
|
174 | ||
|
175 | #fill the m_ProcessingHeader.spectraComb up | |
|
176 | channels = len(channelList) | |
|
177 | ||
|
178 | self.voltageOutObj.channelList = channelList | |
|
179 | self.voltageOutObj.nChannels = nchannels | |
|
180 | self.voltageOutObj.m_ProcessingHeader.totalSpectra = nchannels | |
|
181 | self.voltageOutObj.m_SystemHeader.numChannels = nchannels | |
|
182 | self.voltageOutObj.m_ProcessingHeader.blockSize = data.size | |
|
183 | ||
|
184 | ||
|
185 | def selectHeightsByValue(self, minHei, maxHei): | |
|
186 | """ | |
|
187 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
|
188 | minHei <= height <= maxHei | |
|
189 | ||
|
190 | Input: | |
|
191 | minHei : valor minimo de altura a considerar | |
|
192 | maxHei : valor maximo de altura a considerar | |
|
193 | ||
|
194 | Affected: | |
|
195 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
|
196 | ||
|
197 | Return: | |
|
198 | None | |
|
199 | """ | |
|
200 | minIndex = 0 | |
|
201 | maxIndex = 0 | |
|
202 | data = self.dataOutObj.heightList | |
|
203 | ||
|
204 | for i,val in enumerate(data): | |
|
205 | if val < minHei: | |
|
206 | continue | |
|
207 | else: | |
|
208 | minIndex = i; | |
|
209 | break | |
|
210 | ||
|
211 | for i,val in enumerate(data): | |
|
212 | if val <= maxHei: | |
|
213 | maxIndex = i; | |
|
214 | else: | |
|
215 | break | |
|
216 | ||
|
217 | self.selectHeightsByIndex(minIndex, maxIndex) | |
|
218 | ||
|
219 | ||
|
220 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
|
221 | """ | |
|
222 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
|
223 | minIndex <= index <= maxIndex | |
|
224 | ||
|
225 | Input: | |
|
226 | minIndex : valor minimo de altura a considerar | |
|
227 | maxIndex : valor maximo de altura a considerar | |
|
228 | ||
|
229 | Affected: | |
|
230 | self.voltageOutObj.datablock | |
|
231 | self.voltageOutObj.m_ProcessingHeader.numHeights | |
|
232 | self.voltageOutObj.m_ProcessingHeader.blockSize | |
|
233 | self.voltageOutObj.heightList | |
|
234 | self.voltageOutObj.nHeights | |
|
235 | self.voltageOutObj.m_RadarControllerHeader.numHeights | |
|
236 | ||
|
237 | Return: | |
|
238 | None | |
|
239 | """ | |
|
240 | channels = self.voltageOutObj.nChannels | |
|
241 | profiles = self.voltageOutObj.nProfiles | |
|
242 | newheis = maxIndex - minIndex + 1 | |
|
243 | firstHeight = 0 | |
|
244 | ||
|
245 | #voltage | |
|
246 | data = numpy.zeros( (channels,profiles,newheis), dtype='complex' ) | |
|
247 | for i in range(channels): | |
|
248 | data[i] = self.voltageOutObj.data_spc[i,:,minIndex:maxIndex+1] | |
|
249 | ||
|
250 | self.voltageOutObj.datablock = data | |
|
251 | ||
|
252 | firstHeight = self.dataOutObj.heightList[minIndex] | |
|
253 | ||
|
254 | self.voltageOutObj.nHeights = newheis | |
|
255 | self.voltageOutObj.m_ProcessingHeader.blockSize = data.size | |
|
256 | self.voltageOutObj.m_ProcessingHeader.numHeights = newheis | |
|
257 | self.voltageOutObj.m_ProcessingHeader.firstHeight = firstHeight | |
|
258 | self.voltageOutObj.m_RadarControllerHeader = newheis | |
|
259 | ||
|
260 | xi = firstHeight | |
|
261 | step = self.voltageOutObj.m_ProcessingHeader.deltaHeight | |
|
262 | xf = xi + newheis * step | |
|
263 | self.voltageOutObj.heightList = numpy.arange(xi, xf, step) | |
|
264 | ||
|
265 | ||
|
266 | def selectProfiles(self, minIndex, maxIndex): | |
|
267 | """ | |
|
268 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
|
269 | minIndex <= index <= maxIndex | |
|
270 | ||
|
271 | Input: | |
|
272 | minIndex : valor minimo de altura a considerar | |
|
273 | maxIndex : valor maximo de altura a considerar | |
|
274 | ||
|
275 | Affected: | |
|
276 | self.voltageOutObj.datablock | |
|
277 | self.voltageOutObj.m_ProcessingHeader.numHeights | |
|
278 | self.voltageOutObj.heightList | |
|
279 | ||
|
280 | Return: | |
|
281 | None | |
|
282 | """ | |
|
283 | channels = self.voltageOutObj.nChannels | |
|
284 | heights = self.voltageOutObj.m_ProcessingHeader.numHeights | |
|
285 | newprofiles = maxIndex - minIndex + 1 | |
|
286 | ||
|
287 | #voltage | |
|
288 | data = numpy.zeros( (channels,newprofiles,heights), dtype='complex' ) | |
|
289 | for i in range(channels): | |
|
290 | data[i,:,:] = self.voltageOutObj.data_spc[i,minIndex:maxIndex+1,:] | |
|
291 | ||
|
292 | self.voltageOutObj.datablock = data | |
|
293 | ||
|
294 | self.voltageOutObj.m_ProcessingHeader.blockSize = data.size | |
|
295 | self.voltageOutObj.nProfiles = newprofiles | |
|
296 | self.voltageOutObj.m_SystemHeader.numProfiles = newprofiles | |
|
297 | ||
|
149 | 298 | |
|
150 |
def sel |
|
|
299 | def selectNtxs(self, ntx): | |
|
151 | 300 | pass |
|
152 | 301 | |
|
153 | 302 | |
|
154 | 303 | class Decoder: |
|
155 | 304 | def __init__(self,code, ncode, nbaud): |
|
156 | 305 | self.buffer = None |
|
157 | 306 | self.profCounter = 1 |
|
158 | 307 | self.nCode = ncode |
|
159 | 308 | self.nBaud = nbaud |
|
160 | 309 | self.codeIndex = 0 |
|
161 | 310 | self.code = code #this is a List |
|
162 | 311 | self.fft_code = None |
|
163 | 312 | self.flag = False |
|
164 | 313 | self.setCodeFft = False |
|
165 | 314 | |
|
166 | 315 | def exe(self, data, ndata=None, type = 0): |
|
167 | 316 | if ndata == None: ndata = data.shape[1] |
|
168 | 317 | |
|
169 | 318 | if type == 0: |
|
170 | 319 | self.convolutionInFreq(data,ndata) |
|
171 | 320 | |
|
172 | 321 | if type == 1: |
|
173 | 322 | self.convolutionInTime(data, ndata) |
|
174 | 323 | |
|
175 | 324 | def convolutionInFreq(self,data,ndata): |
|
176 | 325 | |
|
177 | 326 | newcode = numpy.zeros(ndata) |
|
178 | 327 | newcode[0:self.nBaud] = self.code[self.codeIndex] |
|
179 | 328 | |
|
180 | 329 | self.codeIndex += 1 |
|
181 | 330 | |
|
182 | 331 | fft_data = numpy.fft.fft(data, axis=1) |
|
183 | 332 | fft_code = numpy.conj(numpy.fft.fft(newcode)) |
|
184 | 333 | fft_code = fft_code.reshape(1,len(fft_code)) |
|
185 | 334 | |
|
186 | 335 | conv = fft_data.copy() |
|
187 | 336 | conv.fill(0) |
|
188 | 337 | |
|
189 | 338 | conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays |
|
190 | 339 | # for i in range(ndata): |
|
191 | 340 | # conv[i,:] = fft_data[i,:]*fft_code[i] |
|
192 | 341 | |
|
193 | 342 | self.data = numpy.fft.ifft(conv,axis=1) |
|
194 | 343 | self.flag = True |
|
195 | 344 | |
|
196 | 345 | if self.profCounter == self.nCode: |
|
197 | 346 | self.profCounter = 0 |
|
198 | 347 | self.codeIndex = 0 |
|
199 | 348 | |
|
200 | 349 | self.profCounter += 1 |
|
201 | 350 | |
|
202 | 351 | def convolutionInTime(self, data, ndata): |
|
203 | 352 | |
|
204 | 353 | nchannel = data.shape[1] |
|
205 | 354 | newcode = self.code[self.codeIndex] |
|
206 | 355 | self.codeIndex += 1 |
|
207 | 356 | conv = data.copy() |
|
208 | 357 | for i in range(nchannel): |
|
209 | 358 | conv[i,:] = numpy.correlate(data[i,:], newcode, 'same') |
|
210 | 359 | |
|
211 | 360 | self.data = conv |
|
212 | 361 | self.flag = True |
|
213 | 362 | |
|
214 | 363 | if self.profCounter == self.nCode: |
|
215 | 364 | self.profCounter = 0 |
|
216 | 365 | self.codeIndex = 0 |
|
217 | 366 | |
|
218 | 367 | self.profCounter += 1 |
|
219 | 368 | |
|
220 | 369 | |
|
221 | 370 | class CoherentIntegrator: |
|
222 | 371 | def __init__(self, N): |
|
223 | 372 | self.profCounter = 1 |
|
224 | 373 | self.data = None |
|
225 | 374 | self.buffer = None |
|
226 | 375 | self.flag = False |
|
227 | 376 | self.nCohInt = N |
|
228 | 377 | |
|
229 | 378 | def exe(self,data): |
|
230 | 379 | |
|
231 | 380 | if self.buffer == None: |
|
232 | 381 | self.buffer = data |
|
233 | 382 | else: |
|
234 | 383 | self.buffer = self.buffer + data |
|
235 | 384 | |
|
236 | 385 | if self.profCounter == self.nCohInt: |
|
237 | 386 | self.data = self.buffer |
|
238 | 387 | self.buffer = None |
|
239 | 388 | self.profCounter = 0 |
|
240 | 389 | self.flag = True |
|
241 | 390 | else: |
|
242 | 391 | self.flag = False |
|
243 | 392 | |
|
244 | 393 | self.profCounter += 1 |
|
245 | 394 | |
|
246 | 395 | |
|
247 | 396 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now