##// END OF EJS Templates
Se agrego selectHeisa VoltageProc
Miguel Valdez -
r219:70dd31f0d294
parent child
Show More
@@ -1,675 +1,694
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):
263
264 opObj = self.opConfObjList[0]
265
266 opObj.addParameter(**kwargs)
267
268 return opObj
269
262 def addOperation(self, name, optype='self'):
270 def addOperation(self, name, optype='self'):
263
271
264 id = self.__getNewId()
272 id = self.__getNewId()
265 priority = self.__getPriority()
273 priority = self.__getPriority()
266
274
267 opConfObj = OperationConf()
275 opConfObj = OperationConf()
268 opConfObj.setup(id, name=name, priority=priority, type=optype)
276 opConfObj.setup(id, name=name, priority=priority, type=optype)
269
277
270 self.opConfObjList.append(opConfObj)
278 self.opConfObjList.append(opConfObj)
271
279
272 return opConfObj
280 return opConfObj
273
281
274 def makeXml(self, procUnitElement):
282 def makeXml(self, procUnitElement):
275
283
276 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
284 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
277 upElement.set('id', str(self.id))
285 upElement.set('id', str(self.id))
278 upElement.set('name', self.name)
286 upElement.set('name', self.name)
279 upElement.set('datatype', self.datatype)
287 upElement.set('datatype', self.datatype)
280 upElement.set('inputId', str(self.inputId))
288 upElement.set('inputId', str(self.inputId))
281
289
282 for opConfObj in self.opConfObjList:
290 for opConfObj in self.opConfObjList:
283 opConfObj.makeXml(upElement)
291 opConfObj.makeXml(upElement)
284
292
285 def readXml(self, upElement):
293 def readXml(self, upElement):
286
294
287 self.id = upElement.get('id')
295 self.id = upElement.get('id')
288 self.name = upElement.get('name')
296 self.name = upElement.get('name')
289 self.datatype = upElement.get('datatype')
297 self.datatype = upElement.get('datatype')
290 self.inputId = upElement.get('inputId')
298 self.inputId = upElement.get('inputId')
291
299
292 self.opConfObjList = []
300 self.opConfObjList = []
293
301
294 opElementList = upElement.getiterator(OperationConf().getElementName())
302 opElementList = upElement.getiterator(OperationConf().getElementName())
295
303
296 for opElement in opElementList:
304 for opElement in opElementList:
297 opConfObj = OperationConf()
305 opConfObj = OperationConf()
298 opConfObj.readXml(opElement)
306 opConfObj.readXml(opElement)
299 self.opConfObjList.append(opConfObj)
307 self.opConfObjList.append(opConfObj)
300
308
301 def printattr(self):
309 def printattr(self):
302
310
303 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
311 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
304 self.id,
312 self.id,
305 self.name,
313 self.name,
306 self.datatype,
314 self.datatype,
307 self.inputId)
315 self.inputId)
308
316
309 for opConfObj in self.opConfObjList:
317 for opConfObj in self.opConfObjList:
310 opConfObj.printattr()
318 opConfObj.printattr()
311
319
312 def createObjects(self):
320 def createObjects(self):
313
321
314 className = eval(self.name)
322 className = eval(self.name)
315 procUnitObj = className()
323 procUnitObj = className()
316
324
317 for opConfObj in self.opConfObjList:
325 for opConfObj in self.opConfObjList:
318
326
319 if opConfObj.type == 'self':
327 if opConfObj.type == 'self':
320 continue
328 continue
321
329
322 opObj = opConfObj.createObject()
330 opObj = opConfObj.createObject()
323
331
324 self.opObjDict[opConfObj.id] = opObj
332 self.opObjDict[opConfObj.id] = opObj
325 procUnitObj.addOperation(opObj, opConfObj.id)
333 procUnitObj.addOperation(opObj, opConfObj.id)
326
334
327 self.procUnitObj = procUnitObj
335 self.procUnitObj = procUnitObj
328
336
329 return procUnitObj
337 return procUnitObj
330
338
331 def run(self):
339 def run(self):
332
340
333 finalSts = False
341 finalSts = False
334
342
335 for opConfObj in self.opConfObjList:
343 for opConfObj in self.opConfObjList:
336
344
337 kwargs = {}
345 kwargs = {}
338 for parmConfObj in opConfObj.getParameterObjList():
346 for parmConfObj in opConfObj.getParameterObjList():
339 kwargs[parmConfObj.name] = parmConfObj.getValue()
347 kwargs[parmConfObj.name] = parmConfObj.getValue()
340
348
341 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
349 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
342 sts = self.procUnitObj.call(opConfObj, **kwargs)
350 sts = self.procUnitObj.call(opConfObj, **kwargs)
343 finalSts = finalSts or sts
351 finalSts = finalSts or sts
344
352
345 return finalSts
353 return finalSts
346
354
347 class ReadUnitConf(ProcUnitConf):
355 class ReadUnitConf(ProcUnitConf):
348
356
349 path = None
357 path = None
350 startDate = None
358 startDate = None
351 endDate = None
359 endDate = None
352 startTime = None
360 startTime = None
353 endTime = None
361 endTime = None
354 online = None
362 online = None
355 expLabel = None
363 expLabel = None
356 delay = None
364 delay = None
357
365
358 ELEMENTNAME = 'ReadUnit'
366 ELEMENTNAME = 'ReadUnit'
359
367
360 def __init__(self):
368 def __init__(self):
361
369
362 self.id = None
370 self.id = None
363 self.datatype = None
371 self.datatype = None
364 self.name = None
372 self.name = None
365 self.inputId = 0
373 self.inputId = 0
366
374
367 self.opConfObjList = []
375 self.opConfObjList = []
368 self.opObjList = []
376 self.opObjList = []
369
377
370 def getElementName(self):
378 def getElementName(self):
371
379
372 return self.ELEMENTNAME
380 return self.ELEMENTNAME
373
381
374 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):
375
383
376 self.id = id
384 self.id = id
377 self.name = name
385 self.name = name
378 self.datatype = datatype
386 self.datatype = datatype
379
387
380 self.path = path
388 self.path = path
381 self.startDate = startDate
389 self.startDate = startDate
382 self.endDate = endDate
390 self.endDate = endDate
383 self.startTime = startTime
391 self.startTime = startTime
384 self.endTime = endTime
392 self.endTime = endTime
385 self.online = online
393 self.online = online
386 self.expLabel = expLabel
394 self.expLabel = expLabel
387 self.delay = delay
395 self.delay = delay
388
396
389 self.addRunOperation()
397 self.addRunOperation()
390
398
391 def addRunOperation(self):
399 def addRunOperation(self):
392
400
393 opObj = self.addOperation(name = 'run', optype = 'self')
401 opObj = self.addOperation(name = 'run', optype = 'self')
394
402
395 opObj.addParameter(name='path' , value=self.path, format='str')
403 opObj.addParameter(name='path' , value=self.path, format='str')
396 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
404 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
397 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
405 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
398 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
406 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
399 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
407 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
400 opObj.addParameter(name='expLabel' , value=self.expLabel, format='str')
408 opObj.addParameter(name='expLabel' , value=self.expLabel, format='str')
401 opObj.addParameter(name='online' , value=self.online, format='int')
409 opObj.addParameter(name='online' , value=self.online, format='int')
402 opObj.addParameter(name='delay' , value=self.delay, format='float')
410 opObj.addParameter(name='delay' , value=self.delay, format='float')
403
411
404 return opObj
412 return opObj
405
413
406
414
407 class Controller():
415 class Controller():
408
416
409 id = None
417 id = None
410 name = None
418 name = None
411 description = None
419 description = None
412 # readUnitConfObjList = None
420 # readUnitConfObjList = None
413 procUnitConfObjDict = None
421 procUnitConfObjDict = None
414
422
415 ELEMENTNAME = 'Controller'
423 ELEMENTNAME = 'Controller'
416
424
417 def __init__(self):
425 def __init__(self):
418
426
419 self.id = None
427 self.id = None
420 self.name = None
428 self.name = None
421 self.description = None
429 self.description = None
422
430
423 # self.readUnitConfObjList = []
431 # self.readUnitConfObjList = []
424 self.procUnitConfObjDict = {}
432 self.procUnitConfObjDict = {}
425
433
426 def __getNewId(self):
434 def __getNewId(self):
427
435
428 id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1
436 id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1
429
437
430 return str(id)
438 return str(id)
431
439
432 def getElementName(self):
440 def getElementName(self):
433
441
434 return self.ELEMENTNAME
442 return self.ELEMENTNAME
435
443
436 def setup(self, id, name, description):
444 def setup(self, id, name, description):
437
445
438 self.id = id
446 self.id = id
439 self.name = name
447 self.name = name
440 self.description = description
448 self.description = description
441
449
442 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):
443
451
444 id = self.__getNewId()
452 id = self.__getNewId()
445 name = '%sReader' %(datatype)
453 name = '%sReader' %(datatype)
446
454
447 readUnitConfObj = ReadUnitConf()
455 readUnitConfObj = ReadUnitConf()
448 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)
449
457
450 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
458 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
451
459
452 return readUnitConfObj
460 return readUnitConfObj
453
461
454 def addProcUnit(self, datatype, inputId):
462 def addProcUnit(self, datatype, inputId):
455
463
456 id = self.__getNewId()
464 id = self.__getNewId()
457 name = '%sProc' %(datatype)
465 name = '%sProc' %(datatype)
458
466
459 procUnitConfObj = ProcUnitConf()
467 procUnitConfObj = ProcUnitConf()
460 procUnitConfObj.setup(id, name, datatype, inputId)
468 procUnitConfObj.setup(id, name, datatype, inputId)
461
469
462 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
470 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
463
471
464 return procUnitConfObj
472 return procUnitConfObj
465
473
466 def makeXml(self):
474 def makeXml(self):
467
475
468 projectElement = Element('Controller')
476 projectElement = Element('Controller')
469 projectElement.set('id', str(self.id))
477 projectElement.set('id', str(self.id))
470 projectElement.set('name', self.name)
478 projectElement.set('name', self.name)
471 projectElement.set('description', self.description)
479 projectElement.set('description', self.description)
472
480
473 # for readUnitConfObj in self.readUnitConfObjList:
481 # for readUnitConfObj in self.readUnitConfObjList:
474 # readUnitConfObj.makeXml(projectElement)
482 # readUnitConfObj.makeXml(projectElement)
475
483
476 for procUnitConfObj in self.procUnitConfObjDict.values():
484 for procUnitConfObj in self.procUnitConfObjDict.values():
477 procUnitConfObj.makeXml(projectElement)
485 procUnitConfObj.makeXml(projectElement)
478
486
479 self.projectElement = projectElement
487 self.projectElement = projectElement
480
488
481 def writeXml(self, filename):
489 def writeXml(self, filename):
482
490
483 self.makeXml()
491 self.makeXml()
484
492
485 print prettify(self.projectElement)
493 print prettify(self.projectElement)
486
494
487 ElementTree(self.projectElement).write(filename, method='xml')
495 ElementTree(self.projectElement).write(filename, method='xml')
488
496
489 def readXml(self, filename):
497 def readXml(self, filename):
490
498
491 #tree = ET.parse(filename)
499 #tree = ET.parse(filename)
492 self.projectElement = None
500 self.projectElement = None
493 # self.readUnitConfObjList = []
501 # self.readUnitConfObjList = []
494 self.procUnitConfObjDict = {}
502 self.procUnitConfObjDict = {}
495
503
496 self.projectElement = ElementTree().parse(filename)
504 self.projectElement = ElementTree().parse(filename)
497
505
498 self.project = self.projectElement.tag
506 self.project = self.projectElement.tag
499
507
500 self.id = self.projectElement.get('id')
508 self.id = self.projectElement.get('id')
501 self.name = self.projectElement.get('name')
509 self.name = self.projectElement.get('name')
502 self.description = self.projectElement.get('description')
510 self.description = self.projectElement.get('description')
503
511
504 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
512 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
505
513
506 for readUnitElement in readUnitElementList:
514 for readUnitElement in readUnitElementList:
507 readUnitConfObj = ReadUnitConf()
515 readUnitConfObj = ReadUnitConf()
508 readUnitConfObj.readXml(readUnitElement)
516 readUnitConfObj.readXml(readUnitElement)
509
517
510 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
518 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
511
519
512 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
520 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
513
521
514 for procUnitElement in procUnitElementList:
522 for procUnitElement in procUnitElementList:
515 procUnitConfObj = ProcUnitConf()
523 procUnitConfObj = ProcUnitConf()
516 procUnitConfObj.readXml(procUnitElement)
524 procUnitConfObj.readXml(procUnitElement)
517
525
518 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
526 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
519
527
520 def printattr(self):
528 def printattr(self):
521
529
522 print "Controller[%s]: name = %s, description = %s" %(self.id,
530 print "Controller[%s]: name = %s, description = %s" %(self.id,
523 self.name,
531 self.name,
524 self.description)
532 self.description)
525
533
526 # for readUnitConfObj in self.readUnitConfObjList:
534 # for readUnitConfObj in self.readUnitConfObjList:
527 # readUnitConfObj.printattr()
535 # readUnitConfObj.printattr()
528
536
529 for procUnitConfObj in self.procUnitConfObjDict.values():
537 for procUnitConfObj in self.procUnitConfObjDict.values():
530 procUnitConfObj.printattr()
538 procUnitConfObj.printattr()
531
539
532 def createObjects(self):
540 def createObjects(self):
533
541
534 # for readUnitConfObj in self.readUnitConfObjList:
542 # for readUnitConfObj in self.readUnitConfObjList:
535 # readUnitConfObj.createObjects()
543 # readUnitConfObj.createObjects()
536
544
537 for procUnitConfObj in self.procUnitConfObjDict.values():
545 for procUnitConfObj in self.procUnitConfObjDict.values():
538 procUnitConfObj.createObjects()
546 procUnitConfObj.createObjects()
539
547
540 def __connect(self, objIN, obj):
548 def __connect(self, objIN, obj):
541
549
542 obj.setInput(objIN.getOutput())
550 obj.setInput(objIN.getOutput())
543
551
544 def connectObjects(self):
552 def connectObjects(self):
545
553
546 for puConfObj in self.procUnitConfObjDict.values():
554 for puConfObj in self.procUnitConfObjDict.values():
547
555
548 inputId = puConfObj.getInputId()
556 inputId = puConfObj.getInputId()
549
557
550 if int(inputId) == 0:
558 if int(inputId) == 0:
551 continue
559 continue
552
560
553 puConfINObj = self.procUnitConfObjDict[inputId]
561 puConfINObj = self.procUnitConfObjDict[inputId]
554
562
555 puObj = puConfObj.getProcUnitObj()
563 puObj = puConfObj.getProcUnitObj()
556 puINObj = puConfINObj.getProcUnitObj()
564 puINObj = puConfINObj.getProcUnitObj()
557
565
558 self.__connect(puINObj, puObj)
566 self.__connect(puINObj, puObj)
559
567
560 def run(self):
568 def run(self):
561
569
562 # for readUnitConfObj in self.readUnitConfObjList:
570 # for readUnitConfObj in self.readUnitConfObjList:
563 # readUnitConfObj.run()
571 # readUnitConfObj.run()
564
572
565 while(True):
573 while(True):
566
574
567 finalSts = False
575 finalSts = False
568
576
569 for procUnitConfObj in self.procUnitConfObjDict.values():
577 for procUnitConfObj in self.procUnitConfObjDict.values():
570 #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
578 #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
571 sts = procUnitConfObj.run()
579 sts = procUnitConfObj.run()
572 finalSts = finalSts or sts
580 finalSts = finalSts or sts
573
581
574 #If every process unit finished so end process
582 #If every process unit finished so end process
575 if not(finalSts):
583 if not(finalSts):
576 print "Every process units have finished"
584 print "Every process units have finished"
577 break
585 break
578
586
579 if __name__ == '__main__':
587 if __name__ == '__main__':
580
588
581 desc = "Segundo Test"
589 desc = "Segundo Test"
582 filename = "schain.xml"
590 filename = "schain.xml"
583
591
584 controllerObj = Controller()
592 controllerObj = Controller()
585
593
586 controllerObj.setup(id = '191', name='test01', description=desc)
594 controllerObj.setup(id = '191', name='test01', description=desc)
587
595
588 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
596 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
589 path='/Users/dsuarez/Remote/IMAGING',
597 path='data/rawdata/',
590 startDate='2011/03/20',
598 startDate='2011/01/01',
591 endDate='2012/12/31',
599 endDate='2012/12/31',
592 startTime='06:10:00',
600 startTime='00:00:00',
593 endTime='23:59:59',
601 endTime='23:59:59',
594 online=0)
602 online=0)
595
603
596 opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks')
604 opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks')
597
605
598 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
606 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
607
608 opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
609 opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
599
610
600 opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
611 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
601 opObj10.addParameter(name='channelList', value='0,1,2,4,6,7', format='intlist')
612 opObj10.addParameter(name='minHei', value='90', format='float')
613 opObj10.addParameter(name='maxHei', value='180', format='float')
614
615 opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
616 opObj12.addParameter(name='n', value='10', format='int')
617
618 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
619 procUnitConfObj1.addParameter(name='nFFTPoints', value='16', format='int')
602
620
603 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
621 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
604 opObj11.addParameter(name='idfigure', value='1', format='int')
622 opObj11.addParameter(name='idfigure', value='1', format='int')
605 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
623 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
606 # opObj11.addParameter(name='zmin', value='70', format='int')
624 opObj11.addParameter(name='zmin', value='40', format='int')
607 # opObj11.addParameter(name='zmax', value='90', format='int')
625 opObj11.addParameter(name='zmax', value='80', format='int')
608 opObj11.addParameter(name='showprofile', value='0', format='int')
626 opObj11.addParameter(name='showprofile', value='1', format='int')
609 opObj11.addParameter(name='save', value='1', format='int')
610 opObj11.addParameter(name='filename', value='/Users/dsuarez/Pictures/SpectraPlot.png', format='str')
611
627
612 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
628 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
613 opObj11.addParameter(name='idfigure', value='10', format='int')
629 opObj11.addParameter(name='idfigure', value='10', format='int')
614 opObj11.addParameter(name='wintitle', value='RTI', format='str')
630 opObj11.addParameter(name='wintitle', value='RTI', format='str')
615 # opObj11.addParameter(name='zmin', value='70', format='int')
631 # opObj11.addParameter(name='xmin', value='21', format='float')
616 # opObj11.addParameter(name='zmax', value='90', format='int')
632 # opObj11.addParameter(name='xmax', value='22', format='float')
617 opObj11.addParameter(name='showprofile', value='0', format='int')
633 opObj11.addParameter(name='zmin', value='40', format='int')
634 opObj11.addParameter(name='zmax', value='80', format='int')
635 opObj11.addParameter(name='showprofile', value='1', format='int')
636 opObj11.addParameter(name='timerange', value=str(20), format='int')
618
637
619 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
638 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
620 # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist')
639 # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist')
621 #
640 #
622 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
641 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
623 # opObj12.addParameter(name='n', value='2', format='int')
642 # opObj12.addParameter(name='n', value='2', format='int')
624 #
643 #
625 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
644 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
626 # opObj11.addParameter(name='idfigure', value='2', format='int')
645 # opObj11.addParameter(name='idfigure', value='2', format='int')
627 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
646 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
628 # opObj11.addParameter(name='zmin', value='70', format='int')
647 # opObj11.addParameter(name='zmin', value='70', format='int')
629 # opObj11.addParameter(name='zmax', value='90', format='int')
648 # opObj11.addParameter(name='zmax', value='90', format='int')
630 #
649 #
631 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
650 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
632 # opObj10.addParameter(name='channelList', value='2,6', format='intlist')
651 # opObj10.addParameter(name='channelList', value='2,6', format='intlist')
633 #
652 #
634 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
653 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
635 # opObj12.addParameter(name='n', value='2', format='int')
654 # opObj12.addParameter(name='n', value='2', format='int')
636 #
655 #
637 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
656 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
638 # opObj11.addParameter(name='idfigure', value='3', format='int')
657 # opObj11.addParameter(name='idfigure', value='3', format='int')
639 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
658 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
640 # opObj11.addParameter(name='zmin', value='70', format='int')
659 # opObj11.addParameter(name='zmin', value='70', format='int')
641 # opObj11.addParameter(name='zmax', value='90', format='int')
660 # opObj11.addParameter(name='zmax', value='90', format='int')
642
661
643
662
644 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
663 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
645 # opObj12.addParameter(name='ncode', value='2', format='int')
664 # opObj12.addParameter(name='ncode', value='2', format='int')
646 # opObj12.addParameter(name='nbauds', value='8', format='int')
665 # opObj12.addParameter(name='nbauds', value='8', format='int')
647 # opObj12.addParameter(name='code0', value='001110011', format='int')
666 # opObj12.addParameter(name='code0', value='001110011', format='int')
648 # opObj12.addParameter(name='code1', value='001110011', format='int')
667 # opObj12.addParameter(name='code1', value='001110011', format='int')
649
668
650
669
651
670
652 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId())
671 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId())
653 #
672 #
654 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
673 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
655 # opObj21.addParameter(name='n', value='2', format='int')
674 # opObj21.addParameter(name='n', value='2', format='int')
656 #
675 #
657 # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
676 # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
658 # opObj11.addParameter(name='idfigure', value='4', format='int')
677 # opObj11.addParameter(name='idfigure', value='4', format='int')
659 # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str')
678 # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str')
660 # opObj11.addParameter(name='zmin', value='70', format='int')
679 # opObj11.addParameter(name='zmin', value='70', format='int')
661 # opObj11.addParameter(name='zmax', value='90', format='int')
680 # opObj11.addParameter(name='zmax', value='90', format='int')
662
681
663 print "Escribiendo el archivo XML"
682 print "Escribiendo el archivo XML"
664
683
665 controllerObj.writeXml(filename)
684 controllerObj.writeXml(filename)
666
685
667 print "Leyendo el archivo XML"
686 print "Leyendo el archivo XML"
668 controllerObj.readXml(filename)
687 controllerObj.readXml(filename)
669 #controllerObj.printattr()
688 #controllerObj.printattr()
670
689
671 controllerObj.createObjects()
690 controllerObj.createObjects()
672 controllerObj.connectObjects()
691 controllerObj.connectObjects()
673 controllerObj.run()
692 controllerObj.run()
674
693
675 No newline at end of file
694
@@ -1,511 +1,511
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9
9
10 class Header:
10 class Header:
11
11
12 def __init__(self):
12 def __init__(self):
13 raise
13 raise
14
14
15 def copy(self):
15 def copy(self):
16 return copy.deepcopy(self)
16 return copy.deepcopy(self)
17
17
18 def read():
18 def read():
19 pass
19 pass
20
20
21 def write():
21 def write():
22 pass
22 pass
23
23
24 class BasicHeader(Header):
24 class BasicHeader(Header):
25
25
26 size = None
26 size = None
27 version = None
27 version = None
28 dataBlock = None
28 dataBlock = None
29 utc = None
29 utc = None
30 miliSecond = None
30 miliSecond = None
31 timeZone = None
31 timeZone = None
32 dstFlag = None
32 dstFlag = None
33 errorCount = None
33 errorCount = None
34 struct = None
34 struct = None
35
35
36 def __init__(self):
36 def __init__(self):
37
37
38 self.size = 0
38 self.size = 0
39 self.version = 0
39 self.version = 0
40 self.dataBlock = 0
40 self.dataBlock = 0
41 self.utc = 0
41 self.utc = 0
42 self.miliSecond = 0
42 self.miliSecond = 0
43 self.timeZone = 0
43 self.timeZone = 0
44 self.dstFlag = 0
44 self.dstFlag = 0
45 self.errorCount = 0
45 self.errorCount = 0
46 self.struct = numpy.dtype([
46 self.struct = numpy.dtype([
47 ('nSize','<u4'),
47 ('nSize','<u4'),
48 ('nVersion','<u2'),
48 ('nVersion','<u2'),
49 ('nDataBlockId','<u4'),
49 ('nDataBlockId','<u4'),
50 ('nUtime','<u4'),
50 ('nUtime','<u4'),
51 ('nMilsec','<u2'),
51 ('nMilsec','<u2'),
52 ('nTimezone','<i2'),
52 ('nTimezone','<i2'),
53 ('nDstflag','<i2'),
53 ('nDstflag','<i2'),
54 ('nErrorCount','<u4')
54 ('nErrorCount','<u4')
55 ])
55 ])
56
56
57
57
58 def read(self, fp):
58 def read(self, fp):
59 try:
59 try:
60 header = numpy.fromfile(fp, self.struct,1)
60 header = numpy.fromfile(fp, self.struct,1)
61 self.size = int(header['nSize'][0])
61 self.size = int(header['nSize'][0])
62 self.version = int(header['nVersion'][0])
62 self.version = int(header['nVersion'][0])
63 self.dataBlock = int(header['nDataBlockId'][0])
63 self.dataBlock = int(header['nDataBlockId'][0])
64 self.utc = int(header['nUtime'][0])
64 self.utc = int(header['nUtime'][0])
65 self.miliSecond = int(header['nMilsec'][0])
65 self.miliSecond = int(header['nMilsec'][0])
66 self.timeZone = int(header['nTimezone'][0])
66 self.timeZone = int(header['nTimezone'][0])
67 self.dstFlag = int(header['nDstflag'][0])
67 self.dstFlag = int(header['nDstflag'][0])
68 self.errorCount = int(header['nErrorCount'][0])
68 self.errorCount = int(header['nErrorCount'][0])
69
69
70 except Exception, e:
70 except Exception, e:
71 print "BasicHeader: " + e
71 print "BasicHeader: " + e
72 return 0
72 return 0
73
73
74 return 1
74 return 1
75
75
76 def write(self, fp):
76 def write(self, fp):
77 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
77 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
78 header = numpy.array(headerTuple,self.struct)
78 header = numpy.array(headerTuple,self.struct)
79 header.tofile(fp)
79 header.tofile(fp)
80
80
81 return 1
81 return 1
82
82
83 class SystemHeader(Header):
83 class SystemHeader(Header):
84
84
85 size = None
85 size = None
86 nSamples = None
86 nSamples = None
87 nProfiles = None
87 nProfiles = None
88 nChannels = None
88 nChannels = None
89 adcResolution = None
89 adcResolution = None
90 pciDioBusWidth = None
90 pciDioBusWidth = None
91 struct = None
91 struct = None
92
92
93 def __init__(self):
93 def __init__(self):
94 self.size = 0
94 self.size = 0
95 self.nSamples = 0
95 self.nSamples = 0
96 self.nProfiles = 0
96 self.nProfiles = 0
97 self.nChannels = 0
97 self.nChannels = 0
98 self.adcResolution = 0
98 self.adcResolution = 0
99 self.pciDioBusWidth = 0
99 self.pciDioBusWidth = 0
100 self.struct = numpy.dtype([
100 self.struct = numpy.dtype([
101 ('nSize','<u4'),
101 ('nSize','<u4'),
102 ('nNumSamples','<u4'),
102 ('nNumSamples','<u4'),
103 ('nNumProfiles','<u4'),
103 ('nNumProfiles','<u4'),
104 ('nNumChannels','<u4'),
104 ('nNumChannels','<u4'),
105 ('nADCResolution','<u4'),
105 ('nADCResolution','<u4'),
106 ('nPCDIOBusWidth','<u4'),
106 ('nPCDIOBusWidth','<u4'),
107 ])
107 ])
108
108
109
109
110 def read(self, fp):
110 def read(self, fp):
111 try:
111 try:
112 header = numpy.fromfile(fp,self.struct,1)
112 header = numpy.fromfile(fp,self.struct,1)
113 self.size = header['nSize'][0]
113 self.size = header['nSize'][0]
114 self.nSamples = header['nNumSamples'][0]
114 self.nSamples = header['nNumSamples'][0]
115 self.nProfiles = header['nNumProfiles'][0]
115 self.nProfiles = header['nNumProfiles'][0]
116 self.nChannels = header['nNumChannels'][0]
116 self.nChannels = header['nNumChannels'][0]
117 self.adcResolution = header['nADCResolution'][0]
117 self.adcResolution = header['nADCResolution'][0]
118 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
118 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
119
119
120 except Exception, e:
120 except Exception, e:
121 print "SystemHeader: " + e
121 print "SystemHeader: " + e
122 return 0
122 return 0
123
123
124 return 1
124 return 1
125
125
126 def write(self, fp):
126 def write(self, fp):
127 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
127 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
128 header = numpy.array(headerTuple,self.struct)
128 header = numpy.array(headerTuple,self.struct)
129 header.tofile(fp)
129 header.tofile(fp)
130
130
131 return 1
131 return 1
132
132
133 class RadarControllerHeader(Header):
133 class RadarControllerHeader(Header):
134
134
135 size = None
135 size = None
136 expType = None
136 expType = None
137 nTx = None
137 nTx = None
138 ipp = None
138 ipp = None
139 txA = None
139 txA = None
140 txB = None
140 txB = None
141 nWindows = None
141 nWindows = None
142 numTaus = None
142 numTaus = None
143 codeType = None
143 codeType = None
144 line6Function = None
144 line6Function = None
145 line5Function = None
145 line5Function = None
146 fClock = None
146 fClock = None
147 prePulseBefore = None
147 prePulseBefore = None
148 prePulserAfter = None
148 prePulserAfter = None
149 rangeIpp = None
149 rangeIpp = None
150 rangeTxA = None
150 rangeTxA = None
151 rangeTxB = None
151 rangeTxB = None
152 struct = None
152 struct = None
153
153
154 def __init__(self):
154 def __init__(self):
155 self.size = 0
155 self.size = 0
156 self.expType = 0
156 self.expType = 0
157 self.nTx = 0
157 self.nTx = 0
158 self.ipp = 0
158 self.ipp = 0
159 self.txA = 0
159 self.txA = 0
160 self.txB = 0
160 self.txB = 0
161 self.nWindows = 0
161 self.nWindows = 0
162 self.numTaus = 0
162 self.numTaus = 0
163 self.codeType = 0
163 self.codeType = 0
164 self.line6Function = 0
164 self.line6Function = 0
165 self.line5Function = 0
165 self.line5Function = 0
166 self.fClock = 0
166 self.fClock = 0
167 self.prePulseBefore = 0
167 self.prePulseBefore = 0
168 self.prePulserAfter = 0
168 self.prePulserAfter = 0
169 self.rangeIpp = 0
169 self.rangeIpp = 0
170 self.rangeTxA = 0
170 self.rangeTxA = 0
171 self.rangeTxB = 0
171 self.rangeTxB = 0
172 self.struct = numpy.dtype([
172 self.struct = numpy.dtype([
173 ('nSize','<u4'),
173 ('nSize','<u4'),
174 ('nExpType','<u4'),
174 ('nExpType','<u4'),
175 ('nNTx','<u4'),
175 ('nNTx','<u4'),
176 ('fIpp','<f4'),
176 ('fIpp','<f4'),
177 ('fTxA','<f4'),
177 ('fTxA','<f4'),
178 ('fTxB','<f4'),
178 ('fTxB','<f4'),
179 ('nNumWindows','<u4'),
179 ('nNumWindows','<u4'),
180 ('nNumTaus','<u4'),
180 ('nNumTaus','<u4'),
181 ('nCodeType','<u4'),
181 ('nCodeType','<u4'),
182 ('nLine6Function','<u4'),
182 ('nLine6Function','<u4'),
183 ('nLine5Function','<u4'),
183 ('nLine5Function','<u4'),
184 ('fClock','<f4'),
184 ('fClock','<f4'),
185 ('nPrePulseBefore','<u4'),
185 ('nPrePulseBefore','<u4'),
186 ('nPrePulseAfter','<u4'),
186 ('nPrePulseAfter','<u4'),
187 ('sRangeIPP','<a20'),
187 ('sRangeIPP','<a20'),
188 ('sRangeTxA','<a20'),
188 ('sRangeTxA','<a20'),
189 ('sRangeTxB','<a20'),
189 ('sRangeTxB','<a20'),
190 ])
190 ])
191
191
192 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
192 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
193
193
194 self.samplingWindow = None
194 self.samplingWindow = None
195 self.nHeights = None
195 self.nHeights = None
196 self.firstHeight = None
196 self.firstHeight = None
197 self.deltaHeight = None
197 self.deltaHeight = None
198 self.samplesWin = None
198 self.samplesWin = None
199
199
200 self.nCode = None
200 self.nCode = None
201 self.nBaud = None
201 self.nBaud = None
202 self.code = None
202 self.code = None
203 self.flip1 = None
203 self.flip1 = None
204 self.flip2 = None
204 self.flip2 = None
205
205
206 self.dynamic = numpy.array([],numpy.dtype('byte'))
206 self.dynamic = numpy.array([],numpy.dtype('byte'))
207
207
208
208
209 def read(self, fp):
209 def read(self, fp):
210 try:
210 try:
211 startFp = fp.tell()
211 startFp = fp.tell()
212 header = numpy.fromfile(fp,self.struct,1)
212 header = numpy.fromfile(fp,self.struct,1)
213 self.size = int(header['nSize'][0])
213 self.size = int(header['nSize'][0])
214 self.expType = int(header['nExpType'][0])
214 self.expType = int(header['nExpType'][0])
215 self.nTx = int(header['nNTx'][0])
215 self.nTx = int(header['nNTx'][0])
216 self.ipp = float(header['fIpp'][0])
216 self.ipp = float(header['fIpp'][0])
217 self.txA = float(header['fTxA'][0])
217 self.txA = float(header['fTxA'][0])
218 self.txB = float(header['fTxB'][0])
218 self.txB = float(header['fTxB'][0])
219 self.nWindows = int(header['nNumWindows'][0])
219 self.nWindows = int(header['nNumWindows'][0])
220 self.numTaus = int(header['nNumTaus'][0])
220 self.numTaus = int(header['nNumTaus'][0])
221 self.codeType = int(header['nCodeType'][0])
221 self.codeType = int(header['nCodeType'][0])
222 self.line6Function = int(header['nLine6Function'][0])
222 self.line6Function = int(header['nLine6Function'][0])
223 self.line5Function = int(header['nLine5Function'][0])
223 self.line5Function = int(header['nLine5Function'][0])
224 self.fClock = float(header['fClock'][0])
224 self.fClock = float(header['fClock'][0])
225 self.prePulseBefore = int(header['nPrePulseBefore'][0])
225 self.prePulseBefore = int(header['nPrePulseBefore'][0])
226 self.prePulserAfter = int(header['nPrePulseAfter'][0])
226 self.prePulserAfter = int(header['nPrePulseAfter'][0])
227 self.rangeIpp = header['sRangeIPP'][0]
227 self.rangeIpp = header['sRangeIPP'][0]
228 self.rangeTxA = header['sRangeTxA'][0]
228 self.rangeTxA = header['sRangeTxA'][0]
229 self.rangeTxB = header['sRangeTxB'][0]
229 self.rangeTxB = header['sRangeTxB'][0]
230 # jump Dynamic Radar Controller Header
230 # jump Dynamic Radar Controller Header
231 jumpFp = self.size - 116
231 jumpFp = self.size - 116
232 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
232 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
233 #pointer backward to dynamic header and read
233 #pointer backward to dynamic header and read
234 backFp = fp.tell() - jumpFp
234 backFp = fp.tell() - jumpFp
235 fp.seek(backFp)
235 fp.seek(backFp)
236
236
237 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
237 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
238 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
238 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
239 self.firstHeight = self.samplingWindow['h0']
239 self.firstHeight = self.samplingWindow['h0']
240 self.deltaHeight = self.samplingWindow['dh']
240 self.deltaHeight = self.samplingWindow['dh']
241 self.samplesWin = self.samplingWindow['nsa']
241 self.samplesWin = self.samplingWindow['nsa']
242
242
243 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
243 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
244
244
245 if self.codeType != 0:
245 if self.codeType != 0:
246 self.nCode = int(numpy.fromfile(fp,'<u4',1))
246 self.nCode = int(numpy.fromfile(fp,'<u4',1))
247 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
247 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
248 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
248 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
249 tempList = []
249 tempList = []
250 for ic in range(self.nCode):
250 for ic in range(self.nCode):
251 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
251 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
252 tempList.append(temp)
252 tempList.append(temp)
253 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
253 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
254 self.code = 2.0*self.code - 1.0
254 self.code = 2.0*self.code - 1.0
255
255
256 if self.line5Function == RCfunction.FLIP:
256 if self.line5Function == RCfunction.FLIP:
257 self.flip1 = numpy.fromfile(fp,'<u4',1)
257 self.flip1 = numpy.fromfile(fp,'<u4',1)
258
258
259 if self.line6Function == RCfunction.FLIP:
259 if self.line6Function == RCfunction.FLIP:
260 self.flip2 = numpy.fromfile(fp,'<u4',1)
260 self.flip2 = numpy.fromfile(fp,'<u4',1)
261
261
262 endFp = self.size + startFp
262 endFp = self.size + startFp
263 jumpFp = endFp - fp.tell()
263 jumpFp = endFp - fp.tell()
264 if jumpFp > 0:
264 if jumpFp > 0:
265 fp.seek(jumpFp)
265 fp.seek(jumpFp)
266
266
267 except Exception, e:
267 except Exception, e:
268 print "RadarControllerHeader: " + e
268 print "RadarControllerHeader: " + e
269 return 0
269 return 0
270
270
271 return 1
271 return 1
272
272
273 def write(self, fp):
273 def write(self, fp):
274 headerTuple = (self.size,
274 headerTuple = (self.size,
275 self.expType,
275 self.expType,
276 self.nTx,
276 self.nTx,
277 self.ipp,
277 self.ipp,
278 self.txA,
278 self.txA,
279 self.txB,
279 self.txB,
280 self.nWindows,
280 self.nWindows,
281 self.numTaus,
281 self.numTaus,
282 self.codeType,
282 self.codeType,
283 self.line6Function,
283 self.line6Function,
284 self.line5Function,
284 self.line5Function,
285 self.fClock,
285 self.fClock,
286 self.prePulseBefore,
286 self.prePulseBefore,
287 self.prePulserAfter,
287 self.prePulserAfter,
288 self.rangeIpp,
288 self.rangeIpp,
289 self.rangeTxA,
289 self.rangeTxA,
290 self.rangeTxB)
290 self.rangeTxB)
291
291
292 header = numpy.array(headerTuple,self.struct)
292 header = numpy.array(headerTuple,self.struct)
293 header.tofile(fp)
293 header.tofile(fp)
294
294
295 dynamic = self.dynamic
295 dynamic = self.dynamic
296 dynamic.tofile(fp)
296 dynamic.tofile(fp)
297
297
298 return 1
298 return 1
299
299
300
300
301
301
302 class ProcessingHeader(Header):
302 class ProcessingHeader(Header):
303
303
304 size = None
304 size = None
305 dtype = None
305 dtype = None
306 blockSize = None
306 blockSize = None
307 profilesPerBlock = None
307 profilesPerBlock = None
308 dataBlocksPerFile = None
308 dataBlocksPerFile = None
309 nWindows = None
309 nWindows = None
310 processFlags = None
310 processFlags = None
311 nCohInt = None
311 nCohInt = None
312 nIncohInt = None
312 nIncohInt = None
313 totalSpectra = None
313 totalSpectra = None
314 struct = None
314 struct = None
315 flag_dc = None
315 flag_dc = None
316 flag_cspc = None
316 flag_cspc = None
317
317
318 def __init__(self):
318 def __init__(self):
319 self.size = 0
319 self.size = 0
320 self.dtype = 0
320 self.dtype = 0
321 self.blockSize = 0
321 self.blockSize = 0
322 self.profilesPerBlock = 0
322 self.profilesPerBlock = 0
323 self.dataBlocksPerFile = 0
323 self.dataBlocksPerFile = 0
324 self.nWindows = 0
324 self.nWindows = 0
325 self.processFlags = 0
325 self.processFlags = 0
326 self.nCohInt = 0
326 self.nCohInt = 0
327 self.nIncohInt = 0
327 self.nIncohInt = 0
328 self.totalSpectra = 0
328 self.totalSpectra = 0
329 self.struct = numpy.dtype([
329 self.struct = numpy.dtype([
330 ('nSize','<u4'),
330 ('nSize','<u4'),
331 ('nDataType','<u4'),
331 ('nDataType','<u4'),
332 ('nSizeOfDataBlock','<u4'),
332 ('nSizeOfDataBlock','<u4'),
333 ('nProfilesperBlock','<u4'),
333 ('nProfilesperBlock','<u4'),
334 ('nDataBlocksperFile','<u4'),
334 ('nDataBlocksperFile','<u4'),
335 ('nNumWindows','<u4'),
335 ('nNumWindows','<u4'),
336 ('nProcessFlags','<u4'),
336 ('nProcessFlags','<u4'),
337 ('nCoherentIntegrations','<u4'),
337 ('nCoherentIntegrations','<u4'),
338 ('nIncoherentIntegrations','<u4'),
338 ('nIncoherentIntegrations','<u4'),
339 ('nTotalSpectra','<u4')
339 ('nTotalSpectra','<u4')
340 ])
340 ])
341 self.samplingWindow = 0
341 self.samplingWindow = 0
342 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
342 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
343 self.nHeights = 0
343 self.nHeights = 0
344 self.firstHeight = 0
344 self.firstHeight = 0
345 self.deltaHeight = 0
345 self.deltaHeight = 0
346 self.samplesWin = 0
346 self.samplesWin = 0
347 self.spectraComb = 0
347 self.spectraComb = 0
348 self.nCode = None
348 self.nCode = None
349 self.code = None
349 self.code = None
350 self.nBaud = None
350 self.nBaud = None
351 self.shif_fft = False
351 self.shif_fft = False
352 self.flag_dc = False
352 self.flag_dc = False
353 self.flag_cspc = False
353 self.flag_cspc = False
354
354
355 def read(self, fp):
355 def read(self, fp):
356 try:
356 try:
357 header = numpy.fromfile(fp,self.struct,1)
357 header = numpy.fromfile(fp,self.struct,1)
358 self.size = int(header['nSize'][0])
358 self.size = int(header['nSize'][0])
359 self.dtype = int(header['nDataType'][0])
359 self.dtype = int(header['nDataType'][0])
360 self.blockSize = int(header['nSizeOfDataBlock'][0])
360 self.blockSize = int(header['nSizeOfDataBlock'][0])
361 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
361 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
362 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
362 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
363 self.nWindows = int(header['nNumWindows'][0])
363 self.nWindows = int(header['nNumWindows'][0])
364 self.processFlags = int(header['nProcessFlags'])
364 self.processFlags = int(header['nProcessFlags'])
365 self.nCohInt = int(header['nCoherentIntegrations'][0])
365 self.nCohInt = int(header['nCoherentIntegrations'][0])
366 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
366 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
367 self.totalSpectra = int(header['nTotalSpectra'][0])
367 self.totalSpectra = int(header['nTotalSpectra'][0])
368 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
368 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
369 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
369 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
370 self.firstHeight = int(self.samplingWindow['h0'][0])
370 self.firstHeight = float(self.samplingWindow['h0'][0])
371 self.deltaHeight = int(self.samplingWindow['dh'][0])
371 self.deltaHeight = float(self.samplingWindow['dh'][0])
372 self.samplesWin = self.samplingWindow['nsa']
372 self.samplesWin = self.samplingWindow['nsa']
373 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
373 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
374
374
375 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
375 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
376 self.nCode = int(numpy.fromfile(fp,'<u4',1))
376 self.nCode = int(numpy.fromfile(fp,'<u4',1))
377 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
377 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
378 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
378 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
379
379
380 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
380 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
381 self.shif_fft = True
381 self.shif_fft = True
382 else:
382 else:
383 self.shif_fft = False
383 self.shif_fft = False
384
384
385 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
385 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
386 self.flag_dc = True
386 self.flag_dc = True
387
387
388 nChannels = 0
388 nChannels = 0
389 nPairs = 0
389 nPairs = 0
390 pairList = []
390 pairList = []
391
391
392 for i in range( 0, self.totalSpectra*2, 2 ):
392 for i in range( 0, self.totalSpectra*2, 2 ):
393 if self.spectraComb[i] == self.spectraComb[i+1]:
393 if self.spectraComb[i] == self.spectraComb[i+1]:
394 nChannels = nChannels + 1 #par de canales iguales
394 nChannels = nChannels + 1 #par de canales iguales
395 else:
395 else:
396 nPairs = nPairs + 1 #par de canales diferentes
396 nPairs = nPairs + 1 #par de canales diferentes
397 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
397 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
398
398
399 self.flag_cspc = False
399 self.flag_cspc = False
400 if nPairs > 0:
400 if nPairs > 0:
401 self.flag_cspc = True
401 self.flag_cspc = True
402
402
403 except Exception, e:
403 except Exception, e:
404 print "ProcessingHeader: " + e
404 print "ProcessingHeader: " + e
405 return 0
405 return 0
406
406
407 return 1
407 return 1
408
408
409 def write(self, fp):
409 def write(self, fp):
410 headerTuple = (self.size,
410 headerTuple = (self.size,
411 self.dtype,
411 self.dtype,
412 self.blockSize,
412 self.blockSize,
413 self.profilesPerBlock,
413 self.profilesPerBlock,
414 self.dataBlocksPerFile,
414 self.dataBlocksPerFile,
415 self.nWindows,
415 self.nWindows,
416 self.processFlags,
416 self.processFlags,
417 self.nCohInt,
417 self.nCohInt,
418 self.nIncohInt,
418 self.nIncohInt,
419 self.totalSpectra)
419 self.totalSpectra)
420
420
421 header = numpy.array(headerTuple,self.struct)
421 header = numpy.array(headerTuple,self.struct)
422 header.tofile(fp)
422 header.tofile(fp)
423
423
424 if self.nWindows != 0:
424 if self.nWindows != 0:
425 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
425 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
426 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
426 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
427 samplingWindow.tofile(fp)
427 samplingWindow.tofile(fp)
428
428
429
429
430 if self.totalSpectra != 0:
430 if self.totalSpectra != 0:
431 spectraComb = numpy.array([],numpy.dtype('u1'))
431 spectraComb = numpy.array([],numpy.dtype('u1'))
432 spectraComb = self.spectraComb
432 spectraComb = self.spectraComb
433 spectraComb.tofile(fp)
433 spectraComb.tofile(fp)
434
434
435
435
436 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
436 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
437 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
437 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
438 nCode.tofile(fp)
438 nCode.tofile(fp)
439
439
440 nBaud = self.nBaud
440 nBaud = self.nBaud
441 nBaud.tofile(fp)
441 nBaud.tofile(fp)
442
442
443 code = self.code.reshape(nCode*nBaud)
443 code = self.code.reshape(nCode*nBaud)
444 code.tofile(fp)
444 code.tofile(fp)
445
445
446 return 1
446 return 1
447
447
448 class RCfunction:
448 class RCfunction:
449 NONE=0
449 NONE=0
450 FLIP=1
450 FLIP=1
451 CODE=2
451 CODE=2
452 SAMPLING=3
452 SAMPLING=3
453 LIN6DIV256=4
453 LIN6DIV256=4
454 SYNCHRO=5
454 SYNCHRO=5
455
455
456 class nCodeType:
456 class nCodeType:
457 NONE=0
457 NONE=0
458 USERDEFINE=1
458 USERDEFINE=1
459 BARKER2=2
459 BARKER2=2
460 BARKER3=3
460 BARKER3=3
461 BARKER4=4
461 BARKER4=4
462 BARKER5=5
462 BARKER5=5
463 BARKER7=6
463 BARKER7=6
464 BARKER11=7
464 BARKER11=7
465 BARKER13=8
465 BARKER13=8
466 AC128=9
466 AC128=9
467 COMPLEMENTARYCODE2=10
467 COMPLEMENTARYCODE2=10
468 COMPLEMENTARYCODE4=11
468 COMPLEMENTARYCODE4=11
469 COMPLEMENTARYCODE8=12
469 COMPLEMENTARYCODE8=12
470 COMPLEMENTARYCODE16=13
470 COMPLEMENTARYCODE16=13
471 COMPLEMENTARYCODE32=14
471 COMPLEMENTARYCODE32=14
472 COMPLEMENTARYCODE64=15
472 COMPLEMENTARYCODE64=15
473 COMPLEMENTARYCODE128=16
473 COMPLEMENTARYCODE128=16
474 CODE_BINARY28=17
474 CODE_BINARY28=17
475
475
476 class PROCFLAG:
476 class PROCFLAG:
477 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
477 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
478 DECODE_DATA = numpy.uint32(0x00000002)
478 DECODE_DATA = numpy.uint32(0x00000002)
479 SPECTRA_CALC = numpy.uint32(0x00000004)
479 SPECTRA_CALC = numpy.uint32(0x00000004)
480 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
480 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
481 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
481 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
482 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
482 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
483
483
484 DATATYPE_CHAR = numpy.uint32(0x00000040)
484 DATATYPE_CHAR = numpy.uint32(0x00000040)
485 DATATYPE_SHORT = numpy.uint32(0x00000080)
485 DATATYPE_SHORT = numpy.uint32(0x00000080)
486 DATATYPE_LONG = numpy.uint32(0x00000100)
486 DATATYPE_LONG = numpy.uint32(0x00000100)
487 DATATYPE_INT64 = numpy.uint32(0x00000200)
487 DATATYPE_INT64 = numpy.uint32(0x00000200)
488 DATATYPE_FLOAT = numpy.uint32(0x00000400)
488 DATATYPE_FLOAT = numpy.uint32(0x00000400)
489 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
489 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
490
490
491 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
491 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
492 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
492 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
493 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
493 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
494
494
495 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
495 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
496 DEFLIP_DATA = numpy.uint32(0x00010000)
496 DEFLIP_DATA = numpy.uint32(0x00010000)
497 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
497 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
498
498
499 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
499 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
500 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
500 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
501 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
501 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
502 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
502 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
503 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
503 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
504
504
505 EXP_NAME_ESP = numpy.uint32(0x00200000)
505 EXP_NAME_ESP = numpy.uint32(0x00200000)
506 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
506 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
507
507
508 OPERATION_MASK = numpy.uint32(0x0000003F)
508 OPERATION_MASK = numpy.uint32(0x0000003F)
509 DATATYPE_MASK = numpy.uint32(0x00000FC0)
509 DATATYPE_MASK = numpy.uint32(0x00000FC0)
510 DATAARRANGE_MASK = numpy.uint32(0x00007000)
510 DATAARRANGE_MASK = numpy.uint32(0x00007000)
511 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
511 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
@@ -1,903 +1,985
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):
271 """
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
273 minHei <= height <= maxHei
274
275 Input:
276 minHei : valor minimo de altura a considerar
277 maxHei : valor maximo de altura a considerar
278
279 Affected:
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
281
282 Return:
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
284 """
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
287
288 if (maxHei > self.dataOut.heightList[-1]):
289 maxHei = self.dataOut.heightList[-1]
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
291
292 minIndex = 0
293 maxIndex = 0
294 data = self.dataOut.heightList
295
296 for i,val in enumerate(data):
297 if val < minHei:
298 continue
299 else:
300 minIndex = i;
301 break
302
303 for i,val in enumerate(data):
304 if val <= maxHei:
305 maxIndex = i;
306 else:
307 break
308
309 self.selectHeightsByIndex(minIndex, maxIndex)
310
311 return 1
312
313
314 def selectHeightsByIndex(self, minIndex, maxIndex):
315 """
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
317 minIndex <= index <= maxIndex
318
319 Input:
320 minIndex : valor de indice minimo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
322
323 Affected:
324 self.dataOut.data
325 self.dataOut.heightList
326
327 Return:
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
329 """
330
331 if (minIndex < 0) or (minIndex > maxIndex):
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
333
334 if (maxIndex >= self.dataOut.nHeights):
335 maxIndex = self.dataOut.nHeights-1
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
337
338 nHeights = maxIndex - minIndex + 1
339
340 #voltage
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
342
343 firstHeight = self.dataOut.heightList[minIndex]
344
345 self.dataOut.data = data
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
347
348 return 1
349
350
270 class CohInt(Operation):
351 class CohInt(Operation):
271
352
272 __profIndex = 0
353 __profIndex = 0
273 __withOverapping = False
354 __withOverapping = False
274
355
275 __byTime = False
356 __byTime = False
276 __initime = None
357 __initime = None
277 __lastdatatime = None
358 __lastdatatime = None
278 __integrationtime = None
359 __integrationtime = None
279
360
280 __buffer = None
361 __buffer = None
281
362
282 __dataReady = False
363 __dataReady = False
283
364
284 n = None
365 n = None
285
366
286
367
287 def __init__(self):
368 def __init__(self):
288
369
289 self.__isConfig = False
370 self.__isConfig = False
290
371
291 def setup(self, n=None, timeInterval=None, overlapping=False):
372 def setup(self, n=None, timeInterval=None, overlapping=False):
292 """
373 """
293 Set the parameters of the integration class.
374 Set the parameters of the integration class.
294
375
295 Inputs:
376 Inputs:
296
377
297 n : Number of coherent integrations
378 n : Number of coherent integrations
298 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
299 overlapping :
380 overlapping :
300
381
301 """
382 """
302
383
303 self.__initime = None
384 self.__initime = None
304 self.__lastdatatime = 0
385 self.__lastdatatime = 0
305 self.__buffer = None
386 self.__buffer = None
306 self.__dataReady = False
387 self.__dataReady = False
307
388
308
389
309 if n == None and timeInterval == None:
390 if n == None and timeInterval == None:
310 raise ValueError, "n or timeInterval should be specified ..."
391 raise ValueError, "n or timeInterval should be specified ..."
311
392
312 if n != None:
393 if n != None:
313 self.n = n
394 self.n = n
314 self.__byTime = False
395 self.__byTime = False
315 else:
396 else:
316 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
397 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
317 self.n = 9999
398 self.n = 9999
318 self.__byTime = True
399 self.__byTime = True
319
400
320 if overlapping:
401 if overlapping:
321 self.__withOverapping = True
402 self.__withOverapping = True
322 self.__buffer = None
403 self.__buffer = None
323 else:
404 else:
324 self.__withOverapping = False
405 self.__withOverapping = False
325 self.__buffer = 0
406 self.__buffer = 0
326
407
327 self.__profIndex = 0
408 self.__profIndex = 0
328
409
329 def putData(self, data):
410 def putData(self, data):
330
411
331 """
412 """
332 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
333
414
334 """
415 """
335
416
336 if not self.__withOverapping:
417 if not self.__withOverapping:
337 self.__buffer += data.copy()
418 self.__buffer += data.copy()
338 self.__profIndex += 1
419 self.__profIndex += 1
339 return
420 return
340
421
341 #Overlapping data
422 #Overlapping data
342 nChannels, nHeis = data.shape
423 nChannels, nHeis = data.shape
343 data = numpy.reshape(data, (1, nChannels, nHeis))
424 data = numpy.reshape(data, (1, nChannels, nHeis))
344
425
345 #If the buffer is empty then it takes the data value
426 #If the buffer is empty then it takes the data value
346 if self.__buffer == None:
427 if self.__buffer == None:
347 self.__buffer = data
428 self.__buffer = data
348 self.__profIndex += 1
429 self.__profIndex += 1
349 return
430 return
350
431
351 #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
352 if self.__profIndex < self.n:
433 if self.__profIndex < self.n:
353 self.__buffer = numpy.vstack((self.__buffer, data))
434 self.__buffer = numpy.vstack((self.__buffer, data))
354 self.__profIndex += 1
435 self.__profIndex += 1
355 return
436 return
356
437
357 #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
358 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
439 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
359 self.__buffer[self.n-1] = data
440 self.__buffer[self.n-1] = data
360 self.__profIndex = self.n
441 self.__profIndex = self.n
361 return
442 return
362
443
363
444
364 def pushData(self):
445 def pushData(self):
365 """
446 """
366 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.
367
448
368 Affected:
449 Affected:
369
450
370 self.__profileIndex
451 self.__profileIndex
371
452
372 """
453 """
373
454
374 if not self.__withOverapping:
455 if not self.__withOverapping:
375 data = self.__buffer
456 data = self.__buffer
376 n = self.__profIndex
457 n = self.__profIndex
377
458
378 self.__buffer = 0
459 self.__buffer = 0
379 self.__profIndex = 0
460 self.__profIndex = 0
380
461
381 return data, n
462 return data, n
382
463
383 #Integration with Overlapping
464 #Integration with Overlapping
384 data = numpy.sum(self.__buffer, axis=0)
465 data = numpy.sum(self.__buffer, axis=0)
385 n = self.__profIndex
466 n = self.__profIndex
386
467
387 return data, n
468 return data, n
388
469
389 def byProfiles(self, data):
470 def byProfiles(self, data):
390
471
391 self.__dataReady = False
472 self.__dataReady = False
392 avgdata = None
473 avgdata = None
393 n = None
474 n = None
394
475
395 self.putData(data)
476 self.putData(data)
396
477
397 if self.__profIndex == self.n:
478 if self.__profIndex == self.n:
398
479
399 avgdata, n = self.pushData()
480 avgdata, n = self.pushData()
400 self.__dataReady = True
481 self.__dataReady = True
401
482
402 return avgdata
483 return avgdata
403
484
404 def byTime(self, data, datatime):
485 def byTime(self, data, datatime):
405
486
406 self.__dataReady = False
487 self.__dataReady = False
407 avgdata = None
488 avgdata = None
408 n = None
489 n = None
409
490
410 self.putData(data)
491 self.putData(data)
411
492
412 if (datatime - self.__initime) >= self.__integrationtime:
493 if (datatime - self.__initime) >= self.__integrationtime:
413 avgdata, n = self.pushData()
494 avgdata, n = self.pushData()
414 self.n = n
495 self.n = n
415 self.__dataReady = True
496 self.__dataReady = True
416
497
417 return avgdata
498 return avgdata
418
499
419 def integrate(self, data, datatime=None):
500 def integrate(self, data, datatime=None):
420
501
421 if self.__initime == None:
502 if self.__initime == None:
422 self.__initime = datatime
503 self.__initime = datatime
423
504
424 if self.__byTime:
505 if self.__byTime:
425 avgdata = self.byTime(data, datatime)
506 avgdata = self.byTime(data, datatime)
426 else:
507 else:
427 avgdata = self.byProfiles(data)
508 avgdata = self.byProfiles(data)
428
509
429
510
430 self.__lastdatatime = datatime
511 self.__lastdatatime = datatime
431
512
432 if avgdata == None:
513 if avgdata == None:
433 return None, None
514 return None, None
434
515
435 avgdatatime = self.__initime
516 avgdatatime = self.__initime
436
517
437 deltatime = datatime -self.__lastdatatime
518 deltatime = datatime -self.__lastdatatime
438
519
439 if not self.__withOverapping:
520 if not self.__withOverapping:
440 self.__initime = datatime
521 self.__initime = datatime
441 else:
522 else:
442 self.__initime += deltatime
523 self.__initime += deltatime
443
524
444 return avgdata, avgdatatime
525 return avgdata, avgdatatime
445
526
446 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
527 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
447
528
448 if not self.__isConfig:
529 if not self.__isConfig:
449 self.setup(n, timeInterval, overlapping)
530 self.setup(n, timeInterval, overlapping)
450 self.__isConfig = True
531 self.__isConfig = True
451
532
452 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
533 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
453
534
454 # dataOut.timeInterval *= n
535 # dataOut.timeInterval *= n
455 dataOut.flagNoData = True
536 dataOut.flagNoData = True
456
537
457 if self.__dataReady:
538 if self.__dataReady:
458 dataOut.data = avgdata
539 dataOut.data = avgdata
459 dataOut.nCohInt *= self.n
540 dataOut.nCohInt *= self.n
460 dataOut.utctime = avgdatatime
541 dataOut.utctime = avgdatatime
461 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
542 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
462 dataOut.flagNoData = False
543 dataOut.flagNoData = False
463
544
464
545
465 class SpectraProc(ProcessingUnit):
546 class SpectraProc(ProcessingUnit):
466
547
467 def __init__(self):
548 def __init__(self):
468
549
469 self.objectDict = {}
550 self.objectDict = {}
470 self.buffer = None
551 self.buffer = None
471 self.firstdatatime = None
552 self.firstdatatime = None
472 self.profIndex = 0
553 self.profIndex = 0
473 self.dataOut = Spectra()
554 self.dataOut = Spectra()
474
555
475 def __updateObjFromInput(self):
556 def __updateObjFromInput(self):
476
557
477 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
558 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
478 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
559 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
479 self.dataOut.channelList = self.dataIn.channelList
560 self.dataOut.channelList = self.dataIn.channelList
480 self.dataOut.heightList = self.dataIn.heightList
561 self.dataOut.heightList = self.dataIn.heightList
481 self.dataOut.dtype = self.dataIn.dtype
562 self.dataOut.dtype = self.dataIn.dtype
482 # self.dataOut.nHeights = self.dataIn.nHeights
563 # self.dataOut.nHeights = self.dataIn.nHeights
483 # self.dataOut.nChannels = self.dataIn.nChannels
564 # self.dataOut.nChannels = self.dataIn.nChannels
484 self.dataOut.nBaud = self.dataIn.nBaud
565 self.dataOut.nBaud = self.dataIn.nBaud
485 self.dataOut.nCode = self.dataIn.nCode
566 self.dataOut.nCode = self.dataIn.nCode
486 self.dataOut.code = self.dataIn.code
567 self.dataOut.code = self.dataIn.code
487 self.dataOut.nProfiles = self.dataOut.nFFTPoints
568 self.dataOut.nProfiles = self.dataOut.nFFTPoints
488 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
569 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
489 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
570 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
490 self.dataOut.utctime = self.firstdatatime
571 self.dataOut.utctime = self.firstdatatime
491 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
492 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
493 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
574 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
494 self.dataOut.nCohInt = self.dataIn.nCohInt
575 self.dataOut.nCohInt = self.dataIn.nCohInt
495 self.dataOut.nIncohInt = 1
576 self.dataOut.nIncohInt = 1
496 self.dataOut.ippSeconds = self.dataIn.ippSeconds
577 self.dataOut.ippSeconds = self.dataIn.ippSeconds
497 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nConInt*self.dataOut.nIncohInt
578
579 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nCohInt*self.dataOut.nIncohInt
498
580
499 def __getFft(self):
581 def __getFft(self):
500 """
582 """
501 Convierte valores de Voltaje a Spectra
583 Convierte valores de Voltaje a Spectra
502
584
503 Affected:
585 Affected:
504 self.dataOut.data_spc
586 self.dataOut.data_spc
505 self.dataOut.data_cspc
587 self.dataOut.data_cspc
506 self.dataOut.data_dc
588 self.dataOut.data_dc
507 self.dataOut.heightList
589 self.dataOut.heightList
508 self.dataOut.m_BasicHeader
590 self.dataOut.m_BasicHeader
509 self.dataOut.m_ProcessingHeader
591 self.dataOut.m_ProcessingHeader
510 self.dataOut.radarControllerHeaderObj
592 self.dataOut.radarControllerHeaderObj
511 self.dataOut.systemHeaderObj
593 self.dataOut.systemHeaderObj
512 self.profIndex
594 self.profIndex
513 self.buffer
595 self.buffer
514 self.dataOut.flagNoData
596 self.dataOut.flagNoData
515 self.dataOut.dtype
597 self.dataOut.dtype
516 self.dataOut.nPairs
598 self.dataOut.nPairs
517 self.dataOut.nChannels
599 self.dataOut.nChannels
518 self.dataOut.nProfiles
600 self.dataOut.nProfiles
519 self.dataOut.systemHeaderObj.numChannels
601 self.dataOut.systemHeaderObj.numChannels
520 self.dataOut.m_ProcessingHeader.totalSpectra
602 self.dataOut.m_ProcessingHeader.totalSpectra
521 self.dataOut.m_ProcessingHeader.profilesPerBlock
603 self.dataOut.m_ProcessingHeader.profilesPerBlock
522 self.dataOut.m_ProcessingHeader.numHeights
604 self.dataOut.m_ProcessingHeader.numHeights
523 self.dataOut.m_ProcessingHeader.spectraComb
605 self.dataOut.m_ProcessingHeader.spectraComb
524 self.dataOut.m_ProcessingHeader.shif_fft
606 self.dataOut.m_ProcessingHeader.shif_fft
525 """
607 """
526 fft_volt = numpy.fft.fft(self.buffer,axis=1)
608 fft_volt = numpy.fft.fft(self.buffer,axis=1)
527 dc = fft_volt[:,0,:]
609 dc = fft_volt[:,0,:]
528
610
529 #calculo de self-spectra
611 #calculo de self-spectra
530 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
612 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
531 spc = fft_volt * numpy.conjugate(fft_volt)
613 spc = fft_volt * numpy.conjugate(fft_volt)
532 spc = spc.real
614 spc = spc.real
533
615
534 blocksize = 0
616 blocksize = 0
535 blocksize += dc.size
617 blocksize += dc.size
536 blocksize += spc.size
618 blocksize += spc.size
537
619
538 cspc = None
620 cspc = None
539 pairIndex = 0
621 pairIndex = 0
540 if self.dataOut.pairsList != None:
622 if self.dataOut.pairsList != None:
541 #calculo de cross-spectra
623 #calculo de cross-spectra
542 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
624 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
543 for pair in self.dataOut.pairsList:
625 for pair in self.dataOut.pairsList:
544 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
626 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
545 pairIndex += 1
627 pairIndex += 1
546 blocksize += cspc.size
628 blocksize += cspc.size
547
629
548 self.dataOut.data_spc = spc
630 self.dataOut.data_spc = spc
549 self.dataOut.data_cspc = cspc
631 self.dataOut.data_cspc = cspc
550 self.dataOut.data_dc = dc
632 self.dataOut.data_dc = dc
551 self.dataOut.blockSize = blocksize
633 self.dataOut.blockSize = blocksize
552
634
553 def init(self, nFFTPoints=None, pairsList=None):
635 def init(self, nFFTPoints=None, pairsList=None):
554
636
555 if self.dataIn.type == "Spectra":
637 if self.dataIn.type == "Spectra":
556 self.dataOut.copy(self.dataIn)
638 self.dataOut.copy(self.dataIn)
557 return
639 return
558
640
559 if self.dataIn.type == "Voltage":
641 if self.dataIn.type == "Voltage":
560
642
561 if nFFTPoints == None:
643 if nFFTPoints == None:
562 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
644 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
563
645
564 if pairsList == None:
646 if pairsList == None:
565 nPairs = 0
647 nPairs = 0
566 else:
648 else:
567 nPairs = len(pairsList)
649 nPairs = len(pairsList)
568
650
569 self.dataOut.nFFTPoints = nFFTPoints
651 self.dataOut.nFFTPoints = nFFTPoints
570 self.dataOut.pairsList = pairsList
652 self.dataOut.pairsList = pairsList
571 self.dataOut.nPairs = nPairs
653 self.dataOut.nPairs = nPairs
572
654
573 if self.buffer == None:
655 if self.buffer == None:
574 self.buffer = numpy.zeros((self.dataIn.nChannels,
656 self.buffer = numpy.zeros((self.dataIn.nChannels,
575 self.dataOut.nFFTPoints,
657 self.dataOut.nFFTPoints,
576 self.dataIn.nHeights),
658 self.dataIn.nHeights),
577 dtype='complex')
659 dtype='complex')
578
660
579
661
580 self.buffer[:,self.profIndex,:] = self.dataIn.data
662 self.buffer[:,self.profIndex,:] = self.dataIn.data
581 self.profIndex += 1
663 self.profIndex += 1
582
664
583 if self.firstdatatime == None:
665 if self.firstdatatime == None:
584 self.firstdatatime = self.dataIn.utctime
666 self.firstdatatime = self.dataIn.utctime
585
667
586 if self.profIndex == self.dataOut.nFFTPoints:
668 if self.profIndex == self.dataOut.nFFTPoints:
587 self.__updateObjFromInput()
669 self.__updateObjFromInput()
588 self.__getFft()
670 self.__getFft()
589
671
590 self.dataOut.flagNoData = False
672 self.dataOut.flagNoData = False
591
673
592 self.buffer = None
674 self.buffer = None
593 self.firstdatatime = None
675 self.firstdatatime = None
594 self.profIndex = 0
676 self.profIndex = 0
595
677
596 return
678 return
597
679
598 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
680 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
599
681
600 def selectChannels(self, channelList):
682 def selectChannels(self, channelList):
601
683
602 channelIndexList = []
684 channelIndexList = []
603
685
604 for channel in channelList:
686 for channel in channelList:
605 index = self.dataOut.channelList.index(channel)
687 index = self.dataOut.channelList.index(channel)
606 channelIndexList.append(index)
688 channelIndexList.append(index)
607
689
608 self.selectChannelsByIndex(channelIndexList)
690 self.selectChannelsByIndex(channelIndexList)
609
691
610 def selectChannelsByIndex(self, channelIndexList):
692 def selectChannelsByIndex(self, channelIndexList):
611 """
693 """
612 Selecciona un bloque de datos en base a canales segun el channelIndexList
694 Selecciona un bloque de datos en base a canales segun el channelIndexList
613
695
614 Input:
696 Input:
615 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
697 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
616
698
617 Affected:
699 Affected:
618 self.dataOut.data_spc
700 self.dataOut.data_spc
619 self.dataOut.channelIndexList
701 self.dataOut.channelIndexList
620 self.dataOut.nChannels
702 self.dataOut.nChannels
621
703
622 Return:
704 Return:
623 None
705 None
624 """
706 """
625
707
626 for channelIndex in channelIndexList:
708 for channelIndex in channelIndexList:
627 if channelIndex not in self.dataOut.channelIndexList:
709 if channelIndex not in self.dataOut.channelIndexList:
628 print channelIndexList
710 print channelIndexList
629 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
711 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
630
712
631 nChannels = len(channelIndexList)
713 nChannels = len(channelIndexList)
632
714
633 data_spc = self.dataOut.data_spc[channelIndexList,:]
715 data_spc = self.dataOut.data_spc[channelIndexList,:]
634
716
635 self.dataOut.data_spc = data_spc
717 self.dataOut.data_spc = data_spc
636 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
718 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
637 # self.dataOut.nChannels = nChannels
719 # self.dataOut.nChannels = nChannels
638
720
639 return 1
721 return 1
640
722
641
723
642 class IncohInt(Operation):
724 class IncohInt(Operation):
643
725
644
726
645 __profIndex = 0
727 __profIndex = 0
646 __withOverapping = False
728 __withOverapping = False
647
729
648 __byTime = False
730 __byTime = False
649 __initime = None
731 __initime = None
650 __lastdatatime = None
732 __lastdatatime = None
651 __integrationtime = None
733 __integrationtime = None
652
734
653 __buffer_spc = None
735 __buffer_spc = None
654 __buffer_cspc = None
736 __buffer_cspc = None
655 __buffer_dc = None
737 __buffer_dc = None
656
738
657 __dataReady = False
739 __dataReady = False
658
740
659 n = None
741 n = None
660
742
661
743
662 def __init__(self):
744 def __init__(self):
663
745
664 self.__isConfig = False
746 self.__isConfig = False
665
747
666 def setup(self, n=None, timeInterval=None, overlapping=False):
748 def setup(self, n=None, timeInterval=None, overlapping=False):
667 """
749 """
668 Set the parameters of the integration class.
750 Set the parameters of the integration class.
669
751
670 Inputs:
752 Inputs:
671
753
672 n : Number of coherent integrations
754 n : Number of coherent integrations
673 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
755 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
674 overlapping :
756 overlapping :
675
757
676 """
758 """
677
759
678 self.__initime = None
760 self.__initime = None
679 self.__lastdatatime = 0
761 self.__lastdatatime = 0
680 self.__buffer_spc = None
762 self.__buffer_spc = None
681 self.__buffer_cspc = None
763 self.__buffer_cspc = None
682 self.__buffer_dc = None
764 self.__buffer_dc = None
683 self.__dataReady = False
765 self.__dataReady = False
684
766
685
767
686 if n == None and timeInterval == None:
768 if n == None and timeInterval == None:
687 raise ValueError, "n or timeInterval should be specified ..."
769 raise ValueError, "n or timeInterval should be specified ..."
688
770
689 if n != None:
771 if n != None:
690 self.n = n
772 self.n = n
691 self.__byTime = False
773 self.__byTime = False
692 else:
774 else:
693 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
775 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
694 self.n = 9999
776 self.n = 9999
695 self.__byTime = True
777 self.__byTime = True
696
778
697 if overlapping:
779 if overlapping:
698 self.__withOverapping = True
780 self.__withOverapping = True
699 else:
781 else:
700 self.__withOverapping = False
782 self.__withOverapping = False
701 self.__buffer_spc = 0
783 self.__buffer_spc = 0
702 self.__buffer_cspc = 0
784 self.__buffer_cspc = 0
703 self.__buffer_dc = 0
785 self.__buffer_dc = 0
704
786
705 self.__profIndex = 0
787 self.__profIndex = 0
706
788
707 def putData(self, data_spc, data_cspc, data_dc):
789 def putData(self, data_spc, data_cspc, data_dc):
708
790
709 """
791 """
710 Add a profile to the __buffer_spc and increase in one the __profileIndex
792 Add a profile to the __buffer_spc and increase in one the __profileIndex
711
793
712 """
794 """
713
795
714 if not self.__withOverapping:
796 if not self.__withOverapping:
715 self.__buffer_spc += data_spc
797 self.__buffer_spc += data_spc
716
798
717 if data_cspc == None:
799 if data_cspc == None:
718 self.__buffer_cspc = None
800 self.__buffer_cspc = None
719 else:
801 else:
720 self.__buffer_cspc += data_cspc
802 self.__buffer_cspc += data_cspc
721
803
722 if data_dc == None:
804 if data_dc == None:
723 self.__buffer_dc = None
805 self.__buffer_dc = None
724 else:
806 else:
725 self.__buffer_dc += data_dc
807 self.__buffer_dc += data_dc
726
808
727 self.__profIndex += 1
809 self.__profIndex += 1
728 return
810 return
729
811
730 #Overlapping data
812 #Overlapping data
731 nChannels, nFFTPoints, nHeis = data_spc.shape
813 nChannels, nFFTPoints, nHeis = data_spc.shape
732 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
814 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
733 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
815 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
734 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
816 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
735
817
736 #If the buffer is empty then it takes the data value
818 #If the buffer is empty then it takes the data value
737 if self.__buffer_spc == None:
819 if self.__buffer_spc == None:
738 self.__buffer_spc = data_spc.copy()
820 self.__buffer_spc = data_spc.copy()
739
821
740 if data_cspc == None:
822 if data_cspc == None:
741 self.__buffer_cspc = None
823 self.__buffer_cspc = None
742 else:
824 else:
743 self.__buffer_cspc += data_cspc.copy()
825 self.__buffer_cspc += data_cspc.copy()
744
826
745 if data_dc == None:
827 if data_dc == None:
746 self.__buffer_dc = None
828 self.__buffer_dc = None
747 else:
829 else:
748 self.__buffer_dc += data_dc.copy()
830 self.__buffer_dc += data_dc.copy()
749
831
750 self.__profIndex += 1
832 self.__profIndex += 1
751 return
833 return
752
834
753 #If the buffer length is lower than n then stakcing the data value
835 #If the buffer length is lower than n then stakcing the data value
754 if self.__profIndex < self.n:
836 if self.__profIndex < self.n:
755 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
837 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
756
838
757 if self.__buffer_cspc != None:
839 if self.__buffer_cspc != None:
758 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
840 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
759
841
760 if self.__buffer_dc != None:
842 if self.__buffer_dc != None:
761 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
843 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
762
844
763 self.__profIndex += 1
845 self.__profIndex += 1
764 return
846 return
765
847
766 #If the buffer length is equal to n then replacing the last buffer value with the data value
848 #If the buffer length is equal to n then replacing the last buffer value with the data value
767 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
849 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
768 self.__buffer_spc[self.n-1] = data_spc
850 self.__buffer_spc[self.n-1] = data_spc
769
851
770 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
852 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
771 self.__buffer_cspc[self.n-1] = data_cspc
853 self.__buffer_cspc[self.n-1] = data_cspc
772
854
773 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
855 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
774 self.__buffer_dc[self.n-1] = data_dc
856 self.__buffer_dc[self.n-1] = data_dc
775
857
776 self.__profIndex = self.n
858 self.__profIndex = self.n
777 return
859 return
778
860
779
861
780 def pushData(self):
862 def pushData(self):
781 """
863 """
782 Return the sum of the last profiles and the profiles used in the sum.
864 Return the sum of the last profiles and the profiles used in the sum.
783
865
784 Affected:
866 Affected:
785
867
786 self.__profileIndex
868 self.__profileIndex
787
869
788 """
870 """
789 data_spc = None
871 data_spc = None
790 data_cspc = None
872 data_cspc = None
791 data_dc = None
873 data_dc = None
792
874
793 if not self.__withOverapping:
875 if not self.__withOverapping:
794 data_spc = self.__buffer_spc
876 data_spc = self.__buffer_spc
795 data_cspc = self.__buffer_cspc
877 data_cspc = self.__buffer_cspc
796 data_dc = self.__buffer_dc
878 data_dc = self.__buffer_dc
797
879
798 n = self.__profIndex
880 n = self.__profIndex
799
881
800 self.__buffer_spc = 0
882 self.__buffer_spc = 0
801 self.__buffer_cspc = 0
883 self.__buffer_cspc = 0
802 self.__buffer_dc = 0
884 self.__buffer_dc = 0
803 self.__profIndex = 0
885 self.__profIndex = 0
804
886
805 return data_spc, data_cspc, data_dc, n
887 return data_spc, data_cspc, data_dc, n
806
888
807 #Integration with Overlapping
889 #Integration with Overlapping
808 data_spc = numpy.sum(self.__buffer_spc, axis=0)
890 data_spc = numpy.sum(self.__buffer_spc, axis=0)
809
891
810 if self.__buffer_cspc != None:
892 if self.__buffer_cspc != None:
811 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
893 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
812
894
813 if self.__buffer_dc != None:
895 if self.__buffer_dc != None:
814 data_dc = numpy.sum(self.__buffer_dc, axis=0)
896 data_dc = numpy.sum(self.__buffer_dc, axis=0)
815
897
816 n = self.__profIndex
898 n = self.__profIndex
817
899
818 return data_spc, data_cspc, data_dc, n
900 return data_spc, data_cspc, data_dc, n
819
901
820 def byProfiles(self, *args):
902 def byProfiles(self, *args):
821
903
822 self.__dataReady = False
904 self.__dataReady = False
823 avgdata_spc = None
905 avgdata_spc = None
824 avgdata_cspc = None
906 avgdata_cspc = None
825 avgdata_dc = None
907 avgdata_dc = None
826 n = None
908 n = None
827
909
828 self.putData(*args)
910 self.putData(*args)
829
911
830 if self.__profIndex == self.n:
912 if self.__profIndex == self.n:
831
913
832 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
914 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
833 self.__dataReady = True
915 self.__dataReady = True
834
916
835 return avgdata_spc, avgdata_cspc, avgdata_dc
917 return avgdata_spc, avgdata_cspc, avgdata_dc
836
918
837 def byTime(self, datatime, *args):
919 def byTime(self, datatime, *args):
838
920
839 self.__dataReady = False
921 self.__dataReady = False
840 avgdata_spc = None
922 avgdata_spc = None
841 avgdata_cspc = None
923 avgdata_cspc = None
842 avgdata_dc = None
924 avgdata_dc = None
843 n = None
925 n = None
844
926
845 self.putData(*args)
927 self.putData(*args)
846
928
847 if (datatime - self.__initime) >= self.__integrationtime:
929 if (datatime - self.__initime) >= self.__integrationtime:
848 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
930 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
849 self.n = n
931 self.n = n
850 self.__dataReady = True
932 self.__dataReady = True
851
933
852 return avgdata_spc, avgdata_cspc, avgdata_dc
934 return avgdata_spc, avgdata_cspc, avgdata_dc
853
935
854 def integrate(self, datatime, *args):
936 def integrate(self, datatime, *args):
855
937
856 if self.__initime == None:
938 if self.__initime == None:
857 self.__initime = datatime
939 self.__initime = datatime
858
940
859 if self.__byTime:
941 if self.__byTime:
860 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
942 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
861 else:
943 else:
862 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
944 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
863
945
864 self.__lastdatatime = datatime
946 self.__lastdatatime = datatime
865
947
866 if avgdata_spc == None:
948 if avgdata_spc == None:
867 return None, None, None, None
949 return None, None, None, None
868
950
869 avgdatatime = self.__initime
951 avgdatatime = self.__initime
870
952
871 deltatime = datatime -self.__lastdatatime
953 deltatime = datatime -self.__lastdatatime
872
954
873 if not self.__withOverapping:
955 if not self.__withOverapping:
874 self.__initime = datatime
956 self.__initime = datatime
875 else:
957 else:
876 self.__initime += deltatime
958 self.__initime += deltatime
877
959
878 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
960 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
879
961
880 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
962 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
881
963
882 if not self.__isConfig:
964 if not self.__isConfig:
883 self.setup(n, timeInterval, overlapping)
965 self.setup(n, timeInterval, overlapping)
884 self.__isConfig = True
966 self.__isConfig = True
885
967
886 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
968 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
887 dataOut.data_spc,
969 dataOut.data_spc,
888 dataOut.data_cspc,
970 dataOut.data_cspc,
889 dataOut.data_dc)
971 dataOut.data_dc)
890
972
891 # dataOut.timeInterval *= n
973 # dataOut.timeInterval *= n
892 dataOut.flagNoData = True
974 dataOut.flagNoData = True
893
975
894 if self.__dataReady:
976 if self.__dataReady:
895 dataOut.data_spc = avgdata_spc
977 dataOut.data_spc = avgdata_spc
896 dataOut.data_cspc = avgdata_cspc
978 dataOut.data_cspc = avgdata_cspc
897 dataOut.data_dc = avgdata_dc
979 dataOut.data_dc = avgdata_dc
898
980
899 dataOut.nIncohInt *= self.n
981 dataOut.nIncohInt *= self.n
900 dataOut.utctime = avgdatatime
982 dataOut.utctime = avgdatatime
901 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
983 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
902 dataOut.flagNoData = False
984 dataOut.flagNoData = False
903 No newline at end of file
985
General Comments 0
You need to be logged in to leave comments. Login now