@@ -1,530 +1,541 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import time |
|
9 | import time | |
10 | import datetime |
|
10 | import datetime | |
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 Data.JROData import SpectraHeis |
|
14 | from Data.JROData import SpectraHeis | |
15 | from IO.SpectraIO import SpectraWriter |
|
15 | from IO.SpectraIO import SpectraWriter | |
16 |
|
|
16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure | |
17 | #from JRONoise import Noise |
|
17 | #from JRONoise import Noise | |
18 |
|
18 | |||
19 | class SpectraProcessor: |
|
19 | class SpectraProcessor: | |
20 | ''' |
|
20 | ''' | |
21 | classdocs |
|
21 | classdocs | |
22 | ''' |
|
22 | ''' | |
23 |
|
23 | |||
24 | dataInObj = None |
|
24 | dataInObj = None | |
25 |
|
25 | |||
26 | dataOutObj = None |
|
26 | dataOutObj = None | |
27 |
|
27 | |||
28 | noiseObj = None |
|
28 | noiseObj = None | |
29 |
|
29 | |||
30 | integratorObjList = [] |
|
30 | integratorObjList = [] | |
31 |
|
31 | |||
32 | writerObjList = [] |
|
32 | writerObjList = [] | |
33 |
|
33 | |||
34 | integratorObjIndex = None |
|
34 | integratorObjIndex = None | |
35 |
|
35 | |||
36 | writerObjIndex = None |
|
36 | writerObjIndex = None | |
37 |
|
37 | |||
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | def __init__(self): |
|
41 | def __init__(self): | |
42 | ''' |
|
42 | ''' | |
43 | Constructor |
|
43 | Constructor | |
44 | ''' |
|
44 | ''' | |
45 |
|
45 | |||
46 | self.integratorObjIndex = None |
|
46 | self.integratorObjIndex = None | |
47 | self.writerObjIndex = None |
|
47 | self.writerObjIndex = None | |
48 | self.plotObjIndex = None |
|
48 | self.plotObjIndex = None | |
49 | self.integratorOst = [] |
|
49 | self.integratorOst = [] | |
50 | self.plotObjList = [] |
|
50 | self.plotObjList = [] | |
51 | self.noiseObj = bjList = [] |
|
51 | self.noiseObj = bjList = [] | |
52 | self.writerObjLiNone |
|
52 | self.writerObjLiNone | |
53 | self.buffer = None |
|
53 | self.buffer = None | |
54 | self.profIndex = 0 |
|
54 | self.profIndex = 0 | |
55 |
|
55 | |||
56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): | |
57 |
|
57 | |||
58 | if dataInObj == None: |
|
58 | if dataInObj == None: | |
59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" | |
60 |
|
60 | |||
61 | if dataInObj.type == "Voltage": |
|
61 | if dataInObj.type == "Voltage": | |
62 | if nFFTPoints == None: |
|
62 | if nFFTPoints == None: | |
63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" | |
64 | else: |
|
64 | else: | |
65 | nFFTPoints = dataInObj.nFFTPoints |
|
65 | nFFTPoints = dataInObj.nFFTPoints | |
66 |
|
66 | |||
67 | self.dataInObj = dataInObj |
|
67 | self.dataInObj = dataInObj | |
68 |
|
68 | |||
69 | if dataOutObj == None: |
|
69 | if dataOutObj == None: | |
70 | dataOutObj = Spectra() |
|
70 | dataOutObj = Spectra() | |
71 |
|
71 | |||
72 | self.dataOutObj = dataOutObj |
|
72 | self.dataOutObj = dataOutObj | |
73 |
|
73 | |||
74 | return self.dataOutObj |
|
74 | return self.dataOutObj | |
75 |
|
75 | |||
76 | def init(self): |
|
76 | def init(self): | |
77 |
|
77 | |||
78 | self.integratorObjIndex = 0 |
|
78 | self.integratorObjIndex = 0 | |
79 | self.writerObjIndex = 0 |
|
79 | self.writerObjIndex = 0 | |
80 | self.plotObjIndex = 0 |
|
80 | self.plotObjIndex = 0 | |
81 | if self.dataInObj.type == "Voltage": |
|
81 | if self.dataInObj.type == "Voltage": | |
82 |
|
82 | |||
83 | if self.buffer == None: |
|
83 | if self.buffer == None: | |
84 | self.buffer = numpy.zeros((self.nChannels, |
|
84 | self.buffer = numpy.zeros((self.nChannels, | |
85 | self.nFFTPoints, |
|
85 | self.nFFTPoints, | |
86 | self.dataInObj.nHeights), |
|
86 | self.dataInObj.nHeights), | |
87 | dtype='complex') |
|
87 | dtype='complex') | |
88 |
|
88 | |||
89 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
89 | self.buffer[:,self.profIndex,:] = self.dataInObj.data | |
90 | self.profIndex += 1 |
|
90 | self.profIndex += 1 | |
91 |
|
91 | |||
92 | if self.profIndex == self.nFFTPoints: |
|
92 | if self.profIndex == self.nFFTPoints: | |
93 | self.__getFft() |
|
93 | self.__getFft() | |
94 | self.dataOutObj.flagNoData = False |
|
94 | self.dataOutObj.flagNoData = False | |
95 |
|
95 | |||
96 | self.buffer = None |
|
96 | self.buffer = None | |
97 | self.profIndex = 0 |
|
97 | self.profIndex = 0 | |
98 | return |
|
98 | return | |
99 |
|
99 | |||
100 | self.dataOutObj.flagNoData = True |
|
100 | self.dataOutObj.flagNoData = True | |
101 |
|
101 | |||
102 | return |
|
102 | return | |
103 |
|
103 | |||
104 | #Other kind of data |
|
104 | #Other kind of data | |
105 | if self.dataInObj.type == "Spectra": |
|
105 | if self.dataInObj.type == "Spectra": | |
106 | self.dataOutObj.copy(self.dataInObj) |
|
106 | self.dataOutObj.copy(self.dataInObj) | |
107 | self.dataOutObj.flagNoData = False |
|
107 | self.dataOutObj.flagNoData = False | |
108 | return |
|
108 | return | |
109 |
|
109 | |||
110 | raise ValueError, "The dtype is not valid" |
|
110 | raise ValueError, "The dtype is not valid" | |
111 |
|
111 | |||
112 | def __getFft(self): |
|
112 | def __getFft(self): | |
113 | """ |
|
113 | """ | |
114 | Convierte valores de Voltaje a Spectra |
|
114 | Convierte valores de Voltaje a Spectra | |
115 |
|
115 | |||
116 | Affected: |
|
116 | Affected: | |
117 | self.dataOutObj.data_spc |
|
117 | self.dataOutObj.data_spc | |
118 | self.dataOutObj.data_cspc |
|
118 | self.dataOutObj.data_cspc | |
119 | self.dataOutObj.data_dc |
|
119 | self.dataOutObj.data_dc | |
120 | self.dataOutObj.heightList |
|
120 | self.dataOutObj.heightList | |
121 | self.dataOutObj.m_BasicHeader |
|
121 | self.dataOutObj.m_BasicHeader | |
122 | self.dataOutObj.m_ProcessingHeader |
|
122 | self.dataOutObj.m_ProcessingHeader | |
123 | self.dataOutObj.radarControllerHeaderObj |
|
123 | self.dataOutObj.radarControllerHeaderObj | |
124 | self.dataOutObj.systemHeaderObj |
|
124 | self.dataOutObj.systemHeaderObj | |
125 | self.profIndex |
|
125 | self.profIndex | |
126 | self.buffer |
|
126 | self.buffer | |
127 | self.dataOutObj.flagNoData |
|
127 | self.dataOutObj.flagNoData | |
128 | self.dataOutObj.dtype |
|
128 | self.dataOutObj.dtype | |
129 | self.dataOutObj.nPairs |
|
129 | self.dataOutObj.nPairs | |
130 | self.dataOutObj.nChannels |
|
130 | self.dataOutObj.nChannels | |
131 | self.dataOutObj.nProfiles |
|
131 | self.dataOutObj.nProfiles | |
132 | self.dataOutObj.systemHeaderObj.numChannels |
|
132 | self.dataOutObj.systemHeaderObj.numChannels | |
133 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
133 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
134 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
134 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
135 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
135 | self.dataOutObj.m_ProcessingHeader.numHeights | |
136 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
136 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
137 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
137 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
138 | """ |
|
138 | """ | |
139 |
|
139 | |||
140 | if self.dataInObj.flagNoData: |
|
140 | if self.dataInObj.flagNoData: | |
141 | return 0 |
|
141 | return 0 | |
142 |
|
142 | |||
143 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
143 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
144 | dc = fft_volt[:,0,:] |
|
144 | dc = fft_volt[:,0,:] | |
145 |
|
145 | |||
146 | #calculo de self-spectra |
|
146 | #calculo de self-spectra | |
147 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
147 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
148 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
148 | spc = fft_volt * numpy.conjugate(fft_volt) | |
149 | spc = spc.real |
|
149 | spc = spc.real | |
150 |
|
150 | |||
151 | blocksize = 0 |
|
151 | blocksize = 0 | |
152 | blocksize += dc.size |
|
152 | blocksize += dc.size | |
153 | blocksize += spc.size |
|
153 | blocksize += spc.size | |
154 |
|
154 | |||
155 | cspc = None |
|
155 | cspc = None | |
156 | pairIndex = 0 |
|
156 | pairIndex = 0 | |
157 | if self.pairList != None: |
|
157 | if self.pairList != None: | |
158 | #calculo de cross-spectra |
|
158 | #calculo de cross-spectra | |
159 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') |
|
159 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') | |
160 | for pair in self.pairList: |
|
160 | for pair in self.pairList: | |
161 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
161 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
162 | pairIndex += 1 |
|
162 | pairIndex += 1 | |
163 | blocksize += cspc.size |
|
163 | blocksize += cspc.size | |
164 |
|
164 | |||
165 | self.dataOutObj.data_spc = spc |
|
165 | self.dataOutObj.data_spc = spc | |
166 | self.dataOutObj.data_cspc = cspc |
|
166 | self.dataOutObj.data_cspc = cspc | |
167 | self.dataOutObj.data_dc = dc |
|
167 | self.dataOutObj.data_dc = dc | |
168 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
168 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize | |
169 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc |
|
169 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc | |
170 |
|
170 | |||
171 | # self.getNoise() |
|
171 | # self.getNoise() | |
172 |
|
172 | |||
173 | def addWriter(self, wrpath, blocksPerFile): |
|
173 | def addWriter(self, wrpath, blocksPerFile): | |
174 | objWriter = SpectraWriter(self.dataOutObj) |
|
174 | objWriter = SpectraWriter(self.dataOutObj) | |
175 | objWriter.setup(wrpath, blocksPerFile) |
|
175 | objWriter.setup(wrpath, blocksPerFile) | |
176 | self.writerObjList.append(objWriter) |
|
176 | self.writerObjList.append(objWriter) | |
177 |
|
177 | |||
178 | def addIntegrator(self,N,timeInterval): |
|
178 | def addIntegrator(self,N,timeInterval): | |
179 |
|
179 | |||
180 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
180 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
181 | self.integratorObjList.append(objIncohInt) |
|
181 | self.integratorObjList.append(objIncohInt) | |
182 |
|
182 | |||
183 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
183 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
184 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
184 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
185 | self.plotObjList.append(spcObj) |
|
185 | self.plotObjList.append(spcObj) | |
186 |
|
186 | |||
187 | def plotSpc(self, idfigure=None, |
|
187 | def plotSpc(self, idfigure=None, | |
188 | xmin=None, |
|
188 | xmin=None, | |
189 | xmax=None, |
|
189 | xmax=None, | |
190 | ymin=None, |
|
190 | ymin=None, | |
191 | ymax=None, |
|
191 | ymax=None, | |
192 | minvalue=None, |
|
192 | minvalue=None, | |
193 | maxvalue=None, |
|
193 | maxvalue=None, | |
194 | wintitle='', |
|
194 | wintitle='', | |
195 | driver='plplot', |
|
195 | driver='plplot', | |
196 | colormap='br_greeen', |
|
196 | colormap='br_greeen', | |
197 | colorbar=True, |
|
197 | colorbar=True, | |
198 | showprofile=False, |
|
198 | showprofile=False, | |
199 | save=False, |
|
199 | save=False, | |
200 | gpath=None): |
|
200 | gpath=None): | |
201 |
|
201 | |||
202 | if self.dataOutObj.flagNoData: |
|
202 | if self.dataOutObj.flagNoData: | |
203 | return 0 |
|
203 | return 0 | |
204 |
|
204 | |||
205 | nframes = len(self.dataOutObj.channelList) |
|
205 | nframes = len(self.dataOutObj.channelList) | |
206 |
|
206 | |||
207 | if len(self.plotObjList) <= self.plotObjIndex: |
|
207 | if len(self.plotObjList) <= self.plotObjIndex: | |
208 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
208 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
209 |
|
209 | |||
210 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
210 | x = numpy.arange(self.dataOutObj.nFFTPoints) | |
211 |
|
211 | |||
212 | y = self.dataOutObj.heightList |
|
212 | y = self.dataOutObj.heightList | |
213 |
|
213 | |||
214 | channelList = self.dataOutObj.channelList |
|
214 | channelList = self.dataOutObj.channelList | |
215 |
|
215 | |||
216 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) |
|
216 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |
217 | # noisedB = 10.*numpy.log10(noise) |
|
217 | # noisedB = 10.*numpy.log10(noise) | |
218 | noisedB = numpy.arange(len(channelList)+1) |
|
218 | noisedB = numpy.arange(len(channelList)+1) | |
219 | noisedB = noisedB *1.2 |
|
219 | noisedB = noisedB *1.2 | |
220 | titleList = [] |
|
220 | titleList = [] | |
221 | for i in range(len(noisedB)): |
|
221 | for i in range(len(noisedB)): | |
222 | title = "%.2f"%noisedB[i] |
|
222 | title = "%.2f"%noisedB[i] | |
223 | titleList.append(title) |
|
223 | titleList.append(title) | |
224 |
|
224 | |||
225 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) |
|
225 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) | |
226 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
226 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
227 | figuretitle = "Spc Radar Data: %s"%dateTime |
|
227 | figuretitle = "Spc Radar Data: %s"%dateTime | |
228 |
|
228 | |||
229 | cleardata = True |
|
229 | cleardata = True | |
230 |
|
230 | |||
231 | plotObj = self.plotObjList[self.plotObjIndex] |
|
231 | plotObj = self.plotObjList[self.plotObjIndex] | |
232 |
|
232 | |||
233 | plotObj.plotPcolor(data, |
|
233 | plotObj.plotPcolor(data, | |
234 | x, |
|
234 | x, | |
235 | y, |
|
235 | y, | |
236 | channelList, |
|
236 | channelList, | |
237 | xmin, |
|
237 | xmin, | |
238 | xmax, |
|
238 | xmax, | |
239 | ymin, |
|
239 | ymin, | |
240 | ymax, |
|
240 | ymax, | |
241 | minvalue, |
|
241 | minvalue, | |
242 | maxvalue, |
|
242 | maxvalue, | |
243 | figuretitle, |
|
243 | figuretitle, | |
244 | None, |
|
244 | None, | |
245 | save, |
|
245 | save, | |
246 | gpath, |
|
246 | gpath, | |
247 | cleardata, |
|
247 | cleardata, | |
248 | titleList) |
|
248 | titleList) | |
249 |
|
249 | |||
250 | self.plotObjIndex += 1 |
|
250 | self.plotObjIndex += 1 | |
251 |
|
251 | |||
252 |
|
252 | |||
253 | def writeData(self, wrpath, blocksPerFile): |
|
253 | def writeData(self, wrpath, blocksPerFile): | |
254 | if self.dataOutObj.flagNoData: |
|
254 | if self.dataOutObj.flagNoData: | |
255 | return 0 |
|
255 | return 0 | |
256 |
|
256 | |||
257 | if len(self.writerObjList) <= self.writerObjIndex: |
|
257 | if len(self.writerObjList) <= self.writerObjIndex: | |
258 | self.addWriter(wrpath, blocksPerFile) |
|
258 | self.addWriter(wrpath, blocksPerFile) | |
259 |
|
259 | |||
260 | self.writerObjList[self.writerObjIndex].putData() |
|
260 | self.writerObjList[self.writerObjIndex].putData() | |
261 |
|
261 | |||
262 | self.writerObjIndex += 1 |
|
262 | self.writerObjIndex += 1 | |
263 |
|
263 | |||
264 | def integrator(self, N=None, timeInterval=None): |
|
264 | def integrator(self, N=None, timeInterval=None): | |
265 |
|
265 | |||
266 | if self.dataOutObj.flagNoData: |
|
266 | if self.dataOutObj.flagNoData: | |
267 | return 0 |
|
267 | return 0 | |
268 |
|
268 | |||
269 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
269 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
270 | self.addIntegrator(N,timeInterval) |
|
270 | self.addIntegrator(N,timeInterval) | |
271 |
|
271 | |||
272 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
272 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
273 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
273 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) | |
274 |
|
274 | |||
275 | if myIncohIntObj.isReady: |
|
275 | if myIncohIntObj.isReady: | |
276 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
276 | self.dataOutObj.data_spc = myIncohIntObj.data | |
277 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
277 | self.dataOutObj.nAvg = myIncohIntObj.navg | |
278 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
278 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg | |
279 | self.dataOutObj.flagNoData = False |
|
279 | self.dataOutObj.flagNoData = False | |
280 |
|
280 | |||
281 | """Calcular el ruido""" |
|
281 | """Calcular el ruido""" | |
282 | self.getNoise() |
|
282 | self.getNoise() | |
283 | else: |
|
283 | else: | |
284 | self.dataOutObj.flagNoData = True |
|
284 | self.dataOutObj.flagNoData = True | |
285 |
|
285 | |||
286 | self.integratorObjIndex += 1 |
|
286 | self.integratorObjIndex += 1 | |
287 |
|
287 | |||
288 |
|
288 | |||
289 | class SpectraHeisProcessor: |
|
289 | class SpectraHeisProcessor: | |
290 |
|
290 | |||
291 | def __init__(self): |
|
291 | def __init__(self): | |
292 |
|
292 | |||
293 | self.integratorObjIndex = None |
|
293 | self.integratorObjIndex = None | |
294 | self.writerObjIndex = None |
|
294 | self.writerObjIndex = None | |
295 |
self.plot |
|
295 | self.plotObjIndex = None | |
296 | self.integratorObjList = [] |
|
296 | self.integratorObjList = [] | |
297 | self.writerObjList = [] |
|
297 | self.writerObjList = [] | |
298 |
self.plot |
|
298 | self.plotObjList = [] | |
299 | #self.noiseObj = Noise() |
|
299 | #self.noiseObj = Noise() | |
300 |
|
300 | |||
301 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
301 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): | |
302 |
|
302 | |||
303 | if nFFTPoints == None: |
|
303 | if nFFTPoints == None: | |
304 | nFFTPoints = self.dataInObj.nHeights |
|
304 | nFFTPoints = self.dataInObj.nHeights | |
305 |
|
305 | |||
306 | self.dataInObj = dataInObj |
|
306 | self.dataInObj = dataInObj | |
307 |
|
307 | |||
308 | if dataOutObj == None: |
|
308 | if dataOutObj == None: | |
309 | dataOutObj = SpectraHeis() |
|
309 | dataOutObj = SpectraHeis() | |
310 |
|
310 | |||
311 | self.dataOutObj = dataOutObj |
|
311 | self.dataOutObj = dataOutObj | |
312 | # self.noiseObj = Noise() |
|
|||
313 |
|
||||
314 | ########################################## |
|
|||
315 | self.nFFTPoints = nFFTPoints |
|
|||
316 | self.nChannels = self.dataInObj.nChannels |
|
|||
317 | self.nHeights = self.dataInObj.nHeights |
|
|||
318 | self.pairList = pairList |
|
|||
319 |
|
||||
320 | if pairList != None: |
|
|||
321 | self.nPairs = len(pairList) |
|
|||
322 | else: |
|
|||
323 | self.nPairs = 0 |
|
|||
324 |
|
||||
325 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
|||
326 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
|||
327 |
|
||||
328 | self.dataOutObj.type = "SpectraHeis" |
|
|||
329 |
|
||||
330 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
|||
331 |
|
||||
332 | self.dataOutObj.nChannels = self.nChannels |
|
|||
333 |
|
||||
334 | self.dataOutObj.nHeights = self.nHeights |
|
|||
335 |
|
||||
336 | self.dataOutObj.nProfiles = self.nFFTPoints |
|
|||
337 |
|
||||
338 | self.dataOutObj.heightList = None |
|
|||
339 |
|
||||
340 | self.dataOutObj.channelList = None |
|
|||
341 |
|
||||
342 | self.dataOutObj.channelIndexList = None |
|
|||
343 |
|
||||
344 | self.dataOutObj.flagNoData = False |
|
|||
345 |
|
||||
346 | self.dataOutObj.flagTimeBlock = False |
|
|||
347 |
|
||||
348 | self.dataOutObj.dataUtcTime = None |
|
|||
349 |
|
||||
350 | self.dataOutObj.nCode = None |
|
|||
351 |
|
||||
352 | self.dataOutObj.nBaud = None |
|
|||
353 |
|
||||
354 | self.dataOutObj.code = None |
|
|||
355 |
|
||||
356 | self.dataOutObj.flagDecodeData = True #asumo q la data esta decodificada |
|
|||
357 |
|
||||
358 | self.dataOutObj.flagDeflipData = True #asumo q la data esta sin flip |
|
|||
359 |
|
||||
360 | self.dataOutObj.flagShiftFFT = False |
|
|||
361 |
|
||||
362 | self.dataOutObj.ippSeconds = None |
|
|||
363 |
|
||||
364 | self.dataOutObjdata_spc = None |
|
|||
365 |
|
||||
366 | self.dataOutObjdata_cspc = None |
|
|||
367 |
|
||||
368 | self.dataOutObjdata_dc = None |
|
|||
369 |
|
||||
370 | self.dataOutObjnFFTPoints = None |
|
|||
371 |
|
||||
372 | self.dataOutObjnPairs = None |
|
|||
373 |
|
||||
374 | self.dataOutObjpairsList = None |
|
|||
375 |
|
||||
376 |
|
312 | |||
377 | return self.dataOutObj |
|
313 | return self.dataOutObj | |
378 |
|
314 | |||
379 | def init(self): |
|
315 | def init(self): | |
380 | self.integratorObjIndex = 0 |
|
316 | self.integratorObjIndex = 0 | |
381 | self.writerObjIndex = 0 |
|
317 | self.writerObjIndex = 0 | |
382 |
self.plot |
|
318 | self.plotObjIndex = 0 | |
383 |
|
319 | |||
384 | if self.dataInObj.type == "Voltage": |
|
320 | if self.dataInObj.type == "Voltage": | |
385 | self.__getFft() |
|
321 | self.__getFft() | |
|
322 | self.__updateFromObj() | |||
386 | self.dataOutObj.flagNoData = False |
|
323 | self.dataOutObj.flagNoData = False | |
387 | return |
|
324 | return | |
388 |
|
325 | |||
389 | #Other kind of data |
|
326 | #Other kind of data | |
390 | if self.dataInObj.type == "SpectraHeis": |
|
327 | if self.dataInObj.type == "SpectraHeis": | |
391 | self.dataOutObj.copy(self.dataInObj) |
|
328 | self.dataOutObj.copy(self.dataInObj) | |
392 | self.dataOutObj.flagNoData = False |
|
329 | self.dataOutObj.flagNoData = False | |
393 | return |
|
330 | return | |
394 |
|
331 | |||
395 | raise ValueError, "The type is not valid" |
|
332 | raise ValueError, "The type is not valid" | |
396 |
|
333 | |||
|
334 | def __updateFromObj(self): | |||
|
335 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() | |||
|
336 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() | |||
|
337 | self.dataOutObj.channelList = self.dataInObj.channelList | |||
|
338 | self.dataOutObj.heightList = self.dataInObj.heightList | |||
|
339 | self.dataOutObj.dtype = self.dataInObj.dtype | |||
|
340 | self.dataOutObj.nHeights = self.dataInObj.nHeights | |||
|
341 | self.dataOutObj.nChannels = self.dataInObj.nChannels | |||
|
342 | self.dataOutObj.nBaud = self.dataInObj.nBaud | |||
|
343 | self.dataOutObj.nCode = self.dataInObj.nCode | |||
|
344 | self.dataOutObj.code = self.dataInObj.code | |||
|
345 | self.dataOutObj.nProfiles = 1 | |||
|
346 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights | |||
|
347 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |||
|
348 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData | |||
|
349 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock | |||
|
350 | self.dataOutObj.dataUtcTime = self.dataInObj.dataUtcTime | |||
|
351 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada | |||
|
352 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip | |||
|
353 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT | |||
|
354 | self.dataOutObj.nIncohInt = 1 | |||
|
355 | ||||
397 | def __getFft(self): |
|
356 | def __getFft(self): | |
398 | if self.dataInObj.flagNoData: |
|
357 | if self.dataInObj.flagNoData: | |
399 | return 0 |
|
358 | return 0 | |
400 |
|
359 | |||
401 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) |
|
360 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) | |
402 | #print fft_volt |
|
361 | #print fft_volt | |
403 | #calculo de self-spectra |
|
362 | #calculo de self-spectra | |
404 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
363 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
405 |
|
364 | |||
406 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
365 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) | |
407 | self.dataOutObj.data_spc = spc |
|
366 | self.dataOutObj.data_spc = spc | |
408 | #print spc |
|
|||
409 |
|
367 | |||
410 | def getSpectra(self): |
|
368 | def getSpectra(self): | |
411 |
|
369 | |||
412 | return self.dataOutObj.data_spc |
|
370 | return self.dataOutObj.data_spc | |
413 |
|
371 | |||
414 | def getFrecuencies(self): |
|
372 | def getFrecuencies(self): | |
415 |
|
373 | |||
416 | print self.nFFTPoints |
|
374 | print self.nFFTPoints | |
417 | return numpy.arange(int(self.nFFTPoints)) |
|
375 | return numpy.arange(int(self.nFFTPoints)) | |
418 |
|
376 | |||
419 | def addIntegrator(self,N,timeInterval): |
|
377 | def addIntegrator(self,N,timeInterval): | |
420 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
378 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
421 | self.integratorObjList.append(objIncohInt) |
|
379 | self.integratorObjList.append(objIncohInt) | |
422 |
|
380 | |||
423 | def integrator(self, N=None, timeInterval=None): |
|
381 | def integrator(self, N=None, timeInterval=None): | |
424 | if self.dataOutObj.flagNoData: |
|
382 | if self.dataOutObj.flagNoData: | |
425 | return 0 |
|
383 | return 0 | |
426 |
|
384 | |||
427 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
385 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
428 | self.addIntegrator(N,timeInterval) |
|
386 | self.addIntegrator(N,timeInterval) | |
429 |
|
387 | |||
430 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
388 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
431 |
myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj. |
|
389 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.dataUtcTime) | |
432 |
|
390 | |||
433 | if myIncohIntObj.isReady: |
|
391 | if myIncohIntObj.isReady: | |
434 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
392 | self.dataOutObj.data_spc = myIncohIntObj.data | |
435 |
self.dataOutObj.n |
|
393 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg | |
436 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg |
|
|||
437 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg |
|
|||
438 | self.dataOutObj.flagNoData = False |
|
394 | self.dataOutObj.flagNoData = False | |
439 |
|
395 | |||
440 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) |
|
396 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) | |
441 | # self.getNoise(type="sort", parm=16) |
|
397 | # self.getNoise(type="sort", parm=16) | |
442 |
|
398 | |||
443 | else: |
|
399 | else: | |
444 | self.dataOutObj.flagNoData = True |
|
400 | self.dataOutObj.flagNoData = True | |
445 |
|
401 | |||
446 | self.integratorObjIndex += 1 |
|
402 | self.integratorObjIndex += 1 | |
447 |
|
403 | |||
448 |
|
404 | |||
|
405 | def addScope(self, idfigure, nframes, wintitle, driver): | |||
|
406 | if idfigure==None: | |||
|
407 | idfigure = self.plotObjIndex | |||
|
408 | ||||
|
409 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) | |||
|
410 | self.plotObjList.append(scopeObj) | |||
|
411 | ||||
|
412 | def plotScope(self, | |||
|
413 | idfigure=None, | |||
|
414 | minvalue=None, | |||
|
415 | maxvalue=None, | |||
|
416 | xmin=None, | |||
|
417 | xmax=None, | |||
|
418 | wintitle='', | |||
|
419 | driver='plplot', | |||
|
420 | save=False, | |||
|
421 | gpath=None, | |||
|
422 | titleList=None, | |||
|
423 | xlabelList=None, | |||
|
424 | ylabelList=None): | |||
|
425 | ||||
|
426 | if self.dataOutObj.flagNoData: | |||
|
427 | return 0 | |||
|
428 | ||||
|
429 | nframes = len(self.dataOutObj.channelList) | |||
|
430 | ||||
|
431 | if len(self.plotObjList) <= self.plotObjIndex: | |||
|
432 | self.addScope(idfigure, nframes, wintitle, driver) | |||
|
433 | ||||
|
434 | ||||
|
435 | data1D = self.dataOutObj.data_spc | |||
|
436 | ||||
|
437 | x = numpy.arange(self.dataOutObj.nHeights) | |||
|
438 | ||||
|
439 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) | |||
|
440 | ||||
|
441 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
442 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |||
|
443 | ||||
|
444 | figureTitle = "Scope Plot Radar Data: " + date | |||
|
445 | ||||
|
446 | plotObj = self.plotObjList[self.plotObjIndex] | |||
|
447 | ||||
|
448 | plotObj.plot1DArray(data1D, | |||
|
449 | x, | |||
|
450 | self.dataOutObj.channelList, | |||
|
451 | xmin, | |||
|
452 | xmax, | |||
|
453 | minvalue, | |||
|
454 | maxvalue, | |||
|
455 | figureTitle, | |||
|
456 | save, | |||
|
457 | gpath) | |||
|
458 | ||||
|
459 | self.plotObjIndex += 1 | |||
449 |
|
460 | |||
450 | class IncoherentIntegration: |
|
461 | class IncoherentIntegration: | |
451 |
|
462 | |||
452 | integ_counter = None |
|
463 | integ_counter = None | |
453 | data = None |
|
464 | data = None | |
454 | navg = None |
|
465 | navg = None | |
455 | buffer = None |
|
466 | buffer = None | |
456 | nIncohInt = None |
|
467 | nIncohInt = None | |
457 |
|
468 | |||
458 | def __init__(self, N = None, timeInterval = None): |
|
469 | def __init__(self, N = None, timeInterval = None): | |
459 | """ |
|
470 | """ | |
460 | N |
|
471 | N | |
461 | timeInterval - interval time [min], integer value |
|
472 | timeInterval - interval time [min], integer value | |
462 | """ |
|
473 | """ | |
463 |
|
474 | |||
464 | self.data = None |
|
475 | self.data = None | |
465 | self.navg = None |
|
476 | self.navg = None | |
466 | self.buffer = None |
|
477 | self.buffer = None | |
467 | self.timeOut = None |
|
478 | self.timeOut = None | |
468 | self.exitCondition = False |
|
479 | self.exitCondition = False | |
469 | self.isReady = False |
|
480 | self.isReady = False | |
470 | self.nIncohInt = N |
|
481 | self.nIncohInt = N | |
471 | self.integ_counter = 0 |
|
482 | self.integ_counter = 0 | |
472 | if timeInterval!=None: |
|
483 | if timeInterval!=None: | |
473 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
484 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
474 |
|
485 | |||
475 | if ((timeInterval==None) and (N==None)): |
|
486 | if ((timeInterval==None) and (N==None)): | |
476 | print 'N = None ; timeInterval = None' |
|
487 | print 'N = None ; timeInterval = None' | |
477 | sys.exit(0) |
|
488 | sys.exit(0) | |
478 | elif timeInterval == None: |
|
489 | elif timeInterval == None: | |
479 | self.timeFlag = False |
|
490 | self.timeFlag = False | |
480 | else: |
|
491 | else: | |
481 | self.timeFlag = True |
|
492 | self.timeFlag = True | |
482 |
|
493 | |||
483 |
|
494 | |||
484 | def exe(self,data,timeOfData): |
|
495 | def exe(self,data,timeOfData): | |
485 | """ |
|
496 | """ | |
486 | data |
|
497 | data | |
487 |
|
498 | |||
488 | timeOfData [seconds] |
|
499 | timeOfData [seconds] | |
489 | """ |
|
500 | """ | |
490 |
|
501 | |||
491 | if self.timeFlag: |
|
502 | if self.timeFlag: | |
492 | if self.timeOut == None: |
|
503 | if self.timeOut == None: | |
493 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
504 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
494 |
|
505 | |||
495 | if timeOfData < self.timeOut: |
|
506 | if timeOfData < self.timeOut: | |
496 | if self.buffer == None: |
|
507 | if self.buffer == None: | |
497 | self.buffer = data |
|
508 | self.buffer = data | |
498 | else: |
|
509 | else: | |
499 | self.buffer = self.buffer + data |
|
510 | self.buffer = self.buffer + data | |
500 | self.integ_counter += 1 |
|
511 | self.integ_counter += 1 | |
501 | else: |
|
512 | else: | |
502 | self.exitCondition = True |
|
513 | self.exitCondition = True | |
503 |
|
514 | |||
504 | else: |
|
515 | else: | |
505 | if self.integ_counter < self.nIncohInt: |
|
516 | if self.integ_counter < self.nIncohInt: | |
506 | if self.buffer == None: |
|
517 | if self.buffer == None: | |
507 | self.buffer = data |
|
518 | self.buffer = data | |
508 | else: |
|
519 | else: | |
509 | self.buffer = self.buffer + data |
|
520 | self.buffer = self.buffer + data | |
510 |
|
521 | |||
511 | self.integ_counter += 1 |
|
522 | self.integ_counter += 1 | |
512 |
|
523 | |||
513 | if self.integ_counter == self.nIncohInt: |
|
524 | if self.integ_counter == self.nIncohInt: | |
514 | self.exitCondition = True |
|
525 | self.exitCondition = True | |
515 |
|
526 | |||
516 | if self.exitCondition: |
|
527 | if self.exitCondition: | |
517 | self.data = self.buffer |
|
528 | self.data = self.buffer | |
518 | self.navg = self.integ_counter |
|
529 | self.navg = self.integ_counter | |
519 | self.isReady = True |
|
530 | self.isReady = True | |
520 | self.buffer = None |
|
531 | self.buffer = None | |
521 | self.timeOut = None |
|
532 | self.timeOut = None | |
522 | self.integ_counter = 0 |
|
533 | self.integ_counter = 0 | |
523 | self.exitCondition = False |
|
534 | self.exitCondition = False | |
524 |
|
535 | |||
525 | if self.timeFlag: |
|
536 | if self.timeFlag: | |
526 | self.buffer = data |
|
537 | self.buffer = data | |
527 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
538 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
528 | else: |
|
539 | else: | |
529 | self.isReady = False |
|
540 | self.isReady = False | |
530 | No newline at end of file |
|
541 |
General Comments 0
You need to be logged in to leave comments.
Login now