@@ -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 | ||||
|
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 |
@@ -49,7 +49,7 class SpectraProcessor: | |||||
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 | ''' | |
@@ -73,19 +73,40 class SpectraProcessor: | |||||
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: |
@@ -37,7 +37,7 class VoltageProcessor: | |||||
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 | ''' | |
@@ -61,6 +61,22 class VoltageProcessor: | |||||
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 | |
@@ -79,11 +95,13 class VoltageProcessor: | |||||
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, |
|
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) | |
@@ -114,14 +132,14 class VoltageProcessor: | |||||
114 |
|
132 | |||
115 | self.writerObjIndex += 1 |
|
133 | self.writerObjIndex += 1 | |
116 |
|
134 | |||
117 |
def plotData(self, |
|
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( |
|
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 |
@@ -28,12 +28,12 class TestSChain(): | |||||
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,1 |
|
35 | self.startDateTime = datetime.datetime(2011,11,20,0,0,0) | |
36 |
self.endDateTime = datetime.datetime(2011,1 |
|
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 | |||
@@ -66,7 +66,7 class TestSChain(): | |||||
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 | # |
General Comments 0
You need to be logged in to leave comments.
Login now