@@ -1,1321 +1,1321 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on September , 2012 |
|
2 | Created on September , 2012 | |
3 | @author: |
|
3 | @author: | |
4 | ''' |
|
4 | ''' | |
5 |
|
5 | |||
6 | import sys |
|
6 | import sys | |
7 | import ast |
|
7 | import ast | |
8 | import datetime |
|
8 | import datetime | |
9 | import traceback |
|
9 | import traceback | |
10 | import math |
|
10 | import math | |
11 | import time |
|
11 | import time | |
12 | from multiprocessing import Process, Queue, cpu_count |
|
12 | from multiprocessing import Process, Queue, cpu_count | |
13 |
|
13 | |||
14 | import schainpy |
|
14 | import schainpy | |
15 | import schainpy.admin |
|
15 | import schainpy.admin | |
16 |
|
16 | |||
17 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
17 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring | |
18 | from xml.dom import minidom |
|
18 | from xml.dom import minidom | |
19 |
|
19 | |||
20 | from schainpy.model import * |
|
20 | from schainpy.model import * | |
21 | from time import sleep |
|
21 | from time import sleep | |
22 |
|
22 | |||
23 | def prettify(elem): |
|
23 | def prettify(elem): | |
24 | """Return a pretty-printed XML string for the Element. |
|
24 | """Return a pretty-printed XML string for the Element. | |
25 | """ |
|
25 | """ | |
26 | rough_string = tostring(elem, 'utf-8') |
|
26 | rough_string = tostring(elem, 'utf-8') | |
27 | reparsed = minidom.parseString(rough_string) |
|
27 | reparsed = minidom.parseString(rough_string) | |
28 | return reparsed.toprettyxml(indent=" ") |
|
28 | return reparsed.toprettyxml(indent=" ") | |
29 |
|
29 | |||
30 | def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_day=False): |
|
30 | def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_day=False): | |
31 | skip = 0 |
|
31 | skip = 0 | |
32 | cursor = 0 |
|
32 | cursor = 0 | |
33 | nFiles = None |
|
33 | nFiles = None | |
34 | processes = [] |
|
34 | processes = [] | |
35 | dt1 = datetime.datetime.strptime(startDate, '%Y/%m/%d') |
|
35 | dt1 = datetime.datetime.strptime(startDate, '%Y/%m/%d') | |
36 | dt2 = datetime.datetime.strptime(endDate, '%Y/%m/%d') |
|
36 | dt2 = datetime.datetime.strptime(endDate, '%Y/%m/%d') | |
37 | days = (dt2 - dt1).days |
|
37 | days = (dt2 - dt1).days | |
38 |
|
38 | |||
39 | for day in range(days+1): |
|
39 | for day in range(days+1): | |
40 | skip = 0 |
|
40 | skip = 0 | |
41 | cursor = 0 |
|
41 | cursor = 0 | |
42 | q = Queue() |
|
42 | q = Queue() | |
43 | processes = [] |
|
43 | processes = [] | |
44 | dt = (dt1 + datetime.timedelta(day)).strftime('%Y/%m/%d') |
|
44 | dt = (dt1 + datetime.timedelta(day)).strftime('%Y/%m/%d') | |
45 | firstProcess = Process(target=child, args=(cursor, skip, q, dt)) |
|
45 | firstProcess = Process(target=child, args=(cursor, skip, q, dt)) | |
46 | firstProcess.start() |
|
46 | firstProcess.start() | |
47 | if by_day: |
|
47 | if by_day: | |
48 | continue |
|
48 | continue | |
49 | nFiles = q.get() |
|
49 | nFiles = q.get() | |
50 | firstProcess.terminate() |
|
50 | firstProcess.terminate() | |
51 | skip = int(math.ceil(nFiles/nProcess)) |
|
51 | skip = int(math.ceil(nFiles/nProcess)) | |
52 | while True: |
|
52 | while True: | |
53 | processes.append(Process(target=child, args=(cursor, skip, q, dt))) |
|
53 | processes.append(Process(target=child, args=(cursor, skip, q, dt))) | |
54 | processes[cursor].start() |
|
54 | processes[cursor].start() | |
55 | if nFiles < cursor*skip: |
|
55 | if nFiles < cursor*skip: | |
56 | break |
|
56 | break | |
57 | cursor += 1 |
|
57 | cursor += 1 | |
58 |
|
58 | |||
59 | def beforeExit(exctype, value, trace): |
|
59 | def beforeExit(exctype, value, trace): | |
60 | for process in processes: |
|
60 | for process in processes: | |
61 | process.terminate() |
|
61 | process.terminate() | |
62 | process.join() |
|
62 | process.join() | |
63 | print traceback.print_tb(trace) |
|
63 | print traceback.print_tb(trace) | |
64 |
|
64 | |||
65 | sys.excepthook = beforeExit |
|
65 | sys.excepthook = beforeExit | |
66 |
|
66 | |||
67 | for process in processes: |
|
67 | for process in processes: | |
68 | process.join() |
|
68 | process.join() | |
69 | process.terminate() |
|
69 | process.terminate() | |
70 | time.sleep(3) |
|
70 | time.sleep(3) | |
71 |
|
71 | |||
72 | class ParameterConf(): |
|
72 | class ParameterConf(): | |
73 |
|
73 | |||
74 | id = None |
|
74 | id = None | |
75 | name = None |
|
75 | name = None | |
76 | value = None |
|
76 | value = None | |
77 | format = None |
|
77 | format = None | |
78 |
|
78 | |||
79 | __formated_value = None |
|
79 | __formated_value = None | |
80 |
|
80 | |||
81 | ELEMENTNAME = 'Parameter' |
|
81 | ELEMENTNAME = 'Parameter' | |
82 |
|
82 | |||
83 | def __init__(self): |
|
83 | def __init__(self): | |
84 |
|
84 | |||
85 | self.format = 'str' |
|
85 | self.format = 'str' | |
86 |
|
86 | |||
87 | def getElementName(self): |
|
87 | def getElementName(self): | |
88 |
|
88 | |||
89 | return self.ELEMENTNAME |
|
89 | return self.ELEMENTNAME | |
90 |
|
90 | |||
91 | def getValue(self): |
|
91 | def getValue(self): | |
92 |
|
92 | |||
93 | value = self.value |
|
93 | value = self.value | |
94 | format = self.format |
|
94 | format = self.format | |
95 |
|
95 | |||
96 | if self.__formated_value != None: |
|
96 | if self.__formated_value != None: | |
97 |
|
97 | |||
98 | return self.__formated_value |
|
98 | return self.__formated_value | |
99 |
|
99 | |||
100 | if format == 'obj': |
|
100 | if format == 'obj': | |
101 | return value |
|
101 | return value | |
102 |
|
102 | |||
103 | if format == 'str': |
|
103 | if format == 'str': | |
104 | self.__formated_value = str(value) |
|
104 | self.__formated_value = str(value) | |
105 | return self.__formated_value |
|
105 | return self.__formated_value | |
106 |
|
106 | |||
107 | if value == '': |
|
107 | if value == '': | |
108 | raise ValueError, "%s: This parameter value is empty" %self.name |
|
108 | raise ValueError, "%s: This parameter value is empty" %self.name | |
109 |
|
109 | |||
110 | if format == 'list': |
|
110 | if format == 'list': | |
111 | strList = value.split(',') |
|
111 | strList = value.split(',') | |
112 |
|
112 | |||
113 | self.__formated_value = strList |
|
113 | self.__formated_value = strList | |
114 |
|
114 | |||
115 | return self.__formated_value |
|
115 | return self.__formated_value | |
116 |
|
116 | |||
117 | if format == 'intlist': |
|
117 | if format == 'intlist': | |
118 | """ |
|
118 | """ | |
119 | Example: |
|
119 | Example: | |
120 | value = (0,1,2) |
|
120 | value = (0,1,2) | |
121 | """ |
|
121 | """ | |
122 |
|
122 | |||
123 | new_value = ast.literal_eval(value) |
|
123 | new_value = ast.literal_eval(value) | |
124 |
|
124 | |||
125 | if type(new_value) not in (tuple, list): |
|
125 | if type(new_value) not in (tuple, list): | |
126 | new_value = [int(new_value)] |
|
126 | new_value = [int(new_value)] | |
127 |
|
127 | |||
128 | self.__formated_value = new_value |
|
128 | self.__formated_value = new_value | |
129 |
|
129 | |||
130 | return self.__formated_value |
|
130 | return self.__formated_value | |
131 |
|
131 | |||
132 | if format == 'floatlist': |
|
132 | if format == 'floatlist': | |
133 | """ |
|
133 | """ | |
134 | Example: |
|
134 | Example: | |
135 | value = (0.5, 1.4, 2.7) |
|
135 | value = (0.5, 1.4, 2.7) | |
136 | """ |
|
136 | """ | |
137 |
|
137 | |||
138 | new_value = ast.literal_eval(value) |
|
138 | new_value = ast.literal_eval(value) | |
139 |
|
139 | |||
140 | if type(new_value) not in (tuple, list): |
|
140 | if type(new_value) not in (tuple, list): | |
141 | new_value = [float(new_value)] |
|
141 | new_value = [float(new_value)] | |
142 |
|
142 | |||
143 | self.__formated_value = new_value |
|
143 | self.__formated_value = new_value | |
144 |
|
144 | |||
145 | return self.__formated_value |
|
145 | return self.__formated_value | |
146 |
|
146 | |||
147 | if format == 'date': |
|
147 | if format == 'date': | |
148 | strList = value.split('/') |
|
148 | strList = value.split('/') | |
149 | intList = [int(x) for x in strList] |
|
149 | intList = [int(x) for x in strList] | |
150 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
150 | date = datetime.date(intList[0], intList[1], intList[2]) | |
151 |
|
151 | |||
152 | self.__formated_value = date |
|
152 | self.__formated_value = date | |
153 |
|
153 | |||
154 | return self.__formated_value |
|
154 | return self.__formated_value | |
155 |
|
155 | |||
156 | if format == 'time': |
|
156 | if format == 'time': | |
157 | strList = value.split(':') |
|
157 | strList = value.split(':') | |
158 | intList = [int(x) for x in strList] |
|
158 | intList = [int(x) for x in strList] | |
159 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
159 | time = datetime.time(intList[0], intList[1], intList[2]) | |
160 |
|
160 | |||
161 | self.__formated_value = time |
|
161 | self.__formated_value = time | |
162 |
|
162 | |||
163 | return self.__formated_value |
|
163 | return self.__formated_value | |
164 |
|
164 | |||
165 | if format == 'pairslist': |
|
165 | if format == 'pairslist': | |
166 | """ |
|
166 | """ | |
167 | Example: |
|
167 | Example: | |
168 | value = (0,1),(1,2) |
|
168 | value = (0,1),(1,2) | |
169 | """ |
|
169 | """ | |
170 |
|
170 | |||
171 | new_value = ast.literal_eval(value) |
|
171 | new_value = ast.literal_eval(value) | |
172 |
|
172 | |||
173 | if type(new_value) not in (tuple, list): |
|
173 | if type(new_value) not in (tuple, list): | |
174 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
174 | raise ValueError, "%s has to be a tuple or list of pairs" %value | |
175 |
|
175 | |||
176 | if type(new_value[0]) not in (tuple, list): |
|
176 | if type(new_value[0]) not in (tuple, list): | |
177 | if len(new_value) != 2: |
|
177 | if len(new_value) != 2: | |
178 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
178 | raise ValueError, "%s has to be a tuple or list of pairs" %value | |
179 | new_value = [new_value] |
|
179 | new_value = [new_value] | |
180 |
|
180 | |||
181 | for thisPair in new_value: |
|
181 | for thisPair in new_value: | |
182 | if len(thisPair) != 2: |
|
182 | if len(thisPair) != 2: | |
183 | raise ValueError, "%s has to be a tuple or list of pairs" %value |
|
183 | raise ValueError, "%s has to be a tuple or list of pairs" %value | |
184 |
|
184 | |||
185 | self.__formated_value = new_value |
|
185 | self.__formated_value = new_value | |
186 |
|
186 | |||
187 | return self.__formated_value |
|
187 | return self.__formated_value | |
188 |
|
188 | |||
189 | if format == 'multilist': |
|
189 | if format == 'multilist': | |
190 | """ |
|
190 | """ | |
191 | Example: |
|
191 | Example: | |
192 | value = (0,1,2),(3,4,5) |
|
192 | value = (0,1,2),(3,4,5) | |
193 | """ |
|
193 | """ | |
194 | multiList = ast.literal_eval(value) |
|
194 | multiList = ast.literal_eval(value) | |
195 |
|
195 | |||
196 | if type(multiList[0]) == int: |
|
196 | if type(multiList[0]) == int: | |
197 | multiList = ast.literal_eval("(" + value + ")") |
|
197 | multiList = ast.literal_eval("(" + value + ")") | |
198 |
|
198 | |||
199 | self.__formated_value = multiList |
|
199 | self.__formated_value = multiList | |
200 |
|
200 | |||
201 | return self.__formated_value |
|
201 | return self.__formated_value | |
202 |
|
202 | |||
203 | if format == 'bool': |
|
203 | if format == 'bool': | |
204 | value = int(value) |
|
204 | value = int(value) | |
205 |
|
205 | |||
206 | if format == 'int': |
|
206 | if format == 'int': | |
207 | value = float(value) |
|
207 | value = float(value) | |
208 |
|
208 | |||
209 | format_func = eval(format) |
|
209 | format_func = eval(format) | |
210 |
|
210 | |||
211 | self.__formated_value = format_func(value) |
|
211 | self.__formated_value = format_func(value) | |
212 |
|
212 | |||
213 | return self.__formated_value |
|
213 | return self.__formated_value | |
214 |
|
214 | |||
215 | def updateId(self, new_id): |
|
215 | def updateId(self, new_id): | |
216 |
|
216 | |||
217 | self.id = str(new_id) |
|
217 | self.id = str(new_id) | |
218 |
|
218 | |||
219 | def setup(self, id, name, value, format='str'): |
|
219 | def setup(self, id, name, value, format='str'): | |
220 |
|
220 | |||
221 | self.id = str(id) |
|
221 | self.id = str(id) | |
222 | self.name = name |
|
222 | self.name = name | |
223 | if format == 'obj': |
|
223 | if format == 'obj': | |
224 | self.value = value |
|
224 | self.value = value | |
225 | else: |
|
225 | else: | |
226 | self.value = str(value) |
|
226 | self.value = str(value) | |
227 | self.format = str.lower(format) |
|
227 | self.format = str.lower(format) | |
228 |
|
228 | |||
229 | self.getValue() |
|
229 | self.getValue() | |
230 |
|
230 | |||
231 | return 1 |
|
231 | return 1 | |
232 |
|
232 | |||
233 | def update(self, name, value, format='str'): |
|
233 | def update(self, name, value, format='str'): | |
234 |
|
234 | |||
235 | self.name = name |
|
235 | self.name = name | |
236 | self.value = str(value) |
|
236 | self.value = str(value) | |
237 | self.format = format |
|
237 | self.format = format | |
238 |
|
238 | |||
239 | def makeXml(self, opElement): |
|
239 | def makeXml(self, opElement): | |
240 | if self.name not in ('queue',): |
|
240 | if self.name not in ('queue',): | |
241 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
241 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
242 | parmElement.set('id', str(self.id)) |
|
242 | parmElement.set('id', str(self.id)) | |
243 | parmElement.set('name', self.name) |
|
243 | parmElement.set('name', self.name) | |
244 | parmElement.set('value', self.value) |
|
244 | parmElement.set('value', self.value) | |
245 | parmElement.set('format', self.format) |
|
245 | parmElement.set('format', self.format) | |
246 |
|
246 | |||
247 | def readXml(self, parmElement): |
|
247 | def readXml(self, parmElement): | |
248 |
|
248 | |||
249 | self.id = parmElement.get('id') |
|
249 | self.id = parmElement.get('id') | |
250 | self.name = parmElement.get('name') |
|
250 | self.name = parmElement.get('name') | |
251 | self.value = parmElement.get('value') |
|
251 | self.value = parmElement.get('value') | |
252 | self.format = str.lower(parmElement.get('format')) |
|
252 | self.format = str.lower(parmElement.get('format')) | |
253 |
|
253 | |||
254 | #Compatible with old signal chain version |
|
254 | #Compatible with old signal chain version | |
255 | if self.format == 'int' and self.name == 'idfigure': |
|
255 | if self.format == 'int' and self.name == 'idfigure': | |
256 | self.name = 'id' |
|
256 | self.name = 'id' | |
257 |
|
257 | |||
258 | def printattr(self): |
|
258 | def printattr(self): | |
259 |
|
259 | |||
260 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
260 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
261 |
|
261 | |||
262 | class OperationConf(): |
|
262 | class OperationConf(): | |
263 |
|
263 | |||
264 | id = None |
|
264 | id = None | |
265 | name = None |
|
265 | name = None | |
266 | priority = None |
|
266 | priority = None | |
267 | type = None |
|
267 | type = None | |
268 |
|
268 | |||
269 | parmConfObjList = [] |
|
269 | parmConfObjList = [] | |
270 |
|
270 | |||
271 | ELEMENTNAME = 'Operation' |
|
271 | ELEMENTNAME = 'Operation' | |
272 |
|
272 | |||
273 | def __init__(self): |
|
273 | def __init__(self): | |
274 |
|
274 | |||
275 | self.id = '0' |
|
275 | self.id = '0' | |
276 | self.name = None |
|
276 | self.name = None | |
277 | self.priority = None |
|
277 | self.priority = None | |
278 | self.type = 'self' |
|
278 | self.type = 'self' | |
279 |
|
279 | |||
280 |
|
280 | |||
281 | def __getNewId(self): |
|
281 | def __getNewId(self): | |
282 |
|
282 | |||
283 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
283 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
284 |
|
284 | |||
285 | def updateId(self, new_id): |
|
285 | def updateId(self, new_id): | |
286 |
|
286 | |||
287 | self.id = str(new_id) |
|
287 | self.id = str(new_id) | |
288 |
|
288 | |||
289 | n = 1 |
|
289 | n = 1 | |
290 | for parmObj in self.parmConfObjList: |
|
290 | for parmObj in self.parmConfObjList: | |
291 |
|
291 | |||
292 | idParm = str(int(new_id)*10 + n) |
|
292 | idParm = str(int(new_id)*10 + n) | |
293 | parmObj.updateId(idParm) |
|
293 | parmObj.updateId(idParm) | |
294 |
|
294 | |||
295 | n += 1 |
|
295 | n += 1 | |
296 |
|
296 | |||
297 | def getElementName(self): |
|
297 | def getElementName(self): | |
298 |
|
298 | |||
299 | return self.ELEMENTNAME |
|
299 | return self.ELEMENTNAME | |
300 |
|
300 | |||
301 | def getParameterObjList(self): |
|
301 | def getParameterObjList(self): | |
302 |
|
302 | |||
303 | return self.parmConfObjList |
|
303 | return self.parmConfObjList | |
304 |
|
304 | |||
305 | def getParameterObj(self, parameterName): |
|
305 | def getParameterObj(self, parameterName): | |
306 |
|
306 | |||
307 | for parmConfObj in self.parmConfObjList: |
|
307 | for parmConfObj in self.parmConfObjList: | |
308 |
|
308 | |||
309 | if parmConfObj.name != parameterName: |
|
309 | if parmConfObj.name != parameterName: | |
310 | continue |
|
310 | continue | |
311 |
|
311 | |||
312 | return parmConfObj |
|
312 | return parmConfObj | |
313 |
|
313 | |||
314 | return None |
|
314 | return None | |
315 |
|
315 | |||
316 | def getParameterObjfromValue(self, parameterValue): |
|
316 | def getParameterObjfromValue(self, parameterValue): | |
317 |
|
317 | |||
318 | for parmConfObj in self.parmConfObjList: |
|
318 | for parmConfObj in self.parmConfObjList: | |
319 |
|
319 | |||
320 | if parmConfObj.getValue() != parameterValue: |
|
320 | if parmConfObj.getValue() != parameterValue: | |
321 | continue |
|
321 | continue | |
322 |
|
322 | |||
323 | return parmConfObj.getValue() |
|
323 | return parmConfObj.getValue() | |
324 |
|
324 | |||
325 | return None |
|
325 | return None | |
326 |
|
326 | |||
327 | def getParameterValue(self, parameterName): |
|
327 | def getParameterValue(self, parameterName): | |
328 |
|
328 | |||
329 | parameterObj = self.getParameterObj(parameterName) |
|
329 | parameterObj = self.getParameterObj(parameterName) | |
330 |
|
330 | |||
331 | # if not parameterObj: |
|
331 | # if not parameterObj: | |
332 | # return None |
|
332 | # return None | |
333 |
|
333 | |||
334 | value = parameterObj.getValue() |
|
334 | value = parameterObj.getValue() | |
335 |
|
335 | |||
336 | return value |
|
336 | return value | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | def getKwargs(self): |
|
339 | def getKwargs(self): | |
340 |
|
340 | |||
341 | kwargs = {} |
|
341 | kwargs = {} | |
342 |
|
342 | |||
343 | for parmConfObj in self.parmConfObjList: |
|
343 | for parmConfObj in self.parmConfObjList: | |
344 | if self.name == 'run' and parmConfObj.name == 'datatype': |
|
344 | if self.name == 'run' and parmConfObj.name == 'datatype': | |
345 | continue |
|
345 | continue | |
346 |
|
346 | |||
347 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
347 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
348 |
|
348 | |||
349 | return kwargs |
|
349 | return kwargs | |
350 |
|
350 | |||
351 | def setup(self, id, name, priority, type): |
|
351 | def setup(self, id, name, priority, type): | |
352 |
|
352 | |||
353 | self.id = str(id) |
|
353 | self.id = str(id) | |
354 | self.name = name |
|
354 | self.name = name | |
355 | self.type = type |
|
355 | self.type = type | |
356 | self.priority = priority |
|
356 | self.priority = priority | |
357 |
|
357 | |||
358 | self.parmConfObjList = [] |
|
358 | self.parmConfObjList = [] | |
359 |
|
359 | |||
360 | def removeParameters(self): |
|
360 | def removeParameters(self): | |
361 |
|
361 | |||
362 | for obj in self.parmConfObjList: |
|
362 | for obj in self.parmConfObjList: | |
363 | del obj |
|
363 | del obj | |
364 |
|
364 | |||
365 | self.parmConfObjList = [] |
|
365 | self.parmConfObjList = [] | |
366 |
|
366 | |||
367 | def addParameter(self, name, value, format='str'): |
|
367 | def addParameter(self, name, value, format='str'): | |
368 |
|
368 | |||
369 | id = self.__getNewId() |
|
369 | id = self.__getNewId() | |
370 |
|
370 | |||
371 | parmConfObj = ParameterConf() |
|
371 | parmConfObj = ParameterConf() | |
372 | if not parmConfObj.setup(id, name, value, format): |
|
372 | if not parmConfObj.setup(id, name, value, format): | |
373 | return None |
|
373 | return None | |
374 |
|
374 | |||
375 | self.parmConfObjList.append(parmConfObj) |
|
375 | self.parmConfObjList.append(parmConfObj) | |
376 |
|
376 | |||
377 | return parmConfObj |
|
377 | return parmConfObj | |
378 |
|
378 | |||
379 | def changeParameter(self, name, value, format='str'): |
|
379 | def changeParameter(self, name, value, format='str'): | |
380 |
|
380 | |||
381 | parmConfObj = self.getParameterObj(name) |
|
381 | parmConfObj = self.getParameterObj(name) | |
382 | parmConfObj.update(name, value, format) |
|
382 | parmConfObj.update(name, value, format) | |
383 |
|
383 | |||
384 | return parmConfObj |
|
384 | return parmConfObj | |
385 |
|
385 | |||
386 | def makeXml(self, procUnitElement): |
|
386 | def makeXml(self, procUnitElement): | |
387 |
|
387 | |||
388 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
388 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
389 | opElement.set('id', str(self.id)) |
|
389 | opElement.set('id', str(self.id)) | |
390 | opElement.set('name', self.name) |
|
390 | opElement.set('name', self.name) | |
391 | opElement.set('type', self.type) |
|
391 | opElement.set('type', self.type) | |
392 | opElement.set('priority', str(self.priority)) |
|
392 | opElement.set('priority', str(self.priority)) | |
393 |
|
393 | |||
394 | for parmConfObj in self.parmConfObjList: |
|
394 | for parmConfObj in self.parmConfObjList: | |
395 | parmConfObj.makeXml(opElement) |
|
395 | parmConfObj.makeXml(opElement) | |
396 |
|
396 | |||
397 | def readXml(self, opElement): |
|
397 | def readXml(self, opElement): | |
398 |
|
398 | |||
399 | self.id = opElement.get('id') |
|
399 | self.id = opElement.get('id') | |
400 | self.name = opElement.get('name') |
|
400 | self.name = opElement.get('name') | |
401 | self.type = opElement.get('type') |
|
401 | self.type = opElement.get('type') | |
402 | self.priority = opElement.get('priority') |
|
402 | self.priority = opElement.get('priority') | |
403 |
|
403 | |||
404 | #Compatible with old signal chain version |
|
404 | #Compatible with old signal chain version | |
405 | #Use of 'run' method instead 'init' |
|
405 | #Use of 'run' method instead 'init' | |
406 | if self.type == 'self' and self.name == 'init': |
|
406 | if self.type == 'self' and self.name == 'init': | |
407 | self.name = 'run' |
|
407 | self.name = 'run' | |
408 |
|
408 | |||
409 | self.parmConfObjList = [] |
|
409 | self.parmConfObjList = [] | |
410 |
|
410 | |||
411 | parmElementList = opElement.iter(ParameterConf().getElementName()) |
|
411 | parmElementList = opElement.iter(ParameterConf().getElementName()) | |
412 |
|
412 | |||
413 | for parmElement in parmElementList: |
|
413 | for parmElement in parmElementList: | |
414 | parmConfObj = ParameterConf() |
|
414 | parmConfObj = ParameterConf() | |
415 | parmConfObj.readXml(parmElement) |
|
415 | parmConfObj.readXml(parmElement) | |
416 |
|
416 | |||
417 | #Compatible with old signal chain version |
|
417 | #Compatible with old signal chain version | |
418 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
418 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
419 | if self.type != 'self' and self.name == 'Plot': |
|
419 | if self.type != 'self' and self.name == 'Plot': | |
420 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
420 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': | |
421 | self.name = parmConfObj.value |
|
421 | self.name = parmConfObj.value | |
422 | continue |
|
422 | continue | |
423 |
|
423 | |||
424 | self.parmConfObjList.append(parmConfObj) |
|
424 | self.parmConfObjList.append(parmConfObj) | |
425 |
|
425 | |||
426 | def printattr(self): |
|
426 | def printattr(self): | |
427 |
|
427 | |||
428 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
428 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
429 | self.id, |
|
429 | self.id, | |
430 | self.name, |
|
430 | self.name, | |
431 | self.type, |
|
431 | self.type, | |
432 | self.priority) |
|
432 | self.priority) | |
433 |
|
433 | |||
434 | for parmConfObj in self.parmConfObjList: |
|
434 | for parmConfObj in self.parmConfObjList: | |
435 | parmConfObj.printattr() |
|
435 | parmConfObj.printattr() | |
436 |
|
436 | |||
437 | def createObject(self, plotter_queue=None): |
|
437 | def createObject(self, plotter_queue=None): | |
438 |
|
438 | |||
439 |
|
439 | |||
440 | if self.type == 'self': |
|
440 | if self.type == 'self': | |
441 | raise ValueError, "This operation type cannot be created" |
|
441 | raise ValueError, "This operation type cannot be created" | |
442 |
|
442 | |||
443 | if self.type == 'plotter': |
|
443 | if self.type == 'plotter': | |
444 | #Plotter(plotter_name) |
|
444 | #Plotter(plotter_name) | |
445 | if not plotter_queue: |
|
445 | if not plotter_queue: | |
446 | raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)" |
|
446 | raise ValueError, "plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)" | |
447 |
|
447 | |||
448 | opObj = Plotter(self.name, plotter_queue) |
|
448 | opObj = Plotter(self.name, plotter_queue) | |
449 |
|
449 | |||
450 | if self.type == 'external' or self.type == 'other': |
|
450 | if self.type == 'external' or self.type == 'other': | |
451 |
|
451 | |||
452 | className = eval(self.name) |
|
452 | className = eval(self.name) | |
453 | kwargs = self.getKwargs() |
|
453 | kwargs = self.getKwargs() | |
454 |
|
454 | |||
455 | opObj = className(**kwargs) |
|
455 | opObj = className(**kwargs) | |
456 |
|
456 | |||
457 | return opObj |
|
457 | return opObj | |
458 |
|
458 | |||
459 |
|
459 | |||
460 | class ProcUnitConf(): |
|
460 | class ProcUnitConf(): | |
461 |
|
461 | |||
462 | id = None |
|
462 | id = None | |
463 | name = None |
|
463 | name = None | |
464 | datatype = None |
|
464 | datatype = None | |
465 | inputId = None |
|
465 | inputId = None | |
466 | parentId = None |
|
466 | parentId = None | |
467 |
|
467 | |||
468 | opConfObjList = [] |
|
468 | opConfObjList = [] | |
469 |
|
469 | |||
470 | procUnitObj = None |
|
470 | procUnitObj = None | |
471 | opObjList = [] |
|
471 | opObjList = [] | |
472 |
|
472 | |||
473 | ELEMENTNAME = 'ProcUnit' |
|
473 | ELEMENTNAME = 'ProcUnit' | |
474 |
|
474 | |||
475 | def __init__(self): |
|
475 | def __init__(self): | |
476 |
|
476 | |||
477 | self.id = None |
|
477 | self.id = None | |
478 | self.datatype = None |
|
478 | self.datatype = None | |
479 | self.name = None |
|
479 | self.name = None | |
480 | self.inputId = None |
|
480 | self.inputId = None | |
481 |
|
481 | |||
482 | self.opConfObjList = [] |
|
482 | self.opConfObjList = [] | |
483 |
|
483 | |||
484 | self.procUnitObj = None |
|
484 | self.procUnitObj = None | |
485 | self.opObjDict = {} |
|
485 | self.opObjDict = {} | |
486 |
|
486 | |||
487 | def __getPriority(self): |
|
487 | def __getPriority(self): | |
488 |
|
488 | |||
489 | return len(self.opConfObjList)+1 |
|
489 | return len(self.opConfObjList)+1 | |
490 |
|
490 | |||
491 | def __getNewId(self): |
|
491 | def __getNewId(self): | |
492 |
|
492 | |||
493 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
493 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
494 |
|
494 | |||
495 | def getElementName(self): |
|
495 | def getElementName(self): | |
496 |
|
496 | |||
497 | return self.ELEMENTNAME |
|
497 | return self.ELEMENTNAME | |
498 |
|
498 | |||
499 | def getId(self): |
|
499 | def getId(self): | |
500 |
|
500 | |||
501 | return self.id |
|
501 | return self.id | |
502 |
|
502 | |||
503 | def updateId(self, new_id, parentId=parentId): |
|
503 | def updateId(self, new_id, parentId=parentId): | |
504 |
|
504 | |||
505 |
|
505 | |||
506 | new_id = int(parentId)*10 + (int(self.id) % 10) |
|
506 | new_id = int(parentId)*10 + (int(self.id) % 10) | |
507 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) |
|
507 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) | |
508 |
|
508 | |||
509 | #If this proc unit has not inputs |
|
509 | #If this proc unit has not inputs | |
510 | if self.inputId == '0': |
|
510 | if self.inputId == '0': | |
511 | new_inputId = 0 |
|
511 | new_inputId = 0 | |
512 |
|
512 | |||
513 | n = 1 |
|
513 | n = 1 | |
514 | for opConfObj in self.opConfObjList: |
|
514 | for opConfObj in self.opConfObjList: | |
515 |
|
515 | |||
516 | idOp = str(int(new_id)*10 + n) |
|
516 | idOp = str(int(new_id)*10 + n) | |
517 | opConfObj.updateId(idOp) |
|
517 | opConfObj.updateId(idOp) | |
518 |
|
518 | |||
519 | n += 1 |
|
519 | n += 1 | |
520 |
|
520 | |||
521 | self.parentId = str(parentId) |
|
521 | self.parentId = str(parentId) | |
522 | self.id = str(new_id) |
|
522 | self.id = str(new_id) | |
523 | self.inputId = str(new_inputId) |
|
523 | self.inputId = str(new_inputId) | |
524 |
|
524 | |||
525 |
|
525 | |||
526 | def getInputId(self): |
|
526 | def getInputId(self): | |
527 |
|
527 | |||
528 | return self.inputId |
|
528 | return self.inputId | |
529 |
|
529 | |||
530 | def getOperationObjList(self): |
|
530 | def getOperationObjList(self): | |
531 |
|
531 | |||
532 | return self.opConfObjList |
|
532 | return self.opConfObjList | |
533 |
|
533 | |||
534 | def getOperationObj(self, name=None): |
|
534 | def getOperationObj(self, name=None): | |
535 |
|
535 | |||
536 | for opConfObj in self.opConfObjList: |
|
536 | for opConfObj in self.opConfObjList: | |
537 |
|
537 | |||
538 | if opConfObj.name != name: |
|
538 | if opConfObj.name != name: | |
539 | continue |
|
539 | continue | |
540 |
|
540 | |||
541 | return opConfObj |
|
541 | return opConfObj | |
542 |
|
542 | |||
543 | return None |
|
543 | return None | |
544 |
|
544 | |||
545 | def getOpObjfromParamValue(self, value=None): |
|
545 | def getOpObjfromParamValue(self, value=None): | |
546 |
|
546 | |||
547 | for opConfObj in self.opConfObjList: |
|
547 | for opConfObj in self.opConfObjList: | |
548 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
548 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: | |
549 | continue |
|
549 | continue | |
550 | return opConfObj |
|
550 | return opConfObj | |
551 | return None |
|
551 | return None | |
552 |
|
552 | |||
553 | def getProcUnitObj(self): |
|
553 | def getProcUnitObj(self): | |
554 |
|
554 | |||
555 | return self.procUnitObj |
|
555 | return self.procUnitObj | |
556 |
|
556 | |||
557 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
557 | def setup(self, id, name, datatype, inputId, parentId=None): | |
558 |
|
558 | |||
559 | #Compatible with old signal chain version |
|
559 | #Compatible with old signal chain version | |
560 | if datatype==None and name==None: |
|
560 | if datatype==None and name==None: | |
561 | raise ValueError, "datatype or name should be defined" |
|
561 | raise ValueError, "datatype or name should be defined" | |
562 |
|
562 | |||
563 | if name==None: |
|
563 | if name==None: | |
564 | if 'Proc' in datatype: |
|
564 | if 'Proc' in datatype: | |
565 | name = datatype |
|
565 | name = datatype | |
566 | else: |
|
566 | else: | |
567 | name = '%sProc' %(datatype) |
|
567 | name = '%sProc' %(datatype) | |
568 |
|
568 | |||
569 | if datatype==None: |
|
569 | if datatype==None: | |
570 | datatype = name.replace('Proc','') |
|
570 | datatype = name.replace('Proc','') | |
571 |
|
571 | |||
572 | self.id = str(id) |
|
572 | self.id = str(id) | |
573 | self.name = name |
|
573 | self.name = name | |
574 | self.datatype = datatype |
|
574 | self.datatype = datatype | |
575 | self.inputId = inputId |
|
575 | self.inputId = inputId | |
576 | self.parentId = parentId |
|
576 | self.parentId = parentId | |
577 |
|
577 | |||
578 | self.opConfObjList = [] |
|
578 | self.opConfObjList = [] | |
579 |
|
579 | |||
580 | self.addOperation(name='run', optype='self') |
|
580 | self.addOperation(name='run', optype='self') | |
581 |
|
581 | |||
582 | def removeOperations(self): |
|
582 | def removeOperations(self): | |
583 |
|
583 | |||
584 | for obj in self.opConfObjList: |
|
584 | for obj in self.opConfObjList: | |
585 | del obj |
|
585 | del obj | |
586 |
|
586 | |||
587 | self.opConfObjList = [] |
|
587 | self.opConfObjList = [] | |
588 | self.addOperation(name='run') |
|
588 | self.addOperation(name='run') | |
589 |
|
589 | |||
590 | def addParameter(self, **kwargs): |
|
590 | def addParameter(self, **kwargs): | |
591 | ''' |
|
591 | ''' | |
592 | Add parameters to "run" operation |
|
592 | Add parameters to "run" operation | |
593 | ''' |
|
593 | ''' | |
594 | opObj = self.opConfObjList[0] |
|
594 | opObj = self.opConfObjList[0] | |
595 |
|
595 | |||
596 | opObj.addParameter(**kwargs) |
|
596 | opObj.addParameter(**kwargs) | |
597 |
|
597 | |||
598 | return opObj |
|
598 | return opObj | |
599 |
|
599 | |||
600 | def addOperation(self, name, optype='self'): |
|
600 | def addOperation(self, name, optype='self'): | |
601 |
|
601 | |||
602 | id = self.__getNewId() |
|
602 | id = self.__getNewId() | |
603 | priority = self.__getPriority() |
|
603 | priority = self.__getPriority() | |
604 |
|
604 | |||
605 | opConfObj = OperationConf() |
|
605 | opConfObj = OperationConf() | |
606 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
606 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
607 |
|
607 | |||
608 | self.opConfObjList.append(opConfObj) |
|
608 | self.opConfObjList.append(opConfObj) | |
609 |
|
609 | |||
610 | return opConfObj |
|
610 | return opConfObj | |
611 |
|
611 | |||
612 | def makeXml(self, projectElement): |
|
612 | def makeXml(self, projectElement): | |
613 |
|
613 | |||
614 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
614 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
615 | procUnitElement.set('id', str(self.id)) |
|
615 | procUnitElement.set('id', str(self.id)) | |
616 | procUnitElement.set('name', self.name) |
|
616 | procUnitElement.set('name', self.name) | |
617 | procUnitElement.set('datatype', self.datatype) |
|
617 | procUnitElement.set('datatype', self.datatype) | |
618 | procUnitElement.set('inputId', str(self.inputId)) |
|
618 | procUnitElement.set('inputId', str(self.inputId)) | |
619 |
|
619 | |||
620 | for opConfObj in self.opConfObjList: |
|
620 | for opConfObj in self.opConfObjList: | |
621 | opConfObj.makeXml(procUnitElement) |
|
621 | opConfObj.makeXml(procUnitElement) | |
622 |
|
622 | |||
623 | def readXml(self, upElement): |
|
623 | def readXml(self, upElement): | |
624 |
|
624 | |||
625 | self.id = upElement.get('id') |
|
625 | self.id = upElement.get('id') | |
626 | self.name = upElement.get('name') |
|
626 | self.name = upElement.get('name') | |
627 | self.datatype = upElement.get('datatype') |
|
627 | self.datatype = upElement.get('datatype') | |
628 | self.inputId = upElement.get('inputId') |
|
628 | self.inputId = upElement.get('inputId') | |
629 |
|
629 | |||
630 | if self.ELEMENTNAME == "ReadUnit": |
|
630 | if self.ELEMENTNAME == "ReadUnit": | |
631 | self.datatype = self.datatype.replace("Reader", "") |
|
631 | self.datatype = self.datatype.replace("Reader", "") | |
632 |
|
632 | |||
633 | if self.ELEMENTNAME == "ProcUnit": |
|
633 | if self.ELEMENTNAME == "ProcUnit": | |
634 | self.datatype = self.datatype.replace("Proc", "") |
|
634 | self.datatype = self.datatype.replace("Proc", "") | |
635 |
|
635 | |||
636 | if self.inputId == 'None': |
|
636 | if self.inputId == 'None': | |
637 | self.inputId = '0' |
|
637 | self.inputId = '0' | |
638 |
|
638 | |||
639 | self.opConfObjList = [] |
|
639 | self.opConfObjList = [] | |
640 |
|
640 | |||
641 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
641 | opElementList = upElement.iter(OperationConf().getElementName()) | |
642 |
|
642 | |||
643 | for opElement in opElementList: |
|
643 | for opElement in opElementList: | |
644 | opConfObj = OperationConf() |
|
644 | opConfObj = OperationConf() | |
645 | opConfObj.readXml(opElement) |
|
645 | opConfObj.readXml(opElement) | |
646 | self.opConfObjList.append(opConfObj) |
|
646 | self.opConfObjList.append(opConfObj) | |
647 |
|
647 | |||
648 | def printattr(self): |
|
648 | def printattr(self): | |
649 |
|
649 | |||
650 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
650 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
651 | self.id, |
|
651 | self.id, | |
652 | self.name, |
|
652 | self.name, | |
653 | self.datatype, |
|
653 | self.datatype, | |
654 | self.inputId) |
|
654 | self.inputId) | |
655 |
|
655 | |||
656 | for opConfObj in self.opConfObjList: |
|
656 | for opConfObj in self.opConfObjList: | |
657 | opConfObj.printattr() |
|
657 | opConfObj.printattr() | |
658 |
|
658 | |||
659 |
|
659 | |||
660 | def getKwargs(self): |
|
660 | def getKwargs(self): | |
661 |
|
661 | |||
662 | opObj = self.opConfObjList[0] |
|
662 | opObj = self.opConfObjList[0] | |
663 | kwargs = opObj.getKwargs() |
|
663 | kwargs = opObj.getKwargs() | |
664 |
|
664 | |||
665 | return kwargs |
|
665 | return kwargs | |
666 |
|
666 | |||
667 | def createObjects(self, plotter_queue=None): |
|
667 | def createObjects(self, plotter_queue=None): | |
668 |
|
668 | |||
669 | className = eval(self.name) |
|
669 | className = eval(self.name) | |
670 | kwargs = self.getKwargs() |
|
670 | kwargs = self.getKwargs() | |
671 | procUnitObj = className(**kwargs) |
|
671 | procUnitObj = className(**kwargs) | |
672 |
|
672 | |||
673 | for opConfObj in self.opConfObjList: |
|
673 | for opConfObj in self.opConfObjList: | |
674 |
|
674 | |||
675 | if opConfObj.type=='self' and self.name=='run': |
|
675 | if opConfObj.type=='self' and self.name=='run': | |
676 | continue |
|
676 | continue | |
677 | elif opConfObj.type=='self': |
|
677 | elif opConfObj.type=='self': | |
678 | procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs()) |
|
678 | procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs()) | |
679 | continue |
|
679 | continue | |
680 |
|
680 | |||
681 | opObj = opConfObj.createObject(plotter_queue) |
|
681 | opObj = opConfObj.createObject(plotter_queue) | |
682 |
|
682 | |||
683 | self.opObjDict[opConfObj.id] = opObj |
|
683 | self.opObjDict[opConfObj.id] = opObj | |
684 |
|
684 | |||
685 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
685 | procUnitObj.addOperation(opObj, opConfObj.id) | |
686 |
|
686 | |||
687 | self.procUnitObj = procUnitObj |
|
687 | self.procUnitObj = procUnitObj | |
688 |
|
688 | |||
689 | return procUnitObj |
|
689 | return procUnitObj | |
690 |
|
690 | |||
691 | def run(self): |
|
691 | def run(self): | |
692 |
|
692 | |||
693 | is_ok = False |
|
693 | is_ok = False | |
694 |
|
694 | |||
695 | for opConfObj in self.opConfObjList: |
|
695 | for opConfObj in self.opConfObjList: | |
696 |
|
696 | |||
697 | kwargs = {} |
|
697 | kwargs = {} | |
698 | for parmConfObj in opConfObj.getParameterObjList(): |
|
698 | for parmConfObj in opConfObj.getParameterObjList(): | |
699 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
699 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': | |
700 | continue |
|
700 | continue | |
701 |
|
701 | |||
702 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
702 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
703 |
|
703 | |||
704 | #ini = time.time() |
|
704 | #ini = time.time() | |
705 |
|
705 | |||
706 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
706 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
707 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
707 | sts = self.procUnitObj.call(opType = opConfObj.type, | |
708 | opName = opConfObj.name, |
|
708 | opName = opConfObj.name, | |
709 | opId = opConfObj.id, |
|
709 | opId = opConfObj.id, | |
710 | ) |
|
710 | ) | |
711 |
|
711 | |||
712 | # total_time = time.time() - ini |
|
712 | # total_time = time.time() - ini | |
713 | # |
|
713 | # | |
714 | # if total_time > 0.002: |
|
714 | # if total_time > 0.002: | |
715 | # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time) |
|
715 | # print "%s::%s took %f seconds" %(self.name, opConfObj.name, total_time) | |
716 |
|
716 | |||
717 | is_ok = is_ok or sts |
|
717 | is_ok = is_ok or sts | |
718 |
|
718 | |||
719 | return is_ok |
|
719 | return is_ok | |
720 |
|
720 | |||
721 | def close(self): |
|
721 | def close(self): | |
722 |
|
722 | |||
723 | for opConfObj in self.opConfObjList: |
|
723 | for opConfObj in self.opConfObjList: | |
724 | if opConfObj.type == 'self': |
|
724 | if opConfObj.type == 'self': | |
725 | continue |
|
725 | continue | |
726 |
|
726 | |||
727 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
727 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) | |
728 | opObj.close() |
|
728 | opObj.close() | |
729 |
|
729 | |||
730 | self.procUnitObj.close() |
|
730 | self.procUnitObj.close() | |
731 |
|
731 | |||
732 | return |
|
732 | return | |
733 |
|
733 | |||
734 | class ReadUnitConf(ProcUnitConf): |
|
734 | class ReadUnitConf(ProcUnitConf): | |
735 |
|
735 | |||
736 | path = None |
|
736 | path = None | |
737 | startDate = None |
|
737 | startDate = None | |
738 | endDate = None |
|
738 | endDate = None | |
739 | startTime = None |
|
739 | startTime = None | |
740 | endTime = None |
|
740 | endTime = None | |
741 |
|
741 | |||
742 | ELEMENTNAME = 'ReadUnit' |
|
742 | ELEMENTNAME = 'ReadUnit' | |
743 |
|
743 | |||
744 | def __init__(self): |
|
744 | def __init__(self): | |
745 |
|
745 | |||
746 | self.id = None |
|
746 | self.id = None | |
747 | self.datatype = None |
|
747 | self.datatype = None | |
748 | self.name = None |
|
748 | self.name = None | |
749 | self.inputId = None |
|
749 | self.inputId = None | |
750 |
|
750 | |||
751 | self.parentId = None |
|
751 | self.parentId = None | |
752 |
|
752 | |||
753 | self.opConfObjList = [] |
|
753 | self.opConfObjList = [] | |
754 | self.opObjList = [] |
|
754 | self.opObjList = [] | |
755 |
|
755 | |||
756 | def getElementName(self): |
|
756 | def getElementName(self): | |
757 |
|
757 | |||
758 | return self.ELEMENTNAME |
|
758 | return self.ELEMENTNAME | |
759 |
|
759 | |||
760 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, queue=None, **kwargs): |
|
760 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, queue=None, **kwargs): | |
761 |
|
761 | |||
762 | #Compatible with old signal chain version |
|
762 | #Compatible with old signal chain version | |
763 | if datatype==None and name==None: |
|
763 | if datatype==None and name==None: | |
764 | raise ValueError, "datatype or name should be defined" |
|
764 | raise ValueError, "datatype or name should be defined" | |
765 |
|
765 | |||
766 | if name==None: |
|
766 | if name==None: | |
767 | if 'Reader' in datatype: |
|
767 | if 'Reader' in datatype: | |
768 | name = datatype |
|
768 | name = datatype | |
769 | else: |
|
769 | else: | |
770 | name = '%sReader' %(datatype) |
|
770 | name = '%sReader' %(datatype) | |
771 |
|
771 | |||
772 | if datatype==None: |
|
772 | if datatype==None: | |
773 | datatype = name.replace('Reader','') |
|
773 | datatype = name.replace('Reader','') | |
774 |
|
774 | |||
775 | self.id = id |
|
775 | self.id = id | |
776 | self.name = name |
|
776 | self.name = name | |
777 | self.datatype = datatype |
|
777 | self.datatype = datatype | |
778 |
|
778 | |||
779 | self.path = os.path.abspath(path) |
|
779 | self.path = os.path.abspath(path) | |
780 | self.startDate = startDate |
|
780 | self.startDate = startDate | |
781 | self.endDate = endDate |
|
781 | self.endDate = endDate | |
782 | self.startTime = startTime |
|
782 | self.startTime = startTime | |
783 | self.endTime = endTime |
|
783 | self.endTime = endTime | |
784 |
|
784 | |||
785 | self.inputId = '0' |
|
785 | self.inputId = '0' | |
786 | self.parentId = parentId |
|
786 | self.parentId = parentId | |
787 | self.queue = queue |
|
787 | self.queue = queue | |
788 | self.addRunOperation(**kwargs) |
|
788 | self.addRunOperation(**kwargs) | |
789 |
|
789 | |||
790 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): |
|
790 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): | |
791 |
|
791 | |||
792 | #Compatible with old signal chain version |
|
792 | #Compatible with old signal chain version | |
793 | if datatype==None and name==None: |
|
793 | if datatype==None and name==None: | |
794 | raise ValueError, "datatype or name should be defined" |
|
794 | raise ValueError, "datatype or name should be defined" | |
795 |
|
795 | |||
796 | if name==None: |
|
796 | if name==None: | |
797 | if 'Reader' in datatype: |
|
797 | if 'Reader' in datatype: | |
798 | name = datatype |
|
798 | name = datatype | |
799 | else: |
|
799 | else: | |
800 | name = '%sReader' %(datatype) |
|
800 | name = '%sReader' %(datatype) | |
801 |
|
801 | |||
802 | if datatype==None: |
|
802 | if datatype==None: | |
803 | datatype = name.replace('Reader','') |
|
803 | datatype = name.replace('Reader','') | |
804 |
|
804 | |||
805 | self.datatype = datatype |
|
805 | self.datatype = datatype | |
806 | self.name = name |
|
806 | self.name = name | |
807 | self.path = path |
|
807 | self.path = path | |
808 | self.startDate = startDate |
|
808 | self.startDate = startDate | |
809 | self.endDate = endDate |
|
809 | self.endDate = endDate | |
810 | self.startTime = startTime |
|
810 | self.startTime = startTime | |
811 | self.endTime = endTime |
|
811 | self.endTime = endTime | |
812 |
|
812 | |||
813 | self.inputId = '0' |
|
813 | self.inputId = '0' | |
814 | self.parentId = parentId |
|
814 | self.parentId = parentId | |
815 |
|
815 | |||
816 | self.updateRunOperation(**kwargs) |
|
816 | self.updateRunOperation(**kwargs) | |
817 |
|
817 | |||
818 | def removeOperations(self): |
|
818 | def removeOperations(self): | |
819 |
|
819 | |||
820 | for obj in self.opConfObjList: |
|
820 | for obj in self.opConfObjList: | |
821 | del obj |
|
821 | del obj | |
822 |
|
822 | |||
823 | self.opConfObjList = [] |
|
823 | self.opConfObjList = [] | |
824 |
|
824 | |||
825 | def addRunOperation(self, **kwargs): |
|
825 | def addRunOperation(self, **kwargs): | |
826 |
|
826 | |||
827 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
827 | opObj = self.addOperation(name = 'run', optype = 'self') | |
828 |
|
828 | |||
829 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
829 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
830 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
830 | opObj.addParameter(name='path' , value=self.path, format='str') | |
831 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
831 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
832 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
832 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
833 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
833 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
834 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
834 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
835 | opObj.addParameter(name='queue' , value=self.queue, format='obj') |
|
835 | opObj.addParameter(name='queue' , value=self.queue, format='obj') | |
836 |
|
836 | |||
837 | for key, value in kwargs.items(): |
|
837 | for key, value in kwargs.items(): | |
838 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
838 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
839 |
|
839 | |||
840 | return opObj |
|
840 | return opObj | |
841 |
|
841 | |||
842 | def updateRunOperation(self, **kwargs): |
|
842 | def updateRunOperation(self, **kwargs): | |
843 |
|
843 | |||
844 | opObj = self.getOperationObj(name = 'run') |
|
844 | opObj = self.getOperationObj(name = 'run') | |
845 | opObj.removeParameters() |
|
845 | opObj.removeParameters() | |
846 |
|
846 | |||
847 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
847 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
848 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
848 | opObj.addParameter(name='path' , value=self.path, format='str') | |
849 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
849 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
850 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
850 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
851 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
851 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
852 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
852 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
853 |
|
853 | |||
854 | for key, value in kwargs.items(): |
|
854 | for key, value in kwargs.items(): | |
855 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
855 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
856 |
|
856 | |||
857 | return opObj |
|
857 | return opObj | |
858 |
|
858 | |||
859 | # def makeXml(self, projectElement): |
|
859 | # def makeXml(self, projectElement): | |
860 | # |
|
860 | # | |
861 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
861 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
862 | # procUnitElement.set('id', str(self.id)) |
|
862 | # procUnitElement.set('id', str(self.id)) | |
863 | # procUnitElement.set('name', self.name) |
|
863 | # procUnitElement.set('name', self.name) | |
864 | # procUnitElement.set('datatype', self.datatype) |
|
864 | # procUnitElement.set('datatype', self.datatype) | |
865 | # procUnitElement.set('inputId', str(self.inputId)) |
|
865 | # procUnitElement.set('inputId', str(self.inputId)) | |
866 | # |
|
866 | # | |
867 | # for opConfObj in self.opConfObjList: |
|
867 | # for opConfObj in self.opConfObjList: | |
868 | # opConfObj.makeXml(procUnitElement) |
|
868 | # opConfObj.makeXml(procUnitElement) | |
869 |
|
869 | |||
870 | def readXml(self, upElement): |
|
870 | def readXml(self, upElement): | |
871 |
|
871 | |||
872 | self.id = upElement.get('id') |
|
872 | self.id = upElement.get('id') | |
873 | self.name = upElement.get('name') |
|
873 | self.name = upElement.get('name') | |
874 | self.datatype = upElement.get('datatype') |
|
874 | self.datatype = upElement.get('datatype') | |
875 | self.inputId = upElement.get('inputId') |
|
875 | self.inputId = upElement.get('inputId') | |
876 |
|
876 | |||
877 | if self.ELEMENTNAME == "ReadUnit": |
|
877 | if self.ELEMENTNAME == "ReadUnit": | |
878 | self.datatype = self.datatype.replace("Reader", "") |
|
878 | self.datatype = self.datatype.replace("Reader", "") | |
879 |
|
879 | |||
880 | if self.inputId == 'None': |
|
880 | if self.inputId == 'None': | |
881 | self.inputId = '0' |
|
881 | self.inputId = '0' | |
882 |
|
882 | |||
883 | self.opConfObjList = [] |
|
883 | self.opConfObjList = [] | |
884 |
|
884 | |||
885 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
885 | opElementList = upElement.iter(OperationConf().getElementName()) | |
886 |
|
886 | |||
887 | for opElement in opElementList: |
|
887 | for opElement in opElementList: | |
888 | opConfObj = OperationConf() |
|
888 | opConfObj = OperationConf() | |
889 | opConfObj.readXml(opElement) |
|
889 | opConfObj.readXml(opElement) | |
890 | self.opConfObjList.append(opConfObj) |
|
890 | self.opConfObjList.append(opConfObj) | |
891 |
|
891 | |||
892 | if opConfObj.name == 'run': |
|
892 | if opConfObj.name == 'run': | |
893 | self.path = opConfObj.getParameterValue('path') |
|
893 | self.path = opConfObj.getParameterValue('path') | |
894 | self.startDate = opConfObj.getParameterValue('startDate') |
|
894 | self.startDate = opConfObj.getParameterValue('startDate') | |
895 | self.endDate = opConfObj.getParameterValue('endDate') |
|
895 | self.endDate = opConfObj.getParameterValue('endDate') | |
896 | self.startTime = opConfObj.getParameterValue('startTime') |
|
896 | self.startTime = opConfObj.getParameterValue('startTime') | |
897 | self.endTime = opConfObj.getParameterValue('endTime') |
|
897 | self.endTime = opConfObj.getParameterValue('endTime') | |
898 |
|
898 | |||
899 | class Project(): |
|
899 | class Project(): | |
900 |
|
900 | |||
901 | id = None |
|
901 | id = None | |
902 | name = None |
|
902 | name = None | |
903 | description = None |
|
903 | description = None | |
904 | filename = None |
|
904 | filename = None | |
905 |
|
905 | |||
906 | procUnitConfObjDict = None |
|
906 | procUnitConfObjDict = None | |
907 |
|
907 | |||
908 | ELEMENTNAME = 'Project' |
|
908 | ELEMENTNAME = 'Project' | |
909 |
|
909 | |||
910 | plotterQueue = None |
|
910 | plotterQueue = None | |
911 |
|
911 | |||
912 | def __init__(self, plotter_queue=None): |
|
912 | def __init__(self, plotter_queue=None): | |
913 |
|
913 | |||
914 | self.id = None |
|
914 | self.id = None | |
915 | self.name = None |
|
915 | self.name = None | |
916 | self.description = None |
|
916 | self.description = None | |
917 |
|
917 | |||
918 | self.plotterQueue = plotter_queue |
|
918 | self.plotterQueue = plotter_queue | |
919 |
|
919 | |||
920 | self.procUnitConfObjDict = {} |
|
920 | self.procUnitConfObjDict = {} | |
921 |
|
921 | |||
922 | def __getNewId(self): |
|
922 | def __getNewId(self): | |
923 |
|
923 | |||
924 | idList = self.procUnitConfObjDict.keys() |
|
924 | idList = self.procUnitConfObjDict.keys() | |
925 |
|
925 | |||
926 | id = int(self.id)*10 |
|
926 | id = int(self.id)*10 | |
927 |
|
927 | |||
928 | while True: |
|
928 | while True: | |
929 | id += 1 |
|
929 | id += 1 | |
930 |
|
930 | |||
931 | if str(id) in idList: |
|
931 | if str(id) in idList: | |
932 | continue |
|
932 | continue | |
933 |
|
933 | |||
934 | break |
|
934 | break | |
935 |
|
935 | |||
936 | return str(id) |
|
936 | return str(id) | |
937 |
|
937 | |||
938 | def getElementName(self): |
|
938 | def getElementName(self): | |
939 |
|
939 | |||
940 | return self.ELEMENTNAME |
|
940 | return self.ELEMENTNAME | |
941 |
|
941 | |||
942 | def getId(self): |
|
942 | def getId(self): | |
943 |
|
943 | |||
944 | return self.id |
|
944 | return self.id | |
945 |
|
945 | |||
946 | def updateId(self, new_id): |
|
946 | def updateId(self, new_id): | |
947 |
|
947 | |||
948 | self.id = str(new_id) |
|
948 | self.id = str(new_id) | |
949 |
|
949 | |||
950 | keyList = self.procUnitConfObjDict.keys() |
|
950 | keyList = self.procUnitConfObjDict.keys() | |
951 | keyList.sort() |
|
951 | keyList.sort() | |
952 |
|
952 | |||
953 | n = 1 |
|
953 | n = 1 | |
954 | newProcUnitConfObjDict = {} |
|
954 | newProcUnitConfObjDict = {} | |
955 |
|
955 | |||
956 | for procKey in keyList: |
|
956 | for procKey in keyList: | |
957 |
|
957 | |||
958 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
958 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
959 | idProcUnit = str(int(self.id)*10 + n) |
|
959 | idProcUnit = str(int(self.id)*10 + n) | |
960 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
960 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) | |
961 |
|
961 | |||
962 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
962 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj | |
963 | n += 1 |
|
963 | n += 1 | |
964 |
|
964 | |||
965 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
965 | self.procUnitConfObjDict = newProcUnitConfObjDict | |
966 |
|
966 | |||
967 | def setup(self, id, name, description): |
|
967 | def setup(self, id, name, description): | |
968 |
|
968 | |||
969 | self.id = str(id) |
|
969 | self.id = str(id) | |
970 | self.name = name |
|
970 | self.name = name | |
971 | self.description = description |
|
971 | self.description = description | |
972 |
|
972 | |||
973 | def update(self, name, description): |
|
973 | def update(self, name, description): | |
974 |
|
974 | |||
975 | self.name = name |
|
975 | self.name = name | |
976 | self.description = description |
|
976 | self.description = description | |
977 |
|
977 | |||
978 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
978 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): | |
979 |
|
979 | |||
980 | if id is None: |
|
980 | if id is None: | |
981 | idReadUnit = self.__getNewId() |
|
981 | idReadUnit = self.__getNewId() | |
982 | else: |
|
982 | else: | |
983 | idReadUnit = str(id) |
|
983 | idReadUnit = str(id) | |
984 |
|
984 | |||
985 | readUnitConfObj = ReadUnitConf() |
|
985 | readUnitConfObj = ReadUnitConf() | |
986 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
986 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) | |
987 |
|
987 | |||
988 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
988 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
989 |
|
989 | |||
990 | return readUnitConfObj |
|
990 | return readUnitConfObj | |
991 |
|
991 | |||
992 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
992 | def addProcUnit(self, inputId='0', datatype=None, name=None): | |
993 |
|
993 | |||
994 | idProcUnit = self.__getNewId() |
|
994 | idProcUnit = self.__getNewId() | |
995 |
|
995 | |||
996 | procUnitConfObj = ProcUnitConf() |
|
996 | procUnitConfObj = ProcUnitConf() | |
997 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
997 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) | |
998 |
|
998 | |||
999 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
999 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1000 |
|
1000 | |||
1001 | return procUnitConfObj |
|
1001 | return procUnitConfObj | |
1002 |
|
1002 | |||
1003 | def removeProcUnit(self, id): |
|
1003 | def removeProcUnit(self, id): | |
1004 |
|
1004 | |||
1005 | if id in self.procUnitConfObjDict.keys(): |
|
1005 | if id in self.procUnitConfObjDict.keys(): | |
1006 | self.procUnitConfObjDict.pop(id) |
|
1006 | self.procUnitConfObjDict.pop(id) | |
1007 |
|
1007 | |||
1008 | def getReadUnitId(self): |
|
1008 | def getReadUnitId(self): | |
1009 |
|
1009 | |||
1010 | readUnitConfObj = self.getReadUnitObj() |
|
1010 | readUnitConfObj = self.getReadUnitObj() | |
1011 |
|
1011 | |||
1012 | return readUnitConfObj.id |
|
1012 | return readUnitConfObj.id | |
1013 |
|
1013 | |||
1014 | def getReadUnitObj(self): |
|
1014 | def getReadUnitObj(self): | |
1015 |
|
1015 | |||
1016 | for obj in self.procUnitConfObjDict.values(): |
|
1016 | for obj in self.procUnitConfObjDict.values(): | |
1017 | if obj.getElementName() == "ReadUnit": |
|
1017 | if obj.getElementName() == "ReadUnit": | |
1018 | return obj |
|
1018 | return obj | |
1019 |
|
1019 | |||
1020 | return None |
|
1020 | return None | |
1021 |
|
1021 | |||
1022 | def getProcUnitObj(self, id=None, name=None): |
|
1022 | def getProcUnitObj(self, id=None, name=None): | |
1023 |
|
1023 | |||
1024 | if id != None: |
|
1024 | if id != None: | |
1025 | return self.procUnitConfObjDict[id] |
|
1025 | return self.procUnitConfObjDict[id] | |
1026 |
|
1026 | |||
1027 | if name != None: |
|
1027 | if name != None: | |
1028 | return self.getProcUnitObjByName(name) |
|
1028 | return self.getProcUnitObjByName(name) | |
1029 |
|
1029 | |||
1030 | return None |
|
1030 | return None | |
1031 |
|
1031 | |||
1032 | def getProcUnitObjByName(self, name): |
|
1032 | def getProcUnitObjByName(self, name): | |
1033 |
|
1033 | |||
1034 | for obj in self.procUnitConfObjDict.values(): |
|
1034 | for obj in self.procUnitConfObjDict.values(): | |
1035 | if obj.name == name: |
|
1035 | if obj.name == name: | |
1036 | return obj |
|
1036 | return obj | |
1037 |
|
1037 | |||
1038 | return None |
|
1038 | return None | |
1039 |
|
1039 | |||
1040 | def procUnitItems(self): |
|
1040 | def procUnitItems(self): | |
1041 |
|
1041 | |||
1042 | return self.procUnitConfObjDict.items() |
|
1042 | return self.procUnitConfObjDict.items() | |
1043 |
|
1043 | |||
1044 | def makeXml(self): |
|
1044 | def makeXml(self): | |
1045 |
|
1045 | |||
1046 | projectElement = Element('Project') |
|
1046 | projectElement = Element('Project') | |
1047 | projectElement.set('id', str(self.id)) |
|
1047 | projectElement.set('id', str(self.id)) | |
1048 | projectElement.set('name', self.name) |
|
1048 | projectElement.set('name', self.name) | |
1049 | projectElement.set('description', self.description) |
|
1049 | projectElement.set('description', self.description) | |
1050 |
|
1050 | |||
1051 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1051 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1052 | procUnitConfObj.makeXml(projectElement) |
|
1052 | procUnitConfObj.makeXml(projectElement) | |
1053 |
|
1053 | |||
1054 | self.projectElement = projectElement |
|
1054 | self.projectElement = projectElement | |
1055 |
|
1055 | |||
1056 | def writeXml(self, filename=None): |
|
1056 | def writeXml(self, filename=None): | |
1057 |
|
1057 | |||
1058 | if filename == None: |
|
1058 | if filename == None: | |
1059 | if self.filename: |
|
1059 | if self.filename: | |
1060 | filename = self.filename |
|
1060 | filename = self.filename | |
1061 | else: |
|
1061 | else: | |
1062 | filename = "schain.xml" |
|
1062 | filename = "schain.xml" | |
1063 |
|
1063 | |||
1064 | if not filename: |
|
1064 | if not filename: | |
1065 | print "filename has not been defined. Use setFilename(filename) for do it." |
|
1065 | print "filename has not been defined. Use setFilename(filename) for do it." | |
1066 | return 0 |
|
1066 | return 0 | |
1067 |
|
1067 | |||
1068 | abs_file = os.path.abspath(filename) |
|
1068 | abs_file = os.path.abspath(filename) | |
1069 |
|
1069 | |||
1070 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
1070 | if not os.access(os.path.dirname(abs_file), os.W_OK): | |
1071 | print "No write permission on %s" %os.path.dirname(abs_file) |
|
1071 | print "No write permission on %s" %os.path.dirname(abs_file) | |
1072 | return 0 |
|
1072 | return 0 | |
1073 |
|
1073 | |||
1074 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
1074 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): | |
1075 | print "File %s already exists and it could not be overwriten" %abs_file |
|
1075 | print "File %s already exists and it could not be overwriten" %abs_file | |
1076 | return 0 |
|
1076 | return 0 | |
1077 |
|
1077 | |||
1078 | self.makeXml() |
|
1078 | self.makeXml() | |
1079 |
|
1079 | |||
1080 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
1080 | ElementTree(self.projectElement).write(abs_file, method='xml') | |
1081 |
|
1081 | |||
1082 | self.filename = abs_file |
|
1082 | self.filename = abs_file | |
1083 |
|
1083 | |||
1084 | return 1 |
|
1084 | return 1 | |
1085 |
|
1085 | |||
1086 | def readXml(self, filename = None): |
|
1086 | def readXml(self, filename = None): | |
1087 |
|
1087 | |||
1088 | if not filename: |
|
1088 | if not filename: | |
1089 | print "filename is not defined" |
|
1089 | print "filename is not defined" | |
1090 | return 0 |
|
1090 | return 0 | |
1091 |
|
1091 | |||
1092 | abs_file = os.path.abspath(filename) |
|
1092 | abs_file = os.path.abspath(filename) | |
1093 |
|
1093 | |||
1094 | if not os.path.isfile(abs_file): |
|
1094 | if not os.path.isfile(abs_file): | |
1095 | print "%s file does not exist" %abs_file |
|
1095 | print "%s file does not exist" %abs_file | |
1096 | return 0 |
|
1096 | return 0 | |
1097 |
|
1097 | |||
1098 | self.projectElement = None |
|
1098 | self.projectElement = None | |
1099 | self.procUnitConfObjDict = {} |
|
1099 | self.procUnitConfObjDict = {} | |
1100 |
|
1100 | |||
1101 | try: |
|
1101 | try: | |
1102 | self.projectElement = ElementTree().parse(abs_file) |
|
1102 | self.projectElement = ElementTree().parse(abs_file) | |
1103 | except: |
|
1103 | except: | |
1104 | print "Error reading %s, verify file format" %filename |
|
1104 | print "Error reading %s, verify file format" %filename | |
1105 | return 0 |
|
1105 | return 0 | |
1106 |
|
1106 | |||
1107 | self.project = self.projectElement.tag |
|
1107 | self.project = self.projectElement.tag | |
1108 |
|
1108 | |||
1109 | self.id = self.projectElement.get('id') |
|
1109 | self.id = self.projectElement.get('id') | |
1110 | self.name = self.projectElement.get('name') |
|
1110 | self.name = self.projectElement.get('name') | |
1111 | self.description = self.projectElement.get('description') |
|
1111 | self.description = self.projectElement.get('description') | |
1112 |
|
1112 | |||
1113 | readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) |
|
1113 | readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName()) | |
1114 |
|
1114 | |||
1115 | for readUnitElement in readUnitElementList: |
|
1115 | for readUnitElement in readUnitElementList: | |
1116 | readUnitConfObj = ReadUnitConf() |
|
1116 | readUnitConfObj = ReadUnitConf() | |
1117 | readUnitConfObj.readXml(readUnitElement) |
|
1117 | readUnitConfObj.readXml(readUnitElement) | |
1118 |
|
1118 | |||
1119 | if readUnitConfObj.parentId == None: |
|
1119 | if readUnitConfObj.parentId == None: | |
1120 | readUnitConfObj.parentId = self.id |
|
1120 | readUnitConfObj.parentId = self.id | |
1121 |
|
1121 | |||
1122 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1122 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
1123 |
|
1123 | |||
1124 | procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) |
|
1124 | procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName()) | |
1125 |
|
1125 | |||
1126 | for procUnitElement in procUnitElementList: |
|
1126 | for procUnitElement in procUnitElementList: | |
1127 | procUnitConfObj = ProcUnitConf() |
|
1127 | procUnitConfObj = ProcUnitConf() | |
1128 | procUnitConfObj.readXml(procUnitElement) |
|
1128 | procUnitConfObj.readXml(procUnitElement) | |
1129 |
|
1129 | |||
1130 | if procUnitConfObj.parentId == None: |
|
1130 | if procUnitConfObj.parentId == None: | |
1131 | procUnitConfObj.parentId = self.id |
|
1131 | procUnitConfObj.parentId = self.id | |
1132 |
|
1132 | |||
1133 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1133 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1134 |
|
1134 | |||
1135 | self.filename = abs_file |
|
1135 | self.filename = abs_file | |
1136 |
|
1136 | |||
1137 | return 1 |
|
1137 | return 1 | |
1138 |
|
1138 | |||
1139 | def printattr(self): |
|
1139 | def printattr(self): | |
1140 |
|
1140 | |||
1141 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
1141 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
1142 | self.name, |
|
1142 | self.name, | |
1143 | self.description) |
|
1143 | self.description) | |
1144 |
|
1144 | |||
1145 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1145 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1146 | procUnitConfObj.printattr() |
|
1146 | procUnitConfObj.printattr() | |
1147 |
|
1147 | |||
1148 | def createObjects(self): |
|
1148 | def createObjects(self): | |
1149 |
|
1149 | |||
1150 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1150 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1151 | procUnitConfObj.createObjects(self.plotterQueue) |
|
1151 | procUnitConfObj.createObjects(self.plotterQueue) | |
1152 |
|
1152 | |||
1153 | def __connect(self, objIN, thisObj): |
|
1153 | def __connect(self, objIN, thisObj): | |
1154 |
|
1154 | |||
1155 | thisObj.setInput(objIN.getOutputObj()) |
|
1155 | thisObj.setInput(objIN.getOutputObj()) | |
1156 |
|
1156 | |||
1157 | def connectObjects(self): |
|
1157 | def connectObjects(self): | |
1158 |
|
1158 | |||
1159 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1159 | for thisPUConfObj in self.procUnitConfObjDict.values(): | |
1160 |
|
1160 | |||
1161 | inputId = thisPUConfObj.getInputId() |
|
1161 | inputId = thisPUConfObj.getInputId() | |
1162 |
|
1162 | |||
1163 | if int(inputId) == 0: |
|
1163 | if int(inputId) == 0: | |
1164 | continue |
|
1164 | continue | |
1165 |
|
1165 | |||
1166 | #Get input object |
|
1166 | #Get input object | |
1167 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1167 | puConfINObj = self.procUnitConfObjDict[inputId] | |
1168 | puObjIN = puConfINObj.getProcUnitObj() |
|
1168 | puObjIN = puConfINObj.getProcUnitObj() | |
1169 |
|
1169 | |||
1170 | #Get current object |
|
1170 | #Get current object | |
1171 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1171 | thisPUObj = thisPUConfObj.getProcUnitObj() | |
1172 |
|
1172 | |||
1173 | self.__connect(puObjIN, thisPUObj) |
|
1173 | self.__connect(puObjIN, thisPUObj) | |
1174 |
|
1174 | |||
1175 | def __handleError(self, procUnitConfObj, send_email=True): |
|
1175 | def __handleError(self, procUnitConfObj, send_email=True): | |
1176 |
|
1176 | |||
1177 | import socket |
|
1177 | import socket | |
1178 |
|
1178 | |||
1179 | err = traceback.format_exception(sys.exc_info()[0], |
|
1179 | err = traceback.format_exception(sys.exc_info()[0], | |
1180 | sys.exc_info()[1], |
|
1180 | sys.exc_info()[1], | |
1181 | sys.exc_info()[2]) |
|
1181 | sys.exc_info()[2]) | |
1182 |
|
1182 | |||
1183 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1183 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1184 | print "***** %s" %err[-1] |
|
1184 | print "***** %s" %err[-1] | |
1185 |
|
1185 | |||
1186 | message = "".join(err) |
|
1186 | message = "".join(err) | |
1187 |
|
1187 | |||
1188 | sys.stderr.write(message) |
|
1188 | sys.stderr.write(message) | |
1189 |
|
1189 | |||
1190 | if not send_email: |
|
1190 | if not send_email: | |
1191 | return |
|
1191 | return | |
1192 |
|
1192 | |||
1193 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) |
|
1193 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) | |
1194 |
|
1194 | |||
1195 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
1195 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |
1196 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
1196 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |
1197 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
1197 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |
1198 | subtitle += "Configuration file: %s\n" %self.filename |
|
1198 | subtitle += "Configuration file: %s\n" %self.filename | |
1199 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
1199 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |
1200 |
|
1200 | |||
1201 | readUnitConfObj = self.getReadUnitObj() |
|
1201 | readUnitConfObj = self.getReadUnitObj() | |
1202 | if readUnitConfObj: |
|
1202 | if readUnitConfObj: | |
1203 | subtitle += "\nInput parameters:\n" |
|
1203 | subtitle += "\nInput parameters:\n" | |
1204 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path |
|
1204 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path | |
1205 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype |
|
1205 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype | |
1206 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate |
|
1206 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate | |
1207 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate |
|
1207 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate | |
1208 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime |
|
1208 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime | |
1209 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime |
|
1209 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime | |
1210 |
|
1210 | |||
1211 | adminObj = schainpy.admin.SchainNotify() |
|
1211 | adminObj = schainpy.admin.SchainNotify() | |
1212 | adminObj.sendAlert(message=message, |
|
1212 | adminObj.sendAlert(message=message, | |
1213 | subject=subject, |
|
1213 | subject=subject, | |
1214 | subtitle=subtitle, |
|
1214 | subtitle=subtitle, | |
1215 | filename=self.filename) |
|
1215 | filename=self.filename) | |
1216 |
|
1216 | |||
1217 | def isPaused(self): |
|
1217 | def isPaused(self): | |
1218 | return 0 |
|
1218 | return 0 | |
1219 |
|
1219 | |||
1220 | def isStopped(self): |
|
1220 | def isStopped(self): | |
1221 | return 0 |
|
1221 | return 0 | |
1222 |
|
1222 | |||
1223 | def runController(self): |
|
1223 | def runController(self): | |
1224 | """ |
|
1224 | """ | |
1225 | returns 0 when this process has been stopped, 1 otherwise |
|
1225 | returns 0 when this process has been stopped, 1 otherwise | |
1226 | """ |
|
1226 | """ | |
1227 |
|
1227 | |||
1228 | if self.isPaused(): |
|
1228 | if self.isPaused(): | |
1229 | print "Process suspended" |
|
1229 | print "Process suspended" | |
1230 |
|
1230 | |||
1231 | while True: |
|
1231 | while True: | |
1232 | sleep(0.1) |
|
1232 | sleep(0.1) | |
1233 |
|
1233 | |||
1234 | if not self.isPaused(): |
|
1234 | if not self.isPaused(): | |
1235 | break |
|
1235 | break | |
1236 |
|
1236 | |||
1237 | if self.isStopped(): |
|
1237 | if self.isStopped(): | |
1238 | break |
|
1238 | break | |
1239 |
|
1239 | |||
1240 | print "Process reinitialized" |
|
1240 | print "Process reinitialized" | |
1241 |
|
1241 | |||
1242 | if self.isStopped(): |
|
1242 | if self.isStopped(): | |
1243 | print "Process stopped" |
|
1243 | print "Process stopped" | |
1244 | return 0 |
|
1244 | return 0 | |
1245 |
|
1245 | |||
1246 | return 1 |
|
1246 | return 1 | |
1247 |
|
1247 | |||
1248 | def setFilename(self, filename): |
|
1248 | def setFilename(self, filename): | |
1249 |
|
1249 | |||
1250 | self.filename = filename |
|
1250 | self.filename = filename | |
1251 |
|
1251 | |||
1252 | def setPlotterQueue(self, plotter_queue): |
|
1252 | def setPlotterQueue(self, plotter_queue): | |
1253 |
|
1253 | |||
1254 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1254 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1255 |
|
1255 | |||
1256 | def getPlotterQueue(self): |
|
1256 | def getPlotterQueue(self): | |
1257 |
|
1257 | |||
1258 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1258 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1259 |
|
1259 | |||
1260 | def useExternalPlotter(self): |
|
1260 | def useExternalPlotter(self): | |
1261 |
|
1261 | |||
1262 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" |
|
1262 | raise NotImplementedError, "Use schainpy.controller_api.ControllerThread instead Project class" | |
1263 |
|
1263 | |||
1264 | def run(self): |
|
1264 | def run(self): | |
1265 |
|
1265 | |||
1266 |
|
1266 | |||
1267 | print "*"*60 |
|
1267 | print "*"*60 | |
1268 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ |
|
1268 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ | |
1269 | print "*"*60 |
|
1269 | print "*"*60 | |
1270 |
|
1270 | |||
1271 |
|
1271 | |||
1272 | keyList = self.procUnitConfObjDict.keys() |
|
1272 | keyList = self.procUnitConfObjDict.keys() | |
1273 | keyList.sort() |
|
1273 | keyList.sort() | |
1274 |
|
1274 | |||
1275 | while(True): |
|
1275 | while(True): | |
1276 |
|
1276 | |||
1277 | is_ok = False |
|
1277 | is_ok = False | |
1278 |
|
1278 | |||
1279 | for procKey in keyList: |
|
1279 | for procKey in keyList: | |
1280 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1280 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
1281 |
|
1281 | |||
1282 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1282 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1283 |
|
1283 | |||
1284 | try: |
|
1284 | try: | |
1285 | sts = procUnitConfObj.run() |
|
1285 | sts = procUnitConfObj.run() | |
1286 | is_ok = is_ok or sts |
|
1286 | is_ok = is_ok or sts | |
1287 | except KeyboardInterrupt: |
|
1287 | except KeyboardInterrupt: | |
1288 | is_ok = False |
|
1288 | is_ok = False | |
1289 | break |
|
1289 | break | |
1290 | except ValueError, e: |
|
1290 | except ValueError, e: | |
1291 | sleep(0.5) |
|
1291 | sleep(0.5) | |
1292 | self.__handleError(procUnitConfObj, send_email=True) |
|
1292 | self.__handleError(procUnitConfObj, send_email=True) | |
1293 | is_ok = False |
|
1293 | is_ok = False | |
1294 | break |
|
1294 | break | |
1295 | except: |
|
1295 | except: | |
1296 | sleep(0.5) |
|
1296 | sleep(0.5) | |
1297 | self.__handleError(procUnitConfObj) |
|
1297 | self.__handleError(procUnitConfObj) | |
1298 | is_ok = False |
|
1298 | is_ok = False | |
1299 | break |
|
1299 | break | |
1300 |
|
1300 | |||
1301 | #If every process unit finished so end process |
|
1301 | #If every process unit finished so end process | |
1302 | if not(is_ok): |
|
1302 | if not(is_ok): | |
1303 | # print "Every process unit have finished" |
|
1303 | # print "Every process unit have finished" | |
1304 | break |
|
1304 | break | |
1305 |
|
1305 | |||
1306 | if not self.runController(): |
|
1306 | if not self.runController(): | |
1307 | break |
|
1307 | break | |
1308 |
|
1308 | |||
1309 | #Closing every process |
|
1309 | #Closing every process | |
1310 | for procKey in keyList: |
|
1310 | for procKey in keyList: | |
1311 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1311 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1312 | procUnitConfObj.close() |
|
1312 | procUnitConfObj.close() | |
1313 |
|
1313 | |||
1314 | print "Process finished" |
|
1314 | print "Process finished" | |
1315 |
|
1315 | |||
1316 | def start(self, filename=None): |
|
1316 | def start(self, filename=None): | |
1317 |
|
1317 | |||
1318 | self.writeXml(filename) |
|
1318 | self.writeXml(filename) | |
1319 | self.createObjects() |
|
1319 | self.createObjects() | |
1320 | self.connectObjects() |
|
1320 | self.connectObjects() | |
1321 | self.run() |
|
1321 | self.run() |
@@ -1,1228 +1,1220 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import copy |
|
7 | import copy | |
8 | import numpy |
|
8 | import numpy | |
9 | import datetime |
|
9 | import datetime | |
10 |
|
10 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
11 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 | from schainpy import cSchain |
|
12 | from schainpy import cSchain | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | def getNumpyDtype(dataTypeCode): |
|
15 | def getNumpyDtype(dataTypeCode): | |
16 |
|
16 | |||
17 | if dataTypeCode == 0: |
|
17 | if dataTypeCode == 0: | |
18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
19 | elif dataTypeCode == 1: |
|
19 | elif dataTypeCode == 1: | |
20 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
20 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
21 | elif dataTypeCode == 2: |
|
21 | elif dataTypeCode == 2: | |
22 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
22 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
23 | elif dataTypeCode == 3: |
|
23 | elif dataTypeCode == 3: | |
24 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
24 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
25 | elif dataTypeCode == 4: |
|
25 | elif dataTypeCode == 4: | |
26 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
26 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
27 | elif dataTypeCode == 5: |
|
27 | elif dataTypeCode == 5: | |
28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
29 | else: |
|
29 | else: | |
30 | raise ValueError, 'dataTypeCode was not defined' |
|
30 | raise ValueError, 'dataTypeCode was not defined' | |
31 |
|
31 | |||
32 | return numpyDtype |
|
32 | return numpyDtype | |
33 |
|
33 | |||
34 | def getDataTypeCode(numpyDtype): |
|
34 | def getDataTypeCode(numpyDtype): | |
35 |
|
35 | |||
36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): | |
37 | datatype = 0 |
|
37 | datatype = 0 | |
38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): | |
39 | datatype = 1 |
|
39 | datatype = 1 | |
40 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): |
|
40 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): | |
41 | datatype = 2 |
|
41 | datatype = 2 | |
42 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): |
|
42 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): | |
43 | datatype = 3 |
|
43 | datatype = 3 | |
44 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): |
|
44 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): | |
45 | datatype = 4 |
|
45 | datatype = 4 | |
46 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): |
|
46 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): | |
47 | datatype = 5 |
|
47 | datatype = 5 | |
48 | else: |
|
48 | else: | |
49 | datatype = None |
|
49 | datatype = None | |
50 |
|
50 | |||
51 | return datatype |
|
51 | return datatype | |
52 |
|
52 | |||
53 | def hildebrand_sekhon(data, navg): |
|
53 | def hildebrand_sekhon(data, navg): | |
54 | """ |
|
54 | """ | |
55 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
55 | This method is for the objective determination of the noise level in Doppler spectra. This | |
56 | implementation technique is based on the fact that the standard deviation of the spectral |
|
56 | implementation technique is based on the fact that the standard deviation of the spectral | |
57 | densities is equal to the mean spectral density for white Gaussian noise |
|
57 | densities is equal to the mean spectral density for white Gaussian noise | |
58 |
|
58 | |||
59 | Inputs: |
|
59 | Inputs: | |
60 | Data : heights |
|
60 | Data : heights | |
61 | navg : numbers of averages |
|
61 | navg : numbers of averages | |
62 |
|
62 | |||
63 | Return: |
|
63 | Return: | |
64 | -1 : any error |
|
64 | -1 : any error | |
65 | anoise : noise's level |
|
65 | anoise : noise's level | |
66 | """ |
|
66 | """ | |
67 |
|
67 | |||
68 | sortdata = numpy.sort(data, axis=None) |
|
68 | sortdata = numpy.sort(data, axis=None) | |
69 | # lenOfData = len(sortdata) |
|
69 | # lenOfData = len(sortdata) | |
70 | # nums_min = lenOfData*0.2 |
|
70 | # nums_min = lenOfData*0.2 | |
71 | # |
|
71 | # | |
72 | # if nums_min <= 5: |
|
72 | # if nums_min <= 5: | |
73 | # nums_min = 5 |
|
73 | # nums_min = 5 | |
74 | # |
|
74 | # | |
75 | # sump = 0. |
|
75 | # sump = 0. | |
76 | # |
|
76 | # | |
77 | # sumq = 0. |
|
77 | # sumq = 0. | |
78 | # |
|
78 | # | |
79 | # j = 0 |
|
79 | # j = 0 | |
80 | # |
|
80 | # | |
81 | # cont = 1 |
|
81 | # cont = 1 | |
82 | # |
|
82 | # | |
83 | # while((cont==1)and(j<lenOfData)): |
|
83 | # while((cont==1)and(j<lenOfData)): | |
84 | # |
|
84 | # | |
85 | # sump += sortdata[j] |
|
85 | # sump += sortdata[j] | |
86 | # |
|
86 | # | |
87 | # sumq += sortdata[j]**2 |
|
87 | # sumq += sortdata[j]**2 | |
88 | # |
|
88 | # | |
89 | # if j > nums_min: |
|
89 | # if j > nums_min: | |
90 | # rtest = float(j)/(j-1) + 1.0/navg |
|
90 | # rtest = float(j)/(j-1) + 1.0/navg | |
91 | # if ((sumq*j) > (rtest*sump**2)): |
|
91 | # if ((sumq*j) > (rtest*sump**2)): | |
92 | # j = j - 1 |
|
92 | # j = j - 1 | |
93 | # sump = sump - sortdata[j] |
|
93 | # sump = sump - sortdata[j] | |
94 | # sumq = sumq - sortdata[j]**2 |
|
94 | # sumq = sumq - sortdata[j]**2 | |
95 | # cont = 0 |
|
95 | # cont = 0 | |
96 | # |
|
96 | # | |
97 | # j += 1 |
|
97 | # j += 1 | |
98 | # |
|
98 | # | |
99 | # lnoise = sump /j |
|
99 | # lnoise = sump /j | |
100 | # |
|
100 | # | |
101 | # return lnoise |
|
101 | # return lnoise | |
102 |
|
102 | |||
103 | return cSchain.hildebrand_sekhon(sortdata, navg) |
|
103 | return cSchain.hildebrand_sekhon(sortdata, navg) | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | class Beam: |
|
106 | class Beam: | |
107 |
|
107 | |||
108 | def __init__(self): |
|
108 | def __init__(self): | |
109 | self.codeList = [] |
|
109 | self.codeList = [] | |
110 | self.azimuthList = [] |
|
110 | self.azimuthList = [] | |
111 | self.zenithList = [] |
|
111 | self.zenithList = [] | |
112 |
|
112 | |||
113 | class GenericData(object): |
|
113 | class GenericData(object): | |
114 |
|
114 | |||
115 | flagNoData = True |
|
115 | flagNoData = True | |
116 |
|
116 | |||
117 | def __init__(self): |
|
|||
118 |
|
||||
119 | raise NotImplementedError |
|
|||
120 |
|
||||
121 | def copy(self, inputObj=None): |
|
117 | def copy(self, inputObj=None): | |
122 |
|
118 | |||
123 | if inputObj == None: |
|
119 | if inputObj == None: | |
124 | return copy.deepcopy(self) |
|
120 | return copy.deepcopy(self) | |
125 |
|
121 | |||
126 | for key in inputObj.__dict__.keys(): |
|
122 | for key in inputObj.__dict__.keys(): | |
127 |
|
123 | |||
128 | attribute = inputObj.__dict__[key] |
|
124 | attribute = inputObj.__dict__[key] | |
129 |
|
125 | |||
130 | #If this attribute is a tuple or list |
|
126 | #If this attribute is a tuple or list | |
131 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
127 | if type(inputObj.__dict__[key]) in (tuple, list): | |
132 | self.__dict__[key] = attribute[:] |
|
128 | self.__dict__[key] = attribute[:] | |
133 | continue |
|
129 | continue | |
134 |
|
130 | |||
135 | #If this attribute is another object or instance |
|
131 | #If this attribute is another object or instance | |
136 | if hasattr(attribute, '__dict__'): |
|
132 | if hasattr(attribute, '__dict__'): | |
137 | self.__dict__[key] = attribute.copy() |
|
133 | self.__dict__[key] = attribute.copy() | |
138 | continue |
|
134 | continue | |
139 |
|
135 | |||
140 | self.__dict__[key] = inputObj.__dict__[key] |
|
136 | self.__dict__[key] = inputObj.__dict__[key] | |
141 |
|
137 | |||
142 | def deepcopy(self): |
|
138 | def deepcopy(self): | |
143 |
|
139 | |||
144 | return copy.deepcopy(self) |
|
140 | return copy.deepcopy(self) | |
145 |
|
141 | |||
146 | def isEmpty(self): |
|
142 | def isEmpty(self): | |
147 |
|
143 | |||
148 | return self.flagNoData |
|
144 | return self.flagNoData | |
149 |
|
145 | |||
150 | class JROData(GenericData): |
|
146 | class JROData(GenericData): | |
151 |
|
147 | |||
152 | # m_BasicHeader = BasicHeader() |
|
148 | # m_BasicHeader = BasicHeader() | |
153 | # m_ProcessingHeader = ProcessingHeader() |
|
149 | # m_ProcessingHeader = ProcessingHeader() | |
154 |
|
150 | |||
155 | systemHeaderObj = SystemHeader() |
|
151 | systemHeaderObj = SystemHeader() | |
156 |
|
152 | |||
157 | radarControllerHeaderObj = RadarControllerHeader() |
|
153 | radarControllerHeaderObj = RadarControllerHeader() | |
158 |
|
154 | |||
159 | # data = None |
|
155 | # data = None | |
160 |
|
156 | |||
161 | type = None |
|
157 | type = None | |
162 |
|
158 | |||
163 | datatype = None #dtype but in string |
|
159 | datatype = None #dtype but in string | |
164 |
|
160 | |||
165 | # dtype = None |
|
161 | # dtype = None | |
166 |
|
162 | |||
167 | # nChannels = None |
|
163 | # nChannels = None | |
168 |
|
164 | |||
169 | # nHeights = None |
|
165 | # nHeights = None | |
170 |
|
166 | |||
171 | nProfiles = None |
|
167 | nProfiles = None | |
172 |
|
168 | |||
173 | heightList = None |
|
169 | heightList = None | |
174 |
|
170 | |||
175 | channelList = None |
|
171 | channelList = None | |
176 |
|
172 | |||
177 | flagDiscontinuousBlock = False |
|
173 | flagDiscontinuousBlock = False | |
178 |
|
174 | |||
179 | useLocalTime = False |
|
175 | useLocalTime = False | |
180 |
|
176 | |||
181 | utctime = None |
|
177 | utctime = None | |
182 |
|
178 | |||
183 | timeZone = None |
|
179 | timeZone = None | |
184 |
|
180 | |||
185 | dstFlag = None |
|
181 | dstFlag = None | |
186 |
|
182 | |||
187 | errorCount = None |
|
183 | errorCount = None | |
188 |
|
184 | |||
189 | blocksize = None |
|
185 | blocksize = None | |
190 |
|
186 | |||
191 | # nCode = None |
|
187 | # nCode = None | |
192 | # |
|
188 | # | |
193 | # nBaud = None |
|
189 | # nBaud = None | |
194 | # |
|
190 | # | |
195 | # code = None |
|
191 | # code = None | |
196 |
|
192 | |||
197 | flagDecodeData = False #asumo q la data no esta decodificada |
|
193 | flagDecodeData = False #asumo q la data no esta decodificada | |
198 |
|
194 | |||
199 | flagDeflipData = False #asumo q la data no esta sin flip |
|
195 | flagDeflipData = False #asumo q la data no esta sin flip | |
200 |
|
196 | |||
201 | flagShiftFFT = False |
|
197 | flagShiftFFT = False | |
202 |
|
198 | |||
203 | # ippSeconds = None |
|
199 | # ippSeconds = None | |
204 |
|
200 | |||
205 | # timeInterval = None |
|
201 | # timeInterval = None | |
206 |
|
202 | |||
207 | nCohInt = None |
|
203 | nCohInt = None | |
208 |
|
204 | |||
209 | # noise = None |
|
205 | # noise = None | |
210 |
|
206 | |||
211 | windowOfFilter = 1 |
|
207 | windowOfFilter = 1 | |
212 |
|
208 | |||
213 | #Speed of ligth |
|
209 | #Speed of ligth | |
214 | C = 3e8 |
|
210 | C = 3e8 | |
215 |
|
211 | |||
216 | frequency = 49.92e6 |
|
212 | frequency = 49.92e6 | |
217 |
|
213 | |||
218 | realtime = False |
|
214 | realtime = False | |
219 |
|
215 | |||
220 | beacon_heiIndexList = None |
|
216 | beacon_heiIndexList = None | |
221 |
|
217 | |||
222 | last_block = None |
|
218 | last_block = None | |
223 |
|
219 | |||
224 | blocknow = None |
|
220 | blocknow = None | |
225 |
|
221 | |||
226 | azimuth = None |
|
222 | azimuth = None | |
227 |
|
223 | |||
228 | zenith = None |
|
224 | zenith = None | |
229 |
|
225 | |||
230 | beam = Beam() |
|
226 | beam = Beam() | |
231 |
|
227 | |||
232 | profileIndex = None |
|
228 | profileIndex = None | |
233 |
|
229 | |||
234 | def __init__(self): |
|
|||
235 |
|
||||
236 | raise NotImplementedError |
|
|||
237 |
|
||||
238 | def getNoise(self): |
|
230 | def getNoise(self): | |
239 |
|
231 | |||
240 | raise NotImplementedError |
|
232 | raise NotImplementedError | |
241 |
|
233 | |||
242 | def getNChannels(self): |
|
234 | def getNChannels(self): | |
243 |
|
235 | |||
244 | return len(self.channelList) |
|
236 | return len(self.channelList) | |
245 |
|
237 | |||
246 | def getChannelIndexList(self): |
|
238 | def getChannelIndexList(self): | |
247 |
|
239 | |||
248 | return range(self.nChannels) |
|
240 | return range(self.nChannels) | |
249 |
|
241 | |||
250 | def getNHeights(self): |
|
242 | def getNHeights(self): | |
251 |
|
243 | |||
252 | return len(self.heightList) |
|
244 | return len(self.heightList) | |
253 |
|
245 | |||
254 | def getHeiRange(self, extrapoints=0): |
|
246 | def getHeiRange(self, extrapoints=0): | |
255 |
|
247 | |||
256 | heis = self.heightList |
|
248 | heis = self.heightList | |
257 | # deltah = self.heightList[1] - self.heightList[0] |
|
249 | # deltah = self.heightList[1] - self.heightList[0] | |
258 | # |
|
250 | # | |
259 | # heis.append(self.heightList[-1]) |
|
251 | # heis.append(self.heightList[-1]) | |
260 |
|
252 | |||
261 | return heis |
|
253 | return heis | |
262 |
|
254 | |||
263 | def getDeltaH(self): |
|
255 | def getDeltaH(self): | |
264 |
|
256 | |||
265 | delta = self.heightList[1] - self.heightList[0] |
|
257 | delta = self.heightList[1] - self.heightList[0] | |
266 |
|
258 | |||
267 | return delta |
|
259 | return delta | |
268 |
|
260 | |||
269 | def getltctime(self): |
|
261 | def getltctime(self): | |
270 |
|
262 | |||
271 | if self.useLocalTime: |
|
263 | if self.useLocalTime: | |
272 | return self.utctime - self.timeZone*60 |
|
264 | return self.utctime - self.timeZone*60 | |
273 |
|
265 | |||
274 | return self.utctime |
|
266 | return self.utctime | |
275 |
|
267 | |||
276 | def getDatatime(self): |
|
268 | def getDatatime(self): | |
277 |
|
269 | |||
278 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
270 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
279 | return datatimeValue |
|
271 | return datatimeValue | |
280 |
|
272 | |||
281 | def getTimeRange(self): |
|
273 | def getTimeRange(self): | |
282 |
|
274 | |||
283 | datatime = [] |
|
275 | datatime = [] | |
284 |
|
276 | |||
285 | datatime.append(self.ltctime) |
|
277 | datatime.append(self.ltctime) | |
286 | datatime.append(self.ltctime + self.timeInterval+1) |
|
278 | datatime.append(self.ltctime + self.timeInterval+1) | |
287 |
|
279 | |||
288 | datatime = numpy.array(datatime) |
|
280 | datatime = numpy.array(datatime) | |
289 |
|
281 | |||
290 | return datatime |
|
282 | return datatime | |
291 |
|
283 | |||
292 | def getFmaxTimeResponse(self): |
|
284 | def getFmaxTimeResponse(self): | |
293 |
|
285 | |||
294 | period = (10**-6)*self.getDeltaH()/(0.15) |
|
286 | period = (10**-6)*self.getDeltaH()/(0.15) | |
295 |
|
287 | |||
296 | PRF = 1./(period * self.nCohInt) |
|
288 | PRF = 1./(period * self.nCohInt) | |
297 |
|
289 | |||
298 | fmax = PRF |
|
290 | fmax = PRF | |
299 |
|
291 | |||
300 | return fmax |
|
292 | return fmax | |
301 |
|
293 | |||
302 | def getFmax(self): |
|
294 | def getFmax(self): | |
303 |
|
295 | |||
304 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
296 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
305 |
|
297 | |||
306 | fmax = PRF |
|
298 | fmax = PRF | |
307 |
|
299 | |||
308 | return fmax |
|
300 | return fmax | |
309 |
|
301 | |||
310 | def getVmax(self): |
|
302 | def getVmax(self): | |
311 |
|
303 | |||
312 | _lambda = self.C/self.frequency |
|
304 | _lambda = self.C/self.frequency | |
313 |
|
305 | |||
314 | vmax = self.getFmax() * _lambda/2 |
|
306 | vmax = self.getFmax() * _lambda/2 | |
315 |
|
307 | |||
316 | return vmax |
|
308 | return vmax | |
317 |
|
309 | |||
318 | def get_ippSeconds(self): |
|
310 | def get_ippSeconds(self): | |
319 | ''' |
|
311 | ''' | |
320 | ''' |
|
312 | ''' | |
321 | return self.radarControllerHeaderObj.ippSeconds |
|
313 | return self.radarControllerHeaderObj.ippSeconds | |
322 |
|
314 | |||
323 | def set_ippSeconds(self, ippSeconds): |
|
315 | def set_ippSeconds(self, ippSeconds): | |
324 | ''' |
|
316 | ''' | |
325 | ''' |
|
317 | ''' | |
326 |
|
318 | |||
327 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
319 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
328 |
|
320 | |||
329 | return |
|
321 | return | |
330 |
|
322 | |||
331 | def get_dtype(self): |
|
323 | def get_dtype(self): | |
332 | ''' |
|
324 | ''' | |
333 | ''' |
|
325 | ''' | |
334 | return getNumpyDtype(self.datatype) |
|
326 | return getNumpyDtype(self.datatype) | |
335 |
|
327 | |||
336 | def set_dtype(self, numpyDtype): |
|
328 | def set_dtype(self, numpyDtype): | |
337 | ''' |
|
329 | ''' | |
338 | ''' |
|
330 | ''' | |
339 |
|
331 | |||
340 | self.datatype = getDataTypeCode(numpyDtype) |
|
332 | self.datatype = getDataTypeCode(numpyDtype) | |
341 |
|
333 | |||
342 | def get_code(self): |
|
334 | def get_code(self): | |
343 | ''' |
|
335 | ''' | |
344 | ''' |
|
336 | ''' | |
345 | return self.radarControllerHeaderObj.code |
|
337 | return self.radarControllerHeaderObj.code | |
346 |
|
338 | |||
347 | def set_code(self, code): |
|
339 | def set_code(self, code): | |
348 | ''' |
|
340 | ''' | |
349 | ''' |
|
341 | ''' | |
350 | self.radarControllerHeaderObj.code = code |
|
342 | self.radarControllerHeaderObj.code = code | |
351 |
|
343 | |||
352 | return |
|
344 | return | |
353 |
|
345 | |||
354 | def get_ncode(self): |
|
346 | def get_ncode(self): | |
355 | ''' |
|
347 | ''' | |
356 | ''' |
|
348 | ''' | |
357 | return self.radarControllerHeaderObj.nCode |
|
349 | return self.radarControllerHeaderObj.nCode | |
358 |
|
350 | |||
359 | def set_ncode(self, nCode): |
|
351 | def set_ncode(self, nCode): | |
360 | ''' |
|
352 | ''' | |
361 | ''' |
|
353 | ''' | |
362 | self.radarControllerHeaderObj.nCode = nCode |
|
354 | self.radarControllerHeaderObj.nCode = nCode | |
363 |
|
355 | |||
364 | return |
|
356 | return | |
365 |
|
357 | |||
366 | def get_nbaud(self): |
|
358 | def get_nbaud(self): | |
367 | ''' |
|
359 | ''' | |
368 | ''' |
|
360 | ''' | |
369 | return self.radarControllerHeaderObj.nBaud |
|
361 | return self.radarControllerHeaderObj.nBaud | |
370 |
|
362 | |||
371 | def set_nbaud(self, nBaud): |
|
363 | def set_nbaud(self, nBaud): | |
372 | ''' |
|
364 | ''' | |
373 | ''' |
|
365 | ''' | |
374 | self.radarControllerHeaderObj.nBaud = nBaud |
|
366 | self.radarControllerHeaderObj.nBaud = nBaud | |
375 |
|
367 | |||
376 | return |
|
368 | return | |
377 |
|
369 | |||
378 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
370 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
379 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
371 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
380 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
372 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
381 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
373 | #noise = property(getNoise, "I'm the 'nHeights' property.") | |
382 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
374 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
383 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
375 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
384 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
376 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
385 | dtype = property(get_dtype, set_dtype) |
|
377 | dtype = property(get_dtype, set_dtype) | |
386 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
378 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
387 | code = property(get_code, set_code) |
|
379 | code = property(get_code, set_code) | |
388 | nCode = property(get_ncode, set_ncode) |
|
380 | nCode = property(get_ncode, set_ncode) | |
389 | nBaud = property(get_nbaud, set_nbaud) |
|
381 | nBaud = property(get_nbaud, set_nbaud) | |
390 |
|
382 | |||
391 | class Voltage(JROData): |
|
383 | class Voltage(JROData): | |
392 |
|
384 | |||
393 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
385 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
394 | data = None |
|
386 | data = None | |
395 |
|
387 | |||
396 | def __init__(self): |
|
388 | def __init__(self): | |
397 | ''' |
|
389 | ''' | |
398 | Constructor |
|
390 | Constructor | |
399 | ''' |
|
391 | ''' | |
400 |
|
392 | |||
401 | self.useLocalTime = True |
|
393 | self.useLocalTime = True | |
402 |
|
394 | |||
403 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
395 | self.radarControllerHeaderObj = RadarControllerHeader() | |
404 |
|
396 | |||
405 | self.systemHeaderObj = SystemHeader() |
|
397 | self.systemHeaderObj = SystemHeader() | |
406 |
|
398 | |||
407 | self.type = "Voltage" |
|
399 | self.type = "Voltage" | |
408 |
|
400 | |||
409 | self.data = None |
|
401 | self.data = None | |
410 |
|
402 | |||
411 | # self.dtype = None |
|
403 | # self.dtype = None | |
412 |
|
404 | |||
413 | # self.nChannels = 0 |
|
405 | # self.nChannels = 0 | |
414 |
|
406 | |||
415 | # self.nHeights = 0 |
|
407 | # self.nHeights = 0 | |
416 |
|
408 | |||
417 | self.nProfiles = None |
|
409 | self.nProfiles = None | |
418 |
|
410 | |||
419 | self.heightList = None |
|
411 | self.heightList = None | |
420 |
|
412 | |||
421 | self.channelList = None |
|
413 | self.channelList = None | |
422 |
|
414 | |||
423 | # self.channelIndexList = None |
|
415 | # self.channelIndexList = None | |
424 |
|
416 | |||
425 | self.flagNoData = True |
|
417 | self.flagNoData = True | |
426 |
|
418 | |||
427 | self.flagDiscontinuousBlock = False |
|
419 | self.flagDiscontinuousBlock = False | |
428 |
|
420 | |||
429 | self.utctime = None |
|
421 | self.utctime = None | |
430 |
|
422 | |||
431 | self.timeZone = None |
|
423 | self.timeZone = None | |
432 |
|
424 | |||
433 | self.dstFlag = None |
|
425 | self.dstFlag = None | |
434 |
|
426 | |||
435 | self.errorCount = None |
|
427 | self.errorCount = None | |
436 |
|
428 | |||
437 | self.nCohInt = None |
|
429 | self.nCohInt = None | |
438 |
|
430 | |||
439 | self.blocksize = None |
|
431 | self.blocksize = None | |
440 |
|
432 | |||
441 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
433 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
442 |
|
434 | |||
443 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
435 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
444 |
|
436 | |||
445 | self.flagShiftFFT = False |
|
437 | self.flagShiftFFT = False | |
446 |
|
438 | |||
447 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil |
|
439 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil | |
448 |
|
440 | |||
449 | self.profileIndex = 0 |
|
441 | self.profileIndex = 0 | |
450 |
|
442 | |||
451 | def getNoisebyHildebrand(self, channel = None): |
|
443 | def getNoisebyHildebrand(self, channel = None): | |
452 | """ |
|
444 | """ | |
453 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
445 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
454 |
|
446 | |||
455 | Return: |
|
447 | Return: | |
456 | noiselevel |
|
448 | noiselevel | |
457 | """ |
|
449 | """ | |
458 |
|
450 | |||
459 | if channel != None: |
|
451 | if channel != None: | |
460 | data = self.data[channel] |
|
452 | data = self.data[channel] | |
461 | nChannels = 1 |
|
453 | nChannels = 1 | |
462 | else: |
|
454 | else: | |
463 | data = self.data |
|
455 | data = self.data | |
464 | nChannels = self.nChannels |
|
456 | nChannels = self.nChannels | |
465 |
|
457 | |||
466 | noise = numpy.zeros(nChannels) |
|
458 | noise = numpy.zeros(nChannels) | |
467 | power = data * numpy.conjugate(data) |
|
459 | power = data * numpy.conjugate(data) | |
468 |
|
460 | |||
469 | for thisChannel in range(nChannels): |
|
461 | for thisChannel in range(nChannels): | |
470 | if nChannels == 1: |
|
462 | if nChannels == 1: | |
471 | daux = power[:].real |
|
463 | daux = power[:].real | |
472 | else: |
|
464 | else: | |
473 | daux = power[thisChannel,:].real |
|
465 | daux = power[thisChannel,:].real | |
474 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
466 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
475 |
|
467 | |||
476 | return noise |
|
468 | return noise | |
477 |
|
469 | |||
478 | def getNoise(self, type = 1, channel = None): |
|
470 | def getNoise(self, type = 1, channel = None): | |
479 |
|
471 | |||
480 | if type == 1: |
|
472 | if type == 1: | |
481 | noise = self.getNoisebyHildebrand(channel) |
|
473 | noise = self.getNoisebyHildebrand(channel) | |
482 |
|
474 | |||
483 | return noise |
|
475 | return noise | |
484 |
|
476 | |||
485 | def getPower(self, channel = None): |
|
477 | def getPower(self, channel = None): | |
486 |
|
478 | |||
487 | if channel != None: |
|
479 | if channel != None: | |
488 | data = self.data[channel] |
|
480 | data = self.data[channel] | |
489 | else: |
|
481 | else: | |
490 | data = self.data |
|
482 | data = self.data | |
491 |
|
483 | |||
492 | power = data * numpy.conjugate(data) |
|
484 | power = data * numpy.conjugate(data) | |
493 | powerdB = 10*numpy.log10(power.real) |
|
485 | powerdB = 10*numpy.log10(power.real) | |
494 | powerdB = numpy.squeeze(powerdB) |
|
486 | powerdB = numpy.squeeze(powerdB) | |
495 |
|
487 | |||
496 | return powerdB |
|
488 | return powerdB | |
497 |
|
489 | |||
498 | def getTimeInterval(self): |
|
490 | def getTimeInterval(self): | |
499 |
|
491 | |||
500 | timeInterval = self.ippSeconds * self.nCohInt |
|
492 | timeInterval = self.ippSeconds * self.nCohInt | |
501 |
|
493 | |||
502 | return timeInterval |
|
494 | return timeInterval | |
503 |
|
495 | |||
504 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
496 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
505 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
497 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
506 |
|
498 | |||
507 | class Spectra(JROData): |
|
499 | class Spectra(JROData): | |
508 |
|
500 | |||
509 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
501 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
510 | data_spc = None |
|
502 | data_spc = None | |
511 |
|
503 | |||
512 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
504 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) | |
513 | data_cspc = None |
|
505 | data_cspc = None | |
514 |
|
506 | |||
515 | #data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
507 | #data dc es un numpy array de 2 dmensiones (canales, alturas) | |
516 | data_dc = None |
|
508 | data_dc = None | |
517 |
|
509 | |||
518 | #data power |
|
510 | #data power | |
519 | data_pwr = None |
|
511 | data_pwr = None | |
520 |
|
512 | |||
521 | nFFTPoints = None |
|
513 | nFFTPoints = None | |
522 |
|
514 | |||
523 | # nPairs = None |
|
515 | # nPairs = None | |
524 |
|
516 | |||
525 | pairsList = None |
|
517 | pairsList = None | |
526 |
|
518 | |||
527 | nIncohInt = None |
|
519 | nIncohInt = None | |
528 |
|
520 | |||
529 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
521 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
530 |
|
522 | |||
531 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
523 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
532 |
|
524 | |||
533 | ippFactor = None |
|
525 | ippFactor = None | |
534 |
|
526 | |||
535 | profileIndex = 0 |
|
527 | profileIndex = 0 | |
536 |
|
528 | |||
537 | plotting = "spectra" |
|
529 | plotting = "spectra" | |
538 |
|
530 | |||
539 | def __init__(self): |
|
531 | def __init__(self): | |
540 | ''' |
|
532 | ''' | |
541 | Constructor |
|
533 | Constructor | |
542 | ''' |
|
534 | ''' | |
543 |
|
535 | |||
544 | self.useLocalTime = True |
|
536 | self.useLocalTime = True | |
545 |
|
537 | |||
546 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
538 | self.radarControllerHeaderObj = RadarControllerHeader() | |
547 |
|
539 | |||
548 | self.systemHeaderObj = SystemHeader() |
|
540 | self.systemHeaderObj = SystemHeader() | |
549 |
|
541 | |||
550 | self.type = "Spectra" |
|
542 | self.type = "Spectra" | |
551 |
|
543 | |||
552 | # self.data = None |
|
544 | # self.data = None | |
553 |
|
545 | |||
554 | # self.dtype = None |
|
546 | # self.dtype = None | |
555 |
|
547 | |||
556 | # self.nChannels = 0 |
|
548 | # self.nChannels = 0 | |
557 |
|
549 | |||
558 | # self.nHeights = 0 |
|
550 | # self.nHeights = 0 | |
559 |
|
551 | |||
560 | self.nProfiles = None |
|
552 | self.nProfiles = None | |
561 |
|
553 | |||
562 | self.heightList = None |
|
554 | self.heightList = None | |
563 |
|
555 | |||
564 | self.channelList = None |
|
556 | self.channelList = None | |
565 |
|
557 | |||
566 | # self.channelIndexList = None |
|
558 | # self.channelIndexList = None | |
567 |
|
559 | |||
568 | self.pairsList = None |
|
560 | self.pairsList = None | |
569 |
|
561 | |||
570 | self.flagNoData = True |
|
562 | self.flagNoData = True | |
571 |
|
563 | |||
572 | self.flagDiscontinuousBlock = False |
|
564 | self.flagDiscontinuousBlock = False | |
573 |
|
565 | |||
574 | self.utctime = None |
|
566 | self.utctime = None | |
575 |
|
567 | |||
576 | self.nCohInt = None |
|
568 | self.nCohInt = None | |
577 |
|
569 | |||
578 | self.nIncohInt = None |
|
570 | self.nIncohInt = None | |
579 |
|
571 | |||
580 | self.blocksize = None |
|
572 | self.blocksize = None | |
581 |
|
573 | |||
582 | self.nFFTPoints = None |
|
574 | self.nFFTPoints = None | |
583 |
|
575 | |||
584 | self.wavelength = None |
|
576 | self.wavelength = None | |
585 |
|
577 | |||
586 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
578 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
587 |
|
579 | |||
588 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
580 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
589 |
|
581 | |||
590 | self.flagShiftFFT = False |
|
582 | self.flagShiftFFT = False | |
591 |
|
583 | |||
592 | self.ippFactor = 1 |
|
584 | self.ippFactor = 1 | |
593 |
|
585 | |||
594 | #self.noise = None |
|
586 | #self.noise = None | |
595 |
|
587 | |||
596 | self.beacon_heiIndexList = [] |
|
588 | self.beacon_heiIndexList = [] | |
597 |
|
589 | |||
598 | self.noise_estimation = None |
|
590 | self.noise_estimation = None | |
599 |
|
591 | |||
600 |
|
592 | |||
601 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
593 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
602 | """ |
|
594 | """ | |
603 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
595 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
604 |
|
596 | |||
605 | Return: |
|
597 | Return: | |
606 | noiselevel |
|
598 | noiselevel | |
607 | """ |
|
599 | """ | |
608 |
|
600 | |||
609 | noise = numpy.zeros(self.nChannels) |
|
601 | noise = numpy.zeros(self.nChannels) | |
610 |
|
602 | |||
611 | for channel in range(self.nChannels): |
|
603 | for channel in range(self.nChannels): | |
612 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] |
|
604 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] | |
613 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
605 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
614 |
|
606 | |||
615 | return noise |
|
607 | return noise | |
616 |
|
608 | |||
617 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
609 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
618 |
|
610 | |||
619 | if self.noise_estimation is not None: |
|
611 | if self.noise_estimation is not None: | |
620 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
612 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py | |
621 | else: |
|
613 | else: | |
622 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) |
|
614 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) | |
623 | return noise |
|
615 | return noise | |
624 |
|
616 | |||
625 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
617 | def getFreqRangeTimeResponse(self, extrapoints=0): | |
626 |
|
618 | |||
627 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) |
|
619 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) | |
628 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
620 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
629 |
|
621 | |||
630 | return freqrange |
|
622 | return freqrange | |
631 |
|
623 | |||
632 | def getAcfRange(self, extrapoints=0): |
|
624 | def getAcfRange(self, extrapoints=0): | |
633 |
|
625 | |||
634 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) |
|
626 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) | |
635 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
627 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
636 |
|
628 | |||
637 | return freqrange |
|
629 | return freqrange | |
638 |
|
630 | |||
639 | def getFreqRange(self, extrapoints=0): |
|
631 | def getFreqRange(self, extrapoints=0): | |
640 |
|
632 | |||
641 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
633 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) | |
642 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
634 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
643 |
|
635 | |||
644 | return freqrange |
|
636 | return freqrange | |
645 |
|
637 | |||
646 | def getVelRange(self, extrapoints=0): |
|
638 | def getVelRange(self, extrapoints=0): | |
647 |
|
639 | |||
648 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
640 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) | |
649 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 |
|
641 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 | |
650 |
|
642 | |||
651 | return velrange |
|
643 | return velrange | |
652 |
|
644 | |||
653 | def getNPairs(self): |
|
645 | def getNPairs(self): | |
654 |
|
646 | |||
655 | return len(self.pairsList) |
|
647 | return len(self.pairsList) | |
656 |
|
648 | |||
657 | def getPairsIndexList(self): |
|
649 | def getPairsIndexList(self): | |
658 |
|
650 | |||
659 | return range(self.nPairs) |
|
651 | return range(self.nPairs) | |
660 |
|
652 | |||
661 | def getNormFactor(self): |
|
653 | def getNormFactor(self): | |
662 |
|
654 | |||
663 | pwcode = 1 |
|
655 | pwcode = 1 | |
664 |
|
656 | |||
665 | if self.flagDecodeData: |
|
657 | if self.flagDecodeData: | |
666 | pwcode = numpy.sum(self.code[0]**2) |
|
658 | pwcode = numpy.sum(self.code[0]**2) | |
667 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
659 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
668 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
660 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
669 |
|
661 | |||
670 | return normFactor |
|
662 | return normFactor | |
671 |
|
663 | |||
672 | def getFlagCspc(self): |
|
664 | def getFlagCspc(self): | |
673 |
|
665 | |||
674 | if self.data_cspc is None: |
|
666 | if self.data_cspc is None: | |
675 | return True |
|
667 | return True | |
676 |
|
668 | |||
677 | return False |
|
669 | return False | |
678 |
|
670 | |||
679 | def getFlagDc(self): |
|
671 | def getFlagDc(self): | |
680 |
|
672 | |||
681 | if self.data_dc is None: |
|
673 | if self.data_dc is None: | |
682 | return True |
|
674 | return True | |
683 |
|
675 | |||
684 | return False |
|
676 | return False | |
685 |
|
677 | |||
686 | def getTimeInterval(self): |
|
678 | def getTimeInterval(self): | |
687 |
|
679 | |||
688 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles |
|
680 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles | |
689 |
|
681 | |||
690 | return timeInterval |
|
682 | return timeInterval | |
691 |
|
683 | |||
692 | def getPower(self): |
|
684 | def getPower(self): | |
693 |
|
685 | |||
694 | factor = self.normFactor |
|
686 | factor = self.normFactor | |
695 | z = self.data_spc/factor |
|
687 | z = self.data_spc/factor | |
696 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
688 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
697 | avg = numpy.average(z, axis=1) |
|
689 | avg = numpy.average(z, axis=1) | |
698 |
|
690 | |||
699 | return 10*numpy.log10(avg) |
|
691 | return 10*numpy.log10(avg) | |
700 |
|
692 | |||
701 | def getCoherence(self, pairsList=None, phase=False): |
|
693 | def getCoherence(self, pairsList=None, phase=False): | |
702 |
|
694 | |||
703 | z = [] |
|
695 | z = [] | |
704 | if pairsList is None: |
|
696 | if pairsList is None: | |
705 | pairsIndexList = self.pairsIndexList |
|
697 | pairsIndexList = self.pairsIndexList | |
706 | else: |
|
698 | else: | |
707 | pairsIndexList = [] |
|
699 | pairsIndexList = [] | |
708 | for pair in pairsList: |
|
700 | for pair in pairsList: | |
709 | if pair not in self.pairsList: |
|
701 | if pair not in self.pairsList: | |
710 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
702 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
711 | pairsIndexList.append(self.pairsList.index(pair)) |
|
703 | pairsIndexList.append(self.pairsList.index(pair)) | |
712 | for i in range(len(pairsIndexList)): |
|
704 | for i in range(len(pairsIndexList)): | |
713 | pair = self.pairsList[pairsIndexList[i]] |
|
705 | pair = self.pairsList[pairsIndexList[i]] | |
714 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
706 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) | |
715 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
707 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) | |
716 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
708 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) | |
717 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
709 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
718 | if phase: |
|
710 | if phase: | |
719 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
711 | data = numpy.arctan2(avgcoherenceComplex.imag, | |
720 | avgcoherenceComplex.real)*180/numpy.pi |
|
712 | avgcoherenceComplex.real)*180/numpy.pi | |
721 | else: |
|
713 | else: | |
722 | data = numpy.abs(avgcoherenceComplex) |
|
714 | data = numpy.abs(avgcoherenceComplex) | |
723 |
|
715 | |||
724 | z.append(data) |
|
716 | z.append(data) | |
725 |
|
717 | |||
726 | return numpy.array(z) |
|
718 | return numpy.array(z) | |
727 |
|
719 | |||
728 | def setValue(self, value): |
|
720 | def setValue(self, value): | |
729 |
|
721 | |||
730 | print "This property should not be initialized" |
|
722 | print "This property should not be initialized" | |
731 |
|
723 | |||
732 | return |
|
724 | return | |
733 |
|
725 | |||
734 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
726 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") | |
735 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
727 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") | |
736 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") |
|
728 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") | |
737 | flag_cspc = property(getFlagCspc, setValue) |
|
729 | flag_cspc = property(getFlagCspc, setValue) | |
738 | flag_dc = property(getFlagDc, setValue) |
|
730 | flag_dc = property(getFlagDc, setValue) | |
739 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
731 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") | |
740 | timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") |
|
732 | timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") | |
741 |
|
733 | |||
742 | class SpectraHeis(Spectra): |
|
734 | class SpectraHeis(Spectra): | |
743 |
|
735 | |||
744 | data_spc = None |
|
736 | data_spc = None | |
745 |
|
737 | |||
746 | data_cspc = None |
|
738 | data_cspc = None | |
747 |
|
739 | |||
748 | data_dc = None |
|
740 | data_dc = None | |
749 |
|
741 | |||
750 | nFFTPoints = None |
|
742 | nFFTPoints = None | |
751 |
|
743 | |||
752 | # nPairs = None |
|
744 | # nPairs = None | |
753 |
|
745 | |||
754 | pairsList = None |
|
746 | pairsList = None | |
755 |
|
747 | |||
756 | nCohInt = None |
|
748 | nCohInt = None | |
757 |
|
749 | |||
758 | nIncohInt = None |
|
750 | nIncohInt = None | |
759 |
|
751 | |||
760 | def __init__(self): |
|
752 | def __init__(self): | |
761 |
|
753 | |||
762 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
754 | self.radarControllerHeaderObj = RadarControllerHeader() | |
763 |
|
755 | |||
764 | self.systemHeaderObj = SystemHeader() |
|
756 | self.systemHeaderObj = SystemHeader() | |
765 |
|
757 | |||
766 | self.type = "SpectraHeis" |
|
758 | self.type = "SpectraHeis" | |
767 |
|
759 | |||
768 | # self.dtype = None |
|
760 | # self.dtype = None | |
769 |
|
761 | |||
770 | # self.nChannels = 0 |
|
762 | # self.nChannels = 0 | |
771 |
|
763 | |||
772 | # self.nHeights = 0 |
|
764 | # self.nHeights = 0 | |
773 |
|
765 | |||
774 | self.nProfiles = None |
|
766 | self.nProfiles = None | |
775 |
|
767 | |||
776 | self.heightList = None |
|
768 | self.heightList = None | |
777 |
|
769 | |||
778 | self.channelList = None |
|
770 | self.channelList = None | |
779 |
|
771 | |||
780 | # self.channelIndexList = None |
|
772 | # self.channelIndexList = None | |
781 |
|
773 | |||
782 | self.flagNoData = True |
|
774 | self.flagNoData = True | |
783 |
|
775 | |||
784 | self.flagDiscontinuousBlock = False |
|
776 | self.flagDiscontinuousBlock = False | |
785 |
|
777 | |||
786 | # self.nPairs = 0 |
|
778 | # self.nPairs = 0 | |
787 |
|
779 | |||
788 | self.utctime = None |
|
780 | self.utctime = None | |
789 |
|
781 | |||
790 | self.blocksize = None |
|
782 | self.blocksize = None | |
791 |
|
783 | |||
792 | self.profileIndex = 0 |
|
784 | self.profileIndex = 0 | |
793 |
|
785 | |||
794 | self.nCohInt = 1 |
|
786 | self.nCohInt = 1 | |
795 |
|
787 | |||
796 | self.nIncohInt = 1 |
|
788 | self.nIncohInt = 1 | |
797 |
|
789 | |||
798 | def getNormFactor(self): |
|
790 | def getNormFactor(self): | |
799 | pwcode = 1 |
|
791 | pwcode = 1 | |
800 | if self.flagDecodeData: |
|
792 | if self.flagDecodeData: | |
801 | pwcode = numpy.sum(self.code[0]**2) |
|
793 | pwcode = numpy.sum(self.code[0]**2) | |
802 |
|
794 | |||
803 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
795 | normFactor = self.nIncohInt*self.nCohInt*pwcode | |
804 |
|
796 | |||
805 | return normFactor |
|
797 | return normFactor | |
806 |
|
798 | |||
807 | def getTimeInterval(self): |
|
799 | def getTimeInterval(self): | |
808 |
|
800 | |||
809 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
801 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
810 |
|
802 | |||
811 | return timeInterval |
|
803 | return timeInterval | |
812 |
|
804 | |||
813 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
805 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
814 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
806 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
815 |
|
807 | |||
816 | class Fits(JROData): |
|
808 | class Fits(JROData): | |
817 |
|
809 | |||
818 | heightList = None |
|
810 | heightList = None | |
819 |
|
811 | |||
820 | channelList = None |
|
812 | channelList = None | |
821 |
|
813 | |||
822 | flagNoData = True |
|
814 | flagNoData = True | |
823 |
|
815 | |||
824 | flagDiscontinuousBlock = False |
|
816 | flagDiscontinuousBlock = False | |
825 |
|
817 | |||
826 | useLocalTime = False |
|
818 | useLocalTime = False | |
827 |
|
819 | |||
828 | utctime = None |
|
820 | utctime = None | |
829 |
|
821 | |||
830 | timeZone = None |
|
822 | timeZone = None | |
831 |
|
823 | |||
832 | # ippSeconds = None |
|
824 | # ippSeconds = None | |
833 |
|
825 | |||
834 | # timeInterval = None |
|
826 | # timeInterval = None | |
835 |
|
827 | |||
836 | nCohInt = None |
|
828 | nCohInt = None | |
837 |
|
829 | |||
838 | nIncohInt = None |
|
830 | nIncohInt = None | |
839 |
|
831 | |||
840 | noise = None |
|
832 | noise = None | |
841 |
|
833 | |||
842 | windowOfFilter = 1 |
|
834 | windowOfFilter = 1 | |
843 |
|
835 | |||
844 | #Speed of ligth |
|
836 | #Speed of ligth | |
845 | C = 3e8 |
|
837 | C = 3e8 | |
846 |
|
838 | |||
847 | frequency = 49.92e6 |
|
839 | frequency = 49.92e6 | |
848 |
|
840 | |||
849 | realtime = False |
|
841 | realtime = False | |
850 |
|
842 | |||
851 |
|
843 | |||
852 | def __init__(self): |
|
844 | def __init__(self): | |
853 |
|
845 | |||
854 | self.type = "Fits" |
|
846 | self.type = "Fits" | |
855 |
|
847 | |||
856 | self.nProfiles = None |
|
848 | self.nProfiles = None | |
857 |
|
849 | |||
858 | self.heightList = None |
|
850 | self.heightList = None | |
859 |
|
851 | |||
860 | self.channelList = None |
|
852 | self.channelList = None | |
861 |
|
853 | |||
862 | # self.channelIndexList = None |
|
854 | # self.channelIndexList = None | |
863 |
|
855 | |||
864 | self.flagNoData = True |
|
856 | self.flagNoData = True | |
865 |
|
857 | |||
866 | self.utctime = None |
|
858 | self.utctime = None | |
867 |
|
859 | |||
868 | self.nCohInt = 1 |
|
860 | self.nCohInt = 1 | |
869 |
|
861 | |||
870 | self.nIncohInt = 1 |
|
862 | self.nIncohInt = 1 | |
871 |
|
863 | |||
872 | self.useLocalTime = True |
|
864 | self.useLocalTime = True | |
873 |
|
865 | |||
874 | self.profileIndex = 0 |
|
866 | self.profileIndex = 0 | |
875 |
|
867 | |||
876 | # self.utctime = None |
|
868 | # self.utctime = None | |
877 | # self.timeZone = None |
|
869 | # self.timeZone = None | |
878 | # self.ltctime = None |
|
870 | # self.ltctime = None | |
879 | # self.timeInterval = None |
|
871 | # self.timeInterval = None | |
880 | # self.header = None |
|
872 | # self.header = None | |
881 | # self.data_header = None |
|
873 | # self.data_header = None | |
882 | # self.data = None |
|
874 | # self.data = None | |
883 | # self.datatime = None |
|
875 | # self.datatime = None | |
884 | # self.flagNoData = False |
|
876 | # self.flagNoData = False | |
885 | # self.expName = '' |
|
877 | # self.expName = '' | |
886 | # self.nChannels = None |
|
878 | # self.nChannels = None | |
887 | # self.nSamples = None |
|
879 | # self.nSamples = None | |
888 | # self.dataBlocksPerFile = None |
|
880 | # self.dataBlocksPerFile = None | |
889 | # self.comments = '' |
|
881 | # self.comments = '' | |
890 | # |
|
882 | # | |
891 |
|
883 | |||
892 |
|
884 | |||
893 | def getltctime(self): |
|
885 | def getltctime(self): | |
894 |
|
886 | |||
895 | if self.useLocalTime: |
|
887 | if self.useLocalTime: | |
896 | return self.utctime - self.timeZone*60 |
|
888 | return self.utctime - self.timeZone*60 | |
897 |
|
889 | |||
898 | return self.utctime |
|
890 | return self.utctime | |
899 |
|
891 | |||
900 | def getDatatime(self): |
|
892 | def getDatatime(self): | |
901 |
|
893 | |||
902 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
894 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
903 | return datatime |
|
895 | return datatime | |
904 |
|
896 | |||
905 | def getTimeRange(self): |
|
897 | def getTimeRange(self): | |
906 |
|
898 | |||
907 | datatime = [] |
|
899 | datatime = [] | |
908 |
|
900 | |||
909 | datatime.append(self.ltctime) |
|
901 | datatime.append(self.ltctime) | |
910 | datatime.append(self.ltctime + self.timeInterval) |
|
902 | datatime.append(self.ltctime + self.timeInterval) | |
911 |
|
903 | |||
912 | datatime = numpy.array(datatime) |
|
904 | datatime = numpy.array(datatime) | |
913 |
|
905 | |||
914 | return datatime |
|
906 | return datatime | |
915 |
|
907 | |||
916 | def getHeiRange(self): |
|
908 | def getHeiRange(self): | |
917 |
|
909 | |||
918 | heis = self.heightList |
|
910 | heis = self.heightList | |
919 |
|
911 | |||
920 | return heis |
|
912 | return heis | |
921 |
|
913 | |||
922 | def getNHeights(self): |
|
914 | def getNHeights(self): | |
923 |
|
915 | |||
924 | return len(self.heightList) |
|
916 | return len(self.heightList) | |
925 |
|
917 | |||
926 | def getNChannels(self): |
|
918 | def getNChannels(self): | |
927 |
|
919 | |||
928 | return len(self.channelList) |
|
920 | return len(self.channelList) | |
929 |
|
921 | |||
930 | def getChannelIndexList(self): |
|
922 | def getChannelIndexList(self): | |
931 |
|
923 | |||
932 | return range(self.nChannels) |
|
924 | return range(self.nChannels) | |
933 |
|
925 | |||
934 | def getNoise(self, type = 1): |
|
926 | def getNoise(self, type = 1): | |
935 |
|
927 | |||
936 | #noise = numpy.zeros(self.nChannels) |
|
928 | #noise = numpy.zeros(self.nChannels) | |
937 |
|
929 | |||
938 | if type == 1: |
|
930 | if type == 1: | |
939 | noise = self.getNoisebyHildebrand() |
|
931 | noise = self.getNoisebyHildebrand() | |
940 |
|
932 | |||
941 | if type == 2: |
|
933 | if type == 2: | |
942 | noise = self.getNoisebySort() |
|
934 | noise = self.getNoisebySort() | |
943 |
|
935 | |||
944 | if type == 3: |
|
936 | if type == 3: | |
945 | noise = self.getNoisebyWindow() |
|
937 | noise = self.getNoisebyWindow() | |
946 |
|
938 | |||
947 | return noise |
|
939 | return noise | |
948 |
|
940 | |||
949 | def getTimeInterval(self): |
|
941 | def getTimeInterval(self): | |
950 |
|
942 | |||
951 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
943 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
952 |
|
944 | |||
953 | return timeInterval |
|
945 | return timeInterval | |
954 |
|
946 | |||
955 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
947 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
956 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
948 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
957 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
949 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
958 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
950 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
959 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
951 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
960 |
|
952 | |||
961 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
953 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
962 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
954 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
963 |
|
955 | |||
964 |
|
956 | |||
965 | class Correlation(JROData): |
|
957 | class Correlation(JROData): | |
966 |
|
958 | |||
967 | noise = None |
|
959 | noise = None | |
968 |
|
960 | |||
969 | SNR = None |
|
961 | SNR = None | |
970 |
|
962 | |||
971 | #-------------------------------------------------- |
|
963 | #-------------------------------------------------- | |
972 |
|
964 | |||
973 | mode = None |
|
965 | mode = None | |
974 |
|
966 | |||
975 | split = False |
|
967 | split = False | |
976 |
|
968 | |||
977 | data_cf = None |
|
969 | data_cf = None | |
978 |
|
970 | |||
979 | lags = None |
|
971 | lags = None | |
980 |
|
972 | |||
981 | lagRange = None |
|
973 | lagRange = None | |
982 |
|
974 | |||
983 | pairsList = None |
|
975 | pairsList = None | |
984 |
|
976 | |||
985 | normFactor = None |
|
977 | normFactor = None | |
986 |
|
978 | |||
987 | #-------------------------------------------------- |
|
979 | #-------------------------------------------------- | |
988 |
|
980 | |||
989 | # calculateVelocity = None |
|
981 | # calculateVelocity = None | |
990 |
|
982 | |||
991 | nLags = None |
|
983 | nLags = None | |
992 |
|
984 | |||
993 | nPairs = None |
|
985 | nPairs = None | |
994 |
|
986 | |||
995 | nAvg = None |
|
987 | nAvg = None | |
996 |
|
988 | |||
997 |
|
989 | |||
998 | def __init__(self): |
|
990 | def __init__(self): | |
999 | ''' |
|
991 | ''' | |
1000 | Constructor |
|
992 | Constructor | |
1001 | ''' |
|
993 | ''' | |
1002 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
994 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1003 |
|
995 | |||
1004 | self.systemHeaderObj = SystemHeader() |
|
996 | self.systemHeaderObj = SystemHeader() | |
1005 |
|
997 | |||
1006 | self.type = "Correlation" |
|
998 | self.type = "Correlation" | |
1007 |
|
999 | |||
1008 | self.data = None |
|
1000 | self.data = None | |
1009 |
|
1001 | |||
1010 | self.dtype = None |
|
1002 | self.dtype = None | |
1011 |
|
1003 | |||
1012 | self.nProfiles = None |
|
1004 | self.nProfiles = None | |
1013 |
|
1005 | |||
1014 | self.heightList = None |
|
1006 | self.heightList = None | |
1015 |
|
1007 | |||
1016 | self.channelList = None |
|
1008 | self.channelList = None | |
1017 |
|
1009 | |||
1018 | self.flagNoData = True |
|
1010 | self.flagNoData = True | |
1019 |
|
1011 | |||
1020 | self.flagDiscontinuousBlock = False |
|
1012 | self.flagDiscontinuousBlock = False | |
1021 |
|
1013 | |||
1022 | self.utctime = None |
|
1014 | self.utctime = None | |
1023 |
|
1015 | |||
1024 | self.timeZone = None |
|
1016 | self.timeZone = None | |
1025 |
|
1017 | |||
1026 | self.dstFlag = None |
|
1018 | self.dstFlag = None | |
1027 |
|
1019 | |||
1028 | self.errorCount = None |
|
1020 | self.errorCount = None | |
1029 |
|
1021 | |||
1030 | self.blocksize = None |
|
1022 | self.blocksize = None | |
1031 |
|
1023 | |||
1032 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
1024 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
1033 |
|
1025 | |||
1034 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
1026 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
1035 |
|
1027 | |||
1036 | self.pairsList = None |
|
1028 | self.pairsList = None | |
1037 |
|
1029 | |||
1038 | self.nPoints = None |
|
1030 | self.nPoints = None | |
1039 |
|
1031 | |||
1040 | def getPairsList(self): |
|
1032 | def getPairsList(self): | |
1041 |
|
1033 | |||
1042 | return self.pairsList |
|
1034 | return self.pairsList | |
1043 |
|
1035 | |||
1044 | def getNoise(self, mode = 2): |
|
1036 | def getNoise(self, mode = 2): | |
1045 |
|
1037 | |||
1046 | indR = numpy.where(self.lagR == 0)[0][0] |
|
1038 | indR = numpy.where(self.lagR == 0)[0][0] | |
1047 | indT = numpy.where(self.lagT == 0)[0][0] |
|
1039 | indT = numpy.where(self.lagT == 0)[0][0] | |
1048 |
|
1040 | |||
1049 | jspectra0 = self.data_corr[:,:,indR,:] |
|
1041 | jspectra0 = self.data_corr[:,:,indR,:] | |
1050 | jspectra = copy.copy(jspectra0) |
|
1042 | jspectra = copy.copy(jspectra0) | |
1051 |
|
1043 | |||
1052 | num_chan = jspectra.shape[0] |
|
1044 | num_chan = jspectra.shape[0] | |
1053 | num_hei = jspectra.shape[2] |
|
1045 | num_hei = jspectra.shape[2] | |
1054 |
|
1046 | |||
1055 | freq_dc = jspectra.shape[1]/2 |
|
1047 | freq_dc = jspectra.shape[1]/2 | |
1056 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1048 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
1057 |
|
1049 | |||
1058 | if ind_vel[0]<0: |
|
1050 | if ind_vel[0]<0: | |
1059 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1051 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
1060 |
|
1052 | |||
1061 | if mode == 1: |
|
1053 | if mode == 1: | |
1062 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1054 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
1063 |
|
1055 | |||
1064 | if mode == 2: |
|
1056 | if mode == 2: | |
1065 |
|
1057 | |||
1066 | vel = numpy.array([-2,-1,1,2]) |
|
1058 | vel = numpy.array([-2,-1,1,2]) | |
1067 | xx = numpy.zeros([4,4]) |
|
1059 | xx = numpy.zeros([4,4]) | |
1068 |
|
1060 | |||
1069 | for fil in range(4): |
|
1061 | for fil in range(4): | |
1070 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1062 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
1071 |
|
1063 | |||
1072 | xx_inv = numpy.linalg.inv(xx) |
|
1064 | xx_inv = numpy.linalg.inv(xx) | |
1073 | xx_aux = xx_inv[0,:] |
|
1065 | xx_aux = xx_inv[0,:] | |
1074 |
|
1066 | |||
1075 | for ich in range(num_chan): |
|
1067 | for ich in range(num_chan): | |
1076 | yy = jspectra[ich,ind_vel,:] |
|
1068 | yy = jspectra[ich,ind_vel,:] | |
1077 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1069 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1078 |
|
1070 | |||
1079 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1071 | junkid = jspectra[ich,freq_dc,:]<=0 | |
1080 | cjunkid = sum(junkid) |
|
1072 | cjunkid = sum(junkid) | |
1081 |
|
1073 | |||
1082 | if cjunkid.any(): |
|
1074 | if cjunkid.any(): | |
1083 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1075 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
1084 |
|
1076 | |||
1085 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
1077 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] | |
1086 |
|
1078 | |||
1087 | return noise |
|
1079 | return noise | |
1088 |
|
1080 | |||
1089 | def getTimeInterval(self): |
|
1081 | def getTimeInterval(self): | |
1090 |
|
1082 | |||
1091 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
1083 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles | |
1092 |
|
1084 | |||
1093 | return timeInterval |
|
1085 | return timeInterval | |
1094 |
|
1086 | |||
1095 | def splitFunctions(self): |
|
1087 | def splitFunctions(self): | |
1096 |
|
1088 | |||
1097 | pairsList = self.pairsList |
|
1089 | pairsList = self.pairsList | |
1098 | ccf_pairs = [] |
|
1090 | ccf_pairs = [] | |
1099 | acf_pairs = [] |
|
1091 | acf_pairs = [] | |
1100 | ccf_ind = [] |
|
1092 | ccf_ind = [] | |
1101 | acf_ind = [] |
|
1093 | acf_ind = [] | |
1102 | for l in range(len(pairsList)): |
|
1094 | for l in range(len(pairsList)): | |
1103 | chan0 = pairsList[l][0] |
|
1095 | chan0 = pairsList[l][0] | |
1104 | chan1 = pairsList[l][1] |
|
1096 | chan1 = pairsList[l][1] | |
1105 |
|
1097 | |||
1106 | #Obteniendo pares de Autocorrelacion |
|
1098 | #Obteniendo pares de Autocorrelacion | |
1107 | if chan0 == chan1: |
|
1099 | if chan0 == chan1: | |
1108 | acf_pairs.append(chan0) |
|
1100 | acf_pairs.append(chan0) | |
1109 | acf_ind.append(l) |
|
1101 | acf_ind.append(l) | |
1110 | else: |
|
1102 | else: | |
1111 | ccf_pairs.append(pairsList[l]) |
|
1103 | ccf_pairs.append(pairsList[l]) | |
1112 | ccf_ind.append(l) |
|
1104 | ccf_ind.append(l) | |
1113 |
|
1105 | |||
1114 | data_acf = self.data_cf[acf_ind] |
|
1106 | data_acf = self.data_cf[acf_ind] | |
1115 | data_ccf = self.data_cf[ccf_ind] |
|
1107 | data_ccf = self.data_cf[ccf_ind] | |
1116 |
|
1108 | |||
1117 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1109 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf | |
1118 |
|
1110 | |||
1119 | def getNormFactor(self): |
|
1111 | def getNormFactor(self): | |
1120 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1112 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() | |
1121 | acf_pairs = numpy.array(acf_pairs) |
|
1113 | acf_pairs = numpy.array(acf_pairs) | |
1122 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) |
|
1114 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) | |
1123 |
|
1115 | |||
1124 | for p in range(self.nPairs): |
|
1116 | for p in range(self.nPairs): | |
1125 | pair = self.pairsList[p] |
|
1117 | pair = self.pairsList[p] | |
1126 |
|
1118 | |||
1127 | ch0 = pair[0] |
|
1119 | ch0 = pair[0] | |
1128 | ch1 = pair[1] |
|
1120 | ch1 = pair[1] | |
1129 |
|
1121 | |||
1130 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) |
|
1122 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) | |
1131 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) |
|
1123 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) | |
1132 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) |
|
1124 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) | |
1133 |
|
1125 | |||
1134 | return normFactor |
|
1126 | return normFactor | |
1135 |
|
1127 | |||
1136 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1128 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
1137 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1129 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") | |
1138 |
|
1130 | |||
1139 | class Parameters(Spectra): |
|
1131 | class Parameters(Spectra): | |
1140 |
|
1132 | |||
1141 | experimentInfo = None #Information about the experiment |
|
1133 | experimentInfo = None #Information about the experiment | |
1142 |
|
1134 | |||
1143 | #Information from previous data |
|
1135 | #Information from previous data | |
1144 |
|
1136 | |||
1145 | inputUnit = None #Type of data to be processed |
|
1137 | inputUnit = None #Type of data to be processed | |
1146 |
|
1138 | |||
1147 | operation = None #Type of operation to parametrize |
|
1139 | operation = None #Type of operation to parametrize | |
1148 |
|
1140 | |||
1149 | #normFactor = None #Normalization Factor |
|
1141 | #normFactor = None #Normalization Factor | |
1150 |
|
1142 | |||
1151 | groupList = None #List of Pairs, Groups, etc |
|
1143 | groupList = None #List of Pairs, Groups, etc | |
1152 |
|
1144 | |||
1153 | #Parameters |
|
1145 | #Parameters | |
1154 |
|
1146 | |||
1155 | data_param = None #Parameters obtained |
|
1147 | data_param = None #Parameters obtained | |
1156 |
|
1148 | |||
1157 | data_pre = None #Data Pre Parametrization |
|
1149 | data_pre = None #Data Pre Parametrization | |
1158 |
|
1150 | |||
1159 | data_SNR = None #Signal to Noise Ratio |
|
1151 | data_SNR = None #Signal to Noise Ratio | |
1160 |
|
1152 | |||
1161 | # heightRange = None #Heights |
|
1153 | # heightRange = None #Heights | |
1162 |
|
1154 | |||
1163 | abscissaList = None #Abscissa, can be velocities, lags or time |
|
1155 | abscissaList = None #Abscissa, can be velocities, lags or time | |
1164 |
|
1156 | |||
1165 | # noise = None #Noise Potency |
|
1157 | # noise = None #Noise Potency | |
1166 |
|
1158 | |||
1167 | utctimeInit = None #Initial UTC time |
|
1159 | utctimeInit = None #Initial UTC time | |
1168 |
|
1160 | |||
1169 | paramInterval = None #Time interval to calculate Parameters in seconds |
|
1161 | paramInterval = None #Time interval to calculate Parameters in seconds | |
1170 |
|
1162 | |||
1171 | useLocalTime = True |
|
1163 | useLocalTime = True | |
1172 |
|
1164 | |||
1173 | #Fitting |
|
1165 | #Fitting | |
1174 |
|
1166 | |||
1175 | data_error = None #Error of the estimation |
|
1167 | data_error = None #Error of the estimation | |
1176 |
|
1168 | |||
1177 | constants = None |
|
1169 | constants = None | |
1178 |
|
1170 | |||
1179 | library = None |
|
1171 | library = None | |
1180 |
|
1172 | |||
1181 | #Output signal |
|
1173 | #Output signal | |
1182 |
|
1174 | |||
1183 | outputInterval = None #Time interval to calculate output signal in seconds |
|
1175 | outputInterval = None #Time interval to calculate output signal in seconds | |
1184 |
|
1176 | |||
1185 | data_output = None #Out signal |
|
1177 | data_output = None #Out signal | |
1186 |
|
1178 | |||
1187 | nAvg = None |
|
1179 | nAvg = None | |
1188 |
|
1180 | |||
1189 | noise_estimation = None |
|
1181 | noise_estimation = None | |
1190 |
|
1182 | |||
1191 |
|
1183 | |||
1192 | def __init__(self): |
|
1184 | def __init__(self): | |
1193 | ''' |
|
1185 | ''' | |
1194 | Constructor |
|
1186 | Constructor | |
1195 | ''' |
|
1187 | ''' | |
1196 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1188 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1197 |
|
1189 | |||
1198 | self.systemHeaderObj = SystemHeader() |
|
1190 | self.systemHeaderObj = SystemHeader() | |
1199 |
|
1191 | |||
1200 | self.type = "Parameters" |
|
1192 | self.type = "Parameters" | |
1201 |
|
1193 | |||
1202 | def getTimeRange1(self, interval): |
|
1194 | def getTimeRange1(self, interval): | |
1203 |
|
1195 | |||
1204 | datatime = [] |
|
1196 | datatime = [] | |
1205 |
|
1197 | |||
1206 | if self.useLocalTime: |
|
1198 | if self.useLocalTime: | |
1207 | time1 = self.utctimeInit - self.timeZone*60 |
|
1199 | time1 = self.utctimeInit - self.timeZone*60 | |
1208 | else: |
|
1200 | else: | |
1209 | time1 = self.utctimeInit |
|
1201 | time1 = self.utctimeInit | |
1210 |
|
1202 | |||
1211 | datatime.append(time1) |
|
1203 | datatime.append(time1) | |
1212 | datatime.append(time1 + interval) |
|
1204 | datatime.append(time1 + interval) | |
1213 | datatime = numpy.array(datatime) |
|
1205 | datatime = numpy.array(datatime) | |
1214 |
|
1206 | |||
1215 | return datatime |
|
1207 | return datatime | |
1216 |
|
1208 | |||
1217 | def getTimeInterval(self): |
|
1209 | def getTimeInterval(self): | |
1218 |
|
1210 | |||
1219 | if hasattr(self, 'timeInterval1'): |
|
1211 | if hasattr(self, 'timeInterval1'): | |
1220 | return self.timeInterval1 |
|
1212 | return self.timeInterval1 | |
1221 | else: |
|
1213 | else: | |
1222 | return self.paramInterval |
|
1214 | return self.paramInterval | |
1223 |
|
1215 | |||
1224 | def getNoise(self): |
|
1216 | def getNoise(self): | |
1225 |
|
1217 | |||
1226 | return self.spc_noise |
|
1218 | return self.spc_noise | |
1227 |
|
1219 | |||
1228 | timeInterval = property(getTimeInterval) |
|
1220 | timeInterval = property(getTimeInterval) |
@@ -1,464 +1,502 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Juan C. Espinoza |
|
2 | @author: Juan C. Espinoza | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | import time |
|
5 | import time | |
6 | import json |
|
6 | import json | |
7 | import numpy |
|
7 | import numpy | |
8 | import paho.mqtt.client as mqtt |
|
8 | import paho.mqtt.client as mqtt | |
9 | import zmq |
|
9 | import zmq | |
10 | from profilehooks import profile |
|
10 | from profilehooks import profile | |
11 | import datetime |
|
11 | import datetime | |
12 | from zmq.utils.monitor import recv_monitor_message |
|
12 | from zmq.utils.monitor import recv_monitor_message | |
13 | from functools import wraps |
|
13 | from functools import wraps | |
14 | from threading import Thread |
|
14 | from threading import Thread | |
15 | from multiprocessing import Process |
|
15 | from multiprocessing import Process | |
16 |
|
16 | |||
17 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
17 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit | |
|
18 | from schainpy.model.data.jrodata import JROData | |||
18 |
|
19 | |||
19 | MAXNUMX = 100 |
|
20 | MAXNUMX = 100 | |
20 | MAXNUMY = 100 |
|
21 | MAXNUMY = 100 | |
21 |
|
22 | |||
22 | class PrettyFloat(float): |
|
23 | class PrettyFloat(float): | |
23 | def __repr__(self): |
|
24 | def __repr__(self): | |
24 | return '%.2f' % self |
|
25 | return '%.2f' % self | |
25 |
|
26 | |||
26 | def roundFloats(obj): |
|
27 | def roundFloats(obj): | |
27 | if isinstance(obj, list): |
|
28 | if isinstance(obj, list): | |
28 | return map(roundFloats, obj) |
|
29 | return map(roundFloats, obj) | |
29 | elif isinstance(obj, float): |
|
30 | elif isinstance(obj, float): | |
30 | return round(obj, 2) |
|
31 | return round(obj, 2) | |
31 |
|
32 | |||
32 | def decimate(z, MAXNUMY): |
|
33 | def decimate(z, MAXNUMY): | |
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
34 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
34 |
|
35 | |||
35 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
36 | dy = int(len(z[0])/MAXNUMY) + 1 | |
36 |
|
37 | |||
37 | return z[::, ::dy] |
|
38 | return z[::, ::dy] | |
38 |
|
39 | |||
39 | class throttle(object): |
|
40 | class throttle(object): | |
40 | """Decorator that prevents a function from being called more than once every |
|
41 | """Decorator that prevents a function from being called more than once every | |
41 | time period. |
|
42 | time period. | |
42 | To create a function that cannot be called more than once a minute, but |
|
43 | To create a function that cannot be called more than once a minute, but | |
43 | will sleep until it can be called: |
|
44 | will sleep until it can be called: | |
44 | @throttle(minutes=1) |
|
45 | @throttle(minutes=1) | |
45 | def foo(): |
|
46 | def foo(): | |
46 | pass |
|
47 | pass | |
47 |
|
48 | |||
48 | for i in range(10): |
|
49 | for i in range(10): | |
49 | foo() |
|
50 | foo() | |
50 | print "This function has run %s times." % i |
|
51 | print "This function has run %s times." % i | |
51 | """ |
|
52 | """ | |
52 |
|
53 | |||
53 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
54 | def __init__(self, seconds=0, minutes=0, hours=0): | |
54 | self.throttle_period = datetime.timedelta( |
|
55 | self.throttle_period = datetime.timedelta( | |
55 | seconds=seconds, minutes=minutes, hours=hours |
|
56 | seconds=seconds, minutes=minutes, hours=hours | |
56 | ) |
|
57 | ) | |
57 |
|
58 | |||
58 | self.time_of_last_call = datetime.datetime.min |
|
59 | self.time_of_last_call = datetime.datetime.min | |
59 |
|
60 | |||
60 | def __call__(self, fn): |
|
61 | def __call__(self, fn): | |
61 | @wraps(fn) |
|
62 | @wraps(fn) | |
62 | def wrapper(*args, **kwargs): |
|
63 | def wrapper(*args, **kwargs): | |
63 | now = datetime.datetime.now() |
|
64 | now = datetime.datetime.now() | |
64 | time_since_last_call = now - self.time_of_last_call |
|
65 | time_since_last_call = now - self.time_of_last_call | |
65 | time_left = self.throttle_period - time_since_last_call |
|
66 | time_left = self.throttle_period - time_since_last_call | |
66 |
|
67 | |||
67 | if time_left > datetime.timedelta(seconds=0): |
|
68 | if time_left > datetime.timedelta(seconds=0): | |
68 | return |
|
69 | return | |
69 |
|
70 | |||
70 | self.time_of_last_call = datetime.datetime.now() |
|
71 | self.time_of_last_call = datetime.datetime.now() | |
71 | return fn(*args, **kwargs) |
|
72 | return fn(*args, **kwargs) | |
72 |
|
73 | |||
73 | return wrapper |
|
74 | return wrapper | |
74 |
|
75 | |||
75 |
|
76 | |||
76 | class PublishData(Operation): |
|
77 | class PublishData(Operation): | |
77 | """Clase publish.""" |
|
78 | """Clase publish.""" | |
78 |
|
79 | |||
79 | def __init__(self, **kwargs): |
|
80 | def __init__(self, **kwargs): | |
80 | """Inicio.""" |
|
81 | """Inicio.""" | |
81 | Operation.__init__(self, **kwargs) |
|
82 | Operation.__init__(self, **kwargs) | |
82 | self.isConfig = False |
|
83 | self.isConfig = False | |
83 | self.client = None |
|
84 | self.client = None | |
84 | self.zeromq = None |
|
85 | self.zeromq = None | |
85 | self.mqtt = None |
|
86 | self.mqtt = None | |
86 |
|
87 | |||
87 | def on_disconnect(self, client, userdata, rc): |
|
88 | def on_disconnect(self, client, userdata, rc): | |
88 | if rc != 0: |
|
89 | if rc != 0: | |
89 | print("Unexpected disconnection.") |
|
90 | print("Unexpected disconnection.") | |
90 | self.connect() |
|
91 | self.connect() | |
91 |
|
92 | |||
92 | def connect(self): |
|
93 | def connect(self): | |
93 | print 'trying to connect' |
|
94 | print 'trying to connect' | |
94 | try: |
|
95 | try: | |
95 | self.client.connect( |
|
96 | self.client.connect( | |
96 | host=self.host, |
|
97 | host=self.host, | |
97 | port=self.port, |
|
98 | port=self.port, | |
98 | keepalive=60*10, |
|
99 | keepalive=60*10, | |
99 | bind_address='') |
|
100 | bind_address='') | |
100 | self.client.loop_start() |
|
101 | self.client.loop_start() | |
101 | # self.client.publish( |
|
102 | # self.client.publish( | |
102 | # self.topic + 'SETUP', |
|
103 | # self.topic + 'SETUP', | |
103 | # json.dumps(setup), |
|
104 | # json.dumps(setup), | |
104 | # retain=True |
|
105 | # retain=True | |
105 | # ) |
|
106 | # ) | |
106 | except: |
|
107 | except: | |
107 | print "MQTT Conection error." |
|
108 | print "MQTT Conection error." | |
108 | self.client = False |
|
109 | self.client = False | |
109 |
|
110 | |||
110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): |
|
111 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): | |
111 | self.counter = 0 |
|
112 | self.counter = 0 | |
112 | self.topic = kwargs.get('topic', 'schain') |
|
113 | self.topic = kwargs.get('topic', 'schain') | |
113 | self.delay = kwargs.get('delay', 0) |
|
114 | self.delay = kwargs.get('delay', 0) | |
114 | self.plottype = kwargs.get('plottype', 'spectra') |
|
115 | self.plottype = kwargs.get('plottype', 'spectra') | |
115 | self.host = kwargs.get('host', "10.10.10.82") |
|
116 | self.host = kwargs.get('host', "10.10.10.82") | |
116 | self.port = kwargs.get('port', 3000) |
|
117 | self.port = kwargs.get('port', 3000) | |
117 | self.clientId = clientId |
|
118 | self.clientId = clientId | |
118 | self.cnt = 0 |
|
119 | self.cnt = 0 | |
119 | self.zeromq = zeromq |
|
120 | self.zeromq = zeromq | |
120 | self.mqtt = kwargs.get('plottype', 0) |
|
121 | self.mqtt = kwargs.get('plottype', 0) | |
121 | self.client = None |
|
122 | self.client = None | |
122 | self.verbose = verbose |
|
123 | self.verbose = verbose | |
123 | self.dataOut.firstdata = True |
|
124 | self.dataOut.firstdata = True | |
124 | setup = [] |
|
125 | setup = [] | |
125 | if mqtt is 1: |
|
126 | if mqtt is 1: | |
126 | self.client = mqtt.Client( |
|
127 | self.client = mqtt.Client( | |
127 | client_id=self.clientId + self.topic + 'SCHAIN', |
|
128 | client_id=self.clientId + self.topic + 'SCHAIN', | |
128 | clean_session=True) |
|
129 | clean_session=True) | |
129 | self.client.on_disconnect = self.on_disconnect |
|
130 | self.client.on_disconnect = self.on_disconnect | |
130 | self.connect() |
|
131 | self.connect() | |
131 | for plot in self.plottype: |
|
132 | for plot in self.plottype: | |
132 | setup.append({ |
|
133 | setup.append({ | |
133 | 'plot': plot, |
|
134 | 'plot': plot, | |
134 | 'topic': self.topic + plot, |
|
135 | 'topic': self.topic + plot, | |
135 | 'title': getattr(self, plot + '_' + 'title', False), |
|
136 | 'title': getattr(self, plot + '_' + 'title', False), | |
136 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), |
|
137 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), | |
137 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), |
|
138 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), | |
138 | 'xrange': getattr(self, plot + '_' + 'xrange', False), |
|
139 | 'xrange': getattr(self, plot + '_' + 'xrange', False), | |
139 | 'yrange': getattr(self, plot + '_' + 'yrange', False), |
|
140 | 'yrange': getattr(self, plot + '_' + 'yrange', False), | |
140 | 'zrange': getattr(self, plot + '_' + 'zrange', False), |
|
141 | 'zrange': getattr(self, plot + '_' + 'zrange', False), | |
141 | }) |
|
142 | }) | |
142 | if zeromq is 1: |
|
143 | if zeromq is 1: | |
143 | context = zmq.Context() |
|
144 | context = zmq.Context() | |
144 | self.zmq_socket = context.socket(zmq.PUSH) |
|
145 | self.zmq_socket = context.socket(zmq.PUSH) | |
145 | server = kwargs.get('server', 'zmq.pipe') |
|
146 | server = kwargs.get('server', 'zmq.pipe') | |
146 |
|
147 | |||
147 | if 'tcp://' in server: |
|
148 | if 'tcp://' in server: | |
148 | address = server |
|
149 | address = server | |
149 | else: |
|
150 | else: | |
150 | address = 'ipc:///tmp/%s' % server |
|
151 | address = 'ipc:///tmp/%s' % server | |
151 |
|
152 | |||
152 | self.zmq_socket.connect(address) |
|
153 | self.zmq_socket.connect(address) | |
153 | time.sleep(1) |
|
154 | time.sleep(1) | |
154 |
|
155 | |||
155 |
|
156 | |||
156 | def publish_data(self): |
|
157 | def publish_data(self): | |
157 | self.dataOut.finished = False |
|
158 | self.dataOut.finished = False | |
158 | if self.mqtt is 1: |
|
159 | if self.mqtt is 1: | |
159 | yData = self.dataOut.heightList[:2].tolist() |
|
160 | yData = self.dataOut.heightList[:2].tolist() | |
160 | if self.plottype == 'spectra': |
|
161 | if self.plottype == 'spectra': | |
161 | data = getattr(self.dataOut, 'data_spc') |
|
162 | data = getattr(self.dataOut, 'data_spc') | |
162 | z = data/self.dataOut.normFactor |
|
163 | z = data/self.dataOut.normFactor | |
163 | zdB = 10*numpy.log10(z) |
|
164 | zdB = 10*numpy.log10(z) | |
164 | xlen, ylen = zdB[0].shape |
|
165 | xlen, ylen = zdB[0].shape | |
165 | dx = int(xlen/MAXNUMX) + 1 |
|
166 | dx = int(xlen/MAXNUMX) + 1 | |
166 | dy = int(ylen/MAXNUMY) + 1 |
|
167 | dy = int(ylen/MAXNUMY) + 1 | |
167 | Z = [0 for i in self.dataOut.channelList] |
|
168 | Z = [0 for i in self.dataOut.channelList] | |
168 | for i in self.dataOut.channelList: |
|
169 | for i in self.dataOut.channelList: | |
169 | Z[i] = zdB[i][::dx, ::dy].tolist() |
|
170 | Z[i] = zdB[i][::dx, ::dy].tolist() | |
170 | payload = { |
|
171 | payload = { | |
171 | 'timestamp': self.dataOut.utctime, |
|
172 | 'timestamp': self.dataOut.utctime, | |
172 | 'data': roundFloats(Z), |
|
173 | 'data': roundFloats(Z), | |
173 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
174 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
174 | 'interval': self.dataOut.getTimeInterval(), |
|
175 | 'interval': self.dataOut.getTimeInterval(), | |
175 | 'type': self.plottype, |
|
176 | 'type': self.plottype, | |
176 | 'yData': yData |
|
177 | 'yData': yData | |
177 | } |
|
178 | } | |
178 | # print payload |
|
179 | # print payload | |
179 |
|
180 | |||
180 | elif self.plottype in ('rti', 'power'): |
|
181 | elif self.plottype in ('rti', 'power'): | |
181 | data = getattr(self.dataOut, 'data_spc') |
|
182 | data = getattr(self.dataOut, 'data_spc') | |
182 | z = data/self.dataOut.normFactor |
|
183 | z = data/self.dataOut.normFactor | |
183 | avg = numpy.average(z, axis=1) |
|
184 | avg = numpy.average(z, axis=1) | |
184 | avgdB = 10*numpy.log10(avg) |
|
185 | avgdB = 10*numpy.log10(avg) | |
185 | xlen, ylen = z[0].shape |
|
186 | xlen, ylen = z[0].shape | |
186 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
187 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
187 | AVG = [0 for i in self.dataOut.channelList] |
|
188 | AVG = [0 for i in self.dataOut.channelList] | |
188 | for i in self.dataOut.channelList: |
|
189 | for i in self.dataOut.channelList: | |
189 | AVG[i] = avgdB[i][::dy].tolist() |
|
190 | AVG[i] = avgdB[i][::dy].tolist() | |
190 | payload = { |
|
191 | payload = { | |
191 | 'timestamp': self.dataOut.utctime, |
|
192 | 'timestamp': self.dataOut.utctime, | |
192 | 'data': roundFloats(AVG), |
|
193 | 'data': roundFloats(AVG), | |
193 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
194 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
194 | 'interval': self.dataOut.getTimeInterval(), |
|
195 | 'interval': self.dataOut.getTimeInterval(), | |
195 | 'type': self.plottype, |
|
196 | 'type': self.plottype, | |
196 | 'yData': yData |
|
197 | 'yData': yData | |
197 | } |
|
198 | } | |
198 | elif self.plottype == 'noise': |
|
199 | elif self.plottype == 'noise': | |
199 | noise = self.dataOut.getNoise()/self.dataOut.normFactor |
|
200 | noise = self.dataOut.getNoise()/self.dataOut.normFactor | |
200 | noisedB = 10*numpy.log10(noise) |
|
201 | noisedB = 10*numpy.log10(noise) | |
201 | payload = { |
|
202 | payload = { | |
202 | 'timestamp': self.dataOut.utctime, |
|
203 | 'timestamp': self.dataOut.utctime, | |
203 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), |
|
204 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), | |
204 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
205 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
205 | 'interval': self.dataOut.getTimeInterval(), |
|
206 | 'interval': self.dataOut.getTimeInterval(), | |
206 | 'type': self.plottype, |
|
207 | 'type': self.plottype, | |
207 | 'yData': yData |
|
208 | 'yData': yData | |
208 | } |
|
209 | } | |
209 | elif self.plottype == 'snr': |
|
210 | elif self.plottype == 'snr': | |
210 | data = getattr(self.dataOut, 'data_SNR') |
|
211 | data = getattr(self.dataOut, 'data_SNR') | |
211 | avgdB = 10*numpy.log10(data) |
|
212 | avgdB = 10*numpy.log10(data) | |
212 |
|
213 | |||
213 | ylen = data[0].size |
|
214 | ylen = data[0].size | |
214 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
215 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
215 | AVG = [0 for i in self.dataOut.channelList] |
|
216 | AVG = [0 for i in self.dataOut.channelList] | |
216 | for i in self.dataOut.channelList: |
|
217 | for i in self.dataOut.channelList: | |
217 | AVG[i] = avgdB[i][::dy].tolist() |
|
218 | AVG[i] = avgdB[i][::dy].tolist() | |
218 | payload = { |
|
219 | payload = { | |
219 | 'timestamp': self.dataOut.utctime, |
|
220 | 'timestamp': self.dataOut.utctime, | |
220 | 'data': roundFloats(AVG), |
|
221 | 'data': roundFloats(AVG), | |
221 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
222 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
222 | 'type': self.plottype, |
|
223 | 'type': self.plottype, | |
223 | 'yData': yData |
|
224 | 'yData': yData | |
224 | } |
|
225 | } | |
225 | else: |
|
226 | else: | |
226 | print "Tipo de grafico invalido" |
|
227 | print "Tipo de grafico invalido" | |
227 | payload = { |
|
228 | payload = { | |
228 | 'data': 'None', |
|
229 | 'data': 'None', | |
229 | 'timestamp': 'None', |
|
230 | 'timestamp': 'None', | |
230 | 'type': None |
|
231 | 'type': None | |
231 | } |
|
232 | } | |
232 | # print 'Publishing data to {}'.format(self.host) |
|
233 | # print 'Publishing data to {}'.format(self.host) | |
233 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
234 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) | |
234 |
|
235 | |||
235 | if self.zeromq is 1: |
|
236 | if self.zeromq is 1: | |
236 | if self.verbose: |
|
237 | if self.verbose: | |
237 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) |
|
238 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) | |
238 | self.zmq_socket.send_pyobj(self.dataOut) |
|
239 | self.zmq_socket.send_pyobj(self.dataOut) | |
239 | self.dataOut.firstdata = False |
|
240 | self.dataOut.firstdata = False | |
240 |
|
241 | |||
241 |
|
242 | |||
242 | def run(self, dataOut, **kwargs): |
|
243 | def run(self, dataOut, **kwargs): | |
243 | self.dataOut = dataOut |
|
244 | self.dataOut = dataOut | |
244 | if not self.isConfig: |
|
245 | if not self.isConfig: | |
245 | self.setup(**kwargs) |
|
246 | self.setup(**kwargs) | |
246 | self.isConfig = True |
|
247 | self.isConfig = True | |
247 |
|
248 | |||
248 | self.publish_data() |
|
249 | self.publish_data() | |
249 | time.sleep(self.delay) |
|
250 | time.sleep(self.delay) | |
250 |
|
251 | |||
251 | def close(self): |
|
252 | def close(self): | |
252 | if self.zeromq is 1: |
|
253 | if self.zeromq is 1: | |
253 | self.dataOut.finished = True |
|
254 | self.dataOut.finished = True | |
254 | self.zmq_socket.send_pyobj(self.dataOut) |
|
255 | self.zmq_socket.send_pyobj(self.dataOut) | |
255 | self.zmq_socket.close() |
|
256 | self.zmq_socket.close() | |
256 | if self.client: |
|
257 | if self.client: | |
257 | self.client.loop_stop() |
|
258 | self.client.loop_stop() | |
258 | self.client.disconnect() |
|
259 | self.client.disconnect() | |
259 |
|
260 | |||
260 | class ReceiverData(ProcessingUnit, Process): |
|
261 | ||
|
262 | class ReceiverData(ProcessingUnit): | |||
|
263 | ||||
|
264 | def __init__(self, **kwargs): | |||
|
265 | ||||
|
266 | ProcessingUnit.__init__(self, **kwargs) | |||
|
267 | ||||
|
268 | self.isConfig = False | |||
|
269 | server = kwargs.get('server', 'zmq.pipe') | |||
|
270 | if 'tcp://' in server: | |||
|
271 | address = server | |||
|
272 | else: | |||
|
273 | address = 'ipc:///tmp/%s' % server | |||
|
274 | ||||
|
275 | self.address = address | |||
|
276 | self.dataOut = JROData() | |||
|
277 | ||||
|
278 | def setup(self): | |||
|
279 | ||||
|
280 | self.context = zmq.Context() | |||
|
281 | self.receiver = self.context.socket(zmq.PULL) | |||
|
282 | self.receiver.bind(self.address) | |||
|
283 | time.sleep(0.5) | |||
|
284 | print '[Starting] ReceiverData from {}'.format(self.address) | |||
|
285 | ||||
|
286 | ||||
|
287 | def run(self): | |||
|
288 | ||||
|
289 | if not self.isConfig: | |||
|
290 | self.setup() | |||
|
291 | self.isConfig = True | |||
|
292 | ||||
|
293 | self.dataOut = self.receiver.recv_pyobj() | |||
|
294 | print '[Receiving] {} - {}'.format(self.dataOut.type, | |||
|
295 | self.dataOut.datatime.ctime()) | |||
|
296 | ||||
|
297 | ||||
|
298 | class PlotterReceiver(ProcessingUnit, Process): | |||
261 |
|
299 | |||
262 | throttle_value = 5 |
|
300 | throttle_value = 5 | |
263 |
|
301 | |||
264 | def __init__(self, **kwargs): |
|
302 | def __init__(self, **kwargs): | |
265 |
|
303 | |||
266 | ProcessingUnit.__init__(self, **kwargs) |
|
304 | ProcessingUnit.__init__(self, **kwargs) | |
267 | Process.__init__(self) |
|
305 | Process.__init__(self) | |
268 | self.mp = False |
|
306 | self.mp = False | |
269 | self.isConfig = False |
|
307 | self.isConfig = False | |
270 | self.isWebConfig = False |
|
308 | self.isWebConfig = False | |
271 | self.plottypes =[] |
|
309 | self.plottypes = [] | |
272 | self.connections = 0 |
|
310 | self.connections = 0 | |
273 | server = kwargs.get('server', 'zmq.pipe') |
|
311 | server = kwargs.get('server', 'zmq.pipe') | |
274 | plot_server = kwargs.get('plot_server', 'zmq.web') |
|
312 | plot_server = kwargs.get('plot_server', 'zmq.web') | |
275 | if 'tcp://' in server: |
|
313 | if 'tcp://' in server: | |
276 | address = server |
|
314 | address = server | |
277 | else: |
|
315 | else: | |
278 | address = 'ipc:///tmp/%s' % server |
|
316 | address = 'ipc:///tmp/%s' % server | |
279 |
|
317 | |||
280 | if 'tcp://' in plot_server: |
|
318 | if 'tcp://' in plot_server: | |
281 | plot_address = plot_server |
|
319 | plot_address = plot_server | |
282 | else: |
|
320 | else: | |
283 | plot_address = 'ipc:///tmp/%s' % plot_server |
|
321 | plot_address = 'ipc:///tmp/%s' % plot_server | |
284 |
|
322 | |||
285 | self.address = address |
|
323 | self.address = address | |
286 | self.plot_address = plot_address |
|
324 | self.plot_address = plot_address | |
287 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] |
|
325 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] | |
288 | self.realtime = kwargs.get('realtime', False) |
|
326 | self.realtime = kwargs.get('realtime', False) | |
289 | self.throttle_value = kwargs.get('throttle', 5) |
|
327 | self.throttle_value = kwargs.get('throttle', 5) | |
290 | self.sendData = self.initThrottle(self.throttle_value) |
|
328 | self.sendData = self.initThrottle(self.throttle_value) | |
291 | self.setup() |
|
329 | self.setup() | |
292 |
|
330 | |||
293 | def setup(self): |
|
331 | def setup(self): | |
294 |
|
332 | |||
295 | self.data = {} |
|
333 | self.data = {} | |
296 | self.data['times'] = [] |
|
334 | self.data['times'] = [] | |
297 | for plottype in self.plottypes: |
|
335 | for plottype in self.plottypes: | |
298 | self.data[plottype] = {} |
|
336 | self.data[plottype] = {} | |
299 | self.data['noise'] = {} |
|
337 | self.data['noise'] = {} | |
300 | self.data['throttle'] = self.throttle_value |
|
338 | self.data['throttle'] = self.throttle_value | |
301 | self.data['ENDED'] = False |
|
339 | self.data['ENDED'] = False | |
302 | self.isConfig = True |
|
340 | self.isConfig = True | |
303 | self.data_web = {} |
|
341 | self.data_web = {} | |
304 |
|
342 | |||
305 | def event_monitor(self, monitor): |
|
343 | def event_monitor(self, monitor): | |
306 |
|
344 | |||
307 | events = {} |
|
345 | events = {} | |
308 |
|
346 | |||
309 | for name in dir(zmq): |
|
347 | for name in dir(zmq): | |
310 | if name.startswith('EVENT_'): |
|
348 | if name.startswith('EVENT_'): | |
311 | value = getattr(zmq, name) |
|
349 | value = getattr(zmq, name) | |
312 | events[value] = name |
|
350 | events[value] = name | |
313 |
|
351 | |||
314 | while monitor.poll(): |
|
352 | while monitor.poll(): | |
315 | evt = recv_monitor_message(monitor) |
|
353 | evt = recv_monitor_message(monitor) | |
316 | if evt['event'] == 32: |
|
354 | if evt['event'] == 32: | |
317 | self.connections += 1 |
|
355 | self.connections += 1 | |
318 | if evt['event'] == 512: |
|
356 | if evt['event'] == 512: | |
319 | pass |
|
357 | pass | |
320 | if self.connections == 0 and self.started is True: |
|
358 | if self.connections == 0 and self.started is True: | |
321 | self.ended = True |
|
359 | self.ended = True | |
322 |
|
360 | |||
323 | evt.update({'description': events[evt['event']]}) |
|
361 | evt.update({'description': events[evt['event']]}) | |
324 |
|
362 | |||
325 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
363 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: | |
326 | break |
|
364 | break | |
327 | monitor.close() |
|
365 | monitor.close() | |
328 | print("event monitor thread done!") |
|
366 | print("event monitor thread done!") | |
329 |
|
367 | |||
330 | def initThrottle(self, throttle_value): |
|
368 | def initThrottle(self, throttle_value): | |
331 |
|
369 | |||
332 | @throttle(seconds=throttle_value) |
|
370 | @throttle(seconds=throttle_value) | |
333 | def sendDataThrottled(fn_sender, data): |
|
371 | def sendDataThrottled(fn_sender, data): | |
334 | fn_sender(data) |
|
372 | fn_sender(data) | |
335 |
|
373 | |||
336 | return sendDataThrottled |
|
374 | return sendDataThrottled | |
337 |
|
375 | |||
338 |
|
376 | |||
339 | def send(self, data): |
|
377 | def send(self, data): | |
340 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) |
|
378 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) | |
341 | self.sender.send_pyobj(data) |
|
379 | self.sender.send_pyobj(data) | |
342 |
|
380 | |||
343 |
|
381 | |||
344 | def update(self): |
|
382 | def update(self): | |
345 | t = self.dataOut.utctime |
|
383 | t = self.dataOut.utctime | |
346 |
|
384 | |||
347 | if t in self.data['times']: |
|
385 | if t in self.data['times']: | |
348 | return |
|
386 | return | |
349 |
|
387 | |||
350 | self.data['times'].append(t) |
|
388 | self.data['times'].append(t) | |
351 | self.data['dataOut'] = self.dataOut |
|
389 | self.data['dataOut'] = self.dataOut | |
352 |
|
390 | |||
353 | for plottype in self.plottypes: |
|
391 | for plottype in self.plottypes: | |
354 | if plottype == 'spc': |
|
392 | if plottype == 'spc': | |
355 | z = self.dataOut.data_spc/self.dataOut.normFactor |
|
393 | z = self.dataOut.data_spc/self.dataOut.normFactor | |
356 | self.data[plottype] = 10*numpy.log10(z) |
|
394 | self.data[plottype] = 10*numpy.log10(z) | |
357 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) |
|
395 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) | |
358 | if plottype == 'cspc': |
|
396 | if plottype == 'cspc': | |
359 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) |
|
397 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) | |
360 | self.data['cspc_coh'] = numpy.abs(jcoherence) |
|
398 | self.data['cspc_coh'] = numpy.abs(jcoherence) | |
361 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi |
|
399 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi | |
362 | if plottype == 'rti': |
|
400 | if plottype == 'rti': | |
363 | self.data[plottype][t] = self.dataOut.getPower() |
|
401 | self.data[plottype][t] = self.dataOut.getPower() | |
364 | if plottype == 'snr': |
|
402 | if plottype == 'snr': | |
365 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) |
|
403 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) | |
366 | if plottype == 'dop': |
|
404 | if plottype == 'dop': | |
367 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) |
|
405 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) | |
368 | if plottype == 'mean': |
|
406 | if plottype == 'mean': | |
369 | self.data[plottype][t] = self.dataOut.data_MEAN |
|
407 | self.data[plottype][t] = self.dataOut.data_MEAN | |
370 | if plottype == 'std': |
|
408 | if plottype == 'std': | |
371 | self.data[plottype][t] = self.dataOut.data_STD |
|
409 | self.data[plottype][t] = self.dataOut.data_STD | |
372 | if plottype == 'coh': |
|
410 | if plottype == 'coh': | |
373 | self.data[plottype][t] = self.dataOut.getCoherence() |
|
411 | self.data[plottype][t] = self.dataOut.getCoherence() | |
374 | if plottype == 'phase': |
|
412 | if plottype == 'phase': | |
375 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) |
|
413 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) | |
376 | if plottype == 'output': |
|
414 | if plottype == 'output': | |
377 | self.data[plottype][t] = self.dataOut.data_output |
|
415 | self.data[plottype][t] = self.dataOut.data_output | |
378 | if plottype == 'param': |
|
416 | if plottype == 'param': | |
379 | self.data[plottype][t] = self.dataOut.data_param |
|
417 | self.data[plottype][t] = self.dataOut.data_param | |
380 | if self.realtime: |
|
418 | if self.realtime: | |
381 | self.data_web['timestamp'] = t |
|
419 | self.data_web['timestamp'] = t | |
382 | if plottype == 'spc': |
|
420 | if plottype == 'spc': | |
383 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) |
|
421 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) | |
384 | elif plottype == 'cspc': |
|
422 | elif plottype == 'cspc': | |
385 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) |
|
423 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) | |
386 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) |
|
424 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) | |
387 | elif plottype == 'noise': |
|
425 | elif plottype == 'noise': | |
388 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) |
|
426 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) | |
389 | else: |
|
427 | else: | |
390 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) |
|
428 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) | |
391 | self.data_web['interval'] = self.dataOut.getTimeInterval() |
|
429 | self.data_web['interval'] = self.dataOut.getTimeInterval() | |
392 | self.data_web['type'] = plottype |
|
430 | self.data_web['type'] = plottype | |
393 |
|
431 | |||
394 | def run(self): |
|
432 | def run(self): | |
395 |
|
433 | |||
396 | print '[Starting] {} from {}'.format(self.name, self.address) |
|
434 | print '[Starting] {} from {}'.format(self.name, self.address) | |
397 |
|
435 | |||
398 | self.context = zmq.Context() |
|
436 | self.context = zmq.Context() | |
399 | self.receiver = self.context.socket(zmq.PULL) |
|
437 | self.receiver = self.context.socket(zmq.PULL) | |
400 | self.receiver.bind(self.address) |
|
438 | self.receiver.bind(self.address) | |
401 | monitor = self.receiver.get_monitor_socket() |
|
439 | monitor = self.receiver.get_monitor_socket() | |
402 | self.sender = self.context.socket(zmq.PUB) |
|
440 | self.sender = self.context.socket(zmq.PUB) | |
403 | if self.realtime: |
|
441 | if self.realtime: | |
404 | self.sender_web = self.context.socket(zmq.PUB) |
|
442 | self.sender_web = self.context.socket(zmq.PUB) | |
405 | self.sender_web.connect(self.plot_address) |
|
443 | self.sender_web.connect(self.plot_address) | |
406 | time.sleep(1) |
|
444 | time.sleep(1) | |
407 |
|
445 | |||
408 | if 'server' in self.kwargs: |
|
446 | if 'server' in self.kwargs: | |
409 | self.sender.bind("ipc:///tmp/{}.plots".format(self.kwargs['server'])) |
|
447 | self.sender.bind("ipc:///tmp/{}.plots".format(self.kwargs['server'])) | |
410 | else: |
|
448 | else: | |
411 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
449 | self.sender.bind("ipc:///tmp/zmq.plots") | |
412 |
|
450 | |||
413 | time.sleep(3) |
|
451 | time.sleep(3) | |
414 |
|
452 | |||
415 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
453 | t = Thread(target=self.event_monitor, args=(monitor,)) | |
416 | t.start() |
|
454 | t.start() | |
417 |
|
455 | |||
418 | while True: |
|
456 | while True: | |
419 | self.dataOut = self.receiver.recv_pyobj() |
|
457 | self.dataOut = self.receiver.recv_pyobj() | |
420 | # print '[Receiving] {} - {}'.format(self.dataOut.type, |
|
458 | # print '[Receiving] {} - {}'.format(self.dataOut.type, | |
421 | # self.dataOut.datatime.ctime()) |
|
459 | # self.dataOut.datatime.ctime()) | |
422 |
|
460 | |||
423 | self.update() |
|
461 | self.update() | |
424 |
|
462 | |||
425 | if self.dataOut.firstdata is True: |
|
463 | if self.dataOut.firstdata is True: | |
426 | self.data['STARTED'] = True |
|
464 | self.data['STARTED'] = True | |
427 |
|
465 | |||
428 | if self.dataOut.finished is True: |
|
466 | if self.dataOut.finished is True: | |
429 | self.send(self.data) |
|
467 | self.send(self.data) | |
430 | self.connections -= 1 |
|
468 | self.connections -= 1 | |
431 | if self.connections == 0 and self.started: |
|
469 | if self.connections == 0 and self.started: | |
432 | self.ended = True |
|
470 | self.ended = True | |
433 | self.data['ENDED'] = True |
|
471 | self.data['ENDED'] = True | |
434 | self.send(self.data) |
|
472 | self.send(self.data) | |
435 | self.setup() |
|
473 | self.setup() | |
436 | self.started = False |
|
474 | self.started = False | |
437 | else: |
|
475 | else: | |
438 | if self.realtime: |
|
476 | if self.realtime: | |
439 | self.send(self.data) |
|
477 | self.send(self.data) | |
440 | self.sender_web.send_string(json.dumps(self.data_web)) |
|
478 | self.sender_web.send_string(json.dumps(self.data_web)) | |
441 | else: |
|
479 | else: | |
442 | self.sendData(self.send, self.data) |
|
480 | self.sendData(self.send, self.data) | |
443 | self.started = True |
|
481 | self.started = True | |
444 |
|
482 | |||
445 | self.data['STARTED'] = False |
|
483 | self.data['STARTED'] = False | |
446 | return |
|
484 | return | |
447 |
|
485 | |||
448 | def sendToWeb(self): |
|
486 | def sendToWeb(self): | |
449 |
|
487 | |||
450 | if not self.isWebConfig: |
|
488 | if not self.isWebConfig: | |
451 | context = zmq.Context() |
|
489 | context = zmq.Context() | |
452 | sender_web_config = context.socket(zmq.PUB) |
|
490 | sender_web_config = context.socket(zmq.PUB) | |
453 | if 'tcp://' in self.plot_address: |
|
491 | if 'tcp://' in self.plot_address: | |
454 | dum, address, port = self.plot_address.split(':') |
|
492 | dum, address, port = self.plot_address.split(':') | |
455 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) |
|
493 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) | |
456 | else: |
|
494 | else: | |
457 | conf_address = self.plot_address + '.config' |
|
495 | conf_address = self.plot_address + '.config' | |
458 | sender_web_config.bind(conf_address) |
|
496 | sender_web_config.bind(conf_address) | |
459 | time.sleep(1) |
|
497 | time.sleep(1) | |
460 | for kwargs in self.operationKwargs.values(): |
|
498 | for kwargs in self.operationKwargs.values(): | |
461 | if 'plot' in kwargs: |
|
499 | if 'plot' in kwargs: | |
462 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) |
|
500 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) | |
463 | sender_web_config.send_string(json.dumps(kwargs)) |
|
501 | sender_web_config.send_string(json.dumps(kwargs)) | |
464 | self.isWebConfig = True |
|
502 | self.isWebConfig = True |
General Comments 0
You need to be logged in to leave comments.
Login now