@@ -1,698 +1,710 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on September , 2012 |
|
2 | Created on September , 2012 | |
3 | @author: |
|
3 | @author: | |
4 | ''' |
|
4 | ''' | |
5 | from xml.etree.ElementTree import Element, SubElement, ElementTree |
|
5 | from xml.etree.ElementTree import Element, SubElement, ElementTree | |
6 | from xml.etree import ElementTree as ET |
|
6 | from xml.etree import ElementTree as ET | |
7 | from xml.dom import minidom |
|
7 | from xml.dom import minidom | |
8 |
|
8 | |||
9 | import sys |
|
9 | import sys | |
10 | import datetime |
|
10 | import datetime | |
11 | from model.jrodataIO import * |
|
11 | from model.jrodataIO import * | |
12 | from model.jroprocessing import * |
|
12 | from model.jroprocessing import * | |
13 | from model.jroplot import * |
|
13 | from model.jroplot import * | |
14 |
|
14 | |||
15 | def prettify(elem): |
|
15 | def prettify(elem): | |
16 | """Return a pretty-printed XML string for the Element. |
|
16 | """Return a pretty-printed XML string for the Element. | |
17 | """ |
|
17 | """ | |
18 | rough_string = ET.tostring(elem, 'utf-8') |
|
18 | rough_string = ET.tostring(elem, 'utf-8') | |
19 | reparsed = minidom.parseString(rough_string) |
|
19 | reparsed = minidom.parseString(rough_string) | |
20 | return reparsed.toprettyxml(indent=" ") |
|
20 | return reparsed.toprettyxml(indent=" ") | |
21 |
|
21 | |||
22 | class ParameterConf(): |
|
22 | class ParameterConf(): | |
23 |
|
23 | |||
24 | id = None |
|
24 | id = None | |
25 | name = None |
|
25 | name = None | |
26 | value = None |
|
26 | value = None | |
27 | format = None |
|
27 | format = None | |
28 |
|
28 | |||
29 | ELEMENTNAME = 'Parameter' |
|
29 | ELEMENTNAME = 'Parameter' | |
30 |
|
30 | |||
31 | def __init__(self): |
|
31 | def __init__(self): | |
32 |
|
32 | |||
33 | self.format = 'str' |
|
33 | self.format = 'str' | |
34 |
|
34 | |||
35 | def getElementName(self): |
|
35 | def getElementName(self): | |
36 |
|
36 | |||
37 | return self.ELEMENTNAME |
|
37 | return self.ELEMENTNAME | |
38 |
|
38 | |||
39 | def getValue(self): |
|
39 | def getValue(self): | |
40 |
|
40 | |||
41 | if self.format == 'list': |
|
41 | if self.format == 'list': | |
42 | strList = self.value.split(',') |
|
42 | strList = self.value.split(',') | |
43 | return strList |
|
43 | return strList | |
44 |
|
44 | |||
45 | if self.format == 'intlist': |
|
45 | if self.format == 'intlist': | |
46 | strList = self.value.split(',') |
|
46 | strList = self.value.split(',') | |
47 | intList = [int(x) for x in strList] |
|
47 | intList = [int(x) for x in strList] | |
48 | return intList |
|
48 | return intList | |
49 |
|
49 | |||
50 | if self.format == 'floatlist': |
|
50 | if self.format == 'floatlist': | |
51 | strList = self.value.split(',') |
|
51 | strList = self.value.split(',') | |
52 | floatList = [float(x) for x in strList] |
|
52 | floatList = [float(x) for x in strList] | |
53 | return floatList |
|
53 | return floatList | |
54 |
|
54 | |||
55 | if self.format == 'date': |
|
55 | if self.format == 'date': | |
56 | strList = self.value.split('/') |
|
56 | strList = self.value.split('/') | |
57 | intList = [int(x) for x in strList] |
|
57 | intList = [int(x) for x in strList] | |
58 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
58 | date = datetime.date(intList[0], intList[1], intList[2]) | |
59 | return date |
|
59 | return date | |
60 |
|
60 | |||
61 | if self.format == 'time': |
|
61 | if self.format == 'time': | |
62 | strList = self.value.split(':') |
|
62 | strList = self.value.split(':') | |
63 | intList = [int(x) for x in strList] |
|
63 | intList = [int(x) for x in strList] | |
64 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
64 | time = datetime.time(intList[0], intList[1], intList[2]) | |
65 | return time |
|
65 | return time | |
66 |
|
66 | |||
67 | func = eval(self.format) |
|
67 | func = eval(self.format) | |
68 |
|
68 | |||
69 | return func(self.value) |
|
69 | return func(self.value) | |
70 |
|
70 | |||
71 | def setup(self, id, name, value, format='str'): |
|
71 | def setup(self, id, name, value, format='str'): | |
72 |
|
72 | |||
73 | self.id = id |
|
73 | self.id = id | |
74 | self.name = name |
|
74 | self.name = name | |
75 | self.value = str(value) |
|
75 | self.value = str(value) | |
76 | self.format = format |
|
76 | self.format = format | |
77 |
|
77 | |||
78 | def makeXml(self, opElement): |
|
78 | def makeXml(self, opElement): | |
79 |
|
79 | |||
80 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
80 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
81 | parmElement.set('id', str(self.id)) |
|
81 | parmElement.set('id', str(self.id)) | |
82 | parmElement.set('name', self.name) |
|
82 | parmElement.set('name', self.name) | |
83 | parmElement.set('value', self.value) |
|
83 | parmElement.set('value', self.value) | |
84 | parmElement.set('format', self.format) |
|
84 | parmElement.set('format', self.format) | |
85 |
|
85 | |||
86 | def readXml(self, parmElement): |
|
86 | def readXml(self, parmElement): | |
87 |
|
87 | |||
88 | self.id = parmElement.get('id') |
|
88 | self.id = parmElement.get('id') | |
89 | self.name = parmElement.get('name') |
|
89 | self.name = parmElement.get('name') | |
90 | self.value = parmElement.get('value') |
|
90 | self.value = parmElement.get('value') | |
91 | self.format = parmElement.get('format') |
|
91 | self.format = parmElement.get('format') | |
92 |
|
92 | |||
93 | def printattr(self): |
|
93 | def printattr(self): | |
94 |
|
94 | |||
95 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
95 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
96 |
|
96 | |||
97 | class OperationConf(): |
|
97 | class OperationConf(): | |
98 |
|
98 | |||
99 | id = None |
|
99 | id = None | |
100 | name = None |
|
100 | name = None | |
101 | priority = None |
|
101 | priority = None | |
102 | type = None |
|
102 | type = None | |
103 |
|
103 | |||
104 | parmConfObjList = [] |
|
104 | parmConfObjList = [] | |
105 |
|
105 | |||
106 | ELEMENTNAME = 'Operation' |
|
106 | ELEMENTNAME = 'Operation' | |
107 |
|
107 | |||
108 | def __init__(self): |
|
108 | def __init__(self): | |
109 |
|
109 | |||
110 | id = 0 |
|
110 | id = 0 | |
111 | name = None |
|
111 | name = None | |
112 | priority = None |
|
112 | priority = None | |
113 | type = 'self' |
|
113 | type = 'self' | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | def __getNewId(self): |
|
116 | def __getNewId(self): | |
117 |
|
117 | |||
118 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
118 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
119 |
|
119 | |||
120 | def getElementName(self): |
|
120 | def getElementName(self): | |
121 |
|
121 | |||
122 | return self.ELEMENTNAME |
|
122 | return self.ELEMENTNAME | |
123 |
|
123 | |||
124 | def getParameterObjList(self): |
|
124 | def getParameterObjList(self): | |
125 |
|
125 | |||
126 | return self.parmConfObjList |
|
126 | return self.parmConfObjList | |
127 |
|
127 | |||
128 | def setup(self, id, name, priority, type): |
|
128 | def setup(self, id, name, priority, type): | |
129 |
|
129 | |||
130 | self.id = id |
|
130 | self.id = id | |
131 | self.name = name |
|
131 | self.name = name | |
132 | self.type = type |
|
132 | self.type = type | |
133 | self.priority = priority |
|
133 | self.priority = priority | |
134 |
|
134 | |||
135 | self.parmConfObjList = [] |
|
135 | self.parmConfObjList = [] | |
136 |
|
136 | |||
137 | def addParameter(self, name, value, format='str'): |
|
137 | def addParameter(self, name, value, format='str'): | |
138 |
|
138 | |||
139 | id = self.__getNewId() |
|
139 | id = self.__getNewId() | |
140 |
|
140 | |||
141 | parmConfObj = ParameterConf() |
|
141 | parmConfObj = ParameterConf() | |
142 | parmConfObj.setup(id, name, value, format) |
|
142 | parmConfObj.setup(id, name, value, format) | |
143 |
|
143 | |||
144 | self.parmConfObjList.append(parmConfObj) |
|
144 | self.parmConfObjList.append(parmConfObj) | |
145 |
|
145 | |||
146 | return parmConfObj |
|
146 | return parmConfObj | |
147 |
|
147 | |||
148 | def makeXml(self, upElement): |
|
148 | def makeXml(self, upElement): | |
149 |
|
149 | |||
150 | opElement = SubElement(upElement, self.ELEMENTNAME) |
|
150 | opElement = SubElement(upElement, self.ELEMENTNAME) | |
151 | opElement.set('id', str(self.id)) |
|
151 | opElement.set('id', str(self.id)) | |
152 | opElement.set('name', self.name) |
|
152 | opElement.set('name', self.name) | |
153 | opElement.set('type', self.type) |
|
153 | opElement.set('type', self.type) | |
154 | opElement.set('priority', str(self.priority)) |
|
154 | opElement.set('priority', str(self.priority)) | |
155 |
|
155 | |||
156 | for parmConfObj in self.parmConfObjList: |
|
156 | for parmConfObj in self.parmConfObjList: | |
157 | parmConfObj.makeXml(opElement) |
|
157 | parmConfObj.makeXml(opElement) | |
158 |
|
158 | |||
159 | def readXml(self, opElement): |
|
159 | def readXml(self, opElement): | |
160 |
|
160 | |||
161 | self.id = opElement.get('id') |
|
161 | self.id = opElement.get('id') | |
162 | self.name = opElement.get('name') |
|
162 | self.name = opElement.get('name') | |
163 | self.type = opElement.get('type') |
|
163 | self.type = opElement.get('type') | |
164 | self.priority = opElement.get('priority') |
|
164 | self.priority = opElement.get('priority') | |
165 |
|
165 | |||
166 | self.parmConfObjList = [] |
|
166 | self.parmConfObjList = [] | |
167 |
|
167 | |||
168 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
168 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |
169 |
|
169 | |||
170 | for parmElement in parmElementList: |
|
170 | for parmElement in parmElementList: | |
171 | parmConfObj = ParameterConf() |
|
171 | parmConfObj = ParameterConf() | |
172 | parmConfObj.readXml(parmElement) |
|
172 | parmConfObj.readXml(parmElement) | |
173 | self.parmConfObjList.append(parmConfObj) |
|
173 | self.parmConfObjList.append(parmConfObj) | |
174 |
|
174 | |||
175 | def printattr(self): |
|
175 | def printattr(self): | |
176 |
|
176 | |||
177 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
177 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
178 | self.id, |
|
178 | self.id, | |
179 | self.name, |
|
179 | self.name, | |
180 | self.type, |
|
180 | self.type, | |
181 | self.priority) |
|
181 | self.priority) | |
182 |
|
182 | |||
183 | for parmConfObj in self.parmConfObjList: |
|
183 | for parmConfObj in self.parmConfObjList: | |
184 | parmConfObj.printattr() |
|
184 | parmConfObj.printattr() | |
185 |
|
185 | |||
186 | def createObject(self): |
|
186 | def createObject(self): | |
187 |
|
187 | |||
188 | if self.type == 'self': |
|
188 | if self.type == 'self': | |
189 | raise ValueError, "This operation type cannot be created" |
|
189 | raise ValueError, "This operation type cannot be created" | |
190 |
|
190 | |||
191 | if self.type == 'other': |
|
191 | if self.type == 'other': | |
192 | className = eval(self.name) |
|
192 | className = eval(self.name) | |
193 | opObj = className() |
|
193 | opObj = className() | |
194 |
|
194 | |||
195 | return opObj |
|
195 | return opObj | |
196 |
|
196 | |||
197 | class ProcUnitConf(): |
|
197 | class ProcUnitConf(): | |
198 |
|
198 | |||
199 | id = None |
|
199 | id = None | |
200 | name = None |
|
200 | name = None | |
201 | datatype = None |
|
201 | datatype = None | |
202 | inputId = None |
|
202 | inputId = None | |
203 |
|
203 | |||
204 | opConfObjList = [] |
|
204 | opConfObjList = [] | |
205 |
|
205 | |||
206 | procUnitObj = None |
|
206 | procUnitObj = None | |
207 | opObjList = [] |
|
207 | opObjList = [] | |
208 |
|
208 | |||
209 | ELEMENTNAME = 'ProcUnit' |
|
209 | ELEMENTNAME = 'ProcUnit' | |
210 |
|
210 | |||
211 | def __init__(self): |
|
211 | def __init__(self): | |
212 |
|
212 | |||
213 | self.id = None |
|
213 | self.id = None | |
214 | self.datatype = None |
|
214 | self.datatype = None | |
215 | self.name = None |
|
215 | self.name = None | |
216 | self.inputId = None |
|
216 | self.inputId = None | |
217 |
|
217 | |||
218 | self.opConfObjList = [] |
|
218 | self.opConfObjList = [] | |
219 |
|
219 | |||
220 | self.procUnitObj = None |
|
220 | self.procUnitObj = None | |
221 | self.opObjDict = {} |
|
221 | self.opObjDict = {} | |
222 |
|
222 | |||
223 | def __getPriority(self): |
|
223 | def __getPriority(self): | |
224 |
|
224 | |||
225 | return len(self.opConfObjList)+1 |
|
225 | return len(self.opConfObjList)+1 | |
226 |
|
226 | |||
227 | def __getNewId(self): |
|
227 | def __getNewId(self): | |
228 |
|
228 | |||
229 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
229 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
230 |
|
230 | |||
231 | def getElementName(self): |
|
231 | def getElementName(self): | |
232 |
|
232 | |||
233 | return self.ELEMENTNAME |
|
233 | return self.ELEMENTNAME | |
234 |
|
234 | |||
235 | def getId(self): |
|
235 | def getId(self): | |
236 |
|
236 | |||
237 | return str(self.id) |
|
237 | return str(self.id) | |
238 |
|
238 | |||
239 | def getInputId(self): |
|
239 | def getInputId(self): | |
240 |
|
240 | |||
241 | return str(self.inputId) |
|
241 | return str(self.inputId) | |
242 |
|
242 | |||
243 | def getOperationObjList(self): |
|
243 | def getOperationObjList(self): | |
244 |
|
244 | |||
245 | return self.opConfObjList |
|
245 | return self.opConfObjList | |
246 |
|
246 | |||
247 | def getProcUnitObj(self): |
|
247 | def getProcUnitObj(self): | |
248 |
|
248 | |||
249 | return self.procUnitObj |
|
249 | return self.procUnitObj | |
250 |
|
250 | |||
251 | def setup(self, id, name, datatype, inputId): |
|
251 | def setup(self, id, name, datatype, inputId): | |
252 |
|
252 | |||
253 | self.id = id |
|
253 | self.id = id | |
254 | self.name = name |
|
254 | self.name = name | |
255 | self.datatype = datatype |
|
255 | self.datatype = datatype | |
256 | self.inputId = inputId |
|
256 | self.inputId = inputId | |
257 |
|
257 | |||
258 | self.opConfObjList = [] |
|
258 | self.opConfObjList = [] | |
259 |
|
259 | |||
260 | self.addOperation(name='init', optype='self') |
|
260 | self.addOperation(name='init', optype='self') | |
261 |
|
261 | |||
262 | def addParameter(self, **kwargs): |
|
262 | def addParameter(self, **kwargs): | |
263 |
|
263 | |||
264 | opObj = self.opConfObjList[0] |
|
264 | opObj = self.opConfObjList[0] | |
265 |
|
265 | |||
266 | opObj.addParameter(**kwargs) |
|
266 | opObj.addParameter(**kwargs) | |
267 |
|
267 | |||
268 | return opObj |
|
268 | return opObj | |
269 |
|
269 | |||
270 | def addOperation(self, name, optype='self'): |
|
270 | def addOperation(self, name, optype='self'): | |
271 |
|
271 | |||
272 | id = self.__getNewId() |
|
272 | id = self.__getNewId() | |
273 | priority = self.__getPriority() |
|
273 | priority = self.__getPriority() | |
274 |
|
274 | |||
275 | opConfObj = OperationConf() |
|
275 | opConfObj = OperationConf() | |
276 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
276 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
277 |
|
277 | |||
278 | self.opConfObjList.append(opConfObj) |
|
278 | self.opConfObjList.append(opConfObj) | |
279 |
|
279 | |||
280 | return opConfObj |
|
280 | return opConfObj | |
281 |
|
281 | |||
282 | def makeXml(self, procUnitElement): |
|
282 | def makeXml(self, procUnitElement): | |
283 |
|
283 | |||
284 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
284 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
285 | upElement.set('id', str(self.id)) |
|
285 | upElement.set('id', str(self.id)) | |
286 | upElement.set('name', self.name) |
|
286 | upElement.set('name', self.name) | |
287 | upElement.set('datatype', self.datatype) |
|
287 | upElement.set('datatype', self.datatype) | |
288 | upElement.set('inputId', str(self.inputId)) |
|
288 | upElement.set('inputId', str(self.inputId)) | |
289 |
|
289 | |||
290 | for opConfObj in self.opConfObjList: |
|
290 | for opConfObj in self.opConfObjList: | |
291 | opConfObj.makeXml(upElement) |
|
291 | opConfObj.makeXml(upElement) | |
292 |
|
292 | |||
293 | def readXml(self, upElement): |
|
293 | def readXml(self, upElement): | |
294 |
|
294 | |||
295 | self.id = upElement.get('id') |
|
295 | self.id = upElement.get('id') | |
296 | self.name = upElement.get('name') |
|
296 | self.name = upElement.get('name') | |
297 | self.datatype = upElement.get('datatype') |
|
297 | self.datatype = upElement.get('datatype') | |
298 | self.inputId = upElement.get('inputId') |
|
298 | self.inputId = upElement.get('inputId') | |
299 |
|
299 | |||
300 | self.opConfObjList = [] |
|
300 | self.opConfObjList = [] | |
301 |
|
301 | |||
302 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
302 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
303 |
|
303 | |||
304 | for opElement in opElementList: |
|
304 | for opElement in opElementList: | |
305 | opConfObj = OperationConf() |
|
305 | opConfObj = OperationConf() | |
306 | opConfObj.readXml(opElement) |
|
306 | opConfObj.readXml(opElement) | |
307 | self.opConfObjList.append(opConfObj) |
|
307 | self.opConfObjList.append(opConfObj) | |
308 |
|
308 | |||
309 | def printattr(self): |
|
309 | def printattr(self): | |
310 |
|
310 | |||
311 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
311 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
312 | self.id, |
|
312 | self.id, | |
313 | self.name, |
|
313 | self.name, | |
314 | self.datatype, |
|
314 | self.datatype, | |
315 | self.inputId) |
|
315 | self.inputId) | |
316 |
|
316 | |||
317 | for opConfObj in self.opConfObjList: |
|
317 | for opConfObj in self.opConfObjList: | |
318 | opConfObj.printattr() |
|
318 | opConfObj.printattr() | |
319 |
|
319 | |||
320 | def createObjects(self): |
|
320 | def createObjects(self): | |
321 |
|
321 | |||
322 | className = eval(self.name) |
|
322 | className = eval(self.name) | |
323 | procUnitObj = className() |
|
323 | procUnitObj = className() | |
324 |
|
324 | |||
325 | for opConfObj in self.opConfObjList: |
|
325 | for opConfObj in self.opConfObjList: | |
326 |
|
326 | |||
327 | if opConfObj.type == 'self': |
|
327 | if opConfObj.type == 'self': | |
328 | continue |
|
328 | continue | |
329 |
|
329 | |||
330 | opObj = opConfObj.createObject() |
|
330 | opObj = opConfObj.createObject() | |
331 |
|
331 | |||
332 | self.opObjDict[opConfObj.id] = opObj |
|
332 | self.opObjDict[opConfObj.id] = opObj | |
333 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
333 | procUnitObj.addOperation(opObj, opConfObj.id) | |
334 |
|
334 | |||
335 | self.procUnitObj = procUnitObj |
|
335 | self.procUnitObj = procUnitObj | |
336 |
|
336 | |||
337 | return procUnitObj |
|
337 | return procUnitObj | |
338 |
|
338 | |||
339 | def run(self): |
|
339 | def run(self): | |
340 |
|
340 | |||
341 | finalSts = False |
|
341 | finalSts = False | |
342 |
|
342 | |||
343 | for opConfObj in self.opConfObjList: |
|
343 | for opConfObj in self.opConfObjList: | |
344 |
|
344 | |||
345 | kwargs = {} |
|
345 | kwargs = {} | |
346 | for parmConfObj in opConfObj.getParameterObjList(): |
|
346 | for parmConfObj in opConfObj.getParameterObjList(): | |
347 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
347 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
348 |
|
348 | |||
349 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
349 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
350 | sts = self.procUnitObj.call(opConfObj, **kwargs) |
|
350 | sts = self.procUnitObj.call(opConfObj, **kwargs) | |
351 | finalSts = finalSts or sts |
|
351 | finalSts = finalSts or sts | |
352 |
|
352 | |||
353 | return finalSts |
|
353 | return finalSts | |
354 |
|
354 | |||
355 | class ReadUnitConf(ProcUnitConf): |
|
355 | class ReadUnitConf(ProcUnitConf): | |
356 |
|
356 | |||
357 | path = None |
|
357 | path = None | |
358 | startDate = None |
|
358 | startDate = None | |
359 | endDate = None |
|
359 | endDate = None | |
360 | startTime = None |
|
360 | startTime = None | |
361 | endTime = None |
|
361 | endTime = None | |
362 | online = None |
|
362 | online = None | |
363 | expLabel = None |
|
363 | expLabel = None | |
364 | delay = None |
|
364 | delay = None | |
365 |
|
365 | |||
366 | ELEMENTNAME = 'ReadUnit' |
|
366 | ELEMENTNAME = 'ReadUnit' | |
367 |
|
367 | |||
368 | def __init__(self): |
|
368 | def __init__(self): | |
369 |
|
369 | |||
370 | self.id = None |
|
370 | self.id = None | |
371 | self.datatype = None |
|
371 | self.datatype = None | |
372 | self.name = None |
|
372 | self.name = None | |
373 | self.inputId = 0 |
|
373 | self.inputId = 0 | |
374 |
|
374 | |||
375 | self.opConfObjList = [] |
|
375 | self.opConfObjList = [] | |
376 | self.opObjList = [] |
|
376 | self.opObjList = [] | |
377 |
|
377 | |||
378 | def getElementName(self): |
|
378 | def getElementName(self): | |
379 |
|
379 | |||
380 | return self.ELEMENTNAME |
|
380 | return self.ELEMENTNAME | |
381 |
|
381 | |||
382 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): |
|
382 | def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): | |
383 |
|
383 | |||
384 | self.id = id |
|
384 | self.id = id | |
385 | self.name = name |
|
385 | self.name = name | |
386 | self.datatype = datatype |
|
386 | self.datatype = datatype | |
387 |
|
387 | |||
388 | self.path = path |
|
388 | self.path = path | |
389 | self.startDate = startDate |
|
389 | self.startDate = startDate | |
390 | self.endDate = endDate |
|
390 | self.endDate = endDate | |
391 | self.startTime = startTime |
|
391 | self.startTime = startTime | |
392 | self.endTime = endTime |
|
392 | self.endTime = endTime | |
393 | self.online = online |
|
393 | self.online = online | |
394 | self.expLabel = expLabel |
|
394 | self.expLabel = expLabel | |
395 | self.delay = delay |
|
395 | self.delay = delay | |
396 |
|
396 | |||
397 | self.addRunOperation() |
|
397 | self.addRunOperation() | |
398 |
|
398 | |||
399 | def addRunOperation(self): |
|
399 | def addRunOperation(self): | |
400 |
|
400 | |||
401 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
401 | opObj = self.addOperation(name = 'run', optype = 'self') | |
402 |
|
402 | |||
403 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
403 | opObj.addParameter(name='path' , value=self.path, format='str') | |
404 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
404 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
405 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
405 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
406 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
406 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
407 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
407 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
408 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') |
|
408 | opObj.addParameter(name='expLabel' , value=self.expLabel, format='str') | |
409 | opObj.addParameter(name='online' , value=self.online, format='int') |
|
409 | opObj.addParameter(name='online' , value=self.online, format='int') | |
410 | opObj.addParameter(name='delay' , value=self.delay, format='float') |
|
410 | opObj.addParameter(name='delay' , value=self.delay, format='float') | |
411 |
|
411 | |||
412 | return opObj |
|
412 | return opObj | |
413 |
|
413 | |||
414 |
|
414 | |||
415 | class Controller(): |
|
415 | class Controller(): | |
416 |
|
416 | |||
417 | id = None |
|
417 | id = None | |
418 | name = None |
|
418 | name = None | |
419 | description = None |
|
419 | description = None | |
420 | # readUnitConfObjList = None |
|
420 | # readUnitConfObjList = None | |
421 | procUnitConfObjDict = None |
|
421 | procUnitConfObjDict = None | |
422 |
|
422 | |||
423 | ELEMENTNAME = 'Controller' |
|
423 | ELEMENTNAME = 'Controller' | |
424 |
|
424 | |||
425 | def __init__(self): |
|
425 | def __init__(self): | |
426 |
|
426 | |||
427 | self.id = None |
|
427 | self.id = None | |
428 | self.name = None |
|
428 | self.name = None | |
429 | self.description = None |
|
429 | self.description = None | |
430 |
|
430 | |||
431 | # self.readUnitConfObjList = [] |
|
431 | # self.readUnitConfObjList = [] | |
432 | self.procUnitConfObjDict = {} |
|
432 | self.procUnitConfObjDict = {} | |
433 |
|
433 | |||
434 | def __getNewId(self): |
|
434 | def __getNewId(self): | |
435 |
|
435 | |||
436 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
436 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
437 |
|
437 | |||
438 | return str(id) |
|
438 | return str(id) | |
439 |
|
439 | |||
440 | def getElementName(self): |
|
440 | def getElementName(self): | |
441 |
|
441 | |||
442 | return self.ELEMENTNAME |
|
442 | return self.ELEMENTNAME | |
443 |
|
443 | |||
444 | def setup(self, id, name, description): |
|
444 | def setup(self, id, name, description): | |
445 |
|
445 | |||
446 | self.id = id |
|
446 | self.id = id | |
447 | self.name = name |
|
447 | self.name = name | |
448 | self.description = description |
|
448 | self.description = description | |
449 |
|
449 | |||
450 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): |
|
450 | def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): | |
451 |
|
451 | |||
452 | id = self.__getNewId() |
|
452 | id = self.__getNewId() | |
453 | name = '%sReader' %(datatype) |
|
453 | name = '%sReader' %(datatype) | |
454 |
|
454 | |||
455 | readUnitConfObj = ReadUnitConf() |
|
455 | readUnitConfObj = ReadUnitConf() | |
456 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay) |
|
456 | readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay) | |
457 |
|
457 | |||
458 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
458 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
459 |
|
459 | |||
460 | return readUnitConfObj |
|
460 | return readUnitConfObj | |
461 |
|
461 | |||
462 | def addProcUnit(self, datatype, inputId): |
|
462 | def addProcUnit(self, datatype, inputId): | |
463 |
|
463 | |||
464 | id = self.__getNewId() |
|
464 | id = self.__getNewId() | |
465 | name = '%sProc' %(datatype) |
|
465 | name = '%sProc' %(datatype) | |
466 |
|
466 | |||
467 | procUnitConfObj = ProcUnitConf() |
|
467 | procUnitConfObj = ProcUnitConf() | |
468 | procUnitConfObj.setup(id, name, datatype, inputId) |
|
468 | procUnitConfObj.setup(id, name, datatype, inputId) | |
469 |
|
469 | |||
470 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
470 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
471 |
|
471 | |||
472 | return procUnitConfObj |
|
472 | return procUnitConfObj | |
473 |
|
473 | |||
474 | def makeXml(self): |
|
474 | def makeXml(self): | |
475 |
|
475 | |||
476 | projectElement = Element('Controller') |
|
476 | projectElement = Element('Controller') | |
477 | projectElement.set('id', str(self.id)) |
|
477 | projectElement.set('id', str(self.id)) | |
478 | projectElement.set('name', self.name) |
|
478 | projectElement.set('name', self.name) | |
479 | projectElement.set('description', self.description) |
|
479 | projectElement.set('description', self.description) | |
480 |
|
480 | |||
481 | # for readUnitConfObj in self.readUnitConfObjList: |
|
481 | # for readUnitConfObj in self.readUnitConfObjList: | |
482 | # readUnitConfObj.makeXml(projectElement) |
|
482 | # readUnitConfObj.makeXml(projectElement) | |
483 |
|
483 | |||
484 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
484 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
485 | procUnitConfObj.makeXml(projectElement) |
|
485 | procUnitConfObj.makeXml(projectElement) | |
486 |
|
486 | |||
487 | self.projectElement = projectElement |
|
487 | self.projectElement = projectElement | |
488 |
|
488 | |||
489 | def writeXml(self, filename): |
|
489 | def writeXml(self, filename): | |
490 |
|
490 | |||
491 | self.makeXml() |
|
491 | self.makeXml() | |
492 |
|
492 | |||
493 | print prettify(self.projectElement) |
|
493 | print prettify(self.projectElement) | |
494 |
|
494 | |||
495 | ElementTree(self.projectElement).write(filename, method='xml') |
|
495 | ElementTree(self.projectElement).write(filename, method='xml') | |
496 |
|
496 | |||
497 | def readXml(self, filename): |
|
497 | def readXml(self, filename): | |
498 |
|
498 | |||
499 | #tree = ET.parse(filename) |
|
499 | #tree = ET.parse(filename) | |
500 | self.projectElement = None |
|
500 | self.projectElement = None | |
501 | # self.readUnitConfObjList = [] |
|
501 | # self.readUnitConfObjList = [] | |
502 | self.procUnitConfObjDict = {} |
|
502 | self.procUnitConfObjDict = {} | |
503 |
|
503 | |||
504 | self.projectElement = ElementTree().parse(filename) |
|
504 | self.projectElement = ElementTree().parse(filename) | |
505 |
|
505 | |||
506 | self.project = self.projectElement.tag |
|
506 | self.project = self.projectElement.tag | |
507 |
|
507 | |||
508 | self.id = self.projectElement.get('id') |
|
508 | self.id = self.projectElement.get('id') | |
509 | self.name = self.projectElement.get('name') |
|
509 | self.name = self.projectElement.get('name') | |
510 | self.description = self.projectElement.get('description') |
|
510 | self.description = self.projectElement.get('description') | |
511 |
|
511 | |||
512 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
512 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
513 |
|
513 | |||
514 | for readUnitElement in readUnitElementList: |
|
514 | for readUnitElement in readUnitElementList: | |
515 | readUnitConfObj = ReadUnitConf() |
|
515 | readUnitConfObj = ReadUnitConf() | |
516 | readUnitConfObj.readXml(readUnitElement) |
|
516 | readUnitConfObj.readXml(readUnitElement) | |
517 |
|
517 | |||
518 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
518 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
519 |
|
519 | |||
520 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
520 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
521 |
|
521 | |||
522 | for procUnitElement in procUnitElementList: |
|
522 | for procUnitElement in procUnitElementList: | |
523 | procUnitConfObj = ProcUnitConf() |
|
523 | procUnitConfObj = ProcUnitConf() | |
524 | procUnitConfObj.readXml(procUnitElement) |
|
524 | procUnitConfObj.readXml(procUnitElement) | |
525 |
|
525 | |||
526 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
526 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
527 |
|
527 | |||
528 | def printattr(self): |
|
528 | def printattr(self): | |
529 |
|
529 | |||
530 | print "Controller[%s]: name = %s, description = %s" %(self.id, |
|
530 | print "Controller[%s]: name = %s, description = %s" %(self.id, | |
531 | self.name, |
|
531 | self.name, | |
532 | self.description) |
|
532 | self.description) | |
533 |
|
533 | |||
534 | # for readUnitConfObj in self.readUnitConfObjList: |
|
534 | # for readUnitConfObj in self.readUnitConfObjList: | |
535 | # readUnitConfObj.printattr() |
|
535 | # readUnitConfObj.printattr() | |
536 |
|
536 | |||
537 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
537 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
538 | procUnitConfObj.printattr() |
|
538 | procUnitConfObj.printattr() | |
539 |
|
539 | |||
540 | def createObjects(self): |
|
540 | def createObjects(self): | |
541 |
|
541 | |||
542 | # for readUnitConfObj in self.readUnitConfObjList: |
|
542 | # for readUnitConfObj in self.readUnitConfObjList: | |
543 | # readUnitConfObj.createObjects() |
|
543 | # readUnitConfObj.createObjects() | |
544 |
|
544 | |||
545 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
545 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
546 | procUnitConfObj.createObjects() |
|
546 | procUnitConfObj.createObjects() | |
547 |
|
547 | |||
548 | def __connect(self, objIN, obj): |
|
548 | def __connect(self, objIN, obj): | |
549 |
|
549 | |||
550 | obj.setInput(objIN.getOutput()) |
|
550 | obj.setInput(objIN.getOutput()) | |
551 |
|
551 | |||
552 | def connectObjects(self): |
|
552 | def connectObjects(self): | |
553 |
|
553 | |||
554 | for puConfObj in self.procUnitConfObjDict.values(): |
|
554 | for puConfObj in self.procUnitConfObjDict.values(): | |
555 |
|
555 | |||
556 | inputId = puConfObj.getInputId() |
|
556 | inputId = puConfObj.getInputId() | |
557 |
|
557 | |||
558 | if int(inputId) == 0: |
|
558 | if int(inputId) == 0: | |
559 | continue |
|
559 | continue | |
560 |
|
560 | |||
561 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
561 | puConfINObj = self.procUnitConfObjDict[inputId] | |
562 |
|
562 | |||
563 | puObj = puConfObj.getProcUnitObj() |
|
563 | puObj = puConfObj.getProcUnitObj() | |
564 | puINObj = puConfINObj.getProcUnitObj() |
|
564 | puINObj = puConfINObj.getProcUnitObj() | |
565 |
|
565 | |||
566 | self.__connect(puINObj, puObj) |
|
566 | self.__connect(puINObj, puObj) | |
567 |
|
567 | |||
568 | def run(self): |
|
568 | def run(self): | |
569 |
|
569 | |||
570 | # for readUnitConfObj in self.readUnitConfObjList: |
|
570 | # for readUnitConfObj in self.readUnitConfObjList: | |
571 | # readUnitConfObj.run() |
|
571 | # readUnitConfObj.run() | |
572 |
|
572 | |||
573 | while(True): |
|
573 | while(True): | |
574 |
|
574 | |||
575 | finalSts = False |
|
575 | finalSts = False | |
576 |
|
576 | |||
577 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
577 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
578 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
578 | #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
579 | sts = procUnitConfObj.run() |
|
579 | sts = procUnitConfObj.run() | |
580 | finalSts = finalSts or sts |
|
580 | finalSts = finalSts or sts | |
581 |
|
581 | |||
582 | #If every process unit finished so end process |
|
582 | #If every process unit finished so end process | |
583 | if not(finalSts): |
|
583 | if not(finalSts): | |
584 | print "Every process units have finished" |
|
584 | print "Every process units have finished" | |
585 | break |
|
585 | break | |
586 |
|
586 | |||
587 | if __name__ == '__main__': |
|
587 | if __name__ == '__main__': | |
588 |
|
588 | |||
589 | desc = "Segundo Test" |
|
589 | desc = "Segundo Test" | |
590 | filename = "schain.xml" |
|
590 | filename = "schain.xml" | |
591 |
|
591 | |||
592 | controllerObj = Controller() |
|
592 | controllerObj = Controller() | |
593 |
|
593 | |||
594 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
594 | controllerObj.setup(id = '191', name='test01', description=desc) | |
595 |
|
595 | |||
596 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
596 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
597 | path='data/rawdata/', |
|
597 | path='data/rawdata/', | |
598 | startDate='2011/01/01', |
|
598 | startDate='2011/01/01', | |
599 | endDate='2012/12/31', |
|
599 | endDate='2012/12/31', | |
600 | startTime='00:00:00', |
|
600 | startTime='00:00:00', | |
601 | endTime='23:59:59', |
|
601 | endTime='23:59:59', | |
602 | online=0) |
|
602 | online=0) | |
603 |
|
603 | |||
604 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') |
|
604 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') | |
605 |
|
605 | |||
606 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
606 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
607 |
|
607 | |||
608 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
608 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') | |
609 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
609 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') | |
610 |
|
610 | |||
611 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
611 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
612 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
612 | opObj10.addParameter(name='minHei', value='90', format='float') | |
613 |
opObj10.addParameter(name='maxHei', value=' |
|
613 | opObj10.addParameter(name='maxHei', value='180', format='float') | |
614 |
|
614 | |||
615 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') |
|
615 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') | |
616 | opObj12.addParameter(name='n', value='10', format='int') |
|
616 | opObj12.addParameter(name='n', value='10', format='int') | |
617 |
|
617 | |||
618 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') |
|
|||
619 | opObj12.addParameter(name='n', value='2', format='int') |
|
|||
620 | opObj12.addParameter(name='overlapping', value='1', format='int') |
|
|||
621 |
|
||||
622 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
618 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
623 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
619 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') | |
624 |
|
620 | |||
625 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
621 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
626 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
622 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
627 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') |
|
623 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') | |
628 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
624 | opObj11.addParameter(name='zmin', value='40', format='int') | |
629 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
625 | opObj11.addParameter(name='zmax', value='90', format='int') | |
630 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
626 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
631 |
|
627 | |||
632 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
|
628 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) | |
633 | opObj11.addParameter(name='idfigure', value='10', format='int') |
|
629 | ||
634 | opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
630 | opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other') | |
635 |
|
|
631 | opObj12.addParameter(name='n', value='2', format='int') | |
636 |
|
|
632 | opObj12.addParameter(name='overlapping', value='1', format='int') | |
|
633 | ||||
|
634 | procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) | |||
|
635 | procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') | |||
|
636 | ||||
|
637 | opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other') | |||
|
638 | opObj11.addParameter(name='idfigure', value='2', format='int') | |||
|
639 | opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') | |||
637 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
640 | opObj11.addParameter(name='zmin', value='40', format='int') | |
638 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
641 | opObj11.addParameter(name='zmax', value='90', format='int') | |
639 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
642 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
640 | opObj11.addParameter(name='timerange', value=str(60), format='int') |
|
643 | ||
|
644 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |||
|
645 | # opObj11.addParameter(name='idfigure', value='10', format='int') | |||
|
646 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') | |||
|
647 | ## opObj11.addParameter(name='xmin', value='21', format='float') | |||
|
648 | ## opObj11.addParameter(name='xmax', value='22', format='float') | |||
|
649 | # opObj11.addParameter(name='zmin', value='40', format='int') | |||
|
650 | # opObj11.addParameter(name='zmax', value='90', format='int') | |||
|
651 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |||
|
652 | # opObj11.addParameter(name='timerange', value=str(60), format='int') | |||
641 |
|
653 | |||
642 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
654 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
643 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') |
|
655 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') | |
644 | # |
|
656 | # | |
645 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
657 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
646 | # opObj12.addParameter(name='n', value='2', format='int') |
|
658 | # opObj12.addParameter(name='n', value='2', format='int') | |
647 | # |
|
659 | # | |
648 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
660 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
649 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
661 | # opObj11.addParameter(name='idfigure', value='2', format='int') | |
650 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
662 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
651 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
663 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
652 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
664 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
653 | # |
|
665 | # | |
654 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
666 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
655 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') |
|
667 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') | |
656 | # |
|
668 | # | |
657 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
669 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
658 | # opObj12.addParameter(name='n', value='2', format='int') |
|
670 | # opObj12.addParameter(name='n', value='2', format='int') | |
659 | # |
|
671 | # | |
660 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
672 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
661 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
673 | # opObj11.addParameter(name='idfigure', value='3', format='int') | |
662 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
674 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
663 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
675 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
664 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
676 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
665 |
|
677 | |||
666 |
|
678 | |||
667 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
679 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |
668 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
680 | # opObj12.addParameter(name='ncode', value='2', format='int') | |
669 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
681 | # opObj12.addParameter(name='nbauds', value='8', format='int') | |
670 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
682 | # opObj12.addParameter(name='code0', value='001110011', format='int') | |
671 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
683 | # opObj12.addParameter(name='code1', value='001110011', format='int') | |
672 |
|
684 | |||
673 |
|
685 | |||
674 |
|
686 | |||
675 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
687 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) | |
676 | # |
|
688 | # | |
677 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') |
|
689 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') | |
678 | # opObj21.addParameter(name='n', value='2', format='int') |
|
690 | # opObj21.addParameter(name='n', value='2', format='int') | |
679 | # |
|
691 | # | |
680 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') |
|
692 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') | |
681 | # opObj11.addParameter(name='idfigure', value='4', format='int') |
|
693 | # opObj11.addParameter(name='idfigure', value='4', format='int') | |
682 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') |
|
694 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') | |
683 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
695 | # opObj11.addParameter(name='zmin', value='70', format='int') | |
684 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
696 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
685 |
|
697 | |||
686 | print "Escribiendo el archivo XML" |
|
698 | print "Escribiendo el archivo XML" | |
687 |
|
699 | |||
688 | controllerObj.writeXml(filename) |
|
700 | controllerObj.writeXml(filename) | |
689 |
|
701 | |||
690 | print "Leyendo el archivo XML" |
|
702 | print "Leyendo el archivo XML" | |
691 | controllerObj.readXml(filename) |
|
703 | controllerObj.readXml(filename) | |
692 | #controllerObj.printattr() |
|
704 | #controllerObj.printattr() | |
693 |
|
705 | |||
694 | controllerObj.createObjects() |
|
706 | controllerObj.createObjects() | |
695 | controllerObj.connectObjects() |
|
707 | controllerObj.connectObjects() | |
696 | controllerObj.run() |
|
708 | controllerObj.run() | |
697 |
|
709 | |||
698 | No newline at end of file |
|
710 |
@@ -1,971 +1,975 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: dsuarez $ |
|
3 | $Author: dsuarez $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import numpy |
|
7 | import numpy | |
8 | import datetime |
|
8 | import datetime | |
9 | import time |
|
9 | import time | |
10 |
|
10 | |||
11 | from jrodata import * |
|
11 | from jrodata import * | |
12 | from jrodataIO import * |
|
12 | from jrodataIO import * | |
13 | from jroplot import * |
|
13 | from jroplot import * | |
14 |
|
14 | |||
15 | class ProcessingUnit: |
|
15 | class ProcessingUnit: | |
16 |
|
16 | |||
17 | """ |
|
17 | """ | |
18 | Esta es la clase base para el procesamiento de datos. |
|
18 | Esta es la clase base para el procesamiento de datos. | |
19 |
|
19 | |||
20 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
20 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
21 | - Metodos internos (callMethod) |
|
21 | - Metodos internos (callMethod) | |
22 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
22 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
23 | tienen que ser agreagados con el metodo "add". |
|
23 | tienen que ser agreagados con el metodo "add". | |
24 |
|
24 | |||
25 | """ |
|
25 | """ | |
26 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
26 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
27 | dataIn = None |
|
27 | dataIn = None | |
28 |
|
28 | |||
29 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
29 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
30 | dataOut = None |
|
30 | dataOut = None | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | objectDict = None |
|
33 | objectDict = None | |
34 |
|
34 | |||
35 | def __init__(self): |
|
35 | def __init__(self): | |
36 |
|
36 | |||
37 | self.objectDict = {} |
|
37 | self.objectDict = {} | |
38 |
|
38 | |||
39 | def init(self): |
|
39 | def init(self): | |
40 |
|
40 | |||
41 | raise ValueError, "Not implemented" |
|
41 | raise ValueError, "Not implemented" | |
42 |
|
42 | |||
43 | def addOperation(self, object, objId): |
|
43 | def addOperation(self, object, objId): | |
44 |
|
44 | |||
45 | """ |
|
45 | """ | |
46 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
46 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el | |
47 | identificador asociado a este objeto. |
|
47 | identificador asociado a este objeto. | |
48 |
|
48 | |||
49 | Input: |
|
49 | Input: | |
50 |
|
50 | |||
51 | object : objeto de la clase "Operation" |
|
51 | object : objeto de la clase "Operation" | |
52 |
|
52 | |||
53 | Return: |
|
53 | Return: | |
54 |
|
54 | |||
55 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
55 | objId : identificador del objeto, necesario para ejecutar la operacion | |
56 | """ |
|
56 | """ | |
57 |
|
57 | |||
58 | self.objectDict[objId] = object |
|
58 | self.objectDict[objId] = object | |
59 |
|
59 | |||
60 | return objId |
|
60 | return objId | |
61 |
|
61 | |||
62 | def operation(self, **kwargs): |
|
62 | def operation(self, **kwargs): | |
63 |
|
63 | |||
64 | """ |
|
64 | """ | |
65 | Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los |
|
65 | Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los | |
66 | atributos del objeto dataOut |
|
66 | atributos del objeto dataOut | |
67 |
|
67 | |||
68 | Input: |
|
68 | Input: | |
69 |
|
69 | |||
70 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
70 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
71 | """ |
|
71 | """ | |
72 |
|
72 | |||
73 | raise ValueError, "ImplementedError" |
|
73 | raise ValueError, "ImplementedError" | |
74 |
|
74 | |||
75 | def callMethod(self, name, **kwargs): |
|
75 | def callMethod(self, name, **kwargs): | |
76 |
|
76 | |||
77 | """ |
|
77 | """ | |
78 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
78 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
79 |
|
79 | |||
80 | Input: |
|
80 | Input: | |
81 | name : nombre del metodo a ejecutar |
|
81 | name : nombre del metodo a ejecutar | |
82 |
|
82 | |||
83 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
83 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
84 |
|
84 | |||
85 | """ |
|
85 | """ | |
86 | if name != 'run': |
|
86 | if name != 'run': | |
87 |
|
87 | |||
88 | if name == 'init' and self.dataIn.isEmpty(): |
|
88 | if name == 'init' and self.dataIn.isEmpty(): | |
89 | self.dataOut.flagNoData = True |
|
89 | self.dataOut.flagNoData = True | |
90 | return False |
|
90 | return False | |
91 |
|
91 | |||
92 | if name != 'init' and self.dataOut.isEmpty(): |
|
92 | if name != 'init' and self.dataOut.isEmpty(): | |
93 | return False |
|
93 | return False | |
94 |
|
94 | |||
95 | methodToCall = getattr(self, name) |
|
95 | methodToCall = getattr(self, name) | |
96 |
|
96 | |||
97 | methodToCall(**kwargs) |
|
97 | methodToCall(**kwargs) | |
98 |
|
98 | |||
99 | if name != 'run': |
|
99 | if name != 'run': | |
100 | return True |
|
100 | return True | |
101 |
|
101 | |||
102 | if self.dataOut.isEmpty(): |
|
102 | if self.dataOut.isEmpty(): | |
103 | return False |
|
103 | return False | |
104 |
|
104 | |||
105 | return True |
|
105 | return True | |
106 |
|
106 | |||
107 | def callObject(self, objId, **kwargs): |
|
107 | def callObject(self, objId, **kwargs): | |
108 |
|
108 | |||
109 | """ |
|
109 | """ | |
110 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
110 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
111 |
|
111 | |||
112 | Input: |
|
112 | Input: | |
113 |
|
113 | |||
114 | objId : identificador del objeto a ejecutar |
|
114 | objId : identificador del objeto a ejecutar | |
115 |
|
115 | |||
116 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
116 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
117 |
|
117 | |||
118 | Return: |
|
118 | Return: | |
119 |
|
119 | |||
120 | None |
|
120 | None | |
121 | """ |
|
121 | """ | |
122 |
|
122 | |||
123 | if self.dataOut.isEmpty(): |
|
123 | if self.dataOut.isEmpty(): | |
124 | return False |
|
124 | return False | |
125 |
|
125 | |||
126 | object = self.objectDict[objId] |
|
126 | object = self.objectDict[objId] | |
127 |
|
127 | |||
128 | object.run(self.dataOut, **kwargs) |
|
128 | object.run(self.dataOut, **kwargs) | |
129 |
|
129 | |||
130 | return True |
|
130 | return True | |
131 |
|
131 | |||
132 | def call(self, operationConf, **kwargs): |
|
132 | def call(self, operationConf, **kwargs): | |
133 |
|
133 | |||
134 | """ |
|
134 | """ | |
135 | Return True si ejecuta la operacion "operationConf.name" con los |
|
135 | Return True si ejecuta la operacion "operationConf.name" con los | |
136 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
136 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
137 | La operacion puede ser de dos tipos: |
|
137 | La operacion puede ser de dos tipos: | |
138 |
|
138 | |||
139 | 1. Un metodo propio de esta clase: |
|
139 | 1. Un metodo propio de esta clase: | |
140 |
|
140 | |||
141 | operation.type = "self" |
|
141 | operation.type = "self" | |
142 |
|
142 | |||
143 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
143 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
144 | operation.type = "other". |
|
144 | operation.type = "other". | |
145 |
|
145 | |||
146 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
146 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
147 | "addOperation" e identificado con el operation.id |
|
147 | "addOperation" e identificado con el operation.id | |
148 |
|
148 | |||
149 |
|
149 | |||
150 | con el id de la operacion. |
|
150 | con el id de la operacion. | |
151 |
|
151 | |||
152 | Input: |
|
152 | Input: | |
153 |
|
153 | |||
154 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
154 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
155 |
|
155 | |||
156 | """ |
|
156 | """ | |
157 |
|
157 | |||
158 | if operationConf.type == 'self': |
|
158 | if operationConf.type == 'self': | |
159 | sts = self.callMethod(operationConf.name, **kwargs) |
|
159 | sts = self.callMethod(operationConf.name, **kwargs) | |
160 |
|
160 | |||
161 | if operationConf.type == 'other': |
|
161 | if operationConf.type == 'other': | |
162 | sts = self.callObject(operationConf.id, **kwargs) |
|
162 | sts = self.callObject(operationConf.id, **kwargs) | |
163 |
|
163 | |||
164 | return sts |
|
164 | return sts | |
165 |
|
165 | |||
166 | def setInput(self, dataIn): |
|
166 | def setInput(self, dataIn): | |
167 |
|
167 | |||
168 | self.dataIn = dataIn |
|
168 | self.dataIn = dataIn | |
169 |
|
169 | |||
170 | def getOutput(self): |
|
170 | def getOutput(self): | |
171 |
|
171 | |||
172 | return self.dataOut |
|
172 | return self.dataOut | |
173 |
|
173 | |||
174 | class Operation(): |
|
174 | class Operation(): | |
175 |
|
175 | |||
176 | """ |
|
176 | """ | |
177 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
177 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
178 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
178 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
179 | acumulacion dentro de esta clase |
|
179 | acumulacion dentro de esta clase | |
180 |
|
180 | |||
181 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
181 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
182 |
|
182 | |||
183 | """ |
|
183 | """ | |
184 |
|
184 | |||
185 | __buffer = None |
|
185 | __buffer = None | |
186 | __isConfig = False |
|
186 | __isConfig = False | |
187 |
|
187 | |||
188 | def __init__(self): |
|
188 | def __init__(self): | |
189 |
|
189 | |||
190 | pass |
|
190 | pass | |
191 |
|
191 | |||
192 | def run(self, dataIn, **kwargs): |
|
192 | def run(self, dataIn, **kwargs): | |
193 |
|
193 | |||
194 | """ |
|
194 | """ | |
195 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
195 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. | |
196 |
|
196 | |||
197 | Input: |
|
197 | Input: | |
198 |
|
198 | |||
199 | dataIn : objeto del tipo JROData |
|
199 | dataIn : objeto del tipo JROData | |
200 |
|
200 | |||
201 | Return: |
|
201 | Return: | |
202 |
|
202 | |||
203 | None |
|
203 | None | |
204 |
|
204 | |||
205 | Affected: |
|
205 | Affected: | |
206 | __buffer : buffer de recepcion de datos. |
|
206 | __buffer : buffer de recepcion de datos. | |
207 |
|
207 | |||
208 | """ |
|
208 | """ | |
209 |
|
209 | |||
210 | raise ValueError, "ImplementedError" |
|
210 | raise ValueError, "ImplementedError" | |
211 |
|
211 | |||
212 | class VoltageProc(ProcessingUnit): |
|
212 | class VoltageProc(ProcessingUnit): | |
213 |
|
213 | |||
214 |
|
214 | |||
215 | def __init__(self): |
|
215 | def __init__(self): | |
216 |
|
216 | |||
217 | self.objectDict = {} |
|
217 | self.objectDict = {} | |
218 | self.dataOut = Voltage() |
|
218 | self.dataOut = Voltage() | |
219 |
|
219 | |||
220 | def init(self): |
|
220 | def init(self): | |
221 |
|
221 | |||
222 | self.dataOut.copy(self.dataIn) |
|
222 | self.dataOut.copy(self.dataIn) | |
223 | # No necesita copiar en cada init() los atributos de dataIn |
|
223 | # No necesita copiar en cada init() los atributos de dataIn | |
224 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
224 | # la copia deberia hacerse por cada nuevo bloque de datos | |
225 |
|
225 | |||
226 | def selectChannels(self, channelList): |
|
226 | def selectChannels(self, channelList): | |
227 |
|
227 | |||
228 | channelIndexList = [] |
|
228 | channelIndexList = [] | |
229 |
|
229 | |||
230 | for channel in channelList: |
|
230 | for channel in channelList: | |
231 | index = self.dataOut.channelList.index(channel) |
|
231 | index = self.dataOut.channelList.index(channel) | |
232 | channelIndexList.append(index) |
|
232 | channelIndexList.append(index) | |
233 |
|
233 | |||
234 | self.selectChannelsByIndex(channelIndexList) |
|
234 | self.selectChannelsByIndex(channelIndexList) | |
235 |
|
235 | |||
236 | def selectChannelsByIndex(self, channelIndexList): |
|
236 | def selectChannelsByIndex(self, channelIndexList): | |
237 | """ |
|
237 | """ | |
238 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
238 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
239 |
|
239 | |||
240 | Input: |
|
240 | Input: | |
241 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
241 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
242 |
|
242 | |||
243 | Affected: |
|
243 | Affected: | |
244 | self.dataOut.data |
|
244 | self.dataOut.data | |
245 | self.dataOut.channelIndexList |
|
245 | self.dataOut.channelIndexList | |
246 | self.dataOut.nChannels |
|
246 | self.dataOut.nChannels | |
247 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
247 | self.dataOut.m_ProcessingHeader.totalSpectra | |
248 | self.dataOut.systemHeaderObj.numChannels |
|
248 | self.dataOut.systemHeaderObj.numChannels | |
249 | self.dataOut.m_ProcessingHeader.blockSize |
|
249 | self.dataOut.m_ProcessingHeader.blockSize | |
250 |
|
250 | |||
251 | Return: |
|
251 | Return: | |
252 | None |
|
252 | None | |
253 | """ |
|
253 | """ | |
254 |
|
254 | |||
255 | for channelIndex in channelIndexList: |
|
255 | for channelIndex in channelIndexList: | |
256 | if channelIndex not in self.dataOut.channelIndexList: |
|
256 | if channelIndex not in self.dataOut.channelIndexList: | |
257 | print channelIndexList |
|
257 | print channelIndexList | |
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
259 |
|
259 | |||
260 | nChannels = len(channelIndexList) |
|
260 | nChannels = len(channelIndexList) | |
261 |
|
261 | |||
262 | data = self.dataOut.data[channelIndexList,:] |
|
262 | data = self.dataOut.data[channelIndexList,:] | |
263 |
|
263 | |||
264 | self.dataOut.data = data |
|
264 | self.dataOut.data = data | |
265 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
265 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
266 | # self.dataOut.nChannels = nChannels |
|
266 | # self.dataOut.nChannels = nChannels | |
267 |
|
267 | |||
268 | return 1 |
|
268 | return 1 | |
269 |
|
269 | |||
270 | def selectHeights(self, minHei, maxHei): |
|
270 | def selectHeights(self, minHei, maxHei): | |
271 | """ |
|
271 | """ | |
272 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
272 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
273 | minHei <= height <= maxHei |
|
273 | minHei <= height <= maxHei | |
274 |
|
274 | |||
275 | Input: |
|
275 | Input: | |
276 | minHei : valor minimo de altura a considerar |
|
276 | minHei : valor minimo de altura a considerar | |
277 | maxHei : valor maximo de altura a considerar |
|
277 | maxHei : valor maximo de altura a considerar | |
278 |
|
278 | |||
279 | Affected: |
|
279 | Affected: | |
280 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
280 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
281 |
|
281 | |||
282 | Return: |
|
282 | Return: | |
283 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
283 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
284 | """ |
|
284 | """ | |
285 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
285 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
286 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
286 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
287 |
|
287 | |||
288 | if (maxHei > self.dataOut.heightList[-1]): |
|
288 | if (maxHei > self.dataOut.heightList[-1]): | |
289 | maxHei = self.dataOut.heightList[-1] |
|
289 | maxHei = self.dataOut.heightList[-1] | |
290 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
290 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
291 |
|
291 | |||
292 | minIndex = 0 |
|
292 | minIndex = 0 | |
293 | maxIndex = 0 |
|
293 | maxIndex = 0 | |
294 | data = self.dataOut.heightList |
|
294 | data = self.dataOut.heightList | |
295 |
|
295 | |||
296 | for i,val in enumerate(data): |
|
296 | for i,val in enumerate(data): | |
297 | if val < minHei: |
|
297 | if val < minHei: | |
298 | continue |
|
298 | continue | |
299 | else: |
|
299 | else: | |
300 | minIndex = i; |
|
300 | minIndex = i; | |
301 | break |
|
301 | break | |
302 |
|
302 | |||
303 | for i,val in enumerate(data): |
|
303 | for i,val in enumerate(data): | |
304 | if val <= maxHei: |
|
304 | if val <= maxHei: | |
305 | maxIndex = i; |
|
305 | maxIndex = i; | |
306 | else: |
|
306 | else: | |
307 | break |
|
307 | break | |
308 |
|
308 | |||
309 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
309 | self.selectHeightsByIndex(minIndex, maxIndex) | |
310 |
|
310 | |||
311 | return 1 |
|
311 | return 1 | |
312 |
|
312 | |||
313 |
|
313 | |||
314 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
314 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
315 | """ |
|
315 | """ | |
316 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
316 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
317 | minIndex <= index <= maxIndex |
|
317 | minIndex <= index <= maxIndex | |
318 |
|
318 | |||
319 | Input: |
|
319 | Input: | |
320 | minIndex : valor de indice minimo de altura a considerar |
|
320 | minIndex : valor de indice minimo de altura a considerar | |
321 | maxIndex : valor de indice maximo de altura a considerar |
|
321 | maxIndex : valor de indice maximo de altura a considerar | |
322 |
|
322 | |||
323 | Affected: |
|
323 | Affected: | |
324 | self.dataOut.data |
|
324 | self.dataOut.data | |
325 | self.dataOut.heightList |
|
325 | self.dataOut.heightList | |
326 |
|
326 | |||
327 | Return: |
|
327 | Return: | |
328 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
328 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
329 | """ |
|
329 | """ | |
330 |
|
330 | |||
331 | if (minIndex < 0) or (minIndex > maxIndex): |
|
331 | if (minIndex < 0) or (minIndex > maxIndex): | |
332 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
332 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
333 |
|
333 | |||
334 | if (maxIndex >= self.dataOut.nHeights): |
|
334 | if (maxIndex >= self.dataOut.nHeights): | |
335 | maxIndex = self.dataOut.nHeights-1 |
|
335 | maxIndex = self.dataOut.nHeights-1 | |
336 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
336 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
337 |
|
337 | |||
338 | nHeights = maxIndex - minIndex + 1 |
|
338 | nHeights = maxIndex - minIndex + 1 | |
339 |
|
339 | |||
340 | #voltage |
|
340 | #voltage | |
341 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
341 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
342 |
|
342 | |||
343 | firstHeight = self.dataOut.heightList[minIndex] |
|
343 | firstHeight = self.dataOut.heightList[minIndex] | |
344 |
|
344 | |||
345 | self.dataOut.data = data |
|
345 | self.dataOut.data = data | |
346 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
346 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
347 |
|
347 | |||
348 | return 1 |
|
348 | return 1 | |
349 |
|
349 | |||
350 |
|
350 | |||
351 | class CohInt(Operation): |
|
351 | class CohInt(Operation): | |
352 |
|
352 | |||
353 | __profIndex = 0 |
|
353 | __profIndex = 0 | |
354 | __withOverapping = False |
|
354 | __withOverapping = False | |
355 |
|
355 | |||
356 | __byTime = False |
|
356 | __byTime = False | |
357 | __initime = None |
|
357 | __initime = None | |
358 | __lastdatatime = None |
|
358 | __lastdatatime = None | |
359 | __integrationtime = None |
|
359 | __integrationtime = None | |
360 |
|
360 | |||
361 | __buffer = None |
|
361 | __buffer = None | |
362 |
|
362 | |||
363 | __dataReady = False |
|
363 | __dataReady = False | |
364 |
|
364 | |||
365 | n = None |
|
365 | n = None | |
366 |
|
366 | |||
367 |
|
367 | |||
368 | def __init__(self): |
|
368 | def __init__(self): | |
369 |
|
369 | |||
370 | self.__isConfig = False |
|
370 | self.__isConfig = False | |
371 |
|
371 | |||
372 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
372 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
373 | """ |
|
373 | """ | |
374 | Set the parameters of the integration class. |
|
374 | Set the parameters of the integration class. | |
375 |
|
375 | |||
376 | Inputs: |
|
376 | Inputs: | |
377 |
|
377 | |||
378 | n : Number of coherent integrations |
|
378 | n : Number of coherent integrations | |
379 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
379 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
380 | overlapping : |
|
380 | overlapping : | |
381 |
|
381 | |||
382 | """ |
|
382 | """ | |
383 |
|
383 | |||
384 | self.__initime = None |
|
384 | self.__initime = None | |
385 | self.__lastdatatime = 0 |
|
385 | self.__lastdatatime = 0 | |
386 | self.__buffer = None |
|
386 | self.__buffer = None | |
387 | self.__dataReady = False |
|
387 | self.__dataReady = False | |
388 |
|
388 | |||
389 |
|
389 | |||
390 | if n == None and timeInterval == None: |
|
390 | if n == None and timeInterval == None: | |
391 | raise ValueError, "n or timeInterval should be specified ..." |
|
391 | raise ValueError, "n or timeInterval should be specified ..." | |
392 |
|
392 | |||
393 | if n != None: |
|
393 | if n != None: | |
394 | self.n = n |
|
394 | self.n = n | |
395 | self.__byTime = False |
|
395 | self.__byTime = False | |
396 | else: |
|
396 | else: | |
397 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
397 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
398 | self.n = 9999 |
|
398 | self.n = 9999 | |
399 | self.__byTime = True |
|
399 | self.__byTime = True | |
400 |
|
400 | |||
401 | if overlapping: |
|
401 | if overlapping: | |
402 | self.__withOverapping = True |
|
402 | self.__withOverapping = True | |
403 | self.__buffer = None |
|
403 | self.__buffer = None | |
404 | else: |
|
404 | else: | |
405 | self.__withOverapping = False |
|
405 | self.__withOverapping = False | |
406 | self.__buffer = 0 |
|
406 | self.__buffer = 0 | |
407 |
|
407 | |||
408 | self.__profIndex = 0 |
|
408 | self.__profIndex = 0 | |
409 |
|
409 | |||
410 | def putData(self, data): |
|
410 | def putData(self, data): | |
411 |
|
411 | |||
412 | """ |
|
412 | """ | |
413 | Add a profile to the __buffer and increase in one the __profileIndex |
|
413 | Add a profile to the __buffer and increase in one the __profileIndex | |
414 |
|
414 | |||
415 | """ |
|
415 | """ | |
416 |
|
416 | |||
417 | if not self.__withOverapping: |
|
417 | if not self.__withOverapping: | |
418 | self.__buffer += data.copy() |
|
418 | self.__buffer += data.copy() | |
419 | self.__profIndex += 1 |
|
419 | self.__profIndex += 1 | |
420 | return |
|
420 | return | |
421 |
|
421 | |||
422 | #Overlapping data |
|
422 | #Overlapping data | |
423 | nChannels, nHeis = data.shape |
|
423 | nChannels, nHeis = data.shape | |
424 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
424 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
425 |
|
425 | |||
426 | #If the buffer is empty then it takes the data value |
|
426 | #If the buffer is empty then it takes the data value | |
427 | if self.__buffer == None: |
|
427 | if self.__buffer == None: | |
428 | self.__buffer = data |
|
428 | self.__buffer = data | |
429 | self.__profIndex += 1 |
|
429 | self.__profIndex += 1 | |
430 | return |
|
430 | return | |
431 |
|
431 | |||
432 | #If the buffer length is lower than n then stakcing the data value |
|
432 | #If the buffer length is lower than n then stakcing the data value | |
433 | if self.__profIndex < self.n: |
|
433 | if self.__profIndex < self.n: | |
434 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
434 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
435 | self.__profIndex += 1 |
|
435 | self.__profIndex += 1 | |
436 | return |
|
436 | return | |
437 |
|
437 | |||
438 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
438 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
439 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
439 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
440 | self.__buffer[self.n-1] = data |
|
440 | self.__buffer[self.n-1] = data | |
441 | self.__profIndex = self.n |
|
441 | self.__profIndex = self.n | |
442 | return |
|
442 | return | |
443 |
|
443 | |||
444 |
|
444 | |||
445 | def pushData(self): |
|
445 | def pushData(self): | |
446 | """ |
|
446 | """ | |
447 | Return the sum of the last profiles and the profiles used in the sum. |
|
447 | Return the sum of the last profiles and the profiles used in the sum. | |
448 |
|
448 | |||
449 | Affected: |
|
449 | Affected: | |
450 |
|
450 | |||
451 | self.__profileIndex |
|
451 | self.__profileIndex | |
452 |
|
452 | |||
453 | """ |
|
453 | """ | |
454 |
|
454 | |||
455 | if not self.__withOverapping: |
|
455 | if not self.__withOverapping: | |
456 | data = self.__buffer |
|
456 | data = self.__buffer | |
457 | n = self.__profIndex |
|
457 | n = self.__profIndex | |
458 |
|
458 | |||
459 | self.__buffer = 0 |
|
459 | self.__buffer = 0 | |
460 | self.__profIndex = 0 |
|
460 | self.__profIndex = 0 | |
461 |
|
461 | |||
462 | return data, n |
|
462 | return data, n | |
463 |
|
463 | |||
464 | #Integration with Overlapping |
|
464 | #Integration with Overlapping | |
465 | data = numpy.sum(self.__buffer, axis=0) |
|
465 | data = numpy.sum(self.__buffer, axis=0) | |
466 | n = self.__profIndex |
|
466 | n = self.__profIndex | |
467 |
|
467 | |||
468 | return data, n |
|
468 | return data, n | |
469 |
|
469 | |||
470 | def byProfiles(self, data): |
|
470 | def byProfiles(self, data): | |
471 |
|
471 | |||
472 | self.__dataReady = False |
|
472 | self.__dataReady = False | |
473 | avgdata = None |
|
473 | avgdata = None | |
474 | n = None |
|
474 | n = None | |
475 |
|
475 | |||
476 | self.putData(data) |
|
476 | self.putData(data) | |
477 |
|
477 | |||
478 | if self.__profIndex == self.n: |
|
478 | if self.__profIndex == self.n: | |
479 |
|
479 | |||
480 | avgdata, n = self.pushData() |
|
480 | avgdata, n = self.pushData() | |
481 | self.__dataReady = True |
|
481 | self.__dataReady = True | |
482 |
|
482 | |||
483 | return avgdata |
|
483 | return avgdata | |
484 |
|
484 | |||
485 | def byTime(self, data, datatime): |
|
485 | def byTime(self, data, datatime): | |
486 |
|
486 | |||
487 | self.__dataReady = False |
|
487 | self.__dataReady = False | |
488 | avgdata = None |
|
488 | avgdata = None | |
489 | n = None |
|
489 | n = None | |
490 |
|
490 | |||
491 | self.putData(data) |
|
491 | self.putData(data) | |
492 |
|
492 | |||
493 | if (datatime - self.__initime) >= self.__integrationtime: |
|
493 | if (datatime - self.__initime) >= self.__integrationtime: | |
494 | avgdata, n = self.pushData() |
|
494 | avgdata, n = self.pushData() | |
495 | self.n = n |
|
495 | self.n = n | |
496 | self.__dataReady = True |
|
496 | self.__dataReady = True | |
497 |
|
497 | |||
498 | return avgdata |
|
498 | return avgdata | |
499 |
|
499 | |||
500 | def integrate(self, data, datatime=None): |
|
500 | def integrate(self, data, datatime=None): | |
501 |
|
501 | |||
502 | if self.__initime == None: |
|
502 | if self.__initime == None: | |
503 | self.__initime = datatime |
|
503 | self.__initime = datatime | |
504 |
|
504 | |||
505 | if self.__byTime: |
|
505 | if self.__byTime: | |
506 | avgdata = self.byTime(data, datatime) |
|
506 | avgdata = self.byTime(data, datatime) | |
507 | else: |
|
507 | else: | |
508 | avgdata = self.byProfiles(data) |
|
508 | avgdata = self.byProfiles(data) | |
509 |
|
509 | |||
510 |
|
510 | |||
511 | self.__lastdatatime = datatime |
|
511 | self.__lastdatatime = datatime | |
512 |
|
512 | |||
513 | if avgdata == None: |
|
513 | if avgdata == None: | |
514 | return None, None |
|
514 | return None, None | |
515 |
|
515 | |||
516 | avgdatatime = self.__initime |
|
516 | avgdatatime = self.__initime | |
517 |
|
517 | |||
518 | deltatime = datatime -self.__lastdatatime |
|
518 | deltatime = datatime -self.__lastdatatime | |
519 |
|
519 | |||
520 | if not self.__withOverapping: |
|
520 | if not self.__withOverapping: | |
521 | self.__initime = datatime |
|
521 | self.__initime = datatime | |
522 | else: |
|
522 | else: | |
523 | self.__initime += deltatime |
|
523 | self.__initime += deltatime | |
524 |
|
524 | |||
525 | return avgdata, avgdatatime |
|
525 | return avgdata, avgdatatime | |
526 |
|
526 | |||
527 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
527 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
528 |
|
528 | |||
529 | if not self.__isConfig: |
|
529 | if not self.__isConfig: | |
530 | self.setup(n, timeInterval, overlapping) |
|
530 | self.setup(n, timeInterval, overlapping) | |
531 | self.__isConfig = True |
|
531 | self.__isConfig = True | |
532 |
|
532 | |||
533 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
533 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
534 |
|
534 | |||
535 | # dataOut.timeInterval *= n |
|
535 | # dataOut.timeInterval *= n | |
536 | dataOut.flagNoData = True |
|
536 | dataOut.flagNoData = True | |
537 |
|
537 | |||
538 | if self.__dataReady: |
|
538 | if self.__dataReady: | |
539 | dataOut.data = avgdata |
|
539 | dataOut.data = avgdata | |
540 | dataOut.nCohInt *= self.n |
|
540 | dataOut.nCohInt *= self.n | |
541 | dataOut.utctime = avgdatatime |
|
541 | dataOut.utctime = avgdatatime | |
542 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
542 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
543 | dataOut.flagNoData = False |
|
543 | dataOut.flagNoData = False | |
544 |
|
544 | |||
545 |
|
545 | |||
546 | class SpectraProc(ProcessingUnit): |
|
546 | class SpectraProc(ProcessingUnit): | |
547 |
|
547 | |||
548 | def __init__(self): |
|
548 | def __init__(self): | |
549 |
|
549 | |||
550 | self.objectDict = {} |
|
550 | self.objectDict = {} | |
551 | self.buffer = None |
|
551 | self.buffer = None | |
552 | self.firstdatatime = None |
|
552 | self.firstdatatime = None | |
553 | self.profIndex = 0 |
|
553 | self.profIndex = 0 | |
554 | self.dataOut = Spectra() |
|
554 | self.dataOut = Spectra() | |
555 |
|
555 | |||
556 | def __updateObjFromInput(self): |
|
556 | def __updateObjFromInput(self): | |
557 |
|
557 | |||
558 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
558 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
559 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
559 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
560 | self.dataOut.channelList = self.dataIn.channelList |
|
560 | self.dataOut.channelList = self.dataIn.channelList | |
561 | self.dataOut.heightList = self.dataIn.heightList |
|
561 | self.dataOut.heightList = self.dataIn.heightList | |
562 | self.dataOut.dtype = self.dataIn.dtype |
|
562 | self.dataOut.dtype = self.dataIn.dtype | |
563 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
563 | # self.dataOut.nHeights = self.dataIn.nHeights | |
564 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
564 | # self.dataOut.nChannels = self.dataIn.nChannels | |
565 | self.dataOut.nBaud = self.dataIn.nBaud |
|
565 | self.dataOut.nBaud = self.dataIn.nBaud | |
566 | self.dataOut.nCode = self.dataIn.nCode |
|
566 | self.dataOut.nCode = self.dataIn.nCode | |
567 | self.dataOut.code = self.dataIn.code |
|
567 | self.dataOut.code = self.dataIn.code | |
568 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
568 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
569 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
569 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
570 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
570 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
571 | self.dataOut.utctime = self.firstdatatime |
|
571 | self.dataOut.utctime = self.firstdatatime | |
572 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
572 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
573 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
573 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
574 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
574 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
575 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
575 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
576 | self.dataOut.nIncohInt = 1 |
|
576 | self.dataOut.nIncohInt = 1 | |
577 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
577 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
578 |
|
578 | |||
579 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
579 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
580 |
|
580 | |||
581 | def __getFft(self): |
|
581 | def __getFft(self): | |
582 | """ |
|
582 | """ | |
583 | Convierte valores de Voltaje a Spectra |
|
583 | Convierte valores de Voltaje a Spectra | |
584 |
|
584 | |||
585 | Affected: |
|
585 | Affected: | |
586 | self.dataOut.data_spc |
|
586 | self.dataOut.data_spc | |
587 | self.dataOut.data_cspc |
|
587 | self.dataOut.data_cspc | |
588 | self.dataOut.data_dc |
|
588 | self.dataOut.data_dc | |
589 | self.dataOut.heightList |
|
589 | self.dataOut.heightList | |
590 | self.profIndex |
|
590 | self.profIndex | |
591 | self.buffer |
|
591 | self.buffer | |
592 | self.dataOut.flagNoData |
|
592 | self.dataOut.flagNoData | |
593 | """ |
|
593 | """ | |
594 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
594 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
595 | dc = fft_volt[:,0,:] |
|
595 | dc = fft_volt[:,0,:] | |
596 |
|
596 | |||
597 | #calculo de self-spectra |
|
597 | #calculo de self-spectra | |
598 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
598 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
599 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
599 | spc = fft_volt * numpy.conjugate(fft_volt) | |
600 | spc = spc.real |
|
600 | spc = spc.real | |
601 |
|
601 | |||
602 | blocksize = 0 |
|
602 | blocksize = 0 | |
603 | blocksize += dc.size |
|
603 | blocksize += dc.size | |
604 | blocksize += spc.size |
|
604 | blocksize += spc.size | |
605 |
|
605 | |||
606 | cspc = None |
|
606 | cspc = None | |
607 | pairIndex = 0 |
|
607 | pairIndex = 0 | |
608 | if self.dataOut.pairsList != None: |
|
608 | if self.dataOut.pairsList != None: | |
609 | #calculo de cross-spectra |
|
609 | #calculo de cross-spectra | |
610 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
610 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
611 | for pair in self.dataOut.pairsList: |
|
611 | for pair in self.dataOut.pairsList: | |
612 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
612 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
613 | pairIndex += 1 |
|
613 | pairIndex += 1 | |
614 | blocksize += cspc.size |
|
614 | blocksize += cspc.size | |
615 |
|
615 | |||
616 | self.dataOut.data_spc = spc |
|
616 | self.dataOut.data_spc = spc | |
617 | self.dataOut.data_cspc = cspc |
|
617 | self.dataOut.data_cspc = cspc | |
618 | self.dataOut.data_dc = dc |
|
618 | self.dataOut.data_dc = dc | |
619 | self.dataOut.blockSize = blocksize |
|
619 | self.dataOut.blockSize = blocksize | |
620 |
|
620 | |||
621 | def init(self, nFFTPoints=None, pairsList=None): |
|
621 | def init(self, nFFTPoints=None, pairsList=None): | |
622 |
|
622 | |||
623 | if self.dataIn.type == "Spectra": |
|
623 | if self.dataIn.type == "Spectra": | |
624 | self.dataOut.copy(self.dataIn) |
|
624 | self.dataOut.copy(self.dataIn) | |
625 | return |
|
625 | return | |
626 |
|
626 | |||
627 | if self.dataIn.type == "Voltage": |
|
627 | if self.dataIn.type == "Voltage": | |
628 |
|
628 | |||
629 | if nFFTPoints == None: |
|
629 | if nFFTPoints == None: | |
630 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
630 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" | |
631 |
|
631 | |||
632 | if pairsList == None: |
|
632 | if pairsList == None: | |
633 | nPairs = 0 |
|
633 | nPairs = 0 | |
634 | else: |
|
634 | else: | |
635 | nPairs = len(pairsList) |
|
635 | nPairs = len(pairsList) | |
636 |
|
636 | |||
637 | self.dataOut.nFFTPoints = nFFTPoints |
|
637 | self.dataOut.nFFTPoints = nFFTPoints | |
638 | self.dataOut.pairsList = pairsList |
|
638 | self.dataOut.pairsList = pairsList | |
639 | self.dataOut.nPairs = nPairs |
|
639 | self.dataOut.nPairs = nPairs | |
640 |
|
640 | |||
641 | if self.buffer == None: |
|
641 | if self.buffer == None: | |
642 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
642 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
643 | self.dataOut.nFFTPoints, |
|
643 | self.dataOut.nFFTPoints, | |
644 | self.dataIn.nHeights), |
|
644 | self.dataIn.nHeights), | |
645 | dtype='complex') |
|
645 | dtype='complex') | |
646 |
|
646 | |||
647 |
|
647 | |||
648 | self.buffer[:,self.profIndex,:] = self.dataIn.data |
|
648 | self.buffer[:,self.profIndex,:] = self.dataIn.data | |
649 | self.profIndex += 1 |
|
649 | self.profIndex += 1 | |
650 |
|
650 | |||
651 | if self.firstdatatime == None: |
|
651 | if self.firstdatatime == None: | |
652 | self.firstdatatime = self.dataIn.utctime |
|
652 | self.firstdatatime = self.dataIn.utctime | |
653 |
|
653 | |||
654 | if self.profIndex == self.dataOut.nFFTPoints: |
|
654 | if self.profIndex == self.dataOut.nFFTPoints: | |
655 | self.__updateObjFromInput() |
|
655 | self.__updateObjFromInput() | |
656 | self.__getFft() |
|
656 | self.__getFft() | |
657 |
|
657 | |||
658 | self.dataOut.flagNoData = False |
|
658 | self.dataOut.flagNoData = False | |
659 |
|
659 | |||
660 | self.buffer = None |
|
660 | self.buffer = None | |
661 | self.firstdatatime = None |
|
661 | self.firstdatatime = None | |
662 | self.profIndex = 0 |
|
662 | self.profIndex = 0 | |
663 |
|
663 | |||
664 | return |
|
664 | return | |
665 |
|
665 | |||
666 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
666 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) | |
667 |
|
667 | |||
668 | def selectChannels(self, channelList): |
|
668 | def selectChannels(self, channelList): | |
669 |
|
669 | |||
670 | channelIndexList = [] |
|
670 | channelIndexList = [] | |
671 |
|
671 | |||
672 | for channel in channelList: |
|
672 | for channel in channelList: | |
673 | index = self.dataOut.channelList.index(channel) |
|
673 | index = self.dataOut.channelList.index(channel) | |
674 | channelIndexList.append(index) |
|
674 | channelIndexList.append(index) | |
675 |
|
675 | |||
676 | self.selectChannelsByIndex(channelIndexList) |
|
676 | self.selectChannelsByIndex(channelIndexList) | |
677 |
|
677 | |||
678 | def selectChannelsByIndex(self, channelIndexList): |
|
678 | def selectChannelsByIndex(self, channelIndexList): | |
679 | """ |
|
679 | """ | |
680 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
680 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
681 |
|
681 | |||
682 | Input: |
|
682 | Input: | |
683 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
683 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
684 |
|
684 | |||
685 | Affected: |
|
685 | Affected: | |
686 | self.dataOut.data_spc |
|
686 | self.dataOut.data_spc | |
687 | self.dataOut.channelIndexList |
|
687 | self.dataOut.channelIndexList | |
688 | self.dataOut.nChannels |
|
688 | self.dataOut.nChannels | |
689 |
|
689 | |||
690 | Return: |
|
690 | Return: | |
691 | None |
|
691 | None | |
692 | """ |
|
692 | """ | |
693 |
|
693 | |||
694 | for channelIndex in channelIndexList: |
|
694 | for channelIndex in channelIndexList: | |
695 | if channelIndex not in self.dataOut.channelIndexList: |
|
695 | if channelIndex not in self.dataOut.channelIndexList: | |
696 | print channelIndexList |
|
696 | print channelIndexList | |
697 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
697 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
698 |
|
698 | |||
699 | nChannels = len(channelIndexList) |
|
699 | nChannels = len(channelIndexList) | |
700 |
|
700 | |||
701 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
701 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
702 |
|
702 | |||
703 | self.dataOut.data_spc = data_spc |
|
703 | self.dataOut.data_spc = data_spc | |
704 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
704 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
705 | # self.dataOut.nChannels = nChannels |
|
705 | # self.dataOut.nChannels = nChannels | |
706 |
|
706 | |||
707 | return 1 |
|
707 | return 1 | |
708 |
|
708 | |||
709 |
|
709 | |||
710 | class IncohInt(Operation): |
|
710 | class IncohInt(Operation): | |
711 |
|
711 | |||
712 |
|
712 | |||
713 | __profIndex = 0 |
|
713 | __profIndex = 0 | |
714 | __withOverapping = False |
|
714 | __withOverapping = False | |
715 |
|
715 | |||
716 | __byTime = False |
|
716 | __byTime = False | |
717 | __initime = None |
|
717 | __initime = None | |
718 | __lastdatatime = None |
|
718 | __lastdatatime = None | |
719 | __integrationtime = None |
|
719 | __integrationtime = None | |
720 |
|
720 | |||
721 | __buffer_spc = None |
|
721 | __buffer_spc = None | |
722 | __buffer_cspc = None |
|
722 | __buffer_cspc = None | |
723 | __buffer_dc = None |
|
723 | __buffer_dc = None | |
724 |
|
724 | |||
725 | __dataReady = False |
|
725 | __dataReady = False | |
726 |
|
726 | |||
727 | n = None |
|
727 | n = None | |
728 |
|
728 | |||
729 |
|
729 | |||
730 | def __init__(self): |
|
730 | def __init__(self): | |
731 |
|
731 | |||
732 | self.__isConfig = False |
|
732 | self.__isConfig = False | |
733 |
|
733 | |||
734 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
734 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
735 | """ |
|
735 | """ | |
736 | Set the parameters of the integration class. |
|
736 | Set the parameters of the integration class. | |
737 |
|
737 | |||
738 | Inputs: |
|
738 | Inputs: | |
739 |
|
739 | |||
740 | n : Number of coherent integrations |
|
740 | n : Number of coherent integrations | |
741 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
741 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
742 | overlapping : |
|
742 | overlapping : | |
743 |
|
743 | |||
744 | """ |
|
744 | """ | |
745 |
|
745 | |||
746 | self.__initime = None |
|
746 | self.__initime = None | |
747 | self.__lastdatatime = 0 |
|
747 | self.__lastdatatime = 0 | |
748 | self.__buffer_spc = None |
|
748 | self.__buffer_spc = None | |
749 | self.__buffer_cspc = None |
|
749 | self.__buffer_cspc = None | |
750 | self.__buffer_dc = None |
|
750 | self.__buffer_dc = None | |
751 | self.__dataReady = False |
|
751 | self.__dataReady = False | |
752 |
|
752 | |||
753 |
|
753 | |||
754 | if n == None and timeInterval == None: |
|
754 | if n == None and timeInterval == None: | |
755 | raise ValueError, "n or timeInterval should be specified ..." |
|
755 | raise ValueError, "n or timeInterval should be specified ..." | |
756 |
|
756 | |||
757 | if n != None: |
|
757 | if n != None: | |
758 | self.n = n |
|
758 | self.n = n | |
759 | self.__byTime = False |
|
759 | self.__byTime = False | |
760 | else: |
|
760 | else: | |
761 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
761 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
762 | self.n = 9999 |
|
762 | self.n = 9999 | |
763 | self.__byTime = True |
|
763 | self.__byTime = True | |
764 |
|
764 | |||
765 | if overlapping: |
|
765 | if overlapping: | |
766 | self.__withOverapping = True |
|
766 | self.__withOverapping = True | |
767 | else: |
|
767 | else: | |
768 | self.__withOverapping = False |
|
768 | self.__withOverapping = False | |
769 | self.__buffer_spc = 0 |
|
769 | self.__buffer_spc = 0 | |
770 | self.__buffer_cspc = 0 |
|
770 | self.__buffer_cspc = 0 | |
771 | self.__buffer_dc = 0 |
|
771 | self.__buffer_dc = 0 | |
772 |
|
772 | |||
773 | self.__profIndex = 0 |
|
773 | self.__profIndex = 0 | |
774 |
|
774 | |||
775 | def putData(self, data_spc, data_cspc, data_dc): |
|
775 | def putData(self, data_spc, data_cspc, data_dc): | |
776 |
|
776 | |||
777 | """ |
|
777 | """ | |
778 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
778 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
779 |
|
779 | |||
780 | """ |
|
780 | """ | |
781 |
|
781 | |||
782 | if not self.__withOverapping: |
|
782 | if not self.__withOverapping: | |
783 | self.__buffer_spc += data_spc |
|
783 | self.__buffer_spc += data_spc | |
784 |
|
784 | |||
785 | if data_cspc == None: |
|
785 | if data_cspc == None: | |
786 | self.__buffer_cspc = None |
|
786 | self.__buffer_cspc = None | |
787 | else: |
|
787 | else: | |
788 | self.__buffer_cspc += data_cspc |
|
788 | self.__buffer_cspc += data_cspc | |
789 |
|
789 | |||
790 | if data_dc == None: |
|
790 | if data_dc == None: | |
791 | self.__buffer_dc = None |
|
791 | self.__buffer_dc = None | |
792 | else: |
|
792 | else: | |
793 | self.__buffer_dc += data_dc |
|
793 | self.__buffer_dc += data_dc | |
794 |
|
794 | |||
795 | self.__profIndex += 1 |
|
795 | self.__profIndex += 1 | |
796 | return |
|
796 | return | |
797 |
|
797 | |||
798 | #Overlapping data |
|
798 | #Overlapping data | |
799 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
799 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
800 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
800 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
|
801 | if data_cspc != None: | |||
801 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
802 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
|
803 | if data_dc != None: | |||
802 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
804 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
803 |
|
805 | |||
804 | #If the buffer is empty then it takes the data value |
|
806 | #If the buffer is empty then it takes the data value | |
805 | if self.__buffer_spc == None: |
|
807 | if self.__buffer_spc == None: | |
806 |
self.__buffer_spc = data_spc |
|
808 | self.__buffer_spc = data_spc | |
807 |
|
809 | |||
808 | if data_cspc == None: |
|
810 | if data_cspc == None: | |
809 | self.__buffer_cspc = None |
|
811 | self.__buffer_cspc = None | |
810 | else: |
|
812 | else: | |
811 |
self.__buffer_cspc += data_cspc |
|
813 | self.__buffer_cspc += data_cspc | |
812 |
|
814 | |||
813 | if data_dc == None: |
|
815 | if data_dc == None: | |
814 | self.__buffer_dc = None |
|
816 | self.__buffer_dc = None | |
815 | else: |
|
817 | else: | |
816 |
self.__buffer_dc += data_dc |
|
818 | self.__buffer_dc += data_dc | |
817 |
|
819 | |||
818 | self.__profIndex += 1 |
|
820 | self.__profIndex += 1 | |
819 | return |
|
821 | return | |
820 |
|
822 | |||
821 | #If the buffer length is lower than n then stakcing the data value |
|
823 | #If the buffer length is lower than n then stakcing the data value | |
822 | if self.__profIndex < self.n: |
|
824 | if self.__profIndex < self.n: | |
823 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
825 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
824 |
|
826 | |||
825 |
if |
|
827 | if data_cspc != None: | |
826 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
828 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
827 |
|
829 | |||
828 |
if |
|
830 | if data_dc != None: | |
829 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
831 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
830 |
|
832 | |||
831 | self.__profIndex += 1 |
|
833 | self.__profIndex += 1 | |
832 | return |
|
834 | return | |
833 |
|
835 | |||
834 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
836 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
835 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
837 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
836 | self.__buffer_spc[self.n-1] = data_spc |
|
838 | self.__buffer_spc[self.n-1] = data_spc | |
837 |
|
839 | |||
|
840 | if data_cspc != None: | |||
838 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
841 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
839 | self.__buffer_cspc[self.n-1] = data_cspc |
|
842 | self.__buffer_cspc[self.n-1] = data_cspc | |
840 |
|
843 | |||
|
844 | if data_dc != None: | |||
841 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
845 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
842 | self.__buffer_dc[self.n-1] = data_dc |
|
846 | self.__buffer_dc[self.n-1] = data_dc | |
843 |
|
847 | |||
844 | self.__profIndex = self.n |
|
848 | self.__profIndex = self.n | |
845 | return |
|
849 | return | |
846 |
|
850 | |||
847 |
|
851 | |||
848 | def pushData(self): |
|
852 | def pushData(self): | |
849 | """ |
|
853 | """ | |
850 | Return the sum of the last profiles and the profiles used in the sum. |
|
854 | Return the sum of the last profiles and the profiles used in the sum. | |
851 |
|
855 | |||
852 | Affected: |
|
856 | Affected: | |
853 |
|
857 | |||
854 | self.__profileIndex |
|
858 | self.__profileIndex | |
855 |
|
859 | |||
856 | """ |
|
860 | """ | |
857 | data_spc = None |
|
861 | data_spc = None | |
858 | data_cspc = None |
|
862 | data_cspc = None | |
859 | data_dc = None |
|
863 | data_dc = None | |
860 |
|
864 | |||
861 | if not self.__withOverapping: |
|
865 | if not self.__withOverapping: | |
862 | data_spc = self.__buffer_spc |
|
866 | data_spc = self.__buffer_spc | |
863 | data_cspc = self.__buffer_cspc |
|
867 | data_cspc = self.__buffer_cspc | |
864 | data_dc = self.__buffer_dc |
|
868 | data_dc = self.__buffer_dc | |
865 |
|
869 | |||
866 | n = self.__profIndex |
|
870 | n = self.__profIndex | |
867 |
|
871 | |||
868 | self.__buffer_spc = 0 |
|
872 | self.__buffer_spc = 0 | |
869 | self.__buffer_cspc = 0 |
|
873 | self.__buffer_cspc = 0 | |
870 | self.__buffer_dc = 0 |
|
874 | self.__buffer_dc = 0 | |
871 | self.__profIndex = 0 |
|
875 | self.__profIndex = 0 | |
872 |
|
876 | |||
873 | return data_spc, data_cspc, data_dc, n |
|
877 | return data_spc, data_cspc, data_dc, n | |
874 |
|
878 | |||
875 | #Integration with Overlapping |
|
879 | #Integration with Overlapping | |
876 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
880 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
877 |
|
881 | |||
878 | if self.__buffer_cspc != None: |
|
882 | if self.__buffer_cspc != None: | |
879 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
883 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
880 |
|
884 | |||
881 | if self.__buffer_dc != None: |
|
885 | if self.__buffer_dc != None: | |
882 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
886 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
883 |
|
887 | |||
884 | n = self.__profIndex |
|
888 | n = self.__profIndex | |
885 |
|
889 | |||
886 | return data_spc, data_cspc, data_dc, n |
|
890 | return data_spc, data_cspc, data_dc, n | |
887 |
|
891 | |||
888 | def byProfiles(self, *args): |
|
892 | def byProfiles(self, *args): | |
889 |
|
893 | |||
890 | self.__dataReady = False |
|
894 | self.__dataReady = False | |
891 | avgdata_spc = None |
|
895 | avgdata_spc = None | |
892 | avgdata_cspc = None |
|
896 | avgdata_cspc = None | |
893 | avgdata_dc = None |
|
897 | avgdata_dc = None | |
894 | n = None |
|
898 | n = None | |
895 |
|
899 | |||
896 | self.putData(*args) |
|
900 | self.putData(*args) | |
897 |
|
901 | |||
898 | if self.__profIndex == self.n: |
|
902 | if self.__profIndex == self.n: | |
899 |
|
903 | |||
900 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
904 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
901 | self.__dataReady = True |
|
905 | self.__dataReady = True | |
902 |
|
906 | |||
903 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
907 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
904 |
|
908 | |||
905 | def byTime(self, datatime, *args): |
|
909 | def byTime(self, datatime, *args): | |
906 |
|
910 | |||
907 | self.__dataReady = False |
|
911 | self.__dataReady = False | |
908 | avgdata_spc = None |
|
912 | avgdata_spc = None | |
909 | avgdata_cspc = None |
|
913 | avgdata_cspc = None | |
910 | avgdata_dc = None |
|
914 | avgdata_dc = None | |
911 | n = None |
|
915 | n = None | |
912 |
|
916 | |||
913 | self.putData(*args) |
|
917 | self.putData(*args) | |
914 |
|
918 | |||
915 | if (datatime - self.__initime) >= self.__integrationtime: |
|
919 | if (datatime - self.__initime) >= self.__integrationtime: | |
916 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
920 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
917 | self.n = n |
|
921 | self.n = n | |
918 | self.__dataReady = True |
|
922 | self.__dataReady = True | |
919 |
|
923 | |||
920 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
924 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
921 |
|
925 | |||
922 | def integrate(self, datatime, *args): |
|
926 | def integrate(self, datatime, *args): | |
923 |
|
927 | |||
924 | if self.__initime == None: |
|
928 | if self.__initime == None: | |
925 | self.__initime = datatime |
|
929 | self.__initime = datatime | |
926 |
|
930 | |||
927 | if self.__byTime: |
|
931 | if self.__byTime: | |
928 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
932 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
929 | else: |
|
933 | else: | |
930 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
934 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
931 |
|
935 | |||
932 | self.__lastdatatime = datatime |
|
936 | self.__lastdatatime = datatime | |
933 |
|
937 | |||
934 | if avgdata_spc == None: |
|
938 | if avgdata_spc == None: | |
935 | return None, None, None, None |
|
939 | return None, None, None, None | |
936 |
|
940 | |||
937 | avgdatatime = self.__initime |
|
941 | avgdatatime = self.__initime | |
938 |
|
942 | |||
939 | deltatime = datatime -self.__lastdatatime |
|
943 | deltatime = datatime -self.__lastdatatime | |
940 |
|
944 | |||
941 | if not self.__withOverapping: |
|
945 | if not self.__withOverapping: | |
942 | self.__initime = datatime |
|
946 | self.__initime = datatime | |
943 | else: |
|
947 | else: | |
944 | self.__initime += deltatime |
|
948 | self.__initime += deltatime | |
945 |
|
949 | |||
946 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
950 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
947 |
|
951 | |||
948 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
952 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
949 |
|
953 | |||
950 | if not self.__isConfig: |
|
954 | if not self.__isConfig: | |
951 | self.setup(n, timeInterval, overlapping) |
|
955 | self.setup(n, timeInterval, overlapping) | |
952 | self.__isConfig = True |
|
956 | self.__isConfig = True | |
953 |
|
957 | |||
954 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
958 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
955 | dataOut.data_spc, |
|
959 | dataOut.data_spc, | |
956 | dataOut.data_cspc, |
|
960 | dataOut.data_cspc, | |
957 | dataOut.data_dc) |
|
961 | dataOut.data_dc) | |
958 |
|
962 | |||
959 | # dataOut.timeInterval *= n |
|
963 | # dataOut.timeInterval *= n | |
960 | dataOut.flagNoData = True |
|
964 | dataOut.flagNoData = True | |
961 |
|
965 | |||
962 | if self.__dataReady: |
|
966 | if self.__dataReady: | |
963 | dataOut.data_spc = avgdata_spc |
|
967 | dataOut.data_spc = avgdata_spc | |
964 | dataOut.data_cspc = avgdata_cspc |
|
968 | dataOut.data_cspc = avgdata_cspc | |
965 | dataOut.data_dc = avgdata_dc |
|
969 | dataOut.data_dc = avgdata_dc | |
966 |
|
970 | |||
967 | dataOut.nIncohInt *= self.n |
|
971 | dataOut.nIncohInt *= self.n | |
968 | dataOut.utctime = avgdatatime |
|
972 | dataOut.utctime = avgdatatime | |
969 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
973 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
970 | dataOut.flagNoData = False |
|
974 | dataOut.flagNoData = False | |
971 | No newline at end of file |
|
975 |
General Comments 0
You need to be logged in to leave comments.
Login now