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