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