##// END OF EJS Templates
-Estandarizacion de los nombres de paquetes y modulos escritos en minusculas...
Miguel Valdez -
r175:d5210476252d
parent child
Show More
@@ -1,370 +1,384
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 element import prettify
7 from xml.etree import ElementTree as ET
6 from xml.etree import ElementTree as ET
7 from xml.dom import minidom
8
8 import sys
9 import sys
9
10
11 def prettify(elem):
12 """Return a pretty-printed XML string for the Element.
13 """
14 rough_string = ET.tostring(elem, 'utf-8')
15 reparsed = minidom.parseString(rough_string)
16 return reparsed.toprettyxml(indent=" ")
10
17
11 #def save(a, b):
18 #def save(a, b):
12 #
19 #
13 # nameP = "Alexnder"
20 # nameP = "Alexnder"
14 # descripcion = self.projectWindow.Text()
21 # descripcion = self.projectWindow.Text()
15 # id = 1
22 # id = 1
16 # x = self.data.projectWindow.cmbbox.value()
23 # x = self.data.projectWindow.cmbbox.value()
17 #
24 #
18 # projectObj = Project(id, name, description)
25 # projectObj = Project(id, name, description)
19 #
26 #
20 # projectObj.setup(id, name, description)
27 # projectObj.setup(id, name, description)
21
28
22 class Project():
29 class Project():
23
30
24 id = None
31 id = None
25 name = None
32 name = None
26 description = None
33 description = None
27 readBranchObjList = None
34 readBranchObjList = None
28 procBranchObjList = None
35 procBranchObjList = None
29
36
30 def __init__(self):
37 def __init__(self):
31
38
32 # self.id = id
39 # self.id = id
33 # self.name = name
40 # self.name = name
34 # self.description = description
41 # self.description = description
35
42
36 self.readBranchObjList = []
43 self.readBranchObjList = []
37 self.procBranchObjList = []
44 self.procBranchObjList = []
38
45
39 def setParms(self, id, name, description):
46 def setParms(self, id, name, description):
40
47
41 self.id = id
48 self.id = id
42 self.name = name
49 self.name = name
43 self.description = description
50 self.description = description
44
51
45 def addReadBranch(self, dpath, dataformat, readMode, startDate='', endDate='', startTime='', endTime=''):
52 def addReadBranch(self, dpath, dataformat, readMode, startDate='', endDate='', startTime='', endTime=''):
46
53
47 id = len(self.readBranchObjList) + 1
54 id = len(self.readBranchObjList) + 1
48
55
49 readBranchObj = ReadBranch(id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime)
56 readBranchObj = ReadBranch(id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime)
50
57
51 self.readBranchObjList.append(readBranchObj)
58 self.readBranchObjList.append(readBranchObj)
52
59
53 return readBranchObj
60 return readBranchObj
54
61
55 def addProcBranch(self, name):
62 def addProcBranch(self, name):
56
63
57 id = len(self.procBranchObjList) + 1
64 id = len(self.procBranchObjList) + 1
58
65
59 procBranchObj = ProcBranch(id, name)
66 procBranchObj = ProcBranch(id, name)
60
67
61 self.procBranchObjList.append(procBranchObj)
68 self.procBranchObjList.append(procBranchObj)
62
69
63 return procBranchObj
70 return procBranchObj
64
71
65 def makeXml(self):
72 def makeXml(self):
66
73
67 projectElement = Element('Project')
74 projectElement = Element('Project')
68 projectElement.set('id', str(self.id))
75 projectElement.set('id', str(self.id))
69 projectElement.set('name', self.name)
76 projectElement.set('name', self.name)
70 #projectElement.set('description', self.description)
77 #projectElement.set('description', self.description)
71
78
72 se = SubElement(projectElement, 'description',description=self.description)#ESTO ES LO ULTIMO QUE SE TRABAJO
79 se = SubElement(projectElement, 'description',description=self.description)#ESTO ES LO ULTIMO QUE SE TRABAJO
73 #se.text = self.description #ULTIMA MODIFICACION PARA SACAR UN SUB ELEMENT
80 #se.text = self.description #ULTIMA MODIFICACION PARA SACAR UN SUB ELEMENT
74
81
75 for readBranchObj in self.readBranchObjList:
82 for readBranchObj in self.readBranchObjList:
76 readBranchObj.makeXml(projectElement)
83 readBranchObj.makeXml(projectElement)
77
84
78 for procBranchObj in self.procBranchObjList:
85 for procBranchObj in self.procBranchObjList:
79 procBranchObj.makeXml(projectElement)
86 procBranchObj.makeXml(projectElement)
80
87
81 self.projectElement = projectElement
88 self.projectElement = projectElement
82
89
83 def writeXml(self, filename):
90 def writeXml(self, filename):
84
91
85 self.makeXml()
92 self.makeXml()
86 ElementTree(self.projectElement).write(filename, method='xml')
93 ElementTree(self.projectElement).write(filename, method='xml')
87 print prettify(self.projectElement)
94 print prettify(self.projectElement)
88
95
89 def readXml(self,workspace):
96 def readXml(self, filename):
90 print "Aqui estoy leyendo"
97
91 tree=ET.parse(workspace)
98 #tree = ET.parse(filename)
92 root=tree.getroot()
99 self.projectElement = None
93 self.project=root.tag
100 tree = ElementTree(self.projectElement).parse(filename)
94 self.idProyect= root.attrib.get('id')
101
95 self.nameProyect= root.attrib.get('name')
102 self.project = self.projectElement.tag
103
104 self.id = self.projectElement.get('id')
105 self.name = self.projectElement.get('name')
106
107 readElement = self.projectElement.getiterator('readBranch')
108
109 root = tree.getroot()
110 self.project = root.tag
111 self.id = root.attrib.get('id')
112 self.name = root.attrib.get('name')
113
96 for description in root.findall('description'):
114 for description in root.findall('description'):
97 description = description.get('description')
115 description = description.get('description')
98
116
99 self.description= description
117 self.description= description
100
118
101 for readBranch in root.findall('readBranch'):
119 for readBranch in root.findall('readBranch'):
102 id = readBranch.get('id')
120 id = readBranch.get('id')
103 self.idrb=id
121 self.idrb=id
104
122
105 for procBranch in root.findall('procBranch'):
123 for procBranch in root.findall('procBranch'):
106 id = readBranch.get('id')
124 id = readBranch.get('id')
107 name = readBranch.get('name')
125 name = readBranch.get('name')
108 self.idpb=id
126 self.idpb=id
109 self.nameBranch=name
127 self.nameBranch=name
110 #
128 #
111 #
112 print self.project
113 print self.idProyect
114 print self.nameProyect
115 print self.description
116 print self.idrb
117 print self.idpb
118 print self.nameBranch
119 #
120 ####ESTO DEL MEDIO ESTABA COMENTADO
129 ####ESTO DEL MEDIO ESTABA COMENTADO
121 # print root.tag , root.attrib
130 # print root.tag , root.attrib
122 #
131 #
123 # print root.attrib.get('id')
132 # print root.attrib.get('id')
124 # print root.attrib.get('name')
133 # print root.attrib.get('name')
125
134
126
135
127 # for description in root.findall('description'):
136 # for description in root.findall('description'):
128 # description = root.find('description').text
137 # description = root.find('description').text
129 # name = root.get('name')
138 # name = root.get('name')
130 # print name, description
139 # print name, description
131
140
132 # description=root.find('description').text
141 # description=root.find('description').text
133 # print description
142 # print description
134 # ESTO FUNCIONABA HACIA ABAJO
143 # ESTO FUNCIONABA HACIA ABAJO
135 print "Otra forma "
144
136 root=tree.getroot()
145 root=tree.getroot()
137 print root.tag , root.attrib
146 print root.tag , root.attrib
138 for child in root:
147 for child in root:
139 print child.tag ,child.attrib
148 print child.tag ,child.attrib
140 for child in child:
149 for child in child:
141 print child.tag ,child.attrib
150 print child.tag ,child.attrib
142 for child in child:
151 for child in child:
143 print child.tag ,child.attrib
152 print child.tag ,child.attrib
144 for child in child:
153 for child in child:
145 print child.tag ,child.attrib
154 print child.tag ,child.attrib
146 #
155 #
147 class ReadBranch():
156 class ReadBranch():
148
157
149 id = None
158 id = None
150 dpath = None
159 dpath = None
151 dataformat = None
160 dataformat = None
152 readMode = None
161 readMode = None
153 startDate = None
162 startDate = None
154 endDate = None
163 endDate = None
155 startTime = None
164 startTime = None
156 endTime = None
165 endTime = None
157
166
158 def __init__(self, id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime):
167 def __init__(self, id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime):
159
168
160 self.id = id
169 self.id = id
161 self.dpath = dpath
170 self.dpath = dpath
162 self.dataformat = dataformat
171 self.dataformat = dataformat
163 self.readMode = readMode
172 self.readMode = readMode
164 self.startDate = startDate
173 self.startDate = startDate
165 self.endDate = endDate
174 self.endDate = endDate
166 self.startTime = startTime
175 self.startTime = startTime
167 self.endTime = endTime
176 self.endTime = endTime
168
177
169 def makeXml(self, projectElement):
178 def makeXml(self, projectElement):
170
179
171 readBranchElement = SubElement(projectElement, 'readBranch')
180 readBranchElement = SubElement(projectElement, 'readBranch')
172 readBranchElement.set('id', str(self.id))
181 readBranchElement.set('id', str(self.id))
173
182
174 # readBranchElement.set('dpath', self.dpath)
183 # readBranchElement.set('dpath', self.dpath)
175 # readBranchElement.set('dataformat', self.dataformat)
184 # readBranchElement.set('dataformat', self.dataformat)
176 # readBranchElement.set('startDate', self.startDate)
185 # readBranchElement.set('startDate', self.startDate)
177 # readBranchElement.set('endDate', self.endDate)
186 # readBranchElement.set('endDate', self.endDate)
178 # readBranchElement.set('startTime', self.startTime)
187 # readBranchElement.set('startTime', self.startTime)
179 # readBranchElement.set('endTime', self.endTime)
188 # readBranchElement.set('endTime', self.endTime)
180 # readBranchElement.set('readMode', str(self.readMode))
189 # readBranchElement.set('readMode', str(self.readMode))
181
190
182 # se = SubElement(readBranchElement, 'dpath')#ESTO ES LO ULTIMO QUE SE TRABAJO
191 # se = SubElement(readBranchElement, 'dpath')#ESTO ES LO ULTIMO QUE SE TRABAJO
183 # se.text = self.dpath
192 # se.text = self.dpath
184 #
193 #
185 # se = SubElement(readBranchElement, 'dataformat')#ESTO ES LO ULTIMO QUE SE TRABAJO
194 # se = SubElement(readBranchElement, 'dataformat')#ESTO ES LO ULTIMO QUE SE TRABAJO
186 # se.text = self.dataformat
195 # se.text = self.dataformat
187 #
196 #
188 # se = SubElement(readBranchElement, 'startDate')#ESTO ES LO ULTIMO QUE SE TRABAJO
197 # se = SubElement(readBranchElement, 'startDate')#ESTO ES LO ULTIMO QUE SE TRABAJO
189 # se.text = self.startDate
198 # se.text = self.startDate
190 #
199 #
191 # se = SubElement(readBranchElement, 'endDate')#ESTO ES LO ULTIMO QUE SE TRABAJO
200 # se = SubElement(readBranchElement, 'endDate')#ESTO ES LO ULTIMO QUE SE TRABAJO
192 # se.text = self.endDate
201 # se.text = self.endDate
193 #
202 #
194 # se = SubElement(readBranchElement, 'startTime')#ESTO ES LO ULTIMO QUE SE TRABAJO
203 # se = SubElement(readBranchElement, 'startTime')#ESTO ES LO ULTIMO QUE SE TRABAJO
195 # se.text = self.startTime
204 # se.text = self.startTime
196 #
205 #
197 # se = SubElement(readBranchElement, 'endTime')#ESTO ES LO ULTIMO QUE SE TRABAJO
206 # se = SubElement(readBranchElement, 'endTime')#ESTO ES LO ULTIMO QUE SE TRABAJO
198 # se.text = self.endTime
207 # se.text = self.endTime
199 #
208 #
200 # se = SubElement(readBranchElement, 'readMode')#ESTO ES LO ULTIMO QUE SE TRABAJO
209 # se = SubElement(readBranchElement, 'readMode')#ESTO ES LO ULTIMO QUE SE TRABAJO
201 # se.text = str(self.readMode)
210 # se.text = str(self.readMode)
202
211
203 ##########################################################################
212 ##########################################################################
204 se = SubElement(readBranchElement, 'parameter', name='dpath' , value=self.dpath)
213 se = SubElement(readBranchElement, 'parameter', name='dpath' , value=self.dpath)
205 se = SubElement(readBranchElement, 'parameter', name='dataformat', value=self.dataformat)
214 se = SubElement(readBranchElement, 'parameter', name='dataformat', value=self.dataformat)
206 se = SubElement(readBranchElement, 'parameter', name='startDate' , value=self.startDate)
215 se = SubElement(readBranchElement, 'parameter', name='startDate' , value=self.startDate)
207 se = SubElement(readBranchElement, 'parameter', name='endDate' , value=self.endDate)
216 se = SubElement(readBranchElement, 'parameter', name='endDate' , value=self.endDate)
208 se = SubElement(readBranchElement, 'parameter', name='startTime' , value=self.startTime)
217 se = SubElement(readBranchElement, 'parameter', name='startTime' , value=self.startTime)
209 se = SubElement(readBranchElement, 'parameter', name='endTime' , value=self.endTime)
218 se = SubElement(readBranchElement, 'parameter', name='endTime' , value=self.endTime)
210 se = SubElement(readBranchElement, 'parameter', name='readMode' , value=str(self.readMode))
219 se = SubElement(readBranchElement, 'parameter', name='readMode' , value=str(self.readMode))
211
220
212
221
213 class ProcBranch():
222 class ProcBranch():
214
223
215 id = None
224 id = None
216 name = None
225 name = None
217
226
218 upObjList = None
227 upObjList = None
219
228
220 def __init__(self, id, name):
229 def __init__(self, id, name):
221
230
222 self.id = id
231 self.id = id
223 self.name = name
232 self.name = name
224
233
225 self.upObjList = []
234 self.upObjList = []
226
235
227 def addUP(self, name, type):
236 def addUP(self, name, type):
228
237
229 id = len(self.upObjList) + 1
238 id = len(self.upObjList) + 1
230
239
231 upObj = UP(id, name, type)
240 upObj = UP(id, name, type)
232
241
233 self.upObjList.append(upObj)
242 self.upObjList.append(upObj)
234
243
235 return upObj
244 return upObj
236
245
237 def makeXml(self, projectElement):
246 def makeXml(self, projectElement):
238
247
239 procBranchElement = SubElement(projectElement, 'procBranch')
248 procBranchElement = SubElement(projectElement, 'procBranch')
240 procBranchElement.set('id', str(self.id))
249 procBranchElement.set('id', str(self.id))
241 procBranchElement.set('name', self.name)
250 procBranchElement.set('name', self.name)
242
251
243 for upObj in self.upObjList:
252 for upObj in self.upObjList:
244 upObj.makeXml(procBranchElement)
253 upObj.makeXml(procBranchElement)
245
254
246 class UP():
255 class UP():
247
256
248 id = None
257 id = None
249 name = None
258 name = None
250 type = None
259 type = None
251
260
252 opObjList = []
261 opObjList = []
253
262
254 def __init__(self, id, name, type):
263 def __init__(self, id, name, type):
255
264
256 self.id = id
265 self.id = id
257 self.name = name
266 self.name = name
258 self.type = type
267 self.type = type
259
268
260 self.opObjList = []
269 self.opObjList = []
261
270
262 def addOperation(self, name, priority):
271 def addOperation(self, name, priority):
263
272
264 id = len(self.opObjList) + 1
273 id = len(self.opObjList) + 1
265
274
266 opObj = Operation(id, name, priority)
275 opObj = Operation(id, name, priority)
267
276
268 self.opObjList.append(opObj)
277 self.opObjList.append(opObj)
269
278
270 return opObj
279 return opObj
271
280
272 def makeXml(self, procBranchElement):
281 def makeXml(self, procBranchElement):
273
282
274 upElement = SubElement(procBranchElement, 'UP')
283 upElement = SubElement(procBranchElement, 'UP')
275 upElement.set('id', str(self.id))
284 upElement.set('id', str(self.id))
276 upElement.set('name', self.name)
285 upElement.set('name', self.name)
277 upElement.set('type', self.type)
286 upElement.set('type', self.type)
278
287
279 for opObj in self.opObjList:
288 for opObj in self.opObjList:
280 opObj.makeXml(upElement)
289 opObj.makeXml(upElement)
281
290
282 class Operation():
291 class Operation():
283
292
284 id = 0
293 id = 0
285 name = None
294 name = None
286 priority = None
295 priority = None
287 parmObjList = []
296 parmObjList = []
288
297
289 def __init__(self, id, name, priority):
298 def __init__(self, id, name, priority):
290
299
291 self.id = id
300 self.id = id
292 self.name = name
301 self.name = name
293 self.priority = priority
302 self.priority = priority
294
303
295 self.parmObjList = []
304 self.parmObjList = []
296
305
297 def addParameter(self, name, value):
306 def addParameter(self, name, value):
298
307
299 id = len(self.parmObjList) + 1
308 id = len(self.parmObjList) + 1
300
309
301 parmObj = Parameter(id, name, value)
310 parmObj = Parameter(id, name, value)
302
311
303 self.parmObjList.append(parmObj)
312 self.parmObjList.append(parmObj)
304
313
305 return parmObj
314 return parmObj
306
315
307 def makeXml(self, upElement):
316 def makeXml(self, upElement):
308
317
309 opElement = SubElement(upElement, 'Operation')
318 opElement = SubElement(upElement, 'Operation')
310 opElement.set('id', str(self.id))
319 opElement.set('id', str(self.id))
311 opElement.set('name', self.name)
320 opElement.set('name', self.name)
312 opElement.set('priority', str(self.priority))
321 opElement.set('priority', str(self.priority))
313
322
314 for parmObj in self.parmObjList:
323 for parmObj in self.parmObjList:
315 parmObj.makeXml(opElement)
324 parmObj.makeXml(opElement)
316
325
317 class Parameter():
326 class Parameter():
318
327
319 id = None
328 id = None
320 name = None
329 name = None
321 value = None
330 value = None
322
331
323 def __init__(self, id, name, value):
332 def __init__(self, id, name, value):
324
333
325 self.id = id
334 self.id = id
326 self.name = name
335 self.name = name
327 self.value = value
336 self.value = value
328
337
329 def makeXml(self, opElement):
338 def makeXml(self, opElement):
330
339
331 parmElement = SubElement(opElement, 'Parameter')
340 parmElement = SubElement(opElement, 'Parameter')
332 parmElement.set('name', self.name)
341 parmElement.set('name', self.name)
333 parmElement.set('value', self.value)
342 parmElement.set('value', self.value)
343
344 def readXml(self, opElement):
334
345
346
347 pass
335 # se = SubElement(parmElement, 'value')#ESTO ES LO ULTIMO QUE SE TRABAJO
348 # se = SubElement(parmElement, 'value')#ESTO ES LO ULTIMO QUE SE TRABAJO
336 # se.text = self.value
349 # se.text = self.value
337
350
338 if __name__ == '__main__':
351 if __name__ == '__main__':
339
352
340 desc = "Este es un test"
353 desc = "Este es un test"
341 filename = "test.xml"
354 filename = "test.xml"
342
355
343 workspace=str("C:\\Users\\alex\\workspace\\GUIV2.0\\test.xml")
344
345 projectObj = Project()
356 projectObj = Project()
346
357
347 projectObj.setParms(id = '11', name='test01', description=desc)
358 projectObj.setParms(id = '11', name='test01', description=desc)
348
359
349 readBranchObj = projectObj.addReadBranch(dpath='mydata', dataformat='rawdata', readMode=0, startDate='1', endDate='3', startTime='4', endTime='5')
360 readBranchObj = projectObj.addReadBranch(dpath='mydata', dataformat='rawdata', readMode=0, startDate='1', endDate='3', startTime='4', endTime='5')
350
361
351 procBranchObj = projectObj.addProcBranch(name='Branch1')
362 procBranchObj = projectObj.addProcBranch(name='Branch1')
352
363
353 procBranchObj1 = projectObj.addProcBranch(name='Branch2')
364 procBranchObj1 = projectObj.addProcBranch(name='Branch2')
354 upObj1 = procBranchObj.addUP(name='UP1', type='Voltage')
365 upObj1 = procBranchObj.addUP(name='UP1', type='Voltage')
355 upObj2 = procBranchObj.addUP(name='UP2', type='Voltage')
366 upObj2 = procBranchObj.addUP(name='UP2', type='Voltage')
356
367
357 opObj11 = upObj1.addOperation(name='removeDC', priority=1)
368 opObj11 = upObj1.addOperation(name='removeDC', priority=1)
358 opObj11.addParameter(name='type', value='1')
369 opObj11.addParameter(name='type', value='1')
359
370
360
371
361 opObj12 = upObj1.addOperation(name='decodification', priority=2)
372 opObj12 = upObj1.addOperation(name='decodification', priority=2)
362 opObj12.addParameter(name='ncode', value='2')
373 opObj12.addParameter(name='ncode', value='2')
363 opObj12.addParameter(name='nbauds', value='8')
374 opObj12.addParameter(name='nbauds', value='8')
364 opObj12.addParameter(name='code1', value='001110011')
375 opObj12.addParameter(name='code1', value='001110011')
365 opObj12.addParameter(name='code2', value='001110011')
376 opObj12.addParameter(name='code2', value='001110011')
366
377
378 print "Escribiendo el XML"
379
367 projectObj.writeXml(filename)
380 projectObj.writeXml(filename)
368
381
369 projectObj.readXml(workspace)
382 print "Leyendo el XML"
383 projectObj.readXml(filename)
370 No newline at end of file
384
1 NO CONTENT: file renamed from schainpy/Controller/controller1.py to schainpy/controller/controller1.py
NO CONTENT: file renamed from schainpy/Controller/controller1.py to schainpy/controller/controller1.py
1 NO CONTENT: file renamed from schainpy/Model/JROData.py to schainpy/model/jrodata.py
NO CONTENT: file renamed from schainpy/Model/JROData.py to schainpy/model/jrodata.py
1 NO CONTENT: file renamed from schainpy/Model/JRODataIO.py to schainpy/model/jrodataIO.py
NO CONTENT: file renamed from schainpy/Model/JRODataIO.py to schainpy/model/jrodataIO.py
1 NO CONTENT: file renamed from schainpy/Model/JROHeaderIO.py to schainpy/model/jroheaderIO.py
NO CONTENT: file renamed from schainpy/Model/JROHeaderIO.py to schainpy/model/jroheaderIO.py
1 NO CONTENT: file renamed from schainpy/Model/JROPlot.py to schainpy/model/jroplot.py
NO CONTENT: file renamed from schainpy/Model/JROPlot.py to schainpy/model/jroplot.py
@@ -1,423 +1,444
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 addOperation(self, object, objId):
39 def addOperation(self, object, objId):
40
40
41 """
41 """
42 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
42 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
43 identificador asociado a este objeto.
43 identificador asociado a este objeto.
44
44
45 Input:
45 Input:
46
46
47 object : objeto de la clase "Operation"
47 object : objeto de la clase "Operation"
48
48
49 Return:
49 Return:
50
50
51 objId : identificador del objeto, necesario para ejecutar la operacion
51 objId : identificador del objeto, necesario para ejecutar la operacion
52 """
52 """
53
53
54 self.object[objId] = object
54 self.object[objId] = object
55
55
56 return objId
56 return objId
57
57
58 def operation(self, **kwargs):
58 def operation(self, **kwargs):
59
59
60 """
60 """
61 Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los
61 Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los
62 atributos del objeto dataOut
62 atributos del objeto dataOut
63
63
64 Input:
64 Input:
65
65
66 **kwargs : Diccionario de argumentos de la funcion a ejecutar
66 **kwargs : Diccionario de argumentos de la funcion a ejecutar
67 """
67 """
68
68
69 if self.dataIn.isEmpty():
69 if self.dataIn.isEmpty():
70 return None
70 return None
71
71
72 raise ValueError, "ImplementedError"
72 raise ValueError, "ImplementedError"
73
73
74 def callMethod(self, name, **kwargs):
74 def callMethod(self, name, **kwargs):
75
75
76 """
76 """
77 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
77 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
78
78
79 Input:
79 Input:
80 name : nombre del metodo a ejecutar
80 name : nombre del metodo a ejecutar
81
81
82 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
82 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
83
83
84 """
84 """
85
85
86 if self.dataIn.isEmpty():
86 if self.dataIn.isEmpty():
87 return None
87 return None
88
88
89 methodToCall = getattr(self, name)
89 methodToCall = getattr(self, name)
90
90
91 methodToCall(**kwargs)
91 methodToCall(**kwargs)
92
92
93 def callObject(self, objId, **kwargs):
93 def callObject(self, objId, **kwargs):
94
94
95 """
95 """
96 Ejecuta la operacion asociada al identificador del objeto "objId"
96 Ejecuta la operacion asociada al identificador del objeto "objId"
97
97
98 Input:
98 Input:
99
99
100 objId : identificador del objeto a ejecutar
100 objId : identificador del objeto a ejecutar
101
101
102 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
102 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
103
103
104 Return:
104 Return:
105
105
106 None
106 None
107 """
107 """
108
108
109 if self.dataIn.isEmpty():
109 if self.dataIn.isEmpty():
110 return None
110 return None
111
111
112 object = self.objectList[objId]
112 object = self.objectList[objId]
113
113
114 object.run(self.dataOut, **kwargs)
114 object.run(self.dataOut, **kwargs)
115
115
116 def call(self, operation, **kwargs):
116 def call(self, operation, **kwargs):
117
117
118 """
118 """
119 Ejecuta la operacion "operation" con los argumentos "**kwargs". La operacion puede
119 Ejecuta la operacion "operation" con los argumentos "**kwargs". La operacion puede
120 ser de dos tipos:
120 ser de dos tipos:
121
121
122 1. Un metodo propio de esta clase:
122 1. Un metodo propio de esta clase:
123
123
124 operation.type = "self"
124 operation.type = "self"
125
125
126 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
126 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
127 operation.type = "other".
127 operation.type = "other".
128
128
129 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
129 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
130 "addOperation" e identificado con el operation.id
130 "addOperation" e identificado con el operation.id
131
131
132
132
133 con el id de la operacion.
133 con el id de la operacion.
134 """
134 """
135 if self.dataIn.isEmpty():
135 if self.dataIn.isEmpty():
136 return None
136 return None
137
137
138 if operation.type == 'self':
138 if operation.type == 'self':
139 self.callMethod(operation.name, **kwargs)
139 self.callMethod(operation.name, **kwargs)
140 return
140 return
141
141
142 if operation.type == 'other':
142 if operation.type == 'other':
143 self.callObject(operation.id, **kwargs)
143 self.callObject(operation.id, **kwargs)
144 return
144 return
145
145
146 class Operation():
146 class Operation():
147
147
148 """
148 """
149 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
149 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
150 y necesiten acumular informaciΓ³n previa de los datos a procesar. De preferencia usar un buffer de
150 y necesiten acumular informaciΓ³n previa de los datos a procesar. De preferencia usar un buffer de
151 acumulacion dentro de esta clase
151 acumulacion dentro de esta clase
152
152
153 Ejemplo: Integraciones coherentes, necesita la informaciΓ³n previa de los n perfiles anteriores (bufffer)
153 Ejemplo: Integraciones coherentes, necesita la informaciΓ³n previa de los n perfiles anteriores (bufffer)
154
154
155 """
155 """
156
156
157 __buffer = None
157 __buffer = None
158 __isConfig = False
158
159
159 def __init__(self):
160 def __init__(self):
160
161
161 pass
162 pass
162
163
163 def run(self, dataIn, **kwargs):
164 def run(self, dataIn, **kwargs):
164
165
165 """
166 """
166 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
167 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
167
168
168 Input:
169 Input:
169
170
170 dataIn : objeto del tipo JROData
171 dataIn : objeto del tipo JROData
171
172
172 Return:
173 Return:
173
174
174 None
175 None
175
176
176 Affected:
177 Affected:
177 __buffer : buffer de recepcion de datos.
178 __buffer : buffer de recepcion de datos.
178
179
179 """
180 """
180
181
181 raise ValueError, "ImplementedError"
182 raise ValueError, "ImplementedError"
182
183
183 class VoltageProc(ProcessingUnit):
184 class VoltageProc(ProcessingUnit):
184
185
185
186
186 def __init__(self):
187 def __init__(self):
187
188
188 pass
189 pass
189
190
190 def setup(self, dataInObj=None, dataOutObj=None):
191 def setup(self, dataInObj=None, dataOutObj=None):
191
192
192 self.dataInObj = dataInObj
193 self.dataInObj = dataInObj
193
194
194 if self.dataOutObj == None:
195 if self.dataOutObj == None:
195 dataOutObj = Voltage()
196 dataOutObj = Voltage()
196
197
197 self.dataOutObj = dataOutObj
198 self.dataOutObj = dataOutObj
198
199
199 return self.dataOutObj
200 return self.dataOutObj
200
201
201 def init(self):
202 def init(self):
202
203
203 if self.dataInObj.isEmpty():
204 if self.dataInObj.isEmpty():
204 return 0
205 return 0
205
206
206 self.dataOutObj.copy(self.dataInObj)
207 self.dataOutObj.copy(self.dataInObj)
207 # No necesita copiar en cada init() los atributos de dataInObj
208 # No necesita copiar en cada init() los atributos de dataInObj
208 # la copia deberia hacerse por cada nuevo bloque de datos
209 # la copia deberia hacerse por cada nuevo bloque de datos
209
210
210 def selectChannels(self, channelList):
211 def selectChannels(self, channelList):
211
212
212 if self.dataInObj.isEmpty():
213 if self.dataInObj.isEmpty():
213 return 0
214 return 0
214
215
215 self.selectChannelsByIndex(channelList)
216 self.selectChannelsByIndex(channelList)
216
217
217 def selectChannelsByIndex(self, channelIndexList):
218 def selectChannelsByIndex(self, channelIndexList):
218 """
219 """
219 Selecciona un bloque de datos en base a canales segun el channelIndexList
220 Selecciona un bloque de datos en base a canales segun el channelIndexList
220
221
221 Input:
222 Input:
222 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
223 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
223
224
224 Affected:
225 Affected:
225 self.dataOutObj.data
226 self.dataOutObj.data
226 self.dataOutObj.channelIndexList
227 self.dataOutObj.channelIndexList
227 self.dataOutObj.nChannels
228 self.dataOutObj.nChannels
228 self.dataOutObj.m_ProcessingHeader.totalSpectra
229 self.dataOutObj.m_ProcessingHeader.totalSpectra
229 self.dataOutObj.systemHeaderObj.numChannels
230 self.dataOutObj.systemHeaderObj.numChannels
230 self.dataOutObj.m_ProcessingHeader.blockSize
231 self.dataOutObj.m_ProcessingHeader.blockSize
231
232
232 Return:
233 Return:
233 None
234 None
234 """
235 """
235
236
236 for channel in channelIndexList:
237 for channel in channelIndexList:
237 if channel not in self.dataOutObj.channelIndexList:
238 if channel not in self.dataOutObj.channelIndexList:
238 raise ValueError, "The value %d in channelIndexList is not valid" %channel
239 raise ValueError, "The value %d in channelIndexList is not valid" %channel
239
240
240 nChannels = len(channelIndexList)
241 nChannels = len(channelIndexList)
241
242
242 data = self.dataOutObj.data[channelIndexList,:]
243 data = self.dataOutObj.data[channelIndexList,:]
243
244
244 self.dataOutObj.data = data
245 self.dataOutObj.data = data
245 self.dataOutObj.channelIndexList = channelIndexList
246 self.dataOutObj.channelIndexList = channelIndexList
246 self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList]
247 self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList]
247 self.dataOutObj.nChannels = nChannels
248 self.dataOutObj.nChannels = nChannels
248
249
249 return 1
250 return 1
250
251
251 class CohInt(Operation):
252 class CohInt(Operation):
252
253
253 __profIndex = 0
254 __profIndex = 0
254 __withOverapping = False
255 __withOverapping = False
255
256
256 __byTime = False
257 __byTime = False
257 __initime = None
258 __initime = None
259 __lastdatatime = None
258 __integrationtime = None
260 __integrationtime = None
259
261
260 __buffer = None
262 __buffer = None
261
263
262 __dataReady = False
264 __dataReady = False
263
265
264 nCohInt = None
266 nCohInt = None
265
267
266
268
267 def __init__(self):
269 def __init__(self):
268
270
269 pass
271 self.__isConfig = False
270
272
271 def setup(self, nCohInt=None, timeInterval=None, overlapping=False):
273 def setup(self, nCohInt=None, timeInterval=None, overlapping=False):
272 """
274 """
273 Set the parameters of the integration class.
275 Set the parameters of the integration class.
274
276
275 Inputs:
277 Inputs:
276
278
277 nCohInt : Number of coherent integrations
279 nCohInt : Number of coherent integrations
278 timeInterval : Time of integration. If the parameter "nCohInt" is selected this one does not work
280 timeInterval : Time of integration. If the parameter "nCohInt" is selected this one does not work
279 overlapping :
281 overlapping :
280
282
281 """
283 """
282
284
283 self.__initime = None
285 self.__initime = None
286 self.__lastdatatime = 0
284 self.__buffer = None
287 self.__buffer = None
285 self.__dataReady = False
288 self.__dataReady = False
286
289
287
290
288 if nCohInt == None and timeInterval == None:
291 if nCohInt == None and timeInterval == None:
289 raise ValueError, "nCohInt or timeInterval should be specified ..."
292 raise ValueError, "nCohInt or timeInterval should be specified ..."
290
293
291 if nCohInt != None:
294 if nCohInt != None:
292 self.nCohInt = nCohInt
295 self.nCohInt = nCohInt
293 self.__byTime = False
296 self.__byTime = False
294 else:
297 else:
295 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
298 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
296 self.nCohInt = 9999
299 self.nCohInt = 9999
297 self.__byTime = True
300 self.__byTime = True
298
301
299 if overlapping:
302 if overlapping:
300 self.__withOverapping = True
303 self.__withOverapping = True
301 self.__buffer = None
304 self.__buffer = None
302 else:
305 else:
303 self.__withOverapping = False
306 self.__withOverapping = False
304 self.__buffer = 0
307 self.__buffer = 0
305
308
306 self.__profIndex = 0
309 self.__profIndex = 0
307
310
308 def putData(self, data):
311 def putData(self, data):
309
312
310 """
313 """
311 Add a profile to the __buffer and increase in one the __profileIndex
314 Add a profile to the __buffer and increase in one the __profileIndex
312
315
313 """
316 """
314 if self.__initime == None:
315 self.__initime = datatime
316
317
317 if not self.__withOverapping:
318 if not self.__withOverapping:
318 self.__buffer += data
319 self.__buffer += data
319 self.__profIndex += 1
320 self.__profIndex += 1
320 return
321 return
321
322
322 #Overlapping data
323 #Overlapping data
323 nChannels, nHeis = data.shape
324 nChannels, nHeis = data.shape
324 data = numpy.reshape(data, (1, nChannels, nHeis))
325 data = numpy.reshape(data, (1, nChannels, nHeis))
325
326
326 #If the buffer is empty then it takes the data value
327 #If the buffer is empty then it takes the data value
327 if self.__buffer == None:
328 if self.__buffer == None:
328 self.__buffer = data
329 self.__buffer = data
329 self.__profIndex += 1
330 self.__profIndex += 1
330 return
331 return
331
332
332 #If the buffer length is lower than nCohInt then stakcing the data value
333 #If the buffer length is lower than nCohInt then stakcing the data value
333 if self.__profIndex < self.nCohInt:
334 if self.__profIndex < self.nCohInt:
334 self.__buffer = numpy.vstack((self.__buffer, data))
335 self.__buffer = numpy.vstack((self.__buffer, data))
335 self.__profIndex += 1
336 self.__profIndex += 1
336 return
337 return
337
338
338 #If the buffer length is equal to nCohInt then replacing the last buffer value with the data value
339 #If the buffer length is equal to nCohInt then replacing the last buffer value with the data value
339 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
340 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
340 self.__buffer[self.nCohInt-1] = data
341 self.__buffer[self.nCohInt-1] = data
341 self.__profIndex = self.nCohInt
342 self.__profIndex = self.nCohInt
342 return
343 return
343
344
344
345
345 def pushData(self):
346 def pushData(self):
346 """
347 """
347 Return the sum of the last profiles and the profiles used in the sum.
348 Return the sum of the last profiles and the profiles used in the sum.
348
349
349 Affected:
350 Affected:
350
351
351 self.__profileIndex
352 self.__profileIndex
352
353
353 """
354 """
354
355
355 self.__initime = None
356
357 if not self.__withOverapping:
356 if not self.__withOverapping:
358 data = self.__buffer
357 data = self.__buffer
359 nCohInt = self.__profIndex
358 nCohInt = self.__profIndex
360
359
361 self.__buffer = 0
360 self.__buffer = 0
362 self.__profIndex = 0
361 self.__profIndex = 0
363
362
364 return data, nCohInt
363 return data, nCohInt
365
364
366 #Integration with Overlapping
365 #Integration with Overlapping
367 data = numpy.sum(self.__buffer, axis=0)
366 data = numpy.sum(self.__buffer, axis=0)
368 nCohInt = self.__profIndex
367 nCohInt = self.__profIndex
369
368
370 return data, nCohInt
369 return data, nCohInt
371
370
372 def byProfiles(self, data):
371 def byProfiles(self, data):
373
372
374 self.__dataReady = False
373 self.__dataReady = False
375 avg_data = None
374 avg_data = None
375 nCohInt = None
376
376
377 self.putData(data)
377 self.putData(data)
378
378
379 if self.__profIndex == self.nCohInt:
379 if self.__profIndex == self.nCohInt:
380
380
381 avgdata, nCohInt = self.pushData()
381 avgdata, nCohInt = self.pushData()
382 self.__dataReady = True
382 self.__dataReady = True
383
383
384 return avgdata, nCohInt
384 return avgdata, nCohInt
385
385
386 def byTime(self, data, datatime):
386 def byTime(self, data, datatime):
387
387
388 self.__dataReady = False
388 self.__dataReady = False
389 avg_data = None
389 avg_data = None
390
390 nCohInt = None
391
391 self.putData(data)
392 self.putData(data)
392
393
393 if (datatime - self.__initime) >= self.__integrationtime:
394 if (datatime - self.__initime) >= self.__integrationtime:
394 avgdata, nCohInt = self.pushData()
395 avgdata, nCohInt = self.pushData()
395 self.nCohInt = nCohInt
396 self.nCohInt = nCohInt
396 self.__dataReady = True
397 self.__dataReady = True
397
398
398 return avgdata, nCohInt
399 return avgdata, nCohInt
399
400
400 def integrate(self, data, datatime=None):
401 def integrate(self, data, datatime=None):
401
402
402 if not self.__byTime:
403 if self.__initime == None:
403 avg_data = self.byProfiles(data)
404 self.__initime = datatime
405
406 if self.__byTime:
407 avgdata = self.byTime(data, datatime)
404 else:
408 else:
405 avg_data = self.byTime(data, datatime)
409 avgdata = self.byProfiles(data)
406
410
407 self.data = avg_data
408
411
412 self.__lastdatatime = datatime
413
414 if avgdata == None:
415 return None
416
417 avgdatatime = self.__initime
418
419 deltatime = datatime -self.__lastdatatime
420
421 if not self.__withOverapping:
422 self.__initime = datatime
423 else:
424 self.__initime += deltatime
425
426 return avgdata, avgdatatime
409
427
410 def run(self, dataOut, nCohInt=None, timeInterval=None, overlapping=False):
428 def run(self, dataOut, nCohInt=None, timeInterval=None, overlapping=False):
411
429
430 if not self.__isConfig:
431 self.setup(nCohInt, timeInterval, overlapping)
432 self.__isConfig = True
433
434 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
412
435
413 # self.dataOutObj.timeInterval *= nCohInt
436 # self.dataOutObj.timeInterval *= nCohInt
414 self.dataOutObj.flagNoData = True
437 self.dataOutObj.flagNoData = True
415
438
416 if myCohIntObj.__dataReady:
439 if self.__dataReady:
417 self.dataOutObj.data = myCohIntObj.data
440 dataOutObj.data = avgdata
418 self.dataOutObj.timeInterval *= myCohIntObj.nCohInt
441 dataOutObj.timeInterval *= self.nCohInt
419 self.dataOutObj.nCohInt = myCohIntObj.nCohInt * self.dataInObj.nCohInt
442 dataOutObj.nCohInt *= self.nCohInt
420 self.dataOutObj.utctime = myCohIntObj.firstdatatime
443 dataOutObj.utctime = avgdatatime
421 self.dataOutObj.flagNoData = False
444 dataOutObj.flagNoData = False No newline at end of file
422
423 return avg_data No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now