@@ -1,497 +1,511 | |||||
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 | def __init__(self, dataInObj, dataOutObj=None): |
|
23 | def __init__(self, dataInObj, dataOutObj=None): | |
24 | ''' |
|
24 | ''' | |
25 | Constructor |
|
25 | Constructor | |
26 | ''' |
|
26 | ''' | |
27 | self.dataInObj = dataInObj |
|
27 | self.dataInObj = dataInObj | |
28 |
|
28 | |||
29 | if dataOutObj == None: |
|
29 | if dataOutObj == None: | |
30 | self.dataOutObj = Spectra() |
|
30 | self.dataOutObj = Spectra() | |
31 | else: |
|
31 | else: | |
32 | self.dataOutObj = dataOutObj |
|
32 | self.dataOutObj = dataOutObj | |
33 |
|
33 | |||
34 | self.integratorIndex = None |
|
34 | self.integratorIndex = None | |
35 | self.decoderIndex = None |
|
35 | self.decoderIndex = None | |
36 | self.writerIndex = None |
|
36 | self.writerIndex = None | |
37 | self.plotterIndex = None |
|
37 | self.plotterIndex = None | |
38 |
|
38 | |||
39 | self.integratorList = [] |
|
39 | self.integratorList = [] | |
40 | self.decoderList = [] |
|
40 | self.decoderList = [] | |
41 | self.writerList = [] |
|
41 | self.writerList = [] | |
42 | self.plotterList = [] |
|
42 | self.plotterList = [] | |
43 |
|
43 | |||
44 | self.buffer = None |
|
44 | self.buffer = None | |
45 | self.ptsId = 0 |
|
45 | self.ptsId = 0 | |
46 |
|
46 | |||
47 | def init(self, nFFTPoints, pairList=None): |
|
47 | def init(self, nFFTPoints, pairList=None): | |
48 |
|
48 | |||
49 | self.integratorIndex = 0 |
|
49 | self.integratorIndex = 0 | |
50 | self.decoderIndex = 0 |
|
50 | self.decoderIndex = 0 | |
51 | self.writerIndex = 0 |
|
51 | self.writerIndex = 0 | |
52 | self.plotterIndex = 0 |
|
52 | self.plotterIndex = 0 | |
53 |
|
53 | |||
54 | if nFFTPoints == None: |
|
54 | if nFFTPoints == None: | |
55 | nFFTPoints = self.dataOutObj.nFFTPoints |
|
55 | nFFTPoints = self.dataOutObj.nFFTPoints | |
56 |
|
56 | |||
57 | self.nFFTPoints = nFFTPoints |
|
57 | self.nFFTPoints = nFFTPoints | |
58 | self.pairList = pairList |
|
58 | self.pairList = pairList | |
59 |
|
59 | |||
60 | if not( isinstance(self.dataInObj, Spectra) ): |
|
60 | if not( isinstance(self.dataInObj, Spectra) ): | |
61 | self.__getFft() |
|
61 | self.__getFft() | |
62 | else: |
|
62 | else: | |
63 | self.dataOutObj.copy(self.dataInObj) |
|
63 | self.dataOutObj.copy(self.dataInObj) | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | def __getFft(self): |
|
66 | def __getFft(self): | |
67 | """ |
|
67 | """ | |
68 | Convierte valores de Voltaje a Spectra |
|
68 | Convierte valores de Voltaje a Spectra | |
69 |
|
69 | |||
70 | Affected: |
|
70 | Affected: | |
71 | self.dataOutObj.data_spc |
|
71 | self.dataOutObj.data_spc | |
72 | self.dataOutObj.data_cspc |
|
72 | self.dataOutObj.data_cspc | |
73 | self.dataOutObj.data_dc |
|
73 | self.dataOutObj.data_dc | |
74 | self.dataOutObj.heightList |
|
74 | self.dataOutObj.heightList | |
75 | self.dataOutObj.m_BasicHeader |
|
75 | self.dataOutObj.m_BasicHeader | |
76 | self.dataOutObj.m_ProcessingHeader |
|
76 | self.dataOutObj.m_ProcessingHeader | |
77 | self.dataOutObj.m_RadarControllerHeader |
|
77 | self.dataOutObj.m_RadarControllerHeader | |
78 | self.dataOutObj.m_SystemHeader |
|
78 | self.dataOutObj.m_SystemHeader | |
79 | self.ptsId |
|
79 | self.ptsId | |
80 | self.buffer |
|
80 | self.buffer | |
81 | self.dataOutObj.flagNoData |
|
81 | self.dataOutObj.flagNoData | |
82 | self.dataOutObj.dataType |
|
82 | self.dataOutObj.dataType | |
83 | self.dataOutObj.nPairs |
|
83 | self.dataOutObj.nPairs | |
84 | self.dataOutObj.nChannels |
|
84 | self.dataOutObj.nChannels | |
85 | self.dataOutObj.nProfiles |
|
85 | self.dataOutObj.nProfiles | |
86 | self.dataOutObj.m_SystemHeader.numChannels |
|
86 | self.dataOutObj.m_SystemHeader.numChannels | |
87 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
87 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
88 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
88 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
89 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
89 | self.dataOutObj.m_ProcessingHeader.numHeights | |
90 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
90 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
91 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
91 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
92 | """ |
|
92 | """ | |
93 | blocksize = 0 |
|
93 | blocksize = 0 | |
94 | nFFTPoints = self.nFFTPoints |
|
94 | nFFTPoints = self.nFFTPoints | |
95 | nChannels, nheis = self.dataInObj.data.shape |
|
95 | nChannels, nheis = self.dataInObj.data.shape | |
96 |
|
96 | |||
97 | if self.buffer == None: |
|
97 | if self.buffer == None: | |
98 | self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex') |
|
98 | self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex') | |
99 |
|
99 | |||
100 | self.buffer[:,self.ptsId,:] = self.dataInObj.data |
|
100 | self.buffer[:,self.ptsId,:] = self.dataInObj.data | |
101 | self.ptsId += 1 |
|
101 | self.ptsId += 1 | |
102 |
|
102 | |||
103 | if self.ptsId < self.dataOutObj.nFFTPoints: |
|
103 | if self.ptsId < self.dataOutObj.nFFTPoints: | |
104 | self.dataOutObj.flagNoData = True |
|
104 | self.dataOutObj.flagNoData = True | |
105 | return |
|
105 | return | |
106 |
|
106 | |||
107 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
107 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
108 | dc = fft_volt[:,0,:] |
|
108 | dc = fft_volt[:,0,:] | |
109 |
|
109 | |||
110 | #calculo de self-spectra |
|
110 | #calculo de self-spectra | |
111 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
111 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
112 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
112 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) | |
113 |
|
113 | |||
114 | blocksize += dc.size |
|
114 | blocksize += dc.size | |
115 | blocksize += spc.size |
|
115 | blocksize += spc.size | |
116 |
|
116 | |||
117 | cspc = None |
|
117 | cspc = None | |
118 | nPair = 0 |
|
118 | nPair = 0 | |
119 | if self.pairList != None: |
|
119 | if self.pairList != None: | |
120 | #calculo de cross-spectra |
|
120 | #calculo de cross-spectra | |
121 | nPairs = len(self.pairList) |
|
121 | nPairs = len(self.pairList) | |
122 | cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex') |
|
122 | cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex') | |
123 | for pair in self.pairList: |
|
123 | for pair in self.pairList: | |
124 | cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
124 | cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
125 | nPair += 1 |
|
125 | nPair += 1 | |
126 | blocksize += cspc.size |
|
126 | blocksize += cspc.size | |
127 |
|
127 | |||
128 | self.dataOutObj.data_spc = spc |
|
128 | self.dataOutObj.data_spc = spc | |
129 | self.dataOutObj.data_cspc = cspc |
|
129 | self.dataOutObj.data_cspc = cspc | |
130 | self.dataOutObj.data_dc = dc |
|
130 | self.dataOutObj.data_dc = dc | |
131 |
|
131 | |||
132 | self.ptsId = 0 |
|
132 | self.ptsId = 0 | |
133 | self.buffer = None |
|
133 | self.buffer = None | |
134 | self.dataOutObj.flagNoData = False |
|
134 | self.dataOutObj.flagNoData = False | |
135 |
|
135 | |||
136 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
136 | self.dataOutObj.heightList = self.dataInObj.heightList | |
137 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
137 | self.dataOutObj.channelList = self.dataInObj.channelList | |
138 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
138 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() | |
139 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
139 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() | |
140 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
140 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() | |
141 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
141 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() | |
142 |
|
142 | |||
143 | self.dataOutObj.dataType = self.dataInObj.dataType |
|
143 | self.dataOutObj.dataType = self.dataInObj.dataType | |
144 | self.dataOutObj.nPairs = nPair |
|
144 | self.dataOutObj.nPairs = nPair | |
145 | self.dataOutObj.nChannels = nChannels |
|
145 | self.dataOutObj.nChannels = nChannels | |
146 | self.dataOutObj.nProfiles = nFFTPoints |
|
146 | self.dataOutObj.nProfiles = nFFTPoints | |
147 | self.dataOutObj.nHeights = nheis |
|
147 | self.dataOutObj.nHeights = nheis | |
148 | self.dataOutObj.nFFTPoints = nFFTPoints |
|
148 | self.dataOutObj.nFFTPoints = nFFTPoints | |
149 | #self.dataOutObj.data = None |
|
149 | #self.dataOutObj.data = None | |
150 |
|
150 | |||
151 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
151 | self.dataOutObj.m_SystemHeader.numChannels = nChannels | |
152 | self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints |
|
152 | self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints | |
153 |
|
153 | |||
154 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
154 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
155 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair |
|
155 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair | |
156 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints |
|
156 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints | |
157 | self.dataOutObj.m_ProcessingHeader.numHeights = nheis |
|
157 | self.dataOutObj.m_ProcessingHeader.numHeights = nheis | |
158 | self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
158 | self.dataOutObj.m_ProcessingHeader.shif_fft = True | |
159 |
|
159 | |||
160 | spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1')) |
|
160 | spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1')) | |
161 | k = 0 |
|
161 | k = 0 | |
162 | for i in range( 0,nChannels*2,2 ): |
|
162 | for i in range( 0,nChannels*2,2 ): | |
163 | spectraComb[i] = k |
|
163 | spectraComb[i] = k | |
164 | spectraComb[i+1] = k |
|
164 | spectraComb[i+1] = k | |
165 | k += 1 |
|
165 | k += 1 | |
166 |
|
166 | |||
167 | k *= 2 |
|
167 | k *= 2 | |
168 |
|
168 | |||
169 | if self.pairList != None: |
|
169 | if self.pairList != None: | |
170 |
|
170 | |||
171 | for pair in self.pairList: |
|
171 | for pair in self.pairList: | |
172 | spectraComb[k] = pair[0] |
|
172 | spectraComb[k] = pair[0] | |
173 | spectraComb[k+1] = pair[1] |
|
173 | spectraComb[k+1] = pair[1] | |
174 | k += 2 |
|
174 | k += 2 | |
175 |
|
175 | |||
176 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
176 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb | |
177 |
|
177 | |||
178 | #self.selectHeightsByIndex( 0,10) |
|
|||
179 | #self.selectHeightsByValue( 120,200 ) |
|
|||
180 | #self.selectChannels((2,4,5), self.pairList) |
|
|||
181 |
|
||||
182 |
|
178 | |||
183 | def addWriter(self,wrpath): |
|
179 | def addWriter(self,wrpath): | |
184 | objWriter = SpectraWriter(self.dataOutObj) |
|
180 | objWriter = SpectraWriter(self.dataOutObj) | |
185 | objWriter.setup(wrpath) |
|
181 | objWriter.setup(wrpath) | |
186 | self.writerList.append(objWriter) |
|
182 | self.writerList.append(objWriter) | |
187 |
|
183 | |||
188 |
|
184 | |||
189 | def addPlotter(self, index=None): |
|
185 | def addPlotter(self, index=None): | |
190 |
|
186 | |||
191 | if index==None: |
|
187 | if index==None: | |
192 | index = self.plotterIndex |
|
188 | index = self.plotterIndex | |
193 |
|
189 | |||
194 | plotObj = Spectrum(self.dataOutObj, index) |
|
190 | plotObj = Spectrum(self.dataOutObj, index) | |
195 | self.plotterList.append(plotObj) |
|
191 | self.plotterList.append(plotObj) | |
196 |
|
192 | |||
197 |
|
193 | |||
198 | def addIntegrator(self,N): |
|
194 | def addIntegrator(self,N): | |
199 |
|
195 | |||
200 | objIncohInt = IncoherentIntegration(N) |
|
196 | objIncohInt = IncoherentIntegration(N) | |
201 | self.integratorList.append(objIncohInt) |
|
197 | self.integratorList.append(objIncohInt) | |
202 |
|
198 | |||
203 |
|
199 | |||
204 | def writeData(self, wrpath): |
|
200 | def writeData(self, wrpath): | |
205 | if self.dataOutObj.flagNoData: |
|
201 | if self.dataOutObj.flagNoData: | |
206 | return 0 |
|
202 | return 0 | |
207 |
|
203 | |||
208 | if len(self.writerList) <= self.writerIndex: |
|
204 | if len(self.writerList) <= self.writerIndex: | |
209 | self.addWriter(wrpath) |
|
205 | self.addWriter(wrpath) | |
210 |
|
206 | |||
211 | self.writerList[self.writerIndex].putData() |
|
207 | self.writerList[self.writerIndex].putData() | |
212 |
|
208 | |||
213 | self.writerIndex += 1 |
|
209 | self.writerIndex += 1 | |
214 |
|
210 | |||
215 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): |
|
211 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): | |
216 | if self.dataOutObj.flagNoData: |
|
212 | if self.dataOutObj.flagNoData: | |
217 | return 0 |
|
213 | return 0 | |
218 |
|
214 | |||
219 | if len(self.plotterList) <= self.plotterIndex: |
|
215 | if len(self.plotterList) <= self.plotterIndex: | |
220 | self.addPlotter(index) |
|
216 | self.addPlotter(index) | |
221 |
|
217 | |||
222 | self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
218 | self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
223 |
|
219 | |||
224 | self.plotterIndex += 1 |
|
220 | self.plotterIndex += 1 | |
225 |
|
221 | |||
226 | def integrator(self, N): |
|
222 | def integrator(self, N): | |
227 | if self.dataOutObj.flagNoData: |
|
223 | if self.dataOutObj.flagNoData: | |
228 | return 0 |
|
224 | return 0 | |
229 |
|
225 | |||
230 | if len(self.integratorList) <= self.integratorIndex: |
|
226 | if len(self.integratorList) <= self.integratorIndex: | |
231 | self.addIntegrator(N) |
|
227 | self.addIntegrator(N) | |
232 |
|
228 | |||
233 | myCohIntObj = self.integratorList[self.integratorIndex] |
|
229 | myCohIntObj = self.integratorList[self.integratorIndex] | |
234 | myCohIntObj.exe(self.dataOutObj.data_spc) |
|
230 | myCohIntObj.exe(self.dataOutObj.data_spc) | |
235 |
|
231 | |||
236 | if myCohIntObj.flag: |
|
232 | if myCohIntObj.flag: | |
237 | self.dataOutObj.data_spc = myCohIntObj.data |
|
233 | self.dataOutObj.data_spc = myCohIntObj.data | |
238 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= N |
|
234 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= N | |
239 | self.dataOutObj.flagNoData = False |
|
235 | self.dataOutObj.flagNoData = False | |
240 |
|
236 | |||
241 | else: |
|
237 | else: | |
242 | self.dataOutObj.flagNoData = True |
|
238 | self.dataOutObj.flagNoData = True | |
243 |
|
239 | |||
244 | self.integratorIndex += 1 |
|
240 | self.integratorIndex += 1 | |
245 |
|
241 | |||
246 | def removeDC(self, type): |
|
242 | def removeDC(self, type): | |
247 |
|
243 | |||
248 | if self.dataOutObj.flagNoData: |
|
244 | if self.dataOutObj.flagNoData: | |
249 | return 0 |
|
245 | return 0 | |
250 | pass |
|
246 | pass | |
251 |
|
247 | |||
252 | def removeInterference(self): |
|
248 | def removeInterference(self): | |
253 |
|
249 | |||
254 | if self.dataOutObj.flagNoData: |
|
250 | if self.dataOutObj.flagNoData: | |
255 | return 0 |
|
251 | return 0 | |
256 | pass |
|
252 | pass | |
257 |
|
253 | |||
258 | def removeSatellites(self): |
|
254 | def removeSatellites(self): | |
259 |
|
255 | |||
260 | if self.dataOutObj.flagNoData: |
|
256 | if self.dataOutObj.flagNoData: | |
261 | return 0 |
|
257 | return 0 | |
262 | pass |
|
258 | pass | |
263 |
|
259 | |||
264 | def selectChannels(self, channelList, pairList=None): |
|
260 | def selectChannels(self, channelList, pairList=None): | |
265 | """ |
|
261 | """ | |
266 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList |
|
262 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList | |
267 |
|
263 | |||
268 | Input: |
|
264 | Input: | |
269 | channelList : lista sencilla de canales a seleccionar por ej. (2,3,7) |
|
265 | channelList : lista sencilla de canales a seleccionar por ej. (2,3,7) | |
270 | pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) ) |
|
266 | pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) ) | |
271 |
|
267 | |||
272 | Affected: |
|
268 | Affected: | |
273 | self.dataOutObj.data_spc |
|
269 | self.dataOutObj.data_spc | |
274 | self.dataOutObj.data_cspc |
|
270 | self.dataOutObj.data_cspc | |
275 | self.dataOutObj.data_dc |
|
271 | self.dataOutObj.data_dc | |
276 | self.dataOutObj.nChannels |
|
272 | self.dataOutObj.nChannels | |
277 | self.dataOutObj.nPairs |
|
273 | self.dataOutObj.nPairs | |
278 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
274 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
279 | self.dataOutObj.m_SystemHeader.numChannels |
|
275 | self.dataOutObj.m_SystemHeader.numChannels | |
280 |
|
276 | |||
281 | Return: |
|
277 | Return: | |
282 | None |
|
278 | None | |
283 | """ |
|
279 | """ | |
284 |
|
280 | |||
285 | if self.dataOutObj.flagNoData: |
|
281 | if self.dataOutObj.flagNoData: | |
286 | return 0 |
|
282 | return 0 | |
287 |
|
283 | |||
|
284 | channelIndexList = [] | |||
|
285 | for channel in channelList: | |||
|
286 | if channel in self.dataOutObj.channelList: | |||
|
287 | index = self.dataOutObj.channelList.index(channel) | |||
|
288 | channelIndexList.append(index) | |||
|
289 | continue | |||
|
290 | ||||
|
291 | raise ValueError, "The value %d in channelList is not valid" %channel | |||
|
292 | ||||
288 | nProfiles = self.dataOutObj.nProfiles |
|
293 | nProfiles = self.dataOutObj.nProfiles | |
289 | dataType = self.dataOutObj.dataType |
|
294 | #dataType = self.dataOutObj.dataType | |
290 | nHeights = self.dataOutObj.m_ProcessingHeader.numHeights |
|
295 | nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights | |
291 | blocksize = 0 |
|
296 | blocksize = 0 | |
292 |
|
297 | |||
293 | #self spectra |
|
298 | #self spectra | |
294 | nChannels = len(channelList) |
|
299 | nChannels = len(channelIndexList) | |
295 |
spc = numpy.zeros( (nChannels,nProfiles,nHeights), d |
|
300 | spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] ) | |
296 |
|
301 | |||
297 | for index, channel in enumerate(channelList): |
|
302 | for index, channel in enumerate(channelIndexList): | |
298 |
spc[index,:,:] = self.dataOutObj.data_spc[ |
|
303 | spc[index,:,:] = self.dataOutObj.data_spc[index,:,:] | |
299 |
|
304 | |||
300 | #DC channel |
|
305 | #DC channel | |
301 | dc = numpy.zeros( (nChannels,nHeights), dtype='complex' ) |
|
306 | dc = numpy.zeros( (nChannels,nHeights), dtype='complex' ) | |
302 | for index, channel in enumerate(channelList): |
|
307 | for index, channel in enumerate(channelIndexList): | |
303 | dc[index,:] = self.dataOutObj.data_dc[channel,:] |
|
308 | dc[index,:] = self.dataOutObj.data_dc[channel,:] | |
304 |
|
309 | |||
305 | blocksize += dc.size |
|
310 | blocksize += dc.size | |
306 | blocksize += spc.size |
|
311 | blocksize += spc.size | |
307 |
|
312 | |||
308 | nPairs = 0 |
|
313 | nPairs = 0 | |
309 | cspc = None |
|
314 | cspc = None | |
310 |
|
315 | |||
311 | if pairList == None: |
|
316 | if pairList == None: | |
312 | pairList = self.pairList |
|
317 | pairList = self.pairList | |
313 |
|
318 | |||
314 | if pairList != None: |
|
319 | if (pairList != None) and (self.dataOutObj.data_cspc != None): | |
315 | #cross spectra |
|
320 | #cross spectra | |
316 | nPairs = len(pairList) |
|
321 | nPairs = len(pairList) | |
317 | cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' ) |
|
322 | cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' ) | |
318 |
|
323 | |||
319 | spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb |
|
324 | spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb | |
320 | totalSpectra = len(spectraComb) |
|
325 | totalSpectra = len(spectraComb) | |
321 | nchan = self.dataOutObj.nChannels |
|
326 | nchan = self.dataOutObj.nChannels | |
322 | indexList = [] |
|
327 | pairIndexList = [] | |
323 |
|
328 | |||
324 | for pair in pairList: #busco el par en la lista de pares del Spectra Combinations |
|
329 | for pair in pairList: #busco el par en la lista de pares del Spectra Combinations | |
325 | for index in range(0,totalSpectra,2): |
|
330 | for index in range(0,totalSpectra,2): | |
326 | if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]: |
|
331 | if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]: | |
327 | indexList.append( index/2 - nchan ) |
|
332 | pairIndexList.append( index/2 - nchan ) | |
328 |
|
333 | |||
329 | for index, pair in enumerate(indexList): |
|
334 | for index, pair in enumerate(pairIndexList): | |
330 | cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:] |
|
335 | cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:] | |
331 | blocksize += cspc.size |
|
336 | blocksize += cspc.size | |
332 |
|
337 | |||
333 | else: |
|
338 | else: | |
334 | pairList = self.pairList |
|
339 | pairList = self.pairList | |
335 | cspc = self.dataOutObj.data_cspc |
|
340 | cspc = self.dataOutObj.data_cspc | |
336 | if cspc != None: |
|
341 | if cspc != None: | |
337 | blocksize += cspc.size |
|
342 | blocksize += cspc.size | |
338 |
|
343 | |||
339 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) |
|
344 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) | |
340 | i = 0 |
|
345 | i = 0 | |
341 | for val in channelList: |
|
346 | for val in channelList: | |
342 | spectraComb[i] = val |
|
347 | spectraComb[i] = val | |
343 | spectraComb[i+1] = val |
|
348 | spectraComb[i+1] = val | |
344 | i += 2 |
|
349 | i += 2 | |
345 |
|
350 | |||
346 | if pairList != None: |
|
351 | if pairList != None: | |
347 | for pair in pairList: |
|
352 | for pair in pairList: | |
348 | spectraComb[i] = pair[0] |
|
353 | spectraComb[i] = pair[0] | |
349 | spectraComb[i+1] = pair[1] |
|
354 | spectraComb[i+1] = pair[1] | |
350 | i += 2 |
|
355 | i += 2 | |
351 |
|
356 | |||
352 | self.dataOutObj.data_spc = spc |
|
357 | self.dataOutObj.data_spc = spc | |
353 | self.dataOutObj.data_cspc = cspc |
|
358 | self.dataOutObj.data_cspc = cspc | |
354 | self.dataOutObj.data_dc = dc |
|
359 | self.dataOutObj.data_dc = dc | |
355 | self.dataOutObj.nChannels = nChannels |
|
360 | self.dataOutObj.nChannels = nChannels | |
356 | self.dataOutObj.nPairs = nPairs |
|
361 | self.dataOutObj.nPairs = nPairs | |
357 |
|
362 | |||
358 | self.dataOutObj.channelList = channelList |
|
363 | self.dataOutObj.channelList = channelList | |
359 |
|
364 | |||
360 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
365 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb | |
361 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs |
|
366 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs | |
362 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
367 | self.dataOutObj.m_SystemHeader.numChannels = nChannels | |
363 | self.dataOutObj.nChannels = nChannels |
|
368 | self.dataOutObj.nChannels = nChannels | |
364 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
369 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
365 |
|
370 | |||
366 |
|
371 | |||
367 | def selectHeightsByValue(self, minHei, maxHei): |
|
372 | def selectHeightsByValue(self, minHei, maxHei): | |
368 | """ |
|
373 | """ | |
369 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
374 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
370 | minHei <= height <= maxHei |
|
375 | minHei <= height <= maxHei | |
371 |
|
376 | |||
372 | Input: |
|
377 | Input: | |
373 | minHei : valor minimo de altura a considerar |
|
378 | minHei : valor minimo de altura a considerar | |
374 | maxHei : valor maximo de altura a considerar |
|
379 | maxHei : valor maximo de altura a considerar | |
375 |
|
380 | |||
376 | Affected: |
|
381 | Affected: | |
377 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
382 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
378 |
|
383 | |||
379 | Return: |
|
384 | Return: | |
380 | None |
|
385 | None | |
381 | """ |
|
386 | """ | |
382 |
|
387 | |||
383 | if self.dataOutObj.flagNoData: |
|
388 | if self.dataOutObj.flagNoData: | |
384 | return 0 |
|
389 | return 0 | |
385 |
|
390 | |||
|
391 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): | |||
|
392 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |||
|
393 | ||||
|
394 | if (maxHei > self.dataOutObj.heightList[-1]): | |||
|
395 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |||
|
396 | ||||
386 | minIndex = 0 |
|
397 | minIndex = 0 | |
387 | maxIndex = 0 |
|
398 | maxIndex = 0 | |
388 | data = self.dataOutObj.heightList |
|
399 | data = self.dataOutObj.heightList | |
389 |
|
400 | |||
390 | for i,val in enumerate(data): |
|
401 | for i,val in enumerate(data): | |
391 | if val < minHei: |
|
402 | if val < minHei: | |
392 | continue |
|
403 | continue | |
393 | else: |
|
404 | else: | |
394 | minIndex = i; |
|
405 | minIndex = i; | |
395 | break |
|
406 | break | |
396 |
|
407 | |||
397 | for i,val in enumerate(data): |
|
408 | for i,val in enumerate(data): | |
398 | if val <= maxHei: |
|
409 | if val <= maxHei: | |
399 | maxIndex = i; |
|
410 | maxIndex = i; | |
400 | else: |
|
411 | else: | |
401 | break |
|
412 | break | |
402 |
|
413 | |||
403 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
414 | self.selectHeightsByIndex(minIndex, maxIndex) | |
404 |
|
415 | |||
405 |
|
416 | |||
406 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
417 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
407 | """ |
|
418 | """ | |
408 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
419 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
409 | minIndex <= index <= maxIndex |
|
420 | minIndex <= index <= maxIndex | |
410 |
|
421 | |||
411 | Input: |
|
422 | Input: | |
412 | minIndex : valor minimo de altura a considerar |
|
423 | minIndex : valor minimo de altura a considerar | |
413 | maxIndex : valor maximo de altura a considerar |
|
424 | maxIndex : valor maximo de altura a considerar | |
414 |
|
425 | |||
415 | Affected: |
|
426 | Affected: | |
416 | self.dataOutObj.data_spc |
|
427 | self.dataOutObj.data_spc | |
417 | self.dataOutObj.data_cspc |
|
428 | self.dataOutObj.data_cspc | |
418 | self.dataOutObj.data_dc |
|
429 | self.dataOutObj.data_dc | |
419 | self.dataOutObj.heightList |
|
430 | self.dataOutObj.heightList | |
420 | self.dataOutObj.nHeights |
|
431 | self.dataOutObj.nHeights | |
421 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
432 | self.dataOutObj.m_ProcessingHeader.numHeights | |
422 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
433 | self.dataOutObj.m_ProcessingHeader.blockSize | |
423 | self.dataOutObj.m_ProcessingHeader.firstHeight |
|
434 | self.dataOutObj.m_ProcessingHeader.firstHeight | |
424 | self.dataOutObj.m_RadarControllerHeader.numHeights |
|
435 | self.dataOutObj.m_RadarControllerHeader.numHeights | |
425 |
|
436 | |||
426 | Return: |
|
437 | Return: | |
427 | None |
|
438 | None | |
428 | """ |
|
439 | """ | |
429 |
|
440 | |||
430 | if self.dataOutObj.flagNoData: |
|
441 | if self.dataOutObj.flagNoData: | |
431 | return 0 |
|
442 | return 0 | |
432 |
|
443 | |||
|
444 | if (minIndex < 0) or (minIndex > maxIndex): | |||
|
445 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |||
|
446 | ||||
|
447 | if (maxIndex >= self.dataOutObj.nHeights): | |||
|
448 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |||
|
449 | ||||
433 | nChannels = self.dataOutObj.nChannels |
|
450 | nChannels = self.dataOutObj.nChannels | |
434 | nPairs = self.dataOutObj.nPairs |
|
451 | nPairs = self.dataOutObj.nPairs | |
435 | nProfiles = self.dataOutObj.nProfiles |
|
452 | nProfiles = self.dataOutObj.nProfiles | |
436 | dataType = self.dataOutObj.dataType |
|
453 | dataType = self.dataOutObj.dataType | |
437 |
n |
|
454 | nHeights = maxIndex - minIndex + 1 | |
438 | blockSize = 0 |
|
455 | blockSize = 0 | |
439 |
|
456 | |||
440 | #self spectra |
|
457 | #self spectra | |
441 | spc = numpy.zeros( (nChannels,nProfiles,newheis), dataType[0] ) |
|
458 | spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1] | |
442 | for i in range(nChannels): |
|
459 | blockSize += spc.size | |
443 | spc[i,:,:] = self.dataOutObj.data_spc[i,:,minIndex:maxIndex+1] |
|
|||
444 |
|
460 | |||
445 | #cross spectra |
|
461 | #cross spectra | |
446 | cspc = numpy.zeros( (nPairs,nProfiles,newheis), dtype='complex') |
|
462 | cspc = None | |
447 | for i in range(nPairs): |
|
463 | if self.dataOutObj.data_cspc != None: | |
448 |
cspc |
|
464 | cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1] | |
|
465 | blockSize += cspc.size | |||
449 |
|
466 | |||
450 | #DC channel |
|
467 | #DC channel | |
451 | dc = numpy.zeros( (nChannels,newheis), dtype='complex') |
|
468 | dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1] | |
452 | for i in range(nChannels): |
|
469 | blockSize += dc.size | |
453 | dc[i] = self.dataOutObj.data_dc[i,minIndex:maxIndex+1] |
|
|||
454 |
|
470 | |||
455 | self.dataOutObj.data_spc = spc |
|
471 | self.dataOutObj.data_spc = spc | |
|
472 | if cspc != None: | |||
456 | self.dataOutObj.data_cspc = cspc |
|
473 | self.dataOutObj.data_cspc = cspc | |
457 | self.dataOutObj.data_dc = dc |
|
474 | self.dataOutObj.data_dc = dc | |
458 |
|
475 | |||
459 | firstHeight = self.dataOutObj.heightList[minIndex] |
|
476 | firstHeight = self.dataOutObj.heightList[minIndex] | |
460 |
|
477 | |||
461 |
self.dataOutObj.nHeights = n |
|
478 | self.dataOutObj.nHeights = nHeights | |
462 |
self.dataOutObj.m_ProcessingHeader.blockSize = |
|
479 | self.dataOutObj.m_ProcessingHeader.blockSize = blockSize | |
463 |
self.dataOutObj.m_ProcessingHeader.numHeights = n |
|
480 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights | |
464 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight |
|
481 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight | |
465 |
self.dataOutObj.m_RadarControllerHeader.numHeights = n |
|
482 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights | |
466 |
|
483 | |||
467 | xi = firstHeight |
|
484 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] | |
468 | step = self.dataOutObj.m_ProcessingHeader.deltaHeight |
|
|||
469 | xf = xi + newheis * step |
|
|||
470 | self.dataOutObj.heightList = numpy.arange(xi, xf, step) |
|
|||
471 |
|
485 | |||
472 |
|
486 | |||
473 | class IncoherentIntegration: |
|
487 | class IncoherentIntegration: | |
474 | def __init__(self, N): |
|
488 | def __init__(self, N): | |
475 | self.profCounter = 1 |
|
489 | self.profCounter = 1 | |
476 | self.data = None |
|
490 | self.data = None | |
477 | self.buffer = None |
|
491 | self.buffer = None | |
478 | self.flag = False |
|
492 | self.flag = False | |
479 | self.nIncohInt = N |
|
493 | self.nIncohInt = N | |
480 |
|
494 | |||
481 | def exe(self,data): |
|
495 | def exe(self,data): | |
482 |
|
496 | |||
483 | if self.buffer == None: |
|
497 | if self.buffer == None: | |
484 | self.buffer = data |
|
498 | self.buffer = data | |
485 | else: |
|
499 | else: | |
486 | self.buffer = self.buffer + data |
|
500 | self.buffer = self.buffer + data | |
487 |
|
501 | |||
488 | if self.profCounter == self.nIncohInt: |
|
502 | if self.profCounter == self.nIncohInt: | |
489 | self.data = self.buffer |
|
503 | self.data = self.buffer | |
490 | self.buffer = None |
|
504 | self.buffer = None | |
491 | self.profCounter = 0 |
|
505 | self.profCounter = 0 | |
492 | self.flag = True |
|
506 | self.flag = True | |
493 | else: |
|
507 | else: | |
494 | self.flag = False |
|
508 | self.flag = False | |
495 |
|
509 | |||
496 | self.profCounter += 1 |
|
510 | self.profCounter += 1 | |
497 |
|
511 |
General Comments 0
You need to be logged in to leave comments.
Login now