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